summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/Makefile.ssl (renamed from src/lib/libcrypto/Attic/Makefile)26
-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/Makefile.ssl103
-rw-r--r--src/lib/libcrypto/aes/README3
-rw-r--r--src/lib/libcrypto/aes/aes.h127
-rw-r--r--src/lib/libcrypto/aes/aes_cbc.c131
-rw-r--r--src/lib/libcrypto/aes/aes_cfb.c225
-rw-r--r--src/lib/libcrypto/aes/aes_core.c1261
-rw-r--r--src/lib/libcrypto/aes/aes_ctr.c139
-rw-r--r--src/lib/libcrypto/aes/aes_ecb.c73
-rw-r--r--src/lib/libcrypto/aes/aes_locl.h85
-rw-r--r--src/lib/libcrypto/aes/aes_misc.c64
-rw-r--r--src/lib/libcrypto/aes/aes_ofb.c142
-rw-r--r--src/lib/libcrypto/aes/asm/aes-586.pl1541
-rw-r--r--src/lib/libcrypto/asn1/Makefile.ssl1152
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c222
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c114
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c312
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c262
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c111
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c107
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c180
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c163
-rw-r--r--src/lib/libcrypto/asn1/a_int.c453
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c400
-rw-r--r--src/lib/libcrypto/asn1/a_object.c320
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c71
-rw-r--r--src/lib/libcrypto/asn1/a_print.c127
-rw-r--r--src/lib/libcrypto/asn1/a_set.c235
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c294
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c567
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c290
-rw-r--r--src/lib/libcrypto/asn1/a_time.c164
-rw-r--r--src/lib/libcrypto/asn1/a_type.c84
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c211
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c181
-rw-r--r--src/lib/libcrypto/asn1/asn1.h1111
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c248
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c433
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h560
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c418
-rw-r--r--src/lib/libcrypto/asn1/asn1t.h846
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c100
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c191
-rw-r--r--src/lib/libcrypto/asn1/charmap.h15
-rw-r--r--src/lib/libcrypto/asn1/charmap.pl80
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c145
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c122
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c189
-rw-r--r--src/lib/libcrypto/asn1/f.c80
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c207
-rw-r--r--src/lib/libcrypto/asn1/f_int.c219
-rw-r--r--src/lib/libcrypto/asn1/f_string.c212
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c90
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c88
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c333
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c82
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c130
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c205
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c84
-rw-r--r--src/lib/libcrypto/asn1/t_bitst.c102
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c134
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c387
-rw-r--r--src/lib/libcrypto/asn1/t_req.c276
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c116
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c505
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c110
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c965
-rw-r--r--src/lib/libcrypto/asn1/tasn_enc.c497
-rw-r--r--src/lib/libcrypto/asn1/tasn_fre.c229
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c351
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c198
-rw-r--r--src/lib/libcrypto/asn1/tasn_typ.c133
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c253
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c73
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c118
-rw-r--r--src/lib/libcrypto/asn1/x_bignum.c137
-rw-r--r--src/lib/libcrypto/asn1/x_cinf.c201
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c140
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c71
-rw-r--r--src/lib/libcrypto/asn1/x_info.c114
-rw-r--r--src/lib/libcrypto/asn1/x_long.c169
-rw-r--r--src/lib/libcrypto/asn1/x_name.c275
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c151
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c360
-rw-r--r--src/lib/libcrypto/asn1/x_req.c112
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c69
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c81
-rw-r--r--src/lib/libcrypto/asn1/x_val.c69
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c189
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c151
-rw-r--r--src/lib/libcrypto/bf/COPYRIGHT46
-rw-r--r--src/lib/libcrypto/bf/INSTALL14
-rw-r--r--src/lib/libcrypto/bf/Makefile.ssl115
-rw-r--r--src/lib/libcrypto/bf/README8
-rw-r--r--src/lib/libcrypto/bf/VERSION6
-rw-r--r--src/lib/libcrypto/bf/asm/bf-586.pl136
-rw-r--r--src/lib/libcrypto/bf/bf_cbc.c143
-rw-r--r--src/lib/libcrypto/bf/bf_cfb64.c121
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c96
-rw-r--r--src/lib/libcrypto/bf/bf_enc.c306
-rw-r--r--src/lib/libcrypto/bf/bf_locl.h219
-rw-r--r--src/lib/libcrypto/bf/bf_ofb64.c110
-rw-r--r--src/lib/libcrypto/bf/bf_pi.h325
-rw-r--r--src/lib/libcrypto/bf/bf_skey.c117
-rw-r--r--src/lib/libcrypto/bf/blowfish.h130
-rw-r--r--src/lib/libcrypto/bio/Makefile.ssl216
-rw-r--r--src/lib/libcrypto/bio/b_dump.c156
-rw-r--r--src/lib/libcrypto/bio/b_print.c841
-rw-r--r--src/lib/libcrypto/bio/b_sock.c752
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c511
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c397
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c255
-rw-r--r--src/lib/libcrypto/bio/bf_null.c183
-rw-r--r--src/lib/libcrypto/bio/bio.h695
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c139
-rw-r--r--src/lib/libcrypto/bio/bio_err.c152
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c556
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c479
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c924
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c652
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c282
-rw-r--r--src/lib/libcrypto/bio/bss_file.c343
-rw-r--r--src/lib/libcrypto/bio/bss_log.c400
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c321
-rw-r--r--src/lib/libcrypto/bio/bss_null.c150
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c305
-rw-r--r--src/lib/libcrypto/bn/Makefile.ssl326
-rw-r--r--src/lib/libcrypto/bn/asm/bn-586.pl593
-rw-r--r--src/lib/libcrypto/bn/asm/co-586.pl286
-rw-r--r--src/lib/libcrypto/bn/asm/ia64.S1560
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc2.s1618
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc2W.s1605
-rw-r--r--src/lib/libcrypto/bn/asm/ppc.pl2081
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8.S1458
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8plus.S1535
-rw-r--r--src/lib/libcrypto/bn/asm/x86.pl28
-rw-r--r--src/lib/libcrypto/bn/asm/x86/add.pl76
-rw-r--r--src/lib/libcrypto/bn/asm/x86/comba.pl277
-rw-r--r--src/lib/libcrypto/bn/asm/x86/div.pl15
-rw-r--r--src/lib/libcrypto/bn/asm/x86/mul.pl77
-rw-r--r--src/lib/libcrypto/bn/asm/x86/mul_add.pl87
-rw-r--r--src/lib/libcrypto/bn/asm/x86/sqr.pl60
-rw-r--r--src/lib/libcrypto/bn/asm/x86/sub.pl76
-rw-r--r--src/lib/libcrypto/bn/asm/x86_64-gcc.c593
-rw-r--r--src/lib/libcrypto/bn/bn.h549
-rw-r--r--src/lib/libcrypto/bn/bn_add.c309
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c832
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c144
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c155
-rw-r--r--src/lib/libcrypto/bn/bn_div.c387
-rw-r--r--src/lib/libcrypto/bn/bn_err.c131
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c747
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c313
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c490
-rw-r--r--src/lib/libcrypto/bn/bn_kron.c182
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h453
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c824
-rw-r--r--src/lib/libcrypto/bn/bn_mod.c296
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c349
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c129
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c802
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c468
-rw-r--r--src/lib/libcrypto/bn/bn_prime.h325
-rw-r--r--src/lib/libcrypto/bn/bn_prime.pl117
-rw-r--r--src/lib/libcrypto/bn/bn_print.c333
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c291
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c230
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c205
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c288
-rw-r--r--src/lib/libcrypto/bn/bn_sqrt.c387
-rw-r--r--src/lib/libcrypto/bn/bn_word.c208
-rw-r--r--src/lib/libcrypto/bn/bntest.c60
-rw-r--r--src/lib/libcrypto/bn/expspeed.c2
-rw-r--r--src/lib/libcrypto/bn/exptest.c18
-rw-r--r--src/lib/libcrypto/buffer/Makefile.ssl94
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c95
-rw-r--r--src/lib/libcrypto/buffer/buffer.c202
-rw-r--r--src/lib/libcrypto/buffer/buffer.h105
-rw-r--r--src/lib/libcrypto/cast/Makefile.ssl120
-rw-r--r--src/lib/libcrypto/cast/asm/cast-586.pl176
-rw-r--r--src/lib/libcrypto/cast/c_cfb64.c122
-rw-r--r--src/lib/libcrypto/cast/c_ecb.c80
-rw-r--r--src/lib/libcrypto/cast/c_enc.c209
-rw-r--r--src/lib/libcrypto/cast/c_ofb64.c111
-rw-r--r--src/lib/libcrypto/cast/c_skey.c168
-rw-r--r--src/lib/libcrypto/cast/cast.h106
-rw-r--r--src/lib/libcrypto/cast/cast_lcl.h232
-rw-r--r--src/lib/libcrypto/cast/cast_s.h585
-rw-r--r--src/lib/libcrypto/comp/Makefile.ssl114
-rw-r--r--src/lib/libcrypto/comp/c_rle.c62
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c271
-rw-r--r--src/lib/libcrypto/comp/comp.h59
-rw-r--r--src/lib/libcrypto/comp/comp_err.c92
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c78
-rw-r--r--src/lib/libcrypto/conf/Makefile.ssl183
-rw-r--r--src/lib/libcrypto/conf/README78
-rw-r--r--src/lib/libcrypto/conf/conf.h250
-rw-r--r--src/lib/libcrypto/conf/conf_api.c308
-rw-r--r--src/lib/libcrypto/conf/conf_api.h89
-rw-r--r--src/lib/libcrypto/conf/conf_def.c745
-rw-r--r--src/lib/libcrypto/conf/conf_def.h180
-rw-r--r--src/lib/libcrypto/conf/conf_err.c126
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c401
-rw-r--r--src/lib/libcrypto/conf/conf_mall.c80
-rw-r--r--src/lib/libcrypto/conf/conf_mod.c616
-rw-r--r--src/lib/libcrypto/conf/conf_sap.c111
-rw-r--r--src/lib/libcrypto/conf/keysets.pl185
-rw-r--r--src/lib/libcrypto/conf/ssleay.cnf78
-rw-r--r--src/lib/libcrypto/cpt_err.c102
-rw-r--r--src/lib/libcrypto/cryptlib.c632
-rw-r--r--src/lib/libcrypto/cryptlib.h100
-rw-r--r--src/lib/libcrypto/crypto-lib.com23
-rw-r--r--src/lib/libcrypto/crypto.h521
-rw-r--r--src/lib/libcrypto/cversion.c120
-rw-r--r--src/lib/libcrypto/des/COPYRIGHT50
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl316
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl208
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl255
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl79
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c106
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c61
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c254
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c121
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c174
-rw-r--r--src/lib/libcrypto/des/des.h246
-rw-r--r--src/lib/libcrypto/des/des_enc.c417
-rw-r--r--src/lib/libcrypto/des/des_locl.h428
-rw-r--r--src/lib/libcrypto/des/des_old.h6
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c81
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c123
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c197
-rw-r--r--src/lib/libcrypto/des/enc_read.c228
-rw-r--r--src/lib/libcrypto/des/enc_writ.c171
-rw-r--r--src/lib/libcrypto/des/fcrypt.c173
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c145
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c148
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c125
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c110
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c135
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c123
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c139
-rw-r--r--src/lib/libcrypto/des/rand_key.c68
-rw-r--r--src/lib/libcrypto/des/set_key.c411
-rw-r--r--src/lib/libcrypto/des/spr.h204
-rw-r--r--src/lib/libcrypto/des/str2key.c173
-rw-r--r--src/lib/libcrypto/des/times/usparc.cc2
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c195
-rw-r--r--src/lib/libcrypto/dh/Makefile.ssl133
-rw-r--r--src/lib/libcrypto/dh/dh.h213
-rw-r--r--src/lib/libcrypto/dh/dh_asn1.c87
-rw-r--r--src/lib/libcrypto/dh/dh_check.c146
-rw-r--r--src/lib/libcrypto/dh/dh_err.c101
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c175
-rw-r--r--src/lib/libcrypto/dh/dh_key.c233
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c247
-rw-r--r--src/lib/libcrypto/dh/dhtest.c4
-rw-r--r--src/lib/libcrypto/doc/DH_generate_key.pod50
-rw-r--r--src/lib/libcrypto/doc/DH_generate_parameters.pod73
-rw-r--r--src/lib/libcrypto/doc/DH_get_ex_new_index.pod36
-rw-r--r--src/lib/libcrypto/doc/DH_new.pod40
-rw-r--r--src/lib/libcrypto/doc/DH_set_method.pod129
-rw-r--r--src/lib/libcrypto/doc/DH_size.pod33
-rw-r--r--src/lib/libcrypto/doc/DSA_SIG_new.pod40
-rw-r--r--src/lib/libcrypto/doc/DSA_do_sign.pod47
-rw-r--r--src/lib/libcrypto/doc/DSA_dup_DH.pod36
-rw-r--r--src/lib/libcrypto/doc/DSA_generate_key.pod34
-rw-r--r--src/lib/libcrypto/doc/DSA_generate_parameters.pod105
-rw-r--r--src/lib/libcrypto/doc/DSA_get_ex_new_index.pod36
-rw-r--r--src/lib/libcrypto/doc/DSA_new.pod42
-rw-r--r--src/lib/libcrypto/doc/DSA_set_method.pod143
-rw-r--r--src/lib/libcrypto/doc/DSA_sign.pod66
-rw-r--r--src/lib/libcrypto/doc/DSA_size.pod33
-rw-r--r--src/lib/libcrypto/doc/ERR_GET_LIB.pod51
-rw-r--r--src/lib/libcrypto/doc/ERR_clear_error.pod29
-rw-r--r--src/lib/libcrypto/doc/ERR_error_string.pod73
-rw-r--r--src/lib/libcrypto/doc/ERR_get_error.pod76
-rw-r--r--src/lib/libcrypto/doc/ERR_load_crypto_strings.pod46
-rw-r--r--src/lib/libcrypto/doc/ERR_load_strings.pod54
-rw-r--r--src/lib/libcrypto/doc/ERR_print_errors.pod51
-rw-r--r--src/lib/libcrypto/doc/ERR_put_error.pod44
-rw-r--r--src/lib/libcrypto/doc/ERR_remove_state.pod34
-rw-r--r--src/lib/libcrypto/doc/EVP_BytesToKey.pod67
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod256
-rw-r--r--src/lib/libcrypto/doc/EVP_EncryptInit.pod511
-rw-r--r--src/lib/libcrypto/doc/EVP_OpenInit.pod63
-rw-r--r--src/lib/libcrypto/doc/EVP_PKEY_new.pod47
-rw-r--r--src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod80
-rw-r--r--src/lib/libcrypto/doc/EVP_SealInit.pod85
-rw-r--r--src/lib/libcrypto/doc/EVP_SignInit.pod95
-rw-r--r--src/lib/libcrypto/doc/EVP_VerifyInit.pod86
-rw-r--r--src/lib/libcrypto/doc/OBJ_nid2obj.pod149
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod101
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_config.pod82
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod51
-rw-r--r--src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod66
-rw-r--r--src/lib/libcrypto/doc/PKCS12_create.pod57
-rw-r--r--src/lib/libcrypto/doc/PKCS12_parse.pod50
-rw-r--r--src/lib/libcrypto/doc/PKCS7_decrypt.pod53
-rw-r--r--src/lib/libcrypto/doc/PKCS7_encrypt.pod65
-rw-r--r--src/lib/libcrypto/doc/PKCS7_sign.pod85
-rw-r--r--src/lib/libcrypto/doc/PKCS7_verify.pod116
-rw-r--r--src/lib/libcrypto/doc/RAND_add.pod77
-rw-r--r--src/lib/libcrypto/doc/RAND_bytes.pod47
-rw-r--r--src/lib/libcrypto/doc/RAND_cleanup.pod29
-rw-r--r--src/lib/libcrypto/doc/RAND_load_file.pod53
-rw-r--r--src/lib/libcrypto/doc/RAND_set_rand_method.pod83
-rw-r--r--src/lib/libcrypto/doc/RSA_blinding_on.pod43
-rw-r--r--src/lib/libcrypto/doc/RSA_check_key.pod67
-rw-r--r--src/lib/libcrypto/doc/RSA_generate_key.pod69
-rw-r--r--src/lib/libcrypto/doc/RSA_get_ex_new_index.pod120
-rw-r--r--src/lib/libcrypto/doc/RSA_new.pod41
-rw-r--r--src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod124
-rw-r--r--src/lib/libcrypto/doc/RSA_print.pod49
-rw-r--r--src/lib/libcrypto/doc/RSA_private_encrypt.pod70
-rw-r--r--src/lib/libcrypto/doc/RSA_public_encrypt.pod84
-rw-r--r--src/lib/libcrypto/doc/RSA_set_method.pod202
-rw-r--r--src/lib/libcrypto/doc/RSA_sign.pod62
-rw-r--r--src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod59
-rw-r--r--src/lib/libcrypto/doc/RSA_size.pod33
-rw-r--r--src/lib/libcrypto/doc/SMIME_read_PKCS7.pod71
-rw-r--r--src/lib/libcrypto/doc/SMIME_write_PKCS7.pod59
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod72
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod114
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod106
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_print_ex.pod105
-rw-r--r--src/lib/libcrypto/doc/X509_new.pod37
-rw-r--r--src/lib/libcrypto/doc/bn.pod158
-rw-r--r--src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod29
-rw-r--r--src/lib/libcrypto/doc/d2i_DHparams.pod30
-rw-r--r--src/lib/libcrypto/doc/d2i_DSAPublicKey.pod83
-rw-r--r--src/lib/libcrypto/doc/d2i_RSAPublicKey.pod67
-rw-r--r--src/lib/libcrypto/doc/d2i_X509.pod231
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_ALGOR.pod30
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_CRL.pod37
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_NAME.pod31
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_REQ.pod36
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_SIG.pod30
-rw-r--r--src/lib/libcrypto/doc/dh.pod78
-rw-r--r--src/lib/libcrypto/doc/dsa.pod113
-rw-r--r--src/lib/libcrypto/doc/engine.pod621
-rw-r--r--src/lib/libcrypto/doc/evp.pod45
-rw-r--r--src/lib/libcrypto/doc/lh_stats.pod60
-rw-r--r--src/lib/libcrypto/doc/rsa.pod123
-rw-r--r--src/lib/libcrypto/dsa/Makefile.ssl171
-rw-r--r--src/lib/libcrypto/dsa/dsa.h254
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c140
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c108
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c305
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c107
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c308
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c350
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c104
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c102
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c9
-rw-r--r--src/lib/libcrypto/dso/Makefile.ssl142
-rw-r--r--src/lib/libcrypto/dso/dso.h322
-rw-r--r--src/lib/libcrypto/dso/dso_dl.c35
-rw-r--r--src/lib/libcrypto/dso/dso_dlfcn.c293
-rw-r--r--src/lib/libcrypto/dso/dso_err.c135
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c439
-rw-r--r--src/lib/libcrypto/dso/dso_null.c86
-rw-r--r--src/lib/libcrypto/dso/dso_openssl.c81
-rw-r--r--src/lib/libcrypto/dso/dso_win32.c21
-rw-r--r--src/lib/libcrypto/ec/Makefile.ssl128
-rw-r--r--src/lib/libcrypto/ec/ec.h243
-rw-r--r--src/lib/libcrypto/ec/ec_cvt.c80
-rw-r--r--src/lib/libcrypto/ec/ec_err.c149
-rw-r--r--src/lib/libcrypto/ec/ec_lcl.h277
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c656
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c485
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c304
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c134
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c1717
-rw-r--r--src/lib/libcrypto/ec/ectest.c2
-rw-r--r--src/lib/libcrypto/engine/Makefile.ssl538
-rw-r--r--src/lib/libcrypto/engine/README211
-rw-r--r--src/lib/libcrypto/engine/eng_all.c113
-rw-r--r--src/lib/libcrypto/engine/eng_cnf.c242
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c391
-rw-r--r--src/lib/libcrypto/engine/eng_dyn.c460
-rw-r--r--src/lib/libcrypto/engine/eng_err.c166
-rw-r--r--src/lib/libcrypto/engine/eng_fat.c147
-rw-r--r--src/lib/libcrypto/engine/eng_init.c157
-rw-r--r--src/lib/libcrypto/engine/eng_int.h185
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c321
-rw-r--r--src/lib/libcrypto/engine/eng_list.c394
-rw-r--r--src/lib/libcrypto/engine/eng_openssl.c361
-rw-r--r--src/lib/libcrypto/engine/eng_pkey.c157
-rw-r--r--src/lib/libcrypto/engine/eng_table.c361
-rw-r--r--src/lib/libcrypto/engine/engine.h729
-rw-r--r--src/lib/libcrypto/engine/hw_aep.c1
-rw-r--r--src/lib/libcrypto/engine/hw_atalla.c1
-rw-r--r--src/lib/libcrypto/engine/hw_cryptodev.c343
-rw-r--r--src/lib/libcrypto/engine/hw_cswift.c204
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec.c1
-rw-r--r--src/lib/libcrypto/engine/tb_cipher.c145
-rw-r--r--src/lib/libcrypto/engine/tb_dh.c120
-rw-r--r--src/lib/libcrypto/engine/tb_digest.c145
-rw-r--r--src/lib/libcrypto/engine/tb_dsa.c120
-rw-r--r--src/lib/libcrypto/engine/tb_rand.c120
-rw-r--r--src/lib/libcrypto/engine/tb_rsa.c120
-rw-r--r--src/lib/libcrypto/err/Makefile.ssl119
-rw-r--r--src/lib/libcrypto/err/err.c1077
-rw-r--r--src/lib/libcrypto/err/err.h302
-rw-r--r--src/lib/libcrypto/err/err_all.c137
-rw-r--r--src/lib/libcrypto/err/err_prn.c106
-rw-r--r--src/lib/libcrypto/err/openssl.ec82
-rw-r--r--src/lib/libcrypto/evp/Makefile.ssl1059
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c567
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c426
-rw-r--r--src/lib/libcrypto/evp/bio_md.c264
-rw-r--r--src/lib/libcrypto/evp/c_all.c84
-rw-r--r--src/lib/libcrypto/evp/c_alld.c10
-rw-r--r--src/lib/libcrypto/evp/digest.c379
-rw-r--r--src/lib/libcrypto/evp/e_acss.c85
-rw-r--r--src/lib/libcrypto/evp/e_aes.c118
-rw-r--r--src/lib/libcrypto/evp/e_bf.c88
-rw-r--r--src/lib/libcrypto/evp/e_cast.c90
-rw-r--r--src/lib/libcrypto/evp/e_des.c154
-rw-r--r--src/lib/libcrypto/evp/e_des3.c232
-rw-r--r--src/lib/libcrypto/evp/e_idea.c118
-rw-r--r--src/lib/libcrypto/evp/e_null.c101
-rw-r--r--src/lib/libcrypto/evp/e_old.c108
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c230
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c134
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c122
-rw-r--r--src/lib/libcrypto/evp/encode.c446
-rw-r--r--src/lib/libcrypto/evp/evp.h900
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c592
-rw-r--r--src/lib/libcrypto/evp/evp_err.c167
-rw-r--r--src/lib/libcrypto/evp/evp_key.c174
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c168
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h252
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c136
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c468
-rw-r--r--src/lib/libcrypto/evp/m_dss.c95
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c95
-rw-r--r--src/lib/libcrypto/evp/m_md4.c97
-rw-r--r--src/lib/libcrypto/evp/m_md5.c97
-rw-r--r--src/lib/libcrypto/evp/m_null.c95
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c96
-rw-r--r--src/lib/libcrypto/evp/m_sha.c3
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c95
-rw-r--r--src/lib/libcrypto/evp/names.c126
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c153
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c251
-rw-r--r--src/lib/libcrypto/evp/p_dec.c87
-rw-r--r--src/lib/libcrypto/evp/p_enc.c86
-rw-r--r--src/lib/libcrypto/evp/p_lib.c337
-rw-r--r--src/lib/libcrypto/evp/p_open.c123
-rw-r--r--src/lib/libcrypto/evp/p_seal.c115
-rw-r--r--src/lib/libcrypto/evp/p_sign.c114
-rw-r--r--src/lib/libcrypto/evp/p_verify.c101
-rw-r--r--src/lib/libcrypto/ex_data.c636
-rw-r--r--src/lib/libcrypto/hmac/Makefile.ssl101
-rw-r--r--src/lib/libcrypto/hmac/hmac.c189
-rw-r--r--src/lib/libcrypto/hmac/hmac.h107
-rw-r--r--src/lib/libcrypto/idea/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/idea/idea.h103
-rw-r--r--src/lib/libcrypto/krb5/Makefile.ssl90
-rw-r--r--src/lib/libcrypto/krb5/krb5_asn.c167
-rw-r--r--src/lib/libcrypto/krb5/krb5_asn.h256
-rw-r--r--src/lib/libcrypto/lhash/Makefile.ssl93
-rw-r--r--src/lib/libcrypto/lhash/lh_stats.c248
-rw-r--r--src/lib/libcrypto/lhash/lhash.c470
-rw-r--r--src/lib/libcrypto/lhash/lhash.h199
-rw-r--r--src/lib/libcrypto/md2/Makefile.ssl93
-rw-r--r--src/lib/libcrypto/md2/md2_one.c3
-rw-r--r--src/lib/libcrypto/md32_common.h649
-rw-r--r--src/lib/libcrypto/md4/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/md4/md4.h119
-rw-r--r--src/lib/libcrypto/md4/md4_dgst.c258
-rw-r--r--src/lib/libcrypto/md4/md4_locl.h154
-rw-r--r--src/lib/libcrypto/md4/md4_one.c96
-rw-r--r--src/lib/libcrypto/md5/Makefile.ssl127
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl306
-rw-r--r--src/lib/libcrypto/md5/md5.h119
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c292
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h172
-rw-r--r--src/lib/libcrypto/md5/md5_one.c96
-rw-r--r--src/lib/libcrypto/mdc2/Makefile2
-rw-r--r--src/lib/libcrypto/mdc2/Makefile.ssl98
-rw-r--r--src/lib/libcrypto/mem_clr.c75
-rw-r--r--src/lib/libcrypto/mem_dbg.c787
-rw-r--r--src/lib/libcrypto/o_str.c96
-rw-r--r--src/lib/libcrypto/o_time.c217
-rw-r--r--src/lib/libcrypto/o_time.h66
-rw-r--r--src/lib/libcrypto/objects/Makefile.ssl123
-rw-r--r--src/lib/libcrypto/objects/o_names.c369
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c668
-rw-r--r--src/lib/libcrypto/objects/obj_dat.h3762
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl307
-rw-r--r--src/lib/libcrypto/objects/obj_err.c101
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c127
-rw-r--r--src/lib/libcrypto/objects/obj_mac.h2987
-rw-r--r--src/lib/libcrypto/objects/obj_mac.num667
-rw-r--r--src/lib/libcrypto/objects/objects.README44
-rw-r--r--src/lib/libcrypto/objects/objects.h1044
-rw-r--r--src/lib/libcrypto/objects/objects.pl230
-rw-r--r--src/lib/libcrypto/objects/objects.txt938
-rw-r--r--src/lib/libcrypto/ocsp/Makefile.ssl293
-rw-r--r--src/lib/libcrypto/ocsp/ocsp.h619
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_asn.c182
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_cl.c370
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_err.c139
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ext.c538
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ht.c173
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_lib.c262
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_prn.c291
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_srv.c264
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_vfy.c444
-rw-r--r--src/lib/libcrypto/opensslconf.h180
-rw-r--r--src/lib/libcrypto/opensslv.h89
-rw-r--r--src/lib/libcrypto/ossl_typ.h122
-rw-r--r--src/lib/libcrypto/pem/Makefile.ssl336
-rw-r--r--src/lib/libcrypto/pem/message16
-rw-r--r--src/lib/libcrypto/pem/pem.h672
-rw-r--r--src/lib/libcrypto/pem/pem2.h70
-rw-r--r--src/lib/libcrypto/pem/pem_all.c315
-rw-r--r--src/lib/libcrypto/pem/pem_err.c131
-rw-r--r--src/lib/libcrypto/pem/pem_info.c365
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c776
-rw-r--r--src/lib/libcrypto/pem/pem_oth.c85
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c243
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c145
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c187
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c102
-rw-r--r--src/lib/libcrypto/pem/pem_x509.c69
-rw-r--r--src/lib/libcrypto/pem/pem_xaux.c68
-rw-r--r--src/lib/libcrypto/pem/pkcs7.lis22
-rw-r--r--src/lib/libcrypto/perlasm/cbc.pl349
-rw-r--r--src/lib/libcrypto/perlasm/readme124
-rw-r--r--src/lib/libcrypto/perlasm/x86asm.pl135
-rw-r--r--src/lib/libcrypto/perlasm/x86nasm.pl10
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl45
-rw-r--r--src/lib/libcrypto/pkcs12/Makefile.ssl417
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c215
-rw-r--r--src/lib/libcrypto/pkcs12/p12_asn.c125
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c145
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c124
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crt.c164
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c176
-rw-r--r--src/lib/libcrypto/pkcs12/p12_init.c92
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c206
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c297
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c176
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c217
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8d.c68
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8e.c97
-rw-r--r--src/lib/libcrypto/pkcs12/p12_utl.c146
-rw-r--r--src/lib/libcrypto/pkcs12/pk12err.c139
-rw-r--r--src/lib/libcrypto/pkcs12/pkcs12.h320
-rw-r--r--src/lib/libcrypto/pkcs7/Makefile.ssl243
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_asn1.c213
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c140
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c1013
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c500
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_mime.c714
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c471
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h451
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c160
-rw-r--r--src/lib/libcrypto/rand/Makefile.ssl196
-rw-r--r--src/lib/libcrypto/rand/rand.h143
-rw-r--r--src/lib/libcrypto/rand/rand_err.c101
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c188
-rw-r--r--src/lib/libcrypto/rand/randfile.c285
-rw-r--r--src/lib/libcrypto/rc2/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/rc2/rc2.h104
-rw-r--r--src/lib/libcrypto/rc2/rc2_cbc.c226
-rw-r--r--src/lib/libcrypto/rc2/rc2_ecb.c88
-rw-r--r--src/lib/libcrypto/rc2/rc2_locl.h156
-rw-r--r--src/lib/libcrypto/rc2/rc2_skey.c151
-rw-r--r--src/lib/libcrypto/rc2/rc2cfb64.c122
-rw-r--r--src/lib/libcrypto/rc2/rc2ofb64.c111
-rw-r--r--src/lib/libcrypto/rc2/rc2speed.c6
-rw-r--r--src/lib/libcrypto/rc2/rrc2.doc219
-rw-r--r--src/lib/libcrypto/rc2/version22
-rw-r--r--src/lib/libcrypto/rc4/Makefile.ssl110
-rw-r--r--src/lib/libcrypto/rc4/asm/rc4-586.pl229
-rwxr-xr-xsrc/lib/libcrypto/rc4/asm/rc4-amd64.pl227
-rw-r--r--src/lib/libcrypto/rc4/rc4.h95
-rw-r--r--src/lib/libcrypto/rc4/rc4_enc.c319
-rw-r--r--src/lib/libcrypto/rc4/rc4_locl.h5
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c123
-rw-r--r--src/lib/libcrypto/rc5/Makefile.ssl108
-rw-r--r--src/lib/libcrypto/ripemd/Makefile.ssl108
-rw-r--r--src/lib/libcrypto/ripemd/README15
-rw-r--r--src/lib/libcrypto/ripemd/asm/rmd-586.pl590
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h106
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c495
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h160
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c77
-rw-r--r--src/lib/libcrypto/ripemd/rmdconst.h399
-rw-r--r--src/lib/libcrypto/rsa/Makefile.ssl241
-rw-r--r--src/lib/libcrypto/rsa/rsa.h366
-rw-r--r--src/lib/libcrypto/rsa/rsa_asn1.c121
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c184
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c727
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c149
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c200
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c414
-rw-r--r--src/lib/libcrypto/rsa/rsa_none.c98
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c206
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c224
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c149
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c232
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c154
-rw-r--r--src/lib/libcrypto/rsa/rsa_test.c5
-rw-r--r--src/lib/libcrypto/sha/Makefile.ssl116
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl425
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-ia64.pl549
-rw-r--r--src/lib/libcrypto/sha/sha.h128
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c77
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c81
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h481
-rw-r--r--src/lib/libcrypto/sha/sha_one.c3
-rw-r--r--src/lib/libcrypto/stack/Makefile.ssl88
-rw-r--r--src/lib/libcrypto/stack/safestack.h1571
-rw-r--r--src/lib/libcrypto/stack/stack.c340
-rw-r--r--src/lib/libcrypto/stack/stack.h108
-rw-r--r--src/lib/libcrypto/txt_db/Makefile.ssl88
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c383
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.h108
-rw-r--r--src/lib/libcrypto/ui/Makefile.ssl117
-rw-r--r--src/lib/libcrypto/ui/ui.h387
-rw-r--r--src/lib/libcrypto/ui/ui_compat.h83
-rw-r--r--src/lib/libcrypto/ui/ui_err.c111
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c902
-rw-r--r--src/lib/libcrypto/ui/ui_locl.h148
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c673
-rw-r--r--src/lib/libcrypto/ui/ui_util.c91
-rw-r--r--src/lib/libcrypto/util/libeay.num42
-rw-r--r--src/lib/libcrypto/util/mk1mf.pl337
-rw-r--r--src/lib/libcrypto/util/mkdef.pl11
-rw-r--r--src/lib/libcrypto/util/mkerr.pl630
-rw-r--r--src/lib/libcrypto/util/mkfiles.pl17
-rw-r--r--src/lib/libcrypto/util/mklink.pl7
-rw-r--r--src/lib/libcrypto/util/mkstack.pl125
-rw-r--r--src/lib/libcrypto/util/pl/BC-32.pl14
-rw-r--r--src/lib/libcrypto/util/pl/OS2-EMX.pl1
-rw-r--r--src/lib/libcrypto/util/pl/VC-32.pl99
-rw-r--r--src/lib/libcrypto/util/pod2man.pl1
-rw-r--r--src/lib/libcrypto/util/selftest.pl26
-rw-r--r--src/lib/libcrypto/x509/Makefile.ssl594
-rw-r--r--src/lib/libcrypto/x509/by_dir.c381
-rw-r--r--src/lib/libcrypto/x509/by_file.c300
-rw-r--r--src/lib/libcrypto/x509/x509.h1259
-rw-r--r--src/lib/libcrypto/x509/x509_att.c326
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c440
-rw-r--r--src/lib/libcrypto/x509/x509_d2.c107
-rw-r--r--src/lib/libcrypto/x509/x509_def.c81
-rw-r--r--src/lib/libcrypto/x509/x509_err.c156
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c210
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c557
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c226
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c112
-rw-r--r--src/lib/libcrypto/x509/x509_req.c279
-rw-r--r--src/lib/libcrypto/x509/x509_set.c150
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c287
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c165
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c268
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c1333
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h422
-rw-r--r--src/lib/libcrypto/x509/x509cset.c170
-rw-r--r--src/lib/libcrypto/x509/x509name.c383
-rw-r--r--src/lib/libcrypto/x509/x509rset.c83
-rw-r--r--src/lib/libcrypto/x509/x509spki.c120
-rw-r--r--src/lib/libcrypto/x509/x509type.c115
-rw-r--r--src/lib/libcrypto/x509/x_all.c489
-rw-r--r--src/lib/libcrypto/x509v3/Makefile.ssl603
-rw-r--r--src/lib/libcrypto/x509v3/ext_dat.h118
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c190
-rw-r--r--src/lib/libcrypto/x509v3/v3_akeya.c72
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c458
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c124
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c147
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c485
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c422
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c162
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c94
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c142
-rw-r--r--src/lib/libcrypto/x509v3/v3_genn.c101
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c116
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c194
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c76
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c302
-rw-r--r--src/lib/libcrypto/x509v3/v3_ocsp.c275
-rw-r--r--src/lib/libcrypto/x509v3/v3_pci.c313
-rw-r--r--src/lib/libcrypto/x509v3/v3_pcia.c55
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c108
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c233
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c647
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c144
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c262
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c535
-rw-r--r--src/lib/libcrypto/x509v3/v3err.c193
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h687
700 files changed, 162971 insertions, 7821 deletions
diff --git a/src/lib/libcrypto/Attic/Makefile b/src/lib/libcrypto/Makefile.ssl
index cda9de0ac9..b9951a4600 100644
--- a/src/lib/libcrypto/Attic/Makefile
+++ b/src/lib/libcrypto/Makefile.ssl
@@ -1,5 +1,5 @@
1# 1#
2# OpenSSL/crypto/Makefile 2# SSLeay/crypto/Makefile
3# 3#
4 4
5DIR= crypto 5DIR= crypto
@@ -11,9 +11,10 @@ CFLAG= -g
11INSTALL_PREFIX= 11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl 12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP= /usr/local/ssl 13INSTALLTOP= /usr/local/ssl
14MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend 15MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) 16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile 17MAKEFILE= Makefile.ssl
17RM= rm -f 18RM= rm -f
18AR= ar r 19AR= ar r
19 20
@@ -35,14 +36,14 @@ GENERAL=Makefile README crypto-lib.com install.com
35 36
36LIB= $(TOP)/libcrypto.a 37LIB= $(TOP)/libcrypto.a
37SHARED_LIB= libcrypto$(SHLIB_EXT) 38SHARED_LIB= libcrypto$(SHLIB_EXT)
38LIBSRC= 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 o_str.c 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
39LIBOBJ= 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 o_str.o 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
40 41
41SRC= $(LIBSRC) 42SRC= $(LIBSRC)
42 43
43EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h symhacks.h \ 44EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h symhacks.h \
44 ossl_typ.h 45 ossl_typ.h
45HEADER= cryptlib.h buildinf.h md32_common.h o_time.h o_str.h $(EXHEADER) 46HEADER= cryptlib.h buildinf.h md32_common.h o_time.h $(EXHEADER)
46 47
47ALL= $(GENERAL) $(SRC) $(HEADER) 48ALL= $(GENERAL) $(SRC) $(HEADER)
48 49
@@ -51,9 +52,9 @@ top:
51 52
52all: shared 53all: shared
53 54
54buildinf.h: ../Makefile 55buildinf.h: ../Makefile.ssl
55 ( echo "#ifndef MK1MF_BUILD"; \ 56 ( echo "#ifndef MK1MF_BUILD"; \
56 echo ' /* auto-generated by crypto/Makefile for crypto/cversion.c */'; \ 57 echo ' /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c */'; \
57 echo ' #define CFLAGS "$(CC) $(CFLAG)"'; \ 58 echo ' #define CFLAGS "$(CC) $(CFLAG)"'; \
58 echo ' #define PLATFORM "$(PLATFORM)"'; \ 59 echo ' #define PLATFORM "$(PLATFORM)"'; \
59 echo " #define DATE \"`LC_ALL=C LC_TIME=C date`\""; \ 60 echo " #define DATE \"`LC_ALL=C LC_TIME=C date`\""; \
@@ -72,7 +73,7 @@ subdirs:
72 done; 73 done;
73 74
74files: 75files:
75 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO 76 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
76 @for i in $(SDIRS) ;\ 77 @for i in $(SDIRS) ;\
77 do \ 78 do \
78 (cd $$i && echo "making 'files' in crypto/$$i..." && \ 79 (cd $$i && echo "making 'files' in crypto/$$i..." && \
@@ -80,9 +81,11 @@ files:
80 done; 81 done;
81 82
82links: 83links:
84 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
83 @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER) 85 @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
84 @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST) 86 @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
85 @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS) 87 @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS)
88 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
86 @for i in $(SDIRS); do \ 89 @for i in $(SDIRS); do \
87 (cd $$i && echo "making links in crypto/$$i..." && \ 90 (cd $$i && echo "making links in crypto/$$i..." && \
88 $(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 ); \ 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 ); \
@@ -94,8 +97,7 @@ lib: $(LIBOBJ)
94 @touch lib 97 @touch lib
95 98
96shared: buildinf.h lib subdirs 99shared: buildinf.h lib subdirs
97 @if [ -n "$(SHARED_LIBS)" ]; then \ 100 if [ -n "$(SHARED_LIBS)" ]; then \
98 egrep 'define OPENSSL_FIPS' $(TOP)/include/openssl/opensslconf.h > /dev/null || \
99 (cd ..; $(MAKE) $(SHARED_LIB)); \ 101 (cd ..; $(MAKE) $(SHARED_LIB)); \
100 fi 102 fi
101 103
@@ -114,7 +116,7 @@ tests:
114 done; 116 done;
115 117
116install: 118install:
117 @headerlist="$(EXHEADER)"; for i in $$headerlist ;\ 119 @for i in $(EXHEADER) ;\
118 do \ 120 do \
119 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ 121 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
120 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ 122 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
@@ -201,8 +203,6 @@ mem_dbg.o: ../include/openssl/err.h ../include/openssl/lhash.h
201mem_dbg.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 203mem_dbg.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
202mem_dbg.o: ../include/openssl/safestack.h ../include/openssl/stack.h 204mem_dbg.o: ../include/openssl/safestack.h ../include/openssl/stack.h
203mem_dbg.o: ../include/openssl/symhacks.h cryptlib.h mem_dbg.c 205mem_dbg.o: ../include/openssl/symhacks.h cryptlib.h mem_dbg.c
204o_str.o: ../e_os.h ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
205o_str.o: o_str.c o_str.h
206o_time.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h o_time.c 206o_time.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h o_time.c
207o_time.o: o_time.h 207o_time.o: o_time.h
208tmdiff.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h 208tmdiff.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
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.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/README b/src/lib/libcrypto/aes/README
new file mode 100644
index 0000000000..0f9620a80e
--- /dev/null
+++ b/src/lib/libcrypto/aes/README
@@ -0,0 +1,3 @@
1This is an OpenSSL-compatible version of AES (also called Rijndael).
2aes_core.c is basically the same as rijndael-alg-fst.c but with an
3API that looks like the rest of the OpenSSL symmetric cipher suite.
diff --git a/src/lib/libcrypto/aes/aes.h b/src/lib/libcrypto/aes/aes.h
new file mode 100644
index 0000000000..8a3ea0b883
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes.h
@@ -0,0 +1,127 @@
1/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef HEADER_AES_H
53#define HEADER_AES_H
54
55#include <openssl/e_os2.h>
56
57#ifdef OPENSSL_NO_AES
58#error AES is disabled.
59#endif
60
61#define AES_ENCRYPT 1
62#define AES_DECRYPT 0
63
64/* Because array size can't be a const in C, the following two are macros.
65 Both sizes are in bytes. */
66#define AES_MAXNR 14
67#define AES_BLOCK_SIZE 16
68
69#if defined(OPENSSL_FIPS)
70#define FIPS_AES_SIZE_T int
71#endif
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77/* This should be a hidden type, but EVP requires that the size be known */
78struct aes_key_st {
79 unsigned long rd_key[4 *(AES_MAXNR + 1)];
80 int rounds;
81};
82typedef struct aes_key_st AES_KEY;
83
84const char *AES_options(void);
85
86int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
87 AES_KEY *key);
88int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
89 AES_KEY *key);
90
91void AES_encrypt(const unsigned char *in, unsigned char *out,
92 const AES_KEY *key);
93void AES_decrypt(const unsigned char *in, unsigned char *out,
94 const AES_KEY *key);
95
96void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
97 const AES_KEY *key, const int enc);
98void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
99 const unsigned long length, const AES_KEY *key,
100 unsigned char *ivec, const int enc);
101void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
102 const unsigned long length, const AES_KEY *key,
103 unsigned char *ivec, int *num, const int enc);
104void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
105 const unsigned long length, const AES_KEY *key,
106 unsigned char *ivec, int *num, const int enc);
107void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
108 const unsigned long length, const AES_KEY *key,
109 unsigned char *ivec, int *num, const int enc);
110void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
111 const int nbits,const AES_KEY *key,
112 unsigned char *ivec,const int enc);
113void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
114 const unsigned long length, const AES_KEY *key,
115 unsigned char *ivec, int *num);
116void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
117 const unsigned long length, const AES_KEY *key,
118 unsigned char ivec[AES_BLOCK_SIZE],
119 unsigned char ecount_buf[AES_BLOCK_SIZE],
120 unsigned int *num);
121
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif /* !HEADER_AES_H */
diff --git a/src/lib/libcrypto/aes/aes_cbc.c b/src/lib/libcrypto/aes/aes_cbc.c
new file mode 100644
index 0000000000..d2ba6bcdb4
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_cbc.c
@@ -0,0 +1,131 @@
1/* crypto/aes/aes_cbc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef AES_DEBUG
53# ifndef NDEBUG
54# define NDEBUG
55# endif
56#endif
57#include <assert.h>
58
59#include <openssl/aes.h>
60#include "aes_locl.h"
61
62void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
63 const unsigned long length, const AES_KEY *key,
64 unsigned char *ivec, const int enc) {
65
66 unsigned long n;
67 unsigned long len = length;
68 unsigned char tmp[AES_BLOCK_SIZE];
69 const unsigned char *iv = ivec;
70
71 assert(in && out && key && ivec);
72 assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
73
74 if (AES_ENCRYPT == enc) {
75 while (len >= AES_BLOCK_SIZE) {
76 for(n=0; n < AES_BLOCK_SIZE; ++n)
77 out[n] = in[n] ^ iv[n];
78 AES_encrypt(out, out, key);
79 iv = out;
80 len -= AES_BLOCK_SIZE;
81 in += AES_BLOCK_SIZE;
82 out += AES_BLOCK_SIZE;
83 }
84 if (len) {
85 for(n=0; n < len; ++n)
86 out[n] = in[n] ^ iv[n];
87 for(n=len; n < AES_BLOCK_SIZE; ++n)
88 out[n] = iv[n];
89 AES_encrypt(out, out, key);
90 iv = out;
91 }
92 memcpy(ivec,iv,AES_BLOCK_SIZE);
93 } else if (in != out) {
94 while (len >= AES_BLOCK_SIZE) {
95 AES_decrypt(in, out, key);
96 for(n=0; n < AES_BLOCK_SIZE; ++n)
97 out[n] ^= iv[n];
98 iv = in;
99 len -= AES_BLOCK_SIZE;
100 in += AES_BLOCK_SIZE;
101 out += AES_BLOCK_SIZE;
102 }
103 if (len) {
104 AES_decrypt(in,tmp,key);
105 for(n=0; n < len; ++n)
106 out[n] = tmp[n] ^ iv[n];
107 iv = in;
108 }
109 memcpy(ivec,iv,AES_BLOCK_SIZE);
110 } else {
111 while (len >= AES_BLOCK_SIZE) {
112 memcpy(tmp, in, AES_BLOCK_SIZE);
113 AES_decrypt(in, out, key);
114 for(n=0; n < AES_BLOCK_SIZE; ++n)
115 out[n] ^= ivec[n];
116 memcpy(ivec, tmp, AES_BLOCK_SIZE);
117 len -= AES_BLOCK_SIZE;
118 in += AES_BLOCK_SIZE;
119 out += AES_BLOCK_SIZE;
120 }
121 if (len) {
122 memcpy(tmp, in, AES_BLOCK_SIZE);
123 AES_decrypt(tmp, out, key);
124 for(n=0; n < len; ++n)
125 out[n] ^= ivec[n];
126 for(n=len; n < AES_BLOCK_SIZE; ++n)
127 out[n] = tmp[n];
128 memcpy(ivec, tmp, AES_BLOCK_SIZE);
129 }
130 }
131}
diff --git a/src/lib/libcrypto/aes/aes_cfb.c b/src/lib/libcrypto/aes/aes_cfb.c
new file mode 100644
index 0000000000..49f0411010
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_cfb.c
@@ -0,0 +1,225 @@
1/* crypto/aes/aes_cfb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#ifndef AES_DEBUG
109# ifndef NDEBUG
110# define NDEBUG
111# endif
112#endif
113#include <assert.h>
114
115#include <openssl/aes.h>
116#include "aes_locl.h"
117#include "e_os.h"
118
119/* The input and output encrypted as though 128bit cfb mode is being
120 * used. The extra state information to record how much of the
121 * 128bit block we have used is contained in *num;
122 */
123
124void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
125 const unsigned long length, const AES_KEY *key,
126 unsigned char *ivec, int *num, const int enc) {
127
128 unsigned int n;
129 unsigned long l = length;
130 unsigned char c;
131
132 assert(in && out && key && ivec && num);
133
134 n = *num;
135
136 if (enc) {
137 while (l--) {
138 if (n == 0) {
139 AES_encrypt(ivec, ivec, key);
140 }
141 ivec[n] = *(out++) = *(in++) ^ ivec[n];
142 n = (n+1) % AES_BLOCK_SIZE;
143 }
144 } else {
145 while (l--) {
146 if (n == 0) {
147 AES_encrypt(ivec, ivec, key);
148 }
149 c = *(in);
150 *(out++) = *(in++) ^ ivec[n];
151 ivec[n] = c;
152 n = (n+1) % AES_BLOCK_SIZE;
153 }
154 }
155
156 *num=n;
157}
158
159/* This expects a single block of size nbits for both in and out. Note that
160 it corrupts any extra bits in the last byte of out */
161void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
162 const int nbits,const AES_KEY *key,
163 unsigned char *ivec,const int enc)
164 {
165 int n,rem,num;
166 unsigned char ovec[AES_BLOCK_SIZE*2];
167
168 if (nbits<=0 || nbits>128) return;
169
170 /* fill in the first half of the new IV with the current IV */
171 memcpy(ovec,ivec,AES_BLOCK_SIZE);
172 /* construct the new IV */
173 AES_encrypt(ivec,ivec,key);
174 num = (nbits+7)/8;
175 if (enc) /* encrypt the input */
176 for(n=0 ; n < num ; ++n)
177 out[n] = (ovec[AES_BLOCK_SIZE+n] = in[n] ^ ivec[n]);
178 else /* decrypt the input */
179 for(n=0 ; n < num ; ++n)
180 out[n] = (ovec[AES_BLOCK_SIZE+n] = in[n]) ^ ivec[n];
181 /* shift ovec left... */
182 rem = nbits%8;
183 num = nbits/8;
184 if(rem==0)
185 memcpy(ivec,ovec+num,AES_BLOCK_SIZE);
186 else
187 for(n=0 ; n < AES_BLOCK_SIZE ; ++n)
188 ivec[n] = ovec[n+num]<<rem | ovec[n+num+1]>>(8-rem);
189
190 /* it is not necessary to cleanse ovec, since the IV is not secret */
191 }
192
193/* N.B. This expects the input to be packed, MS bit first */
194void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
195 const unsigned long length, const AES_KEY *key,
196 unsigned char *ivec, int *num, const int enc)
197 {
198 unsigned int n;
199 unsigned char c[1],d[1];
200
201 assert(in && out && key && ivec && num);
202 assert(*num == 0);
203
204 memset(out,0,(length+7)/8);
205 for(n=0 ; n < length ; ++n)
206 {
207 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
208 AES_cfbr_encrypt_block(c,d,1,key,ivec,enc);
209 out[n/8]=(out[n/8]&~(1 << (7-n%8)))|((d[0]&0x80) >> (n%8));
210 }
211 }
212
213void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
214 const unsigned long length, const AES_KEY *key,
215 unsigned char *ivec, int *num, const int enc)
216 {
217 unsigned int n;
218
219 assert(in && out && key && ivec && num);
220 assert(*num == 0);
221
222 for(n=0 ; n < length ; ++n)
223 AES_cfbr_encrypt_block(&in[n],&out[n],8,key,ivec,enc);
224 }
225
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c
new file mode 100644
index 0000000000..ed566a8123
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_core.c
@@ -0,0 +1,1261 @@
1/* crypto/aes/aes_core.c -*- mode:C; c-file-style: "eay" -*- */
2/**
3 * rijndael-alg-fst.c
4 *
5 * @version 3.0 (December 2000)
6 *
7 * Optimised ANSI C code for the Rijndael cipher (now AES)
8 *
9 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
10 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
11 * @author Paulo Barreto <paulo.barreto@terra.com.br>
12 *
13 * This code is hereby placed in the public domain.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Note: rewritten a little bit to provide error control and an OpenSSL-
29 compatible API */
30
31#ifndef AES_DEBUG
32# ifndef NDEBUG
33# define NDEBUG
34# endif
35#endif
36#include <assert.h>
37
38#include <stdlib.h>
39#include <openssl/aes.h>
40#include <openssl/fips.h>
41#include "aes_locl.h"
42
43#ifndef OPENSSL_FIPS
44
45/*
46Te0[x] = S [x].[02, 01, 01, 03];
47Te1[x] = S [x].[03, 02, 01, 01];
48Te2[x] = S [x].[01, 03, 02, 01];
49Te3[x] = S [x].[01, 01, 03, 02];
50Te4[x] = S [x].[01, 01, 01, 01];
51
52Td0[x] = Si[x].[0e, 09, 0d, 0b];
53Td1[x] = Si[x].[0b, 0e, 09, 0d];
54Td2[x] = Si[x].[0d, 0b, 0e, 09];
55Td3[x] = Si[x].[09, 0d, 0b, 0e];
56Td4[x] = Si[x].[01, 01, 01, 01];
57*/
58
59static const u32 Te0[256] = {
60 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
61 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
62 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
63 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
64 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
65 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
66 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
67 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
68 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
69 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
70 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
71 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
72 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
73 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
74 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
75 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
76 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
77 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
78 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
79 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
80 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
81 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
82 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
83 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
84 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
85 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
86 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
87 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
88 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
89 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
90 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
91 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
92 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
93 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
94 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
95 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
96 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
97 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
98 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
99 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
100 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
101 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
102 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
103 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
104 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
105 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
106 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
107 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
108 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
109 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
110 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
111 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
112 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
113 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
114 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
115 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
116 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
117 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
118 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
119 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
120 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
121 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
122 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
123 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
124};
125static const u32 Te1[256] = {
126 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
127 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
128 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
129 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
130 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
131 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
132 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
133 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
134 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
135 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
136 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
137 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
138 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
139 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
140 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
141 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
142 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
143 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
144 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
145 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
146 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
147 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
148 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
149 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
150 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
151 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
152 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
153 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
154 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
155 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
156 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
157 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
158 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
159 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
160 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
161 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
162 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
163 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
164 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
165 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
166 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
167 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
168 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
169 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
170 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
171 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
172 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
173 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
174 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
175 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
176 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
177 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
178 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
179 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
180 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
181 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
182 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
183 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
184 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
185 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
186 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
187 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
188 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
189 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
190};
191static const u32 Te2[256] = {
192 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
193 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
194 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
195 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
196 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
197 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
198 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
199 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
200 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
201 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
202 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
203 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
204 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
205 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
206 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
207 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
208 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
209 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
210 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
211 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
212 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
213 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
214 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
215 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
216 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
217 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
218 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
219 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
220 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
221 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
222 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
223 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
224 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
225 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
226 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
227 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
228 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
229 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
230 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
231 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
232 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
233 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
234 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
235 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
236 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
237 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
238 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
239 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
240 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
241 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
242 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
243 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
244 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
245 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
246 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
247 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
248 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
249 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
250 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
251 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
252 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
253 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
254 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
255 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
256};
257static const u32 Te3[256] = {
258
259 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
260 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
261 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
262 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
263 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
264 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
265 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
266 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
267 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
268 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
269 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
270 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
271 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
272 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
273 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
274 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
275 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
276 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
277 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
278 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
279 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
280 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
281 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
282 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
283 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
284 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
285 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
286 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
287 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
288 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
289 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
290 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
291 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
292 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
293 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
294 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
295 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
296 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
297 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
298 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
299 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
300 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
301 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
302 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
303 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
304 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
305 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
306 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
307 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
308 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
309 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
310 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
311 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
312 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
313 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
314 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
315 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
316 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
317 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
318 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
319 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
320 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
321 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
322 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
323};
324static const u32 Te4[256] = {
325 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
326 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
327 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
328 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
329 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
330 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
331 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
332 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
333 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
334 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
335 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
336 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
337 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
338 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
339 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
340 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
341 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
342 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
343 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
344 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
345 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
346 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
347 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
348 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
349 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
350 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
351 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
352 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
353 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
354 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
355 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
356 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
357 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
358 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
359 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
360 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
361 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
362 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
363 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
364 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
365 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
366 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
367 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
368 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
369 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
370 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
371 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
372 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
373 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
374 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
375 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
376 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
377 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
378 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
379 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
380 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
381 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
382 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
383 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
384 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
385 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
386 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
387 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
388 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
389};
390static const u32 Td0[256] = {
391 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
392 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
393 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
394 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
395 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
396 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
397 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
398 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
399 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
400 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
401 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
402 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
403 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
404 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
405 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
406 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
407 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
408 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
409 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
410 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
411 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
412 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
413 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
414 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
415 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
416 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
417 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
418 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
419 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
420 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
421 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
422 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
423 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
424 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
425 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
426 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
427 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
428 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
429 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
430 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
431 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
432 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
433 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
434 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
435 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
436 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
437 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
438 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
439 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
440 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
441 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
442 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
443 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
444 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
445 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
446 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
447 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
448 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
449 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
450 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
451 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
452 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
453 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
454 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
455};
456static const u32 Td1[256] = {
457 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
458 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
459 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
460 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
461 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
462 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
463 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
464 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
465 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
466 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
467 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
468 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
469 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
470 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
471 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
472 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
473 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
474 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
475 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
476 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
477 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
478 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
479 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
480 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
481 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
482 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
483 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
484 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
485 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
486 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
487 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
488 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
489 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
490 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
491 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
492 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
493 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
494 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
495 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
496 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
497 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
498 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
499 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
500 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
501 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
502 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
503 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
504 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
505 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
506 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
507 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
508 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
509 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
510 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
511 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
512 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
513 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
514 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
515 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
516 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
517 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
518 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
519 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
520 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
521};
522static const u32 Td2[256] = {
523 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
524 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
525 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
526 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
527 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
528 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
529 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
530 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
531 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
532 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
533 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
534 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
535 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
536 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
537 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
538 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
539 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
540 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
541 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
542 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
543
544 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
545 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
546 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
547 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
548 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
549 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
550 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
551 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
552 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
553 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
554 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
555 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
556 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
557 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
558 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
559 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
560 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
561 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
562 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
563 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
564 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
565 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
566 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
567 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
568 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
569 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
570 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
571 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
572 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
573 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
574 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
575 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
576 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
577 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
578 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
579 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
580 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
581 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
582 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
583 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
584 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
585 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
586 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
587 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
588};
589static const u32 Td3[256] = {
590 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
591 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
592 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
593 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
594 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
595 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
596 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
597 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
598 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
599 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
600 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
601 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
602 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
603 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
604 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
605 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
606 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
607 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
608 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
609 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
610 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
611 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
612 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
613 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
614 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
615 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
616 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
617 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
618 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
619 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
620 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
621 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
622 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
623 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
624 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
625 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
626 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
627 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
628 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
629 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
630 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
631 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
632 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
633 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
634 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
635 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
636 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
637 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
638 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
639 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
640 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
641 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
642 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
643 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
644 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
645 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
646 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
647 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
648 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
649 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
650 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
651 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
652 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
653 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
654};
655static const u32 Td4[256] = {
656 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
657 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
658 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
659 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
660 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
661 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
662 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
663 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
664 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
665 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
666 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
667 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
668 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
669 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
670 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
671 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
672 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
673 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
674 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
675 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
676 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
677 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
678 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
679 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
680 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
681 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
682 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
683 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
684 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
685 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
686 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
687 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
688 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
689 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
690 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
691 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
692 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
693 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
694 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
695 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
696 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
697 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
698 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
699 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
700 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
701 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
702 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
703 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
704 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
705 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
706 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
707 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
708 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
709 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
710 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
711 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
712 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
713 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
714 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
715 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
716 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
717 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
718 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
719 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
720};
721static const u32 rcon[] = {
722 0x01000000, 0x02000000, 0x04000000, 0x08000000,
723 0x10000000, 0x20000000, 0x40000000, 0x80000000,
724 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
725};
726
727/**
728 * Expand the cipher key into the encryption key schedule.
729 */
730int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
731 AES_KEY *key) {
732
733 u32 *rk;
734 int i = 0;
735 u32 temp;
736
737 if (!userKey || !key)
738 return -1;
739 if (bits != 128 && bits != 192 && bits != 256)
740 return -2;
741
742 rk = key->rd_key;
743
744 if (bits==128)
745 key->rounds = 10;
746 else if (bits==192)
747 key->rounds = 12;
748 else
749 key->rounds = 14;
750
751 rk[0] = GETU32(userKey );
752 rk[1] = GETU32(userKey + 4);
753 rk[2] = GETU32(userKey + 8);
754 rk[3] = GETU32(userKey + 12);
755 if (bits == 128) {
756 while (1) {
757 temp = rk[3];
758 rk[4] = rk[0] ^
759 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
760 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
761 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
762 (Te4[(temp >> 24) ] & 0x000000ff) ^
763 rcon[i];
764 rk[5] = rk[1] ^ rk[4];
765 rk[6] = rk[2] ^ rk[5];
766 rk[7] = rk[3] ^ rk[6];
767 if (++i == 10) {
768 return 0;
769 }
770 rk += 4;
771 }
772 }
773 rk[4] = GETU32(userKey + 16);
774 rk[5] = GETU32(userKey + 20);
775 if (bits == 192) {
776 while (1) {
777 temp = rk[ 5];
778 rk[ 6] = rk[ 0] ^
779 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
780 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
781 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
782 (Te4[(temp >> 24) ] & 0x000000ff) ^
783 rcon[i];
784 rk[ 7] = rk[ 1] ^ rk[ 6];
785 rk[ 8] = rk[ 2] ^ rk[ 7];
786 rk[ 9] = rk[ 3] ^ rk[ 8];
787 if (++i == 8) {
788 return 0;
789 }
790 rk[10] = rk[ 4] ^ rk[ 9];
791 rk[11] = rk[ 5] ^ rk[10];
792 rk += 6;
793 }
794 }
795 rk[6] = GETU32(userKey + 24);
796 rk[7] = GETU32(userKey + 28);
797 if (bits == 256) {
798 while (1) {
799 temp = rk[ 7];
800 rk[ 8] = rk[ 0] ^
801 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
802 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
803 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
804 (Te4[(temp >> 24) ] & 0x000000ff) ^
805 rcon[i];
806 rk[ 9] = rk[ 1] ^ rk[ 8];
807 rk[10] = rk[ 2] ^ rk[ 9];
808 rk[11] = rk[ 3] ^ rk[10];
809 if (++i == 7) {
810 return 0;
811 }
812 temp = rk[11];
813 rk[12] = rk[ 4] ^
814 (Te4[(temp >> 24) ] & 0xff000000) ^
815 (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
816 (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
817 (Te4[(temp ) & 0xff] & 0x000000ff);
818 rk[13] = rk[ 5] ^ rk[12];
819 rk[14] = rk[ 6] ^ rk[13];
820 rk[15] = rk[ 7] ^ rk[14];
821
822 rk += 8;
823 }
824 }
825 return 0;
826}
827
828/**
829 * Expand the cipher key into the decryption key schedule.
830 */
831int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
832 AES_KEY *key) {
833
834 u32 *rk;
835 int i, j, status;
836 u32 temp;
837
838 /* first, start with an encryption schedule */
839 status = AES_set_encrypt_key(userKey, bits, key);
840 if (status < 0)
841 return status;
842
843 rk = key->rd_key;
844
845 /* invert the order of the round keys: */
846 for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
847 temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
848 temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
849 temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
850 temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
851 }
852 /* apply the inverse MixColumn transform to all round keys but the first and the last: */
853 for (i = 1; i < (key->rounds); i++) {
854 rk += 4;
855 rk[0] =
856 Td0[Te4[(rk[0] >> 24) ] & 0xff] ^
857 Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
858 Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
859 Td3[Te4[(rk[0] ) & 0xff] & 0xff];
860 rk[1] =
861 Td0[Te4[(rk[1] >> 24) ] & 0xff] ^
862 Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
863 Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
864 Td3[Te4[(rk[1] ) & 0xff] & 0xff];
865 rk[2] =
866 Td0[Te4[(rk[2] >> 24) ] & 0xff] ^
867 Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
868 Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
869 Td3[Te4[(rk[2] ) & 0xff] & 0xff];
870 rk[3] =
871 Td0[Te4[(rk[3] >> 24) ] & 0xff] ^
872 Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
873 Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
874 Td3[Te4[(rk[3] ) & 0xff] & 0xff];
875 }
876 return 0;
877}
878
879/*
880 * Encrypt a single block
881 * in and out can overlap
882 */
883void AES_encrypt(const unsigned char *in, unsigned char *out,
884 const AES_KEY *key) {
885
886 const u32 *rk;
887 u32 s0, s1, s2, s3, t0, t1, t2, t3;
888#ifndef FULL_UNROLL
889 int r;
890#endif /* ?FULL_UNROLL */
891
892 assert(in && out && key);
893 rk = key->rd_key;
894
895 /*
896 * map byte array block to cipher state
897 * and add initial round key:
898 */
899 s0 = GETU32(in ) ^ rk[0];
900 s1 = GETU32(in + 4) ^ rk[1];
901 s2 = GETU32(in + 8) ^ rk[2];
902 s3 = GETU32(in + 12) ^ rk[3];
903#ifdef FULL_UNROLL
904 /* round 1: */
905 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4];
906 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5];
907 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6];
908 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7];
909 /* round 2: */
910 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8];
911 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9];
912 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10];
913 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11];
914 /* round 3: */
915 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12];
916 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13];
917 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14];
918 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15];
919 /* round 4: */
920 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16];
921 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17];
922 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18];
923 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19];
924 /* round 5: */
925 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20];
926 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21];
927 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22];
928 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23];
929 /* round 6: */
930 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24];
931 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25];
932 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26];
933 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27];
934 /* round 7: */
935 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28];
936 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29];
937 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30];
938 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31];
939 /* round 8: */
940 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32];
941 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33];
942 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34];
943 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35];
944 /* round 9: */
945 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36];
946 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37];
947 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38];
948 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39];
949 if (key->rounds > 10) {
950 /* round 10: */
951 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40];
952 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41];
953 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42];
954 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43];
955 /* round 11: */
956 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44];
957 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45];
958 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46];
959 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47];
960 if (key->rounds > 12) {
961 /* round 12: */
962 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48];
963 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49];
964 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50];
965 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51];
966 /* round 13: */
967 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52];
968 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53];
969 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54];
970 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55];
971 }
972 }
973 rk += key->rounds << 2;
974#else /* !FULL_UNROLL */
975 /*
976 * Nr - 1 full rounds:
977 */
978 r = key->rounds >> 1;
979 for (;;) {
980 t0 =
981 Te0[(s0 >> 24) ] ^
982 Te1[(s1 >> 16) & 0xff] ^
983 Te2[(s2 >> 8) & 0xff] ^
984 Te3[(s3 ) & 0xff] ^
985 rk[4];
986 t1 =
987 Te0[(s1 >> 24) ] ^
988 Te1[(s2 >> 16) & 0xff] ^
989 Te2[(s3 >> 8) & 0xff] ^
990 Te3[(s0 ) & 0xff] ^
991 rk[5];
992 t2 =
993 Te0[(s2 >> 24) ] ^
994 Te1[(s3 >> 16) & 0xff] ^
995 Te2[(s0 >> 8) & 0xff] ^
996 Te3[(s1 ) & 0xff] ^
997 rk[6];
998 t3 =
999 Te0[(s3 >> 24) ] ^
1000 Te1[(s0 >> 16) & 0xff] ^
1001 Te2[(s1 >> 8) & 0xff] ^
1002 Te3[(s2 ) & 0xff] ^
1003 rk[7];
1004
1005 rk += 8;
1006 if (--r == 0) {
1007 break;
1008 }
1009
1010 s0 =
1011 Te0[(t0 >> 24) ] ^
1012 Te1[(t1 >> 16) & 0xff] ^
1013 Te2[(t2 >> 8) & 0xff] ^
1014 Te3[(t3 ) & 0xff] ^
1015 rk[0];
1016 s1 =
1017 Te0[(t1 >> 24) ] ^
1018 Te1[(t2 >> 16) & 0xff] ^
1019 Te2[(t3 >> 8) & 0xff] ^
1020 Te3[(t0 ) & 0xff] ^
1021 rk[1];
1022 s2 =
1023 Te0[(t2 >> 24) ] ^
1024 Te1[(t3 >> 16) & 0xff] ^
1025 Te2[(t0 >> 8) & 0xff] ^
1026 Te3[(t1 ) & 0xff] ^
1027 rk[2];
1028 s3 =
1029 Te0[(t3 >> 24) ] ^
1030 Te1[(t0 >> 16) & 0xff] ^
1031 Te2[(t1 >> 8) & 0xff] ^
1032 Te3[(t2 ) & 0xff] ^
1033 rk[3];
1034 }
1035#endif /* ?FULL_UNROLL */
1036 /*
1037 * apply last round and
1038 * map cipher state to byte array block:
1039 */
1040 s0 =
1041 (Te4[(t0 >> 24) ] & 0xff000000) ^
1042 (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1043 (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1044 (Te4[(t3 ) & 0xff] & 0x000000ff) ^
1045 rk[0];
1046 PUTU32(out , s0);
1047 s1 =
1048 (Te4[(t1 >> 24) ] & 0xff000000) ^
1049 (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1050 (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1051 (Te4[(t0 ) & 0xff] & 0x000000ff) ^
1052 rk[1];
1053 PUTU32(out + 4, s1);
1054 s2 =
1055 (Te4[(t2 >> 24) ] & 0xff000000) ^
1056 (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1057 (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1058 (Te4[(t1 ) & 0xff] & 0x000000ff) ^
1059 rk[2];
1060 PUTU32(out + 8, s2);
1061 s3 =
1062 (Te4[(t3 >> 24) ] & 0xff000000) ^
1063 (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1064 (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1065 (Te4[(t2 ) & 0xff] & 0x000000ff) ^
1066 rk[3];
1067 PUTU32(out + 12, s3);
1068}
1069
1070/*
1071 * Decrypt a single block
1072 * in and out can overlap
1073 */
1074void AES_decrypt(const unsigned char *in, unsigned char *out,
1075 const AES_KEY *key) {
1076
1077 const u32 *rk;
1078 u32 s0, s1, s2, s3, t0, t1, t2, t3;
1079#ifndef FULL_UNROLL
1080 int r;
1081#endif /* ?FULL_UNROLL */
1082
1083 assert(in && out && key);
1084 rk = key->rd_key;
1085
1086 /*
1087 * map byte array block to cipher state
1088 * and add initial round key:
1089 */
1090 s0 = GETU32(in ) ^ rk[0];
1091 s1 = GETU32(in + 4) ^ rk[1];
1092 s2 = GETU32(in + 8) ^ rk[2];
1093 s3 = GETU32(in + 12) ^ rk[3];
1094#ifdef FULL_UNROLL
1095 /* round 1: */
1096 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4];
1097 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5];
1098 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6];
1099 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7];
1100 /* round 2: */
1101 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8];
1102 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9];
1103 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10];
1104 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11];
1105 /* round 3: */
1106 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12];
1107 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13];
1108 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14];
1109 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15];
1110 /* round 4: */
1111 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16];
1112 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17];
1113 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18];
1114 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19];
1115 /* round 5: */
1116 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20];
1117 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21];
1118 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22];
1119 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23];
1120 /* round 6: */
1121 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24];
1122 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25];
1123 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26];
1124 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27];
1125 /* round 7: */
1126 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28];
1127 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29];
1128 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30];
1129 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31];
1130 /* round 8: */
1131 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32];
1132 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33];
1133 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34];
1134 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35];
1135 /* round 9: */
1136 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36];
1137 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37];
1138 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38];
1139 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39];
1140 if (key->rounds > 10) {
1141 /* round 10: */
1142 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40];
1143 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41];
1144 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42];
1145 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43];
1146 /* round 11: */
1147 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44];
1148 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45];
1149 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46];
1150 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47];
1151 if (key->rounds > 12) {
1152 /* round 12: */
1153 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48];
1154 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49];
1155 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50];
1156 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51];
1157 /* round 13: */
1158 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52];
1159 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53];
1160 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54];
1161 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55];
1162 }
1163 }
1164 rk += key->rounds << 2;
1165#else /* !FULL_UNROLL */
1166 /*
1167 * Nr - 1 full rounds:
1168 */
1169 r = key->rounds >> 1;
1170 for (;;) {
1171 t0 =
1172 Td0[(s0 >> 24) ] ^
1173 Td1[(s3 >> 16) & 0xff] ^
1174 Td2[(s2 >> 8) & 0xff] ^
1175 Td3[(s1 ) & 0xff] ^
1176 rk[4];
1177 t1 =
1178 Td0[(s1 >> 24) ] ^
1179 Td1[(s0 >> 16) & 0xff] ^
1180 Td2[(s3 >> 8) & 0xff] ^
1181 Td3[(s2 ) & 0xff] ^
1182 rk[5];
1183 t2 =
1184 Td0[(s2 >> 24) ] ^
1185 Td1[(s1 >> 16) & 0xff] ^
1186 Td2[(s0 >> 8) & 0xff] ^
1187 Td3[(s3 ) & 0xff] ^
1188 rk[6];
1189 t3 =
1190 Td0[(s3 >> 24) ] ^
1191 Td1[(s2 >> 16) & 0xff] ^
1192 Td2[(s1 >> 8) & 0xff] ^
1193 Td3[(s0 ) & 0xff] ^
1194 rk[7];
1195
1196 rk += 8;
1197 if (--r == 0) {
1198 break;
1199 }
1200
1201 s0 =
1202 Td0[(t0 >> 24) ] ^
1203 Td1[(t3 >> 16) & 0xff] ^
1204 Td2[(t2 >> 8) & 0xff] ^
1205 Td3[(t1 ) & 0xff] ^
1206 rk[0];
1207 s1 =
1208 Td0[(t1 >> 24) ] ^
1209 Td1[(t0 >> 16) & 0xff] ^
1210 Td2[(t3 >> 8) & 0xff] ^
1211 Td3[(t2 ) & 0xff] ^
1212 rk[1];
1213 s2 =
1214 Td0[(t2 >> 24) ] ^
1215 Td1[(t1 >> 16) & 0xff] ^
1216 Td2[(t0 >> 8) & 0xff] ^
1217 Td3[(t3 ) & 0xff] ^
1218 rk[2];
1219 s3 =
1220 Td0[(t3 >> 24) ] ^
1221 Td1[(t2 >> 16) & 0xff] ^
1222 Td2[(t1 >> 8) & 0xff] ^
1223 Td3[(t0 ) & 0xff] ^
1224 rk[3];
1225 }
1226#endif /* ?FULL_UNROLL */
1227 /*
1228 * apply last round and
1229 * map cipher state to byte array block:
1230 */
1231 s0 =
1232 (Td4[(t0 >> 24) ] & 0xff000000) ^
1233 (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1234 (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1235 (Td4[(t1 ) & 0xff] & 0x000000ff) ^
1236 rk[0];
1237 PUTU32(out , s0);
1238 s1 =
1239 (Td4[(t1 >> 24) ] & 0xff000000) ^
1240 (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1241 (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1242 (Td4[(t2 ) & 0xff] & 0x000000ff) ^
1243 rk[1];
1244 PUTU32(out + 4, s1);
1245 s2 =
1246 (Td4[(t2 >> 24) ] & 0xff000000) ^
1247 (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1248 (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1249 (Td4[(t3 ) & 0xff] & 0x000000ff) ^
1250 rk[2];
1251 PUTU32(out + 8, s2);
1252 s3 =
1253 (Td4[(t3 >> 24) ] & 0xff000000) ^
1254 (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1255 (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1256 (Td4[(t0 ) & 0xff] & 0x000000ff) ^
1257 rk[3];
1258 PUTU32(out + 12, s3);
1259}
1260
1261#endif /* ndef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/aes/aes_ctr.c b/src/lib/libcrypto/aes/aes_ctr.c
new file mode 100644
index 0000000000..f36982be1e
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_ctr.c
@@ -0,0 +1,139 @@
1/* crypto/aes/aes_ctr.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef AES_DEBUG
53# ifndef NDEBUG
54# define NDEBUG
55# endif
56#endif
57#include <assert.h>
58
59#include <openssl/aes.h>
60#include "aes_locl.h"
61
62/* NOTE: the IV/counter CTR mode is big-endian. The rest of the AES code
63 * is endian-neutral. */
64
65/* increment counter (128-bit int) by 1 */
66static void AES_ctr128_inc(unsigned char *counter) {
67 unsigned long c;
68
69 /* Grab bottom dword of counter and increment */
70 c = GETU32(counter + 12);
71 c++; c &= 0xFFFFFFFF;
72 PUTU32(counter + 12, c);
73
74 /* if no overflow, we're done */
75 if (c)
76 return;
77
78 /* Grab 1st dword of counter and increment */
79 c = GETU32(counter + 8);
80 c++; c &= 0xFFFFFFFF;
81 PUTU32(counter + 8, c);
82
83 /* if no overflow, we're done */
84 if (c)
85 return;
86
87 /* Grab 2nd dword of counter and increment */
88 c = GETU32(counter + 4);
89 c++; c &= 0xFFFFFFFF;
90 PUTU32(counter + 4, c);
91
92 /* if no overflow, we're done */
93 if (c)
94 return;
95
96 /* Grab top dword of counter and increment */
97 c = GETU32(counter + 0);
98 c++; c &= 0xFFFFFFFF;
99 PUTU32(counter + 0, c);
100}
101
102/* The input encrypted as though 128bit counter mode is being
103 * used. The extra state information to record how much of the
104 * 128bit block we have used is contained in *num, and the
105 * encrypted counter is kept in ecount_buf. Both *num and
106 * ecount_buf must be initialised with zeros before the first
107 * call to AES_ctr128_encrypt().
108 *
109 * This algorithm assumes that the counter is in the x lower bits
110 * of the IV (ivec), and that the application has full control over
111 * overflow and the rest of the IV. This implementation takes NO
112 * responsability for checking that the counter doesn't overflow
113 * into the rest of the IV when incremented.
114 */
115void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
116 const unsigned long length, const AES_KEY *key,
117 unsigned char ivec[AES_BLOCK_SIZE],
118 unsigned char ecount_buf[AES_BLOCK_SIZE],
119 unsigned int *num) {
120
121 unsigned int n;
122 unsigned long l=length;
123
124 assert(in && out && key && counter && num);
125 assert(*num < AES_BLOCK_SIZE);
126
127 n = *num;
128
129 while (l--) {
130 if (n == 0) {
131 AES_encrypt(ivec, ecount_buf, key);
132 AES_ctr128_inc(ivec);
133 }
134 *(out++) = *(in++) ^ ecount_buf[n];
135 n = (n+1) % AES_BLOCK_SIZE;
136 }
137
138 *num=n;
139}
diff --git a/src/lib/libcrypto/aes/aes_ecb.c b/src/lib/libcrypto/aes/aes_ecb.c
new file mode 100644
index 0000000000..28aa561c2d
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_ecb.c
@@ -0,0 +1,73 @@
1/* crypto/aes/aes_ecb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef AES_DEBUG
53# ifndef NDEBUG
54# define NDEBUG
55# endif
56#endif
57#include <assert.h>
58
59#include <openssl/aes.h>
60#include "aes_locl.h"
61
62void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
63 const AES_KEY *key, const int enc) {
64
65 assert(in && out && key);
66 assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
67
68 if (AES_ENCRYPT == enc)
69 AES_encrypt(in, out, key);
70 else
71 AES_decrypt(in, out, key);
72}
73
diff --git a/src/lib/libcrypto/aes/aes_locl.h b/src/lib/libcrypto/aes/aes_locl.h
new file mode 100644
index 0000000000..4184729e34
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_locl.h
@@ -0,0 +1,85 @@
1/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef HEADER_AES_LOCL_H
53#define HEADER_AES_LOCL_H
54
55#include <openssl/e_os2.h>
56
57#ifdef OPENSSL_NO_AES
58#error AES is disabled.
59#endif
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64
65#if defined(_MSC_VER) && !defined(_M_IA64) && !defined(OPENSSL_SYS_WINCE)
66# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
67# define GETU32(p) SWAP(*((u32 *)(p)))
68# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
69#else
70# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
71# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
72#endif
73
74typedef unsigned long u32;
75typedef unsigned short u16;
76typedef unsigned char u8;
77
78#define MAXKC (256/32)
79#define MAXKB (256/8)
80#define MAXNR 14
81
82/* This controls loop-unrolling in aes_core.c */
83#undef FULL_UNROLL
84
85#endif /* !HEADER_AES_LOCL_H */
diff --git a/src/lib/libcrypto/aes/aes_misc.c b/src/lib/libcrypto/aes/aes_misc.c
new file mode 100644
index 0000000000..090def25d5
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_misc.c
@@ -0,0 +1,64 @@
1/* crypto/aes/aes_misc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <openssl/opensslv.h>
53#include <openssl/aes.h>
54#include "aes_locl.h"
55
56const char *AES_version="AES" OPENSSL_VERSION_PTEXT;
57
58const char *AES_options(void) {
59#ifdef FULL_UNROLL
60 return "aes(full)";
61#else
62 return "aes(partial)";
63#endif
64}
diff --git a/src/lib/libcrypto/aes/aes_ofb.c b/src/lib/libcrypto/aes/aes_ofb.c
new file mode 100644
index 0000000000..f358bb39e2
--- /dev/null
+++ b/src/lib/libcrypto/aes/aes_ofb.c
@@ -0,0 +1,142 @@
1/* crypto/aes/aes_ofb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#ifndef AES_DEBUG
109# ifndef NDEBUG
110# define NDEBUG
111# endif
112#endif
113#include <assert.h>
114
115#include <openssl/aes.h>
116#include "aes_locl.h"
117
118/* The input and output encrypted as though 128bit ofb mode is being
119 * used. The extra state information to record how much of the
120 * 128bit block we have used is contained in *num;
121 */
122void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
123 const unsigned long length, const AES_KEY *key,
124 unsigned char *ivec, int *num) {
125
126 unsigned int n;
127 unsigned long l=length;
128
129 assert(in && out && key && ivec && num);
130
131 n = *num;
132
133 while (l--) {
134 if (n == 0) {
135 AES_encrypt(ivec, ivec, key);
136 }
137 *(out++) = *(in++) ^ ivec[n];
138 n = (n+1) % AES_BLOCK_SIZE;
139 }
140
141 *num=n;
142}
diff --git a/src/lib/libcrypto/aes/asm/aes-586.pl b/src/lib/libcrypto/aes/asm/aes-586.pl
new file mode 100644
index 0000000000..688fda21ff
--- /dev/null
+++ b/src/lib/libcrypto/aes/asm/aes-586.pl
@@ -0,0 +1,1541 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# Version 2.0.
10#
11# You might fail to appreciate this module performance from the first
12# try. If compared to "vanilla" linux-ia32-icc target, i.e. considered
13# to be *the* best Intel C compiler without -KPIC, performance appears
14# to be virtually identical... But try to re-configure with shared
15# library support... Aha! Intel compiler "suddenly" lags behind by 30%
16# [on P4, more on others]:-) And if compared to position-independent
17# code generated by GNU C, this code performs *more* than *twice* as
18# fast! Yes, all this buzz about PIC means that unlike other hand-
19# coded implementations, this one was explicitly designed to be safe
20# to use even in shared library context... This also means that this
21# code isn't necessarily absolutely fastest "ever," because in order
22# to achieve position independence an extra register has to be
23# off-loaded to stack, which affects the benchmark result.
24#
25# Special note about instruction choice. Do you recall RC4_INT code
26# performing poorly on P4? It might be the time to figure out why.
27# RC4_INT code implies effective address calculations in base+offset*4
28# form. Trouble is that it seems that offset scaling turned to be
29# critical path... At least eliminating scaling resulted in 2.8x RC4
30# performance improvement [as you might recall]. As AES code is hungry
31# for scaling too, I [try to] avoid the latter by favoring off-by-2
32# shifts and masking the result with 0xFF<<2 instead of "boring" 0xFF.
33#
34# As was shown by Dean Gaudet <dean@arctic.org>, the above note turned
35# void. Performance improvement with off-by-2 shifts was observed on
36# intermediate implementation, which was spilling yet another register
37# to stack... Final offset*4 code below runs just a tad faster on P4,
38# but exhibits up to 10% improvement on other cores.
39#
40# Second version is "monolithic" replacement for aes_core.c, which in
41# addition to AES_[de|en]crypt implements AES_set_[de|en]cryption_key.
42# This made it possible to implement little-endian variant of the
43# algorithm without modifying the base C code. Motivating factor for
44# the undertaken effort was that it appeared that in tight IA-32
45# register window little-endian flavor could achieve slightly higher
46# Instruction Level Parallelism, and it indeed resulted in up to 15%
47# better performance on most recent µ-archs...
48#
49# Current ECB performance numbers for 128-bit key in cycles per byte
50# [measure commonly used by AES benchmarkers] are:
51#
52# small footprint fully unrolled
53# P4[-3] 23[24] 22[23]
54# AMD K8 19 18
55# PIII 26(*) 23
56# Pentium 63(*) 52
57#
58# (*) Performance difference between small footprint code and fully
59# unrolled in more commonly used CBC mode is not as big, 7% for
60# PIII and 15% for Pentium, which I consider tolerable.
61
62push(@INC,"perlasm","../../perlasm");
63require "x86asm.pl";
64
65&asm_init($ARGV[0],"aes-586.pl",$ARGV[$#ARGV] eq "386");
66
67$small_footprint=1; # $small_footprint=1 code is ~5% slower [on
68 # recent µ-archs], but ~5 times smaller!
69 # I favor compact code, because it minimizes
70 # cache contention...
71$vertical_spin=0; # shift "verticaly" defaults to 0, because of
72 # its proof-of-concept status, see below...
73
74$s0="eax";
75$s1="ebx";
76$s2="ecx";
77$s3="edx";
78$key="esi";
79$acc="edi";
80
81if ($vertical_spin) {
82 # I need high parts of volatile registers to be accessible...
83 $s1="esi"; $key="ebx";
84 $s2="edi"; $acc="ecx";
85}
86# Note that there is no decvert(), as well as last encryption round is
87# performed with "horizontal" shifts. This is because this "vertical"
88# implementation [one which groups shifts on a given $s[i] to form a
89# "column," unlike "horizontal" one, which groups shifts on different
90# $s[i] to form a "row"] is work in progress. It was observed to run
91# few percents faster on Intel cores, but not AMD. On AMD K8 core it's
92# whole 12% slower:-( So we face a trade-off... Shall it be resolved
93# some day? Till then the code is considered experimental and by
94# default remains dormant...
95
96sub encvert()
97{ my ($te,@s) = @_;
98 my $v0 = $acc, $v1 = $key;
99
100 &mov ($v0,$s[3]); # copy s3
101 &mov (&DWP(0,"esp"),$s[2]); # save s2
102 &mov ($v1,$s[0]); # copy s0
103 &mov (&DWP(4,"esp"),$s[1]); # save s1
104
105 &movz ($s[2],&HB($s[0]));
106 &and ($s[0],0xFF);
107 &mov ($s[0],&DWP(1024*0,$te,$s[0],4)); # s0>>0
108 &shr ($v1,16);
109 &mov ($s[3],&DWP(1024*1,$te,$s[2],4)); # s0>>8
110 &movz ($s[1],&HB($v1));
111 &and ($v1,0xFF);
112 &mov ($s[2],&DWP(1024*2,$te,$v1,4)); # s0>>16
113 &mov ($v1,$v0);
114 &mov ($s[1],&DWP(1024*3,$te,$s[1],4)); # s0>>24
115
116 &and ($v0,0xFF);
117 &xor ($s[3],&DWP(1024*0,$te,$v0,4)); # s3>>0
118 &movz ($v0,&HB($v1));
119 &shr ($v1,16);
120 &xor ($s[2],&DWP(1024*1,$te,$v0,4)); # s3>>8
121 &movz ($v0,&HB($v1));
122 &and ($v1,0xFF);
123 &xor ($s[1],&DWP(1024*2,$te,$v1,4)); # s3>>16
124 &mov ($v1,&DWP(0,"esp")); # restore s2
125 &xor ($s[0],&DWP(1024*3,$te,$v0,4)); # s3>>24
126
127 &mov ($v0,$v1);
128 &and ($v1,0xFF);
129 &xor ($s[2],&DWP(1024*0,$te,$v1,4)); # s2>>0
130 &movz ($v1,&HB($v0));
131 &shr ($v0,16);
132 &xor ($s[1],&DWP(1024*1,$te,$v1,4)); # s2>>8
133 &movz ($v1,&HB($v0));
134 &and ($v0,0xFF);
135 &xor ($s[0],&DWP(1024*2,$te,$v0,4)); # s2>>16
136 &mov ($v0,&DWP(4,"esp")); # restore s1
137 &xor ($s[3],&DWP(1024*3,$te,$v1,4)); # s2>>24
138
139 &mov ($v1,$v0);
140 &and ($v0,0xFF);
141 &xor ($s[1],&DWP(1024*0,$te,$v0,4)); # s1>>0
142 &movz ($v0,&HB($v1));
143 &shr ($v1,16);
144 &xor ($s[0],&DWP(1024*1,$te,$v0,4)); # s1>>8
145 &movz ($v0,&HB($v1));
146 &and ($v1,0xFF);
147 &xor ($s[3],&DWP(1024*2,$te,$v1,4)); # s1>>16
148 &mov ($key,&DWP(12,"esp")); # reincarnate v1 as key
149 &xor ($s[2],&DWP(1024*3,$te,$v0,4)); # s1>>24
150}
151
152sub encstep()
153{ my ($i,$te,@s) = @_;
154 my $tmp = $key;
155 my $out = $i==3?$s[0]:$acc;
156
157 # lines marked with #%e?x[i] denote "reordered" instructions...
158 if ($i==3) { &mov ($key,&DWP(12,"esp")); }##%edx
159 else { &mov ($out,$s[0]);
160 &and ($out,0xFF); }
161 if ($i==1) { &shr ($s[0],16); }#%ebx[1]
162 if ($i==2) { &shr ($s[0],24); }#%ecx[2]
163 &mov ($out,&DWP(1024*0,$te,$out,4));
164
165 if ($i==3) { $tmp=$s[1]; }##%eax
166 &movz ($tmp,&HB($s[1]));
167 &xor ($out,&DWP(1024*1,$te,$tmp,4));
168
169 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(0,"esp")); }##%ebx
170 else { &mov ($tmp,$s[2]);
171 &shr ($tmp,16); }
172 if ($i==2) { &and ($s[1],0xFF); }#%edx[2]
173 &and ($tmp,0xFF);
174 &xor ($out,&DWP(1024*2,$te,$tmp,4));
175
176 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }##%ecx
177 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
178 else { &mov ($tmp,$s[3]);
179 &shr ($tmp,24) }
180 &xor ($out,&DWP(1024*3,$te,$tmp,4));
181 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
182 if ($i==3) { &mov ($s[3],$acc); }
183 &comment();
184}
185
186sub enclast()
187{ my ($i,$te,@s)=@_;
188 my $tmp = $key;
189 my $out = $i==3?$s[0]:$acc;
190
191 if ($i==3) { &mov ($key,&DWP(12,"esp")); }##%edx
192 else { &mov ($out,$s[0]); }
193 &and ($out,0xFF);
194 if ($i==1) { &shr ($s[0],16); }#%ebx[1]
195 if ($i==2) { &shr ($s[0],24); }#%ecx[2]
196 &mov ($out,&DWP(1024*0,$te,$out,4));
197 &and ($out,0x000000ff);
198
199 if ($i==3) { $tmp=$s[1]; }##%eax
200 &movz ($tmp,&HB($s[1]));
201 &mov ($tmp,&DWP(0,$te,$tmp,4));
202 &and ($tmp,0x0000ff00);
203 &xor ($out,$tmp);
204
205 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(0,"esp")); }##%ebx
206 else { mov ($tmp,$s[2]);
207 &shr ($tmp,16); }
208 if ($i==2) { &and ($s[1],0xFF); }#%edx[2]
209 &and ($tmp,0xFF);
210 &mov ($tmp,&DWP(0,$te,$tmp,4));
211 &and ($tmp,0x00ff0000);
212 &xor ($out,$tmp);
213
214 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }##%ecx
215 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
216 else { &mov ($tmp,$s[3]);
217 &shr ($tmp,24); }
218 &mov ($tmp,&DWP(0,$te,$tmp,4));
219 &and ($tmp,0xff000000);
220 &xor ($out,$tmp);
221 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
222 if ($i==3) { &mov ($s[3],$acc); }
223}
224
225# void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
226&public_label("AES_Te");
227&function_begin("AES_encrypt");
228 &mov ($acc,&wparam(0)); # load inp
229 &mov ($key,&wparam(2)); # load key
230
231 &call (&label("pic_point")); # make it PIC!
232 &set_label("pic_point");
233 &blindpop("ebp");
234 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
235
236 # allocate aligned stack frame
237 &mov ($s0,"esp");
238 &sub ("esp",20);
239 &and ("esp",-16);
240
241 &mov (&DWP(12,"esp"),$key); # save key
242 &mov (&DWP(16,"esp"),$s0); # save %esp
243
244 &mov ($s0,&DWP(0,$acc)); # load input data
245 &mov ($s1,&DWP(4,$acc));
246 &mov ($s2,&DWP(8,$acc));
247 &mov ($s3,&DWP(12,$acc));
248
249 &xor ($s0,&DWP(0,$key));
250 &xor ($s1,&DWP(4,$key));
251 &xor ($s2,&DWP(8,$key));
252 &xor ($s3,&DWP(12,$key));
253
254 &mov ($acc,&DWP(240,$key)); # load key->rounds
255
256 if ($small_footprint) {
257 &lea ($acc,&DWP(-2,$acc,$acc));
258 &lea ($acc,&DWP(0,$key,$acc,8));
259 &mov (&DWP(8,"esp"),$acc); # end of key schedule
260 &align (4);
261 &set_label("loop");
262 if ($vertical_spin) {
263 &encvert("ebp",$s0,$s1,$s2,$s3);
264 } else {
265 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
266 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
267 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
268 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
269 }
270 &add ($key,16); # advance rd_key
271 &xor ($s0,&DWP(0,$key));
272 &xor ($s1,&DWP(4,$key));
273 &xor ($s2,&DWP(8,$key));
274 &xor ($s3,&DWP(12,$key));
275 &cmp ($key,&DWP(8,"esp"));
276 &mov (&DWP(12,"esp"),$key);
277 &jb (&label("loop"));
278 }
279 else {
280 &cmp ($acc,10);
281 &jle (&label("10rounds"));
282 &cmp ($acc,12);
283 &jle (&label("12rounds"));
284
285 &set_label("14rounds");
286 for ($i=1;$i<3;$i++) {
287 if ($vertical_spin) {
288 &encvert("ebp",$s0,$s1,$s2,$s3);
289 } else {
290 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
291 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
292 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
293 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
294 }
295 &xor ($s0,&DWP(16*$i+0,$key));
296 &xor ($s1,&DWP(16*$i+4,$key));
297 &xor ($s2,&DWP(16*$i+8,$key));
298 &xor ($s3,&DWP(16*$i+12,$key));
299 }
300 &add ($key,32);
301 &mov (&DWP(12,"esp"),$key); # advance rd_key
302 &set_label("12rounds");
303 for ($i=1;$i<3;$i++) {
304 if ($vertical_spin) {
305 &encvert("ebp",$s0,$s1,$s2,$s3);
306 } else {
307 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
308 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
309 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
310 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
311 }
312 &xor ($s0,&DWP(16*$i+0,$key));
313 &xor ($s1,&DWP(16*$i+4,$key));
314 &xor ($s2,&DWP(16*$i+8,$key));
315 &xor ($s3,&DWP(16*$i+12,$key));
316 }
317 &add ($key,32);
318 &mov (&DWP(12,"esp"),$key); # advance rd_key
319 &set_label("10rounds");
320 for ($i=1;$i<10;$i++) {
321 if ($vertical_spin) {
322 &encvert("ebp",$s0,$s1,$s2,$s3);
323 } else {
324 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
325 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
326 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
327 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
328 }
329 &xor ($s0,&DWP(16*$i+0,$key));
330 &xor ($s1,&DWP(16*$i+4,$key));
331 &xor ($s2,&DWP(16*$i+8,$key));
332 &xor ($s3,&DWP(16*$i+12,$key));
333 }
334 }
335
336 &add ("ebp",4*1024); # skip to Te4
337 if ($vertical_spin) {
338 # "reincarnate" some registers for "horizontal" spin...
339 &mov ($s1="ebx",$key="esi");
340 &mov ($s2="ecx",$acc="edi");
341 }
342 &enclast(0,"ebp",$s0,$s1,$s2,$s3);
343 &enclast(1,"ebp",$s1,$s2,$s3,$s0);
344 &enclast(2,"ebp",$s2,$s3,$s0,$s1);
345 &enclast(3,"ebp",$s3,$s0,$s1,$s2);
346
347 &mov ("esp",&DWP(16,"esp")); # restore %esp
348 &add ($key,$small_footprint?16:160);
349 &xor ($s0,&DWP(0,$key));
350 &xor ($s1,&DWP(4,$key));
351 &xor ($s2,&DWP(8,$key));
352 &xor ($s3,&DWP(12,$key));
353
354 &mov ($acc,&wparam(1)); # load out
355 &mov (&DWP(0,$acc),$s0); # write output data
356 &mov (&DWP(4,$acc),$s1);
357 &mov (&DWP(8,$acc),$s2);
358 &mov (&DWP(12,$acc),$s3);
359
360 &pop ("edi");
361 &pop ("esi");
362 &pop ("ebx");
363 &pop ("ebp");
364 &ret ();
365
366&set_label("AES_Te",64); # Yes! I keep it in the code segment!
367 &data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
368 &data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
369 &data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
370 &data_word(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
371 &data_word(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
372 &data_word(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
373 &data_word(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
374 &data_word(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
375 &data_word(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
376 &data_word(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
377 &data_word(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
378 &data_word(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
379 &data_word(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
380 &data_word(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
381 &data_word(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
382 &data_word(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
383 &data_word(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
384 &data_word(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
385 &data_word(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
386 &data_word(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
387 &data_word(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
388 &data_word(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
389 &data_word(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
390 &data_word(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
391 &data_word(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
392 &data_word(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
393 &data_word(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
394 &data_word(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
395 &data_word(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
396 &data_word(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
397 &data_word(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
398 &data_word(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
399 &data_word(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
400 &data_word(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
401 &data_word(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
402 &data_word(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
403 &data_word(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
404 &data_word(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
405 &data_word(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
406 &data_word(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
407 &data_word(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
408 &data_word(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
409 &data_word(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
410 &data_word(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
411 &data_word(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
412 &data_word(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
413 &data_word(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
414 &data_word(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
415 &data_word(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
416 &data_word(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
417 &data_word(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
418 &data_word(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
419 &data_word(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
420 &data_word(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
421 &data_word(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
422 &data_word(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
423 &data_word(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
424 &data_word(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
425 &data_word(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
426 &data_word(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
427 &data_word(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
428 &data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
429 &data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
430 &data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
431#Te1:
432 &data_word(0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d);
433 &data_word(0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154);
434 &data_word(0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d);
435 &data_word(0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a);
436 &data_word(0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87);
437 &data_word(0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b);
438 &data_word(0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea);
439 &data_word(0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b);
440 &data_word(0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a);
441 &data_word(0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f);
442 &data_word(0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908);
443 &data_word(0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f);
444 &data_word(0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e);
445 &data_word(0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5);
446 &data_word(0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d);
447 &data_word(0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f);
448 &data_word(0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e);
449 &data_word(0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb);
450 &data_word(0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce);
451 &data_word(0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397);
452 &data_word(0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c);
453 &data_word(0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed);
454 &data_word(0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b);
455 &data_word(0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a);
456 &data_word(0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16);
457 &data_word(0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194);
458 &data_word(0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81);
459 &data_word(0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3);
460 &data_word(0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a);
461 &data_word(0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104);
462 &data_word(0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263);
463 &data_word(0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d);
464 &data_word(0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f);
465 &data_word(0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39);
466 &data_word(0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47);
467 &data_word(0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695);
468 &data_word(0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f);
469 &data_word(0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83);
470 &data_word(0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c);
471 &data_word(0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76);
472 &data_word(0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e);
473 &data_word(0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4);
474 &data_word(0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6);
475 &data_word(0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b);
476 &data_word(0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7);
477 &data_word(0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0);
478 &data_word(0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25);
479 &data_word(0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018);
480 &data_word(0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72);
481 &data_word(0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751);
482 &data_word(0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21);
483 &data_word(0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85);
484 &data_word(0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa);
485 &data_word(0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12);
486 &data_word(0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0);
487 &data_word(0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9);
488 &data_word(0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233);
489 &data_word(0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7);
490 &data_word(0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920);
491 &data_word(0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a);
492 &data_word(0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17);
493 &data_word(0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8);
494 &data_word(0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11);
495 &data_word(0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a);
496#Te2:
497 &data_word(0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b);
498 &data_word(0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5);
499 &data_word(0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b);
500 &data_word(0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76);
501 &data_word(0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d);
502 &data_word(0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0);
503 &data_word(0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf);
504 &data_word(0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0);
505 &data_word(0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26);
506 &data_word(0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc);
507 &data_word(0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1);
508 &data_word(0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15);
509 &data_word(0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3);
510 &data_word(0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a);
511 &data_word(0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2);
512 &data_word(0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75);
513 &data_word(0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a);
514 &data_word(0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0);
515 &data_word(0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3);
516 &data_word(0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784);
517 &data_word(0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced);
518 &data_word(0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b);
519 &data_word(0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39);
520 &data_word(0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf);
521 &data_word(0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb);
522 &data_word(0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485);
523 &data_word(0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f);
524 &data_word(0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8);
525 &data_word(0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f);
526 &data_word(0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5);
527 &data_word(0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321);
528 &data_word(0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2);
529 &data_word(0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec);
530 &data_word(0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917);
531 &data_word(0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d);
532 &data_word(0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573);
533 &data_word(0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc);
534 &data_word(0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388);
535 &data_word(0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14);
536 &data_word(0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db);
537 &data_word(0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a);
538 &data_word(0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c);
539 &data_word(0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662);
540 &data_word(0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79);
541 &data_word(0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d);
542 &data_word(0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9);
543 &data_word(0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea);
544 &data_word(0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808);
545 &data_word(0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e);
546 &data_word(0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6);
547 &data_word(0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f);
548 &data_word(0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a);
549 &data_word(0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66);
550 &data_word(0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e);
551 &data_word(0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9);
552 &data_word(0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e);
553 &data_word(0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311);
554 &data_word(0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794);
555 &data_word(0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9);
556 &data_word(0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf);
557 &data_word(0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d);
558 &data_word(0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868);
559 &data_word(0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f);
560 &data_word(0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16);
561#Te3:
562 &data_word(0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b);
563 &data_word(0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5);
564 &data_word(0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b);
565 &data_word(0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676);
566 &data_word(0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d);
567 &data_word(0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0);
568 &data_word(0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf);
569 &data_word(0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0);
570 &data_word(0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626);
571 &data_word(0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc);
572 &data_word(0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1);
573 &data_word(0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515);
574 &data_word(0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3);
575 &data_word(0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a);
576 &data_word(0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2);
577 &data_word(0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575);
578 &data_word(0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a);
579 &data_word(0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0);
580 &data_word(0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3);
581 &data_word(0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484);
582 &data_word(0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded);
583 &data_word(0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b);
584 &data_word(0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939);
585 &data_word(0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf);
586 &data_word(0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb);
587 &data_word(0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585);
588 &data_word(0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f);
589 &data_word(0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8);
590 &data_word(0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f);
591 &data_word(0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5);
592 &data_word(0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121);
593 &data_word(0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2);
594 &data_word(0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec);
595 &data_word(0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717);
596 &data_word(0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d);
597 &data_word(0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373);
598 &data_word(0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc);
599 &data_word(0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888);
600 &data_word(0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414);
601 &data_word(0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb);
602 &data_word(0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a);
603 &data_word(0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c);
604 &data_word(0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262);
605 &data_word(0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979);
606 &data_word(0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d);
607 &data_word(0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9);
608 &data_word(0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea);
609 &data_word(0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808);
610 &data_word(0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e);
611 &data_word(0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6);
612 &data_word(0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f);
613 &data_word(0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a);
614 &data_word(0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666);
615 &data_word(0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e);
616 &data_word(0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9);
617 &data_word(0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e);
618 &data_word(0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111);
619 &data_word(0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494);
620 &data_word(0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9);
621 &data_word(0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf);
622 &data_word(0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d);
623 &data_word(0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868);
624 &data_word(0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f);
625 &data_word(0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616);
626#Te4:
627 &data_word(0x63636363, 0x7c7c7c7c, 0x77777777, 0x7b7b7b7b);
628 &data_word(0xf2f2f2f2, 0x6b6b6b6b, 0x6f6f6f6f, 0xc5c5c5c5);
629 &data_word(0x30303030, 0x01010101, 0x67676767, 0x2b2b2b2b);
630 &data_word(0xfefefefe, 0xd7d7d7d7, 0xabababab, 0x76767676);
631 &data_word(0xcacacaca, 0x82828282, 0xc9c9c9c9, 0x7d7d7d7d);
632 &data_word(0xfafafafa, 0x59595959, 0x47474747, 0xf0f0f0f0);
633 &data_word(0xadadadad, 0xd4d4d4d4, 0xa2a2a2a2, 0xafafafaf);
634 &data_word(0x9c9c9c9c, 0xa4a4a4a4, 0x72727272, 0xc0c0c0c0);
635 &data_word(0xb7b7b7b7, 0xfdfdfdfd, 0x93939393, 0x26262626);
636 &data_word(0x36363636, 0x3f3f3f3f, 0xf7f7f7f7, 0xcccccccc);
637 &data_word(0x34343434, 0xa5a5a5a5, 0xe5e5e5e5, 0xf1f1f1f1);
638 &data_word(0x71717171, 0xd8d8d8d8, 0x31313131, 0x15151515);
639 &data_word(0x04040404, 0xc7c7c7c7, 0x23232323, 0xc3c3c3c3);
640 &data_word(0x18181818, 0x96969696, 0x05050505, 0x9a9a9a9a);
641 &data_word(0x07070707, 0x12121212, 0x80808080, 0xe2e2e2e2);
642 &data_word(0xebebebeb, 0x27272727, 0xb2b2b2b2, 0x75757575);
643 &data_word(0x09090909, 0x83838383, 0x2c2c2c2c, 0x1a1a1a1a);
644 &data_word(0x1b1b1b1b, 0x6e6e6e6e, 0x5a5a5a5a, 0xa0a0a0a0);
645 &data_word(0x52525252, 0x3b3b3b3b, 0xd6d6d6d6, 0xb3b3b3b3);
646 &data_word(0x29292929, 0xe3e3e3e3, 0x2f2f2f2f, 0x84848484);
647 &data_word(0x53535353, 0xd1d1d1d1, 0x00000000, 0xedededed);
648 &data_word(0x20202020, 0xfcfcfcfc, 0xb1b1b1b1, 0x5b5b5b5b);
649 &data_word(0x6a6a6a6a, 0xcbcbcbcb, 0xbebebebe, 0x39393939);
650 &data_word(0x4a4a4a4a, 0x4c4c4c4c, 0x58585858, 0xcfcfcfcf);
651 &data_word(0xd0d0d0d0, 0xefefefef, 0xaaaaaaaa, 0xfbfbfbfb);
652 &data_word(0x43434343, 0x4d4d4d4d, 0x33333333, 0x85858585);
653 &data_word(0x45454545, 0xf9f9f9f9, 0x02020202, 0x7f7f7f7f);
654 &data_word(0x50505050, 0x3c3c3c3c, 0x9f9f9f9f, 0xa8a8a8a8);
655 &data_word(0x51515151, 0xa3a3a3a3, 0x40404040, 0x8f8f8f8f);
656 &data_word(0x92929292, 0x9d9d9d9d, 0x38383838, 0xf5f5f5f5);
657 &data_word(0xbcbcbcbc, 0xb6b6b6b6, 0xdadadada, 0x21212121);
658 &data_word(0x10101010, 0xffffffff, 0xf3f3f3f3, 0xd2d2d2d2);
659 &data_word(0xcdcdcdcd, 0x0c0c0c0c, 0x13131313, 0xecececec);
660 &data_word(0x5f5f5f5f, 0x97979797, 0x44444444, 0x17171717);
661 &data_word(0xc4c4c4c4, 0xa7a7a7a7, 0x7e7e7e7e, 0x3d3d3d3d);
662 &data_word(0x64646464, 0x5d5d5d5d, 0x19191919, 0x73737373);
663 &data_word(0x60606060, 0x81818181, 0x4f4f4f4f, 0xdcdcdcdc);
664 &data_word(0x22222222, 0x2a2a2a2a, 0x90909090, 0x88888888);
665 &data_word(0x46464646, 0xeeeeeeee, 0xb8b8b8b8, 0x14141414);
666 &data_word(0xdededede, 0x5e5e5e5e, 0x0b0b0b0b, 0xdbdbdbdb);
667 &data_word(0xe0e0e0e0, 0x32323232, 0x3a3a3a3a, 0x0a0a0a0a);
668 &data_word(0x49494949, 0x06060606, 0x24242424, 0x5c5c5c5c);
669 &data_word(0xc2c2c2c2, 0xd3d3d3d3, 0xacacacac, 0x62626262);
670 &data_word(0x91919191, 0x95959595, 0xe4e4e4e4, 0x79797979);
671 &data_word(0xe7e7e7e7, 0xc8c8c8c8, 0x37373737, 0x6d6d6d6d);
672 &data_word(0x8d8d8d8d, 0xd5d5d5d5, 0x4e4e4e4e, 0xa9a9a9a9);
673 &data_word(0x6c6c6c6c, 0x56565656, 0xf4f4f4f4, 0xeaeaeaea);
674 &data_word(0x65656565, 0x7a7a7a7a, 0xaeaeaeae, 0x08080808);
675 &data_word(0xbabababa, 0x78787878, 0x25252525, 0x2e2e2e2e);
676 &data_word(0x1c1c1c1c, 0xa6a6a6a6, 0xb4b4b4b4, 0xc6c6c6c6);
677 &data_word(0xe8e8e8e8, 0xdddddddd, 0x74747474, 0x1f1f1f1f);
678 &data_word(0x4b4b4b4b, 0xbdbdbdbd, 0x8b8b8b8b, 0x8a8a8a8a);
679 &data_word(0x70707070, 0x3e3e3e3e, 0xb5b5b5b5, 0x66666666);
680 &data_word(0x48484848, 0x03030303, 0xf6f6f6f6, 0x0e0e0e0e);
681 &data_word(0x61616161, 0x35353535, 0x57575757, 0xb9b9b9b9);
682 &data_word(0x86868686, 0xc1c1c1c1, 0x1d1d1d1d, 0x9e9e9e9e);
683 &data_word(0xe1e1e1e1, 0xf8f8f8f8, 0x98989898, 0x11111111);
684 &data_word(0x69696969, 0xd9d9d9d9, 0x8e8e8e8e, 0x94949494);
685 &data_word(0x9b9b9b9b, 0x1e1e1e1e, 0x87878787, 0xe9e9e9e9);
686 &data_word(0xcececece, 0x55555555, 0x28282828, 0xdfdfdfdf);
687 &data_word(0x8c8c8c8c, 0xa1a1a1a1, 0x89898989, 0x0d0d0d0d);
688 &data_word(0xbfbfbfbf, 0xe6e6e6e6, 0x42424242, 0x68686868);
689 &data_word(0x41414141, 0x99999999, 0x2d2d2d2d, 0x0f0f0f0f);
690 &data_word(0xb0b0b0b0, 0x54545454, 0xbbbbbbbb, 0x16161616);
691#rcon:
692 &data_word(0x00000001, 0x00000002, 0x00000004, 0x00000008);
693 &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080);
694 &data_word(0x0000001b, 0x00000036);
695&function_end_B("AES_encrypt");
696
697#------------------------------------------------------------------#
698
699$s0="eax";
700$s1="ebx";
701$s2="ecx";
702$s3="edx";
703$key="edi";
704$acc="esi";
705
706sub decstep()
707{ my ($i,$td,@s) = @_;
708 my $tmp = $key;
709 my $out = $i==3?$s[0]:$acc;
710
711 # no instructions are reordered, as performance appears
712 # optimal... or rather that all attempts to reorder didn't
713 # result in better performance [which by the way is not a
714 # bit lower than ecryption].
715 if($i==3) { &mov ($key,&DWP(12,"esp")); }
716 else { &mov ($out,$s[0]); }
717 &and ($out,0xFF);
718 &mov ($out,&DWP(1024*0,$td,$out,4));
719
720 if ($i==3) { $tmp=$s[1]; }
721 &movz ($tmp,&HB($s[1]));
722 &xor ($out,&DWP(1024*1,$td,$tmp,4));
723
724 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); }
725 else { &mov ($tmp,$s[2]); }
726 &shr ($tmp,16);
727 &and ($tmp,0xFF);
728 &xor ($out,&DWP(1024*2,$td,$tmp,4));
729
730 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }
731 else { &mov ($tmp,$s[3]); }
732 &shr ($tmp,24);
733 &xor ($out,&DWP(1024*3,$td,$tmp,4));
734 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
735 if ($i==3) { &mov ($s[3],&DWP(0,"esp")); }
736 &comment();
737}
738
739sub declast()
740{ my ($i,$td,@s)=@_;
741 my $tmp = $key;
742 my $out = $i==3?$s[0]:$acc;
743
744 if($i==3) { &mov ($key,&DWP(12,"esp")); }
745 else { &mov ($out,$s[0]); }
746 &and ($out,0xFF);
747 &mov ($out,&DWP(0,$td,$out,4));
748 &and ($out,0x000000ff);
749
750 if ($i==3) { $tmp=$s[1]; }
751 &movz ($tmp,&HB($s[1]));
752 &mov ($tmp,&DWP(0,$td,$tmp,4));
753 &and ($tmp,0x0000ff00);
754 &xor ($out,$tmp);
755
756 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); }
757 else { mov ($tmp,$s[2]); }
758 &shr ($tmp,16);
759 &and ($tmp,0xFF);
760 &mov ($tmp,&DWP(0,$td,$tmp,4));
761 &and ($tmp,0x00ff0000);
762 &xor ($out,$tmp);
763
764 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }
765 else { &mov ($tmp,$s[3]); }
766 &shr ($tmp,24);
767 &mov ($tmp,&DWP(0,$td,$tmp,4));
768 &and ($tmp,0xff000000);
769 &xor ($out,$tmp);
770 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
771 if ($i==3) { &mov ($s[3],&DWP(0,"esp")); }
772}
773
774# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
775&public_label("AES_Td");
776&function_begin("AES_decrypt");
777 &mov ($acc,&wparam(0)); # load inp
778 &mov ($key,&wparam(2)); # load key
779
780 &call (&label("pic_point")); # make it PIC!
781 &set_label("pic_point");
782 &blindpop("ebp");
783 &lea ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
784
785 # allocate aligned stack frame
786 &mov ($s0,"esp");
787 &sub ("esp",20);
788 &and ("esp",-16);
789
790 &mov (&DWP(12,"esp"),$key); # save key
791 &mov (&DWP(16,"esp"),$s0); # save %esp
792
793 &mov ($s0,&DWP(0,$acc)); # load input data
794 &mov ($s1,&DWP(4,$acc));
795 &mov ($s2,&DWP(8,$acc));
796 &mov ($s3,&DWP(12,$acc));
797
798 &xor ($s0,&DWP(0,$key));
799 &xor ($s1,&DWP(4,$key));
800 &xor ($s2,&DWP(8,$key));
801 &xor ($s3,&DWP(12,$key));
802
803 &mov ($acc,&DWP(240,$key)); # load key->rounds
804
805 if ($small_footprint) {
806 &lea ($acc,&DWP(-2,$acc,$acc));
807 &lea ($acc,&DWP(0,$key,$acc,8));
808 &mov (&DWP(8,"esp"),$acc); # end of key schedule
809 &align (4);
810 &set_label("loop");
811 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
812 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
813 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
814 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
815 &add ($key,16); # advance rd_key
816 &xor ($s0,&DWP(0,$key));
817 &xor ($s1,&DWP(4,$key));
818 &xor ($s2,&DWP(8,$key));
819 &xor ($s3,&DWP(12,$key));
820 &cmp ($key,&DWP(8,"esp"));
821 &mov (&DWP(12,"esp"),$key);
822 &jb (&label("loop"));
823 }
824 else {
825 &cmp ($acc,10);
826 &jle (&label("10rounds"));
827 &cmp ($acc,12);
828 &jle (&label("12rounds"));
829
830 &set_label("14rounds");
831 for ($i=1;$i<3;$i++) {
832 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
833 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
834 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
835 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
836 &xor ($s0,&DWP(16*$i+0,$key));
837 &xor ($s1,&DWP(16*$i+4,$key));
838 &xor ($s2,&DWP(16*$i+8,$key));
839 &xor ($s3,&DWP(16*$i+12,$key));
840 }
841 &add ($key,32);
842 &mov (&DWP(12,"esp"),$key); # advance rd_key
843 &set_label("12rounds");
844 for ($i=1;$i<3;$i++) {
845 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
846 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
847 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
848 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
849 &xor ($s0,&DWP(16*$i+0,$key));
850 &xor ($s1,&DWP(16*$i+4,$key));
851 &xor ($s2,&DWP(16*$i+8,$key));
852 &xor ($s3,&DWP(16*$i+12,$key));
853 }
854 &add ($key,32);
855 &mov (&DWP(12,"esp"),$key); # advance rd_key
856 &set_label("10rounds");
857 for ($i=1;$i<10;$i++) {
858 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
859 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
860 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
861 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
862 &xor ($s0,&DWP(16*$i+0,$key));
863 &xor ($s1,&DWP(16*$i+4,$key));
864 &xor ($s2,&DWP(16*$i+8,$key));
865 &xor ($s3,&DWP(16*$i+12,$key));
866 }
867 }
868
869 &add ("ebp",4*1024); # skip to Te4
870 &declast(0,"ebp",$s0,$s3,$s2,$s1);
871 &declast(1,"ebp",$s1,$s0,$s3,$s2);
872 &declast(2,"ebp",$s2,$s1,$s0,$s3);
873 &declast(3,"ebp",$s3,$s2,$s1,$s0);
874
875 &mov ("esp",&DWP(16,"esp")); # restore %esp
876 &add ($key,$small_footprint?16:160);
877 &xor ($s0,&DWP(0,$key));
878 &xor ($s1,&DWP(4,$key));
879 &xor ($s2,&DWP(8,$key));
880 &xor ($s3,&DWP(12,$key));
881
882 &mov ($key,&wparam(1)); # load out
883 &mov (&DWP(0,$key),$s0); # write output data
884 &mov (&DWP(4,$key),$s1);
885 &mov (&DWP(8,$key),$s2);
886 &mov (&DWP(12,$key),$s3);
887
888 &pop ("edi");
889 &pop ("esi");
890 &pop ("ebx");
891 &pop ("ebp");
892 &ret ();
893
894&set_label("AES_Td",64); # Yes! I keep it in the code segment!
895 &data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
896 &data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
897 &data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5);
898 &data_word(0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5);
899 &data_word(0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d);
900 &data_word(0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b);
901 &data_word(0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295);
902 &data_word(0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e);
903 &data_word(0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927);
904 &data_word(0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d);
905 &data_word(0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362);
906 &data_word(0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9);
907 &data_word(0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52);
908 &data_word(0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566);
909 &data_word(0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3);
910 &data_word(0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed);
911 &data_word(0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e);
912 &data_word(0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4);
913 &data_word(0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4);
914 &data_word(0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd);
915 &data_word(0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d);
916 &data_word(0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060);
917 &data_word(0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967);
918 &data_word(0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879);
919 &data_word(0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000);
920 &data_word(0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c);
921 &data_word(0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36);
922 &data_word(0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624);
923 &data_word(0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b);
924 &data_word(0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c);
925 &data_word(0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12);
926 &data_word(0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14);
927 &data_word(0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3);
928 &data_word(0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b);
929 &data_word(0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8);
930 &data_word(0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684);
931 &data_word(0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7);
932 &data_word(0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177);
933 &data_word(0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947);
934 &data_word(0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322);
935 &data_word(0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498);
936 &data_word(0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f);
937 &data_word(0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54);
938 &data_word(0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382);
939 &data_word(0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf);
940 &data_word(0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb);
941 &data_word(0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83);
942 &data_word(0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef);
943 &data_word(0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029);
944 &data_word(0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235);
945 &data_word(0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733);
946 &data_word(0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117);
947 &data_word(0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4);
948 &data_word(0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546);
949 &data_word(0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb);
950 &data_word(0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d);
951 &data_word(0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb);
952 &data_word(0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a);
953 &data_word(0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773);
954 &data_word(0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478);
955 &data_word(0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2);
956 &data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
957 &data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
958 &data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
959#Td1:
960 &data_word(0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96);
961 &data_word(0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93);
962 &data_word(0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525);
963 &data_word(0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f);
964 &data_word(0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1);
965 &data_word(0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6);
966 &data_word(0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da);
967 &data_word(0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44);
968 &data_word(0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd);
969 &data_word(0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4);
970 &data_word(0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245);
971 &data_word(0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994);
972 &data_word(0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7);
973 &data_word(0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a);
974 &data_word(0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5);
975 &data_word(0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c);
976 &data_word(0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1);
977 &data_word(0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a);
978 &data_word(0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475);
979 &data_word(0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51);
980 &data_word(0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46);
981 &data_word(0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff);
982 &data_word(0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777);
983 &data_word(0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db);
984 &data_word(0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000);
985 &data_word(0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e);
986 &data_word(0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627);
987 &data_word(0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a);
988 &data_word(0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e);
989 &data_word(0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16);
990 &data_word(0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d);
991 &data_word(0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8);
992 &data_word(0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd);
993 &data_word(0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34);
994 &data_word(0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863);
995 &data_word(0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420);
996 &data_word(0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d);
997 &data_word(0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0);
998 &data_word(0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722);
999 &data_word(0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef);
1000 &data_word(0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836);
1001 &data_word(0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4);
1002 &data_word(0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462);
1003 &data_word(0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5);
1004 &data_word(0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3);
1005 &data_word(0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b);
1006 &data_word(0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8);
1007 &data_word(0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6);
1008 &data_word(0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6);
1009 &data_word(0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0);
1010 &data_word(0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315);
1011 &data_word(0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f);
1012 &data_word(0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df);
1013 &data_word(0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f);
1014 &data_word(0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e);
1015 &data_word(0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13);
1016 &data_word(0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89);
1017 &data_word(0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c);
1018 &data_word(0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf);
1019 &data_word(0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886);
1020 &data_word(0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f);
1021 &data_word(0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41);
1022 &data_word(0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490);
1023 &data_word(0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042);
1024#Td2:
1025 &data_word(0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e);
1026 &data_word(0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303);
1027 &data_word(0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c);
1028 &data_word(0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3);
1029 &data_word(0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0);
1030 &data_word(0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9);
1031 &data_word(0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59);
1032 &data_word(0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8);
1033 &data_word(0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71);
1034 &data_word(0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a);
1035 &data_word(0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f);
1036 &data_word(0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b);
1037 &data_word(0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8);
1038 &data_word(0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab);
1039 &data_word(0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508);
1040 &data_word(0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82);
1041 &data_word(0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2);
1042 &data_word(0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe);
1043 &data_word(0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb);
1044 &data_word(0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110);
1045 &data_word(0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd);
1046 &data_word(0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15);
1047 &data_word(0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e);
1048 &data_word(0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee);
1049 &data_word(0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000);
1050 &data_word(0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72);
1051 &data_word(0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739);
1052 &data_word(0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e);
1053 &data_word(0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91);
1054 &data_word(0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a);
1055 &data_word(0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17);
1056 &data_word(0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9);
1057 &data_word(0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60);
1058 &data_word(0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e);
1059 &data_word(0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1);
1060 &data_word(0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011);
1061 &data_word(0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1);
1062 &data_word(0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3);
1063 &data_word(0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264);
1064 &data_word(0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90);
1065 &data_word(0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b);
1066 &data_word(0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf);
1067 &data_word(0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246);
1068 &data_word(0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af);
1069 &data_word(0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312);
1070 &data_word(0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb);
1071 &data_word(0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a);
1072 &data_word(0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8);
1073 &data_word(0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c);
1074 &data_word(0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066);
1075 &data_word(0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8);
1076 &data_word(0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6);
1077 &data_word(0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04);
1078 &data_word(0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51);
1079 &data_word(0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41);
1080 &data_word(0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347);
1081 &data_word(0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c);
1082 &data_word(0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1);
1083 &data_word(0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37);
1084 &data_word(0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db);
1085 &data_word(0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40);
1086 &data_word(0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195);
1087 &data_word(0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1);
1088 &data_word(0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257);
1089#Td3:
1090 &data_word(0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27);
1091 &data_word(0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3);
1092 &data_word(0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02);
1093 &data_word(0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362);
1094 &data_word(0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe);
1095 &data_word(0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3);
1096 &data_word(0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952);
1097 &data_word(0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9);
1098 &data_word(0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9);
1099 &data_word(0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace);
1100 &data_word(0x63184adf, 0xe582311a, 0x97603351, 0x62457f53);
1101 &data_word(0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08);
1102 &data_word(0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b);
1103 &data_word(0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55);
1104 &data_word(0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837);
1105 &data_word(0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216);
1106 &data_word(0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269);
1107 &data_word(0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6);
1108 &data_word(0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6);
1109 &data_word(0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e);
1110 &data_word(0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6);
1111 &data_word(0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550);
1112 &data_word(0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9);
1113 &data_word(0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8);
1114 &data_word(0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000);
1115 &data_word(0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a);
1116 &data_word(0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d);
1117 &data_word(0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36);
1118 &data_word(0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b);
1119 &data_word(0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12);
1120 &data_word(0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b);
1121 &data_word(0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e);
1122 &data_word(0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f);
1123 &data_word(0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb);
1124 &data_word(0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4);
1125 &data_word(0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6);
1126 &data_word(0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129);
1127 &data_word(0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1);
1128 &data_word(0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9);
1129 &data_word(0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033);
1130 &data_word(0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4);
1131 &data_word(0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad);
1132 &data_word(0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e);
1133 &data_word(0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3);
1134 &data_word(0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225);
1135 &data_word(0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b);
1136 &data_word(0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f);
1137 &data_word(0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815);
1138 &data_word(0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0);
1139 &data_word(0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2);
1140 &data_word(0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7);
1141 &data_word(0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691);
1142 &data_word(0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496);
1143 &data_word(0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165);
1144 &data_word(0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b);
1145 &data_word(0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6);
1146 &data_word(0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13);
1147 &data_word(0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147);
1148 &data_word(0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7);
1149 &data_word(0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44);
1150 &data_word(0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3);
1151 &data_word(0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d);
1152 &data_word(0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156);
1153 &data_word(0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8);
1154#Td4:
1155 &data_word(0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5);
1156 &data_word(0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838);
1157 &data_word(0xbfbfbfbf, 0x40404040, 0xa3a3a3a3, 0x9e9e9e9e);
1158 &data_word(0x81818181, 0xf3f3f3f3, 0xd7d7d7d7, 0xfbfbfbfb);
1159 &data_word(0x7c7c7c7c, 0xe3e3e3e3, 0x39393939, 0x82828282);
1160 &data_word(0x9b9b9b9b, 0x2f2f2f2f, 0xffffffff, 0x87878787);
1161 &data_word(0x34343434, 0x8e8e8e8e, 0x43434343, 0x44444444);
1162 &data_word(0xc4c4c4c4, 0xdededede, 0xe9e9e9e9, 0xcbcbcbcb);
1163 &data_word(0x54545454, 0x7b7b7b7b, 0x94949494, 0x32323232);
1164 &data_word(0xa6a6a6a6, 0xc2c2c2c2, 0x23232323, 0x3d3d3d3d);
1165 &data_word(0xeeeeeeee, 0x4c4c4c4c, 0x95959595, 0x0b0b0b0b);
1166 &data_word(0x42424242, 0xfafafafa, 0xc3c3c3c3, 0x4e4e4e4e);
1167 &data_word(0x08080808, 0x2e2e2e2e, 0xa1a1a1a1, 0x66666666);
1168 &data_word(0x28282828, 0xd9d9d9d9, 0x24242424, 0xb2b2b2b2);
1169 &data_word(0x76767676, 0x5b5b5b5b, 0xa2a2a2a2, 0x49494949);
1170 &data_word(0x6d6d6d6d, 0x8b8b8b8b, 0xd1d1d1d1, 0x25252525);
1171 &data_word(0x72727272, 0xf8f8f8f8, 0xf6f6f6f6, 0x64646464);
1172 &data_word(0x86868686, 0x68686868, 0x98989898, 0x16161616);
1173 &data_word(0xd4d4d4d4, 0xa4a4a4a4, 0x5c5c5c5c, 0xcccccccc);
1174 &data_word(0x5d5d5d5d, 0x65656565, 0xb6b6b6b6, 0x92929292);
1175 &data_word(0x6c6c6c6c, 0x70707070, 0x48484848, 0x50505050);
1176 &data_word(0xfdfdfdfd, 0xedededed, 0xb9b9b9b9, 0xdadadada);
1177 &data_word(0x5e5e5e5e, 0x15151515, 0x46464646, 0x57575757);
1178 &data_word(0xa7a7a7a7, 0x8d8d8d8d, 0x9d9d9d9d, 0x84848484);
1179 &data_word(0x90909090, 0xd8d8d8d8, 0xabababab, 0x00000000);
1180 &data_word(0x8c8c8c8c, 0xbcbcbcbc, 0xd3d3d3d3, 0x0a0a0a0a);
1181 &data_word(0xf7f7f7f7, 0xe4e4e4e4, 0x58585858, 0x05050505);
1182 &data_word(0xb8b8b8b8, 0xb3b3b3b3, 0x45454545, 0x06060606);
1183 &data_word(0xd0d0d0d0, 0x2c2c2c2c, 0x1e1e1e1e, 0x8f8f8f8f);
1184 &data_word(0xcacacaca, 0x3f3f3f3f, 0x0f0f0f0f, 0x02020202);
1185 &data_word(0xc1c1c1c1, 0xafafafaf, 0xbdbdbdbd, 0x03030303);
1186 &data_word(0x01010101, 0x13131313, 0x8a8a8a8a, 0x6b6b6b6b);
1187 &data_word(0x3a3a3a3a, 0x91919191, 0x11111111, 0x41414141);
1188 &data_word(0x4f4f4f4f, 0x67676767, 0xdcdcdcdc, 0xeaeaeaea);
1189 &data_word(0x97979797, 0xf2f2f2f2, 0xcfcfcfcf, 0xcececece);
1190 &data_word(0xf0f0f0f0, 0xb4b4b4b4, 0xe6e6e6e6, 0x73737373);
1191 &data_word(0x96969696, 0xacacacac, 0x74747474, 0x22222222);
1192 &data_word(0xe7e7e7e7, 0xadadadad, 0x35353535, 0x85858585);
1193 &data_word(0xe2e2e2e2, 0xf9f9f9f9, 0x37373737, 0xe8e8e8e8);
1194 &data_word(0x1c1c1c1c, 0x75757575, 0xdfdfdfdf, 0x6e6e6e6e);
1195 &data_word(0x47474747, 0xf1f1f1f1, 0x1a1a1a1a, 0x71717171);
1196 &data_word(0x1d1d1d1d, 0x29292929, 0xc5c5c5c5, 0x89898989);
1197 &data_word(0x6f6f6f6f, 0xb7b7b7b7, 0x62626262, 0x0e0e0e0e);
1198 &data_word(0xaaaaaaaa, 0x18181818, 0xbebebebe, 0x1b1b1b1b);
1199 &data_word(0xfcfcfcfc, 0x56565656, 0x3e3e3e3e, 0x4b4b4b4b);
1200 &data_word(0xc6c6c6c6, 0xd2d2d2d2, 0x79797979, 0x20202020);
1201 &data_word(0x9a9a9a9a, 0xdbdbdbdb, 0xc0c0c0c0, 0xfefefefe);
1202 &data_word(0x78787878, 0xcdcdcdcd, 0x5a5a5a5a, 0xf4f4f4f4);
1203 &data_word(0x1f1f1f1f, 0xdddddddd, 0xa8a8a8a8, 0x33333333);
1204 &data_word(0x88888888, 0x07070707, 0xc7c7c7c7, 0x31313131);
1205 &data_word(0xb1b1b1b1, 0x12121212, 0x10101010, 0x59595959);
1206 &data_word(0x27272727, 0x80808080, 0xecececec, 0x5f5f5f5f);
1207 &data_word(0x60606060, 0x51515151, 0x7f7f7f7f, 0xa9a9a9a9);
1208 &data_word(0x19191919, 0xb5b5b5b5, 0x4a4a4a4a, 0x0d0d0d0d);
1209 &data_word(0x2d2d2d2d, 0xe5e5e5e5, 0x7a7a7a7a, 0x9f9f9f9f);
1210 &data_word(0x93939393, 0xc9c9c9c9, 0x9c9c9c9c, 0xefefefef);
1211 &data_word(0xa0a0a0a0, 0xe0e0e0e0, 0x3b3b3b3b, 0x4d4d4d4d);
1212 &data_word(0xaeaeaeae, 0x2a2a2a2a, 0xf5f5f5f5, 0xb0b0b0b0);
1213 &data_word(0xc8c8c8c8, 0xebebebeb, 0xbbbbbbbb, 0x3c3c3c3c);
1214 &data_word(0x83838383, 0x53535353, 0x99999999, 0x61616161);
1215 &data_word(0x17171717, 0x2b2b2b2b, 0x04040404, 0x7e7e7e7e);
1216 &data_word(0xbabababa, 0x77777777, 0xd6d6d6d6, 0x26262626);
1217 &data_word(0xe1e1e1e1, 0x69696969, 0x14141414, 0x63636363);
1218 &data_word(0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d);
1219&function_end_B("AES_decrypt");
1220
1221sub enckey()
1222{
1223 &movz ("esi",&LB("edx")); # rk[i]>>0
1224 &mov ("ebx",&DWP(0,"ebp","esi",4));
1225 &movz ("esi",&HB("edx")); # rk[i]>>8
1226 &and ("ebx",0xFF000000);
1227 &xor ("eax","ebx");
1228
1229 &mov ("ebx",&DWP(0,"ebp","esi",4));
1230 &shr ("edx",16);
1231 &and ("ebx",0x000000FF);
1232 &movz ("esi",&LB("edx")); # rk[i]>>16
1233 &xor ("eax","ebx");
1234
1235 &mov ("ebx",&DWP(0,"ebp","esi",4));
1236 &movz ("esi",&HB("edx")); # rk[i]>>24
1237 &and ("ebx",0x0000FF00);
1238 &xor ("eax","ebx");
1239
1240 &mov ("ebx",&DWP(0,"ebp","esi",4));
1241 &and ("ebx",0x00FF0000);
1242 &xor ("eax","ebx");
1243
1244 &xor ("eax",&DWP(1024,"ebp","ecx",4)); # rcon
1245}
1246
1247# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
1248# AES_KEY *key)
1249&public_label("AES_Te");
1250&function_begin("AES_set_encrypt_key");
1251 &mov ("esi",&wparam(0)); # user supplied key
1252 &mov ("edi",&wparam(2)); # private key schedule
1253
1254 &test ("esi",-1);
1255 &jz (&label("badpointer"));
1256 &test ("edi",-1);
1257 &jz (&label("badpointer"));
1258
1259 &call (&label("pic_point"));
1260 &set_label("pic_point");
1261 &blindpop("ebp");
1262 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
1263 &add ("ebp",1024*4); # skip to Te4
1264
1265 &mov ("ecx",&wparam(1)); # number of bits in key
1266 &cmp ("ecx",128);
1267 &je (&label("10rounds"));
1268 &cmp ("ecx",192);
1269 &je (&label("12rounds"));
1270 &cmp ("ecx",256);
1271 &je (&label("14rounds"));
1272 &mov ("eax",-2); # invalid number of bits
1273 &jmp (&label("exit"));
1274
1275 &set_label("10rounds");
1276 &mov ("eax",&DWP(0,"esi")); # copy first 4 dwords
1277 &mov ("ebx",&DWP(4,"esi"));
1278 &mov ("ecx",&DWP(8,"esi"));
1279 &mov ("edx",&DWP(12,"esi"));
1280 &mov (&DWP(0,"edi"),"eax");
1281 &mov (&DWP(4,"edi"),"ebx");
1282 &mov (&DWP(8,"edi"),"ecx");
1283 &mov (&DWP(12,"edi"),"edx");
1284
1285 &xor ("ecx","ecx");
1286 &jmp (&label("10shortcut"));
1287
1288 &align (4);
1289 &set_label("10loop");
1290 &mov ("eax",&DWP(0,"edi")); # rk[0]
1291 &mov ("edx",&DWP(12,"edi")); # rk[3]
1292 &set_label("10shortcut");
1293 &enckey ();
1294
1295 &mov (&DWP(16,"edi"),"eax"); # rk[4]
1296 &xor ("eax",&DWP(4,"edi"));
1297 &mov (&DWP(20,"edi"),"eax"); # rk[5]
1298 &xor ("eax",&DWP(8,"edi"));
1299 &mov (&DWP(24,"edi"),"eax"); # rk[6]
1300 &xor ("eax",&DWP(12,"edi"));
1301 &mov (&DWP(28,"edi"),"eax"); # rk[7]
1302 &inc ("ecx");
1303 &add ("edi",16);
1304 &cmp ("ecx",10);
1305 &jl (&label("10loop"));
1306
1307 &mov (&DWP(80,"edi"),10); # setup number of rounds
1308 &xor ("eax","eax");
1309 &jmp (&label("exit"));
1310
1311 &set_label("12rounds");
1312 &mov ("eax",&DWP(0,"esi")); # copy first 6 dwords
1313 &mov ("ebx",&DWP(4,"esi"));
1314 &mov ("ecx",&DWP(8,"esi"));
1315 &mov ("edx",&DWP(12,"esi"));
1316 &mov (&DWP(0,"edi"),"eax");
1317 &mov (&DWP(4,"edi"),"ebx");
1318 &mov (&DWP(8,"edi"),"ecx");
1319 &mov (&DWP(12,"edi"),"edx");
1320 &mov ("ecx",&DWP(16,"esi"));
1321 &mov ("edx",&DWP(20,"esi"));
1322 &mov (&DWP(16,"edi"),"ecx");
1323 &mov (&DWP(20,"edi"),"edx");
1324
1325 &xor ("ecx","ecx");
1326 &jmp (&label("12shortcut"));
1327
1328 &align (4);
1329 &set_label("12loop");
1330 &mov ("eax",&DWP(0,"edi")); # rk[0]
1331 &mov ("edx",&DWP(20,"edi")); # rk[5]
1332 &set_label("12shortcut");
1333 &enckey ();
1334
1335 &mov (&DWP(24,"edi"),"eax"); # rk[6]
1336 &xor ("eax",&DWP(4,"edi"));
1337 &mov (&DWP(28,"edi"),"eax"); # rk[7]
1338 &xor ("eax",&DWP(8,"edi"));
1339 &mov (&DWP(32,"edi"),"eax"); # rk[8]
1340 &xor ("eax",&DWP(12,"edi"));
1341 &mov (&DWP(36,"edi"),"eax"); # rk[9]
1342
1343 &cmp ("ecx",7);
1344 &je (&label("12break"));
1345 &inc ("ecx");
1346
1347 &xor ("eax",&DWP(16,"edi"));
1348 &mov (&DWP(40,"edi"),"eax"); # rk[10]
1349 &xor ("eax",&DWP(20,"edi"));
1350 &mov (&DWP(44,"edi"),"eax"); # rk[11]
1351
1352 &add ("edi",24);
1353 &jmp (&label("12loop"));
1354
1355 &set_label("12break");
1356 &mov (&DWP(72,"edi"),12); # setup number of rounds
1357 &xor ("eax","eax");
1358 &jmp (&label("exit"));
1359
1360 &set_label("14rounds");
1361 &mov ("eax",&DWP(0,"esi")); # copy first 8 dwords
1362 &mov ("ebx",&DWP(4,"esi"));
1363 &mov ("ecx",&DWP(8,"esi"));
1364 &mov ("edx",&DWP(12,"esi"));
1365 &mov (&DWP(0,"edi"),"eax");
1366 &mov (&DWP(4,"edi"),"ebx");
1367 &mov (&DWP(8,"edi"),"ecx");
1368 &mov (&DWP(12,"edi"),"edx");
1369 &mov ("eax",&DWP(16,"esi"));
1370 &mov ("ebx",&DWP(20,"esi"));
1371 &mov ("ecx",&DWP(24,"esi"));
1372 &mov ("edx",&DWP(28,"esi"));
1373 &mov (&DWP(16,"edi"),"eax");
1374 &mov (&DWP(20,"edi"),"ebx");
1375 &mov (&DWP(24,"edi"),"ecx");
1376 &mov (&DWP(28,"edi"),"edx");
1377
1378 &xor ("ecx","ecx");
1379 &jmp (&label("14shortcut"));
1380
1381 &align (4);
1382 &set_label("14loop");
1383 &mov ("edx",&DWP(28,"edi")); # rk[7]
1384 &set_label("14shortcut");
1385 &mov ("eax",&DWP(0,"edi")); # rk[0]
1386
1387 &enckey ();
1388
1389 &mov (&DWP(32,"edi"),"eax"); # rk[8]
1390 &xor ("eax",&DWP(4,"edi"));
1391 &mov (&DWP(36,"edi"),"eax"); # rk[9]
1392 &xor ("eax",&DWP(8,"edi"));
1393 &mov (&DWP(40,"edi"),"eax"); # rk[10]
1394 &xor ("eax",&DWP(12,"edi"));
1395 &mov (&DWP(44,"edi"),"eax"); # rk[11]
1396
1397 &cmp ("ecx",6);
1398 &je (&label("14break"));
1399 &inc ("ecx");
1400
1401 &mov ("edx","eax");
1402 &mov ("eax",&DWP(16,"edi")); # rk[4]
1403 &movz ("esi",&LB("edx")); # rk[11]>>0
1404 &mov ("ebx",&DWP(0,"ebp","esi",4));
1405 &movz ("esi",&HB("edx")); # rk[11]>>8
1406 &and ("ebx",0x000000FF);
1407 &xor ("eax","ebx");
1408
1409 &mov ("ebx",&DWP(0,"ebp","esi",4));
1410 &shr ("edx",16);
1411 &and ("ebx",0x0000FF00);
1412 &movz ("esi",&LB("edx")); # rk[11]>>16
1413 &xor ("eax","ebx");
1414
1415 &mov ("ebx",&DWP(0,"ebp","esi",4));
1416 &movz ("esi",&HB("edx")); # rk[11]>>24
1417 &and ("ebx",0x00FF0000);
1418 &xor ("eax","ebx");
1419
1420 &mov ("ebx",&DWP(0,"ebp","esi",4));
1421 &and ("ebx",0xFF000000);
1422 &xor ("eax","ebx");
1423
1424 &mov (&DWP(48,"edi"),"eax"); # rk[12]
1425 &xor ("eax",&DWP(20,"edi"));
1426 &mov (&DWP(52,"edi"),"eax"); # rk[13]
1427 &xor ("eax",&DWP(24,"edi"));
1428 &mov (&DWP(56,"edi"),"eax"); # rk[14]
1429 &xor ("eax",&DWP(28,"edi"));
1430 &mov (&DWP(60,"edi"),"eax"); # rk[15]
1431
1432 &add ("edi",32);
1433 &jmp (&label("14loop"));
1434
1435 &set_label("14break");
1436 &mov (&DWP(48,"edi"),14); # setup number of rounds
1437 &xor ("eax","eax");
1438 &jmp (&label("exit"));
1439
1440 &set_label("badpointer");
1441 &mov ("eax",-1);
1442 &set_label("exit");
1443&function_end("AES_set_encrypt_key");
1444
1445sub deckey()
1446{ my ($i,$ptr,$te4,$td) = @_;
1447
1448 &mov ("eax",&DWP($i,$ptr));
1449 &mov ("edx","eax");
1450 &movz ("ebx",&HB("eax"));
1451 &shr ("edx",16);
1452 &and ("eax",0xFF);
1453 &movz ("eax",&BP(0,$te4,"eax",4));
1454 &movz ("ebx",&BP(0,$te4,"ebx",4));
1455 &mov ("eax",&DWP(1024*0,$td,"eax",4));
1456 &xor ("eax",&DWP(1024*1,$td,"ebx",4));
1457 &movz ("ebx",&HB("edx"));
1458 &and ("edx",0xFF);
1459 &movz ("edx",&BP(0,$te4,"edx",4));
1460 &movz ("ebx",&BP(0,$te4,"ebx",4));
1461 &xor ("eax",&DWP(1024*2,$td,"edx",4));
1462 &xor ("eax",&DWP(1024*3,$td,"ebx",4));
1463 &mov (&DWP($i,$ptr),"eax");
1464}
1465
1466# int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
1467# AES_KEY *key)
1468&public_label("AES_Td");
1469&public_label("AES_Te");
1470&function_begin_B("AES_set_decrypt_key");
1471 &mov ("eax",&wparam(0));
1472 &mov ("ecx",&wparam(1));
1473 &mov ("edx",&wparam(2));
1474 &sub ("esp",12);
1475 &mov (&DWP(0,"esp"),"eax");
1476 &mov (&DWP(4,"esp"),"ecx");
1477 &mov (&DWP(8,"esp"),"edx");
1478 &call ("AES_set_encrypt_key");
1479 &add ("esp",12);
1480 &cmp ("eax",0);
1481 &je (&label("proceed"));
1482 &ret ();
1483
1484 &set_label("proceed");
1485 &push ("ebp");
1486 &push ("ebx");
1487 &push ("esi");
1488 &push ("edi");
1489
1490 &mov ("esi",&wparam(2));
1491 &mov ("ecx",&DWP(240,"esi")); # pull number of rounds
1492 &lea ("ecx",&DWP(0,"","ecx",4));
1493 &lea ("edi",&DWP(0,"esi","ecx",4)); # pointer to last chunk
1494
1495 &align (4);
1496 &set_label("invert"); # invert order of chunks
1497 &mov ("eax",&DWP(0,"esi"));
1498 &mov ("ebx",&DWP(4,"esi"));
1499 &mov ("ecx",&DWP(0,"edi"));
1500 &mov ("edx",&DWP(4,"edi"));
1501 &mov (&DWP(0,"edi"),"eax");
1502 &mov (&DWP(4,"edi"),"ebx");
1503 &mov (&DWP(0,"esi"),"ecx");
1504 &mov (&DWP(4,"esi"),"edx");
1505 &mov ("eax",&DWP(8,"esi"));
1506 &mov ("ebx",&DWP(12,"esi"));
1507 &mov ("ecx",&DWP(8,"edi"));
1508 &mov ("edx",&DWP(12,"edi"));
1509 &mov (&DWP(8,"edi"),"eax");
1510 &mov (&DWP(12,"edi"),"ebx");
1511 &mov (&DWP(8,"esi"),"ecx");
1512 &mov (&DWP(12,"esi"),"edx");
1513 &add ("esi",16);
1514 &sub ("edi",16);
1515 &cmp ("esi","edi");
1516 &jne (&label("invert"));
1517
1518 &call (&label("pic_point"));
1519 &set_label("pic_point");
1520 blindpop("ebp");
1521 &lea ("edi",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
1522 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
1523 &add ("ebp",1024*4); # skip to Te4
1524
1525 &mov ("esi",&wparam(2));
1526 &mov ("ecx",&DWP(240,"esi")); # pull number of rounds
1527 &dec ("ecx");
1528 &align (4);
1529 &set_label("permute"); # permute the key schedule
1530 &add ("esi",16);
1531 &deckey (0,"esi","ebp","edi");
1532 &deckey (4,"esi","ebp","edi");
1533 &deckey (8,"esi","ebp","edi");
1534 &deckey (12,"esi","ebp","edi");
1535 &dec ("ecx");
1536 &jnz (&label("permute"));
1537
1538 &xor ("eax","eax"); # return success
1539&function_end("AES_set_decrypt_key");
1540
1541&asm_finish();
diff --git a/src/lib/libcrypto/asn1/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
new file mode 100644
index 0000000000..b81bf4fc81
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -0,0 +1,222 @@
1/* crypto/asn1/a_bitstr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
64{ return M_ASN1_BIT_STRING_set(x, d, len); }
65
66int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
67 {
68 int ret,j,bits,len;
69 unsigned char *p,*d;
70
71 if (a == NULL) return(0);
72
73 len=a->length;
74
75 if (len > 0)
76 {
77 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
78 {
79 bits=(int)a->flags&0x07;
80 }
81 else
82 {
83 for ( ; len > 0; len--)
84 {
85 if (a->data[len-1]) break;
86 }
87 j=a->data[len-1];
88 if (j & 0x01) bits=0;
89 else if (j & 0x02) bits=1;
90 else if (j & 0x04) bits=2;
91 else if (j & 0x08) bits=3;
92 else if (j & 0x10) bits=4;
93 else if (j & 0x20) bits=5;
94 else if (j & 0x40) bits=6;
95 else if (j & 0x80) bits=7;
96 else bits=0; /* should not happen */
97 }
98 }
99 else
100 bits=0;
101
102 ret=1+len;
103 if (pp == NULL) return(ret);
104
105 p= *pp;
106
107 *(p++)=(unsigned char)bits;
108 d=a->data;
109 memcpy(p,d,len);
110 p+=len;
111 if (len > 0) p[-1]&=(0xff<<bits);
112 *pp=p;
113 return(ret);
114 }
115
116ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
117 long len)
118 {
119 ASN1_BIT_STRING *ret=NULL;
120 unsigned char *p,*s;
121 int i;
122
123 if (len < 1)
124 {
125 i=ASN1_R_STRING_TOO_SHORT;
126 goto err;
127 }
128
129 if ((a == NULL) || ((*a) == NULL))
130 {
131 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
132 }
133 else
134 ret=(*a);
135
136 p= *pp;
137 i= *(p++);
138 /* We do this to preserve the settings. If we modify
139 * the settings, via the _set_bit function, we will recalculate
140 * on output */
141 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
142 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
143
144 if (len-- > 1) /* using one because of the bits left byte */
145 {
146 s=(unsigned char *)OPENSSL_malloc((int)len);
147 if (s == NULL)
148 {
149 i=ERR_R_MALLOC_FAILURE;
150 goto err;
151 }
152 memcpy(s,p,(int)len);
153 s[len-1]&=(0xff<<i);
154 p+=len;
155 }
156 else
157 s=NULL;
158
159 ret->length=(int)len;
160 if (ret->data != NULL) OPENSSL_free(ret->data);
161 ret->data=s;
162 ret->type=V_ASN1_BIT_STRING;
163 if (a != NULL) (*a)=ret;
164 *pp=p;
165 return(ret);
166err:
167 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
168 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
169 M_ASN1_BIT_STRING_free(ret);
170 return(NULL);
171 }
172
173/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
174 */
175int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
176 {
177 int w,v,iv;
178 unsigned char *c;
179
180 w=n/8;
181 v=1<<(7-(n&0x07));
182 iv= ~v;
183 if (!value) v=0;
184
185 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
186
187 if (a == NULL) return(0);
188 if ((a->length < (w+1)) || (a->data == NULL))
189 {
190 if (!value) return(1); /* Don't need to set */
191 if (a->data == NULL)
192 c=(unsigned char *)OPENSSL_malloc(w+1);
193 else
194 c=(unsigned char *)OPENSSL_realloc_clean(a->data,
195 a->length,
196 w+1);
197 if (c == NULL)
198 {
199 ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE);
200 return 0;
201 }
202 if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
203 a->data=c;
204 a->length=w+1;
205 }
206 a->data[w]=((a->data[w])&iv)|v;
207 while ((a->length > 0) && (a->data[a->length-1] == 0))
208 a->length--;
209 return(1);
210 }
211
212int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
213 {
214 int w,v;
215
216 w=n/8;
217 v=1<<(7-(n&0x07));
218 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
219 return(0);
220 return((a->data[w]&v) != 0);
221 }
222
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
new file mode 100644
index 0000000000..24333ea4d5
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_bool.c
@@ -0,0 +1,114 @@
1/* crypto/asn1/a_bool.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
64 {
65 int r;
66 unsigned char *p;
67
68 r=ASN1_object_size(0,1,V_ASN1_BOOLEAN);
69 if (pp == NULL) return(r);
70 p= *pp;
71
72 ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL);
73 *(p++)= (unsigned char)a;
74 *pp=p;
75 return(r);
76 }
77
78int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length)
79 {
80 int ret= -1;
81 unsigned char *p;
82 long len;
83 int inf,tag,xclass;
84 int i=0;
85
86 p= *pp;
87 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
88 if (inf & 0x80)
89 {
90 i=ASN1_R_BAD_OBJECT_HEADER;
91 goto err;
92 }
93
94 if (tag != V_ASN1_BOOLEAN)
95 {
96 i=ASN1_R_EXPECTING_A_BOOLEAN;
97 goto err;
98 }
99
100 if (len != 1)
101 {
102 i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
103 goto err;
104 }
105 ret= (int)*(p++);
106 if (a != NULL) (*a)=ret;
107 *pp=p;
108 return(ret);
109err:
110 ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i);
111 return(ret);
112 }
113
114
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
new file mode 100644
index 0000000000..2407f7c87a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -0,0 +1,312 @@
1/* crypto/asn1/a_bytes.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
64/* type is a 'bitmap' of acceptable string types.
65 */
66ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
67 long length, int type)
68 {
69 ASN1_STRING *ret=NULL;
70 unsigned char *p,*s;
71 long len;
72 int inf,tag,xclass;
73 int i=0;
74
75 p= *pp;
76 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
77 if (inf & 0x80) goto err;
78
79 if (tag >= 32)
80 {
81 i=ASN1_R_TAG_VALUE_TOO_HIGH;
82 goto err;
83 }
84 if (!(ASN1_tag2bit(tag) & type))
85 {
86 i=ASN1_R_WRONG_TYPE;
87 goto err;
88 }
89
90 /* If a bit-string, exit early */
91 if (tag == V_ASN1_BIT_STRING)
92 return(d2i_ASN1_BIT_STRING(a,pp,length));
93
94 if ((a == NULL) || ((*a) == NULL))
95 {
96 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
97 }
98 else
99 ret=(*a);
100
101 if (len != 0)
102 {
103 s=(unsigned char *)OPENSSL_malloc((int)len+1);
104 if (s == NULL)
105 {
106 i=ERR_R_MALLOC_FAILURE;
107 goto err;
108 }
109 memcpy(s,p,(int)len);
110 s[len]='\0';
111 p+=len;
112 }
113 else
114 s=NULL;
115
116 if (ret->data != NULL) OPENSSL_free(ret->data);
117 ret->length=(int)len;
118 ret->data=s;
119 ret->type=tag;
120 if (a != NULL) (*a)=ret;
121 *pp=p;
122 return(ret);
123err:
124 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i);
125 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
126 ASN1_STRING_free(ret);
127 return(NULL);
128 }
129
130int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
131 {
132 int ret,r,constructed;
133 unsigned char *p;
134
135 if (a == NULL) return(0);
136
137 if (tag == V_ASN1_BIT_STRING)
138 return(i2d_ASN1_BIT_STRING(a,pp));
139
140 ret=a->length;
141 r=ASN1_object_size(0,ret,tag);
142 if (pp == NULL) return(r);
143 p= *pp;
144
145 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
146 constructed=1;
147 else
148 constructed=0;
149 ASN1_put_object(&p,constructed,ret,tag,xclass);
150 memcpy(p,a->data,a->length);
151 p+=a->length;
152 *pp= p;
153 return(r);
154 }
155
156ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
157 int Ptag, int Pclass)
158 {
159 ASN1_STRING *ret=NULL;
160 unsigned char *p,*s;
161 long len;
162 int inf,tag,xclass;
163 int i=0;
164
165 if ((a == NULL) || ((*a) == NULL))
166 {
167 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
168 }
169 else
170 ret=(*a);
171
172 p= *pp;
173 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
174 if (inf & 0x80)
175 {
176 i=ASN1_R_BAD_OBJECT_HEADER;
177 goto err;
178 }
179
180 if (tag != Ptag)
181 {
182 i=ASN1_R_WRONG_TAG;
183 goto err;
184 }
185
186 if (inf & V_ASN1_CONSTRUCTED)
187 {
188 ASN1_CTX c;
189
190 c.pp=pp;
191 c.p=p;
192 c.inf=inf;
193 c.slen=len;
194 c.tag=Ptag;
195 c.xclass=Pclass;
196 c.max=(length == 0)?0:(p+length);
197 if (!asn1_collate_primitive(ret,&c))
198 goto err;
199 else
200 {
201 p=c.p;
202 }
203 }
204 else
205 {
206 if (len != 0)
207 {
208 if ((ret->length < len) || (ret->data == NULL))
209 {
210 if (ret->data != NULL) OPENSSL_free(ret->data);
211 s=(unsigned char *)OPENSSL_malloc((int)len + 1);
212 if (s == NULL)
213 {
214 i=ERR_R_MALLOC_FAILURE;
215 goto err;
216 }
217 }
218 else
219 s=ret->data;
220 memcpy(s,p,(int)len);
221 s[len] = '\0';
222 p+=len;
223 }
224 else
225 {
226 s=NULL;
227 if (ret->data != NULL) OPENSSL_free(ret->data);
228 }
229
230 ret->length=(int)len;
231 ret->data=s;
232 ret->type=Ptag;
233 }
234
235 if (a != NULL) (*a)=ret;
236 *pp=p;
237 return(ret);
238err:
239 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
240 ASN1_STRING_free(ret);
241 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
242 return(NULL);
243 }
244
245
246/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
247 * them into the one structure that is then returned */
248/* There have been a few bug fixes for this function from
249 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
250static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
251 {
252 ASN1_STRING *os=NULL;
253 BUF_MEM b;
254 int num;
255
256 b.length=0;
257 b.max=0;
258 b.data=NULL;
259
260 if (a == NULL)
261 {
262 c->error=ERR_R_PASSED_NULL_PARAMETER;
263 goto err;
264 }
265
266 num=0;
267 for (;;)
268 {
269 if (c->inf & 1)
270 {
271 c->eos=ASN1_check_infinite_end(&c->p,
272 (long)(c->max-c->p));
273 if (c->eos) break;
274 }
275 else
276 {
277 if (c->slen <= 0) break;
278 }
279
280 c->q=c->p;
281 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
282 == NULL)
283 {
284 c->error=ERR_R_ASN1_LIB;
285 goto err;
286 }
287
288 if (!BUF_MEM_grow_clean(&b,num+os->length))
289 {
290 c->error=ERR_R_BUF_LIB;
291 goto err;
292 }
293 memcpy(&(b.data[num]),os->data,os->length);
294 if (!(c->inf & 1))
295 c->slen-=(c->p-c->q);
296 num+=os->length;
297 }
298
299 if (!asn1_Finish(c)) goto err;
300
301 a->length=num;
302 if (a->data != NULL) OPENSSL_free(a->data);
303 a->data=(unsigned char *)b.data;
304 if (os != NULL) ASN1_STRING_free(os);
305 return(1);
306err:
307 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
308 if (os != NULL) ASN1_STRING_free(os);
309 if (b.data != NULL) OPENSSL_free(b.data);
310 return(0);
311 }
312
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
new file mode 100644
index 0000000000..b67b75e7c2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_d2i_fp.c
@@ -0,0 +1,262 @@
1/* crypto/asn1/a_d2i_fp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1_mac.h>
63
64static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
65
66#ifndef NO_OLD_ASN1
67#ifndef OPENSSL_NO_FP_API
68
69char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
70 unsigned char **x)
71 {
72 BIO *b;
73 char *ret;
74
75 if ((b=BIO_new(BIO_s_file())) == NULL)
76 {
77 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
78 return(NULL);
79 }
80 BIO_set_fp(b,in,BIO_NOCLOSE);
81 ret=ASN1_d2i_bio(xnew,d2i,b,x);
82 BIO_free(b);
83 return(ret);
84 }
85#endif
86
87char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
88 unsigned char **x)
89 {
90 BUF_MEM *b = NULL;
91 unsigned char *p;
92 char *ret=NULL;
93 int len;
94
95 len = asn1_d2i_read_bio(in, &b);
96 if(len < 0) goto err;
97
98 p=(unsigned char *)b->data;
99 ret=d2i(x,&p,len);
100err:
101 if (b != NULL) BUF_MEM_free(b);
102 return(ret);
103 }
104
105#endif
106
107void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
108 {
109 BUF_MEM *b = NULL;
110 unsigned char *p;
111 void *ret=NULL;
112 int len;
113
114 len = asn1_d2i_read_bio(in, &b);
115 if(len < 0) goto err;
116
117 p=(unsigned char *)b->data;
118 ret=ASN1_item_d2i(x,&p,len, it);
119err:
120 if (b != NULL) BUF_MEM_free(b);
121 return(ret);
122 }
123
124#ifndef OPENSSL_NO_FP_API
125void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
126 {
127 BIO *b;
128 char *ret;
129
130 if ((b=BIO_new(BIO_s_file())) == NULL)
131 {
132 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
133 return(NULL);
134 }
135 BIO_set_fp(b,in,BIO_NOCLOSE);
136 ret=ASN1_item_d2i_bio(it,b,x);
137 BIO_free(b);
138 return(ret);
139 }
140#endif
141
142#define HEADER_SIZE 8
143static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
144 {
145 BUF_MEM *b;
146 unsigned char *p;
147 int i;
148 int ret=-1;
149 ASN1_CTX c;
150 int want=HEADER_SIZE;
151 int eos=0;
152#if defined(__GNUC__) && defined(__ia64)
153 /* pathetic compiler bug in all known versions as of Nov. 2002 */
154 long off=0;
155#else
156 int off=0;
157#endif
158 int len=0;
159
160 b=BUF_MEM_new();
161 if (b == NULL)
162 {
163 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
164 return -1;
165 }
166
167 ERR_clear_error();
168 for (;;)
169 {
170 if (want >= (len-off))
171 {
172 want-=(len-off);
173
174 if (!BUF_MEM_grow_clean(b,len+want))
175 {
176 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
177 goto err;
178 }
179 i=BIO_read(in,&(b->data[len]),want);
180 if ((i < 0) && ((len-off) == 0))
181 {
182 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
183 goto err;
184 }
185 if (i > 0)
186 len+=i;
187 }
188 /* else data already loaded */
189
190 p=(unsigned char *)&(b->data[off]);
191 c.p=p;
192 c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass),
193 len-off);
194 if (c.inf & 0x80)
195 {
196 unsigned long e;
197
198 e=ERR_GET_REASON(ERR_peek_error());
199 if (e != ASN1_R_TOO_LONG)
200 goto err;
201 else
202 ERR_get_error(); /* clear error */
203 }
204 i=c.p-p;/* header length */
205 off+=i; /* end of data */
206
207 if (c.inf & 1)
208 {
209 /* no data body so go round again */
210 eos++;
211 want=HEADER_SIZE;
212 }
213 else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC))
214 {
215 /* eos value, so go back and read another header */
216 eos--;
217 if (eos <= 0)
218 break;
219 else
220 want=HEADER_SIZE;
221 }
222 else
223 {
224 /* suck in c.slen bytes of data */
225 want=(int)c.slen;
226 if (want > (len-off))
227 {
228 want-=(len-off);
229 if (!BUF_MEM_grow_clean(b,len+want))
230 {
231 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
232 goto err;
233 }
234 while (want > 0)
235 {
236 i=BIO_read(in,&(b->data[len]),want);
237 if (i <= 0)
238 {
239 ASN1err(ASN1_F_ASN1_D2I_BIO,
240 ASN1_R_NOT_ENOUGH_DATA);
241 goto err;
242 }
243 len+=i;
244 want -= i;
245 }
246 }
247 off+=(int)c.slen;
248 if (eos <= 0)
249 {
250 break;
251 }
252 else
253 want=HEADER_SIZE;
254 }
255 }
256
257 *pb = b;
258 return off;
259err:
260 if (b != NULL) BUF_MEM_free(b);
261 return(ret);
262 }
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
new file mode 100644
index 0000000000..7182e9fa5d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_digest.c
@@ -0,0 +1,111 @@
1/* crypto/asn1/a_digest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/err.h>
69#include <openssl/evp.h>
70#include <openssl/buffer.h>
71#include <openssl/x509.h>
72
73#ifndef NO_ASN1_OLD
74
75int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
76 unsigned char *md, unsigned int *len)
77 {
78 int i;
79 unsigned char *str,*p;
80
81 i=i2d(data,NULL);
82 if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL)
83 {
84 ASN1err(ASN1_F_ASN1_DIGEST,ERR_R_MALLOC_FAILURE);
85 return(0);
86 }
87 p=str;
88 i2d(data,&p);
89
90 EVP_Digest(str, i, md, len, type, NULL);
91 OPENSSL_free(str);
92 return(1);
93 }
94
95#endif
96
97
98int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
99 unsigned char *md, unsigned int *len)
100 {
101 int i;
102 unsigned char *str = NULL;
103
104 i=ASN1_item_i2d(asn,&str, it);
105 if (!str) return(0);
106
107 EVP_Digest(str, i, md, len, type, NULL);
108 OPENSSL_free(str);
109 return(1);
110 }
111
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
new file mode 100644
index 0000000000..58a017884c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_dup.c
@@ -0,0 +1,107 @@
1/* crypto/asn1/a_dup.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63#ifndef NO_OLD_ASN1
64
65char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
66 {
67 unsigned char *b,*p;
68 long i;
69 char *ret;
70
71 if (x == NULL) return(NULL);
72
73 i=(long)i2d(x,NULL);
74 b=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
75 if (b == NULL)
76 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
77 p= b;
78 i=i2d(x,&p);
79 p= b;
80 ret=d2i(NULL,&p,i);
81 OPENSSL_free(b);
82 return(ret);
83 }
84
85#endif
86
87/* ASN1_ITEM version of dup: this follows the model above except we don't need
88 * to allocate the buffer. At some point this could be rewritten to directly dup
89 * the underlying structure instead of doing and encode and decode.
90 */
91
92void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
93 {
94 unsigned char *b = NULL, *p;
95 long i;
96 void *ret;
97
98 if (x == NULL) return(NULL);
99
100 i=ASN1_item_i2d(x,&b,it);
101 if (b == NULL)
102 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
103 p= b;
104 ret=ASN1_item_d2i(NULL,&p,i, it);
105 OPENSSL_free(b);
106 return(ret);
107 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
new file mode 100644
index 0000000000..03ede68d1c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -0,0 +1,180 @@
1/* crypto/asn1/a_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/*
64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
65 * for comments on encoding see a_int.c
66 */
67
68int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
69 {
70 int i,j,k;
71 unsigned char buf[sizeof(long)+1];
72 long d;
73
74 a->type=V_ASN1_ENUMERATED;
75 if (a->length < (sizeof(long)+1))
76 {
77 if (a->data != NULL)
78 OPENSSL_free(a->data);
79 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
80 memset((char *)a->data,0,sizeof(long)+1);
81 }
82 if (a->data == NULL)
83 {
84 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
85 return(0);
86 }
87 d=v;
88 if (d < 0)
89 {
90 d= -d;
91 a->type=V_ASN1_NEG_ENUMERATED;
92 }
93
94 for (i=0; i<sizeof(long); i++)
95 {
96 if (d == 0) break;
97 buf[i]=(int)d&0xff;
98 d>>=8;
99 }
100 j=0;
101 for (k=i-1; k >=0; k--)
102 a->data[j++]=buf[k];
103 a->length=j;
104 return(1);
105 }
106
107long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
108 {
109 int neg=0,i;
110 long r=0;
111
112 if (a == NULL) return(0L);
113 i=a->type;
114 if (i == V_ASN1_NEG_ENUMERATED)
115 neg=1;
116 else if (i != V_ASN1_ENUMERATED)
117 return -1;
118
119 if (a->length > sizeof(long))
120 {
121 /* hmm... a bit ugly */
122 return(0xffffffffL);
123 }
124 if (a->data == NULL)
125 return 0;
126
127 for (i=0; i<a->length; i++)
128 {
129 r<<=8;
130 r|=(unsigned char)a->data[i];
131 }
132 if (neg) r= -r;
133 return(r);
134 }
135
136ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
137 {
138 ASN1_ENUMERATED *ret;
139 int len,j;
140
141 if (ai == NULL)
142 ret=M_ASN1_ENUMERATED_new();
143 else
144 ret=ai;
145 if (ret == NULL)
146 {
147 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
148 goto err;
149 }
150 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
151 else ret->type=V_ASN1_ENUMERATED;
152 j=BN_num_bits(bn);
153 len=((j == 0)?0:((j/8)+1));
154 if (ret->length < len+4)
155 {
156 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
157 if (!new_data)
158 {
159 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
160 goto err;
161 }
162 ret->data=new_data;
163 }
164
165 ret->length=BN_bn2bin(bn,ret->data);
166 return(ret);
167err:
168 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
169 return(NULL);
170 }
171
172BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
173 {
174 BIGNUM *ret;
175
176 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
177 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
178 else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
179 return(ret);
180 }
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
new file mode 100644
index 0000000000..f4f1b73ebe
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.c
@@ -0,0 +1,163 @@
1/* crypto/asn1/a_i2d_fp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64#ifndef NO_OLD_ASN1
65
66#ifndef OPENSSL_NO_FP_API
67int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
68 {
69 BIO *b;
70 int ret;
71
72 if ((b=BIO_new(BIO_s_file())) == NULL)
73 {
74 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
75 return(0);
76 }
77 BIO_set_fp(b,out,BIO_NOCLOSE);
78 ret=ASN1_i2d_bio(i2d,b,x);
79 BIO_free(b);
80 return(ret);
81 }
82#endif
83
84int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
85 {
86 char *b;
87 unsigned char *p;
88 int i,j=0,n,ret=1;
89
90 n=i2d(x,NULL);
91 b=(char *)OPENSSL_malloc(n);
92 if (b == NULL)
93 {
94 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
95 return(0);
96 }
97
98 p=(unsigned char *)b;
99 i2d(x,&p);
100
101 for (;;)
102 {
103 i=BIO_write(out,&(b[j]),n);
104 if (i == n) break;
105 if (i <= 0)
106 {
107 ret=0;
108 break;
109 }
110 j+=i;
111 n-=i;
112 }
113 OPENSSL_free(b);
114 return(ret);
115 }
116
117#endif
118
119#ifndef OPENSSL_NO_FP_API
120int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
121 {
122 BIO *b;
123 int ret;
124
125 if ((b=BIO_new(BIO_s_file())) == NULL)
126 {
127 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
128 return(0);
129 }
130 BIO_set_fp(b,out,BIO_NOCLOSE);
131 ret=ASN1_item_i2d_bio(it,b,x);
132 BIO_free(b);
133 return(ret);
134 }
135#endif
136
137int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
138 {
139 unsigned char *b = NULL;
140 int i,j=0,n,ret=1;
141
142 n = ASN1_item_i2d(x, &b, it);
143 if (b == NULL)
144 {
145 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
146 return(0);
147 }
148
149 for (;;)
150 {
151 i=BIO_write(out,&(b[j]),n);
152 if (i == n) break;
153 if (i <= 0)
154 {
155 ret=0;
156 break;
157 }
158 j+=i;
159 n-=i;
160 }
161 OPENSSL_free(b);
162 return(ret);
163 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
new file mode 100644
index 0000000000..21cc64bb23
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -0,0 +1,453 @@
1/* crypto/asn1/a_int.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
64{ return M_ASN1_INTEGER_dup(x);}
65
66int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
67 {
68 int neg, ret;
69 /* Compare signs */
70 neg = x->type & V_ASN1_NEG;
71 if (neg != (y->type & V_ASN1_NEG))
72 {
73 if (neg)
74 return -1;
75 else
76 return 1;
77 }
78
79 ret = ASN1_STRING_cmp(x, y);
80
81 if (neg)
82 return -ret;
83 else
84 return ret;
85 }
86
87
88/*
89 * This converts an ASN1 INTEGER into its content encoding.
90 * The internal representation is an ASN1_STRING whose data is a big endian
91 * representation of the value, ignoring the sign. The sign is determined by
92 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
93 *
94 * Positive integers are no problem: they are almost the same as the DER
95 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
96 *
97 * Negative integers are a bit trickier...
98 * The DER representation of negative integers is in 2s complement form.
99 * The internal form is converted by complementing each octet and finally
100 * adding one to the result. This can be done less messily with a little trick.
101 * If the internal form has trailing zeroes then they will become FF by the
102 * complement and 0 by the add one (due to carry) so just copy as many trailing
103 * zeros to the destination as there are in the source. The carry will add one
104 * to the last none zero octet: so complement this octet and add one and finally
105 * complement any left over until you get to the start of the string.
106 *
107 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
108 * with 0xff. However if the first byte is 0x80 and one of the following bytes
109 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
110 * followed by optional zeros isn't padded.
111 */
112
113int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
114 {
115 int pad=0,ret,i,neg;
116 unsigned char *p,*n,pb=0;
117
118 if ((a == NULL) || (a->data == NULL)) return(0);
119 neg=a->type & V_ASN1_NEG;
120 if (a->length == 0)
121 ret=1;
122 else
123 {
124 ret=a->length;
125 i=a->data[0];
126 if (!neg && (i > 127)) {
127 pad=1;
128 pb=0;
129 } else if(neg) {
130 if(i>128) {
131 pad=1;
132 pb=0xFF;
133 } else if(i == 128) {
134 /*
135 * Special case: if any other bytes non zero we pad:
136 * otherwise we don't.
137 */
138 for(i = 1; i < a->length; i++) if(a->data[i]) {
139 pad=1;
140 pb=0xFF;
141 break;
142 }
143 }
144 }
145 ret+=pad;
146 }
147 if (pp == NULL) return(ret);
148 p= *pp;
149
150 if (pad) *(p++)=pb;
151 if (a->length == 0) *(p++)=0;
152 else if (!neg) memcpy(p,a->data,(unsigned int)a->length);
153 else {
154 /* Begin at the end of the encoding */
155 n=a->data + a->length - 1;
156 p += a->length - 1;
157 i = a->length;
158 /* Copy zeros to destination as long as source is zero */
159 while(!*n) {
160 *(p--) = 0;
161 n--;
162 i--;
163 }
164 /* Complement and increment next octet */
165 *(p--) = ((*(n--)) ^ 0xff) + 1;
166 i--;
167 /* Complement any octets left */
168 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
169 }
170
171 *pp+=ret;
172 return(ret);
173 }
174
175/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
176
177ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
178 long len)
179 {
180 ASN1_INTEGER *ret=NULL;
181 unsigned char *p,*to,*s, *pend;
182 int i;
183
184 if ((a == NULL) || ((*a) == NULL))
185 {
186 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
187 ret->type=V_ASN1_INTEGER;
188 }
189 else
190 ret=(*a);
191
192 p= *pp;
193 pend = p + len;
194
195 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
196 * signifies a missing NULL parameter. */
197 s=(unsigned char *)OPENSSL_malloc((int)len+1);
198 if (s == NULL)
199 {
200 i=ERR_R_MALLOC_FAILURE;
201 goto err;
202 }
203 to=s;
204 if(!len) {
205 /* Strictly speaking this is an illegal INTEGER but we
206 * tolerate it.
207 */
208 ret->type=V_ASN1_INTEGER;
209 } else if (*p & 0x80) /* a negative number */
210 {
211 ret->type=V_ASN1_NEG_INTEGER;
212 if ((*p == 0xff) && (len != 1)) {
213 p++;
214 len--;
215 }
216 i = len;
217 p += i - 1;
218 to += i - 1;
219 while((!*p) && i) {
220 *(to--) = 0;
221 i--;
222 p--;
223 }
224 /* Special case: if all zeros then the number will be of
225 * the form FF followed by n zero bytes: this corresponds to
226 * 1 followed by n zero bytes. We've already written n zeros
227 * so we just append an extra one and set the first byte to
228 * a 1. This is treated separately because it is the only case
229 * where the number of bytes is larger than len.
230 */
231 if(!i) {
232 *s = 1;
233 s[len] = 0;
234 len++;
235 } else {
236 *(to--) = (*(p--) ^ 0xff) + 1;
237 i--;
238 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
239 }
240 } else {
241 ret->type=V_ASN1_INTEGER;
242 if ((*p == 0) && (len != 1))
243 {
244 p++;
245 len--;
246 }
247 memcpy(s,p,(int)len);
248 }
249
250 if (ret->data != NULL) OPENSSL_free(ret->data);
251 ret->data=s;
252 ret->length=(int)len;
253 if (a != NULL) (*a)=ret;
254 *pp=pend;
255 return(ret);
256err:
257 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
258 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
259 M_ASN1_INTEGER_free(ret);
260 return(NULL);
261 }
262
263
264/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
265 * ASN1 integers: some broken software can encode a positive INTEGER
266 * with its MSB set as negative (it doesn't add a padding zero).
267 */
268
269ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
270 long length)
271 {
272 ASN1_INTEGER *ret=NULL;
273 unsigned char *p,*to,*s;
274 long len;
275 int inf,tag,xclass;
276 int i;
277
278 if ((a == NULL) || ((*a) == NULL))
279 {
280 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
281 ret->type=V_ASN1_INTEGER;
282 }
283 else
284 ret=(*a);
285
286 p= *pp;
287 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
288 if (inf & 0x80)
289 {
290 i=ASN1_R_BAD_OBJECT_HEADER;
291 goto err;
292 }
293
294 if (tag != V_ASN1_INTEGER)
295 {
296 i=ASN1_R_EXPECTING_AN_INTEGER;
297 goto err;
298 }
299
300 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
301 * signifies a missing NULL parameter. */
302 s=(unsigned char *)OPENSSL_malloc((int)len+1);
303 if (s == NULL)
304 {
305 i=ERR_R_MALLOC_FAILURE;
306 goto err;
307 }
308 to=s;
309 ret->type=V_ASN1_INTEGER;
310 if(len) {
311 if ((*p == 0) && (len != 1))
312 {
313 p++;
314 len--;
315 }
316 memcpy(s,p,(int)len);
317 p+=len;
318 }
319
320 if (ret->data != NULL) OPENSSL_free(ret->data);
321 ret->data=s;
322 ret->length=(int)len;
323 if (a != NULL) (*a)=ret;
324 *pp=p;
325 return(ret);
326err:
327 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
328 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
329 M_ASN1_INTEGER_free(ret);
330 return(NULL);
331 }
332
333int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
334 {
335 int i,j,k;
336 unsigned char buf[sizeof(long)+1];
337 long d;
338
339 a->type=V_ASN1_INTEGER;
340 if (a->length < (sizeof(long)+1))
341 {
342 if (a->data != NULL)
343 OPENSSL_free(a->data);
344 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
345 memset((char *)a->data,0,sizeof(long)+1);
346 }
347 if (a->data == NULL)
348 {
349 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
350 return(0);
351 }
352 d=v;
353 if (d < 0)
354 {
355 d= -d;
356 a->type=V_ASN1_NEG_INTEGER;
357 }
358
359 for (i=0; i<sizeof(long); i++)
360 {
361 if (d == 0) break;
362 buf[i]=(int)d&0xff;
363 d>>=8;
364 }
365 j=0;
366 for (k=i-1; k >=0; k--)
367 a->data[j++]=buf[k];
368 a->length=j;
369 return(1);
370 }
371
372long ASN1_INTEGER_get(ASN1_INTEGER *a)
373 {
374 int neg=0,i;
375 long r=0;
376
377 if (a == NULL) return(0L);
378 i=a->type;
379 if (i == V_ASN1_NEG_INTEGER)
380 neg=1;
381 else if (i != V_ASN1_INTEGER)
382 return -1;
383
384 if (a->length > sizeof(long))
385 {
386 /* hmm... a bit ugly */
387 return(0xffffffffL);
388 }
389 if (a->data == NULL)
390 return 0;
391
392 for (i=0; i<a->length; i++)
393 {
394 r<<=8;
395 r|=(unsigned char)a->data[i];
396 }
397 if (neg) r= -r;
398 return(r);
399 }
400
401ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
402 {
403 ASN1_INTEGER *ret;
404 int len,j;
405
406 if (ai == NULL)
407 ret=M_ASN1_INTEGER_new();
408 else
409 ret=ai;
410 if (ret == NULL)
411 {
412 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
413 goto err;
414 }
415 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
416 else ret->type=V_ASN1_INTEGER;
417 j=BN_num_bits(bn);
418 len=((j == 0)?0:((j/8)+1));
419 if (ret->length < len+4)
420 {
421 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
422 if (!new_data)
423 {
424 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
425 goto err;
426 }
427 ret->data=new_data;
428 }
429 ret->length=BN_bn2bin(bn,ret->data);
430 /* Correct zero case */
431 if(!ret->length)
432 {
433 ret->data[0] = 0;
434 ret->length = 1;
435 }
436 return(ret);
437err:
438 if (ret != ai) M_ASN1_INTEGER_free(ret);
439 return(NULL);
440 }
441
442BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
443 {
444 BIGNUM *ret;
445
446 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
447 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
448 else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;
449 return(ret);
450 }
451
452IMPLEMENT_STACK_OF(ASN1_INTEGER)
453IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER)
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
new file mode 100644
index 0000000000..208b3ec395
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -0,0 +1,400 @@
1/* a_mbstr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63
64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg);
69static int cpy_asc(unsigned long value, void *arg);
70static int cpy_bmp(unsigned long value, void *arg);
71static int cpy_univ(unsigned long value, void *arg);
72static int cpy_utf8(unsigned long value, void *arg);
73static int is_printable(unsigned long value);
74
75/* These functions take a string in UTF8, ASCII or multibyte form and
76 * a mask of permissible ASN1 string types. It then works out the minimal
77 * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8)
78 * and creates a string of the correct type with the supplied data.
79 * Yes this is horrible: it has to be :-(
80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */
82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
84 int inform, unsigned long mask)
85{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87}
88
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
90 int inform, unsigned long mask,
91 long minsize, long maxsize)
92{
93 int str_type;
94 int ret;
95 char free_out;
96 int outform, outlen;
97 ASN1_STRING *dest;
98 unsigned char *p;
99 int nchar;
100 char strbuf[32];
101 int (*cpyfunc)(unsigned long,void *) = NULL;
102 if(len == -1) len = strlen((const char *)in);
103 if(!mask) mask = DIRSTRING_TYPE;
104
105 /* First do a string check and work out the number of characters */
106 switch(inform) {
107
108 case MBSTRING_BMP:
109 if(len & 1) {
110 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
111 ASN1_R_INVALID_BMPSTRING_LENGTH);
112 return -1;
113 }
114 nchar = len >> 1;
115 break;
116
117 case MBSTRING_UNIV:
118 if(len & 3) {
119 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
121 return -1;
122 }
123 nchar = len >> 2;
124 break;
125
126 case MBSTRING_UTF8:
127 nchar = 0;
128 /* This counts the characters and does utf8 syntax checking */
129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
130 if(ret < 0) {
131 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
132 ASN1_R_INVALID_UTF8STRING);
133 return -1;
134 }
135 break;
136
137 case MBSTRING_ASC:
138 nchar = len;
139 break;
140
141 default:
142 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
143 return -1;
144 }
145
146 if((minsize > 0) && (nchar < minsize)) {
147 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
148 BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize);
149 ERR_add_error_data(2, "minsize=", strbuf);
150 return -1;
151 }
152
153 if((maxsize > 0) && (nchar > maxsize)) {
154 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
155 BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
156 ERR_add_error_data(2, "maxsize=", strbuf);
157 return -1;
158 }
159
160 /* Now work out minimal type (if any) */
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
162 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
163 return -1;
164 }
165
166
167 /* Now work out output format and string type */
168 outform = MBSTRING_ASC;
169 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
170 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
171 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
172 else if(mask & B_ASN1_BMPSTRING) {
173 str_type = V_ASN1_BMPSTRING;
174 outform = MBSTRING_BMP;
175 } else if(mask & B_ASN1_UNIVERSALSTRING) {
176 str_type = V_ASN1_UNIVERSALSTRING;
177 outform = MBSTRING_UNIV;
178 } else {
179 str_type = V_ASN1_UTF8STRING;
180 outform = MBSTRING_UTF8;
181 }
182 if(!out) return str_type;
183 if(*out) {
184 free_out = 0;
185 dest = *out;
186 if(dest->data) {
187 dest->length = 0;
188 OPENSSL_free(dest->data);
189 dest->data = NULL;
190 }
191 dest->type = str_type;
192 } else {
193 free_out = 1;
194 dest = ASN1_STRING_type_new(str_type);
195 if(!dest) {
196 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
197 ERR_R_MALLOC_FAILURE);
198 return -1;
199 }
200 *out = dest;
201 }
202 /* If both the same type just copy across */
203 if(inform == outform) {
204 if(!ASN1_STRING_set(dest, in, len)) {
205 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
206 return -1;
207 }
208 return str_type;
209 }
210
211 /* Work out how much space the destination will need */
212 switch(outform) {
213 case MBSTRING_ASC:
214 outlen = nchar;
215 cpyfunc = cpy_asc;
216 break;
217
218 case MBSTRING_BMP:
219 outlen = nchar << 1;
220 cpyfunc = cpy_bmp;
221 break;
222
223 case MBSTRING_UNIV:
224 outlen = nchar << 2;
225 cpyfunc = cpy_univ;
226 break;
227
228 case MBSTRING_UTF8:
229 outlen = 0;
230 traverse_string(in, len, inform, out_utf8, &outlen);
231 cpyfunc = cpy_utf8;
232 break;
233 }
234 if(!(p = OPENSSL_malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest);
236 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
237 return -1;
238 }
239 dest->length = outlen;
240 dest->data = p;
241 p[outlen] = 0;
242 traverse_string(in, len, inform, cpyfunc, &p);
243 return str_type;
244}
245
246/* This function traverses a string and passes the value of each character
247 * to an optional function along with a void * argument.
248 */
249
250static int traverse_string(const unsigned char *p, int len, int inform,
251 int (*rfunc)(unsigned long value, void *in), void *arg)
252{
253 unsigned long value;
254 int ret;
255 while(len) {
256 if(inform == MBSTRING_ASC) {
257 value = *p++;
258 len--;
259 } else if(inform == MBSTRING_BMP) {
260 value = *p++ << 8;
261 value |= *p++;
262 len -= 2;
263 } else if(inform == MBSTRING_UNIV) {
264 value = ((unsigned long)*p++) << 24;
265 value |= ((unsigned long)*p++) << 16;
266 value |= *p++ << 8;
267 value |= *p++;
268 len -= 4;
269 } else {
270 ret = UTF8_getc(p, len, &value);
271 if(ret < 0) return -1;
272 len -= ret;
273 p += ret;
274 }
275 if(rfunc) {
276 ret = rfunc(value, arg);
277 if(ret <= 0) return ret;
278 }
279 }
280 return 1;
281}
282
283/* Various utility functions for traverse_string */
284
285/* Just count number of characters */
286
287static int in_utf8(unsigned long value, void *arg)
288{
289 int *nchar;
290 nchar = arg;
291 (*nchar)++;
292 return 1;
293}
294
295/* Determine size of output as a UTF8 String */
296
297static int out_utf8(unsigned long value, void *arg)
298{
299 int *outlen;
300 outlen = arg;
301 *outlen += UTF8_putc(NULL, -1, value);
302 return 1;
303}
304
305/* Determine the "type" of a string: check each character against a
306 * supplied "mask".
307 */
308
309static int type_str(unsigned long value, void *arg)
310{
311 unsigned long types;
312 types = *((unsigned long *)arg);
313 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
314 types &= ~B_ASN1_PRINTABLESTRING;
315 if((types & B_ASN1_IA5STRING) && (value > 127))
316 types &= ~B_ASN1_IA5STRING;
317 if((types & B_ASN1_T61STRING) && (value > 0xff))
318 types &= ~B_ASN1_T61STRING;
319 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
320 types &= ~B_ASN1_BMPSTRING;
321 if(!types) return -1;
322 *((unsigned long *)arg) = types;
323 return 1;
324}
325
326/* Copy one byte per character ASCII like strings */
327
328static int cpy_asc(unsigned long value, void *arg)
329{
330 unsigned char **p, *q;
331 p = arg;
332 q = *p;
333 *q = (unsigned char) value;
334 (*p)++;
335 return 1;
336}
337
338/* Copy two byte per character BMPStrings */
339
340static int cpy_bmp(unsigned long value, void *arg)
341{
342 unsigned char **p, *q;
343 p = arg;
344 q = *p;
345 *q++ = (unsigned char) ((value >> 8) & 0xff);
346 *q = (unsigned char) (value & 0xff);
347 *p += 2;
348 return 1;
349}
350
351/* Copy four byte per character UniversalStrings */
352
353static int cpy_univ(unsigned long value, void *arg)
354{
355 unsigned char **p, *q;
356 p = arg;
357 q = *p;
358 *q++ = (unsigned char) ((value >> 24) & 0xff);
359 *q++ = (unsigned char) ((value >> 16) & 0xff);
360 *q++ = (unsigned char) ((value >> 8) & 0xff);
361 *q = (unsigned char) (value & 0xff);
362 *p += 4;
363 return 1;
364}
365
366/* Copy to a UTF8String */
367
368static int cpy_utf8(unsigned long value, void *arg)
369{
370 unsigned char **p;
371 int ret;
372 p = arg;
373 /* We already know there is enough room so pass 0xff as the length */
374 ret = UTF8_putc(*p, 0xff, value);
375 *p += ret;
376 return 1;
377}
378
379/* Return 1 if the character is permitted in a PrintableString */
380static int is_printable(unsigned long value)
381{
382 int ch;
383 if(value > 0x7f) return 0;
384 ch = (int) value;
385 /* Note: we can't use 'isalnum' because certain accented
386 * characters may count as alphanumeric in some environments.
387 */
388#ifndef CHARSET_EBCDIC
389 if((ch >= 'a') && (ch <= 'z')) return 1;
390 if((ch >= 'A') && (ch <= 'Z')) return 1;
391 if((ch >= '0') && (ch <= '9')) return 1;
392 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
393#else /*CHARSET_EBCDIC*/
394 if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1;
395 if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1;
396 if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1;
397 if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1;
398#endif /*CHARSET_EBCDIC*/
399 return 0;
400}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
new file mode 100644
index 0000000000..0a8e6c287c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -0,0 +1,320 @@
1/* crypto/asn1/a_object.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
66 {
67 unsigned char *p;
68 int objsize;
69
70 if ((a == NULL) || (a->data == NULL)) return(0);
71
72 objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT);
73 if (pp == NULL) return objsize;
74
75 p= *pp;
76 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
77 memcpy(p,a->data,a->length);
78 p+=a->length;
79
80 *pp=p;
81 return(objsize);
82 }
83
84int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
85 {
86 int i,first,len=0,c;
87 char tmp[24];
88 const char *p;
89 unsigned long l;
90
91 if (num == 0)
92 return(0);
93 else if (num == -1)
94 num=strlen(buf);
95
96 p=buf;
97 c= *(p++);
98 num--;
99 if ((c >= '0') && (c <= '2'))
100 {
101 first=(c-'0')*40;
102 }
103 else
104 {
105 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
106 goto err;
107 }
108
109 if (num <= 0)
110 {
111 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
112 goto err;
113 }
114 c= *(p++);
115 num--;
116 for (;;)
117 {
118 if (num <= 0) break;
119 if ((c != '.') && (c != ' '))
120 {
121 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
122 goto err;
123 }
124 l=0;
125 for (;;)
126 {
127 if (num <= 0) break;
128 num--;
129 c= *(p++);
130 if ((c == ' ') || (c == '.'))
131 break;
132 if ((c < '0') || (c > '9'))
133 {
134 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
135 goto err;
136 }
137 l=l*10L+(long)(c-'0');
138 }
139 if (len == 0)
140 {
141 if ((first < 2) && (l >= 40))
142 {
143 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
144 goto err;
145 }
146 l+=(long)first;
147 }
148 i=0;
149 for (;;)
150 {
151 tmp[i++]=(unsigned char)l&0x7f;
152 l>>=7L;
153 if (l == 0L) break;
154 }
155 if (out != NULL)
156 {
157 if (len+i > olen)
158 {
159 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
160 goto err;
161 }
162 while (--i > 0)
163 out[len++]=tmp[i]|0x80;
164 out[len++]=tmp[0];
165 }
166 else
167 len+=i;
168 }
169 return(len);
170err:
171 return(0);
172 }
173
174int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
175{
176 return OBJ_obj2txt(buf, buf_len, a, 0);
177}
178
179int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
180 {
181 char buf[80];
182 int i;
183
184 if ((a == NULL) || (a->data == NULL))
185 return(BIO_write(bp,"NULL",4));
186 i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
187 if (i > sizeof buf) i=sizeof buf;
188 BIO_write(bp,buf,i);
189 return(i);
190 }
191
192ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
193 long length)
194{
195 unsigned char *p;
196 long len;
197 int tag,xclass;
198 int inf,i;
199 ASN1_OBJECT *ret = NULL;
200 p= *pp;
201 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
202 if (inf & 0x80)
203 {
204 i=ASN1_R_BAD_OBJECT_HEADER;
205 goto err;
206 }
207
208 if (tag != V_ASN1_OBJECT)
209 {
210 i=ASN1_R_EXPECTING_AN_OBJECT;
211 goto err;
212 }
213 ret = c2i_ASN1_OBJECT(a, &p, len);
214 if(ret) *pp = p;
215 return ret;
216err:
217 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
218 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
219 ASN1_OBJECT_free(ret);
220 return(NULL);
221}
222ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
223 long len)
224 {
225 ASN1_OBJECT *ret=NULL;
226 unsigned char *p;
227 int i;
228
229 /* only the ASN1_OBJECTs from the 'table' will have values
230 * for ->sn or ->ln */
231 if ((a == NULL) || ((*a) == NULL) ||
232 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
233 {
234 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
235 }
236 else ret=(*a);
237
238 p= *pp;
239 if ((ret->data == NULL) || (ret->length < len))
240 {
241 if (ret->data != NULL) OPENSSL_free(ret->data);
242 ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
243 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
244 if (ret->data == NULL)
245 { i=ERR_R_MALLOC_FAILURE; goto err; }
246 }
247 memcpy(ret->data,p,(int)len);
248 ret->length=(int)len;
249 ret->sn=NULL;
250 ret->ln=NULL;
251 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
252 p+=len;
253
254 if (a != NULL) (*a)=ret;
255 *pp=p;
256 return(ret);
257err:
258 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
260 ASN1_OBJECT_free(ret);
261 return(NULL);
262 }
263
264ASN1_OBJECT *ASN1_OBJECT_new(void)
265 {
266 ASN1_OBJECT *ret;
267
268 ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
269 if (ret == NULL)
270 {
271 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
272 return(NULL);
273 }
274 ret->length=0;
275 ret->data=NULL;
276 ret->nid=0;
277 ret->sn=NULL;
278 ret->ln=NULL;
279 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
280 return(ret);
281 }
282
283void ASN1_OBJECT_free(ASN1_OBJECT *a)
284 {
285 if (a == NULL) return;
286 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
287 {
288#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
289 if (a->sn != NULL) OPENSSL_free((void *)a->sn);
290 if (a->ln != NULL) OPENSSL_free((void *)a->ln);
291#endif
292 a->sn=a->ln=NULL;
293 }
294 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
295 {
296 if (a->data != NULL) OPENSSL_free(a->data);
297 a->data=NULL;
298 a->length=0;
299 }
300 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
301 OPENSSL_free(a);
302 }
303
304ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
305 const char *sn, const char *ln)
306 {
307 ASN1_OBJECT o;
308
309 o.sn=sn;
310 o.ln=ln;
311 o.data=data;
312 o.nid=nid;
313 o.length=len;
314 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
315 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
316 return(OBJ_dup(&o));
317 }
318
319IMPLEMENT_STACK_OF(ASN1_OBJECT)
320IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT)
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
new file mode 100644
index 0000000000..9690bae0f1
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_octet.c
@@ -0,0 +1,71 @@
1/* crypto/asn1/a_octet.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
64{ return M_ASN1_OCTET_STRING_dup(x); }
65
66int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
67{ return M_ASN1_OCTET_STRING_cmp(a, b); }
68
69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_OCTET_STRING_set(x, d, len); }
71
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
new file mode 100644
index 0000000000..d18e772320
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_print.c
@@ -0,0 +1,127 @@
1/* crypto/asn1/a_print.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int ASN1_PRINTABLE_type(const unsigned char *s, int len)
64 {
65 int c;
66 int ia5=0;
67 int t61=0;
68
69 if (len <= 0) len= -1;
70 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
71
72 while ((*s) && (len-- != 0))
73 {
74 c= *(s++);
75#ifndef CHARSET_EBCDIC
76 if (!( ((c >= 'a') && (c <= 'z')) ||
77 ((c >= 'A') && (c <= 'Z')) ||
78 (c == ' ') ||
79 ((c >= '0') && (c <= '9')) ||
80 (c == ' ') || (c == '\'') ||
81 (c == '(') || (c == ')') ||
82 (c == '+') || (c == ',') ||
83 (c == '-') || (c == '.') ||
84 (c == '/') || (c == ':') ||
85 (c == '=') || (c == '?')))
86 ia5=1;
87 if (c&0x80)
88 t61=1;
89#else
90 if (!isalnum(c) && (c != ' ') &&
91 strchr("'()+,-./:=?", c) == NULL)
92 ia5=1;
93 if (os_toascii[c] & 0x80)
94 t61=1;
95#endif
96 }
97 if (t61) return(V_ASN1_T61STRING);
98 if (ia5) return(V_ASN1_IA5STRING);
99 return(V_ASN1_PRINTABLESTRING);
100 }
101
102int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
103 {
104 int i;
105 unsigned char *p;
106
107 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
108 if ((s->length%4) != 0) return(0);
109 p=s->data;
110 for (i=0; i<s->length; i+=4)
111 {
112 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
113 break;
114 else
115 p+=4;
116 }
117 if (i < s->length) return(0);
118 p=s->data;
119 for (i=3; i<s->length; i+=4)
120 {
121 *(p++)=s->data[i];
122 }
123 *(p)='\0';
124 s->length/=4;
125 s->type=ASN1_PRINTABLE_type(s->data,s->length);
126 return(1);
127 }
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
new file mode 100644
index 0000000000..e24061c545
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_set.c
@@ -0,0 +1,235 @@
1/* crypto/asn1/a_set.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62
63#ifndef NO_ASN1_OLD
64
65typedef struct
66 {
67 unsigned char *pbData;
68 int cbData;
69 } MYBLOB;
70
71/* SetBlobCmp
72 * This function compares two elements of SET_OF block
73 */
74static int SetBlobCmp(const void *elem1, const void *elem2 )
75 {
76 const MYBLOB *b1 = (const MYBLOB *)elem1;
77 const MYBLOB *b2 = (const MYBLOB *)elem2;
78 int r;
79
80 r = memcmp(b1->pbData, b2->pbData,
81 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
82 if(r != 0)
83 return r;
84 return b1->cbData-b2->cbData;
85 }
86
87/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
88int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
89 int ex_class, int is_set)
90 {
91 int ret=0,r;
92 int i;
93 unsigned char *p;
94 unsigned char *pStart, *pTempMem;
95 MYBLOB *rgSetBlob;
96 int totSize;
97
98 if (a == NULL) return(0);
99 for (i=sk_num(a)-1; i>=0; i--)
100 ret+=func(sk_value(a,i),NULL);
101 r=ASN1_object_size(1,ret,ex_tag);
102 if (pp == NULL) return(r);
103
104 p= *pp;
105 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
106
107/* Modified by gp@nsj.co.jp */
108 /* And then again by Ben */
109 /* And again by Steve */
110
111 if(!is_set || (sk_num(a) < 2))
112 {
113 for (i=0; i<sk_num(a); i++)
114 func(sk_value(a,i),&p);
115
116 *pp=p;
117 return(r);
118 }
119
120 pStart = p; /* Catch the beg of Setblobs*/
121 /* In this array we will store the SET blobs */
122 rgSetBlob = (MYBLOB *)OPENSSL_malloc(sk_num(a) * sizeof(MYBLOB));
123 if (rgSetBlob == NULL)
124 {
125 ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
126 return(0);
127 }
128
129 for (i=0; i<sk_num(a); i++)
130 {
131 rgSetBlob[i].pbData = p; /* catch each set encode blob */
132 func(sk_value(a,i),&p);
133 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
134SetBlob
135*/
136 }
137 *pp=p;
138 totSize = p - pStart; /* This is the total size of all set blobs */
139
140 /* Now we have to sort the blobs. I am using a simple algo.
141 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
142 qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
143 if (!(pTempMem = OPENSSL_malloc(totSize)))
144 {
145 ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
146 return(0);
147 }
148
149/* Copy to temp mem */
150 p = pTempMem;
151 for(i=0; i<sk_num(a); ++i)
152 {
153 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
154 p += rgSetBlob[i].cbData;
155 }
156
157/* Copy back to user mem*/
158 memcpy(pStart, pTempMem, totSize);
159 OPENSSL_free(pTempMem);
160 OPENSSL_free(rgSetBlob);
161
162 return(r);
163 }
164
165STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
166 char *(*func)(), void (*free_func)(void *), int ex_tag, int ex_class)
167 {
168 ASN1_CTX c;
169 STACK *ret=NULL;
170
171 if ((a == NULL) || ((*a) == NULL))
172 {
173 if ((ret=sk_new_null()) == NULL)
174 {
175 ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE);
176 goto err;
177 }
178 }
179 else
180 ret=(*a);
181
182 c.p= *pp;
183 c.max=(length == 0)?0:(c.p+length);
184
185 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
186 if (c.inf & 0x80) goto err;
187 if (ex_class != c.xclass)
188 {
189 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
190 goto err;
191 }
192 if (ex_tag != c.tag)
193 {
194 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
195 goto err;
196 }
197 if ((c.slen+c.p) > c.max)
198 {
199 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
200 goto err;
201 }
202 /* check for infinite constructed - it can be as long
203 * as the amount of data passed to us */
204 if (c.inf == (V_ASN1_CONSTRUCTED+1))
205 c.slen=length+ *pp-c.p;
206 c.max=c.p+c.slen;
207
208 while (c.p < c.max)
209 {
210 char *s;
211
212 if (M_ASN1_D2I_end_sequence()) break;
213 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
214 {
215 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
216 asn1_add_error(*pp,(int)(c.q- *pp));
217 goto err;
218 }
219 if (!sk_push(ret,s)) goto err;
220 }
221 if (a != NULL) (*a)=ret;
222 *pp=c.p;
223 return(ret);
224err:
225 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
226 {
227 if (free_func != NULL)
228 sk_pop_free(ret,free_func);
229 else
230 sk_free(ret);
231 }
232 return(NULL);
233 }
234
235#endif
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
new file mode 100644
index 0000000000..52ce7e3974
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -0,0 +1,294 @@
1/* crypto/asn1/a_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <time.h>
114
115#include "cryptlib.h"
116
117#ifndef NO_SYS_TYPES_H
118# include <sys/types.h>
119#endif
120
121#include <openssl/bn.h>
122#include <openssl/evp.h>
123#include <openssl/x509.h>
124#include <openssl/objects.h>
125#include <openssl/buffer.h>
126
127#ifndef NO_ASN1_OLD
128
129int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
130 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
131 const EVP_MD *type)
132 {
133 EVP_MD_CTX ctx;
134 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
135 int i,inl=0,outl=0,outll=0;
136 X509_ALGOR *a;
137
138 EVP_MD_CTX_init(&ctx);
139 for (i=0; i<2; i++)
140 {
141 if (i == 0)
142 a=algor1;
143 else
144 a=algor2;
145 if (a == NULL) continue;
146 if (type->pkey_type == NID_dsaWithSHA1)
147 {
148 /* special case: RFC 2459 tells us to omit 'parameters'
149 * with id-dsa-with-sha1 */
150 ASN1_TYPE_free(a->parameter);
151 a->parameter = NULL;
152 }
153 else if ((a->parameter == NULL) ||
154 (a->parameter->type != V_ASN1_NULL))
155 {
156 ASN1_TYPE_free(a->parameter);
157 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
158 a->parameter->type=V_ASN1_NULL;
159 }
160 ASN1_OBJECT_free(a->algorithm);
161 a->algorithm=OBJ_nid2obj(type->pkey_type);
162 if (a->algorithm == NULL)
163 {
164 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
165 goto err;
166 }
167 if (a->algorithm->length == 0)
168 {
169 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
170 goto err;
171 }
172 }
173 inl=i2d(data,NULL);
174 buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
175 outll=outl=EVP_PKEY_size(pkey);
176 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
177 if ((buf_in == NULL) || (buf_out == NULL))
178 {
179 outl=0;
180 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
181 goto err;
182 }
183 p=buf_in;
184
185 i2d(data,&p);
186 EVP_SignInit_ex(&ctx,type, NULL);
187 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
188 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
189 (unsigned int *)&outl,pkey))
190 {
191 outl=0;
192 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
193 goto err;
194 }
195 if (signature->data != NULL) OPENSSL_free(signature->data);
196 signature->data=buf_out;
197 buf_out=NULL;
198 signature->length=outl;
199 /* In the interests of compatibility, I'll make sure that
200 * the bit string has a 'not-used bits' value of 0
201 */
202 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
203 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
204err:
205 EVP_MD_CTX_cleanup(&ctx);
206 if (buf_in != NULL)
207 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); }
208 if (buf_out != NULL)
209 { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); }
210 return(outl);
211 }
212
213#endif
214
215int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
216 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey,
217 const EVP_MD *type)
218 {
219 EVP_MD_CTX ctx;
220 unsigned char *buf_in=NULL,*buf_out=NULL;
221 int i,inl=0,outl=0,outll=0;
222 X509_ALGOR *a;
223
224 EVP_MD_CTX_init(&ctx);
225 for (i=0; i<2; i++)
226 {
227 if (i == 0)
228 a=algor1;
229 else
230 a=algor2;
231 if (a == NULL) continue;
232 if (type->pkey_type == NID_dsaWithSHA1)
233 {
234 /* special case: RFC 2459 tells us to omit 'parameters'
235 * with id-dsa-with-sha1 */
236 ASN1_TYPE_free(a->parameter);
237 a->parameter = NULL;
238 }
239 else if ((a->parameter == NULL) ||
240 (a->parameter->type != V_ASN1_NULL))
241 {
242 ASN1_TYPE_free(a->parameter);
243 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
244 a->parameter->type=V_ASN1_NULL;
245 }
246 ASN1_OBJECT_free(a->algorithm);
247 a->algorithm=OBJ_nid2obj(type->pkey_type);
248 if (a->algorithm == NULL)
249 {
250 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
251 goto err;
252 }
253 if (a->algorithm->length == 0)
254 {
255 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
256 goto err;
257 }
258 }
259 inl=ASN1_item_i2d(asn,&buf_in, it);
260 outll=outl=EVP_PKEY_size(pkey);
261 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
262 if ((buf_in == NULL) || (buf_out == NULL))
263 {
264 outl=0;
265 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
266 goto err;
267 }
268
269 EVP_SignInit_ex(&ctx,type, NULL);
270 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
271 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
272 (unsigned int *)&outl,pkey))
273 {
274 outl=0;
275 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
276 goto err;
277 }
278 if (signature->data != NULL) OPENSSL_free(signature->data);
279 signature->data=buf_out;
280 buf_out=NULL;
281 signature->length=outl;
282 /* In the interests of compatibility, I'll make sure that
283 * the bit string has a 'not-used bits' value of 0
284 */
285 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
286 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
287err:
288 EVP_MD_CTX_cleanup(&ctx);
289 if (buf_in != NULL)
290 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); }
291 if (buf_out != NULL)
292 { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); }
293 return(outl);
294 }
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
new file mode 100644
index 0000000000..a07122ba47
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -0,0 +1,567 @@
1/* a_strex.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63#include <openssl/asn1.h>
64
65#include "charmap.h"
66#include "cryptlib.h"
67
68/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
69 * Enhanced string and name printing routines handling
70 * multibyte characters, RFC2253 and a host of other
71 * options.
72 */
73
74
75#define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
76
77
78/* Three IO functions for sending data to memory, a BIO and
79 * and a FILE pointer.
80 */
81#if 0 /* never used */
82static int send_mem_chars(void *arg, const void *buf, int len)
83{
84 unsigned char **out = arg;
85 if(!out) return 1;
86 memcpy(*out, buf, len);
87 *out += len;
88 return 1;
89}
90#endif
91
92static int send_bio_chars(void *arg, const void *buf, int len)
93{
94 if(!arg) return 1;
95 if(BIO_write(arg, buf, len) != len) return 0;
96 return 1;
97}
98
99static int send_fp_chars(void *arg, const void *buf, int len)
100{
101 if(!arg) return 1;
102 if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0;
103 return 1;
104}
105
106typedef int char_io(void *arg, const void *buf, int len);
107
108/* This function handles display of
109 * strings, one character at a time.
110 * It is passed an unsigned long for each
111 * character because it could come from 2 or even
112 * 4 byte forms.
113 */
114
115static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg)
116{
117 unsigned char chflgs, chtmp;
118 char tmphex[HEX_SIZE(long)+3];
119
120 if(c > 0xffffffffL)
121 return -1;
122 if(c > 0xffff) {
123 BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c);
124 if(!io_ch(arg, tmphex, 10)) return -1;
125 return 10;
126 }
127 if(c > 0xff) {
128 BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c);
129 if(!io_ch(arg, tmphex, 6)) return -1;
130 return 6;
131 }
132 chtmp = (unsigned char)c;
133 if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB;
134 else chflgs = char_type[chtmp] & flags;
135 if(chflgs & CHARTYPE_BS_ESC) {
136 /* If we don't escape with quotes, signal we need quotes */
137 if(chflgs & ASN1_STRFLGS_ESC_QUOTE) {
138 if(do_quotes) *do_quotes = 1;
139 if(!io_ch(arg, &chtmp, 1)) return -1;
140 return 1;
141 }
142 if(!io_ch(arg, "\\", 1)) return -1;
143 if(!io_ch(arg, &chtmp, 1)) return -1;
144 return 2;
145 }
146 if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) {
147 BIO_snprintf(tmphex, 11, "\\%02X", chtmp);
148 if(!io_ch(arg, tmphex, 3)) return -1;
149 return 3;
150 }
151 if(!io_ch(arg, &chtmp, 1)) return -1;
152 return 1;
153}
154
155#define BUF_TYPE_WIDTH_MASK 0x7
156#define BUF_TYPE_CONVUTF8 0x8
157
158/* This function sends each character in a buffer to
159 * do_esc_char(). It interprets the content formats
160 * and converts to or from UTF8 as appropriate.
161 */
162
163static int do_buf(unsigned char *buf, int buflen,
164 int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)
165{
166 int i, outlen, len;
167 unsigned char orflags, *p, *q;
168 unsigned long c;
169 p = buf;
170 q = buf + buflen;
171 outlen = 0;
172 while(p != q) {
173 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
174 else orflags = 0;
175 switch(type & BUF_TYPE_WIDTH_MASK) {
176 case 4:
177 c = ((unsigned long)*p++) << 24;
178 c |= ((unsigned long)*p++) << 16;
179 c |= ((unsigned long)*p++) << 8;
180 c |= *p++;
181 break;
182
183 case 2:
184 c = ((unsigned long)*p++) << 8;
185 c |= *p++;
186 break;
187
188 case 1:
189 c = *p++;
190 break;
191
192 case 0:
193 i = UTF8_getc(p, buflen, &c);
194 if(i < 0) return -1; /* Invalid UTF8String */
195 p += i;
196 break;
197 }
198 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
199 if(type & BUF_TYPE_CONVUTF8) {
200 unsigned char utfbuf[6];
201 int utflen;
202 utflen = UTF8_putc(utfbuf, sizeof utfbuf, c);
203 for(i = 0; i < utflen; i++) {
204 /* We don't need to worry about setting orflags correctly
205 * because if utflen==1 its value will be correct anyway
206 * otherwise each character will be > 0x7f and so the
207 * character will never be escaped on first and last.
208 */
209 len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg);
210 if(len < 0) return -1;
211 outlen += len;
212 }
213 } else {
214 len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg);
215 if(len < 0) return -1;
216 outlen += len;
217 }
218 }
219 return outlen;
220}
221
222/* This function hex dumps a buffer of characters */
223
224static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
225{
226 const static char hexdig[] = "0123456789ABCDEF";
227 unsigned char *p, *q;
228 char hextmp[2];
229 if(arg) {
230 p = buf;
231 q = buf + buflen;
232 while(p != q) {
233 hextmp[0] = hexdig[*p >> 4];
234 hextmp[1] = hexdig[*p & 0xf];
235 if(!io_ch(arg, hextmp, 2)) return -1;
236 p++;
237 }
238 }
239 return buflen << 1;
240}
241
242/* "dump" a string. This is done when the type is unknown,
243 * or the flags request it. We can either dump the content
244 * octets or the entire DER encoding. This uses the RFC2253
245 * #01234 format.
246 */
247
248static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str)
249{
250 /* Placing the ASN1_STRING in a temp ASN1_TYPE allows
251 * the DER encoding to readily obtained
252 */
253 ASN1_TYPE t;
254 unsigned char *der_buf, *p;
255 int outlen, der_len;
256
257 if(!io_ch(arg, "#", 1)) return -1;
258 /* If we don't dump DER encoding just dump content octets */
259 if(!(lflags & ASN1_STRFLGS_DUMP_DER)) {
260 outlen = do_hex_dump(io_ch, arg, str->data, str->length);
261 if(outlen < 0) return -1;
262 return outlen + 1;
263 }
264 t.type = str->type;
265 t.value.ptr = (char *)str;
266 der_len = i2d_ASN1_TYPE(&t, NULL);
267 der_buf = OPENSSL_malloc(der_len);
268 if(!der_buf) return -1;
269 p = der_buf;
270 i2d_ASN1_TYPE(&t, &p);
271 outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
272 OPENSSL_free(der_buf);
273 if(outlen < 0) return -1;
274 return outlen + 1;
275}
276
277/* Lookup table to convert tags to character widths,
278 * 0 = UTF8 encoded, -1 is used for non string types
279 * otherwise it is the number of bytes per character
280 */
281
282const static signed char tag2nbyte[] = {
283 -1, -1, -1, -1, -1, /* 0-4 */
284 -1, -1, -1, -1, -1, /* 5-9 */
285 -1, -1, 0, -1, /* 10-13 */
286 -1, -1, -1, -1, /* 15-17 */
287 -1, 1, 1, /* 18-20 */
288 -1, 1, 1, 1, /* 21-24 */
289 -1, 1, -1, /* 25-27 */
290 4, -1, 2 /* 28-30 */
291};
292
293#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
294 ASN1_STRFLGS_ESC_QUOTE | \
295 ASN1_STRFLGS_ESC_CTRL | \
296 ASN1_STRFLGS_ESC_MSB)
297
298/* This is the main function, print out an
299 * ASN1_STRING taking note of various escape
300 * and display options. Returns number of
301 * characters written or -1 if an error
302 * occurred.
303 */
304
305static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str)
306{
307 int outlen, len;
308 int type;
309 char quotes;
310 unsigned char flags;
311 quotes = 0;
312 /* Keep a copy of escape flags */
313 flags = (unsigned char)(lflags & ESC_FLAGS);
314
315 type = str->type;
316
317 outlen = 0;
318
319
320 if(lflags & ASN1_STRFLGS_SHOW_TYPE) {
321 const char *tagname;
322 tagname = ASN1_tag2str(type);
323 outlen += strlen(tagname);
324 if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1;
325 outlen++;
326 }
327
328 /* Decide what to do with type, either dump content or display it */
329
330 /* Dump everything */
331 if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1;
332 /* Ignore the string type */
333 else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1;
334 else {
335 /* Else determine width based on type */
336 if((type > 0) && (type < 31)) type = tag2nbyte[type];
337 else type = -1;
338 if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1;
339 }
340
341 if(type == -1) {
342 len = do_dump(lflags, io_ch, arg, str);
343 if(len < 0) return -1;
344 outlen += len;
345 return outlen;
346 }
347
348 if(lflags & ASN1_STRFLGS_UTF8_CONVERT) {
349 /* Note: if string is UTF8 and we want
350 * to convert to UTF8 then we just interpret
351 * it as 1 byte per character to avoid converting
352 * twice.
353 */
354 if(!type) type = 1;
355 else type |= BUF_TYPE_CONVUTF8;
356 }
357
358 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
359 if(outlen < 0) return -1;
360 outlen += len;
361 if(quotes) outlen += 2;
362 if(!arg) return outlen;
363 if(quotes && !io_ch(arg, "\"", 1)) return -1;
364 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
365 if(quotes && !io_ch(arg, "\"", 1)) return -1;
366 return outlen;
367}
368
369/* Used for line indenting: print 'indent' spaces */
370
371static int do_indent(char_io *io_ch, void *arg, int indent)
372{
373 int i;
374 for(i = 0; i < indent; i++)
375 if(!io_ch(arg, " ", 1)) return 0;
376 return 1;
377}
378
379#define FN_WIDTH_LN 25
380#define FN_WIDTH_SN 10
381
382static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
383 int indent, unsigned long flags)
384{
385 int i, prev = -1, orflags, cnt;
386 int fn_opt, fn_nid;
387 ASN1_OBJECT *fn;
388 ASN1_STRING *val;
389 X509_NAME_ENTRY *ent;
390 char objtmp[80];
391 const char *objbuf;
392 int outlen, len;
393 char *sep_dn, *sep_mv, *sep_eq;
394 int sep_dn_len, sep_mv_len, sep_eq_len;
395 if(indent < 0) indent = 0;
396 outlen = indent;
397 if(!do_indent(io_ch, arg, indent)) return -1;
398 switch (flags & XN_FLAG_SEP_MASK)
399 {
400 case XN_FLAG_SEP_MULTILINE:
401 sep_dn = "\n";
402 sep_dn_len = 1;
403 sep_mv = " + ";
404 sep_mv_len = 3;
405 break;
406
407 case XN_FLAG_SEP_COMMA_PLUS:
408 sep_dn = ",";
409 sep_dn_len = 1;
410 sep_mv = "+";
411 sep_mv_len = 1;
412 indent = 0;
413 break;
414
415 case XN_FLAG_SEP_CPLUS_SPC:
416 sep_dn = ", ";
417 sep_dn_len = 2;
418 sep_mv = " + ";
419 sep_mv_len = 3;
420 indent = 0;
421 break;
422
423 case XN_FLAG_SEP_SPLUS_SPC:
424 sep_dn = "; ";
425 sep_dn_len = 2;
426 sep_mv = " + ";
427 sep_mv_len = 3;
428 indent = 0;
429 break;
430
431 default:
432 return -1;
433 }
434
435 if(flags & XN_FLAG_SPC_EQ) {
436 sep_eq = " = ";
437 sep_eq_len = 3;
438 } else {
439 sep_eq = "=";
440 sep_eq_len = 1;
441 }
442
443 fn_opt = flags & XN_FLAG_FN_MASK;
444
445 cnt = X509_NAME_entry_count(n);
446 for(i = 0; i < cnt; i++) {
447 if(flags & XN_FLAG_DN_REV)
448 ent = X509_NAME_get_entry(n, cnt - i - 1);
449 else ent = X509_NAME_get_entry(n, i);
450 if(prev != -1) {
451 if(prev == ent->set) {
452 if(!io_ch(arg, sep_mv, sep_mv_len)) return -1;
453 outlen += sep_mv_len;
454 } else {
455 if(!io_ch(arg, sep_dn, sep_dn_len)) return -1;
456 outlen += sep_dn_len;
457 if(!do_indent(io_ch, arg, indent)) return -1;
458 outlen += indent;
459 }
460 }
461 prev = ent->set;
462 fn = X509_NAME_ENTRY_get_object(ent);
463 val = X509_NAME_ENTRY_get_data(ent);
464 fn_nid = OBJ_obj2nid(fn);
465 if(fn_opt != XN_FLAG_FN_NONE) {
466 int objlen, fld_len;
467 if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
468 OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1);
469 fld_len = 0; /* XXX: what should this be? */
470 objbuf = objtmp;
471 } else {
472 if(fn_opt == XN_FLAG_FN_SN) {
473 fld_len = FN_WIDTH_SN;
474 objbuf = OBJ_nid2sn(fn_nid);
475 } else if(fn_opt == XN_FLAG_FN_LN) {
476 fld_len = FN_WIDTH_LN;
477 objbuf = OBJ_nid2ln(fn_nid);
478 } else {
479 fld_len = 0; /* XXX: what should this be? */
480 objbuf = "";
481 }
482 }
483 objlen = strlen(objbuf);
484 if(!io_ch(arg, objbuf, objlen)) return -1;
485 if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) {
486 if (!do_indent(io_ch, arg, fld_len - objlen)) return -1;
487 outlen += fld_len - objlen;
488 }
489 if(!io_ch(arg, sep_eq, sep_eq_len)) return -1;
490 outlen += objlen + sep_eq_len;
491 }
492 /* If the field name is unknown then fix up the DER dump
493 * flag. We might want to limit this further so it will
494 * DER dump on anything other than a few 'standard' fields.
495 */
496 if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS))
497 orflags = ASN1_STRFLGS_DUMP_ALL;
498 else orflags = 0;
499
500 len = do_print_ex(io_ch, arg, flags | orflags, val);
501 if(len < 0) return -1;
502 outlen += len;
503 }
504 return outlen;
505}
506
507/* Wrappers round the main functions */
508
509int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
510{
511 if(flags == XN_FLAG_COMPAT)
512 return X509_NAME_print(out, nm, indent);
513 return do_name_ex(send_bio_chars, out, nm, indent, flags);
514}
515
516
517int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
518{
519 if(flags == XN_FLAG_COMPAT)
520 {
521 BIO *btmp;
522 int ret;
523 btmp = BIO_new_fp(fp, BIO_NOCLOSE);
524 if(!btmp) return -1;
525 ret = X509_NAME_print(btmp, nm, indent);
526 BIO_free(btmp);
527 return ret;
528 }
529 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
530}
531
532int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
533{
534 return do_print_ex(send_bio_chars, out, flags, str);
535}
536
537
538int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
539{
540 return do_print_ex(send_fp_chars, fp, flags, str);
541}
542
543/* Utility function: convert any string type to UTF8, returns number of bytes
544 * in output string or a negative error code
545 */
546
547int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
548{
549 ASN1_STRING stmp, *str = &stmp;
550 int mbflag, type, ret;
551 if(!in) return -1;
552 type = in->type;
553 if((type < 0) || (type > 30)) return -1;
554 mbflag = tag2nbyte[type];
555 if(mbflag == -1) return -1;
556 if (mbflag == 0)
557 mbflag = MBSTRING_UTF8;
558 else if (mbflag == 4)
559 mbflag = MBSTRING_UNIV;
560 else
561 mbflag |= MBSTRING_FLAG;
562 stmp.data = NULL;
563 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
564 if(ret < 0) return ret;
565 *out = stmp.data;
566 return stmp.length;
567}
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
new file mode 100644
index 0000000000..613bbc4a7d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -0,0 +1,290 @@
1/* a_strnid.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65
66static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
67static void st_free(ASN1_STRING_TABLE *tbl);
68static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
69 const ASN1_STRING_TABLE * const *b);
70static int table_cmp(const void *a, const void *b);
71
72
73/* This is the global mask for the mbstring functions: this is use to
74 * mask out certain types (such as BMPString and UTF8String) because
75 * certain software (e.g. Netscape) has problems with them.
76 */
77
78static unsigned long global_mask = 0xFFFFFFFFL;
79
80void ASN1_STRING_set_default_mask(unsigned long mask)
81{
82 global_mask = mask;
83}
84
85unsigned long ASN1_STRING_get_default_mask(void)
86{
87 return global_mask;
88}
89
90/* This function sets the default to various "flavours" of configuration.
91 * based on an ASCII string. Currently this is:
92 * MASK:XXXX : a numerical mask value.
93 * nobmp : Don't use BMPStrings (just Printable, T61).
94 * pkix : PKIX recommendation in RFC2459.
95 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
96 * default: the default value, Printable, T61, BMP.
97 */
98
99int ASN1_STRING_set_default_mask_asc(char *p)
100{
101 unsigned long mask;
102 char *end;
103 if(!strncmp(p, "MASK:", 5)) {
104 if(!p[5]) return 0;
105 mask = strtoul(p + 5, &end, 0);
106 if(*end) return 0;
107 } else if(!strcmp(p, "nombstr"))
108 mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING));
109 else if(!strcmp(p, "pkix"))
110 mask = ~((unsigned long)B_ASN1_T61STRING);
111 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
112 else if(!strcmp(p, "default"))
113 mask = 0xFFFFFFFFL;
114 else return 0;
115 ASN1_STRING_set_default_mask(mask);
116 return 1;
117}
118
119/* The following function generates an ASN1_STRING based on limits in a table.
120 * Frequently the types and length of an ASN1_STRING are restricted by a
121 * corresponding OID. For example certificates and certificate requests.
122 */
123
124ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
125 int inlen, int inform, int nid)
126{
127 ASN1_STRING_TABLE *tbl;
128 ASN1_STRING *str = NULL;
129 unsigned long mask;
130 int ret;
131 if(!out) out = &str;
132 tbl = ASN1_STRING_TABLE_get(nid);
133 if(tbl) {
134 mask = tbl->mask;
135 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
136 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
137 tbl->minsize, tbl->maxsize);
138 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
139 if(ret <= 0) return NULL;
140 return *out;
141}
142
143/* Now the tables and helper functions for the string table:
144 */
145
146/* size limits: this stuff is taken straight from RFC3280 */
147
148#define ub_name 32768
149#define ub_common_name 64
150#define ub_locality_name 128
151#define ub_state_name 128
152#define ub_organization_name 64
153#define ub_organization_unit_name 64
154#define ub_title 64
155#define ub_email_address 128
156#define ub_serial_number 64
157
158
159/* This table must be kept in NID order */
160
161static ASN1_STRING_TABLE tbl_standard[] = {
162{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
163{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
164{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
165{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
166{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
167{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
168{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
169{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
170{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
171{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
172{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
174{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
175{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
176{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
177{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
178{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
179{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
180{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
181};
182
183static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
184 const ASN1_STRING_TABLE * const *b)
185{
186 return (*a)->nid - (*b)->nid;
187}
188
189static int table_cmp(const void *a, const void *b)
190{
191 const ASN1_STRING_TABLE *sa = a, *sb = b;
192 return sa->nid - sb->nid;
193}
194
195ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
196{
197 int idx;
198 ASN1_STRING_TABLE *ttmp;
199 ASN1_STRING_TABLE fnd;
200 fnd.nid = nid;
201 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
202 (char *)tbl_standard,
203 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
204 sizeof(ASN1_STRING_TABLE), table_cmp);
205 if(ttmp) return ttmp;
206 if(!stable) return NULL;
207 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
208 if(idx < 0) return NULL;
209 return sk_ASN1_STRING_TABLE_value(stable, idx);
210}
211
212int ASN1_STRING_TABLE_add(int nid,
213 long minsize, long maxsize, unsigned long mask,
214 unsigned long flags)
215{
216 ASN1_STRING_TABLE *tmp;
217 char new_nid = 0;
218 flags &= ~STABLE_FLAGS_MALLOC;
219 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
220 if(!stable) {
221 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
222 return 0;
223 }
224 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
225 tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
226 if(!tmp) {
227 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
228 ERR_R_MALLOC_FAILURE);
229 return 0;
230 }
231 tmp->flags = flags | STABLE_FLAGS_MALLOC;
232 tmp->nid = nid;
233 new_nid = 1;
234 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
235 if(minsize != -1) tmp->minsize = minsize;
236 if(maxsize != -1) tmp->maxsize = maxsize;
237 tmp->mask = mask;
238 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
239 return 1;
240}
241
242void ASN1_STRING_TABLE_cleanup(void)
243{
244 STACK_OF(ASN1_STRING_TABLE) *tmp;
245 tmp = stable;
246 if(!tmp) return;
247 stable = NULL;
248 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
249}
250
251static void st_free(ASN1_STRING_TABLE *tbl)
252{
253 if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl);
254}
255
256
257IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
258
259#ifdef STRING_TABLE_TEST
260
261main()
262{
263 ASN1_STRING_TABLE *tmp;
264 int i, last_nid = -1;
265
266 for (tmp = tbl_standard, i = 0;
267 i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
268 {
269 if (tmp->nid < last_nid)
270 {
271 last_nid = 0;
272 break;
273 }
274 last_nid = tmp->nid;
275 }
276
277 if (last_nid != 0)
278 {
279 printf("Table order OK\n");
280 exit(0);
281 }
282
283 for (tmp = tbl_standard, i = 0;
284 i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
285 printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
286 OBJ_nid2ln(tmp->nid));
287
288}
289
290#endif
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
new file mode 100644
index 0000000000..159681fbcb
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_time.c
@@ -0,0 +1,164 @@
1/* crypto/asn1/a_time.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57/* This is an implementation of the ASN1 Time structure which is:
58 * Time ::= CHOICE {
59 * utcTime UTCTime,
60 * generalTime GeneralizedTime }
61 * written by Steve Henson.
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include "cryptlib.h"
67#include "o_time.h"
68#include <openssl/asn1t.h>
69
70IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
71
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
73
74#if 0
75int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
76 {
77#ifdef CHARSET_EBCDIC
78 /* KLUDGE! We convert to ascii before writing DER */
79 char tmp[24];
80 ASN1_STRING tmpstr;
81
82 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
83 int len;
84
85 tmpstr = *(ASN1_STRING *)a;
86 len = tmpstr.length;
87 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
88 tmpstr.data = tmp;
89 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
90 }
91#endif
92 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
93 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
94 a->type ,V_ASN1_UNIVERSAL));
95 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
96 return -1;
97 }
98#endif
99
100
101ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
102 {
103 struct tm *ts;
104 struct tm data;
105
106 ts=OPENSSL_gmtime(&t,&data);
107 if (ts == NULL)
108 {
109 ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME);
110 return NULL;
111 }
112 if((ts->tm_year >= 50) && (ts->tm_year < 150))
113 return ASN1_UTCTIME_set(s, t);
114 return ASN1_GENERALIZEDTIME_set(s,t);
115 }
116
117int ASN1_TIME_check(ASN1_TIME *t)
118 {
119 if (t->type == V_ASN1_GENERALIZEDTIME)
120 return ASN1_GENERALIZEDTIME_check(t);
121 else if (t->type == V_ASN1_UTCTIME)
122 return ASN1_UTCTIME_check(t);
123 return 0;
124 }
125
126/* Convert an ASN1_TIME structure to GeneralizedTime */
127ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
128 {
129 ASN1_GENERALIZEDTIME *ret;
130 char *str;
131 int newlen;
132
133 if (!ASN1_TIME_check(t)) return NULL;
134
135 if (!out || !*out)
136 {
137 if (!(ret = ASN1_GENERALIZEDTIME_new ()))
138 return NULL;
139 if (out) *out = ret;
140 }
141 else ret = *out;
142
143 /* If already GeneralizedTime just copy across */
144 if (t->type == V_ASN1_GENERALIZEDTIME)
145 {
146 if(!ASN1_STRING_set(ret, t->data, t->length))
147 return NULL;
148 return ret;
149 }
150
151 /* grow the string */
152 if (!ASN1_STRING_set(ret, NULL, t->length + 2))
153 return NULL;
154 /* ASN1_STRING_set() allocated 'len + 1' bytes. */
155 newlen = t->length + 2 + 1;
156 str = (char *)ret->data;
157 /* Work out the century and prepend */
158 if (t->data[0] >= '5') BUF_strlcpy(str, "19", newlen);
159 else BUF_strlcpy(str, "20", newlen);
160
161 BUF_strlcat(str, (char *)t->data, newlen);
162
163 return ret;
164 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
new file mode 100644
index 0000000000..2292d49b93
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_type.c
@@ -0,0 +1,84 @@
1/* crypto/asn1/a_type.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/asn1t.h>
61#include "cryptlib.h"
62
63int ASN1_TYPE_get(ASN1_TYPE *a)
64 {
65 if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
66 return(a->type);
67 else
68 return(0);
69 }
70
71void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
72 {
73 if (a->value.ptr != NULL)
74 {
75 ASN1_TYPE **tmp_a = &a;
76 ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
77 }
78 a->type=type;
79 a->value.ptr=value;
80 }
81
82
83IMPLEMENT_STACK_OF(ASN1_TYPE)
84IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c
new file mode 100644
index 0000000000..508e11e527
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_utf8.c
@@ -0,0 +1,211 @@
1/* crypto/asn1/a_utf8.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63
64/* UTF8 utilities */
65
66/* This parses a UTF8 string one character at a time. It is passed a pointer
67 * to the string and the length of the string. It sets 'value' to the value of
68 * the current character. It returns the number of characters read or a
69 * negative error code:
70 * -1 = string too short
71 * -2 = illegal character
72 * -3 = subsequent characters not of the form 10xxxxxx
73 * -4 = character encoded incorrectly (not minimal length).
74 */
75
76int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
77{
78 const unsigned char *p;
79 unsigned long value;
80 int ret;
81 if(len <= 0) return 0;
82 p = str;
83
84 /* Check syntax and work out the encoded value (if correct) */
85 if((*p & 0x80) == 0) {
86 value = *p++ & 0x7f;
87 ret = 1;
88 } else if((*p & 0xe0) == 0xc0) {
89 if(len < 2) return -1;
90 if((p[1] & 0xc0) != 0x80) return -3;
91 value = (*p++ & 0x1f) << 6;
92 value |= *p++ & 0x3f;
93 if(value < 0x80) return -4;
94 ret = 2;
95 } else if((*p & 0xf0) == 0xe0) {
96 if(len < 3) return -1;
97 if( ((p[1] & 0xc0) != 0x80)
98 || ((p[2] & 0xc0) != 0x80) ) return -3;
99 value = (*p++ & 0xf) << 12;
100 value |= (*p++ & 0x3f) << 6;
101 value |= *p++ & 0x3f;
102 if(value < 0x800) return -4;
103 ret = 3;
104 } else if((*p & 0xf8) == 0xf0) {
105 if(len < 4) return -1;
106 if( ((p[1] & 0xc0) != 0x80)
107 || ((p[2] & 0xc0) != 0x80)
108 || ((p[3] & 0xc0) != 0x80) ) return -3;
109 value = ((unsigned long)(*p++ & 0x7)) << 18;
110 value |= (*p++ & 0x3f) << 12;
111 value |= (*p++ & 0x3f) << 6;
112 value |= *p++ & 0x3f;
113 if(value < 0x10000) return -4;
114 ret = 4;
115 } else if((*p & 0xfc) == 0xf8) {
116 if(len < 5) return -1;
117 if( ((p[1] & 0xc0) != 0x80)
118 || ((p[2] & 0xc0) != 0x80)
119 || ((p[3] & 0xc0) != 0x80)
120 || ((p[4] & 0xc0) != 0x80) ) return -3;
121 value = ((unsigned long)(*p++ & 0x3)) << 24;
122 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
123 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
124 value |= (*p++ & 0x3f) << 6;
125 value |= *p++ & 0x3f;
126 if(value < 0x200000) return -4;
127 ret = 5;
128 } else if((*p & 0xfe) == 0xfc) {
129 if(len < 6) return -1;
130 if( ((p[1] & 0xc0) != 0x80)
131 || ((p[2] & 0xc0) != 0x80)
132 || ((p[3] & 0xc0) != 0x80)
133 || ((p[4] & 0xc0) != 0x80)
134 || ((p[5] & 0xc0) != 0x80) ) return -3;
135 value = ((unsigned long)(*p++ & 0x1)) << 30;
136 value |= ((unsigned long)(*p++ & 0x3f)) << 24;
137 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
138 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
139 value |= (*p++ & 0x3f) << 6;
140 value |= *p++ & 0x3f;
141 if(value < 0x4000000) return -4;
142 ret = 6;
143 } else return -2;
144 *val = value;
145 return ret;
146}
147
148/* This takes a character 'value' and writes the UTF8 encoded value in
149 * 'str' where 'str' is a buffer containing 'len' characters. Returns
150 * the number of characters written or -1 if 'len' is too small. 'str' can
151 * be set to NULL in which case it just returns the number of characters.
152 * It will need at most 6 characters.
153 */
154
155int UTF8_putc(unsigned char *str, int len, unsigned long value)
156{
157 if(!str) len = 6; /* Maximum we will need */
158 else if(len <= 0) return -1;
159 if(value < 0x80) {
160 if(str) *str = (unsigned char)value;
161 return 1;
162 }
163 if(value < 0x800) {
164 if(len < 2) return -1;
165 if(str) {
166 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
167 *str = (unsigned char)((value & 0x3f) | 0x80);
168 }
169 return 2;
170 }
171 if(value < 0x10000) {
172 if(len < 3) return -1;
173 if(str) {
174 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
175 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
176 *str = (unsigned char)((value & 0x3f) | 0x80);
177 }
178 return 3;
179 }
180 if(value < 0x200000) {
181 if(len < 4) return -1;
182 if(str) {
183 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
184 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
185 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
186 *str = (unsigned char)((value & 0x3f) | 0x80);
187 }
188 return 4;
189 }
190 if(value < 0x4000000) {
191 if(len < 5) return -1;
192 if(str) {
193 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);
194 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
195 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
196 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
197 *str = (unsigned char)((value & 0x3f) | 0x80);
198 }
199 return 5;
200 }
201 if(len < 6) return -1;
202 if(str) {
203 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);
204 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);
205 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
206 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
207 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
208 *str = (unsigned char)((value & 0x3f) | 0x80);
209 }
210 return 6;
211}
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
new file mode 100644
index 0000000000..18ef0acf00
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -0,0 +1,181 @@
1/* crypto/asn1/a_verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/bn.h>
69#include <openssl/x509.h>
70#include <openssl/objects.h>
71#include <openssl/buffer.h>
72#include <openssl/evp.h>
73
74#ifndef NO_ASN1_OLD
75
76int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
77 char *data, EVP_PKEY *pkey)
78 {
79 EVP_MD_CTX ctx;
80 const EVP_MD *type;
81 unsigned char *p,*buf_in=NULL;
82 int ret= -1,i,inl;
83
84 EVP_MD_CTX_init(&ctx);
85 i=OBJ_obj2nid(a->algorithm);
86 type=EVP_get_digestbyname(OBJ_nid2sn(i));
87 if (type == NULL)
88 {
89 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
90 goto err;
91 }
92
93 inl=i2d(data,NULL);
94 buf_in=OPENSSL_malloc((unsigned int)inl);
95 if (buf_in == NULL)
96 {
97 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
98 goto err;
99 }
100 p=buf_in;
101
102 i2d(data,&p);
103 EVP_VerifyInit_ex(&ctx,type, NULL);
104 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
105
106 OPENSSL_cleanse(buf_in,(unsigned int)inl);
107 OPENSSL_free(buf_in);
108
109 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
110 (unsigned int)signature->length,pkey) <= 0)
111 {
112 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
113 ret=0;
114 goto err;
115 }
116 /* we don't need to zero the 'ctx' because we just checked
117 * public information */
118 /* memset(&ctx,0,sizeof(ctx)); */
119 ret=1;
120err:
121 EVP_MD_CTX_cleanup(&ctx);
122 return(ret);
123 }
124
125#endif
126
127
128int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signature,
129 void *asn, EVP_PKEY *pkey)
130 {
131 EVP_MD_CTX ctx;
132 const EVP_MD *type;
133 unsigned char *buf_in=NULL;
134 int ret= -1,i,inl;
135
136 EVP_MD_CTX_init(&ctx);
137 i=OBJ_obj2nid(a->algorithm);
138 type=EVP_get_digestbyname(OBJ_nid2sn(i));
139 if (type == NULL)
140 {
141 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
142 goto err;
143 }
144
145 if (!EVP_VerifyInit_ex(&ctx,type, NULL))
146 {
147 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
148 ret=0;
149 goto err;
150 }
151
152 inl = ASN1_item_i2d(asn, &buf_in, it);
153
154 if (buf_in == NULL)
155 {
156 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
157 goto err;
158 }
159
160 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
161
162 OPENSSL_cleanse(buf_in,(unsigned int)inl);
163 OPENSSL_free(buf_in);
164
165 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
166 (unsigned int)signature->length,pkey) <= 0)
167 {
168 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
169 ret=0;
170 goto err;
171 }
172 /* we don't need to zero the 'ctx' because we just checked
173 * public information */
174 /* memset(&ctx,0,sizeof(ctx)); */
175 ret=1;
176err:
177 EVP_MD_CTX_cleanup(&ctx);
178 return(ret);
179 }
180
181
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
new file mode 100644
index 0000000000..ceaeb4cbe3
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -0,0 +1,1111 @@
1/* crypto/asn1/asn1.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ASN1_H
60#define HEADER_ASN1_H
61
62#include <time.h>
63#ifndef OPENSSL_NO_BIO
64#include <openssl/bio.h>
65#endif
66#include <openssl/e_os2.h>
67#include <openssl/bn.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70
71#include <openssl/symhacks.h>
72
73#include <openssl/ossl_typ.h>
74
75#ifdef OPENSSL_BUILD_SHLIBCRYPTO
76# undef OPENSSL_EXTERN
77# define OPENSSL_EXTERN OPENSSL_EXPORT
78#endif
79
80#ifdef __cplusplus
81extern "C" {
82#endif
83
84#define V_ASN1_UNIVERSAL 0x00
85#define V_ASN1_APPLICATION 0x40
86#define V_ASN1_CONTEXT_SPECIFIC 0x80
87#define V_ASN1_PRIVATE 0xc0
88
89#define V_ASN1_CONSTRUCTED 0x20
90#define V_ASN1_PRIMITIVE_TAG 0x1f
91#define V_ASN1_PRIMATIVE_TAG 0x1f
92
93#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
94#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
95#define V_ASN1_ANY -4 /* used in ASN1 template code */
96
97#define V_ASN1_NEG 0x100 /* negative flag */
98
99#define V_ASN1_UNDEF -1
100#define V_ASN1_EOC 0
101#define V_ASN1_BOOLEAN 1 /**/
102#define V_ASN1_INTEGER 2
103#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
104#define V_ASN1_BIT_STRING 3
105#define V_ASN1_OCTET_STRING 4
106#define V_ASN1_NULL 5
107#define V_ASN1_OBJECT 6
108#define V_ASN1_OBJECT_DESCRIPTOR 7
109#define V_ASN1_EXTERNAL 8
110#define V_ASN1_REAL 9
111#define V_ASN1_ENUMERATED 10
112#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
113#define V_ASN1_UTF8STRING 12
114#define V_ASN1_SEQUENCE 16
115#define V_ASN1_SET 17
116#define V_ASN1_NUMERICSTRING 18 /**/
117#define V_ASN1_PRINTABLESTRING 19
118#define V_ASN1_T61STRING 20
119#define V_ASN1_TELETEXSTRING 20 /* alias */
120#define V_ASN1_VIDEOTEXSTRING 21 /**/
121#define V_ASN1_IA5STRING 22
122#define V_ASN1_UTCTIME 23
123#define V_ASN1_GENERALIZEDTIME 24 /**/
124#define V_ASN1_GRAPHICSTRING 25 /**/
125#define V_ASN1_ISO64STRING 26 /**/
126#define V_ASN1_VISIBLESTRING 26 /* alias */
127#define V_ASN1_GENERALSTRING 27 /**/
128#define V_ASN1_UNIVERSALSTRING 28 /**/
129#define V_ASN1_BMPSTRING 30
130
131/* For use with d2i_ASN1_type_bytes() */
132#define B_ASN1_NUMERICSTRING 0x0001
133#define B_ASN1_PRINTABLESTRING 0x0002
134#define B_ASN1_T61STRING 0x0004
135#define B_ASN1_TELETEXSTRING 0x0004
136#define B_ASN1_VIDEOTEXSTRING 0x0008
137#define B_ASN1_IA5STRING 0x0010
138#define B_ASN1_GRAPHICSTRING 0x0020
139#define B_ASN1_ISO64STRING 0x0040
140#define B_ASN1_VISIBLESTRING 0x0040
141#define B_ASN1_GENERALSTRING 0x0080
142#define B_ASN1_UNIVERSALSTRING 0x0100
143#define B_ASN1_OCTET_STRING 0x0200
144#define B_ASN1_BIT_STRING 0x0400
145#define B_ASN1_BMPSTRING 0x0800
146#define B_ASN1_UNKNOWN 0x1000
147#define B_ASN1_UTF8STRING 0x2000
148#define B_ASN1_UTCTIME 0x4000
149#define B_ASN1_GENERALIZEDTIME 0x8000
150
151/* For use with ASN1_mbstring_copy() */
152#define MBSTRING_FLAG 0x1000
153#define MBSTRING_ASC (MBSTRING_FLAG|1)
154#define MBSTRING_BMP (MBSTRING_FLAG|2)
155#define MBSTRING_UNIV (MBSTRING_FLAG|3)
156#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
157
158struct X509_algor_st;
159
160#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
161#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
162
163typedef struct asn1_ctx_st
164 {
165 unsigned char *p;/* work char pointer */
166 int eos; /* end of sequence read for indefinite encoding */
167 int error; /* error code to use when returning an error */
168 int inf; /* constructed if 0x20, indefinite is 0x21 */
169 int tag; /* tag from last 'get object' */
170 int xclass; /* class from last 'get object' */
171 long slen; /* length of last 'get object' */
172 unsigned char *max; /* largest value of p allowed */
173 unsigned char *q;/* temporary variable */
174 unsigned char **pp;/* variable */
175 int line; /* used in error processing */
176 } ASN1_CTX;
177
178/* These are used internally in the ASN1_OBJECT to keep track of
179 * whether the names and data need to be free()ed */
180#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
181#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
182#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
183#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
184typedef struct asn1_object_st
185 {
186 const char *sn,*ln;
187 int nid;
188 int length;
189 unsigned char *data;
190 int flags; /* Should we free this one */
191 } ASN1_OBJECT;
192
193#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
194/* This is the base type that holds just about everything :-) */
195typedef struct asn1_string_st
196 {
197 int length;
198 int type;
199 unsigned char *data;
200 /* The value of the following field depends on the type being
201 * held. It is mostly being used for BIT_STRING so if the
202 * input data has a non-zero 'unused bits' value, it will be
203 * handled correctly */
204 long flags;
205 } ASN1_STRING;
206
207/* ASN1_ENCODING structure: this is used to save the received
208 * encoding of an ASN1 type. This is useful to get round
209 * problems with invalid encodings which can break signatures.
210 */
211
212typedef struct ASN1_ENCODING_st
213 {
214 unsigned char *enc; /* DER encoding */
215 long len; /* Length of encoding */
216 int modified; /* set to 1 if 'enc' is invalid */
217 } ASN1_ENCODING;
218
219/* Used with ASN1 LONG type: if a long is set to this it is omitted */
220#define ASN1_LONG_UNDEF 0x7fffffffL
221
222#define STABLE_FLAGS_MALLOC 0x01
223#define STABLE_NO_MASK 0x02
224#define DIRSTRING_TYPE \
225 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
226#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
227
228typedef struct asn1_string_table_st {
229 int nid;
230 long minsize;
231 long maxsize;
232 unsigned long mask;
233 unsigned long flags;
234} ASN1_STRING_TABLE;
235
236DECLARE_STACK_OF(ASN1_STRING_TABLE)
237
238/* size limits: this stuff is taken straight from RFC2459 */
239
240#define ub_name 32768
241#define ub_common_name 64
242#define ub_locality_name 128
243#define ub_state_name 128
244#define ub_organization_name 64
245#define ub_organization_unit_name 64
246#define ub_title 64
247#define ub_email_address 128
248
249/* Declarations for template structures: for full definitions
250 * see asn1t.h
251 */
252typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
253typedef struct ASN1_ITEM_st ASN1_ITEM;
254typedef struct ASN1_TLC_st ASN1_TLC;
255/* This is just an opaque pointer */
256typedef struct ASN1_VALUE_st ASN1_VALUE;
257
258/* Declare ASN1 functions: the implement macro in in asn1t.h */
259
260#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
261
262#define DECLARE_ASN1_FUNCTIONS_name(type, name) \
263 type *name##_new(void); \
264 void name##_free(type *a); \
265 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
266
267#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
268 type *name##_new(void); \
269 void name##_free(type *a); \
270 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
271
272#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
273 type *d2i_##name(type **a, unsigned char **in, long len); \
274 int i2d_##name(type *a, unsigned char **out); \
275 DECLARE_ASN1_ITEM(itname)
276
277#define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
278 type *d2i_##name(type **a, const unsigned char **in, long len); \
279 int i2d_##name(const type *a, unsigned char **out); \
280 DECLARE_ASN1_ITEM(name)
281
282#define DECLARE_ASN1_FUNCTIONS_const(name) \
283 name *name##_new(void); \
284 void name##_free(name *a);
285
286
287/* The following macros and typedefs allow an ASN1_ITEM
288 * to be embedded in a structure and referenced. Since
289 * the ASN1_ITEM pointers need to be globally accessible
290 * (possibly from shared libraries) they may exist in
291 * different forms. On platforms that support it the
292 * ASN1_ITEM structure itself will be globally exported.
293 * Other platforms will export a function that returns
294 * an ASN1_ITEM pointer.
295 *
296 * To handle both cases transparently the macros below
297 * should be used instead of hard coding an ASN1_ITEM
298 * pointer in a structure.
299 *
300 * The structure will look like this:
301 *
302 * typedef struct SOMETHING_st {
303 * ...
304 * ASN1_ITEM_EXP *iptr;
305 * ...
306 * } SOMETHING;
307 *
308 * It would be initialised as e.g.:
309 *
310 * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
311 *
312 * and the actual pointer extracted with:
313 *
314 * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
315 *
316 * Finally an ASN1_ITEM pointer can be extracted from an
317 * appropriate reference with: ASN1_ITEM_rptr(X509). This
318 * would be used when a function takes an ASN1_ITEM * argument.
319 *
320 */
321
322#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
323
324/* ASN1_ITEM pointer exported type */
325typedef const ASN1_ITEM ASN1_ITEM_EXP;
326
327/* Macro to obtain ASN1_ITEM pointer from exported type */
328#define ASN1_ITEM_ptr(iptr) (iptr)
329
330/* Macro to include ASN1_ITEM pointer from base type */
331#define ASN1_ITEM_ref(iptr) (&(iptr##_it))
332
333#define ASN1_ITEM_rptr(ref) (&(ref##_it))
334
335#define DECLARE_ASN1_ITEM(name) \
336 OPENSSL_EXTERN const ASN1_ITEM name##_it;
337
338#else
339
340/* Platforms that can't easily handle shared global variables are declared
341 * as functions returning ASN1_ITEM pointers.
342 */
343
344/* ASN1_ITEM pointer exported type */
345typedef const ASN1_ITEM * ASN1_ITEM_EXP(void);
346
347/* Macro to obtain ASN1_ITEM pointer from exported type */
348#define ASN1_ITEM_ptr(iptr) (iptr())
349
350/* Macro to include ASN1_ITEM pointer from base type */
351#define ASN1_ITEM_ref(iptr) (iptr##_it)
352
353#define ASN1_ITEM_rptr(ref) (ref##_it())
354
355#define DECLARE_ASN1_ITEM(name) \
356 const ASN1_ITEM * name##_it(void);
357
358#endif
359
360/* Parameters used by ASN1_STRING_print_ex() */
361
362/* These determine which characters to escape:
363 * RFC2253 special characters, control characters and
364 * MSB set characters
365 */
366
367#define ASN1_STRFLGS_ESC_2253 1
368#define ASN1_STRFLGS_ESC_CTRL 2
369#define ASN1_STRFLGS_ESC_MSB 4
370
371
372/* This flag determines how we do escaping: normally
373 * RC2253 backslash only, set this to use backslash and
374 * quote.
375 */
376
377#define ASN1_STRFLGS_ESC_QUOTE 8
378
379
380/* These three flags are internal use only. */
381
382/* Character is a valid PrintableString character */
383#define CHARTYPE_PRINTABLESTRING 0x10
384/* Character needs escaping if it is the first character */
385#define CHARTYPE_FIRST_ESC_2253 0x20
386/* Character needs escaping if it is the last character */
387#define CHARTYPE_LAST_ESC_2253 0x40
388
389/* NB the internal flags are safely reused below by flags
390 * handled at the top level.
391 */
392
393/* If this is set we convert all character strings
394 * to UTF8 first
395 */
396
397#define ASN1_STRFLGS_UTF8_CONVERT 0x10
398
399/* If this is set we don't attempt to interpret content:
400 * just assume all strings are 1 byte per character. This
401 * will produce some pretty odd looking output!
402 */
403
404#define ASN1_STRFLGS_IGNORE_TYPE 0x20
405
406/* If this is set we include the string type in the output */
407#define ASN1_STRFLGS_SHOW_TYPE 0x40
408
409/* This determines which strings to display and which to
410 * 'dump' (hex dump of content octets or DER encoding). We can
411 * only dump non character strings or everything. If we
412 * don't dump 'unknown' they are interpreted as character
413 * strings with 1 octet per character and are subject to
414 * the usual escaping options.
415 */
416
417#define ASN1_STRFLGS_DUMP_ALL 0x80
418#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
419
420/* These determine what 'dumping' does, we can dump the
421 * content octets or the DER encoding: both use the
422 * RFC2253 #XXXXX notation.
423 */
424
425#define ASN1_STRFLGS_DUMP_DER 0x200
426
427/* All the string flags consistent with RFC2253,
428 * escaping control characters isn't essential in
429 * RFC2253 but it is advisable anyway.
430 */
431
432#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
433 ASN1_STRFLGS_ESC_CTRL | \
434 ASN1_STRFLGS_ESC_MSB | \
435 ASN1_STRFLGS_UTF8_CONVERT | \
436 ASN1_STRFLGS_DUMP_UNKNOWN | \
437 ASN1_STRFLGS_DUMP_DER)
438
439DECLARE_STACK_OF(ASN1_INTEGER)
440DECLARE_ASN1_SET_OF(ASN1_INTEGER)
441
442DECLARE_STACK_OF(ASN1_GENERALSTRING)
443
444typedef struct asn1_type_st
445 {
446 int type;
447 union {
448 char *ptr;
449 ASN1_BOOLEAN boolean;
450 ASN1_STRING * asn1_string;
451 ASN1_OBJECT * object;
452 ASN1_INTEGER * integer;
453 ASN1_ENUMERATED * enumerated;
454 ASN1_BIT_STRING * bit_string;
455 ASN1_OCTET_STRING * octet_string;
456 ASN1_PRINTABLESTRING * printablestring;
457 ASN1_T61STRING * t61string;
458 ASN1_IA5STRING * ia5string;
459 ASN1_GENERALSTRING * generalstring;
460 ASN1_BMPSTRING * bmpstring;
461 ASN1_UNIVERSALSTRING * universalstring;
462 ASN1_UTCTIME * utctime;
463 ASN1_GENERALIZEDTIME * generalizedtime;
464 ASN1_VISIBLESTRING * visiblestring;
465 ASN1_UTF8STRING * utf8string;
466 /* set and sequence are left complete and still
467 * contain the set or sequence bytes */
468 ASN1_STRING * set;
469 ASN1_STRING * sequence;
470 } value;
471 } ASN1_TYPE;
472
473DECLARE_STACK_OF(ASN1_TYPE)
474DECLARE_ASN1_SET_OF(ASN1_TYPE)
475
476typedef struct asn1_method_st
477 {
478 int (*i2d)();
479 char *(*d2i)();
480 char *(*create)();
481 void (*destroy)();
482 } ASN1_METHOD;
483
484/* This is used when parsing some Netscape objects */
485typedef struct asn1_header_st
486 {
487 ASN1_OCTET_STRING *header;
488 char *data;
489 ASN1_METHOD *meth;
490 } ASN1_HEADER;
491
492/* This is used to contain a list of bit names */
493typedef struct BIT_STRING_BITNAME_st {
494 int bitnum;
495 const char *lname;
496 const char *sname;
497} BIT_STRING_BITNAME;
498
499
500#define M_ASN1_STRING_length(x) ((x)->length)
501#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
502#define M_ASN1_STRING_type(x) ((x)->type)
503#define M_ASN1_STRING_data(x) ((x)->data)
504
505/* Macros for string operations */
506#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
507 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
508#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
509#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
510 ASN1_STRING_dup((ASN1_STRING *)a)
511#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
512 (ASN1_STRING *)a,(ASN1_STRING *)b)
513#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
514
515#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
516 ASN1_STRING_type_new(V_ASN1_INTEGER)
517#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
518#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
519#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
520 (ASN1_STRING *)a,(ASN1_STRING *)b)
521
522#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
523 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
524#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
525#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
526#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
527 (ASN1_STRING *)a,(ASN1_STRING *)b)
528
529#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
530 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
531#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
532#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
533 ASN1_STRING_dup((ASN1_STRING *)a)
534#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
535 (ASN1_STRING *)a,(ASN1_STRING *)b)
536#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
537#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
538#define M_i2d_ASN1_OCTET_STRING(a,pp) \
539 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
540 V_ASN1_UNIVERSAL)
541
542#define B_ASN1_TIME \
543 B_ASN1_UTCTIME | \
544 B_ASN1_GENERALIZEDTIME
545
546#define B_ASN1_PRINTABLE \
547 B_ASN1_PRINTABLESTRING| \
548 B_ASN1_T61STRING| \
549 B_ASN1_IA5STRING| \
550 B_ASN1_BIT_STRING| \
551 B_ASN1_UNIVERSALSTRING|\
552 B_ASN1_BMPSTRING|\
553 B_ASN1_UTF8STRING|\
554 B_ASN1_UNKNOWN
555
556#define B_ASN1_DIRECTORYSTRING \
557 B_ASN1_PRINTABLESTRING| \
558 B_ASN1_TELETEXSTRING|\
559 B_ASN1_BMPSTRING|\
560 B_ASN1_UNIVERSALSTRING|\
561 B_ASN1_UTF8STRING
562
563#define B_ASN1_DISPLAYTEXT \
564 B_ASN1_IA5STRING| \
565 B_ASN1_VISIBLESTRING| \
566 B_ASN1_BMPSTRING|\
567 B_ASN1_UTF8STRING
568
569#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
570#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
571#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
572 pp,a->type,V_ASN1_UNIVERSAL)
573#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
574 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
575 B_ASN1_PRINTABLE)
576
577#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
578#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
579#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
580 pp,a->type,V_ASN1_UNIVERSAL)
581#define M_d2i_DIRECTORYSTRING(a,pp,l) \
582 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
583 B_ASN1_DIRECTORYSTRING)
584
585#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
586#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
587#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
588 pp,a->type,V_ASN1_UNIVERSAL)
589#define M_d2i_DISPLAYTEXT(a,pp,l) \
590 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
591 B_ASN1_DISPLAYTEXT)
592
593#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
594 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
595#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
596#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
597 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
598 V_ASN1_UNIVERSAL)
599#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
600 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
601 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
602
603#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
604 ASN1_STRING_type_new(V_ASN1_T61STRING)
605#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
606#define M_i2d_ASN1_T61STRING(a,pp) \
607 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
608 V_ASN1_UNIVERSAL)
609#define M_d2i_ASN1_T61STRING(a,pp,l) \
610 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
611 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
612
613#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
614 ASN1_STRING_type_new(V_ASN1_IA5STRING)
615#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
616#define M_ASN1_IA5STRING_dup(a) \
617 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
618#define M_i2d_ASN1_IA5STRING(a,pp) \
619 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
620 V_ASN1_UNIVERSAL)
621#define M_d2i_ASN1_IA5STRING(a,pp,l) \
622 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
623 B_ASN1_IA5STRING)
624
625#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
626 ASN1_STRING_type_new(V_ASN1_UTCTIME)
627#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
628#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
629
630#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
631 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
632#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
633#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
634 (ASN1_STRING *)a)
635
636#define M_ASN1_TIME_new() (ASN1_TIME *)\
637 ASN1_STRING_type_new(V_ASN1_UTCTIME)
638#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
639#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
640
641#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
642 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
643#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
644#define M_i2d_ASN1_GENERALSTRING(a,pp) \
645 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
646 V_ASN1_UNIVERSAL)
647#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
648 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
649 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
650
651#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
652 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
653#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
654#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
655 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
656 V_ASN1_UNIVERSAL)
657#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
658 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
659 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
660
661#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
662 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
663#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
664#define M_i2d_ASN1_BMPSTRING(a,pp) \
665 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
666 V_ASN1_UNIVERSAL)
667#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
668 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
669 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
670
671#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
672 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
673#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
674#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
675 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
676 V_ASN1_UNIVERSAL)
677#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
678 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
679 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
680
681#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
682 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
683#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
684#define M_i2d_ASN1_UTF8STRING(a,pp) \
685 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
686 V_ASN1_UNIVERSAL)
687#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
688 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
689 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
690
691 /* for the is_set parameter to i2d_ASN1_SET */
692#define IS_SEQUENCE 0
693#define IS_SET 1
694
695DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
696
697int ASN1_TYPE_get(ASN1_TYPE *a);
698void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
699
700ASN1_OBJECT * ASN1_OBJECT_new(void );
701void ASN1_OBJECT_free(ASN1_OBJECT *a);
702int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
703ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
704 long length);
705ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
706 long length);
707
708DECLARE_ASN1_ITEM(ASN1_OBJECT)
709
710DECLARE_STACK_OF(ASN1_OBJECT)
711DECLARE_ASN1_SET_OF(ASN1_OBJECT)
712
713ASN1_STRING * ASN1_STRING_new(void);
714void ASN1_STRING_free(ASN1_STRING *a);
715ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
716ASN1_STRING * ASN1_STRING_type_new(int type );
717int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
718 /* Since this is used to store all sorts of things, via macros, for now, make
719 its data void * */
720int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
721int ASN1_STRING_length(ASN1_STRING *x);
722void ASN1_STRING_length_set(ASN1_STRING *x, int n);
723int ASN1_STRING_type(ASN1_STRING *x);
724unsigned char * ASN1_STRING_data(ASN1_STRING *x);
725
726DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
727int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
728ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
729 long length);
730int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
731 int length );
732int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
733int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
734
735#ifndef OPENSSL_NO_BIO
736int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
737 BIT_STRING_BITNAME *tbl, int indent);
738#endif
739int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
740int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
741 BIT_STRING_BITNAME *tbl);
742
743int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
744int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
745
746DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
747int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
748ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
749 long length);
750ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
751 long length);
752ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
753int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
754
755DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
756
757int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
758ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
759int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
760int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
761#if 0
762time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
763#endif
764
765int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
766ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
767int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
768
769DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
770ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
771int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
772int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
773
774DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
775DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
776DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
777DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
778DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
779
780int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
781int UTF8_putc(unsigned char *str, int len, unsigned long value);
782
783DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
784
785DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
786DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
787DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
788DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
789DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
790DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
791DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
792DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
793DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
794
795ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
796int ASN1_TIME_check(ASN1_TIME *t);
797ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
798
799int i2d_ASN1_SET(STACK *a, unsigned char **pp,
800 int (*func)(), int ex_tag, int ex_class, int is_set);
801STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
802 char *(*func)(), void (*free_func)(void *),
803 int ex_tag, int ex_class);
804
805#ifndef OPENSSL_NO_BIO
806int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
807int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
808int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
809int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
810int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
811int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
812int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
813#endif
814int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
815
816int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
817ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
818 const char *sn, const char *ln);
819
820int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
821long ASN1_INTEGER_get(ASN1_INTEGER *a);
822ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
823BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
824
825int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
826long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
827ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
828BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
829
830/* General */
831/* given a string, return the correct type, max is the maximum length */
832int ASN1_PRINTABLE_type(const unsigned char *s, int max);
833
834int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
835ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
836 long length, int Ptag, int Pclass);
837unsigned long ASN1_tag2bit(int tag);
838/* type is one or more of the B_ASN1_ values. */
839ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
840 long length,int type);
841
842/* PARSING */
843int asn1_Finish(ASN1_CTX *c);
844
845/* SPECIALS */
846int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
847 int *pclass, long omax);
848int ASN1_check_infinite_end(unsigned char **p,long len);
849void ASN1_put_object(unsigned char **pp, int constructed, int length,
850 int tag, int xclass);
851int ASN1_object_size(int constructed, int length, int tag);
852
853/* Used to implement other functions */
854char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
855
856void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
857
858#ifndef OPENSSL_NO_FP_API
859char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
860void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
861int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
862int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
863int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
864#endif
865
866int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
867
868#ifndef OPENSSL_NO_BIO
869char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
870void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
871int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
872int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
873int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
874int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
875int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
876int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
877int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
878int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
879int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
880#endif
881const char *ASN1_tag2str(int tag);
882
883/* Used to load and write netscape format cert/key */
884int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
885ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
886ASN1_HEADER *ASN1_HEADER_new(void );
887void ASN1_HEADER_free(ASN1_HEADER *a);
888
889int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
890
891/* Not used that much at this point, except for the first two */
892ASN1_METHOD *X509_asn1_meth(void);
893ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
894ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
895ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
896
897int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
898 unsigned char *data, int len);
899int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
900 unsigned char *data, int max_len);
901int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
902 unsigned char *data, int len);
903int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
904 unsigned char *data, int max_len);
905
906STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
907 void (*free_func)(void *) );
908unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
909 int *len );
910void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
911void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
912ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
913ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
914
915void ASN1_STRING_set_default_mask(unsigned long mask);
916int ASN1_STRING_set_default_mask_asc(char *p);
917unsigned long ASN1_STRING_get_default_mask(void);
918int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
919 int inform, unsigned long mask);
920int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
921 int inform, unsigned long mask,
922 long minsize, long maxsize);
923
924ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
925 const unsigned char *in, int inlen, int inform, int nid);
926ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
927int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
928void ASN1_STRING_TABLE_cleanup(void);
929
930/* ASN1 template functions */
931
932/* Old API compatible functions */
933ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
934void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
935ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
936int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
937
938void ASN1_add_oid_module(void);
939
940/* BEGIN ERROR CODES */
941/* The following lines are auto generated by the script mkerr.pl. Any changes
942 * made after this point may be overwritten when the script is next run.
943 */
944void ERR_load_ASN1_strings(void);
945
946/* Error codes for the ASN1 functions. */
947
948/* Function codes. */
949#define ASN1_F_A2D_ASN1_OBJECT 100
950#define ASN1_F_A2I_ASN1_ENUMERATED 101
951#define ASN1_F_A2I_ASN1_INTEGER 102
952#define ASN1_F_A2I_ASN1_STRING 103
953#define ASN1_F_ASN1_BIT_STRING_SET_BIT 176
954#define ASN1_F_ASN1_CHECK_TLEN 104
955#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105
956#define ASN1_F_ASN1_COLLECT 106
957#define ASN1_F_ASN1_D2I_BIO 107
958#define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108
959#define ASN1_F_ASN1_D2I_FP 109
960#define ASN1_F_ASN1_DIGEST 177
961#define ASN1_F_ASN1_DO_ADB 110
962#define ASN1_F_ASN1_DUP 111
963#define ASN1_F_ASN1_ENUMERATED_SET 112
964#define ASN1_F_ASN1_ENUMERATED_TO_BN 113
965#define ASN1_F_ASN1_GENERALIZEDTIME_SET 178
966#define ASN1_F_ASN1_GET_OBJECT 114
967#define ASN1_F_ASN1_HEADER_NEW 115
968#define ASN1_F_ASN1_I2D_BIO 116
969#define ASN1_F_ASN1_I2D_FP 117
970#define ASN1_F_ASN1_INTEGER_SET 118
971#define ASN1_F_ASN1_INTEGER_TO_BN 119
972#define ASN1_F_ASN1_ITEM_EX_D2I 120
973#define ASN1_F_ASN1_ITEM_NEW 121
974#define ASN1_F_ASN1_MBSTRING_COPY 122
975#define ASN1_F_ASN1_OBJECT_NEW 123
976#define ASN1_F_ASN1_PACK_STRING 124
977#define ASN1_F_ASN1_PBE_SET 125
978#define ASN1_F_ASN1_SEQ_PACK 126
979#define ASN1_F_ASN1_SEQ_UNPACK 127
980#define ASN1_F_ASN1_SIGN 128
981#define ASN1_F_ASN1_STRING_SET 179
982#define ASN1_F_ASN1_STRING_TABLE_ADD 129
983#define ASN1_F_ASN1_STRING_TYPE_NEW 130
984#define ASN1_F_ASN1_TEMPLATE_D2I 131
985#define ASN1_F_ASN1_TEMPLATE_EX_D2I 132
986#define ASN1_F_ASN1_TEMPLATE_NEW 133
987#define ASN1_F_ASN1_TIME_SET 175
988#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134
989#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135
990#define ASN1_F_ASN1_UNPACK_STRING 136
991#define ASN1_F_ASN1_UTCTIME_SET 180
992#define ASN1_F_ASN1_VERIFY 137
993#define ASN1_F_BN_TO_ASN1_ENUMERATED 138
994#define ASN1_F_BN_TO_ASN1_INTEGER 139
995#define ASN1_F_COLLECT_DATA 140
996#define ASN1_F_D2I_ASN1_BIT_STRING 141
997#define ASN1_F_D2I_ASN1_BOOLEAN 142
998#define ASN1_F_D2I_ASN1_BYTES 143
999#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144
1000#define ASN1_F_D2I_ASN1_HEADER 145
1001#define ASN1_F_D2I_ASN1_INTEGER 146
1002#define ASN1_F_D2I_ASN1_OBJECT 147
1003#define ASN1_F_D2I_ASN1_SET 148
1004#define ASN1_F_D2I_ASN1_TYPE_BYTES 149
1005#define ASN1_F_D2I_ASN1_UINTEGER 150
1006#define ASN1_F_D2I_ASN1_UTCTIME 151
1007#define ASN1_F_D2I_NETSCAPE_RSA 152
1008#define ASN1_F_D2I_NETSCAPE_RSA_2 153
1009#define ASN1_F_D2I_PRIVATEKEY 154
1010#define ASN1_F_D2I_PUBLICKEY 155
1011#define ASN1_F_D2I_X509 156
1012#define ASN1_F_D2I_X509_CINF 157
1013#define ASN1_F_D2I_X509_NAME 158
1014#define ASN1_F_D2I_X509_PKEY 159
1015#define ASN1_F_I2D_ASN1_SET 181
1016#define ASN1_F_I2D_ASN1_TIME 160
1017#define ASN1_F_I2D_DSA_PUBKEY 161
1018#define ASN1_F_I2D_NETSCAPE_RSA 162
1019#define ASN1_F_I2D_PRIVATEKEY 163
1020#define ASN1_F_I2D_PUBLICKEY 164
1021#define ASN1_F_I2D_RSA_PUBKEY 165
1022#define ASN1_F_LONG_C2I 166
1023#define ASN1_F_OID_MODULE_INIT 174
1024#define ASN1_F_PKCS5_PBE2_SET 167
1025#define ASN1_F_X509_CINF_NEW 168
1026#define ASN1_F_X509_CRL_ADD0_REVOKED 169
1027#define ASN1_F_X509_INFO_NEW 170
1028#define ASN1_F_X509_NAME_NEW 171
1029#define ASN1_F_X509_NEW 172
1030#define ASN1_F_X509_PKEY_NEW 173
1031
1032/* Reason codes. */
1033#define ASN1_R_ADDING_OBJECT 171
1034#define ASN1_R_AUX_ERROR 100
1035#define ASN1_R_BAD_CLASS 101
1036#define ASN1_R_BAD_OBJECT_HEADER 102
1037#define ASN1_R_BAD_PASSWORD_READ 103
1038#define ASN1_R_BAD_TAG 104
1039#define ASN1_R_BN_LIB 105
1040#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106
1041#define ASN1_R_BUFFER_TOO_SMALL 107
1042#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108
1043#define ASN1_R_DATA_IS_WRONG 109
1044#define ASN1_R_DECODE_ERROR 110
1045#define ASN1_R_DECODING_ERROR 111
1046#define ASN1_R_ENCODE_ERROR 112
1047#define ASN1_R_ERROR_GETTING_TIME 173
1048#define ASN1_R_ERROR_LOADING_SECTION 172
1049#define ASN1_R_ERROR_PARSING_SET_ELEMENT 113
1050#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114
1051#define ASN1_R_EXPECTING_AN_INTEGER 115
1052#define ASN1_R_EXPECTING_AN_OBJECT 116
1053#define ASN1_R_EXPECTING_A_BOOLEAN 117
1054#define ASN1_R_EXPECTING_A_TIME 118
1055#define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119
1056#define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120
1057#define ASN1_R_FIELD_MISSING 121
1058#define ASN1_R_FIRST_NUM_TOO_LARGE 122
1059#define ASN1_R_HEADER_TOO_LONG 123
1060#define ASN1_R_ILLEGAL_CHARACTERS 124
1061#define ASN1_R_ILLEGAL_NULL 125
1062#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126
1063#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170
1064#define ASN1_R_ILLEGAL_TAGGED_ANY 127
1065#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
1066#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
1067#define ASN1_R_INVALID_DIGIT 130
1068#define ASN1_R_INVALID_SEPARATOR 131
1069#define ASN1_R_INVALID_TIME_FORMAT 132
1070#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133
1071#define ASN1_R_INVALID_UTF8STRING 134
1072#define ASN1_R_IV_TOO_LARGE 135
1073#define ASN1_R_LENGTH_ERROR 136
1074#define ASN1_R_MISSING_EOC 137
1075#define ASN1_R_MISSING_SECOND_NUMBER 138
1076#define ASN1_R_MSTRING_NOT_UNIVERSAL 139
1077#define ASN1_R_MSTRING_WRONG_TAG 140
1078#define ASN1_R_NON_HEX_CHARACTERS 141
1079#define ASN1_R_NOT_ENOUGH_DATA 142
1080#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
1081#define ASN1_R_NULL_IS_WRONG_LENGTH 144
1082#define ASN1_R_ODD_NUMBER_OF_CHARS 145
1083#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146
1084#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147
1085#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148
1086#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
1087#define ASN1_R_SHORT_LINE 150
1088#define ASN1_R_STRING_TOO_LONG 151
1089#define ASN1_R_STRING_TOO_SHORT 152
1090#define ASN1_R_TAG_VALUE_TOO_HIGH 153
1091#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
1092#define ASN1_R_TOO_LONG 155
1093#define ASN1_R_TYPE_NOT_CONSTRUCTED 156
1094#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
1095#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158
1096#define ASN1_R_UNEXPECTED_EOC 159
1097#define ASN1_R_UNKNOWN_FORMAT 160
1098#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161
1099#define ASN1_R_UNKNOWN_OBJECT_TYPE 162
1100#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163
1101#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164
1102#define ASN1_R_UNSUPPORTED_CIPHER 165
1103#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166
1104#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167
1105#define ASN1_R_WRONG_TAG 168
1106#define ASN1_R_WRONG_TYPE 169
1107
1108#ifdef __cplusplus
1109}
1110#endif
1111#endif
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
new file mode 100644
index 0000000000..3b57c8fbae
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_err.c
@@ -0,0 +1,248 @@
1/* crypto/asn1/asn1_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/asn1.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ASN1_str_functs[]=
68 {
69{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"},
70{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
71{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
72{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
73{ERR_PACK(0,ASN1_F_ASN1_BIT_STRING_SET_BIT,0), "ASN1_BIT_STRING_set_bit"},
74{ERR_PACK(0,ASN1_F_ASN1_CHECK_TLEN,0), "ASN1_CHECK_TLEN"},
75{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
76{ERR_PACK(0,ASN1_F_ASN1_COLLECT,0), "ASN1_COLLECT"},
77{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
78{ERR_PACK(0,ASN1_F_ASN1_D2I_EX_PRIMITIVE,0), "ASN1_D2I_EX_PRIMITIVE"},
79{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
80{ERR_PACK(0,ASN1_F_ASN1_DIGEST,0), "ASN1_digest"},
81{ERR_PACK(0,ASN1_F_ASN1_DO_ADB,0), "ASN1_DO_ADB"},
82{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
83{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
84{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
85{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_SET,0), "ASN1_GENERALIZEDTIME_set"},
86{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
87{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
88{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
89{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
90{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
91{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
92{ERR_PACK(0,ASN1_F_ASN1_ITEM_EX_D2I,0), "ASN1_ITEM_EX_D2I"},
93{ERR_PACK(0,ASN1_F_ASN1_ITEM_NEW,0), "ASN1_item_new"},
94{ERR_PACK(0,ASN1_F_ASN1_MBSTRING_COPY,0), "ASN1_mbstring_copy"},
95{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
96{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
97{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
98{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
99{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
100{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
101{ERR_PACK(0,ASN1_F_ASN1_STRING_SET,0), "ASN1_STRING_set"},
102{ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"},
103{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
104{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_D2I,0), "ASN1_TEMPLATE_D2I"},
105{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_EX_D2I,0), "ASN1_TEMPLATE_EX_D2I"},
106{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_NEW,0), "ASN1_TEMPLATE_NEW"},
107{ERR_PACK(0,ASN1_F_ASN1_TIME_SET,0), "ASN1_TIME_set"},
108{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
109{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
110{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
111{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_SET,0), "ASN1_UTCTIME_set"},
112{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
113{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
114{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
115{ERR_PACK(0,ASN1_F_COLLECT_DATA,0), "COLLECT_DATA"},
116{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "D2I_ASN1_BIT_STRING"},
117{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
118{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
119{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "D2I_ASN1_GENERALIZEDTIME"},
120{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
121{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "D2I_ASN1_INTEGER"},
122{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
123{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
124{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
125{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"},
126{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "D2I_ASN1_UTCTIME"},
127{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"},
128{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"},
129{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"},
130{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"},
131{ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"},
132{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"},
133{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"},
134{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
135{ERR_PACK(0,ASN1_F_I2D_ASN1_SET,0), "i2d_ASN1_SET"},
136{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "I2D_ASN1_TIME"},
137{ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"},
138{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
139{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
140{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
141{ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"},
142{ERR_PACK(0,ASN1_F_LONG_C2I,0), "LONG_C2I"},
143{ERR_PACK(0,ASN1_F_OID_MODULE_INIT,0), "OID_MODULE_INIT"},
144{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
145{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"},
146{ERR_PACK(0,ASN1_F_X509_CRL_ADD0_REVOKED,0), "X509_CRL_add0_revoked"},
147{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"},
148{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"},
149{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"},
150{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"},
151{0,NULL}
152 };
153
154static ERR_STRING_DATA ASN1_str_reasons[]=
155 {
156{ASN1_R_ADDING_OBJECT ,"adding object"},
157{ASN1_R_AUX_ERROR ,"aux error"},
158{ASN1_R_BAD_CLASS ,"bad class"},
159{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
160{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
161{ASN1_R_BAD_TAG ,"bad tag"},
162{ASN1_R_BN_LIB ,"bn lib"},
163{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
164{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
165{ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
166{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
167{ASN1_R_DECODE_ERROR ,"decode error"},
168{ASN1_R_DECODING_ERROR ,"decoding error"},
169{ASN1_R_ENCODE_ERROR ,"encode error"},
170{ASN1_R_ERROR_GETTING_TIME ,"error getting time"},
171{ASN1_R_ERROR_LOADING_SECTION ,"error loading section"},
172{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
173{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"},
174{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
175{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
176{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
177{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
178{ASN1_R_EXPLICIT_LENGTH_MISMATCH ,"explicit length mismatch"},
179{ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED ,"explicit tag not constructed"},
180{ASN1_R_FIELD_MISSING ,"field missing"},
181{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
182{ASN1_R_HEADER_TOO_LONG ,"header too long"},
183{ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"},
184{ASN1_R_ILLEGAL_NULL ,"illegal null"},
185{ASN1_R_ILLEGAL_OPTIONAL_ANY ,"illegal optional any"},
186{ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE ,"illegal options on item template"},
187{ASN1_R_ILLEGAL_TAGGED_ANY ,"illegal tagged any"},
188{ASN1_R_INTEGER_TOO_LARGE_FOR_LONG ,"integer too large for long"},
189{ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"},
190{ASN1_R_INVALID_DIGIT ,"invalid digit"},
191{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
192{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
193{ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"},
194{ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"},
195{ASN1_R_IV_TOO_LARGE ,"iv too large"},
196{ASN1_R_LENGTH_ERROR ,"length error"},
197{ASN1_R_MISSING_EOC ,"missing eoc"},
198{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
199{ASN1_R_MSTRING_NOT_UNIVERSAL ,"mstring not universal"},
200{ASN1_R_MSTRING_WRONG_TAG ,"mstring wrong tag"},
201{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
202{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
203{ASN1_R_NO_MATCHING_CHOICE_TYPE ,"no matching choice type"},
204{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
205{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
206{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
207{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
208{ASN1_R_SEQUENCE_LENGTH_MISMATCH ,"sequence length mismatch"},
209{ASN1_R_SEQUENCE_NOT_CONSTRUCTED ,"sequence not constructed"},
210{ASN1_R_SHORT_LINE ,"short line"},
211{ASN1_R_STRING_TOO_LONG ,"string too long"},
212{ASN1_R_STRING_TOO_SHORT ,"string too short"},
213{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
214{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
215{ASN1_R_TOO_LONG ,"too long"},
216{ASN1_R_TYPE_NOT_CONSTRUCTED ,"type not constructed"},
217{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
218{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
219{ASN1_R_UNEXPECTED_EOC ,"unexpected eoc"},
220{ASN1_R_UNKNOWN_FORMAT ,"unknown format"},
221{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
222{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
223{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
224{ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE ,"unsupported any defined by type"},
225{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
226{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
227{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
228{ASN1_R_WRONG_TAG ,"wrong tag"},
229{ASN1_R_WRONG_TYPE ,"wrong type"},
230{0,NULL}
231 };
232
233#endif
234
235void ERR_load_ASN1_strings(void)
236 {
237 static int init=1;
238
239 if (init)
240 {
241 init=0;
242#ifndef OPENSSL_NO_ERR
243 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs);
244 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons);
245#endif
246
247 }
248 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
new file mode 100644
index 0000000000..97b9b35f4b
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -0,0 +1,433 @@
1/* crypto/asn1/asn1_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <limits.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64
65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length);
67const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
68
69int ASN1_check_infinite_end(unsigned char **p, long len)
70 {
71 /* If there is 0 or 1 byte left, the length check should pick
72 * things up */
73 if (len <= 0)
74 return(1);
75 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
76 {
77 (*p)+=2;
78 return(1);
79 }
80 return(0);
81 }
82
83
84int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
85 long omax)
86 {
87 int i,ret;
88 long l;
89 unsigned char *p= *pp;
90 int tag,xclass,inf;
91 long max=omax;
92
93 if (!max) goto err;
94 ret=(*p&V_ASN1_CONSTRUCTED);
95 xclass=(*p&V_ASN1_PRIVATE);
96 i= *p&V_ASN1_PRIMITIVE_TAG;
97 if (i == V_ASN1_PRIMITIVE_TAG)
98 { /* high-tag */
99 p++;
100 if (--max == 0) goto err;
101 l=0;
102 while (*p&0x80)
103 {
104 l<<=7L;
105 l|= *(p++)&0x7f;
106 if (--max == 0) goto err;
107 if (l > (INT_MAX >> 7L)) goto err;
108 }
109 l<<=7L;
110 l|= *(p++)&0x7f;
111 tag=(int)l;
112 if (--max == 0) goto err;
113 }
114 else
115 {
116 tag=i;
117 p++;
118 if (--max == 0) goto err;
119 }
120 *ptag=tag;
121 *pclass=xclass;
122 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
123
124#if 0
125 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
126 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
127 (int)(omax+ *pp));
128
129#endif
130 if (*plength > (omax - (p - *pp)))
131 {
132 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
133 /* Set this so that even if things are not long enough
134 * the values are set correctly */
135 ret|=0x80;
136 }
137 *pp=p;
138 return(ret|inf);
139err:
140 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
141 return(0x80);
142 }
143
144static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
145 {
146 unsigned char *p= *pp;
147 unsigned long ret=0;
148 int i;
149
150 if (max-- < 1) return(0);
151 if (*p == 0x80)
152 {
153 *inf=1;
154 ret=0;
155 p++;
156 }
157 else
158 {
159 *inf=0;
160 i= *p&0x7f;
161 if (*(p++) & 0x80)
162 {
163 if (i > sizeof(long))
164 return 0;
165 if (max-- == 0) return(0);
166 while (i-- > 0)
167 {
168 ret<<=8L;
169 ret|= *(p++);
170 if (max-- == 0) return(0);
171 }
172 }
173 else
174 ret=i;
175 }
176 if (ret > LONG_MAX)
177 return 0;
178 *pp=p;
179 *rl=(long)ret;
180 return(1);
181 }
182
183/* class 0 is constructed
184 * constructed == 2 for indefinite length constructed */
185void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
186 int xclass)
187 {
188 unsigned char *p= *pp;
189 int i, ttag;
190
191 i=(constructed)?V_ASN1_CONSTRUCTED:0;
192 i|=(xclass&V_ASN1_PRIVATE);
193 if (tag < 31)
194 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
195 else
196 {
197 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
198 for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
199 ttag = i;
200 while(i-- > 0)
201 {
202 p[i] = tag & 0x7f;
203 if(i != (ttag - 1)) p[i] |= 0x80;
204 tag >>= 7;
205 }
206 p += ttag;
207 }
208 if ((constructed == 2) && (length == 0))
209 *(p++)=0x80; /* der_put_length would output 0 instead */
210 else
211 asn1_put_length(&p,length);
212 *pp=p;
213 }
214
215static void asn1_put_length(unsigned char **pp, int length)
216 {
217 unsigned char *p= *pp;
218 int i,l;
219 if (length <= 127)
220 *(p++)=(unsigned char)length;
221 else
222 {
223 l=length;
224 for (i=0; l > 0; i++)
225 l>>=8;
226 *(p++)=i|0x80;
227 l=i;
228 while (i-- > 0)
229 {
230 p[i]=length&0xff;
231 length>>=8;
232 }
233 p+=l;
234 }
235 *pp=p;
236 }
237
238int ASN1_object_size(int constructed, int length, int tag)
239 {
240 int ret;
241
242 ret=length;
243 ret++;
244 if (tag >= 31)
245 {
246 while (tag > 0)
247 {
248 tag>>=7;
249 ret++;
250 }
251 }
252 if ((length == 0) && (constructed == 2))
253 ret+=2;
254 ret++;
255 if (length > 127)
256 {
257 while (length > 0)
258 {
259 length>>=8;
260 ret++;
261 }
262 }
263 return(ret);
264 }
265
266int asn1_Finish(ASN1_CTX *c)
267 {
268 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
269 {
270 if (!ASN1_check_infinite_end(&c->p,c->slen))
271 {
272 c->error=ERR_R_MISSING_ASN1_EOS;
273 return(0);
274 }
275 }
276 if ( ((c->slen != 0) && !(c->inf & 1)) ||
277 ((c->slen < 0) && (c->inf & 1)))
278 {
279 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
280 return(0);
281 }
282 return(1);
283 }
284
285int asn1_GetSequence(ASN1_CTX *c, long *length)
286 {
287 unsigned char *q;
288
289 q=c->p;
290 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
291 *length);
292 if (c->inf & 0x80)
293 {
294 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
295 return(0);
296 }
297 if (c->tag != V_ASN1_SEQUENCE)
298 {
299 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
300 return(0);
301 }
302 (*length)-=(c->p-q);
303 if (c->max && (*length < 0))
304 {
305 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
306 return(0);
307 }
308 if (c->inf == (1|V_ASN1_CONSTRUCTED))
309 c->slen= *length+ *(c->pp)-c->p;
310 c->eos=0;
311 return(1);
312 }
313
314ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
315 {
316 ASN1_STRING *ret;
317
318 if (str == NULL) return(NULL);
319 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
320 return(NULL);
321 if (!ASN1_STRING_set(ret,str->data,str->length))
322 {
323 ASN1_STRING_free(ret);
324 return(NULL);
325 }
326 ret->flags = str->flags;
327 return(ret);
328 }
329
330int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
331 {
332 unsigned char *c;
333 const char *data=_data;
334
335 if (len < 0)
336 {
337 if (data == NULL)
338 return(0);
339 else
340 len=strlen(data);
341 }
342 if ((str->length < len) || (str->data == NULL))
343 {
344 c=str->data;
345 if (c == NULL)
346 str->data=OPENSSL_malloc(len+1);
347 else
348 str->data=OPENSSL_realloc(c,len+1);
349
350 if (str->data == NULL)
351 {
352 ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
353 str->data=c;
354 return(0);
355 }
356 }
357 str->length=len;
358 if (data != NULL)
359 {
360 memcpy(str->data,data,len);
361 /* an allowance for strings :-) */
362 str->data[len]='\0';
363 }
364 return(1);
365 }
366
367ASN1_STRING *ASN1_STRING_new(void)
368 {
369 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
370 }
371
372
373ASN1_STRING *ASN1_STRING_type_new(int type)
374 {
375 ASN1_STRING *ret;
376
377 ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
378 if (ret == NULL)
379 {
380 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
381 return(NULL);
382 }
383 ret->length=0;
384 ret->type=type;
385 ret->data=NULL;
386 ret->flags=0;
387 return(ret);
388 }
389
390void ASN1_STRING_free(ASN1_STRING *a)
391 {
392 if (a == NULL) return;
393 if (a->data != NULL) OPENSSL_free(a->data);
394 OPENSSL_free(a);
395 }
396
397int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
398 {
399 int i;
400
401 i=(a->length-b->length);
402 if (i == 0)
403 {
404 i=memcmp(a->data,b->data,a->length);
405 if (i == 0)
406 return(a->type-b->type);
407 else
408 return(i);
409 }
410 else
411 return(i);
412 }
413
414void asn1_add_error(unsigned char *address, int offset)
415 {
416 char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1];
417
418 BIO_snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address);
419 BIO_snprintf(buf2,sizeof buf2,"%d",offset);
420 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
421 }
422
423int ASN1_STRING_length(ASN1_STRING *x)
424{ return M_ASN1_STRING_length(x); }
425
426void ASN1_STRING_length_set(ASN1_STRING *x, int len)
427{ M_ASN1_STRING_length_set(x, len); return; }
428
429int ASN1_STRING_type(ASN1_STRING *x)
430{ return M_ASN1_STRING_type(x); }
431
432unsigned char * ASN1_STRING_data(ASN1_STRING *x)
433{ return M_ASN1_STRING_data(x); }
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
new file mode 100644
index 0000000000..a48649ceeb
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_mac.h
@@ -0,0 +1,560 @@
1/* crypto/asn1/asn1_mac.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ASN1_MAC_H
60#define HEADER_ASN1_MAC_H
61
62#include <openssl/asn1.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifndef ASN1_MAC_ERR_LIB
69#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
70#endif
71
72#define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
74
75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_CTX c; \
77 type ret=NULL; \
78 \
79 c.pp=(unsigned char **)pp; \
80 c.q= *(unsigned char **)pp; \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \
82 if ((a == NULL) || ((*a) == NULL)) \
83 { if ((ret=(type)func()) == NULL) \
84 { c.line=__LINE__; goto err; } } \
85 else ret=(*a);
86
87#define M_ASN1_D2I_Init() \
88 c.p= *(unsigned char **)pp; \
89 c.max=(length == 0)?0:(c.p+length);
90
91#define M_ASN1_D2I_Finish_2(a) \
92 if (!asn1_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \
94 *(unsigned char **)pp=c.p; \
95 if (a != NULL) (*a)=ret; \
96 return(ret);
97
98#define M_ASN1_D2I_Finish(a,func,e) \
99 M_ASN1_D2I_Finish_2(a); \
100err:\
101 ASN1_MAC_H_err((e),c.error,c.line); \
102 asn1_add_error(*(unsigned char **)pp,(int)(c.q- *pp)); \
103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
104 return(NULL)
105
106#define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
109/* Begin reading ASN1 without a surrounding sequence */
110#define M_ASN1_D2I_begin() \
111 c.slen = length;
112
113/* End reading ASN1 with no check on length */
114#define M_ASN1_D2I_Finish_nolen(a, func, e) \
115 *pp=c.p; \
116 if (a != NULL) (*a)=ret; \
117 return(ret); \
118err:\
119 ASN1_MAC_H_err((e),c.error,c.line); \
120 asn1_add_error(*pp,(int)(c.q- *pp)); \
121 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
122 return(NULL)
123
124#define M_ASN1_D2I_end_sequence() \
125 (((c.inf&1) == 0)?(c.slen <= 0): \
126 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
127
128/* Don't use this with d2i_ASN1_BOOLEAN() */
129#define M_ASN1_D2I_get(b,func) \
130 c.q=c.p; \
131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \
133 c.slen-=(c.p-c.q);
134
135/* use this instead () */
136#define M_ASN1_D2I_get_int(b,func) \
137 c.q=c.p; \
138 if (func(&(b),&c.p,c.slen) < 0) \
139 {c.line=__LINE__; goto err; } \
140 c.slen-=(c.p-c.q);
141
142#define M_ASN1_D2I_get_opt(b,func,type) \
143 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
144 == (V_ASN1_UNIVERSAL|(type)))) \
145 { \
146 M_ASN1_D2I_get(b,func); \
147 }
148
149#define M_ASN1_D2I_get_imp(b,func, type) \
150 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
151 c.q=c.p; \
152 if (func(&(b),&c.p,c.slen) == NULL) \
153 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
154 c.slen-=(c.p-c.q);\
155 M_ASN1_next_prev=_tmp;
156
157#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
158 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
159 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
160 { \
161 unsigned char _tmp = M_ASN1_next; \
162 M_ASN1_D2I_get_imp(b,func, type);\
163 }
164
165#define M_ASN1_D2I_get_set(r,func,free_func) \
166 M_ASN1_D2I_get_imp_set(r,func,free_func, \
167 V_ASN1_SET,V_ASN1_UNIVERSAL);
168
169#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
170 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
171 V_ASN1_SET,V_ASN1_UNIVERSAL);
172
173#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
174 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
175 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
176 { M_ASN1_D2I_get_set(r,func,free_func); }
177
178#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
179 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
180 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
181 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
182
183#define M_ASN1_I2D_len_SET_opt(a,f) \
184 if ((a != NULL) && (sk_num(a) != 0)) \
185 M_ASN1_I2D_len_SET(a,f);
186
187#define M_ASN1_I2D_put_SET_opt(a,f) \
188 if ((a != NULL) && (sk_num(a) != 0)) \
189 M_ASN1_I2D_put_SET(a,f);
190
191#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
192 if ((a != NULL) && (sk_num(a) != 0)) \
193 M_ASN1_I2D_put_SEQUENCE(a,f);
194
195#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
196 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
197 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
198
199#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
200 if ((c.slen != 0) && \
201 (M_ASN1_next == \
202 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
203 { \
204 M_ASN1_D2I_get_imp_set(b,func,free_func,\
205 tag,V_ASN1_CONTEXT_SPECIFIC); \
206 }
207
208#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
209 if ((c.slen != 0) && \
210 (M_ASN1_next == \
211 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
212 { \
213 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
214 tag,V_ASN1_CONTEXT_SPECIFIC); \
215 }
216
217#define M_ASN1_D2I_get_seq(r,func,free_func) \
218 M_ASN1_D2I_get_imp_set(r,func,free_func,\
219 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
220
221#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
222 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
223 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
224
225#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
226 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
227 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
228 { M_ASN1_D2I_get_seq(r,func,free_func); }
229
230#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
231 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
232 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
233 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
234
235#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
236 M_ASN1_D2I_get_imp_set(r,func,free_func,\
237 x,V_ASN1_CONTEXT_SPECIFIC);
238
239#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
240 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
241 x,V_ASN1_CONTEXT_SPECIFIC);
242
243#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
244 c.q=c.p; \
245 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
246 (void (*)())free_func,a,b) == NULL) \
247 { c.line=__LINE__; goto err; } \
248 c.slen-=(c.p-c.q);
249
250#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
251 c.q=c.p; \
252 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
253 free_func,a,b) == NULL) \
254 { c.line=__LINE__; goto err; } \
255 c.slen-=(c.p-c.q);
256
257#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
258 c.q=c.p; \
259 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
260 { c.line=__LINE__; goto err; } \
261 c.slen-=(c.p-c.q);
262
263#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
264 if ((c.slen != 0L) && (M_ASN1_next == \
265 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
266 { \
267 int Tinf,Ttag,Tclass; \
268 long Tlen; \
269 \
270 c.q=c.p; \
271 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
272 if (Tinf & 0x80) \
273 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
274 c.line=__LINE__; goto err; } \
275 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
276 Tlen = c.slen - (c.p - c.q) - 2; \
277 if (func(&(r),&c.p,Tlen) == NULL) \
278 { c.line=__LINE__; goto err; } \
279 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
280 Tlen = c.slen - (c.p - c.q); \
281 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
282 { c.error=ERR_R_MISSING_ASN1_EOS; \
283 c.line=__LINE__; goto err; } \
284 }\
285 c.slen-=(c.p-c.q); \
286 }
287
288#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
289 if ((c.slen != 0) && (M_ASN1_next == \
290 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
291 { \
292 int Tinf,Ttag,Tclass; \
293 long Tlen; \
294 \
295 c.q=c.p; \
296 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
297 if (Tinf & 0x80) \
298 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
299 c.line=__LINE__; goto err; } \
300 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
301 Tlen = c.slen - (c.p - c.q) - 2; \
302 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
303 (void (*)())free_func, \
304 b,V_ASN1_UNIVERSAL) == NULL) \
305 { c.line=__LINE__; goto err; } \
306 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
307 Tlen = c.slen - (c.p - c.q); \
308 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
309 { c.error=ERR_R_MISSING_ASN1_EOS; \
310 c.line=__LINE__; goto err; } \
311 }\
312 c.slen-=(c.p-c.q); \
313 }
314
315#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
316 if ((c.slen != 0) && (M_ASN1_next == \
317 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
318 { \
319 int Tinf,Ttag,Tclass; \
320 long Tlen; \
321 \
322 c.q=c.p; \
323 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
324 if (Tinf & 0x80) \
325 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
326 c.line=__LINE__; goto err; } \
327 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
328 Tlen = c.slen - (c.p - c.q) - 2; \
329 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
330 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
331 { c.line=__LINE__; goto err; } \
332 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
333 Tlen = c.slen - (c.p - c.q); \
334 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
335 { c.error=ERR_R_MISSING_ASN1_EOS; \
336 c.line=__LINE__; goto err; } \
337 }\
338 c.slen-=(c.p-c.q); \
339 }
340
341/* New macros */
342#define M_ASN1_New_Malloc(ret,type) \
343 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
344 { c.line=__LINE__; goto err2; }
345
346#define M_ASN1_New(arg,func) \
347 if (((arg)=func()) == NULL) return(NULL)
348
349#define M_ASN1_New_Error(a) \
350/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
351 return(NULL);*/ \
352 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
353 return(NULL)
354
355
356#define M_ASN1_next (*c.p)
357#define M_ASN1_next_prev (*c.q)
358
359/*************************************************/
360
361#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
362 unsigned char *p; \
363 if (a == NULL) return(0)
364
365/* Length Macros */
366#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
367#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
368
369#define M_ASN1_I2D_len_SET(a,f) \
370 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
371
372#define M_ASN1_I2D_len_SET_type(type,a,f) \
373 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
374 V_ASN1_UNIVERSAL,IS_SET);
375
376#define M_ASN1_I2D_len_SEQUENCE(a,f) \
377 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
378 IS_SEQUENCE);
379
380#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
381 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
382 V_ASN1_UNIVERSAL,IS_SEQUENCE)
383
384#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
385 if ((a != NULL) && (sk_num(a) != 0)) \
386 M_ASN1_I2D_len_SEQUENCE(a,f);
387
388#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
389 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
390 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
391
392#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
393 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
394
395#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
396 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
397 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
398
399#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
400 if ((a != NULL) && (sk_num(a) != 0)) \
401 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
402 IS_SET);
403
404#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
405 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
406 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
407 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
408
409#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
410 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
411 IS_SEQUENCE);
412
413#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
414 if ((a != NULL) && (sk_num(a) != 0)) \
415 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
416 IS_SEQUENCE);
417
418#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
419 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
420 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
421 V_ASN1_CONTEXT_SPECIFIC, \
422 IS_SEQUENCE);
423
424#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
425 if (a != NULL)\
426 { \
427 v=f(a,NULL); \
428 ret+=ASN1_object_size(1,v,mtag); \
429 }
430
431#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
432 if ((a != NULL) && (sk_num(a) != 0))\
433 { \
434 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
435 ret+=ASN1_object_size(1,v,mtag); \
436 }
437
438#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
439 if ((a != NULL) && (sk_num(a) != 0))\
440 { \
441 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
442 IS_SEQUENCE); \
443 ret+=ASN1_object_size(1,v,mtag); \
444 }
445
446#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
447 if ((a != NULL) && (sk_##type##_num(a) != 0))\
448 { \
449 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
450 V_ASN1_UNIVERSAL, \
451 IS_SEQUENCE); \
452 ret+=ASN1_object_size(1,v,mtag); \
453 }
454
455/* Put Macros */
456#define M_ASN1_I2D_put(a,f) f(a,&p)
457
458#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
459 if (a != NULL) \
460 { \
461 unsigned char *q=p; \
462 f(a,&p); \
463 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
464 }
465
466#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
467 V_ASN1_UNIVERSAL,IS_SET)
468#define M_ASN1_I2D_put_SET_type(type,a,f) \
469 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
470#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
471 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
472#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
473 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
474#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
475 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
476
477#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
478 V_ASN1_UNIVERSAL,IS_SEQUENCE)
479
480#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
481 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
482 IS_SEQUENCE)
483
484#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
485 if ((a != NULL) && (sk_num(a) != 0)) \
486 M_ASN1_I2D_put_SEQUENCE(a,f);
487
488#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
489 if ((a != NULL) && (sk_num(a) != 0)) \
490 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
491 IS_SET); }
492
493#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
494 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
495 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
496 V_ASN1_CONTEXT_SPECIFIC, \
497 IS_SET); }
498
499#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
500 if ((a != NULL) && (sk_num(a) != 0)) \
501 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
502 IS_SEQUENCE); }
503
504#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
505 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
506 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
507 V_ASN1_CONTEXT_SPECIFIC, \
508 IS_SEQUENCE); }
509
510#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
511 if (a != NULL) \
512 { \
513 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
514 f(a,&p); \
515 }
516
517#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
518 if ((a != NULL) && (sk_num(a) != 0)) \
519 { \
520 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
521 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
522 }
523
524#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
525 if ((a != NULL) && (sk_num(a) != 0)) \
526 { \
527 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
528 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
529 }
530
531#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
532 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
533 { \
534 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
535 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
536 IS_SEQUENCE); \
537 }
538
539#define M_ASN1_I2D_seq_total() \
540 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
541 if (pp == NULL) return(r); \
542 p= *pp; \
543 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
544
545#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
546 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
547 *(p++)=0x80
548
549#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
550
551#define M_ASN1_I2D_finish() *pp=p; \
552 return(r);
553
554int asn1_GetSequence(ASN1_CTX *c, long *length);
555void asn1_add_error(unsigned char *address,int offset);
556#ifdef __cplusplus
557}
558#endif
559
560#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
new file mode 100644
index 0000000000..676d434f03
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1_par.c
@@ -0,0 +1,418 @@
1/* crypto/asn1/asn1_par.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/asn1.h>
64
65static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed,
66 int indent);
67static int asn1_parse2(BIO *bp, unsigned char **pp, long length,
68 int offset, int depth, int indent, int dump);
69static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
70 int indent)
71 {
72 static const char fmt[]="%-18s";
73 static const char fmt2[]="%2d %-15s";
74 char str[128];
75 const char *p,*p2=NULL;
76
77 if (constructed & V_ASN1_CONSTRUCTED)
78 p="cons: ";
79 else
80 p="prim: ";
81 if (BIO_write(bp,p,6) < 6) goto err;
82 BIO_indent(bp,indent,128);
83
84 p=str;
85 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
86 BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag);
87 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
88 BIO_snprintf(str,sizeof str,"cont [ %d ]",tag);
89 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
90 BIO_snprintf(str,sizeof str,"appl [ %d ]",tag);
91 else p = ASN1_tag2str(tag);
92
93 if (p2 != NULL)
94 {
95 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
96 }
97 else
98 {
99 if (BIO_printf(bp,fmt,p) <= 0) goto err;
100 }
101 return(1);
102err:
103 return(0);
104 }
105
106int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
107 {
108 return(asn1_parse2(bp,&pp,len,0,0,indent,0));
109 }
110
111int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump)
112 {
113 return(asn1_parse2(bp,&pp,len,0,0,indent,dump));
114 }
115
116static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
117 int depth, int indent, int dump)
118 {
119 unsigned char *p,*ep,*tot,*op,*opp;
120 long len;
121 int tag,xclass,ret=0;
122 int nl,hl,j,r;
123 ASN1_OBJECT *o=NULL;
124 ASN1_OCTET_STRING *os=NULL;
125 /* ASN1_BMPSTRING *bmp=NULL;*/
126 int dump_indent;
127
128#if 0
129 dump_indent = indent;
130#else
131 dump_indent = 6; /* Because we know BIO_dump_indent() */
132#endif
133 p= *pp;
134 tot=p+length;
135 op=p-1;
136 while ((p < tot) && (op < p))
137 {
138 op=p;
139 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
140#ifdef LINT
141 j=j;
142#endif
143 if (j & 0x80)
144 {
145 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
146 goto end;
147 ret=0;
148 goto end;
149 }
150 hl=(p-op);
151 length-=hl;
152 /* if j == 0x21 it is a constructed indefinite length object */
153 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
154 <= 0) goto end;
155
156 if (j != (V_ASN1_CONSTRUCTED | 1))
157 {
158 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
159 depth,(long)hl,len) <= 0)
160 goto end;
161 }
162 else
163 {
164 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
165 depth,(long)hl) <= 0)
166 goto end;
167 }
168 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
169 goto end;
170 if (j & V_ASN1_CONSTRUCTED)
171 {
172 ep=p+len;
173 if (BIO_write(bp,"\n",1) <= 0) goto end;
174 if (len > length)
175 {
176 BIO_printf(bp,
177 "length is greater than %ld\n",length);
178 ret=0;
179 goto end;
180 }
181 if ((j == 0x21) && (len == 0))
182 {
183 for (;;)
184 {
185 r=asn1_parse2(bp,&p,(long)(tot-p),
186 offset+(p - *pp),depth+1,
187 indent,dump);
188 if (r == 0) { ret=0; goto end; }
189 if ((r == 2) || (p >= tot)) break;
190 }
191 }
192 else
193 while (p < ep)
194 {
195 r=asn1_parse2(bp,&p,(long)len,
196 offset+(p - *pp),depth+1,
197 indent,dump);
198 if (r == 0) { ret=0; goto end; }
199 }
200 }
201 else if (xclass != 0)
202 {
203 p+=len;
204 if (BIO_write(bp,"\n",1) <= 0) goto end;
205 }
206 else
207 {
208 nl=0;
209 if ( (tag == V_ASN1_PRINTABLESTRING) ||
210 (tag == V_ASN1_T61STRING) ||
211 (tag == V_ASN1_IA5STRING) ||
212 (tag == V_ASN1_VISIBLESTRING) ||
213 (tag == V_ASN1_UTCTIME) ||
214 (tag == V_ASN1_GENERALIZEDTIME))
215 {
216 if (BIO_write(bp,":",1) <= 0) goto end;
217 if ((len > 0) &&
218 BIO_write(bp,(char *)p,(int)len)
219 != (int)len)
220 goto end;
221 }
222 else if (tag == V_ASN1_OBJECT)
223 {
224 opp=op;
225 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
226 {
227 if (BIO_write(bp,":",1) <= 0) goto end;
228 i2a_ASN1_OBJECT(bp,o);
229 }
230 else
231 {
232 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
233 goto end;
234 }
235 }
236 else if (tag == V_ASN1_BOOLEAN)
237 {
238 int ii;
239
240 opp=op;
241 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
242 if (ii < 0)
243 {
244 if (BIO_write(bp,"Bad boolean\n",12))
245 goto end;
246 }
247 BIO_printf(bp,":%d",ii);
248 }
249 else if (tag == V_ASN1_BMPSTRING)
250 {
251 /* do the BMP thang */
252 }
253 else if (tag == V_ASN1_OCTET_STRING)
254 {
255 int i,printable=1;
256
257 opp=op;
258 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
259 if (os != NULL)
260 {
261 opp=os->data;
262 for (i=0; i<os->length; i++)
263 {
264 if (( (opp[i] < ' ') &&
265 (opp[i] != '\n') &&
266 (opp[i] != '\r') &&
267 (opp[i] != '\t')) ||
268 (opp[i] > '~'))
269 {
270 printable=0;
271 break;
272 }
273 }
274 if (printable && (os->length > 0))
275 {
276 if (BIO_write(bp,":",1) <= 0)
277 goto end;
278 if (BIO_write(bp,(char *)opp,
279 os->length) <= 0)
280 goto end;
281 }
282 if (!printable && (os->length > 0)
283 && dump)
284 {
285 if (!nl)
286 {
287 if (BIO_write(bp,"\n",1) <= 0)
288 goto end;
289 }
290 if (BIO_dump_indent(bp,(char *)opp,
291 ((dump == -1 || dump > os->length)?os->length:dump),
292 dump_indent) <= 0)
293 goto end;
294 nl=1;
295 }
296 M_ASN1_OCTET_STRING_free(os);
297 os=NULL;
298 }
299 }
300 else if (tag == V_ASN1_INTEGER)
301 {
302 ASN1_INTEGER *bs;
303 int i;
304
305 opp=op;
306 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
307 if (bs != NULL)
308 {
309 if (BIO_write(bp,":",1) <= 0) goto end;
310 if (bs->type == V_ASN1_NEG_INTEGER)
311 if (BIO_write(bp,"-",1) <= 0)
312 goto end;
313 for (i=0; i<bs->length; i++)
314 {
315 if (BIO_printf(bp,"%02X",
316 bs->data[i]) <= 0)
317 goto end;
318 }
319 if (bs->length == 0)
320 {
321 if (BIO_write(bp,"00",2) <= 0)
322 goto end;
323 }
324 }
325 else
326 {
327 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
328 goto end;
329 }
330 M_ASN1_INTEGER_free(bs);
331 }
332 else if (tag == V_ASN1_ENUMERATED)
333 {
334 ASN1_ENUMERATED *bs;
335 int i;
336
337 opp=op;
338 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
339 if (bs != NULL)
340 {
341 if (BIO_write(bp,":",1) <= 0) goto end;
342 if (bs->type == V_ASN1_NEG_ENUMERATED)
343 if (BIO_write(bp,"-",1) <= 0)
344 goto end;
345 for (i=0; i<bs->length; i++)
346 {
347 if (BIO_printf(bp,"%02X",
348 bs->data[i]) <= 0)
349 goto end;
350 }
351 if (bs->length == 0)
352 {
353 if (BIO_write(bp,"00",2) <= 0)
354 goto end;
355 }
356 }
357 else
358 {
359 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
360 goto end;
361 }
362 M_ASN1_ENUMERATED_free(bs);
363 }
364 else if (len > 0 && dump)
365 {
366 if (!nl)
367 {
368 if (BIO_write(bp,"\n",1) <= 0)
369 goto end;
370 }
371 if (BIO_dump_indent(bp,(char *)p,
372 ((dump == -1 || dump > len)?len:dump),
373 dump_indent) <= 0)
374 goto end;
375 nl=1;
376 }
377
378 if (!nl)
379 {
380 if (BIO_write(bp,"\n",1) <= 0) goto end;
381 }
382 p+=len;
383 if ((tag == V_ASN1_EOC) && (xclass == 0))
384 {
385 ret=2; /* End of sequence */
386 goto end;
387 }
388 }
389 length-=len;
390 }
391 ret=1;
392end:
393 if (o != NULL) ASN1_OBJECT_free(o);
394 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
395 *pp=p;
396 return(ret);
397 }
398
399const char *ASN1_tag2str(int tag)
400{
401 const static char *tag2str[] = {
402 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
403 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
404 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
405 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */
406 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */
407 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */
408 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */
409 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */
410 };
411
412 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
413 tag &= ~0x100;
414
415 if(tag < 0 || tag > 30) return "(unknown)";
416 return tag2str[tag];
417}
418
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h
new file mode 100644
index 0000000000..ed372f8554
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn1t.h
@@ -0,0 +1,846 @@
1/* asn1t.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#ifndef HEADER_ASN1T_H
59#define HEADER_ASN1T_H
60
61#include <stddef.h>
62#include <openssl/e_os2.h>
63#include <openssl/asn1.h>
64
65#ifdef OPENSSL_BUILD_SHLIBCRYPTO
66# undef OPENSSL_EXTERN
67# define OPENSSL_EXTERN OPENSSL_EXPORT
68#endif
69
70/* ASN1 template defines, structures and functions */
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76
77#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
78
79/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
80#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
81
82
83/* Macros for start and end of ASN1_ITEM definition */
84
85#define ASN1_ITEM_start(itname) \
86 OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
87
88#define ASN1_ITEM_end(itname) \
89 };
90
91#else
92
93/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
94#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
95
96
97/* Macros for start and end of ASN1_ITEM definition */
98
99#define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \
101 { \
102 static const ASN1_ITEM local_it = { \
103
104#define ASN1_ITEM_end(itname) \
105 }; \
106 return &local_it; \
107 }
108
109#endif
110
111
112/* Macros to aid ASN1 template writing */
113
114#define ASN1_ITEM_TEMPLATE(tname) \
115 const static ASN1_TEMPLATE tname##_item_tt
116
117#define ASN1_ITEM_TEMPLATE_END(tname) \
118 ;\
119 ASN1_ITEM_start(tname) \
120 ASN1_ITYPE_PRIMITIVE,\
121 -1,\
122 &tname##_item_tt,\
123 0,\
124 NULL,\
125 0,\
126 #tname \
127 ASN1_ITEM_end(tname)
128
129
130/* This is a ASN1 type which just embeds a template */
131
132/* This pair helps declare a SEQUENCE. We can do:
133 *
134 * ASN1_SEQUENCE(stname) = {
135 * ... SEQUENCE components ...
136 * } ASN1_SEQUENCE_END(stname)
137 *
138 * This will produce an ASN1_ITEM called stname_it
139 * for a structure called stname.
140 *
141 * If you want the same structure but a different
142 * name then use:
143 *
144 * ASN1_SEQUENCE(itname) = {
145 * ... SEQUENCE components ...
146 * } ASN1_SEQUENCE_END_name(stname, itname)
147 *
148 * This will create an item called itname_it using
149 * a structure called stname.
150 */
151
152#define ASN1_SEQUENCE(tname) \
153 const static ASN1_TEMPLATE tname##_seq_tt[]
154
155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
156
157#define ASN1_SEQUENCE_END_name(stname, tname) \
158 ;\
159 ASN1_ITEM_start(tname) \
160 ASN1_ITYPE_SEQUENCE,\
161 V_ASN1_SEQUENCE,\
162 tname##_seq_tt,\
163 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
164 NULL,\
165 sizeof(stname),\
166 #stname \
167 ASN1_ITEM_end(tname)
168
169#define ASN1_SEQUENCE_cb(tname, cb) \
170 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
171 ASN1_SEQUENCE(tname)
172
173#define ASN1_BROKEN_SEQUENCE(tname) \
174 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
175 ASN1_SEQUENCE(tname)
176
177#define ASN1_SEQUENCE_ref(tname, cb, lck) \
178 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
179 ASN1_SEQUENCE(tname)
180
181#define ASN1_SEQUENCE_enc(tname, enc, cb) \
182 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
183 ASN1_SEQUENCE(tname)
184
185#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
186
187#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
188
189#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
190
191#define ASN1_SEQUENCE_END_ref(stname, tname) \
192 ;\
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_SEQUENCE,\
195 V_ASN1_SEQUENCE,\
196 tname##_seq_tt,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
198 &tname##_aux,\
199 sizeof(stname),\
200 #stname \
201 ASN1_ITEM_end(tname)
202
203
204/* This pair helps declare a CHOICE type. We can do:
205 *
206 * ASN1_CHOICE(chname) = {
207 * ... CHOICE options ...
208 * ASN1_CHOICE_END(chname)
209 *
210 * This will produce an ASN1_ITEM called chname_it
211 * for a structure called chname. The structure
212 * definition must look like this:
213 * typedef struct {
214 * int type;
215 * union {
216 * ASN1_SOMETHING *opt1;
217 * ASN1_SOMEOTHER *opt2;
218 * } value;
219 * } chname;
220 *
221 * the name of the selector must be 'type'.
222 * to use an alternative selector name use the
223 * ASN1_CHOICE_END_selector() version.
224 */
225
226#define ASN1_CHOICE(tname) \
227 const static ASN1_TEMPLATE tname##_ch_tt[]
228
229#define ASN1_CHOICE_cb(tname, cb) \
230 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
231 ASN1_CHOICE(tname)
232
233#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
234
235#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
236
237#define ASN1_CHOICE_END_selector(stname, tname, selname) \
238 ;\
239 ASN1_ITEM_start(tname) \
240 ASN1_ITYPE_CHOICE,\
241 offsetof(stname,selname) ,\
242 tname##_ch_tt,\
243 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
244 NULL,\
245 sizeof(stname),\
246 #stname \
247 ASN1_ITEM_end(tname)
248
249#define ASN1_CHOICE_END_cb(stname, tname, selname) \
250 ;\
251 ASN1_ITEM_start(tname) \
252 ASN1_ITYPE_CHOICE,\
253 offsetof(stname,selname) ,\
254 tname##_ch_tt,\
255 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
256 &tname##_aux,\
257 sizeof(stname),\
258 #stname \
259 ASN1_ITEM_end(tname)
260
261/* This helps with the template wrapper form of ASN1_ITEM */
262
263#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
264 (flags), (tag), 0,\
265 #name, ASN1_ITEM_ref(type) }
266
267/* These help with SEQUENCE or CHOICE components */
268
269/* used to declare other types */
270
271#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
272 (flags), (tag), offsetof(stname, field),\
273 #field, ASN1_ITEM_ref(type) }
274
275/* used when the structure is combined with the parent */
276
277#define ASN1_EX_COMBINE(flags, tag, type) { \
278 (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
279
280/* implicit and explicit helper macros */
281
282#define ASN1_IMP_EX(stname, field, type, tag, ex) \
283 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
284
285#define ASN1_EXP_EX(stname, field, type, tag, ex) \
286 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
287
288/* Any defined by macros: the field used is in the table itself */
289
290#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
291#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
292#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
293#else
294#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
295#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
296#endif
297/* Plain simple type */
298#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
299
300/* OPTIONAL simple type */
301#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
302
303/* IMPLICIT tagged simple type */
304#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
305
306/* IMPLICIT tagged OPTIONAL simple type */
307#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
308
309/* Same as above but EXPLICIT */
310
311#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
312#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
313
314/* SEQUENCE OF type */
315#define ASN1_SEQUENCE_OF(stname, field, type) \
316 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
317
318/* OPTIONAL SEQUENCE OF */
319#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
320 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
321
322/* Same as above but for SET OF */
323
324#define ASN1_SET_OF(stname, field, type) \
325 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
326
327#define ASN1_SET_OF_OPT(stname, field, type) \
328 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
329
330/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
331
332#define ASN1_IMP_SET_OF(stname, field, type, tag) \
333 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
334
335#define ASN1_EXP_SET_OF(stname, field, type, tag) \
336 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
337
338#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
339 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
340
341#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
342 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
343
344#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
345 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
346
347#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
348 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
349
350#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
351 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
352
353#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
354 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
355
356/* Macros for the ASN1_ADB structure */
357
358#define ASN1_ADB(name) \
359 const static ASN1_ADB_TABLE name##_adbtbl[]
360
361#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
362
363#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
364 ;\
365 const static ASN1_ADB name##_adb = {\
366 flags,\
367 offsetof(name, field),\
368 app_table,\
369 name##_adbtbl,\
370 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
371 def,\
372 none\
373 }
374
375#else
376
377#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
378 ;\
379 const static ASN1_ITEM *name##_adb(void) \
380 { \
381 const static ASN1_ADB internal_adb = \
382 {\
383 flags,\
384 offsetof(name, field),\
385 app_table,\
386 name##_adbtbl,\
387 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
388 def,\
389 none\
390 }; \
391 return (const ASN1_ITEM *) &internal_adb; \
392 } \
393 void dummy_function(void)
394
395#endif
396
397#define ADB_ENTRY(val, template) {val, template}
398
399#define ASN1_ADB_TEMPLATE(name) \
400 const static ASN1_TEMPLATE name##_tt
401
402/* This is the ASN1 template structure that defines
403 * a wrapper round the actual type. It determines the
404 * actual position of the field in the value structure,
405 * various flags such as OPTIONAL and the field name.
406 */
407
408struct ASN1_TEMPLATE_st {
409unsigned long flags; /* Various flags */
410long tag; /* tag, not used if no tagging */
411unsigned long offset; /* Offset of this field in structure */
412#ifndef NO_ASN1_FIELD_NAMES
413char *field_name; /* Field name */
414#endif
415ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
416};
417
418/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
419
420#define ASN1_TEMPLATE_item(t) (t->item_ptr)
421#define ASN1_TEMPLATE_adb(t) (t->item_ptr)
422
423typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
424typedef struct ASN1_ADB_st ASN1_ADB;
425
426struct ASN1_ADB_st {
427 unsigned long flags; /* Various flags */
428 unsigned long offset; /* Offset of selector field */
429 STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */
430 const ASN1_ADB_TABLE *tbl; /* Table of possible types */
431 long tblcount; /* Number of entries in tbl */
432 const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
433 const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
434};
435
436struct ASN1_ADB_TABLE_st {
437 long value; /* NID for an object or value for an int */
438 const ASN1_TEMPLATE tt; /* item for this value */
439};
440
441/* template flags */
442
443/* Field is optional */
444#define ASN1_TFLG_OPTIONAL (0x1)
445
446/* Field is a SET OF */
447#define ASN1_TFLG_SET_OF (0x1 << 1)
448
449/* Field is a SEQUENCE OF */
450#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
451
452/* Special case: this refers to a SET OF that
453 * will be sorted into DER order when encoded *and*
454 * the corresponding STACK will be modified to match
455 * the new order.
456 */
457#define ASN1_TFLG_SET_ORDER (0x3 << 1)
458
459/* Mask for SET OF or SEQUENCE OF */
460#define ASN1_TFLG_SK_MASK (0x3 << 1)
461
462/* These flags mean the tag should be taken from the
463 * tag field. If EXPLICIT then the underlying type
464 * is used for the inner tag.
465 */
466
467/* IMPLICIT tagging */
468#define ASN1_TFLG_IMPTAG (0x1 << 3)
469
470
471/* EXPLICIT tagging, inner tag from underlying type */
472#define ASN1_TFLG_EXPTAG (0x2 << 3)
473
474#define ASN1_TFLG_TAG_MASK (0x3 << 3)
475
476/* context specific IMPLICIT */
477#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
478
479/* context specific EXPLICIT */
480#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
481
482/* If tagging is in force these determine the
483 * type of tag to use. Otherwise the tag is
484 * determined by the underlying type. These
485 * values reflect the actual octet format.
486 */
487
488/* Universal tag */
489#define ASN1_TFLG_UNIVERSAL (0x0<<6)
490/* Application tag */
491#define ASN1_TFLG_APPLICATION (0x1<<6)
492/* Context specific tag */
493#define ASN1_TFLG_CONTEXT (0x2<<6)
494/* Private tag */
495#define ASN1_TFLG_PRIVATE (0x3<<6)
496
497#define ASN1_TFLG_TAG_CLASS (0x3<<6)
498
499/* These are for ANY DEFINED BY type. In this case
500 * the 'item' field points to an ASN1_ADB structure
501 * which contains a table of values to decode the
502 * relevant type
503 */
504
505#define ASN1_TFLG_ADB_MASK (0x3<<8)
506
507#define ASN1_TFLG_ADB_OID (0x1<<8)
508
509#define ASN1_TFLG_ADB_INT (0x1<<9)
510
511/* This flag means a parent structure is passed
512 * instead of the field: this is useful is a
513 * SEQUENCE is being combined with a CHOICE for
514 * example. Since this means the structure and
515 * item name will differ we need to use the
516 * ASN1_CHOICE_END_name() macro for example.
517 */
518
519#define ASN1_TFLG_COMBINE (0x1<<10)
520
521/* This is the actual ASN1 item itself */
522
523struct ASN1_ITEM_st {
524char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
525long utype; /* underlying type */
526const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */
527long tcount; /* Number of templates if SEQUENCE or CHOICE */
528const void *funcs; /* functions that handle this type */
529long size; /* Structure size (usually)*/
530#ifndef NO_ASN1_FIELD_NAMES
531const char *sname; /* Structure name */
532#endif
533};
534
535/* These are values for the itype field and
536 * determine how the type is interpreted.
537 *
538 * For PRIMITIVE types the underlying type
539 * determines the behaviour if items is NULL.
540 *
541 * Otherwise templates must contain a single
542 * template and the type is treated in the
543 * same way as the type specified in the template.
544 *
545 * For SEQUENCE types the templates field points
546 * to the members, the size field is the
547 * structure size.
548 *
549 * For CHOICE types the templates field points
550 * to each possible member (typically a union)
551 * and the 'size' field is the offset of the
552 * selector.
553 *
554 * The 'funcs' field is used for application
555 * specific functions.
556 *
557 * For COMPAT types the funcs field gives a
558 * set of functions that handle this type, this
559 * supports the old d2i, i2d convention.
560 *
561 * The EXTERN type uses a new style d2i/i2d.
562 * The new style should be used where possible
563 * because it avoids things like the d2i IMPLICIT
564 * hack.
565 *
566 * MSTRING is a multiple string type, it is used
567 * for a CHOICE of character strings where the
568 * actual strings all occupy an ASN1_STRING
569 * structure. In this case the 'utype' field
570 * has a special meaning, it is used as a mask
571 * of acceptable types using the B_ASN1 constants.
572 *
573 */
574
575#define ASN1_ITYPE_PRIMITIVE 0x0
576
577#define ASN1_ITYPE_SEQUENCE 0x1
578
579#define ASN1_ITYPE_CHOICE 0x2
580
581#define ASN1_ITYPE_COMPAT 0x3
582
583#define ASN1_ITYPE_EXTERN 0x4
584
585#define ASN1_ITYPE_MSTRING 0x5
586
587/* Cache for ASN1 tag and length, so we
588 * don't keep re-reading it for things
589 * like CHOICE
590 */
591
592struct ASN1_TLC_st{
593 char valid; /* Values below are valid */
594 int ret; /* return value */
595 long plen; /* length */
596 int ptag; /* class value */
597 int pclass; /* class value */
598 int hdrlen; /* header length */
599};
600
601/* Typedefs for ASN1 function pointers */
602
603typedef ASN1_VALUE * ASN1_new_func(void);
604typedef void ASN1_free_func(ASN1_VALUE *a);
605typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length);
606typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
607
608typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
609 int tag, int aclass, char opt, ASN1_TLC *ctx);
610
611typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
612typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
613typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
614
615typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
616typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
617
618typedef struct ASN1_COMPAT_FUNCS_st {
619 ASN1_new_func *asn1_new;
620 ASN1_free_func *asn1_free;
621 ASN1_d2i_func *asn1_d2i;
622 ASN1_i2d_func *asn1_i2d;
623} ASN1_COMPAT_FUNCS;
624
625typedef struct ASN1_EXTERN_FUNCS_st {
626 void *app_data;
627 ASN1_ex_new_func *asn1_ex_new;
628 ASN1_ex_free_func *asn1_ex_free;
629 ASN1_ex_free_func *asn1_ex_clear;
630 ASN1_ex_d2i *asn1_ex_d2i;
631 ASN1_ex_i2d *asn1_ex_i2d;
632} ASN1_EXTERN_FUNCS;
633
634typedef struct ASN1_PRIMITIVE_FUNCS_st {
635 void *app_data;
636 unsigned long flags;
637 ASN1_ex_new_func *prim_new;
638 ASN1_ex_free_func *prim_free;
639 ASN1_ex_free_func *prim_clear;
640 ASN1_primitive_c2i *prim_c2i;
641 ASN1_primitive_i2c *prim_i2c;
642} ASN1_PRIMITIVE_FUNCS;
643
644/* This is the ASN1_AUX structure: it handles various
645 * miscellaneous requirements. For example the use of
646 * reference counts and an informational callback.
647 *
648 * The "informational callback" is called at various
649 * points during the ASN1 encoding and decoding. It can
650 * be used to provide minor customisation of the structures
651 * used. This is most useful where the supplied routines
652 * *almost* do the right thing but need some extra help
653 * at a few points. If the callback returns zero then
654 * it is assumed a fatal error has occurred and the
655 * main operation should be abandoned.
656 *
657 * If major changes in the default behaviour are required
658 * then an external type is more appropriate.
659 */
660
661typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
662
663typedef struct ASN1_AUX_st {
664 void *app_data;
665 int flags;
666 int ref_offset; /* Offset of reference value */
667 int ref_lock; /* Lock type to use */
668 ASN1_aux_cb *asn1_cb;
669 int enc_offset; /* Offset of ASN1_ENCODING structure */
670} ASN1_AUX;
671
672/* Flags in ASN1_AUX */
673
674/* Use a reference count */
675#define ASN1_AFLG_REFCOUNT 1
676/* Save the encoding of structure (useful for signatures) */
677#define ASN1_AFLG_ENCODING 2
678/* The Sequence length is invalid */
679#define ASN1_AFLG_BROKEN 4
680
681/* operation values for asn1_cb */
682
683#define ASN1_OP_NEW_PRE 0
684#define ASN1_OP_NEW_POST 1
685#define ASN1_OP_FREE_PRE 2
686#define ASN1_OP_FREE_POST 3
687#define ASN1_OP_D2I_PRE 4
688#define ASN1_OP_D2I_POST 5
689#define ASN1_OP_I2D_PRE 6
690#define ASN1_OP_I2D_POST 7
691
692/* Macro to implement a primitive type */
693#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
694#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
695 ASN1_ITEM_start(itname) \
696 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
697 ASN1_ITEM_end(itname)
698
699/* Macro to implement a multi string type */
700#define IMPLEMENT_ASN1_MSTRING(itname, mask) \
701 ASN1_ITEM_start(itname) \
702 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
703 ASN1_ITEM_end(itname)
704
705/* Macro to implement an ASN1_ITEM in terms of old style funcs */
706
707#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
708
709#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
710 static const ASN1_COMPAT_FUNCS sname##_ff = { \
711 (ASN1_new_func *)sname##_new, \
712 (ASN1_free_func *)sname##_free, \
713 (ASN1_d2i_func *)d2i_##sname, \
714 (ASN1_i2d_func *)i2d_##sname, \
715 }; \
716 ASN1_ITEM_start(sname) \
717 ASN1_ITYPE_COMPAT, \
718 tag, \
719 NULL, \
720 0, \
721 &sname##_ff, \
722 0, \
723 #sname \
724 ASN1_ITEM_end(sname)
725
726#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
727 ASN1_ITEM_start(sname) \
728 ASN1_ITYPE_EXTERN, \
729 tag, \
730 NULL, \
731 0, \
732 &fptrs, \
733 0, \
734 #sname \
735 ASN1_ITEM_end(sname)
736
737/* Macro to implement standard functions in terms of ASN1_ITEM structures */
738
739#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
740
741#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
742
743#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
744 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
745
746#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
747 stname *fname##_new(void) \
748 { \
749 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
750 } \
751 void fname##_free(stname *a) \
752 { \
753 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
754 }
755
756#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
757 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
758 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
759
760#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
761 stname *d2i_##fname(stname **a, unsigned char **in, long len) \
762 { \
763 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
764 } \
765 int i2d_##fname(stname *a, unsigned char **out) \
766 { \
767 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
768 }
769
770/* This includes evil casts to remove const: they will go away when full
771 * ASN1 constification is done.
772 */
773#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
774 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
775 { \
776 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\
777 } \
778 int i2d_##fname(const stname *a, unsigned char **out) \
779 { \
780 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
781 }
782
783#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
784 stname * stname##_dup(stname *x) \
785 { \
786 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
787 }
788
789#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
790 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
791
792#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
793 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
794 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
795
796/* external definitions for primitive types */
797
798DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
799DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
800DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
801DECLARE_ASN1_ITEM(ASN1_ANY)
802DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
803DECLARE_ASN1_ITEM(CBIGNUM)
804DECLARE_ASN1_ITEM(BIGNUM)
805DECLARE_ASN1_ITEM(LONG)
806DECLARE_ASN1_ITEM(ZLONG)
807
808DECLARE_STACK_OF(ASN1_VALUE)
809
810/* Functions used internally by the ASN1 code */
811
812int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
813void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
814int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
815int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
816
817void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
818int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt);
819int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
820 int tag, int aclass, char opt, ASN1_TLC *ctx);
821
822int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
823int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);
824void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
825
826int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
827int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
828
829int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
830int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
831
832ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
833
834const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
835
836int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
837
838void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
839void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
840int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
841int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it);
842
843#ifdef __cplusplus
844}
845#endif
846#endif
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
new file mode 100644
index 0000000000..edb44c988f
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn_moid.c
@@ -0,0 +1,100 @@
1/* asn_moid.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65
66/* Simple ASN1 OID module: add all objects in a given section */
67
68static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
69 {
70 int i;
71 const char *oid_section;
72 STACK_OF(CONF_VALUE) *sktmp;
73 CONF_VALUE *oval;
74 oid_section = CONF_imodule_get_value(md);
75 if(!(sktmp = NCONF_get_section(cnf, oid_section)))
76 {
77 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
78 return 0;
79 }
80 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
81 {
82 oval = sk_CONF_VALUE_value(sktmp, i);
83 if(OBJ_create(oval->value, oval->name, oval->name) == NID_undef)
84 {
85 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
86 return 0;
87 }
88 }
89 return 1;
90 }
91
92static void oid_module_finish(CONF_IMODULE *md)
93 {
94 OBJ_cleanup();
95 }
96
97void ASN1_add_oid_module(void)
98 {
99 CONF_module_add("oid_section", oid_module_init, oid_module_finish);
100 }
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
new file mode 100644
index 0000000000..e6051db2dc
--- /dev/null
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -0,0 +1,191 @@
1/* asn_pack.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63#ifndef NO_ASN1_OLD
64
65/* ASN1 packing and unpacking functions */
66
67/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
68
69STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
70 void (*free_func)(void *))
71{
72 STACK *sk;
73 unsigned char *pbuf;
74 pbuf = buf;
75 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
76 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
77 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
78 return sk;
79}
80
81/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
82 * OPENSSL_malloc'ed buffer
83 */
84
85unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
86 int *len)
87{
88 int safelen;
89 unsigned char *safe, *p;
90 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
91 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
92 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
93 return NULL;
94 }
95 if (!(safe = OPENSSL_malloc (safelen))) {
96 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
97 return NULL;
98 }
99 p = safe;
100 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
101 IS_SEQUENCE);
102 if (len) *len = safelen;
103 if (buf) *buf = safe;
104 return safe;
105}
106
107/* Extract an ASN1 object from an ASN1_STRING */
108
109void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
110{
111 unsigned char *p;
112 char *ret;
113
114 p = oct->data;
115 if(!(ret = d2i(NULL, &p, oct->length)))
116 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
117 return ret;
118}
119
120/* Pack an ASN1 object into an ASN1_STRING */
121
122ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_STRING **oct)
123{
124 unsigned char *p;
125 ASN1_STRING *octmp;
126
127 if (!oct || !*oct) {
128 if (!(octmp = ASN1_STRING_new ())) {
129 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
130 return NULL;
131 }
132 if (oct) *oct = octmp;
133 } else octmp = *oct;
134
135 if (!(octmp->length = i2d(obj, NULL))) {
136 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
137 return NULL;
138 }
139 if (!(p = OPENSSL_malloc (octmp->length))) {
140 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
141 return NULL;
142 }
143 octmp->data = p;
144 i2d (obj, &p);
145 return octmp;
146}
147
148#endif
149
150/* ASN1_ITEM versions of the above */
151
152ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
153{
154 ASN1_STRING *octmp;
155
156 if (!oct || !*oct) {
157 if (!(octmp = ASN1_STRING_new ())) {
158 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
159 return NULL;
160 }
161 if (oct) *oct = octmp;
162 } else octmp = *oct;
163
164 if(octmp->data) {
165 OPENSSL_free(octmp->data);
166 octmp->data = NULL;
167 }
168
169 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
170 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
171 return NULL;
172 }
173 if (!octmp->data) {
174 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
175 return NULL;
176 }
177 return octmp;
178}
179
180/* Extract an ASN1 object from an ASN1_STRING */
181
182void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
183{
184 unsigned char *p;
185 void *ret;
186
187 p = oct->data;
188 if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
189 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
190 return ret;
191}
diff --git a/src/lib/libcrypto/asn1/charmap.h b/src/lib/libcrypto/asn1/charmap.h
new file mode 100644
index 0000000000..bd020a9562
--- /dev/null
+++ b/src/lib/libcrypto/asn1/charmap.h
@@ -0,0 +1,15 @@
1/* Auto generated with chartype.pl script.
2 * Mask of various character properties
3 */
4
5static unsigned char char_type[] = {
6 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
8120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
916,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16,
10 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1116,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0,
12 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1316,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2
14};
15
diff --git a/src/lib/libcrypto/asn1/charmap.pl b/src/lib/libcrypto/asn1/charmap.pl
new file mode 100644
index 0000000000..2875c59867
--- /dev/null
+++ b/src/lib/libcrypto/asn1/charmap.pl
@@ -0,0 +1,80 @@
1#!/usr/local/bin/perl -w
2
3use strict;
4
5my ($i, @arr);
6
7# Set up an array with the type of ASCII characters
8# Each set bit represents a character property.
9
10# RFC2253 character properties
11my $RFC2253_ESC = 1; # Character escaped with \
12my $ESC_CTRL = 2; # Escaped control character
13# These are used with RFC1779 quoting using "
14my $NOESC_QUOTE = 8; # Not escaped if quoted
15my $PSTRING_CHAR = 0x10; # Valid PrintableString character
16my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character
17my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character
18
19for($i = 0; $i < 128; $i++) {
20 # Set the RFC2253 escape characters (control)
21 $arr[$i] = 0;
22 if(($i < 32) || ($i > 126)) {
23 $arr[$i] |= $ESC_CTRL;
24 }
25
26 # Some PrintableString characters
27 if( ( ( $i >= ord("a")) && ( $i <= ord("z")) )
28 || ( ( $i >= ord("A")) && ( $i <= ord("Z")) )
29 || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) {
30 $arr[$i] |= $PSTRING_CHAR;
31 }
32}
33
34# Now setup the rest
35
36# Remaining RFC2253 escaped characters
37
38$arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC;
39$arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC;
40
41$arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC;
42$arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC;
43$arr[ord("\"")] |= $RFC2253_ESC;
44$arr[ord("\\")] |= $RFC2253_ESC;
45$arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC;
46$arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC;
47$arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC;
48
49# Remaining PrintableString characters
50
51$arr[ord(" ")] |= $PSTRING_CHAR;
52$arr[ord("'")] |= $PSTRING_CHAR;
53$arr[ord("(")] |= $PSTRING_CHAR;
54$arr[ord(")")] |= $PSTRING_CHAR;
55$arr[ord("+")] |= $PSTRING_CHAR;
56$arr[ord(",")] |= $PSTRING_CHAR;
57$arr[ord("-")] |= $PSTRING_CHAR;
58$arr[ord(".")] |= $PSTRING_CHAR;
59$arr[ord("/")] |= $PSTRING_CHAR;
60$arr[ord(":")] |= $PSTRING_CHAR;
61$arr[ord("=")] |= $PSTRING_CHAR;
62$arr[ord("?")] |= $PSTRING_CHAR;
63
64# Now generate the C code
65
66print <<EOF;
67/* Auto generated with chartype.pl script.
68 * Mask of various character properties
69 */
70
71static unsigned char char_type[] = {
72EOF
73
74for($i = 0; $i < 128; $i++) {
75 print("\n") if($i && (($i % 16) == 0));
76 printf("%2d", $arr[$i]);
77 print(",") if ($i != 127);
78}
79print("\n};\n\n");
80
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
new file mode 100644
index 0000000000..2e7d96af90
--- /dev/null
+++ b/src/lib/libcrypto/asn1/d2i_pr.c
@@ -0,0 +1,145 @@
1/* crypto/asn1/d2i_pr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/asn1.h>
65#ifndef OPENSSL_NO_RSA
66#include <openssl/rsa.h>
67#endif
68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h>
70#endif
71
72EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
73 long length)
74 {
75 EVP_PKEY *ret;
76
77 if ((a == NULL) || (*a == NULL))
78 {
79 if ((ret=EVP_PKEY_new()) == NULL)
80 {
81 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
82 return(NULL);
83 }
84 }
85 else ret= *a;
86
87 ret->save_type=type;
88 ret->type=EVP_PKEY_type(type);
89 switch (ret->type)
90 {
91#ifndef OPENSSL_NO_RSA
92 case EVP_PKEY_RSA:
93 if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,
94 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
95 {
96 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
97 goto err;
98 }
99 break;
100#endif
101#ifndef OPENSSL_NO_DSA
102 case EVP_PKEY_DSA:
103 if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,
104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
105 {
106 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
107 goto err;
108 }
109 break;
110#endif
111 default:
112 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err;
114 /* break; */
115 }
116 if (a != NULL) (*a)=ret;
117 return(ret);
118err:
119 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
120 return(NULL);
121 }
122
123/* This works like d2i_PrivateKey() except it automatically works out the type */
124
125EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
126 long length)
127{
128 STACK_OF(ASN1_TYPE) *inkey;
129 unsigned char *p;
130 int keytype;
131 p = *pp;
132 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
133 * by analyzing it we can determine the passed structure: this
134 * assumes the input is surrounded by an ASN1 SEQUENCE.
135 */
136 inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE,
137 ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
138 /* Since we only need to discern "traditional format" RSA and DSA
139 * keys we can just count the elements.
140 */
141 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
142 else keytype = EVP_PKEY_RSA;
143 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
144 return d2i_PrivateKey(keytype, a, pp, length);
145}
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
new file mode 100644
index 0000000000..71f2eb361b
--- /dev/null
+++ b/src/lib/libcrypto/asn1/d2i_pu.c
@@ -0,0 +1,122 @@
1/* crypto/asn1/d2i_pu.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/asn1.h>
65#ifndef OPENSSL_NO_RSA
66#include <openssl/rsa.h>
67#endif
68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h>
70#endif
71
72EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
73 long length)
74 {
75 EVP_PKEY *ret;
76
77 if ((a == NULL) || (*a == NULL))
78 {
79 if ((ret=EVP_PKEY_new()) == NULL)
80 {
81 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
82 return(NULL);
83 }
84 }
85 else ret= *a;
86
87 ret->save_type=type;
88 ret->type=EVP_PKEY_type(type);
89 switch (ret->type)
90 {
91#ifndef OPENSSL_NO_RSA
92 case EVP_PKEY_RSA:
93 if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,
94 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
95 {
96 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
97 goto err;
98 }
99 break;
100#endif
101#ifndef OPENSSL_NO_DSA
102 case EVP_PKEY_DSA:
103 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,
104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
105 {
106 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
107 goto err;
108 }
109 break;
110#endif
111 default:
112 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err;
114 /* break; */
115 }
116 if (a != NULL) (*a)=ret;
117 return(ret);
118err:
119 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
120 return(NULL);
121 }
122
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
new file mode 100644
index 0000000000..f92ce6cb5d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/evp_asn1.c
@@ -0,0 +1,189 @@
1/* crypto/asn1/evp_asn1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63
64int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
65 {
66 ASN1_STRING *os;
67
68 if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0);
69 if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0);
70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
71 return(1);
72 }
73
74/* int max_len: for returned value */
75int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data,
76 int max_len)
77 {
78 int ret,num;
79 unsigned char *p;
80
81 if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL))
82 {
83 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
84 return(-1);
85 }
86 p=M_ASN1_STRING_data(a->value.octet_string);
87 ret=M_ASN1_STRING_length(a->value.octet_string);
88 if (ret < max_len)
89 num=ret;
90 else
91 num=max_len;
92 memcpy(data,p,num);
93 return(ret);
94 }
95
96int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
97 int len)
98 {
99 int n,size;
100 ASN1_OCTET_STRING os,*osp;
101 ASN1_INTEGER in;
102 unsigned char *p;
103 unsigned char buf[32]; /* when they have 256bit longs,
104 * I'll be in trouble */
105 in.data=buf;
106 in.length=32;
107 os.data=data;
108 os.type=V_ASN1_OCTET_STRING;
109 os.length=len;
110 ASN1_INTEGER_set(&in,num);
111 n = i2d_ASN1_INTEGER(&in,NULL);
112 n+=M_i2d_ASN1_OCTET_STRING(&os,NULL);
113
114 size=ASN1_object_size(1,n,V_ASN1_SEQUENCE);
115
116 if ((osp=ASN1_STRING_new()) == NULL) return(0);
117 /* Grow the 'string' */
118 if (!ASN1_STRING_set(osp,NULL,size))
119 {
120 ASN1_STRING_free(osp);
121 return(0);
122 }
123
124 M_ASN1_STRING_length_set(osp, size);
125 p=M_ASN1_STRING_data(osp);
126
127 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
128 i2d_ASN1_INTEGER(&in,&p);
129 M_i2d_ASN1_OCTET_STRING(&os,&p);
130
131 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp);
132 return(1);
133 }
134
135/* we return the actual length..., num may be missing, in which
136 * case, set it to zero */
137/* int max_len: for returned value */
138int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
139 int max_len)
140 {
141 int ret= -1,n;
142 ASN1_INTEGER *ai=NULL;
143 ASN1_OCTET_STRING *os=NULL;
144 unsigned char *p;
145 long length;
146 ASN1_CTX c;
147
148 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
149 {
150 goto err;
151 }
152 p=M_ASN1_STRING_data(a->value.sequence);
153 length=M_ASN1_STRING_length(a->value.sequence);
154
155 c.pp= &p;
156 c.p=p;
157 c.max=p+length;
158 c.error=ASN1_R_DATA_IS_WRONG;
159
160 M_ASN1_D2I_start_sequence();
161 c.q=c.p;
162 if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err;
163 c.slen-=(c.p-c.q);
164 c.q=c.p;
165 if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err;
166 c.slen-=(c.p-c.q);
167 if (!M_ASN1_D2I_end_sequence()) goto err;
168
169 if (num != NULL)
170 *num=ASN1_INTEGER_get(ai);
171
172 ret=M_ASN1_STRING_length(os);
173 if (max_len > ret)
174 n=ret;
175 else
176 n=max_len;
177
178 if (data != NULL)
179 memcpy(data,M_ASN1_STRING_data(os),n);
180 if (0)
181 {
182err:
183 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
184 }
185 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
186 if (ai != NULL) M_ASN1_INTEGER_free(ai);
187 return(ret);
188 }
189
diff --git a/src/lib/libcrypto/asn1/f.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/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
new file mode 100644
index 0000000000..56e3cc8df2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f_enum.c
@@ -0,0 +1,207 @@
1/* crypto/asn1/f_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64/* Based on a_int.c: equivalent ENUMERATED functions */
65
66int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
67 {
68 int i,n=0;
69 static const char *h="0123456789ABCDEF";
70 char buf[2];
71
72 if (a == NULL) return(0);
73
74 if (a->length == 0)
75 {
76 if (BIO_write(bp,"00",2) != 2) goto err;
77 n=2;
78 }
79 else
80 {
81 for (i=0; i<a->length; i++)
82 {
83 if ((i != 0) && (i%35 == 0))
84 {
85 if (BIO_write(bp,"\\\n",2) != 2) goto err;
86 n+=2;
87 }
88 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
89 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
90 if (BIO_write(bp,buf,2) != 2) goto err;
91 n+=2;
92 }
93 }
94 return(n);
95err:
96 return(-1);
97 }
98
99int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
100 {
101 int ret=0;
102 int i,j,k,m,n,again,bufsize;
103 unsigned char *s=NULL,*sp;
104 unsigned char *bufp;
105 int num=0,slen=0,first=1;
106
107 bs->type=V_ASN1_ENUMERATED;
108
109 bufsize=BIO_gets(bp,buf,size);
110 for (;;)
111 {
112 if (bufsize < 1) goto err_sl;
113 i=bufsize;
114 if (buf[i-1] == '\n') buf[--i]='\0';
115 if (i == 0) goto err_sl;
116 if (buf[i-1] == '\r') buf[--i]='\0';
117 if (i == 0) goto err_sl;
118 again=(buf[i-1] == '\\');
119
120 for (j=0; j<i; j++)
121 {
122 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
123 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
124 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
125 {
126 i=j;
127 break;
128 }
129 }
130 buf[i]='\0';
131 /* We have now cleared all the crap off the end of the
132 * line */
133 if (i < 2) goto err_sl;
134
135 bufp=(unsigned char *)buf;
136 if (first)
137 {
138 first=0;
139 if ((bufp[0] == '0') && (buf[1] == '0'))
140 {
141 bufp+=2;
142 i-=2;
143 }
144 }
145 k=0;
146 i-=again;
147 if (i%2 != 0)
148 {
149 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
150 goto err;
151 }
152 i/=2;
153 if (num+i > slen)
154 {
155 if (s == NULL)
156 sp=(unsigned char *)OPENSSL_malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)OPENSSL_realloc(s,
160 (unsigned int)num+i*2);
161 if (sp == NULL)
162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) OPENSSL_free(s);
165 goto err;
166 }
167 s=sp;
168 slen=num+i*2;
169 }
170 for (j=0; j<i; j++,k+=2)
171 {
172 for (n=0; n<2; n++)
173 {
174 m=bufp[k+n];
175 if ((m >= '0') && (m <= '9'))
176 m-='0';
177 else if ((m >= 'a') && (m <= 'f'))
178 m=m-'a'+10;
179 else if ((m >= 'A') && (m <= 'F'))
180 m=m-'A'+10;
181 else
182 {
183 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
184 goto err;
185 }
186 s[num+j]<<=4;
187 s[num+j]|=m;
188 }
189 }
190 num+=i;
191 if (again)
192 bufsize=BIO_gets(bp,buf,size);
193 else
194 break;
195 }
196 bs->length=num;
197 bs->data=s;
198 ret=1;
199err:
200 if (0)
201 {
202err_sl:
203 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
204 }
205 return(ret);
206 }
207
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c
new file mode 100644
index 0000000000..9494e597ab
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f_int.c
@@ -0,0 +1,219 @@
1/* crypto/asn1/f_int.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
65 {
66 int i,n=0;
67 static const char *h="0123456789ABCDEF";
68 char buf[2];
69
70 if (a == NULL) return(0);
71
72 if (a->type & V_ASN1_NEG)
73 {
74 if (BIO_write(bp, "-", 1) != 1) goto err;
75 n = 1;
76 }
77
78 if (a->length == 0)
79 {
80 if (BIO_write(bp,"00",2) != 2) goto err;
81 n += 2;
82 }
83 else
84 {
85 for (i=0; i<a->length; i++)
86 {
87 if ((i != 0) && (i%35 == 0))
88 {
89 if (BIO_write(bp,"\\\n",2) != 2) goto err;
90 n+=2;
91 }
92 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
93 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
94 if (BIO_write(bp,buf,2) != 2) goto err;
95 n+=2;
96 }
97 }
98 return(n);
99err:
100 return(-1);
101 }
102
103int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
104 {
105 int ret=0;
106 int i,j,k,m,n,again,bufsize;
107 unsigned char *s=NULL,*sp;
108 unsigned char *bufp;
109 int num=0,slen=0,first=1;
110
111 bs->type=V_ASN1_INTEGER;
112
113 bufsize=BIO_gets(bp,buf,size);
114 for (;;)
115 {
116 if (bufsize < 1) goto err_sl;
117 i=bufsize;
118 if (buf[i-1] == '\n') buf[--i]='\0';
119 if (i == 0) goto err_sl;
120 if (buf[i-1] == '\r') buf[--i]='\0';
121 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\');
123
124 for (j=0; j<i; j++)
125 {
126#ifndef CHARSET_EBCDIC
127 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
128 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
129 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
130#else
131 /* This #ifdef is not strictly necessary, since
132 * the characters A...F a...f 0...9 are contiguous
133 * (yes, even in EBCDIC - but not the whole alphabet).
134 * Nevertheless, isxdigit() is faster.
135 */
136 if (!isxdigit(buf[j]))
137#endif
138 {
139 i=j;
140 break;
141 }
142 }
143 buf[i]='\0';
144 /* We have now cleared all the crap off the end of the
145 * line */
146 if (i < 2) goto err_sl;
147
148 bufp=(unsigned char *)buf;
149 if (first)
150 {
151 first=0;
152 if ((bufp[0] == '0') && (buf[1] == '0'))
153 {
154 bufp+=2;
155 i-=2;
156 }
157 }
158 k=0;
159 i-=again;
160 if (i%2 != 0)
161 {
162 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
163 goto err;
164 }
165 i/=2;
166 if (num+i > slen)
167 {
168 if (s == NULL)
169 sp=(unsigned char *)OPENSSL_malloc(
170 (unsigned int)num+i*2);
171 else
172 sp=OPENSSL_realloc_clean(s,slen,num+i*2);
173 if (sp == NULL)
174 {
175 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
176 if (s != NULL) OPENSSL_free(s);
177 goto err;
178 }
179 s=sp;
180 slen=num+i*2;
181 }
182 for (j=0; j<i; j++,k+=2)
183 {
184 for (n=0; n<2; n++)
185 {
186 m=bufp[k+n];
187 if ((m >= '0') && (m <= '9'))
188 m-='0';
189 else if ((m >= 'a') && (m <= 'f'))
190 m=m-'a'+10;
191 else if ((m >= 'A') && (m <= 'F'))
192 m=m-'A'+10;
193 else
194 {
195 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
196 goto err;
197 }
198 s[num+j]<<=4;
199 s[num+j]|=m;
200 }
201 }
202 num+=i;
203 if (again)
204 bufsize=BIO_gets(bp,buf,size);
205 else
206 break;
207 }
208 bs->length=num;
209 bs->data=s;
210 ret=1;
211err:
212 if (0)
213 {
214err_sl:
215 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
216 }
217 return(ret);
218 }
219
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
new file mode 100644
index 0000000000..968698a798
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -0,0 +1,212 @@
1/* crypto/asn1/f_string.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
65 {
66 int i,n=0;
67 static const char *h="0123456789ABCDEF";
68 char buf[2];
69
70 if (a == NULL) return(0);
71
72 if (a->length == 0)
73 {
74 if (BIO_write(bp,"0",1) != 1) goto err;
75 n=1;
76 }
77 else
78 {
79 for (i=0; i<a->length; i++)
80 {
81 if ((i != 0) && (i%35 == 0))
82 {
83 if (BIO_write(bp,"\\\n",2) != 2) goto err;
84 n+=2;
85 }
86 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
87 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
88 if (BIO_write(bp,buf,2) != 2) goto err;
89 n+=2;
90 }
91 }
92 return(n);
93err:
94 return(-1);
95 }
96
97int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
98 {
99 int ret=0;
100 int i,j,k,m,n,again,bufsize;
101 unsigned char *s=NULL,*sp;
102 unsigned char *bufp;
103 int num=0,slen=0,first=1;
104
105 bufsize=BIO_gets(bp,buf,size);
106 for (;;)
107 {
108 if (bufsize < 1)
109 {
110 if (first)
111 break;
112 else
113 goto err_sl;
114 }
115 first=0;
116
117 i=bufsize;
118 if (buf[i-1] == '\n') buf[--i]='\0';
119 if (i == 0) goto err_sl;
120 if (buf[i-1] == '\r') buf[--i]='\0';
121 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\');
123
124 for (j=i-1; j>0; j--)
125 {
126#ifndef CHARSET_EBCDIC
127 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
128 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
129 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
130#else
131 /* This #ifdef is not strictly necessary, since
132 * the characters A...F a...f 0...9 are contiguous
133 * (yes, even in EBCDIC - but not the whole alphabet).
134 * Nevertheless, isxdigit() is faster.
135 */
136 if (!isxdigit(buf[j]))
137#endif
138 {
139 i=j;
140 break;
141 }
142 }
143 buf[i]='\0';
144 /* We have now cleared all the crap off the end of the
145 * line */
146 if (i < 2) goto err_sl;
147
148 bufp=(unsigned char *)buf;
149
150 k=0;
151 i-=again;
152 if (i%2 != 0)
153 {
154 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
155 goto err;
156 }
157 i/=2;
158 if (num+i > slen)
159 {
160 if (s == NULL)
161 sp=(unsigned char *)OPENSSL_malloc(
162 (unsigned int)num+i*2);
163 else
164 sp=(unsigned char *)OPENSSL_realloc(s,
165 (unsigned int)num+i*2);
166 if (sp == NULL)
167 {
168 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
169 if (s != NULL) OPENSSL_free(s);
170 goto err;
171 }
172 s=sp;
173 slen=num+i*2;
174 }
175 for (j=0; j<i; j++,k+=2)
176 {
177 for (n=0; n<2; n++)
178 {
179 m=bufp[k+n];
180 if ((m >= '0') && (m <= '9'))
181 m-='0';
182 else if ((m >= 'a') && (m <= 'f'))
183 m=m-'a'+10;
184 else if ((m >= 'A') && (m <= 'F'))
185 m=m-'A'+10;
186 else
187 {
188 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
189 goto err;
190 }
191 s[num+j]<<=4;
192 s[num+j]|=m;
193 }
194 }
195 num+=i;
196 if (again)
197 bufsize=BIO_gets(bp,buf,size);
198 else
199 break;
200 }
201 bs->length=num;
202 bs->data=s;
203 ret=1;
204err:
205 if (0)
206 {
207err_sl:
208 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
209 }
210 return(ret);
211 }
212
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c
new file mode 100644
index 0000000000..1e951ae01d
--- /dev/null
+++ b/src/lib/libcrypto/asn1/i2d_pr.c
@@ -0,0 +1,90 @@
1/* crypto/asn1/i2d_pr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
72 {
73#ifndef OPENSSL_NO_RSA
74 if (a->type == EVP_PKEY_RSA)
75 {
76 return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
77 }
78 else
79#endif
80#ifndef OPENSSL_NO_DSA
81 if (a->type == EVP_PKEY_DSA)
82 {
83 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
84 }
85#endif
86
87 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
88 return(-1);
89 }
90
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
new file mode 100644
index 0000000000..013d19bbf4
--- /dev/null
+++ b/src/lib/libcrypto/asn1/i2d_pu.c
@@ -0,0 +1,88 @@
1/* crypto/asn1/i2d_pu.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
72 {
73 switch (a->type)
74 {
75#ifndef OPENSSL_NO_RSA
76 case EVP_PKEY_RSA:
77 return(i2d_RSAPublicKey(a->pkey.rsa,pp));
78#endif
79#ifndef OPENSSL_NO_DSA
80 case EVP_PKEY_DSA:
81 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
82#endif
83 default:
84 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
85 return(-1);
86 }
87 }
88
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
new file mode 100644
index 0000000000..766b51c538
--- /dev/null
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -0,0 +1,333 @@
1/* crypto/asn1/n_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/asn1t.h>
65#include <openssl/asn1_mac.h>
66#include <openssl/evp.h>
67#include <openssl/x509.h>
68
69
70#ifndef OPENSSL_NO_RC4
71
72typedef struct netscape_pkey_st
73 {
74 long version;
75 X509_ALGOR *algor;
76 ASN1_OCTET_STRING *private_key;
77 } NETSCAPE_PKEY;
78
79typedef struct netscape_encrypted_pkey_st
80 {
81 ASN1_OCTET_STRING *os;
82 /* This is the same structure as DigestInfo so use it:
83 * although this isn't really anything to do with
84 * digests.
85 */
86 X509_SIG *enckey;
87 } NETSCAPE_ENCRYPTED_PKEY;
88
89
90ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
91 ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING),
92 ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG)
93} ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY)
94
95DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
96DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY)
97IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
98
99ASN1_SEQUENCE(NETSCAPE_PKEY) = {
100 ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG),
101 ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR),
102 ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
103} ASN1_SEQUENCE_END(NETSCAPE_PKEY)
104
105DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
106DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY)
107IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
108
109static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
110 int (*cb)(), int sgckey);
111
112int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)())
113{
114 return i2d_RSA_NET(a, pp, cb, 0);
115}
116
117int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey)
118 {
119 int i, j, ret = 0;
120 int rsalen, pkeylen, olen;
121 NETSCAPE_PKEY *pkey = NULL;
122 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
123 unsigned char buf[256],*zz;
124 unsigned char key[EVP_MAX_KEY_LENGTH];
125 EVP_CIPHER_CTX ctx;
126
127 if (a == NULL) return(0);
128
129 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
130 if ((enckey=NETSCAPE_ENCRYPTED_PKEY_new()) == NULL) goto err;
131 pkey->version = 0;
132
133 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
134 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
135 pkey->algor->parameter->type=V_ASN1_NULL;
136
137 rsalen = i2d_RSAPrivateKey(a, NULL);
138
139 /* Fake some octet strings just for the initial length
140 * calculation.
141 */
142
143 pkey->private_key->length=rsalen;
144
145 pkeylen=i2d_NETSCAPE_PKEY(pkey,NULL);
146
147 enckey->enckey->digest->length = pkeylen;
148
149 enckey->os->length = 11; /* "private-key" */
150
151 enckey->enckey->algor->algorithm=OBJ_nid2obj(NID_rc4);
152 if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
153 enckey->enckey->algor->parameter->type=V_ASN1_NULL;
154
155 if (pp == NULL)
156 {
157 olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
158 NETSCAPE_PKEY_free(pkey);
159 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
160 return olen;
161 }
162
163
164 /* Since its RC4 encrypted length is actual length */
165 if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL)
166 {
167 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
168 goto err;
169 }
170
171 pkey->private_key->data = zz;
172 /* Write out private key encoding */
173 i2d_RSAPrivateKey(a,&zz);
174
175 if ((zz=OPENSSL_malloc(pkeylen)) == NULL)
176 {
177 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
178 goto err;
179 }
180
181 if (!ASN1_STRING_set(enckey->os, "private-key", -1))
182 {
183 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
184 goto err;
185 }
186 enckey->enckey->digest->data = zz;
187 i2d_NETSCAPE_PKEY(pkey,&zz);
188
189 /* Wipe the private key encoding */
190 OPENSSL_cleanse(pkey->private_key->data, rsalen);
191
192 if (cb == NULL)
193 cb=EVP_read_pw_string;
194 i=cb(buf,256,"Enter Private Key password:",1);
195 if (i != 0)
196 {
197 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
198 goto err;
199 }
200 i = strlen((char *)buf);
201 /* If the key is used for SGC the algorithm is modified a little. */
202 if(sgckey) {
203 EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL);
204 memcpy(buf + 16, "SGCKEYSALT", 10);
205 i = 26;
206 }
207
208 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
209 OPENSSL_cleanse(buf,256);
210
211 /* Encrypt private key in place */
212 zz = enckey->enckey->digest->data;
213 EVP_CIPHER_CTX_init(&ctx);
214 EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL);
215 EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen);
216 EVP_EncryptFinal_ex(&ctx,zz + i,&j);
217 EVP_CIPHER_CTX_cleanup(&ctx);
218
219 ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp);
220err:
221 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
222 NETSCAPE_PKEY_free(pkey);
223 return(ret);
224 }
225
226
227RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)())
228{
229 return d2i_RSA_NET(a, pp, length, cb, 0);
230}
231
232RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey)
233 {
234 RSA *ret=NULL;
235 const unsigned char *p, *kp;
236 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
237
238 p = *pp;
239
240 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length);
241 if(!enckey) {
242 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
243 return NULL;
244 }
245
246 if ((enckey->os->length != 11) || (strncmp("private-key",
247 (char *)enckey->os->data,11) != 0))
248 {
249 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
250 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
251 return NULL;
252 }
253 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
254 {
255 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
256 goto err;
257 }
258 kp = enckey->enckey->digest->data;
259 if (cb == NULL)
260 cb=EVP_read_pw_string;
261 if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err;
262
263 *pp = p;
264
265 err:
266 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
267 return ret;
268
269 }
270
271static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
272 int (*cb)(), int sgckey)
273 {
274 NETSCAPE_PKEY *pkey=NULL;
275 RSA *ret=NULL;
276 int i,j;
277 unsigned char buf[256];
278 const unsigned char *zz;
279 unsigned char key[EVP_MAX_KEY_LENGTH];
280 EVP_CIPHER_CTX ctx;
281
282 i=cb(buf,256,"Enter Private Key password:",0);
283 if (i != 0)
284 {
285 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
286 goto err;
287 }
288
289 i = strlen((char *)buf);
290 if(sgckey){
291 EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL);
292 memcpy(buf + 16, "SGCKEYSALT", 10);
293 i = 26;
294 }
295
296 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
297 OPENSSL_cleanse(buf,256);
298
299 EVP_CIPHER_CTX_init(&ctx);
300 EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL);
301 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
302 EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j);
303 EVP_CIPHER_CTX_cleanup(&ctx);
304 os->length=i+j;
305
306 zz=os->data;
307
308 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
309 {
310 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
311 goto err;
312 }
313
314 zz=pkey->private_key->data;
315 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
316 {
317 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
318 goto err;
319 }
320err:
321 NETSCAPE_PKEY_free(pkey);
322 return(ret);
323 }
324
325#endif /* OPENSSL_NO_RC4 */
326
327#else /* !OPENSSL_NO_RSA */
328
329# if PEDANTIC
330static void *dummy=&dummy;
331# endif
332
333#endif
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c
new file mode 100644
index 0000000000..50e2d4d07a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/nsseq.c
@@ -0,0 +1,82 @@
1/* nsseq.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/objects.h>
64
65static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 if(operation == ASN1_OP_NEW_POST) {
68 NETSCAPE_CERT_SEQUENCE *nsseq;
69 nsseq = (NETSCAPE_CERT_SEQUENCE *)*pval;
70 nsseq->type = OBJ_nid2obj(NID_netscape_cert_sequence);
71 }
72 return 1;
73}
74
75/* Netscape certificate sequence structure */
76
77ASN1_SEQUENCE_cb(NETSCAPE_CERT_SEQUENCE, nsseq_cb) = {
78 ASN1_SIMPLE(NETSCAPE_CERT_SEQUENCE, type, ASN1_OBJECT),
79 ASN1_EXP_SEQUENCE_OF_OPT(NETSCAPE_CERT_SEQUENCE, certs, X509, 0)
80} ASN1_SEQUENCE_END_cb(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
81
82IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
new file mode 100644
index 0000000000..ec788267e0
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -0,0 +1,130 @@
1/* p5_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67ASN1_SEQUENCE(PBEPARAM) = {
68 ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING),
69 ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER)
70} ASN1_SEQUENCE_END(PBEPARAM)
71
72IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM)
73
74/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
75
76X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
77 int saltlen)
78{
79 PBEPARAM *pbe=NULL;
80 ASN1_OBJECT *al;
81 X509_ALGOR *algor;
82 ASN1_TYPE *astype=NULL;
83
84 if (!(pbe = PBEPARAM_new ())) {
85 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
86 goto err;
87 }
88 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
89 if (!ASN1_INTEGER_set(pbe->iter, iter)) {
90 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93 if (!saltlen) saltlen = PKCS5_SALT_LEN;
94 if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) {
95 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
96 goto err;
97 }
98 pbe->salt->length = saltlen;
99 if (salt) memcpy (pbe->salt->data, salt, saltlen);
100 else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0)
101 goto err;
102
103 if (!(astype = ASN1_TYPE_new())) {
104 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
105 goto err;
106 }
107
108 astype->type = V_ASN1_SEQUENCE;
109 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
110 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
111 goto err;
112 }
113 PBEPARAM_free (pbe);
114 pbe = NULL;
115
116 al = OBJ_nid2obj(alg); /* never need to free al */
117 if (!(algor = X509_ALGOR_new())) {
118 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
119 goto err;
120 }
121 ASN1_OBJECT_free(algor->algorithm);
122 algor->algorithm = al;
123 algor->parameter = astype;
124
125 return (algor);
126err:
127 if (pbe != NULL) PBEPARAM_free(pbe);
128 if (astype != NULL) ASN1_TYPE_free(astype);
129 return NULL;
130}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
new file mode 100644
index 0000000000..e0dc0ec4ee
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -0,0 +1,205 @@
1/* p5_pbev2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999-2004.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67ASN1_SEQUENCE(PBE2PARAM) = {
68 ASN1_SIMPLE(PBE2PARAM, keyfunc, X509_ALGOR),
69 ASN1_SIMPLE(PBE2PARAM, encryption, X509_ALGOR)
70} ASN1_SEQUENCE_END(PBE2PARAM)
71
72IMPLEMENT_ASN1_FUNCTIONS(PBE2PARAM)
73
74ASN1_SEQUENCE(PBKDF2PARAM) = {
75 ASN1_SIMPLE(PBKDF2PARAM, salt, ASN1_ANY),
76 ASN1_SIMPLE(PBKDF2PARAM, iter, ASN1_INTEGER),
77 ASN1_OPT(PBKDF2PARAM, keylength, ASN1_INTEGER),
78 ASN1_OPT(PBKDF2PARAM, prf, X509_ALGOR)
79} ASN1_SEQUENCE_END(PBKDF2PARAM)
80
81IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM)
82
83/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
84 * yes I know this is horrible!
85 */
86
87X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
88 unsigned char *salt, int saltlen)
89{
90 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
91 int alg_nid;
92 EVP_CIPHER_CTX ctx;
93 unsigned char iv[EVP_MAX_IV_LENGTH];
94 PBKDF2PARAM *kdf = NULL;
95 PBE2PARAM *pbe2 = NULL;
96 ASN1_OCTET_STRING *osalt = NULL;
97 ASN1_OBJECT *obj;
98
99 alg_nid = EVP_CIPHER_type(cipher);
100 if(alg_nid == NID_undef) {
101 ASN1err(ASN1_F_PKCS5_PBE2_SET,
102 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
103 goto err;
104 }
105 obj = OBJ_nid2obj(alg_nid);
106
107 if(!(pbe2 = PBE2PARAM_new())) goto merr;
108
109 /* Setup the AlgorithmIdentifier for the encryption scheme */
110 scheme = pbe2->encryption;
111
112 scheme->algorithm = obj;
113 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
114
115 /* Create random IV */
116 if (EVP_CIPHER_iv_length(cipher) &&
117 RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
118 goto err;
119
120 EVP_CIPHER_CTX_init(&ctx);
121
122 /* Dummy cipherinit to just setup the IV */
123 EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0);
124 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
125 ASN1err(ASN1_F_PKCS5_PBE2_SET,
126 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
127 EVP_CIPHER_CTX_cleanup(&ctx);
128 goto err;
129 }
130 EVP_CIPHER_CTX_cleanup(&ctx);
131
132 if(!(kdf = PBKDF2PARAM_new())) goto merr;
133 if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
134
135 if (!saltlen) saltlen = PKCS5_SALT_LEN;
136 if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr;
137 osalt->length = saltlen;
138 if (salt) memcpy (osalt->data, salt, saltlen);
139 else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr;
140
141 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
142 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
143
144 /* Now include salt in kdf structure */
145 kdf->salt->value.octet_string = osalt;
146 kdf->salt->type = V_ASN1_OCTET_STRING;
147 osalt = NULL;
148
149 /* If its RC2 then we'd better setup the key length */
150
151 if(alg_nid == NID_rc2_cbc) {
152 if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr;
153 if(!ASN1_INTEGER_set (kdf->keylength,
154 EVP_CIPHER_key_length(cipher))) goto merr;
155 }
156
157 /* prf can stay NULL because we are using hmacWithSHA1 */
158
159 /* Now setup the PBE2PARAM keyfunc structure */
160
161 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
162
163 /* Encode PBKDF2PARAM into parameter of pbe2 */
164
165 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
166
167 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
168 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
169 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
170
171 PBKDF2PARAM_free(kdf);
172 kdf = NULL;
173
174 /* Now set up top level AlgorithmIdentifier */
175
176 if(!(ret = X509_ALGOR_new())) goto merr;
177 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
178
179 ret->algorithm = OBJ_nid2obj(NID_pbes2);
180
181 /* Encode PBE2PARAM into parameter */
182
183 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
184 &ret->parameter->value.sequence)) goto merr;
185 ret->parameter->type = V_ASN1_SEQUENCE;
186
187 PBE2PARAM_free(pbe2);
188 pbe2 = NULL;
189
190 return ret;
191
192 merr:
193 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
194
195 err:
196 PBE2PARAM_free(pbe2);
197 /* Note 'scheme' is freed as part of pbe2 */
198 M_ASN1_OCTET_STRING_free(osalt);
199 PBKDF2PARAM_free(kdf);
200 X509_ALGOR_free(kalg);
201 X509_ALGOR_free(ret);
202
203 return NULL;
204
205}
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
new file mode 100644
index 0000000000..24b409132f
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p8_pkey.c
@@ -0,0 +1,84 @@
1/* p8_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64/* Minor tweak to operation: zero private key data */
65static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 /* Since the structure must still be valid use ASN1_OP_FREE_PRE */
68 if(operation == ASN1_OP_FREE_PRE) {
69 PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
70 if (key->pkey->value.octet_string)
71 OPENSSL_cleanse(key->pkey->value.octet_string->data,
72 key->pkey->value.octet_string->length);
73 }
74 return 1;
75}
76
77ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = {
78 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER),
79 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR),
80 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY),
81 ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0)
82} ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
83
84IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c
new file mode 100644
index 0000000000..397332d9b8
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_bitst.c
@@ -0,0 +1,102 @@
1/* t_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
65 BIT_STRING_BITNAME *tbl, int indent)
66{
67 BIT_STRING_BITNAME *bnam;
68 char first = 1;
69 BIO_printf(out, "%*s", indent, "");
70 for(bnam = tbl; bnam->lname; bnam++) {
71 if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
72 if(!first) BIO_puts(out, ", ");
73 BIO_puts(out, bnam->lname);
74 first = 0;
75 }
76 }
77 BIO_puts(out, "\n");
78 return 1;
79}
80
81int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
82 BIT_STRING_BITNAME *tbl)
83{
84 int bitnum;
85 bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86 if(bitnum < 0) return 0;
87 if(bs) {
88 if(!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
89 return 0;
90 }
91 return 1;
92}
93
94int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
95{
96 BIT_STRING_BITNAME *bnam;
97 for(bnam = tbl; bnam->lname; bnam++) {
98 if(!strcmp(bnam->sname, name) ||
99 !strcmp(bnam->lname, name) ) return bnam->bitnum;
100 }
101 return -1;
102}
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
new file mode 100644
index 0000000000..757c148df8
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -0,0 +1,134 @@
1/* t_crl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67#ifndef OPENSSL_NO_FP_API
68int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=X509_CRL_print(b, x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int X509_CRL_print(BIO *out, X509_CRL *x)
86{
87 STACK_OF(X509_REVOKED) *rev;
88 X509_REVOKED *r;
89 long l;
90 int i, n;
91 char *p;
92
93 BIO_printf(out, "Certificate Revocation List (CRL):\n");
94 l = X509_CRL_get_version(x);
95 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
96 i = OBJ_obj2nid(x->sig_alg->algorithm);
97 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
98 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
99 p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0);
100 BIO_printf(out,"%8sIssuer: %s\n","",p);
101 OPENSSL_free(p);
102 BIO_printf(out,"%8sLast Update: ","");
103 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
104 BIO_printf(out,"\n%8sNext Update: ","");
105 if (X509_CRL_get_nextUpdate(x))
106 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
107 else BIO_printf(out,"NONE");
108 BIO_printf(out,"\n");
109
110 n=X509_CRL_get_ext_count(x);
111 X509V3_extensions_print(out, "CRL extensions",
112 x->crl->extensions, 0, 8);
113
114 rev = X509_CRL_get_REVOKED(x);
115
116 if(sk_X509_REVOKED_num(rev) > 0)
117 BIO_printf(out, "Revoked Certificates:\n");
118 else BIO_printf(out, "No Revoked Certificates.\n");
119
120 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
121 r = sk_X509_REVOKED_value(rev, i);
122 BIO_printf(out," Serial Number: ");
123 i2a_ASN1_INTEGER(out,r->serialNumber);
124 BIO_printf(out,"\n Revocation Date: ","");
125 ASN1_TIME_print(out,r->revocationDate);
126 BIO_printf(out,"\n");
127 X509V3_extensions_print(out, "CRL entry extensions",
128 r->extensions, 0, 8);
129 }
130 X509_signature_print(out, x->sig_alg, x->signature);
131
132 return 1;
133
134}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
new file mode 100644
index 0000000000..d15006e654
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_pkey.c
@@ -0,0 +1,387 @@
1/* crypto/asn1/t_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#ifndef OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DH
67#include <openssl/dh.h>
68#endif
69#ifndef OPENSSL_NO_DSA
70#include <openssl/dsa.h>
71#endif
72
73static int print(BIO *fp,const char *str,BIGNUM *num,
74 unsigned char *buf,int off);
75#ifndef OPENSSL_NO_RSA
76#ifndef OPENSSL_NO_FP_API
77int RSA_print_fp(FILE *fp, const RSA *x, int off)
78 {
79 BIO *b;
80 int ret;
81
82 if ((b=BIO_new(BIO_s_file())) == NULL)
83 {
84 RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
85 return(0);
86 }
87 BIO_set_fp(b,fp,BIO_NOCLOSE);
88 ret=RSA_print(b,x,off);
89 BIO_free(b);
90 return(ret);
91 }
92#endif
93
94int RSA_print(BIO *bp, const RSA *x, int off)
95 {
96 char str[128];
97 const char *s;
98 unsigned char *m=NULL;
99 int ret=0;
100 size_t buf_len=0, i;
101
102 if (x->n)
103 buf_len = (size_t)BN_num_bytes(x->n);
104 if (x->e)
105 if (buf_len < (i = (size_t)BN_num_bytes(x->e)))
106 buf_len = i;
107 if (x->d)
108 if (buf_len < (i = (size_t)BN_num_bytes(x->d)))
109 buf_len = i;
110 if (x->p)
111 if (buf_len < (i = (size_t)BN_num_bytes(x->p)))
112 buf_len = i;
113 if (x->q)
114 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
115 buf_len = i;
116 if (x->dmp1)
117 if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1)))
118 buf_len = i;
119 if (x->dmq1)
120 if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1)))
121 buf_len = i;
122 if (x->iqmp)
123 if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp)))
124 buf_len = i;
125
126 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
127 if (m == NULL)
128 {
129 RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
130 goto err;
131 }
132
133 if (x->d != NULL)
134 {
135 if(!BIO_indent(bp,off,128))
136 goto err;
137 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
138 <= 0) goto err;
139 }
140
141 if (x->d == NULL)
142 BIO_snprintf(str,sizeof str,"Modulus (%d bit):",BN_num_bits(x->n));
143 else
144 BUF_strlcpy(str,"modulus:",sizeof str);
145 if (!print(bp,str,x->n,m,off)) goto err;
146 s=(x->d == NULL)?"Exponent:":"publicExponent:";
147 if (!print(bp,s,x->e,m,off)) goto err;
148 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
149 if (!print(bp,"prime1:",x->p,m,off)) goto err;
150 if (!print(bp,"prime2:",x->q,m,off)) goto err;
151 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
152 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
153 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
154 ret=1;
155err:
156 if (m != NULL) OPENSSL_free(m);
157 return(ret);
158 }
159#endif /* OPENSSL_NO_RSA */
160
161#ifndef OPENSSL_NO_DSA
162#ifndef OPENSSL_NO_FP_API
163int DSA_print_fp(FILE *fp, const DSA *x, int off)
164 {
165 BIO *b;
166 int ret;
167
168 if ((b=BIO_new(BIO_s_file())) == NULL)
169 {
170 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
171 return(0);
172 }
173 BIO_set_fp(b,fp,BIO_NOCLOSE);
174 ret=DSA_print(b,x,off);
175 BIO_free(b);
176 return(ret);
177 }
178#endif
179
180int DSA_print(BIO *bp, const DSA *x, int off)
181 {
182 unsigned char *m=NULL;
183 int ret=0;
184 size_t buf_len=0,i;
185
186 if (x->p)
187 buf_len = (size_t)BN_num_bytes(x->p);
188 if (x->q)
189 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
190 buf_len = i;
191 if (x->g)
192 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
193 buf_len = i;
194 if (x->priv_key)
195 if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key)))
196 buf_len = i;
197 if (x->pub_key)
198 if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key)))
199 buf_len = i;
200
201 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
202 if (m == NULL)
203 {
204 DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
205 goto err;
206 }
207
208 if (x->priv_key != NULL)
209 {
210 if(!BIO_indent(bp,off,128))
211 goto err;
212 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
213 <= 0) goto err;
214 }
215
216 if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
217 goto err;
218 if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
219 goto err;
220 if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err;
221 if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err;
222 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
223 ret=1;
224err:
225 if (m != NULL) OPENSSL_free(m);
226 return(ret);
227 }
228#endif /* !OPENSSL_NO_DSA */
229
230static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
231 int off)
232 {
233 int n,i;
234 const char *neg;
235
236 if (num == NULL) return(1);
237 neg=(num->neg)?"-":"";
238 if(!BIO_indent(bp,off,128))
239 return 0;
240
241 if (BN_num_bytes(num) <= BN_BYTES)
242 {
243 if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
244 (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
245 <= 0) return(0);
246 }
247 else
248 {
249 buf[0]=0;
250 if (BIO_printf(bp,"%s%s",number,
251 (neg[0] == '-')?" (Negative)":"") <= 0)
252 return(0);
253 n=BN_bn2bin(num,&buf[1]);
254
255 if (buf[1] & 0x80)
256 n++;
257 else buf++;
258
259 for (i=0; i<n; i++)
260 {
261 if ((i%15) == 0)
262 {
263 if(BIO_puts(bp,"\n") <= 0
264 || !BIO_indent(bp,off+4,128))
265 return 0;
266 }
267 if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
268 <= 0) return(0);
269 }
270 if (BIO_write(bp,"\n",1) <= 0) return(0);
271 }
272 return(1);
273 }
274
275#ifndef OPENSSL_NO_DH
276#ifndef OPENSSL_NO_FP_API
277int DHparams_print_fp(FILE *fp, const DH *x)
278 {
279 BIO *b;
280 int ret;
281
282 if ((b=BIO_new(BIO_s_file())) == NULL)
283 {
284 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
285 return(0);
286 }
287 BIO_set_fp(b,fp,BIO_NOCLOSE);
288 ret=DHparams_print(b, x);
289 BIO_free(b);
290 return(ret);
291 }
292#endif
293
294int DHparams_print(BIO *bp, const DH *x)
295 {
296 unsigned char *m=NULL;
297 int reason=ERR_R_BUF_LIB,ret=0;
298 size_t buf_len=0, i;
299
300 if (x->p)
301 buf_len = (size_t)BN_num_bytes(x->p);
302 if (x->g)
303 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
304 buf_len = i;
305 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
306 if (m == NULL)
307 {
308 reason=ERR_R_MALLOC_FAILURE;
309 goto err;
310 }
311
312 if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
313 BN_num_bits(x->p)) <= 0)
314 goto err;
315 if (!print(bp,"prime:",x->p,m,4)) goto err;
316 if (!print(bp,"generator:",x->g,m,4)) goto err;
317 if (x->length != 0)
318 {
319 if (BIO_printf(bp," recommended-private-length: %d bits\n",
320 (int)x->length) <= 0) goto err;
321 }
322 ret=1;
323 if (0)
324 {
325err:
326 DHerr(DH_F_DHPARAMS_PRINT,reason);
327 }
328 if (m != NULL) OPENSSL_free(m);
329 return(ret);
330 }
331#endif
332
333#ifndef OPENSSL_NO_DSA
334#ifndef OPENSSL_NO_FP_API
335int DSAparams_print_fp(FILE *fp, const DSA *x)
336 {
337 BIO *b;
338 int ret;
339
340 if ((b=BIO_new(BIO_s_file())) == NULL)
341 {
342 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
343 return(0);
344 }
345 BIO_set_fp(b,fp,BIO_NOCLOSE);
346 ret=DSAparams_print(b, x);
347 BIO_free(b);
348 return(ret);
349 }
350#endif
351
352int DSAparams_print(BIO *bp, const DSA *x)
353 {
354 unsigned char *m=NULL;
355 int reason=ERR_R_BUF_LIB,ret=0;
356 size_t buf_len=0,i;
357
358 if (x->p)
359 buf_len = (size_t)BN_num_bytes(x->p);
360 if (x->q)
361 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
362 buf_len = i;
363 if (x->g)
364 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
365 buf_len = i;
366 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
367 if (m == NULL)
368 {
369 reason=ERR_R_MALLOC_FAILURE;
370 goto err;
371 }
372
373 if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
374 BN_num_bits(x->p)) <= 0)
375 goto err;
376 if (!print(bp,"p:",x->p,m,4)) goto err;
377 if (!print(bp,"q:",x->q,m,4)) goto err;
378 if (!print(bp,"g:",x->g,m,4)) goto err;
379 ret=1;
380err:
381 if (m != NULL) OPENSSL_free(m);
382 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
383 return(ret);
384 }
385
386#endif /* !OPENSSL_NO_DSA */
387
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
new file mode 100644
index 0000000000..740cee80c0
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -0,0 +1,276 @@
1/* crypto/asn1/t_req.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67#ifndef OPENSSL_NO_FP_API
68int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=X509_REQ_print(b, x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag)
86 {
87 unsigned long l;
88 int i;
89 const char *neg;
90 X509_REQ_INFO *ri;
91 EVP_PKEY *pkey;
92 STACK_OF(X509_ATTRIBUTE) *sk;
93 STACK_OF(X509_EXTENSION) *exts;
94 char mlch = ' ';
95 int nmindent = 0;
96
97 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
98 mlch = '\n';
99 nmindent = 12;
100 }
101
102 if(nmflags == X509_FLAG_COMPAT)
103 nmindent = 16;
104
105
106 ri=x->req_info;
107 if(!(cflag & X509_FLAG_NO_HEADER))
108 {
109 if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
110 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
111 }
112 if(!(cflag & X509_FLAG_NO_VERSION))
113 {
114 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
115 l=0;
116 for (i=0; i<ri->version->length; i++)
117 { l<<=8; l+=ri->version->data[i]; }
118 if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,
119 l) <= 0)
120 goto err;
121 }
122 if(!(cflag & X509_FLAG_NO_SUBJECT))
123 {
124 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
125 if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
126 if (BIO_write(bp,"\n",1) <= 0) goto err;
127 }
128 if(!(cflag & X509_FLAG_NO_PUBKEY))
129 {
130 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
131 goto err;
132 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
133 goto err;
134 if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
135 goto err;
136 if (BIO_puts(bp, "\n") <= 0)
137 goto err;
138
139 pkey=X509_REQ_get_pubkey(x);
140 if (pkey == NULL)
141 {
142 BIO_printf(bp,"%12sUnable to load Public Key\n","");
143 ERR_print_errors(bp);
144 }
145 else
146#ifndef OPENSSL_NO_RSA
147 if (pkey->type == EVP_PKEY_RSA)
148 {
149 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
150 BN_num_bits(pkey->pkey.rsa->n));
151 RSA_print(bp,pkey->pkey.rsa,16);
152 }
153 else
154#endif
155#ifndef OPENSSL_NO_DSA
156 if (pkey->type == EVP_PKEY_DSA)
157 {
158 BIO_printf(bp,"%12sDSA Public Key:\n","");
159 DSA_print(bp,pkey->pkey.dsa,16);
160 }
161 else
162#endif
163 BIO_printf(bp,"%12sUnknown Public Key:\n","");
164
165 EVP_PKEY_free(pkey);
166 }
167
168 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
169 {
170 /* may not be */
171 if(BIO_printf(bp,"%8sAttributes:\n","") <= 0)
172 goto err;
173
174 sk=x->req_info->attributes;
175 if (sk_X509_ATTRIBUTE_num(sk) == 0)
176 {
177 if(BIO_printf(bp,"%12sa0:00\n","") <= 0)
178 goto err;
179 }
180 else
181 {
182 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
183 {
184 ASN1_TYPE *at;
185 X509_ATTRIBUTE *a;
186 ASN1_BIT_STRING *bs=NULL;
187 ASN1_TYPE *t;
188 int j,type=0,count=1,ii=0;
189
190 a=sk_X509_ATTRIBUTE_value(sk,i);
191 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
192 continue;
193 if(BIO_printf(bp,"%12s","") <= 0)
194 goto err;
195 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
196 {
197 if (a->single)
198 {
199 t=a->value.single;
200 type=t->type;
201 bs=t->value.bit_string;
202 }
203 else
204 {
205 ii=0;
206 count=sk_ASN1_TYPE_num(a->value.set);
207get_next:
208 at=sk_ASN1_TYPE_value(a->value.set,ii);
209 type=at->type;
210 bs=at->value.asn1_string;
211 }
212 }
213 for (j=25-j; j>0; j--)
214 if (BIO_write(bp," ",1) != 1) goto err;
215 if (BIO_puts(bp,":") <= 0) goto err;
216 if ( (type == V_ASN1_PRINTABLESTRING) ||
217 (type == V_ASN1_T61STRING) ||
218 (type == V_ASN1_IA5STRING))
219 {
220 if (BIO_write(bp,(char *)bs->data,bs->length)
221 != bs->length)
222 goto err;
223 BIO_puts(bp,"\n");
224 }
225 else
226 {
227 BIO_puts(bp,"unable to print attribute\n");
228 }
229 if (++ii < count) goto get_next;
230 }
231 }
232 }
233 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
234 {
235 exts = X509_REQ_get_extensions(x);
236 if(exts)
237 {
238 BIO_printf(bp,"%8sRequested Extensions:\n","");
239 for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
240 {
241 ASN1_OBJECT *obj;
242 X509_EXTENSION *ex;
243 int j;
244 ex=sk_X509_EXTENSION_value(exts, i);
245 if (BIO_printf(bp,"%12s","") <= 0) goto err;
246 obj=X509_EXTENSION_get_object(ex);
247 i2a_ASN1_OBJECT(bp,obj);
248 j=X509_EXTENSION_get_critical(ex);
249 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
250 goto err;
251 if(!X509V3_EXT_print(bp, ex, 0, 16))
252 {
253 BIO_printf(bp, "%16s", "");
254 M_ASN1_OCTET_STRING_print(bp,ex->value);
255 }
256 if (BIO_write(bp,"\n",1) <= 0) goto err;
257 }
258 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
259 }
260 }
261
262 if(!(cflag & X509_FLAG_NO_SIGDUMP))
263 {
264 if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
265 }
266
267 return(1);
268err:
269 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
270 return(0);
271 }
272
273int X509_REQ_print(BIO *bp, X509_REQ *x)
274 {
275 return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
276 }
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
new file mode 100644
index 0000000000..5abfbc815e
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_spki.c
@@ -0,0 +1,116 @@
1/* t_spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1.h>
63
64/* Print out an SPKI */
65
66int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
67{
68 EVP_PKEY *pkey;
69 ASN1_IA5STRING *chal;
70 int i, n;
71 char *s;
72 BIO_printf(out, "Netscape SPKI:\n");
73 i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
74 BIO_printf(out," Public Key Algorithm: %s\n",
75 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
76 pkey = X509_PUBKEY_get(spki->spkac->pubkey);
77 if(!pkey) BIO_printf(out, " Unable to load public key\n");
78 else {
79#ifndef OPENSSL_NO_RSA
80 if (pkey->type == EVP_PKEY_RSA)
81 {
82 BIO_printf(out," RSA Public Key: (%d bit)\n",
83 BN_num_bits(pkey->pkey.rsa->n));
84 RSA_print(out,pkey->pkey.rsa,2);
85 }
86 else
87#endif
88#ifndef OPENSSL_NO_DSA
89 if (pkey->type == EVP_PKEY_DSA)
90 {
91 BIO_printf(out," DSA Public Key:\n");
92 DSA_print(out,pkey->pkey.dsa,2);
93 }
94 else
95#endif
96 BIO_printf(out," Unknown Public Key:\n");
97 EVP_PKEY_free(pkey);
98 }
99 chal = spki->spkac->challenge;
100 if(chal->length)
101 BIO_printf(out, " Challenge String: %s\n", chal->data);
102 i=OBJ_obj2nid(spki->sig_algor->algorithm);
103 BIO_printf(out," Signature Algorithm: %s",
104 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
105
106 n=spki->signature->length;
107 s=(char *)spki->signature->data;
108 for (i=0; i<n; i++)
109 {
110 if ((i%18) == 0) BIO_write(out,"\n ",7);
111 BIO_printf(out,"%02x%s",(unsigned char)s[i],
112 ((i+1) == n)?"":":");
113 }
114 BIO_write(out,"\n",1);
115 return 1;
116}
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
new file mode 100644
index 0000000000..30f68561b7
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -0,0 +1,505 @@
1/* crypto/asn1/t_x509.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#ifndef OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DSA
67#include <openssl/dsa.h>
68#endif
69#include <openssl/objects.h>
70#include <openssl/x509.h>
71#include <openssl/x509v3.h>
72
73#ifndef OPENSSL_NO_FP_API
74int X509_print_fp(FILE *fp, X509 *x)
75 {
76 return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
77 }
78
79int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag)
80 {
81 BIO *b;
82 int ret;
83
84 if ((b=BIO_new(BIO_s_file())) == NULL)
85 {
86 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
87 return(0);
88 }
89 BIO_set_fp(b,fp,BIO_NOCLOSE);
90 ret=X509_print_ex(b, x, nmflag, cflag);
91 BIO_free(b);
92 return(ret);
93 }
94#endif
95
96int X509_print(BIO *bp, X509 *x)
97{
98 return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
99}
100
101int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
102 {
103 long l;
104 int ret=0,i;
105 char *m=NULL,mlch = ' ';
106 int nmindent = 0;
107 X509_CINF *ci;
108 ASN1_INTEGER *bs;
109 EVP_PKEY *pkey=NULL;
110 const char *neg;
111 ASN1_STRING *str=NULL;
112
113 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
114 mlch = '\n';
115 nmindent = 12;
116 }
117
118 if(nmflags == X509_FLAG_COMPAT)
119 nmindent = 16;
120
121 ci=x->cert_info;
122 if(!(cflag & X509_FLAG_NO_HEADER))
123 {
124 if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
125 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
126 }
127 if(!(cflag & X509_FLAG_NO_VERSION))
128 {
129 l=X509_get_version(x);
130 if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
131 }
132 if(!(cflag & X509_FLAG_NO_SERIAL))
133 {
134
135 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
136
137 bs=X509_get_serialNumber(x);
138 if (bs->length <= 4)
139 {
140 l=ASN1_INTEGER_get(bs);
141 if (l < 0)
142 {
143 l= -l;
144 neg="-";
145 }
146 else
147 neg="";
148 if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
149 goto err;
150 }
151 else
152 {
153 neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
154 if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
155
156 for (i=0; i<bs->length; i++)
157 {
158 if (BIO_printf(bp,"%02x%c",bs->data[i],
159 ((i+1 == bs->length)?'\n':':')) <= 0)
160 goto err;
161 }
162 }
163
164 }
165
166 if(!(cflag & X509_FLAG_NO_SIGNAME))
167 {
168 if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0)
169 goto err;
170 if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0)
171 goto err;
172 if (BIO_puts(bp, "\n") <= 0)
173 goto err;
174 }
175
176 if(!(cflag & X509_FLAG_NO_ISSUER))
177 {
178 if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err;
179 if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err;
180 if (BIO_write(bp,"\n",1) <= 0) goto err;
181 }
182 if(!(cflag & X509_FLAG_NO_VALIDITY))
183 {
184 if (BIO_write(bp," Validity\n",17) <= 0) goto err;
185 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
186 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
187 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
188 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
189 if (BIO_write(bp,"\n",1) <= 0) goto err;
190 }
191 if(!(cflag & X509_FLAG_NO_SUBJECT))
192 {
193 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
194 if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err;
195 if (BIO_write(bp,"\n",1) <= 0) goto err;
196 }
197 if(!(cflag & X509_FLAG_NO_PUBKEY))
198 {
199 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
200 goto err;
201 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
202 goto err;
203 if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0)
204 goto err;
205 if (BIO_puts(bp, "\n") <= 0)
206 goto err;
207
208 pkey=X509_get_pubkey(x);
209 if (pkey == NULL)
210 {
211 BIO_printf(bp,"%12sUnable to load Public Key\n","");
212 ERR_print_errors(bp);
213 }
214 else
215#ifndef OPENSSL_NO_RSA
216 if (pkey->type == EVP_PKEY_RSA)
217 {
218 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
219 BN_num_bits(pkey->pkey.rsa->n));
220 RSA_print(bp,pkey->pkey.rsa,16);
221 }
222 else
223#endif
224#ifndef OPENSSL_NO_DSA
225 if (pkey->type == EVP_PKEY_DSA)
226 {
227 BIO_printf(bp,"%12sDSA Public Key:\n","");
228 DSA_print(bp,pkey->pkey.dsa,16);
229 }
230 else
231#endif
232 BIO_printf(bp,"%12sUnknown Public Key:\n","");
233
234 EVP_PKEY_free(pkey);
235 }
236
237 if (!(cflag & X509_FLAG_NO_EXTENSIONS))
238 X509V3_extensions_print(bp, "X509v3 extensions",
239 ci->extensions, cflag, 8);
240
241 if(!(cflag & X509_FLAG_NO_SIGDUMP))
242 {
243 if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err;
244 }
245 if(!(cflag & X509_FLAG_NO_AUX))
246 {
247 if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
248 }
249 ret=1;
250err:
251 if (str != NULL) ASN1_STRING_free(str);
252 if (m != NULL) OPENSSL_free(m);
253 return(ret);
254 }
255
256int X509_ocspid_print (BIO *bp, X509 *x)
257 {
258 unsigned char *der=NULL ;
259 unsigned char *dertmp;
260 int derlen;
261 int i;
262 unsigned char SHA1md[SHA_DIGEST_LENGTH];
263
264 /* display the hash of the subject as it would appear
265 in OCSP requests */
266 if (BIO_printf(bp," Subject OCSP hash: ") <= 0)
267 goto err;
268 derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
269 if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL)
270 goto err;
271 i2d_X509_NAME(x->cert_info->subject, &dertmp);
272
273 EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL);
274 for (i=0; i < SHA_DIGEST_LENGTH; i++)
275 {
276 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
277 }
278 OPENSSL_free (der);
279 der=NULL;
280
281 /* display the hash of the public key as it would appear
282 in OCSP requests */
283 if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0)
284 goto err;
285
286 EVP_Digest(x->cert_info->key->public_key->data,
287 x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL);
288 for (i=0; i < SHA_DIGEST_LENGTH; i++)
289 {
290 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
291 goto err;
292 }
293 BIO_printf(bp,"\n");
294
295 return (1);
296err:
297 if (der != NULL) OPENSSL_free(der);
298 return(0);
299 }
300
301int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
302{
303 unsigned char *s;
304 int i, n;
305 if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0;
306 if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
307
308 n=sig->length;
309 s=sig->data;
310 for (i=0; i<n; i++)
311 {
312 if ((i%18) == 0)
313 if (BIO_write(bp,"\n ",9) <= 0) return 0;
314 if (BIO_printf(bp,"%02x%s",s[i],
315 ((i+1) == n)?"":":") <= 0) return 0;
316 }
317 if (BIO_write(bp,"\n",1) != 1) return 0;
318 return 1;
319}
320
321int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
322 {
323 int i,n;
324 char buf[80],*p;
325
326 if (v == NULL) return(0);
327 n=0;
328 p=(char *)v->data;
329 for (i=0; i<v->length; i++)
330 {
331 if ((p[i] > '~') || ((p[i] < ' ') &&
332 (p[i] != '\n') && (p[i] != '\r')))
333 buf[n]='.';
334 else
335 buf[n]=p[i];
336 n++;
337 if (n >= 80)
338 {
339 if (BIO_write(bp,buf,n) <= 0)
340 return(0);
341 n=0;
342 }
343 }
344 if (n > 0)
345 if (BIO_write(bp,buf,n) <= 0)
346 return(0);
347 return(1);
348 }
349
350int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
351{
352 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
353 if(tm->type == V_ASN1_GENERALIZEDTIME)
354 return ASN1_GENERALIZEDTIME_print(bp, tm);
355 BIO_write(bp,"Bad time value",14);
356 return(0);
357}
358
359static const char *mon[12]=
360 {
361 "Jan","Feb","Mar","Apr","May","Jun",
362 "Jul","Aug","Sep","Oct","Nov","Dec"
363 };
364
365int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
366 {
367 char *v;
368 int gmt=0;
369 int i;
370 int y=0,M=0,d=0,h=0,m=0,s=0;
371
372 i=tm->length;
373 v=(char *)tm->data;
374
375 if (i < 12) goto err;
376 if (v[i-1] == 'Z') gmt=1;
377 for (i=0; i<12; i++)
378 if ((v[i] > '9') || (v[i] < '0')) goto err;
379 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
380 M= (v[4]-'0')*10+(v[5]-'0');
381 if ((M > 12) || (M < 1)) goto err;
382 d= (v[6]-'0')*10+(v[7]-'0');
383 h= (v[8]-'0')*10+(v[9]-'0');
384 m= (v[10]-'0')*10+(v[11]-'0');
385 if ( (v[12] >= '0') && (v[12] <= '9') &&
386 (v[13] >= '0') && (v[13] <= '9'))
387 s= (v[12]-'0')*10+(v[13]-'0');
388
389 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
390 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
391 return(0);
392 else
393 return(1);
394err:
395 BIO_write(bp,"Bad time value",14);
396 return(0);
397 }
398
399int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
400 {
401 char *v;
402 int gmt=0;
403 int i;
404 int y=0,M=0,d=0,h=0,m=0,s=0;
405
406 i=tm->length;
407 v=(char *)tm->data;
408
409 if (i < 10) goto err;
410 if (v[i-1] == 'Z') gmt=1;
411 for (i=0; i<10; i++)
412 if ((v[i] > '9') || (v[i] < '0')) goto err;
413 y= (v[0]-'0')*10+(v[1]-'0');
414 if (y < 50) y+=100;
415 M= (v[2]-'0')*10+(v[3]-'0');
416 if ((M > 12) || (M < 1)) goto err;
417 d= (v[4]-'0')*10+(v[5]-'0');
418 h= (v[6]-'0')*10+(v[7]-'0');
419 m= (v[8]-'0')*10+(v[9]-'0');
420 if ( (v[10] >= '0') && (v[10] <= '9') &&
421 (v[11] >= '0') && (v[11] <= '9'))
422 s= (v[10]-'0')*10+(v[11]-'0');
423
424 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
425 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
426 return(0);
427 else
428 return(1);
429err:
430 BIO_write(bp,"Bad time value",14);
431 return(0);
432 }
433
434int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
435 {
436 char *s,*c,*b;
437 int ret=0,l,ll,i,first=1;
438
439 ll=80-2-obase;
440
441 b=s=X509_NAME_oneline(name,NULL,0);
442 if (!*s)
443 {
444 OPENSSL_free(b);
445 return 1;
446 }
447 s++; /* skip the first slash */
448
449 l=ll;
450 c=s;
451 for (;;)
452 {
453#ifndef CHARSET_EBCDIC
454 if ( ((*s == '/') &&
455 ((s[1] >= 'A') && (s[1] <= 'Z') && (
456 (s[2] == '=') ||
457 ((s[2] >= 'A') && (s[2] <= 'Z') &&
458 (s[3] == '='))
459 ))) ||
460 (*s == '\0'))
461#else
462 if ( ((*s == '/') &&
463 (isupper(s[1]) && (
464 (s[2] == '=') ||
465 (isupper(s[2]) &&
466 (s[3] == '='))
467 ))) ||
468 (*s == '\0'))
469#endif
470 {
471 if ((l <= 0) && !first)
472 {
473 first=0;
474 if (BIO_write(bp,"\n",1) != 1) goto err;
475 for (i=0; i<obase; i++)
476 {
477 if (BIO_write(bp," ",1) != 1) goto err;
478 }
479 l=ll;
480 }
481 i=s-c;
482 if (BIO_write(bp,c,i) != i) goto err;
483 c+=i;
484 c++;
485 if (*s != '\0')
486 {
487 if (BIO_write(bp,", ",2) != 2) goto err;
488 }
489 l--;
490 }
491 if (*s == '\0') break;
492 s++;
493 l--;
494 }
495
496 ret=1;
497 if (0)
498 {
499err:
500 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
501 }
502 OPENSSL_free(b);
503 return(ret);
504 }
505
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
new file mode 100644
index 0000000000..ffbbfb51f4
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_x509a.c
@@ -0,0 +1,110 @@
1/* t_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX and string set routines
66 */
67
68int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
69{
70 char oidstr[80], first;
71 int i;
72 if(!aux) return 1;
73 if(aux->trust) {
74 first = 1;
75 BIO_printf(out, "%*sTrusted Uses:\n%*s",
76 indent, "", indent + 2, "");
77 for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
78 if(!first) BIO_puts(out, ", ");
79 else first = 0;
80 OBJ_obj2txt(oidstr, sizeof oidstr,
81 sk_ASN1_OBJECT_value(aux->trust, i), 0);
82 BIO_puts(out, oidstr);
83 }
84 BIO_puts(out, "\n");
85 } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
86 if(aux->reject) {
87 first = 1;
88 BIO_printf(out, "%*sRejected Uses:\n%*s",
89 indent, "", indent + 2, "");
90 for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
91 if(!first) BIO_puts(out, ", ");
92 else first = 0;
93 OBJ_obj2txt(oidstr, sizeof oidstr,
94 sk_ASN1_OBJECT_value(aux->reject, i), 0);
95 BIO_puts(out, oidstr);
96 }
97 BIO_puts(out, "\n");
98 } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
99 if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "",
100 aux->alias->data);
101 if(aux->keyid) {
102 BIO_printf(out, "%*sKey Id: ", indent, "");
103 for(i = 0; i < aux->keyid->length; i++)
104 BIO_printf(out, "%s%02X",
105 i ? ":" : "",
106 aux->keyid->data[i]);
107 BIO_write(out,"\n",1);
108 }
109 return 1;
110}
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
new file mode 100644
index 0000000000..2426cb6253
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -0,0 +1,965 @@
1/* tasn_dec.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/buffer.h>
66#include <openssl/err.h>
67
68static int asn1_check_eoc(unsigned char **in, long len);
69static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass);
70static int collect_data(BUF_MEM *buf, unsigned char **p, long plen);
71static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
72 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx);
73static int asn1_template_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
74static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
75static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long len,
76 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
77
78/* Table to convert tags to bit values, used for MSTRING type */
79static unsigned long tag2bit[32]={
800, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
81B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
82B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
83B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
840, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
85B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */
86B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
87B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */
88B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
89 };
90
91unsigned long ASN1_tag2bit(int tag)
92{
93 if((tag < 0) || (tag > 30)) return 0;
94 return tag2bit[tag];
95}
96
97/* Macro to initialize and invalidate the cache */
98
99#define asn1_tlc_clear(c) if(c) (c)->valid = 0
100
101/* Decode an ASN1 item, this currently behaves just
102 * like a standard 'd2i' function. 'in' points to
103 * a buffer to read the data from, in future we will
104 * have more advanced versions that can input data
105 * a piece at a time and this will simply be a special
106 * case.
107 */
108
109ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it)
110{
111 ASN1_TLC c;
112 ASN1_VALUE *ptmpval = NULL;
113 if(!pval) pval = &ptmpval;
114 asn1_tlc_clear(&c);
115 if(ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
116 return *pval;
117 return NULL;
118}
119
120int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt)
121{
122 ASN1_TLC c;
123 asn1_tlc_clear(&c);
124 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
125}
126
127
128/* Decode an item, taking care of IMPLICIT tagging, if any.
129 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
130 */
131
132int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
133 int tag, int aclass, char opt, ASN1_TLC *ctx)
134{
135 const ASN1_TEMPLATE *tt, *errtt = NULL;
136 const ASN1_COMPAT_FUNCS *cf;
137 const ASN1_EXTERN_FUNCS *ef;
138 const ASN1_AUX *aux = it->funcs;
139 ASN1_aux_cb *asn1_cb;
140 unsigned char *p, *q, imphack = 0, oclass;
141 char seq_eoc, seq_nolen, cst, isopt;
142 long tmplen;
143 int i;
144 int otag;
145 int ret = 0;
146 ASN1_VALUE *pchval, **pchptr, *ptmpval;
147 if(!pval) return 0;
148 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
149 else asn1_cb = 0;
150
151 switch(it->itype) {
152
153 case ASN1_ITYPE_PRIMITIVE:
154 if(it->templates) {
155 /* tagging or OPTIONAL is currently illegal on an item template
156 * because the flags can't get passed down. In practice this isn't
157 * a problem: we include the relevant flags from the item template
158 * in the template itself.
159 */
160 if ((tag != -1) || opt) {
161 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
162 goto err;
163 }
164 return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx);
165 }
166 return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx);
167 break;
168
169 case ASN1_ITYPE_MSTRING:
170 p = *in;
171 /* Just read in tag and class */
172 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx);
173 if(!ret) {
174 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
175 goto err;
176 }
177 /* Must be UNIVERSAL class */
178 if(oclass != V_ASN1_UNIVERSAL) {
179 /* If OPTIONAL, assume this is OK */
180 if(opt) return -1;
181 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
182 goto err;
183 }
184 /* Check tag matches bit map */
185 if(!(ASN1_tag2bit(otag) & it->utype)) {
186 /* If OPTIONAL, assume this is OK */
187 if(opt) return -1;
188 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG);
189 goto err;
190 }
191 return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
192
193 case ASN1_ITYPE_EXTERN:
194 /* Use new style d2i */
195 ef = it->funcs;
196 return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
197
198 case ASN1_ITYPE_COMPAT:
199 /* we must resort to old style evil hackery */
200 cf = it->funcs;
201
202 /* If OPTIONAL see if it is there */
203 if(opt) {
204 int exptag;
205 p = *in;
206 if(tag == -1) exptag = it->utype;
207 else exptag = tag;
208 /* Don't care about anything other than presence of expected tag */
209 ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx);
210 if(!ret) {
211 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
212 goto err;
213 }
214 if(ret == -1) return -1;
215 }
216 /* This is the old style evil hack IMPLICIT handling:
217 * since the underlying code is expecting a tag and
218 * class other than the one present we change the
219 * buffer temporarily then change it back afterwards.
220 * This doesn't and never did work for tags > 30.
221 *
222 * Yes this is *horrible* but it is only needed for
223 * old style d2i which will hopefully not be around
224 * for much longer.
225 * FIXME: should copy the buffer then modify it so
226 * the input buffer can be const: we should *always*
227 * copy because the old style d2i might modify the
228 * buffer.
229 */
230
231 if(tag != -1) {
232 p = *in;
233 imphack = *p;
234 *p = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype);
235 }
236
237 ptmpval = cf->asn1_d2i(pval, in, len);
238
239 if(tag != -1) *p = imphack;
240
241 if(ptmpval) return 1;
242 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
243 goto err;
244
245
246 case ASN1_ITYPE_CHOICE:
247 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
248 goto auxerr;
249
250 /* Allocate structure */
251 if(!*pval) {
252 if(!ASN1_item_ex_new(pval, it)) {
253 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
254 goto err;
255 }
256 }
257 /* CHOICE type, try each possibility in turn */
258 pchval = NULL;
259 p = *in;
260 for(i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
261 pchptr = asn1_get_field_ptr(pval, tt);
262 /* We mark field as OPTIONAL so its absence
263 * can be recognised.
264 */
265 ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
266 /* If field not present, try the next one */
267 if(ret == -1) continue;
268 /* If positive return, read OK, break loop */
269 if(ret > 0) break;
270 /* Otherwise must be an ASN1 parsing error */
271 errtt = tt;
272 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
273 goto err;
274 }
275 /* Did we fall off the end without reading anything? */
276 if(i == it->tcount) {
277 /* If OPTIONAL, this is OK */
278 if(opt) {
279 /* Free and zero it */
280 ASN1_item_ex_free(pval, it);
281 return -1;
282 }
283 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);
284 goto err;
285 }
286 asn1_set_choice_selector(pval, i, it);
287 *in = p;
288 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
289 goto auxerr;
290 return 1;
291
292 case ASN1_ITYPE_SEQUENCE:
293 p = *in;
294 tmplen = len;
295
296 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
297 if(tag == -1) {
298 tag = V_ASN1_SEQUENCE;
299 aclass = V_ASN1_UNIVERSAL;
300 }
301 /* Get SEQUENCE length and update len, p */
302 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx);
303 if(!ret) {
304 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
305 goto err;
306 } else if(ret == -1) return -1;
307 if(aux && (aux->flags & ASN1_AFLG_BROKEN)) {
308 len = tmplen - (p - *in);
309 seq_nolen = 1;
310 } else seq_nolen = seq_eoc; /* If indefinite we don't do a length check */
311 if(!cst) {
312 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
313 goto err;
314 }
315
316 if(!*pval) {
317 if(!ASN1_item_ex_new(pval, it)) {
318 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
319 goto err;
320 }
321 }
322 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
323 goto auxerr;
324
325 /* Get each field entry */
326 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
327 const ASN1_TEMPLATE *seqtt;
328 ASN1_VALUE **pseqval;
329 seqtt = asn1_do_adb(pval, tt, 1);
330 if(!seqtt) goto err;
331 pseqval = asn1_get_field_ptr(pval, seqtt);
332 /* Have we ran out of data? */
333 if(!len) break;
334 q = p;
335 if(asn1_check_eoc(&p, len)) {
336 if(!seq_eoc) {
337 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC);
338 goto err;
339 }
340 len -= p - q;
341 seq_eoc = 0;
342 q = p;
343 break;
344 }
345 /* This determines the OPTIONAL flag value. The field cannot
346 * be omitted if it is the last of a SEQUENCE and there is
347 * still data to be read. This isn't strictly necessary but
348 * it increases efficiency in some cases.
349 */
350 if(i == (it->tcount - 1)) isopt = 0;
351 else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
352 /* attempt to read in field, allowing each to be OPTIONAL */
353 ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
354 if(!ret) {
355 errtt = seqtt;
356 goto err;
357 } else if(ret == -1) {
358 /* OPTIONAL component absent. Free and zero the field
359 */
360 ASN1_template_free(pseqval, seqtt);
361 continue;
362 }
363 /* Update length */
364 len -= p - q;
365 }
366 /* Check for EOC if expecting one */
367 if(seq_eoc && !asn1_check_eoc(&p, len)) {
368 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
369 goto err;
370 }
371 /* Check all data read */
372 if(!seq_nolen && len) {
373 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
374 goto err;
375 }
376
377 /* If we get here we've got no more data in the SEQUENCE,
378 * however we may not have read all fields so check all
379 * remaining are OPTIONAL and clear any that are.
380 */
381 for(; i < it->tcount; tt++, i++) {
382 const ASN1_TEMPLATE *seqtt;
383 seqtt = asn1_do_adb(pval, tt, 1);
384 if(!seqtt) goto err;
385 if(seqtt->flags & ASN1_TFLG_OPTIONAL) {
386 ASN1_VALUE **pseqval;
387 pseqval = asn1_get_field_ptr(pval, seqtt);
388 ASN1_template_free(pseqval, seqtt);
389 } else {
390 errtt = seqtt;
391 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING);
392 goto err;
393 }
394 }
395 /* Save encoding */
396 if(!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr;
397 *in = p;
398 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
399 goto auxerr;
400 return 1;
401
402 default:
403 return 0;
404 }
405 auxerr:
406 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
407 err:
408 ASN1_item_ex_free(pval, it);
409 if(errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
410 else ERR_add_error_data(2, "Type=", it->sname);
411 return 0;
412}
413
414/* Templates are handled with two separate functions. One handles any EXPLICIT tag and the other handles the
415 * rest.
416 */
417
418static int asn1_template_ex_d2i(ASN1_VALUE **val, unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
419{
420 int flags, aclass;
421 int ret;
422 long len;
423 unsigned char *p, *q;
424 char exp_eoc;
425 if(!val) return 0;
426 flags = tt->flags;
427 aclass = flags & ASN1_TFLG_TAG_CLASS;
428
429 p = *in;
430
431 /* Check if EXPLICIT tag expected */
432 if(flags & ASN1_TFLG_EXPTAG) {
433 char cst;
434 /* Need to work out amount of data available to the inner content and where it
435 * starts: so read in EXPLICIT header to get the info.
436 */
437 ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx);
438 q = p;
439 if(!ret) {
440 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
441 return 0;
442 } else if(ret == -1) return -1;
443 if(!cst) {
444 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
445 return 0;
446 }
447 /* We've found the field so it can't be OPTIONAL now */
448 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
449 if(!ret) {
450 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
451 return 0;
452 }
453 /* We read the field in OK so update length */
454 len -= p - q;
455 if(exp_eoc) {
456 /* If NDEF we must have an EOC here */
457 if(!asn1_check_eoc(&p, len)) {
458 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
459 goto err;
460 }
461 } else {
462 /* Otherwise we must hit the EXPLICIT tag end or its an error */
463 if(len) {
464 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
465 goto err;
466 }
467 }
468 } else
469 return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
470
471 *in = p;
472 return 1;
473
474 err:
475 ASN1_template_free(val, tt);
476 *val = NULL;
477 return 0;
478}
479
480static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
481{
482 int flags, aclass;
483 int ret;
484 unsigned char *p, *q;
485 if(!val) return 0;
486 flags = tt->flags;
487 aclass = flags & ASN1_TFLG_TAG_CLASS;
488
489 p = *in;
490 q = p;
491
492 if(flags & ASN1_TFLG_SK_MASK) {
493 /* SET OF, SEQUENCE OF */
494 int sktag, skaclass;
495 char sk_eoc;
496 /* First work out expected inner tag value */
497 if(flags & ASN1_TFLG_IMPTAG) {
498 sktag = tt->tag;
499 skaclass = aclass;
500 } else {
501 skaclass = V_ASN1_UNIVERSAL;
502 if(flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET;
503 else sktag = V_ASN1_SEQUENCE;
504 }
505 /* Get the tag */
506 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx);
507 if(!ret) {
508 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
509 return 0;
510 } else if(ret == -1) return -1;
511 if(!*val) *val = (ASN1_VALUE *)sk_new_null();
512 else {
513 /* We've got a valid STACK: free up any items present */
514 STACK *sktmp = (STACK *)*val;
515 ASN1_VALUE *vtmp;
516 while(sk_num(sktmp) > 0) {
517 vtmp = (ASN1_VALUE *)sk_pop(sktmp);
518 ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
519 }
520 }
521
522 if(!*val) {
523 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_MALLOC_FAILURE);
524 goto err;
525 }
526 /* Read as many items as we can */
527 while(len > 0) {
528 ASN1_VALUE *skfield;
529 q = p;
530 /* See if EOC found */
531 if(asn1_check_eoc(&p, len)) {
532 if(!sk_eoc) {
533 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_UNEXPECTED_EOC);
534 goto err;
535 }
536 len -= p - q;
537 sk_eoc = 0;
538 break;
539 }
540 skfield = NULL;
541 if(!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
542 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
543 goto err;
544 }
545 len -= p - q;
546 if(!sk_push((STACK *)*val, (char *)skfield)) {
547 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_MALLOC_FAILURE);
548 goto err;
549 }
550 }
551 if(sk_eoc) {
552 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
553 goto err;
554 }
555 } else if(flags & ASN1_TFLG_IMPTAG) {
556 /* IMPLICIT tagging */
557 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
558 if(!ret) {
559 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
560 goto err;
561 } else if(ret == -1) return -1;
562 } else {
563 /* Nothing special */
564 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx);
565 if(!ret) {
566 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
567 goto err;
568 } else if(ret == -1) return -1;
569 }
570
571 *in = p;
572 return 1;
573
574 err:
575 ASN1_template_free(val, tt);
576 *val = NULL;
577 return 0;
578}
579
580static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inlen,
581 const ASN1_ITEM *it,
582 int tag, int aclass, char opt, ASN1_TLC *ctx)
583{
584 int ret = 0, utype;
585 long plen;
586 char cst, inf, free_cont = 0;
587 unsigned char *p;
588 BUF_MEM buf;
589 unsigned char *cont = NULL;
590 long len;
591 if(!pval) {
592 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
593 return 0; /* Should never happen */
594 }
595
596 if(it->itype == ASN1_ITYPE_MSTRING) {
597 utype = tag;
598 tag = -1;
599 } else utype = it->utype;
600
601 if(utype == V_ASN1_ANY) {
602 /* If type is ANY need to figure out type from tag */
603 unsigned char oclass;
604 if(tag >= 0) {
605 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY);
606 return 0;
607 }
608 if(opt) {
609 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY);
610 return 0;
611 }
612 p = *in;
613 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx);
614 if(!ret) {
615 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
616 return 0;
617 }
618 if(oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER;
619 }
620 if(tag == -1) {
621 tag = utype;
622 aclass = V_ASN1_UNIVERSAL;
623 }
624 p = *in;
625 /* Check header */
626 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx);
627 if(!ret) {
628 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
629 return 0;
630 } else if(ret == -1) return -1;
631 /* SEQUENCE, SET and "OTHER" are left in encoded form */
632 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
633 /* Clear context cache for type OTHER because the auto clear when
634 * we have a exact match wont work
635 */
636 if(utype == V_ASN1_OTHER) {
637 asn1_tlc_clear(ctx);
638 /* SEQUENCE and SET must be constructed */
639 } else if(!cst) {
640 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED);
641 return 0;
642 }
643
644 cont = *in;
645 /* If indefinite length constructed find the real end */
646 if(inf) {
647 if(!asn1_collect(NULL, &p, plen, inf, -1, -1)) goto err;
648 len = p - cont;
649 } else {
650 len = p - cont + plen;
651 p += plen;
652 buf.data = NULL;
653 }
654 } else if(cst) {
655 buf.length = 0;
656 buf.max = 0;
657 buf.data = NULL;
658 /* Should really check the internal tags are correct but
659 * some things may get this wrong. The relevant specs
660 * say that constructed string types should be OCTET STRINGs
661 * internally irrespective of the type. So instead just check
662 * for UNIVERSAL class and ignore the tag.
663 */
664 if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err;
665 len = buf.length;
666 /* Append a final null to string */
667 if(!BUF_MEM_grow_clean(&buf, len + 1)) {
668 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
669 return 0;
670 }
671 buf.data[len] = 0;
672 cont = (unsigned char *)buf.data;
673 free_cont = 1;
674 } else {
675 cont = p;
676 len = plen;
677 p += plen;
678 }
679
680 /* We now have content length and type: translate into a structure */
681 if(!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) goto err;
682
683 *in = p;
684 ret = 1;
685 err:
686 if(free_cont && buf.data) OPENSSL_free(buf.data);
687 return ret;
688}
689
690/* Translate ASN1 content octets into a structure */
691
692int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
693{
694 ASN1_VALUE **opval = NULL;
695 ASN1_STRING *stmp;
696 ASN1_TYPE *typ = NULL;
697 int ret = 0;
698 const ASN1_PRIMITIVE_FUNCS *pf;
699 ASN1_INTEGER **tint;
700 pf = it->funcs;
701 if(pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
702 /* If ANY type clear type and set pointer to internal value */
703 if(it->utype == V_ASN1_ANY) {
704 if(!*pval) {
705 typ = ASN1_TYPE_new();
706 *pval = (ASN1_VALUE *)typ;
707 } else typ = (ASN1_TYPE *)*pval;
708 if(utype != typ->type) ASN1_TYPE_set(typ, utype, NULL);
709 opval = pval;
710 pval = (ASN1_VALUE **)&typ->value.ptr;
711 }
712 switch(utype) {
713 case V_ASN1_OBJECT:
714 if(!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err;
715 break;
716
717 case V_ASN1_NULL:
718 if(len) {
719 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_NULL_IS_WRONG_LENGTH);
720 goto err;
721 }
722 *pval = (ASN1_VALUE *)1;
723 break;
724
725 case V_ASN1_BOOLEAN:
726 if(len != 1) {
727 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
728 goto err;
729 } else {
730 ASN1_BOOLEAN *tbool;
731 tbool = (ASN1_BOOLEAN *)pval;
732 *tbool = *cont;
733 }
734 break;
735
736 case V_ASN1_BIT_STRING:
737 if(!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err;
738 break;
739
740 case V_ASN1_INTEGER:
741 case V_ASN1_NEG_INTEGER:
742 case V_ASN1_ENUMERATED:
743 case V_ASN1_NEG_ENUMERATED:
744 tint = (ASN1_INTEGER **)pval;
745 if(!c2i_ASN1_INTEGER(tint, &cont, len)) goto err;
746 /* Fixup type to match the expected form */
747 (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
748 break;
749
750 case V_ASN1_OCTET_STRING:
751 case V_ASN1_NUMERICSTRING:
752 case V_ASN1_PRINTABLESTRING:
753 case V_ASN1_T61STRING:
754 case V_ASN1_VIDEOTEXSTRING:
755 case V_ASN1_IA5STRING:
756 case V_ASN1_UTCTIME:
757 case V_ASN1_GENERALIZEDTIME:
758 case V_ASN1_GRAPHICSTRING:
759 case V_ASN1_VISIBLESTRING:
760 case V_ASN1_GENERALSTRING:
761 case V_ASN1_UNIVERSALSTRING:
762 case V_ASN1_BMPSTRING:
763 case V_ASN1_UTF8STRING:
764 case V_ASN1_OTHER:
765 case V_ASN1_SET:
766 case V_ASN1_SEQUENCE:
767 default:
768 /* All based on ASN1_STRING and handled the same */
769 if(!*pval) {
770 stmp = ASN1_STRING_type_new(utype);
771 if(!stmp) {
772 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
773 goto err;
774 }
775 *pval = (ASN1_VALUE *)stmp;
776 } else {
777 stmp = (ASN1_STRING *)*pval;
778 stmp->type = utype;
779 }
780 /* If we've already allocated a buffer use it */
781 if(*free_cont) {
782 if(stmp->data) OPENSSL_free(stmp->data);
783 stmp->data = cont;
784 stmp->length = len;
785 *free_cont = 0;
786 } else {
787 if(!ASN1_STRING_set(stmp, cont, len)) {
788 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
789 ASN1_STRING_free(stmp);
790 *pval = NULL;
791 goto err;
792 }
793 }
794 break;
795 }
796 /* If ASN1_ANY and NULL type fix up value */
797 if(typ && utype==V_ASN1_NULL) typ->value.ptr = NULL;
798
799 ret = 1;
800 err:
801 if(!ret)
802 {
803 ASN1_TYPE_free(typ);
804 if (opval)
805 *opval = NULL;
806 }
807 return ret;
808}
809
810/* This function collects the asn1 data from a constructred string
811 * type into a buffer. The values of 'in' and 'len' should refer
812 * to the contents of the constructed type and 'inf' should be set
813 * if it is indefinite length. If 'buf' is NULL then we just want
814 * to find the end of the current structure: useful for indefinite
815 * length constructed stuff.
816 */
817
818static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass)
819{
820 unsigned char *p, *q;
821 long plen;
822 char cst, ininf;
823 p = *in;
824 inf &= 1;
825 /* If no buffer and not indefinite length constructed just pass over the encoded data */
826 if(!buf && !inf) {
827 *in += len;
828 return 1;
829 }
830 while(len > 0) {
831 q = p;
832 /* Check for EOC */
833 if(asn1_check_eoc(&p, len)) {
834 /* EOC is illegal outside indefinite length constructed form */
835 if(!inf) {
836 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC);
837 return 0;
838 }
839 inf = 0;
840 break;
841 }
842 if(!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) {
843 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
844 return 0;
845 }
846 /* If indefinite length constructed update max length */
847 if(cst) {
848 if(!asn1_collect(buf, &p, plen, ininf, tag, aclass)) return 0;
849 } else {
850 if(!collect_data(buf, &p, plen)) return 0;
851 }
852 len -= p - q;
853 }
854 if(inf) {
855 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
856 return 0;
857 }
858 *in = p;
859 return 1;
860}
861
862static int collect_data(BUF_MEM *buf, unsigned char **p, long plen)
863{
864 int len;
865 if(buf) {
866 len = buf->length;
867 if(!BUF_MEM_grow_clean(buf, len + plen)) {
868 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
869 return 0;
870 }
871 memcpy(buf->data + len, *p, plen);
872 }
873 *p += plen;
874 return 1;
875}
876
877/* Check for ASN1 EOC and swallow it if found */
878
879static int asn1_check_eoc(unsigned char **in, long len)
880{
881 unsigned char *p;
882 if(len < 2) return 0;
883 p = *in;
884 if(!p[0] && !p[1]) {
885 *in += 2;
886 return 1;
887 }
888 return 0;
889}
890
891/* Check an ASN1 tag and length: a bit like ASN1_get_object
892 * but it sets the length for indefinite length constructed
893 * form, we don't know the exact length but we can set an
894 * upper bound to the amount of data available minus the
895 * header length just read.
896 */
897
898static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
899 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx)
900{
901 int i;
902 int ptag, pclass;
903 long plen;
904 unsigned char *p, *q;
905 p = *in;
906 q = p;
907
908 if(ctx && ctx->valid) {
909 i = ctx->ret;
910 plen = ctx->plen;
911 pclass = ctx->pclass;
912 ptag = ctx->ptag;
913 p += ctx->hdrlen;
914 } else {
915 i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
916 if(ctx) {
917 ctx->ret = i;
918 ctx->plen = plen;
919 ctx->pclass = pclass;
920 ctx->ptag = ptag;
921 ctx->hdrlen = p - q;
922 ctx->valid = 1;
923 /* If definite length, and no error, length +
924 * header can't exceed total amount of data available.
925 */
926 if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
927 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);
928 asn1_tlc_clear(ctx);
929 return 0;
930 }
931 }
932 }
933
934 if(i & 0x80) {
935 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
936 asn1_tlc_clear(ctx);
937 return 0;
938 }
939 if(exptag >= 0) {
940 if((exptag != ptag) || (expclass != pclass)) {
941 /* If type is OPTIONAL, not an error, but indicate missing
942 * type.
943 */
944 if(opt) return -1;
945 asn1_tlc_clear(ctx);
946 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
947 return 0;
948 }
949 /* We have a tag and class match, so assume we are going to do something with it */
950 asn1_tlc_clear(ctx);
951 }
952
953 if(i & 1) plen = len - (p - q);
954
955 if(inf) *inf = i & 1;
956
957 if(cst) *cst = i & V_ASN1_CONSTRUCTED;
958
959 if(olen) *olen = plen;
960 if(oclass) *oclass = pclass;
961 if(otag) *otag = ptag;
962
963 *in = p;
964 return 1;
965}
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c
new file mode 100644
index 0000000000..f6c8ddef0a
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_enc.c
@@ -0,0 +1,497 @@
1/* tasn_enc.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65
66static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
67static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset);
68
69/* Encode an ASN1 item, this is compatible with the
70 * standard 'i2d' function. 'out' points to
71 * a buffer to output the data to, in future we will
72 * have more advanced versions that can output data
73 * a piece at a time and this will simply be a special
74 * case.
75 *
76 * The new i2d has one additional feature. If the output
77 * buffer is NULL (i.e. *out == NULL) then a buffer is
78 * allocated and populated with the encoding.
79 */
80
81
82int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
83{
84 if(out && !*out) {
85 unsigned char *p, *buf;
86 int len;
87 len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0);
88 if(len <= 0) return len;
89 buf = OPENSSL_malloc(len);
90 if(!buf) return -1;
91 p = buf;
92 ASN1_item_ex_i2d(&val, &p, it, -1, 0);
93 *out = buf;
94 return len;
95 }
96
97 return ASN1_item_ex_i2d(&val, out, it, -1, 0);
98}
99
100/* Encode an item, taking care of IMPLICIT tagging (if any).
101 * This function performs the normal item handling: it can be
102 * used in external types.
103 */
104
105int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
106{
107 const ASN1_TEMPLATE *tt = NULL;
108 unsigned char *p = NULL;
109 int i, seqcontlen, seqlen;
110 ASN1_STRING *strtmp;
111 const ASN1_COMPAT_FUNCS *cf;
112 const ASN1_EXTERN_FUNCS *ef;
113 const ASN1_AUX *aux = it->funcs;
114 ASN1_aux_cb *asn1_cb;
115 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0;
116 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
117 else asn1_cb = 0;
118
119 switch(it->itype) {
120
121 case ASN1_ITYPE_PRIMITIVE:
122 if(it->templates)
123 return ASN1_template_i2d(pval, out, it->templates);
124 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
125 break;
126
127 case ASN1_ITYPE_MSTRING:
128 strtmp = (ASN1_STRING *)*pval;
129 return asn1_i2d_ex_primitive(pval, out, it, -1, 0);
130
131 case ASN1_ITYPE_CHOICE:
132 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
133 return 0;
134 i = asn1_get_choice_selector(pval, it);
135 if((i >= 0) && (i < it->tcount)) {
136 ASN1_VALUE **pchval;
137 const ASN1_TEMPLATE *chtt;
138 chtt = it->templates + i;
139 pchval = asn1_get_field_ptr(pval, chtt);
140 return ASN1_template_i2d(pchval, out, chtt);
141 }
142 /* Fixme: error condition if selector out of range */
143 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
144 return 0;
145 break;
146
147 case ASN1_ITYPE_EXTERN:
148 /* If new style i2d it does all the work */
149 ef = it->funcs;
150 return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
151
152 case ASN1_ITYPE_COMPAT:
153 /* old style hackery... */
154 cf = it->funcs;
155 if(out) p = *out;
156 i = cf->asn1_i2d(*pval, out);
157 /* Fixup for IMPLICIT tag: note this messes up for tags > 30,
158 * but so did the old code. Tags > 30 are very rare anyway.
159 */
160 if(out && (tag != -1))
161 *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
162 return i;
163
164 case ASN1_ITYPE_SEQUENCE:
165 i = asn1_enc_restore(&seqcontlen, out, pval, it);
166 /* An error occurred */
167 if(i < 0) return 0;
168 /* We have a valid cached encoding... */
169 if(i > 0) return seqcontlen;
170 /* Otherwise carry on */
171 seqcontlen = 0;
172 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
173 if(tag == -1) {
174 tag = V_ASN1_SEQUENCE;
175 aclass = V_ASN1_UNIVERSAL;
176 }
177 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
178 return 0;
179 /* First work out sequence content length */
180 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
181 const ASN1_TEMPLATE *seqtt;
182 ASN1_VALUE **pseqval;
183 seqtt = asn1_do_adb(pval, tt, 1);
184 if(!seqtt) return 0;
185 pseqval = asn1_get_field_ptr(pval, seqtt);
186 /* FIXME: check for errors in enhanced version */
187 /* FIXME: special handling of indefinite length encoding */
188 seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt);
189 }
190 seqlen = ASN1_object_size(1, seqcontlen, tag);
191 if(!out) return seqlen;
192 /* Output SEQUENCE header */
193 ASN1_put_object(out, 1, seqcontlen, tag, aclass);
194 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
195 const ASN1_TEMPLATE *seqtt;
196 ASN1_VALUE **pseqval;
197 seqtt = asn1_do_adb(pval, tt, 1);
198 if(!seqtt) return 0;
199 pseqval = asn1_get_field_ptr(pval, seqtt);
200 /* FIXME: check for errors in enhanced version */
201 ASN1_template_i2d(pseqval, out, seqtt);
202 }
203 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
204 return 0;
205 return seqlen;
206
207 default:
208 return 0;
209 }
210 return 0;
211}
212
213int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt)
214{
215 int i, ret, flags, aclass;
216 flags = tt->flags;
217 aclass = flags & ASN1_TFLG_TAG_CLASS;
218 if(flags & ASN1_TFLG_SK_MASK) {
219 /* SET OF, SEQUENCE OF */
220 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
221 int isset, sktag, skaclass;
222 int skcontlen, sklen;
223 ASN1_VALUE *skitem;
224 if(!*pval) return 0;
225 if(flags & ASN1_TFLG_SET_OF) {
226 isset = 1;
227 /* 2 means we reorder */
228 if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2;
229 } else isset = 0;
230 /* First work out inner tag value */
231 if(flags & ASN1_TFLG_IMPTAG) {
232 sktag = tt->tag;
233 skaclass = aclass;
234 } else {
235 skaclass = V_ASN1_UNIVERSAL;
236 if(isset) sktag = V_ASN1_SET;
237 else sktag = V_ASN1_SEQUENCE;
238 }
239 /* Now work out length of items */
240 skcontlen = 0;
241 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
242 skitem = sk_ASN1_VALUE_value(sk, i);
243 skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
244 }
245 sklen = ASN1_object_size(1, skcontlen, sktag);
246 /* If EXPLICIT need length of surrounding tag */
247 if(flags & ASN1_TFLG_EXPTAG)
248 ret = ASN1_object_size(1, sklen, tt->tag);
249 else ret = sklen;
250
251 if(!out) return ret;
252
253 /* Now encode this lot... */
254 /* EXPLICIT tag */
255 if(flags & ASN1_TFLG_EXPTAG)
256 ASN1_put_object(out, 1, sklen, tt->tag, aclass);
257 /* SET or SEQUENCE and IMPLICIT tag */
258 ASN1_put_object(out, 1, skcontlen, sktag, skaclass);
259 /* And finally the stuff itself */
260 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset);
261
262 return ret;
263 }
264
265 if(flags & ASN1_TFLG_EXPTAG) {
266 /* EXPLICIT tagging */
267 /* Find length of tagged item */
268 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
269 if(!i) return 0;
270 /* Find length of EXPLICIT tag */
271 ret = ASN1_object_size(1, i, tt->tag);
272 if(out) {
273 /* Output tag and item */
274 ASN1_put_object(out, 1, i, tt->tag, aclass);
275 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
276 }
277 return ret;
278 }
279 if(flags & ASN1_TFLG_IMPTAG) {
280 /* IMPLICIT tagging */
281 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass);
282 }
283 /* Nothing special: treat as normal */
284 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
285}
286
287/* Temporary structure used to hold DER encoding of items for SET OF */
288
289typedef struct {
290 unsigned char *data;
291 int length;
292 ASN1_VALUE *field;
293} DER_ENC;
294
295static int der_cmp(const void *a, const void *b)
296{
297 const DER_ENC *d1 = a, *d2 = b;
298 int cmplen, i;
299 cmplen = (d1->length < d2->length) ? d1->length : d2->length;
300 i = memcmp(d1->data, d2->data, cmplen);
301 if(i) return i;
302 return d1->length - d2->length;
303}
304
305/* Output the content octets of SET OF or SEQUENCE OF */
306
307static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort)
308{
309 int i;
310 ASN1_VALUE *skitem;
311 unsigned char *tmpdat = NULL, *p = NULL;
312 DER_ENC *derlst = NULL, *tder;
313 if(do_sort) {
314 /* Don't need to sort less than 2 items */
315 if(sk_ASN1_VALUE_num(sk) < 2) do_sort = 0;
316 else {
317 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst));
318 tmpdat = OPENSSL_malloc(skcontlen);
319 if(!derlst || !tmpdat) return 0;
320 }
321 }
322 /* If not sorting just output each item */
323 if(!do_sort) {
324 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
325 skitem = sk_ASN1_VALUE_value(sk, i);
326 ASN1_item_i2d(skitem, out, item);
327 }
328 return 1;
329 }
330 p = tmpdat;
331 /* Doing sort: build up a list of each member's DER encoding */
332 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
333 skitem = sk_ASN1_VALUE_value(sk, i);
334 tder->data = p;
335 tder->length = ASN1_item_i2d(skitem, &p, item);
336 tder->field = skitem;
337 }
338 /* Now sort them */
339 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
340 /* Output sorted DER encoding */
341 p = *out;
342 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
343 memcpy(p, tder->data, tder->length);
344 p += tder->length;
345 }
346 *out = p;
347 /* If do_sort is 2 then reorder the STACK */
348 if(do_sort == 2) {
349 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
350 sk_ASN1_VALUE_set(sk, i, tder->field);
351 }
352 OPENSSL_free(derlst);
353 OPENSSL_free(tmpdat);
354 return 1;
355}
356
357static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
358{
359 int len;
360 int utype;
361 int usetag;
362
363 utype = it->utype;
364
365 /* Get length of content octets and maybe find
366 * out the underlying type.
367 */
368
369 len = asn1_ex_i2c(pval, NULL, &utype, it);
370
371 /* If SEQUENCE, SET or OTHER then header is
372 * included in pseudo content octets so don't
373 * include tag+length. We need to check here
374 * because the call to asn1_ex_i2c() could change
375 * utype.
376 */
377 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
378 (utype == V_ASN1_OTHER))
379 usetag = 0;
380 else usetag = 1;
381
382 /* -1 means omit type */
383
384 if(len == -1) return 0;
385
386 /* If not implicitly tagged get tag from underlying type */
387 if(tag == -1) tag = utype;
388
389 /* Output tag+length followed by content octets */
390 if(out) {
391 if(usetag) ASN1_put_object(out, 0, len, tag, aclass);
392 asn1_ex_i2c(pval, *out, &utype, it);
393 *out += len;
394 }
395
396 if(usetag) return ASN1_object_size(0, len, tag);
397 return len;
398}
399
400/* Produce content octets from a structure */
401
402int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_ITEM *it)
403{
404 ASN1_BOOLEAN *tbool = NULL;
405 ASN1_STRING *strtmp;
406 ASN1_OBJECT *otmp;
407 int utype;
408 unsigned char *cont, c;
409 int len;
410 const ASN1_PRIMITIVE_FUNCS *pf;
411 pf = it->funcs;
412 if(pf && pf->prim_i2c) return pf->prim_i2c(pval, cout, putype, it);
413
414 /* Should type be omitted? */
415 if((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
416 if(!*pval) return -1;
417 }
418
419 if(it->itype == ASN1_ITYPE_MSTRING) {
420 /* If MSTRING type set the underlying type */
421 strtmp = (ASN1_STRING *)*pval;
422 utype = strtmp->type;
423 *putype = utype;
424 } else if(it->utype == V_ASN1_ANY) {
425 /* If ANY set type and pointer to value */
426 ASN1_TYPE *typ;
427 typ = (ASN1_TYPE *)*pval;
428 utype = typ->type;
429 *putype = utype;
430 pval = (ASN1_VALUE **)&typ->value.ptr;
431 } else utype = *putype;
432
433 switch(utype) {
434 case V_ASN1_OBJECT:
435 otmp = (ASN1_OBJECT *)*pval;
436 cont = otmp->data;
437 len = otmp->length;
438 break;
439
440 case V_ASN1_NULL:
441 cont = NULL;
442 len = 0;
443 break;
444
445 case V_ASN1_BOOLEAN:
446 tbool = (ASN1_BOOLEAN *)pval;
447 if(*tbool == -1) return -1;
448 /* Default handling if value == size field then omit */
449 if(*tbool && (it->size > 0)) return -1;
450 if(!*tbool && !it->size) return -1;
451 c = (unsigned char)*tbool;
452 cont = &c;
453 len = 1;
454 break;
455
456 case V_ASN1_BIT_STRING:
457 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL);
458 break;
459
460 case V_ASN1_INTEGER:
461 case V_ASN1_NEG_INTEGER:
462 case V_ASN1_ENUMERATED:
463 case V_ASN1_NEG_ENUMERATED:
464 /* These are all have the same content format
465 * as ASN1_INTEGER
466 */
467 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
468 break;
469
470 case V_ASN1_OCTET_STRING:
471 case V_ASN1_NUMERICSTRING:
472 case V_ASN1_PRINTABLESTRING:
473 case V_ASN1_T61STRING:
474 case V_ASN1_VIDEOTEXSTRING:
475 case V_ASN1_IA5STRING:
476 case V_ASN1_UTCTIME:
477 case V_ASN1_GENERALIZEDTIME:
478 case V_ASN1_GRAPHICSTRING:
479 case V_ASN1_VISIBLESTRING:
480 case V_ASN1_GENERALSTRING:
481 case V_ASN1_UNIVERSALSTRING:
482 case V_ASN1_BMPSTRING:
483 case V_ASN1_UTF8STRING:
484 case V_ASN1_SEQUENCE:
485 case V_ASN1_SET:
486 default:
487 /* All based on ASN1_STRING and handled the same */
488 strtmp = (ASN1_STRING *)*pval;
489 cont = strtmp->data;
490 len = strtmp->length;
491
492 break;
493
494 }
495 if(cout && len) memcpy(cout, cont, len);
496 return len;
497}
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c
new file mode 100644
index 0000000000..2dd844159e
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_fre.c
@@ -0,0 +1,229 @@
1/* tasn_fre.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63#include <openssl/objects.h>
64
65static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
66
67/* Free up an ASN1 structure */
68
69void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
70{
71 asn1_item_combine_free(&val, it, 0);
72}
73
74void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
75{
76 asn1_item_combine_free(pval, it, 0);
77}
78
79static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
80{
81 const ASN1_TEMPLATE *tt = NULL, *seqtt;
82 const ASN1_EXTERN_FUNCS *ef;
83 const ASN1_COMPAT_FUNCS *cf;
84 const ASN1_AUX *aux = it->funcs;
85 ASN1_aux_cb *asn1_cb;
86 int i;
87 if(!pval) return;
88 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
89 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
90 else asn1_cb = 0;
91
92 switch(it->itype) {
93
94 case ASN1_ITYPE_PRIMITIVE:
95 if(it->templates) ASN1_template_free(pval, it->templates);
96 else ASN1_primitive_free(pval, it);
97 break;
98
99 case ASN1_ITYPE_MSTRING:
100 ASN1_primitive_free(pval, it);
101 break;
102
103 case ASN1_ITYPE_CHOICE:
104 if(asn1_cb) {
105 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
106 if(i == 2) return;
107 }
108 i = asn1_get_choice_selector(pval, it);
109 if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
110 if((i >= 0) && (i < it->tcount)) {
111 ASN1_VALUE **pchval;
112 tt = it->templates + i;
113 pchval = asn1_get_field_ptr(pval, tt);
114 ASN1_template_free(pchval, tt);
115 }
116 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
117 if(!combine) {
118 OPENSSL_free(*pval);
119 *pval = NULL;
120 }
121 break;
122
123 case ASN1_ITYPE_COMPAT:
124 cf = it->funcs;
125 if(cf && cf->asn1_free) cf->asn1_free(*pval);
126 break;
127
128 case ASN1_ITYPE_EXTERN:
129 ef = it->funcs;
130 if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
131 break;
132
133 case ASN1_ITYPE_SEQUENCE:
134 if(asn1_do_lock(pval, -1, it) > 0) return;
135 if(asn1_cb) {
136 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
137 if(i == 2) return;
138 }
139 asn1_enc_free(pval, it);
140 /* If we free up as normal we will invalidate any
141 * ANY DEFINED BY field and we wont be able to
142 * determine the type of the field it defines. So
143 * free up in reverse order.
144 */
145 tt = it->templates + it->tcount - 1;
146 for(i = 0; i < it->tcount; tt--, i++) {
147 ASN1_VALUE **pseqval;
148 seqtt = asn1_do_adb(pval, tt, 0);
149 if(!seqtt) continue;
150 pseqval = asn1_get_field_ptr(pval, seqtt);
151 ASN1_template_free(pseqval, seqtt);
152 }
153 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
154 if(!combine) {
155 OPENSSL_free(*pval);
156 *pval = NULL;
157 }
158 break;
159 }
160}
161
162void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
163{
164 int i;
165 if(tt->flags & ASN1_TFLG_SK_MASK) {
166 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
167 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
168 ASN1_VALUE *vtmp;
169 vtmp = sk_ASN1_VALUE_value(sk, i);
170 asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
171 }
172 sk_ASN1_VALUE_free(sk);
173 *pval = NULL;
174 } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
175 tt->flags & ASN1_TFLG_COMBINE);
176}
177
178void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
179{
180 int utype;
181 if(it) {
182 const ASN1_PRIMITIVE_FUNCS *pf;
183 pf = it->funcs;
184 if(pf && pf->prim_free) {
185 pf->prim_free(pval, it);
186 return;
187 }
188 }
189 /* Special case: if 'it' is NULL free contents of ASN1_TYPE */
190 if(!it) {
191 ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
192 utype = typ->type;
193 pval = (ASN1_VALUE **)&typ->value.ptr;
194 if(!*pval) return;
195 } else if(it->itype == ASN1_ITYPE_MSTRING) {
196 utype = -1;
197 if(!*pval) return;
198 } else {
199 utype = it->utype;
200 if((utype != V_ASN1_BOOLEAN) && !*pval) return;
201 }
202
203 switch(utype) {
204 case V_ASN1_OBJECT:
205 ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
206 break;
207
208 case V_ASN1_BOOLEAN:
209 if (it)
210 *(ASN1_BOOLEAN *)pval = it->size;
211 else
212 *(ASN1_BOOLEAN *)pval = -1;
213 return;
214
215 case V_ASN1_NULL:
216 break;
217
218 case V_ASN1_ANY:
219 ASN1_primitive_free(pval, NULL);
220 OPENSSL_free(*pval);
221 break;
222
223 default:
224 ASN1_STRING_free((ASN1_STRING *)*pval);
225 *pval = NULL;
226 break;
227 }
228 *pval = NULL;
229}
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
new file mode 100644
index 0000000000..a0e3db574f
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -0,0 +1,351 @@
1/* tasn_new.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/err.h>
64#include <openssl/asn1t.h>
65#include <string.h>
66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
68static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
70void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
71
72ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
73{
74 ASN1_VALUE *ret = NULL;
75 if(ASN1_item_ex_new(&ret, it) > 0) return ret;
76 return NULL;
77}
78
79/* Allocate an ASN1 structure */
80
81int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
82{
83 return asn1_item_ex_combine_new(pval, it, 0);
84}
85
86static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
87{
88 const ASN1_TEMPLATE *tt = NULL;
89 const ASN1_COMPAT_FUNCS *cf;
90 const ASN1_EXTERN_FUNCS *ef;
91 const ASN1_AUX *aux = it->funcs;
92 ASN1_aux_cb *asn1_cb;
93 ASN1_VALUE **pseqval;
94 int i;
95 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
96 else asn1_cb = 0;
97
98 if(!combine) *pval = NULL;
99
100#ifdef CRYPTO_MDEBUG
101 if(it->sname) CRYPTO_push_info(it->sname);
102#endif
103
104 switch(it->itype) {
105
106 case ASN1_ITYPE_EXTERN:
107 ef = it->funcs;
108 if(ef && ef->asn1_ex_new) {
109 if(!ef->asn1_ex_new(pval, it))
110 goto memerr;
111 }
112 break;
113
114 case ASN1_ITYPE_COMPAT:
115 cf = it->funcs;
116 if(cf && cf->asn1_new) {
117 *pval = cf->asn1_new();
118 if(!*pval) goto memerr;
119 }
120 break;
121
122 case ASN1_ITYPE_PRIMITIVE:
123 if(it->templates) {
124 if(!ASN1_template_new(pval, it->templates))
125 goto memerr;
126 } else {
127 if(!ASN1_primitive_new(pval, it))
128 goto memerr;
129 }
130 break;
131
132 case ASN1_ITYPE_MSTRING:
133 if(!ASN1_primitive_new(pval, it))
134 goto memerr;
135 break;
136
137 case ASN1_ITYPE_CHOICE:
138 if(asn1_cb) {
139 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
140 if(!i) goto auxerr;
141 if(i==2) {
142#ifdef CRYPTO_MDEBUG
143 if(it->sname) CRYPTO_pop_info();
144#endif
145 return 1;
146 }
147 }
148 if(!combine) {
149 *pval = OPENSSL_malloc(it->size);
150 if(!*pval) goto memerr;
151 memset(*pval, 0, it->size);
152 }
153 asn1_set_choice_selector(pval, -1, it);
154 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
155 goto auxerr;
156 break;
157
158 case ASN1_ITYPE_SEQUENCE:
159 if(asn1_cb) {
160 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
161 if(!i) goto auxerr;
162 if(i==2) {
163#ifdef CRYPTO_MDEBUG
164 if(it->sname) CRYPTO_pop_info();
165#endif
166 return 1;
167 }
168 }
169 if(!combine) {
170 *pval = OPENSSL_malloc(it->size);
171 if(!*pval) goto memerr;
172 memset(*pval, 0, it->size);
173 asn1_do_lock(pval, 0, it);
174 asn1_enc_init(pval, it);
175 }
176 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
177 pseqval = asn1_get_field_ptr(pval, tt);
178 if(!ASN1_template_new(pseqval, tt)) goto memerr;
179 }
180 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
181 goto auxerr;
182 break;
183 }
184#ifdef CRYPTO_MDEBUG
185 if(it->sname) CRYPTO_pop_info();
186#endif
187 return 1;
188
189 memerr:
190 ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE);
191#ifdef CRYPTO_MDEBUG
192 if(it->sname) CRYPTO_pop_info();
193#endif
194 return 0;
195
196 auxerr:
197 ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR);
198 ASN1_item_ex_free(pval, it);
199#ifdef CRYPTO_MDEBUG
200 if(it->sname) CRYPTO_pop_info();
201#endif
202 return 0;
203
204}
205
206static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
207{
208 const ASN1_EXTERN_FUNCS *ef;
209
210 switch(it->itype) {
211
212 case ASN1_ITYPE_EXTERN:
213 ef = it->funcs;
214 if(ef && ef->asn1_ex_clear)
215 ef->asn1_ex_clear(pval, it);
216 else *pval = NULL;
217 break;
218
219
220 case ASN1_ITYPE_PRIMITIVE:
221 if(it->templates)
222 asn1_template_clear(pval, it->templates);
223 else
224 asn1_primitive_clear(pval, it);
225 break;
226
227 case ASN1_ITYPE_MSTRING:
228 asn1_primitive_clear(pval, it);
229 break;
230
231 case ASN1_ITYPE_COMPAT:
232 case ASN1_ITYPE_CHOICE:
233 case ASN1_ITYPE_SEQUENCE:
234 *pval = NULL;
235 break;
236 }
237}
238
239
240int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
241{
242 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
243 int ret;
244 if(tt->flags & ASN1_TFLG_OPTIONAL) {
245 asn1_template_clear(pval, tt);
246 return 1;
247 }
248 /* If ANY DEFINED BY nothing to do */
249
250 if(tt->flags & ASN1_TFLG_ADB_MASK) {
251 *pval = NULL;
252 return 1;
253 }
254#ifdef CRYPTO_MDEBUG
255 if(tt->field_name) CRYPTO_push_info(tt->field_name);
256#endif
257 /* If SET OF or SEQUENCE OF, its a STACK */
258 if(tt->flags & ASN1_TFLG_SK_MASK) {
259 STACK_OF(ASN1_VALUE) *skval;
260 skval = sk_ASN1_VALUE_new_null();
261 if(!skval) {
262 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
263 ret = 0;
264 goto done;
265 }
266 *pval = (ASN1_VALUE *)skval;
267 ret = 1;
268 goto done;
269 }
270 /* Otherwise pass it back to the item routine */
271 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
272 done:
273#ifdef CRYPTO_MDEBUG
274 if(it->sname) CRYPTO_pop_info();
275#endif
276 return ret;
277}
278
279static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
280{
281 /* If ADB or STACK just NULL the field */
282 if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
283 *pval = NULL;
284 else
285 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
286}
287
288
289/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old
290 * functions.
291 */
292
293int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
294{
295 ASN1_TYPE *typ;
296 int utype;
297 const ASN1_PRIMITIVE_FUNCS *pf;
298 pf = it->funcs;
299 if(pf && pf->prim_new) return pf->prim_new(pval, it);
300 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
301 else utype = it->utype;
302 switch(utype) {
303 case V_ASN1_OBJECT:
304 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
305 return 1;
306
307 case V_ASN1_BOOLEAN:
308 if (it)
309 *(ASN1_BOOLEAN *)pval = it->size;
310 else
311 *(ASN1_BOOLEAN *)pval = -1;
312 return 1;
313
314 case V_ASN1_NULL:
315 *pval = (ASN1_VALUE *)1;
316 return 1;
317
318 case V_ASN1_ANY:
319 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
320 if(!typ) return 0;
321 typ->value.ptr = NULL;
322 typ->type = -1;
323 *pval = (ASN1_VALUE *)typ;
324 break;
325
326 default:
327 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
328 break;
329 }
330 if(*pval) return 1;
331 return 0;
332}
333
334void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
335{
336 int utype;
337 const ASN1_PRIMITIVE_FUNCS *pf;
338 pf = it->funcs;
339 if(pf) {
340 if(pf->prim_clear)
341 pf->prim_clear(pval, it);
342 else
343 *pval = NULL;
344 return;
345 }
346 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
347 else utype = it->utype;
348 if(utype == V_ASN1_BOOLEAN)
349 *(ASN1_BOOLEAN *)pval = it->size;
350 else *pval = NULL;
351}
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
new file mode 100644
index 0000000000..719639b511
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_prn.c
@@ -0,0 +1,198 @@
1/* tasn_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/nasn.h>
66
67/* Print routines. Print out a whole structure from a template.
68 */
69
70static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name);
71
72int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it)
73{
74 return asn1_item_print_nm(out, fld, indent, it, it->sname);
75}
76
77static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name)
78{
79 ASN1_STRING *str;
80 const ASN1_TEMPLATE *tt;
81 void *tmpfld;
82 int i;
83 if(!fld) {
84 BIO_printf(out, "%*s%s ABSENT\n", indent, "", name);
85 return 1;
86 }
87 switch(it->itype) {
88
89 case ASN1_ITYPE_PRIMITIVE:
90 if(it->templates)
91 return ASN1_template_print(out, fld, indent, it->templates);
92 return asn1_primitive_print(out, fld, it->utype, indent, name);
93 break;
94
95 case ASN1_ITYPE_MSTRING:
96 str = fld;
97 return asn1_primitive_print(out, fld, str->type, indent, name);
98
99 case ASN1_ITYPE_EXTERN:
100 BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
101 return 1;
102 case ASN1_ITYPE_COMPAT:
103 BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
104 return 1;
105
106
107 case ASN1_ITYPE_CHOICE:
108 /* CHOICE type, get selector */
109 i = asn1_get_choice_selector(fld, it);
110 /* This should never happen... */
111 if((i < 0) || (i >= it->tcount)) {
112 BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i);
113 return 1;
114 }
115 tt = it->templates + i;
116 tmpfld = asn1_get_field(fld, tt);
117 return ASN1_template_print(out, tmpfld, indent, tt);
118
119 case ASN1_ITYPE_SEQUENCE:
120 BIO_printf(out, "%*s%s {\n", indent, "", name);
121 /* Get each field entry */
122 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
123 tmpfld = asn1_get_field(fld, tt);
124 ASN1_template_print(out, tmpfld, indent + 2, tt);
125 }
126 BIO_printf(out, "%*s}\n", indent, "");
127 return 1;
128
129 default:
130 return 0;
131 }
132}
133
134int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt)
135{
136 int i, flags;
137#if 0
138 if(!fld) return 0;
139#endif
140 flags = tt->flags;
141 if(flags & ASN1_TFLG_SK_MASK) {
142 char *tname;
143 void *skitem;
144 /* SET OF, SEQUENCE OF */
145 if(flags & ASN1_TFLG_SET_OF) tname = "SET";
146 else tname = "SEQUENCE";
147 if(fld) {
148 BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name);
149 for(i = 0; i < sk_num(fld); i++) {
150 skitem = sk_value(fld, i);
151 asn1_item_print_nm(out, skitem, indent + 2, tt->item, "");
152 }
153 BIO_printf(out, "%*s}\n", indent, "");
154 } else
155 BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name);
156 return 1;
157 }
158 return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name);
159}
160
161static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name)
162{
163 ASN1_STRING *str = fld;
164 if(fld) {
165 if(utype == V_ASN1_BOOLEAN) {
166 int *bool = fld;
167if(*bool == -1) printf("BOOL MISSING\n");
168 BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE");
169 } else if((utype == V_ASN1_INTEGER)
170 || (utype == V_ASN1_ENUMERATED)) {
171 char *s, *nm;
172 s = i2s_ASN1_INTEGER(NULL, fld);
173 if(utype == V_ASN1_INTEGER) nm = "INTEGER";
174 else nm = "ENUMERATED";
175 BIO_printf(out, "%*s%s:%s", indent, "", nm, s);
176 OPENSSL_free(s);
177 } else if(utype == V_ASN1_NULL) {
178 BIO_printf(out, "%*s%s", indent, "", "NULL");
179 } else if(utype == V_ASN1_UTCTIME) {
180 BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME");
181 ASN1_UTCTIME_print(out, str);
182 } else if(utype == V_ASN1_GENERALIZEDTIME) {
183 BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME");
184 ASN1_GENERALIZEDTIME_print(out, str);
185 } else if(utype == V_ASN1_OBJECT) {
186 char objbuf[80], *ln;
187 ln = OBJ_nid2ln(OBJ_obj2nid(fld));
188 if(!ln) ln = "";
189 OBJ_obj2txt(objbuf, sizeof objbuf, fld, 1);
190 BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf);
191 } else {
192 BIO_printf(out, "%*s%s:", indent, "", name);
193 ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE);
194 }
195 BIO_printf(out, "\n");
196 } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name);
197 return 1;
198}
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c
new file mode 100644
index 0000000000..804d2eeba2
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_typ.c
@@ -0,0 +1,133 @@
1/* tasn_typ.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <stdio.h>
59#include <openssl/asn1.h>
60#include <openssl/asn1t.h>
61
62/* Declarations for string types */
63
64
65IMPLEMENT_ASN1_TYPE(ASN1_INTEGER)
66IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER)
67
68IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED)
69IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED)
70
71IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING)
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING)
73
74IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING)
75IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
76
77IMPLEMENT_ASN1_TYPE(ASN1_NULL)
78IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
79
80IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
81
82IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING)
83IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING)
84
85IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING)
86IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
87
88IMPLEMENT_ASN1_TYPE(ASN1_T61STRING)
89IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING)
90
91IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING)
92IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING)
93
94IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING)
95IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
96
97IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME)
98IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME)
99
100IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME)
101IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
102
103IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING)
104IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
105
106IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING)
107IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
108
109IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING)
110IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING)
111
112IMPLEMENT_ASN1_TYPE(ASN1_ANY)
113
114/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
115IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
116
117IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
118
119/* Multistring types */
120
121IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
122IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
123
124IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
125IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
126
127IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
128IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
129
130/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
131IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
132IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
133IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
new file mode 100644
index 0000000000..8996ce8c13
--- /dev/null
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -0,0 +1,253 @@
1/* tasn_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/err.h>
66
67/* Utility functions for manipulating fields and offsets */
68
69/* Add 'offset' to 'addr' */
70#define offset2ptr(addr, offset) (void *)(((char *) addr) + offset)
71
72/* Given an ASN1_ITEM CHOICE type return
73 * the selector value
74 */
75
76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
77{
78 int *sel = offset2ptr(*pval, it->utype);
79 return *sel;
80}
81
82/* Given an ASN1_ITEM CHOICE type set
83 * the selector value, return old value.
84 */
85
86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
87{
88 int *sel, ret;
89 sel = offset2ptr(*pval, it->utype);
90 ret = *sel;
91 *sel = value;
92 return ret;
93}
94
95/* Do reference counting. The value 'op' decides what to do.
96 * if it is +1 then the count is incremented. If op is 0 count is
97 * set to 1. If op is -1 count is decremented and the return value
98 * is the current refrence count or 0 if no reference count exists.
99 */
100
101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
102{
103 const ASN1_AUX *aux;
104 int *lck, ret;
105 if(it->itype != ASN1_ITYPE_SEQUENCE) return 0;
106 aux = it->funcs;
107 if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
108 lck = offset2ptr(*pval, aux->ref_offset);
109 if(op == 0) {
110 *lck = 1;
111 return 1;
112 }
113 ret = CRYPTO_add(lck, op, aux->ref_lock);
114#ifdef REF_PRINT
115 fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
116#endif
117#ifdef REF_CHECK
118 if(ret < 0)
119 fprintf(stderr, "%s, bad reference count\n", it->sname);
120#endif
121 return ret;
122}
123
124static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
125{
126 const ASN1_AUX *aux;
127 if(!pval || !*pval) return NULL;
128 aux = it->funcs;
129 if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL;
130 return offset2ptr(*pval, aux->enc_offset);
131}
132
133void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
134{
135 ASN1_ENCODING *enc;
136 enc = asn1_get_enc_ptr(pval, it);
137 if(enc) {
138 enc->enc = NULL;
139 enc->len = 0;
140 enc->modified = 1;
141 }
142}
143
144void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
145{
146 ASN1_ENCODING *enc;
147 enc = asn1_get_enc_ptr(pval, it);
148 if(enc) {
149 if(enc->enc) OPENSSL_free(enc->enc);
150 enc->enc = NULL;
151 enc->len = 0;
152 enc->modified = 1;
153 }
154}
155
156int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it)
157{
158 ASN1_ENCODING *enc;
159 enc = asn1_get_enc_ptr(pval, it);
160 if(!enc) return 1;
161
162 if(enc->enc) OPENSSL_free(enc->enc);
163 enc->enc = OPENSSL_malloc(inlen);
164 if(!enc->enc) return 0;
165 memcpy(enc->enc, in, inlen);
166 enc->len = inlen;
167 enc->modified = 0;
168
169 return 1;
170}
171
172int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it)
173{
174 ASN1_ENCODING *enc;
175 enc = asn1_get_enc_ptr(pval, it);
176 if(!enc || enc->modified) return 0;
177 if(out) {
178 memcpy(*out, enc->enc, enc->len);
179 *out += enc->len;
180 }
181 if(len) *len = enc->len;
182 return 1;
183}
184
185/* Given an ASN1_TEMPLATE get a pointer to a field */
186ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
187{
188 ASN1_VALUE **pvaltmp;
189 if(tt->flags & ASN1_TFLG_COMBINE) return pval;
190 pvaltmp = offset2ptr(*pval, tt->offset);
191 /* NOTE for BOOLEAN types the field is just a plain
192 * int so we can't return int **, so settle for
193 * (int *).
194 */
195 return pvaltmp;
196}
197
198/* Handle ANY DEFINED BY template, find the selector, look up
199 * the relevant ASN1_TEMPLATE in the table and return it.
200 */
201
202const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
203{
204 const ASN1_ADB *adb;
205 const ASN1_ADB_TABLE *atbl;
206 long selector;
207 ASN1_VALUE **sfld;
208 int i;
209 if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt;
210
211 /* Else ANY DEFINED BY ... get the table */
212 adb = ASN1_ADB_ptr(tt->item);
213
214 /* Get the selector field */
215 sfld = offset2ptr(*pval, adb->offset);
216
217 /* Check if NULL */
218 if(!sfld) {
219 if(!adb->null_tt) goto err;
220 return adb->null_tt;
221 }
222
223 /* Convert type to a long:
224 * NB: don't check for NID_undef here because it
225 * might be a legitimate value in the table
226 */
227 if(tt->flags & ASN1_TFLG_ADB_OID)
228 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
229 else
230 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
231
232 /* Try to find matching entry in table
233 * Maybe should check application types first to
234 * allow application override? Might also be useful
235 * to have a flag which indicates table is sorted and
236 * we can do a binary search. For now stick to a
237 * linear search.
238 */
239
240 for(atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
241 if(atbl->value == selector) return &atbl->tt;
242
243 /* FIXME: need to search application table too */
244
245 /* No match, return default type */
246 if(!adb->default_tt) goto err;
247 return adb->default_tt;
248
249 err:
250 /* FIXME: should log the value or OID of unsupported type */
251 if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
252 return NULL;
253}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
new file mode 100644
index 0000000000..00b9ea54a1
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_algor.c
@@ -0,0 +1,73 @@
1/* x_algor.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stddef.h>
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63
64ASN1_SEQUENCE(X509_ALGOR) = {
65 ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT),
66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
67} ASN1_SEQUENCE_END(X509_ALGOR)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
70IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
71
72IMPLEMENT_STACK_OF(X509_ALGOR)
73IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
new file mode 100644
index 0000000000..1e3713f18f
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_attrib.c
@@ -0,0 +1,118 @@
1/* crypto/asn1/x_attrib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509.h>
64
65/* X509_ATTRIBUTE: this has the following form:
66 *
67 * typedef struct x509_attributes_st
68 * {
69 * ASN1_OBJECT *object;
70 * int single;
71 * union {
72 * char *ptr;
73 * STACK_OF(ASN1_TYPE) *set;
74 * ASN1_TYPE *single;
75 * } value;
76 * } X509_ATTRIBUTE;
77 *
78 * this needs some extra thought because the CHOICE type is
79 * merged with the main structure and because the value can
80 * be anything at all we *must* try the SET OF first because
81 * the ASN1_ANY type will swallow anything including the whole
82 * SET OF structure.
83 */
84
85ASN1_CHOICE(X509_ATTRIBUTE_SET) = {
86 ASN1_SET_OF(X509_ATTRIBUTE, value.set, ASN1_ANY),
87 ASN1_SIMPLE(X509_ATTRIBUTE, value.single, ASN1_ANY)
88} ASN1_CHOICE_END_selector(X509_ATTRIBUTE, X509_ATTRIBUTE_SET, single)
89
90ASN1_SEQUENCE(X509_ATTRIBUTE) = {
91 ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
92 /* CHOICE type merged with parent */
93 ASN1_EX_COMBINE(0, 0, X509_ATTRIBUTE_SET)
94} ASN1_SEQUENCE_END(X509_ATTRIBUTE)
95
96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
98
99X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
100 {
101 X509_ATTRIBUTE *ret=NULL;
102 ASN1_TYPE *val=NULL;
103
104 if ((ret=X509_ATTRIBUTE_new()) == NULL)
105 return(NULL);
106 ret->object=OBJ_nid2obj(nid);
107 ret->single=0;
108 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
109 if ((val=ASN1_TYPE_new()) == NULL) goto err;
110 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
111
112 ASN1_TYPE_set(val,atrtype,value);
113 return(ret);
114err:
115 if (ret != NULL) X509_ATTRIBUTE_free(ret);
116 if (val != NULL) ASN1_TYPE_free(val);
117 return(NULL);
118 }
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c
new file mode 100644
index 0000000000..848c7a0877
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_bignum.c
@@ -0,0 +1,137 @@
1/* x_bignum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a
64 * BIGNUM directly. Currently it ignores the sign which isn't a problem since all
65 * BIGNUMs used are non negative and anything that looks negative is normally due
66 * to an encoding error.
67 */
68
69#define BN_SENSITIVE 1
70
71static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
72static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
73
74static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
75static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
76
77static ASN1_PRIMITIVE_FUNCS bignum_pf = {
78 NULL, 0,
79 bn_new,
80 bn_free,
81 0,
82 bn_c2i,
83 bn_i2c
84};
85
86ASN1_ITEM_start(BIGNUM)
87 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
88ASN1_ITEM_end(BIGNUM)
89
90ASN1_ITEM_start(CBIGNUM)
91 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM"
92ASN1_ITEM_end(CBIGNUM)
93
94static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
95{
96 *pval = (ASN1_VALUE *)BN_new();
97 if(*pval) return 1;
98 else return 0;
99}
100
101static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
102{
103 if(!*pval) return;
104 if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval);
105 else BN_free((BIGNUM *)*pval);
106 *pval = NULL;
107}
108
109static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
110{
111 BIGNUM *bn;
112 int pad;
113 if(!*pval) return -1;
114 bn = (BIGNUM *)*pval;
115 /* If MSB set in an octet we need a padding byte */
116 if(BN_num_bits(bn) & 0x7) pad = 0;
117 else pad = 1;
118 if(cont) {
119 if(pad) *cont++ = 0;
120 BN_bn2bin(bn, cont);
121 }
122 return pad + BN_num_bytes(bn);
123}
124
125static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
126{
127 BIGNUM *bn;
128 if(!*pval) bn_new(pval, it);
129 bn = (BIGNUM *)*pval;
130 if(!BN_bin2bn(cont, len, bn)) {
131 bn_free(pval, it);
132 return 0;
133 }
134 return 1;
135}
136
137
diff --git a/src/lib/libcrypto/asn1/x_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
new file mode 100644
index 0000000000..b99f8fc522
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -0,0 +1,140 @@
1/* crypto/asn1/x_crl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
65 const X509_REVOKED * const *b);
66
67ASN1_SEQUENCE(X509_REVOKED) = {
68 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER),
69 ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME),
70 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION)
71} ASN1_SEQUENCE_END(X509_REVOKED)
72
73/* The X509_CRL_INFO structure needs a bit of customisation.
74 * Since we cache the original encoding the signature wont be affected by
75 * reordering of the revoked field.
76 */
77static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
78{
79 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
80
81 if(!a || !a->revoked) return 1;
82 switch(operation) {
83 /* Just set cmp function here. We don't sort because that
84 * would affect the output of X509_CRL_print().
85 */
86 case ASN1_OP_D2I_POST:
87 sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
88 break;
89 }
90 return 1;
91}
92
93
94ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
95 ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER),
96 ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR),
97 ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME),
98 ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME),
99 ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME),
100 ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED),
101 ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0)
102} ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO)
103
104ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = {
105 ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO),
106 ASN1_SIMPLE(X509_CRL, sig_alg, X509_ALGOR),
107 ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING)
108} ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL)
109
110IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED)
111IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO)
112IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)
113IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL)
114
115static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
116 const X509_REVOKED * const *b)
117 {
118 return(ASN1_STRING_cmp(
119 (ASN1_STRING *)(*a)->serialNumber,
120 (ASN1_STRING *)(*b)->serialNumber));
121 }
122
123int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
124{
125 X509_CRL_INFO *inf;
126 inf = crl->crl;
127 if(!inf->revoked)
128 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
129 if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
130 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
131 return 0;
132 }
133 inf->enc.modified = 1;
134 return 1;
135}
136
137IMPLEMENT_STACK_OF(X509_REVOKED)
138IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
139IMPLEMENT_STACK_OF(X509_CRL)
140IMPLEMENT_ASN1_SET_OF(X509_CRL)
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
new file mode 100644
index 0000000000..702421b6c8
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -0,0 +1,71 @@
1/* x_exten.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stddef.h>
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63
64ASN1_SEQUENCE(X509_EXTENSION) = {
65 ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT),
66 ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN),
67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
68} ASN1_SEQUENCE_END(X509_EXTENSION)
69
70IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
71IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
new file mode 100644
index 0000000000..d44f6cdb01
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_info.c
@@ -0,0 +1,114 @@
1/* crypto/asn1/x_info.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1.h>
63#include <openssl/x509.h>
64
65X509_INFO *X509_INFO_new(void)
66 {
67 X509_INFO *ret=NULL;
68
69 ret=(X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO));
70 if (ret == NULL)
71 {
72 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
75
76 ret->enc_cipher.cipher=NULL;
77 ret->enc_len=0;
78 ret->enc_data=NULL;
79
80 ret->references=1;
81 ret->x509=NULL;
82 ret->crl=NULL;
83 ret->x_pkey=NULL;
84 return(ret);
85 }
86
87void X509_INFO_free(X509_INFO *x)
88 {
89 int i;
90
91 if (x == NULL) return;
92
93 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO);
94#ifdef REF_PRINT
95 REF_PRINT("X509_INFO",x);
96#endif
97 if (i > 0) return;
98#ifdef REF_CHECK
99 if (i < 0)
100 {
101 fprintf(stderr,"X509_INFO_free, bad reference count\n");
102 abort();
103 }
104#endif
105
106 if (x->x509 != NULL) X509_free(x->x509);
107 if (x->crl != NULL) X509_CRL_free(x->crl);
108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
109 if (x->enc_data != NULL) OPENSSL_free(x->enc_data);
110 OPENSSL_free(x);
111 }
112
113IMPLEMENT_STACK_OF(X509_INFO)
114
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
new file mode 100644
index 0000000000..c5f25956cb
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_long.c
@@ -0,0 +1,169 @@
1/* x_long.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for long handling. This converts between an ASN1_INTEGER
64 * and a long directly.
65 */
66
67
68static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
70
71static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
72static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
73
74static ASN1_PRIMITIVE_FUNCS long_pf = {
75 NULL, 0,
76 long_new,
77 long_free,
78 long_free, /* Clear should set to initial value */
79 long_c2i,
80 long_i2c
81};
82
83ASN1_ITEM_start(LONG)
84 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG"
85ASN1_ITEM_end(LONG)
86
87ASN1_ITEM_start(ZLONG)
88 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG"
89ASN1_ITEM_end(ZLONG)
90
91static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
92{
93 *(long *)pval = it->size;
94 return 1;
95}
96
97static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
98{
99 *(long *)pval = it->size;
100}
101
102static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
103{
104 long ltmp;
105 unsigned long utmp;
106 int clen, pad, i;
107 /* this exists to bypass broken gcc optimization */
108 char *cp = (char *)pval;
109
110 /* use memcpy, because we may not be long aligned */
111 memcpy(&ltmp, cp, sizeof(long));
112
113 if(ltmp == it->size) return -1;
114 /* Convert the long to positive: we subtract one if negative so
115 * we can cleanly handle the padding if only the MSB of the leading
116 * octet is set.
117 */
118 if(ltmp < 0) utmp = -ltmp - 1;
119 else utmp = ltmp;
120 clen = BN_num_bits_word(utmp);
121 /* If MSB of leading octet set we need to pad */
122 if(!(clen & 0x7)) pad = 1;
123 else pad = 0;
124
125 /* Convert number of bits to number of octets */
126 clen = (clen + 7) >> 3;
127
128 if(cont) {
129 if(pad) *cont++ = (ltmp < 0) ? 0xff : 0;
130 for(i = clen - 1; i >= 0; i--) {
131 cont[i] = (unsigned char)(utmp & 0xff);
132 if(ltmp < 0) cont[i] ^= 0xff;
133 utmp >>= 8;
134 }
135 }
136 return clen + pad;
137}
138
139static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
140{
141 int neg, i;
142 long ltmp;
143 unsigned long utmp = 0;
144 char *cp = (char *)pval;
145 if(len > sizeof(long)) {
146 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
147 return 0;
148 }
149 /* Is it negative? */
150 if(len && (cont[0] & 0x80)) neg = 1;
151 else neg = 0;
152 utmp = 0;
153 for(i = 0; i < len; i++) {
154 utmp <<= 8;
155 if(neg) utmp |= cont[i] ^ 0xff;
156 else utmp |= cont[i];
157 }
158 ltmp = (long)utmp;
159 if(neg) {
160 ltmp++;
161 ltmp = -ltmp;
162 }
163 if(ltmp == it->size) {
164 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
165 return 0;
166 }
167 memcpy(cp, &ltmp, sizeof(long));
168 return 1;
169}
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
new file mode 100644
index 0000000000..31f3377b64
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -0,0 +1,275 @@
1/* crypto/asn1/x_name.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
65 int tag, int aclass, char opt, ASN1_TLC *ctx);
66
67static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
68static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);
69static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);
70
71static int x509_name_encode(X509_NAME *a);
72
73ASN1_SEQUENCE(X509_NAME_ENTRY) = {
74 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),
75 ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE)
76} ASN1_SEQUENCE_END(X509_NAME_ENTRY)
77
78IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY)
79IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY)
80
81/* For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY }
82 * so declare two template wrappers for this
83 */
84
85ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) =
86 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY)
87ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES)
88
89ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) =
90 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES)
91ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL)
92
93/* Normally that's where it would end: we'd have two nested STACK structures
94 * representing the ASN1. Unfortunately X509_NAME uses a completely different
95 * form and caches encodings so we have to process the internal form and convert
96 * to the external form.
97 */
98
99const ASN1_EXTERN_FUNCS x509_name_ff = {
100 NULL,
101 x509_name_ex_new,
102 x509_name_ex_free,
103 0, /* Default clear behaviour is OK */
104 x509_name_ex_d2i,
105 x509_name_ex_i2d
106};
107
108IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff)
109
110IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)
111IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
112
113static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
114{
115 X509_NAME *ret = NULL;
116 ret = OPENSSL_malloc(sizeof(X509_NAME));
117 if(!ret) goto memerr;
118 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL)
119 goto memerr;
120 if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr;
121 ret->modified=1;
122 *val = (ASN1_VALUE *)ret;
123 return 1;
124
125 memerr:
126 ASN1err(ASN1_F_X509_NAME_NEW, ERR_R_MALLOC_FAILURE);
127 if (ret)
128 {
129 if (ret->entries)
130 sk_X509_NAME_ENTRY_free(ret->entries);
131 OPENSSL_free(ret);
132 }
133 return 0;
134}
135
136static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
137{
138 X509_NAME *a;
139 if(!pval || !*pval)
140 return;
141 a = (X509_NAME *)*pval;
142
143 BUF_MEM_free(a->bytes);
144 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
145 OPENSSL_free(a);
146 *pval = NULL;
147}
148
149/* Used with sk_pop_free() to free up the internal representation.
150 * NB: we only free the STACK and not its contents because it is
151 * already present in the X509_NAME structure.
152 */
153
154static void sk_internal_free(void *a)
155{
156 sk_free(a);
157}
158
159static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
160 int tag, int aclass, char opt, ASN1_TLC *ctx)
161{
162 unsigned char *p = *in, *q;
163 STACK *intname = NULL, **intname_pp = &intname;
164 int i, j, ret;
165 X509_NAME *nm = NULL, **nm_pp = &nm;
166 STACK_OF(X509_NAME_ENTRY) *entries;
167 X509_NAME_ENTRY *entry;
168 q = p;
169
170 /* Get internal representation of Name */
171 ret = ASN1_item_ex_d2i((ASN1_VALUE **)intname_pp,
172 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
173 tag, aclass, opt, ctx);
174
175 if(ret <= 0) return ret;
176
177 if(*val) x509_name_ex_free(val, NULL);
178 if(!x509_name_ex_new((ASN1_VALUE **)nm_pp, NULL)) goto err;
179 /* We've decoded it: now cache encoding */
180 if(!BUF_MEM_grow(nm->bytes, p - q)) goto err;
181 memcpy(nm->bytes->data, q, p - q);
182
183 /* Convert internal representation to X509_NAME structure */
184 for(i = 0; i < sk_num(intname); i++) {
185 entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i);
186 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
187 entry = sk_X509_NAME_ENTRY_value(entries, j);
188 entry->set = i;
189 if(!sk_X509_NAME_ENTRY_push(nm->entries, entry))
190 goto err;
191 }
192 sk_X509_NAME_ENTRY_free(entries);
193 }
194 sk_free(intname);
195 nm->modified = 0;
196 *val = (ASN1_VALUE *)nm;
197 *in = p;
198 return ret;
199 err:
200 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_NESTED_ASN1_ERROR);
201 return 0;
202}
203
204static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
205{
206 int ret;
207 X509_NAME *a = (X509_NAME *)*val;
208 if(a->modified) {
209 ret = x509_name_encode((X509_NAME *)a);
210 if(ret < 0) return ret;
211 }
212 ret = a->bytes->length;
213 if(out != NULL) {
214 memcpy(*out,a->bytes->data,ret);
215 *out+=ret;
216 }
217 return ret;
218}
219
220static int x509_name_encode(X509_NAME *a)
221{
222 STACK *intname = NULL, **intname_pp = &intname;
223 int len;
224 unsigned char *p;
225 STACK_OF(X509_NAME_ENTRY) *entries = NULL;
226 X509_NAME_ENTRY *entry;
227 int i, set = -1;
228 intname = sk_new_null();
229 if(!intname) goto memerr;
230 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
231 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
232 if(entry->set != set) {
233 entries = sk_X509_NAME_ENTRY_new_null();
234 if(!entries) goto memerr;
235 if(!sk_push(intname, (char *)entries)) goto memerr;
236 set = entry->set;
237 }
238 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr;
239 }
240 len = ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, NULL,
241 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
242 if (!BUF_MEM_grow(a->bytes,len)) goto memerr;
243 p=(unsigned char *)a->bytes->data;
244 ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp,
245 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
246 sk_pop_free(intname, sk_internal_free);
247 a->modified = 0;
248 return len;
249 memerr:
250 sk_pop_free(intname, sk_internal_free);
251 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_MALLOC_FAILURE);
252 return -1;
253}
254
255
256int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
257 {
258 X509_NAME *in;
259
260 if (!xn || !name) return(0);
261
262 if (*xn != name)
263 {
264 in=X509_NAME_dup(name);
265 if (in != NULL)
266 {
267 X509_NAME_free(*xn);
268 *xn=in;
269 }
270 }
271 return(*xn != NULL);
272 }
273
274IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
275IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
new file mode 100644
index 0000000000..f1c6221ac3
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -0,0 +1,151 @@
1/* crypto/asn1/x_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66/* need to implement */
67int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
68 {
69 return(0);
70 }
71
72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length)
73 {
74 int i;
75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
76
77 M_ASN1_D2I_Init();
78 M_ASN1_D2I_start_sequence();
79 M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR);
80 M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING);
81
82 ret->cipher.cipher=EVP_get_cipherbyname(
83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
84 if (ret->cipher.cipher == NULL)
85 {
86 c.error=ASN1_R_UNSUPPORTED_CIPHER;
87 c.line=__LINE__;
88 goto err;
89 }
90 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
91 {
92 i=ret->enc_algor->parameter->value.octet_string->length;
93 if (i > EVP_MAX_IV_LENGTH)
94 {
95 c.error=ASN1_R_IV_TOO_LARGE;
96 c.line=__LINE__;
97 goto err;
98 }
99 memcpy(ret->cipher.iv,
100 ret->enc_algor->parameter->value.octet_string->data,i);
101 }
102 else
103 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
104 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
105 }
106
107X509_PKEY *X509_PKEY_new(void)
108 {
109 X509_PKEY *ret=NULL;
110 ASN1_CTX c;
111
112 M_ASN1_New_Malloc(ret,X509_PKEY);
113 ret->version=0;
114 M_ASN1_New(ret->enc_algor,X509_ALGOR_new);
115 M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new);
116 ret->dec_pkey=NULL;
117 ret->key_length=0;
118 ret->key_data=NULL;
119 ret->key_free=0;
120 ret->cipher.cipher=NULL;
121 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
122 ret->references=1;
123 return(ret);
124 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
125 }
126
127void X509_PKEY_free(X509_PKEY *x)
128 {
129 int i;
130
131 if (x == NULL) return;
132
133 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY);
134#ifdef REF_PRINT
135 REF_PRINT("X509_PKEY",x);
136#endif
137 if (i > 0) return;
138#ifdef REF_CHECK
139 if (i < 0)
140 {
141 fprintf(stderr,"X509_PKEY_free, bad reference count\n");
142 abort();
143 }
144#endif
145
146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
147 if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey);
148 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
149 if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data);
150 OPENSSL_free(x);
151 }
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
new file mode 100644
index 0000000000..7d6d71af88
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -0,0 +1,360 @@
1/* crypto/asn1/x_pubkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64/* Minor tweak to operation: free up EVP_PKEY */
65static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 if(operation == ASN1_OP_FREE_POST) {
68 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
69 EVP_PKEY_free(pubkey->pkey);
70 }
71 return 1;
72}
73
74ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
75 ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR),
76 ASN1_SIMPLE(X509_PUBKEY, public_key, ASN1_BIT_STRING)
77} ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY)
78
79IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
80
81int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
82 {
83 X509_PUBKEY *pk=NULL;
84 X509_ALGOR *a;
85 ASN1_OBJECT *o;
86 unsigned char *s,*p = NULL;
87 int i;
88
89 if (x == NULL) return(0);
90
91 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
92 a=pk->algor;
93
94 /* set the algorithm id */
95 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
96 ASN1_OBJECT_free(a->algorithm);
97 a->algorithm=o;
98
99 /* Set the parameter list */
100 if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
101 {
102 if ((a->parameter == NULL) ||
103 (a->parameter->type != V_ASN1_NULL))
104 {
105 ASN1_TYPE_free(a->parameter);
106 if (!(a->parameter=ASN1_TYPE_new()))
107 {
108 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
109 goto err;
110 }
111 a->parameter->type=V_ASN1_NULL;
112 }
113 }
114 else
115#ifndef OPENSSL_NO_DSA
116 if (pkey->type == EVP_PKEY_DSA)
117 {
118 unsigned char *pp;
119 DSA *dsa;
120
121 dsa=pkey->pkey.dsa;
122 dsa->write_params=0;
123 ASN1_TYPE_free(a->parameter);
124 if ((i=i2d_DSAparams(dsa,NULL)) <= 0)
125 goto err;
126 if (!(p=(unsigned char *)OPENSSL_malloc(i)))
127 {
128 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
129 goto err;
130 }
131 pp=p;
132 i2d_DSAparams(dsa,&pp);
133 if (!(a->parameter=ASN1_TYPE_new()))
134 {
135 OPENSSL_free(p);
136 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
137 goto err;
138 }
139 a->parameter->type=V_ASN1_SEQUENCE;
140 if (!(a->parameter->value.sequence=ASN1_STRING_new()))
141 {
142 OPENSSL_free(p);
143 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
144 goto err;
145 }
146 if (!ASN1_STRING_set(a->parameter->value.sequence,p,i))
147 {
148 OPENSSL_free(p);
149 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
150 goto err;
151 }
152 OPENSSL_free(p);
153 }
154 else
155#endif
156 {
157 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
158 goto err;
159 }
160
161 if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
162 if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL)
163 {
164 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
165 goto err;
166 }
167 p=s;
168 i2d_PublicKey(pkey,&p);
169 if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i))
170 {
171 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
172 goto err;
173 }
174 /* Set number of unused bits to zero */
175 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
176 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
177
178 OPENSSL_free(s);
179
180#if 0
181 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
182 pk->pkey=pkey;
183#endif
184
185 if (*x != NULL)
186 X509_PUBKEY_free(*x);
187
188 *x=pk;
189
190 return 1;
191err:
192 if (pk != NULL) X509_PUBKEY_free(pk);
193 return 0;
194 }
195
196EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
197 {
198 EVP_PKEY *ret=NULL;
199 long j;
200 int type;
201 unsigned char *p;
202#ifndef OPENSSL_NO_DSA
203 const unsigned char *cp;
204 X509_ALGOR *a;
205#endif
206
207 if (key == NULL) goto err;
208
209 if (key->pkey != NULL)
210 {
211 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
212 return(key->pkey);
213 }
214
215 if (key->public_key == NULL) goto err;
216
217 type=OBJ_obj2nid(key->algor->algorithm);
218 p=key->public_key->data;
219 j=key->public_key->length;
220 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
221 {
222 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
223 goto err;
224 }
225 ret->save_parameters=0;
226
227#ifndef OPENSSL_NO_DSA
228 a=key->algor;
229 if (ret->type == EVP_PKEY_DSA)
230 {
231 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
232 {
233 ret->pkey.dsa->write_params=0;
234 cp=p=a->parameter->value.sequence->data;
235 j=a->parameter->value.sequence->length;
236 if (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j))
237 goto err;
238 }
239 ret->save_parameters=1;
240 }
241#endif
242 key->pkey=ret;
243 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
244 return(ret);
245err:
246 if (ret != NULL)
247 EVP_PKEY_free(ret);
248 return(NULL);
249 }
250
251/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
252 * and encode or decode as X509_PUBKEY
253 */
254
255EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
256 long length)
257{
258 X509_PUBKEY *xpk;
259 EVP_PKEY *pktmp;
260 xpk = d2i_X509_PUBKEY(NULL, pp, length);
261 if(!xpk) return NULL;
262 pktmp = X509_PUBKEY_get(xpk);
263 X509_PUBKEY_free(xpk);
264 if(!pktmp) return NULL;
265 if(a) {
266 EVP_PKEY_free(*a);
267 *a = pktmp;
268 }
269 return pktmp;
270}
271
272int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
273{
274 X509_PUBKEY *xpk=NULL;
275 int ret;
276 if(!a) return 0;
277 if(!X509_PUBKEY_set(&xpk, a)) return 0;
278 ret = i2d_X509_PUBKEY(xpk, pp);
279 X509_PUBKEY_free(xpk);
280 return ret;
281}
282
283/* The following are equivalents but which return RSA and DSA
284 * keys
285 */
286#ifndef OPENSSL_NO_RSA
287RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
288 long length)
289{
290 EVP_PKEY *pkey;
291 RSA *key;
292 unsigned char *q;
293 q = *pp;
294 pkey = d2i_PUBKEY(NULL, &q, length);
295 if(!pkey) return NULL;
296 key = EVP_PKEY_get1_RSA(pkey);
297 EVP_PKEY_free(pkey);
298 if(!key) return NULL;
299 *pp = q;
300 if(a) {
301 RSA_free(*a);
302 *a = key;
303 }
304 return key;
305}
306
307int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
308{
309 EVP_PKEY *pktmp;
310 int ret;
311 if(!a) return 0;
312 pktmp = EVP_PKEY_new();
313 if(!pktmp) {
314 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
315 return 0;
316 }
317 EVP_PKEY_set1_RSA(pktmp, a);
318 ret = i2d_PUBKEY(pktmp, pp);
319 EVP_PKEY_free(pktmp);
320 return ret;
321}
322#endif
323
324#ifndef OPENSSL_NO_DSA
325DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
326 long length)
327{
328 EVP_PKEY *pkey;
329 DSA *key;
330 unsigned char *q;
331 q = *pp;
332 pkey = d2i_PUBKEY(NULL, &q, length);
333 if(!pkey) return NULL;
334 key = EVP_PKEY_get1_DSA(pkey);
335 EVP_PKEY_free(pkey);
336 if(!key) return NULL;
337 *pp = q;
338 if(a) {
339 DSA_free(*a);
340 *a = key;
341 }
342 return key;
343}
344
345int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
346{
347 EVP_PKEY *pktmp;
348 int ret;
349 if(!a) return 0;
350 pktmp = EVP_PKEY_new();
351 if(!pktmp) {
352 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
353 return 0;
354 }
355 EVP_PKEY_set1_DSA(pktmp, a);
356 ret = i2d_PUBKEY(pktmp, pp);
357 EVP_PKEY_free(pktmp);
358 return ret;
359}
360#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
new file mode 100644
index 0000000000..b3f18ebc12
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_req.c
@@ -0,0 +1,112 @@
1/* crypto/asn1/x_req.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64/* X509_REQ_INFO is handled in an unusual way to get round
65 * invalid encodings. Some broken certificate requests don't
66 * encode the attributes field if it is empty. This is in
67 * violation of PKCS#10 but we need to tolerate it. We do
68 * this by making the attributes field OPTIONAL then using
69 * the callback to initialise it to an empty STACK.
70 *
71 * This means that the field will be correctly encoded unless
72 * we NULL out the field.
73 *
74 * As a result we no longer need the req_kludge field because
75 * the information is now contained in the attributes field:
76 * 1. If it is NULL then it's the invalid omission.
77 * 2. If it is empty it is the correct encoding.
78 * 3. If it is not empty then some attributes are present.
79 *
80 */
81
82static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
83{
84 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
85
86 if(operation == ASN1_OP_NEW_POST) {
87 rinf->attributes = sk_X509_ATTRIBUTE_new_null();
88 if(!rinf->attributes) return 0;
89 }
90 return 1;
91}
92
93ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
94 ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER),
95 ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME),
96 ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY),
97 /* This isn't really OPTIONAL but it gets round invalid
98 * encodings
99 */
100 ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0)
101} ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO)
102
103IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
104
105ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_INFO) = {
106 ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO),
107 ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR),
108 ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING)
109} ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ)
110
111IMPLEMENT_ASN1_FUNCTIONS(X509_REQ)
112IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ)
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
new file mode 100644
index 0000000000..42efa86c1c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_sig.c
@@ -0,0 +1,69 @@
1/* crypto/asn1/x_sig.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64ASN1_SEQUENCE(X509_SIG) = {
65 ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR),
66 ASN1_SIMPLE(X509_SIG, digest, ASN1_OCTET_STRING)
67} ASN1_SEQUENCE_END(X509_SIG)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
new file mode 100644
index 0000000000..2aece077c5
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_spki.c
@@ -0,0 +1,81 @@
1/* crypto/asn1/x_spki.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59 /* This module was send to me my Pat Richards <patr@x509.com> who
60 * wrote it. It is under my Copyright with his permission
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include <openssl/x509.h>
66#include <openssl/asn1t.h>
67
68ASN1_SEQUENCE(NETSCAPE_SPKAC) = {
69 ASN1_SIMPLE(NETSCAPE_SPKAC, pubkey, X509_PUBKEY),
70 ASN1_SIMPLE(NETSCAPE_SPKAC, challenge, ASN1_IA5STRING)
71} ASN1_SEQUENCE_END(NETSCAPE_SPKAC)
72
73IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
74
75ASN1_SEQUENCE(NETSCAPE_SPKI) = {
76 ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC),
77 ASN1_SIMPLE(NETSCAPE_SPKI, sig_algor, X509_ALGOR),
78 ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING)
79} ASN1_SEQUENCE_END(NETSCAPE_SPKI)
80
81IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKI)
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
new file mode 100644
index 0000000000..dc17c67758
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_val.c
@@ -0,0 +1,69 @@
1/* crypto/asn1/x_val.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63
64ASN1_SEQUENCE(X509_VAL) = {
65 ASN1_SIMPLE(X509_VAL, notBefore, ASN1_TIME),
66 ASN1_SIMPLE(X509_VAL, notAfter, ASN1_TIME)
67} ASN1_SEQUENCE_END(X509_VAL)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_VAL)
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
new file mode 100644
index 0000000000..b50167ce43
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -0,0 +1,189 @@
1/* crypto/asn1/x_x509.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(X509_CINF) = {
67 ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0),
68 ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER),
69 ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR),
70 ASN1_SIMPLE(X509_CINF, issuer, X509_NAME),
71 ASN1_SIMPLE(X509_CINF, validity, X509_VAL),
72 ASN1_SIMPLE(X509_CINF, subject, X509_NAME),
73 ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY),
74 ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1),
75 ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2),
76 ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3)
77} ASN1_SEQUENCE_END(X509_CINF)
78
79IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
80/* X509 top level structure needs a bit of customisation */
81
82static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
83{
84 X509 *ret = (X509 *)*pval;
85
86 switch(operation) {
87
88 case ASN1_OP_NEW_POST:
89 ret->valid=0;
90 ret->name = NULL;
91 ret->ex_flags = 0;
92 ret->ex_pathlen = -1;
93 ret->skid = NULL;
94 ret->akid = NULL;
95 ret->aux = NULL;
96 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
97 break;
98
99 case ASN1_OP_D2I_POST:
100 if (ret->name != NULL) OPENSSL_free(ret->name);
101 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
102 break;
103
104 case ASN1_OP_FREE_POST:
105 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
106 X509_CERT_AUX_free(ret->aux);
107 ASN1_OCTET_STRING_free(ret->skid);
108 AUTHORITY_KEYID_free(ret->akid);
109
110 if (ret->name != NULL) OPENSSL_free(ret->name);
111 break;
112
113 }
114
115 return 1;
116
117}
118
119ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
120 ASN1_SIMPLE(X509, cert_info, X509_CINF),
121 ASN1_SIMPLE(X509, sig_alg, X509_ALGOR),
122 ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING)
123} ASN1_SEQUENCE_END_ref(X509, X509)
124
125IMPLEMENT_ASN1_FUNCTIONS(X509)
126IMPLEMENT_ASN1_DUP_FUNCTION(X509)
127
128static ASN1_METHOD meth={
129 (int (*)()) i2d_X509,
130 (char *(*)())d2i_X509,
131 (char *(*)())X509_new,
132 (void (*)()) X509_free};
133
134ASN1_METHOD *X509_asn1_meth(void)
135 {
136 return(&meth);
137 }
138
139int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
140 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
141 {
142 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp,
143 new_func, dup_func, free_func);
144 }
145
146int X509_set_ex_data(X509 *r, int idx, void *arg)
147 {
148 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
149 }
150
151void *X509_get_ex_data(X509 *r, int idx)
152 {
153 return(CRYPTO_get_ex_data(&r->ex_data,idx));
154 }
155
156/* X509_AUX ASN1 routines. X509_AUX is the name given to
157 * a certificate with extra info tagged on the end. Since these
158 * functions set how a certificate is trusted they should only
159 * be used when the certificate comes from a reliable source
160 * such as local storage.
161 *
162 */
163
164X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
165{
166 unsigned char *q;
167 X509 *ret;
168 /* Save start position */
169 q = *pp;
170 ret = d2i_X509(a, pp, length);
171 /* If certificate unreadable then forget it */
172 if(!ret) return NULL;
173 /* update length */
174 length -= *pp - q;
175 if(!length) return ret;
176 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
177 return ret;
178 err:
179 X509_free(ret);
180 return NULL;
181}
182
183int i2d_X509_AUX(X509 *a, unsigned char **pp)
184{
185 int length;
186 length = i2d_X509(a, pp);
187 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
188 return length;
189}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
new file mode 100644
index 0000000000..f244768b7e
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_x509a.c
@@ -0,0 +1,151 @@
1/* a_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX routines. These are used to encode additional
66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data.
70 */
71
72static X509_CERT_AUX *aux_get(X509 *x);
73
74ASN1_SEQUENCE(X509_CERT_AUX) = {
75 ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT),
76 ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0),
77 ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING),
78 ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING),
79 ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1)
80} ASN1_SEQUENCE_END(X509_CERT_AUX)
81
82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
83
84static X509_CERT_AUX *aux_get(X509 *x)
85{
86 if(!x) return NULL;
87 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
88 return x->aux;
89}
90
91int X509_alias_set1(X509 *x, unsigned char *name, int len)
92{
93 X509_CERT_AUX *aux;
94 if(!(aux = aux_get(x))) return 0;
95 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
96 return ASN1_STRING_set(aux->alias, name, len);
97}
98
99int X509_keyid_set1(X509 *x, unsigned char *id, int len)
100{
101 X509_CERT_AUX *aux;
102 if(!(aux = aux_get(x))) return 0;
103 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0;
104 return ASN1_STRING_set(aux->keyid, id, len);
105}
106
107unsigned char *X509_alias_get0(X509 *x, int *len)
108{
109 if(!x->aux || !x->aux->alias) return NULL;
110 if(len) *len = x->aux->alias->length;
111 return x->aux->alias->data;
112}
113
114int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
115{
116 X509_CERT_AUX *aux;
117 ASN1_OBJECT *objtmp;
118 if(!(objtmp = OBJ_dup(obj))) return 0;
119 if(!(aux = aux_get(x))) return 0;
120 if(!aux->trust
121 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
122 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
123}
124
125int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
126{
127 X509_CERT_AUX *aux;
128 ASN1_OBJECT *objtmp;
129 if(!(objtmp = OBJ_dup(obj))) return 0;
130 if(!(aux = aux_get(x))) return 0;
131 if(!aux->reject
132 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
133 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
134}
135
136void X509_trust_clear(X509 *x)
137{
138 if(x->aux && x->aux->trust) {
139 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
140 x->aux->trust = NULL;
141 }
142}
143
144void X509_reject_clear(X509 *x)
145{
146 if(x->aux && x->aux->reject) {
147 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
148 x->aux->reject = NULL;
149 }
150}
151
diff --git a/src/lib/libcrypto/bf/COPYRIGHT b/src/lib/libcrypto/bf/COPYRIGHT
new file mode 100644
index 0000000000..6857223506
--- /dev/null
+++ b/src/lib/libcrypto/bf/COPYRIGHT
@@ -0,0 +1,46 @@
1Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2All rights reserved.
3
4This package is an Blowfish implementation written
5by Eric Young (eay@cryptsoft.com).
6
7This library is free for commercial and non-commercial use as long as
8the following conditions are aheared to. The following conditions
9apply to all code found in this distribution.
10
11Copyright remains Eric Young's, and as such any Copyright notices in
12the code are not to be removed.
13
14Redistribution and use in source and binary forms, with or without
15modification, are permitted provided that the following conditions
16are met:
171. Redistributions of source code must retain the copyright
18 notice, this list of conditions and the following disclaimer.
192. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
223. All advertising materials mentioning features or use of this software
23 must display the following acknowledgement:
24 This product includes software developed by Eric Young (eay@cryptsoft.com)
25
26THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
27ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36SUCH DAMAGE.
37
38The license and distribution terms for any publically available version or
39derivative of this code cannot be changed. i.e. this code cannot simply be
40copied and put under another distrubution license
41[including the GNU Public License.]
42
43The reason behind this being stated in this direct manner is past
44experience in code simply being copied and the attribution removed
45from it and then being distributed as part of other packages. This
46implementation was a non-trivial and unpaid effort.
diff --git a/src/lib/libcrypto/bf/INSTALL b/src/lib/libcrypto/bf/INSTALL
new file mode 100644
index 0000000000..3b25923532
--- /dev/null
+++ b/src/lib/libcrypto/bf/INSTALL
@@ -0,0 +1,14 @@
1This Eric Young's blowfish implementation, taken from his SSLeay library
2and made available as a separate library.
3
4The version number (0.7.2m) is the SSLeay version that this library was
5taken from.
6
7To build, just unpack and type make.
8If you are not using gcc, edit the Makefile.
9If you are compiling for an x86 box, try the assembler (it needs improving).
10There are also some compile time options that can improve performance,
11these are documented in the Makefile.
12
13eric 15-Apr-1997
14
diff --git a/src/lib/libcrypto/bf/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/README b/src/lib/libcrypto/bf/README
new file mode 100644
index 0000000000..f2712fd0e7
--- /dev/null
+++ b/src/lib/libcrypto/bf/README
@@ -0,0 +1,8 @@
1This is a quick packaging up of my blowfish code into a library.
2It has been lifted from SSLeay.
3The copyright notices seem a little harsh because I have not spent the
4time to rewrite the conditions from the normal SSLeay ones.
5
6Basically if you just want to play with the library, not a problem.
7
8eric 15-Apr-1997
diff --git a/src/lib/libcrypto/bf/VERSION b/src/lib/libcrypto/bf/VERSION
new file mode 100644
index 0000000000..be995855e4
--- /dev/null
+++ b/src/lib/libcrypto/bf/VERSION
@@ -0,0 +1,6 @@
1The version numbers will follow my SSL implementation
2
30.7.2r - Some reasonable default compiler options from
4 Peter Gutman <pgut001@cs.auckland.ac.nz>
5
60.7.2m - the first release
diff --git a/src/lib/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl
new file mode 100644
index 0000000000..b5a4760d09
--- /dev/null
+++ b/src/lib/libcrypto/bf/asm/bf-586.pl
@@ -0,0 +1,136 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5require "cbc.pl";
6
7&asm_init($ARGV[0],"bf-586.pl",$ARGV[$#ARGV] eq "386");
8
9$BF_ROUNDS=16;
10$BF_OFF=($BF_ROUNDS+2)*4;
11$L="edi";
12$R="esi";
13$P="ebp";
14$tmp1="eax";
15$tmp2="ebx";
16$tmp3="ecx";
17$tmp4="edx";
18
19&BF_encrypt("BF_encrypt",1);
20&BF_encrypt("BF_decrypt",0);
21&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1) unless $main'openbsd;
22&asm_finish();
23
24sub BF_encrypt
25 {
26 local($name,$enc)=@_;
27
28 &function_begin_B($name,"");
29
30 &comment("");
31
32 &push("ebp");
33 &push("ebx");
34 &mov($tmp2,&wparam(0));
35 &mov($P,&wparam(1));
36 &push("esi");
37 &push("edi");
38
39 &comment("Load the 2 words");
40 &mov($L,&DWP(0,$tmp2,"",0));
41 &mov($R,&DWP(4,$tmp2,"",0));
42
43 &xor( $tmp1, $tmp1);
44
45 # encrypting part
46
47 if ($enc)
48 {
49 &mov($tmp2,&DWP(0,$P,"",0));
50 &xor( $tmp3, $tmp3);
51
52 &xor($L,$tmp2);
53 for ($i=0; $i<$BF_ROUNDS; $i+=2)
54 {
55 &comment("");
56 &comment("Round $i");
57 &BF_ENCRYPT($i+1,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,1);
58
59 &comment("");
60 &comment("Round ".sprintf("%d",$i+1));
61 &BF_ENCRYPT($i+2,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,1);
62 }
63 # &mov($tmp1,&wparam(0)); In last loop
64 &mov($tmp4,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
65 }
66 else
67 {
68 &mov($tmp2,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
69 &xor( $tmp3, $tmp3);
70
71 &xor($L,$tmp2);
72 for ($i=$BF_ROUNDS; $i>0; $i-=2)
73 {
74 &comment("");
75 &comment("Round $i");
76 &BF_ENCRYPT($i,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,0);
77 &comment("");
78 &comment("Round ".sprintf("%d",$i-1));
79 &BF_ENCRYPT($i-1,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,0);
80 }
81 # &mov($tmp1,&wparam(0)); In last loop
82 &mov($tmp4,&DWP(0,$P,"",0));
83 }
84
85 &xor($R,$tmp4);
86 &mov(&DWP(4,$tmp1,"",0),$L);
87
88 &mov(&DWP(0,$tmp1,"",0),$R);
89 &function_end($name);
90 }
91
92sub BF_ENCRYPT
93 {
94 local($i,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,$enc)=@_;
95
96 &mov( $tmp4, &DWP(&n2a($i*4),$P,"",0)); # for next round
97
98 &mov( $tmp2, $R);
99 &xor( $L, $tmp4);
100
101 &shr( $tmp2, 16);
102 &mov( $tmp4, $R);
103
104 &movb( &LB($tmp1), &HB($tmp2)); # A
105 &and( $tmp2, 0xff); # B
106
107 &movb( &LB($tmp3), &HB($tmp4)); # C
108 &and( $tmp4, 0xff); # D
109
110 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
111 &mov( $tmp2, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
112
113 &add( $tmp2, $tmp1);
114 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp3,4));
115
116 &xor( $tmp2, $tmp1);
117 &mov( $tmp4, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp4,4));
118
119 &add( $tmp2, $tmp4);
120 if (($enc && ($i != 16)) || ((!$enc) && ($i != 1)))
121 { &xor( $tmp1, $tmp1); }
122 else
123 {
124 &comment("Load parameter 0 ($i) enc=$enc");
125 &mov($tmp1,&wparam(0));
126 } # In last loop
127
128 &xor( $L, $tmp2);
129 # delay
130 }
131
132sub n2a
133 {
134 sprintf("%d",$_[0]);
135 }
136
diff --git a/src/lib/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c
new file mode 100644
index 0000000000..f949629dc6
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_cbc.c
@@ -0,0 +1,143 @@
1/* crypto/bf/bf_cbc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/blowfish.h>
60#include "bf_locl.h"
61
62void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
64 {
65 register BF_LONG tin0,tin1;
66 register BF_LONG tout0,tout1,xor0,xor1;
67 register long l=length;
68 BF_LONG tin[2];
69
70 if (encrypt)
71 {
72 n2l(ivec,tout0);
73 n2l(ivec,tout1);
74 ivec-=8;
75 for (l-=8; l>=0; l-=8)
76 {
77 n2l(in,tin0);
78 n2l(in,tin1);
79 tin0^=tout0;
80 tin1^=tout1;
81 tin[0]=tin0;
82 tin[1]=tin1;
83 BF_encrypt(tin,schedule);
84 tout0=tin[0];
85 tout1=tin[1];
86 l2n(tout0,out);
87 l2n(tout1,out);
88 }
89 if (l != -8)
90 {
91 n2ln(in,tin0,tin1,l+8);
92 tin0^=tout0;
93 tin1^=tout1;
94 tin[0]=tin0;
95 tin[1]=tin1;
96 BF_encrypt(tin,schedule);
97 tout0=tin[0];
98 tout1=tin[1];
99 l2n(tout0,out);
100 l2n(tout1,out);
101 }
102 l2n(tout0,ivec);
103 l2n(tout1,ivec);
104 }
105 else
106 {
107 n2l(ivec,xor0);
108 n2l(ivec,xor1);
109 ivec-=8;
110 for (l-=8; l>=0; l-=8)
111 {
112 n2l(in,tin0);
113 n2l(in,tin1);
114 tin[0]=tin0;
115 tin[1]=tin1;
116 BF_decrypt(tin,schedule);
117 tout0=tin[0]^xor0;
118 tout1=tin[1]^xor1;
119 l2n(tout0,out);
120 l2n(tout1,out);
121 xor0=tin0;
122 xor1=tin1;
123 }
124 if (l != -8)
125 {
126 n2l(in,tin0);
127 n2l(in,tin1);
128 tin[0]=tin0;
129 tin[1]=tin1;
130 BF_decrypt(tin,schedule);
131 tout0=tin[0]^xor0;
132 tout1=tin[1]^xor1;
133 l2nn(tout0,tout1,out,l+8);
134 xor0=tin0;
135 xor1=tin1;
136 }
137 l2n(xor0,ivec);
138 l2n(xor1,ivec);
139 }
140 tin0=tin1=tout0=tout1=xor0=xor1=0;
141 tin[0]=tin[1]=0;
142 }
143
diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c
new file mode 100644
index 0000000000..6451c8d407
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_cfb64.c
@@ -0,0 +1,121 @@
1/* crypto/bf/bf_cfb64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/blowfish.h>
60#include "bf_locl.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
68 const BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69 {
70 register BF_LONG v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 BF_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv=(unsigned char *)ivec;
77 if (encrypt)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 n2l(iv,v0); ti[0]=v0;
84 n2l(iv,v1); ti[1]=v1;
85 BF_encrypt((BF_LONG *)ti,schedule);
86 iv=(unsigned char *)ivec;
87 t=ti[0]; l2n(t,iv);
88 t=ti[1]; l2n(t,iv);
89 iv=(unsigned char *)ivec;
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 n2l(iv,v0); ti[0]=v0;
104 n2l(iv,v1); ti[1]=v1;
105 BF_encrypt((BF_LONG *)ti,schedule);
106 iv=(unsigned char *)ivec;
107 t=ti[0]; l2n(t,iv);
108 t=ti[1]; l2n(t,iv);
109 iv=(unsigned char *)ivec;
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=t=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c
new file mode 100644
index 0000000000..341991636f
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_ecb.c
@@ -0,0 +1,96 @@
1/* crypto/bf/bf_ecb.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/blowfish.h>
60#include "bf_locl.h"
61#include <openssl/opensslv.h>
62
63/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
64 * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
66 */
67
68const char *BF_version="Blowfish" OPENSSL_VERSION_PTEXT;
69
70const char *BF_options(void)
71 {
72#ifdef BF_PTR
73 return("blowfish(ptr)");
74#elif defined(BF_PTR2)
75 return("blowfish(ptr2)");
76#else
77 return("blowfish(idx)");
78#endif
79 }
80
81void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
82 const BF_KEY *key, int encrypt)
83 {
84 BF_LONG l,d[2];
85
86 n2l(in,l); d[0]=l;
87 n2l(in,l); d[1]=l;
88 if (encrypt)
89 BF_encrypt(d,key);
90 else
91 BF_decrypt(d,key);
92 l=d[0]; l2n(l,out);
93 l=d[1]; l2n(l,out);
94 l=d[0]=d[1]=0;
95 }
96
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c
new file mode 100644
index 0000000000..b380acf959
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_enc.c
@@ -0,0 +1,306 @@
1/* crypto/bf/bf_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/blowfish.h>
60#include "bf_locl.h"
61
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */
66
67#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
68#error If you set BF_ROUNDS to some value other than 16 or 20, you will have \
69to modify the code.
70#endif
71
72void BF_encrypt(BF_LONG *data, const BF_KEY *key)
73 {
74#ifndef BF_PTR2
75 register BF_LONG l,r;
76 const register BF_LONG *p,*s;
77
78 p=key->P;
79 s= &(key->S[0]);
80 l=data[0];
81 r=data[1];
82
83 l^=p[0];
84 BF_ENC(r,l,s,p[ 1]);
85 BF_ENC(l,r,s,p[ 2]);
86 BF_ENC(r,l,s,p[ 3]);
87 BF_ENC(l,r,s,p[ 4]);
88 BF_ENC(r,l,s,p[ 5]);
89 BF_ENC(l,r,s,p[ 6]);
90 BF_ENC(r,l,s,p[ 7]);
91 BF_ENC(l,r,s,p[ 8]);
92 BF_ENC(r,l,s,p[ 9]);
93 BF_ENC(l,r,s,p[10]);
94 BF_ENC(r,l,s,p[11]);
95 BF_ENC(l,r,s,p[12]);
96 BF_ENC(r,l,s,p[13]);
97 BF_ENC(l,r,s,p[14]);
98 BF_ENC(r,l,s,p[15]);
99 BF_ENC(l,r,s,p[16]);
100#if BF_ROUNDS == 20
101 BF_ENC(r,l,s,p[17]);
102 BF_ENC(l,r,s,p[18]);
103 BF_ENC(r,l,s,p[19]);
104 BF_ENC(l,r,s,p[20]);
105#endif
106 r^=p[BF_ROUNDS+1];
107
108 data[1]=l&0xffffffffL;
109 data[0]=r&0xffffffffL;
110#else
111 register BF_LONG l,r,t,*k;
112
113 l=data[0];
114 r=data[1];
115 k=(BF_LONG*)key;
116
117 l^=k[0];
118 BF_ENC(r,l,k, 1);
119 BF_ENC(l,r,k, 2);
120 BF_ENC(r,l,k, 3);
121 BF_ENC(l,r,k, 4);
122 BF_ENC(r,l,k, 5);
123 BF_ENC(l,r,k, 6);
124 BF_ENC(r,l,k, 7);
125 BF_ENC(l,r,k, 8);
126 BF_ENC(r,l,k, 9);
127 BF_ENC(l,r,k,10);
128 BF_ENC(r,l,k,11);
129 BF_ENC(l,r,k,12);
130 BF_ENC(r,l,k,13);
131 BF_ENC(l,r,k,14);
132 BF_ENC(r,l,k,15);
133 BF_ENC(l,r,k,16);
134#if BF_ROUNDS == 20
135 BF_ENC(r,l,k,17);
136 BF_ENC(l,r,k,18);
137 BF_ENC(r,l,k,19);
138 BF_ENC(l,r,k,20);
139#endif
140 r^=k[BF_ROUNDS+1];
141
142 data[1]=l&0xffffffffL;
143 data[0]=r&0xffffffffL;
144#endif
145 }
146
147#ifndef BF_DEFAULT_OPTIONS
148
149void BF_decrypt(BF_LONG *data, const BF_KEY *key)
150 {
151#ifndef BF_PTR2
152 register BF_LONG l,r;
153 const register BF_LONG *p,*s;
154
155 p=key->P;
156 s= &(key->S[0]);
157 l=data[0];
158 r=data[1];
159
160 l^=p[BF_ROUNDS+1];
161#if BF_ROUNDS == 20
162 BF_ENC(r,l,s,p[20]);
163 BF_ENC(l,r,s,p[19]);
164 BF_ENC(r,l,s,p[18]);
165 BF_ENC(l,r,s,p[17]);
166#endif
167 BF_ENC(r,l,s,p[16]);
168 BF_ENC(l,r,s,p[15]);
169 BF_ENC(r,l,s,p[14]);
170 BF_ENC(l,r,s,p[13]);
171 BF_ENC(r,l,s,p[12]);
172 BF_ENC(l,r,s,p[11]);
173 BF_ENC(r,l,s,p[10]);
174 BF_ENC(l,r,s,p[ 9]);
175 BF_ENC(r,l,s,p[ 8]);
176 BF_ENC(l,r,s,p[ 7]);
177 BF_ENC(r,l,s,p[ 6]);
178 BF_ENC(l,r,s,p[ 5]);
179 BF_ENC(r,l,s,p[ 4]);
180 BF_ENC(l,r,s,p[ 3]);
181 BF_ENC(r,l,s,p[ 2]);
182 BF_ENC(l,r,s,p[ 1]);
183 r^=p[0];
184
185 data[1]=l&0xffffffffL;
186 data[0]=r&0xffffffffL;
187#else
188 register BF_LONG l,r,t,*k;
189
190 l=data[0];
191 r=data[1];
192 k=(BF_LONG *)key;
193
194 l^=k[BF_ROUNDS+1];
195#if BF_ROUNDS == 20
196 BF_ENC(r,l,k,20);
197 BF_ENC(l,r,k,19);
198 BF_ENC(r,l,k,18);
199 BF_ENC(l,r,k,17);
200#endif
201 BF_ENC(r,l,k,16);
202 BF_ENC(l,r,k,15);
203 BF_ENC(r,l,k,14);
204 BF_ENC(l,r,k,13);
205 BF_ENC(r,l,k,12);
206 BF_ENC(l,r,k,11);
207 BF_ENC(r,l,k,10);
208 BF_ENC(l,r,k, 9);
209 BF_ENC(r,l,k, 8);
210 BF_ENC(l,r,k, 7);
211 BF_ENC(r,l,k, 6);
212 BF_ENC(l,r,k, 5);
213 BF_ENC(r,l,k, 4);
214 BF_ENC(l,r,k, 3);
215 BF_ENC(r,l,k, 2);
216 BF_ENC(l,r,k, 1);
217 r^=k[0];
218
219 data[1]=l&0xffffffffL;
220 data[0]=r&0xffffffffL;
221#endif
222 }
223
224void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
225 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
226 {
227 register BF_LONG tin0,tin1;
228 register BF_LONG tout0,tout1,xor0,xor1;
229 register long l=length;
230 BF_LONG tin[2];
231
232 if (encrypt)
233 {
234 n2l(ivec,tout0);
235 n2l(ivec,tout1);
236 ivec-=8;
237 for (l-=8; l>=0; l-=8)
238 {
239 n2l(in,tin0);
240 n2l(in,tin1);
241 tin0^=tout0;
242 tin1^=tout1;
243 tin[0]=tin0;
244 tin[1]=tin1;
245 BF_encrypt(tin,schedule);
246 tout0=tin[0];
247 tout1=tin[1];
248 l2n(tout0,out);
249 l2n(tout1,out);
250 }
251 if (l != -8)
252 {
253 n2ln(in,tin0,tin1,l+8);
254 tin0^=tout0;
255 tin1^=tout1;
256 tin[0]=tin0;
257 tin[1]=tin1;
258 BF_encrypt(tin,schedule);
259 tout0=tin[0];
260 tout1=tin[1];
261 l2n(tout0,out);
262 l2n(tout1,out);
263 }
264 l2n(tout0,ivec);
265 l2n(tout1,ivec);
266 }
267 else
268 {
269 n2l(ivec,xor0);
270 n2l(ivec,xor1);
271 ivec-=8;
272 for (l-=8; l>=0; l-=8)
273 {
274 n2l(in,tin0);
275 n2l(in,tin1);
276 tin[0]=tin0;
277 tin[1]=tin1;
278 BF_decrypt(tin,schedule);
279 tout0=tin[0]^xor0;
280 tout1=tin[1]^xor1;
281 l2n(tout0,out);
282 l2n(tout1,out);
283 xor0=tin0;
284 xor1=tin1;
285 }
286 if (l != -8)
287 {
288 n2l(in,tin0);
289 n2l(in,tin1);
290 tin[0]=tin0;
291 tin[1]=tin1;
292 BF_decrypt(tin,schedule);
293 tout0=tin[0]^xor0;
294 tout1=tin[1]^xor1;
295 l2nn(tout0,tout1,out,l+8);
296 xor0=tin0;
297 xor1=tin1;
298 }
299 l2n(xor0,ivec);
300 l2n(xor1,ivec);
301 }
302 tin0=tin1=tout0=tout1=xor0=xor1=0;
303 tin[0]=tin[1]=0;
304 }
305
306#endif
diff --git a/src/lib/libcrypto/bf/bf_locl.h b/src/lib/libcrypto/bf/bf_locl.h
new file mode 100644
index 0000000000..cc7c3ec992
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_locl.h
@@ -0,0 +1,219 @@
1/* crypto/bf/bf_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BF_LOCL_H
60#define HEADER_BF_LOCL_H
61#include <openssl/opensslconf.h> /* BF_PTR, BF_PTR2 */
62
63#undef c2l
64#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
65 l|=((unsigned long)(*((c)++)))<< 8L, \
66 l|=((unsigned long)(*((c)++)))<<16L, \
67 l|=((unsigned long)(*((c)++)))<<24L)
68
69/* NOTE - c is not incremented as per c2l */
70#undef c2ln
71#define c2ln(c,l1,l2,n) { \
72 c+=n; \
73 l1=l2=0; \
74 switch (n) { \
75 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
76 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
77 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
78 case 5: l2|=((unsigned long)(*(--(c)))); \
79 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
80 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
81 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
82 case 1: l1|=((unsigned long)(*(--(c)))); \
83 } \
84 }
85
86#undef l2c
87#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
88 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
89 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
90 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
91
92/* NOTE - c is not incremented as per l2c */
93#undef l2cn
94#define l2cn(l1,l2,c,n) { \
95 c+=n; \
96 switch (n) { \
97 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
98 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
99 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
100 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
101 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
102 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
103 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
104 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
105 } \
106 }
107
108/* NOTE - c is not incremented as per n2l */
109#define n2ln(c,l1,l2,n) { \
110 c+=n; \
111 l1=l2=0; \
112 switch (n) { \
113 case 8: l2 =((unsigned long)(*(--(c)))) ; \
114 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
115 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
116 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
117 case 4: l1 =((unsigned long)(*(--(c)))) ; \
118 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
119 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
120 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
121 } \
122 }
123
124/* NOTE - c is not incremented as per l2n */
125#define l2nn(l1,l2,c,n) { \
126 c+=n; \
127 switch (n) { \
128 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
129 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
130 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
131 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
132 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
133 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
134 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
135 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
136 } \
137 }
138
139#undef n2l
140#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
141 l|=((unsigned long)(*((c)++)))<<16L, \
142 l|=((unsigned long)(*((c)++)))<< 8L, \
143 l|=((unsigned long)(*((c)++))))
144
145#undef l2n
146#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
147 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
149 *((c)++)=(unsigned char)(((l) )&0xff))
150
151/* This is actually a big endian algorithm, the most significant byte
152 * is used to lookup array 0 */
153
154#if defined(BF_PTR2)
155
156/*
157 * This is basically a special Intel version. Point is that Intel
158 * doesn't have many registers, but offers a reach choice of addressing
159 * modes. So we spare some registers by directly traversing BF_KEY
160 * structure and hiring the most decorated addressing mode. The code
161 * generated by EGCS is *perfectly* competitive with assembler
162 * implementation!
163 */
164#define BF_ENC(LL,R,KEY,Pi) (\
165 LL^=KEY[Pi], \
166 t= KEY[BF_ROUNDS+2 + 0 + ((R>>24)&0xFF)], \
167 t+= KEY[BF_ROUNDS+2 + 256 + ((R>>16)&0xFF)], \
168 t^= KEY[BF_ROUNDS+2 + 512 + ((R>>8 )&0xFF)], \
169 t+= KEY[BF_ROUNDS+2 + 768 + ((R )&0xFF)], \
170 LL^=t \
171 )
172
173#elif defined(BF_PTR)
174
175#ifndef BF_LONG_LOG2
176#define BF_LONG_LOG2 2 /* default to BF_LONG being 32 bits */
177#endif
178#define BF_M (0xFF<<BF_LONG_LOG2)
179#define BF_0 (24-BF_LONG_LOG2)
180#define BF_1 (16-BF_LONG_LOG2)
181#define BF_2 ( 8-BF_LONG_LOG2)
182#define BF_3 BF_LONG_LOG2 /* left shift */
183
184/*
185 * This is normally very good on RISC platforms where normally you
186 * have to explicitly "multiply" array index by sizeof(BF_LONG)
187 * in order to calculate the effective address. This implementation
188 * excuses CPU from this extra work. Power[PC] uses should have most
189 * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely
190 * rlwinm. So let'em double-check if their compiler does it.
191 */
192
193#define BF_ENC(LL,R,S,P) ( \
194 LL^=P, \
195 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \
196 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \
197 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \
198 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))) \
199 )
200#else
201
202/*
203 * This is a *generic* version. Seem to perform best on platforms that
204 * offer explicit support for extraction of 8-bit nibbles preferably
205 * complemented with "multiplying" of array index by sizeof(BF_LONG).
206 * For the moment of this writing the list comprises Alpha CPU featuring
207 * extbl and s[48]addq instructions.
208 */
209
210#define BF_ENC(LL,R,S,P) ( \
211 LL^=P, \
212 LL^=((( S[ ((int)(R>>24)&0xff)] + \
213 S[0x0100+((int)(R>>16)&0xff)])^ \
214 S[0x0200+((int)(R>> 8)&0xff)])+ \
215 S[0x0300+((int)(R )&0xff)])&0xffffffffL \
216 )
217#endif
218
219#endif
diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c
new file mode 100644
index 0000000000..f2a9ff6e41
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_ofb64.c
@@ -0,0 +1,110 @@
1/* crypto/bf/bf_ofb64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/blowfish.h>
60#include "bf_locl.h"
61
62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
67 const BF_KEY *schedule, unsigned char *ivec, int *num)
68 {
69 register BF_LONG v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 unsigned char d[8];
73 register char *dp;
74 BF_LONG ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv=(unsigned char *)ivec;
79 n2l(iv,v0);
80 n2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=(char *)d;
84 l2n(v0,dp);
85 l2n(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 BF_encrypt((BF_LONG *)ti,schedule);
91 dp=(char *)d;
92 t=ti[0]; l2n(t,dp);
93 t=ti[1]; l2n(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv=(unsigned char *)ivec;
104 l2n(v0,iv);
105 l2n(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/bf/bf_pi.h b/src/lib/libcrypto/bf/bf_pi.h
new file mode 100644
index 0000000000..9949513c68
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_pi.h
@@ -0,0 +1,325 @@
1/* crypto/bf/bf_pi.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59static const BF_KEY bf_init= {
60 {
61 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L,
62 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L,
63 0x452821e6L, 0x38d01377L, 0xbe5466cfL, 0x34e90c6cL,
64 0xc0ac29b7L, 0xc97c50ddL, 0x3f84d5b5L, 0xb5470917L,
65 0x9216d5d9L, 0x8979fb1b
66 },{
67 0xd1310ba6L, 0x98dfb5acL, 0x2ffd72dbL, 0xd01adfb7L,
68 0xb8e1afedL, 0x6a267e96L, 0xba7c9045L, 0xf12c7f99L,
69 0x24a19947L, 0xb3916cf7L, 0x0801f2e2L, 0x858efc16L,
70 0x636920d8L, 0x71574e69L, 0xa458fea3L, 0xf4933d7eL,
71 0x0d95748fL, 0x728eb658L, 0x718bcd58L, 0x82154aeeL,
72 0x7b54a41dL, 0xc25a59b5L, 0x9c30d539L, 0x2af26013L,
73 0xc5d1b023L, 0x286085f0L, 0xca417918L, 0xb8db38efL,
74 0x8e79dcb0L, 0x603a180eL, 0x6c9e0e8bL, 0xb01e8a3eL,
75 0xd71577c1L, 0xbd314b27L, 0x78af2fdaL, 0x55605c60L,
76 0xe65525f3L, 0xaa55ab94L, 0x57489862L, 0x63e81440L,
77 0x55ca396aL, 0x2aab10b6L, 0xb4cc5c34L, 0x1141e8ceL,
78 0xa15486afL, 0x7c72e993L, 0xb3ee1411L, 0x636fbc2aL,
79 0x2ba9c55dL, 0x741831f6L, 0xce5c3e16L, 0x9b87931eL,
80 0xafd6ba33L, 0x6c24cf5cL, 0x7a325381L, 0x28958677L,
81 0x3b8f4898L, 0x6b4bb9afL, 0xc4bfe81bL, 0x66282193L,
82 0x61d809ccL, 0xfb21a991L, 0x487cac60L, 0x5dec8032L,
83 0xef845d5dL, 0xe98575b1L, 0xdc262302L, 0xeb651b88L,
84 0x23893e81L, 0xd396acc5L, 0x0f6d6ff3L, 0x83f44239L,
85 0x2e0b4482L, 0xa4842004L, 0x69c8f04aL, 0x9e1f9b5eL,
86 0x21c66842L, 0xf6e96c9aL, 0x670c9c61L, 0xabd388f0L,
87 0x6a51a0d2L, 0xd8542f68L, 0x960fa728L, 0xab5133a3L,
88 0x6eef0b6cL, 0x137a3be4L, 0xba3bf050L, 0x7efb2a98L,
89 0xa1f1651dL, 0x39af0176L, 0x66ca593eL, 0x82430e88L,
90 0x8cee8619L, 0x456f9fb4L, 0x7d84a5c3L, 0x3b8b5ebeL,
91 0xe06f75d8L, 0x85c12073L, 0x401a449fL, 0x56c16aa6L,
92 0x4ed3aa62L, 0x363f7706L, 0x1bfedf72L, 0x429b023dL,
93 0x37d0d724L, 0xd00a1248L, 0xdb0fead3L, 0x49f1c09bL,
94 0x075372c9L, 0x80991b7bL, 0x25d479d8L, 0xf6e8def7L,
95 0xe3fe501aL, 0xb6794c3bL, 0x976ce0bdL, 0x04c006baL,
96 0xc1a94fb6L, 0x409f60c4L, 0x5e5c9ec2L, 0x196a2463L,
97 0x68fb6fafL, 0x3e6c53b5L, 0x1339b2ebL, 0x3b52ec6fL,
98 0x6dfc511fL, 0x9b30952cL, 0xcc814544L, 0xaf5ebd09L,
99 0xbee3d004L, 0xde334afdL, 0x660f2807L, 0x192e4bb3L,
100 0xc0cba857L, 0x45c8740fL, 0xd20b5f39L, 0xb9d3fbdbL,
101 0x5579c0bdL, 0x1a60320aL, 0xd6a100c6L, 0x402c7279L,
102 0x679f25feL, 0xfb1fa3ccL, 0x8ea5e9f8L, 0xdb3222f8L,
103 0x3c7516dfL, 0xfd616b15L, 0x2f501ec8L, 0xad0552abL,
104 0x323db5faL, 0xfd238760L, 0x53317b48L, 0x3e00df82L,
105 0x9e5c57bbL, 0xca6f8ca0L, 0x1a87562eL, 0xdf1769dbL,
106 0xd542a8f6L, 0x287effc3L, 0xac6732c6L, 0x8c4f5573L,
107 0x695b27b0L, 0xbbca58c8L, 0xe1ffa35dL, 0xb8f011a0L,
108 0x10fa3d98L, 0xfd2183b8L, 0x4afcb56cL, 0x2dd1d35bL,
109 0x9a53e479L, 0xb6f84565L, 0xd28e49bcL, 0x4bfb9790L,
110 0xe1ddf2daL, 0xa4cb7e33L, 0x62fb1341L, 0xcee4c6e8L,
111 0xef20cadaL, 0x36774c01L, 0xd07e9efeL, 0x2bf11fb4L,
112 0x95dbda4dL, 0xae909198L, 0xeaad8e71L, 0x6b93d5a0L,
113 0xd08ed1d0L, 0xafc725e0L, 0x8e3c5b2fL, 0x8e7594b7L,
114 0x8ff6e2fbL, 0xf2122b64L, 0x8888b812L, 0x900df01cL,
115 0x4fad5ea0L, 0x688fc31cL, 0xd1cff191L, 0xb3a8c1adL,
116 0x2f2f2218L, 0xbe0e1777L, 0xea752dfeL, 0x8b021fa1L,
117 0xe5a0cc0fL, 0xb56f74e8L, 0x18acf3d6L, 0xce89e299L,
118 0xb4a84fe0L, 0xfd13e0b7L, 0x7cc43b81L, 0xd2ada8d9L,
119 0x165fa266L, 0x80957705L, 0x93cc7314L, 0x211a1477L,
120 0xe6ad2065L, 0x77b5fa86L, 0xc75442f5L, 0xfb9d35cfL,
121 0xebcdaf0cL, 0x7b3e89a0L, 0xd6411bd3L, 0xae1e7e49L,
122 0x00250e2dL, 0x2071b35eL, 0x226800bbL, 0x57b8e0afL,
123 0x2464369bL, 0xf009b91eL, 0x5563911dL, 0x59dfa6aaL,
124 0x78c14389L, 0xd95a537fL, 0x207d5ba2L, 0x02e5b9c5L,
125 0x83260376L, 0x6295cfa9L, 0x11c81968L, 0x4e734a41L,
126 0xb3472dcaL, 0x7b14a94aL, 0x1b510052L, 0x9a532915L,
127 0xd60f573fL, 0xbc9bc6e4L, 0x2b60a476L, 0x81e67400L,
128 0x08ba6fb5L, 0x571be91fL, 0xf296ec6bL, 0x2a0dd915L,
129 0xb6636521L, 0xe7b9f9b6L, 0xff34052eL, 0xc5855664L,
130 0x53b02d5dL, 0xa99f8fa1L, 0x08ba4799L, 0x6e85076aL,
131 0x4b7a70e9L, 0xb5b32944L, 0xdb75092eL, 0xc4192623L,
132 0xad6ea6b0L, 0x49a7df7dL, 0x9cee60b8L, 0x8fedb266L,
133 0xecaa8c71L, 0x699a17ffL, 0x5664526cL, 0xc2b19ee1L,
134 0x193602a5L, 0x75094c29L, 0xa0591340L, 0xe4183a3eL,
135 0x3f54989aL, 0x5b429d65L, 0x6b8fe4d6L, 0x99f73fd6L,
136 0xa1d29c07L, 0xefe830f5L, 0x4d2d38e6L, 0xf0255dc1L,
137 0x4cdd2086L, 0x8470eb26L, 0x6382e9c6L, 0x021ecc5eL,
138 0x09686b3fL, 0x3ebaefc9L, 0x3c971814L, 0x6b6a70a1L,
139 0x687f3584L, 0x52a0e286L, 0xb79c5305L, 0xaa500737L,
140 0x3e07841cL, 0x7fdeae5cL, 0x8e7d44ecL, 0x5716f2b8L,
141 0xb03ada37L, 0xf0500c0dL, 0xf01c1f04L, 0x0200b3ffL,
142 0xae0cf51aL, 0x3cb574b2L, 0x25837a58L, 0xdc0921bdL,
143 0xd19113f9L, 0x7ca92ff6L, 0x94324773L, 0x22f54701L,
144 0x3ae5e581L, 0x37c2dadcL, 0xc8b57634L, 0x9af3dda7L,
145 0xa9446146L, 0x0fd0030eL, 0xecc8c73eL, 0xa4751e41L,
146 0xe238cd99L, 0x3bea0e2fL, 0x3280bba1L, 0x183eb331L,
147 0x4e548b38L, 0x4f6db908L, 0x6f420d03L, 0xf60a04bfL,
148 0x2cb81290L, 0x24977c79L, 0x5679b072L, 0xbcaf89afL,
149 0xde9a771fL, 0xd9930810L, 0xb38bae12L, 0xdccf3f2eL,
150 0x5512721fL, 0x2e6b7124L, 0x501adde6L, 0x9f84cd87L,
151 0x7a584718L, 0x7408da17L, 0xbc9f9abcL, 0xe94b7d8cL,
152 0xec7aec3aL, 0xdb851dfaL, 0x63094366L, 0xc464c3d2L,
153 0xef1c1847L, 0x3215d908L, 0xdd433b37L, 0x24c2ba16L,
154 0x12a14d43L, 0x2a65c451L, 0x50940002L, 0x133ae4ddL,
155 0x71dff89eL, 0x10314e55L, 0x81ac77d6L, 0x5f11199bL,
156 0x043556f1L, 0xd7a3c76bL, 0x3c11183bL, 0x5924a509L,
157 0xf28fe6edL, 0x97f1fbfaL, 0x9ebabf2cL, 0x1e153c6eL,
158 0x86e34570L, 0xeae96fb1L, 0x860e5e0aL, 0x5a3e2ab3L,
159 0x771fe71cL, 0x4e3d06faL, 0x2965dcb9L, 0x99e71d0fL,
160 0x803e89d6L, 0x5266c825L, 0x2e4cc978L, 0x9c10b36aL,
161 0xc6150ebaL, 0x94e2ea78L, 0xa5fc3c53L, 0x1e0a2df4L,
162 0xf2f74ea7L, 0x361d2b3dL, 0x1939260fL, 0x19c27960L,
163 0x5223a708L, 0xf71312b6L, 0xebadfe6eL, 0xeac31f66L,
164 0xe3bc4595L, 0xa67bc883L, 0xb17f37d1L, 0x018cff28L,
165 0xc332ddefL, 0xbe6c5aa5L, 0x65582185L, 0x68ab9802L,
166 0xeecea50fL, 0xdb2f953bL, 0x2aef7dadL, 0x5b6e2f84L,
167 0x1521b628L, 0x29076170L, 0xecdd4775L, 0x619f1510L,
168 0x13cca830L, 0xeb61bd96L, 0x0334fe1eL, 0xaa0363cfL,
169 0xb5735c90L, 0x4c70a239L, 0xd59e9e0bL, 0xcbaade14L,
170 0xeecc86bcL, 0x60622ca7L, 0x9cab5cabL, 0xb2f3846eL,
171 0x648b1eafL, 0x19bdf0caL, 0xa02369b9L, 0x655abb50L,
172 0x40685a32L, 0x3c2ab4b3L, 0x319ee9d5L, 0xc021b8f7L,
173 0x9b540b19L, 0x875fa099L, 0x95f7997eL, 0x623d7da8L,
174 0xf837889aL, 0x97e32d77L, 0x11ed935fL, 0x16681281L,
175 0x0e358829L, 0xc7e61fd6L, 0x96dedfa1L, 0x7858ba99L,
176 0x57f584a5L, 0x1b227263L, 0x9b83c3ffL, 0x1ac24696L,
177 0xcdb30aebL, 0x532e3054L, 0x8fd948e4L, 0x6dbc3128L,
178 0x58ebf2efL, 0x34c6ffeaL, 0xfe28ed61L, 0xee7c3c73L,
179 0x5d4a14d9L, 0xe864b7e3L, 0x42105d14L, 0x203e13e0L,
180 0x45eee2b6L, 0xa3aaabeaL, 0xdb6c4f15L, 0xfacb4fd0L,
181 0xc742f442L, 0xef6abbb5L, 0x654f3b1dL, 0x41cd2105L,
182 0xd81e799eL, 0x86854dc7L, 0xe44b476aL, 0x3d816250L,
183 0xcf62a1f2L, 0x5b8d2646L, 0xfc8883a0L, 0xc1c7b6a3L,
184 0x7f1524c3L, 0x69cb7492L, 0x47848a0bL, 0x5692b285L,
185 0x095bbf00L, 0xad19489dL, 0x1462b174L, 0x23820e00L,
186 0x58428d2aL, 0x0c55f5eaL, 0x1dadf43eL, 0x233f7061L,
187 0x3372f092L, 0x8d937e41L, 0xd65fecf1L, 0x6c223bdbL,
188 0x7cde3759L, 0xcbee7460L, 0x4085f2a7L, 0xce77326eL,
189 0xa6078084L, 0x19f8509eL, 0xe8efd855L, 0x61d99735L,
190 0xa969a7aaL, 0xc50c06c2L, 0x5a04abfcL, 0x800bcadcL,
191 0x9e447a2eL, 0xc3453484L, 0xfdd56705L, 0x0e1e9ec9L,
192 0xdb73dbd3L, 0x105588cdL, 0x675fda79L, 0xe3674340L,
193 0xc5c43465L, 0x713e38d8L, 0x3d28f89eL, 0xf16dff20L,
194 0x153e21e7L, 0x8fb03d4aL, 0xe6e39f2bL, 0xdb83adf7L,
195 0xe93d5a68L, 0x948140f7L, 0xf64c261cL, 0x94692934L,
196 0x411520f7L, 0x7602d4f7L, 0xbcf46b2eL, 0xd4a20068L,
197 0xd4082471L, 0x3320f46aL, 0x43b7d4b7L, 0x500061afL,
198 0x1e39f62eL, 0x97244546L, 0x14214f74L, 0xbf8b8840L,
199 0x4d95fc1dL, 0x96b591afL, 0x70f4ddd3L, 0x66a02f45L,
200 0xbfbc09ecL, 0x03bd9785L, 0x7fac6dd0L, 0x31cb8504L,
201 0x96eb27b3L, 0x55fd3941L, 0xda2547e6L, 0xabca0a9aL,
202 0x28507825L, 0x530429f4L, 0x0a2c86daL, 0xe9b66dfbL,
203 0x68dc1462L, 0xd7486900L, 0x680ec0a4L, 0x27a18deeL,
204 0x4f3ffea2L, 0xe887ad8cL, 0xb58ce006L, 0x7af4d6b6L,
205 0xaace1e7cL, 0xd3375fecL, 0xce78a399L, 0x406b2a42L,
206 0x20fe9e35L, 0xd9f385b9L, 0xee39d7abL, 0x3b124e8bL,
207 0x1dc9faf7L, 0x4b6d1856L, 0x26a36631L, 0xeae397b2L,
208 0x3a6efa74L, 0xdd5b4332L, 0x6841e7f7L, 0xca7820fbL,
209 0xfb0af54eL, 0xd8feb397L, 0x454056acL, 0xba489527L,
210 0x55533a3aL, 0x20838d87L, 0xfe6ba9b7L, 0xd096954bL,
211 0x55a867bcL, 0xa1159a58L, 0xcca92963L, 0x99e1db33L,
212 0xa62a4a56L, 0x3f3125f9L, 0x5ef47e1cL, 0x9029317cL,
213 0xfdf8e802L, 0x04272f70L, 0x80bb155cL, 0x05282ce3L,
214 0x95c11548L, 0xe4c66d22L, 0x48c1133fL, 0xc70f86dcL,
215 0x07f9c9eeL, 0x41041f0fL, 0x404779a4L, 0x5d886e17L,
216 0x325f51ebL, 0xd59bc0d1L, 0xf2bcc18fL, 0x41113564L,
217 0x257b7834L, 0x602a9c60L, 0xdff8e8a3L, 0x1f636c1bL,
218 0x0e12b4c2L, 0x02e1329eL, 0xaf664fd1L, 0xcad18115L,
219 0x6b2395e0L, 0x333e92e1L, 0x3b240b62L, 0xeebeb922L,
220 0x85b2a20eL, 0xe6ba0d99L, 0xde720c8cL, 0x2da2f728L,
221 0xd0127845L, 0x95b794fdL, 0x647d0862L, 0xe7ccf5f0L,
222 0x5449a36fL, 0x877d48faL, 0xc39dfd27L, 0xf33e8d1eL,
223 0x0a476341L, 0x992eff74L, 0x3a6f6eabL, 0xf4f8fd37L,
224 0xa812dc60L, 0xa1ebddf8L, 0x991be14cL, 0xdb6e6b0dL,
225 0xc67b5510L, 0x6d672c37L, 0x2765d43bL, 0xdcd0e804L,
226 0xf1290dc7L, 0xcc00ffa3L, 0xb5390f92L, 0x690fed0bL,
227 0x667b9ffbL, 0xcedb7d9cL, 0xa091cf0bL, 0xd9155ea3L,
228 0xbb132f88L, 0x515bad24L, 0x7b9479bfL, 0x763bd6ebL,
229 0x37392eb3L, 0xcc115979L, 0x8026e297L, 0xf42e312dL,
230 0x6842ada7L, 0xc66a2b3bL, 0x12754cccL, 0x782ef11cL,
231 0x6a124237L, 0xb79251e7L, 0x06a1bbe6L, 0x4bfb6350L,
232 0x1a6b1018L, 0x11caedfaL, 0x3d25bdd8L, 0xe2e1c3c9L,
233 0x44421659L, 0x0a121386L, 0xd90cec6eL, 0xd5abea2aL,
234 0x64af674eL, 0xda86a85fL, 0xbebfe988L, 0x64e4c3feL,
235 0x9dbc8057L, 0xf0f7c086L, 0x60787bf8L, 0x6003604dL,
236 0xd1fd8346L, 0xf6381fb0L, 0x7745ae04L, 0xd736fcccL,
237 0x83426b33L, 0xf01eab71L, 0xb0804187L, 0x3c005e5fL,
238 0x77a057beL, 0xbde8ae24L, 0x55464299L, 0xbf582e61L,
239 0x4e58f48fL, 0xf2ddfda2L, 0xf474ef38L, 0x8789bdc2L,
240 0x5366f9c3L, 0xc8b38e74L, 0xb475f255L, 0x46fcd9b9L,
241 0x7aeb2661L, 0x8b1ddf84L, 0x846a0e79L, 0x915f95e2L,
242 0x466e598eL, 0x20b45770L, 0x8cd55591L, 0xc902de4cL,
243 0xb90bace1L, 0xbb8205d0L, 0x11a86248L, 0x7574a99eL,
244 0xb77f19b6L, 0xe0a9dc09L, 0x662d09a1L, 0xc4324633L,
245 0xe85a1f02L, 0x09f0be8cL, 0x4a99a025L, 0x1d6efe10L,
246 0x1ab93d1dL, 0x0ba5a4dfL, 0xa186f20fL, 0x2868f169L,
247 0xdcb7da83L, 0x573906feL, 0xa1e2ce9bL, 0x4fcd7f52L,
248 0x50115e01L, 0xa70683faL, 0xa002b5c4L, 0x0de6d027L,
249 0x9af88c27L, 0x773f8641L, 0xc3604c06L, 0x61a806b5L,
250 0xf0177a28L, 0xc0f586e0L, 0x006058aaL, 0x30dc7d62L,
251 0x11e69ed7L, 0x2338ea63L, 0x53c2dd94L, 0xc2c21634L,
252 0xbbcbee56L, 0x90bcb6deL, 0xebfc7da1L, 0xce591d76L,
253 0x6f05e409L, 0x4b7c0188L, 0x39720a3dL, 0x7c927c24L,
254 0x86e3725fL, 0x724d9db9L, 0x1ac15bb4L, 0xd39eb8fcL,
255 0xed545578L, 0x08fca5b5L, 0xd83d7cd3L, 0x4dad0fc4L,
256 0x1e50ef5eL, 0xb161e6f8L, 0xa28514d9L, 0x6c51133cL,
257 0x6fd5c7e7L, 0x56e14ec4L, 0x362abfceL, 0xddc6c837L,
258 0xd79a3234L, 0x92638212L, 0x670efa8eL, 0x406000e0L,
259 0x3a39ce37L, 0xd3faf5cfL, 0xabc27737L, 0x5ac52d1bL,
260 0x5cb0679eL, 0x4fa33742L, 0xd3822740L, 0x99bc9bbeL,
261 0xd5118e9dL, 0xbf0f7315L, 0xd62d1c7eL, 0xc700c47bL,
262 0xb78c1b6bL, 0x21a19045L, 0xb26eb1beL, 0x6a366eb4L,
263 0x5748ab2fL, 0xbc946e79L, 0xc6a376d2L, 0x6549c2c8L,
264 0x530ff8eeL, 0x468dde7dL, 0xd5730a1dL, 0x4cd04dc6L,
265 0x2939bbdbL, 0xa9ba4650L, 0xac9526e8L, 0xbe5ee304L,
266 0xa1fad5f0L, 0x6a2d519aL, 0x63ef8ce2L, 0x9a86ee22L,
267 0xc089c2b8L, 0x43242ef6L, 0xa51e03aaL, 0x9cf2d0a4L,
268 0x83c061baL, 0x9be96a4dL, 0x8fe51550L, 0xba645bd6L,
269 0x2826a2f9L, 0xa73a3ae1L, 0x4ba99586L, 0xef5562e9L,
270 0xc72fefd3L, 0xf752f7daL, 0x3f046f69L, 0x77fa0a59L,
271 0x80e4a915L, 0x87b08601L, 0x9b09e6adL, 0x3b3ee593L,
272 0xe990fd5aL, 0x9e34d797L, 0x2cf0b7d9L, 0x022b8b51L,
273 0x96d5ac3aL, 0x017da67dL, 0xd1cf3ed6L, 0x7c7d2d28L,
274 0x1f9f25cfL, 0xadf2b89bL, 0x5ad6b472L, 0x5a88f54cL,
275 0xe029ac71L, 0xe019a5e6L, 0x47b0acfdL, 0xed93fa9bL,
276 0xe8d3c48dL, 0x283b57ccL, 0xf8d56629L, 0x79132e28L,
277 0x785f0191L, 0xed756055L, 0xf7960e44L, 0xe3d35e8cL,
278 0x15056dd4L, 0x88f46dbaL, 0x03a16125L, 0x0564f0bdL,
279 0xc3eb9e15L, 0x3c9057a2L, 0x97271aecL, 0xa93a072aL,
280 0x1b3f6d9bL, 0x1e6321f5L, 0xf59c66fbL, 0x26dcf319L,
281 0x7533d928L, 0xb155fdf5L, 0x03563482L, 0x8aba3cbbL,
282 0x28517711L, 0xc20ad9f8L, 0xabcc5167L, 0xccad925fL,
283 0x4de81751L, 0x3830dc8eL, 0x379d5862L, 0x9320f991L,
284 0xea7a90c2L, 0xfb3e7bceL, 0x5121ce64L, 0x774fbe32L,
285 0xa8b6e37eL, 0xc3293d46L, 0x48de5369L, 0x6413e680L,
286 0xa2ae0810L, 0xdd6db224L, 0x69852dfdL, 0x09072166L,
287 0xb39a460aL, 0x6445c0ddL, 0x586cdecfL, 0x1c20c8aeL,
288 0x5bbef7ddL, 0x1b588d40L, 0xccd2017fL, 0x6bb4e3bbL,
289 0xdda26a7eL, 0x3a59ff45L, 0x3e350a44L, 0xbcb4cdd5L,
290 0x72eacea8L, 0xfa6484bbL, 0x8d6612aeL, 0xbf3c6f47L,
291 0xd29be463L, 0x542f5d9eL, 0xaec2771bL, 0xf64e6370L,
292 0x740e0d8dL, 0xe75b1357L, 0xf8721671L, 0xaf537d5dL,
293 0x4040cb08L, 0x4eb4e2ccL, 0x34d2466aL, 0x0115af84L,
294 0xe1b00428L, 0x95983a1dL, 0x06b89fb4L, 0xce6ea048L,
295 0x6f3f3b82L, 0x3520ab82L, 0x011a1d4bL, 0x277227f8L,
296 0x611560b1L, 0xe7933fdcL, 0xbb3a792bL, 0x344525bdL,
297 0xa08839e1L, 0x51ce794bL, 0x2f32c9b7L, 0xa01fbac9L,
298 0xe01cc87eL, 0xbcc7d1f6L, 0xcf0111c3L, 0xa1e8aac7L,
299 0x1a908749L, 0xd44fbd9aL, 0xd0dadecbL, 0xd50ada38L,
300 0x0339c32aL, 0xc6913667L, 0x8df9317cL, 0xe0b12b4fL,
301 0xf79e59b7L, 0x43f5bb3aL, 0xf2d519ffL, 0x27d9459cL,
302 0xbf97222cL, 0x15e6fc2aL, 0x0f91fc71L, 0x9b941525L,
303 0xfae59361L, 0xceb69cebL, 0xc2a86459L, 0x12baa8d1L,
304 0xb6c1075eL, 0xe3056a0cL, 0x10d25065L, 0xcb03a442L,
305 0xe0ec6e0eL, 0x1698db3bL, 0x4c98a0beL, 0x3278e964L,
306 0x9f1f9532L, 0xe0d392dfL, 0xd3a0342bL, 0x8971f21eL,
307 0x1b0a7441L, 0x4ba3348cL, 0xc5be7120L, 0xc37632d8L,
308 0xdf359f8dL, 0x9b992f2eL, 0xe60b6f47L, 0x0fe3f11dL,
309 0xe54cda54L, 0x1edad891L, 0xce6279cfL, 0xcd3e7e6fL,
310 0x1618b166L, 0xfd2c1d05L, 0x848fd2c5L, 0xf6fb2299L,
311 0xf523f357L, 0xa6327623L, 0x93a83531L, 0x56cccd02L,
312 0xacf08162L, 0x5a75ebb5L, 0x6e163697L, 0x88d273ccL,
313 0xde966292L, 0x81b949d0L, 0x4c50901bL, 0x71c65614L,
314 0xe6c6c7bdL, 0x327a140aL, 0x45e1d006L, 0xc3f27b9aL,
315 0xc9aa53fdL, 0x62a80f00L, 0xbb25bfe2L, 0x35bdd2f6L,
316 0x71126905L, 0xb2040222L, 0xb6cbcf7cL, 0xcd769c2bL,
317 0x53113ec0L, 0x1640e3d3L, 0x38abbd60L, 0x2547adf0L,
318 0xba38209cL, 0xf746ce76L, 0x77afa1c5L, 0x20756060L,
319 0x85cbfe4eL, 0x8ae88dd8L, 0x7aaaf9b0L, 0x4cf9aa7eL,
320 0x1948c25cL, 0x02fb8a8cL, 0x01c36ae4L, 0xd6ebe1f9L,
321 0x90d4f869L, 0xa65cdea0L, 0x3f09252dL, 0xc208e69fL,
322 0xb74e6132L, 0xce77e25bL, 0x578fdfe3L, 0x3ac372e6L,
323 }
324 };
325
diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c
new file mode 100644
index 0000000000..fc5bebefce
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_skey.c
@@ -0,0 +1,117 @@
1/* crypto/bf/bf_skey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/crypto.h>
62#include <openssl/blowfish.h>
63#include "bf_locl.h"
64#include "bf_pi.h"
65
66FIPS_NON_FIPS_VCIPHER_Init(BF)
67 {
68 int i;
69 BF_LONG *p,ri,in[2];
70 const unsigned char *d,*end;
71
72
73 memcpy(key,&bf_init,sizeof(BF_KEY));
74 p=key->P;
75
76 if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
77
78 d=data;
79 end= &(data[len]);
80 for (i=0; i<(BF_ROUNDS+2); i++)
81 {
82 ri= *(d++);
83 if (d >= end) d=data;
84
85 ri<<=8;
86 ri|= *(d++);
87 if (d >= end) d=data;
88
89 ri<<=8;
90 ri|= *(d++);
91 if (d >= end) d=data;
92
93 ri<<=8;
94 ri|= *(d++);
95 if (d >= end) d=data;
96
97 p[i]^=ri;
98 }
99
100 in[0]=0L;
101 in[1]=0L;
102 for (i=0; i<(BF_ROUNDS+2); i+=2)
103 {
104 BF_encrypt(in,key);
105 p[i ]=in[0];
106 p[i+1]=in[1];
107 }
108
109 p=key->S;
110 for (i=0; i<4*256; i+=2)
111 {
112 BF_encrypt(in,key);
113 p[i ]=in[0];
114 p[i+1]=in[1];
115 }
116 }
117
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
new file mode 100644
index 0000000000..b4d8774961
--- /dev/null
+++ b/src/lib/libcrypto/bf/blowfish.h
@@ -0,0 +1,130 @@
1/* crypto/bf/blowfish.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BLOWFISH_H
60#define HEADER_BLOWFISH_H
61
62#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_BF
69#error BF is disabled.
70#endif
71
72#define BF_ENCRYPT 1
73#define BF_DECRYPT 0
74
75/*
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 * ! BF_LONG has to be at least 32 bits wide. If it's wider, then !
78 * ! BF_LONG_LOG2 has to be defined along. !
79 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80 */
81
82#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
83#define BF_LONG unsigned long
84#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
85#define BF_LONG unsigned long
86#define BF_LONG_LOG2 3
87/*
88 * _CRAY note. I could declare short, but I have no idea what impact
89 * does it have on performance on none-T3E machines. I could declare
90 * int, but at least on C90 sizeof(int) can be chosen at compile time.
91 * So I've chosen long...
92 * <appro@fy.chalmers.se>
93 */
94#else
95#define BF_LONG unsigned int
96#endif
97
98#define BF_ROUNDS 16
99#define BF_BLOCK 8
100
101typedef struct bf_key_st
102 {
103 BF_LONG P[BF_ROUNDS+2];
104 BF_LONG S[4*256];
105 } BF_KEY;
106
107
108#ifdef OPENSSL_FIPS
109void private_BF_set_key(BF_KEY *key, int len, const unsigned char *data);
110#endif
111void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
112
113void BF_encrypt(BF_LONG *data,const BF_KEY *key);
114void BF_decrypt(BF_LONG *data,const BF_KEY *key);
115
116void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
117 const BF_KEY *key, int enc);
118void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
119 const BF_KEY *schedule, unsigned char *ivec, int enc);
120void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
121 const BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
122void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
123 const BF_KEY *schedule, unsigned char *ivec, int *num);
124const char *BF_options(void);
125
126#ifdef __cplusplus
127}
128#endif
129
130#endif
diff --git a/src/lib/libcrypto/bio/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
new file mode 100644
index 0000000000..f671e722fa
--- /dev/null
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -0,0 +1,156 @@
1/* crypto/bio/b_dump.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 * Stolen from tjh's ssl/ssl_trc.c stuff.
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#define TRUNCATE
68#define DUMP_WIDTH 16
69#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
70
71int BIO_dump(BIO *bio, const char *s, int len)
72 {
73 return BIO_dump_indent(bio, s, len, 0);
74 }
75
76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
77 {
78 int ret=0;
79 char buf[288+1],tmp[20],str[128+1];
80 int i,j,rows,trunc;
81 unsigned char ch;
82 int dump_width;
83
84 trunc=0;
85
86#ifdef TRUNCATE
87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
88 trunc++;
89#endif
90
91 if (indent < 0)
92 indent = 0;
93 if (indent)
94 {
95 if (indent > 128) indent=128;
96 memset(str,' ',indent);
97 }
98 str[indent]='\0';
99
100 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
101 rows=(len/dump_width);
102 if ((rows*dump_width)<len)
103 rows++;
104 for(i=0;i<rows;i++)
105 {
106 buf[0]='\0'; /* start with empty string */
107 BUF_strlcpy(buf,str,sizeof buf);
108 BIO_snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width);
109 BUF_strlcat(buf,tmp,sizeof buf);
110 for(j=0;j<dump_width;j++)
111 {
112 if (((i*dump_width)+j)>=len)
113 {
114 BUF_strlcat(buf," ",sizeof buf);
115 }
116 else
117 {
118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
119 BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch,
120 j==7?'-':' ');
121 BUF_strlcat(buf,tmp,sizeof buf);
122 }
123 }
124 BUF_strlcat(buf," ",sizeof buf);
125 for(j=0;j<dump_width;j++)
126 {
127 if (((i*dump_width)+j)>=len)
128 break;
129 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
130#ifndef CHARSET_EBCDIC
131 BIO_snprintf(tmp,sizeof tmp,"%c",
132 ((ch>=' ')&&(ch<='~'))?ch:'.');
133#else
134 BIO_snprintf(tmp,sizeof tmp,"%c",
135 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
136 ? os_toebcdic[ch]
137 : '.');
138#endif
139 BUF_strlcat(buf,tmp,sizeof buf);
140 }
141 BUF_strlcat(buf,"\n",sizeof buf);
142 /* if this is the last call then update the ddt_dump thing so that
143 * we will move the selection point in the debug window
144 */
145 ret+=BIO_write(bio,(char *)buf,strlen(buf));
146 }
147#ifdef TRUNCATE
148 if (trunc > 0)
149 {
150 BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
151 len+trunc);
152 ret+=BIO_write(bio,(char *)buf,strlen(buf));
153 }
154#endif
155 return(ret);
156 }
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
new file mode 100644
index 0000000000..8b753e7ca0
--- /dev/null
+++ b/src/lib/libcrypto/bio/b_print.c
@@ -0,0 +1,841 @@
1/* crypto/bio/b_print.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* disable assert() unless BIO_DEBUG has been defined */
60#ifndef BIO_DEBUG
61# ifndef NDEBUG
62# define NDEBUG
63# endif
64#endif
65
66/*
67 * Stolen from tjh's ssl/ssl_trc.c stuff.
68 */
69
70#include <stdio.h>
71#include <string.h>
72#include <ctype.h>
73#include <assert.h>
74#include <limits.h>
75#include "cryptlib.h"
76#ifndef NO_SYS_TYPES_H
77#include <sys/types.h>
78#endif
79#include <openssl/bn.h> /* To get BN_LLONG properly defined */
80#include <openssl/bio.h>
81
82#ifdef BN_LLONG
83# ifndef HAVE_LONG_LONG
84# define HAVE_LONG_LONG 1
85# endif
86#endif
87
88/***************************************************************************/
89
90/*
91 * Copyright Patrick Powell 1995
92 * This code is based on code written by Patrick Powell <papowell@astart.com>
93 * It may be used for any purpose as long as this notice remains intact
94 * on all source code distributions.
95 */
96
97/*
98 * This code contains numerious changes and enhancements which were
99 * made by lots of contributors over the last years to Patrick Powell's
100 * original code:
101 *
102 * o Patrick Powell <papowell@astart.com> (1995)
103 * o Brandon Long <blong@fiction.net> (1996, for Mutt)
104 * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
105 * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
106 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
107 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
108 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
109 * o ... (for OpenSSL)
110 */
111
112#ifdef HAVE_LONG_DOUBLE
113#define LDOUBLE long double
114#else
115#define LDOUBLE double
116#endif
117
118#if HAVE_LONG_LONG
119# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
120# define LLONG _int64
121# else
122# define LLONG long long
123# endif
124#else
125#define LLONG long
126#endif
127
128static void fmtstr (char **, char **, size_t *, size_t *,
129 const char *, int, int, int);
130static void fmtint (char **, char **, size_t *, size_t *,
131 LLONG, int, int, int, int);
132static void fmtfp (char **, char **, size_t *, size_t *,
133 LDOUBLE, int, int, int);
134static void doapr_outch (char **, char **, size_t *, size_t *, int);
135static void _dopr(char **sbuffer, char **buffer,
136 size_t *maxlen, size_t *retlen, int *truncated,
137 const char *format, va_list args);
138
139/* format read states */
140#define DP_S_DEFAULT 0
141#define DP_S_FLAGS 1
142#define DP_S_MIN 2
143#define DP_S_DOT 3
144#define DP_S_MAX 4
145#define DP_S_MOD 5
146#define DP_S_CONV 6
147#define DP_S_DONE 7
148
149/* format flags - Bits */
150#define DP_F_MINUS (1 << 0)
151#define DP_F_PLUS (1 << 1)
152#define DP_F_SPACE (1 << 2)
153#define DP_F_NUM (1 << 3)
154#define DP_F_ZERO (1 << 4)
155#define DP_F_UP (1 << 5)
156#define DP_F_UNSIGNED (1 << 6)
157
158/* conversion flags */
159#define DP_C_SHORT 1
160#define DP_C_LONG 2
161#define DP_C_LDOUBLE 3
162#define DP_C_LLONG 4
163
164/* some handy macros */
165#define char_to_int(p) (p - '0')
166#define OSSL_MAX(p,q) ((p >= q) ? p : q)
167
168static void
169_dopr(
170 char **sbuffer,
171 char **buffer,
172 size_t *maxlen,
173 size_t *retlen,
174 int *truncated,
175 const char *format,
176 va_list args)
177{
178 char ch;
179 LLONG value;
180 LDOUBLE fvalue;
181 char *strvalue;
182 int min;
183 int max;
184 int state;
185 int flags;
186 int cflags;
187 size_t currlen;
188
189 state = DP_S_DEFAULT;
190 flags = currlen = cflags = min = 0;
191 max = -1;
192 ch = *format++;
193
194 while (state != DP_S_DONE) {
195 if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
196 state = DP_S_DONE;
197
198 switch (state) {
199 case DP_S_DEFAULT:
200 if (ch == '%')
201 state = DP_S_FLAGS;
202 else
203 doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
204 ch = *format++;
205 break;
206 case DP_S_FLAGS:
207 switch (ch) {
208 case '-':
209 flags |= DP_F_MINUS;
210 ch = *format++;
211 break;
212 case '+':
213 flags |= DP_F_PLUS;
214 ch = *format++;
215 break;
216 case ' ':
217 flags |= DP_F_SPACE;
218 ch = *format++;
219 break;
220 case '#':
221 flags |= DP_F_NUM;
222 ch = *format++;
223 break;
224 case '0':
225 flags |= DP_F_ZERO;
226 ch = *format++;
227 break;
228 default:
229 state = DP_S_MIN;
230 break;
231 }
232 break;
233 case DP_S_MIN:
234 if (isdigit((unsigned char)ch)) {
235 min = 10 * min + char_to_int(ch);
236 ch = *format++;
237 } else if (ch == '*') {
238 min = va_arg(args, int);
239 ch = *format++;
240 state = DP_S_DOT;
241 } else
242 state = DP_S_DOT;
243 break;
244 case DP_S_DOT:
245 if (ch == '.') {
246 state = DP_S_MAX;
247 ch = *format++;
248 } else
249 state = DP_S_MOD;
250 break;
251 case DP_S_MAX:
252 if (isdigit((unsigned char)ch)) {
253 if (max < 0)
254 max = 0;
255 max = 10 * max + char_to_int(ch);
256 ch = *format++;
257 } else if (ch == '*') {
258 max = va_arg(args, int);
259 ch = *format++;
260 state = DP_S_MOD;
261 } else
262 state = DP_S_MOD;
263 break;
264 case DP_S_MOD:
265 switch (ch) {
266 case 'h':
267 cflags = DP_C_SHORT;
268 ch = *format++;
269 break;
270 case 'l':
271 if (*format == 'l') {
272 cflags = DP_C_LLONG;
273 format++;
274 } else
275 cflags = DP_C_LONG;
276 ch = *format++;
277 break;
278 case 'q':
279 cflags = DP_C_LLONG;
280 ch = *format++;
281 break;
282 case 'L':
283 cflags = DP_C_LDOUBLE;
284 ch = *format++;
285 break;
286 default:
287 break;
288 }
289 state = DP_S_CONV;
290 break;
291 case DP_S_CONV:
292 switch (ch) {
293 case 'd':
294 case 'i':
295 switch (cflags) {
296 case DP_C_SHORT:
297 value = (short int)va_arg(args, int);
298 break;
299 case DP_C_LONG:
300 value = va_arg(args, long int);
301 break;
302 case DP_C_LLONG:
303 value = va_arg(args, LLONG);
304 break;
305 default:
306 value = va_arg(args, int);
307 break;
308 }
309 fmtint(sbuffer, buffer, &currlen, maxlen,
310 value, 10, min, max, flags);
311 break;
312 case 'X':
313 flags |= DP_F_UP;
314 /* FALLTHROUGH */
315 case 'x':
316 case 'o':
317 case 'u':
318 flags |= DP_F_UNSIGNED;
319 switch (cflags) {
320 case DP_C_SHORT:
321 value = (unsigned short int)va_arg(args, unsigned int);
322 break;
323 case DP_C_LONG:
324 value = (LLONG) va_arg(args,
325 unsigned long int);
326 break;
327 case DP_C_LLONG:
328 value = va_arg(args, unsigned LLONG);
329 break;
330 default:
331 value = (LLONG) va_arg(args,
332 unsigned int);
333 break;
334 }
335 fmtint(sbuffer, buffer, &currlen, maxlen, value,
336 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
337 min, max, flags);
338 break;
339 case 'f':
340 if (cflags == DP_C_LDOUBLE)
341 fvalue = va_arg(args, LDOUBLE);
342 else
343 fvalue = va_arg(args, double);
344 fmtfp(sbuffer, buffer, &currlen, maxlen,
345 fvalue, min, max, flags);
346 break;
347 case 'E':
348 flags |= DP_F_UP;
349 case 'e':
350 if (cflags == DP_C_LDOUBLE)
351 fvalue = va_arg(args, LDOUBLE);
352 else
353 fvalue = va_arg(args, double);
354 break;
355 case 'G':
356 flags |= DP_F_UP;
357 case 'g':
358 if (cflags == DP_C_LDOUBLE)
359 fvalue = va_arg(args, LDOUBLE);
360 else
361 fvalue = va_arg(args, double);
362 break;
363 case 'c':
364 doapr_outch(sbuffer, buffer, &currlen, maxlen,
365 va_arg(args, int));
366 break;
367 case 's':
368 strvalue = va_arg(args, char *);
369 if (max < 0) {
370 if (buffer)
371 max = INT_MAX;
372 else
373 max = *maxlen;
374 }
375 fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
376 flags, min, max);
377 break;
378 case 'p':
379 value = (long)va_arg(args, void *);
380 fmtint(sbuffer, buffer, &currlen, maxlen,
381 value, 16, min, max, flags|DP_F_NUM);
382 break;
383 case 'n': /* XXX */
384 if (cflags == DP_C_SHORT) {
385 short int *num;
386 num = va_arg(args, short int *);
387 *num = currlen;
388 } else if (cflags == DP_C_LONG) { /* XXX */
389 long int *num;
390 num = va_arg(args, long int *);
391 *num = (long int) currlen;
392 } else if (cflags == DP_C_LLONG) { /* XXX */
393 LLONG *num;
394 num = va_arg(args, LLONG *);
395 *num = (LLONG) currlen;
396 } else {
397 int *num;
398 num = va_arg(args, int *);
399 *num = currlen;
400 }
401 break;
402 case '%':
403 doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
404 break;
405 case 'w':
406 /* not supported yet, treat as next char */
407 ch = *format++;
408 break;
409 default:
410 /* unknown, skip */
411 break;
412 }
413 ch = *format++;
414 state = DP_S_DEFAULT;
415 flags = cflags = min = 0;
416 max = -1;
417 break;
418 case DP_S_DONE:
419 break;
420 default:
421 break;
422 }
423 }
424 *truncated = (currlen > *maxlen - 1);
425 if (*truncated)
426 currlen = *maxlen - 1;
427 doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
428 *retlen = currlen - 1;
429 return;
430}
431
432static void
433fmtstr(
434 char **sbuffer,
435 char **buffer,
436 size_t *currlen,
437 size_t *maxlen,
438 const char *value,
439 int flags,
440 int min,
441 int max)
442{
443 int padlen, strln;
444 int cnt = 0;
445
446 if (value == 0)
447 value = "<NULL>";
448 for (strln = 0; value[strln]; ++strln)
449 ;
450 padlen = min - strln;
451 if (padlen < 0)
452 padlen = 0;
453 if (flags & DP_F_MINUS)
454 padlen = -padlen;
455
456 while ((padlen > 0) && (cnt < max)) {
457 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
458 --padlen;
459 ++cnt;
460 }
461 while (*value && (cnt < max)) {
462 doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
463 ++cnt;
464 }
465 while ((padlen < 0) && (cnt < max)) {
466 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
467 ++padlen;
468 ++cnt;
469 }
470}
471
472static void
473fmtint(
474 char **sbuffer,
475 char **buffer,
476 size_t *currlen,
477 size_t *maxlen,
478 LLONG value,
479 int base,
480 int min,
481 int max,
482 int flags)
483{
484 int signvalue = 0;
485 char *prefix = "";
486 unsigned LLONG uvalue;
487 char convert[DECIMAL_SIZE(value)+3];
488 int place = 0;
489 int spadlen = 0;
490 int zpadlen = 0;
491 int caps = 0;
492
493 if (max < 0)
494 max = 0;
495 uvalue = value;
496 if (!(flags & DP_F_UNSIGNED)) {
497 if (value < 0) {
498 signvalue = '-';
499 uvalue = -value;
500 } else if (flags & DP_F_PLUS)
501 signvalue = '+';
502 else if (flags & DP_F_SPACE)
503 signvalue = ' ';
504 }
505 if (flags & DP_F_NUM) {
506 if (base == 8) prefix = "0";
507 if (base == 16) prefix = "0x";
508 }
509 if (flags & DP_F_UP)
510 caps = 1;
511 do {
512 convert[place++] =
513 (caps ? "0123456789ABCDEF" : "0123456789abcdef")
514 [uvalue % (unsigned) base];
515 uvalue = (uvalue / (unsigned) base);
516 } while (uvalue && (place < sizeof convert));
517 if (place == sizeof convert)
518 place--;
519 convert[place] = 0;
520
521 zpadlen = max - place;
522 spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);
523 if (zpadlen < 0)
524 zpadlen = 0;
525 if (spadlen < 0)
526 spadlen = 0;
527 if (flags & DP_F_ZERO) {
528 zpadlen = OSSL_MAX(zpadlen, spadlen);
529 spadlen = 0;
530 }
531 if (flags & DP_F_MINUS)
532 spadlen = -spadlen;
533
534 /* spaces */
535 while (spadlen > 0) {
536 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
537 --spadlen;
538 }
539
540 /* sign */
541 if (signvalue)
542 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
543
544 /* prefix */
545 while (*prefix) {
546 doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);
547 prefix++;
548 }
549
550 /* zeros */
551 if (zpadlen > 0) {
552 while (zpadlen > 0) {
553 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
554 --zpadlen;
555 }
556 }
557 /* digits */
558 while (place > 0)
559 doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
560
561 /* left justified spaces */
562 while (spadlen < 0) {
563 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
564 ++spadlen;
565 }
566 return;
567}
568
569static LDOUBLE
570abs_val(LDOUBLE value)
571{
572 LDOUBLE result = value;
573 if (value < 0)
574 result = -value;
575 return result;
576}
577
578static LDOUBLE
579pow10(int in_exp)
580{
581 LDOUBLE result = 1;
582 while (in_exp) {
583 result *= 10;
584 in_exp--;
585 }
586 return result;
587}
588
589static long
590roundv(LDOUBLE value)
591{
592 long intpart;
593 intpart = (long) value;
594 value = value - intpart;
595 if (value >= 0.5)
596 intpart++;
597 return intpart;
598}
599
600static void
601fmtfp(
602 char **sbuffer,
603 char **buffer,
604 size_t *currlen,
605 size_t *maxlen,
606 LDOUBLE fvalue,
607 int min,
608 int max,
609 int flags)
610{
611 int signvalue = 0;
612 LDOUBLE ufvalue;
613 char iconvert[20];
614 char fconvert[20];
615 int iplace = 0;
616 int fplace = 0;
617 int padlen = 0;
618 int zpadlen = 0;
619 int caps = 0;
620 long intpart;
621 long fracpart;
622
623 if (max < 0)
624 max = 6;
625 ufvalue = abs_val(fvalue);
626 if (fvalue < 0)
627 signvalue = '-';
628 else if (flags & DP_F_PLUS)
629 signvalue = '+';
630 else if (flags & DP_F_SPACE)
631 signvalue = ' ';
632
633 intpart = (long)ufvalue;
634
635 /* sorry, we only support 9 digits past the decimal because of our
636 conversion method */
637 if (max > 9)
638 max = 9;
639
640 /* we "cheat" by converting the fractional part to integer by
641 multiplying by a factor of 10 */
642 fracpart = roundv((pow10(max)) * (ufvalue - intpart));
643
644 if (fracpart >= (long)pow10(max)) {
645 intpart++;
646 fracpart -= (long)pow10(max);
647 }
648
649 /* convert integer part */
650 do {
651 iconvert[iplace++] =
652 (caps ? "0123456789ABCDEF"
653 : "0123456789abcdef")[intpart % 10];
654 intpart = (intpart / 10);
655 } while (intpart && (iplace < sizeof iconvert));
656 if (iplace == sizeof iconvert)
657 iplace--;
658 iconvert[iplace] = 0;
659
660 /* convert fractional part */
661 do {
662 fconvert[fplace++] =
663 (caps ? "0123456789ABCDEF"
664 : "0123456789abcdef")[fracpart % 10];
665 fracpart = (fracpart / 10);
666 } while (fplace < max);
667 if (fplace == sizeof fconvert)
668 fplace--;
669 fconvert[fplace] = 0;
670
671 /* -1 for decimal point, another -1 if we are printing a sign */
672 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
673 zpadlen = max - fplace;
674 if (zpadlen < 0)
675 zpadlen = 0;
676 if (padlen < 0)
677 padlen = 0;
678 if (flags & DP_F_MINUS)
679 padlen = -padlen;
680
681 if ((flags & DP_F_ZERO) && (padlen > 0)) {
682 if (signvalue) {
683 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
684 --padlen;
685 signvalue = 0;
686 }
687 while (padlen > 0) {
688 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
689 --padlen;
690 }
691 }
692 while (padlen > 0) {
693 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
694 --padlen;
695 }
696 if (signvalue)
697 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
698
699 while (iplace > 0)
700 doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
701
702 /*
703 * Decimal point. This should probably use locale to find the correct
704 * char to print out.
705 */
706 if (max > 0 || (flags & DP_F_NUM)) {
707 doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
708
709 while (fplace > 0)
710 doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
711 }
712 while (zpadlen > 0) {
713 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
714 --zpadlen;
715 }
716
717 while (padlen < 0) {
718 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
719 ++padlen;
720 }
721}
722
723static void
724doapr_outch(
725 char **sbuffer,
726 char **buffer,
727 size_t *currlen,
728 size_t *maxlen,
729 int c)
730{
731 /* If we haven't at least one buffer, someone has doe a big booboo */
732 assert(*sbuffer != NULL || buffer != NULL);
733
734 if (buffer) {
735 while (*currlen >= *maxlen) {
736 if (*buffer == NULL) {
737 if (*maxlen == 0)
738 *maxlen = 1024;
739 *buffer = OPENSSL_malloc(*maxlen);
740 if (*currlen > 0) {
741 assert(*sbuffer != NULL);
742 memcpy(*buffer, *sbuffer, *currlen);
743 }
744 *sbuffer = NULL;
745 } else {
746 *maxlen += 1024;
747 *buffer = OPENSSL_realloc(*buffer, *maxlen);
748 }
749 }
750 /* What to do if *buffer is NULL? */
751 assert(*sbuffer != NULL || *buffer != NULL);
752 }
753
754 if (*currlen < *maxlen) {
755 if (*sbuffer)
756 (*sbuffer)[(*currlen)++] = (char)c;
757 else
758 (*buffer)[(*currlen)++] = (char)c;
759 }
760
761 return;
762}
763
764/***************************************************************************/
765
766int BIO_printf (BIO *bio, const char *format, ...)
767 {
768 va_list args;
769 int ret;
770
771 va_start(args, format);
772
773 ret = BIO_vprintf(bio, format, args);
774
775 va_end(args);
776 return(ret);
777 }
778
779int BIO_vprintf (BIO *bio, const char *format, va_list args)
780 {
781 int ret;
782 size_t retlen;
783 char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable
784 in small-stack environments, like threads
785 or DOS programs. */
786 char *hugebufp = hugebuf;
787 size_t hugebufsize = sizeof(hugebuf);
788 char *dynbuf = NULL;
789 int ignored;
790
791 dynbuf = NULL;
792 CRYPTO_push_info("doapr()");
793 _dopr(&hugebufp, &dynbuf, &hugebufsize,
794 &retlen, &ignored, format, args);
795 if (dynbuf)
796 {
797 ret=BIO_write(bio, dynbuf, (int)retlen);
798 OPENSSL_free(dynbuf);
799 }
800 else
801 {
802 ret=BIO_write(bio, hugebuf, (int)retlen);
803 }
804 CRYPTO_pop_info();
805 return(ret);
806 }
807
808/* As snprintf is not available everywhere, we provide our own implementation.
809 * In case of overflow or error, this returns -1.
810 * This function has nothing to do with BIOs, but it's closely related
811 * to BIO_printf, and we need *some* name prefix ...
812 * (XXX the function should be renamed, but to what?) */
813int BIO_snprintf(char *buf, size_t n, const char *format, ...)
814 {
815 va_list args;
816 int ret;
817
818 va_start(args, format);
819
820 ret = BIO_vsnprintf(buf, n, format, args);
821
822 va_end(args);
823 return(ret);
824 }
825
826int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
827 {
828 size_t retlen;
829 int truncated;
830
831 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
832
833 if (truncated)
834 /* In case of truncation, return -1 unlike traditional snprintf.
835 * (Current drafts for ISO/IEC 9899 say snprintf should return
836 * the number of characters that would have been written,
837 * had the buffer been large enough, as it did historically.) */
838 return -1;
839 else
840 return (retlen <= INT_MAX) ? (int)retlen : -1;
841 }
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
new file mode 100644
index 0000000000..c851298d1e
--- /dev/null
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -0,0 +1,752 @@
1/* crypto/bio/b_sock.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <errno.h>
64#define USE_SOCKETS
65#include "cryptlib.h"
66#include <openssl/bio.h>
67
68#ifdef OPENSSL_SYS_WIN16
69#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
70#else
71#define SOCKET_PROTOCOL IPPROTO_TCP
72#endif
73
74#ifdef SO_MAXCONN
75#define MAX_LISTEN SO_MAXCONN
76#elif defined(SOMAXCONN)
77#define MAX_LISTEN SOMAXCONN
78#else
79#define MAX_LISTEN 32
80#endif
81
82#ifdef OPENSSL_SYS_WINDOWS
83static int wsa_init_done=0;
84#endif
85
86#if 0
87static unsigned long BIO_ghbn_hits=0L;
88static unsigned long BIO_ghbn_miss=0L;
89
90#define GHBN_NUM 4
91static struct ghbn_cache_st
92 {
93 char name[129];
94 struct hostent *ent;
95 unsigned long order;
96 } ghbn_cache[GHBN_NUM];
97#endif
98
99static int get_ip(const char *str,unsigned char *ip);
100#if 0
101static void ghbn_free(struct hostent *a);
102static struct hostent *ghbn_dup(struct hostent *a);
103#endif
104int BIO_get_host_ip(const char *str, unsigned char *ip)
105 {
106 int i;
107 int err = 1;
108 int locked = 0;
109 struct hostent *he;
110
111 i=get_ip(str,ip);
112 if (i < 0)
113 {
114 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
115 goto err;
116 }
117
118 /* At this point, we have something that is most probably correct
119 in some way, so let's init the socket. */
120 if (BIO_sock_init() != 1)
121 return 0; /* don't generate another error code here */
122
123 /* If the string actually contained an IP address, we need not do
124 anything more */
125 if (i > 0) return(1);
126
127 /* do a gethostbyname */
128 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
129 locked = 1;
130 he=BIO_gethostbyname(str);
131 if (he == NULL)
132 {
133 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
134 goto err;
135 }
136
137 /* cast to short because of win16 winsock definition */
138 if ((short)he->h_addrtype != AF_INET)
139 {
140 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
141 goto err;
142 }
143 for (i=0; i<4; i++)
144 ip[i]=he->h_addr_list[0][i];
145 err = 0;
146
147 err:
148 if (locked)
149 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
150 if (err)
151 {
152 ERR_add_error_data(2,"host=",str);
153 return 0;
154 }
155 else
156 return 1;
157 }
158
159int BIO_get_port(const char *str, unsigned short *port_ptr)
160 {
161 int i;
162 struct servent *s;
163
164 if (str == NULL)
165 {
166 BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
167 return(0);
168 }
169 i=atoi(str);
170 if (i != 0)
171 *port_ptr=(unsigned short)i;
172 else
173 {
174 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
175 /* Note: under VMS with SOCKETSHR, it seems like the first
176 * parameter is 'char *', instead of 'const char *'
177 */
178 s=getservbyname(
179#ifndef CONST_STRICT
180 (char *)
181#endif
182 str,"tcp");
183 if(s != NULL)
184 *port_ptr=ntohs((unsigned short)s->s_port);
185 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
186 if(s == NULL)
187 {
188 if (strcmp(str,"http") == 0)
189 *port_ptr=80;
190 else if (strcmp(str,"telnet") == 0)
191 *port_ptr=23;
192 else if (strcmp(str,"socks") == 0)
193 *port_ptr=1080;
194 else if (strcmp(str,"https") == 0)
195 *port_ptr=443;
196 else if (strcmp(str,"ssl") == 0)
197 *port_ptr=443;
198 else if (strcmp(str,"ftp") == 0)
199 *port_ptr=21;
200 else if (strcmp(str,"gopher") == 0)
201 *port_ptr=70;
202#if 0
203 else if (strcmp(str,"wais") == 0)
204 *port_ptr=21;
205#endif
206 else
207 {
208 SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error());
209 ERR_add_error_data(3,"service='",str,"'");
210 return(0);
211 }
212 }
213 }
214 return(1);
215 }
216
217int BIO_sock_error(int sock)
218 {
219 int j,i;
220 int size;
221
222 size=sizeof(int);
223 /* Note: under Windows the third parameter is of type (char *)
224 * whereas under other systems it is (void *) if you don't have
225 * a cast it will choke the compiler: if you do have a cast then
226 * you can either go for (char *) or (void *).
227 */
228 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
229 if (i < 0)
230 return(1);
231 else
232 return(j);
233 }
234
235#if 0
236long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
237 {
238 int i;
239 char **p;
240
241 switch (cmd)
242 {
243 case BIO_GHBN_CTRL_HITS:
244 return(BIO_ghbn_hits);
245 /* break; */
246 case BIO_GHBN_CTRL_MISSES:
247 return(BIO_ghbn_miss);
248 /* break; */
249 case BIO_GHBN_CTRL_CACHE_SIZE:
250 return(GHBN_NUM);
251 /* break; */
252 case BIO_GHBN_CTRL_GET_ENTRY:
253 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
254 (ghbn_cache[iarg].order > 0))
255 {
256 p=(char **)parg;
257 if (p == NULL) return(0);
258 *p=ghbn_cache[iarg].name;
259 ghbn_cache[iarg].name[128]='\0';
260 return(1);
261 }
262 return(0);
263 /* break; */
264 case BIO_GHBN_CTRL_FLUSH:
265 for (i=0; i<GHBN_NUM; i++)
266 ghbn_cache[i].order=0;
267 break;
268 default:
269 return(0);
270 }
271 return(1);
272 }
273#endif
274
275#if 0
276static struct hostent *ghbn_dup(struct hostent *a)
277 {
278 struct hostent *ret;
279 int i,j;
280
281 MemCheck_off();
282 ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
283 if (ret == NULL) return(NULL);
284 memset(ret,0,sizeof(struct hostent));
285
286 for (i=0; a->h_aliases[i] != NULL; i++)
287 ;
288 i++;
289 ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
290 if (ret->h_aliases == NULL)
291 goto err;
292 memset(ret->h_aliases, 0, i*sizeof(char *));
293
294 for (i=0; a->h_addr_list[i] != NULL; i++)
295 ;
296 i++;
297 ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
298 if (ret->h_addr_list == NULL)
299 goto err;
300 memset(ret->h_addr_list, 0, i*sizeof(char *));
301
302 j=strlen(a->h_name)+1;
303 if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
304 memcpy((char *)ret->h_name,a->h_name,j);
305 for (i=0; a->h_aliases[i] != NULL; i++)
306 {
307 j=strlen(a->h_aliases[i])+1;
308 if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
309 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
310 }
311 ret->h_length=a->h_length;
312 ret->h_addrtype=a->h_addrtype;
313 for (i=0; a->h_addr_list[i] != NULL; i++)
314 {
315 if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
316 goto err;
317 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
318 }
319 if (0)
320 {
321err:
322 if (ret != NULL)
323 ghbn_free(ret);
324 ret=NULL;
325 }
326 MemCheck_on();
327 return(ret);
328 }
329
330static void ghbn_free(struct hostent *a)
331 {
332 int i;
333
334 if(a == NULL)
335 return;
336
337 if (a->h_aliases != NULL)
338 {
339 for (i=0; a->h_aliases[i] != NULL; i++)
340 OPENSSL_free(a->h_aliases[i]);
341 OPENSSL_free(a->h_aliases);
342 }
343 if (a->h_addr_list != NULL)
344 {
345 for (i=0; a->h_addr_list[i] != NULL; i++)
346 OPENSSL_free(a->h_addr_list[i]);
347 OPENSSL_free(a->h_addr_list);
348 }
349 if (a->h_name != NULL) OPENSSL_free(a->h_name);
350 OPENSSL_free(a);
351 }
352
353#endif
354
355struct hostent *BIO_gethostbyname(const char *name)
356 {
357#if 1
358 /* Caching gethostbyname() results forever is wrong,
359 * so we have to let the true gethostbyname() worry about this */
360 return gethostbyname(name);
361#else
362 struct hostent *ret;
363 int i,lowi=0,j;
364 unsigned long low= (unsigned long)-1;
365
366
367# if 0
368 /* It doesn't make sense to use locking here: The function interface
369 * is not thread-safe, because threads can never be sure when
370 * some other thread destroys the data they were given a pointer to.
371 */
372 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
373# endif
374 j=strlen(name);
375 if (j < 128)
376 {
377 for (i=0; i<GHBN_NUM; i++)
378 {
379 if (low > ghbn_cache[i].order)
380 {
381 low=ghbn_cache[i].order;
382 lowi=i;
383 }
384 if (ghbn_cache[i].order > 0)
385 {
386 if (strncmp(name,ghbn_cache[i].name,128) == 0)
387 break;
388 }
389 }
390 }
391 else
392 i=GHBN_NUM;
393
394 if (i == GHBN_NUM) /* no hit*/
395 {
396 BIO_ghbn_miss++;
397 /* Note: under VMS with SOCKETSHR, it seems like the first
398 * parameter is 'char *', instead of 'const char *'
399 */
400 ret=gethostbyname(
401# ifndef CONST_STRICT
402 (char *)
403# endif
404 name);
405
406 if (ret == NULL)
407 goto end;
408 if (j > 128) /* too big to cache */
409 {
410# if 0
411 /* If we were trying to make this function thread-safe (which
412 * is bound to fail), we'd have to give up in this case
413 * (or allocate more memory). */
414 ret = NULL;
415# endif
416 goto end;
417 }
418
419 /* else add to cache */
420 if (ghbn_cache[lowi].ent != NULL)
421 ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
422 ghbn_cache[lowi].name[0] = '\0';
423
424 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
425 {
426 BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
427 goto end;
428 }
429 strncpy(ghbn_cache[lowi].name,name,128);
430 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
431 }
432 else
433 {
434 BIO_ghbn_hits++;
435 ret= ghbn_cache[i].ent;
436 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
437 }
438end:
439# if 0
440 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
441# endif
442 return(ret);
443#endif
444 }
445
446
447int BIO_sock_init(void)
448 {
449#ifdef OPENSSL_SYS_WINDOWS
450 static struct WSAData wsa_state;
451
452 if (!wsa_init_done)
453 {
454 int err;
455
456#ifdef SIGINT
457 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
458#endif
459 wsa_init_done=1;
460 memset(&wsa_state,0,sizeof(wsa_state));
461 if (WSAStartup(0x0101,&wsa_state)!=0)
462 {
463 err=WSAGetLastError();
464 SYSerr(SYS_F_WSASTARTUP,err);
465 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
466 return(-1);
467 }
468 }
469#endif /* OPENSSL_SYS_WINDOWS */
470#ifdef WATT32
471 extern int _watt_do_exit;
472 _watt_do_exit = 0; /* don't make sock_init() call exit() */
473 if (sock_init())
474 return (-1);
475#endif
476 return(1);
477 }
478
479void BIO_sock_cleanup(void)
480 {
481#ifdef OPENSSL_SYS_WINDOWS
482 if (wsa_init_done)
483 {
484 wsa_init_done=0;
485#ifndef OPENSSL_SYS_WINCE
486 WSACancelBlockingCall();
487#endif
488 WSACleanup();
489 }
490#endif
491 }
492
493#if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000
494
495int BIO_socket_ioctl(int fd, long type, void *arg)
496 {
497 int i;
498
499#ifdef __DJGPP__
500 i=ioctlsocket(fd,type,(char *)arg);
501#else
502 i=ioctlsocket(fd,type,arg);
503#endif /* __DJGPP__ */
504 if (i < 0)
505 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
506 return(i);
507 }
508#endif /* __VMS_VER */
509
510/* The reason I have implemented this instead of using sscanf is because
511 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
512static int get_ip(const char *str, unsigned char ip[4])
513 {
514 unsigned int tmp[4];
515 int num=0,c,ok=0;
516
517 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
518
519 for (;;)
520 {
521 c= *(str++);
522 if ((c >= '0') && (c <= '9'))
523 {
524 ok=1;
525 tmp[num]=tmp[num]*10+c-'0';
526 if (tmp[num] > 255) return(0);
527 }
528 else if (c == '.')
529 {
530 if (!ok) return(-1);
531 if (num == 3) return(0);
532 num++;
533 ok=0;
534 }
535 else if (c == '\0' && (num == 3) && ok)
536 break;
537 else
538 return(0);
539 }
540 ip[0]=tmp[0];
541 ip[1]=tmp[1];
542 ip[2]=tmp[2];
543 ip[3]=tmp[3];
544 return(1);
545 }
546
547int BIO_get_accept_socket(char *host, int bind_mode)
548 {
549 int ret=0;
550 struct sockaddr_in server,client;
551 int s=INVALID_SOCKET,cs;
552 unsigned char ip[4];
553 unsigned short port;
554 char *str=NULL,*e;
555 const char *h,*p;
556 unsigned long l;
557 int err_num;
558
559 if (BIO_sock_init() != 1) return(INVALID_SOCKET);
560
561 if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
562
563 h=p=NULL;
564 h=str;
565 for (e=str; *e; e++)
566 {
567 if (*e == ':')
568 {
569 p= &(e[1]);
570 *e='\0';
571 }
572 else if (*e == '/')
573 {
574 *e='\0';
575 break;
576 }
577 }
578
579 if (p == NULL)
580 {
581 p=h;
582 h="*";
583 }
584
585 if (!BIO_get_port(p,&port)) goto err;
586
587 memset((char *)&server,0,sizeof(server));
588 server.sin_family=AF_INET;
589 server.sin_port=htons(port);
590
591 if (strcmp(h,"*") == 0)
592 server.sin_addr.s_addr=INADDR_ANY;
593 else
594 {
595 if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
596 l=(unsigned long)
597 ((unsigned long)ip[0]<<24L)|
598 ((unsigned long)ip[1]<<16L)|
599 ((unsigned long)ip[2]<< 8L)|
600 ((unsigned long)ip[3]);
601 server.sin_addr.s_addr=htonl(l);
602 }
603
604again:
605 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
606 if (s == INVALID_SOCKET)
607 {
608 SYSerr(SYS_F_SOCKET,get_last_socket_error());
609 ERR_add_error_data(3,"port='",host,"'");
610 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
611 goto err;
612 }
613
614#ifdef SO_REUSEADDR
615 if (bind_mode == BIO_BIND_REUSEADDR)
616 {
617 int i=1;
618
619 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
620 bind_mode=BIO_BIND_NORMAL;
621 }
622#endif
623 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
624 {
625#ifdef SO_REUSEADDR
626 err_num=get_last_socket_error();
627 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
628 (err_num == EADDRINUSE))
629 {
630 memcpy((char *)&client,(char *)&server,sizeof(server));
631 if (strcmp(h,"*") == 0)
632 client.sin_addr.s_addr=htonl(0x7F000001);
633 cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
634 if (cs != INVALID_SOCKET)
635 {
636 int ii;
637 ii=connect(cs,(struct sockaddr *)&client,
638 sizeof(client));
639 closesocket(cs);
640 if (ii == INVALID_SOCKET)
641 {
642 bind_mode=BIO_BIND_REUSEADDR;
643 closesocket(s);
644 goto again;
645 }
646 /* else error */
647 }
648 /* else error */
649 }
650#endif
651 SYSerr(SYS_F_BIND,err_num);
652 ERR_add_error_data(3,"port='",host,"'");
653 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
654 goto err;
655 }
656 if (listen(s,MAX_LISTEN) == -1)
657 {
658 SYSerr(SYS_F_BIND,get_last_socket_error());
659 ERR_add_error_data(3,"port='",host,"'");
660 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
661 goto err;
662 }
663 ret=1;
664err:
665 if (str != NULL) OPENSSL_free(str);
666 if ((ret == 0) && (s != INVALID_SOCKET))
667 {
668 closesocket(s);
669 s= INVALID_SOCKET;
670 }
671 return(s);
672 }
673
674int BIO_accept(int sock, char **addr)
675 {
676 int ret=INVALID_SOCKET;
677 static struct sockaddr_in from;
678 unsigned long l;
679 unsigned short port;
680 int len;
681 char *p;
682
683 memset((char *)&from,0,sizeof(from));
684 len=sizeof(from);
685 /* Note: under VMS with SOCKETSHR the fourth parameter is currently
686 * of type (int *) whereas under other systems it is (void *) if
687 * you don't have a cast it will choke the compiler: if you do
688 * have a cast then you can either go for (int *) or (void *).
689 */
690 ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
691 if (ret == INVALID_SOCKET)
692 {
693 if(BIO_sock_should_retry(ret)) return -2;
694 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
695 BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
696 goto end;
697 }
698
699 if (addr == NULL) goto end;
700
701 l=ntohl(from.sin_addr.s_addr);
702 port=ntohs(from.sin_port);
703 if (*addr == NULL)
704 {
705 if ((p=OPENSSL_malloc(24)) == NULL)
706 {
707 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
708 goto end;
709 }
710 *addr=p;
711 }
712 BIO_snprintf(*addr,24,"%d.%d.%d.%d:%d",
713 (unsigned char)(l>>24L)&0xff,
714 (unsigned char)(l>>16L)&0xff,
715 (unsigned char)(l>> 8L)&0xff,
716 (unsigned char)(l )&0xff,
717 port);
718end:
719 return(ret);
720 }
721
722int BIO_set_tcp_ndelay(int s, int on)
723 {
724 int ret=0;
725#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
726 int opt;
727
728#ifdef SOL_TCP
729 opt=SOL_TCP;
730#else
731#ifdef IPPROTO_TCP
732 opt=IPPROTO_TCP;
733#endif
734#endif
735
736 ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
737#endif
738 return(ret == 0);
739 }
740#endif
741
742int BIO_socket_nbio(int s, int mode)
743 {
744 int ret= -1;
745 int l;
746
747 l=mode;
748#ifdef FIONBIO
749 ret=BIO_socket_ioctl(s,FIONBIO,&l);
750#endif
751 return(ret == 0);
752 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
new file mode 100644
index 0000000000..c1fd75aaad
--- /dev/null
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -0,0 +1,511 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64static int buffer_write(BIO *h, const char *buf,int num);
65static int buffer_read(BIO *h, char *buf, int size);
66static int buffer_puts(BIO *h, const char *str);
67static int buffer_gets(BIO *h, char *str, int size);
68static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int buffer_new(BIO *h);
70static int buffer_free(BIO *data);
71static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
72#define DEFAULT_BUFFER_SIZE 4096
73
74static BIO_METHOD methods_buffer=
75 {
76 BIO_TYPE_BUFFER,
77 "buffer",
78 buffer_write,
79 buffer_read,
80 buffer_puts,
81 buffer_gets,
82 buffer_ctrl,
83 buffer_new,
84 buffer_free,
85 buffer_callback_ctrl,
86 };
87
88BIO_METHOD *BIO_f_buffer(void)
89 {
90 return(&methods_buffer);
91 }
92
93static int buffer_new(BIO *bi)
94 {
95 BIO_F_BUFFER_CTX *ctx;
96
97 ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
98 if (ctx == NULL) return(0);
99 ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
100 if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
101 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
102 if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
103 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
104 ctx->obuf_size=DEFAULT_BUFFER_SIZE;
105 ctx->ibuf_len=0;
106 ctx->ibuf_off=0;
107 ctx->obuf_len=0;
108 ctx->obuf_off=0;
109
110 bi->init=1;
111 bi->ptr=(char *)ctx;
112 bi->flags=0;
113 return(1);
114 }
115
116static int buffer_free(BIO *a)
117 {
118 BIO_F_BUFFER_CTX *b;
119
120 if (a == NULL) return(0);
121 b=(BIO_F_BUFFER_CTX *)a->ptr;
122 if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
123 if (b->obuf != NULL) OPENSSL_free(b->obuf);
124 OPENSSL_free(a->ptr);
125 a->ptr=NULL;
126 a->init=0;
127 a->flags=0;
128 return(1);
129 }
130
131static int buffer_read(BIO *b, char *out, int outl)
132 {
133 int i,num=0;
134 BIO_F_BUFFER_CTX *ctx;
135
136 if (out == NULL) return(0);
137 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
138
139 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
140 num=0;
141 BIO_clear_retry_flags(b);
142
143start:
144 i=ctx->ibuf_len;
145 /* If there is stuff left over, grab it */
146 if (i != 0)
147 {
148 if (i > outl) i=outl;
149 memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
150 ctx->ibuf_off+=i;
151 ctx->ibuf_len-=i;
152 num+=i;
153 if (outl == i) return(num);
154 outl-=i;
155 out+=i;
156 }
157
158 /* We may have done a partial read. try to do more.
159 * We have nothing in the buffer.
160 * If we get an error and have read some data, just return it
161 * and let them retry to get the error again.
162 * copy direct to parent address space */
163 if (outl > ctx->ibuf_size)
164 {
165 for (;;)
166 {
167 i=BIO_read(b->next_bio,out,outl);
168 if (i <= 0)
169 {
170 BIO_copy_next_retry(b);
171 if (i < 0) return((num > 0)?num:i);
172 if (i == 0) return(num);
173 }
174 num+=i;
175 if (outl == i) return(num);
176 out+=i;
177 outl-=i;
178 }
179 }
180 /* else */
181
182 /* we are going to be doing some buffering */
183 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
184 if (i <= 0)
185 {
186 BIO_copy_next_retry(b);
187 if (i < 0) return((num > 0)?num:i);
188 if (i == 0) return(num);
189 }
190 ctx->ibuf_off=0;
191 ctx->ibuf_len=i;
192
193 /* Lets re-read using ourselves :-) */
194 goto start;
195 }
196
197static int buffer_write(BIO *b, const char *in, int inl)
198 {
199 int i,num=0;
200 BIO_F_BUFFER_CTX *ctx;
201
202 if ((in == NULL) || (inl <= 0)) return(0);
203 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
204 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
205
206 BIO_clear_retry_flags(b);
207start:
208 i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
209 /* add to buffer and return */
210 if (i >= inl)
211 {
212 memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
213 ctx->obuf_len+=inl;
214 return(num+inl);
215 }
216 /* else */
217 /* stuff already in buffer, so add to it first, then flush */
218 if (ctx->obuf_len != 0)
219 {
220 if (i > 0) /* lets fill it up if we can */
221 {
222 memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
223 in+=i;
224 inl-=i;
225 num+=i;
226 ctx->obuf_len+=i;
227 }
228 /* we now have a full buffer needing flushing */
229 for (;;)
230 {
231 i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
232 ctx->obuf_len);
233 if (i <= 0)
234 {
235 BIO_copy_next_retry(b);
236
237 if (i < 0) return((num > 0)?num:i);
238 if (i == 0) return(num);
239 }
240 ctx->obuf_off+=i;
241 ctx->obuf_len-=i;
242 if (ctx->obuf_len == 0) break;
243 }
244 }
245 /* we only get here if the buffer has been flushed and we
246 * still have stuff to write */
247 ctx->obuf_off=0;
248
249 /* we now have inl bytes to write */
250 while (inl >= ctx->obuf_size)
251 {
252 i=BIO_write(b->next_bio,in,inl);
253 if (i <= 0)
254 {
255 BIO_copy_next_retry(b);
256 if (i < 0) return((num > 0)?num:i);
257 if (i == 0) return(num);
258 }
259 num+=i;
260 in+=i;
261 inl-=i;
262 if (inl == 0) return(num);
263 }
264
265 /* copy the rest into the buffer since we have only a small
266 * amount left */
267 goto start;
268 }
269
270static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
271 {
272 BIO *dbio;
273 BIO_F_BUFFER_CTX *ctx;
274 long ret=1;
275 char *p1,*p2;
276 int r,i,*ip;
277 int ibs,obs;
278
279 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
280
281 switch (cmd)
282 {
283 case BIO_CTRL_RESET:
284 ctx->ibuf_off=0;
285 ctx->ibuf_len=0;
286 ctx->obuf_off=0;
287 ctx->obuf_len=0;
288 if (b->next_bio == NULL) return(0);
289 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
290 break;
291 case BIO_CTRL_INFO:
292 ret=(long)ctx->obuf_len;
293 break;
294 case BIO_C_GET_BUFF_NUM_LINES:
295 ret=0;
296 p1=ctx->ibuf;
297 for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
298 {
299 if (p1[i] == '\n') ret++;
300 }
301 break;
302 case BIO_CTRL_WPENDING:
303 ret=(long)ctx->obuf_len;
304 if (ret == 0)
305 {
306 if (b->next_bio == NULL) return(0);
307 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
308 }
309 break;
310 case BIO_CTRL_PENDING:
311 ret=(long)ctx->ibuf_len;
312 if (ret == 0)
313 {
314 if (b->next_bio == NULL) return(0);
315 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
316 }
317 break;
318 case BIO_C_SET_BUFF_READ_DATA:
319 if (num > ctx->ibuf_size)
320 {
321 p1=OPENSSL_malloc((int)num);
322 if (p1 == NULL) goto malloc_error;
323 if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
324 ctx->ibuf=p1;
325 }
326 ctx->ibuf_off=0;
327 ctx->ibuf_len=(int)num;
328 memcpy(ctx->ibuf,ptr,(int)num);
329 ret=1;
330 break;
331 case BIO_C_SET_BUFF_SIZE:
332 if (ptr != NULL)
333 {
334 ip=(int *)ptr;
335 if (*ip == 0)
336 {
337 ibs=(int)num;
338 obs=ctx->obuf_size;
339 }
340 else /* if (*ip == 1) */
341 {
342 ibs=ctx->ibuf_size;
343 obs=(int)num;
344 }
345 }
346 else
347 {
348 ibs=(int)num;
349 obs=(int)num;
350 }
351 p1=ctx->ibuf;
352 p2=ctx->obuf;
353 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
354 {
355 p1=(char *)OPENSSL_malloc((int)num);
356 if (p1 == NULL) goto malloc_error;
357 }
358 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
359 {
360 p2=(char *)OPENSSL_malloc((int)num);
361 if (p2 == NULL)
362 {
363 if (p1 != ctx->ibuf) OPENSSL_free(p1);
364 goto malloc_error;
365 }
366 }
367 if (ctx->ibuf != p1)
368 {
369 OPENSSL_free(ctx->ibuf);
370 ctx->ibuf=p1;
371 ctx->ibuf_off=0;
372 ctx->ibuf_len=0;
373 ctx->ibuf_size=ibs;
374 }
375 if (ctx->obuf != p2)
376 {
377 OPENSSL_free(ctx->obuf);
378 ctx->obuf=p2;
379 ctx->obuf_off=0;
380 ctx->obuf_len=0;
381 ctx->obuf_size=obs;
382 }
383 break;
384 case BIO_C_DO_STATE_MACHINE:
385 if (b->next_bio == NULL) return(0);
386 BIO_clear_retry_flags(b);
387 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
388 BIO_copy_next_retry(b);
389 break;
390
391 case BIO_CTRL_FLUSH:
392 if (b->next_bio == NULL) return(0);
393 if (ctx->obuf_len <= 0)
394 {
395 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
396 break;
397 }
398
399 for (;;)
400 {
401 BIO_clear_retry_flags(b);
402 if (ctx->obuf_len > ctx->obuf_off)
403 {
404 r=BIO_write(b->next_bio,
405 &(ctx->obuf[ctx->obuf_off]),
406 ctx->obuf_len-ctx->obuf_off);
407#if 0
408fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
409#endif
410 BIO_copy_next_retry(b);
411 if (r <= 0) return((long)r);
412 ctx->obuf_off+=r;
413 }
414 else
415 {
416 ctx->obuf_len=0;
417 ctx->obuf_off=0;
418 ret=1;
419 break;
420 }
421 }
422 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
423 break;
424 case BIO_CTRL_DUP:
425 dbio=(BIO *)ptr;
426 if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
427 !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
428 ret=0;
429 break;
430 default:
431 if (b->next_bio == NULL) return(0);
432 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
433 break;
434 }
435 return(ret);
436malloc_error:
437 BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
438 return(0);
439 }
440
441static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
442 {
443 long ret=1;
444
445 if (b->next_bio == NULL) return(0);
446 switch (cmd)
447 {
448 default:
449 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
450 break;
451 }
452 return(ret);
453 }
454
455static int buffer_gets(BIO *b, char *buf, int size)
456 {
457 BIO_F_BUFFER_CTX *ctx;
458 int num=0,i,flag;
459 char *p;
460
461 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
462 size--; /* reserve space for a '\0' */
463 BIO_clear_retry_flags(b);
464
465 for (;;)
466 {
467 if (ctx->ibuf_len > 0)
468 {
469 p= &(ctx->ibuf[ctx->ibuf_off]);
470 flag=0;
471 for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
472 {
473 *(buf++)=p[i];
474 if (p[i] == '\n')
475 {
476 flag=1;
477 i++;
478 break;
479 }
480 }
481 num+=i;
482 size-=i;
483 ctx->ibuf_len-=i;
484 ctx->ibuf_off+=i;
485 if (flag || size == 0)
486 {
487 *buf='\0';
488 return(num);
489 }
490 }
491 else /* read another chunk */
492 {
493 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
494 if (i <= 0)
495 {
496 BIO_copy_next_retry(b);
497 *buf='\0';
498 if (i < 0) return((num > 0)?num:i);
499 if (i == 0) return(num);
500 }
501 ctx->ibuf_len=i;
502 ctx->ibuf_off=0;
503 }
504 }
505 }
506
507static int buffer_puts(BIO *b, const char *str)
508 {
509 return(buffer_write(b,str,strlen(str)));
510 }
511
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
new file mode 100644
index 0000000000..ec0f7eb0b7
--- /dev/null
+++ b/src/lib/libcrypto/bio/bf_lbuf.c
@@ -0,0 +1,397 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64
65static int linebuffer_write(BIO *h, const char *buf,int num);
66static int linebuffer_read(BIO *h, char *buf, int size);
67static int linebuffer_puts(BIO *h, const char *str);
68static int linebuffer_gets(BIO *h, char *str, int size);
69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int linebuffer_new(BIO *h);
71static int linebuffer_free(BIO *data);
72static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
73
74/* A 10k maximum should be enough for most purposes */
75#define DEFAULT_LINEBUFFER_SIZE 1024*10
76
77/* #define DEBUG */
78
79static BIO_METHOD methods_linebuffer=
80 {
81 BIO_TYPE_LINEBUFFER,
82 "linebuffer",
83 linebuffer_write,
84 linebuffer_read,
85 linebuffer_puts,
86 linebuffer_gets,
87 linebuffer_ctrl,
88 linebuffer_new,
89 linebuffer_free,
90 linebuffer_callback_ctrl,
91 };
92
93BIO_METHOD *BIO_f_linebuffer(void)
94 {
95 return(&methods_linebuffer);
96 }
97
98typedef struct bio_linebuffer_ctx_struct
99 {
100 char *obuf; /* the output char array */
101 int obuf_size; /* how big is the output buffer */
102 int obuf_len; /* how many bytes are in it */
103 } BIO_LINEBUFFER_CTX;
104
105static int linebuffer_new(BIO *bi)
106 {
107 BIO_LINEBUFFER_CTX *ctx;
108
109 ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
110 if (ctx == NULL) return(0);
111 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
112 if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
113 ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
114 ctx->obuf_len=0;
115
116 bi->init=1;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int linebuffer_free(BIO *a)
123 {
124 BIO_LINEBUFFER_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_LINEBUFFER_CTX *)a->ptr;
128 if (b->obuf != NULL) OPENSSL_free(b->obuf);
129 OPENSSL_free(a->ptr);
130 a->ptr=NULL;
131 a->init=0;
132 a->flags=0;
133 return(1);
134 }
135
136static int linebuffer_read(BIO *b, char *out, int outl)
137 {
138 int ret=0;
139
140 if (out == NULL) return(0);
141 if (b->next_bio == NULL) return(0);
142 ret=BIO_read(b->next_bio,out,outl);
143 BIO_clear_retry_flags(b);
144 BIO_copy_next_retry(b);
145 return(ret);
146 }
147
148static int linebuffer_write(BIO *b, const char *in, int inl)
149 {
150 int i,num=0,foundnl;
151 BIO_LINEBUFFER_CTX *ctx;
152
153 if ((in == NULL) || (inl <= 0)) return(0);
154 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
155 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
156
157 BIO_clear_retry_flags(b);
158
159 do
160 {
161 const char *p;
162
163 for(p = in; p < in + inl && *p != '\n'; p++)
164 ;
165 if (*p == '\n')
166 {
167 p++;
168 foundnl = 1;
169 }
170 else
171 foundnl = 0;
172
173 /* If a NL was found and we already have text in the save
174 buffer, concatenate them and write */
175 while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
176 && ctx->obuf_len > 0)
177 {
178 int orig_olen = ctx->obuf_len;
179
180 i = ctx->obuf_size - ctx->obuf_len;
181 if (p - in > 0)
182 {
183 if (i >= p - in)
184 {
185 memcpy(&(ctx->obuf[ctx->obuf_len]),
186 in,p - in);
187 ctx->obuf_len += p - in;
188 inl -= p - in;
189 num += p - in;
190 in = p;
191 }
192 else
193 {
194 memcpy(&(ctx->obuf[ctx->obuf_len]),
195 in,i);
196 ctx->obuf_len += i;
197 inl -= i;
198 in += i;
199 num += i;
200 }
201 }
202
203#if 0
204BIO_write(b->next_bio, "<*<", 3);
205#endif
206 i=BIO_write(b->next_bio,
207 ctx->obuf, ctx->obuf_len);
208 if (i <= 0)
209 {
210 ctx->obuf_len = orig_olen;
211 BIO_copy_next_retry(b);
212
213#if 0
214BIO_write(b->next_bio, ">*>", 3);
215#endif
216 if (i < 0) return((num > 0)?num:i);
217 if (i == 0) return(num);
218 }
219#if 0
220BIO_write(b->next_bio, ">*>", 3);
221#endif
222 if (i < ctx->obuf_len)
223 memmove(ctx->obuf, ctx->obuf + i,
224 ctx->obuf_len - i);
225 ctx->obuf_len-=i;
226 }
227
228 /* Now that the save buffer is emptied, let's write the input
229 buffer if a NL was found and there is anything to write. */
230 if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
231 {
232#if 0
233BIO_write(b->next_bio, "<*<", 3);
234#endif
235 i=BIO_write(b->next_bio,in,p - in);
236 if (i <= 0)
237 {
238 BIO_copy_next_retry(b);
239#if 0
240BIO_write(b->next_bio, ">*>", 3);
241#endif
242 if (i < 0) return((num > 0)?num:i);
243 if (i == 0) return(num);
244 }
245#if 0
246BIO_write(b->next_bio, ">*>", 3);
247#endif
248 num+=i;
249 in+=i;
250 inl-=i;
251 }
252 }
253 while(foundnl && inl > 0);
254 /* We've written as much as we can. The rest of the input buffer, if
255 any, is text that doesn't and with a NL and therefore needs to be
256 saved for the next trip. */
257 if (inl > 0)
258 {
259 memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
260 ctx->obuf_len += inl;
261 num += inl;
262 }
263 return num;
264 }
265
266static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
267 {
268 BIO *dbio;
269 BIO_LINEBUFFER_CTX *ctx;
270 long ret=1;
271 char *p;
272 int r;
273 int obs;
274
275 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
276
277 switch (cmd)
278 {
279 case BIO_CTRL_RESET:
280 ctx->obuf_len=0;
281 if (b->next_bio == NULL) return(0);
282 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
283 break;
284 case BIO_CTRL_INFO:
285 ret=(long)ctx->obuf_len;
286 break;
287 case BIO_CTRL_WPENDING:
288 ret=(long)ctx->obuf_len;
289 if (ret == 0)
290 {
291 if (b->next_bio == NULL) return(0);
292 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
293 }
294 break;
295 case BIO_C_SET_BUFF_SIZE:
296 obs=(int)num;
297 p=ctx->obuf;
298 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
299 {
300 p=(char *)OPENSSL_malloc((int)num);
301 if (p == NULL)
302 goto malloc_error;
303 }
304 if (ctx->obuf != p)
305 {
306 if (ctx->obuf_len > obs)
307 {
308 ctx->obuf_len = obs;
309 }
310 memcpy(p, ctx->obuf, ctx->obuf_len);
311 OPENSSL_free(ctx->obuf);
312 ctx->obuf=p;
313 ctx->obuf_size=obs;
314 }
315 break;
316 case BIO_C_DO_STATE_MACHINE:
317 if (b->next_bio == NULL) return(0);
318 BIO_clear_retry_flags(b);
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 BIO_copy_next_retry(b);
321 break;
322
323 case BIO_CTRL_FLUSH:
324 if (b->next_bio == NULL) return(0);
325 if (ctx->obuf_len <= 0)
326 {
327 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
328 break;
329 }
330
331 for (;;)
332 {
333 BIO_clear_retry_flags(b);
334 if (ctx->obuf_len > 0)
335 {
336 r=BIO_write(b->next_bio,
337 ctx->obuf, ctx->obuf_len);
338#if 0
339fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
340#endif
341 BIO_copy_next_retry(b);
342 if (r <= 0) return((long)r);
343 if (r < ctx->obuf_len)
344 memmove(ctx->obuf, ctx->obuf + r,
345 ctx->obuf_len - r);
346 ctx->obuf_len-=r;
347 }
348 else
349 {
350 ctx->obuf_len=0;
351 ret=1;
352 break;
353 }
354 }
355 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
356 break;
357 case BIO_CTRL_DUP:
358 dbio=(BIO *)ptr;
359 if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
360 ret=0;
361 break;
362 default:
363 if (b->next_bio == NULL) return(0);
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 break;
366 }
367 return(ret);
368malloc_error:
369 BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
370 return(0);
371 }
372
373static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
387static int linebuffer_gets(BIO *b, char *buf, int size)
388 {
389 if (b->next_bio == NULL) return(0);
390 return(BIO_gets(b->next_bio,buf,size));
391 }
392
393static int linebuffer_puts(BIO *b, const char *str)
394 {
395 return(linebuffer_write(b,str,strlen(str)));
396 }
397
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
new file mode 100644
index 0000000000..1ce2bfacc0
--- /dev/null
+++ b/src/lib/libcrypto/bio/bf_nbio.c
@@ -0,0 +1,255 @@
1/* crypto/bio/bf_nbio.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#include <openssl/bio.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int nbiof_write(BIO *h,const char *buf,int num);
69static int nbiof_read(BIO *h,char *buf,int size);
70static int nbiof_puts(BIO *h,const char *str);
71static int nbiof_gets(BIO *h,char *str,int size);
72static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
73static int nbiof_new(BIO *h);
74static int nbiof_free(BIO *data);
75static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
76typedef struct nbio_test_st
77 {
78 /* only set if we sent a 'should retry' error */
79 int lrn;
80 int lwn;
81 } NBIO_TEST;
82
83static BIO_METHOD methods_nbiof=
84 {
85 BIO_TYPE_NBIO_TEST,
86 "non-blocking IO test filter",
87 nbiof_write,
88 nbiof_read,
89 nbiof_puts,
90 nbiof_gets,
91 nbiof_ctrl,
92 nbiof_new,
93 nbiof_free,
94 nbiof_callback_ctrl,
95 };
96
97BIO_METHOD *BIO_f_nbio_test(void)
98 {
99 return(&methods_nbiof);
100 }
101
102static int nbiof_new(BIO *bi)
103 {
104 NBIO_TEST *nt;
105
106 if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0);
107 nt->lrn= -1;
108 nt->lwn= -1;
109 bi->ptr=(char *)nt;
110 bi->init=1;
111 bi->flags=0;
112 return(1);
113 }
114
115static int nbiof_free(BIO *a)
116 {
117 if (a == NULL) return(0);
118 if (a->ptr != NULL)
119 OPENSSL_free(a->ptr);
120 a->ptr=NULL;
121 a->init=0;
122 a->flags=0;
123 return(1);
124 }
125
126static int nbiof_read(BIO *b, char *out, int outl)
127 {
128 NBIO_TEST *nt;
129 int ret=0;
130#if 0
131 int num;
132 unsigned char n;
133#endif
134
135 if (out == NULL) return(0);
136 if (b->next_bio == NULL) return(0);
137 nt=(NBIO_TEST *)b->ptr;
138
139 BIO_clear_retry_flags(b);
140#if 0
141 RAND_pseudo_bytes(&n,1);
142 num=(n&0x07);
143
144 if (outl > num) outl=num;
145
146 if (num == 0)
147 {
148 ret= -1;
149 BIO_set_retry_read(b);
150 }
151 else
152#endif
153 {
154 ret=BIO_read(b->next_bio,out,outl);
155 if (ret < 0)
156 BIO_copy_next_retry(b);
157 }
158 return(ret);
159 }
160
161static int nbiof_write(BIO *b, const char *in, int inl)
162 {
163 NBIO_TEST *nt;
164 int ret=0;
165 int num;
166 unsigned char n;
167
168 if ((in == NULL) || (inl <= 0)) return(0);
169 if (b->next_bio == NULL) return(0);
170 nt=(NBIO_TEST *)b->ptr;
171
172 BIO_clear_retry_flags(b);
173
174#if 1
175 if (nt->lwn > 0)
176 {
177 num=nt->lwn;
178 nt->lwn=0;
179 }
180 else
181 {
182 RAND_pseudo_bytes(&n,1);
183 num=(n&7);
184 }
185
186 if (inl > num) inl=num;
187
188 if (num == 0)
189 {
190 ret= -1;
191 BIO_set_retry_write(b);
192 }
193 else
194#endif
195 {
196 ret=BIO_write(b->next_bio,in,inl);
197 if (ret < 0)
198 {
199 BIO_copy_next_retry(b);
200 nt->lwn=inl;
201 }
202 }
203 return(ret);
204 }
205
206static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
207 {
208 long ret;
209
210 if (b->next_bio == NULL) return(0);
211 switch (cmd)
212 {
213 case BIO_C_DO_STATE_MACHINE:
214 BIO_clear_retry_flags(b);
215 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
216 BIO_copy_next_retry(b);
217 break;
218 case BIO_CTRL_DUP:
219 ret=0L;
220 break;
221 default:
222 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
223 break;
224 }
225 return(ret);
226 }
227
228static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
229 {
230 long ret=1;
231
232 if (b->next_bio == NULL) return(0);
233 switch (cmd)
234 {
235 default:
236 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
237 break;
238 }
239 return(ret);
240 }
241
242static int nbiof_gets(BIO *bp, char *buf, int size)
243 {
244 if (bp->next_bio == NULL) return(0);
245 return(BIO_gets(bp->next_bio,buf,size));
246 }
247
248
249static int nbiof_puts(BIO *bp, const char *str)
250 {
251 if (bp->next_bio == NULL) return(0);
252 return(BIO_puts(bp->next_bio,str));
253 }
254
255
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
new file mode 100644
index 0000000000..c1bf39a904
--- /dev/null
+++ b/src/lib/libcrypto/bio/bf_null.c
@@ -0,0 +1,183 @@
1/* crypto/bio/bf_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64/* BIO_put and BIO_get both add to the digest,
65 * BIO_gets returns the digest */
66
67static int nullf_write(BIO *h, const char *buf, int num);
68static int nullf_read(BIO *h, char *buf, int size);
69static int nullf_puts(BIO *h, const char *str);
70static int nullf_gets(BIO *h, char *str, int size);
71static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
72static int nullf_new(BIO *h);
73static int nullf_free(BIO *data);
74static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
75static BIO_METHOD methods_nullf=
76 {
77 BIO_TYPE_NULL_FILTER,
78 "NULL filter",
79 nullf_write,
80 nullf_read,
81 nullf_puts,
82 nullf_gets,
83 nullf_ctrl,
84 nullf_new,
85 nullf_free,
86 nullf_callback_ctrl,
87 };
88
89BIO_METHOD *BIO_f_null(void)
90 {
91 return(&methods_nullf);
92 }
93
94static int nullf_new(BIO *bi)
95 {
96 bi->init=1;
97 bi->ptr=NULL;
98 bi->flags=0;
99 return(1);
100 }
101
102static int nullf_free(BIO *a)
103 {
104 if (a == NULL) return(0);
105/* a->ptr=NULL;
106 a->init=0;
107 a->flags=0;*/
108 return(1);
109 }
110
111static int nullf_read(BIO *b, char *out, int outl)
112 {
113 int ret=0;
114
115 if (out == NULL) return(0);
116 if (b->next_bio == NULL) return(0);
117 ret=BIO_read(b->next_bio,out,outl);
118 BIO_clear_retry_flags(b);
119 BIO_copy_next_retry(b);
120 return(ret);
121 }
122
123static int nullf_write(BIO *b, const char *in, int inl)
124 {
125 int ret=0;
126
127 if ((in == NULL) || (inl <= 0)) return(0);
128 if (b->next_bio == NULL) return(0);
129 ret=BIO_write(b->next_bio,in,inl);
130 BIO_clear_retry_flags(b);
131 BIO_copy_next_retry(b);
132 return(ret);
133 }
134
135static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
136 {
137 long ret;
138
139 if (b->next_bio == NULL) return(0);
140 switch(cmd)
141 {
142 case BIO_C_DO_STATE_MACHINE:
143 BIO_clear_retry_flags(b);
144 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
145 BIO_copy_next_retry(b);
146 break;
147 case BIO_CTRL_DUP:
148 ret=0L;
149 break;
150 default:
151 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
152 }
153 return(ret);
154 }
155
156static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
157 {
158 long ret=1;
159
160 if (b->next_bio == NULL) return(0);
161 switch (cmd)
162 {
163 default:
164 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
165 break;
166 }
167 return(ret);
168 }
169
170static int nullf_gets(BIO *bp, char *buf, int size)
171 {
172 if (bp->next_bio == NULL) return(0);
173 return(BIO_gets(bp->next_bio,buf,size));
174 }
175
176
177static int nullf_puts(BIO *bp, const char *str)
178 {
179 if (bp->next_bio == NULL) return(0);
180 return(BIO_puts(bp->next_bio,str));
181 }
182
183
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
new file mode 100644
index 0000000000..2eb703830f
--- /dev/null
+++ b/src/lib/libcrypto/bio/bio.h
@@ -0,0 +1,695 @@
1/* crypto/bio/bio.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BIO_H
60#define HEADER_BIO_H
61
62#ifndef OPENSSL_NO_FP_API
63# include <stdio.h>
64#endif
65#include <stdarg.h>
66
67#include <openssl/crypto.h>
68#include <openssl/e_os2.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/* These are the 'types' of BIOs */
75#define BIO_TYPE_NONE 0
76#define BIO_TYPE_MEM (1|0x0400)
77#define BIO_TYPE_FILE (2|0x0400)
78
79#define BIO_TYPE_FD (4|0x0400|0x0100)
80#define BIO_TYPE_SOCKET (5|0x0400|0x0100)
81#define BIO_TYPE_NULL (6|0x0400)
82#define BIO_TYPE_SSL (7|0x0200)
83#define BIO_TYPE_MD (8|0x0200) /* passive filter */
84#define BIO_TYPE_BUFFER (9|0x0200) /* filter */
85#define BIO_TYPE_CIPHER (10|0x0200) /* filter */
86#define BIO_TYPE_BASE64 (11|0x0200) /* filter */
87#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */
88#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */
89#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */
90#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */
91#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */
92#define BIO_TYPE_NULL_FILTER (17|0x0200)
93#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
94#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
95#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
96
97#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
98#define BIO_TYPE_FILTER 0x0200
99#define BIO_TYPE_SOURCE_SINK 0x0400
100
101/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
102 * BIO_set_fp(in,stdin,BIO_NOCLOSE); */
103#define BIO_NOCLOSE 0x00
104#define BIO_CLOSE 0x01
105
106/* These are used in the following macros and are passed to
107 * BIO_ctrl() */
108#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */
109#define BIO_CTRL_EOF 2 /* opt - are we at the eof */
110#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */
111#define BIO_CTRL_SET 4 /* man - set the 'IO' type */
112#define BIO_CTRL_GET 5 /* man - get the 'IO' type */
113#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */
114#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */
115#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */
116#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */
117#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */
118#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */
119#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */
120#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */
121/* callback is int cb(BIO *bio,state,ret); */
122#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */
123#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */
124
125#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */
126
127/* modifiers */
128#define BIO_FP_READ 0x02
129#define BIO_FP_WRITE 0x04
130#define BIO_FP_APPEND 0x08
131#define BIO_FP_TEXT 0x10
132
133#define BIO_FLAGS_READ 0x01
134#define BIO_FLAGS_WRITE 0x02
135#define BIO_FLAGS_IO_SPECIAL 0x04
136#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
137#define BIO_FLAGS_SHOULD_RETRY 0x08
138
139/* Used in BIO_gethostbyname() */
140#define BIO_GHBN_CTRL_HITS 1
141#define BIO_GHBN_CTRL_MISSES 2
142#define BIO_GHBN_CTRL_CACHE_SIZE 3
143#define BIO_GHBN_CTRL_GET_ENTRY 4
144#define BIO_GHBN_CTRL_FLUSH 5
145
146/* Mostly used in the SSL BIO */
147/* Not used anymore
148 * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10
149 * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20
150 * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40
151 */
152
153#define BIO_FLAGS_BASE64_NO_NL 0x100
154
155/* This is used with memory BIOs: it means we shouldn't free up or change the
156 * data in any way.
157 */
158#define BIO_FLAGS_MEM_RDONLY 0x200
159
160#define BIO_set_flags(b,f) ((b)->flags|=(f))
161#define BIO_get_flags(b) ((b)->flags)
162#define BIO_set_retry_special(b) \
163 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
164#define BIO_set_retry_read(b) \
165 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
166#define BIO_set_retry_write(b) \
167 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
168
169/* These are normally used internally in BIOs */
170#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
171#define BIO_clear_retry_flags(b) \
172 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
173#define BIO_get_retry_flags(b) \
174 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
175
176/* These should be used by the application to tell why we should retry */
177#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
178#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
179#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
180#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
181#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
182
183/* The next three are used in conjunction with the
184 * BIO_should_io_special() condition. After this returns true,
185 * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
186 * stack and return the 'reason' for the special and the offending BIO.
187 * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
188/* Returned from the SSL bio when the certificate retrieval code had an error */
189#define BIO_RR_SSL_X509_LOOKUP 0x01
190/* Returned from the connect BIO when a connect would have blocked */
191#define BIO_RR_CONNECT 0x02
192/* Returned from the accept BIO when an accept would have blocked */
193#define BIO_RR_ACCEPT 0x03
194
195/* These are passed by the BIO callback */
196#define BIO_CB_FREE 0x01
197#define BIO_CB_READ 0x02
198#define BIO_CB_WRITE 0x03
199#define BIO_CB_PUTS 0x04
200#define BIO_CB_GETS 0x05
201#define BIO_CB_CTRL 0x06
202
203/* The callback is called before and after the underling operation,
204 * The BIO_CB_RETURN flag indicates if it is after the call */
205#define BIO_CB_RETURN 0x80
206#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
207#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
208#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
209
210#define BIO_set_callback(b,cb) ((b)->callback=(cb))
211#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
212#define BIO_get_callback_arg(b) ((b)->cb_arg)
213#define BIO_get_callback(b) ((b)->callback)
214#define BIO_method_name(b) ((b)->method->name)
215#define BIO_method_type(b) ((b)->method->type)
216
217typedef struct bio_st BIO;
218
219typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
220
221#ifndef OPENSSL_SYS_WIN16
222typedef struct bio_method_st
223 {
224 int type;
225 const char *name;
226 int (*bwrite)(BIO *, const char *, int);
227 int (*bread)(BIO *, char *, int);
228 int (*bputs)(BIO *, const char *);
229 int (*bgets)(BIO *, char *, int);
230 long (*ctrl)(BIO *, int, long, void *);
231 int (*create)(BIO *);
232 int (*destroy)(BIO *);
233 long (*callback_ctrl)(BIO *, int, bio_info_cb *);
234 } BIO_METHOD;
235#else
236typedef struct bio_method_st
237 {
238 int type;
239 const char *name;
240 int (_far *bwrite)();
241 int (_far *bread)();
242 int (_far *bputs)();
243 int (_far *bgets)();
244 long (_far *ctrl)();
245 int (_far *create)();
246 int (_far *destroy)();
247 long (_far *callback_ctrl)();
248 } BIO_METHOD;
249#endif
250
251struct bio_st
252 {
253 BIO_METHOD *method;
254 /* bio, mode, argp, argi, argl, ret */
255 long (*callback)(struct bio_st *,int,const char *,int, long,long);
256 char *cb_arg; /* first argument for the callback */
257
258 int init;
259 int shutdown;
260 int flags; /* extra storage */
261 int retry_reason;
262 int num;
263 void *ptr;
264 struct bio_st *next_bio; /* used by filter BIOs */
265 struct bio_st *prev_bio; /* used by filter BIOs */
266 int references;
267 unsigned long num_read;
268 unsigned long num_write;
269
270 CRYPTO_EX_DATA ex_data;
271 };
272
273DECLARE_STACK_OF(BIO)
274
275typedef struct bio_f_buffer_ctx_struct
276 {
277 /* BIO *bio; */ /* this is now in the BIO struct */
278 int ibuf_size; /* how big is the input buffer */
279 int obuf_size; /* how big is the output buffer */
280
281 char *ibuf; /* the char array */
282 int ibuf_len; /* how many bytes are in it */
283 int ibuf_off; /* write/read offset */
284
285 char *obuf; /* the char array */
286 int obuf_len; /* how many bytes are in it */
287 int obuf_off; /* write/read offset */
288 } BIO_F_BUFFER_CTX;
289
290/* connect BIO stuff */
291#define BIO_CONN_S_BEFORE 1
292#define BIO_CONN_S_GET_IP 2
293#define BIO_CONN_S_GET_PORT 3
294#define BIO_CONN_S_CREATE_SOCKET 4
295#define BIO_CONN_S_CONNECT 5
296#define BIO_CONN_S_OK 6
297#define BIO_CONN_S_BLOCKED_CONNECT 7
298#define BIO_CONN_S_NBIO 8
299/*#define BIO_CONN_get_param_hostname BIO_ctrl */
300
301#define BIO_C_SET_CONNECT 100
302#define BIO_C_DO_STATE_MACHINE 101
303#define BIO_C_SET_NBIO 102
304#define BIO_C_SET_PROXY_PARAM 103
305#define BIO_C_SET_FD 104
306#define BIO_C_GET_FD 105
307#define BIO_C_SET_FILE_PTR 106
308#define BIO_C_GET_FILE_PTR 107
309#define BIO_C_SET_FILENAME 108
310#define BIO_C_SET_SSL 109
311#define BIO_C_GET_SSL 110
312#define BIO_C_SET_MD 111
313#define BIO_C_GET_MD 112
314#define BIO_C_GET_CIPHER_STATUS 113
315#define BIO_C_SET_BUF_MEM 114
316#define BIO_C_GET_BUF_MEM_PTR 115
317#define BIO_C_GET_BUFF_NUM_LINES 116
318#define BIO_C_SET_BUFF_SIZE 117
319#define BIO_C_SET_ACCEPT 118
320#define BIO_C_SSL_MODE 119
321#define BIO_C_GET_MD_CTX 120
322#define BIO_C_GET_PROXY_PARAM 121
323#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */
324#define BIO_C_GET_CONNECT 123
325#define BIO_C_GET_ACCEPT 124
326#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
327#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
328#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
329#define BIO_C_FILE_SEEK 128
330#define BIO_C_GET_CIPHER_CTX 129
331#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/
332#define BIO_C_SET_BIND_MODE 131
333#define BIO_C_GET_BIND_MODE 132
334#define BIO_C_FILE_TELL 133
335#define BIO_C_GET_SOCKS 134
336#define BIO_C_SET_SOCKS 135
337
338#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
339#define BIO_C_GET_WRITE_BUF_SIZE 137
340#define BIO_C_MAKE_BIO_PAIR 138
341#define BIO_C_DESTROY_BIO_PAIR 139
342#define BIO_C_GET_WRITE_GUARANTEE 140
343#define BIO_C_GET_READ_REQUEST 141
344#define BIO_C_SHUTDOWN_WR 142
345#define BIO_C_NREAD0 143
346#define BIO_C_NREAD 144
347#define BIO_C_NWRITE0 145
348#define BIO_C_NWRITE 146
349#define BIO_C_RESET_READ_REQUEST 147
350#define BIO_C_SET_MD_CTX 148
351
352
353#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
354#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
355
356/* BIO_s_connect() and BIO_s_socks4a_connect() */
357#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
358#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
359#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
360#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
361#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
362#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
363#define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)
364#define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3)
365
366
367#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
368
369/* BIO_s_accept_socket() */
370#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
371#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
372/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
373#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
374#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
375
376#define BIO_BIND_NORMAL 0
377#define BIO_BIND_REUSEADDR_IF_UNUSED 1
378#define BIO_BIND_REUSEADDR 2
379#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
380#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
381
382#define BIO_do_connect(b) BIO_do_handshake(b)
383#define BIO_do_accept(b) BIO_do_handshake(b)
384#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
385
386/* BIO_s_proxy_client() */
387#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
388#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
389/* BIO_set_nbio(b,n) */
390#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
391/* BIO *BIO_get_filter_bio(BIO *bio); */
392#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))
393#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
394#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
395
396#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
397#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
398#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
399#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
400
401#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
402#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
403
404#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
405#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
406
407#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
408#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
409
410/* name is cast to lose const, but might be better to route through a function
411 so we can do it safely */
412#ifdef CONST_STRICT
413/* If you are wondering why this isn't defined, its because CONST_STRICT is
414 * purely a compile-time kludge to allow const to be checked.
415 */
416int BIO_read_filename(BIO *b,const char *name);
417#else
418#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
419 BIO_CLOSE|BIO_FP_READ,(char *)name)
420#endif
421#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
422 BIO_CLOSE|BIO_FP_WRITE,name)
423#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
424 BIO_CLOSE|BIO_FP_APPEND,name)
425#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
426 BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
427
428/* WARNING WARNING, this ups the reference count on the read bio of the
429 * SSL structure. This is because the ssl read BIO is now pointed to by
430 * the next_bio field in the bio. So when you free the BIO, make sure
431 * you are doing a BIO_free_all() to catch the underlying BIO. */
432#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
433#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
434#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
435#define BIO_set_ssl_renegotiate_bytes(b,num) \
436 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
437#define BIO_get_num_renegotiates(b) \
438 BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL);
439#define BIO_set_ssl_renegotiate_timeout(b,seconds) \
440 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
441
442/* defined in evp.h */
443/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
444
445#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
446#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
447#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
448#define BIO_set_mem_eof_return(b,v) \
449 BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
450
451/* For the BIO_f_buffer() type */
452#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
453#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
454#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
455#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
456#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
457
458/* Don't use the next one unless you know what you are doing :-) */
459#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
460
461#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
462#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
463#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
464#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
465#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
466#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
467/* ...pending macros have inappropriate return type */
468size_t BIO_ctrl_pending(BIO *b);
469size_t BIO_ctrl_wpending(BIO *b);
470#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
471#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \
472 cbp)
473#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)
474
475/* For the BIO_f_buffer() type */
476#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
477
478/* For BIO_s_bio() */
479#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
480#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
481#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
482#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
483#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
484/* macros with inappropriate type -- but ...pending macros use int too: */
485#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
486#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
487size_t BIO_ctrl_get_write_guarantee(BIO *b);
488size_t BIO_ctrl_get_read_request(BIO *b);
489int BIO_ctrl_reset_read_request(BIO *b);
490
491/* These two aren't currently implemented */
492/* int BIO_get_ex_num(BIO *bio); */
493/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
494int BIO_set_ex_data(BIO *bio,int idx,void *data);
495void *BIO_get_ex_data(BIO *bio,int idx);
496int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
497 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
498unsigned long BIO_number_read(BIO *bio);
499unsigned long BIO_number_written(BIO *bio);
500
501# ifndef OPENSSL_NO_FP_API
502# if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL)
503BIO_METHOD *BIO_s_file_internal(void);
504BIO *BIO_new_file_internal(char *filename, char *mode);
505BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
506# define BIO_s_file BIO_s_file_internal
507# define BIO_new_file BIO_new_file_internal
508# define BIO_new_fp BIO_new_fp_internal
509# else /* FP_API */
510BIO_METHOD *BIO_s_file(void );
511BIO *BIO_new_file(const char *filename, const char *mode);
512BIO *BIO_new_fp(FILE *stream, int close_flag);
513# define BIO_s_file_internal BIO_s_file
514# define BIO_new_file_internal BIO_new_file
515# define BIO_new_fp_internal BIO_s_file
516# endif /* FP_API */
517# endif
518BIO * BIO_new(BIO_METHOD *type);
519int BIO_set(BIO *a,BIO_METHOD *type);
520int BIO_free(BIO *a);
521void BIO_vfree(BIO *a);
522int BIO_read(BIO *b, void *data, int len);
523int BIO_gets(BIO *bp,char *buf, int size);
524int BIO_write(BIO *b, const void *data, int len);
525int BIO_puts(BIO *bp,const char *buf);
526int BIO_indent(BIO *b,int indent,int max);
527long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
528long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
529char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
530long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
531BIO * BIO_push(BIO *b,BIO *append);
532BIO * BIO_pop(BIO *b);
533void BIO_free_all(BIO *a);
534BIO * BIO_find_type(BIO *b,int bio_type);
535BIO * BIO_next(BIO *b);
536BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
537int BIO_get_retry_reason(BIO *bio);
538BIO * BIO_dup_chain(BIO *in);
539
540int BIO_nread0(BIO *bio, char **buf);
541int BIO_nread(BIO *bio, char **buf, int num);
542int BIO_nwrite0(BIO *bio, char **buf);
543int BIO_nwrite(BIO *bio, char **buf, int num);
544
545#ifndef OPENSSL_SYS_WIN16
546long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
547 long argl,long ret);
548#else
549long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
550 long argl,long ret);
551#endif
552
553BIO_METHOD *BIO_s_mem(void);
554BIO *BIO_new_mem_buf(void *buf, int len);
555BIO_METHOD *BIO_s_socket(void);
556BIO_METHOD *BIO_s_connect(void);
557BIO_METHOD *BIO_s_accept(void);
558BIO_METHOD *BIO_s_fd(void);
559#ifndef OPENSSL_SYS_OS2
560BIO_METHOD *BIO_s_log(void);
561#endif
562BIO_METHOD *BIO_s_bio(void);
563BIO_METHOD *BIO_s_null(void);
564BIO_METHOD *BIO_f_null(void);
565BIO_METHOD *BIO_f_buffer(void);
566#ifdef OPENSSL_SYS_VMS
567BIO_METHOD *BIO_f_linebuffer(void);
568#endif
569BIO_METHOD *BIO_f_nbio_test(void);
570/* BIO_METHOD *BIO_f_ber(void); */
571
572int BIO_sock_should_retry(int i);
573int BIO_sock_non_fatal_error(int error);
574int BIO_fd_should_retry(int i);
575int BIO_fd_non_fatal_error(int error);
576int BIO_dump(BIO *b,const char *bytes,int len);
577int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
578
579struct hostent *BIO_gethostbyname(const char *name);
580/* We might want a thread-safe interface too:
581 * struct hostent *BIO_gethostbyname_r(const char *name,
582 * struct hostent *result, void *buffer, size_t buflen);
583 * or something similar (caller allocates a struct hostent,
584 * pointed to by "result", and additional buffer space for the various
585 * substructures; if the buffer does not suffice, NULL is returned
586 * and an appropriate error code is set).
587 */
588int BIO_sock_error(int sock);
589int BIO_socket_ioctl(int fd, long type, void *arg);
590int BIO_socket_nbio(int fd,int mode);
591int BIO_get_port(const char *str, unsigned short *port_ptr);
592int BIO_get_host_ip(const char *str, unsigned char *ip);
593int BIO_get_accept_socket(char *host_port,int mode);
594int BIO_accept(int sock,char **ip_port);
595int BIO_sock_init(void );
596void BIO_sock_cleanup(void);
597int BIO_set_tcp_ndelay(int sock,int turn_on);
598
599BIO *BIO_new_socket(int sock, int close_flag);
600BIO *BIO_new_fd(int fd, int close_flag);
601BIO *BIO_new_connect(char *host_port);
602BIO *BIO_new_accept(char *host_port);
603
604int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
605 BIO **bio2, size_t writebuf2);
606/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
607 * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
608 * Size 0 uses default value.
609 */
610
611void BIO_copy_next_retry(BIO *b);
612
613/*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/
614
615int BIO_printf(BIO *bio, const char *format, ...);
616int BIO_vprintf(BIO *bio, const char *format, va_list args);
617int BIO_snprintf(char *buf, size_t n, const char *format, ...);
618int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args);
619
620/* BEGIN ERROR CODES */
621/* The following lines are auto generated by the script mkerr.pl. Any changes
622 * made after this point may be overwritten when the script is next run.
623 */
624void ERR_load_BIO_strings(void);
625
626/* Error codes for the BIO functions. */
627
628/* Function codes. */
629#define BIO_F_ACPT_STATE 100
630#define BIO_F_BIO_ACCEPT 101
631#define BIO_F_BIO_BER_GET_HEADER 102
632#define BIO_F_BIO_CTRL 103
633#define BIO_F_BIO_GETHOSTBYNAME 120
634#define BIO_F_BIO_GETS 104
635#define BIO_F_BIO_GET_ACCEPT_SOCKET 105
636#define BIO_F_BIO_GET_HOST_IP 106
637#define BIO_F_BIO_GET_PORT 107
638#define BIO_F_BIO_MAKE_PAIR 121
639#define BIO_F_BIO_NEW 108
640#define BIO_F_BIO_NEW_FILE 109
641#define BIO_F_BIO_NEW_MEM_BUF 126
642#define BIO_F_BIO_NREAD 123
643#define BIO_F_BIO_NREAD0 124
644#define BIO_F_BIO_NWRITE 125
645#define BIO_F_BIO_NWRITE0 122
646#define BIO_F_BIO_PUTS 110
647#define BIO_F_BIO_READ 111
648#define BIO_F_BIO_SOCK_INIT 112
649#define BIO_F_BIO_WRITE 113
650#define BIO_F_BUFFER_CTRL 114
651#define BIO_F_CONN_CTRL 127
652#define BIO_F_CONN_STATE 115
653#define BIO_F_FILE_CTRL 116
654#define BIO_F_FILE_READ 130
655#define BIO_F_LINEBUFFER_CTRL 129
656#define BIO_F_MEM_READ 128
657#define BIO_F_MEM_WRITE 117
658#define BIO_F_SSL_NEW 118
659#define BIO_F_WSASTARTUP 119
660
661/* Reason codes. */
662#define BIO_R_ACCEPT_ERROR 100
663#define BIO_R_BAD_FOPEN_MODE 101
664#define BIO_R_BAD_HOSTNAME_LOOKUP 102
665#define BIO_R_BROKEN_PIPE 124
666#define BIO_R_CONNECT_ERROR 103
667#define BIO_R_EOF_ON_MEMORY_BIO 127
668#define BIO_R_ERROR_SETTING_NBIO 104
669#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
670#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
671#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
672#define BIO_R_INVALID_ARGUMENT 125
673#define BIO_R_INVALID_IP_ADDRESS 108
674#define BIO_R_IN_USE 123
675#define BIO_R_KEEPALIVE 109
676#define BIO_R_NBIO_CONNECT_ERROR 110
677#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
678#define BIO_R_NO_HOSTNAME_SPECIFIED 112
679#define BIO_R_NO_PORT_DEFINED 113
680#define BIO_R_NO_PORT_SPECIFIED 114
681#define BIO_R_NO_SUCH_FILE 128
682#define BIO_R_NULL_PARAMETER 115
683#define BIO_R_TAG_MISMATCH 116
684#define BIO_R_UNABLE_TO_BIND_SOCKET 117
685#define BIO_R_UNABLE_TO_CREATE_SOCKET 118
686#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
687#define BIO_R_UNINITIALIZED 120
688#define BIO_R_UNSUPPORTED_METHOD 121
689#define BIO_R_WRITE_TO_READ_ONLY_BIO 126
690#define BIO_R_WSASTARTUP 122
691
692#ifdef __cplusplus
693}
694#endif
695#endif
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c
new file mode 100644
index 0000000000..6f4254a114
--- /dev/null
+++ b/src/lib/libcrypto/bio/bio_cb.c
@@ -0,0 +1,139 @@
1/* crypto/bio/bio_cb.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62#include "cryptlib.h"
63#include <openssl/bio.h>
64#include <openssl/err.h>
65
66long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp,
67 int argi, long argl, long ret)
68 {
69 BIO *b;
70 MS_STATIC char buf[256];
71 char *p;
72 long r=1;
73 size_t p_maxlen;
74
75 if (BIO_CB_RETURN & cmd)
76 r=ret;
77
78 BIO_snprintf(buf,sizeof buf,"BIO[%08lX]:",(unsigned long)bio);
79 p= &(buf[14]);
80 p_maxlen = sizeof buf - 14;
81 switch (cmd)
82 {
83 case BIO_CB_FREE:
84 BIO_snprintf(p,p_maxlen,"Free - %s\n",bio->method->name);
85 break;
86 case BIO_CB_READ:
87 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
88 BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s fd=%d\n",
89 bio->num,argi,bio->method->name,bio->num);
90 else
91 BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s\n",
92 bio->num,argi,bio->method->name);
93 break;
94 case BIO_CB_WRITE:
95 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
96 BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s fd=%d\n",
97 bio->num,argi,bio->method->name,bio->num);
98 else
99 BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s\n",
100 bio->num,argi,bio->method->name);
101 break;
102 case BIO_CB_PUTS:
103 BIO_snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name);
104 break;
105 case BIO_CB_GETS:
106 BIO_snprintf(p,p_maxlen,"gets(%d) - %s\n",argi,bio->method->name);
107 break;
108 case BIO_CB_CTRL:
109 BIO_snprintf(p,p_maxlen,"ctrl(%d) - %s\n",argi,bio->method->name);
110 break;
111 case BIO_CB_RETURN|BIO_CB_READ:
112 BIO_snprintf(p,p_maxlen,"read return %ld\n",ret);
113 break;
114 case BIO_CB_RETURN|BIO_CB_WRITE:
115 BIO_snprintf(p,p_maxlen,"write return %ld\n",ret);
116 break;
117 case BIO_CB_RETURN|BIO_CB_GETS:
118 BIO_snprintf(p,p_maxlen,"gets return %ld\n",ret);
119 break;
120 case BIO_CB_RETURN|BIO_CB_PUTS:
121 BIO_snprintf(p,p_maxlen,"puts return %ld\n",ret);
122 break;
123 case BIO_CB_RETURN|BIO_CB_CTRL:
124 BIO_snprintf(p,p_maxlen,"ctrl return %ld\n",ret);
125 break;
126 default:
127 BIO_snprintf(p,p_maxlen,"bio callback - unknown type (%d)\n",cmd);
128 break;
129 }
130
131 b=(BIO *)bio->cb_arg;
132 if (b != NULL)
133 BIO_write(b,buf,strlen(buf));
134#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
135 else
136 fputs(buf,stderr);
137#endif
138 return(r);
139 }
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
new file mode 100644
index 0000000000..68a119d895
--- /dev/null
+++ b/src/lib/libcrypto/bio/bio_err.c
@@ -0,0 +1,152 @@
1/* crypto/bio/bio_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/bio.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA BIO_str_functs[]=
68 {
69{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"},
70{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"},
71{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"},
72{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"},
73{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"},
74{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"},
75{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"},
76{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"},
77{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"},
78{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"},
79{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
80{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
81{ERR_PACK(0,BIO_F_BIO_NEW_MEM_BUF,0), "BIO_new_mem_buf"},
82{ERR_PACK(0,BIO_F_BIO_NREAD,0), "BIO_nread"},
83{ERR_PACK(0,BIO_F_BIO_NREAD0,0), "BIO_nread0"},
84{ERR_PACK(0,BIO_F_BIO_NWRITE,0), "BIO_nwrite"},
85{ERR_PACK(0,BIO_F_BIO_NWRITE0,0), "BIO_nwrite0"},
86{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
87{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"},
88{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"},
89{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"},
90{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"},
91{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
92{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
93{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
94{ERR_PACK(0,BIO_F_FILE_READ,0), "FILE_READ"},
95{ERR_PACK(0,BIO_F_LINEBUFFER_CTRL,0), "LINEBUFFER_CTRL"},
96{ERR_PACK(0,BIO_F_MEM_READ,0), "MEM_READ"},
97{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
98{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
99{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
100{0,NULL}
101 };
102
103static ERR_STRING_DATA BIO_str_reasons[]=
104 {
105{BIO_R_ACCEPT_ERROR ,"accept error"},
106{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"},
107{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
108{BIO_R_BROKEN_PIPE ,"broken pipe"},
109{BIO_R_CONNECT_ERROR ,"connect error"},
110{BIO_R_EOF_ON_MEMORY_BIO ,"EOF on memory BIO"},
111{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
112{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
113{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
114{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"},
115{BIO_R_INVALID_ARGUMENT ,"invalid argument"},
116{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"},
117{BIO_R_IN_USE ,"in use"},
118{BIO_R_KEEPALIVE ,"keepalive"},
119{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"},
120{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"},
121{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"},
122{BIO_R_NO_PORT_DEFINED ,"no port defined"},
123{BIO_R_NO_PORT_SPECIFIED ,"no port specified"},
124{BIO_R_NO_SUCH_FILE ,"no such file"},
125{BIO_R_NULL_PARAMETER ,"null parameter"},
126{BIO_R_TAG_MISMATCH ,"tag mismatch"},
127{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"},
128{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"},
129{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
130{BIO_R_UNINITIALIZED ,"uninitialized"},
131{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
132{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only BIO"},
133{BIO_R_WSASTARTUP ,"WSAStartup"},
134{0,NULL}
135 };
136
137#endif
138
139void ERR_load_BIO_strings(void)
140 {
141 static int init=1;
142
143 if (init)
144 {
145 init=0;
146#ifndef OPENSSL_NO_ERR
147 ERR_load_strings(ERR_LIB_BIO,BIO_str_functs);
148 ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons);
149#endif
150
151 }
152 }
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
new file mode 100644
index 0000000000..692c8fb5c6
--- /dev/null
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -0,0 +1,556 @@
1/* crypto/bio/bio_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/bio.h>
64#include <openssl/stack.h>
65
66BIO *BIO_new(BIO_METHOD *method)
67 {
68 BIO *ret=NULL;
69
70 ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
71 if (ret == NULL)
72 {
73 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
74 return(NULL);
75 }
76 if (!BIO_set(ret,method))
77 {
78 OPENSSL_free(ret);
79 ret=NULL;
80 }
81 return(ret);
82 }
83
84int BIO_set(BIO *bio, BIO_METHOD *method)
85 {
86 bio->method=method;
87 bio->callback=NULL;
88 bio->cb_arg=NULL;
89 bio->init=0;
90 bio->shutdown=1;
91 bio->flags=0;
92 bio->retry_reason=0;
93 bio->num=0;
94 bio->ptr=NULL;
95 bio->prev_bio=NULL;
96 bio->next_bio=NULL;
97 bio->references=1;
98 bio->num_read=0L;
99 bio->num_write=0L;
100 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
101 if (method->create != NULL)
102 if (!method->create(bio))
103 {
104 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio,
105 &bio->ex_data);
106 return(0);
107 }
108 return(1);
109 }
110
111int BIO_free(BIO *a)
112 {
113 int ret=0,i;
114
115 if (a == NULL) return(0);
116
117 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
118#ifdef REF_PRINT
119 REF_PRINT("BIO",a);
120#endif
121 if (i > 0) return(1);
122#ifdef REF_CHECK
123 if (i < 0)
124 {
125 fprintf(stderr,"BIO_free, bad reference count\n");
126 abort();
127 }
128#endif
129 if ((a->callback != NULL) &&
130 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
131 return(i);
132
133 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
134
135 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
136 ret=a->method->destroy(a);
137 OPENSSL_free(a);
138 return(1);
139 }
140
141void BIO_vfree(BIO *a)
142 { BIO_free(a); }
143
144int BIO_read(BIO *b, void *out, int outl)
145 {
146 int i;
147 long (*cb)();
148
149 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
150 {
151 BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
152 return(-2);
153 }
154
155 cb=b->callback;
156 if ((cb != NULL) &&
157 ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
158 return(i);
159
160 if (!b->init)
161 {
162 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
163 return(-2);
164 }
165
166 i=b->method->bread(b,out,outl);
167
168 if (i > 0) b->num_read+=(unsigned long)i;
169
170 if (cb != NULL)
171 i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
172 0L,(long)i);
173 return(i);
174 }
175
176int BIO_write(BIO *b, const void *in, int inl)
177 {
178 int i;
179 long (*cb)();
180
181 if (b == NULL)
182 return(0);
183
184 cb=b->callback;
185 if ((b->method == NULL) || (b->method->bwrite == NULL))
186 {
187 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
188 return(-2);
189 }
190
191 if ((cb != NULL) &&
192 ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
193 return(i);
194
195 if (!b->init)
196 {
197 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
198 return(-2);
199 }
200
201 i=b->method->bwrite(b,in,inl);
202
203 if (i > 0) b->num_write+=(unsigned long)i;
204
205 if (cb != NULL)
206 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
207 0L,(long)i);
208 return(i);
209 }
210
211int BIO_puts(BIO *b, const char *in)
212 {
213 int i;
214 long (*cb)();
215
216 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
217 {
218 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
219 return(-2);
220 }
221
222 cb=b->callback;
223
224 if ((cb != NULL) &&
225 ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
226 return(i);
227
228 if (!b->init)
229 {
230 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
231 return(-2);
232 }
233
234 i=b->method->bputs(b,in);
235
236 if (i > 0) b->num_write+=(unsigned long)i;
237
238 if (cb != NULL)
239 i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
240 0L,(long)i);
241 return(i);
242 }
243
244int BIO_gets(BIO *b, char *in, int inl)
245 {
246 int i;
247 long (*cb)();
248
249 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
250 {
251 BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
252 return(-2);
253 }
254
255 cb=b->callback;
256
257 if ((cb != NULL) &&
258 ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
259 return(i);
260
261 if (!b->init)
262 {
263 BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED);
264 return(-2);
265 }
266
267 i=b->method->bgets(b,in,inl);
268
269 if (cb != NULL)
270 i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
271 0L,(long)i);
272 return(i);
273 }
274
275int BIO_indent(BIO *b,int indent,int max)
276 {
277 if(indent < 0)
278 indent=0;
279 if(indent > max)
280 indent=max;
281 while(indent--)
282 if(BIO_puts(b," ") != 1)
283 return 0;
284 return 1;
285 }
286
287long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
288 {
289 int i;
290
291 i=iarg;
292 return(BIO_ctrl(b,cmd,larg,(char *)&i));
293 }
294
295char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
296 {
297 char *p=NULL;
298
299 if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
300 return(NULL);
301 else
302 return(p);
303 }
304
305long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
306 {
307 long ret;
308 long (*cb)();
309
310 if (b == NULL) return(0);
311
312 if ((b->method == NULL) || (b->method->ctrl == NULL))
313 {
314 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
315 return(-2);
316 }
317
318 cb=b->callback;
319
320 if ((cb != NULL) &&
321 ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
322 return(ret);
323
324 ret=b->method->ctrl(b,cmd,larg,parg);
325
326 if (cb != NULL)
327 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
328 larg,ret);
329 return(ret);
330 }
331
332long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
333 {
334 long ret;
335 long (*cb)();
336
337 if (b == NULL) return(0);
338
339 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
340 {
341 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
342 return(-2);
343 }
344
345 cb=b->callback;
346
347 if ((cb != NULL) &&
348 ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
349 return(ret);
350
351 ret=b->method->callback_ctrl(b,cmd,fp);
352
353 if (cb != NULL)
354 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
355 0,ret);
356 return(ret);
357 }
358
359/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
360 * do; but those macros have inappropriate return type, and for interfacing
361 * from other programming languages, C macros aren't much of a help anyway. */
362size_t BIO_ctrl_pending(BIO *bio)
363 {
364 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
365 }
366
367size_t BIO_ctrl_wpending(BIO *bio)
368 {
369 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
370 }
371
372
373/* put the 'bio' on the end of b's list of operators */
374BIO *BIO_push(BIO *b, BIO *bio)
375 {
376 BIO *lb;
377
378 if (b == NULL) return(bio);
379 lb=b;
380 while (lb->next_bio != NULL)
381 lb=lb->next_bio;
382 lb->next_bio=bio;
383 if (bio != NULL)
384 bio->prev_bio=lb;
385 /* called to do internal processing */
386 BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
387 return(b);
388 }
389
390/* Remove the first and return the rest */
391BIO *BIO_pop(BIO *b)
392 {
393 BIO *ret;
394
395 if (b == NULL) return(NULL);
396 ret=b->next_bio;
397
398 BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
399
400 if (b->prev_bio != NULL)
401 b->prev_bio->next_bio=b->next_bio;
402 if (b->next_bio != NULL)
403 b->next_bio->prev_bio=b->prev_bio;
404
405 b->next_bio=NULL;
406 b->prev_bio=NULL;
407 return(ret);
408 }
409
410BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
411 {
412 BIO *b,*last;
413
414 b=last=bio;
415 for (;;)
416 {
417 if (!BIO_should_retry(b)) break;
418 last=b;
419 b=b->next_bio;
420 if (b == NULL) break;
421 }
422 if (reason != NULL) *reason=last->retry_reason;
423 return(last);
424 }
425
426int BIO_get_retry_reason(BIO *bio)
427 {
428 return(bio->retry_reason);
429 }
430
431BIO *BIO_find_type(BIO *bio, int type)
432 {
433 int mt,mask;
434
435 if(!bio) return NULL;
436 mask=type&0xff;
437 do {
438 if (bio->method != NULL)
439 {
440 mt=bio->method->type;
441
442 if (!mask)
443 {
444 if (mt & type) return(bio);
445 }
446 else if (mt == type)
447 return(bio);
448 }
449 bio=bio->next_bio;
450 } while (bio != NULL);
451 return(NULL);
452 }
453
454BIO *BIO_next(BIO *b)
455 {
456 if(!b) return NULL;
457 return b->next_bio;
458 }
459
460void BIO_free_all(BIO *bio)
461 {
462 BIO *b;
463 int ref;
464
465 while (bio != NULL)
466 {
467 b=bio;
468 ref=b->references;
469 bio=bio->next_bio;
470 BIO_free(b);
471 /* Since ref count > 1, don't free anyone else. */
472 if (ref > 1) break;
473 }
474 }
475
476BIO *BIO_dup_chain(BIO *in)
477 {
478 BIO *ret=NULL,*eoc=NULL,*bio,*new;
479
480 for (bio=in; bio != NULL; bio=bio->next_bio)
481 {
482 if ((new=BIO_new(bio->method)) == NULL) goto err;
483 new->callback=bio->callback;
484 new->cb_arg=bio->cb_arg;
485 new->init=bio->init;
486 new->shutdown=bio->shutdown;
487 new->flags=bio->flags;
488
489 /* This will let SSL_s_sock() work with stdin/stdout */
490 new->num=bio->num;
491
492 if (!BIO_dup_state(bio,(char *)new))
493 {
494 BIO_free(new);
495 goto err;
496 }
497
498 /* copy app data */
499 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new->ex_data,
500 &bio->ex_data))
501 goto err;
502
503 if (ret == NULL)
504 {
505 eoc=new;
506 ret=eoc;
507 }
508 else
509 {
510 BIO_push(eoc,new);
511 eoc=new;
512 }
513 }
514 return(ret);
515err:
516 if (ret != NULL)
517 BIO_free(ret);
518 return(NULL);
519 }
520
521void BIO_copy_next_retry(BIO *b)
522 {
523 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
524 b->retry_reason=b->next_bio->retry_reason;
525 }
526
527int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
528 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
529 {
530 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp,
531 new_func, dup_func, free_func);
532 }
533
534int BIO_set_ex_data(BIO *bio, int idx, void *data)
535 {
536 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
537 }
538
539void *BIO_get_ex_data(BIO *bio, int idx)
540 {
541 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
542 }
543
544unsigned long BIO_number_read(BIO *bio)
545{
546 if(bio) return bio->num_read;
547 return 0;
548}
549
550unsigned long BIO_number_written(BIO *bio)
551{
552 if(bio) return bio->num_write;
553 return 0;
554}
555
556IMPLEMENT_STACK_OF(BIO)
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
new file mode 100644
index 0000000000..8ea1db158b
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_acpt.c
@@ -0,0 +1,479 @@
1/* crypto/bio/bss_acpt.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#ifdef OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78typedef struct bio_accept_st
79 {
80 int state;
81 char *param_addr;
82
83 int accept_sock;
84 int accept_nbio;
85
86 char *addr;
87 int nbio;
88 /* If 0, it means normal, if 1, do a connect on bind failure,
89 * and if there is no-one listening, bind with SO_REUSEADDR.
90 * If 2, always use SO_REUSEADDR. */
91 int bind_mode;
92 BIO *bio_chain;
93 } BIO_ACCEPT;
94
95static int acpt_write(BIO *h, const char *buf, int num);
96static int acpt_read(BIO *h, char *buf, int size);
97static int acpt_puts(BIO *h, const char *str);
98static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2);
99static int acpt_new(BIO *h);
100static int acpt_free(BIO *data);
101static int acpt_state(BIO *b, BIO_ACCEPT *c);
102static void acpt_close_socket(BIO *data);
103BIO_ACCEPT *BIO_ACCEPT_new(void );
104void BIO_ACCEPT_free(BIO_ACCEPT *a);
105
106#define ACPT_S_BEFORE 1
107#define ACPT_S_GET_ACCEPT_SOCKET 2
108#define ACPT_S_OK 3
109
110static BIO_METHOD methods_acceptp=
111 {
112 BIO_TYPE_ACCEPT,
113 "socket accept",
114 acpt_write,
115 acpt_read,
116 acpt_puts,
117 NULL, /* connect_gets, */
118 acpt_ctrl,
119 acpt_new,
120 acpt_free,
121 NULL,
122 };
123
124BIO_METHOD *BIO_s_accept(void)
125 {
126 return(&methods_acceptp);
127 }
128
129static int acpt_new(BIO *bi)
130 {
131 BIO_ACCEPT *ba;
132
133 bi->init=0;
134 bi->num=INVALID_SOCKET;
135 bi->flags=0;
136 if ((ba=BIO_ACCEPT_new()) == NULL)
137 return(0);
138 bi->ptr=(char *)ba;
139 ba->state=ACPT_S_BEFORE;
140 bi->shutdown=1;
141 return(1);
142 }
143
144BIO_ACCEPT *BIO_ACCEPT_new(void)
145 {
146 BIO_ACCEPT *ret;
147
148 if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
149 return(NULL);
150
151 memset(ret,0,sizeof(BIO_ACCEPT));
152 ret->accept_sock=INVALID_SOCKET;
153 ret->bind_mode=BIO_BIND_NORMAL;
154 return(ret);
155 }
156
157void BIO_ACCEPT_free(BIO_ACCEPT *a)
158 {
159 if(a == NULL)
160 return;
161
162 if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
163 if (a->addr != NULL) OPENSSL_free(a->addr);
164 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
165 OPENSSL_free(a);
166 }
167
168static void acpt_close_socket(BIO *bio)
169 {
170 BIO_ACCEPT *c;
171
172 c=(BIO_ACCEPT *)bio->ptr;
173 if (c->accept_sock != INVALID_SOCKET)
174 {
175 shutdown(c->accept_sock,2);
176 closesocket(c->accept_sock);
177 c->accept_sock=INVALID_SOCKET;
178 bio->num=INVALID_SOCKET;
179 }
180 }
181
182static int acpt_free(BIO *a)
183 {
184 BIO_ACCEPT *data;
185
186 if (a == NULL) return(0);
187 data=(BIO_ACCEPT *)a->ptr;
188
189 if (a->shutdown)
190 {
191 acpt_close_socket(a);
192 BIO_ACCEPT_free(data);
193 a->ptr=NULL;
194 a->flags=0;
195 a->init=0;
196 }
197 return(1);
198 }
199
200static int acpt_state(BIO *b, BIO_ACCEPT *c)
201 {
202 BIO *bio=NULL,*dbio;
203 int s= -1;
204 int i;
205
206again:
207 switch (c->state)
208 {
209 case ACPT_S_BEFORE:
210 if (c->param_addr == NULL)
211 {
212 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
213 return(-1);
214 }
215 s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
216 if (s == INVALID_SOCKET)
217 return(-1);
218
219 if (c->accept_nbio)
220 {
221 if (!BIO_socket_nbio(s,1))
222 {
223 closesocket(s);
224 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
225 return(-1);
226 }
227 }
228 c->accept_sock=s;
229 b->num=s;
230 c->state=ACPT_S_GET_ACCEPT_SOCKET;
231 return(1);
232 /* break; */
233 case ACPT_S_GET_ACCEPT_SOCKET:
234 if (b->next_bio != NULL)
235 {
236 c->state=ACPT_S_OK;
237 goto again;
238 }
239 BIO_clear_retry_flags(b);
240 b->retry_reason=0;
241 i=BIO_accept(c->accept_sock,&(c->addr));
242
243 /* -2 return means we should retry */
244 if(i == -2)
245 {
246 BIO_set_retry_special(b);
247 b->retry_reason=BIO_RR_ACCEPT;
248 return -1;
249 }
250
251 if (i < 0) return(i);
252
253 bio=BIO_new_socket(i,BIO_CLOSE);
254 if (bio == NULL) goto err;
255
256 BIO_set_callback(bio,BIO_get_callback(b));
257 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
258
259 if (c->nbio)
260 {
261 if (!BIO_socket_nbio(i,1))
262 {
263 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
264 goto err;
265 }
266 }
267
268 /* If the accept BIO has an bio_chain, we dup it and
269 * put the new socket at the end. */
270 if (c->bio_chain != NULL)
271 {
272 if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
273 goto err;
274 if (!BIO_push(dbio,bio)) goto err;
275 bio=dbio;
276 }
277 if (BIO_push(b,bio) == NULL) goto err;
278
279 c->state=ACPT_S_OK;
280 return(1);
281err:
282 if (bio != NULL)
283 BIO_free(bio);
284 else if (s >= 0)
285 closesocket(s);
286 return(0);
287 /* break; */
288 case ACPT_S_OK:
289 if (b->next_bio == NULL)
290 {
291 c->state=ACPT_S_GET_ACCEPT_SOCKET;
292 goto again;
293 }
294 return(1);
295 /* break; */
296 default:
297 return(0);
298 /* break; */
299 }
300
301 }
302
303static int acpt_read(BIO *b, char *out, int outl)
304 {
305 int ret=0;
306 BIO_ACCEPT *data;
307
308 BIO_clear_retry_flags(b);
309 data=(BIO_ACCEPT *)b->ptr;
310
311 while (b->next_bio == NULL)
312 {
313 ret=acpt_state(b,data);
314 if (ret <= 0) return(ret);
315 }
316
317 ret=BIO_read(b->next_bio,out,outl);
318 BIO_copy_next_retry(b);
319 return(ret);
320 }
321
322static int acpt_write(BIO *b, const char *in, int inl)
323 {
324 int ret;
325 BIO_ACCEPT *data;
326
327 BIO_clear_retry_flags(b);
328 data=(BIO_ACCEPT *)b->ptr;
329
330 while (b->next_bio == NULL)
331 {
332 ret=acpt_state(b,data);
333 if (ret <= 0) return(ret);
334 }
335
336 ret=BIO_write(b->next_bio,in,inl);
337 BIO_copy_next_retry(b);
338 return(ret);
339 }
340
341static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
342 {
343 BIO *dbio;
344 int *ip;
345 long ret=1;
346 BIO_ACCEPT *data;
347 char **pp;
348
349 data=(BIO_ACCEPT *)b->ptr;
350
351 switch (cmd)
352 {
353 case BIO_CTRL_RESET:
354 ret=0;
355 data->state=ACPT_S_BEFORE;
356 acpt_close_socket(b);
357 b->flags=0;
358 break;
359 case BIO_C_DO_STATE_MACHINE:
360 /* use this one to start the connection */
361 ret=(long)acpt_state(b,data);
362 break;
363 case BIO_C_SET_ACCEPT:
364 if (ptr != NULL)
365 {
366 if (num == 0)
367 {
368 b->init=1;
369 if (data->param_addr != NULL)
370 OPENSSL_free(data->param_addr);
371 data->param_addr=BUF_strdup(ptr);
372 }
373 else if (num == 1)
374 {
375 data->accept_nbio=(ptr != NULL);
376 }
377 else if (num == 2)
378 {
379 if (data->bio_chain != NULL)
380 BIO_free(data->bio_chain);
381 data->bio_chain=(BIO *)ptr;
382 }
383 }
384 break;
385 case BIO_C_SET_NBIO:
386 data->nbio=(int)num;
387 break;
388 case BIO_C_SET_FD:
389 b->init=1;
390 b->num= *((int *)ptr);
391 data->accept_sock=b->num;
392 data->state=ACPT_S_GET_ACCEPT_SOCKET;
393 b->shutdown=(int)num;
394 b->init=1;
395 break;
396 case BIO_C_GET_FD:
397 if (b->init)
398 {
399 ip=(int *)ptr;
400 if (ip != NULL)
401 *ip=data->accept_sock;
402 ret=data->accept_sock;
403 }
404 else
405 ret= -1;
406 break;
407 case BIO_C_GET_ACCEPT:
408 if (b->init)
409 {
410 if (ptr != NULL)
411 {
412 pp=(char **)ptr;
413 *pp=data->param_addr;
414 }
415 else
416 ret= -1;
417 }
418 else
419 ret= -1;
420 break;
421 case BIO_CTRL_GET_CLOSE:
422 ret=b->shutdown;
423 break;
424 case BIO_CTRL_SET_CLOSE:
425 b->shutdown=(int)num;
426 break;
427 case BIO_CTRL_PENDING:
428 case BIO_CTRL_WPENDING:
429 ret=0;
430 break;
431 case BIO_CTRL_FLUSH:
432 break;
433 case BIO_C_SET_BIND_MODE:
434 data->bind_mode=(int)num;
435 break;
436 case BIO_C_GET_BIND_MODE:
437 ret=(long)data->bind_mode;
438 break;
439 case BIO_CTRL_DUP:
440 dbio=(BIO *)ptr;
441/* if (data->param_port) EAY EAY
442 BIO_set_port(dbio,data->param_port);
443 if (data->param_hostname)
444 BIO_set_hostname(dbio,data->param_hostname);
445 BIO_set_nbio(dbio,data->nbio); */
446 break;
447
448 default:
449 ret=0;
450 break;
451 }
452 return(ret);
453 }
454
455static int acpt_puts(BIO *bp, const char *str)
456 {
457 int n,ret;
458
459 n=strlen(str);
460 ret=acpt_write(bp,str,n);
461 return(ret);
462 }
463
464BIO *BIO_new_accept(char *str)
465 {
466 BIO *ret;
467
468 ret=BIO_new(BIO_s_accept());
469 if (ret == NULL) return(NULL);
470 if (BIO_set_accept_port(ret,str))
471 return(ret);
472 else
473 {
474 BIO_free(ret);
475 return(NULL);
476 }
477 }
478
479#endif
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
new file mode 100644
index 0000000000..0f9f0955b4
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_bio.c
@@ -0,0 +1,924 @@
1/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* Special method for a BIO where the other endpoint is also a BIO
57 * of this kind, handled by the same thread (i.e. the "peer" is actually
58 * ourselves, wearing a different hat).
59 * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces
60 * for which no specific BIO method is available.
61 * See ssl/ssltest.c for some hints on how this can be used. */
62
63/* BIO_DEBUG implies BIO_PAIR_DEBUG */
64#ifdef BIO_DEBUG
65# ifndef BIO_PAIR_DEBUG
66# define BIO_PAIR_DEBUG
67# endif
68#endif
69
70/* disable assert() unless BIO_PAIR_DEBUG has been defined */
71#ifndef BIO_PAIR_DEBUG
72# ifndef NDEBUG
73# define NDEBUG
74# endif
75#endif
76
77#include <assert.h>
78#include <limits.h>
79#include <stdlib.h>
80#include <string.h>
81
82#include <openssl/bio.h>
83#include <openssl/err.h>
84#include <openssl/crypto.h>
85
86#include "e_os.h"
87
88/* VxWorks defines SSIZE_MAX with an empty value causing compile errors */
89#if defined(OPENSSL_SYS_VXWORKS)
90# undef SSIZE_MAX
91#endif
92#ifndef SSIZE_MAX
93# define SSIZE_MAX INT_MAX
94#endif
95
96static int bio_new(BIO *bio);
97static int bio_free(BIO *bio);
98static int bio_read(BIO *bio, char *buf, int size);
99static int bio_write(BIO *bio, const char *buf, int num);
100static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
101static int bio_puts(BIO *bio, const char *str);
102
103static int bio_make_pair(BIO *bio1, BIO *bio2);
104static void bio_destroy_pair(BIO *bio);
105
106static BIO_METHOD methods_biop =
107{
108 BIO_TYPE_BIO,
109 "BIO pair",
110 bio_write,
111 bio_read,
112 bio_puts,
113 NULL /* no bio_gets */,
114 bio_ctrl,
115 bio_new,
116 bio_free,
117 NULL /* no bio_callback_ctrl */
118};
119
120BIO_METHOD *BIO_s_bio(void)
121 {
122 return &methods_biop;
123 }
124
125struct bio_bio_st
126{
127 BIO *peer; /* NULL if buf == NULL.
128 * If peer != NULL, then peer->ptr is also a bio_bio_st,
129 * and its "peer" member points back to us.
130 * peer != NULL iff init != 0 in the BIO. */
131
132 /* This is for what we write (i.e. reading uses peer's struct): */
133 int closed; /* valid iff peer != NULL */
134 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
135 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
136 size_t size;
137 char *buf; /* "size" elements (if != NULL) */
138
139 size_t request; /* valid iff peer != NULL; 0 if len != 0,
140 * otherwise set by peer to number of bytes
141 * it (unsuccessfully) tried to read,
142 * never more than buffer space (size-len) warrants. */
143};
144
145static int bio_new(BIO *bio)
146 {
147 struct bio_bio_st *b;
148
149 b = OPENSSL_malloc(sizeof *b);
150 if (b == NULL)
151 return 0;
152
153 b->peer = NULL;
154 b->size = 17*1024; /* enough for one TLS record (just a default) */
155 b->buf = NULL;
156
157 bio->ptr = b;
158 return 1;
159 }
160
161
162static int bio_free(BIO *bio)
163 {
164 struct bio_bio_st *b;
165
166 if (bio == NULL)
167 return 0;
168 b = bio->ptr;
169
170 assert(b != NULL);
171
172 if (b->peer)
173 bio_destroy_pair(bio);
174
175 if (b->buf != NULL)
176 {
177 OPENSSL_free(b->buf);
178 }
179
180 OPENSSL_free(b);
181
182 return 1;
183 }
184
185
186
187static int bio_read(BIO *bio, char *buf, int size_)
188 {
189 size_t size = size_;
190 size_t rest;
191 struct bio_bio_st *b, *peer_b;
192
193 BIO_clear_retry_flags(bio);
194
195 if (!bio->init)
196 return 0;
197
198 b = bio->ptr;
199 assert(b != NULL);
200 assert(b->peer != NULL);
201 peer_b = b->peer->ptr;
202 assert(peer_b != NULL);
203 assert(peer_b->buf != NULL);
204
205 peer_b->request = 0; /* will be set in "retry_read" situation */
206
207 if (buf == NULL || size == 0)
208 return 0;
209
210 if (peer_b->len == 0)
211 {
212 if (peer_b->closed)
213 return 0; /* writer has closed, and no data is left */
214 else
215 {
216 BIO_set_retry_read(bio); /* buffer is empty */
217 if (size <= peer_b->size)
218 peer_b->request = size;
219 else
220 /* don't ask for more than the peer can
221 * deliver in one write */
222 peer_b->request = peer_b->size;
223 return -1;
224 }
225 }
226
227 /* we can read */
228 if (peer_b->len < size)
229 size = peer_b->len;
230
231 /* now read "size" bytes */
232
233 rest = size;
234
235 assert(rest > 0);
236 do /* one or two iterations */
237 {
238 size_t chunk;
239
240 assert(rest <= peer_b->len);
241 if (peer_b->offset + rest <= peer_b->size)
242 chunk = rest;
243 else
244 /* wrap around ring buffer */
245 chunk = peer_b->size - peer_b->offset;
246 assert(peer_b->offset + chunk <= peer_b->size);
247
248 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
249
250 peer_b->len -= chunk;
251 if (peer_b->len)
252 {
253 peer_b->offset += chunk;
254 assert(peer_b->offset <= peer_b->size);
255 if (peer_b->offset == peer_b->size)
256 peer_b->offset = 0;
257 buf += chunk;
258 }
259 else
260 {
261 /* buffer now empty, no need to advance "buf" */
262 assert(chunk == rest);
263 peer_b->offset = 0;
264 }
265 rest -= chunk;
266 }
267 while (rest);
268
269 return size;
270 }
271
272/* non-copying interface: provide pointer to available data in buffer
273 * bio_nread0: return number of available bytes
274 * bio_nread: also advance index
275 * (example usage: bio_nread0(), read from buffer, bio_nread()
276 * or just bio_nread(), read from buffer)
277 */
278/* WARNING: The non-copying interface is largely untested as of yet
279 * and may contain bugs. */
280static ssize_t bio_nread0(BIO *bio, char **buf)
281 {
282 struct bio_bio_st *b, *peer_b;
283 ssize_t num;
284
285 BIO_clear_retry_flags(bio);
286
287 if (!bio->init)
288 return 0;
289
290 b = bio->ptr;
291 assert(b != NULL);
292 assert(b->peer != NULL);
293 peer_b = b->peer->ptr;
294 assert(peer_b != NULL);
295 assert(peer_b->buf != NULL);
296
297 peer_b->request = 0;
298
299 if (peer_b->len == 0)
300 {
301 char dummy;
302
303 /* avoid code duplication -- nothing available for reading */
304 return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
305 }
306
307 num = peer_b->len;
308 if (peer_b->size < peer_b->offset + num)
309 /* no ring buffer wrap-around for non-copying interface */
310 num = peer_b->size - peer_b->offset;
311 assert(num > 0);
312
313 if (buf != NULL)
314 *buf = peer_b->buf + peer_b->offset;
315 return num;
316 }
317
318static ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
319 {
320 struct bio_bio_st *b, *peer_b;
321 ssize_t num, available;
322
323 if (num_ > SSIZE_MAX)
324 num = SSIZE_MAX;
325 else
326 num = (ssize_t)num_;
327
328 available = bio_nread0(bio, buf);
329 if (num > available)
330 num = available;
331 if (num <= 0)
332 return num;
333
334 b = bio->ptr;
335 peer_b = b->peer->ptr;
336
337 peer_b->len -= num;
338 if (peer_b->len)
339 {
340 peer_b->offset += num;
341 assert(peer_b->offset <= peer_b->size);
342 if (peer_b->offset == peer_b->size)
343 peer_b->offset = 0;
344 }
345 else
346 peer_b->offset = 0;
347
348 return num;
349 }
350
351
352static int bio_write(BIO *bio, const char *buf, int num_)
353 {
354 size_t num = num_;
355 size_t rest;
356 struct bio_bio_st *b;
357
358 BIO_clear_retry_flags(bio);
359
360 if (!bio->init || buf == NULL || num == 0)
361 return 0;
362
363 b = bio->ptr;
364 assert(b != NULL);
365 assert(b->peer != NULL);
366 assert(b->buf != NULL);
367
368 b->request = 0;
369 if (b->closed)
370 {
371 /* we already closed */
372 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
373 return -1;
374 }
375
376 assert(b->len <= b->size);
377
378 if (b->len == b->size)
379 {
380 BIO_set_retry_write(bio); /* buffer is full */
381 return -1;
382 }
383
384 /* we can write */
385 if (num > b->size - b->len)
386 num = b->size - b->len;
387
388 /* now write "num" bytes */
389
390 rest = num;
391
392 assert(rest > 0);
393 do /* one or two iterations */
394 {
395 size_t write_offset;
396 size_t chunk;
397
398 assert(b->len + rest <= b->size);
399
400 write_offset = b->offset + b->len;
401 if (write_offset >= b->size)
402 write_offset -= b->size;
403 /* b->buf[write_offset] is the first byte we can write to. */
404
405 if (write_offset + rest <= b->size)
406 chunk = rest;
407 else
408 /* wrap around ring buffer */
409 chunk = b->size - write_offset;
410
411 memcpy(b->buf + write_offset, buf, chunk);
412
413 b->len += chunk;
414
415 assert(b->len <= b->size);
416
417 rest -= chunk;
418 buf += chunk;
419 }
420 while (rest);
421
422 return num;
423 }
424
425/* non-copying interface: provide pointer to region to write to
426 * bio_nwrite0: check how much space is available
427 * bio_nwrite: also increase length
428 * (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
429 * or just bio_nwrite(), write to buffer)
430 */
431static ssize_t bio_nwrite0(BIO *bio, char **buf)
432 {
433 struct bio_bio_st *b;
434 size_t num;
435 size_t write_offset;
436
437 BIO_clear_retry_flags(bio);
438
439 if (!bio->init)
440 return 0;
441
442 b = bio->ptr;
443 assert(b != NULL);
444 assert(b->peer != NULL);
445 assert(b->buf != NULL);
446
447 b->request = 0;
448 if (b->closed)
449 {
450 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
451 return -1;
452 }
453
454 assert(b->len <= b->size);
455
456 if (b->len == b->size)
457 {
458 BIO_set_retry_write(bio);
459 return -1;
460 }
461
462 num = b->size - b->len;
463 write_offset = b->offset + b->len;
464 if (write_offset >= b->size)
465 write_offset -= b->size;
466 if (write_offset + num > b->size)
467 /* no ring buffer wrap-around for non-copying interface
468 * (to fulfil the promise by BIO_ctrl_get_write_guarantee,
469 * BIO_nwrite may have to be called twice) */
470 num = b->size - write_offset;
471
472 if (buf != NULL)
473 *buf = b->buf + write_offset;
474 assert(write_offset + num <= b->size);
475
476 return num;
477 }
478
479static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
480 {
481 struct bio_bio_st *b;
482 ssize_t num, space;
483
484 if (num_ > SSIZE_MAX)
485 num = SSIZE_MAX;
486 else
487 num = (ssize_t)num_;
488
489 space = bio_nwrite0(bio, buf);
490 if (num > space)
491 num = space;
492 if (num <= 0)
493 return num;
494 b = bio->ptr;
495 assert(b != NULL);
496 b->len += num;
497 assert(b->len <= b->size);
498
499 return num;
500 }
501
502
503static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
504 {
505 long ret;
506 struct bio_bio_st *b = bio->ptr;
507
508 assert(b != NULL);
509
510 switch (cmd)
511 {
512 /* specific CTRL codes */
513
514 case BIO_C_SET_WRITE_BUF_SIZE:
515 if (b->peer)
516 {
517 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
518 ret = 0;
519 }
520 else if (num == 0)
521 {
522 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
523 ret = 0;
524 }
525 else
526 {
527 size_t new_size = num;
528
529 if (b->size != new_size)
530 {
531 if (b->buf)
532 {
533 OPENSSL_free(b->buf);
534 b->buf = NULL;
535 }
536 b->size = new_size;
537 }
538 ret = 1;
539 }
540 break;
541
542 case BIO_C_GET_WRITE_BUF_SIZE:
543 ret = (long) b->size;
544 break;
545
546 case BIO_C_MAKE_BIO_PAIR:
547 {
548 BIO *other_bio = ptr;
549
550 if (bio_make_pair(bio, other_bio))
551 ret = 1;
552 else
553 ret = 0;
554 }
555 break;
556
557 case BIO_C_DESTROY_BIO_PAIR:
558 /* Affects both BIOs in the pair -- call just once!
559 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
560 bio_destroy_pair(bio);
561 ret = 1;
562 break;
563
564 case BIO_C_GET_WRITE_GUARANTEE:
565 /* How many bytes can the caller feed to the next write
566 * without having to keep any? */
567 if (b->peer == NULL || b->closed)
568 ret = 0;
569 else
570 ret = (long) b->size - b->len;
571 break;
572
573 case BIO_C_GET_READ_REQUEST:
574 /* If the peer unsuccessfully tried to read, how many bytes
575 * were requested? (As with BIO_CTRL_PENDING, that number
576 * can usually be treated as boolean.) */
577 ret = (long) b->request;
578 break;
579
580 case BIO_C_RESET_READ_REQUEST:
581 /* Reset request. (Can be useful after read attempts
582 * at the other side that are meant to be non-blocking,
583 * e.g. when probing SSL_read to see if any data is
584 * available.) */
585 b->request = 0;
586 ret = 1;
587 break;
588
589 case BIO_C_SHUTDOWN_WR:
590 /* similar to shutdown(..., SHUT_WR) */
591 b->closed = 1;
592 ret = 1;
593 break;
594
595 case BIO_C_NREAD0:
596 /* prepare for non-copying read */
597 ret = (long) bio_nread0(bio, ptr);
598 break;
599
600 case BIO_C_NREAD:
601 /* non-copying read */
602 ret = (long) bio_nread(bio, ptr, (size_t) num);
603 break;
604
605 case BIO_C_NWRITE0:
606 /* prepare for non-copying write */
607 ret = (long) bio_nwrite0(bio, ptr);
608 break;
609
610 case BIO_C_NWRITE:
611 /* non-copying write */
612 ret = (long) bio_nwrite(bio, ptr, (size_t) num);
613 break;
614
615
616 /* standard CTRL codes follow */
617
618 case BIO_CTRL_RESET:
619 if (b->buf != NULL)
620 {
621 b->len = 0;
622 b->offset = 0;
623 }
624 ret = 0;
625 break;
626
627 case BIO_CTRL_GET_CLOSE:
628 ret = bio->shutdown;
629 break;
630
631 case BIO_CTRL_SET_CLOSE:
632 bio->shutdown = (int) num;
633 ret = 1;
634 break;
635
636 case BIO_CTRL_PENDING:
637 if (b->peer != NULL)
638 {
639 struct bio_bio_st *peer_b = b->peer->ptr;
640
641 ret = (long) peer_b->len;
642 }
643 else
644 ret = 0;
645 break;
646
647 case BIO_CTRL_WPENDING:
648 if (b->buf != NULL)
649 ret = (long) b->len;
650 else
651 ret = 0;
652 break;
653
654 case BIO_CTRL_DUP:
655 /* See BIO_dup_chain for circumstances we have to expect. */
656 {
657 BIO *other_bio = ptr;
658 struct bio_bio_st *other_b;
659
660 assert(other_bio != NULL);
661 other_b = other_bio->ptr;
662 assert(other_b != NULL);
663
664 assert(other_b->buf == NULL); /* other_bio is always fresh */
665
666 other_b->size = b->size;
667 }
668
669 ret = 1;
670 break;
671
672 case BIO_CTRL_FLUSH:
673 ret = 1;
674 break;
675
676 case BIO_CTRL_EOF:
677 {
678 BIO *other_bio = ptr;
679
680 if (other_bio)
681 {
682 struct bio_bio_st *other_b = other_bio->ptr;
683
684 assert(other_b != NULL);
685 ret = other_b->len == 0 && other_b->closed;
686 }
687 else
688 ret = 1;
689 }
690 break;
691
692 default:
693 ret = 0;
694 }
695 return ret;
696 }
697
698static int bio_puts(BIO *bio, const char *str)
699 {
700 return bio_write(bio, str, strlen(str));
701 }
702
703
704static int bio_make_pair(BIO *bio1, BIO *bio2)
705 {
706 struct bio_bio_st *b1, *b2;
707
708 assert(bio1 != NULL);
709 assert(bio2 != NULL);
710
711 b1 = bio1->ptr;
712 b2 = bio2->ptr;
713
714 if (b1->peer != NULL || b2->peer != NULL)
715 {
716 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
717 return 0;
718 }
719
720 if (b1->buf == NULL)
721 {
722 b1->buf = OPENSSL_malloc(b1->size);
723 if (b1->buf == NULL)
724 {
725 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
726 return 0;
727 }
728 b1->len = 0;
729 b1->offset = 0;
730 }
731
732 if (b2->buf == NULL)
733 {
734 b2->buf = OPENSSL_malloc(b2->size);
735 if (b2->buf == NULL)
736 {
737 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
738 return 0;
739 }
740 b2->len = 0;
741 b2->offset = 0;
742 }
743
744 b1->peer = bio2;
745 b1->closed = 0;
746 b1->request = 0;
747 b2->peer = bio1;
748 b2->closed = 0;
749 b2->request = 0;
750
751 bio1->init = 1;
752 bio2->init = 1;
753
754 return 1;
755 }
756
757static void bio_destroy_pair(BIO *bio)
758 {
759 struct bio_bio_st *b = bio->ptr;
760
761 if (b != NULL)
762 {
763 BIO *peer_bio = b->peer;
764
765 if (peer_bio != NULL)
766 {
767 struct bio_bio_st *peer_b = peer_bio->ptr;
768
769 assert(peer_b != NULL);
770 assert(peer_b->peer == bio);
771
772 peer_b->peer = NULL;
773 peer_bio->init = 0;
774 assert(peer_b->buf != NULL);
775 peer_b->len = 0;
776 peer_b->offset = 0;
777
778 b->peer = NULL;
779 bio->init = 0;
780 assert(b->buf != NULL);
781 b->len = 0;
782 b->offset = 0;
783 }
784 }
785 }
786
787
788/* Exported convenience functions */
789int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
790 BIO **bio2_p, size_t writebuf2)
791 {
792 BIO *bio1 = NULL, *bio2 = NULL;
793 long r;
794 int ret = 0;
795
796 bio1 = BIO_new(BIO_s_bio());
797 if (bio1 == NULL)
798 goto err;
799 bio2 = BIO_new(BIO_s_bio());
800 if (bio2 == NULL)
801 goto err;
802
803 if (writebuf1)
804 {
805 r = BIO_set_write_buf_size(bio1, writebuf1);
806 if (!r)
807 goto err;
808 }
809 if (writebuf2)
810 {
811 r = BIO_set_write_buf_size(bio2, writebuf2);
812 if (!r)
813 goto err;
814 }
815
816 r = BIO_make_bio_pair(bio1, bio2);
817 if (!r)
818 goto err;
819 ret = 1;
820
821 err:
822 if (ret == 0)
823 {
824 if (bio1)
825 {
826 BIO_free(bio1);
827 bio1 = NULL;
828 }
829 if (bio2)
830 {
831 BIO_free(bio2);
832 bio2 = NULL;
833 }
834 }
835
836 *bio1_p = bio1;
837 *bio2_p = bio2;
838 return ret;
839 }
840
841size_t BIO_ctrl_get_write_guarantee(BIO *bio)
842 {
843 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
844 }
845
846size_t BIO_ctrl_get_read_request(BIO *bio)
847 {
848 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
849 }
850
851int BIO_ctrl_reset_read_request(BIO *bio)
852 {
853 return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
854 }
855
856
857/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
858 * (conceivably some other BIOs could allow non-copying reads and writes too.)
859 */
860int BIO_nread0(BIO *bio, char **buf)
861 {
862 long ret;
863
864 if (!bio->init)
865 {
866 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
867 return -2;
868 }
869
870 ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
871 if (ret > INT_MAX)
872 return INT_MAX;
873 else
874 return (int) ret;
875 }
876
877int BIO_nread(BIO *bio, char **buf, int num)
878 {
879 int ret;
880
881 if (!bio->init)
882 {
883 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
884 return -2;
885 }
886
887 ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
888 if (ret > 0)
889 bio->num_read += ret;
890 return ret;
891 }
892
893int BIO_nwrite0(BIO *bio, char **buf)
894 {
895 long ret;
896
897 if (!bio->init)
898 {
899 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
900 return -2;
901 }
902
903 ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
904 if (ret > INT_MAX)
905 return INT_MAX;
906 else
907 return (int) ret;
908 }
909
910int BIO_nwrite(BIO *bio, char **buf, int num)
911 {
912 int ret;
913
914 if (!bio->init)
915 {
916 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
917 return -2;
918 }
919
920 ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
921 if (ret > 0)
922 bio->num_read += ret;
923 return ret;
924 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
new file mode 100644
index 0000000000..f5d0e759e2
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -0,0 +1,652 @@
1/* crypto/bio/bss_conn.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#ifdef OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78
79typedef struct bio_connect_st
80 {
81 int state;
82
83 char *param_hostname;
84 char *param_port;
85 int nbio;
86
87 unsigned char ip[4];
88 unsigned short port;
89
90 struct sockaddr_in them;
91
92 /* int socket; this will be kept in bio->num so that it is
93 * compatible with the bss_sock bio */
94
95 /* called when the connection is initially made
96 * callback(BIO,state,ret); The callback should return
97 * 'ret'. state is for compatibility with the ssl info_callback */
98 int (*info_callback)(const BIO *bio,int state,int ret);
99 } BIO_CONNECT;
100
101static int conn_write(BIO *h, const char *buf, int num);
102static int conn_read(BIO *h, char *buf, int size);
103static int conn_puts(BIO *h, const char *str);
104static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2);
105static int conn_new(BIO *h);
106static int conn_free(BIO *data);
107static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *);
108
109static int conn_state(BIO *b, BIO_CONNECT *c);
110static void conn_close_socket(BIO *data);
111BIO_CONNECT *BIO_CONNECT_new(void );
112void BIO_CONNECT_free(BIO_CONNECT *a);
113
114static BIO_METHOD methods_connectp=
115 {
116 BIO_TYPE_CONNECT,
117 "socket connect",
118 conn_write,
119 conn_read,
120 conn_puts,
121 NULL, /* connect_gets, */
122 conn_ctrl,
123 conn_new,
124 conn_free,
125 conn_callback_ctrl,
126 };
127
128static int conn_state(BIO *b, BIO_CONNECT *c)
129 {
130 int ret= -1,i;
131 unsigned long l;
132 char *p,*q;
133 int (*cb)()=NULL;
134
135 if (c->info_callback != NULL)
136 cb=c->info_callback;
137
138 for (;;)
139 {
140 switch (c->state)
141 {
142 case BIO_CONN_S_BEFORE:
143 p=c->param_hostname;
144 if (p == NULL)
145 {
146 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
147 goto exit_loop;
148 }
149 for ( ; *p != '\0'; p++)
150 {
151 if ((*p == ':') || (*p == '/')) break;
152 }
153
154 i= *p;
155 if ((i == ':') || (i == '/'))
156 {
157
158 *(p++)='\0';
159 if (i == ':')
160 {
161 for (q=p; *q; q++)
162 if (*q == '/')
163 {
164 *q='\0';
165 break;
166 }
167 if (c->param_port != NULL)
168 OPENSSL_free(c->param_port);
169 c->param_port=BUF_strdup(p);
170 }
171 }
172
173 if (c->param_port == NULL)
174 {
175 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
176 ERR_add_error_data(2,"host=",c->param_hostname);
177 goto exit_loop;
178 }
179 c->state=BIO_CONN_S_GET_IP;
180 break;
181
182 case BIO_CONN_S_GET_IP:
183 if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
184 goto exit_loop;
185 c->state=BIO_CONN_S_GET_PORT;
186 break;
187
188 case BIO_CONN_S_GET_PORT:
189 if (c->param_port == NULL)
190 {
191 /* abort(); */
192 goto exit_loop;
193 }
194 else if (BIO_get_port(c->param_port,&c->port) <= 0)
195 goto exit_loop;
196 c->state=BIO_CONN_S_CREATE_SOCKET;
197 break;
198
199 case BIO_CONN_S_CREATE_SOCKET:
200 /* now setup address */
201 memset((char *)&c->them,0,sizeof(c->them));
202 c->them.sin_family=AF_INET;
203 c->them.sin_port=htons((unsigned short)c->port);
204 l=(unsigned long)
205 ((unsigned long)c->ip[0]<<24L)|
206 ((unsigned long)c->ip[1]<<16L)|
207 ((unsigned long)c->ip[2]<< 8L)|
208 ((unsigned long)c->ip[3]);
209 c->them.sin_addr.s_addr=htonl(l);
210 c->state=BIO_CONN_S_CREATE_SOCKET;
211
212 ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
213 if (ret == INVALID_SOCKET)
214 {
215 SYSerr(SYS_F_SOCKET,get_last_socket_error());
216 ERR_add_error_data(4,"host=",c->param_hostname,
217 ":",c->param_port);
218 BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
219 goto exit_loop;
220 }
221 b->num=ret;
222 c->state=BIO_CONN_S_NBIO;
223 break;
224
225 case BIO_CONN_S_NBIO:
226 if (c->nbio)
227 {
228 if (!BIO_socket_nbio(b->num,1))
229 {
230 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
231 ERR_add_error_data(4,"host=",
232 c->param_hostname,
233 ":",c->param_port);
234 goto exit_loop;
235 }
236 }
237 c->state=BIO_CONN_S_CONNECT;
238
239#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
240 i=1;
241 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
242 if (i < 0)
243 {
244 SYSerr(SYS_F_SOCKET,get_last_socket_error());
245 ERR_add_error_data(4,"host=",c->param_hostname,
246 ":",c->param_port);
247 BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
248 goto exit_loop;
249 }
250#endif
251 break;
252
253 case BIO_CONN_S_CONNECT:
254 BIO_clear_retry_flags(b);
255 ret=connect(b->num,
256 (struct sockaddr *)&c->them,
257 sizeof(c->them));
258 b->retry_reason=0;
259 if (ret < 0)
260 {
261 if (BIO_sock_should_retry(ret))
262 {
263 BIO_set_retry_special(b);
264 c->state=BIO_CONN_S_BLOCKED_CONNECT;
265 b->retry_reason=BIO_RR_CONNECT;
266 }
267 else
268 {
269 SYSerr(SYS_F_CONNECT,get_last_socket_error());
270 ERR_add_error_data(4,"host=",
271 c->param_hostname,
272 ":",c->param_port);
273 BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
274 }
275 goto exit_loop;
276 }
277 else
278 c->state=BIO_CONN_S_OK;
279 break;
280
281 case BIO_CONN_S_BLOCKED_CONNECT:
282 i=BIO_sock_error(b->num);
283 if (i)
284 {
285 BIO_clear_retry_flags(b);
286 SYSerr(SYS_F_CONNECT,i);
287 ERR_add_error_data(4,"host=",
288 c->param_hostname,
289 ":",c->param_port);
290 BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
291 ret=0;
292 goto exit_loop;
293 }
294 else
295 c->state=BIO_CONN_S_OK;
296 break;
297
298 case BIO_CONN_S_OK:
299 ret=1;
300 goto exit_loop;
301 default:
302 /* abort(); */
303 goto exit_loop;
304 }
305
306 if (cb != NULL)
307 {
308 if (!(ret=cb((BIO *)b,c->state,ret)))
309 goto end;
310 }
311 }
312
313 /* Loop does not exit */
314exit_loop:
315 if (cb != NULL)
316 ret=cb((BIO *)b,c->state,ret);
317end:
318 return(ret);
319 }
320
321BIO_CONNECT *BIO_CONNECT_new(void)
322 {
323 BIO_CONNECT *ret;
324
325 if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
326 return(NULL);
327 ret->state=BIO_CONN_S_BEFORE;
328 ret->param_hostname=NULL;
329 ret->param_port=NULL;
330 ret->info_callback=NULL;
331 ret->nbio=0;
332 ret->ip[0]=0;
333 ret->ip[1]=0;
334 ret->ip[2]=0;
335 ret->ip[3]=0;
336 ret->port=0;
337 memset((char *)&ret->them,0,sizeof(ret->them));
338 return(ret);
339 }
340
341void BIO_CONNECT_free(BIO_CONNECT *a)
342 {
343 if(a == NULL)
344 return;
345
346 if (a->param_hostname != NULL)
347 OPENSSL_free(a->param_hostname);
348 if (a->param_port != NULL)
349 OPENSSL_free(a->param_port);
350 OPENSSL_free(a);
351 }
352
353BIO_METHOD *BIO_s_connect(void)
354 {
355 return(&methods_connectp);
356 }
357
358static int conn_new(BIO *bi)
359 {
360 bi->init=0;
361 bi->num=INVALID_SOCKET;
362 bi->flags=0;
363 if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
364 return(0);
365 else
366 return(1);
367 }
368
369static void conn_close_socket(BIO *bio)
370 {
371 BIO_CONNECT *c;
372
373 c=(BIO_CONNECT *)bio->ptr;
374 if (bio->num != INVALID_SOCKET)
375 {
376 /* Only do a shutdown if things were established */
377 if (c->state == BIO_CONN_S_OK)
378 shutdown(bio->num,2);
379 closesocket(bio->num);
380 bio->num=INVALID_SOCKET;
381 }
382 }
383
384static int conn_free(BIO *a)
385 {
386 BIO_CONNECT *data;
387
388 if (a == NULL) return(0);
389 data=(BIO_CONNECT *)a->ptr;
390
391 if (a->shutdown)
392 {
393 conn_close_socket(a);
394 BIO_CONNECT_free(data);
395 a->ptr=NULL;
396 a->flags=0;
397 a->init=0;
398 }
399 return(1);
400 }
401
402static int conn_read(BIO *b, char *out, int outl)
403 {
404 int ret=0;
405 BIO_CONNECT *data;
406
407 data=(BIO_CONNECT *)b->ptr;
408 if (data->state != BIO_CONN_S_OK)
409 {
410 ret=conn_state(b,data);
411 if (ret <= 0)
412 return(ret);
413 }
414
415 if (out != NULL)
416 {
417 clear_socket_error();
418 ret=readsocket(b->num,out,outl);
419 BIO_clear_retry_flags(b);
420 if (ret <= 0)
421 {
422 if (BIO_sock_should_retry(ret))
423 BIO_set_retry_read(b);
424 }
425 }
426 return(ret);
427 }
428
429static int conn_write(BIO *b, const char *in, int inl)
430 {
431 int ret;
432 BIO_CONNECT *data;
433
434 data=(BIO_CONNECT *)b->ptr;
435 if (data->state != BIO_CONN_S_OK)
436 {
437 ret=conn_state(b,data);
438 if (ret <= 0) return(ret);
439 }
440
441 clear_socket_error();
442 ret=writesocket(b->num,in,inl);
443 BIO_clear_retry_flags(b);
444 if (ret <= 0)
445 {
446 if (BIO_sock_should_retry(ret))
447 BIO_set_retry_write(b);
448 }
449 return(ret);
450 }
451
452static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
453 {
454 BIO *dbio;
455 int *ip;
456 const char **pptr;
457 long ret=1;
458 BIO_CONNECT *data;
459
460 data=(BIO_CONNECT *)b->ptr;
461
462 switch (cmd)
463 {
464 case BIO_CTRL_RESET:
465 ret=0;
466 data->state=BIO_CONN_S_BEFORE;
467 conn_close_socket(b);
468 b->flags=0;
469 break;
470 case BIO_C_DO_STATE_MACHINE:
471 /* use this one to start the connection */
472 if (!data->state != BIO_CONN_S_OK)
473 ret=(long)conn_state(b,data);
474 else
475 ret=1;
476 break;
477 case BIO_C_GET_CONNECT:
478 if (ptr != NULL)
479 {
480 pptr=(const char **)ptr;
481 if (num == 0)
482 {
483 *pptr=data->param_hostname;
484
485 }
486 else if (num == 1)
487 {
488 *pptr=data->param_port;
489 }
490 else if (num == 2)
491 {
492 *pptr= (char *)&(data->ip[0]);
493 }
494 else if (num == 3)
495 {
496 *((int *)ptr)=data->port;
497 }
498 if ((!b->init) || (ptr == NULL))
499 *pptr="not initialized";
500 ret=1;
501 }
502 break;
503 case BIO_C_SET_CONNECT:
504 if (ptr != NULL)
505 {
506 b->init=1;
507 if (num == 0)
508 {
509 if (data->param_hostname != NULL)
510 OPENSSL_free(data->param_hostname);
511 data->param_hostname=BUF_strdup(ptr);
512 }
513 else if (num == 1)
514 {
515 if (data->param_port != NULL)
516 OPENSSL_free(data->param_port);
517 data->param_port=BUF_strdup(ptr);
518 }
519 else if (num == 2)
520 {
521 char buf[16];
522 unsigned char *p = ptr;
523
524 BIO_snprintf(buf,sizeof buf,"%d.%d.%d.%d",
525 p[0],p[1],p[2],p[3]);
526 if (data->param_hostname != NULL)
527 OPENSSL_free(data->param_hostname);
528 data->param_hostname=BUF_strdup(buf);
529 memcpy(&(data->ip[0]),ptr,4);
530 }
531 else if (num == 3)
532 {
533 char buf[DECIMAL_SIZE(int)+1];
534
535 BIO_snprintf(buf,sizeof buf,"%d",*(int *)ptr);
536 if (data->param_port != NULL)
537 OPENSSL_free(data->param_port);
538 data->param_port=BUF_strdup(buf);
539 data->port= *(int *)ptr;
540 }
541 }
542 break;
543 case BIO_C_SET_NBIO:
544 data->nbio=(int)num;
545 break;
546 case BIO_C_GET_FD:
547 if (b->init)
548 {
549 ip=(int *)ptr;
550 if (ip != NULL)
551 *ip=b->num;
552 ret=b->num;
553 }
554 else
555 ret= -1;
556 break;
557 case BIO_CTRL_GET_CLOSE:
558 ret=b->shutdown;
559 break;
560 case BIO_CTRL_SET_CLOSE:
561 b->shutdown=(int)num;
562 break;
563 case BIO_CTRL_PENDING:
564 case BIO_CTRL_WPENDING:
565 ret=0;
566 break;
567 case BIO_CTRL_FLUSH:
568 break;
569 case BIO_CTRL_DUP:
570 {
571 dbio=(BIO *)ptr;
572 if (data->param_port)
573 BIO_set_conn_port(dbio,data->param_port);
574 if (data->param_hostname)
575 BIO_set_conn_hostname(dbio,data->param_hostname);
576 BIO_set_nbio(dbio,data->nbio);
577 /* FIXME: the cast of the function seems unlikely to be a good idea */
578 (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback);
579 }
580 break;
581 case BIO_CTRL_SET_CALLBACK:
582 {
583#if 0 /* FIXME: Should this be used? -- Richard Levitte */
584 BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
585 ret = -1;
586#else
587 ret=0;
588#endif
589 }
590 break;
591 case BIO_CTRL_GET_CALLBACK:
592 {
593 int (**fptr)();
594
595 fptr=(int (**)())ptr;
596 *fptr=data->info_callback;
597 }
598 break;
599 default:
600 ret=0;
601 break;
602 }
603 return(ret);
604 }
605
606static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
607 {
608 long ret=1;
609 BIO_CONNECT *data;
610
611 data=(BIO_CONNECT *)b->ptr;
612
613 switch (cmd)
614 {
615 case BIO_CTRL_SET_CALLBACK:
616 {
617 data->info_callback=(int (*)(const struct bio_st *, int, int))fp;
618 }
619 break;
620 default:
621 ret=0;
622 break;
623 }
624 return(ret);
625 }
626
627static int conn_puts(BIO *bp, const char *str)
628 {
629 int n,ret;
630
631 n=strlen(str);
632 ret=conn_write(bp,str,n);
633 return(ret);
634 }
635
636BIO *BIO_new_connect(char *str)
637 {
638 BIO *ret;
639
640 ret=BIO_new(BIO_s_connect());
641 if (ret == NULL) return(NULL);
642 if (BIO_set_conn_hostname(ret,str))
643 return(ret);
644 else
645 {
646 BIO_free(ret);
647 return(NULL);
648 }
649 }
650
651#endif
652
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
new file mode 100644
index 0000000000..5e3e187de6
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_fd.c
@@ -0,0 +1,282 @@
1/* crypto/bio/bss_fd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#define USE_SOCKETS
62#include "cryptlib.h"
63#include <openssl/bio.h>
64
65static int fd_write(BIO *h, const char *buf, int num);
66static int fd_read(BIO *h, char *buf, int size);
67static int fd_puts(BIO *h, const char *str);
68static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int fd_new(BIO *h);
70static int fd_free(BIO *data);
71int BIO_fd_should_retry(int s);
72
73static BIO_METHOD methods_fdp=
74 {
75 BIO_TYPE_FD,"file descriptor",
76 fd_write,
77 fd_read,
78 fd_puts,
79 NULL, /* fd_gets, */
80 fd_ctrl,
81 fd_new,
82 fd_free,
83 NULL,
84 };
85
86BIO_METHOD *BIO_s_fd(void)
87 {
88 return(&methods_fdp);
89 }
90
91BIO *BIO_new_fd(int fd,int close_flag)
92 {
93 BIO *ret;
94 ret=BIO_new(BIO_s_fd());
95 if (ret == NULL) return(NULL);
96 BIO_set_fd(ret,fd,close_flag);
97 return(ret);
98 }
99
100static int fd_new(BIO *bi)
101 {
102 bi->init=0;
103 bi->num=0;
104 bi->ptr=NULL;
105 bi->flags=0;
106 return(1);
107 }
108
109static int fd_free(BIO *a)
110 {
111 if (a == NULL) return(0);
112 if (a->shutdown)
113 {
114 if (a->init)
115 {
116 close(a->num);
117 }
118 a->init=0;
119 a->flags=0;
120 }
121 return(1);
122 }
123
124static int fd_read(BIO *b, char *out,int outl)
125 {
126 int ret=0;
127
128 if (out != NULL)
129 {
130 clear_sys_error();
131 ret=read(b->num,out,outl);
132 BIO_clear_retry_flags(b);
133 if (ret <= 0)
134 {
135 if (BIO_fd_should_retry(ret))
136 BIO_set_retry_read(b);
137 }
138 }
139 return(ret);
140 }
141
142static int fd_write(BIO *b, const char *in, int inl)
143 {
144 int ret;
145 clear_sys_error();
146 ret=write(b->num,in,inl);
147 BIO_clear_retry_flags(b);
148 if (ret <= 0)
149 {
150 if (BIO_fd_should_retry(ret))
151 BIO_set_retry_write(b);
152 }
153 return(ret);
154 }
155
156static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
157 {
158 long ret=1;
159 int *ip;
160
161 switch (cmd)
162 {
163 case BIO_CTRL_RESET:
164 num=0;
165 case BIO_C_FILE_SEEK:
166 ret=(long)lseek(b->num,num,0);
167 break;
168 case BIO_C_FILE_TELL:
169 case BIO_CTRL_INFO:
170 ret=(long)lseek(b->num,0,1);
171 break;
172 case BIO_C_SET_FD:
173 fd_free(b);
174 b->num= *((int *)ptr);
175 b->shutdown=(int)num;
176 b->init=1;
177 break;
178 case BIO_C_GET_FD:
179 if (b->init)
180 {
181 ip=(int *)ptr;
182 if (ip != NULL) *ip=b->num;
183 ret=b->num;
184 }
185 else
186 ret= -1;
187 break;
188 case BIO_CTRL_GET_CLOSE:
189 ret=b->shutdown;
190 break;
191 case BIO_CTRL_SET_CLOSE:
192 b->shutdown=(int)num;
193 break;
194 case BIO_CTRL_PENDING:
195 case BIO_CTRL_WPENDING:
196 ret=0;
197 break;
198 case BIO_CTRL_DUP:
199 case BIO_CTRL_FLUSH:
200 ret=1;
201 break;
202 default:
203 ret=0;
204 break;
205 }
206 return(ret);
207 }
208
209static int fd_puts(BIO *bp, const char *str)
210 {
211 int n,ret;
212
213 n=strlen(str);
214 ret=fd_write(bp,str,n);
215 return(ret);
216 }
217
218int BIO_fd_should_retry(int i)
219 {
220 int err;
221
222 if ((i == 0) || (i == -1))
223 {
224 err=get_last_sys_error();
225
226#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
227 if ((i == -1) && (err == 0))
228 return(1);
229#endif
230
231 return(BIO_fd_non_fatal_error(err));
232 }
233 return(0);
234 }
235
236int BIO_fd_non_fatal_error(int err)
237 {
238 switch (err)
239 {
240
241#ifdef EWOULDBLOCK
242# ifdef WSAEWOULDBLOCK
243# if WSAEWOULDBLOCK != EWOULDBLOCK
244 case EWOULDBLOCK:
245# endif
246# else
247 case EWOULDBLOCK:
248# endif
249#endif
250
251#if defined(ENOTCONN)
252 case ENOTCONN:
253#endif
254
255#ifdef EINTR
256 case EINTR:
257#endif
258
259#ifdef EAGAIN
260#if EWOULDBLOCK != EAGAIN
261 case EAGAIN:
262# endif
263#endif
264
265#ifdef EPROTO
266 case EPROTO:
267#endif
268
269#ifdef EINPROGRESS
270 case EINPROGRESS:
271#endif
272
273#ifdef EALREADY
274 case EALREADY:
275#endif
276 return(1);
277 /* break; */
278 default:
279 break;
280 }
281 return(0);
282 }
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
new file mode 100644
index 0000000000..8034ac93f9
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -0,0 +1,343 @@
1/* crypto/bio/bss_file.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 * 03-Dec-1997 rdenny@dc3.com Fix bug preventing use of stdin/stdout
61 * with binary data (e.g. asn1parse -inform DER < xxx) under
62 * Windows
63 */
64
65#ifndef HEADER_BSS_FILE_C
66#define HEADER_BSS_FILE_C
67
68#include <stdio.h>
69#include <errno.h>
70#include "cryptlib.h"
71#include <openssl/bio.h>
72#include <openssl/err.h>
73
74#if !defined(OPENSSL_NO_STDIO)
75
76static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
77static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
78static int MS_CALLBACK file_puts(BIO *h, const char *str);
79static int MS_CALLBACK file_gets(BIO *h, char *str, int size);
80static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
81static int MS_CALLBACK file_new(BIO *h);
82static int MS_CALLBACK file_free(BIO *data);
83static BIO_METHOD methods_filep=
84 {
85 BIO_TYPE_FILE,
86 "FILE pointer",
87 file_write,
88 file_read,
89 file_puts,
90 file_gets,
91 file_ctrl,
92 file_new,
93 file_free,
94 NULL,
95 };
96
97BIO *BIO_new_file(const char *filename, const char *mode)
98 {
99 BIO *ret;
100 FILE *file;
101
102 if ((file=fopen(filename,mode)) == NULL)
103 {
104 SYSerr(SYS_F_FOPEN,get_last_sys_error());
105 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
106 if (errno == ENOENT)
107 BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
108 else
109 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
110 return(NULL);
111 }
112 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
113 return(NULL);
114
115 BIO_set_fp(ret,file,BIO_CLOSE);
116 return(ret);
117 }
118
119BIO *BIO_new_fp(FILE *stream, int close_flag)
120 {
121 BIO *ret;
122
123 if ((ret=BIO_new(BIO_s_file())) == NULL)
124 return(NULL);
125
126 BIO_set_fp(ret,stream,close_flag);
127 return(ret);
128 }
129
130BIO_METHOD *BIO_s_file(void)
131 {
132 return(&methods_filep);
133 }
134
135static int MS_CALLBACK file_new(BIO *bi)
136 {
137 bi->init=0;
138 bi->num=0;
139 bi->ptr=NULL;
140 return(1);
141 }
142
143static int MS_CALLBACK file_free(BIO *a)
144 {
145 if (a == NULL) return(0);
146 if (a->shutdown)
147 {
148 if ((a->init) && (a->ptr != NULL))
149 {
150 fclose((FILE *)a->ptr);
151 a->ptr=NULL;
152 }
153 a->init=0;
154 }
155 return(1);
156 }
157
158static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
159 {
160 int ret=0;
161
162 if (b->init && (out != NULL))
163 {
164 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
165 if(ret == 0 && ferror((FILE *)b->ptr))
166 {
167 SYSerr(SYS_F_FREAD,get_last_sys_error());
168 BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
169 ret=-1;
170 }
171 }
172 return(ret);
173 }
174
175static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
176 {
177 int ret=0;
178
179 if (b->init && (in != NULL))
180 {
181 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
182 ret=inl;
183 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
184 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented
185 * out version above can cause 'inl' write calls under
186 * some stupid stdio implementations (VMS) */
187 }
188 return(ret);
189 }
190
191static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
192 {
193 long ret=1;
194 FILE *fp=(FILE *)b->ptr;
195 FILE **fpp;
196 char p[4];
197
198 switch (cmd)
199 {
200 case BIO_C_FILE_SEEK:
201 case BIO_CTRL_RESET:
202 ret=(long)fseek(fp,num,0);
203 break;
204 case BIO_CTRL_EOF:
205 ret=(long)feof(fp);
206 break;
207 case BIO_C_FILE_TELL:
208 case BIO_CTRL_INFO:
209 ret=ftell(fp);
210 break;
211 case BIO_C_SET_FILE_PTR:
212 file_free(b);
213 b->shutdown=(int)num&BIO_CLOSE;
214 b->ptr=(char *)ptr;
215 b->init=1;
216 {
217#if defined(OPENSSL_SYS_WINDOWS)
218 int fd = fileno((FILE*)ptr);
219 if (num & BIO_FP_TEXT)
220 _setmode(fd,_O_TEXT);
221 else
222 _setmode(fd,_O_BINARY);
223#elif defined(OPENSSL_SYS_MSDOS)
224 int fd = fileno((FILE*)ptr);
225 /* Set correct text/binary mode */
226 if (num & BIO_FP_TEXT)
227 _setmode(fd,_O_TEXT);
228 /* Dangerous to set stdin/stdout to raw (unless redirected) */
229 else
230 {
231 if (fd == STDIN_FILENO || fd == STDOUT_FILENO)
232 {
233 if (isatty(fd) <= 0)
234 _setmode(fd,_O_BINARY);
235 }
236 else
237 _setmode(fd,_O_BINARY);
238 }
239#elif defined(OPENSSL_SYS_OS2)
240 int fd = fileno((FILE*)ptr);
241 if (num & BIO_FP_TEXT)
242 setmode(fd, O_TEXT);
243 else
244 setmode(fd, O_BINARY);
245#endif
246 }
247 break;
248 case BIO_C_SET_FILENAME:
249 file_free(b);
250 b->shutdown=(int)num&BIO_CLOSE;
251 if (num & BIO_FP_APPEND)
252 {
253 if (num & BIO_FP_READ)
254 BUF_strlcpy(p,"a+",sizeof p);
255 else BUF_strlcpy(p,"a",sizeof p);
256 }
257 else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
258 BUF_strlcpy(p,"r+",sizeof p);
259 else if (num & BIO_FP_WRITE)
260 BUF_strlcpy(p,"w",sizeof p);
261 else if (num & BIO_FP_READ)
262 BUF_strlcpy(p,"r",sizeof p);
263 else
264 {
265 BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
266 ret=0;
267 break;
268 }
269#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
270 if (!(num & BIO_FP_TEXT))
271 strcat(p,"b");
272 else
273 strcat(p,"t");
274#endif
275 fp=fopen(ptr,p);
276 if (fp == NULL)
277 {
278 SYSerr(SYS_F_FOPEN,get_last_sys_error());
279 ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
280 BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
281 ret=0;
282 break;
283 }
284 b->ptr=(char *)fp;
285 b->init=1;
286 break;
287 case BIO_C_GET_FILE_PTR:
288 /* the ptr parameter is actually a FILE ** in this case. */
289 if (ptr != NULL)
290 {
291 fpp=(FILE **)ptr;
292 *fpp=(FILE *)b->ptr;
293 }
294 break;
295 case BIO_CTRL_GET_CLOSE:
296 ret=(long)b->shutdown;
297 break;
298 case BIO_CTRL_SET_CLOSE:
299 b->shutdown=(int)num;
300 break;
301 case BIO_CTRL_FLUSH:
302 fflush((FILE *)b->ptr);
303 break;
304 case BIO_CTRL_DUP:
305 ret=1;
306 break;
307
308 case BIO_CTRL_WPENDING:
309 case BIO_CTRL_PENDING:
310 case BIO_CTRL_PUSH:
311 case BIO_CTRL_POP:
312 default:
313 ret=0;
314 break;
315 }
316 return(ret);
317 }
318
319static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
320 {
321 int ret=0;
322
323 buf[0]='\0';
324 fgets(buf,size,(FILE *)bp->ptr);
325 if (buf[0] != '\0')
326 ret=strlen(buf);
327 return(ret);
328 }
329
330static int MS_CALLBACK file_puts(BIO *bp, const char *str)
331 {
332 int n,ret;
333
334 n=strlen(str);
335 ret=file_write(bp,str,n);
336 return(ret);
337 }
338
339#endif /* OPENSSL_NO_STDIO */
340
341#endif /* HEADER_BSS_FILE_C */
342
343
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
new file mode 100644
index 0000000000..1eb678cac0
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -0,0 +1,400 @@
1/* crypto/bio/bss_log.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 Why BIO_s_log?
58
59 BIO_s_log is useful for system daemons (or services under NT).
60 It is one-way BIO, it sends all stuff to syslogd (on system that
61 commonly use that), or event log (on NT), or OPCOM (on OpenVMS).
62
63*/
64
65
66#include <stdio.h>
67#include <errno.h>
68
69#include "cryptlib.h"
70
71#if defined(OPENSSL_SYS_WINCE)
72#elif defined(OPENSSL_SYS_WIN32)
73# include <process.h>
74#elif defined(OPENSSL_SYS_VMS)
75# include <opcdef.h>
76# include <descrip.h>
77# include <lib$routines.h>
78# include <starlet.h>
79#elif defined(__ultrix)
80# include <sys/syslog.h>
81#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG)
82# include <syslog.h>
83#endif
84
85#include <openssl/buffer.h>
86#include <openssl/err.h>
87
88#ifndef NO_SYSLOG
89
90#if defined(OPENSSL_SYS_WIN32)
91#define LOG_EMERG 0
92#define LOG_ALERT 1
93#define LOG_CRIT 2
94#define LOG_ERR 3
95#define LOG_WARNING 4
96#define LOG_NOTICE 5
97#define LOG_INFO 6
98#define LOG_DEBUG 7
99
100#define LOG_DAEMON (3<<3)
101#elif defined(OPENSSL_SYS_VMS)
102/* On VMS, we don't really care about these, but we need them to compile */
103#define LOG_EMERG 0
104#define LOG_ALERT 1
105#define LOG_CRIT 2
106#define LOG_ERR 3
107#define LOG_WARNING 4
108#define LOG_NOTICE 5
109#define LOG_INFO 6
110#define LOG_DEBUG 7
111
112#define LOG_DAEMON OPC$M_NM_NTWORK
113#endif
114
115static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num);
116static int MS_CALLBACK slg_puts(BIO *h, const char *str);
117static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
118static int MS_CALLBACK slg_new(BIO *h);
119static int MS_CALLBACK slg_free(BIO *data);
120static void xopenlog(BIO* bp, char* name, int level);
121static void xsyslog(BIO* bp, int priority, const char* string);
122static void xcloselog(BIO* bp);
123#ifdef OPENSSL_SYS_WIN32
124LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
125HANDLE (WINAPI *register_event_source)() = NULL;
126BOOL (WINAPI *deregister_event_source)() = NULL;
127BOOL (WINAPI *report_event)() = NULL;
128#define DL_PROC(m,f) (GetProcAddress( m, f ))
129#ifdef UNICODE
130#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
131#else
132#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
133#endif
134#endif
135
136static BIO_METHOD methods_slg=
137 {
138 BIO_TYPE_MEM,"syslog",
139 slg_write,
140 NULL,
141 slg_puts,
142 NULL,
143 slg_ctrl,
144 slg_new,
145 slg_free,
146 NULL,
147 };
148
149BIO_METHOD *BIO_s_log(void)
150 {
151 return(&methods_slg);
152 }
153
154static int MS_CALLBACK slg_new(BIO *bi)
155 {
156 bi->init=1;
157 bi->num=0;
158 bi->ptr=NULL;
159 xopenlog(bi, "application", LOG_DAEMON);
160 return(1);
161 }
162
163static int MS_CALLBACK slg_free(BIO *a)
164 {
165 if (a == NULL) return(0);
166 xcloselog(a);
167 return(1);
168 }
169
170static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
171 {
172 int ret= inl;
173 char* buf;
174 char* pp;
175 int priority, i;
176 static struct
177 {
178 int strl;
179 char str[10];
180 int log_level;
181 }
182 mapping[] =
183 {
184 { 6, "PANIC ", LOG_EMERG },
185 { 6, "EMERG ", LOG_EMERG },
186 { 4, "EMR ", LOG_EMERG },
187 { 6, "ALERT ", LOG_ALERT },
188 { 4, "ALR ", LOG_ALERT },
189 { 5, "CRIT ", LOG_CRIT },
190 { 4, "CRI ", LOG_CRIT },
191 { 6, "ERROR ", LOG_ERR },
192 { 4, "ERR ", LOG_ERR },
193 { 8, "WARNING ", LOG_WARNING },
194 { 5, "WARN ", LOG_WARNING },
195 { 4, "WAR ", LOG_WARNING },
196 { 7, "NOTICE ", LOG_NOTICE },
197 { 5, "NOTE ", LOG_NOTICE },
198 { 4, "NOT ", LOG_NOTICE },
199 { 5, "INFO ", LOG_INFO },
200 { 4, "INF ", LOG_INFO },
201 { 6, "DEBUG ", LOG_DEBUG },
202 { 4, "DBG ", LOG_DEBUG },
203 { 0, "", LOG_ERR } /* The default */
204 };
205
206 if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
207 return(0);
208 }
209 strncpy(buf, in, inl);
210 buf[inl]= '\0';
211
212 i = 0;
213 while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
214 priority = mapping[i].log_level;
215 pp = buf + mapping[i].strl;
216
217 xsyslog(b, priority, pp);
218
219 OPENSSL_free(buf);
220 return(ret);
221 }
222
223static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr)
224 {
225 switch (cmd)
226 {
227 case BIO_CTRL_SET:
228 xcloselog(b);
229 xopenlog(b, ptr, num);
230 break;
231 default:
232 break;
233 }
234 return(0);
235 }
236
237static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
238 {
239 int n,ret;
240
241 n=strlen(str);
242 ret=slg_write(bp,str,n);
243 return(ret);
244 }
245
246#if defined(OPENSSL_SYS_WIN32)
247
248static void xopenlog(BIO* bp, char* name, int level)
249{
250 if ( !register_event_source )
251 {
252 HANDLE advapi;
253 if ( !(advapi = GetModuleHandle("advapi32")) )
254 return;
255 register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
256 "RegisterEventSource" );
257 deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
258 "DeregisterEventSource");
259 report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
260 "ReportEvent" );
261 if ( !(register_event_source && deregister_event_source &&
262 report_event) )
263 {
264 register_event_source = NULL;
265 deregister_event_source = NULL;
266 report_event = NULL;
267 return;
268 }
269 }
270 bp->ptr= (char *)register_event_source(NULL, name);
271}
272
273static void xsyslog(BIO *bp, int priority, const char *string)
274{
275 LPCSTR lpszStrings[2];
276 WORD evtype= EVENTLOG_ERROR_TYPE;
277 int pid = _getpid();
278 char pidbuf[DECIMAL_SIZE(pid)+4];
279
280 switch (priority)
281 {
282 case LOG_EMERG:
283 case LOG_ALERT:
284 case LOG_CRIT:
285 case LOG_ERR:
286 evtype = EVENTLOG_ERROR_TYPE;
287 break;
288 case LOG_WARNING:
289 evtype = EVENTLOG_WARNING_TYPE;
290 break;
291 case LOG_NOTICE:
292 case LOG_INFO:
293 case LOG_DEBUG:
294 evtype = EVENTLOG_INFORMATION_TYPE;
295 break;
296 default: /* Should never happen, but set it
297 as error anyway. */
298 evtype = EVENTLOG_ERROR_TYPE;
299 break;
300 }
301
302 sprintf(pidbuf, "[%d] ", pid);
303 lpszStrings[0] = pidbuf;
304 lpszStrings[1] = string;
305
306 if(report_event && bp->ptr)
307 report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
308 lpszStrings, NULL);
309}
310
311static void xcloselog(BIO* bp)
312{
313 if(deregister_event_source && bp->ptr)
314 deregister_event_source((HANDLE)(bp->ptr));
315 bp->ptr= NULL;
316}
317
318#elif defined(OPENSSL_SYS_VMS)
319
320static int VMS_OPC_target = LOG_DAEMON;
321
322static void xopenlog(BIO* bp, char* name, int level)
323{
324 VMS_OPC_target = level;
325}
326
327static void xsyslog(BIO *bp, int priority, const char *string)
328{
329 struct dsc$descriptor_s opc_dsc;
330 struct opcdef *opcdef_p;
331 char buf[10240];
332 unsigned int len;
333 struct dsc$descriptor_s buf_dsc;
334 $DESCRIPTOR(fao_cmd, "!AZ: !AZ");
335 char *priority_tag;
336
337 switch (priority)
338 {
339 case LOG_EMERG: priority_tag = "Emergency"; break;
340 case LOG_ALERT: priority_tag = "Alert"; break;
341 case LOG_CRIT: priority_tag = "Critical"; break;
342 case LOG_ERR: priority_tag = "Error"; break;
343 case LOG_WARNING: priority_tag = "Warning"; break;
344 case LOG_NOTICE: priority_tag = "Notice"; break;
345 case LOG_INFO: priority_tag = "Info"; break;
346 case LOG_DEBUG: priority_tag = "DEBUG"; break;
347 }
348
349 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
350 buf_dsc.dsc$b_class = DSC$K_CLASS_S;
351 buf_dsc.dsc$a_pointer = buf;
352 buf_dsc.dsc$w_length = sizeof(buf) - 1;
353
354 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
355
356 /* we know there's an 8 byte header. That's documented */
357 opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len);
358 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
359 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
360 opcdef_p->opc$l_ms_rqstid = 0;
361 memcpy(&opcdef_p->opc$l_ms_text, buf, len);
362
363 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
364 opc_dsc.dsc$b_class = DSC$K_CLASS_S;
365 opc_dsc.dsc$a_pointer = (char *)opcdef_p;
366 opc_dsc.dsc$w_length = len + 8;
367
368 sys$sndopr(opc_dsc, 0);
369
370 OPENSSL_free(opcdef_p);
371}
372
373static void xcloselog(BIO* bp)
374{
375}
376
377#else /* Unix/Watt32 */
378
379static void xopenlog(BIO* bp, char* name, int level)
380{
381#ifdef WATT32 /* djgpp/DOS */
382 openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level);
383#else
384 openlog(name, LOG_PID|LOG_CONS, level);
385#endif
386}
387
388static void xsyslog(BIO *bp, int priority, const char *string)
389{
390 syslog(priority, "%s", string);
391}
392
393static void xcloselog(BIO* bp)
394{
395 closelog();
396}
397
398#endif /* Unix */
399
400#endif /* NO_SYSLOG */
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
new file mode 100644
index 0000000000..a4edb711ae
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_mem.c
@@ -0,0 +1,321 @@
1/* crypto/bio/bss_mem.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64static int mem_write(BIO *h, const char *buf, int num);
65static int mem_read(BIO *h, char *buf, int size);
66static int mem_puts(BIO *h, const char *str);
67static int mem_gets(BIO *h, char *str, int size);
68static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int mem_new(BIO *h);
70static int mem_free(BIO *data);
71static BIO_METHOD mem_method=
72 {
73 BIO_TYPE_MEM,
74 "memory buffer",
75 mem_write,
76 mem_read,
77 mem_puts,
78 mem_gets,
79 mem_ctrl,
80 mem_new,
81 mem_free,
82 NULL,
83 };
84
85/* bio->num is used to hold the value to return on 'empty', if it is
86 * 0, should_retry is not set */
87
88BIO_METHOD *BIO_s_mem(void)
89 {
90 return(&mem_method);
91 }
92
93BIO *BIO_new_mem_buf(void *buf, int len)
94{
95 BIO *ret;
96 BUF_MEM *b;
97 if (!buf) {
98 BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
99 return NULL;
100 }
101 if(len == -1) len = strlen(buf);
102 if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
103 b = (BUF_MEM *)ret->ptr;
104 b->data = buf;
105 b->length = len;
106 b->max = len;
107 ret->flags |= BIO_FLAGS_MEM_RDONLY;
108 /* Since this is static data retrying wont help */
109 ret->num = 0;
110 return ret;
111}
112
113static int mem_new(BIO *bi)
114 {
115 BUF_MEM *b;
116
117 if ((b=BUF_MEM_new()) == NULL)
118 return(0);
119 bi->shutdown=1;
120 bi->init=1;
121 bi->num= -1;
122 bi->ptr=(char *)b;
123 return(1);
124 }
125
126static int mem_free(BIO *a)
127 {
128 if (a == NULL) return(0);
129 if (a->shutdown)
130 {
131 if ((a->init) && (a->ptr != NULL))
132 {
133 BUF_MEM *b;
134 b = (BUF_MEM *)a->ptr;
135 if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL;
136 BUF_MEM_free(b);
137 a->ptr=NULL;
138 }
139 }
140 return(1);
141 }
142
143static int mem_read(BIO *b, char *out, int outl)
144 {
145 int ret= -1;
146 BUF_MEM *bm;
147 int i;
148 char *from,*to;
149
150 bm=(BUF_MEM *)b->ptr;
151 BIO_clear_retry_flags(b);
152 ret=(outl > bm->length)?bm->length:outl;
153 if ((out != NULL) && (ret > 0)) {
154 memcpy(out,bm->data,ret);
155 bm->length-=ret;
156 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
157 if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
158 else {
159 from=(char *)&(bm->data[ret]);
160 to=(char *)&(bm->data[0]);
161 for (i=0; i<bm->length; i++)
162 to[i]=from[i];
163 }
164 } else if (bm->length == 0)
165 {
166 ret = b->num;
167 if (ret != 0)
168 BIO_set_retry_read(b);
169 }
170 return(ret);
171 }
172
173static int mem_write(BIO *b, const char *in, int inl)
174 {
175 int ret= -1;
176 int blen;
177 BUF_MEM *bm;
178
179 bm=(BUF_MEM *)b->ptr;
180 if (in == NULL)
181 {
182 BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
183 goto end;
184 }
185
186 if(b->flags & BIO_FLAGS_MEM_RDONLY) {
187 BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO);
188 goto end;
189 }
190
191 BIO_clear_retry_flags(b);
192 blen=bm->length;
193 if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl))
194 goto end;
195 memcpy(&(bm->data[blen]),in,inl);
196 ret=inl;
197end:
198 return(ret);
199 }
200
201static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
202 {
203 long ret=1;
204 char **pptr;
205
206 BUF_MEM *bm=(BUF_MEM *)b->ptr;
207
208 switch (cmd)
209 {
210 case BIO_CTRL_RESET:
211 if (bm->data != NULL)
212 {
213 /* For read only case reset to the start again */
214 if(b->flags & BIO_FLAGS_MEM_RDONLY)
215 {
216 bm->data -= bm->max - bm->length;
217 bm->length = bm->max;
218 }
219 else
220 {
221 memset(bm->data,0,bm->max);
222 bm->length=0;
223 }
224 }
225 break;
226 case BIO_CTRL_EOF:
227 ret=(long)(bm->length == 0);
228 break;
229 case BIO_C_SET_BUF_MEM_EOF_RETURN:
230 b->num=(int)num;
231 break;
232 case BIO_CTRL_INFO:
233 ret=(long)bm->length;
234 if (ptr != NULL)
235 {
236 pptr=(char **)ptr;
237 *pptr=(char *)&(bm->data[0]);
238 }
239 break;
240 case BIO_C_SET_BUF_MEM:
241 mem_free(b);
242 b->shutdown=(int)num;
243 b->ptr=ptr;
244 break;
245 case BIO_C_GET_BUF_MEM_PTR:
246 if (ptr != NULL)
247 {
248 pptr=(char **)ptr;
249 *pptr=(char *)bm;
250 }
251 break;
252 case BIO_CTRL_GET_CLOSE:
253 ret=(long)b->shutdown;
254 break;
255 case BIO_CTRL_SET_CLOSE:
256 b->shutdown=(int)num;
257 break;
258
259 case BIO_CTRL_WPENDING:
260 ret=0L;
261 break;
262 case BIO_CTRL_PENDING:
263 ret=(long)bm->length;
264 break;
265 case BIO_CTRL_DUP:
266 case BIO_CTRL_FLUSH:
267 ret=1;
268 break;
269 case BIO_CTRL_PUSH:
270 case BIO_CTRL_POP:
271 default:
272 ret=0;
273 break;
274 }
275 return(ret);
276 }
277
278static int mem_gets(BIO *bp, char *buf, int size)
279 {
280 int i,j;
281 int ret= -1;
282 char *p;
283 BUF_MEM *bm=(BUF_MEM *)bp->ptr;
284
285 BIO_clear_retry_flags(bp);
286 j=bm->length;
287 if (j <= 0)
288 {
289 *buf='\0';
290 return 0;
291 }
292 p=bm->data;
293 for (i=0; i<j; i++)
294 {
295 if (p[i] == '\n') break;
296 }
297 if (i == j)
298 {
299 BIO_set_retry_read(bp);
300 /* return(-1); change the semantics 0.6.6a */
301 }
302 else
303 i++;
304 /* i is the max to copy */
305 if ((size-1) < i) i=size-1;
306 i=mem_read(bp,buf,i);
307 if (i > 0) buf[i]='\0';
308 ret=i;
309 return(ret);
310 }
311
312static int mem_puts(BIO *bp, const char *str)
313 {
314 int n,ret;
315
316 n=strlen(str);
317 ret=mem_write(bp,str,n);
318 /* memory semantics is that it will always work */
319 return(ret);
320 }
321
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
new file mode 100644
index 0000000000..46b73339df
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_null.c
@@ -0,0 +1,150 @@
1/* crypto/bio/bss_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64static int null_write(BIO *h, const char *buf, int num);
65static int null_read(BIO *h, char *buf, int size);
66static int null_puts(BIO *h, const char *str);
67static int null_gets(BIO *h, char *str, int size);
68static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int null_new(BIO *h);
70static int null_free(BIO *data);
71static BIO_METHOD null_method=
72 {
73 BIO_TYPE_NULL,
74 "NULL",
75 null_write,
76 null_read,
77 null_puts,
78 null_gets,
79 null_ctrl,
80 null_new,
81 null_free,
82 NULL,
83 };
84
85BIO_METHOD *BIO_s_null(void)
86 {
87 return(&null_method);
88 }
89
90static int null_new(BIO *bi)
91 {
92 bi->init=1;
93 bi->num=0;
94 bi->ptr=(NULL);
95 return(1);
96 }
97
98static int null_free(BIO *a)
99 {
100 if (a == NULL) return(0);
101 return(1);
102 }
103
104static int null_read(BIO *b, char *out, int outl)
105 {
106 return(0);
107 }
108
109static int null_write(BIO *b, const char *in, int inl)
110 {
111 return(inl);
112 }
113
114static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
115 {
116 long ret=1;
117
118 switch (cmd)
119 {
120 case BIO_CTRL_RESET:
121 case BIO_CTRL_EOF:
122 case BIO_CTRL_SET:
123 case BIO_CTRL_SET_CLOSE:
124 case BIO_CTRL_FLUSH:
125 case BIO_CTRL_DUP:
126 ret=1;
127 break;
128 case BIO_CTRL_GET_CLOSE:
129 case BIO_CTRL_INFO:
130 case BIO_CTRL_GET:
131 case BIO_CTRL_PENDING:
132 case BIO_CTRL_WPENDING:
133 default:
134 ret=0;
135 break;
136 }
137 return(ret);
138 }
139
140static int null_gets(BIO *bp, char *buf, int size)
141 {
142 return(0);
143 }
144
145static int null_puts(BIO *bp, const char *str)
146 {
147 if (str == NULL) return(0);
148 return(strlen(str));
149 }
150
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
new file mode 100644
index 0000000000..2c1c405ec7
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_sock.c
@@ -0,0 +1,305 @@
1/* crypto/bio/bss_sock.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#ifdef WATT32
68#define sock_write SockWrite /* Watt-32 uses same names */
69#define sock_read SockRead
70#define sock_puts SockPuts
71#endif
72
73static int sock_write(BIO *h, const char *buf, int num);
74static int sock_read(BIO *h, char *buf, int size);
75static int sock_puts(BIO *h, const char *str);
76static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2);
77static int sock_new(BIO *h);
78static int sock_free(BIO *data);
79int BIO_sock_should_retry(int s);
80
81static BIO_METHOD methods_sockp=
82 {
83 BIO_TYPE_SOCKET,
84 "socket",
85 sock_write,
86 sock_read,
87 sock_puts,
88 NULL, /* sock_gets, */
89 sock_ctrl,
90 sock_new,
91 sock_free,
92 NULL,
93 };
94
95BIO_METHOD *BIO_s_socket(void)
96 {
97 return(&methods_sockp);
98 }
99
100BIO *BIO_new_socket(int fd, int close_flag)
101 {
102 BIO *ret;
103
104 ret=BIO_new(BIO_s_socket());
105 if (ret == NULL) return(NULL);
106 BIO_set_fd(ret,fd,close_flag);
107 return(ret);
108 }
109
110static int sock_new(BIO *bi)
111 {
112 bi->init=0;
113 bi->num=0;
114 bi->ptr=NULL;
115 bi->flags=0;
116 return(1);
117 }
118
119static int sock_free(BIO *a)
120 {
121 if (a == NULL) return(0);
122 if (a->shutdown)
123 {
124 if (a->init)
125 {
126 SHUTDOWN2(a->num);
127 }
128 a->init=0;
129 a->flags=0;
130 }
131 return(1);
132 }
133
134static int sock_read(BIO *b, char *out, int outl)
135 {
136 int ret=0;
137
138 if (out != NULL)
139 {
140 clear_socket_error();
141 ret=readsocket(b->num,out,outl);
142 BIO_clear_retry_flags(b);
143 if (ret <= 0)
144 {
145 if (BIO_sock_should_retry(ret))
146 BIO_set_retry_read(b);
147 }
148 }
149 return(ret);
150 }
151
152static int sock_write(BIO *b, const char *in, int inl)
153 {
154 int ret;
155
156 clear_socket_error();
157 ret=writesocket(b->num,in,inl);
158 BIO_clear_retry_flags(b);
159 if (ret <= 0)
160 {
161 if (BIO_sock_should_retry(ret))
162 BIO_set_retry_write(b);
163 }
164 return(ret);
165 }
166
167static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
168 {
169 long ret=1;
170 int *ip;
171
172 switch (cmd)
173 {
174 case BIO_CTRL_RESET:
175 num=0;
176 case BIO_C_FILE_SEEK:
177 ret=0;
178 break;
179 case BIO_C_FILE_TELL:
180 case BIO_CTRL_INFO:
181 ret=0;
182 break;
183 case BIO_C_SET_FD:
184 sock_free(b);
185 b->num= *((int *)ptr);
186 b->shutdown=(int)num;
187 b->init=1;
188 break;
189 case BIO_C_GET_FD:
190 if (b->init)
191 {
192 ip=(int *)ptr;
193 if (ip != NULL) *ip=b->num;
194 ret=b->num;
195 }
196 else
197 ret= -1;
198 break;
199 case BIO_CTRL_GET_CLOSE:
200 ret=b->shutdown;
201 break;
202 case BIO_CTRL_SET_CLOSE:
203 b->shutdown=(int)num;
204 break;
205 case BIO_CTRL_PENDING:
206 case BIO_CTRL_WPENDING:
207 ret=0;
208 break;
209 case BIO_CTRL_DUP:
210 case BIO_CTRL_FLUSH:
211 ret=1;
212 break;
213 default:
214 ret=0;
215 break;
216 }
217 return(ret);
218 }
219
220static int sock_puts(BIO *bp, const char *str)
221 {
222 int n,ret;
223
224 n=strlen(str);
225 ret=sock_write(bp,str,n);
226 return(ret);
227 }
228
229int BIO_sock_should_retry(int i)
230 {
231 int err;
232
233 if ((i == 0) || (i == -1))
234 {
235 err=get_last_socket_error();
236
237#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
238 if ((i == -1) && (err == 0))
239 return(1);
240#endif
241
242 return(BIO_sock_non_fatal_error(err));
243 }
244 return(0);
245 }
246
247int BIO_sock_non_fatal_error(int err)
248 {
249 switch (err)
250 {
251#if defined(OPENSSL_SYS_WINDOWS)
252# if defined(WSAEWOULDBLOCK)
253 case WSAEWOULDBLOCK:
254# endif
255
256# if 0 /* This appears to always be an error */
257# if defined(WSAENOTCONN)
258 case WSAENOTCONN:
259# endif
260# endif
261#endif
262
263#ifdef EWOULDBLOCK
264# ifdef WSAEWOULDBLOCK
265# if WSAEWOULDBLOCK != EWOULDBLOCK
266 case EWOULDBLOCK:
267# endif
268# else
269 case EWOULDBLOCK:
270# endif
271#endif
272
273#if defined(ENOTCONN)
274 case ENOTCONN:
275#endif
276
277#ifdef EINTR
278 case EINTR:
279#endif
280
281#ifdef EAGAIN
282#if EWOULDBLOCK != EAGAIN
283 case EAGAIN:
284# endif
285#endif
286
287#ifdef EPROTO
288 case EPROTO:
289#endif
290
291#ifdef EINPROGRESS
292 case EINPROGRESS:
293#endif
294
295#ifdef EALREADY
296 case EALREADY:
297#endif
298 return(1);
299 /* break; */
300 default:
301 break;
302 }
303 return(0);
304 }
305#endif
diff --git a/src/lib/libcrypto/bn/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/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl
new file mode 100644
index 0000000000..c4de4a2bee
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/bn-586.pl
@@ -0,0 +1,593 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6&asm_init($ARGV[0],$0);
7
8&bn_mul_add_words("bn_mul_add_words");
9&bn_mul_words("bn_mul_words");
10&bn_sqr_words("bn_sqr_words");
11&bn_div_words("bn_div_words");
12&bn_add_words("bn_add_words");
13&bn_sub_words("bn_sub_words");
14#&bn_sub_part_words("bn_sub_part_words");
15
16&asm_finish();
17
18sub bn_mul_add_words
19 {
20 local($name)=@_;
21
22 &function_begin($name,"");
23
24 &comment("");
25 $Low="eax";
26 $High="edx";
27 $a="ebx";
28 $w="ebp";
29 $r="edi";
30 $c="esi";
31
32 &xor($c,$c); # clear carry
33 &mov($r,&wparam(0)); #
34
35 &mov("ecx",&wparam(2)); #
36 &mov($a,&wparam(1)); #
37
38 &and("ecx",0xfffffff8); # num / 8
39 &mov($w,&wparam(3)); #
40
41 &push("ecx"); # Up the stack for a tmp variable
42
43 &jz(&label("maw_finish"));
44
45 &set_label("maw_loop",0);
46
47 &mov(&swtmp(0),"ecx"); #
48
49 for ($i=0; $i<32; $i+=4)
50 {
51 &comment("Round $i");
52
53 &mov("eax",&DWP($i,$a,"",0)); # *a
54 &mul($w); # *a * w
55 &add("eax",$c); # L(t)+= *r
56 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
57 &adc("edx",0); # H(t)+=carry
58 &add("eax",$c); # L(t)+=c
59 &adc("edx",0); # H(t)+=carry
60 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
61 &mov($c,"edx"); # c= H(t);
62 }
63
64 &comment("");
65 &mov("ecx",&swtmp(0)); #
66 &add($a,32);
67 &add($r,32);
68 &sub("ecx",8);
69 &jnz(&label("maw_loop"));
70
71 &set_label("maw_finish",0);
72 &mov("ecx",&wparam(2)); # get num
73 &and("ecx",7);
74 &jnz(&label("maw_finish2")); # helps branch prediction
75 &jmp(&label("maw_end"));
76
77 &set_label("maw_finish2",1);
78 for ($i=0; $i<7; $i++)
79 {
80 &comment("Tail Round $i");
81 &mov("eax",&DWP($i*4,$a,"",0));# *a
82 &mul($w); # *a * w
83 &add("eax",$c); # L(t)+=c
84 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
85 &adc("edx",0); # H(t)+=carry
86 &add("eax",$c);
87 &adc("edx",0); # H(t)+=carry
88 &dec("ecx") if ($i != 7-1);
89 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
90 &mov($c,"edx"); # c= H(t);
91 &jz(&label("maw_end")) if ($i != 7-1);
92 }
93 &set_label("maw_end",0);
94 &mov("eax",$c);
95
96 &pop("ecx"); # clear variable from
97
98 &function_end($name);
99 }
100
101sub bn_mul_words
102 {
103 local($name)=@_;
104
105 &function_begin($name,"");
106
107 &comment("");
108 $Low="eax";
109 $High="edx";
110 $a="ebx";
111 $w="ecx";
112 $r="edi";
113 $c="esi";
114 $num="ebp";
115
116 &xor($c,$c); # clear carry
117 &mov($r,&wparam(0)); #
118 &mov($a,&wparam(1)); #
119 &mov($num,&wparam(2)); #
120 &mov($w,&wparam(3)); #
121
122 &and($num,0xfffffff8); # num / 8
123 &jz(&label("mw_finish"));
124
125 &set_label("mw_loop",0);
126 for ($i=0; $i<32; $i+=4)
127 {
128 &comment("Round $i");
129
130 &mov("eax",&DWP($i,$a,"",0)); # *a
131 &mul($w); # *a * w
132 &add("eax",$c); # L(t)+=c
133 # XXX
134
135 &adc("edx",0); # H(t)+=carry
136 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
137
138 &mov($c,"edx"); # c= H(t);
139 }
140
141 &comment("");
142 &add($a,32);
143 &add($r,32);
144 &sub($num,8);
145 &jz(&label("mw_finish"));
146 &jmp(&label("mw_loop"));
147
148 &set_label("mw_finish",0);
149 &mov($num,&wparam(2)); # get num
150 &and($num,7);
151 &jnz(&label("mw_finish2"));
152 &jmp(&label("mw_end"));
153
154 &set_label("mw_finish2",1);
155 for ($i=0; $i<7; $i++)
156 {
157 &comment("Tail Round $i");
158 &mov("eax",&DWP($i*4,$a,"",0));# *a
159 &mul($w); # *a * w
160 &add("eax",$c); # L(t)+=c
161 # XXX
162 &adc("edx",0); # H(t)+=carry
163 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
164 &mov($c,"edx"); # c= H(t);
165 &dec($num) if ($i != 7-1);
166 &jz(&label("mw_end")) if ($i != 7-1);
167 }
168 &set_label("mw_end",0);
169 &mov("eax",$c);
170
171 &function_end($name);
172 }
173
174sub bn_sqr_words
175 {
176 local($name)=@_;
177
178 &function_begin($name,"");
179
180 &comment("");
181 $r="esi";
182 $a="edi";
183 $num="ebx";
184
185 &mov($r,&wparam(0)); #
186 &mov($a,&wparam(1)); #
187 &mov($num,&wparam(2)); #
188
189 &and($num,0xfffffff8); # num / 8
190 &jz(&label("sw_finish"));
191
192 &set_label("sw_loop",0);
193 for ($i=0; $i<32; $i+=4)
194 {
195 &comment("Round $i");
196 &mov("eax",&DWP($i,$a,"",0)); # *a
197 # XXX
198 &mul("eax"); # *a * *a
199 &mov(&DWP($i*2,$r,"",0),"eax"); #
200 &mov(&DWP($i*2+4,$r,"",0),"edx");#
201 }
202
203 &comment("");
204 &add($a,32);
205 &add($r,64);
206 &sub($num,8);
207 &jnz(&label("sw_loop"));
208
209 &set_label("sw_finish",0);
210 &mov($num,&wparam(2)); # get num
211 &and($num,7);
212 &jz(&label("sw_end"));
213
214 for ($i=0; $i<7; $i++)
215 {
216 &comment("Tail Round $i");
217 &mov("eax",&DWP($i*4,$a,"",0)); # *a
218 # XXX
219 &mul("eax"); # *a * *a
220 &mov(&DWP($i*8,$r,"",0),"eax"); #
221 &dec($num) if ($i != 7-1);
222 &mov(&DWP($i*8+4,$r,"",0),"edx");
223 &jz(&label("sw_end")) if ($i != 7-1);
224 }
225 &set_label("sw_end",0);
226
227 &function_end($name);
228 }
229
230sub bn_div_words
231 {
232 local($name)=@_;
233
234 &function_begin($name,"");
235 &mov("edx",&wparam(0)); #
236 &mov("eax",&wparam(1)); #
237 &mov("ebx",&wparam(2)); #
238 &div("ebx");
239 &function_end($name);
240 }
241
242sub bn_add_words
243 {
244 local($name)=@_;
245
246 &function_begin($name,"");
247
248 &comment("");
249 $a="esi";
250 $b="edi";
251 $c="eax";
252 $r="ebx";
253 $tmp1="ecx";
254 $tmp2="edx";
255 $num="ebp";
256
257 &mov($r,&wparam(0)); # get r
258 &mov($a,&wparam(1)); # get a
259 &mov($b,&wparam(2)); # get b
260 &mov($num,&wparam(3)); # get num
261 &xor($c,$c); # clear carry
262 &and($num,0xfffffff8); # num / 8
263
264 &jz(&label("aw_finish"));
265
266 &set_label("aw_loop",0);
267 for ($i=0; $i<8; $i++)
268 {
269 &comment("Round $i");
270
271 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
272 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
273 &add($tmp1,$c);
274 &mov($c,0);
275 &adc($c,$c);
276 &add($tmp1,$tmp2);
277 &adc($c,0);
278 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
279 }
280
281 &comment("");
282 &add($a,32);
283 &add($b,32);
284 &add($r,32);
285 &sub($num,8);
286 &jnz(&label("aw_loop"));
287
288 &set_label("aw_finish",0);
289 &mov($num,&wparam(3)); # get num
290 &and($num,7);
291 &jz(&label("aw_end"));
292
293 for ($i=0; $i<7; $i++)
294 {
295 &comment("Tail Round $i");
296 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
297 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
298 &add($tmp1,$c);
299 &mov($c,0);
300 &adc($c,$c);
301 &add($tmp1,$tmp2);
302 &adc($c,0);
303 &dec($num) if ($i != 6);
304 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
305 &jz(&label("aw_end")) if ($i != 6);
306 }
307 &set_label("aw_end",0);
308
309# &mov("eax",$c); # $c is "eax"
310
311 &function_end($name);
312 }
313
314sub bn_sub_words
315 {
316 local($name)=@_;
317
318 &function_begin($name,"");
319
320 &comment("");
321 $a="esi";
322 $b="edi";
323 $c="eax";
324 $r="ebx";
325 $tmp1="ecx";
326 $tmp2="edx";
327 $num="ebp";
328
329 &mov($r,&wparam(0)); # get r
330 &mov($a,&wparam(1)); # get a
331 &mov($b,&wparam(2)); # get b
332 &mov($num,&wparam(3)); # get num
333 &xor($c,$c); # clear carry
334 &and($num,0xfffffff8); # num / 8
335
336 &jz(&label("aw_finish"));
337
338 &set_label("aw_loop",0);
339 for ($i=0; $i<8; $i++)
340 {
341 &comment("Round $i");
342
343 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
344 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
345 &sub($tmp1,$c);
346 &mov($c,0);
347 &adc($c,$c);
348 &sub($tmp1,$tmp2);
349 &adc($c,0);
350 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
351 }
352
353 &comment("");
354 &add($a,32);
355 &add($b,32);
356 &add($r,32);
357 &sub($num,8);
358 &jnz(&label("aw_loop"));
359
360 &set_label("aw_finish",0);
361 &mov($num,&wparam(3)); # get num
362 &and($num,7);
363 &jz(&label("aw_end"));
364
365 for ($i=0; $i<7; $i++)
366 {
367 &comment("Tail Round $i");
368 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
369 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
370 &sub($tmp1,$c);
371 &mov($c,0);
372 &adc($c,$c);
373 &sub($tmp1,$tmp2);
374 &adc($c,0);
375 &dec($num) if ($i != 6);
376 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
377 &jz(&label("aw_end")) if ($i != 6);
378 }
379 &set_label("aw_end",0);
380
381# &mov("eax",$c); # $c is "eax"
382
383 &function_end($name);
384 }
385
386sub bn_sub_part_words
387 {
388 local($name)=@_;
389
390 &function_begin($name,"");
391
392 &comment("");
393 $a="esi";
394 $b="edi";
395 $c="eax";
396 $r="ebx";
397 $tmp1="ecx";
398 $tmp2="edx";
399 $num="ebp";
400
401 &mov($r,&wparam(0)); # get r
402 &mov($a,&wparam(1)); # get a
403 &mov($b,&wparam(2)); # get b
404 &mov($num,&wparam(3)); # get num
405 &xor($c,$c); # clear carry
406 &and($num,0xfffffff8); # num / 8
407
408 &jz(&label("aw_finish"));
409
410 &set_label("aw_loop",0);
411 for ($i=0; $i<8; $i++)
412 {
413 &comment("Round $i");
414
415 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
416 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
417 &sub($tmp1,$c);
418 &mov($c,0);
419 &adc($c,$c);
420 &sub($tmp1,$tmp2);
421 &adc($c,0);
422 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
423 }
424
425 &comment("");
426 &add($a,32);
427 &add($b,32);
428 &add($r,32);
429 &sub($num,8);
430 &jnz(&label("aw_loop"));
431
432 &set_label("aw_finish",0);
433 &mov($num,&wparam(3)); # get num
434 &and($num,7);
435 &jz(&label("aw_end"));
436
437 for ($i=0; $i<7; $i++)
438 {
439 &comment("Tail Round $i");
440 &mov($tmp1,&DWP(0,$a,"",0)); # *a
441 &mov($tmp2,&DWP(0,$b,"",0));# *b
442 &sub($tmp1,$c);
443 &mov($c,0);
444 &adc($c,$c);
445 &sub($tmp1,$tmp2);
446 &adc($c,0);
447 &mov(&DWP(0,$r,"",0),$tmp1); # *r
448 &add($a, 4);
449 &add($b, 4);
450 &add($r, 4);
451 &dec($num) if ($i != 6);
452 &jz(&label("aw_end")) if ($i != 6);
453 }
454 &set_label("aw_end",0);
455
456 &cmp(&wparam(4),0);
457 &je(&label("pw_end"));
458
459 &mov($num,&wparam(4)); # get dl
460 &cmp($num,0);
461 &je(&label("pw_end"));
462 &jge(&label("pw_pos"));
463
464 &comment("pw_neg");
465 &mov($tmp2,0);
466 &sub($tmp2,$num);
467 &mov($num,$tmp2);
468 &and($num,0xfffffff8); # num / 8
469 &jz(&label("pw_neg_finish"));
470
471 &set_label("pw_neg_loop",0);
472 for ($i=0; $i<8; $i++)
473 {
474 &comment("dl<0 Round $i");
475
476 &mov($tmp1,0);
477 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
478 &sub($tmp1,$c);
479 &mov($c,0);
480 &adc($c,$c);
481 &sub($tmp1,$tmp2);
482 &adc($c,0);
483 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
484 }
485
486 &comment("");
487 &add($b,32);
488 &add($r,32);
489 &sub($num,8);
490 &jnz(&label("pw_neg_loop"));
491
492 &set_label("pw_neg_finish",0);
493 &mov($tmp2,&wparam(4)); # get dl
494 &mov($num,0);
495 &sub($num,$tmp2);
496 &and($num,7);
497 &jz(&label("pw_end"));
498
499 for ($i=0; $i<7; $i++)
500 {
501 &comment("dl<0 Tail Round $i");
502 &mov($tmp1,0);
503 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
504 &sub($tmp1,$c);
505 &mov($c,0);
506 &adc($c,$c);
507 &sub($tmp1,$tmp2);
508 &adc($c,0);
509 &dec($num) if ($i != 6);
510 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
511 &jz(&label("pw_end")) if ($i != 6);
512 }
513
514 &jmp(&label("pw_end"));
515
516 &set_label("pw_pos",0);
517
518 &and($num,0xfffffff8); # num / 8
519 &jz(&label("pw_pos_finish"));
520
521 &set_label("pw_pos_loop",0);
522
523 for ($i=0; $i<8; $i++)
524 {
525 &comment("dl>0 Round $i");
526
527 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
528 &sub($tmp1,$c);
529 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
530 &jnc(&label("pw_nc".$i));
531 }
532
533 &comment("");
534 &add($a,32);
535 &add($r,32);
536 &sub($num,8);
537 &jnz(&label("pw_pos_loop"));
538
539 &set_label("pw_pos_finish",0);
540 &mov($num,&wparam(4)); # get dl
541 &and($num,7);
542 &jz(&label("pw_end"));
543
544 for ($i=0; $i<7; $i++)
545 {
546 &comment("dl>0 Tail Round $i");
547 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
548 &sub($tmp1,$c);
549 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
550 &jnc(&label("pw_tail_nc".$i));
551 &dec($num) if ($i != 6);
552 &jz(&label("pw_end")) if ($i != 6);
553 }
554 &mov($c,1);
555 &jmp(&label("pw_end"));
556
557 &set_label("pw_nc_loop",0);
558 for ($i=0; $i<8; $i++)
559 {
560 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
561 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
562 &set_label("pw_nc".$i,0);
563 }
564
565 &comment("");
566 &add($a,32);
567 &add($r,32);
568 &sub($num,8);
569 &jnz(&label("pw_nc_loop"));
570
571 &mov($num,&wparam(4)); # get dl
572 &and($num,7);
573 &jz(&label("pw_nc_end"));
574
575 for ($i=0; $i<7; $i++)
576 {
577 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
578 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
579 &set_label("pw_tail_nc".$i,0);
580 &dec($num) if ($i != 6);
581 &jz(&label("pw_nc_end")) if ($i != 6);
582 }
583
584 &set_label("pw_nc_end",0);
585 &mov($c,0);
586
587 &set_label("pw_end",0);
588
589# &mov("eax",$c); # $c is "eax"
590
591 &function_end($name);
592 }
593
diff --git a/src/lib/libcrypto/bn/asm/co-586.pl b/src/lib/libcrypto/bn/asm/co-586.pl
new file mode 100644
index 0000000000..5d962cb957
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/co-586.pl
@@ -0,0 +1,286 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6&asm_init($ARGV[0],$0);
7
8&bn_mul_comba("bn_mul_comba8",8);
9&bn_mul_comba("bn_mul_comba4",4);
10&bn_sqr_comba("bn_sqr_comba8",8);
11&bn_sqr_comba("bn_sqr_comba4",4);
12
13&asm_finish();
14
15sub mul_add_c
16 {
17 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
18
19 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
20 # words, and 1 if load return value
21
22 &comment("mul a[$ai]*b[$bi]");
23
24 # "eax" and "edx" will always be pre-loaded.
25 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
26 # &mov("edx",&DWP($bi*4,$b,"",0));
27
28 &mul("edx");
29 &add($c0,"eax");
30 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
31 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
32 ###
33 &adc($c1,"edx");
34 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
35 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
36 ###
37 &adc($c2,0);
38 # is pos > 1, it means it is the last loop
39 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
40 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
41 }
42
43sub sqr_add_c
44 {
45 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
46
47 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
48 # words, and 1 if load return value
49
50 &comment("sqr a[$ai]*a[$bi]");
51
52 # "eax" and "edx" will always be pre-loaded.
53 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
54 # &mov("edx",&DWP($bi*4,$b,"",0));
55
56 if ($ai == $bi)
57 { &mul("eax");}
58 else
59 { &mul("edx");}
60 &add($c0,"eax");
61 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
62 ###
63 &adc($c1,"edx");
64 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
65 ###
66 &adc($c2,0);
67 # is pos > 1, it means it is the last loop
68 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
69 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
70 }
71
72sub sqr_add_c2
73 {
74 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
75
76 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
77 # words, and 1 if load return value
78
79 &comment("sqr a[$ai]*a[$bi]");
80
81 # "eax" and "edx" will always be pre-loaded.
82 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
83 # &mov("edx",&DWP($bi*4,$a,"",0));
84
85 if ($ai == $bi)
86 { &mul("eax");}
87 else
88 { &mul("edx");}
89 &add("eax","eax");
90 ###
91 &adc("edx","edx");
92 ###
93 &adc($c2,0);
94 &add($c0,"eax");
95 &adc($c1,"edx");
96 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
97 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
98 &adc($c2,0);
99 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
100 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
101 ###
102 }
103
104sub bn_mul_comba
105 {
106 local($name,$num)=@_;
107 local($a,$b,$c0,$c1,$c2);
108 local($i,$as,$ae,$bs,$be,$ai,$bi);
109 local($tot,$end);
110
111 &function_begin_B($name,"");
112
113 $c0="ebx";
114 $c1="ecx";
115 $c2="ebp";
116 $a="esi";
117 $b="edi";
118
119 $as=0;
120 $ae=0;
121 $bs=0;
122 $be=0;
123 $tot=$num+$num-1;
124
125 &push("esi");
126 &mov($a,&wparam(1));
127 &push("edi");
128 &mov($b,&wparam(2));
129 &push("ebp");
130 &push("ebx");
131
132 &xor($c0,$c0);
133 &mov("eax",&DWP(0,$a,"",0)); # load the first word
134 &xor($c1,$c1);
135 &mov("edx",&DWP(0,$b,"",0)); # load the first second
136
137 for ($i=0; $i<$tot; $i++)
138 {
139 $ai=$as;
140 $bi=$bs;
141 $end=$be+1;
142
143 &comment("################## Calculate word $i");
144
145 for ($j=$bs; $j<$end; $j++)
146 {
147 &xor($c2,$c2) if ($j == $bs);
148 if (($j+1) == $end)
149 {
150 $v=1;
151 $v=2 if (($i+1) == $tot);
152 }
153 else
154 { $v=0; }
155 if (($j+1) != $end)
156 {
157 $na=($ai-1);
158 $nb=($bi+1);
159 }
160 else
161 {
162 $na=$as+($i < ($num-1));
163 $nb=$bs+($i >= ($num-1));
164 }
165#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
166 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
167 if ($v)
168 {
169 &comment("saved r[$i]");
170 # &mov("eax",&wparam(0));
171 # &mov(&DWP($i*4,"eax","",0),$c0);
172 ($c0,$c1,$c2)=($c1,$c2,$c0);
173 }
174 $ai--;
175 $bi++;
176 }
177 $as++ if ($i < ($num-1));
178 $ae++ if ($i >= ($num-1));
179
180 $bs++ if ($i >= ($num-1));
181 $be++ if ($i < ($num-1));
182 }
183 &comment("save r[$i]");
184 # &mov("eax",&wparam(0));
185 &mov(&DWP($i*4,"eax","",0),$c0);
186
187 &pop("ebx");
188 &pop("ebp");
189 &pop("edi");
190 &pop("esi");
191 &ret();
192 &function_end_B($name);
193 }
194
195sub bn_sqr_comba
196 {
197 local($name,$num)=@_;
198 local($r,$a,$c0,$c1,$c2)=@_;
199 local($i,$as,$ae,$bs,$be,$ai,$bi);
200 local($b,$tot,$end,$half);
201
202 &function_begin_B($name,"");
203
204 $c0="ebx";
205 $c1="ecx";
206 $c2="ebp";
207 $a="esi";
208 $r="edi";
209
210 &push("esi");
211 &push("edi");
212 &push("ebp");
213 &push("ebx");
214 &mov($r,&wparam(0));
215 &mov($a,&wparam(1));
216 &xor($c0,$c0);
217 &xor($c1,$c1);
218 &mov("eax",&DWP(0,$a,"",0)); # load the first word
219
220 $as=0;
221 $ae=0;
222 $bs=0;
223 $be=0;
224 $tot=$num+$num-1;
225
226 for ($i=0; $i<$tot; $i++)
227 {
228 $ai=$as;
229 $bi=$bs;
230 $end=$be+1;
231
232 &comment("############### Calculate word $i");
233 for ($j=$bs; $j<$end; $j++)
234 {
235 &xor($c2,$c2) if ($j == $bs);
236 if (($ai-1) < ($bi+1))
237 {
238 $v=1;
239 $v=2 if ($i+1) == $tot;
240 }
241 else
242 { $v=0; }
243 if (!$v)
244 {
245 $na=$ai-1;
246 $nb=$bi+1;
247 }
248 else
249 {
250 $na=$as+($i < ($num-1));
251 $nb=$bs+($i >= ($num-1));
252 }
253 if ($ai == $bi)
254 {
255 &sqr_add_c($r,$a,$ai,$bi,
256 $c0,$c1,$c2,$v,$i,$na,$nb);
257 }
258 else
259 {
260 &sqr_add_c2($r,$a,$ai,$bi,
261 $c0,$c1,$c2,$v,$i,$na,$nb);
262 }
263 if ($v)
264 {
265 &comment("saved r[$i]");
266 #&mov(&DWP($i*4,$r,"",0),$c0);
267 ($c0,$c1,$c2)=($c1,$c2,$c0);
268 last;
269 }
270 $ai--;
271 $bi++;
272 }
273 $as++ if ($i < ($num-1));
274 $ae++ if ($i >= ($num-1));
275
276 $bs++ if ($i >= ($num-1));
277 $be++ if ($i < ($num-1));
278 }
279 &mov(&DWP($i*4,$r,"",0),$c0);
280 &pop("ebx");
281 &pop("ebp");
282 &pop("edi");
283 &pop("esi");
284 &ret();
285 &function_end_B($name);
286 }
diff --git a/src/lib/libcrypto/bn/asm/ia64.S b/src/lib/libcrypto/bn/asm/ia64.S
new file mode 100644
index 0000000000..7b82b820e6
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/ia64.S
@@ -0,0 +1,1560 @@
1.explicit
2.text
3.ident "ia64.S, Version 2.1"
4.ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
5
6//
7// ====================================================================
8// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
9// project.
10//
11// Rights for redistribution and usage in source and binary forms are
12// granted according to the OpenSSL license. Warranty of any kind is
13// disclaimed.
14// ====================================================================
15//
16// Version 2.x is Itanium2 re-tune. Few words about how Itanum2 is
17// different from Itanium to this module viewpoint. Most notably, is it
18// "wider" than Itanium? Can you experience loop scalability as
19// discussed in commentary sections? Not really:-( Itanium2 has 6
20// integer ALU ports, i.e. it's 2 ports wider, but it's not enough to
21// spin twice as fast, as I need 8 IALU ports. Amount of floating point
22// ports is the same, i.e. 2, while I need 4. In other words, to this
23// module Itanium2 remains effectively as "wide" as Itanium. Yet it's
24// essentially different in respect to this module, and a re-tune was
25// required. Well, because some intruction latencies has changed. Most
26// noticeably those intensively used:
27//
28// Itanium Itanium2
29// ldf8 9 6 L2 hit
30// ld8 2 1 L1 hit
31// getf 2 5
32// xma[->getf] 7[+1] 4[+0]
33// add[->st8] 1[+1] 1[+0]
34//
35// What does it mean? You might ratiocinate that the original code
36// should run just faster... Because sum of latencies is smaller...
37// Wrong! Note that getf latency increased. This means that if a loop is
38// scheduled for lower latency (as they were), then it will suffer from
39// stall condition and the code will therefore turn anti-scalable, e.g.
40// original bn_mul_words spun at 5*n or 2.5 times slower than expected
41// on Itanium2! What to do? Reschedule loops for Itanium2? But then
42// Itanium would exhibit anti-scalability. So I've chosen to reschedule
43// for worst latency for every instruction aiming for best *all-round*
44// performance.
45
46// Q. How much faster does it get?
47// A. Here is the output from 'openssl speed rsa dsa' for vanilla
48// 0.9.6a compiled with gcc version 2.96 20000731 (Red Hat
49// Linux 7.1 2.96-81):
50//
51// sign verify sign/s verify/s
52// rsa 512 bits 0.0036s 0.0003s 275.3 2999.2
53// rsa 1024 bits 0.0203s 0.0011s 49.3 894.1
54// rsa 2048 bits 0.1331s 0.0040s 7.5 250.9
55// rsa 4096 bits 0.9270s 0.0147s 1.1 68.1
56// sign verify sign/s verify/s
57// dsa 512 bits 0.0035s 0.0043s 288.3 234.8
58// dsa 1024 bits 0.0111s 0.0135s 90.0 74.2
59//
60// And here is similar output but for this assembler
61// implementation:-)
62//
63// sign verify sign/s verify/s
64// rsa 512 bits 0.0021s 0.0001s 549.4 9638.5
65// rsa 1024 bits 0.0055s 0.0002s 183.8 4481.1
66// rsa 2048 bits 0.0244s 0.0006s 41.4 1726.3
67// rsa 4096 bits 0.1295s 0.0018s 7.7 561.5
68// sign verify sign/s verify/s
69// dsa 512 bits 0.0012s 0.0013s 891.9 756.6
70// dsa 1024 bits 0.0023s 0.0028s 440.4 376.2
71//
72// Yes, you may argue that it's not fair comparison as it's
73// possible to craft the C implementation with BN_UMULT_HIGH
74// inline assembler macro. But of course! Here is the output
75// with the macro:
76//
77// sign verify sign/s verify/s
78// rsa 512 bits 0.0020s 0.0002s 495.0 6561.0
79// rsa 1024 bits 0.0086s 0.0004s 116.2 2235.7
80// rsa 2048 bits 0.0519s 0.0015s 19.3 667.3
81// rsa 4096 bits 0.3464s 0.0053s 2.9 187.7
82// sign verify sign/s verify/s
83// dsa 512 bits 0.0016s 0.0020s 613.1 510.5
84// dsa 1024 bits 0.0045s 0.0054s 221.0 183.9
85//
86// My code is still way faster, huh:-) And I believe that even
87// higher performance can be achieved. Note that as keys get
88// longer, performance gain is larger. Why? According to the
89// profiler there is another player in the field, namely
90// BN_from_montgomery consuming larger and larger portion of CPU
91// time as keysize decreases. I therefore consider putting effort
92// to assembler implementation of the following routine:
93//
94// void bn_mul_add_mont (BN_ULONG *rp,BN_ULONG *np,int nl,BN_ULONG n0)
95// {
96// int i,j;
97// BN_ULONG v;
98//
99// for (i=0; i<nl; i++)
100// {
101// v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
102// nrp++;
103// rp++;
104// if (((nrp[-1]+=v)&BN_MASK2) < v)
105// for (j=0; ((++nrp[j])&BN_MASK2) == 0; j++) ;
106// }
107// }
108//
109// It might as well be beneficial to implement even combaX
110// variants, as it appears as it can literally unleash the
111// performance (see comment section to bn_mul_comba8 below).
112//
113// And finally for your reference the output for 0.9.6a compiled
114// with SGIcc version 0.01.0-12 (keep in mind that for the moment
115// of this writing it's not possible to convince SGIcc to use
116// BN_UMULT_HIGH inline assembler macro, yet the code is fast,
117// i.e. for a compiler generated one:-):
118//
119// sign verify sign/s verify/s
120// rsa 512 bits 0.0022s 0.0002s 452.7 5894.3
121// rsa 1024 bits 0.0097s 0.0005s 102.7 2002.9
122// rsa 2048 bits 0.0578s 0.0017s 17.3 600.2
123// rsa 4096 bits 0.3838s 0.0061s 2.6 164.5
124// sign verify sign/s verify/s
125// dsa 512 bits 0.0018s 0.0022s 547.3 459.6
126// dsa 1024 bits 0.0051s 0.0062s 196.6 161.3
127//
128// Oh! Benchmarks were performed on 733MHz Lion-class Itanium
129// system running Redhat Linux 7.1 (very special thanks to Ray
130// McCaffity of Williams Communications for providing an account).
131//
132// Q. What's the heck with 'rum 1<<5' at the end of every function?
133// A. Well, by clearing the "upper FP registers written" bit of the
134// User Mask I want to excuse the kernel from preserving upper
135// (f32-f128) FP register bank over process context switch, thus
136// minimizing bus bandwidth consumption during the switch (i.e.
137// after PKI opration completes and the program is off doing
138// something else like bulk symmetric encryption). Having said
139// this, I also want to point out that it might be good idea
140// to compile the whole toolkit (as well as majority of the
141// programs for that matter) with -mfixed-range=f32-f127 command
142// line option. No, it doesn't prevent the compiler from writing
143// to upper bank, but at least discourages to do so. If you don't
144// like the idea you have the option to compile the module with
145// -Drum=nop.m in command line.
146//
147
148#if defined(_HPUX_SOURCE) && !defined(_LP64)
149#define ADDP addp4
150#else
151#define ADDP add
152#endif
153
154#if 1
155//
156// bn_[add|sub]_words routines.
157//
158// Loops are spinning in 2*(n+5) ticks on Itanuim (provided that the
159// data reside in L1 cache, i.e. 2 ticks away). It's possible to
160// compress the epilogue and get down to 2*n+6, but at the cost of
161// scalability (the neat feature of this implementation is that it
162// shall automagically spin in n+5 on "wider" IA-64 implementations:-)
163// I consider that the epilogue is short enough as it is to trade tiny
164// performance loss on Itanium for scalability.
165//
166// BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num)
167//
168.global bn_add_words#
169.proc bn_add_words#
170.align 64
171.skip 32 // makes the loop body aligned at 64-byte boundary
172bn_add_words:
173 .prologue
174 .fframe 0
175 .save ar.pfs,r2
176{ .mii; alloc r2=ar.pfs,4,12,0,16
177 cmp4.le p6,p0=r35,r0 };;
178{ .mfb; mov r8=r0 // return value
179(p6) br.ret.spnt.many b0 };;
180
181 .save ar.lc,r3
182{ .mib; sub r10=r35,r0,1
183 mov r3=ar.lc
184 brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16
185 }
186 .body
187{ .mib; ADDP r14=0,r32 // rp
188 mov r9=pr };;
189{ .mii; ADDP r15=0,r33 // ap
190 mov ar.lc=r10
191 mov ar.ec=6 }
192{ .mib; ADDP r16=0,r34 // bp
193 mov pr.rot=1<<16 };;
194
195.L_bn_add_words_ctop:
196{ .mii; (p16) ld8 r32=[r16],8 // b=*(bp++)
197 (p18) add r39=r37,r34
198 (p19) cmp.ltu.unc p56,p0=r40,r38 }
199{ .mfb; (p0) nop.m 0x0
200 (p0) nop.f 0x0
201 (p0) nop.b 0x0 }
202{ .mii; (p16) ld8 r35=[r15],8 // a=*(ap++)
203 (p58) cmp.eq.or p57,p0=-1,r41 // (p20)
204 (p58) add r41=1,r41 } // (p20)
205{ .mfb; (p21) st8 [r14]=r42,8 // *(rp++)=r
206 (p0) nop.f 0x0
207 br.ctop.sptk .L_bn_add_words_ctop };;
208.L_bn_add_words_cend:
209
210{ .mii;
211(p59) add r8=1,r8 // return value
212 mov pr=r9,0x1ffff
213 mov ar.lc=r3 }
214{ .mbb; nop.b 0x0
215 br.ret.sptk.many b0 };;
216.endp bn_add_words#
217
218//
219// BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num)
220//
221.global bn_sub_words#
222.proc bn_sub_words#
223.align 64
224.skip 32 // makes the loop body aligned at 64-byte boundary
225bn_sub_words:
226 .prologue
227 .fframe 0
228 .save ar.pfs,r2
229{ .mii; alloc r2=ar.pfs,4,12,0,16
230 cmp4.le p6,p0=r35,r0 };;
231{ .mfb; mov r8=r0 // return value
232(p6) br.ret.spnt.many b0 };;
233
234 .save ar.lc,r3
235{ .mib; sub r10=r35,r0,1
236 mov r3=ar.lc
237 brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16
238 }
239 .body
240{ .mib; ADDP r14=0,r32 // rp
241 mov r9=pr };;
242{ .mii; ADDP r15=0,r33 // ap
243 mov ar.lc=r10
244 mov ar.ec=6 }
245{ .mib; ADDP r16=0,r34 // bp
246 mov pr.rot=1<<16 };;
247
248.L_bn_sub_words_ctop:
249{ .mii; (p16) ld8 r32=[r16],8 // b=*(bp++)
250 (p18) sub r39=r37,r34
251 (p19) cmp.gtu.unc p56,p0=r40,r38 }
252{ .mfb; (p0) nop.m 0x0
253 (p0) nop.f 0x0
254 (p0) nop.b 0x0 }
255{ .mii; (p16) ld8 r35=[r15],8 // a=*(ap++)
256 (p58) cmp.eq.or p57,p0=0,r41 // (p20)
257 (p58) add r41=-1,r41 } // (p20)
258{ .mbb; (p21) st8 [r14]=r42,8 // *(rp++)=r
259 (p0) nop.b 0x0
260 br.ctop.sptk .L_bn_sub_words_ctop };;
261.L_bn_sub_words_cend:
262
263{ .mii;
264(p59) add r8=1,r8 // return value
265 mov pr=r9,0x1ffff
266 mov ar.lc=r3 }
267{ .mbb; nop.b 0x0
268 br.ret.sptk.many b0 };;
269.endp bn_sub_words#
270#endif
271
272#if 0
273#define XMA_TEMPTATION
274#endif
275
276#if 1
277//
278// BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
279//
280.global bn_mul_words#
281.proc bn_mul_words#
282.align 64
283.skip 32 // makes the loop body aligned at 64-byte boundary
284bn_mul_words:
285 .prologue
286 .fframe 0
287 .save ar.pfs,r2
288#ifdef XMA_TEMPTATION
289{ .mfi; alloc r2=ar.pfs,4,0,0,0 };;
290#else
291{ .mfi; alloc r2=ar.pfs,4,12,0,16 };;
292#endif
293{ .mib; mov r8=r0 // return value
294 cmp4.le p6,p0=r34,r0
295(p6) br.ret.spnt.many b0 };;
296
297 .save ar.lc,r3
298{ .mii; sub r10=r34,r0,1
299 mov r3=ar.lc
300 mov r9=pr };;
301
302 .body
303{ .mib; setf.sig f8=r35 // w
304 mov pr.rot=0x800001<<16
305 // ------^----- serves as (p50) at first (p27)
306 brp.loop.imp .L_bn_mul_words_ctop,.L_bn_mul_words_cend-16
307 }
308
309#ifndef XMA_TEMPTATION
310
311{ .mmi; ADDP r14=0,r32 // rp
312 ADDP r15=0,r33 // ap
313 mov ar.lc=r10 }
314{ .mmi; mov r40=0 // serves as r35 at first (p27)
315 mov ar.ec=13 };;
316
317// This loop spins in 2*(n+12) ticks. It's scheduled for data in Itanium
318// L2 cache (i.e. 9 ticks away) as floating point load/store instructions
319// bypass L1 cache and L2 latency is actually best-case scenario for
320// ldf8. The loop is not scalable and shall run in 2*(n+12) even on
321// "wider" IA-64 implementations. It's a trade-off here. n+24 loop
322// would give us ~5% in *overall* performance improvement on "wider"
323// IA-64, but would hurt Itanium for about same because of longer
324// epilogue. As it's a matter of few percents in either case I've
325// chosen to trade the scalability for development time (you can see
326// this very instruction sequence in bn_mul_add_words loop which in
327// turn is scalable).
328.L_bn_mul_words_ctop:
329{ .mfi; (p25) getf.sig r36=f52 // low
330 (p21) xmpy.lu f48=f37,f8
331 (p28) cmp.ltu p54,p50=r41,r39 }
332{ .mfi; (p16) ldf8 f32=[r15],8
333 (p21) xmpy.hu f40=f37,f8
334 (p0) nop.i 0x0 };;
335{ .mii; (p25) getf.sig r32=f44 // high
336 .pred.rel "mutex",p50,p54
337 (p50) add r40=r38,r35 // (p27)
338 (p54) add r40=r38,r35,1 } // (p27)
339{ .mfb; (p28) st8 [r14]=r41,8
340 (p0) nop.f 0x0
341 br.ctop.sptk .L_bn_mul_words_ctop };;
342.L_bn_mul_words_cend:
343
344{ .mii; nop.m 0x0
345.pred.rel "mutex",p51,p55
346(p51) add r8=r36,r0
347(p55) add r8=r36,r0,1 }
348{ .mfb; nop.m 0x0
349 nop.f 0x0
350 nop.b 0x0 }
351
352#else // XMA_TEMPTATION
353
354 setf.sig f37=r0 // serves as carry at (p18) tick
355 mov ar.lc=r10
356 mov ar.ec=5;;
357
358// Most of you examining this code very likely wonder why in the name
359// of Intel the following loop is commented out? Indeed, it looks so
360// neat that you find it hard to believe that it's something wrong
361// with it, right? The catch is that every iteration depends on the
362// result from previous one and the latter isn't available instantly.
363// The loop therefore spins at the latency of xma minus 1, or in other
364// words at 6*(n+4) ticks:-( Compare to the "production" loop above
365// that runs in 2*(n+11) where the low latency problem is worked around
366// by moving the dependency to one-tick latent interger ALU. Note that
367// "distance" between ldf8 and xma is not latency of ldf8, but the
368// *difference* between xma and ldf8 latencies.
369.L_bn_mul_words_ctop:
370{ .mfi; (p16) ldf8 f32=[r33],8
371 (p18) xma.hu f38=f34,f8,f39 }
372{ .mfb; (p20) stf8 [r32]=f37,8
373 (p18) xma.lu f35=f34,f8,f39
374 br.ctop.sptk .L_bn_mul_words_ctop };;
375.L_bn_mul_words_cend:
376
377 getf.sig r8=f41 // the return value
378
379#endif // XMA_TEMPTATION
380
381{ .mii; nop.m 0x0
382 mov pr=r9,0x1ffff
383 mov ar.lc=r3 }
384{ .mfb; rum 1<<5 // clear um.mfh
385 nop.f 0x0
386 br.ret.sptk.many b0 };;
387.endp bn_mul_words#
388#endif
389
390#if 1
391//
392// BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
393//
394.global bn_mul_add_words#
395.proc bn_mul_add_words#
396.align 64
397.skip 48 // makes the loop body aligned at 64-byte boundary
398bn_mul_add_words:
399 .prologue
400 .fframe 0
401 .save ar.pfs,r2
402 .save ar.lc,r3
403 .save pr,r9
404{ .mmi; alloc r2=ar.pfs,4,4,0,8
405 cmp4.le p6,p0=r34,r0
406 mov r3=ar.lc };;
407{ .mib; mov r8=r0 // return value
408 sub r10=r34,r0,1
409(p6) br.ret.spnt.many b0 };;
410
411 .body
412{ .mib; setf.sig f8=r35 // w
413 mov r9=pr
414 brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16
415 }
416{ .mmi; ADDP r14=0,r32 // rp
417 ADDP r15=0,r33 // ap
418 mov ar.lc=r10 }
419{ .mii; ADDP r16=0,r32 // rp copy
420 mov pr.rot=0x2001<<16
421 // ------^----- serves as (p40) at first (p27)
422 mov ar.ec=11 };;
423
424// This loop spins in 3*(n+10) ticks on Itanium and in 2*(n+10) on
425// Itanium 2. Yes, unlike previous versions it scales:-) Previous
426// version was peforming *all* additions in IALU and was starving
427// for those even on Itanium 2. In this version one addition is
428// moved to FPU and is folded with multiplication. This is at cost
429// of propogating the result from previous call to this subroutine
430// to L2 cache... In other words negligible even for shorter keys.
431// *Overall* performance improvement [over previous version] varies
432// from 11 to 22 percent depending on key length.
433.L_bn_mul_add_words_ctop:
434.pred.rel "mutex",p40,p42
435{ .mfi; (p23) getf.sig r36=f45 // low
436 (p20) xma.lu f42=f36,f8,f50 // low
437 (p40) add r39=r39,r35 } // (p27)
438{ .mfi; (p16) ldf8 f32=[r15],8 // *(ap++)
439 (p20) xma.hu f36=f36,f8,f50 // high
440 (p42) add r39=r39,r35,1 };; // (p27)
441{ .mmi; (p24) getf.sig r32=f40 // high
442 (p16) ldf8 f46=[r16],8 // *(rp1++)
443 (p40) cmp.ltu p41,p39=r39,r35 } // (p27)
444{ .mib; (p26) st8 [r14]=r39,8 // *(rp2++)
445 (p42) cmp.leu p41,p39=r39,r35 // (p27)
446 br.ctop.sptk .L_bn_mul_add_words_ctop};;
447.L_bn_mul_add_words_cend:
448
449{ .mmi; .pred.rel "mutex",p40,p42
450(p40) add r8=r35,r0
451(p42) add r8=r35,r0,1
452 mov pr=r9,0x1ffff }
453{ .mib; rum 1<<5 // clear um.mfh
454 mov ar.lc=r3
455 br.ret.sptk.many b0 };;
456.endp bn_mul_add_words#
457#endif
458
459#if 1
460//
461// void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
462//
463.global bn_sqr_words#
464.proc bn_sqr_words#
465.align 64
466.skip 32 // makes the loop body aligned at 64-byte boundary
467bn_sqr_words:
468 .prologue
469 .fframe 0
470 .save ar.pfs,r2
471{ .mii; alloc r2=ar.pfs,3,0,0,0
472 sxt4 r34=r34 };;
473{ .mii; cmp.le p6,p0=r34,r0
474 mov r8=r0 } // return value
475{ .mfb; ADDP r32=0,r32
476 nop.f 0x0
477(p6) br.ret.spnt.many b0 };;
478
479 .save ar.lc,r3
480{ .mii; sub r10=r34,r0,1
481 mov r3=ar.lc
482 mov r9=pr };;
483
484 .body
485{ .mib; ADDP r33=0,r33
486 mov pr.rot=1<<16
487 brp.loop.imp .L_bn_sqr_words_ctop,.L_bn_sqr_words_cend-16
488 }
489{ .mii; add r34=8,r32
490 mov ar.lc=r10
491 mov ar.ec=18 };;
492
493// 2*(n+17) on Itanium, (n+17) on "wider" IA-64 implementations. It's
494// possible to compress the epilogue (I'm getting tired to write this
495// comment over and over) and get down to 2*n+16 at the cost of
496// scalability. The decision will very likely be reconsidered after the
497// benchmark program is profiled. I.e. if perfomance gain on Itanium
498// will appear larger than loss on "wider" IA-64, then the loop should
499// be explicitely split and the epilogue compressed.
500.L_bn_sqr_words_ctop:
501{ .mfi; (p16) ldf8 f32=[r33],8
502 (p25) xmpy.lu f42=f41,f41
503 (p0) nop.i 0x0 }
504{ .mib; (p33) stf8 [r32]=f50,16
505 (p0) nop.i 0x0
506 (p0) nop.b 0x0 }
507{ .mfi; (p0) nop.m 0x0
508 (p25) xmpy.hu f52=f41,f41
509 (p0) nop.i 0x0 }
510{ .mib; (p33) stf8 [r34]=f60,16
511 (p0) nop.i 0x0
512 br.ctop.sptk .L_bn_sqr_words_ctop };;
513.L_bn_sqr_words_cend:
514
515{ .mii; nop.m 0x0
516 mov pr=r9,0x1ffff
517 mov ar.lc=r3 }
518{ .mfb; rum 1<<5 // clear um.mfh
519 nop.f 0x0
520 br.ret.sptk.many b0 };;
521.endp bn_sqr_words#
522#endif
523
524#if 1
525// Apparently we win nothing by implementing special bn_sqr_comba8.
526// Yes, it is possible to reduce the number of multiplications by
527// almost factor of two, but then the amount of additions would
528// increase by factor of two (as we would have to perform those
529// otherwise performed by xma ourselves). Normally we would trade
530// anyway as multiplications are way more expensive, but not this
531// time... Multiplication kernel is fully pipelined and as we drain
532// one 128-bit multiplication result per clock cycle multiplications
533// are effectively as inexpensive as additions. Special implementation
534// might become of interest for "wider" IA-64 implementation as you'll
535// be able to get through the multiplication phase faster (there won't
536// be any stall issues as discussed in the commentary section below and
537// you therefore will be able to employ all 4 FP units)... But these
538// Itanium days it's simply too hard to justify the effort so I just
539// drop down to bn_mul_comba8 code:-)
540//
541// void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
542//
543.global bn_sqr_comba8#
544.proc bn_sqr_comba8#
545.align 64
546bn_sqr_comba8:
547 .prologue
548 .fframe 0
549 .save ar.pfs,r2
550#if defined(_HPUX_SOURCE) && !defined(_LP64)
551{ .mii; alloc r2=ar.pfs,2,1,0,0
552 addp4 r33=0,r33
553 addp4 r32=0,r32 };;
554{ .mii;
555#else
556{ .mii; alloc r2=ar.pfs,2,1,0,0
557#endif
558 mov r34=r33
559 add r14=8,r33 };;
560 .body
561{ .mii; add r17=8,r34
562 add r15=16,r33
563 add r18=16,r34 }
564{ .mfb; add r16=24,r33
565 br .L_cheat_entry_point8 };;
566.endp bn_sqr_comba8#
567#endif
568
569#if 1
570// I've estimated this routine to run in ~120 ticks, but in reality
571// (i.e. according to ar.itc) it takes ~160 ticks. Are those extra
572// cycles consumed for instructions fetch? Or did I misinterpret some
573// clause in Itanium µ-architecture manual? Comments are welcomed and
574// highly appreciated.
575//
576// On Itanium 2 it takes ~190 ticks. This is because of stalls on
577// result from getf.sig. I do nothing about it at this point for
578// reasons depicted below.
579//
580// However! It should be noted that even 160 ticks is darn good result
581// as it's over 10 (yes, ten, spelled as t-e-n) times faster than the
582// C version (compiled with gcc with inline assembler). I really
583// kicked compiler's butt here, didn't I? Yeah! This brings us to the
584// following statement. It's damn shame that this routine isn't called
585// very often nowadays! According to the profiler most CPU time is
586// consumed by bn_mul_add_words called from BN_from_montgomery. In
587// order to estimate what we're missing, I've compared the performance
588// of this routine against "traditional" implementation, i.e. against
589// following routine:
590//
591// void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
592// { r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
593// r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
594// r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
595// r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
596// r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
597// r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
598// r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
599// r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
600// }
601//
602// The one below is over 8 times faster than the one above:-( Even
603// more reasons to "combafy" bn_mul_add_mont...
604//
605// And yes, this routine really made me wish there were an optimizing
606// assembler! It also feels like it deserves a dedication.
607//
608// To my wife for being there and to my kids...
609//
610// void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
611//
612#define carry1 r14
613#define carry2 r15
614#define carry3 r34
615.global bn_mul_comba8#
616.proc bn_mul_comba8#
617.align 64
618bn_mul_comba8:
619 .prologue
620 .fframe 0
621 .save ar.pfs,r2
622#if defined(_HPUX_SOURCE) && !defined(_LP64)
623{ .mii; alloc r2=ar.pfs,3,0,0,0
624 addp4 r33=0,r33
625 addp4 r34=0,r34 };;
626{ .mii; addp4 r32=0,r32
627#else
628{ .mii; alloc r2=ar.pfs,3,0,0,0
629#endif
630 add r14=8,r33
631 add r17=8,r34 }
632 .body
633{ .mii; add r15=16,r33
634 add r18=16,r34
635 add r16=24,r33 }
636.L_cheat_entry_point8:
637{ .mmi; add r19=24,r34
638
639 ldf8 f32=[r33],32 };;
640
641{ .mmi; ldf8 f120=[r34],32
642 ldf8 f121=[r17],32 }
643{ .mmi; ldf8 f122=[r18],32
644 ldf8 f123=[r19],32 };;
645{ .mmi; ldf8 f124=[r34]
646 ldf8 f125=[r17] }
647{ .mmi; ldf8 f126=[r18]
648 ldf8 f127=[r19] }
649
650{ .mmi; ldf8 f33=[r14],32
651 ldf8 f34=[r15],32 }
652{ .mmi; ldf8 f35=[r16],32;;
653 ldf8 f36=[r33] }
654{ .mmi; ldf8 f37=[r14]
655 ldf8 f38=[r15] }
656{ .mfi; ldf8 f39=[r16]
657// -------\ Entering multiplier's heaven /-------
658// ------------\ /------------
659// -----------------\ /-----------------
660// ----------------------\/----------------------
661 xma.hu f41=f32,f120,f0 }
662{ .mfi; xma.lu f40=f32,f120,f0 };; // (*)
663{ .mfi; xma.hu f51=f32,f121,f0 }
664{ .mfi; xma.lu f50=f32,f121,f0 };;
665{ .mfi; xma.hu f61=f32,f122,f0 }
666{ .mfi; xma.lu f60=f32,f122,f0 };;
667{ .mfi; xma.hu f71=f32,f123,f0 }
668{ .mfi; xma.lu f70=f32,f123,f0 };;
669{ .mfi; xma.hu f81=f32,f124,f0 }
670{ .mfi; xma.lu f80=f32,f124,f0 };;
671{ .mfi; xma.hu f91=f32,f125,f0 }
672{ .mfi; xma.lu f90=f32,f125,f0 };;
673{ .mfi; xma.hu f101=f32,f126,f0 }
674{ .mfi; xma.lu f100=f32,f126,f0 };;
675{ .mfi; xma.hu f111=f32,f127,f0 }
676{ .mfi; xma.lu f110=f32,f127,f0 };;//
677// (*) You can argue that splitting at every second bundle would
678// prevent "wider" IA-64 implementations from achieving the peak
679// performance. Well, not really... The catch is that if you
680// intend to keep 4 FP units busy by splitting at every fourth
681// bundle and thus perform these 16 multiplications in 4 ticks,
682// the first bundle *below* would stall because the result from
683// the first xma bundle *above* won't be available for another 3
684// ticks (if not more, being an optimist, I assume that "wider"
685// implementation will have same latency:-). This stall will hold
686// you back and the performance would be as if every second bundle
687// were split *anyway*...
688{ .mfi; getf.sig r16=f40
689 xma.hu f42=f33,f120,f41
690 add r33=8,r32 }
691{ .mfi; xma.lu f41=f33,f120,f41 };;
692{ .mfi; getf.sig r24=f50
693 xma.hu f52=f33,f121,f51 }
694{ .mfi; xma.lu f51=f33,f121,f51 };;
695{ .mfi; st8 [r32]=r16,16
696 xma.hu f62=f33,f122,f61 }
697{ .mfi; xma.lu f61=f33,f122,f61 };;
698{ .mfi; xma.hu f72=f33,f123,f71 }
699{ .mfi; xma.lu f71=f33,f123,f71 };;
700{ .mfi; xma.hu f82=f33,f124,f81 }
701{ .mfi; xma.lu f81=f33,f124,f81 };;
702{ .mfi; xma.hu f92=f33,f125,f91 }
703{ .mfi; xma.lu f91=f33,f125,f91 };;
704{ .mfi; xma.hu f102=f33,f126,f101 }
705{ .mfi; xma.lu f101=f33,f126,f101 };;
706{ .mfi; xma.hu f112=f33,f127,f111 }
707{ .mfi; xma.lu f111=f33,f127,f111 };;//
708//-------------------------------------------------//
709{ .mfi; getf.sig r25=f41
710 xma.hu f43=f34,f120,f42 }
711{ .mfi; xma.lu f42=f34,f120,f42 };;
712{ .mfi; getf.sig r16=f60
713 xma.hu f53=f34,f121,f52 }
714{ .mfi; xma.lu f52=f34,f121,f52 };;
715{ .mfi; getf.sig r17=f51
716 xma.hu f63=f34,f122,f62
717 add r25=r25,r24 }
718{ .mfi; xma.lu f62=f34,f122,f62
719 mov carry1=0 };;
720{ .mfi; cmp.ltu p6,p0=r25,r24
721 xma.hu f73=f34,f123,f72 }
722{ .mfi; xma.lu f72=f34,f123,f72 };;
723{ .mfi; st8 [r33]=r25,16
724 xma.hu f83=f34,f124,f82
725(p6) add carry1=1,carry1 }
726{ .mfi; xma.lu f82=f34,f124,f82 };;
727{ .mfi; xma.hu f93=f34,f125,f92 }
728{ .mfi; xma.lu f92=f34,f125,f92 };;
729{ .mfi; xma.hu f103=f34,f126,f102 }
730{ .mfi; xma.lu f102=f34,f126,f102 };;
731{ .mfi; xma.hu f113=f34,f127,f112 }
732{ .mfi; xma.lu f112=f34,f127,f112 };;//
733//-------------------------------------------------//
734{ .mfi; getf.sig r18=f42
735 xma.hu f44=f35,f120,f43
736 add r17=r17,r16 }
737{ .mfi; xma.lu f43=f35,f120,f43 };;
738{ .mfi; getf.sig r24=f70
739 xma.hu f54=f35,f121,f53 }
740{ .mfi; mov carry2=0
741 xma.lu f53=f35,f121,f53 };;
742{ .mfi; getf.sig r25=f61
743 xma.hu f64=f35,f122,f63
744 cmp.ltu p7,p0=r17,r16 }
745{ .mfi; add r18=r18,r17
746 xma.lu f63=f35,f122,f63 };;
747{ .mfi; getf.sig r26=f52
748 xma.hu f74=f35,f123,f73
749(p7) add carry2=1,carry2 }
750{ .mfi; cmp.ltu p7,p0=r18,r17
751 xma.lu f73=f35,f123,f73
752 add r18=r18,carry1 };;
753{ .mfi;
754 xma.hu f84=f35,f124,f83
755(p7) add carry2=1,carry2 }
756{ .mfi; cmp.ltu p7,p0=r18,carry1
757 xma.lu f83=f35,f124,f83 };;
758{ .mfi; st8 [r32]=r18,16
759 xma.hu f94=f35,f125,f93
760(p7) add carry2=1,carry2 }
761{ .mfi; xma.lu f93=f35,f125,f93 };;
762{ .mfi; xma.hu f104=f35,f126,f103 }
763{ .mfi; xma.lu f103=f35,f126,f103 };;
764{ .mfi; xma.hu f114=f35,f127,f113 }
765{ .mfi; mov carry1=0
766 xma.lu f113=f35,f127,f113
767 add r25=r25,r24 };;//
768//-------------------------------------------------//
769{ .mfi; getf.sig r27=f43
770 xma.hu f45=f36,f120,f44
771 cmp.ltu p6,p0=r25,r24 }
772{ .mfi; xma.lu f44=f36,f120,f44
773 add r26=r26,r25 };;
774{ .mfi; getf.sig r16=f80
775 xma.hu f55=f36,f121,f54
776(p6) add carry1=1,carry1 }
777{ .mfi; xma.lu f54=f36,f121,f54 };;
778{ .mfi; getf.sig r17=f71
779 xma.hu f65=f36,f122,f64
780 cmp.ltu p6,p0=r26,r25 }
781{ .mfi; xma.lu f64=f36,f122,f64
782 add r27=r27,r26 };;
783{ .mfi; getf.sig r18=f62
784 xma.hu f75=f36,f123,f74
785(p6) add carry1=1,carry1 }
786{ .mfi; cmp.ltu p6,p0=r27,r26
787 xma.lu f74=f36,f123,f74
788 add r27=r27,carry2 };;
789{ .mfi; getf.sig r19=f53
790 xma.hu f85=f36,f124,f84
791(p6) add carry1=1,carry1 }
792{ .mfi; xma.lu f84=f36,f124,f84
793 cmp.ltu p6,p0=r27,carry2 };;
794{ .mfi; st8 [r33]=r27,16
795 xma.hu f95=f36,f125,f94
796(p6) add carry1=1,carry1 }
797{ .mfi; xma.lu f94=f36,f125,f94 };;
798{ .mfi; xma.hu f105=f36,f126,f104 }
799{ .mfi; mov carry2=0
800 xma.lu f104=f36,f126,f104
801 add r17=r17,r16 };;
802{ .mfi; xma.hu f115=f36,f127,f114
803 cmp.ltu p7,p0=r17,r16 }
804{ .mfi; xma.lu f114=f36,f127,f114
805 add r18=r18,r17 };;//
806//-------------------------------------------------//
807{ .mfi; getf.sig r20=f44
808 xma.hu f46=f37,f120,f45
809(p7) add carry2=1,carry2 }
810{ .mfi; cmp.ltu p7,p0=r18,r17
811 xma.lu f45=f37,f120,f45
812 add r19=r19,r18 };;
813{ .mfi; getf.sig r24=f90
814 xma.hu f56=f37,f121,f55 }
815{ .mfi; xma.lu f55=f37,f121,f55 };;
816{ .mfi; getf.sig r25=f81
817 xma.hu f66=f37,f122,f65
818(p7) add carry2=1,carry2 }
819{ .mfi; cmp.ltu p7,p0=r19,r18
820 xma.lu f65=f37,f122,f65
821 add r20=r20,r19 };;
822{ .mfi; getf.sig r26=f72
823 xma.hu f76=f37,f123,f75
824(p7) add carry2=1,carry2 }
825{ .mfi; cmp.ltu p7,p0=r20,r19
826 xma.lu f75=f37,f123,f75
827 add r20=r20,carry1 };;
828{ .mfi; getf.sig r27=f63
829 xma.hu f86=f37,f124,f85
830(p7) add carry2=1,carry2 }
831{ .mfi; xma.lu f85=f37,f124,f85
832 cmp.ltu p7,p0=r20,carry1 };;
833{ .mfi; getf.sig r28=f54
834 xma.hu f96=f37,f125,f95
835(p7) add carry2=1,carry2 }
836{ .mfi; st8 [r32]=r20,16
837 xma.lu f95=f37,f125,f95 };;
838{ .mfi; xma.hu f106=f37,f126,f105 }
839{ .mfi; mov carry1=0
840 xma.lu f105=f37,f126,f105
841 add r25=r25,r24 };;
842{ .mfi; xma.hu f116=f37,f127,f115
843 cmp.ltu p6,p0=r25,r24 }
844{ .mfi; xma.lu f115=f37,f127,f115
845 add r26=r26,r25 };;//
846//-------------------------------------------------//
847{ .mfi; getf.sig r29=f45
848 xma.hu f47=f38,f120,f46
849(p6) add carry1=1,carry1 }
850{ .mfi; cmp.ltu p6,p0=r26,r25
851 xma.lu f46=f38,f120,f46
852 add r27=r27,r26 };;
853{ .mfi; getf.sig r16=f100
854 xma.hu f57=f38,f121,f56
855(p6) add carry1=1,carry1 }
856{ .mfi; cmp.ltu p6,p0=r27,r26
857 xma.lu f56=f38,f121,f56
858 add r28=r28,r27 };;
859{ .mfi; getf.sig r17=f91
860 xma.hu f67=f38,f122,f66
861(p6) add carry1=1,carry1 }
862{ .mfi; cmp.ltu p6,p0=r28,r27
863 xma.lu f66=f38,f122,f66
864 add r29=r29,r28 };;
865{ .mfi; getf.sig r18=f82
866 xma.hu f77=f38,f123,f76
867(p6) add carry1=1,carry1 }
868{ .mfi; cmp.ltu p6,p0=r29,r28
869 xma.lu f76=f38,f123,f76
870 add r29=r29,carry2 };;
871{ .mfi; getf.sig r19=f73
872 xma.hu f87=f38,f124,f86
873(p6) add carry1=1,carry1 }
874{ .mfi; xma.lu f86=f38,f124,f86
875 cmp.ltu p6,p0=r29,carry2 };;
876{ .mfi; getf.sig r20=f64
877 xma.hu f97=f38,f125,f96
878(p6) add carry1=1,carry1 }
879{ .mfi; st8 [r33]=r29,16
880 xma.lu f96=f38,f125,f96 };;
881{ .mfi; getf.sig r21=f55
882 xma.hu f107=f38,f126,f106 }
883{ .mfi; mov carry2=0
884 xma.lu f106=f38,f126,f106
885 add r17=r17,r16 };;
886{ .mfi; xma.hu f117=f38,f127,f116
887 cmp.ltu p7,p0=r17,r16 }
888{ .mfi; xma.lu f116=f38,f127,f116
889 add r18=r18,r17 };;//
890//-------------------------------------------------//
891{ .mfi; getf.sig r22=f46
892 xma.hu f48=f39,f120,f47
893(p7) add carry2=1,carry2 }
894{ .mfi; cmp.ltu p7,p0=r18,r17
895 xma.lu f47=f39,f120,f47
896 add r19=r19,r18 };;
897{ .mfi; getf.sig r24=f110
898 xma.hu f58=f39,f121,f57
899(p7) add carry2=1,carry2 }
900{ .mfi; cmp.ltu p7,p0=r19,r18
901 xma.lu f57=f39,f121,f57
902 add r20=r20,r19 };;
903{ .mfi; getf.sig r25=f101
904 xma.hu f68=f39,f122,f67
905(p7) add carry2=1,carry2 }
906{ .mfi; cmp.ltu p7,p0=r20,r19
907 xma.lu f67=f39,f122,f67
908 add r21=r21,r20 };;
909{ .mfi; getf.sig r26=f92
910 xma.hu f78=f39,f123,f77
911(p7) add carry2=1,carry2 }
912{ .mfi; cmp.ltu p7,p0=r21,r20
913 xma.lu f77=f39,f123,f77
914 add r22=r22,r21 };;
915{ .mfi; getf.sig r27=f83
916 xma.hu f88=f39,f124,f87
917(p7) add carry2=1,carry2 }
918{ .mfi; cmp.ltu p7,p0=r22,r21
919 xma.lu f87=f39,f124,f87
920 add r22=r22,carry1 };;
921{ .mfi; getf.sig r28=f74
922 xma.hu f98=f39,f125,f97
923(p7) add carry2=1,carry2 }
924{ .mfi; xma.lu f97=f39,f125,f97
925 cmp.ltu p7,p0=r22,carry1 };;
926{ .mfi; getf.sig r29=f65
927 xma.hu f108=f39,f126,f107
928(p7) add carry2=1,carry2 }
929{ .mfi; st8 [r32]=r22,16
930 xma.lu f107=f39,f126,f107 };;
931{ .mfi; getf.sig r30=f56
932 xma.hu f118=f39,f127,f117 }
933{ .mfi; xma.lu f117=f39,f127,f117 };;//
934//-------------------------------------------------//
935// Leaving muliplier's heaven... Quite a ride, huh?
936
937{ .mii; getf.sig r31=f47
938 add r25=r25,r24
939 mov carry1=0 };;
940{ .mii; getf.sig r16=f111
941 cmp.ltu p6,p0=r25,r24
942 add r26=r26,r25 };;
943{ .mfb; getf.sig r17=f102 }
944{ .mii;
945(p6) add carry1=1,carry1
946 cmp.ltu p6,p0=r26,r25
947 add r27=r27,r26 };;
948{ .mfb; nop.m 0x0 }
949{ .mii;
950(p6) add carry1=1,carry1
951 cmp.ltu p6,p0=r27,r26
952 add r28=r28,r27 };;
953{ .mii; getf.sig r18=f93
954 add r17=r17,r16
955 mov carry3=0 }
956{ .mii;
957(p6) add carry1=1,carry1
958 cmp.ltu p6,p0=r28,r27
959 add r29=r29,r28 };;
960{ .mii; getf.sig r19=f84
961 cmp.ltu p7,p0=r17,r16 }
962{ .mii;
963(p6) add carry1=1,carry1
964 cmp.ltu p6,p0=r29,r28
965 add r30=r30,r29 };;
966{ .mii; getf.sig r20=f75
967 add r18=r18,r17 }
968{ .mii;
969(p6) add carry1=1,carry1
970 cmp.ltu p6,p0=r30,r29
971 add r31=r31,r30 };;
972{ .mfb; getf.sig r21=f66 }
973{ .mii; (p7) add carry3=1,carry3
974 cmp.ltu p7,p0=r18,r17
975 add r19=r19,r18 }
976{ .mfb; nop.m 0x0 }
977{ .mii;
978(p6) add carry1=1,carry1
979 cmp.ltu p6,p0=r31,r30
980 add r31=r31,carry2 };;
981{ .mfb; getf.sig r22=f57 }
982{ .mii; (p7) add carry3=1,carry3
983 cmp.ltu p7,p0=r19,r18
984 add r20=r20,r19 }
985{ .mfb; nop.m 0x0 }
986{ .mii;
987(p6) add carry1=1,carry1
988 cmp.ltu p6,p0=r31,carry2 };;
989{ .mfb; getf.sig r23=f48 }
990{ .mii; (p7) add carry3=1,carry3
991 cmp.ltu p7,p0=r20,r19
992 add r21=r21,r20 }
993{ .mii;
994(p6) add carry1=1,carry1 }
995{ .mfb; st8 [r33]=r31,16 };;
996
997{ .mfb; getf.sig r24=f112 }
998{ .mii; (p7) add carry3=1,carry3
999 cmp.ltu p7,p0=r21,r20
1000 add r22=r22,r21 };;
1001{ .mfb; getf.sig r25=f103 }
1002{ .mii; (p7) add carry3=1,carry3
1003 cmp.ltu p7,p0=r22,r21
1004 add r23=r23,r22 };;
1005{ .mfb; getf.sig r26=f94 }
1006{ .mii; (p7) add carry3=1,carry3
1007 cmp.ltu p7,p0=r23,r22
1008 add r23=r23,carry1 };;
1009{ .mfb; getf.sig r27=f85 }
1010{ .mii; (p7) add carry3=1,carry3
1011 cmp.ltu p7,p8=r23,carry1};;
1012{ .mii; getf.sig r28=f76
1013 add r25=r25,r24
1014 mov carry1=0 }
1015{ .mii; st8 [r32]=r23,16
1016 (p7) add carry2=1,carry3
1017 (p8) add carry2=0,carry3 };;
1018
1019{ .mfb; nop.m 0x0 }
1020{ .mii; getf.sig r29=f67
1021 cmp.ltu p6,p0=r25,r24
1022 add r26=r26,r25 };;
1023{ .mfb; getf.sig r30=f58 }
1024{ .mii;
1025(p6) add carry1=1,carry1
1026 cmp.ltu p6,p0=r26,r25
1027 add r27=r27,r26 };;
1028{ .mfb; getf.sig r16=f113 }
1029{ .mii;
1030(p6) add carry1=1,carry1
1031 cmp.ltu p6,p0=r27,r26
1032 add r28=r28,r27 };;
1033{ .mfb; getf.sig r17=f104 }
1034{ .mii;
1035(p6) add carry1=1,carry1
1036 cmp.ltu p6,p0=r28,r27
1037 add r29=r29,r28 };;
1038{ .mfb; getf.sig r18=f95 }
1039{ .mii;
1040(p6) add carry1=1,carry1
1041 cmp.ltu p6,p0=r29,r28
1042 add r30=r30,r29 };;
1043{ .mii; getf.sig r19=f86
1044 add r17=r17,r16
1045 mov carry3=0 }
1046{ .mii;
1047(p6) add carry1=1,carry1
1048 cmp.ltu p6,p0=r30,r29
1049 add r30=r30,carry2 };;
1050{ .mii; getf.sig r20=f77
1051 cmp.ltu p7,p0=r17,r16
1052 add r18=r18,r17 }
1053{ .mii;
1054(p6) add carry1=1,carry1
1055 cmp.ltu p6,p0=r30,carry2 };;
1056{ .mfb; getf.sig r21=f68 }
1057{ .mii; st8 [r33]=r30,16
1058(p6) add carry1=1,carry1 };;
1059
1060{ .mfb; getf.sig r24=f114 }
1061{ .mii; (p7) add carry3=1,carry3
1062 cmp.ltu p7,p0=r18,r17
1063 add r19=r19,r18 };;
1064{ .mfb; getf.sig r25=f105 }
1065{ .mii; (p7) add carry3=1,carry3
1066 cmp.ltu p7,p0=r19,r18
1067 add r20=r20,r19 };;
1068{ .mfb; getf.sig r26=f96 }
1069{ .mii; (p7) add carry3=1,carry3
1070 cmp.ltu p7,p0=r20,r19
1071 add r21=r21,r20 };;
1072{ .mfb; getf.sig r27=f87 }
1073{ .mii; (p7) add carry3=1,carry3
1074 cmp.ltu p7,p0=r21,r20
1075 add r21=r21,carry1 };;
1076{ .mib; getf.sig r28=f78
1077 add r25=r25,r24 }
1078{ .mib; (p7) add carry3=1,carry3
1079 cmp.ltu p7,p8=r21,carry1};;
1080{ .mii; st8 [r32]=r21,16
1081 (p7) add carry2=1,carry3
1082 (p8) add carry2=0,carry3 }
1083
1084{ .mii; mov carry1=0
1085 cmp.ltu p6,p0=r25,r24
1086 add r26=r26,r25 };;
1087{ .mfb; getf.sig r16=f115 }
1088{ .mii;
1089(p6) add carry1=1,carry1
1090 cmp.ltu p6,p0=r26,r25
1091 add r27=r27,r26 };;
1092{ .mfb; getf.sig r17=f106 }
1093{ .mii;
1094(p6) add carry1=1,carry1
1095 cmp.ltu p6,p0=r27,r26
1096 add r28=r28,r27 };;
1097{ .mfb; getf.sig r18=f97 }
1098{ .mii;
1099(p6) add carry1=1,carry1
1100 cmp.ltu p6,p0=r28,r27
1101 add r28=r28,carry2 };;
1102{ .mib; getf.sig r19=f88
1103 add r17=r17,r16 }
1104{ .mib;
1105(p6) add carry1=1,carry1
1106 cmp.ltu p6,p0=r28,carry2 };;
1107{ .mii; st8 [r33]=r28,16
1108(p6) add carry1=1,carry1 }
1109
1110{ .mii; mov carry2=0
1111 cmp.ltu p7,p0=r17,r16
1112 add r18=r18,r17 };;
1113{ .mfb; getf.sig r24=f116 }
1114{ .mii; (p7) add carry2=1,carry2
1115 cmp.ltu p7,p0=r18,r17
1116 add r19=r19,r18 };;
1117{ .mfb; getf.sig r25=f107 }
1118{ .mii; (p7) add carry2=1,carry2
1119 cmp.ltu p7,p0=r19,r18
1120 add r19=r19,carry1 };;
1121{ .mfb; getf.sig r26=f98 }
1122{ .mii; (p7) add carry2=1,carry2
1123 cmp.ltu p7,p0=r19,carry1};;
1124{ .mii; st8 [r32]=r19,16
1125 (p7) add carry2=1,carry2 }
1126
1127{ .mfb; add r25=r25,r24 };;
1128
1129{ .mfb; getf.sig r16=f117 }
1130{ .mii; mov carry1=0
1131 cmp.ltu p6,p0=r25,r24
1132 add r26=r26,r25 };;
1133{ .mfb; getf.sig r17=f108 }
1134{ .mii;
1135(p6) add carry1=1,carry1
1136 cmp.ltu p6,p0=r26,r25
1137 add r26=r26,carry2 };;
1138{ .mfb; nop.m 0x0 }
1139{ .mii;
1140(p6) add carry1=1,carry1
1141 cmp.ltu p6,p0=r26,carry2 };;
1142{ .mii; st8 [r33]=r26,16
1143(p6) add carry1=1,carry1 }
1144
1145{ .mfb; add r17=r17,r16 };;
1146{ .mfb; getf.sig r24=f118 }
1147{ .mii; mov carry2=0
1148 cmp.ltu p7,p0=r17,r16
1149 add r17=r17,carry1 };;
1150{ .mii; (p7) add carry2=1,carry2
1151 cmp.ltu p7,p0=r17,carry1};;
1152{ .mii; st8 [r32]=r17
1153 (p7) add carry2=1,carry2 };;
1154{ .mfb; add r24=r24,carry2 };;
1155{ .mib; st8 [r33]=r24 }
1156
1157{ .mib; rum 1<<5 // clear um.mfh
1158 br.ret.sptk.many b0 };;
1159.endp bn_mul_comba8#
1160#undef carry3
1161#undef carry2
1162#undef carry1
1163#endif
1164
1165#if 1
1166// It's possible to make it faster (see comment to bn_sqr_comba8), but
1167// I reckon it doesn't worth the effort. Basically because the routine
1168// (actually both of them) practically never called... So I just play
1169// same trick as with bn_sqr_comba8.
1170//
1171// void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1172//
1173.global bn_sqr_comba4#
1174.proc bn_sqr_comba4#
1175.align 64
1176bn_sqr_comba4:
1177 .prologue
1178 .fframe 0
1179 .save ar.pfs,r2
1180#if defined(_HPUX_SOURCE) && !defined(_LP64)
1181{ .mii; alloc r2=ar.pfs,2,1,0,0
1182 addp4 r32=0,r32
1183 addp4 r33=0,r33 };;
1184{ .mii;
1185#else
1186{ .mii; alloc r2=ar.pfs,2,1,0,0
1187#endif
1188 mov r34=r33
1189 add r14=8,r33 };;
1190 .body
1191{ .mii; add r17=8,r34
1192 add r15=16,r33
1193 add r18=16,r34 }
1194{ .mfb; add r16=24,r33
1195 br .L_cheat_entry_point4 };;
1196.endp bn_sqr_comba4#
1197#endif
1198
1199#if 1
1200// Runs in ~115 cycles and ~4.5 times faster than C. Well, whatever...
1201//
1202// void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1203//
1204#define carry1 r14
1205#define carry2 r15
1206.global bn_mul_comba4#
1207.proc bn_mul_comba4#
1208.align 64
1209bn_mul_comba4:
1210 .prologue
1211 .fframe 0
1212 .save ar.pfs,r2
1213#if defined(_HPUX_SOURCE) && !defined(_LP64)
1214{ .mii; alloc r2=ar.pfs,3,0,0,0
1215 addp4 r33=0,r33
1216 addp4 r34=0,r34 };;
1217{ .mii; addp4 r32=0,r32
1218#else
1219{ .mii; alloc r2=ar.pfs,3,0,0,0
1220#endif
1221 add r14=8,r33
1222 add r17=8,r34 }
1223 .body
1224{ .mii; add r15=16,r33
1225 add r18=16,r34
1226 add r16=24,r33 };;
1227.L_cheat_entry_point4:
1228{ .mmi; add r19=24,r34
1229
1230 ldf8 f32=[r33] }
1231
1232{ .mmi; ldf8 f120=[r34]
1233 ldf8 f121=[r17] };;
1234{ .mmi; ldf8 f122=[r18]
1235 ldf8 f123=[r19] }
1236
1237{ .mmi; ldf8 f33=[r14]
1238 ldf8 f34=[r15] }
1239{ .mfi; ldf8 f35=[r16]
1240
1241 xma.hu f41=f32,f120,f0 }
1242{ .mfi; xma.lu f40=f32,f120,f0 };;
1243{ .mfi; xma.hu f51=f32,f121,f0 }
1244{ .mfi; xma.lu f50=f32,f121,f0 };;
1245{ .mfi; xma.hu f61=f32,f122,f0 }
1246{ .mfi; xma.lu f60=f32,f122,f0 };;
1247{ .mfi; xma.hu f71=f32,f123,f0 }
1248{ .mfi; xma.lu f70=f32,f123,f0 };;//
1249// Major stall takes place here, and 3 more places below. Result from
1250// first xma is not available for another 3 ticks.
1251{ .mfi; getf.sig r16=f40
1252 xma.hu f42=f33,f120,f41
1253 add r33=8,r32 }
1254{ .mfi; xma.lu f41=f33,f120,f41 };;
1255{ .mfi; getf.sig r24=f50
1256 xma.hu f52=f33,f121,f51 }
1257{ .mfi; xma.lu f51=f33,f121,f51 };;
1258{ .mfi; st8 [r32]=r16,16
1259 xma.hu f62=f33,f122,f61 }
1260{ .mfi; xma.lu f61=f33,f122,f61 };;
1261{ .mfi; xma.hu f72=f33,f123,f71 }
1262{ .mfi; xma.lu f71=f33,f123,f71 };;//
1263//-------------------------------------------------//
1264{ .mfi; getf.sig r25=f41
1265 xma.hu f43=f34,f120,f42 }
1266{ .mfi; xma.lu f42=f34,f120,f42 };;
1267{ .mfi; getf.sig r16=f60
1268 xma.hu f53=f34,f121,f52 }
1269{ .mfi; xma.lu f52=f34,f121,f52 };;
1270{ .mfi; getf.sig r17=f51
1271 xma.hu f63=f34,f122,f62
1272 add r25=r25,r24 }
1273{ .mfi; mov carry1=0
1274 xma.lu f62=f34,f122,f62 };;
1275{ .mfi; st8 [r33]=r25,16
1276 xma.hu f73=f34,f123,f72
1277 cmp.ltu p6,p0=r25,r24 }
1278{ .mfi; xma.lu f72=f34,f123,f72 };;//
1279//-------------------------------------------------//
1280{ .mfi; getf.sig r18=f42
1281 xma.hu f44=f35,f120,f43
1282(p6) add carry1=1,carry1 }
1283{ .mfi; add r17=r17,r16
1284 xma.lu f43=f35,f120,f43
1285 mov carry2=0 };;
1286{ .mfi; getf.sig r24=f70
1287 xma.hu f54=f35,f121,f53
1288 cmp.ltu p7,p0=r17,r16 }
1289{ .mfi; xma.lu f53=f35,f121,f53 };;
1290{ .mfi; getf.sig r25=f61
1291 xma.hu f64=f35,f122,f63
1292 add r18=r18,r17 }
1293{ .mfi; xma.lu f63=f35,f122,f63
1294(p7) add carry2=1,carry2 };;
1295{ .mfi; getf.sig r26=f52
1296 xma.hu f74=f35,f123,f73
1297 cmp.ltu p7,p0=r18,r17 }
1298{ .mfi; xma.lu f73=f35,f123,f73
1299 add r18=r18,carry1 };;
1300//-------------------------------------------------//
1301{ .mii; st8 [r32]=r18,16
1302(p7) add carry2=1,carry2
1303 cmp.ltu p7,p0=r18,carry1 };;
1304
1305{ .mfi; getf.sig r27=f43 // last major stall
1306(p7) add carry2=1,carry2 };;
1307{ .mii; getf.sig r16=f71
1308 add r25=r25,r24
1309 mov carry1=0 };;
1310{ .mii; getf.sig r17=f62
1311 cmp.ltu p6,p0=r25,r24
1312 add r26=r26,r25 };;
1313{ .mii;
1314(p6) add carry1=1,carry1
1315 cmp.ltu p6,p0=r26,r25
1316 add r27=r27,r26 };;
1317{ .mii;
1318(p6) add carry1=1,carry1
1319 cmp.ltu p6,p0=r27,r26
1320 add r27=r27,carry2 };;
1321{ .mii; getf.sig r18=f53
1322(p6) add carry1=1,carry1
1323 cmp.ltu p6,p0=r27,carry2 };;
1324{ .mfi; st8 [r33]=r27,16
1325(p6) add carry1=1,carry1 }
1326
1327{ .mii; getf.sig r19=f44
1328 add r17=r17,r16
1329 mov carry2=0 };;
1330{ .mii; getf.sig r24=f72
1331 cmp.ltu p7,p0=r17,r16
1332 add r18=r18,r17 };;
1333{ .mii; (p7) add carry2=1,carry2
1334 cmp.ltu p7,p0=r18,r17
1335 add r19=r19,r18 };;
1336{ .mii; (p7) add carry2=1,carry2
1337 cmp.ltu p7,p0=r19,r18
1338 add r19=r19,carry1 };;
1339{ .mii; getf.sig r25=f63
1340 (p7) add carry2=1,carry2
1341 cmp.ltu p7,p0=r19,carry1};;
1342{ .mii; st8 [r32]=r19,16
1343 (p7) add carry2=1,carry2 }
1344
1345{ .mii; getf.sig r26=f54
1346 add r25=r25,r24
1347 mov carry1=0 };;
1348{ .mii; getf.sig r16=f73
1349 cmp.ltu p6,p0=r25,r24
1350 add r26=r26,r25 };;
1351{ .mii;
1352(p6) add carry1=1,carry1
1353 cmp.ltu p6,p0=r26,r25
1354 add r26=r26,carry2 };;
1355{ .mii; getf.sig r17=f64
1356(p6) add carry1=1,carry1
1357 cmp.ltu p6,p0=r26,carry2 };;
1358{ .mii; st8 [r33]=r26,16
1359(p6) add carry1=1,carry1 }
1360
1361{ .mii; getf.sig r24=f74
1362 add r17=r17,r16
1363 mov carry2=0 };;
1364{ .mii; cmp.ltu p7,p0=r17,r16
1365 add r17=r17,carry1 };;
1366
1367{ .mii; (p7) add carry2=1,carry2
1368 cmp.ltu p7,p0=r17,carry1};;
1369{ .mii; st8 [r32]=r17,16
1370 (p7) add carry2=1,carry2 };;
1371
1372{ .mii; add r24=r24,carry2 };;
1373{ .mii; st8 [r33]=r24 }
1374
1375{ .mib; rum 1<<5 // clear um.mfh
1376 br.ret.sptk.many b0 };;
1377.endp bn_mul_comba4#
1378#undef carry2
1379#undef carry1
1380#endif
1381
1382#if 1
1383//
1384// BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
1385//
1386// In the nutshell it's a port of my MIPS III/IV implementation.
1387//
1388#define AT r14
1389#define H r16
1390#define HH r20
1391#define L r17
1392#define D r18
1393#define DH r22
1394#define I r21
1395
1396#if 0
1397// Some preprocessors (most notably HP-UX) appear to be allergic to
1398// macros enclosed to parenthesis [as these three were].
1399#define cont p16
1400#define break p0 // p20
1401#define equ p24
1402#else
1403cont=p16
1404break=p0
1405equ=p24
1406#endif
1407
1408.global abort#
1409.global bn_div_words#
1410.proc bn_div_words#
1411.align 64
1412bn_div_words:
1413 .prologue
1414 .fframe 0
1415 .save ar.pfs,r2
1416 .save b0,r3
1417{ .mii; alloc r2=ar.pfs,3,5,0,8
1418 mov r3=b0
1419 mov r10=pr };;
1420{ .mmb; cmp.eq p6,p0=r34,r0
1421 mov r8=-1
1422(p6) br.ret.spnt.many b0 };;
1423
1424 .body
1425{ .mii; mov H=r32 // save h
1426 mov ar.ec=0 // don't rotate at exit
1427 mov pr.rot=0 }
1428{ .mii; mov L=r33 // save l
1429 mov r36=r0 };;
1430
1431.L_divw_shift: // -vv- note signed comparison
1432{ .mfi; (p0) cmp.lt p16,p0=r0,r34 // d
1433 (p0) shladd r33=r34,1,r0 }
1434{ .mfb; (p0) add r35=1,r36
1435 (p0) nop.f 0x0
1436(p16) br.wtop.dpnt .L_divw_shift };;
1437
1438{ .mii; mov D=r34
1439 shr.u DH=r34,32
1440 sub r35=64,r36 };;
1441{ .mii; setf.sig f7=DH
1442 shr.u AT=H,r35
1443 mov I=r36 };;
1444{ .mib; cmp.ne p6,p0=r0,AT
1445 shl H=H,r36
1446(p6) br.call.spnt.clr b0=abort };; // overflow, die...
1447
1448{ .mfi; fcvt.xuf.s1 f7=f7
1449 shr.u AT=L,r35 };;
1450{ .mii; shl L=L,r36
1451 or H=H,AT };;
1452
1453{ .mii; nop.m 0x0
1454 cmp.leu p6,p0=D,H;;
1455(p6) sub H=H,D }
1456
1457{ .mlx; setf.sig f14=D
1458 movl AT=0xffffffff };;
1459///////////////////////////////////////////////////////////
1460{ .mii; setf.sig f6=H
1461 shr.u HH=H,32;;
1462 cmp.eq p6,p7=HH,DH };;
1463{ .mfb;
1464(p6) setf.sig f8=AT
1465(p7) fcvt.xuf.s1 f6=f6
1466(p7) br.call.sptk b6=.L_udiv64_32_b6 };;
1467
1468{ .mfi; getf.sig r33=f8 // q
1469 xmpy.lu f9=f8,f14 }
1470{ .mfi; xmpy.hu f10=f8,f14
1471 shrp H=H,L,32 };;
1472
1473{ .mmi; getf.sig r35=f9 // tl
1474 getf.sig r31=f10 };; // th
1475
1476.L_divw_1st_iter:
1477{ .mii; (p0) add r32=-1,r33
1478 (p0) cmp.eq equ,cont=HH,r31 };;
1479{ .mii; (p0) cmp.ltu p8,p0=r35,D
1480 (p0) sub r34=r35,D
1481 (equ) cmp.leu break,cont=r35,H };;
1482{ .mib; (cont) cmp.leu cont,break=HH,r31
1483 (p8) add r31=-1,r31
1484(cont) br.wtop.spnt .L_divw_1st_iter };;
1485///////////////////////////////////////////////////////////
1486{ .mii; sub H=H,r35
1487 shl r8=r33,32
1488 shl L=L,32 };;
1489///////////////////////////////////////////////////////////
1490{ .mii; setf.sig f6=H
1491 shr.u HH=H,32;;
1492 cmp.eq p6,p7=HH,DH };;
1493{ .mfb;
1494(p6) setf.sig f8=AT
1495(p7) fcvt.xuf.s1 f6=f6
1496(p7) br.call.sptk b6=.L_udiv64_32_b6 };;
1497
1498{ .mfi; getf.sig r33=f8 // q
1499 xmpy.lu f9=f8,f14 }
1500{ .mfi; xmpy.hu f10=f8,f14
1501 shrp H=H,L,32 };;
1502
1503{ .mmi; getf.sig r35=f9 // tl
1504 getf.sig r31=f10 };; // th
1505
1506.L_divw_2nd_iter:
1507{ .mii; (p0) add r32=-1,r33
1508 (p0) cmp.eq equ,cont=HH,r31 };;
1509{ .mii; (p0) cmp.ltu p8,p0=r35,D
1510 (p0) sub r34=r35,D
1511 (equ) cmp.leu break,cont=r35,H };;
1512{ .mib; (cont) cmp.leu cont,break=HH,r31
1513 (p8) add r31=-1,r31
1514(cont) br.wtop.spnt .L_divw_2nd_iter };;
1515///////////////////////////////////////////////////////////
1516{ .mii; sub H=H,r35
1517 or r8=r8,r33
1518 mov ar.pfs=r2 };;
1519{ .mii; shr.u r9=H,I // remainder if anybody wants it
1520 mov pr=r10,0x1ffff }
1521{ .mfb; br.ret.sptk.many b0 };;
1522
1523// Unsigned 64 by 32 (well, by 64 for the moment) bit integer division
1524// procedure.
1525//
1526// inputs: f6 = (double)a, f7 = (double)b
1527// output: f8 = (int)(a/b)
1528// clobbered: f8,f9,f10,f11,pred
1529pred=p15
1530// One can argue that this snippet is copyrighted to Intel
1531// Corporation, as it's essentially identical to one of those
1532// found in "Divide, Square Root and Remainder" section at
1533// http://www.intel.com/software/products/opensource/libraries/num.htm.
1534// Yes, I admit that the referred code was used as template,
1535// but after I realized that there hardly is any other instruction
1536// sequence which would perform this operation. I mean I figure that
1537// any independent attempt to implement high-performance division
1538// will result in code virtually identical to the Intel code. It
1539// should be noted though that below division kernel is 1 cycle
1540// faster than Intel one (note commented splits:-), not to mention
1541// original prologue (rather lack of one) and epilogue.
1542.align 32
1543.skip 16
1544.L_udiv64_32_b6:
1545 frcpa.s1 f8,pred=f6,f7;; // [0] y0 = 1 / b
1546
1547(pred) fnma.s1 f9=f7,f8,f1 // [5] e0 = 1 - b * y0
1548(pred) fmpy.s1 f10=f6,f8;; // [5] q0 = a * y0
1549(pred) fmpy.s1 f11=f9,f9 // [10] e1 = e0 * e0
1550(pred) fma.s1 f10=f9,f10,f10;; // [10] q1 = q0 + e0 * q0
1551(pred) fma.s1 f8=f9,f8,f8 //;; // [15] y1 = y0 + e0 * y0
1552(pred) fma.s1 f9=f11,f10,f10;; // [15] q2 = q1 + e1 * q1
1553(pred) fma.s1 f8=f11,f8,f8 //;; // [20] y2 = y1 + e1 * y1
1554(pred) fnma.s1 f10=f7,f9,f6;; // [20] r2 = a - b * q2
1555(pred) fma.s1 f8=f10,f8,f9;; // [25] q3 = q2 + r2 * y2
1556
1557 fcvt.fxu.trunc.s1 f8=f8 // [30] q = trunc(q3)
1558 br.ret.sptk.many b6;;
1559.endp bn_div_words#
1560#endif
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2.s b/src/lib/libcrypto/bn/asm/pa-risc2.s
new file mode 100644
index 0000000000..f3b16290eb
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/pa-risc2.s
@@ -0,0 +1,1618 @@
1;
2; PA-RISC 2.0 implementation of bn_asm code, based on the
3; 64-bit version of the code. This code is effectively the
4; same as the 64-bit version except the register model is
5; slightly different given all values must be 32-bit between
6; function calls. Thus the 64-bit return values are returned
7; in %ret0 and %ret1 vs just %ret0 as is done in 64-bit
8;
9;
10; This code is approximately 2x faster than the C version
11; for RSA/DSA.
12;
13; See http://devresource.hp.com/ for more details on the PA-RISC
14; architecture. Also see the book "PA-RISC 2.0 Architecture"
15; by Gerry Kane for information on the instruction set architecture.
16;
17; Code written by Chris Ruemmler (with some help from the HP C
18; compiler).
19;
20; The code compiles with HP's assembler
21;
22
23 .level 2.0N
24 .space $TEXT$
25 .subspa $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY
26
27;
28; Global Register definitions used for the routines.
29;
30; Some information about HP's runtime architecture for 32-bits.
31;
32; "Caller save" means the calling function must save the register
33; if it wants the register to be preserved.
34; "Callee save" means if a function uses the register, it must save
35; the value before using it.
36;
37; For the floating point registers
38;
39; "caller save" registers: fr4-fr11, fr22-fr31
40; "callee save" registers: fr12-fr21
41; "special" registers: fr0-fr3 (status and exception registers)
42;
43; For the integer registers
44; value zero : r0
45; "caller save" registers: r1,r19-r26
46; "callee save" registers: r3-r18
47; return register : r2 (rp)
48; return values ; r28,r29 (ret0,ret1)
49; Stack pointer ; r30 (sp)
50; millicode return ptr ; r31 (also a caller save register)
51
52
53;
54; Arguments to the routines
55;
56r_ptr .reg %r26
57a_ptr .reg %r25
58b_ptr .reg %r24
59num .reg %r24
60n .reg %r23
61
62;
63; Note that the "w" argument for bn_mul_add_words and bn_mul_words
64; is passed on the stack at a delta of -56 from the top of stack
65; as the routine is entered.
66;
67
68;
69; Globals used in some routines
70;
71
72top_overflow .reg %r23
73high_mask .reg %r22 ; value 0xffffffff80000000L
74
75
76;------------------------------------------------------------------------------
77;
78; bn_mul_add_words
79;
80;BN_ULONG bn_mul_add_words(BN_ULONG *r_ptr, BN_ULONG *a_ptr,
81; int num, BN_ULONG w)
82;
83; arg0 = r_ptr
84; arg1 = a_ptr
85; arg3 = num
86; -56(sp) = w
87;
88; Local register definitions
89;
90
91fm1 .reg %fr22
92fm .reg %fr23
93ht_temp .reg %fr24
94ht_temp_1 .reg %fr25
95lt_temp .reg %fr26
96lt_temp_1 .reg %fr27
97fm1_1 .reg %fr28
98fm_1 .reg %fr29
99
100fw_h .reg %fr7L
101fw_l .reg %fr7R
102fw .reg %fr7
103
104fht_0 .reg %fr8L
105flt_0 .reg %fr8R
106t_float_0 .reg %fr8
107
108fht_1 .reg %fr9L
109flt_1 .reg %fr9R
110t_float_1 .reg %fr9
111
112tmp_0 .reg %r31
113tmp_1 .reg %r21
114m_0 .reg %r20
115m_1 .reg %r19
116ht_0 .reg %r1
117ht_1 .reg %r3
118lt_0 .reg %r4
119lt_1 .reg %r5
120m1_0 .reg %r6
121m1_1 .reg %r7
122rp_val .reg %r8
123rp_val_1 .reg %r9
124
125bn_mul_add_words
126 .export bn_mul_add_words,entry,NO_RELOCATION,LONG_RETURN
127 .proc
128 .callinfo frame=128
129 .entry
130 .align 64
131
132 STD %r3,0(%sp) ; save r3
133 STD %r4,8(%sp) ; save r4
134 NOP ; Needed to make the loop 16-byte aligned
135 NOP ; needed to make the loop 16-byte aligned
136
137 STD %r5,16(%sp) ; save r5
138 NOP
139 STD %r6,24(%sp) ; save r6
140 STD %r7,32(%sp) ; save r7
141
142 STD %r8,40(%sp) ; save r8
143 STD %r9,48(%sp) ; save r9
144 COPY %r0,%ret1 ; return 0 by default
145 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
146
147 CMPIB,>= 0,num,bn_mul_add_words_exit ; if (num <= 0) then exit
148 LDO 128(%sp),%sp ; bump stack
149
150 ;
151 ; The loop is unrolled twice, so if there is only 1 number
152 ; then go straight to the cleanup code.
153 ;
154 CMPIB,= 1,num,bn_mul_add_words_single_top
155 FLDD -184(%sp),fw ; (-56-128) load up w into fw (fw_h/fw_l)
156
157 ;
158 ; This loop is unrolled 2 times (64-byte aligned as well)
159 ;
160 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
161 ; two 32-bit mutiplies can be issued per cycle.
162 ;
163bn_mul_add_words_unroll2
164
165 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
166 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
167 LDD 0(r_ptr),rp_val ; rp[0]
168 LDD 8(r_ptr),rp_val_1 ; rp[1]
169
170 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
171 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = fht_1*fw_l
172 FSTD fm1,-16(%sp) ; -16(sp) = m1[0]
173 FSTD fm1_1,-48(%sp) ; -48(sp) = m1[1]
174
175 XMPYU flt_0,fw_h,fm ; m[0] = flt_0*fw_h
176 XMPYU flt_1,fw_h,fm_1 ; m[1] = flt_1*fw_h
177 FSTD fm,-8(%sp) ; -8(sp) = m[0]
178 FSTD fm_1,-40(%sp) ; -40(sp) = m[1]
179
180 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
181 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp_1 = fht_1*fw_h
182 FSTD ht_temp,-24(%sp) ; -24(sp) = ht_temp
183 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht_temp_1
184
185 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
186 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
187 FSTD lt_temp,-32(%sp) ; -32(sp) = lt_temp
188 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt_temp_1
189
190 LDD -8(%sp),m_0 ; m[0]
191 LDD -40(%sp),m_1 ; m[1]
192 LDD -16(%sp),m1_0 ; m1[0]
193 LDD -48(%sp),m1_1 ; m1[1]
194
195 LDD -24(%sp),ht_0 ; ht[0]
196 LDD -56(%sp),ht_1 ; ht[1]
197 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m[0] + m1[0];
198 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m[1] + m1[1];
199
200 LDD -32(%sp),lt_0
201 LDD -64(%sp),lt_1
202 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m[0] < m1[0])
203 ADD,L ht_0,top_overflow,ht_0 ; ht[0] += (1<<32)
204
205 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m[1] < m1[1])
206 ADD,L ht_1,top_overflow,ht_1 ; ht[1] += (1<<32)
207 EXTRD,U tmp_0,31,32,m_0 ; m[0]>>32
208 DEPD,Z tmp_0,31,32,m1_0 ; m1[0] = m[0]<<32
209
210 EXTRD,U tmp_1,31,32,m_1 ; m[1]>>32
211 DEPD,Z tmp_1,31,32,m1_1 ; m1[1] = m[1]<<32
212 ADD,L ht_0,m_0,ht_0 ; ht[0]+= (m[0]>>32)
213 ADD,L ht_1,m_1,ht_1 ; ht[1]+= (m[1]>>32)
214
215 ADD lt_0,m1_0,lt_0 ; lt[0] = lt[0]+m1[0];
216 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
217 ADD lt_1,m1_1,lt_1 ; lt[1] = lt[1]+m1[1];
218 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
219
220 ADD %ret1,lt_0,lt_0 ; lt[0] = lt[0] + c;
221 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
222 ADD lt_0,rp_val,lt_0 ; lt[0] = lt[0]+rp[0]
223 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
224
225 LDO -2(num),num ; num = num - 2;
226 ADD ht_0,lt_1,lt_1 ; lt[1] = lt[1] + ht_0 (c);
227 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
228 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
229
230 ADD lt_1,rp_val_1,lt_1 ; lt[1] = lt[1]+rp[1]
231 ADD,DC ht_1,%r0,%ret1 ; ht[1]++
232 LDO 16(a_ptr),a_ptr ; a_ptr += 2
233
234 STD lt_1,8(r_ptr) ; rp[1] = lt[1]
235 CMPIB,<= 2,num,bn_mul_add_words_unroll2 ; go again if more to do
236 LDO 16(r_ptr),r_ptr ; r_ptr += 2
237
238 CMPIB,=,N 0,num,bn_mul_add_words_exit ; are we done, or cleanup last one
239
240 ;
241 ; Top of loop aligned on 64-byte boundary
242 ;
243bn_mul_add_words_single_top
244 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
245 LDD 0(r_ptr),rp_val ; rp[0]
246 LDO 8(a_ptr),a_ptr ; a_ptr++
247 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
248 FSTD fm1,-16(%sp) ; -16(sp) = m1
249 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
250 FSTD fm,-8(%sp) ; -8(sp) = m
251 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
252 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
253 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
254 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
255
256 LDD -8(%sp),m_0
257 LDD -16(%sp),m1_0 ; m1 = temp1
258 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
259 LDD -24(%sp),ht_0
260 LDD -32(%sp),lt_0
261
262 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
263 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
264
265 EXTRD,U tmp_0,31,32,m_0 ; m>>32
266 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
267
268 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
269 ADD lt_0,m1_0,tmp_0 ; tmp_0 = lt+m1;
270 ADD,DC ht_0,%r0,ht_0 ; ht++
271 ADD %ret1,tmp_0,lt_0 ; lt = lt + c;
272 ADD,DC ht_0,%r0,ht_0 ; ht++
273 ADD lt_0,rp_val,lt_0 ; lt = lt+rp[0]
274 ADD,DC ht_0,%r0,%ret1 ; ht++
275 STD lt_0,0(r_ptr) ; rp[0] = lt
276
277bn_mul_add_words_exit
278 .EXIT
279
280 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
281 LDD -80(%sp),%r9 ; restore r9
282 LDD -88(%sp),%r8 ; restore r8
283 LDD -96(%sp),%r7 ; restore r7
284 LDD -104(%sp),%r6 ; restore r6
285 LDD -112(%sp),%r5 ; restore r5
286 LDD -120(%sp),%r4 ; restore r4
287 BVE (%rp)
288 LDD,MB -128(%sp),%r3 ; restore r3
289 .PROCEND ;in=23,24,25,26,29;out=28;
290
291;----------------------------------------------------------------------------
292;
293;BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
294;
295; arg0 = rp
296; arg1 = ap
297; arg3 = num
298; w on stack at -56(sp)
299
300bn_mul_words
301 .proc
302 .callinfo frame=128
303 .entry
304 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
305 .align 64
306
307 STD %r3,0(%sp) ; save r3
308 STD %r4,8(%sp) ; save r4
309 NOP
310 STD %r5,16(%sp) ; save r5
311
312 STD %r6,24(%sp) ; save r6
313 STD %r7,32(%sp) ; save r7
314 COPY %r0,%ret1 ; return 0 by default
315 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
316
317 CMPIB,>= 0,num,bn_mul_words_exit
318 LDO 128(%sp),%sp ; bump stack
319
320 ;
321 ; See if only 1 word to do, thus just do cleanup
322 ;
323 CMPIB,= 1,num,bn_mul_words_single_top
324 FLDD -184(%sp),fw ; (-56-128) load up w into fw (fw_h/fw_l)
325
326 ;
327 ; This loop is unrolled 2 times (64-byte aligned as well)
328 ;
329 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
330 ; two 32-bit mutiplies can be issued per cycle.
331 ;
332bn_mul_words_unroll2
333
334 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
335 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
336 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
337 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = ht*fw_l
338
339 FSTD fm1,-16(%sp) ; -16(sp) = m1
340 FSTD fm1_1,-48(%sp) ; -48(sp) = m1
341 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
342 XMPYU flt_1,fw_h,fm_1 ; m = lt*fw_h
343
344 FSTD fm,-8(%sp) ; -8(sp) = m
345 FSTD fm_1,-40(%sp) ; -40(sp) = m
346 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
347 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp = ht*fw_h
348
349 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
350 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht
351 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
352 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
353
354 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
355 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt
356 LDD -8(%sp),m_0
357 LDD -40(%sp),m_1
358
359 LDD -16(%sp),m1_0
360 LDD -48(%sp),m1_1
361 LDD -24(%sp),ht_0
362 LDD -56(%sp),ht_1
363
364 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m + m1;
365 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m + m1;
366 LDD -32(%sp),lt_0
367 LDD -64(%sp),lt_1
368
369 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m < m1)
370 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
371 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m < m1)
372 ADD,L ht_1,top_overflow,ht_1 ; ht += (1<<32)
373
374 EXTRD,U tmp_0,31,32,m_0 ; m>>32
375 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
376 EXTRD,U tmp_1,31,32,m_1 ; m>>32
377 DEPD,Z tmp_1,31,32,m1_1 ; m1 = m<<32
378
379 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
380 ADD,L ht_1,m_1,ht_1 ; ht+= (m>>32)
381 ADD lt_0,m1_0,lt_0 ; lt = lt+m1;
382 ADD,DC ht_0,%r0,ht_0 ; ht++
383
384 ADD lt_1,m1_1,lt_1 ; lt = lt+m1;
385 ADD,DC ht_1,%r0,ht_1 ; ht++
386 ADD %ret1,lt_0,lt_0 ; lt = lt + c (ret1);
387 ADD,DC ht_0,%r0,ht_0 ; ht++
388
389 ADD ht_0,lt_1,lt_1 ; lt = lt + c (ht_0)
390 ADD,DC ht_1,%r0,ht_1 ; ht++
391 STD lt_0,0(r_ptr) ; rp[0] = lt
392 STD lt_1,8(r_ptr) ; rp[1] = lt
393
394 COPY ht_1,%ret1 ; carry = ht
395 LDO -2(num),num ; num = num - 2;
396 LDO 16(a_ptr),a_ptr ; ap += 2
397 CMPIB,<= 2,num,bn_mul_words_unroll2
398 LDO 16(r_ptr),r_ptr ; rp++
399
400 CMPIB,=,N 0,num,bn_mul_words_exit ; are we done?
401
402 ;
403 ; Top of loop aligned on 64-byte boundary
404 ;
405bn_mul_words_single_top
406 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
407
408 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
409 FSTD fm1,-16(%sp) ; -16(sp) = m1
410 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
411 FSTD fm,-8(%sp) ; -8(sp) = m
412 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
413 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
414 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
415 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
416
417 LDD -8(%sp),m_0
418 LDD -16(%sp),m1_0
419 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
420 LDD -24(%sp),ht_0
421 LDD -32(%sp),lt_0
422
423 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
424 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
425
426 EXTRD,U tmp_0,31,32,m_0 ; m>>32
427 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
428
429 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
430 ADD lt_0,m1_0,lt_0 ; lt= lt+m1;
431 ADD,DC ht_0,%r0,ht_0 ; ht++
432
433 ADD %ret1,lt_0,lt_0 ; lt = lt + c;
434 ADD,DC ht_0,%r0,ht_0 ; ht++
435
436 COPY ht_0,%ret1 ; copy carry
437 STD lt_0,0(r_ptr) ; rp[0] = lt
438
439bn_mul_words_exit
440 .EXIT
441 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
442 LDD -96(%sp),%r7 ; restore r7
443 LDD -104(%sp),%r6 ; restore r6
444 LDD -112(%sp),%r5 ; restore r5
445 LDD -120(%sp),%r4 ; restore r4
446 BVE (%rp)
447 LDD,MB -128(%sp),%r3 ; restore r3
448 .PROCEND
449
450;----------------------------------------------------------------------------
451;
452;void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
453;
454; arg0 = rp
455; arg1 = ap
456; arg2 = num
457;
458
459bn_sqr_words
460 .proc
461 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
462 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
463 .entry
464 .align 64
465
466 STD %r3,0(%sp) ; save r3
467 STD %r4,8(%sp) ; save r4
468 NOP
469 STD %r5,16(%sp) ; save r5
470
471 CMPIB,>= 0,num,bn_sqr_words_exit
472 LDO 128(%sp),%sp ; bump stack
473
474 ;
475 ; If only 1, the goto straight to cleanup
476 ;
477 CMPIB,= 1,num,bn_sqr_words_single_top
478 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
479
480 ;
481 ; This loop is unrolled 2 times (64-byte aligned as well)
482 ;
483
484bn_sqr_words_unroll2
485 FLDD 0(a_ptr),t_float_0 ; a[0]
486 FLDD 8(a_ptr),t_float_1 ; a[1]
487 XMPYU fht_0,flt_0,fm ; m[0]
488 XMPYU fht_1,flt_1,fm_1 ; m[1]
489
490 FSTD fm,-24(%sp) ; store m[0]
491 FSTD fm_1,-56(%sp) ; store m[1]
492 XMPYU flt_0,flt_0,lt_temp ; lt[0]
493 XMPYU flt_1,flt_1,lt_temp_1 ; lt[1]
494
495 FSTD lt_temp,-16(%sp) ; store lt[0]
496 FSTD lt_temp_1,-48(%sp) ; store lt[1]
497 XMPYU fht_0,fht_0,ht_temp ; ht[0]
498 XMPYU fht_1,fht_1,ht_temp_1 ; ht[1]
499
500 FSTD ht_temp,-8(%sp) ; store ht[0]
501 FSTD ht_temp_1,-40(%sp) ; store ht[1]
502 LDD -24(%sp),m_0
503 LDD -56(%sp),m_1
504
505 AND m_0,high_mask,tmp_0 ; m[0] & Mask
506 AND m_1,high_mask,tmp_1 ; m[1] & Mask
507 DEPD,Z m_0,30,31,m_0 ; m[0] << 32+1
508 DEPD,Z m_1,30,31,m_1 ; m[1] << 32+1
509
510 LDD -16(%sp),lt_0
511 LDD -48(%sp),lt_1
512 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m[0]&Mask >> 32-1
513 EXTRD,U tmp_1,32,33,tmp_1 ; tmp_1 = m[1]&Mask >> 32-1
514
515 LDD -8(%sp),ht_0
516 LDD -40(%sp),ht_1
517 ADD,L ht_0,tmp_0,ht_0 ; ht[0] += tmp_0
518 ADD,L ht_1,tmp_1,ht_1 ; ht[1] += tmp_1
519
520 ADD lt_0,m_0,lt_0 ; lt = lt+m
521 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
522 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
523 STD ht_0,8(r_ptr) ; rp[1] = ht[1]
524
525 ADD lt_1,m_1,lt_1 ; lt = lt+m
526 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
527 STD lt_1,16(r_ptr) ; rp[2] = lt[1]
528 STD ht_1,24(r_ptr) ; rp[3] = ht[1]
529
530 LDO -2(num),num ; num = num - 2;
531 LDO 16(a_ptr),a_ptr ; ap += 2
532 CMPIB,<= 2,num,bn_sqr_words_unroll2
533 LDO 32(r_ptr),r_ptr ; rp += 4
534
535 CMPIB,=,N 0,num,bn_sqr_words_exit ; are we done?
536
537 ;
538 ; Top of loop aligned on 64-byte boundary
539 ;
540bn_sqr_words_single_top
541 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
542
543 XMPYU fht_0,flt_0,fm ; m
544 FSTD fm,-24(%sp) ; store m
545
546 XMPYU flt_0,flt_0,lt_temp ; lt
547 FSTD lt_temp,-16(%sp) ; store lt
548
549 XMPYU fht_0,fht_0,ht_temp ; ht
550 FSTD ht_temp,-8(%sp) ; store ht
551
552 LDD -24(%sp),m_0 ; load m
553 AND m_0,high_mask,tmp_0 ; m & Mask
554 DEPD,Z m_0,30,31,m_0 ; m << 32+1
555 LDD -16(%sp),lt_0 ; lt
556
557 LDD -8(%sp),ht_0 ; ht
558 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m&Mask >> 32-1
559 ADD m_0,lt_0,lt_0 ; lt = lt+m
560 ADD,L ht_0,tmp_0,ht_0 ; ht += tmp_0
561 ADD,DC ht_0,%r0,ht_0 ; ht++
562
563 STD lt_0,0(r_ptr) ; rp[0] = lt
564 STD ht_0,8(r_ptr) ; rp[1] = ht
565
566bn_sqr_words_exit
567 .EXIT
568 LDD -112(%sp),%r5 ; restore r5
569 LDD -120(%sp),%r4 ; restore r4
570 BVE (%rp)
571 LDD,MB -128(%sp),%r3
572 .PROCEND ;in=23,24,25,26,29;out=28;
573
574
575;----------------------------------------------------------------------------
576;
577;BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
578;
579; arg0 = rp
580; arg1 = ap
581; arg2 = bp
582; arg3 = n
583
584t .reg %r22
585b .reg %r21
586l .reg %r20
587
588bn_add_words
589 .proc
590 .entry
591 .callinfo
592 .EXPORT bn_add_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
593 .align 64
594
595 CMPIB,>= 0,n,bn_add_words_exit
596 COPY %r0,%ret1 ; return 0 by default
597
598 ;
599 ; If 2 or more numbers do the loop
600 ;
601 CMPIB,= 1,n,bn_add_words_single_top
602 NOP
603
604 ;
605 ; This loop is unrolled 2 times (64-byte aligned as well)
606 ;
607bn_add_words_unroll2
608 LDD 0(a_ptr),t
609 LDD 0(b_ptr),b
610 ADD t,%ret1,t ; t = t+c;
611 ADD,DC %r0,%r0,%ret1 ; set c to carry
612 ADD t,b,l ; l = t + b[0]
613 ADD,DC %ret1,%r0,%ret1 ; c+= carry
614 STD l,0(r_ptr)
615
616 LDD 8(a_ptr),t
617 LDD 8(b_ptr),b
618 ADD t,%ret1,t ; t = t+c;
619 ADD,DC %r0,%r0,%ret1 ; set c to carry
620 ADD t,b,l ; l = t + b[0]
621 ADD,DC %ret1,%r0,%ret1 ; c+= carry
622 STD l,8(r_ptr)
623
624 LDO -2(n),n
625 LDO 16(a_ptr),a_ptr
626 LDO 16(b_ptr),b_ptr
627
628 CMPIB,<= 2,n,bn_add_words_unroll2
629 LDO 16(r_ptr),r_ptr
630
631 CMPIB,=,N 0,n,bn_add_words_exit ; are we done?
632
633bn_add_words_single_top
634 LDD 0(a_ptr),t
635 LDD 0(b_ptr),b
636
637 ADD t,%ret1,t ; t = t+c;
638 ADD,DC %r0,%r0,%ret1 ; set c to carry (could use CMPCLR??)
639 ADD t,b,l ; l = t + b[0]
640 ADD,DC %ret1,%r0,%ret1 ; c+= carry
641 STD l,0(r_ptr)
642
643bn_add_words_exit
644 .EXIT
645 BVE (%rp)
646 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
647 .PROCEND ;in=23,24,25,26,29;out=28;
648
649;----------------------------------------------------------------------------
650;
651;BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
652;
653; arg0 = rp
654; arg1 = ap
655; arg2 = bp
656; arg3 = n
657
658t1 .reg %r22
659t2 .reg %r21
660sub_tmp1 .reg %r20
661sub_tmp2 .reg %r19
662
663
664bn_sub_words
665 .proc
666 .callinfo
667 .EXPORT bn_sub_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
668 .entry
669 .align 64
670
671 CMPIB,>= 0,n,bn_sub_words_exit
672 COPY %r0,%ret1 ; return 0 by default
673
674 ;
675 ; If 2 or more numbers do the loop
676 ;
677 CMPIB,= 1,n,bn_sub_words_single_top
678 NOP
679
680 ;
681 ; This loop is unrolled 2 times (64-byte aligned as well)
682 ;
683bn_sub_words_unroll2
684 LDD 0(a_ptr),t1
685 LDD 0(b_ptr),t2
686 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
687 SUB sub_tmp1,%ret1,sub_tmp1 ; t3 = t3- c;
688
689 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
690 LDO 1(%r0),sub_tmp2
691
692 CMPCLR,*= t1,t2,%r0
693 COPY sub_tmp2,%ret1
694 STD sub_tmp1,0(r_ptr)
695
696 LDD 8(a_ptr),t1
697 LDD 8(b_ptr),t2
698 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
699 SUB sub_tmp1,%ret1,sub_tmp1 ; t3 = t3- c;
700 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
701 LDO 1(%r0),sub_tmp2
702
703 CMPCLR,*= t1,t2,%r0
704 COPY sub_tmp2,%ret1
705 STD sub_tmp1,8(r_ptr)
706
707 LDO -2(n),n
708 LDO 16(a_ptr),a_ptr
709 LDO 16(b_ptr),b_ptr
710
711 CMPIB,<= 2,n,bn_sub_words_unroll2
712 LDO 16(r_ptr),r_ptr
713
714 CMPIB,=,N 0,n,bn_sub_words_exit ; are we done?
715
716bn_sub_words_single_top
717 LDD 0(a_ptr),t1
718 LDD 0(b_ptr),t2
719 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
720 SUB sub_tmp1,%ret1,sub_tmp1 ; t3 = t3- c;
721 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
722 LDO 1(%r0),sub_tmp2
723
724 CMPCLR,*= t1,t2,%r0
725 COPY sub_tmp2,%ret1
726
727 STD sub_tmp1,0(r_ptr)
728
729bn_sub_words_exit
730 .EXIT
731 BVE (%rp)
732 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
733 .PROCEND ;in=23,24,25,26,29;out=28;
734
735;------------------------------------------------------------------------------
736;
737; unsigned long bn_div_words(unsigned long h, unsigned long l, unsigned long d)
738;
739; arg0 = h
740; arg1 = l
741; arg2 = d
742;
743; This is mainly just output from the HP C compiler.
744;
745;------------------------------------------------------------------------------
746bn_div_words
747 .PROC
748 .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR,LONG_RETURN
749 .IMPORT BN_num_bits_word,CODE
750 ;--- not PIC .IMPORT __iob,DATA
751 ;--- not PIC .IMPORT fprintf,CODE
752 .IMPORT abort,CODE
753 .IMPORT $$div2U,MILLICODE
754 .CALLINFO CALLER,FRAME=144,ENTRY_GR=%r9,SAVE_RP,ARGS_SAVED,ORDERING_AWARE
755 .ENTRY
756 STW %r2,-20(%r30) ;offset 0x8ec
757 STW,MA %r3,192(%r30) ;offset 0x8f0
758 STW %r4,-188(%r30) ;offset 0x8f4
759 DEPD %r5,31,32,%r6 ;offset 0x8f8
760 STD %r6,-184(%r30) ;offset 0x8fc
761 DEPD %r7,31,32,%r8 ;offset 0x900
762 STD %r8,-176(%r30) ;offset 0x904
763 STW %r9,-168(%r30) ;offset 0x908
764 LDD -248(%r30),%r3 ;offset 0x90c
765 COPY %r26,%r4 ;offset 0x910
766 COPY %r24,%r5 ;offset 0x914
767 DEPD %r25,31,32,%r4 ;offset 0x918
768 CMPB,*<> %r3,%r0,$0006000C ;offset 0x91c
769 DEPD %r23,31,32,%r5 ;offset 0x920
770 MOVIB,TR -1,%r29,$00060002 ;offset 0x924
771 EXTRD,U %r29,31,32,%r28 ;offset 0x928
772$0006002A
773 LDO -1(%r29),%r29 ;offset 0x92c
774 SUB %r23,%r7,%r23 ;offset 0x930
775$00060024
776 SUB %r4,%r31,%r25 ;offset 0x934
777 AND %r25,%r19,%r26 ;offset 0x938
778 CMPB,*<>,N %r0,%r26,$00060046 ;offset 0x93c
779 DEPD,Z %r25,31,32,%r20 ;offset 0x940
780 OR %r20,%r24,%r21 ;offset 0x944
781 CMPB,*<<,N %r21,%r23,$0006002A ;offset 0x948
782 SUB %r31,%r2,%r31 ;offset 0x94c
783$00060046
784$0006002E
785 DEPD,Z %r23,31,32,%r25 ;offset 0x950
786 EXTRD,U %r23,31,32,%r26 ;offset 0x954
787 AND %r25,%r19,%r24 ;offset 0x958
788 ADD,L %r31,%r26,%r31 ;offset 0x95c
789 CMPCLR,*>>= %r5,%r24,%r0 ;offset 0x960
790 LDO 1(%r31),%r31 ;offset 0x964
791$00060032
792 CMPB,*<<=,N %r31,%r4,$00060036 ;offset 0x968
793 LDO -1(%r29),%r29 ;offset 0x96c
794 ADD,L %r4,%r3,%r4 ;offset 0x970
795$00060036
796 ADDIB,=,N -1,%r8,$D0 ;offset 0x974
797 SUB %r5,%r24,%r28 ;offset 0x978
798$0006003A
799 SUB %r4,%r31,%r24 ;offset 0x97c
800 SHRPD %r24,%r28,32,%r4 ;offset 0x980
801 DEPD,Z %r29,31,32,%r9 ;offset 0x984
802 DEPD,Z %r28,31,32,%r5 ;offset 0x988
803$0006001C
804 EXTRD,U %r4,31,32,%r31 ;offset 0x98c
805 CMPB,*<>,N %r31,%r2,$00060020 ;offset 0x990
806 MOVB,TR %r6,%r29,$D1 ;offset 0x994
807 STD %r29,-152(%r30) ;offset 0x998
808$0006000C
809 EXTRD,U %r3,31,32,%r25 ;offset 0x99c
810 COPY %r3,%r26 ;offset 0x9a0
811 EXTRD,U %r3,31,32,%r9 ;offset 0x9a4
812 EXTRD,U %r4,31,32,%r8 ;offset 0x9a8
813 .CALL ARGW0=GR,ARGW1=GR,RTNVAL=GR ;in=25,26;out=28;
814 B,L BN_num_bits_word,%r2 ;offset 0x9ac
815 EXTRD,U %r5,31,32,%r7 ;offset 0x9b0
816 LDI 64,%r20 ;offset 0x9b4
817 DEPD %r7,31,32,%r5 ;offset 0x9b8
818 DEPD %r8,31,32,%r4 ;offset 0x9bc
819 DEPD %r9,31,32,%r3 ;offset 0x9c0
820 CMPB,= %r28,%r20,$00060012 ;offset 0x9c4
821 COPY %r28,%r24 ;offset 0x9c8
822 MTSARCM %r24 ;offset 0x9cc
823 DEPDI,Z -1,%sar,1,%r19 ;offset 0x9d0
824 CMPB,*>>,N %r4,%r19,$D2 ;offset 0x9d4
825$00060012
826 SUBI 64,%r24,%r31 ;offset 0x9d8
827 CMPCLR,*<< %r4,%r3,%r0 ;offset 0x9dc
828 SUB %r4,%r3,%r4 ;offset 0x9e0
829$00060016
830 CMPB,= %r31,%r0,$0006001A ;offset 0x9e4
831 COPY %r0,%r9 ;offset 0x9e8
832 MTSARCM %r31 ;offset 0x9ec
833 DEPD,Z %r3,%sar,64,%r3 ;offset 0x9f0
834 SUBI 64,%r31,%r26 ;offset 0x9f4
835 MTSAR %r26 ;offset 0x9f8
836 SHRPD %r4,%r5,%sar,%r4 ;offset 0x9fc
837 MTSARCM %r31 ;offset 0xa00
838 DEPD,Z %r5,%sar,64,%r5 ;offset 0xa04
839$0006001A
840 DEPDI,Z -1,31,32,%r19 ;offset 0xa08
841 AND %r3,%r19,%r29 ;offset 0xa0c
842 EXTRD,U %r29,31,32,%r2 ;offset 0xa10
843 DEPDI,Z -1,63,32,%r6 ;offset 0xa14
844 MOVIB,TR 2,%r8,$0006001C ;offset 0xa18
845 EXTRD,U %r3,63,32,%r7 ;offset 0xa1c
846$D2
847 ;--- not PIC ADDIL LR'__iob-$global$,%r27,%r1 ;offset 0xa20
848 ;--- not PIC LDIL LR'C$7,%r21 ;offset 0xa24
849 ;--- not PIC LDO RR'__iob-$global$+32(%r1),%r26 ;offset 0xa28
850 ;--- not PIC .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR ;in=24,25,26;out=28;
851 ;--- not PIC B,L fprintf,%r2 ;offset 0xa2c
852 ;--- not PIC LDO RR'C$7(%r21),%r25 ;offset 0xa30
853 .CALL ;
854 B,L abort,%r2 ;offset 0xa34
855 NOP ;offset 0xa38
856 B $D3 ;offset 0xa3c
857 LDW -212(%r30),%r2 ;offset 0xa40
858$00060020
859 COPY %r4,%r26 ;offset 0xa44
860 EXTRD,U %r4,31,32,%r25 ;offset 0xa48
861 COPY %r2,%r24 ;offset 0xa4c
862 .CALL ;in=23,24,25,26;out=20,21,22,28,29; (MILLICALL)
863 B,L $$div2U,%r31 ;offset 0xa50
864 EXTRD,U %r2,31,32,%r23 ;offset 0xa54
865 DEPD %r28,31,32,%r29 ;offset 0xa58
866$00060022
867 STD %r29,-152(%r30) ;offset 0xa5c
868$D1
869 AND %r5,%r19,%r24 ;offset 0xa60
870 EXTRD,U %r24,31,32,%r24 ;offset 0xa64
871 STW %r2,-160(%r30) ;offset 0xa68
872 STW %r7,-128(%r30) ;offset 0xa6c
873 FLDD -152(%r30),%fr4 ;offset 0xa70
874 FLDD -152(%r30),%fr7 ;offset 0xa74
875 FLDW -160(%r30),%fr8L ;offset 0xa78
876 FLDW -128(%r30),%fr5L ;offset 0xa7c
877 XMPYU %fr8L,%fr7L,%fr10 ;offset 0xa80
878 FSTD %fr10,-136(%r30) ;offset 0xa84
879 XMPYU %fr8L,%fr7R,%fr22 ;offset 0xa88
880 FSTD %fr22,-144(%r30) ;offset 0xa8c
881 XMPYU %fr5L,%fr4L,%fr11 ;offset 0xa90
882 XMPYU %fr5L,%fr4R,%fr23 ;offset 0xa94
883 FSTD %fr11,-112(%r30) ;offset 0xa98
884 FSTD %fr23,-120(%r30) ;offset 0xa9c
885 LDD -136(%r30),%r28 ;offset 0xaa0
886 DEPD,Z %r28,31,32,%r31 ;offset 0xaa4
887 LDD -144(%r30),%r20 ;offset 0xaa8
888 ADD,L %r20,%r31,%r31 ;offset 0xaac
889 LDD -112(%r30),%r22 ;offset 0xab0
890 DEPD,Z %r22,31,32,%r22 ;offset 0xab4
891 LDD -120(%r30),%r21 ;offset 0xab8
892 B $00060024 ;offset 0xabc
893 ADD,L %r21,%r22,%r23 ;offset 0xac0
894$D0
895 OR %r9,%r29,%r29 ;offset 0xac4
896$00060040
897 EXTRD,U %r29,31,32,%r28 ;offset 0xac8
898$00060002
899$L2
900 LDW -212(%r30),%r2 ;offset 0xacc
901$D3
902 LDW -168(%r30),%r9 ;offset 0xad0
903 LDD -176(%r30),%r8 ;offset 0xad4
904 EXTRD,U %r8,31,32,%r7 ;offset 0xad8
905 LDD -184(%r30),%r6 ;offset 0xadc
906 EXTRD,U %r6,31,32,%r5 ;offset 0xae0
907 LDW -188(%r30),%r4 ;offset 0xae4
908 BVE (%r2) ;offset 0xae8
909 .EXIT
910 LDW,MB -192(%r30),%r3 ;offset 0xaec
911 .PROCEND ;in=23,25;out=28,29;fpin=105,107;
912
913
914
915
916;----------------------------------------------------------------------------
917;
918; Registers to hold 64-bit values to manipulate. The "L" part
919; of the register corresponds to the upper 32-bits, while the "R"
920; part corresponds to the lower 32-bits
921;
922; Note, that when using b6 and b7, the code must save these before
923; using them because they are callee save registers
924;
925;
926; Floating point registers to use to save values that
927; are manipulated. These don't collide with ftemp1-6 and
928; are all caller save registers
929;
930a0 .reg %fr22
931a0L .reg %fr22L
932a0R .reg %fr22R
933
934a1 .reg %fr23
935a1L .reg %fr23L
936a1R .reg %fr23R
937
938a2 .reg %fr24
939a2L .reg %fr24L
940a2R .reg %fr24R
941
942a3 .reg %fr25
943a3L .reg %fr25L
944a3R .reg %fr25R
945
946a4 .reg %fr26
947a4L .reg %fr26L
948a4R .reg %fr26R
949
950a5 .reg %fr27
951a5L .reg %fr27L
952a5R .reg %fr27R
953
954a6 .reg %fr28
955a6L .reg %fr28L
956a6R .reg %fr28R
957
958a7 .reg %fr29
959a7L .reg %fr29L
960a7R .reg %fr29R
961
962b0 .reg %fr30
963b0L .reg %fr30L
964b0R .reg %fr30R
965
966b1 .reg %fr31
967b1L .reg %fr31L
968b1R .reg %fr31R
969
970;
971; Temporary floating point variables, these are all caller save
972; registers
973;
974ftemp1 .reg %fr4
975ftemp2 .reg %fr5
976ftemp3 .reg %fr6
977ftemp4 .reg %fr7
978
979;
980; The B set of registers when used.
981;
982
983b2 .reg %fr8
984b2L .reg %fr8L
985b2R .reg %fr8R
986
987b3 .reg %fr9
988b3L .reg %fr9L
989b3R .reg %fr9R
990
991b4 .reg %fr10
992b4L .reg %fr10L
993b4R .reg %fr10R
994
995b5 .reg %fr11
996b5L .reg %fr11L
997b5R .reg %fr11R
998
999b6 .reg %fr12
1000b6L .reg %fr12L
1001b6R .reg %fr12R
1002
1003b7 .reg %fr13
1004b7L .reg %fr13L
1005b7R .reg %fr13R
1006
1007c1 .reg %r21 ; only reg
1008temp1 .reg %r20 ; only reg
1009temp2 .reg %r19 ; only reg
1010temp3 .reg %r31 ; only reg
1011
1012m1 .reg %r28
1013c2 .reg %r23
1014high_one .reg %r1
1015ht .reg %r6
1016lt .reg %r5
1017m .reg %r4
1018c3 .reg %r3
1019
1020SQR_ADD_C .macro A0L,A0R,C1,C2,C3
1021 XMPYU A0L,A0R,ftemp1 ; m
1022 FSTD ftemp1,-24(%sp) ; store m
1023
1024 XMPYU A0R,A0R,ftemp2 ; lt
1025 FSTD ftemp2,-16(%sp) ; store lt
1026
1027 XMPYU A0L,A0L,ftemp3 ; ht
1028 FSTD ftemp3,-8(%sp) ; store ht
1029
1030 LDD -24(%sp),m ; load m
1031 AND m,high_mask,temp2 ; m & Mask
1032 DEPD,Z m,30,31,temp3 ; m << 32+1
1033 LDD -16(%sp),lt ; lt
1034
1035 LDD -8(%sp),ht ; ht
1036 EXTRD,U temp2,32,33,temp1 ; temp1 = m&Mask >> 32-1
1037 ADD temp3,lt,lt ; lt = lt+m
1038 ADD,L ht,temp1,ht ; ht += temp1
1039 ADD,DC ht,%r0,ht ; ht++
1040
1041 ADD C1,lt,C1 ; c1=c1+lt
1042 ADD,DC ht,%r0,ht ; ht++
1043
1044 ADD C2,ht,C2 ; c2=c2+ht
1045 ADD,DC C3,%r0,C3 ; c3++
1046.endm
1047
1048SQR_ADD_C2 .macro A0L,A0R,A1L,A1R,C1,C2,C3
1049 XMPYU A0L,A1R,ftemp1 ; m1 = bl*ht
1050 FSTD ftemp1,-16(%sp) ;
1051 XMPYU A0R,A1L,ftemp2 ; m = bh*lt
1052 FSTD ftemp2,-8(%sp) ;
1053 XMPYU A0R,A1R,ftemp3 ; lt = bl*lt
1054 FSTD ftemp3,-32(%sp)
1055 XMPYU A0L,A1L,ftemp4 ; ht = bh*ht
1056 FSTD ftemp4,-24(%sp) ;
1057
1058 LDD -8(%sp),m ; r21 = m
1059 LDD -16(%sp),m1 ; r19 = m1
1060 ADD,L m,m1,m ; m+m1
1061
1062 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1063 LDD -24(%sp),ht ; r24 = ht
1064
1065 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1066 ADD,L ht,high_one,ht ; ht+=high_one
1067
1068 EXTRD,U m,31,32,temp1 ; m >> 32
1069 LDD -32(%sp),lt ; lt
1070 ADD,L ht,temp1,ht ; ht+= m>>32
1071 ADD lt,temp3,lt ; lt = lt+m1
1072 ADD,DC ht,%r0,ht ; ht++
1073
1074 ADD ht,ht,ht ; ht=ht+ht;
1075 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1076
1077 ADD lt,lt,lt ; lt=lt+lt;
1078 ADD,DC ht,%r0,ht ; add in carry (ht++)
1079
1080 ADD C1,lt,C1 ; c1=c1+lt
1081 ADD,DC,*NUV ht,%r0,ht ; add in carry (ht++)
1082 LDO 1(C3),C3 ; bump c3 if overflow,nullify otherwise
1083
1084 ADD C2,ht,C2 ; c2 = c2 + ht
1085 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1086.endm
1087
1088;
1089;void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
1090; arg0 = r_ptr
1091; arg1 = a_ptr
1092;
1093
1094bn_sqr_comba8
1095 .PROC
1096 .CALLINFO FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1097 .EXPORT bn_sqr_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1098 .ENTRY
1099 .align 64
1100
1101 STD %r3,0(%sp) ; save r3
1102 STD %r4,8(%sp) ; save r4
1103 STD %r5,16(%sp) ; save r5
1104 STD %r6,24(%sp) ; save r6
1105
1106 ;
1107 ; Zero out carries
1108 ;
1109 COPY %r0,c1
1110 COPY %r0,c2
1111 COPY %r0,c3
1112
1113 LDO 128(%sp),%sp ; bump stack
1114 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1115 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1116
1117 ;
1118 ; Load up all of the values we are going to use
1119 ;
1120 FLDD 0(a_ptr),a0
1121 FLDD 8(a_ptr),a1
1122 FLDD 16(a_ptr),a2
1123 FLDD 24(a_ptr),a3
1124 FLDD 32(a_ptr),a4
1125 FLDD 40(a_ptr),a5
1126 FLDD 48(a_ptr),a6
1127 FLDD 56(a_ptr),a7
1128
1129 SQR_ADD_C a0L,a0R,c1,c2,c3
1130 STD c1,0(r_ptr) ; r[0] = c1;
1131 COPY %r0,c1
1132
1133 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1134 STD c2,8(r_ptr) ; r[1] = c2;
1135 COPY %r0,c2
1136
1137 SQR_ADD_C a1L,a1R,c3,c1,c2
1138 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1139 STD c3,16(r_ptr) ; r[2] = c3;
1140 COPY %r0,c3
1141
1142 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1143 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1144 STD c1,24(r_ptr) ; r[3] = c1;
1145 COPY %r0,c1
1146
1147 SQR_ADD_C a2L,a2R,c2,c3,c1
1148 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1149 SQR_ADD_C2 a4L,a4R,a0L,a0R,c2,c3,c1
1150 STD c2,32(r_ptr) ; r[4] = c2;
1151 COPY %r0,c2
1152
1153 SQR_ADD_C2 a5L,a5R,a0L,a0R,c3,c1,c2
1154 SQR_ADD_C2 a4L,a4R,a1L,a1R,c3,c1,c2
1155 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1156 STD c3,40(r_ptr) ; r[5] = c3;
1157 COPY %r0,c3
1158
1159 SQR_ADD_C a3L,a3R,c1,c2,c3
1160 SQR_ADD_C2 a4L,a4R,a2L,a2R,c1,c2,c3
1161 SQR_ADD_C2 a5L,a5R,a1L,a1R,c1,c2,c3
1162 SQR_ADD_C2 a6L,a6R,a0L,a0R,c1,c2,c3
1163 STD c1,48(r_ptr) ; r[6] = c1;
1164 COPY %r0,c1
1165
1166 SQR_ADD_C2 a7L,a7R,a0L,a0R,c2,c3,c1
1167 SQR_ADD_C2 a6L,a6R,a1L,a1R,c2,c3,c1
1168 SQR_ADD_C2 a5L,a5R,a2L,a2R,c2,c3,c1
1169 SQR_ADD_C2 a4L,a4R,a3L,a3R,c2,c3,c1
1170 STD c2,56(r_ptr) ; r[7] = c2;
1171 COPY %r0,c2
1172
1173 SQR_ADD_C a4L,a4R,c3,c1,c2
1174 SQR_ADD_C2 a5L,a5R,a3L,a3R,c3,c1,c2
1175 SQR_ADD_C2 a6L,a6R,a2L,a2R,c3,c1,c2
1176 SQR_ADD_C2 a7L,a7R,a1L,a1R,c3,c1,c2
1177 STD c3,64(r_ptr) ; r[8] = c3;
1178 COPY %r0,c3
1179
1180 SQR_ADD_C2 a7L,a7R,a2L,a2R,c1,c2,c3
1181 SQR_ADD_C2 a6L,a6R,a3L,a3R,c1,c2,c3
1182 SQR_ADD_C2 a5L,a5R,a4L,a4R,c1,c2,c3
1183 STD c1,72(r_ptr) ; r[9] = c1;
1184 COPY %r0,c1
1185
1186 SQR_ADD_C a5L,a5R,c2,c3,c1
1187 SQR_ADD_C2 a6L,a6R,a4L,a4R,c2,c3,c1
1188 SQR_ADD_C2 a7L,a7R,a3L,a3R,c2,c3,c1
1189 STD c2,80(r_ptr) ; r[10] = c2;
1190 COPY %r0,c2
1191
1192 SQR_ADD_C2 a7L,a7R,a4L,a4R,c3,c1,c2
1193 SQR_ADD_C2 a6L,a6R,a5L,a5R,c3,c1,c2
1194 STD c3,88(r_ptr) ; r[11] = c3;
1195 COPY %r0,c3
1196
1197 SQR_ADD_C a6L,a6R,c1,c2,c3
1198 SQR_ADD_C2 a7L,a7R,a5L,a5R,c1,c2,c3
1199 STD c1,96(r_ptr) ; r[12] = c1;
1200 COPY %r0,c1
1201
1202 SQR_ADD_C2 a7L,a7R,a6L,a6R,c2,c3,c1
1203 STD c2,104(r_ptr) ; r[13] = c2;
1204 COPY %r0,c2
1205
1206 SQR_ADD_C a7L,a7R,c3,c1,c2
1207 STD c3, 112(r_ptr) ; r[14] = c3
1208 STD c1, 120(r_ptr) ; r[15] = c1
1209
1210 .EXIT
1211 LDD -104(%sp),%r6 ; restore r6
1212 LDD -112(%sp),%r5 ; restore r5
1213 LDD -120(%sp),%r4 ; restore r4
1214 BVE (%rp)
1215 LDD,MB -128(%sp),%r3
1216
1217 .PROCEND
1218
1219;-----------------------------------------------------------------------------
1220;
1221;void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1222; arg0 = r_ptr
1223; arg1 = a_ptr
1224;
1225
1226bn_sqr_comba4
1227 .proc
1228 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1229 .EXPORT bn_sqr_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1230 .entry
1231 .align 64
1232 STD %r3,0(%sp) ; save r3
1233 STD %r4,8(%sp) ; save r4
1234 STD %r5,16(%sp) ; save r5
1235 STD %r6,24(%sp) ; save r6
1236
1237 ;
1238 ; Zero out carries
1239 ;
1240 COPY %r0,c1
1241 COPY %r0,c2
1242 COPY %r0,c3
1243
1244 LDO 128(%sp),%sp ; bump stack
1245 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1246 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1247
1248 ;
1249 ; Load up all of the values we are going to use
1250 ;
1251 FLDD 0(a_ptr),a0
1252 FLDD 8(a_ptr),a1
1253 FLDD 16(a_ptr),a2
1254 FLDD 24(a_ptr),a3
1255 FLDD 32(a_ptr),a4
1256 FLDD 40(a_ptr),a5
1257 FLDD 48(a_ptr),a6
1258 FLDD 56(a_ptr),a7
1259
1260 SQR_ADD_C a0L,a0R,c1,c2,c3
1261
1262 STD c1,0(r_ptr) ; r[0] = c1;
1263 COPY %r0,c1
1264
1265 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1266
1267 STD c2,8(r_ptr) ; r[1] = c2;
1268 COPY %r0,c2
1269
1270 SQR_ADD_C a1L,a1R,c3,c1,c2
1271 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1272
1273 STD c3,16(r_ptr) ; r[2] = c3;
1274 COPY %r0,c3
1275
1276 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1277 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1278
1279 STD c1,24(r_ptr) ; r[3] = c1;
1280 COPY %r0,c1
1281
1282 SQR_ADD_C a2L,a2R,c2,c3,c1
1283 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1284
1285 STD c2,32(r_ptr) ; r[4] = c2;
1286 COPY %r0,c2
1287
1288 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1289 STD c3,40(r_ptr) ; r[5] = c3;
1290 COPY %r0,c3
1291
1292 SQR_ADD_C a3L,a3R,c1,c2,c3
1293 STD c1,48(r_ptr) ; r[6] = c1;
1294 STD c2,56(r_ptr) ; r[7] = c2;
1295
1296 .EXIT
1297 LDD -104(%sp),%r6 ; restore r6
1298 LDD -112(%sp),%r5 ; restore r5
1299 LDD -120(%sp),%r4 ; restore r4
1300 BVE (%rp)
1301 LDD,MB -128(%sp),%r3
1302
1303 .PROCEND
1304
1305
1306;---------------------------------------------------------------------------
1307
1308MUL_ADD_C .macro A0L,A0R,B0L,B0R,C1,C2,C3
1309 XMPYU A0L,B0R,ftemp1 ; m1 = bl*ht
1310 FSTD ftemp1,-16(%sp) ;
1311 XMPYU A0R,B0L,ftemp2 ; m = bh*lt
1312 FSTD ftemp2,-8(%sp) ;
1313 XMPYU A0R,B0R,ftemp3 ; lt = bl*lt
1314 FSTD ftemp3,-32(%sp)
1315 XMPYU A0L,B0L,ftemp4 ; ht = bh*ht
1316 FSTD ftemp4,-24(%sp) ;
1317
1318 LDD -8(%sp),m ; r21 = m
1319 LDD -16(%sp),m1 ; r19 = m1
1320 ADD,L m,m1,m ; m+m1
1321
1322 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1323 LDD -24(%sp),ht ; r24 = ht
1324
1325 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1326 ADD,L ht,high_one,ht ; ht+=high_one
1327
1328 EXTRD,U m,31,32,temp1 ; m >> 32
1329 LDD -32(%sp),lt ; lt
1330 ADD,L ht,temp1,ht ; ht+= m>>32
1331 ADD lt,temp3,lt ; lt = lt+m1
1332 ADD,DC ht,%r0,ht ; ht++
1333
1334 ADD C1,lt,C1 ; c1=c1+lt
1335 ADD,DC ht,%r0,ht ; bump c3 if overflow,nullify otherwise
1336
1337 ADD C2,ht,C2 ; c2 = c2 + ht
1338 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1339.endm
1340
1341
1342;
1343;void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1344; arg0 = r_ptr
1345; arg1 = a_ptr
1346; arg2 = b_ptr
1347;
1348
1349bn_mul_comba8
1350 .proc
1351 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1352 .EXPORT bn_mul_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1353 .entry
1354 .align 64
1355
1356 STD %r3,0(%sp) ; save r3
1357 STD %r4,8(%sp) ; save r4
1358 STD %r5,16(%sp) ; save r5
1359 STD %r6,24(%sp) ; save r6
1360 FSTD %fr12,32(%sp) ; save r6
1361 FSTD %fr13,40(%sp) ; save r7
1362
1363 ;
1364 ; Zero out carries
1365 ;
1366 COPY %r0,c1
1367 COPY %r0,c2
1368 COPY %r0,c3
1369
1370 LDO 128(%sp),%sp ; bump stack
1371 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1372
1373 ;
1374 ; Load up all of the values we are going to use
1375 ;
1376 FLDD 0(a_ptr),a0
1377 FLDD 8(a_ptr),a1
1378 FLDD 16(a_ptr),a2
1379 FLDD 24(a_ptr),a3
1380 FLDD 32(a_ptr),a4
1381 FLDD 40(a_ptr),a5
1382 FLDD 48(a_ptr),a6
1383 FLDD 56(a_ptr),a7
1384
1385 FLDD 0(b_ptr),b0
1386 FLDD 8(b_ptr),b1
1387 FLDD 16(b_ptr),b2
1388 FLDD 24(b_ptr),b3
1389 FLDD 32(b_ptr),b4
1390 FLDD 40(b_ptr),b5
1391 FLDD 48(b_ptr),b6
1392 FLDD 56(b_ptr),b7
1393
1394 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1395 STD c1,0(r_ptr)
1396 COPY %r0,c1
1397
1398 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1399 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1400 STD c2,8(r_ptr)
1401 COPY %r0,c2
1402
1403 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1404 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1405 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1406 STD c3,16(r_ptr)
1407 COPY %r0,c3
1408
1409 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1410 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1411 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1412 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1413 STD c1,24(r_ptr)
1414 COPY %r0,c1
1415
1416 MUL_ADD_C a4L,a4R,b0L,b0R,c2,c3,c1
1417 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1418 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1419 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1420 MUL_ADD_C a0L,a0R,b4L,b4R,c2,c3,c1
1421 STD c2,32(r_ptr)
1422 COPY %r0,c2
1423
1424 MUL_ADD_C a0L,a0R,b5L,b5R,c3,c1,c2
1425 MUL_ADD_C a1L,a1R,b4L,b4R,c3,c1,c2
1426 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1427 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1428 MUL_ADD_C a4L,a4R,b1L,b1R,c3,c1,c2
1429 MUL_ADD_C a5L,a5R,b0L,b0R,c3,c1,c2
1430 STD c3,40(r_ptr)
1431 COPY %r0,c3
1432
1433 MUL_ADD_C a6L,a6R,b0L,b0R,c1,c2,c3
1434 MUL_ADD_C a5L,a5R,b1L,b1R,c1,c2,c3
1435 MUL_ADD_C a4L,a4R,b2L,b2R,c1,c2,c3
1436 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1437 MUL_ADD_C a2L,a2R,b4L,b4R,c1,c2,c3
1438 MUL_ADD_C a1L,a1R,b5L,b5R,c1,c2,c3
1439 MUL_ADD_C a0L,a0R,b6L,b6R,c1,c2,c3
1440 STD c1,48(r_ptr)
1441 COPY %r0,c1
1442
1443 MUL_ADD_C a0L,a0R,b7L,b7R,c2,c3,c1
1444 MUL_ADD_C a1L,a1R,b6L,b6R,c2,c3,c1
1445 MUL_ADD_C a2L,a2R,b5L,b5R,c2,c3,c1
1446 MUL_ADD_C a3L,a3R,b4L,b4R,c2,c3,c1
1447 MUL_ADD_C a4L,a4R,b3L,b3R,c2,c3,c1
1448 MUL_ADD_C a5L,a5R,b2L,b2R,c2,c3,c1
1449 MUL_ADD_C a6L,a6R,b1L,b1R,c2,c3,c1
1450 MUL_ADD_C a7L,a7R,b0L,b0R,c2,c3,c1
1451 STD c2,56(r_ptr)
1452 COPY %r0,c2
1453
1454 MUL_ADD_C a7L,a7R,b1L,b1R,c3,c1,c2
1455 MUL_ADD_C a6L,a6R,b2L,b2R,c3,c1,c2
1456 MUL_ADD_C a5L,a5R,b3L,b3R,c3,c1,c2
1457 MUL_ADD_C a4L,a4R,b4L,b4R,c3,c1,c2
1458 MUL_ADD_C a3L,a3R,b5L,b5R,c3,c1,c2
1459 MUL_ADD_C a2L,a2R,b6L,b6R,c3,c1,c2
1460 MUL_ADD_C a1L,a1R,b7L,b7R,c3,c1,c2
1461 STD c3,64(r_ptr)
1462 COPY %r0,c3
1463
1464 MUL_ADD_C a2L,a2R,b7L,b7R,c1,c2,c3
1465 MUL_ADD_C a3L,a3R,b6L,b6R,c1,c2,c3
1466 MUL_ADD_C a4L,a4R,b5L,b5R,c1,c2,c3
1467 MUL_ADD_C a5L,a5R,b4L,b4R,c1,c2,c3
1468 MUL_ADD_C a6L,a6R,b3L,b3R,c1,c2,c3
1469 MUL_ADD_C a7L,a7R,b2L,b2R,c1,c2,c3
1470 STD c1,72(r_ptr)
1471 COPY %r0,c1
1472
1473 MUL_ADD_C a7L,a7R,b3L,b3R,c2,c3,c1
1474 MUL_ADD_C a6L,a6R,b4L,b4R,c2,c3,c1
1475 MUL_ADD_C a5L,a5R,b5L,b5R,c2,c3,c1
1476 MUL_ADD_C a4L,a4R,b6L,b6R,c2,c3,c1
1477 MUL_ADD_C a3L,a3R,b7L,b7R,c2,c3,c1
1478 STD c2,80(r_ptr)
1479 COPY %r0,c2
1480
1481 MUL_ADD_C a4L,a4R,b7L,b7R,c3,c1,c2
1482 MUL_ADD_C a5L,a5R,b6L,b6R,c3,c1,c2
1483 MUL_ADD_C a6L,a6R,b5L,b5R,c3,c1,c2
1484 MUL_ADD_C a7L,a7R,b4L,b4R,c3,c1,c2
1485 STD c3,88(r_ptr)
1486 COPY %r0,c3
1487
1488 MUL_ADD_C a7L,a7R,b5L,b5R,c1,c2,c3
1489 MUL_ADD_C a6L,a6R,b6L,b6R,c1,c2,c3
1490 MUL_ADD_C a5L,a5R,b7L,b7R,c1,c2,c3
1491 STD c1,96(r_ptr)
1492 COPY %r0,c1
1493
1494 MUL_ADD_C a6L,a6R,b7L,b7R,c2,c3,c1
1495 MUL_ADD_C a7L,a7R,b6L,b6R,c2,c3,c1
1496 STD c2,104(r_ptr)
1497 COPY %r0,c2
1498
1499 MUL_ADD_C a7L,a7R,b7L,b7R,c3,c1,c2
1500 STD c3,112(r_ptr)
1501 STD c1,120(r_ptr)
1502
1503 .EXIT
1504 FLDD -88(%sp),%fr13
1505 FLDD -96(%sp),%fr12
1506 LDD -104(%sp),%r6 ; restore r6
1507 LDD -112(%sp),%r5 ; restore r5
1508 LDD -120(%sp),%r4 ; restore r4
1509 BVE (%rp)
1510 LDD,MB -128(%sp),%r3
1511
1512 .PROCEND
1513
1514;-----------------------------------------------------------------------------
1515;
1516;void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1517; arg0 = r_ptr
1518; arg1 = a_ptr
1519; arg2 = b_ptr
1520;
1521
1522bn_mul_comba4
1523 .proc
1524 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1525 .EXPORT bn_mul_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1526 .entry
1527 .align 64
1528
1529 STD %r3,0(%sp) ; save r3
1530 STD %r4,8(%sp) ; save r4
1531 STD %r5,16(%sp) ; save r5
1532 STD %r6,24(%sp) ; save r6
1533 FSTD %fr12,32(%sp) ; save r6
1534 FSTD %fr13,40(%sp) ; save r7
1535
1536 ;
1537 ; Zero out carries
1538 ;
1539 COPY %r0,c1
1540 COPY %r0,c2
1541 COPY %r0,c3
1542
1543 LDO 128(%sp),%sp ; bump stack
1544 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1545
1546 ;
1547 ; Load up all of the values we are going to use
1548 ;
1549 FLDD 0(a_ptr),a0
1550 FLDD 8(a_ptr),a1
1551 FLDD 16(a_ptr),a2
1552 FLDD 24(a_ptr),a3
1553
1554 FLDD 0(b_ptr),b0
1555 FLDD 8(b_ptr),b1
1556 FLDD 16(b_ptr),b2
1557 FLDD 24(b_ptr),b3
1558
1559 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1560 STD c1,0(r_ptr)
1561 COPY %r0,c1
1562
1563 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1564 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1565 STD c2,8(r_ptr)
1566 COPY %r0,c2
1567
1568 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1569 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1570 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1571 STD c3,16(r_ptr)
1572 COPY %r0,c3
1573
1574 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1575 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1576 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1577 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1578 STD c1,24(r_ptr)
1579 COPY %r0,c1
1580
1581 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1582 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1583 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1584 STD c2,32(r_ptr)
1585 COPY %r0,c2
1586
1587 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1588 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1589 STD c3,40(r_ptr)
1590 COPY %r0,c3
1591
1592 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1593 STD c1,48(r_ptr)
1594 STD c2,56(r_ptr)
1595
1596 .EXIT
1597 FLDD -88(%sp),%fr13
1598 FLDD -96(%sp),%fr12
1599 LDD -104(%sp),%r6 ; restore r6
1600 LDD -112(%sp),%r5 ; restore r5
1601 LDD -120(%sp),%r4 ; restore r4
1602 BVE (%rp)
1603 LDD,MB -128(%sp),%r3
1604
1605 .PROCEND
1606
1607
1608;--- not PIC .SPACE $TEXT$
1609;--- not PIC .SUBSPA $CODE$
1610;--- not PIC .SPACE $PRIVATE$,SORT=16
1611;--- not PIC .IMPORT $global$,DATA
1612;--- not PIC .SPACE $TEXT$
1613;--- not PIC .SUBSPA $CODE$
1614;--- not PIC .SUBSPA $LIT$,ACCESS=0x2c
1615;--- not PIC C$7
1616;--- not PIC .ALIGN 8
1617;--- not PIC .STRINGZ "Division would overflow (%d)\n"
1618 .END
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2W.s b/src/lib/libcrypto/bn/asm/pa-risc2W.s
new file mode 100644
index 0000000000..a99545754d
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/pa-risc2W.s
@@ -0,0 +1,1605 @@
1;
2; PA-RISC 64-bit implementation of bn_asm code
3;
4; This code is approximately 2x faster than the C version
5; for RSA/DSA.
6;
7; See http://devresource.hp.com/ for more details on the PA-RISC
8; architecture. Also see the book "PA-RISC 2.0 Architecture"
9; by Gerry Kane for information on the instruction set architecture.
10;
11; Code written by Chris Ruemmler (with some help from the HP C
12; compiler).
13;
14; The code compiles with HP's assembler
15;
16
17 .level 2.0W
18 .space $TEXT$
19 .subspa $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY
20
21;
22; Global Register definitions used for the routines.
23;
24; Some information about HP's runtime architecture for 64-bits.
25;
26; "Caller save" means the calling function must save the register
27; if it wants the register to be preserved.
28; "Callee save" means if a function uses the register, it must save
29; the value before using it.
30;
31; For the floating point registers
32;
33; "caller save" registers: fr4-fr11, fr22-fr31
34; "callee save" registers: fr12-fr21
35; "special" registers: fr0-fr3 (status and exception registers)
36;
37; For the integer registers
38; value zero : r0
39; "caller save" registers: r1,r19-r26
40; "callee save" registers: r3-r18
41; return register : r2 (rp)
42; return values ; r28 (ret0,ret1)
43; Stack pointer ; r30 (sp)
44; global data pointer ; r27 (dp)
45; argument pointer ; r29 (ap)
46; millicode return ptr ; r31 (also a caller save register)
47
48
49;
50; Arguments to the routines
51;
52r_ptr .reg %r26
53a_ptr .reg %r25
54b_ptr .reg %r24
55num .reg %r24
56w .reg %r23
57n .reg %r23
58
59
60;
61; Globals used in some routines
62;
63
64top_overflow .reg %r29
65high_mask .reg %r22 ; value 0xffffffff80000000L
66
67
68;------------------------------------------------------------------------------
69;
70; bn_mul_add_words
71;
72;BN_ULONG bn_mul_add_words(BN_ULONG *r_ptr, BN_ULONG *a_ptr,
73; int num, BN_ULONG w)
74;
75; arg0 = r_ptr
76; arg1 = a_ptr
77; arg2 = num
78; arg3 = w
79;
80; Local register definitions
81;
82
83fm1 .reg %fr22
84fm .reg %fr23
85ht_temp .reg %fr24
86ht_temp_1 .reg %fr25
87lt_temp .reg %fr26
88lt_temp_1 .reg %fr27
89fm1_1 .reg %fr28
90fm_1 .reg %fr29
91
92fw_h .reg %fr7L
93fw_l .reg %fr7R
94fw .reg %fr7
95
96fht_0 .reg %fr8L
97flt_0 .reg %fr8R
98t_float_0 .reg %fr8
99
100fht_1 .reg %fr9L
101flt_1 .reg %fr9R
102t_float_1 .reg %fr9
103
104tmp_0 .reg %r31
105tmp_1 .reg %r21
106m_0 .reg %r20
107m_1 .reg %r19
108ht_0 .reg %r1
109ht_1 .reg %r3
110lt_0 .reg %r4
111lt_1 .reg %r5
112m1_0 .reg %r6
113m1_1 .reg %r7
114rp_val .reg %r8
115rp_val_1 .reg %r9
116
117bn_mul_add_words
118 .export bn_mul_add_words,entry,NO_RELOCATION,LONG_RETURN
119 .proc
120 .callinfo frame=128
121 .entry
122 .align 64
123
124 STD %r3,0(%sp) ; save r3
125 STD %r4,8(%sp) ; save r4
126 NOP ; Needed to make the loop 16-byte aligned
127 NOP ; Needed to make the loop 16-byte aligned
128
129 STD %r5,16(%sp) ; save r5
130 STD %r6,24(%sp) ; save r6
131 STD %r7,32(%sp) ; save r7
132 STD %r8,40(%sp) ; save r8
133
134 STD %r9,48(%sp) ; save r9
135 COPY %r0,%ret0 ; return 0 by default
136 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
137 STD w,56(%sp) ; store w on stack
138
139 CMPIB,>= 0,num,bn_mul_add_words_exit ; if (num <= 0) then exit
140 LDO 128(%sp),%sp ; bump stack
141
142 ;
143 ; The loop is unrolled twice, so if there is only 1 number
144 ; then go straight to the cleanup code.
145 ;
146 CMPIB,= 1,num,bn_mul_add_words_single_top
147 FLDD -72(%sp),fw ; load up w into fp register fw (fw_h/fw_l)
148
149 ;
150 ; This loop is unrolled 2 times (64-byte aligned as well)
151 ;
152 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
153 ; two 32-bit mutiplies can be issued per cycle.
154 ;
155bn_mul_add_words_unroll2
156
157 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
158 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
159 LDD 0(r_ptr),rp_val ; rp[0]
160 LDD 8(r_ptr),rp_val_1 ; rp[1]
161
162 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
163 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = fht_1*fw_l
164 FSTD fm1,-16(%sp) ; -16(sp) = m1[0]
165 FSTD fm1_1,-48(%sp) ; -48(sp) = m1[1]
166
167 XMPYU flt_0,fw_h,fm ; m[0] = flt_0*fw_h
168 XMPYU flt_1,fw_h,fm_1 ; m[1] = flt_1*fw_h
169 FSTD fm,-8(%sp) ; -8(sp) = m[0]
170 FSTD fm_1,-40(%sp) ; -40(sp) = m[1]
171
172 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
173 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp_1 = fht_1*fw_h
174 FSTD ht_temp,-24(%sp) ; -24(sp) = ht_temp
175 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht_temp_1
176
177 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
178 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
179 FSTD lt_temp,-32(%sp) ; -32(sp) = lt_temp
180 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt_temp_1
181
182 LDD -8(%sp),m_0 ; m[0]
183 LDD -40(%sp),m_1 ; m[1]
184 LDD -16(%sp),m1_0 ; m1[0]
185 LDD -48(%sp),m1_1 ; m1[1]
186
187 LDD -24(%sp),ht_0 ; ht[0]
188 LDD -56(%sp),ht_1 ; ht[1]
189 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m[0] + m1[0];
190 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m[1] + m1[1];
191
192 LDD -32(%sp),lt_0
193 LDD -64(%sp),lt_1
194 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m[0] < m1[0])
195 ADD,L ht_0,top_overflow,ht_0 ; ht[0] += (1<<32)
196
197 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m[1] < m1[1])
198 ADD,L ht_1,top_overflow,ht_1 ; ht[1] += (1<<32)
199 EXTRD,U tmp_0,31,32,m_0 ; m[0]>>32
200 DEPD,Z tmp_0,31,32,m1_0 ; m1[0] = m[0]<<32
201
202 EXTRD,U tmp_1,31,32,m_1 ; m[1]>>32
203 DEPD,Z tmp_1,31,32,m1_1 ; m1[1] = m[1]<<32
204 ADD,L ht_0,m_0,ht_0 ; ht[0]+= (m[0]>>32)
205 ADD,L ht_1,m_1,ht_1 ; ht[1]+= (m[1]>>32)
206
207 ADD lt_0,m1_0,lt_0 ; lt[0] = lt[0]+m1[0];
208 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
209 ADD lt_1,m1_1,lt_1 ; lt[1] = lt[1]+m1[1];
210 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
211
212 ADD %ret0,lt_0,lt_0 ; lt[0] = lt[0] + c;
213 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
214 ADD lt_0,rp_val,lt_0 ; lt[0] = lt[0]+rp[0]
215 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
216
217 LDO -2(num),num ; num = num - 2;
218 ADD ht_0,lt_1,lt_1 ; lt[1] = lt[1] + ht_0 (c);
219 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
220 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
221
222 ADD lt_1,rp_val_1,lt_1 ; lt[1] = lt[1]+rp[1]
223 ADD,DC ht_1,%r0,%ret0 ; ht[1]++
224 LDO 16(a_ptr),a_ptr ; a_ptr += 2
225
226 STD lt_1,8(r_ptr) ; rp[1] = lt[1]
227 CMPIB,<= 2,num,bn_mul_add_words_unroll2 ; go again if more to do
228 LDO 16(r_ptr),r_ptr ; r_ptr += 2
229
230 CMPIB,=,N 0,num,bn_mul_add_words_exit ; are we done, or cleanup last one
231
232 ;
233 ; Top of loop aligned on 64-byte boundary
234 ;
235bn_mul_add_words_single_top
236 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
237 LDD 0(r_ptr),rp_val ; rp[0]
238 LDO 8(a_ptr),a_ptr ; a_ptr++
239 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
240 FSTD fm1,-16(%sp) ; -16(sp) = m1
241 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
242 FSTD fm,-8(%sp) ; -8(sp) = m
243 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
244 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
245 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
246 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
247
248 LDD -8(%sp),m_0
249 LDD -16(%sp),m1_0 ; m1 = temp1
250 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
251 LDD -24(%sp),ht_0
252 LDD -32(%sp),lt_0
253
254 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
255 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
256
257 EXTRD,U tmp_0,31,32,m_0 ; m>>32
258 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
259
260 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
261 ADD lt_0,m1_0,tmp_0 ; tmp_0 = lt+m1;
262 ADD,DC ht_0,%r0,ht_0 ; ht++
263 ADD %ret0,tmp_0,lt_0 ; lt = lt + c;
264 ADD,DC ht_0,%r0,ht_0 ; ht++
265 ADD lt_0,rp_val,lt_0 ; lt = lt+rp[0]
266 ADD,DC ht_0,%r0,%ret0 ; ht++
267 STD lt_0,0(r_ptr) ; rp[0] = lt
268
269bn_mul_add_words_exit
270 .EXIT
271 LDD -80(%sp),%r9 ; restore r9
272 LDD -88(%sp),%r8 ; restore r8
273 LDD -96(%sp),%r7 ; restore r7
274 LDD -104(%sp),%r6 ; restore r6
275 LDD -112(%sp),%r5 ; restore r5
276 LDD -120(%sp),%r4 ; restore r4
277 BVE (%rp)
278 LDD,MB -128(%sp),%r3 ; restore r3
279 .PROCEND ;in=23,24,25,26,29;out=28;
280
281;----------------------------------------------------------------------------
282;
283;BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
284;
285; arg0 = rp
286; arg1 = ap
287; arg2 = num
288; arg3 = w
289
290bn_mul_words
291 .proc
292 .callinfo frame=128
293 .entry
294 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
295 .align 64
296
297 STD %r3,0(%sp) ; save r3
298 STD %r4,8(%sp) ; save r4
299 STD %r5,16(%sp) ; save r5
300 STD %r6,24(%sp) ; save r6
301
302 STD %r7,32(%sp) ; save r7
303 COPY %r0,%ret0 ; return 0 by default
304 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
305 STD w,56(%sp) ; w on stack
306
307 CMPIB,>= 0,num,bn_mul_words_exit
308 LDO 128(%sp),%sp ; bump stack
309
310 ;
311 ; See if only 1 word to do, thus just do cleanup
312 ;
313 CMPIB,= 1,num,bn_mul_words_single_top
314 FLDD -72(%sp),fw ; load up w into fp register fw (fw_h/fw_l)
315
316 ;
317 ; This loop is unrolled 2 times (64-byte aligned as well)
318 ;
319 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
320 ; two 32-bit mutiplies can be issued per cycle.
321 ;
322bn_mul_words_unroll2
323
324 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
325 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
326 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
327 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = ht*fw_l
328
329 FSTD fm1,-16(%sp) ; -16(sp) = m1
330 FSTD fm1_1,-48(%sp) ; -48(sp) = m1
331 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
332 XMPYU flt_1,fw_h,fm_1 ; m = lt*fw_h
333
334 FSTD fm,-8(%sp) ; -8(sp) = m
335 FSTD fm_1,-40(%sp) ; -40(sp) = m
336 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
337 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp = ht*fw_h
338
339 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
340 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht
341 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
342 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
343
344 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
345 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt
346 LDD -8(%sp),m_0
347 LDD -40(%sp),m_1
348
349 LDD -16(%sp),m1_0
350 LDD -48(%sp),m1_1
351 LDD -24(%sp),ht_0
352 LDD -56(%sp),ht_1
353
354 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m + m1;
355 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m + m1;
356 LDD -32(%sp),lt_0
357 LDD -64(%sp),lt_1
358
359 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m < m1)
360 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
361 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m < m1)
362 ADD,L ht_1,top_overflow,ht_1 ; ht += (1<<32)
363
364 EXTRD,U tmp_0,31,32,m_0 ; m>>32
365 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
366 EXTRD,U tmp_1,31,32,m_1 ; m>>32
367 DEPD,Z tmp_1,31,32,m1_1 ; m1 = m<<32
368
369 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
370 ADD,L ht_1,m_1,ht_1 ; ht+= (m>>32)
371 ADD lt_0,m1_0,lt_0 ; lt = lt+m1;
372 ADD,DC ht_0,%r0,ht_0 ; ht++
373
374 ADD lt_1,m1_1,lt_1 ; lt = lt+m1;
375 ADD,DC ht_1,%r0,ht_1 ; ht++
376 ADD %ret0,lt_0,lt_0 ; lt = lt + c (ret0);
377 ADD,DC ht_0,%r0,ht_0 ; ht++
378
379 ADD ht_0,lt_1,lt_1 ; lt = lt + c (ht_0)
380 ADD,DC ht_1,%r0,ht_1 ; ht++
381 STD lt_0,0(r_ptr) ; rp[0] = lt
382 STD lt_1,8(r_ptr) ; rp[1] = lt
383
384 COPY ht_1,%ret0 ; carry = ht
385 LDO -2(num),num ; num = num - 2;
386 LDO 16(a_ptr),a_ptr ; ap += 2
387 CMPIB,<= 2,num,bn_mul_words_unroll2
388 LDO 16(r_ptr),r_ptr ; rp++
389
390 CMPIB,=,N 0,num,bn_mul_words_exit ; are we done?
391
392 ;
393 ; Top of loop aligned on 64-byte boundary
394 ;
395bn_mul_words_single_top
396 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
397
398 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
399 FSTD fm1,-16(%sp) ; -16(sp) = m1
400 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
401 FSTD fm,-8(%sp) ; -8(sp) = m
402 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
403 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
404 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
405 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
406
407 LDD -8(%sp),m_0
408 LDD -16(%sp),m1_0
409 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
410 LDD -24(%sp),ht_0
411 LDD -32(%sp),lt_0
412
413 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
414 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
415
416 EXTRD,U tmp_0,31,32,m_0 ; m>>32
417 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
418
419 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
420 ADD lt_0,m1_0,lt_0 ; lt= lt+m1;
421 ADD,DC ht_0,%r0,ht_0 ; ht++
422
423 ADD %ret0,lt_0,lt_0 ; lt = lt + c;
424 ADD,DC ht_0,%r0,ht_0 ; ht++
425
426 COPY ht_0,%ret0 ; copy carry
427 STD lt_0,0(r_ptr) ; rp[0] = lt
428
429bn_mul_words_exit
430 .EXIT
431 LDD -96(%sp),%r7 ; restore r7
432 LDD -104(%sp),%r6 ; restore r6
433 LDD -112(%sp),%r5 ; restore r5
434 LDD -120(%sp),%r4 ; restore r4
435 BVE (%rp)
436 LDD,MB -128(%sp),%r3 ; restore r3
437 .PROCEND ;in=23,24,25,26,29;out=28;
438
439;----------------------------------------------------------------------------
440;
441;void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
442;
443; arg0 = rp
444; arg1 = ap
445; arg2 = num
446;
447
448bn_sqr_words
449 .proc
450 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
451 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
452 .entry
453 .align 64
454
455 STD %r3,0(%sp) ; save r3
456 STD %r4,8(%sp) ; save r4
457 NOP
458 STD %r5,16(%sp) ; save r5
459
460 CMPIB,>= 0,num,bn_sqr_words_exit
461 LDO 128(%sp),%sp ; bump stack
462
463 ;
464 ; If only 1, the goto straight to cleanup
465 ;
466 CMPIB,= 1,num,bn_sqr_words_single_top
467 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
468
469 ;
470 ; This loop is unrolled 2 times (64-byte aligned as well)
471 ;
472
473bn_sqr_words_unroll2
474 FLDD 0(a_ptr),t_float_0 ; a[0]
475 FLDD 8(a_ptr),t_float_1 ; a[1]
476 XMPYU fht_0,flt_0,fm ; m[0]
477 XMPYU fht_1,flt_1,fm_1 ; m[1]
478
479 FSTD fm,-24(%sp) ; store m[0]
480 FSTD fm_1,-56(%sp) ; store m[1]
481 XMPYU flt_0,flt_0,lt_temp ; lt[0]
482 XMPYU flt_1,flt_1,lt_temp_1 ; lt[1]
483
484 FSTD lt_temp,-16(%sp) ; store lt[0]
485 FSTD lt_temp_1,-48(%sp) ; store lt[1]
486 XMPYU fht_0,fht_0,ht_temp ; ht[0]
487 XMPYU fht_1,fht_1,ht_temp_1 ; ht[1]
488
489 FSTD ht_temp,-8(%sp) ; store ht[0]
490 FSTD ht_temp_1,-40(%sp) ; store ht[1]
491 LDD -24(%sp),m_0
492 LDD -56(%sp),m_1
493
494 AND m_0,high_mask,tmp_0 ; m[0] & Mask
495 AND m_1,high_mask,tmp_1 ; m[1] & Mask
496 DEPD,Z m_0,30,31,m_0 ; m[0] << 32+1
497 DEPD,Z m_1,30,31,m_1 ; m[1] << 32+1
498
499 LDD -16(%sp),lt_0
500 LDD -48(%sp),lt_1
501 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m[0]&Mask >> 32-1
502 EXTRD,U tmp_1,32,33,tmp_1 ; tmp_1 = m[1]&Mask >> 32-1
503
504 LDD -8(%sp),ht_0
505 LDD -40(%sp),ht_1
506 ADD,L ht_0,tmp_0,ht_0 ; ht[0] += tmp_0
507 ADD,L ht_1,tmp_1,ht_1 ; ht[1] += tmp_1
508
509 ADD lt_0,m_0,lt_0 ; lt = lt+m
510 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
511 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
512 STD ht_0,8(r_ptr) ; rp[1] = ht[1]
513
514 ADD lt_1,m_1,lt_1 ; lt = lt+m
515 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
516 STD lt_1,16(r_ptr) ; rp[2] = lt[1]
517 STD ht_1,24(r_ptr) ; rp[3] = ht[1]
518
519 LDO -2(num),num ; num = num - 2;
520 LDO 16(a_ptr),a_ptr ; ap += 2
521 CMPIB,<= 2,num,bn_sqr_words_unroll2
522 LDO 32(r_ptr),r_ptr ; rp += 4
523
524 CMPIB,=,N 0,num,bn_sqr_words_exit ; are we done?
525
526 ;
527 ; Top of loop aligned on 64-byte boundary
528 ;
529bn_sqr_words_single_top
530 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
531
532 XMPYU fht_0,flt_0,fm ; m
533 FSTD fm,-24(%sp) ; store m
534
535 XMPYU flt_0,flt_0,lt_temp ; lt
536 FSTD lt_temp,-16(%sp) ; store lt
537
538 XMPYU fht_0,fht_0,ht_temp ; ht
539 FSTD ht_temp,-8(%sp) ; store ht
540
541 LDD -24(%sp),m_0 ; load m
542 AND m_0,high_mask,tmp_0 ; m & Mask
543 DEPD,Z m_0,30,31,m_0 ; m << 32+1
544 LDD -16(%sp),lt_0 ; lt
545
546 LDD -8(%sp),ht_0 ; ht
547 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m&Mask >> 32-1
548 ADD m_0,lt_0,lt_0 ; lt = lt+m
549 ADD,L ht_0,tmp_0,ht_0 ; ht += tmp_0
550 ADD,DC ht_0,%r0,ht_0 ; ht++
551
552 STD lt_0,0(r_ptr) ; rp[0] = lt
553 STD ht_0,8(r_ptr) ; rp[1] = ht
554
555bn_sqr_words_exit
556 .EXIT
557 LDD -112(%sp),%r5 ; restore r5
558 LDD -120(%sp),%r4 ; restore r4
559 BVE (%rp)
560 LDD,MB -128(%sp),%r3
561 .PROCEND ;in=23,24,25,26,29;out=28;
562
563
564;----------------------------------------------------------------------------
565;
566;BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
567;
568; arg0 = rp
569; arg1 = ap
570; arg2 = bp
571; arg3 = n
572
573t .reg %r22
574b .reg %r21
575l .reg %r20
576
577bn_add_words
578 .proc
579 .entry
580 .callinfo
581 .EXPORT bn_add_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
582 .align 64
583
584 CMPIB,>= 0,n,bn_add_words_exit
585 COPY %r0,%ret0 ; return 0 by default
586
587 ;
588 ; If 2 or more numbers do the loop
589 ;
590 CMPIB,= 1,n,bn_add_words_single_top
591 NOP
592
593 ;
594 ; This loop is unrolled 2 times (64-byte aligned as well)
595 ;
596bn_add_words_unroll2
597 LDD 0(a_ptr),t
598 LDD 0(b_ptr),b
599 ADD t,%ret0,t ; t = t+c;
600 ADD,DC %r0,%r0,%ret0 ; set c to carry
601 ADD t,b,l ; l = t + b[0]
602 ADD,DC %ret0,%r0,%ret0 ; c+= carry
603 STD l,0(r_ptr)
604
605 LDD 8(a_ptr),t
606 LDD 8(b_ptr),b
607 ADD t,%ret0,t ; t = t+c;
608 ADD,DC %r0,%r0,%ret0 ; set c to carry
609 ADD t,b,l ; l = t + b[0]
610 ADD,DC %ret0,%r0,%ret0 ; c+= carry
611 STD l,8(r_ptr)
612
613 LDO -2(n),n
614 LDO 16(a_ptr),a_ptr
615 LDO 16(b_ptr),b_ptr
616
617 CMPIB,<= 2,n,bn_add_words_unroll2
618 LDO 16(r_ptr),r_ptr
619
620 CMPIB,=,N 0,n,bn_add_words_exit ; are we done?
621
622bn_add_words_single_top
623 LDD 0(a_ptr),t
624 LDD 0(b_ptr),b
625
626 ADD t,%ret0,t ; t = t+c;
627 ADD,DC %r0,%r0,%ret0 ; set c to carry (could use CMPCLR??)
628 ADD t,b,l ; l = t + b[0]
629 ADD,DC %ret0,%r0,%ret0 ; c+= carry
630 STD l,0(r_ptr)
631
632bn_add_words_exit
633 .EXIT
634 BVE (%rp)
635 NOP
636 .PROCEND ;in=23,24,25,26,29;out=28;
637
638;----------------------------------------------------------------------------
639;
640;BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
641;
642; arg0 = rp
643; arg1 = ap
644; arg2 = bp
645; arg3 = n
646
647t1 .reg %r22
648t2 .reg %r21
649sub_tmp1 .reg %r20
650sub_tmp2 .reg %r19
651
652
653bn_sub_words
654 .proc
655 .callinfo
656 .EXPORT bn_sub_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
657 .entry
658 .align 64
659
660 CMPIB,>= 0,n,bn_sub_words_exit
661 COPY %r0,%ret0 ; return 0 by default
662
663 ;
664 ; If 2 or more numbers do the loop
665 ;
666 CMPIB,= 1,n,bn_sub_words_single_top
667 NOP
668
669 ;
670 ; This loop is unrolled 2 times (64-byte aligned as well)
671 ;
672bn_sub_words_unroll2
673 LDD 0(a_ptr),t1
674 LDD 0(b_ptr),t2
675 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
676 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
677
678 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
679 LDO 1(%r0),sub_tmp2
680
681 CMPCLR,*= t1,t2,%r0
682 COPY sub_tmp2,%ret0
683 STD sub_tmp1,0(r_ptr)
684
685 LDD 8(a_ptr),t1
686 LDD 8(b_ptr),t2
687 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
688 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
689 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
690 LDO 1(%r0),sub_tmp2
691
692 CMPCLR,*= t1,t2,%r0
693 COPY sub_tmp2,%ret0
694 STD sub_tmp1,8(r_ptr)
695
696 LDO -2(n),n
697 LDO 16(a_ptr),a_ptr
698 LDO 16(b_ptr),b_ptr
699
700 CMPIB,<= 2,n,bn_sub_words_unroll2
701 LDO 16(r_ptr),r_ptr
702
703 CMPIB,=,N 0,n,bn_sub_words_exit ; are we done?
704
705bn_sub_words_single_top
706 LDD 0(a_ptr),t1
707 LDD 0(b_ptr),t2
708 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
709 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
710 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
711 LDO 1(%r0),sub_tmp2
712
713 CMPCLR,*= t1,t2,%r0
714 COPY sub_tmp2,%ret0
715
716 STD sub_tmp1,0(r_ptr)
717
718bn_sub_words_exit
719 .EXIT
720 BVE (%rp)
721 NOP
722 .PROCEND ;in=23,24,25,26,29;out=28;
723
724;------------------------------------------------------------------------------
725;
726; unsigned long bn_div_words(unsigned long h, unsigned long l, unsigned long d)
727;
728; arg0 = h
729; arg1 = l
730; arg2 = d
731;
732; This is mainly just modified assembly from the compiler, thus the
733; lack of variable names.
734;
735;------------------------------------------------------------------------------
736bn_div_words
737 .proc
738 .callinfo CALLER,FRAME=272,ENTRY_GR=%r10,SAVE_RP,ARGS_SAVED,ORDERING_AWARE
739 .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
740 .IMPORT BN_num_bits_word,CODE,NO_RELOCATION
741 .IMPORT __iob,DATA
742 .IMPORT fprintf,CODE,NO_RELOCATION
743 .IMPORT abort,CODE,NO_RELOCATION
744 .IMPORT $$div2U,MILLICODE
745 .entry
746 STD %r2,-16(%r30)
747 STD,MA %r3,352(%r30)
748 STD %r4,-344(%r30)
749 STD %r5,-336(%r30)
750 STD %r6,-328(%r30)
751 STD %r7,-320(%r30)
752 STD %r8,-312(%r30)
753 STD %r9,-304(%r30)
754 STD %r10,-296(%r30)
755
756 STD %r27,-288(%r30) ; save gp
757
758 COPY %r24,%r3 ; save d
759 COPY %r26,%r4 ; save h (high 64-bits)
760 LDO -1(%r0),%ret0 ; return -1 by default
761
762 CMPB,*= %r0,%arg2,$D3 ; if (d == 0)
763 COPY %r25,%r5 ; save l (low 64-bits)
764
765 LDO -48(%r30),%r29 ; create ap
766 .CALL ;in=26,29;out=28;
767 B,L BN_num_bits_word,%r2
768 COPY %r3,%r26
769 LDD -288(%r30),%r27 ; restore gp
770 LDI 64,%r21
771
772 CMPB,= %r21,%ret0,$00000012 ;if (i == 64) (forward)
773 COPY %ret0,%r24 ; i
774 MTSARCM %r24
775 DEPDI,Z -1,%sar,1,%r29
776 CMPB,*<<,N %r29,%r4,bn_div_err_case ; if (h > 1<<i) (forward)
777
778$00000012
779 SUBI 64,%r24,%r31 ; i = 64 - i;
780 CMPCLR,*<< %r4,%r3,%r0 ; if (h >= d)
781 SUB %r4,%r3,%r4 ; h -= d
782 CMPB,= %r31,%r0,$0000001A ; if (i)
783 COPY %r0,%r10 ; ret = 0
784 MTSARCM %r31 ; i to shift
785 DEPD,Z %r3,%sar,64,%r3 ; d <<= i;
786 SUBI 64,%r31,%r19 ; 64 - i; redundent
787 MTSAR %r19 ; (64 -i) to shift
788 SHRPD %r4,%r5,%sar,%r4 ; l>> (64-i)
789 MTSARCM %r31 ; i to shift
790 DEPD,Z %r5,%sar,64,%r5 ; l <<= i;
791
792$0000001A
793 DEPDI,Z -1,31,32,%r19
794 EXTRD,U %r3,31,32,%r6 ; dh=(d&0xfff)>>32
795 EXTRD,U %r3,63,32,%r8 ; dl = d&0xffffff
796 LDO 2(%r0),%r9
797 STD %r3,-280(%r30) ; "d" to stack
798
799$0000001C
800 DEPDI,Z -1,63,32,%r29 ;
801 EXTRD,U %r4,31,32,%r31 ; h >> 32
802 CMPB,*=,N %r31,%r6,$D2 ; if ((h>>32) != dh)(forward) div
803 COPY %r4,%r26
804 EXTRD,U %r4,31,32,%r25
805 COPY %r6,%r24
806 .CALL ;in=23,24,25,26;out=20,21,22,28,29; (MILLICALL)
807 B,L $$div2U,%r2
808 EXTRD,U %r6,31,32,%r23
809 DEPD %r28,31,32,%r29
810$D2
811 STD %r29,-272(%r30) ; q
812 AND %r5,%r19,%r24 ; t & 0xffffffff00000000;
813 EXTRD,U %r24,31,32,%r24 ; ???
814 FLDD -272(%r30),%fr7 ; q
815 FLDD -280(%r30),%fr8 ; d
816 XMPYU %fr8L,%fr7L,%fr10
817 FSTD %fr10,-256(%r30)
818 XMPYU %fr8L,%fr7R,%fr22
819 FSTD %fr22,-264(%r30)
820 XMPYU %fr8R,%fr7L,%fr11
821 XMPYU %fr8R,%fr7R,%fr23
822 FSTD %fr11,-232(%r30)
823 FSTD %fr23,-240(%r30)
824 LDD -256(%r30),%r28
825 DEPD,Z %r28,31,32,%r2
826 LDD -264(%r30),%r20
827 ADD,L %r20,%r2,%r31
828 LDD -232(%r30),%r22
829 DEPD,Z %r22,31,32,%r22
830 LDD -240(%r30),%r21
831 B $00000024 ; enter loop
832 ADD,L %r21,%r22,%r23
833
834$0000002A
835 LDO -1(%r29),%r29
836 SUB %r23,%r8,%r23
837$00000024
838 SUB %r4,%r31,%r25
839 AND %r25,%r19,%r26
840 CMPB,*<>,N %r0,%r26,$00000046 ; (forward)
841 DEPD,Z %r25,31,32,%r20
842 OR %r20,%r24,%r21
843 CMPB,*<<,N %r21,%r23,$0000002A ;(backward)
844 SUB %r31,%r6,%r31
845;-------------Break path---------------------
846
847$00000046
848 DEPD,Z %r23,31,32,%r25 ;tl
849 EXTRD,U %r23,31,32,%r26 ;t
850 AND %r25,%r19,%r24 ;tl = (tl<<32)&0xfffffff0000000L
851 ADD,L %r31,%r26,%r31 ;th += t;
852 CMPCLR,*>>= %r5,%r24,%r0 ;if (l<tl)
853 LDO 1(%r31),%r31 ; th++;
854 CMPB,*<<=,N %r31,%r4,$00000036 ;if (n < th) (forward)
855 LDO -1(%r29),%r29 ;q--;
856 ADD,L %r4,%r3,%r4 ;h += d;
857$00000036
858 ADDIB,=,N -1,%r9,$D1 ;if (--count == 0) break (forward)
859 SUB %r5,%r24,%r28 ; l -= tl;
860 SUB %r4,%r31,%r24 ; h -= th;
861 SHRPD %r24,%r28,32,%r4 ; h = ((h<<32)|(l>>32));
862 DEPD,Z %r29,31,32,%r10 ; ret = q<<32
863 b $0000001C
864 DEPD,Z %r28,31,32,%r5 ; l = l << 32
865
866$D1
867 OR %r10,%r29,%r28 ; ret |= q
868$D3
869 LDD -368(%r30),%r2
870$D0
871 LDD -296(%r30),%r10
872 LDD -304(%r30),%r9
873 LDD -312(%r30),%r8
874 LDD -320(%r30),%r7
875 LDD -328(%r30),%r6
876 LDD -336(%r30),%r5
877 LDD -344(%r30),%r4
878 BVE (%r2)
879 .EXIT
880 LDD,MB -352(%r30),%r3
881
882bn_div_err_case
883 MFIA %r6
884 ADDIL L'bn_div_words-bn_div_err_case,%r6,%r1
885 LDO R'bn_div_words-bn_div_err_case(%r1),%r6
886 ADDIL LT'__iob,%r27,%r1
887 LDD RT'__iob(%r1),%r26
888 ADDIL L'C$4-bn_div_words,%r6,%r1
889 LDO R'C$4-bn_div_words(%r1),%r25
890 LDO 64(%r26),%r26
891 .CALL ;in=24,25,26,29;out=28;
892 B,L fprintf,%r2
893 LDO -48(%r30),%r29
894 LDD -288(%r30),%r27
895 .CALL ;in=29;
896 B,L abort,%r2
897 LDO -48(%r30),%r29
898 LDD -288(%r30),%r27
899 B $D0
900 LDD -368(%r30),%r2
901 .PROCEND ;in=24,25,26,29;out=28;
902
903;----------------------------------------------------------------------------
904;
905; Registers to hold 64-bit values to manipulate. The "L" part
906; of the register corresponds to the upper 32-bits, while the "R"
907; part corresponds to the lower 32-bits
908;
909; Note, that when using b6 and b7, the code must save these before
910; using them because they are callee save registers
911;
912;
913; Floating point registers to use to save values that
914; are manipulated. These don't collide with ftemp1-6 and
915; are all caller save registers
916;
917a0 .reg %fr22
918a0L .reg %fr22L
919a0R .reg %fr22R
920
921a1 .reg %fr23
922a1L .reg %fr23L
923a1R .reg %fr23R
924
925a2 .reg %fr24
926a2L .reg %fr24L
927a2R .reg %fr24R
928
929a3 .reg %fr25
930a3L .reg %fr25L
931a3R .reg %fr25R
932
933a4 .reg %fr26
934a4L .reg %fr26L
935a4R .reg %fr26R
936
937a5 .reg %fr27
938a5L .reg %fr27L
939a5R .reg %fr27R
940
941a6 .reg %fr28
942a6L .reg %fr28L
943a6R .reg %fr28R
944
945a7 .reg %fr29
946a7L .reg %fr29L
947a7R .reg %fr29R
948
949b0 .reg %fr30
950b0L .reg %fr30L
951b0R .reg %fr30R
952
953b1 .reg %fr31
954b1L .reg %fr31L
955b1R .reg %fr31R
956
957;
958; Temporary floating point variables, these are all caller save
959; registers
960;
961ftemp1 .reg %fr4
962ftemp2 .reg %fr5
963ftemp3 .reg %fr6
964ftemp4 .reg %fr7
965
966;
967; The B set of registers when used.
968;
969
970b2 .reg %fr8
971b2L .reg %fr8L
972b2R .reg %fr8R
973
974b3 .reg %fr9
975b3L .reg %fr9L
976b3R .reg %fr9R
977
978b4 .reg %fr10
979b4L .reg %fr10L
980b4R .reg %fr10R
981
982b5 .reg %fr11
983b5L .reg %fr11L
984b5R .reg %fr11R
985
986b6 .reg %fr12
987b6L .reg %fr12L
988b6R .reg %fr12R
989
990b7 .reg %fr13
991b7L .reg %fr13L
992b7R .reg %fr13R
993
994c1 .reg %r21 ; only reg
995temp1 .reg %r20 ; only reg
996temp2 .reg %r19 ; only reg
997temp3 .reg %r31 ; only reg
998
999m1 .reg %r28
1000c2 .reg %r23
1001high_one .reg %r1
1002ht .reg %r6
1003lt .reg %r5
1004m .reg %r4
1005c3 .reg %r3
1006
1007SQR_ADD_C .macro A0L,A0R,C1,C2,C3
1008 XMPYU A0L,A0R,ftemp1 ; m
1009 FSTD ftemp1,-24(%sp) ; store m
1010
1011 XMPYU A0R,A0R,ftemp2 ; lt
1012 FSTD ftemp2,-16(%sp) ; store lt
1013
1014 XMPYU A0L,A0L,ftemp3 ; ht
1015 FSTD ftemp3,-8(%sp) ; store ht
1016
1017 LDD -24(%sp),m ; load m
1018 AND m,high_mask,temp2 ; m & Mask
1019 DEPD,Z m,30,31,temp3 ; m << 32+1
1020 LDD -16(%sp),lt ; lt
1021
1022 LDD -8(%sp),ht ; ht
1023 EXTRD,U temp2,32,33,temp1 ; temp1 = m&Mask >> 32-1
1024 ADD temp3,lt,lt ; lt = lt+m
1025 ADD,L ht,temp1,ht ; ht += temp1
1026 ADD,DC ht,%r0,ht ; ht++
1027
1028 ADD C1,lt,C1 ; c1=c1+lt
1029 ADD,DC ht,%r0,ht ; ht++
1030
1031 ADD C2,ht,C2 ; c2=c2+ht
1032 ADD,DC C3,%r0,C3 ; c3++
1033.endm
1034
1035SQR_ADD_C2 .macro A0L,A0R,A1L,A1R,C1,C2,C3
1036 XMPYU A0L,A1R,ftemp1 ; m1 = bl*ht
1037 FSTD ftemp1,-16(%sp) ;
1038 XMPYU A0R,A1L,ftemp2 ; m = bh*lt
1039 FSTD ftemp2,-8(%sp) ;
1040 XMPYU A0R,A1R,ftemp3 ; lt = bl*lt
1041 FSTD ftemp3,-32(%sp)
1042 XMPYU A0L,A1L,ftemp4 ; ht = bh*ht
1043 FSTD ftemp4,-24(%sp) ;
1044
1045 LDD -8(%sp),m ; r21 = m
1046 LDD -16(%sp),m1 ; r19 = m1
1047 ADD,L m,m1,m ; m+m1
1048
1049 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1050 LDD -24(%sp),ht ; r24 = ht
1051
1052 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1053 ADD,L ht,high_one,ht ; ht+=high_one
1054
1055 EXTRD,U m,31,32,temp1 ; m >> 32
1056 LDD -32(%sp),lt ; lt
1057 ADD,L ht,temp1,ht ; ht+= m>>32
1058 ADD lt,temp3,lt ; lt = lt+m1
1059 ADD,DC ht,%r0,ht ; ht++
1060
1061 ADD ht,ht,ht ; ht=ht+ht;
1062 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1063
1064 ADD lt,lt,lt ; lt=lt+lt;
1065 ADD,DC ht,%r0,ht ; add in carry (ht++)
1066
1067 ADD C1,lt,C1 ; c1=c1+lt
1068 ADD,DC,*NUV ht,%r0,ht ; add in carry (ht++)
1069 LDO 1(C3),C3 ; bump c3 if overflow,nullify otherwise
1070
1071 ADD C2,ht,C2 ; c2 = c2 + ht
1072 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1073.endm
1074
1075;
1076;void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
1077; arg0 = r_ptr
1078; arg1 = a_ptr
1079;
1080
1081bn_sqr_comba8
1082 .PROC
1083 .CALLINFO FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1084 .EXPORT bn_sqr_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1085 .ENTRY
1086 .align 64
1087
1088 STD %r3,0(%sp) ; save r3
1089 STD %r4,8(%sp) ; save r4
1090 STD %r5,16(%sp) ; save r5
1091 STD %r6,24(%sp) ; save r6
1092
1093 ;
1094 ; Zero out carries
1095 ;
1096 COPY %r0,c1
1097 COPY %r0,c2
1098 COPY %r0,c3
1099
1100 LDO 128(%sp),%sp ; bump stack
1101 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1102 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1103
1104 ;
1105 ; Load up all of the values we are going to use
1106 ;
1107 FLDD 0(a_ptr),a0
1108 FLDD 8(a_ptr),a1
1109 FLDD 16(a_ptr),a2
1110 FLDD 24(a_ptr),a3
1111 FLDD 32(a_ptr),a4
1112 FLDD 40(a_ptr),a5
1113 FLDD 48(a_ptr),a6
1114 FLDD 56(a_ptr),a7
1115
1116 SQR_ADD_C a0L,a0R,c1,c2,c3
1117 STD c1,0(r_ptr) ; r[0] = c1;
1118 COPY %r0,c1
1119
1120 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1121 STD c2,8(r_ptr) ; r[1] = c2;
1122 COPY %r0,c2
1123
1124 SQR_ADD_C a1L,a1R,c3,c1,c2
1125 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1126 STD c3,16(r_ptr) ; r[2] = c3;
1127 COPY %r0,c3
1128
1129 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1130 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1131 STD c1,24(r_ptr) ; r[3] = c1;
1132 COPY %r0,c1
1133
1134 SQR_ADD_C a2L,a2R,c2,c3,c1
1135 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1136 SQR_ADD_C2 a4L,a4R,a0L,a0R,c2,c3,c1
1137 STD c2,32(r_ptr) ; r[4] = c2;
1138 COPY %r0,c2
1139
1140 SQR_ADD_C2 a5L,a5R,a0L,a0R,c3,c1,c2
1141 SQR_ADD_C2 a4L,a4R,a1L,a1R,c3,c1,c2
1142 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1143 STD c3,40(r_ptr) ; r[5] = c3;
1144 COPY %r0,c3
1145
1146 SQR_ADD_C a3L,a3R,c1,c2,c3
1147 SQR_ADD_C2 a4L,a4R,a2L,a2R,c1,c2,c3
1148 SQR_ADD_C2 a5L,a5R,a1L,a1R,c1,c2,c3
1149 SQR_ADD_C2 a6L,a6R,a0L,a0R,c1,c2,c3
1150 STD c1,48(r_ptr) ; r[6] = c1;
1151 COPY %r0,c1
1152
1153 SQR_ADD_C2 a7L,a7R,a0L,a0R,c2,c3,c1
1154 SQR_ADD_C2 a6L,a6R,a1L,a1R,c2,c3,c1
1155 SQR_ADD_C2 a5L,a5R,a2L,a2R,c2,c3,c1
1156 SQR_ADD_C2 a4L,a4R,a3L,a3R,c2,c3,c1
1157 STD c2,56(r_ptr) ; r[7] = c2;
1158 COPY %r0,c2
1159
1160 SQR_ADD_C a4L,a4R,c3,c1,c2
1161 SQR_ADD_C2 a5L,a5R,a3L,a3R,c3,c1,c2
1162 SQR_ADD_C2 a6L,a6R,a2L,a2R,c3,c1,c2
1163 SQR_ADD_C2 a7L,a7R,a1L,a1R,c3,c1,c2
1164 STD c3,64(r_ptr) ; r[8] = c3;
1165 COPY %r0,c3
1166
1167 SQR_ADD_C2 a7L,a7R,a2L,a2R,c1,c2,c3
1168 SQR_ADD_C2 a6L,a6R,a3L,a3R,c1,c2,c3
1169 SQR_ADD_C2 a5L,a5R,a4L,a4R,c1,c2,c3
1170 STD c1,72(r_ptr) ; r[9] = c1;
1171 COPY %r0,c1
1172
1173 SQR_ADD_C a5L,a5R,c2,c3,c1
1174 SQR_ADD_C2 a6L,a6R,a4L,a4R,c2,c3,c1
1175 SQR_ADD_C2 a7L,a7R,a3L,a3R,c2,c3,c1
1176 STD c2,80(r_ptr) ; r[10] = c2;
1177 COPY %r0,c2
1178
1179 SQR_ADD_C2 a7L,a7R,a4L,a4R,c3,c1,c2
1180 SQR_ADD_C2 a6L,a6R,a5L,a5R,c3,c1,c2
1181 STD c3,88(r_ptr) ; r[11] = c3;
1182 COPY %r0,c3
1183
1184 SQR_ADD_C a6L,a6R,c1,c2,c3
1185 SQR_ADD_C2 a7L,a7R,a5L,a5R,c1,c2,c3
1186 STD c1,96(r_ptr) ; r[12] = c1;
1187 COPY %r0,c1
1188
1189 SQR_ADD_C2 a7L,a7R,a6L,a6R,c2,c3,c1
1190 STD c2,104(r_ptr) ; r[13] = c2;
1191 COPY %r0,c2
1192
1193 SQR_ADD_C a7L,a7R,c3,c1,c2
1194 STD c3, 112(r_ptr) ; r[14] = c3
1195 STD c1, 120(r_ptr) ; r[15] = c1
1196
1197 .EXIT
1198 LDD -104(%sp),%r6 ; restore r6
1199 LDD -112(%sp),%r5 ; restore r5
1200 LDD -120(%sp),%r4 ; restore r4
1201 BVE (%rp)
1202 LDD,MB -128(%sp),%r3
1203
1204 .PROCEND
1205
1206;-----------------------------------------------------------------------------
1207;
1208;void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1209; arg0 = r_ptr
1210; arg1 = a_ptr
1211;
1212
1213bn_sqr_comba4
1214 .proc
1215 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1216 .EXPORT bn_sqr_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1217 .entry
1218 .align 64
1219 STD %r3,0(%sp) ; save r3
1220 STD %r4,8(%sp) ; save r4
1221 STD %r5,16(%sp) ; save r5
1222 STD %r6,24(%sp) ; save r6
1223
1224 ;
1225 ; Zero out carries
1226 ;
1227 COPY %r0,c1
1228 COPY %r0,c2
1229 COPY %r0,c3
1230
1231 LDO 128(%sp),%sp ; bump stack
1232 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1233 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1234
1235 ;
1236 ; Load up all of the values we are going to use
1237 ;
1238 FLDD 0(a_ptr),a0
1239 FLDD 8(a_ptr),a1
1240 FLDD 16(a_ptr),a2
1241 FLDD 24(a_ptr),a3
1242 FLDD 32(a_ptr),a4
1243 FLDD 40(a_ptr),a5
1244 FLDD 48(a_ptr),a6
1245 FLDD 56(a_ptr),a7
1246
1247 SQR_ADD_C a0L,a0R,c1,c2,c3
1248
1249 STD c1,0(r_ptr) ; r[0] = c1;
1250 COPY %r0,c1
1251
1252 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1253
1254 STD c2,8(r_ptr) ; r[1] = c2;
1255 COPY %r0,c2
1256
1257 SQR_ADD_C a1L,a1R,c3,c1,c2
1258 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1259
1260 STD c3,16(r_ptr) ; r[2] = c3;
1261 COPY %r0,c3
1262
1263 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1264 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1265
1266 STD c1,24(r_ptr) ; r[3] = c1;
1267 COPY %r0,c1
1268
1269 SQR_ADD_C a2L,a2R,c2,c3,c1
1270 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1271
1272 STD c2,32(r_ptr) ; r[4] = c2;
1273 COPY %r0,c2
1274
1275 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1276 STD c3,40(r_ptr) ; r[5] = c3;
1277 COPY %r0,c3
1278
1279 SQR_ADD_C a3L,a3R,c1,c2,c3
1280 STD c1,48(r_ptr) ; r[6] = c1;
1281 STD c2,56(r_ptr) ; r[7] = c2;
1282
1283 .EXIT
1284 LDD -104(%sp),%r6 ; restore r6
1285 LDD -112(%sp),%r5 ; restore r5
1286 LDD -120(%sp),%r4 ; restore r4
1287 BVE (%rp)
1288 LDD,MB -128(%sp),%r3
1289
1290 .PROCEND
1291
1292
1293;---------------------------------------------------------------------------
1294
1295MUL_ADD_C .macro A0L,A0R,B0L,B0R,C1,C2,C3
1296 XMPYU A0L,B0R,ftemp1 ; m1 = bl*ht
1297 FSTD ftemp1,-16(%sp) ;
1298 XMPYU A0R,B0L,ftemp2 ; m = bh*lt
1299 FSTD ftemp2,-8(%sp) ;
1300 XMPYU A0R,B0R,ftemp3 ; lt = bl*lt
1301 FSTD ftemp3,-32(%sp)
1302 XMPYU A0L,B0L,ftemp4 ; ht = bh*ht
1303 FSTD ftemp4,-24(%sp) ;
1304
1305 LDD -8(%sp),m ; r21 = m
1306 LDD -16(%sp),m1 ; r19 = m1
1307 ADD,L m,m1,m ; m+m1
1308
1309 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1310 LDD -24(%sp),ht ; r24 = ht
1311
1312 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1313 ADD,L ht,high_one,ht ; ht+=high_one
1314
1315 EXTRD,U m,31,32,temp1 ; m >> 32
1316 LDD -32(%sp),lt ; lt
1317 ADD,L ht,temp1,ht ; ht+= m>>32
1318 ADD lt,temp3,lt ; lt = lt+m1
1319 ADD,DC ht,%r0,ht ; ht++
1320
1321 ADD C1,lt,C1 ; c1=c1+lt
1322 ADD,DC ht,%r0,ht ; bump c3 if overflow,nullify otherwise
1323
1324 ADD C2,ht,C2 ; c2 = c2 + ht
1325 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1326.endm
1327
1328
1329;
1330;void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1331; arg0 = r_ptr
1332; arg1 = a_ptr
1333; arg2 = b_ptr
1334;
1335
1336bn_mul_comba8
1337 .proc
1338 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1339 .EXPORT bn_mul_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1340 .entry
1341 .align 64
1342
1343 STD %r3,0(%sp) ; save r3
1344 STD %r4,8(%sp) ; save r4
1345 STD %r5,16(%sp) ; save r5
1346 STD %r6,24(%sp) ; save r6
1347 FSTD %fr12,32(%sp) ; save r6
1348 FSTD %fr13,40(%sp) ; save r7
1349
1350 ;
1351 ; Zero out carries
1352 ;
1353 COPY %r0,c1
1354 COPY %r0,c2
1355 COPY %r0,c3
1356
1357 LDO 128(%sp),%sp ; bump stack
1358 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1359
1360 ;
1361 ; Load up all of the values we are going to use
1362 ;
1363 FLDD 0(a_ptr),a0
1364 FLDD 8(a_ptr),a1
1365 FLDD 16(a_ptr),a2
1366 FLDD 24(a_ptr),a3
1367 FLDD 32(a_ptr),a4
1368 FLDD 40(a_ptr),a5
1369 FLDD 48(a_ptr),a6
1370 FLDD 56(a_ptr),a7
1371
1372 FLDD 0(b_ptr),b0
1373 FLDD 8(b_ptr),b1
1374 FLDD 16(b_ptr),b2
1375 FLDD 24(b_ptr),b3
1376 FLDD 32(b_ptr),b4
1377 FLDD 40(b_ptr),b5
1378 FLDD 48(b_ptr),b6
1379 FLDD 56(b_ptr),b7
1380
1381 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1382 STD c1,0(r_ptr)
1383 COPY %r0,c1
1384
1385 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1386 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1387 STD c2,8(r_ptr)
1388 COPY %r0,c2
1389
1390 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1391 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1392 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1393 STD c3,16(r_ptr)
1394 COPY %r0,c3
1395
1396 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1397 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1398 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1399 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1400 STD c1,24(r_ptr)
1401 COPY %r0,c1
1402
1403 MUL_ADD_C a4L,a4R,b0L,b0R,c2,c3,c1
1404 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1405 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1406 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1407 MUL_ADD_C a0L,a0R,b4L,b4R,c2,c3,c1
1408 STD c2,32(r_ptr)
1409 COPY %r0,c2
1410
1411 MUL_ADD_C a0L,a0R,b5L,b5R,c3,c1,c2
1412 MUL_ADD_C a1L,a1R,b4L,b4R,c3,c1,c2
1413 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1414 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1415 MUL_ADD_C a4L,a4R,b1L,b1R,c3,c1,c2
1416 MUL_ADD_C a5L,a5R,b0L,b0R,c3,c1,c2
1417 STD c3,40(r_ptr)
1418 COPY %r0,c3
1419
1420 MUL_ADD_C a6L,a6R,b0L,b0R,c1,c2,c3
1421 MUL_ADD_C a5L,a5R,b1L,b1R,c1,c2,c3
1422 MUL_ADD_C a4L,a4R,b2L,b2R,c1,c2,c3
1423 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1424 MUL_ADD_C a2L,a2R,b4L,b4R,c1,c2,c3
1425 MUL_ADD_C a1L,a1R,b5L,b5R,c1,c2,c3
1426 MUL_ADD_C a0L,a0R,b6L,b6R,c1,c2,c3
1427 STD c1,48(r_ptr)
1428 COPY %r0,c1
1429
1430 MUL_ADD_C a0L,a0R,b7L,b7R,c2,c3,c1
1431 MUL_ADD_C a1L,a1R,b6L,b6R,c2,c3,c1
1432 MUL_ADD_C a2L,a2R,b5L,b5R,c2,c3,c1
1433 MUL_ADD_C a3L,a3R,b4L,b4R,c2,c3,c1
1434 MUL_ADD_C a4L,a4R,b3L,b3R,c2,c3,c1
1435 MUL_ADD_C a5L,a5R,b2L,b2R,c2,c3,c1
1436 MUL_ADD_C a6L,a6R,b1L,b1R,c2,c3,c1
1437 MUL_ADD_C a7L,a7R,b0L,b0R,c2,c3,c1
1438 STD c2,56(r_ptr)
1439 COPY %r0,c2
1440
1441 MUL_ADD_C a7L,a7R,b1L,b1R,c3,c1,c2
1442 MUL_ADD_C a6L,a6R,b2L,b2R,c3,c1,c2
1443 MUL_ADD_C a5L,a5R,b3L,b3R,c3,c1,c2
1444 MUL_ADD_C a4L,a4R,b4L,b4R,c3,c1,c2
1445 MUL_ADD_C a3L,a3R,b5L,b5R,c3,c1,c2
1446 MUL_ADD_C a2L,a2R,b6L,b6R,c3,c1,c2
1447 MUL_ADD_C a1L,a1R,b7L,b7R,c3,c1,c2
1448 STD c3,64(r_ptr)
1449 COPY %r0,c3
1450
1451 MUL_ADD_C a2L,a2R,b7L,b7R,c1,c2,c3
1452 MUL_ADD_C a3L,a3R,b6L,b6R,c1,c2,c3
1453 MUL_ADD_C a4L,a4R,b5L,b5R,c1,c2,c3
1454 MUL_ADD_C a5L,a5R,b4L,b4R,c1,c2,c3
1455 MUL_ADD_C a6L,a6R,b3L,b3R,c1,c2,c3
1456 MUL_ADD_C a7L,a7R,b2L,b2R,c1,c2,c3
1457 STD c1,72(r_ptr)
1458 COPY %r0,c1
1459
1460 MUL_ADD_C a7L,a7R,b3L,b3R,c2,c3,c1
1461 MUL_ADD_C a6L,a6R,b4L,b4R,c2,c3,c1
1462 MUL_ADD_C a5L,a5R,b5L,b5R,c2,c3,c1
1463 MUL_ADD_C a4L,a4R,b6L,b6R,c2,c3,c1
1464 MUL_ADD_C a3L,a3R,b7L,b7R,c2,c3,c1
1465 STD c2,80(r_ptr)
1466 COPY %r0,c2
1467
1468 MUL_ADD_C a4L,a4R,b7L,b7R,c3,c1,c2
1469 MUL_ADD_C a5L,a5R,b6L,b6R,c3,c1,c2
1470 MUL_ADD_C a6L,a6R,b5L,b5R,c3,c1,c2
1471 MUL_ADD_C a7L,a7R,b4L,b4R,c3,c1,c2
1472 STD c3,88(r_ptr)
1473 COPY %r0,c3
1474
1475 MUL_ADD_C a7L,a7R,b5L,b5R,c1,c2,c3
1476 MUL_ADD_C a6L,a6R,b6L,b6R,c1,c2,c3
1477 MUL_ADD_C a5L,a5R,b7L,b7R,c1,c2,c3
1478 STD c1,96(r_ptr)
1479 COPY %r0,c1
1480
1481 MUL_ADD_C a6L,a6R,b7L,b7R,c2,c3,c1
1482 MUL_ADD_C a7L,a7R,b6L,b6R,c2,c3,c1
1483 STD c2,104(r_ptr)
1484 COPY %r0,c2
1485
1486 MUL_ADD_C a7L,a7R,b7L,b7R,c3,c1,c2
1487 STD c3,112(r_ptr)
1488 STD c1,120(r_ptr)
1489
1490 .EXIT
1491 FLDD -88(%sp),%fr13
1492 FLDD -96(%sp),%fr12
1493 LDD -104(%sp),%r6 ; restore r6
1494 LDD -112(%sp),%r5 ; restore r5
1495 LDD -120(%sp),%r4 ; restore r4
1496 BVE (%rp)
1497 LDD,MB -128(%sp),%r3
1498
1499 .PROCEND
1500
1501;-----------------------------------------------------------------------------
1502;
1503;void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1504; arg0 = r_ptr
1505; arg1 = a_ptr
1506; arg2 = b_ptr
1507;
1508
1509bn_mul_comba4
1510 .proc
1511 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1512 .EXPORT bn_mul_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1513 .entry
1514 .align 64
1515
1516 STD %r3,0(%sp) ; save r3
1517 STD %r4,8(%sp) ; save r4
1518 STD %r5,16(%sp) ; save r5
1519 STD %r6,24(%sp) ; save r6
1520 FSTD %fr12,32(%sp) ; save r6
1521 FSTD %fr13,40(%sp) ; save r7
1522
1523 ;
1524 ; Zero out carries
1525 ;
1526 COPY %r0,c1
1527 COPY %r0,c2
1528 COPY %r0,c3
1529
1530 LDO 128(%sp),%sp ; bump stack
1531 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1532
1533 ;
1534 ; Load up all of the values we are going to use
1535 ;
1536 FLDD 0(a_ptr),a0
1537 FLDD 8(a_ptr),a1
1538 FLDD 16(a_ptr),a2
1539 FLDD 24(a_ptr),a3
1540
1541 FLDD 0(b_ptr),b0
1542 FLDD 8(b_ptr),b1
1543 FLDD 16(b_ptr),b2
1544 FLDD 24(b_ptr),b3
1545
1546 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1547 STD c1,0(r_ptr)
1548 COPY %r0,c1
1549
1550 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1551 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1552 STD c2,8(r_ptr)
1553 COPY %r0,c2
1554
1555 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1556 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1557 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1558 STD c3,16(r_ptr)
1559 COPY %r0,c3
1560
1561 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1562 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1563 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1564 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1565 STD c1,24(r_ptr)
1566 COPY %r0,c1
1567
1568 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1569 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1570 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1571 STD c2,32(r_ptr)
1572 COPY %r0,c2
1573
1574 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1575 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1576 STD c3,40(r_ptr)
1577 COPY %r0,c3
1578
1579 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1580 STD c1,48(r_ptr)
1581 STD c2,56(r_ptr)
1582
1583 .EXIT
1584 FLDD -88(%sp),%fr13
1585 FLDD -96(%sp),%fr12
1586 LDD -104(%sp),%r6 ; restore r6
1587 LDD -112(%sp),%r5 ; restore r5
1588 LDD -120(%sp),%r4 ; restore r4
1589 BVE (%rp)
1590 LDD,MB -128(%sp),%r3
1591
1592 .PROCEND
1593
1594
1595 .SPACE $TEXT$
1596 .SUBSPA $CODE$
1597 .SPACE $PRIVATE$,SORT=16
1598 .IMPORT $global$,DATA
1599 .SPACE $TEXT$
1600 .SUBSPA $CODE$
1601 .SUBSPA $LIT$,ACCESS=0x2c
1602C$4
1603 .ALIGN 8
1604 .STRINGZ "Division would overflow (%d)\n"
1605 .END
diff --git a/src/lib/libcrypto/bn/asm/ppc.pl b/src/lib/libcrypto/bn/asm/ppc.pl
new file mode 100644
index 0000000000..307c7ccb35
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/ppc.pl
@@ -0,0 +1,2081 @@
1#!/usr/bin/env perl
2#
3# Implemented as a Perl wrapper as we want to support several different
4# architectures with single file. We pick up the target based on the
5# file name we are asked to generate.
6#
7# It should be noted though that this perl code is nothing like
8# <openssl>/crypto/perlasm/x86*. In this case perl is used pretty much
9# as pre-processor to cover for platform differences in name decoration,
10# linker tables, 32-/64-bit instruction sets...
11#
12# As you might know there're several PowerPC ABI in use. Most notably
13# Linux and AIX use different 32-bit ABIs. Good news are that these ABIs
14# are similar enough to implement leaf(!) functions, which would be ABI
15# neutral. And that's what you find here: ABI neutral leaf functions.
16# In case you wonder what that is...
17#
18# AIX performance
19#
20# MEASUREMENTS WITH cc ON a 200 MhZ PowerPC 604e.
21#
22# The following is the performance of 32-bit compiler
23# generated code:
24#
25# OpenSSL 0.9.6c 21 dec 2001
26# built on: Tue Jun 11 11:06:51 EDT 2002
27# options:bn(64,32) ...
28#compiler: cc -DTHREADS -DAIX -DB_ENDIAN -DBN_LLONG -O3
29# sign verify sign/s verify/s
30#rsa 512 bits 0.0098s 0.0009s 102.0 1170.6
31#rsa 1024 bits 0.0507s 0.0026s 19.7 387.5
32#rsa 2048 bits 0.3036s 0.0085s 3.3 117.1
33#rsa 4096 bits 2.0040s 0.0299s 0.5 33.4
34#dsa 512 bits 0.0087s 0.0106s 114.3 94.5
35#dsa 1024 bits 0.0256s 0.0313s 39.0 32.0
36#
37# Same bechmark with this assembler code:
38#
39#rsa 512 bits 0.0056s 0.0005s 178.6 2049.2
40#rsa 1024 bits 0.0283s 0.0015s 35.3 674.1
41#rsa 2048 bits 0.1744s 0.0050s 5.7 201.2
42#rsa 4096 bits 1.1644s 0.0179s 0.9 55.7
43#dsa 512 bits 0.0052s 0.0062s 191.6 162.0
44#dsa 1024 bits 0.0149s 0.0180s 67.0 55.5
45#
46# Number of operations increases by at almost 75%
47#
48# Here are performance numbers for 64-bit compiler
49# generated code:
50#
51# OpenSSL 0.9.6g [engine] 9 Aug 2002
52# built on: Fri Apr 18 16:59:20 EDT 2003
53# options:bn(64,64) ...
54# compiler: cc -DTHREADS -D_REENTRANT -q64 -DB_ENDIAN -O3
55# sign verify sign/s verify/s
56#rsa 512 bits 0.0028s 0.0003s 357.1 3844.4
57#rsa 1024 bits 0.0148s 0.0008s 67.5 1239.7
58#rsa 2048 bits 0.0963s 0.0028s 10.4 353.0
59#rsa 4096 bits 0.6538s 0.0102s 1.5 98.1
60#dsa 512 bits 0.0026s 0.0032s 382.5 313.7
61#dsa 1024 bits 0.0081s 0.0099s 122.8 100.6
62#
63# Same benchmark with this assembler code:
64#
65#rsa 512 bits 0.0020s 0.0002s 510.4 6273.7
66#rsa 1024 bits 0.0088s 0.0005s 114.1 2128.3
67#rsa 2048 bits 0.0540s 0.0016s 18.5 622.5
68#rsa 4096 bits 0.3700s 0.0058s 2.7 171.0
69#dsa 512 bits 0.0016s 0.0020s 610.7 507.1
70#dsa 1024 bits 0.0047s 0.0058s 212.5 173.2
71#
72# Again, performance increases by at about 75%
73#
74# Mac OS X, Apple G5 1.8GHz (Note this is 32 bit code)
75# OpenSSL 0.9.7c 30 Sep 2003
76#
77# Original code.
78#
79#rsa 512 bits 0.0011s 0.0001s 906.1 11012.5
80#rsa 1024 bits 0.0060s 0.0003s 166.6 3363.1
81#rsa 2048 bits 0.0370s 0.0010s 27.1 982.4
82#rsa 4096 bits 0.2426s 0.0036s 4.1 280.4
83#dsa 512 bits 0.0010s 0.0012s 1038.1 841.5
84#dsa 1024 bits 0.0030s 0.0037s 329.6 269.7
85#dsa 2048 bits 0.0101s 0.0127s 98.9 78.6
86#
87# Same benchmark with this assembler code:
88#
89#rsa 512 bits 0.0007s 0.0001s 1416.2 16645.9
90#rsa 1024 bits 0.0036s 0.0002s 274.4 5380.6
91#rsa 2048 bits 0.0222s 0.0006s 45.1 1589.5
92#rsa 4096 bits 0.1469s 0.0022s 6.8 449.6
93#dsa 512 bits 0.0006s 0.0007s 1664.2 1376.2
94#dsa 1024 bits 0.0018s 0.0023s 545.0 442.2
95#dsa 2048 bits 0.0061s 0.0075s 163.5 132.8
96#
97# Performance increase of ~60%
98#
99# If you have comments or suggestions to improve code send
100# me a note at schari@us.ibm.com
101#
102
103$opf = shift;
104
105if ($opf =~ /32\.s/) {
106 $BITS= 32;
107 $BNSZ= $BITS/8;
108 $ISA= "\"ppc\"";
109
110 $LD= "lwz"; # load
111 $LDU= "lwzu"; # load and update
112 $ST= "stw"; # store
113 $STU= "stwu"; # store and update
114 $UMULL= "mullw"; # unsigned multiply low
115 $UMULH= "mulhwu"; # unsigned multiply high
116 $UDIV= "divwu"; # unsigned divide
117 $UCMPI= "cmplwi"; # unsigned compare with immediate
118 $UCMP= "cmplw"; # unsigned compare
119 $COUNTZ="cntlzw"; # count leading zeros
120 $SHL= "slw"; # shift left
121 $SHR= "srw"; # unsigned shift right
122 $SHRI= "srwi"; # unsigned shift right by immediate
123 $SHLI= "slwi"; # shift left by immediate
124 $CLRU= "clrlwi"; # clear upper bits
125 $INSR= "insrwi"; # insert right
126 $ROTL= "rotlwi"; # rotate left by immediate
127} elsif ($opf =~ /64\.s/) {
128 $BITS= 64;
129 $BNSZ= $BITS/8;
130 $ISA= "\"ppc64\"";
131
132 # same as above, but 64-bit mnemonics...
133 $LD= "ld"; # load
134 $LDU= "ldu"; # load and update
135 $ST= "std"; # store
136 $STU= "stdu"; # store and update
137 $UMULL= "mulld"; # unsigned multiply low
138 $UMULH= "mulhdu"; # unsigned multiply high
139 $UDIV= "divdu"; # unsigned divide
140 $UCMPI= "cmpldi"; # unsigned compare with immediate
141 $UCMP= "cmpld"; # unsigned compare
142 $COUNTZ="cntlzd"; # count leading zeros
143 $SHL= "sld"; # shift left
144 $SHR= "srd"; # unsigned shift right
145 $SHRI= "srdi"; # unsigned shift right by immediate
146 $SHLI= "sldi"; # shift left by immediate
147 $CLRU= "clrldi"; # clear upper bits
148 $INSR= "insrdi"; # insert right
149 $ROTL= "rotldi"; # rotate left by immediate
150} else { die "nonsense $opf"; }
151
152( defined shift || open STDOUT,">$opf" ) || die "can't open $opf: $!";
153
154# function entry points from the AIX code
155#
156# There are other, more elegant, ways to handle this. We (IBM) chose
157# this approach as it plays well with scripts we run to 'namespace'
158# OpenSSL .i.e. we add a prefix to all the public symbols so we can
159# co-exist in the same process with other implementations of OpenSSL.
160# 'cleverer' ways of doing these substitutions tend to hide data we
161# need to be obvious.
162#
163my @items = ("bn_sqr_comba4",
164 "bn_sqr_comba8",
165 "bn_mul_comba4",
166 "bn_mul_comba8",
167 "bn_sub_words",
168 "bn_add_words",
169 "bn_div_words",
170 "bn_sqr_words",
171 "bn_mul_words",
172 "bn_mul_add_words");
173
174if ($opf =~ /linux/) { do_linux(); }
175elsif ($opf =~ /aix/) { do_aix(); }
176elsif ($opf =~ /osx/) { do_osx(); }
177else { do_bsd(); }
178
179sub do_linux {
180 $d=&data();
181
182 if ($BITS==64) {
183 foreach $t (@items) {
184 $d =~ s/\.$t:/\
185\t.section\t".opd","aw"\
186\t.align\t3\
187\t.globl\t$t\
188$t:\
189\t.quad\t.$t,.TOC.\@tocbase,0\
190\t.size\t$t,24\
191\t.previous\n\
192\t.type\t.$t,\@function\
193\t.globl\t.$t\
194.$t:/g;
195 }
196 }
197 else {
198 foreach $t (@items) {
199 $d=~s/\.$t/$t/g;
200 }
201 }
202 # hide internal labels to avoid pollution of name table...
203 $d=~s/Lppcasm_/.Lppcasm_/gm;
204 print $d;
205}
206
207sub do_aix {
208 # AIX assembler is smart enough to please the linker without
209 # making us do something special...
210 print &data();
211}
212
213# MacOSX 32 bit
214sub do_osx {
215 $d=&data();
216 # Change the bn symbol prefix from '.' to '_'
217 foreach $t (@items) {
218 $d=~s/\.$t/_$t/g;
219 }
220 # Change .machine to something OS X asm will accept
221 $d=~s/\.machine.*/.text/g;
222 $d=~s/\#/;/g; # change comment from '#' to ';'
223 print $d;
224}
225
226# BSD (Untested)
227sub do_bsd {
228 $d=&data();
229 foreach $t (@items) {
230 $d=~s/\.$t/_$t/g;
231 }
232 print $d;
233}
234
235sub data {
236 local($data)=<<EOF;
237#--------------------------------------------------------------------
238#
239#
240#
241#
242# File: ppc32.s
243#
244# Created by: Suresh Chari
245# IBM Thomas J. Watson Research Library
246# Hawthorne, NY
247#
248#
249# Description: Optimized assembly routines for OpenSSL crypto
250# on the 32 bitPowerPC platform.
251#
252#
253# Version History
254#
255# 2. Fixed bn_add,bn_sub and bn_div_words, added comments,
256# cleaned up code. Also made a single version which can
257# be used for both the AIX and Linux compilers. See NOTE
258# below.
259# 12/05/03 Suresh Chari
260# (with lots of help from) Andy Polyakov
261##
262# 1. Initial version 10/20/02 Suresh Chari
263#
264#
265# The following file works for the xlc,cc
266# and gcc compilers.
267#
268# NOTE: To get the file to link correctly with the gcc compiler
269# you have to change the names of the routines and remove
270# the first .(dot) character. This should automatically
271# be done in the build process.
272#
273# Hand optimized assembly code for the following routines
274#
275# bn_sqr_comba4
276# bn_sqr_comba8
277# bn_mul_comba4
278# bn_mul_comba8
279# bn_sub_words
280# bn_add_words
281# bn_div_words
282# bn_sqr_words
283# bn_mul_words
284# bn_mul_add_words
285#
286# NOTE: It is possible to optimize this code more for
287# specific PowerPC or Power architectures. On the Northstar
288# architecture the optimizations in this file do
289# NOT provide much improvement.
290#
291# If you have comments or suggestions to improve code send
292# me a note at schari\@us.ibm.com
293#
294#--------------------------------------------------------------------------
295#
296# Defines to be used in the assembly code.
297#
298.set r0,0 # we use it as storage for value of 0
299.set SP,1 # preserved
300.set RTOC,2 # preserved
301.set r3,3 # 1st argument/return value
302.set r4,4 # 2nd argument/volatile register
303.set r5,5 # 3rd argument/volatile register
304.set r6,6 # ...
305.set r7,7
306.set r8,8
307.set r9,9
308.set r10,10
309.set r11,11
310.set r12,12
311.set r13,13 # not used, nor any other "below" it...
312
313.set BO_IF_NOT,4
314.set BO_IF,12
315.set BO_dCTR_NZERO,16
316.set BO_dCTR_ZERO,18
317.set BO_ALWAYS,20
318.set CR0_LT,0;
319.set CR0_GT,1;
320.set CR0_EQ,2
321.set CR1_FX,4;
322.set CR1_FEX,5;
323.set CR1_VX,6
324.set LR,8
325
326# Declare function names to be global
327# NOTE: For gcc these names MUST be changed to remove
328# the first . i.e. for example change ".bn_sqr_comba4"
329# to "bn_sqr_comba4". This should be automatically done
330# in the build.
331
332 .globl .bn_sqr_comba4
333 .globl .bn_sqr_comba8
334 .globl .bn_mul_comba4
335 .globl .bn_mul_comba8
336 .globl .bn_sub_words
337 .globl .bn_add_words
338 .globl .bn_div_words
339 .globl .bn_sqr_words
340 .globl .bn_mul_words
341 .globl .bn_mul_add_words
342
343# .text section
344
345 .machine $ISA
346
347#
348# NOTE: The following label name should be changed to
349# "bn_sqr_comba4" i.e. remove the first dot
350# for the gcc compiler. This should be automatically
351# done in the build
352#
353
354.align 4
355.bn_sqr_comba4:
356#
357# Optimized version of bn_sqr_comba4.
358#
359# void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
360# r3 contains r
361# r4 contains a
362#
363# Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
364#
365# r5,r6 are the two BN_ULONGs being multiplied.
366# r7,r8 are the results of the 32x32 giving 64 bit multiply.
367# r9,r10, r11 are the equivalents of c1,c2, c3.
368# Here's the assembly
369#
370#
371 xor r0,r0,r0 # set r0 = 0. Used in the addze
372 # instructions below
373
374 #sqr_add_c(a,0,c1,c2,c3)
375 $LD r5,`0*$BNSZ`(r4)
376 $UMULL r9,r5,r5
377 $UMULH r10,r5,r5 #in first iteration. No need
378 #to add since c1=c2=c3=0.
379 # Note c3(r11) is NOT set to 0
380 # but will be.
381
382 $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
383 # sqr_add_c2(a,1,0,c2,c3,c1);
384 $LD r6,`1*$BNSZ`(r4)
385 $UMULL r7,r5,r6
386 $UMULH r8,r5,r6
387
388 addc r7,r7,r7 # compute (r7,r8)=2*(r7,r8)
389 adde r8,r8,r8
390 addze r9,r0 # catch carry if any.
391 # r9= r0(=0) and carry
392
393 addc r10,r7,r10 # now add to temp result.
394 addze r11,r8 # r8 added to r11 which is 0
395 addze r9,r9
396
397 $ST r10,`1*$BNSZ`(r3) #r[1]=c2;
398 #sqr_add_c(a,1,c3,c1,c2)
399 $UMULL r7,r6,r6
400 $UMULH r8,r6,r6
401 addc r11,r7,r11
402 adde r9,r8,r9
403 addze r10,r0
404 #sqr_add_c2(a,2,0,c3,c1,c2)
405 $LD r6,`2*$BNSZ`(r4)
406 $UMULL r7,r5,r6
407 $UMULH r8,r5,r6
408
409 addc r7,r7,r7
410 adde r8,r8,r8
411 addze r10,r10
412
413 addc r11,r7,r11
414 adde r9,r8,r9
415 addze r10,r10
416 $ST r11,`2*$BNSZ`(r3) #r[2]=c3
417 #sqr_add_c2(a,3,0,c1,c2,c3);
418 $LD r6,`3*$BNSZ`(r4)
419 $UMULL r7,r5,r6
420 $UMULH r8,r5,r6
421 addc r7,r7,r7
422 adde r8,r8,r8
423 addze r11,r0
424
425 addc r9,r7,r9
426 adde r10,r8,r10
427 addze r11,r11
428 #sqr_add_c2(a,2,1,c1,c2,c3);
429 $LD r5,`1*$BNSZ`(r4)
430 $LD r6,`2*$BNSZ`(r4)
431 $UMULL r7,r5,r6
432 $UMULH r8,r5,r6
433
434 addc r7,r7,r7
435 adde r8,r8,r8
436 addze r11,r11
437 addc r9,r7,r9
438 adde r10,r8,r10
439 addze r11,r11
440 $ST r9,`3*$BNSZ`(r3) #r[3]=c1
441 #sqr_add_c(a,2,c2,c3,c1);
442 $UMULL r7,r6,r6
443 $UMULH r8,r6,r6
444 addc r10,r7,r10
445 adde r11,r8,r11
446 addze r9,r0
447 #sqr_add_c2(a,3,1,c2,c3,c1);
448 $LD r6,`3*$BNSZ`(r4)
449 $UMULL r7,r5,r6
450 $UMULH r8,r5,r6
451 addc r7,r7,r7
452 adde r8,r8,r8
453 addze r9,r9
454
455 addc r10,r7,r10
456 adde r11,r8,r11
457 addze r9,r9
458 $ST r10,`4*$BNSZ`(r3) #r[4]=c2
459 #sqr_add_c2(a,3,2,c3,c1,c2);
460 $LD r5,`2*$BNSZ`(r4)
461 $UMULL r7,r5,r6
462 $UMULH r8,r5,r6
463 addc r7,r7,r7
464 adde r8,r8,r8
465 addze r10,r0
466
467 addc r11,r7,r11
468 adde r9,r8,r9
469 addze r10,r10
470 $ST r11,`5*$BNSZ`(r3) #r[5] = c3
471 #sqr_add_c(a,3,c1,c2,c3);
472 $UMULL r7,r6,r6
473 $UMULH r8,r6,r6
474 addc r9,r7,r9
475 adde r10,r8,r10
476
477 $ST r9,`6*$BNSZ`(r3) #r[6]=c1
478 $ST r10,`7*$BNSZ`(r3) #r[7]=c2
479 bclr BO_ALWAYS,CR0_LT
480 .long 0x00000000
481
482#
483# NOTE: The following label name should be changed to
484# "bn_sqr_comba8" i.e. remove the first dot
485# for the gcc compiler. This should be automatically
486# done in the build
487#
488
489.align 4
490.bn_sqr_comba8:
491#
492# This is an optimized version of the bn_sqr_comba8 routine.
493# Tightly uses the adde instruction
494#
495#
496# void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
497# r3 contains r
498# r4 contains a
499#
500# Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
501#
502# r5,r6 are the two BN_ULONGs being multiplied.
503# r7,r8 are the results of the 32x32 giving 64 bit multiply.
504# r9,r10, r11 are the equivalents of c1,c2, c3.
505#
506# Possible optimization of loading all 8 longs of a into registers
507# doesnt provide any speedup
508#
509
510 xor r0,r0,r0 #set r0 = 0.Used in addze
511 #instructions below.
512
513 #sqr_add_c(a,0,c1,c2,c3);
514 $LD r5,`0*$BNSZ`(r4)
515 $UMULL r9,r5,r5 #1st iteration: no carries.
516 $UMULH r10,r5,r5
517 $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
518 #sqr_add_c2(a,1,0,c2,c3,c1);
519 $LD r6,`1*$BNSZ`(r4)
520 $UMULL r7,r5,r6
521 $UMULH r8,r5,r6
522
523 addc r10,r7,r10 #add the two register number
524 adde r11,r8,r0 # (r8,r7) to the three register
525 addze r9,r0 # number (r9,r11,r10).NOTE:r0=0
526
527 addc r10,r7,r10 #add the two register number
528 adde r11,r8,r11 # (r8,r7) to the three register
529 addze r9,r9 # number (r9,r11,r10).
530
531 $ST r10,`1*$BNSZ`(r3) # r[1]=c2
532
533 #sqr_add_c(a,1,c3,c1,c2);
534 $UMULL r7,r6,r6
535 $UMULH r8,r6,r6
536 addc r11,r7,r11
537 adde r9,r8,r9
538 addze r10,r0
539 #sqr_add_c2(a,2,0,c3,c1,c2);
540 $LD r6,`2*$BNSZ`(r4)
541 $UMULL r7,r5,r6
542 $UMULH r8,r5,r6
543
544 addc r11,r7,r11
545 adde r9,r8,r9
546 addze r10,r10
547
548 addc r11,r7,r11
549 adde r9,r8,r9
550 addze r10,r10
551
552 $ST r11,`2*$BNSZ`(r3) #r[2]=c3
553 #sqr_add_c2(a,3,0,c1,c2,c3);
554 $LD r6,`3*$BNSZ`(r4) #r6 = a[3]. r5 is already a[0].
555 $UMULL r7,r5,r6
556 $UMULH r8,r5,r6
557
558 addc r9,r7,r9
559 adde r10,r8,r10
560 addze r11,r0
561
562 addc r9,r7,r9
563 adde r10,r8,r10
564 addze r11,r11
565 #sqr_add_c2(a,2,1,c1,c2,c3);
566 $LD r5,`1*$BNSZ`(r4)
567 $LD r6,`2*$BNSZ`(r4)
568 $UMULL r7,r5,r6
569 $UMULH r8,r5,r6
570
571 addc r9,r7,r9
572 adde r10,r8,r10
573 addze r11,r11
574
575 addc r9,r7,r9
576 adde r10,r8,r10
577 addze r11,r11
578
579 $ST r9,`3*$BNSZ`(r3) #r[3]=c1;
580 #sqr_add_c(a,2,c2,c3,c1);
581 $UMULL r7,r6,r6
582 $UMULH r8,r6,r6
583
584 addc r10,r7,r10
585 adde r11,r8,r11
586 addze r9,r0
587 #sqr_add_c2(a,3,1,c2,c3,c1);
588 $LD r6,`3*$BNSZ`(r4)
589 $UMULL r7,r5,r6
590 $UMULH r8,r5,r6
591
592 addc r10,r7,r10
593 adde r11,r8,r11
594 addze r9,r9
595
596 addc r10,r7,r10
597 adde r11,r8,r11
598 addze r9,r9
599 #sqr_add_c2(a,4,0,c2,c3,c1);
600 $LD r5,`0*$BNSZ`(r4)
601 $LD r6,`4*$BNSZ`(r4)
602 $UMULL r7,r5,r6
603 $UMULH r8,r5,r6
604
605 addc r10,r7,r10
606 adde r11,r8,r11
607 addze r9,r9
608
609 addc r10,r7,r10
610 adde r11,r8,r11
611 addze r9,r9
612 $ST r10,`4*$BNSZ`(r3) #r[4]=c2;
613 #sqr_add_c2(a,5,0,c3,c1,c2);
614 $LD r6,`5*$BNSZ`(r4)
615 $UMULL r7,r5,r6
616 $UMULH r8,r5,r6
617
618 addc r11,r7,r11
619 adde r9,r8,r9
620 addze r10,r0
621
622 addc r11,r7,r11
623 adde r9,r8,r9
624 addze r10,r10
625 #sqr_add_c2(a,4,1,c3,c1,c2);
626 $LD r5,`1*$BNSZ`(r4)
627 $LD r6,`4*$BNSZ`(r4)
628 $UMULL r7,r5,r6
629 $UMULH r8,r5,r6
630
631 addc r11,r7,r11
632 adde r9,r8,r9
633 addze r10,r10
634
635 addc r11,r7,r11
636 adde r9,r8,r9
637 addze r10,r10
638 #sqr_add_c2(a,3,2,c3,c1,c2);
639 $LD r5,`2*$BNSZ`(r4)
640 $LD r6,`3*$BNSZ`(r4)
641 $UMULL r7,r5,r6
642 $UMULH r8,r5,r6
643
644 addc r11,r7,r11
645 adde r9,r8,r9
646 addze r10,r10
647
648 addc r11,r7,r11
649 adde r9,r8,r9
650 addze r10,r10
651 $ST r11,`5*$BNSZ`(r3) #r[5]=c3;
652 #sqr_add_c(a,3,c1,c2,c3);
653 $UMULL r7,r6,r6
654 $UMULH r8,r6,r6
655 addc r9,r7,r9
656 adde r10,r8,r10
657 addze r11,r0
658 #sqr_add_c2(a,4,2,c1,c2,c3);
659 $LD r6,`4*$BNSZ`(r4)
660 $UMULL r7,r5,r6
661 $UMULH r8,r5,r6
662
663 addc r9,r7,r9
664 adde r10,r8,r10
665 addze r11,r11
666
667 addc r9,r7,r9
668 adde r10,r8,r10
669 addze r11,r11
670 #sqr_add_c2(a,5,1,c1,c2,c3);
671 $LD r5,`1*$BNSZ`(r4)
672 $LD r6,`5*$BNSZ`(r4)
673 $UMULL r7,r5,r6
674 $UMULH r8,r5,r6
675
676 addc r9,r7,r9
677 adde r10,r8,r10
678 addze r11,r11
679
680 addc r9,r7,r9
681 adde r10,r8,r10
682 addze r11,r11
683 #sqr_add_c2(a,6,0,c1,c2,c3);
684 $LD r5,`0*$BNSZ`(r4)
685 $LD r6,`6*$BNSZ`(r4)
686 $UMULL r7,r5,r6
687 $UMULH r8,r5,r6
688 addc r9,r7,r9
689 adde r10,r8,r10
690 addze r11,r11
691 addc r9,r7,r9
692 adde r10,r8,r10
693 addze r11,r11
694 $ST r9,`6*$BNSZ`(r3) #r[6]=c1;
695 #sqr_add_c2(a,7,0,c2,c3,c1);
696 $LD r6,`7*$BNSZ`(r4)
697 $UMULL r7,r5,r6
698 $UMULH r8,r5,r6
699
700 addc r10,r7,r10
701 adde r11,r8,r11
702 addze r9,r0
703 addc r10,r7,r10
704 adde r11,r8,r11
705 addze r9,r9
706 #sqr_add_c2(a,6,1,c2,c3,c1);
707 $LD r5,`1*$BNSZ`(r4)
708 $LD r6,`6*$BNSZ`(r4)
709 $UMULL r7,r5,r6
710 $UMULH r8,r5,r6
711
712 addc r10,r7,r10
713 adde r11,r8,r11
714 addze r9,r9
715 addc r10,r7,r10
716 adde r11,r8,r11
717 addze r9,r9
718 #sqr_add_c2(a,5,2,c2,c3,c1);
719 $LD r5,`2*$BNSZ`(r4)
720 $LD r6,`5*$BNSZ`(r4)
721 $UMULL r7,r5,r6
722 $UMULH r8,r5,r6
723 addc r10,r7,r10
724 adde r11,r8,r11
725 addze r9,r9
726 addc r10,r7,r10
727 adde r11,r8,r11
728 addze r9,r9
729 #sqr_add_c2(a,4,3,c2,c3,c1);
730 $LD r5,`3*$BNSZ`(r4)
731 $LD r6,`4*$BNSZ`(r4)
732 $UMULL r7,r5,r6
733 $UMULH r8,r5,r6
734
735 addc r10,r7,r10
736 adde r11,r8,r11
737 addze r9,r9
738 addc r10,r7,r10
739 adde r11,r8,r11
740 addze r9,r9
741 $ST r10,`7*$BNSZ`(r3) #r[7]=c2;
742 #sqr_add_c(a,4,c3,c1,c2);
743 $UMULL r7,r6,r6
744 $UMULH r8,r6,r6
745 addc r11,r7,r11
746 adde r9,r8,r9
747 addze r10,r0
748 #sqr_add_c2(a,5,3,c3,c1,c2);
749 $LD r6,`5*$BNSZ`(r4)
750 $UMULL r7,r5,r6
751 $UMULH r8,r5,r6
752 addc r11,r7,r11
753 adde r9,r8,r9
754 addze r10,r10
755 addc r11,r7,r11
756 adde r9,r8,r9
757 addze r10,r10
758 #sqr_add_c2(a,6,2,c3,c1,c2);
759 $LD r5,`2*$BNSZ`(r4)
760 $LD r6,`6*$BNSZ`(r4)
761 $UMULL r7,r5,r6
762 $UMULH r8,r5,r6
763 addc r11,r7,r11
764 adde r9,r8,r9
765 addze r10,r10
766
767 addc r11,r7,r11
768 adde r9,r8,r9
769 addze r10,r10
770 #sqr_add_c2(a,7,1,c3,c1,c2);
771 $LD r5,`1*$BNSZ`(r4)
772 $LD r6,`7*$BNSZ`(r4)
773 $UMULL r7,r5,r6
774 $UMULH r8,r5,r6
775 addc r11,r7,r11
776 adde r9,r8,r9
777 addze r10,r10
778 addc r11,r7,r11
779 adde r9,r8,r9
780 addze r10,r10
781 $ST r11,`8*$BNSZ`(r3) #r[8]=c3;
782 #sqr_add_c2(a,7,2,c1,c2,c3);
783 $LD r5,`2*$BNSZ`(r4)
784 $UMULL r7,r5,r6
785 $UMULH r8,r5,r6
786
787 addc r9,r7,r9
788 adde r10,r8,r10
789 addze r11,r0
790 addc r9,r7,r9
791 adde r10,r8,r10
792 addze r11,r11
793 #sqr_add_c2(a,6,3,c1,c2,c3);
794 $LD r5,`3*$BNSZ`(r4)
795 $LD r6,`6*$BNSZ`(r4)
796 $UMULL r7,r5,r6
797 $UMULH r8,r5,r6
798 addc r9,r7,r9
799 adde r10,r8,r10
800 addze r11,r11
801 addc r9,r7,r9
802 adde r10,r8,r10
803 addze r11,r11
804 #sqr_add_c2(a,5,4,c1,c2,c3);
805 $LD r5,`4*$BNSZ`(r4)
806 $LD r6,`5*$BNSZ`(r4)
807 $UMULL r7,r5,r6
808 $UMULH r8,r5,r6
809 addc r9,r7,r9
810 adde r10,r8,r10
811 addze r11,r11
812 addc r9,r7,r9
813 adde r10,r8,r10
814 addze r11,r11
815 $ST r9,`9*$BNSZ`(r3) #r[9]=c1;
816 #sqr_add_c(a,5,c2,c3,c1);
817 $UMULL r7,r6,r6
818 $UMULH r8,r6,r6
819 addc r10,r7,r10
820 adde r11,r8,r11
821 addze r9,r0
822 #sqr_add_c2(a,6,4,c2,c3,c1);
823 $LD r6,`6*$BNSZ`(r4)
824 $UMULL r7,r5,r6
825 $UMULH r8,r5,r6
826 addc r10,r7,r10
827 adde r11,r8,r11
828 addze r9,r9
829 addc r10,r7,r10
830 adde r11,r8,r11
831 addze r9,r9
832 #sqr_add_c2(a,7,3,c2,c3,c1);
833 $LD r5,`3*$BNSZ`(r4)
834 $LD r6,`7*$BNSZ`(r4)
835 $UMULL r7,r5,r6
836 $UMULH r8,r5,r6
837 addc r10,r7,r10
838 adde r11,r8,r11
839 addze r9,r9
840 addc r10,r7,r10
841 adde r11,r8,r11
842 addze r9,r9
843 $ST r10,`10*$BNSZ`(r3) #r[10]=c2;
844 #sqr_add_c2(a,7,4,c3,c1,c2);
845 $LD r5,`4*$BNSZ`(r4)
846 $UMULL r7,r5,r6
847 $UMULH r8,r5,r6
848 addc r11,r7,r11
849 adde r9,r8,r9
850 addze r10,r0
851 addc r11,r7,r11
852 adde r9,r8,r9
853 addze r10,r10
854 #sqr_add_c2(a,6,5,c3,c1,c2);
855 $LD r5,`5*$BNSZ`(r4)
856 $LD r6,`6*$BNSZ`(r4)
857 $UMULL r7,r5,r6
858 $UMULH r8,r5,r6
859 addc r11,r7,r11
860 adde r9,r8,r9
861 addze r10,r10
862 addc r11,r7,r11
863 adde r9,r8,r9
864 addze r10,r10
865 $ST r11,`11*$BNSZ`(r3) #r[11]=c3;
866 #sqr_add_c(a,6,c1,c2,c3);
867 $UMULL r7,r6,r6
868 $UMULH r8,r6,r6
869 addc r9,r7,r9
870 adde r10,r8,r10
871 addze r11,r0
872 #sqr_add_c2(a,7,5,c1,c2,c3)
873 $LD r6,`7*$BNSZ`(r4)
874 $UMULL r7,r5,r6
875 $UMULH r8,r5,r6
876 addc r9,r7,r9
877 adde r10,r8,r10
878 addze r11,r11
879 addc r9,r7,r9
880 adde r10,r8,r10
881 addze r11,r11
882 $ST r9,`12*$BNSZ`(r3) #r[12]=c1;
883
884 #sqr_add_c2(a,7,6,c2,c3,c1)
885 $LD r5,`6*$BNSZ`(r4)
886 $UMULL r7,r5,r6
887 $UMULH r8,r5,r6
888 addc r10,r7,r10
889 adde r11,r8,r11
890 addze r9,r0
891 addc r10,r7,r10
892 adde r11,r8,r11
893 addze r9,r9
894 $ST r10,`13*$BNSZ`(r3) #r[13]=c2;
895 #sqr_add_c(a,7,c3,c1,c2);
896 $UMULL r7,r6,r6
897 $UMULH r8,r6,r6
898 addc r11,r7,r11
899 adde r9,r8,r9
900 $ST r11,`14*$BNSZ`(r3) #r[14]=c3;
901 $ST r9, `15*$BNSZ`(r3) #r[15]=c1;
902
903
904 bclr BO_ALWAYS,CR0_LT
905
906 .long 0x00000000
907
908#
909# NOTE: The following label name should be changed to
910# "bn_mul_comba4" i.e. remove the first dot
911# for the gcc compiler. This should be automatically
912# done in the build
913#
914
915.align 4
916.bn_mul_comba4:
917#
918# This is an optimized version of the bn_mul_comba4 routine.
919#
920# void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
921# r3 contains r
922# r4 contains a
923# r5 contains b
924# r6, r7 are the 2 BN_ULONGs being multiplied.
925# r8, r9 are the results of the 32x32 giving 64 multiply.
926# r10, r11, r12 are the equivalents of c1, c2, and c3.
927#
928 xor r0,r0,r0 #r0=0. Used in addze below.
929 #mul_add_c(a[0],b[0],c1,c2,c3);
930 $LD r6,`0*$BNSZ`(r4)
931 $LD r7,`0*$BNSZ`(r5)
932 $UMULL r10,r6,r7
933 $UMULH r11,r6,r7
934 $ST r10,`0*$BNSZ`(r3) #r[0]=c1
935 #mul_add_c(a[0],b[1],c2,c3,c1);
936 $LD r7,`1*$BNSZ`(r5)
937 $UMULL r8,r6,r7
938 $UMULH r9,r6,r7
939 addc r11,r8,r11
940 adde r12,r9,r0
941 addze r10,r0
942 #mul_add_c(a[1],b[0],c2,c3,c1);
943 $LD r6, `1*$BNSZ`(r4)
944 $LD r7, `0*$BNSZ`(r5)
945 $UMULL r8,r6,r7
946 $UMULH r9,r6,r7
947 addc r11,r8,r11
948 adde r12,r9,r12
949 addze r10,r10
950 $ST r11,`1*$BNSZ`(r3) #r[1]=c2
951 #mul_add_c(a[2],b[0],c3,c1,c2);
952 $LD r6,`2*$BNSZ`(r4)
953 $UMULL r8,r6,r7
954 $UMULH r9,r6,r7
955 addc r12,r8,r12
956 adde r10,r9,r10
957 addze r11,r0
958 #mul_add_c(a[1],b[1],c3,c1,c2);
959 $LD r6,`1*$BNSZ`(r4)
960 $LD r7,`1*$BNSZ`(r5)
961 $UMULL r8,r6,r7
962 $UMULH r9,r6,r7
963 addc r12,r8,r12
964 adde r10,r9,r10
965 addze r11,r11
966 #mul_add_c(a[0],b[2],c3,c1,c2);
967 $LD r6,`0*$BNSZ`(r4)
968 $LD r7,`2*$BNSZ`(r5)
969 $UMULL r8,r6,r7
970 $UMULH r9,r6,r7
971 addc r12,r8,r12
972 adde r10,r9,r10
973 addze r11,r11
974 $ST r12,`2*$BNSZ`(r3) #r[2]=c3
975 #mul_add_c(a[0],b[3],c1,c2,c3);
976 $LD r7,`3*$BNSZ`(r5)
977 $UMULL r8,r6,r7
978 $UMULH r9,r6,r7
979 addc r10,r8,r10
980 adde r11,r9,r11
981 addze r12,r0
982 #mul_add_c(a[1],b[2],c1,c2,c3);
983 $LD r6,`1*$BNSZ`(r4)
984 $LD r7,`2*$BNSZ`(r5)
985 $UMULL r8,r6,r7
986 $UMULH r9,r6,r7
987 addc r10,r8,r10
988 adde r11,r9,r11
989 addze r12,r12
990 #mul_add_c(a[2],b[1],c1,c2,c3);
991 $LD r6,`2*$BNSZ`(r4)
992 $LD r7,`1*$BNSZ`(r5)
993 $UMULL r8,r6,r7
994 $UMULH r9,r6,r7
995 addc r10,r8,r10
996 adde r11,r9,r11
997 addze r12,r12
998 #mul_add_c(a[3],b[0],c1,c2,c3);
999 $LD r6,`3*$BNSZ`(r4)
1000 $LD r7,`0*$BNSZ`(r5)
1001 $UMULL r8,r6,r7
1002 $UMULH r9,r6,r7
1003 addc r10,r8,r10
1004 adde r11,r9,r11
1005 addze r12,r12
1006 $ST r10,`3*$BNSZ`(r3) #r[3]=c1
1007 #mul_add_c(a[3],b[1],c2,c3,c1);
1008 $LD r7,`1*$BNSZ`(r5)
1009 $UMULL r8,r6,r7
1010 $UMULH r9,r6,r7
1011 addc r11,r8,r11
1012 adde r12,r9,r12
1013 addze r10,r0
1014 #mul_add_c(a[2],b[2],c2,c3,c1);
1015 $LD r6,`2*$BNSZ`(r4)
1016 $LD r7,`2*$BNSZ`(r5)
1017 $UMULL r8,r6,r7
1018 $UMULH r9,r6,r7
1019 addc r11,r8,r11
1020 adde r12,r9,r12
1021 addze r10,r10
1022 #mul_add_c(a[1],b[3],c2,c3,c1);
1023 $LD r6,`1*$BNSZ`(r4)
1024 $LD r7,`3*$BNSZ`(r5)
1025 $UMULL r8,r6,r7
1026 $UMULH r9,r6,r7
1027 addc r11,r8,r11
1028 adde r12,r9,r12
1029 addze r10,r10
1030 $ST r11,`4*$BNSZ`(r3) #r[4]=c2
1031 #mul_add_c(a[2],b[3],c3,c1,c2);
1032 $LD r6,`2*$BNSZ`(r4)
1033 $UMULL r8,r6,r7
1034 $UMULH r9,r6,r7
1035 addc r12,r8,r12
1036 adde r10,r9,r10
1037 addze r11,r0
1038 #mul_add_c(a[3],b[2],c3,c1,c2);
1039 $LD r6,`3*$BNSZ`(r4)
1040 $LD r7,`2*$BNSZ`(r4)
1041 $UMULL r8,r6,r7
1042 $UMULH r9,r6,r7
1043 addc r12,r8,r12
1044 adde r10,r9,r10
1045 addze r11,r11
1046 $ST r12,`5*$BNSZ`(r3) #r[5]=c3
1047 #mul_add_c(a[3],b[3],c1,c2,c3);
1048 $LD r7,`3*$BNSZ`(r5)
1049 $UMULL r8,r6,r7
1050 $UMULH r9,r6,r7
1051 addc r10,r8,r10
1052 adde r11,r9,r11
1053
1054 $ST r10,`6*$BNSZ`(r3) #r[6]=c1
1055 $ST r11,`7*$BNSZ`(r3) #r[7]=c2
1056 bclr BO_ALWAYS,CR0_LT
1057 .long 0x00000000
1058
1059#
1060# NOTE: The following label name should be changed to
1061# "bn_mul_comba8" i.e. remove the first dot
1062# for the gcc compiler. This should be automatically
1063# done in the build
1064#
1065
1066.align 4
1067.bn_mul_comba8:
1068#
1069# Optimized version of the bn_mul_comba8 routine.
1070#
1071# void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1072# r3 contains r
1073# r4 contains a
1074# r5 contains b
1075# r6, r7 are the 2 BN_ULONGs being multiplied.
1076# r8, r9 are the results of the 32x32 giving 64 multiply.
1077# r10, r11, r12 are the equivalents of c1, c2, and c3.
1078#
1079 xor r0,r0,r0 #r0=0. Used in addze below.
1080
1081 #mul_add_c(a[0],b[0],c1,c2,c3);
1082 $LD r6,`0*$BNSZ`(r4) #a[0]
1083 $LD r7,`0*$BNSZ`(r5) #b[0]
1084 $UMULL r10,r6,r7
1085 $UMULH r11,r6,r7
1086 $ST r10,`0*$BNSZ`(r3) #r[0]=c1;
1087 #mul_add_c(a[0],b[1],c2,c3,c1);
1088 $LD r7,`1*$BNSZ`(r5)
1089 $UMULL r8,r6,r7
1090 $UMULH r9,r6,r7
1091 addc r11,r11,r8
1092 addze r12,r9 # since we didnt set r12 to zero before.
1093 addze r10,r0
1094 #mul_add_c(a[1],b[0],c2,c3,c1);
1095 $LD r6,`1*$BNSZ`(r4)
1096 $LD r7,`0*$BNSZ`(r5)
1097 $UMULL r8,r6,r7
1098 $UMULH r9,r6,r7
1099 addc r11,r11,r8
1100 adde r12,r12,r9
1101 addze r10,r10
1102 $ST r11,`1*$BNSZ`(r3) #r[1]=c2;
1103 #mul_add_c(a[2],b[0],c3,c1,c2);
1104 $LD r6,`2*$BNSZ`(r4)
1105 $UMULL r8,r6,r7
1106 $UMULH r9,r6,r7
1107 addc r12,r12,r8
1108 adde r10,r10,r9
1109 addze r11,r0
1110 #mul_add_c(a[1],b[1],c3,c1,c2);
1111 $LD r6,`1*$BNSZ`(r4)
1112 $LD r7,`1*$BNSZ`(r5)
1113 $UMULL r8,r6,r7
1114 $UMULH r9,r6,r7
1115 addc r12,r12,r8
1116 adde r10,r10,r9
1117 addze r11,r11
1118 #mul_add_c(a[0],b[2],c3,c1,c2);
1119 $LD r6,`0*$BNSZ`(r4)
1120 $LD r7,`2*$BNSZ`(r5)
1121 $UMULL r8,r6,r7
1122 $UMULH r9,r6,r7
1123 addc r12,r12,r8
1124 adde r10,r10,r9
1125 addze r11,r11
1126 $ST r12,`2*$BNSZ`(r3) #r[2]=c3;
1127 #mul_add_c(a[0],b[3],c1,c2,c3);
1128 $LD r7,`3*$BNSZ`(r5)
1129 $UMULL r8,r6,r7
1130 $UMULH r9,r6,r7
1131 addc r10,r10,r8
1132 adde r11,r11,r9
1133 addze r12,r0
1134 #mul_add_c(a[1],b[2],c1,c2,c3);
1135 $LD r6,`1*$BNSZ`(r4)
1136 $LD r7,`2*$BNSZ`(r5)
1137 $UMULL r8,r6,r7
1138 $UMULH r9,r6,r7
1139 addc r10,r10,r8
1140 adde r11,r11,r9
1141 addze r12,r12
1142
1143 #mul_add_c(a[2],b[1],c1,c2,c3);
1144 $LD r6,`2*$BNSZ`(r4)
1145 $LD r7,`1*$BNSZ`(r5)
1146 $UMULL r8,r6,r7
1147 $UMULH r9,r6,r7
1148 addc r10,r10,r8
1149 adde r11,r11,r9
1150 addze r12,r12
1151 #mul_add_c(a[3],b[0],c1,c2,c3);
1152 $LD r6,`3*$BNSZ`(r4)
1153 $LD r7,`0*$BNSZ`(r5)
1154 $UMULL r8,r6,r7
1155 $UMULH r9,r6,r7
1156 addc r10,r10,r8
1157 adde r11,r11,r9
1158 addze r12,r12
1159 $ST r10,`3*$BNSZ`(r3) #r[3]=c1;
1160 #mul_add_c(a[4],b[0],c2,c3,c1);
1161 $LD r6,`4*$BNSZ`(r4)
1162 $UMULL r8,r6,r7
1163 $UMULH r9,r6,r7
1164 addc r11,r11,r8
1165 adde r12,r12,r9
1166 addze r10,r0
1167 #mul_add_c(a[3],b[1],c2,c3,c1);
1168 $LD r6,`3*$BNSZ`(r4)
1169 $LD r7,`1*$BNSZ`(r5)
1170 $UMULL r8,r6,r7
1171 $UMULH r9,r6,r7
1172 addc r11,r11,r8
1173 adde r12,r12,r9
1174 addze r10,r10
1175 #mul_add_c(a[2],b[2],c2,c3,c1);
1176 $LD r6,`2*$BNSZ`(r4)
1177 $LD r7,`2*$BNSZ`(r5)
1178 $UMULL r8,r6,r7
1179 $UMULH r9,r6,r7
1180 addc r11,r11,r8
1181 adde r12,r12,r9
1182 addze r10,r10
1183 #mul_add_c(a[1],b[3],c2,c3,c1);
1184 $LD r6,`1*$BNSZ`(r4)
1185 $LD r7,`3*$BNSZ`(r5)
1186 $UMULL r8,r6,r7
1187 $UMULH r9,r6,r7
1188 addc r11,r11,r8
1189 adde r12,r12,r9
1190 addze r10,r10
1191 #mul_add_c(a[0],b[4],c2,c3,c1);
1192 $LD r6,`0*$BNSZ`(r4)
1193 $LD r7,`4*$BNSZ`(r5)
1194 $UMULL r8,r6,r7
1195 $UMULH r9,r6,r7
1196 addc r11,r11,r8
1197 adde r12,r12,r9
1198 addze r10,r10
1199 $ST r11,`4*$BNSZ`(r3) #r[4]=c2;
1200 #mul_add_c(a[0],b[5],c3,c1,c2);
1201 $LD r7,`5*$BNSZ`(r5)
1202 $UMULL r8,r6,r7
1203 $UMULH r9,r6,r7
1204 addc r12,r12,r8
1205 adde r10,r10,r9
1206 addze r11,r0
1207 #mul_add_c(a[1],b[4],c3,c1,c2);
1208 $LD r6,`1*$BNSZ`(r4)
1209 $LD r7,`4*$BNSZ`(r5)
1210 $UMULL r8,r6,r7
1211 $UMULH r9,r6,r7
1212 addc r12,r12,r8
1213 adde r10,r10,r9
1214 addze r11,r11
1215 #mul_add_c(a[2],b[3],c3,c1,c2);
1216 $LD r6,`2*$BNSZ`(r4)
1217 $LD r7,`3*$BNSZ`(r5)
1218 $UMULL r8,r6,r7
1219 $UMULH r9,r6,r7
1220 addc r12,r12,r8
1221 adde r10,r10,r9
1222 addze r11,r11
1223 #mul_add_c(a[3],b[2],c3,c1,c2);
1224 $LD r6,`3*$BNSZ`(r4)
1225 $LD r7,`2*$BNSZ`(r5)
1226 $UMULL r8,r6,r7
1227 $UMULH r9,r6,r7
1228 addc r12,r12,r8
1229 adde r10,r10,r9
1230 addze r11,r11
1231 #mul_add_c(a[4],b[1],c3,c1,c2);
1232 $LD r6,`4*$BNSZ`(r4)
1233 $LD r7,`1*$BNSZ`(r5)
1234 $UMULL r8,r6,r7
1235 $UMULH r9,r6,r7
1236 addc r12,r12,r8
1237 adde r10,r10,r9
1238 addze r11,r11
1239 #mul_add_c(a[5],b[0],c3,c1,c2);
1240 $LD r6,`5*$BNSZ`(r4)
1241 $LD r7,`0*$BNSZ`(r5)
1242 $UMULL r8,r6,r7
1243 $UMULH r9,r6,r7
1244 addc r12,r12,r8
1245 adde r10,r10,r9
1246 addze r11,r11
1247 $ST r12,`5*$BNSZ`(r3) #r[5]=c3;
1248 #mul_add_c(a[6],b[0],c1,c2,c3);
1249 $LD r6,`6*$BNSZ`(r4)
1250 $UMULL r8,r6,r7
1251 $UMULH r9,r6,r7
1252 addc r10,r10,r8
1253 adde r11,r11,r9
1254 addze r12,r0
1255 #mul_add_c(a[5],b[1],c1,c2,c3);
1256 $LD r6,`5*$BNSZ`(r4)
1257 $LD r7,`1*$BNSZ`(r5)
1258 $UMULL r8,r6,r7
1259 $UMULH r9,r6,r7
1260 addc r10,r10,r8
1261 adde r11,r11,r9
1262 addze r12,r12
1263 #mul_add_c(a[4],b[2],c1,c2,c3);
1264 $LD r6,`4*$BNSZ`(r4)
1265 $LD r7,`2*$BNSZ`(r5)
1266 $UMULL r8,r6,r7
1267 $UMULH r9,r6,r7
1268 addc r10,r10,r8
1269 adde r11,r11,r9
1270 addze r12,r12
1271 #mul_add_c(a[3],b[3],c1,c2,c3);
1272 $LD r6,`3*$BNSZ`(r4)
1273 $LD r7,`3*$BNSZ`(r5)
1274 $UMULL r8,r6,r7
1275 $UMULH r9,r6,r7
1276 addc r10,r10,r8
1277 adde r11,r11,r9
1278 addze r12,r12
1279 #mul_add_c(a[2],b[4],c1,c2,c3);
1280 $LD r6,`2*$BNSZ`(r4)
1281 $LD r7,`4*$BNSZ`(r5)
1282 $UMULL r8,r6,r7
1283 $UMULH r9,r6,r7
1284 addc r10,r10,r8
1285 adde r11,r11,r9
1286 addze r12,r12
1287 #mul_add_c(a[1],b[5],c1,c2,c3);
1288 $LD r6,`1*$BNSZ`(r4)
1289 $LD r7,`5*$BNSZ`(r5)
1290 $UMULL r8,r6,r7
1291 $UMULH r9,r6,r7
1292 addc r10,r10,r8
1293 adde r11,r11,r9
1294 addze r12,r12
1295 #mul_add_c(a[0],b[6],c1,c2,c3);
1296 $LD r6,`0*$BNSZ`(r4)
1297 $LD r7,`6*$BNSZ`(r5)
1298 $UMULL r8,r6,r7
1299 $UMULH r9,r6,r7
1300 addc r10,r10,r8
1301 adde r11,r11,r9
1302 addze r12,r12
1303 $ST r10,`6*$BNSZ`(r3) #r[6]=c1;
1304 #mul_add_c(a[0],b[7],c2,c3,c1);
1305 $LD r7,`7*$BNSZ`(r5)
1306 $UMULL r8,r6,r7
1307 $UMULH r9,r6,r7
1308 addc r11,r11,r8
1309 adde r12,r12,r9
1310 addze r10,r0
1311 #mul_add_c(a[1],b[6],c2,c3,c1);
1312 $LD r6,`1*$BNSZ`(r4)
1313 $LD r7,`6*$BNSZ`(r5)
1314 $UMULL r8,r6,r7
1315 $UMULH r9,r6,r7
1316 addc r11,r11,r8
1317 adde r12,r12,r9
1318 addze r10,r10
1319 #mul_add_c(a[2],b[5],c2,c3,c1);
1320 $LD r6,`2*$BNSZ`(r4)
1321 $LD r7,`5*$BNSZ`(r5)
1322 $UMULL r8,r6,r7
1323 $UMULH r9,r6,r7
1324 addc r11,r11,r8
1325 adde r12,r12,r9
1326 addze r10,r10
1327 #mul_add_c(a[3],b[4],c2,c3,c1);
1328 $LD r6,`3*$BNSZ`(r4)
1329 $LD r7,`4*$BNSZ`(r5)
1330 $UMULL r8,r6,r7
1331 $UMULH r9,r6,r7
1332 addc r11,r11,r8
1333 adde r12,r12,r9
1334 addze r10,r10
1335 #mul_add_c(a[4],b[3],c2,c3,c1);
1336 $LD r6,`4*$BNSZ`(r4)
1337 $LD r7,`3*$BNSZ`(r5)
1338 $UMULL r8,r6,r7
1339 $UMULH r9,r6,r7
1340 addc r11,r11,r8
1341 adde r12,r12,r9
1342 addze r10,r10
1343 #mul_add_c(a[5],b[2],c2,c3,c1);
1344 $LD r6,`5*$BNSZ`(r4)
1345 $LD r7,`2*$BNSZ`(r5)
1346 $UMULL r8,r6,r7
1347 $UMULH r9,r6,r7
1348 addc r11,r11,r8
1349 adde r12,r12,r9
1350 addze r10,r10
1351 #mul_add_c(a[6],b[1],c2,c3,c1);
1352 $LD r6,`6*$BNSZ`(r4)
1353 $LD r7,`1*$BNSZ`(r5)
1354 $UMULL r8,r6,r7
1355 $UMULH r9,r6,r7
1356 addc r11,r11,r8
1357 adde r12,r12,r9
1358 addze r10,r10
1359 #mul_add_c(a[7],b[0],c2,c3,c1);
1360 $LD r6,`7*$BNSZ`(r4)
1361 $LD r7,`0*$BNSZ`(r5)
1362 $UMULL r8,r6,r7
1363 $UMULH r9,r6,r7
1364 addc r11,r11,r8
1365 adde r12,r12,r9
1366 addze r10,r10
1367 $ST r11,`7*$BNSZ`(r3) #r[7]=c2;
1368 #mul_add_c(a[7],b[1],c3,c1,c2);
1369 $LD r7,`1*$BNSZ`(r5)
1370 $UMULL r8,r6,r7
1371 $UMULH r9,r6,r7
1372 addc r12,r12,r8
1373 adde r10,r10,r9
1374 addze r11,r0
1375 #mul_add_c(a[6],b[2],c3,c1,c2);
1376 $LD r6,`6*$BNSZ`(r4)
1377 $LD r7,`2*$BNSZ`(r5)
1378 $UMULL r8,r6,r7
1379 $UMULH r9,r6,r7
1380 addc r12,r12,r8
1381 adde r10,r10,r9
1382 addze r11,r11
1383 #mul_add_c(a[5],b[3],c3,c1,c2);
1384 $LD r6,`5*$BNSZ`(r4)
1385 $LD r7,`3*$BNSZ`(r5)
1386 $UMULL r8,r6,r7
1387 $UMULH r9,r6,r7
1388 addc r12,r12,r8
1389 adde r10,r10,r9
1390 addze r11,r11
1391 #mul_add_c(a[4],b[4],c3,c1,c2);
1392 $LD r6,`4*$BNSZ`(r4)
1393 $LD r7,`4*$BNSZ`(r5)
1394 $UMULL r8,r6,r7
1395 $UMULH r9,r6,r7
1396 addc r12,r12,r8
1397 adde r10,r10,r9
1398 addze r11,r11
1399 #mul_add_c(a[3],b[5],c3,c1,c2);
1400 $LD r6,`3*$BNSZ`(r4)
1401 $LD r7,`5*$BNSZ`(r5)
1402 $UMULL r8,r6,r7
1403 $UMULH r9,r6,r7
1404 addc r12,r12,r8
1405 adde r10,r10,r9
1406 addze r11,r11
1407 #mul_add_c(a[2],b[6],c3,c1,c2);
1408 $LD r6,`2*$BNSZ`(r4)
1409 $LD r7,`6*$BNSZ`(r5)
1410 $UMULL r8,r6,r7
1411 $UMULH r9,r6,r7
1412 addc r12,r12,r8
1413 adde r10,r10,r9
1414 addze r11,r11
1415 #mul_add_c(a[1],b[7],c3,c1,c2);
1416 $LD r6,`1*$BNSZ`(r4)
1417 $LD r7,`7*$BNSZ`(r5)
1418 $UMULL r8,r6,r7
1419 $UMULH r9,r6,r7
1420 addc r12,r12,r8
1421 adde r10,r10,r9
1422 addze r11,r11
1423 $ST r12,`8*$BNSZ`(r3) #r[8]=c3;
1424 #mul_add_c(a[2],b[7],c1,c2,c3);
1425 $LD r6,`2*$BNSZ`(r4)
1426 $UMULL r8,r6,r7
1427 $UMULH r9,r6,r7
1428 addc r10,r10,r8
1429 adde r11,r11,r9
1430 addze r12,r0
1431 #mul_add_c(a[3],b[6],c1,c2,c3);
1432 $LD r6,`3*$BNSZ`(r4)
1433 $LD r7,`6*$BNSZ`(r5)
1434 $UMULL r8,r6,r7
1435 $UMULH r9,r6,r7
1436 addc r10,r10,r8
1437 adde r11,r11,r9
1438 addze r12,r12
1439 #mul_add_c(a[4],b[5],c1,c2,c3);
1440 $LD r6,`4*$BNSZ`(r4)
1441 $LD r7,`5*$BNSZ`(r5)
1442 $UMULL r8,r6,r7
1443 $UMULH r9,r6,r7
1444 addc r10,r10,r8
1445 adde r11,r11,r9
1446 addze r12,r12
1447 #mul_add_c(a[5],b[4],c1,c2,c3);
1448 $LD r6,`5*$BNSZ`(r4)
1449 $LD r7,`4*$BNSZ`(r5)
1450 $UMULL r8,r6,r7
1451 $UMULH r9,r6,r7
1452 addc r10,r10,r8
1453 adde r11,r11,r9
1454 addze r12,r12
1455 #mul_add_c(a[6],b[3],c1,c2,c3);
1456 $LD r6,`6*$BNSZ`(r4)
1457 $LD r7,`3*$BNSZ`(r5)
1458 $UMULL r8,r6,r7
1459 $UMULH r9,r6,r7
1460 addc r10,r10,r8
1461 adde r11,r11,r9
1462 addze r12,r12
1463 #mul_add_c(a[7],b[2],c1,c2,c3);
1464 $LD r6,`7*$BNSZ`(r4)
1465 $LD r7,`2*$BNSZ`(r5)
1466 $UMULL r8,r6,r7
1467 $UMULH r9,r6,r7
1468 addc r10,r10,r8
1469 adde r11,r11,r9
1470 addze r12,r12
1471 $ST r10,`9*$BNSZ`(r3) #r[9]=c1;
1472 #mul_add_c(a[7],b[3],c2,c3,c1);
1473 $LD r7,`3*$BNSZ`(r5)
1474 $UMULL r8,r6,r7
1475 $UMULH r9,r6,r7
1476 addc r11,r11,r8
1477 adde r12,r12,r9
1478 addze r10,r0
1479 #mul_add_c(a[6],b[4],c2,c3,c1);
1480 $LD r6,`6*$BNSZ`(r4)
1481 $LD r7,`4*$BNSZ`(r5)
1482 $UMULL r8,r6,r7
1483 $UMULH r9,r6,r7
1484 addc r11,r11,r8
1485 adde r12,r12,r9
1486 addze r10,r10
1487 #mul_add_c(a[5],b[5],c2,c3,c1);
1488 $LD r6,`5*$BNSZ`(r4)
1489 $LD r7,`5*$BNSZ`(r5)
1490 $UMULL r8,r6,r7
1491 $UMULH r9,r6,r7
1492 addc r11,r11,r8
1493 adde r12,r12,r9
1494 addze r10,r10
1495 #mul_add_c(a[4],b[6],c2,c3,c1);
1496 $LD r6,`4*$BNSZ`(r4)
1497 $LD r7,`6*$BNSZ`(r5)
1498 $UMULL r8,r6,r7
1499 $UMULH r9,r6,r7
1500 addc r11,r11,r8
1501 adde r12,r12,r9
1502 addze r10,r10
1503 #mul_add_c(a[3],b[7],c2,c3,c1);
1504 $LD r6,`3*$BNSZ`(r4)
1505 $LD r7,`7*$BNSZ`(r5)
1506 $UMULL r8,r6,r7
1507 $UMULH r9,r6,r7
1508 addc r11,r11,r8
1509 adde r12,r12,r9
1510 addze r10,r10
1511 $ST r11,`10*$BNSZ`(r3) #r[10]=c2;
1512 #mul_add_c(a[4],b[7],c3,c1,c2);
1513 $LD r6,`4*$BNSZ`(r4)
1514 $UMULL r8,r6,r7
1515 $UMULH r9,r6,r7
1516 addc r12,r12,r8
1517 adde r10,r10,r9
1518 addze r11,r0
1519 #mul_add_c(a[5],b[6],c3,c1,c2);
1520 $LD r6,`5*$BNSZ`(r4)
1521 $LD r7,`6*$BNSZ`(r5)
1522 $UMULL r8,r6,r7
1523 $UMULH r9,r6,r7
1524 addc r12,r12,r8
1525 adde r10,r10,r9
1526 addze r11,r11
1527 #mul_add_c(a[6],b[5],c3,c1,c2);
1528 $LD r6,`6*$BNSZ`(r4)
1529 $LD r7,`5*$BNSZ`(r5)
1530 $UMULL r8,r6,r7
1531 $UMULH r9,r6,r7
1532 addc r12,r12,r8
1533 adde r10,r10,r9
1534 addze r11,r11
1535 #mul_add_c(a[7],b[4],c3,c1,c2);
1536 $LD r6,`7*$BNSZ`(r4)
1537 $LD r7,`4*$BNSZ`(r5)
1538 $UMULL r8,r6,r7
1539 $UMULH r9,r6,r7
1540 addc r12,r12,r8
1541 adde r10,r10,r9
1542 addze r11,r11
1543 $ST r12,`11*$BNSZ`(r3) #r[11]=c3;
1544 #mul_add_c(a[7],b[5],c1,c2,c3);
1545 $LD r7,`5*$BNSZ`(r5)
1546 $UMULL r8,r6,r7
1547 $UMULH r9,r6,r7
1548 addc r10,r10,r8
1549 adde r11,r11,r9
1550 addze r12,r0
1551 #mul_add_c(a[6],b[6],c1,c2,c3);
1552 $LD r6,`6*$BNSZ`(r4)
1553 $LD r7,`6*$BNSZ`(r5)
1554 $UMULL r8,r6,r7
1555 $UMULH r9,r6,r7
1556 addc r10,r10,r8
1557 adde r11,r11,r9
1558 addze r12,r12
1559 #mul_add_c(a[5],b[7],c1,c2,c3);
1560 $LD r6,`5*$BNSZ`(r4)
1561 $LD r7,`7*$BNSZ`(r5)
1562 $UMULL r8,r6,r7
1563 $UMULH r9,r6,r7
1564 addc r10,r10,r8
1565 adde r11,r11,r9
1566 addze r12,r12
1567 $ST r10,`12*$BNSZ`(r3) #r[12]=c1;
1568 #mul_add_c(a[6],b[7],c2,c3,c1);
1569 $LD r6,`6*$BNSZ`(r4)
1570 $UMULL r8,r6,r7
1571 $UMULH r9,r6,r7
1572 addc r11,r11,r8
1573 adde r12,r12,r9
1574 addze r10,r0
1575 #mul_add_c(a[7],b[6],c2,c3,c1);
1576 $LD r6,`7*$BNSZ`(r4)
1577 $LD r7,`6*$BNSZ`(r5)
1578 $UMULL r8,r6,r7
1579 $UMULH r9,r6,r7
1580 addc r11,r11,r8
1581 adde r12,r12,r9
1582 addze r10,r10
1583 $ST r11,`13*$BNSZ`(r3) #r[13]=c2;
1584 #mul_add_c(a[7],b[7],c3,c1,c2);
1585 $LD r7,`7*$BNSZ`(r5)
1586 $UMULL r8,r6,r7
1587 $UMULH r9,r6,r7
1588 addc r12,r12,r8
1589 adde r10,r10,r9
1590 $ST r12,`14*$BNSZ`(r3) #r[14]=c3;
1591 $ST r10,`15*$BNSZ`(r3) #r[15]=c1;
1592 bclr BO_ALWAYS,CR0_LT
1593 .long 0x00000000
1594
1595#
1596# NOTE: The following label name should be changed to
1597# "bn_sub_words" i.e. remove the first dot
1598# for the gcc compiler. This should be automatically
1599# done in the build
1600#
1601#
1602.align 4
1603.bn_sub_words:
1604#
1605# Handcoded version of bn_sub_words
1606#
1607#BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1608#
1609# r3 = r
1610# r4 = a
1611# r5 = b
1612# r6 = n
1613#
1614# Note: No loop unrolling done since this is not a performance
1615# critical loop.
1616
1617 xor r0,r0,r0 #set r0 = 0
1618#
1619# check for r6 = 0 AND set carry bit.
1620#
1621 subfc. r7,r0,r6 # If r6 is 0 then result is 0.
1622 # if r6 > 0 then result !=0
1623 # In either case carry bit is set.
1624 bc BO_IF,CR0_EQ,Lppcasm_sub_adios
1625 addi r4,r4,-$BNSZ
1626 addi r3,r3,-$BNSZ
1627 addi r5,r5,-$BNSZ
1628 mtctr r6
1629Lppcasm_sub_mainloop:
1630 $LDU r7,$BNSZ(r4)
1631 $LDU r8,$BNSZ(r5)
1632 subfe r6,r8,r7 # r6 = r7+carry bit + onescomplement(r8)
1633 # if carry = 1 this is r7-r8. Else it
1634 # is r7-r8 -1 as we need.
1635 $STU r6,$BNSZ(r3)
1636 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_sub_mainloop
1637Lppcasm_sub_adios:
1638 subfze r3,r0 # if carry bit is set then r3 = 0 else -1
1639 andi. r3,r3,1 # keep only last bit.
1640 bclr BO_ALWAYS,CR0_LT
1641 .long 0x00000000
1642
1643
1644#
1645# NOTE: The following label name should be changed to
1646# "bn_add_words" i.e. remove the first dot
1647# for the gcc compiler. This should be automatically
1648# done in the build
1649#
1650
1651.align 4
1652.bn_add_words:
1653#
1654# Handcoded version of bn_add_words
1655#
1656#BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1657#
1658# r3 = r
1659# r4 = a
1660# r5 = b
1661# r6 = n
1662#
1663# Note: No loop unrolling done since this is not a performance
1664# critical loop.
1665
1666 xor r0,r0,r0
1667#
1668# check for r6 = 0. Is this needed?
1669#
1670 addic. r6,r6,0 #test r6 and clear carry bit.
1671 bc BO_IF,CR0_EQ,Lppcasm_add_adios
1672 addi r4,r4,-$BNSZ
1673 addi r3,r3,-$BNSZ
1674 addi r5,r5,-$BNSZ
1675 mtctr r6
1676Lppcasm_add_mainloop:
1677 $LDU r7,$BNSZ(r4)
1678 $LDU r8,$BNSZ(r5)
1679 adde r8,r7,r8
1680 $STU r8,$BNSZ(r3)
1681 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_add_mainloop
1682Lppcasm_add_adios:
1683 addze r3,r0 #return carry bit.
1684 bclr BO_ALWAYS,CR0_LT
1685 .long 0x00000000
1686
1687#
1688# NOTE: The following label name should be changed to
1689# "bn_div_words" i.e. remove the first dot
1690# for the gcc compiler. This should be automatically
1691# done in the build
1692#
1693
1694.align 4
1695.bn_div_words:
1696#
1697# This is a cleaned up version of code generated by
1698# the AIX compiler. The only optimization is to use
1699# the PPC instruction to count leading zeros instead
1700# of call to num_bits_word. Since this was compiled
1701# only at level -O2 we can possibly squeeze it more?
1702#
1703# r3 = h
1704# r4 = l
1705# r5 = d
1706
1707 $UCMPI 0,r5,0 # compare r5 and 0
1708 bc BO_IF_NOT,CR0_EQ,Lppcasm_div1 # proceed if d!=0
1709 li r3,-1 # d=0 return -1
1710 bclr BO_ALWAYS,CR0_LT
1711Lppcasm_div1:
1712 xor r0,r0,r0 #r0=0
1713 $COUNTZ r7,r5 #r7 = num leading 0s in d.
1714 subfic r8,r7,$BITS #r8 = BN_num_bits_word(d)
1715 cmpi 0,0,r8,$BITS #
1716 bc BO_IF,CR0_EQ,Lppcasm_div2 #proceed if (r8==$BITS)
1717 li r9,1 # r9=1
1718 $SHL r10,r9,r8 # r9<<=r8
1719 $UCMP 0,r3,r10 #
1720 bc BO_IF,CR0_GT,Lppcasm_div2 #or if (h > (1<<r8))
1721 $UDIV r3,r3,r0 #if not assert(0) divide by 0!
1722 #that's how we signal overflow
1723 bclr BO_ALWAYS,CR0_LT #return. NEVER REACHED.
1724Lppcasm_div2:
1725 $UCMP 0,r3,r5 #h>=d?
1726 bc BO_IF,CR0_LT,Lppcasm_div3 #goto Lppcasm_div3 if not
1727 subf r3,r5,r3 #h-=d ;
1728Lppcasm_div3: #r7 = BN_BITS2-i. so r7=i
1729 cmpi 0,0,r7,0 # is (i == 0)?
1730 bc BO_IF,CR0_EQ,Lppcasm_div4
1731 $SHL r3,r3,r7 # h = (h<< i)
1732 $SHR r8,r4,r8 # r8 = (l >> BN_BITS2 -i)
1733 $SHL r5,r5,r7 # d<<=i
1734 or r3,r3,r8 # h = (h<<i)|(l>>(BN_BITS2-i))
1735 $SHL r4,r4,r7 # l <<=i
1736Lppcasm_div4:
1737 $SHRI r9,r5,`$BITS/2` # r9 = dh
1738 # dl will be computed when needed
1739 # as it saves registers.
1740 li r6,2 #r6=2
1741 mtctr r6 #counter will be in count.
1742Lppcasm_divouterloop:
1743 $SHRI r8,r3,`$BITS/2` #r8 = (h>>BN_BITS4)
1744 $SHRI r11,r4,`$BITS/2` #r11= (l&BN_MASK2h)>>BN_BITS4
1745 # compute here for innerloop.
1746 $UCMP 0,r8,r9 # is (h>>BN_BITS4)==dh
1747 bc BO_IF_NOT,CR0_EQ,Lppcasm_div5 # goto Lppcasm_div5 if not
1748
1749 li r8,-1
1750 $CLRU r8,r8,`$BITS/2` #q = BN_MASK2l
1751 b Lppcasm_div6
1752Lppcasm_div5:
1753 $UDIV r8,r3,r9 #q = h/dh
1754Lppcasm_div6:
1755 $UMULL r12,r9,r8 #th = q*dh
1756 $CLRU r10,r5,`$BITS/2` #r10=dl
1757 $UMULL r6,r8,r10 #tl = q*dl
1758
1759Lppcasm_divinnerloop:
1760 subf r10,r12,r3 #t = h -th
1761 $SHRI r7,r10,`$BITS/2` #r7= (t &BN_MASK2H), sort of...
1762 addic. r7,r7,0 #test if r7 == 0. used below.
1763 # now want to compute
1764 # r7 = (t<<BN_BITS4)|((l&BN_MASK2h)>>BN_BITS4)
1765 # the following 2 instructions do that
1766 $SHLI r7,r10,`$BITS/2` # r7 = (t<<BN_BITS4)
1767 or r7,r7,r11 # r7|=((l&BN_MASK2h)>>BN_BITS4)
1768 $UCMP 1,r6,r7 # compare (tl <= r7)
1769 bc BO_IF_NOT,CR0_EQ,Lppcasm_divinnerexit
1770 bc BO_IF_NOT,CR1_FEX,Lppcasm_divinnerexit
1771 addi r8,r8,-1 #q--
1772 subf r12,r9,r12 #th -=dh
1773 $CLRU r10,r5,`$BITS/2` #r10=dl. t is no longer needed in loop.
1774 subf r6,r10,r6 #tl -=dl
1775 b Lppcasm_divinnerloop
1776Lppcasm_divinnerexit:
1777 $SHRI r10,r6,`$BITS/2` #t=(tl>>BN_BITS4)
1778 $SHLI r11,r6,`$BITS/2` #tl=(tl<<BN_BITS4)&BN_MASK2h;
1779 $UCMP 1,r4,r11 # compare l and tl
1780 add r12,r12,r10 # th+=t
1781 bc BO_IF_NOT,CR1_FX,Lppcasm_div7 # if (l>=tl) goto Lppcasm_div7
1782 addi r12,r12,1 # th++
1783Lppcasm_div7:
1784 subf r11,r11,r4 #r11=l-tl
1785 $UCMP 1,r3,r12 #compare h and th
1786 bc BO_IF_NOT,CR1_FX,Lppcasm_div8 #if (h>=th) goto Lppcasm_div8
1787 addi r8,r8,-1 # q--
1788 add r3,r5,r3 # h+=d
1789Lppcasm_div8:
1790 subf r12,r12,r3 #r12 = h-th
1791 $SHLI r4,r11,`$BITS/2` #l=(l&BN_MASK2l)<<BN_BITS4
1792 # want to compute
1793 # h = ((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2
1794 # the following 2 instructions will do this.
1795 $INSR r11,r12,`$BITS/2`,`$BITS/2` # r11 is the value we want rotated $BITS/2.
1796 $ROTL r3,r11,`$BITS/2` # rotate by $BITS/2 and store in r3
1797 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_div9#if (count==0) break ;
1798 $SHLI r0,r8,`$BITS/2` #ret =q<<BN_BITS4
1799 b Lppcasm_divouterloop
1800Lppcasm_div9:
1801 or r3,r8,r0
1802 bclr BO_ALWAYS,CR0_LT
1803 .long 0x00000000
1804
1805#
1806# NOTE: The following label name should be changed to
1807# "bn_sqr_words" i.e. remove the first dot
1808# for the gcc compiler. This should be automatically
1809# done in the build
1810#
1811.align 4
1812.bn_sqr_words:
1813#
1814# Optimized version of bn_sqr_words
1815#
1816# void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
1817#
1818# r3 = r
1819# r4 = a
1820# r5 = n
1821#
1822# r6 = a[i].
1823# r7,r8 = product.
1824#
1825# No unrolling done here. Not performance critical.
1826
1827 addic. r5,r5,0 #test r5.
1828 bc BO_IF,CR0_EQ,Lppcasm_sqr_adios
1829 addi r4,r4,-$BNSZ
1830 addi r3,r3,-$BNSZ
1831 mtctr r5
1832Lppcasm_sqr_mainloop:
1833 #sqr(r[0],r[1],a[0]);
1834 $LDU r6,$BNSZ(r4)
1835 $UMULL r7,r6,r6
1836 $UMULH r8,r6,r6
1837 $STU r7,$BNSZ(r3)
1838 $STU r8,$BNSZ(r3)
1839 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_sqr_mainloop
1840Lppcasm_sqr_adios:
1841 bclr BO_ALWAYS,CR0_LT
1842 .long 0x00000000
1843
1844
1845#
1846# NOTE: The following label name should be changed to
1847# "bn_mul_words" i.e. remove the first dot
1848# for the gcc compiler. This should be automatically
1849# done in the build
1850#
1851
1852.align 4
1853.bn_mul_words:
1854#
1855# BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
1856#
1857# r3 = rp
1858# r4 = ap
1859# r5 = num
1860# r6 = w
1861 xor r0,r0,r0
1862 xor r12,r12,r12 # used for carry
1863 rlwinm. r7,r5,30,2,31 # num >> 2
1864 bc BO_IF,CR0_EQ,Lppcasm_mw_REM
1865 mtctr r7
1866Lppcasm_mw_LOOP:
1867 #mul(rp[0],ap[0],w,c1);
1868 $LD r8,`0*$BNSZ`(r4)
1869 $UMULL r9,r6,r8
1870 $UMULH r10,r6,r8
1871 addc r9,r9,r12
1872 #addze r10,r10 #carry is NOT ignored.
1873 #will be taken care of
1874 #in second spin below
1875 #using adde.
1876 $ST r9,`0*$BNSZ`(r3)
1877 #mul(rp[1],ap[1],w,c1);
1878 $LD r8,`1*$BNSZ`(r4)
1879 $UMULL r11,r6,r8
1880 $UMULH r12,r6,r8
1881 adde r11,r11,r10
1882 #addze r12,r12
1883 $ST r11,`1*$BNSZ`(r3)
1884 #mul(rp[2],ap[2],w,c1);
1885 $LD r8,`2*$BNSZ`(r4)
1886 $UMULL r9,r6,r8
1887 $UMULH r10,r6,r8
1888 adde r9,r9,r12
1889 #addze r10,r10
1890 $ST r9,`2*$BNSZ`(r3)
1891 #mul_add(rp[3],ap[3],w,c1);
1892 $LD r8,`3*$BNSZ`(r4)
1893 $UMULL r11,r6,r8
1894 $UMULH r12,r6,r8
1895 adde r11,r11,r10
1896 addze r12,r12 #this spin we collect carry into
1897 #r12
1898 $ST r11,`3*$BNSZ`(r3)
1899
1900 addi r3,r3,`4*$BNSZ`
1901 addi r4,r4,`4*$BNSZ`
1902 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_mw_LOOP
1903
1904Lppcasm_mw_REM:
1905 andi. r5,r5,0x3
1906 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1907 #mul(rp[0],ap[0],w,c1);
1908 $LD r8,`0*$BNSZ`(r4)
1909 $UMULL r9,r6,r8
1910 $UMULH r10,r6,r8
1911 addc r9,r9,r12
1912 addze r10,r10
1913 $ST r9,`0*$BNSZ`(r3)
1914 addi r12,r10,0
1915
1916 addi r5,r5,-1
1917 cmpli 0,0,r5,0
1918 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1919
1920
1921 #mul(rp[1],ap[1],w,c1);
1922 $LD r8,`1*$BNSZ`(r4)
1923 $UMULL r9,r6,r8
1924 $UMULH r10,r6,r8
1925 addc r9,r9,r12
1926 addze r10,r10
1927 $ST r9,`1*$BNSZ`(r3)
1928 addi r12,r10,0
1929
1930 addi r5,r5,-1
1931 cmpli 0,0,r5,0
1932 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1933
1934 #mul_add(rp[2],ap[2],w,c1);
1935 $LD r8,`2*$BNSZ`(r4)
1936 $UMULL r9,r6,r8
1937 $UMULH r10,r6,r8
1938 addc r9,r9,r12
1939 addze r10,r10
1940 $ST r9,`2*$BNSZ`(r3)
1941 addi r12,r10,0
1942
1943Lppcasm_mw_OVER:
1944 addi r3,r12,0
1945 bclr BO_ALWAYS,CR0_LT
1946 .long 0x00000000
1947
1948#
1949# NOTE: The following label name should be changed to
1950# "bn_mul_add_words" i.e. remove the first dot
1951# for the gcc compiler. This should be automatically
1952# done in the build
1953#
1954
1955.align 4
1956.bn_mul_add_words:
1957#
1958# BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
1959#
1960# r3 = rp
1961# r4 = ap
1962# r5 = num
1963# r6 = w
1964#
1965# empirical evidence suggests that unrolled version performs best!!
1966#
1967 xor r0,r0,r0 #r0 = 0
1968 xor r12,r12,r12 #r12 = 0 . used for carry
1969 rlwinm. r7,r5,30,2,31 # num >> 2
1970 bc BO_IF,CR0_EQ,Lppcasm_maw_leftover # if (num < 4) go LPPCASM_maw_leftover
1971 mtctr r7
1972Lppcasm_maw_mainloop:
1973 #mul_add(rp[0],ap[0],w,c1);
1974 $LD r8,`0*$BNSZ`(r4)
1975 $LD r11,`0*$BNSZ`(r3)
1976 $UMULL r9,r6,r8
1977 $UMULH r10,r6,r8
1978 addc r9,r9,r12 #r12 is carry.
1979 addze r10,r10
1980 addc r9,r9,r11
1981 #addze r10,r10
1982 #the above instruction addze
1983 #is NOT needed. Carry will NOT
1984 #be ignored. It's not affected
1985 #by multiply and will be collected
1986 #in the next spin
1987 $ST r9,`0*$BNSZ`(r3)
1988
1989 #mul_add(rp[1],ap[1],w,c1);
1990 $LD r8,`1*$BNSZ`(r4)
1991 $LD r9,`1*$BNSZ`(r3)
1992 $UMULL r11,r6,r8
1993 $UMULH r12,r6,r8
1994 adde r11,r11,r10 #r10 is carry.
1995 addze r12,r12
1996 addc r11,r11,r9
1997 #addze r12,r12
1998 $ST r11,`1*$BNSZ`(r3)
1999
2000 #mul_add(rp[2],ap[2],w,c1);
2001 $LD r8,`2*$BNSZ`(r4)
2002 $UMULL r9,r6,r8
2003 $LD r11,`2*$BNSZ`(r3)
2004 $UMULH r10,r6,r8
2005 adde r9,r9,r12
2006 addze r10,r10
2007 addc r9,r9,r11
2008 #addze r10,r10
2009 $ST r9,`2*$BNSZ`(r3)
2010
2011 #mul_add(rp[3],ap[3],w,c1);
2012 $LD r8,`3*$BNSZ`(r4)
2013 $UMULL r11,r6,r8
2014 $LD r9,`3*$BNSZ`(r3)
2015 $UMULH r12,r6,r8
2016 adde r11,r11,r10
2017 addze r12,r12
2018 addc r11,r11,r9
2019 addze r12,r12
2020 $ST r11,`3*$BNSZ`(r3)
2021 addi r3,r3,`4*$BNSZ`
2022 addi r4,r4,`4*$BNSZ`
2023 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_maw_mainloop
2024
2025Lppcasm_maw_leftover:
2026 andi. r5,r5,0x3
2027 bc BO_IF,CR0_EQ,Lppcasm_maw_adios
2028 addi r3,r3,-$BNSZ
2029 addi r4,r4,-$BNSZ
2030 #mul_add(rp[0],ap[0],w,c1);
2031 mtctr r5
2032 $LDU r8,$BNSZ(r4)
2033 $UMULL r9,r6,r8
2034 $UMULH r10,r6,r8
2035 $LDU r11,$BNSZ(r3)
2036 addc r9,r9,r11
2037 addze r10,r10
2038 addc r9,r9,r12
2039 addze r12,r10
2040 $ST r9,0(r3)
2041
2042 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
2043 #mul_add(rp[1],ap[1],w,c1);
2044 $LDU r8,$BNSZ(r4)
2045 $UMULL r9,r6,r8
2046 $UMULH r10,r6,r8
2047 $LDU r11,$BNSZ(r3)
2048 addc r9,r9,r11
2049 addze r10,r10
2050 addc r9,r9,r12
2051 addze r12,r10
2052 $ST r9,0(r3)
2053
2054 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
2055 #mul_add(rp[2],ap[2],w,c1);
2056 $LDU r8,$BNSZ(r4)
2057 $UMULL r9,r6,r8
2058 $UMULH r10,r6,r8
2059 $LDU r11,$BNSZ(r3)
2060 addc r9,r9,r11
2061 addze r10,r10
2062 addc r9,r9,r12
2063 addze r12,r10
2064 $ST r9,0(r3)
2065
2066Lppcasm_maw_adios:
2067 addi r3,r12,0
2068 bclr BO_ALWAYS,CR0_LT
2069 .long 0x00000000
2070 .align 4
2071EOF
2072 $data =~ s/\`([^\`]*)\`/eval $1/gem;
2073
2074 # if some assembler chokes on some simplified mnemonic,
2075 # this is the spot to fix it up, e.g.:
2076 # GNU as doesn't seem to accept cmplw, 32-bit unsigned compare
2077 $data =~ s/^(\s*)cmplw(\s+)([^,]+),(.*)/$1cmpl$2$3,0,$4/gm;
2078 # assembler X doesn't accept li, load immediate value
2079 #$data =~ s/^(\s*)li(\s+)([^,]+),(.*)/$1addi$2$3,0,$4/gm;
2080 return($data);
2081}
diff --git a/src/lib/libcrypto/bn/asm/sparcv8.S b/src/lib/libcrypto/bn/asm/sparcv8.S
new file mode 100644
index 0000000000..88c5dc480a
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/sparcv8.S
@@ -0,0 +1,1458 @@
1.ident "sparcv8.s, Version 1.4"
2.ident "SPARC v8 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in SuperSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * See bn_asm.sparc.v8plus.S for more details.
22 */
23
24/*
25 * Revision history.
26 *
27 * 1.1 - new loop unrolling model(*);
28 * 1.2 - made gas friendly;
29 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
30 * 1.4 - some retunes;
31 *
32 * (*) see bn_asm.sparc.v8plus.S for details
33 */
34
35.section ".text",#alloc,#execinstr
36.file "bn_asm.sparc.v8.S"
37
38.align 32
39
40.global bn_mul_add_words
41/*
42 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
43 * BN_ULONG *rp,*ap;
44 * int num;
45 * BN_ULONG w;
46 */
47bn_mul_add_words:
48 cmp %o2,0
49 bg,a .L_bn_mul_add_words_proceed
50 ld [%o1],%g2
51 retl
52 clr %o0
53
54.L_bn_mul_add_words_proceed:
55 andcc %o2,-4,%g0
56 bz .L_bn_mul_add_words_tail
57 clr %o5
58
59.L_bn_mul_add_words_loop:
60 ld [%o0],%o4
61 ld [%o1+4],%g3
62 umul %o3,%g2,%g2
63 rd %y,%g1
64 addcc %o4,%o5,%o4
65 addx %g1,0,%g1
66 addcc %o4,%g2,%o4
67 st %o4,[%o0]
68 addx %g1,0,%o5
69
70 ld [%o0+4],%o4
71 ld [%o1+8],%g2
72 umul %o3,%g3,%g3
73 dec 4,%o2
74 rd %y,%g1
75 addcc %o4,%o5,%o4
76 addx %g1,0,%g1
77 addcc %o4,%g3,%o4
78 st %o4,[%o0+4]
79 addx %g1,0,%o5
80
81 ld [%o0+8],%o4
82 ld [%o1+12],%g3
83 umul %o3,%g2,%g2
84 inc 16,%o1
85 rd %y,%g1
86 addcc %o4,%o5,%o4
87 addx %g1,0,%g1
88 addcc %o4,%g2,%o4
89 st %o4,[%o0+8]
90 addx %g1,0,%o5
91
92 ld [%o0+12],%o4
93 umul %o3,%g3,%g3
94 inc 16,%o0
95 rd %y,%g1
96 addcc %o4,%o5,%o4
97 addx %g1,0,%g1
98 addcc %o4,%g3,%o4
99 st %o4,[%o0-4]
100 addx %g1,0,%o5
101 andcc %o2,-4,%g0
102 bnz,a .L_bn_mul_add_words_loop
103 ld [%o1],%g2
104
105 tst %o2
106 bnz,a .L_bn_mul_add_words_tail
107 ld [%o1],%g2
108.L_bn_mul_add_words_return:
109 retl
110 mov %o5,%o0
111 nop
112
113.L_bn_mul_add_words_tail:
114 ld [%o0],%o4
115 umul %o3,%g2,%g2
116 addcc %o4,%o5,%o4
117 rd %y,%g1
118 addx %g1,0,%g1
119 addcc %o4,%g2,%o4
120 addx %g1,0,%o5
121 deccc %o2
122 bz .L_bn_mul_add_words_return
123 st %o4,[%o0]
124
125 ld [%o1+4],%g2
126 ld [%o0+4],%o4
127 umul %o3,%g2,%g2
128 rd %y,%g1
129 addcc %o4,%o5,%o4
130 addx %g1,0,%g1
131 addcc %o4,%g2,%o4
132 addx %g1,0,%o5
133 deccc %o2
134 bz .L_bn_mul_add_words_return
135 st %o4,[%o0+4]
136
137 ld [%o1+8],%g2
138 ld [%o0+8],%o4
139 umul %o3,%g2,%g2
140 rd %y,%g1
141 addcc %o4,%o5,%o4
142 addx %g1,0,%g1
143 addcc %o4,%g2,%o4
144 st %o4,[%o0+8]
145 retl
146 addx %g1,0,%o0
147
148.type bn_mul_add_words,#function
149.size bn_mul_add_words,(.-bn_mul_add_words)
150
151.align 32
152
153.global bn_mul_words
154/*
155 * BN_ULONG bn_mul_words(rp,ap,num,w)
156 * BN_ULONG *rp,*ap;
157 * int num;
158 * BN_ULONG w;
159 */
160bn_mul_words:
161 cmp %o2,0
162 bg,a .L_bn_mul_words_proceeed
163 ld [%o1],%g2
164 retl
165 clr %o0
166
167.L_bn_mul_words_proceeed:
168 andcc %o2,-4,%g0
169 bz .L_bn_mul_words_tail
170 clr %o5
171
172.L_bn_mul_words_loop:
173 ld [%o1+4],%g3
174 umul %o3,%g2,%g2
175 addcc %g2,%o5,%g2
176 rd %y,%g1
177 addx %g1,0,%o5
178 st %g2,[%o0]
179
180 ld [%o1+8],%g2
181 umul %o3,%g3,%g3
182 addcc %g3,%o5,%g3
183 rd %y,%g1
184 dec 4,%o2
185 addx %g1,0,%o5
186 st %g3,[%o0+4]
187
188 ld [%o1+12],%g3
189 umul %o3,%g2,%g2
190 addcc %g2,%o5,%g2
191 rd %y,%g1
192 inc 16,%o1
193 st %g2,[%o0+8]
194 addx %g1,0,%o5
195
196 umul %o3,%g3,%g3
197 addcc %g3,%o5,%g3
198 rd %y,%g1
199 inc 16,%o0
200 addx %g1,0,%o5
201 st %g3,[%o0-4]
202 andcc %o2,-4,%g0
203 nop
204 bnz,a .L_bn_mul_words_loop
205 ld [%o1],%g2
206
207 tst %o2
208 bnz,a .L_bn_mul_words_tail
209 ld [%o1],%g2
210.L_bn_mul_words_return:
211 retl
212 mov %o5,%o0
213 nop
214
215.L_bn_mul_words_tail:
216 umul %o3,%g2,%g2
217 addcc %g2,%o5,%g2
218 rd %y,%g1
219 addx %g1,0,%o5
220 deccc %o2
221 bz .L_bn_mul_words_return
222 st %g2,[%o0]
223 nop
224
225 ld [%o1+4],%g2
226 umul %o3,%g2,%g2
227 addcc %g2,%o5,%g2
228 rd %y,%g1
229 addx %g1,0,%o5
230 deccc %o2
231 bz .L_bn_mul_words_return
232 st %g2,[%o0+4]
233
234 ld [%o1+8],%g2
235 umul %o3,%g2,%g2
236 addcc %g2,%o5,%g2
237 rd %y,%g1
238 st %g2,[%o0+8]
239 retl
240 addx %g1,0,%o0
241
242.type bn_mul_words,#function
243.size bn_mul_words,(.-bn_mul_words)
244
245.align 32
246.global bn_sqr_words
247/*
248 * void bn_sqr_words(r,a,n)
249 * BN_ULONG *r,*a;
250 * int n;
251 */
252bn_sqr_words:
253 cmp %o2,0
254 bg,a .L_bn_sqr_words_proceeed
255 ld [%o1],%g2
256 retl
257 clr %o0
258
259.L_bn_sqr_words_proceeed:
260 andcc %o2,-4,%g0
261 bz .L_bn_sqr_words_tail
262 clr %o5
263
264.L_bn_sqr_words_loop:
265 ld [%o1+4],%g3
266 umul %g2,%g2,%o4
267 st %o4,[%o0]
268 rd %y,%o5
269 st %o5,[%o0+4]
270
271 ld [%o1+8],%g2
272 umul %g3,%g3,%o4
273 dec 4,%o2
274 st %o4,[%o0+8]
275 rd %y,%o5
276 st %o5,[%o0+12]
277 nop
278
279 ld [%o1+12],%g3
280 umul %g2,%g2,%o4
281 st %o4,[%o0+16]
282 rd %y,%o5
283 inc 16,%o1
284 st %o5,[%o0+20]
285
286 umul %g3,%g3,%o4
287 inc 32,%o0
288 st %o4,[%o0-8]
289 rd %y,%o5
290 st %o5,[%o0-4]
291 andcc %o2,-4,%g2
292 bnz,a .L_bn_sqr_words_loop
293 ld [%o1],%g2
294
295 tst %o2
296 nop
297 bnz,a .L_bn_sqr_words_tail
298 ld [%o1],%g2
299.L_bn_sqr_words_return:
300 retl
301 clr %o0
302
303.L_bn_sqr_words_tail:
304 umul %g2,%g2,%o4
305 st %o4,[%o0]
306 deccc %o2
307 rd %y,%o5
308 bz .L_bn_sqr_words_return
309 st %o5,[%o0+4]
310
311 ld [%o1+4],%g2
312 umul %g2,%g2,%o4
313 st %o4,[%o0+8]
314 deccc %o2
315 rd %y,%o5
316 nop
317 bz .L_bn_sqr_words_return
318 st %o5,[%o0+12]
319
320 ld [%o1+8],%g2
321 umul %g2,%g2,%o4
322 st %o4,[%o0+16]
323 rd %y,%o5
324 st %o5,[%o0+20]
325 retl
326 clr %o0
327
328.type bn_sqr_words,#function
329.size bn_sqr_words,(.-bn_sqr_words)
330
331.align 32
332
333.global bn_div_words
334/*
335 * BN_ULONG bn_div_words(h,l,d)
336 * BN_ULONG h,l,d;
337 */
338bn_div_words:
339 wr %o0,%y
340 udiv %o1,%o2,%o0
341 retl
342 nop
343
344.type bn_div_words,#function
345.size bn_div_words,(.-bn_div_words)
346
347.align 32
348
349.global bn_add_words
350/*
351 * BN_ULONG bn_add_words(rp,ap,bp,n)
352 * BN_ULONG *rp,*ap,*bp;
353 * int n;
354 */
355bn_add_words:
356 cmp %o3,0
357 bg,a .L_bn_add_words_proceed
358 ld [%o1],%o4
359 retl
360 clr %o0
361
362.L_bn_add_words_proceed:
363 andcc %o3,-4,%g0
364 bz .L_bn_add_words_tail
365 clr %g1
366 ba .L_bn_add_words_warn_loop
367 addcc %g0,0,%g0 ! clear carry flag
368
369.L_bn_add_words_loop:
370 ld [%o1],%o4
371.L_bn_add_words_warn_loop:
372 ld [%o2],%o5
373 ld [%o1+4],%g3
374 ld [%o2+4],%g4
375 dec 4,%o3
376 addxcc %o5,%o4,%o5
377 st %o5,[%o0]
378
379 ld [%o1+8],%o4
380 ld [%o2+8],%o5
381 inc 16,%o1
382 addxcc %g3,%g4,%g3
383 st %g3,[%o0+4]
384
385 ld [%o1-4],%g3
386 ld [%o2+12],%g4
387 inc 16,%o2
388 addxcc %o5,%o4,%o5
389 st %o5,[%o0+8]
390
391 inc 16,%o0
392 addxcc %g3,%g4,%g3
393 st %g3,[%o0-4]
394 addx %g0,0,%g1
395 andcc %o3,-4,%g0
396 bnz,a .L_bn_add_words_loop
397 addcc %g1,-1,%g0
398
399 tst %o3
400 bnz,a .L_bn_add_words_tail
401 ld [%o1],%o4
402.L_bn_add_words_return:
403 retl
404 mov %g1,%o0
405
406.L_bn_add_words_tail:
407 addcc %g1,-1,%g0
408 ld [%o2],%o5
409 addxcc %o5,%o4,%o5
410 addx %g0,0,%g1
411 deccc %o3
412 bz .L_bn_add_words_return
413 st %o5,[%o0]
414
415 ld [%o1+4],%o4
416 addcc %g1,-1,%g0
417 ld [%o2+4],%o5
418 addxcc %o5,%o4,%o5
419 addx %g0,0,%g1
420 deccc %o3
421 bz .L_bn_add_words_return
422 st %o5,[%o0+4]
423
424 ld [%o1+8],%o4
425 addcc %g1,-1,%g0
426 ld [%o2+8],%o5
427 addxcc %o5,%o4,%o5
428 st %o5,[%o0+8]
429 retl
430 addx %g0,0,%o0
431
432.type bn_add_words,#function
433.size bn_add_words,(.-bn_add_words)
434
435.align 32
436
437.global bn_sub_words
438/*
439 * BN_ULONG bn_sub_words(rp,ap,bp,n)
440 * BN_ULONG *rp,*ap,*bp;
441 * int n;
442 */
443bn_sub_words:
444 cmp %o3,0
445 bg,a .L_bn_sub_words_proceed
446 ld [%o1],%o4
447 retl
448 clr %o0
449
450.L_bn_sub_words_proceed:
451 andcc %o3,-4,%g0
452 bz .L_bn_sub_words_tail
453 clr %g1
454 ba .L_bn_sub_words_warm_loop
455 addcc %g0,0,%g0 ! clear carry flag
456
457.L_bn_sub_words_loop:
458 ld [%o1],%o4
459.L_bn_sub_words_warm_loop:
460 ld [%o2],%o5
461 ld [%o1+4],%g3
462 ld [%o2+4],%g4
463 dec 4,%o3
464 subxcc %o4,%o5,%o5
465 st %o5,[%o0]
466
467 ld [%o1+8],%o4
468 ld [%o2+8],%o5
469 inc 16,%o1
470 subxcc %g3,%g4,%g4
471 st %g4,[%o0+4]
472
473 ld [%o1-4],%g3
474 ld [%o2+12],%g4
475 inc 16,%o2
476 subxcc %o4,%o5,%o5
477 st %o5,[%o0+8]
478
479 inc 16,%o0
480 subxcc %g3,%g4,%g4
481 st %g4,[%o0-4]
482 addx %g0,0,%g1
483 andcc %o3,-4,%g0
484 bnz,a .L_bn_sub_words_loop
485 addcc %g1,-1,%g0
486
487 tst %o3
488 nop
489 bnz,a .L_bn_sub_words_tail
490 ld [%o1],%o4
491.L_bn_sub_words_return:
492 retl
493 mov %g1,%o0
494
495.L_bn_sub_words_tail:
496 addcc %g1,-1,%g0
497 ld [%o2],%o5
498 subxcc %o4,%o5,%o5
499 addx %g0,0,%g1
500 deccc %o3
501 bz .L_bn_sub_words_return
502 st %o5,[%o0]
503 nop
504
505 ld [%o1+4],%o4
506 addcc %g1,-1,%g0
507 ld [%o2+4],%o5
508 subxcc %o4,%o5,%o5
509 addx %g0,0,%g1
510 deccc %o3
511 bz .L_bn_sub_words_return
512 st %o5,[%o0+4]
513
514 ld [%o1+8],%o4
515 addcc %g1,-1,%g0
516 ld [%o2+8],%o5
517 subxcc %o4,%o5,%o5
518 st %o5,[%o0+8]
519 retl
520 addx %g0,0,%o0
521
522.type bn_sub_words,#function
523.size bn_sub_words,(.-bn_sub_words)
524
525#define FRAME_SIZE -96
526
527/*
528 * Here is register usage map for *all* routines below.
529 */
530#define t_1 %o0
531#define t_2 %o1
532#define c_1 %o2
533#define c_2 %o3
534#define c_3 %o4
535
536#define ap(I) [%i1+4*I]
537#define bp(I) [%i2+4*I]
538#define rp(I) [%i0+4*I]
539
540#define a_0 %l0
541#define a_1 %l1
542#define a_2 %l2
543#define a_3 %l3
544#define a_4 %l4
545#define a_5 %l5
546#define a_6 %l6
547#define a_7 %l7
548
549#define b_0 %i3
550#define b_1 %i4
551#define b_2 %i5
552#define b_3 %o5
553#define b_4 %g1
554#define b_5 %g2
555#define b_6 %g3
556#define b_7 %g4
557
558.align 32
559.global bn_mul_comba8
560/*
561 * void bn_mul_comba8(r,a,b)
562 * BN_ULONG *r,*a,*b;
563 */
564bn_mul_comba8:
565 save %sp,FRAME_SIZE,%sp
566 ld ap(0),a_0
567 ld bp(0),b_0
568 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
569 ld bp(1),b_1
570 rd %y,c_2
571 st c_1,rp(0) !r[0]=c1;
572
573 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
574 ld ap(1),a_1
575 addcc c_2,t_1,c_2
576 rd %y,t_2
577 addxcc %g0,t_2,c_3 !=
578 addx %g0,%g0,c_1
579 ld ap(2),a_2
580 umul a_1,b_0,t_1 !mul_add_c(a[1],b[0],c2,c3,c1);
581 addcc c_2,t_1,c_2 !=
582 rd %y,t_2
583 addxcc c_3,t_2,c_3
584 st c_2,rp(1) !r[1]=c2;
585 addx c_1,%g0,c_1 !=
586
587 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
588 addcc c_3,t_1,c_3
589 rd %y,t_2
590 addxcc c_1,t_2,c_1 !=
591 addx %g0,%g0,c_2
592 ld bp(2),b_2
593 umul a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
594 addcc c_3,t_1,c_3 !=
595 rd %y,t_2
596 addxcc c_1,t_2,c_1
597 ld bp(3),b_3
598 addx c_2,%g0,c_2 !=
599 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
600 addcc c_3,t_1,c_3
601 rd %y,t_2
602 addxcc c_1,t_2,c_1 !=
603 addx c_2,%g0,c_2
604 st c_3,rp(2) !r[2]=c3;
605
606 umul a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
607 addcc c_1,t_1,c_1 !=
608 rd %y,t_2
609 addxcc c_2,t_2,c_2
610 addx %g0,%g0,c_3
611 umul a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
612 addcc c_1,t_1,c_1
613 rd %y,t_2
614 addxcc c_2,t_2,c_2
615 addx c_3,%g0,c_3 !=
616 ld ap(3),a_3
617 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
618 addcc c_1,t_1,c_1
619 rd %y,t_2 !=
620 addxcc c_2,t_2,c_2
621 addx c_3,%g0,c_3
622 ld ap(4),a_4
623 umul a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
624 addcc c_1,t_1,c_1
625 rd %y,t_2
626 addxcc c_2,t_2,c_2
627 addx c_3,%g0,c_3 !=
628 st c_1,rp(3) !r[3]=c1;
629
630 umul a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
631 addcc c_2,t_1,c_2
632 rd %y,t_2 !=
633 addxcc c_3,t_2,c_3
634 addx %g0,%g0,c_1
635 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
636 addcc c_2,t_1,c_2 !=
637 rd %y,t_2
638 addxcc c_3,t_2,c_3
639 addx c_1,%g0,c_1
640 umul a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
641 addcc c_2,t_1,c_2
642 rd %y,t_2
643 addxcc c_3,t_2,c_3
644 addx c_1,%g0,c_1 !=
645 ld bp(4),b_4
646 umul a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
647 addcc c_2,t_1,c_2
648 rd %y,t_2 !=
649 addxcc c_3,t_2,c_3
650 addx c_1,%g0,c_1
651 ld bp(5),b_5
652 umul a_0,b_4,t_1 !=!mul_add_c(a[0],b[4],c2,c3,c1);
653 addcc c_2,t_1,c_2
654 rd %y,t_2
655 addxcc c_3,t_2,c_3
656 addx c_1,%g0,c_1 !=
657 st c_2,rp(4) !r[4]=c2;
658
659 umul a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
660 addcc c_3,t_1,c_3
661 rd %y,t_2 !=
662 addxcc c_1,t_2,c_1
663 addx %g0,%g0,c_2
664 umul a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
665 addcc c_3,t_1,c_3 !=
666 rd %y,t_2
667 addxcc c_1,t_2,c_1
668 addx c_2,%g0,c_2
669 umul a_2,b_3,t_1 !=!mul_add_c(a[2],b[3],c3,c1,c2);
670 addcc c_3,t_1,c_3
671 rd %y,t_2
672 addxcc c_1,t_2,c_1
673 addx c_2,%g0,c_2 !=
674 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
675 addcc c_3,t_1,c_3
676 rd %y,t_2
677 addxcc c_1,t_2,c_1 !=
678 addx c_2,%g0,c_2
679 ld ap(5),a_5
680 umul a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
681 addcc c_3,t_1,c_3 !=
682 rd %y,t_2
683 addxcc c_1,t_2,c_1
684 ld ap(6),a_6
685 addx c_2,%g0,c_2 !=
686 umul a_5,b_0,t_1 !mul_add_c(a[5],b[0],c3,c1,c2);
687 addcc c_3,t_1,c_3
688 rd %y,t_2
689 addxcc c_1,t_2,c_1 !=
690 addx c_2,%g0,c_2
691 st c_3,rp(5) !r[5]=c3;
692
693 umul a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
694 addcc c_1,t_1,c_1 !=
695 rd %y,t_2
696 addxcc c_2,t_2,c_2
697 addx %g0,%g0,c_3
698 umul a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
699 addcc c_1,t_1,c_1
700 rd %y,t_2
701 addxcc c_2,t_2,c_2
702 addx c_3,%g0,c_3 !=
703 umul a_4,b_2,t_1 !mul_add_c(a[4],b[2],c1,c2,c3);
704 addcc c_1,t_1,c_1
705 rd %y,t_2
706 addxcc c_2,t_2,c_2 !=
707 addx c_3,%g0,c_3
708 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
709 addcc c_1,t_1,c_1
710 rd %y,t_2 !=
711 addxcc c_2,t_2,c_2
712 addx c_3,%g0,c_3
713 umul a_2,b_4,t_1 !mul_add_c(a[2],b[4],c1,c2,c3);
714 addcc c_1,t_1,c_1 !=
715 rd %y,t_2
716 addxcc c_2,t_2,c_2
717 ld bp(6),b_6
718 addx c_3,%g0,c_3 !=
719 umul a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
720 addcc c_1,t_1,c_1
721 rd %y,t_2
722 addxcc c_2,t_2,c_2 !=
723 addx c_3,%g0,c_3
724 ld bp(7),b_7
725 umul a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
726 addcc c_1,t_1,c_1 !=
727 rd %y,t_2
728 addxcc c_2,t_2,c_2
729 st c_1,rp(6) !r[6]=c1;
730 addx c_3,%g0,c_3 !=
731
732 umul a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
733 addcc c_2,t_1,c_2
734 rd %y,t_2
735 addxcc c_3,t_2,c_3 !=
736 addx %g0,%g0,c_1
737 umul a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
738 addcc c_2,t_1,c_2
739 rd %y,t_2 !=
740 addxcc c_3,t_2,c_3
741 addx c_1,%g0,c_1
742 umul a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
743 addcc c_2,t_1,c_2 !=
744 rd %y,t_2
745 addxcc c_3,t_2,c_3
746 addx c_1,%g0,c_1
747 umul a_3,b_4,t_1 !=!mul_add_c(a[3],b[4],c2,c3,c1);
748 addcc c_2,t_1,c_2
749 rd %y,t_2
750 addxcc c_3,t_2,c_3
751 addx c_1,%g0,c_1 !=
752 umul a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
753 addcc c_2,t_1,c_2
754 rd %y,t_2
755 addxcc c_3,t_2,c_3 !=
756 addx c_1,%g0,c_1
757 umul a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
758 addcc c_2,t_1,c_2
759 rd %y,t_2 !=
760 addxcc c_3,t_2,c_3
761 addx c_1,%g0,c_1
762 ld ap(7),a_7
763 umul a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
764 addcc c_2,t_1,c_2
765 rd %y,t_2
766 addxcc c_3,t_2,c_3
767 addx c_1,%g0,c_1 !=
768 umul a_7,b_0,t_1 !mul_add_c(a[7],b[0],c2,c3,c1);
769 addcc c_2,t_1,c_2
770 rd %y,t_2
771 addxcc c_3,t_2,c_3 !=
772 addx c_1,%g0,c_1
773 st c_2,rp(7) !r[7]=c2;
774
775 umul a_7,b_1,t_1 !mul_add_c(a[7],b[1],c3,c1,c2);
776 addcc c_3,t_1,c_3 !=
777 rd %y,t_2
778 addxcc c_1,t_2,c_1
779 addx %g0,%g0,c_2
780 umul a_6,b_2,t_1 !=!mul_add_c(a[6],b[2],c3,c1,c2);
781 addcc c_3,t_1,c_3
782 rd %y,t_2
783 addxcc c_1,t_2,c_1
784 addx c_2,%g0,c_2 !=
785 umul a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
786 addcc c_3,t_1,c_3
787 rd %y,t_2
788 addxcc c_1,t_2,c_1 !=
789 addx c_2,%g0,c_2
790 umul a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
791 addcc c_3,t_1,c_3
792 rd %y,t_2 !=
793 addxcc c_1,t_2,c_1
794 addx c_2,%g0,c_2
795 umul a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
796 addcc c_3,t_1,c_3 !=
797 rd %y,t_2
798 addxcc c_1,t_2,c_1
799 addx c_2,%g0,c_2
800 umul a_2,b_6,t_1 !=!mul_add_c(a[2],b[6],c3,c1,c2);
801 addcc c_3,t_1,c_3
802 rd %y,t_2
803 addxcc c_1,t_2,c_1
804 addx c_2,%g0,c_2 !=
805 umul a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
806 addcc c_3,t_1,c_3
807 rd %y,t_2
808 addxcc c_1,t_2,c_1 !
809 addx c_2,%g0,c_2
810 st c_3,rp(8) !r[8]=c3;
811
812 umul a_2,b_7,t_1 !mul_add_c(a[2],b[7],c1,c2,c3);
813 addcc c_1,t_1,c_1 !=
814 rd %y,t_2
815 addxcc c_2,t_2,c_2
816 addx %g0,%g0,c_3
817 umul a_3,b_6,t_1 !=!mul_add_c(a[3],b[6],c1,c2,c3);
818 addcc c_1,t_1,c_1
819 rd %y,t_2
820 addxcc c_2,t_2,c_2
821 addx c_3,%g0,c_3 !=
822 umul a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
823 addcc c_1,t_1,c_1
824 rd %y,t_2
825 addxcc c_2,t_2,c_2 !=
826 addx c_3,%g0,c_3
827 umul a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
828 addcc c_1,t_1,c_1
829 rd %y,t_2 !=
830 addxcc c_2,t_2,c_2
831 addx c_3,%g0,c_3
832 umul a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
833 addcc c_1,t_1,c_1 !=
834 rd %y,t_2
835 addxcc c_2,t_2,c_2
836 addx c_3,%g0,c_3
837 umul a_7,b_2,t_1 !=!mul_add_c(a[7],b[2],c1,c2,c3);
838 addcc c_1,t_1,c_1
839 rd %y,t_2
840 addxcc c_2,t_2,c_2
841 addx c_3,%g0,c_3 !=
842 st c_1,rp(9) !r[9]=c1;
843
844 umul a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
845 addcc c_2,t_1,c_2
846 rd %y,t_2 !=
847 addxcc c_3,t_2,c_3
848 addx %g0,%g0,c_1
849 umul a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
850 addcc c_2,t_1,c_2 !=
851 rd %y,t_2
852 addxcc c_3,t_2,c_3
853 addx c_1,%g0,c_1
854 umul a_5,b_5,t_1 !=!mul_add_c(a[5],b[5],c2,c3,c1);
855 addcc c_2,t_1,c_2
856 rd %y,t_2
857 addxcc c_3,t_2,c_3
858 addx c_1,%g0,c_1 !=
859 umul a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
860 addcc c_2,t_1,c_2
861 rd %y,t_2
862 addxcc c_3,t_2,c_3 !=
863 addx c_1,%g0,c_1
864 umul a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
865 addcc c_2,t_1,c_2
866 rd %y,t_2 !=
867 addxcc c_3,t_2,c_3
868 addx c_1,%g0,c_1
869 st c_2,rp(10) !r[10]=c2;
870
871 umul a_4,b_7,t_1 !=!mul_add_c(a[4],b[7],c3,c1,c2);
872 addcc c_3,t_1,c_3
873 rd %y,t_2
874 addxcc c_1,t_2,c_1
875 addx %g0,%g0,c_2 !=
876 umul a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
877 addcc c_3,t_1,c_3
878 rd %y,t_2
879 addxcc c_1,t_2,c_1 !=
880 addx c_2,%g0,c_2
881 umul a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
882 addcc c_3,t_1,c_3
883 rd %y,t_2 !=
884 addxcc c_1,t_2,c_1
885 addx c_2,%g0,c_2
886 umul a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
887 addcc c_3,t_1,c_3 !=
888 rd %y,t_2
889 addxcc c_1,t_2,c_1
890 st c_3,rp(11) !r[11]=c3;
891 addx c_2,%g0,c_2 !=
892
893 umul a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
894 addcc c_1,t_1,c_1
895 rd %y,t_2
896 addxcc c_2,t_2,c_2 !=
897 addx %g0,%g0,c_3
898 umul a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
899 addcc c_1,t_1,c_1
900 rd %y,t_2 !=
901 addxcc c_2,t_2,c_2
902 addx c_3,%g0,c_3
903 umul a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
904 addcc c_1,t_1,c_1 !=
905 rd %y,t_2
906 addxcc c_2,t_2,c_2
907 st c_1,rp(12) !r[12]=c1;
908 addx c_3,%g0,c_3 !=
909
910 umul a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
911 addcc c_2,t_1,c_2
912 rd %y,t_2
913 addxcc c_3,t_2,c_3 !=
914 addx %g0,%g0,c_1
915 umul a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
916 addcc c_2,t_1,c_2
917 rd %y,t_2 !=
918 addxcc c_3,t_2,c_3
919 addx c_1,%g0,c_1
920 st c_2,rp(13) !r[13]=c2;
921
922 umul a_7,b_7,t_1 !=!mul_add_c(a[7],b[7],c3,c1,c2);
923 addcc c_3,t_1,c_3
924 rd %y,t_2
925 addxcc c_1,t_2,c_1
926 nop !=
927 st c_3,rp(14) !r[14]=c3;
928 st c_1,rp(15) !r[15]=c1;
929
930 ret
931 restore %g0,%g0,%o0
932
933.type bn_mul_comba8,#function
934.size bn_mul_comba8,(.-bn_mul_comba8)
935
936.align 32
937
938.global bn_mul_comba4
939/*
940 * void bn_mul_comba4(r,a,b)
941 * BN_ULONG *r,*a,*b;
942 */
943bn_mul_comba4:
944 save %sp,FRAME_SIZE,%sp
945 ld ap(0),a_0
946 ld bp(0),b_0
947 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
948 ld bp(1),b_1
949 rd %y,c_2
950 st c_1,rp(0) !r[0]=c1;
951
952 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
953 ld ap(1),a_1
954 addcc c_2,t_1,c_2
955 rd %y,t_2 !=
956 addxcc %g0,t_2,c_3
957 addx %g0,%g0,c_1
958 ld ap(2),a_2
959 umul a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
960 addcc c_2,t_1,c_2
961 rd %y,t_2
962 addxcc c_3,t_2,c_3
963 addx c_1,%g0,c_1 !=
964 st c_2,rp(1) !r[1]=c2;
965
966 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
967 addcc c_3,t_1,c_3
968 rd %y,t_2 !=
969 addxcc c_1,t_2,c_1
970 addx %g0,%g0,c_2
971 ld bp(2),b_2
972 umul a_1,b_1,t_1 !=!mul_add_c(a[1],b[1],c3,c1,c2);
973 addcc c_3,t_1,c_3
974 rd %y,t_2
975 addxcc c_1,t_2,c_1
976 addx c_2,%g0,c_2 !=
977 ld bp(3),b_3
978 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
979 addcc c_3,t_1,c_3
980 rd %y,t_2 !=
981 addxcc c_1,t_2,c_1
982 addx c_2,%g0,c_2
983 st c_3,rp(2) !r[2]=c3;
984
985 umul a_0,b_3,t_1 !=!mul_add_c(a[0],b[3],c1,c2,c3);
986 addcc c_1,t_1,c_1
987 rd %y,t_2
988 addxcc c_2,t_2,c_2
989 addx %g0,%g0,c_3 !=
990 umul a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
991 addcc c_1,t_1,c_1
992 rd %y,t_2
993 addxcc c_2,t_2,c_2 !=
994 addx c_3,%g0,c_3
995 ld ap(3),a_3
996 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
997 addcc c_1,t_1,c_1 !=
998 rd %y,t_2
999 addxcc c_2,t_2,c_2
1000 addx c_3,%g0,c_3
1001 umul a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);
1002 addcc c_1,t_1,c_1
1003 rd %y,t_2
1004 addxcc c_2,t_2,c_2
1005 addx c_3,%g0,c_3 !=
1006 st c_1,rp(3) !r[3]=c1;
1007
1008 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1009 addcc c_2,t_1,c_2
1010 rd %y,t_2 !=
1011 addxcc c_3,t_2,c_3
1012 addx %g0,%g0,c_1
1013 umul a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1014 addcc c_2,t_1,c_2 !=
1015 rd %y,t_2
1016 addxcc c_3,t_2,c_3
1017 addx c_1,%g0,c_1
1018 umul a_1,b_3,t_1 !=!mul_add_c(a[1],b[3],c2,c3,c1);
1019 addcc c_2,t_1,c_2
1020 rd %y,t_2
1021 addxcc c_3,t_2,c_3
1022 addx c_1,%g0,c_1 !=
1023 st c_2,rp(4) !r[4]=c2;
1024
1025 umul a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1026 addcc c_3,t_1,c_3
1027 rd %y,t_2 !=
1028 addxcc c_1,t_2,c_1
1029 addx %g0,%g0,c_2
1030 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1031 addcc c_3,t_1,c_3 !=
1032 rd %y,t_2
1033 addxcc c_1,t_2,c_1
1034 st c_3,rp(5) !r[5]=c3;
1035 addx c_2,%g0,c_2 !=
1036
1037 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1038 addcc c_1,t_1,c_1
1039 rd %y,t_2
1040 addxcc c_2,t_2,c_2 !=
1041 st c_1,rp(6) !r[6]=c1;
1042 st c_2,rp(7) !r[7]=c2;
1043
1044 ret
1045 restore %g0,%g0,%o0
1046
1047.type bn_mul_comba4,#function
1048.size bn_mul_comba4,(.-bn_mul_comba4)
1049
1050.align 32
1051
1052.global bn_sqr_comba8
1053bn_sqr_comba8:
1054 save %sp,FRAME_SIZE,%sp
1055 ld ap(0),a_0
1056 ld ap(1),a_1
1057 umul a_0,a_0,c_1 !=!sqr_add_c(a,0,c1,c2,c3);
1058 rd %y,c_2
1059 st c_1,rp(0) !r[0]=c1;
1060
1061 ld ap(2),a_2
1062 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1063 addcc c_2,t_1,c_2
1064 rd %y,t_2
1065 addxcc %g0,t_2,c_3
1066 addx %g0,%g0,c_1 !=
1067 addcc c_2,t_1,c_2
1068 addxcc c_3,t_2,c_3
1069 st c_2,rp(1) !r[1]=c2;
1070 addx c_1,%g0,c_1 !=
1071
1072 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1073 addcc c_3,t_1,c_3
1074 rd %y,t_2
1075 addxcc c_1,t_2,c_1 !=
1076 addx %g0,%g0,c_2
1077 addcc c_3,t_1,c_3
1078 addxcc c_1,t_2,c_1
1079 addx c_2,%g0,c_2 !=
1080 ld ap(3),a_3
1081 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1082 addcc c_3,t_1,c_3
1083 rd %y,t_2 !=
1084 addxcc c_1,t_2,c_1
1085 addx c_2,%g0,c_2
1086 st c_3,rp(2) !r[2]=c3;
1087
1088 umul a_0,a_3,t_1 !=!sqr_add_c2(a,3,0,c1,c2,c3);
1089 addcc c_1,t_1,c_1
1090 rd %y,t_2
1091 addxcc c_2,t_2,c_2
1092 addx %g0,%g0,c_3 !=
1093 addcc c_1,t_1,c_1
1094 addxcc c_2,t_2,c_2
1095 ld ap(4),a_4
1096 addx c_3,%g0,c_3 !=
1097 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1098 addcc c_1,t_1,c_1
1099 rd %y,t_2
1100 addxcc c_2,t_2,c_2 !=
1101 addx c_3,%g0,c_3
1102 addcc c_1,t_1,c_1
1103 addxcc c_2,t_2,c_2
1104 addx c_3,%g0,c_3 !=
1105 st c_1,rp(3) !r[3]=c1;
1106
1107 umul a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1108 addcc c_2,t_1,c_2
1109 rd %y,t_2 !=
1110 addxcc c_3,t_2,c_3
1111 addx %g0,%g0,c_1
1112 addcc c_2,t_1,c_2
1113 addxcc c_3,t_2,c_3 !=
1114 addx c_1,%g0,c_1
1115 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1116 addcc c_2,t_1,c_2
1117 rd %y,t_2 !=
1118 addxcc c_3,t_2,c_3
1119 addx c_1,%g0,c_1
1120 addcc c_2,t_1,c_2
1121 addxcc c_3,t_2,c_3 !=
1122 addx c_1,%g0,c_1
1123 ld ap(5),a_5
1124 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1125 addcc c_2,t_1,c_2 !=
1126 rd %y,t_2
1127 addxcc c_3,t_2,c_3
1128 st c_2,rp(4) !r[4]=c2;
1129 addx c_1,%g0,c_1 !=
1130
1131 umul a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1132 addcc c_3,t_1,c_3
1133 rd %y,t_2
1134 addxcc c_1,t_2,c_1 !=
1135 addx %g0,%g0,c_2
1136 addcc c_3,t_1,c_3
1137 addxcc c_1,t_2,c_1
1138 addx c_2,%g0,c_2 !=
1139 umul a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1140 addcc c_3,t_1,c_3
1141 rd %y,t_2
1142 addxcc c_1,t_2,c_1 !=
1143 addx c_2,%g0,c_2
1144 addcc c_3,t_1,c_3
1145 addxcc c_1,t_2,c_1
1146 addx c_2,%g0,c_2 !=
1147 ld ap(6),a_6
1148 umul a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1149 addcc c_3,t_1,c_3
1150 rd %y,t_2 !=
1151 addxcc c_1,t_2,c_1
1152 addx c_2,%g0,c_2
1153 addcc c_3,t_1,c_3
1154 addxcc c_1,t_2,c_1 !=
1155 addx c_2,%g0,c_2
1156 st c_3,rp(5) !r[5]=c3;
1157
1158 umul a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1159 addcc c_1,t_1,c_1 !=
1160 rd %y,t_2
1161 addxcc c_2,t_2,c_2
1162 addx %g0,%g0,c_3
1163 addcc c_1,t_1,c_1 !=
1164 addxcc c_2,t_2,c_2
1165 addx c_3,%g0,c_3
1166 umul a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1167 addcc c_1,t_1,c_1 !=
1168 rd %y,t_2
1169 addxcc c_2,t_2,c_2
1170 addx c_3,%g0,c_3
1171 addcc c_1,t_1,c_1 !=
1172 addxcc c_2,t_2,c_2
1173 addx c_3,%g0,c_3
1174 umul a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1175 addcc c_1,t_1,c_1 !=
1176 rd %y,t_2
1177 addxcc c_2,t_2,c_2
1178 addx c_3,%g0,c_3
1179 addcc c_1,t_1,c_1 !=
1180 addxcc c_2,t_2,c_2
1181 addx c_3,%g0,c_3
1182 ld ap(7),a_7
1183 umul a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1184 addcc c_1,t_1,c_1
1185 rd %y,t_2
1186 addxcc c_2,t_2,c_2
1187 addx c_3,%g0,c_3 !=
1188 st c_1,rp(6) !r[6]=c1;
1189
1190 umul a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1191 addcc c_2,t_1,c_2
1192 rd %y,t_2 !=
1193 addxcc c_3,t_2,c_3
1194 addx %g0,%g0,c_1
1195 addcc c_2,t_1,c_2
1196 addxcc c_3,t_2,c_3 !=
1197 addx c_1,%g0,c_1
1198 umul a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1199 addcc c_2,t_1,c_2
1200 rd %y,t_2 !=
1201 addxcc c_3,t_2,c_3
1202 addx c_1,%g0,c_1
1203 addcc c_2,t_1,c_2
1204 addxcc c_3,t_2,c_3 !=
1205 addx c_1,%g0,c_1
1206 umul a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1207 addcc c_2,t_1,c_2
1208 rd %y,t_2 !=
1209 addxcc c_3,t_2,c_3
1210 addx c_1,%g0,c_1
1211 addcc c_2,t_1,c_2
1212 addxcc c_3,t_2,c_3 !=
1213 addx c_1,%g0,c_1
1214 umul a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1215 addcc c_2,t_1,c_2
1216 rd %y,t_2 !=
1217 addxcc c_3,t_2,c_3
1218 addx c_1,%g0,c_1
1219 addcc c_2,t_1,c_2
1220 addxcc c_3,t_2,c_3 !=
1221 addx c_1,%g0,c_1
1222 st c_2,rp(7) !r[7]=c2;
1223
1224 umul a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1225 addcc c_3,t_1,c_3 !=
1226 rd %y,t_2
1227 addxcc c_1,t_2,c_1
1228 addx %g0,%g0,c_2
1229 addcc c_3,t_1,c_3 !=
1230 addxcc c_1,t_2,c_1
1231 addx c_2,%g0,c_2
1232 umul a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1233 addcc c_3,t_1,c_3 !=
1234 rd %y,t_2
1235 addxcc c_1,t_2,c_1
1236 addx c_2,%g0,c_2
1237 addcc c_3,t_1,c_3 !=
1238 addxcc c_1,t_2,c_1
1239 addx c_2,%g0,c_2
1240 umul a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1241 addcc c_3,t_1,c_3 !=
1242 rd %y,t_2
1243 addxcc c_1,t_2,c_1
1244 addx c_2,%g0,c_2
1245 addcc c_3,t_1,c_3 !=
1246 addxcc c_1,t_2,c_1
1247 addx c_2,%g0,c_2
1248 umul a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1249 addcc c_3,t_1,c_3 !=
1250 rd %y,t_2
1251 addxcc c_1,t_2,c_1
1252 st c_3,rp(8) !r[8]=c3;
1253 addx c_2,%g0,c_2 !=
1254
1255 umul a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1256 addcc c_1,t_1,c_1
1257 rd %y,t_2
1258 addxcc c_2,t_2,c_2 !=
1259 addx %g0,%g0,c_3
1260 addcc c_1,t_1,c_1
1261 addxcc c_2,t_2,c_2
1262 addx c_3,%g0,c_3 !=
1263 umul a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1264 addcc c_1,t_1,c_1
1265 rd %y,t_2
1266 addxcc c_2,t_2,c_2 !=
1267 addx c_3,%g0,c_3
1268 addcc c_1,t_1,c_1
1269 addxcc c_2,t_2,c_2
1270 addx c_3,%g0,c_3 !=
1271 umul a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1272 addcc c_1,t_1,c_1
1273 rd %y,t_2
1274 addxcc c_2,t_2,c_2 !=
1275 addx c_3,%g0,c_3
1276 addcc c_1,t_1,c_1
1277 addxcc c_2,t_2,c_2
1278 addx c_3,%g0,c_3 !=
1279 st c_1,rp(9) !r[9]=c1;
1280
1281 umul a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1282 addcc c_2,t_1,c_2
1283 rd %y,t_2 !=
1284 addxcc c_3,t_2,c_3
1285 addx %g0,%g0,c_1
1286 addcc c_2,t_1,c_2
1287 addxcc c_3,t_2,c_3 !=
1288 addx c_1,%g0,c_1
1289 umul a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1290 addcc c_2,t_1,c_2
1291 rd %y,t_2 !=
1292 addxcc c_3,t_2,c_3
1293 addx c_1,%g0,c_1
1294 addcc c_2,t_1,c_2
1295 addxcc c_3,t_2,c_3 !=
1296 addx c_1,%g0,c_1
1297 umul a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1298 addcc c_2,t_1,c_2
1299 rd %y,t_2 !=
1300 addxcc c_3,t_2,c_3
1301 addx c_1,%g0,c_1
1302 st c_2,rp(10) !r[10]=c2;
1303
1304 umul a_4,a_7,t_1 !=!sqr_add_c2(a,7,4,c3,c1,c2);
1305 addcc c_3,t_1,c_3
1306 rd %y,t_2
1307 addxcc c_1,t_2,c_1
1308 addx %g0,%g0,c_2 !=
1309 addcc c_3,t_1,c_3
1310 addxcc c_1,t_2,c_1
1311 addx c_2,%g0,c_2
1312 umul a_5,a_6,t_1 !=!sqr_add_c2(a,6,5,c3,c1,c2);
1313 addcc c_3,t_1,c_3
1314 rd %y,t_2
1315 addxcc c_1,t_2,c_1
1316 addx c_2,%g0,c_2 !=
1317 addcc c_3,t_1,c_3
1318 addxcc c_1,t_2,c_1
1319 st c_3,rp(11) !r[11]=c3;
1320 addx c_2,%g0,c_2 !=
1321
1322 umul a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1323 addcc c_1,t_1,c_1
1324 rd %y,t_2
1325 addxcc c_2,t_2,c_2 !=
1326 addx %g0,%g0,c_3
1327 addcc c_1,t_1,c_1
1328 addxcc c_2,t_2,c_2
1329 addx c_3,%g0,c_3 !=
1330 umul a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1331 addcc c_1,t_1,c_1
1332 rd %y,t_2
1333 addxcc c_2,t_2,c_2 !=
1334 addx c_3,%g0,c_3
1335 st c_1,rp(12) !r[12]=c1;
1336
1337 umul a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1338 addcc c_2,t_1,c_2 !=
1339 rd %y,t_2
1340 addxcc c_3,t_2,c_3
1341 addx %g0,%g0,c_1
1342 addcc c_2,t_1,c_2 !=
1343 addxcc c_3,t_2,c_3
1344 st c_2,rp(13) !r[13]=c2;
1345 addx c_1,%g0,c_1 !=
1346
1347 umul a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1348 addcc c_3,t_1,c_3
1349 rd %y,t_2
1350 addxcc c_1,t_2,c_1 !=
1351 st c_3,rp(14) !r[14]=c3;
1352 st c_1,rp(15) !r[15]=c1;
1353
1354 ret
1355 restore %g0,%g0,%o0
1356
1357.type bn_sqr_comba8,#function
1358.size bn_sqr_comba8,(.-bn_sqr_comba8)
1359
1360.align 32
1361
1362.global bn_sqr_comba4
1363/*
1364 * void bn_sqr_comba4(r,a)
1365 * BN_ULONG *r,*a;
1366 */
1367bn_sqr_comba4:
1368 save %sp,FRAME_SIZE,%sp
1369 ld ap(0),a_0
1370 umul a_0,a_0,c_1 !sqr_add_c(a,0,c1,c2,c3);
1371 ld ap(1),a_1 !=
1372 rd %y,c_2
1373 st c_1,rp(0) !r[0]=c1;
1374
1375 ld ap(2),a_2
1376 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1377 addcc c_2,t_1,c_2
1378 rd %y,t_2
1379 addxcc %g0,t_2,c_3
1380 addx %g0,%g0,c_1 !=
1381 addcc c_2,t_1,c_2
1382 addxcc c_3,t_2,c_3
1383 addx c_1,%g0,c_1 !=
1384 st c_2,rp(1) !r[1]=c2;
1385
1386 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1387 addcc c_3,t_1,c_3
1388 rd %y,t_2 !=
1389 addxcc c_1,t_2,c_1
1390 addx %g0,%g0,c_2
1391 addcc c_3,t_1,c_3
1392 addxcc c_1,t_2,c_1 !=
1393 addx c_2,%g0,c_2
1394 ld ap(3),a_3
1395 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1396 addcc c_3,t_1,c_3 !=
1397 rd %y,t_2
1398 addxcc c_1,t_2,c_1
1399 st c_3,rp(2) !r[2]=c3;
1400 addx c_2,%g0,c_2 !=
1401
1402 umul a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1403 addcc c_1,t_1,c_1
1404 rd %y,t_2
1405 addxcc c_2,t_2,c_2 !=
1406 addx %g0,%g0,c_3
1407 addcc c_1,t_1,c_1
1408 addxcc c_2,t_2,c_2
1409 addx c_3,%g0,c_3 !=
1410 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1411 addcc c_1,t_1,c_1
1412 rd %y,t_2
1413 addxcc c_2,t_2,c_2 !=
1414 addx c_3,%g0,c_3
1415 addcc c_1,t_1,c_1
1416 addxcc c_2,t_2,c_2
1417 addx c_3,%g0,c_3 !=
1418 st c_1,rp(3) !r[3]=c1;
1419
1420 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1421 addcc c_2,t_1,c_2
1422 rd %y,t_2 !=
1423 addxcc c_3,t_2,c_3
1424 addx %g0,%g0,c_1
1425 addcc c_2,t_1,c_2
1426 addxcc c_3,t_2,c_3 !=
1427 addx c_1,%g0,c_1
1428 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1429 addcc c_2,t_1,c_2
1430 rd %y,t_2 !=
1431 addxcc c_3,t_2,c_3
1432 addx c_1,%g0,c_1
1433 st c_2,rp(4) !r[4]=c2;
1434
1435 umul a_2,a_3,t_1 !=!sqr_add_c2(a,3,2,c3,c1,c2);
1436 addcc c_3,t_1,c_3
1437 rd %y,t_2
1438 addxcc c_1,t_2,c_1
1439 addx %g0,%g0,c_2 !=
1440 addcc c_3,t_1,c_3
1441 addxcc c_1,t_2,c_1
1442 st c_3,rp(5) !r[5]=c3;
1443 addx c_2,%g0,c_2 !=
1444
1445 umul a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1446 addcc c_1,t_1,c_1
1447 rd %y,t_2
1448 addxcc c_2,t_2,c_2 !=
1449 st c_1,rp(6) !r[6]=c1;
1450 st c_2,rp(7) !r[7]=c2;
1451
1452 ret
1453 restore %g0,%g0,%o0
1454
1455.type bn_sqr_comba4,#function
1456.size bn_sqr_comba4,(.-bn_sqr_comba4)
1457
1458.align 32
diff --git a/src/lib/libcrypto/bn/asm/sparcv8plus.S b/src/lib/libcrypto/bn/asm/sparcv8plus.S
new file mode 100644
index 0000000000..0074dfdb75
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/sparcv8plus.S
@@ -0,0 +1,1535 @@
1.ident "sparcv8plus.s, Version 1.4"
2.ident "SPARC v9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * Questions-n-answers.
22 *
23 * Q. How to compile?
24 * A. With SC4.x/SC5.x:
25 *
26 * cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
27 *
28 * and with gcc:
29 *
30 * gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o
31 *
32 * or if above fails (it does if you have gas installed):
33 *
34 * gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o
35 *
36 * Quick-n-dirty way to fuse the module into the library.
37 * Provided that the library is already configured and built
38 * (in 0.9.2 case with no-asm option):
39 *
40 * # cd crypto/bn
41 * # cp /some/place/bn_asm.sparc.v8plus.S .
42 * # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
43 * # make
44 * # cd ../..
45 * # make; make test
46 *
47 * Quick-n-dirty way to get rid of it:
48 *
49 * # cd crypto/bn
50 * # touch bn_asm.c
51 * # make
52 * # cd ../..
53 * # make; make test
54 *
55 * Q. V8plus achitecture? What kind of beast is that?
56 * A. Well, it's rather a programming model than an architecture...
57 * It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under
58 * special conditions, namely when kernel doesn't preserve upper
59 * 32 bits of otherwise 64-bit registers during a context switch.
60 *
61 * Q. Why just UltraSPARC? What about SuperSPARC?
62 * A. Original release did target UltraSPARC only. Now SuperSPARC
63 * version is provided along. Both version share bn_*comba[48]
64 * implementations (see comment later in code for explanation).
65 * But what's so special about this UltraSPARC implementation?
66 * Why didn't I let compiler do the job? Trouble is that most of
67 * available compilers (well, SC5.0 is the only exception) don't
68 * attempt to take advantage of UltraSPARC's 64-bitness under
69 * 32-bit kernels even though it's perfectly possible (see next
70 * question).
71 *
72 * Q. 64-bit registers under 32-bit kernels? Didn't you just say it
73 * doesn't work?
74 * A. You can't adress *all* registers as 64-bit wide:-( The catch is
75 * that you actually may rely upon %o0-%o5 and %g1-%g4 being fully
76 * preserved if you're in a leaf function, i.e. such never calling
77 * any other functions. All functions in this module are leaf and
78 * 10 registers is a handful. And as a matter of fact none-"comba"
79 * routines don't require even that much and I could even afford to
80 * not allocate own stack frame for 'em:-)
81 *
82 * Q. What about 64-bit kernels?
83 * A. What about 'em? Just kidding:-) Pure 64-bit version is currently
84 * under evaluation and development...
85 *
86 * Q. What about shared libraries?
87 * A. What about 'em? Kidding again:-) Code does *not* contain any
88 * code position dependencies and it's safe to include it into
89 * shared library as is.
90 *
91 * Q. How much faster does it go?
92 * A. Do you have a good benchmark? In either case below is what I
93 * experience with crypto/bn/expspeed.c test program:
94 *
95 * v8plus module on U10/300MHz against bn_asm.c compiled with:
96 *
97 * cc-5.0 -xarch=v8plus -xO5 -xdepend +7-12%
98 * cc-4.2 -xarch=v8plus -xO5 -xdepend +25-35%
99 * egcs-1.1.2 -mcpu=ultrasparc -O3 +35-45%
100 *
101 * v8 module on SS10/60MHz against bn_asm.c compiled with:
102 *
103 * cc-5.0 -xarch=v8 -xO5 -xdepend +7-10%
104 * cc-4.2 -xarch=v8 -xO5 -xdepend +10%
105 * egcs-1.1.2 -mv8 -O3 +35-45%
106 *
107 * As you can see it's damn hard to beat the new Sun C compiler
108 * and it's in first place GNU C users who will appreciate this
109 * assembler implementation:-)
110 */
111
112/*
113 * Revision history.
114 *
115 * 1.0 - initial release;
116 * 1.1 - new loop unrolling model(*);
117 * - some more fine tuning;
118 * 1.2 - made gas friendly;
119 * - updates to documentation concerning v9;
120 * - new performance comparison matrix;
121 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
122 * 1.4 - native V9 bn_*_comba[48] implementation (15% more efficient)
123 * resulting in slight overall performance kick;
124 * - some retunes;
125 * - support for GNU as added;
126 *
127 * (*) Originally unrolled loop looked like this:
128 * for (;;) {
129 * op(p+0); if (--n==0) break;
130 * op(p+1); if (--n==0) break;
131 * op(p+2); if (--n==0) break;
132 * op(p+3); if (--n==0) break;
133 * p+=4;
134 * }
135 * I unroll according to following:
136 * while (n&~3) {
137 * op(p+0); op(p+1); op(p+2); op(p+3);
138 * p+=4; n=-4;
139 * }
140 * if (n) {
141 * op(p+0); if (--n==0) return;
142 * op(p+2); if (--n==0) return;
143 * op(p+3); return;
144 * }
145 */
146
147/*
148 * GNU assembler can't stand stuw:-(
149 */
150#define stuw st
151
152.section ".text",#alloc,#execinstr
153.file "bn_asm.sparc.v8plus.S"
154
155.align 32
156
157.global bn_mul_add_words
158/*
159 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
160 * BN_ULONG *rp,*ap;
161 * int num;
162 * BN_ULONG w;
163 */
164bn_mul_add_words:
165 brgz,a %o2,.L_bn_mul_add_words_proceed
166 lduw [%o1],%g2
167 retl
168 clr %o0
169
170.L_bn_mul_add_words_proceed:
171 srl %o3,%g0,%o3 ! clruw %o3
172 andcc %o2,-4,%g0
173 bz,pn %icc,.L_bn_mul_add_words_tail
174 clr %o5
175
176.L_bn_mul_add_words_loop: ! wow! 32 aligned!
177 lduw [%o0],%g1
178 lduw [%o1+4],%g3
179 mulx %o3,%g2,%g2
180 add %g1,%o5,%o4
181 nop
182 add %o4,%g2,%o4
183 stuw %o4,[%o0]
184 srlx %o4,32,%o5
185
186 lduw [%o0+4],%g1
187 lduw [%o1+8],%g2
188 mulx %o3,%g3,%g3
189 add %g1,%o5,%o4
190 dec 4,%o2
191 add %o4,%g3,%o4
192 stuw %o4,[%o0+4]
193 srlx %o4,32,%o5
194
195 lduw [%o0+8],%g1
196 lduw [%o1+12],%g3
197 mulx %o3,%g2,%g2
198 add %g1,%o5,%o4
199 inc 16,%o1
200 add %o4,%g2,%o4
201 stuw %o4,[%o0+8]
202 srlx %o4,32,%o5
203
204 lduw [%o0+12],%g1
205 mulx %o3,%g3,%g3
206 add %g1,%o5,%o4
207 inc 16,%o0
208 add %o4,%g3,%o4
209 andcc %o2,-4,%g0
210 stuw %o4,[%o0-4]
211 srlx %o4,32,%o5
212 bnz,a,pt %icc,.L_bn_mul_add_words_loop
213 lduw [%o1],%g2
214
215 brnz,a,pn %o2,.L_bn_mul_add_words_tail
216 lduw [%o1],%g2
217.L_bn_mul_add_words_return:
218 retl
219 mov %o5,%o0
220
221.L_bn_mul_add_words_tail:
222 lduw [%o0],%g1
223 mulx %o3,%g2,%g2
224 add %g1,%o5,%o4
225 dec %o2
226 add %o4,%g2,%o4
227 srlx %o4,32,%o5
228 brz,pt %o2,.L_bn_mul_add_words_return
229 stuw %o4,[%o0]
230
231 lduw [%o1+4],%g2
232 lduw [%o0+4],%g1
233 mulx %o3,%g2,%g2
234 add %g1,%o5,%o4
235 dec %o2
236 add %o4,%g2,%o4
237 srlx %o4,32,%o5
238 brz,pt %o2,.L_bn_mul_add_words_return
239 stuw %o4,[%o0+4]
240
241 lduw [%o1+8],%g2
242 lduw [%o0+8],%g1
243 mulx %o3,%g2,%g2
244 add %g1,%o5,%o4
245 add %o4,%g2,%o4
246 stuw %o4,[%o0+8]
247 retl
248 srlx %o4,32,%o0
249
250.type bn_mul_add_words,#function
251.size bn_mul_add_words,(.-bn_mul_add_words)
252
253.align 32
254
255.global bn_mul_words
256/*
257 * BN_ULONG bn_mul_words(rp,ap,num,w)
258 * BN_ULONG *rp,*ap;
259 * int num;
260 * BN_ULONG w;
261 */
262bn_mul_words:
263 brgz,a %o2,.L_bn_mul_words_proceeed
264 lduw [%o1],%g2
265 retl
266 clr %o0
267
268.L_bn_mul_words_proceeed:
269 srl %o3,%g0,%o3 ! clruw %o3
270 andcc %o2,-4,%g0
271 bz,pn %icc,.L_bn_mul_words_tail
272 clr %o5
273
274.L_bn_mul_words_loop: ! wow! 32 aligned!
275 lduw [%o1+4],%g3
276 mulx %o3,%g2,%g2
277 add %g2,%o5,%o4
278 nop
279 stuw %o4,[%o0]
280 srlx %o4,32,%o5
281
282 lduw [%o1+8],%g2
283 mulx %o3,%g3,%g3
284 add %g3,%o5,%o4
285 dec 4,%o2
286 stuw %o4,[%o0+4]
287 srlx %o4,32,%o5
288
289 lduw [%o1+12],%g3
290 mulx %o3,%g2,%g2
291 add %g2,%o5,%o4
292 inc 16,%o1
293 stuw %o4,[%o0+8]
294 srlx %o4,32,%o5
295
296 mulx %o3,%g3,%g3
297 add %g3,%o5,%o4
298 inc 16,%o0
299 stuw %o4,[%o0-4]
300 srlx %o4,32,%o5
301 andcc %o2,-4,%g0
302 bnz,a,pt %icc,.L_bn_mul_words_loop
303 lduw [%o1],%g2
304 nop
305 nop
306
307 brnz,a,pn %o2,.L_bn_mul_words_tail
308 lduw [%o1],%g2
309.L_bn_mul_words_return:
310 retl
311 mov %o5,%o0
312
313.L_bn_mul_words_tail:
314 mulx %o3,%g2,%g2
315 add %g2,%o5,%o4
316 dec %o2
317 srlx %o4,32,%o5
318 brz,pt %o2,.L_bn_mul_words_return
319 stuw %o4,[%o0]
320
321 lduw [%o1+4],%g2
322 mulx %o3,%g2,%g2
323 add %g2,%o5,%o4
324 dec %o2
325 srlx %o4,32,%o5
326 brz,pt %o2,.L_bn_mul_words_return
327 stuw %o4,[%o0+4]
328
329 lduw [%o1+8],%g2
330 mulx %o3,%g2,%g2
331 add %g2,%o5,%o4
332 stuw %o4,[%o0+8]
333 retl
334 srlx %o4,32,%o0
335
336.type bn_mul_words,#function
337.size bn_mul_words,(.-bn_mul_words)
338
339.align 32
340.global bn_sqr_words
341/*
342 * void bn_sqr_words(r,a,n)
343 * BN_ULONG *r,*a;
344 * int n;
345 */
346bn_sqr_words:
347 brgz,a %o2,.L_bn_sqr_words_proceeed
348 lduw [%o1],%g2
349 retl
350 clr %o0
351
352.L_bn_sqr_words_proceeed:
353 andcc %o2,-4,%g0
354 nop
355 bz,pn %icc,.L_bn_sqr_words_tail
356 nop
357
358.L_bn_sqr_words_loop: ! wow! 32 aligned!
359 lduw [%o1+4],%g3
360 mulx %g2,%g2,%o4
361 stuw %o4,[%o0]
362 srlx %o4,32,%o5
363 stuw %o5,[%o0+4]
364 nop
365
366 lduw [%o1+8],%g2
367 mulx %g3,%g3,%o4
368 dec 4,%o2
369 stuw %o4,[%o0+8]
370 srlx %o4,32,%o5
371 stuw %o5,[%o0+12]
372
373 lduw [%o1+12],%g3
374 mulx %g2,%g2,%o4
375 srlx %o4,32,%o5
376 stuw %o4,[%o0+16]
377 inc 16,%o1
378 stuw %o5,[%o0+20]
379
380 mulx %g3,%g3,%o4
381 inc 32,%o0
382 stuw %o4,[%o0-8]
383 srlx %o4,32,%o5
384 andcc %o2,-4,%g2
385 stuw %o5,[%o0-4]
386 bnz,a,pt %icc,.L_bn_sqr_words_loop
387 lduw [%o1],%g2
388 nop
389
390 brnz,a,pn %o2,.L_bn_sqr_words_tail
391 lduw [%o1],%g2
392.L_bn_sqr_words_return:
393 retl
394 clr %o0
395
396.L_bn_sqr_words_tail:
397 mulx %g2,%g2,%o4
398 dec %o2
399 stuw %o4,[%o0]
400 srlx %o4,32,%o5
401 brz,pt %o2,.L_bn_sqr_words_return
402 stuw %o5,[%o0+4]
403
404 lduw [%o1+4],%g2
405 mulx %g2,%g2,%o4
406 dec %o2
407 stuw %o4,[%o0+8]
408 srlx %o4,32,%o5
409 brz,pt %o2,.L_bn_sqr_words_return
410 stuw %o5,[%o0+12]
411
412 lduw [%o1+8],%g2
413 mulx %g2,%g2,%o4
414 srlx %o4,32,%o5
415 stuw %o4,[%o0+16]
416 stuw %o5,[%o0+20]
417 retl
418 clr %o0
419
420.type bn_sqr_words,#function
421.size bn_sqr_words,(.-bn_sqr_words)
422
423.align 32
424.global bn_div_words
425/*
426 * BN_ULONG bn_div_words(h,l,d)
427 * BN_ULONG h,l,d;
428 */
429bn_div_words:
430 sllx %o0,32,%o0
431 or %o0,%o1,%o0
432 udivx %o0,%o2,%o0
433 retl
434 srl %o0,%g0,%o0 ! clruw %o0
435
436.type bn_div_words,#function
437.size bn_div_words,(.-bn_div_words)
438
439.align 32
440
441.global bn_add_words
442/*
443 * BN_ULONG bn_add_words(rp,ap,bp,n)
444 * BN_ULONG *rp,*ap,*bp;
445 * int n;
446 */
447bn_add_words:
448 brgz,a %o3,.L_bn_add_words_proceed
449 lduw [%o1],%o4
450 retl
451 clr %o0
452
453.L_bn_add_words_proceed:
454 andcc %o3,-4,%g0
455 bz,pn %icc,.L_bn_add_words_tail
456 addcc %g0,0,%g0 ! clear carry flag
457 nop
458
459.L_bn_add_words_loop: ! wow! 32 aligned!
460 dec 4,%o3
461 lduw [%o2],%o5
462 lduw [%o1+4],%g1
463 lduw [%o2+4],%g2
464 lduw [%o1+8],%g3
465 lduw [%o2+8],%g4
466 addccc %o5,%o4,%o5
467 stuw %o5,[%o0]
468
469 lduw [%o1+12],%o4
470 lduw [%o2+12],%o5
471 inc 16,%o1
472 addccc %g1,%g2,%g1
473 stuw %g1,[%o0+4]
474
475 inc 16,%o2
476 addccc %g3,%g4,%g3
477 stuw %g3,[%o0+8]
478
479 inc 16,%o0
480 addccc %o5,%o4,%o5
481 stuw %o5,[%o0-4]
482 and %o3,-4,%g1
483 brnz,a,pt %g1,.L_bn_add_words_loop
484 lduw [%o1],%o4
485
486 brnz,a,pn %o3,.L_bn_add_words_tail
487 lduw [%o1],%o4
488.L_bn_add_words_return:
489 clr %o0
490 retl
491 movcs %icc,1,%o0
492 nop
493
494.L_bn_add_words_tail:
495 lduw [%o2],%o5
496 dec %o3
497 addccc %o5,%o4,%o5
498 brz,pt %o3,.L_bn_add_words_return
499 stuw %o5,[%o0]
500
501 lduw [%o1+4],%o4
502 lduw [%o2+4],%o5
503 dec %o3
504 addccc %o5,%o4,%o5
505 brz,pt %o3,.L_bn_add_words_return
506 stuw %o5,[%o0+4]
507
508 lduw [%o1+8],%o4
509 lduw [%o2+8],%o5
510 addccc %o5,%o4,%o5
511 stuw %o5,[%o0+8]
512 clr %o0
513 retl
514 movcs %icc,1,%o0
515
516.type bn_add_words,#function
517.size bn_add_words,(.-bn_add_words)
518
519.global bn_sub_words
520/*
521 * BN_ULONG bn_sub_words(rp,ap,bp,n)
522 * BN_ULONG *rp,*ap,*bp;
523 * int n;
524 */
525bn_sub_words:
526 brgz,a %o3,.L_bn_sub_words_proceed
527 lduw [%o1],%o4
528 retl
529 clr %o0
530
531.L_bn_sub_words_proceed:
532 andcc %o3,-4,%g0
533 bz,pn %icc,.L_bn_sub_words_tail
534 addcc %g0,0,%g0 ! clear carry flag
535 nop
536
537.L_bn_sub_words_loop: ! wow! 32 aligned!
538 dec 4,%o3
539 lduw [%o2],%o5
540 lduw [%o1+4],%g1
541 lduw [%o2+4],%g2
542 lduw [%o1+8],%g3
543 lduw [%o2+8],%g4
544 subccc %o4,%o5,%o5
545 stuw %o5,[%o0]
546
547 lduw [%o1+12],%o4
548 lduw [%o2+12],%o5
549 inc 16,%o1
550 subccc %g1,%g2,%g2
551 stuw %g2,[%o0+4]
552
553 inc 16,%o2
554 subccc %g3,%g4,%g4
555 stuw %g4,[%o0+8]
556
557 inc 16,%o0
558 subccc %o4,%o5,%o5
559 stuw %o5,[%o0-4]
560 and %o3,-4,%g1
561 brnz,a,pt %g1,.L_bn_sub_words_loop
562 lduw [%o1],%o4
563
564 brnz,a,pn %o3,.L_bn_sub_words_tail
565 lduw [%o1],%o4
566.L_bn_sub_words_return:
567 clr %o0
568 retl
569 movcs %icc,1,%o0
570 nop
571
572.L_bn_sub_words_tail: ! wow! 32 aligned!
573 lduw [%o2],%o5
574 dec %o3
575 subccc %o4,%o5,%o5
576 brz,pt %o3,.L_bn_sub_words_return
577 stuw %o5,[%o0]
578
579 lduw [%o1+4],%o4
580 lduw [%o2+4],%o5
581 dec %o3
582 subccc %o4,%o5,%o5
583 brz,pt %o3,.L_bn_sub_words_return
584 stuw %o5,[%o0+4]
585
586 lduw [%o1+8],%o4
587 lduw [%o2+8],%o5
588 subccc %o4,%o5,%o5
589 stuw %o5,[%o0+8]
590 clr %o0
591 retl
592 movcs %icc,1,%o0
593
594.type bn_sub_words,#function
595.size bn_sub_words,(.-bn_sub_words)
596
597/*
598 * Code below depends on the fact that upper parts of the %l0-%l7
599 * and %i0-%i7 are zeroed by kernel after context switch. In
600 * previous versions this comment stated that "the trouble is that
601 * it's not feasible to implement the mumbo-jumbo in less V9
602 * instructions:-(" which apparently isn't true thanks to
603 * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement
604 * results not from the shorter code, but from elimination of
605 * multicycle none-pairable 'rd %y,%rd' instructions.
606 *
607 * Andy.
608 */
609
610#define FRAME_SIZE -96
611
612/*
613 * Here is register usage map for *all* routines below.
614 */
615#define t_1 %o0
616#define t_2 %o1
617#define c_12 %o2
618#define c_3 %o3
619
620#define ap(I) [%i1+4*I]
621#define bp(I) [%i2+4*I]
622#define rp(I) [%i0+4*I]
623
624#define a_0 %l0
625#define a_1 %l1
626#define a_2 %l2
627#define a_3 %l3
628#define a_4 %l4
629#define a_5 %l5
630#define a_6 %l6
631#define a_7 %l7
632
633#define b_0 %i3
634#define b_1 %i4
635#define b_2 %i5
636#define b_3 %o4
637#define b_4 %o5
638#define b_5 %o7
639#define b_6 %g1
640#define b_7 %g4
641
642.align 32
643.global bn_mul_comba8
644/*
645 * void bn_mul_comba8(r,a,b)
646 * BN_ULONG *r,*a,*b;
647 */
648bn_mul_comba8:
649 save %sp,FRAME_SIZE,%sp
650 mov 1,t_2
651 lduw ap(0),a_0
652 sllx t_2,32,t_2
653 lduw bp(0),b_0 !=
654 lduw bp(1),b_1
655 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
656 srlx t_1,32,c_12
657 stuw t_1,rp(0) !=!r[0]=c1;
658
659 lduw ap(1),a_1
660 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
661 addcc c_12,t_1,c_12
662 clr c_3 !=
663 bcs,a %xcc,.+8
664 add c_3,t_2,c_3
665 lduw ap(2),a_2
666 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
667 addcc c_12,t_1,t_1
668 bcs,a %xcc,.+8
669 add c_3,t_2,c_3
670 srlx t_1,32,c_12 !=
671 stuw t_1,rp(1) !r[1]=c2;
672 or c_12,c_3,c_12
673
674 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
675 addcc c_12,t_1,c_12 !=
676 clr c_3
677 bcs,a %xcc,.+8
678 add c_3,t_2,c_3
679 lduw bp(2),b_2 !=
680 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
681 addcc c_12,t_1,c_12
682 bcs,a %xcc,.+8
683 add c_3,t_2,c_3 !=
684 lduw bp(3),b_3
685 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
686 addcc c_12,t_1,t_1
687 bcs,a %xcc,.+8 !=
688 add c_3,t_2,c_3
689 srlx t_1,32,c_12
690 stuw t_1,rp(2) !r[2]=c3;
691 or c_12,c_3,c_12 !=
692
693 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
694 addcc c_12,t_1,c_12
695 clr c_3
696 bcs,a %xcc,.+8 !=
697 add c_3,t_2,c_3
698 mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
699 addcc c_12,t_1,c_12
700 bcs,a %xcc,.+8 !=
701 add c_3,t_2,c_3
702 lduw ap(3),a_3
703 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
704 addcc c_12,t_1,c_12 !=
705 bcs,a %xcc,.+8
706 add c_3,t_2,c_3
707 lduw ap(4),a_4
708 mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!=
709 addcc c_12,t_1,t_1
710 bcs,a %xcc,.+8
711 add c_3,t_2,c_3
712 srlx t_1,32,c_12 !=
713 stuw t_1,rp(3) !r[3]=c1;
714 or c_12,c_3,c_12
715
716 mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
717 addcc c_12,t_1,c_12 !=
718 clr c_3
719 bcs,a %xcc,.+8
720 add c_3,t_2,c_3
721 mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1);
722 addcc c_12,t_1,c_12
723 bcs,a %xcc,.+8
724 add c_3,t_2,c_3
725 mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
726 addcc c_12,t_1,c_12
727 bcs,a %xcc,.+8
728 add c_3,t_2,c_3
729 lduw bp(4),b_4 !=
730 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
731 addcc c_12,t_1,c_12
732 bcs,a %xcc,.+8
733 add c_3,t_2,c_3 !=
734 lduw bp(5),b_5
735 mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1);
736 addcc c_12,t_1,t_1
737 bcs,a %xcc,.+8 !=
738 add c_3,t_2,c_3
739 srlx t_1,32,c_12
740 stuw t_1,rp(4) !r[4]=c2;
741 or c_12,c_3,c_12 !=
742
743 mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
744 addcc c_12,t_1,c_12
745 clr c_3
746 bcs,a %xcc,.+8 !=
747 add c_3,t_2,c_3
748 mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
749 addcc c_12,t_1,c_12
750 bcs,a %xcc,.+8 !=
751 add c_3,t_2,c_3
752 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
753 addcc c_12,t_1,c_12
754 bcs,a %xcc,.+8 !=
755 add c_3,t_2,c_3
756 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
757 addcc c_12,t_1,c_12
758 bcs,a %xcc,.+8 !=
759 add c_3,t_2,c_3
760 lduw ap(5),a_5
761 mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
762 addcc c_12,t_1,c_12 !=
763 bcs,a %xcc,.+8
764 add c_3,t_2,c_3
765 lduw ap(6),a_6
766 mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2);
767 addcc c_12,t_1,t_1
768 bcs,a %xcc,.+8
769 add c_3,t_2,c_3
770 srlx t_1,32,c_12 !=
771 stuw t_1,rp(5) !r[5]=c3;
772 or c_12,c_3,c_12
773
774 mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
775 addcc c_12,t_1,c_12 !=
776 clr c_3
777 bcs,a %xcc,.+8
778 add c_3,t_2,c_3
779 mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
780 addcc c_12,t_1,c_12
781 bcs,a %xcc,.+8
782 add c_3,t_2,c_3
783 mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3);
784 addcc c_12,t_1,c_12
785 bcs,a %xcc,.+8
786 add c_3,t_2,c_3
787 mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3);
788 addcc c_12,t_1,c_12
789 bcs,a %xcc,.+8
790 add c_3,t_2,c_3
791 mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3);
792 addcc c_12,t_1,c_12
793 bcs,a %xcc,.+8
794 add c_3,t_2,c_3
795 lduw bp(6),b_6 !=
796 mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
797 addcc c_12,t_1,c_12
798 bcs,a %xcc,.+8
799 add c_3,t_2,c_3 !=
800 lduw bp(7),b_7
801 mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
802 addcc c_12,t_1,t_1
803 bcs,a %xcc,.+8 !=
804 add c_3,t_2,c_3
805 srlx t_1,32,c_12
806 stuw t_1,rp(6) !r[6]=c1;
807 or c_12,c_3,c_12 !=
808
809 mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
810 addcc c_12,t_1,c_12
811 clr c_3
812 bcs,a %xcc,.+8 !=
813 add c_3,t_2,c_3
814 mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
815 addcc c_12,t_1,c_12
816 bcs,a %xcc,.+8 !=
817 add c_3,t_2,c_3
818 mulx a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
819 addcc c_12,t_1,c_12
820 bcs,a %xcc,.+8 !=
821 add c_3,t_2,c_3
822 mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1);
823 addcc c_12,t_1,c_12
824 bcs,a %xcc,.+8 !=
825 add c_3,t_2,c_3
826 mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
827 addcc c_12,t_1,c_12
828 bcs,a %xcc,.+8 !=
829 add c_3,t_2,c_3
830 mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
831 addcc c_12,t_1,c_12
832 bcs,a %xcc,.+8 !=
833 add c_3,t_2,c_3
834 lduw ap(7),a_7
835 mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
836 addcc c_12,t_1,c_12
837 bcs,a %xcc,.+8
838 add c_3,t_2,c_3
839 mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1);
840 addcc c_12,t_1,t_1
841 bcs,a %xcc,.+8
842 add c_3,t_2,c_3
843 srlx t_1,32,c_12 !=
844 stuw t_1,rp(7) !r[7]=c2;
845 or c_12,c_3,c_12
846
847 mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2);
848 addcc c_12,t_1,c_12
849 clr c_3
850 bcs,a %xcc,.+8
851 add c_3,t_2,c_3 !=
852 mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],c3,c1,c2);
853 addcc c_12,t_1,c_12
854 bcs,a %xcc,.+8
855 add c_3,t_2,c_3 !=
856 mulx a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
857 addcc c_12,t_1,c_12
858 bcs,a %xcc,.+8
859 add c_3,t_2,c_3 !=
860 mulx a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
861 addcc c_12,t_1,c_12
862 bcs,a %xcc,.+8
863 add c_3,t_2,c_3 !=
864 mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
865 addcc c_12,t_1,c_12
866 bcs,a %xcc,.+8
867 add c_3,t_2,c_3 !=
868 mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2);
869 addcc c_12,t_1,c_12
870 bcs,a %xcc,.+8
871 add c_3,t_2,c_3 !=
872 mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
873 addcc c_12,t_1,t_1
874 bcs,a %xcc,.+8
875 add c_3,t_2,c_3 !=
876 srlx t_1,32,c_12
877 stuw t_1,rp(8) !r[8]=c3;
878 or c_12,c_3,c_12
879
880 mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3);
881 addcc c_12,t_1,c_12
882 clr c_3
883 bcs,a %xcc,.+8
884 add c_3,t_2,c_3 !=
885 mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],c1,c2,c3);
886 addcc c_12,t_1,c_12
887 bcs,a %xcc,.+8 !=
888 add c_3,t_2,c_3
889 mulx a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
890 addcc c_12,t_1,c_12
891 bcs,a %xcc,.+8 !=
892 add c_3,t_2,c_3
893 mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
894 addcc c_12,t_1,c_12
895 bcs,a %xcc,.+8 !=
896 add c_3,t_2,c_3
897 mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
898 addcc c_12,t_1,c_12
899 bcs,a %xcc,.+8 !=
900 add c_3,t_2,c_3
901 mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3);
902 addcc c_12,t_1,t_1
903 bcs,a %xcc,.+8 !=
904 add c_3,t_2,c_3
905 srlx t_1,32,c_12
906 stuw t_1,rp(9) !r[9]=c1;
907 or c_12,c_3,c_12 !=
908
909 mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
910 addcc c_12,t_1,c_12
911 clr c_3
912 bcs,a %xcc,.+8 !=
913 add c_3,t_2,c_3
914 mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
915 addcc c_12,t_1,c_12
916 bcs,a %xcc,.+8 !=
917 add c_3,t_2,c_3
918 mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1);
919 addcc c_12,t_1,c_12
920 bcs,a %xcc,.+8 !=
921 add c_3,t_2,c_3
922 mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
923 addcc c_12,t_1,c_12
924 bcs,a %xcc,.+8 !=
925 add c_3,t_2,c_3
926 mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
927 addcc c_12,t_1,t_1
928 bcs,a %xcc,.+8 !=
929 add c_3,t_2,c_3
930 srlx t_1,32,c_12
931 stuw t_1,rp(10) !r[10]=c2;
932 or c_12,c_3,c_12 !=
933
934 mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2);
935 addcc c_12,t_1,c_12
936 clr c_3
937 bcs,a %xcc,.+8 !=
938 add c_3,t_2,c_3
939 mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
940 addcc c_12,t_1,c_12
941 bcs,a %xcc,.+8 !=
942 add c_3,t_2,c_3
943 mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
944 addcc c_12,t_1,c_12
945 bcs,a %xcc,.+8 !=
946 add c_3,t_2,c_3
947 mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
948 addcc c_12,t_1,t_1
949 bcs,a %xcc,.+8 !=
950 add c_3,t_2,c_3
951 srlx t_1,32,c_12
952 stuw t_1,rp(11) !r[11]=c3;
953 or c_12,c_3,c_12 !=
954
955 mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
956 addcc c_12,t_1,c_12
957 clr c_3
958 bcs,a %xcc,.+8 !=
959 add c_3,t_2,c_3
960 mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
961 addcc c_12,t_1,c_12
962 bcs,a %xcc,.+8 !=
963 add c_3,t_2,c_3
964 mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
965 addcc c_12,t_1,t_1
966 bcs,a %xcc,.+8 !=
967 add c_3,t_2,c_3
968 srlx t_1,32,c_12
969 stuw t_1,rp(12) !r[12]=c1;
970 or c_12,c_3,c_12 !=
971
972 mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
973 addcc c_12,t_1,c_12
974 clr c_3
975 bcs,a %xcc,.+8 !=
976 add c_3,t_2,c_3
977 mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
978 addcc c_12,t_1,t_1
979 bcs,a %xcc,.+8 !=
980 add c_3,t_2,c_3
981 srlx t_1,32,c_12
982 st t_1,rp(13) !r[13]=c2;
983 or c_12,c_3,c_12 !=
984
985 mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2);
986 addcc c_12,t_1,t_1
987 srlx t_1,32,c_12 !=
988 stuw t_1,rp(14) !r[14]=c3;
989 stuw c_12,rp(15) !r[15]=c1;
990
991 ret
992 restore %g0,%g0,%o0 !=
993
994.type bn_mul_comba8,#function
995.size bn_mul_comba8,(.-bn_mul_comba8)
996
997.align 32
998
999.global bn_mul_comba4
1000/*
1001 * void bn_mul_comba4(r,a,b)
1002 * BN_ULONG *r,*a,*b;
1003 */
1004bn_mul_comba4:
1005 save %sp,FRAME_SIZE,%sp
1006 lduw ap(0),a_0
1007 mov 1,t_2
1008 lduw bp(0),b_0
1009 sllx t_2,32,t_2 !=
1010 lduw bp(1),b_1
1011 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
1012 srlx t_1,32,c_12
1013 stuw t_1,rp(0) !=!r[0]=c1;
1014
1015 lduw ap(1),a_1
1016 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
1017 addcc c_12,t_1,c_12
1018 clr c_3 !=
1019 bcs,a %xcc,.+8
1020 add c_3,t_2,c_3
1021 lduw ap(2),a_2
1022 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
1023 addcc c_12,t_1,t_1
1024 bcs,a %xcc,.+8
1025 add c_3,t_2,c_3
1026 srlx t_1,32,c_12 !=
1027 stuw t_1,rp(1) !r[1]=c2;
1028 or c_12,c_3,c_12
1029
1030 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
1031 addcc c_12,t_1,c_12 !=
1032 clr c_3
1033 bcs,a %xcc,.+8
1034 add c_3,t_2,c_3
1035 lduw bp(2),b_2 !=
1036 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
1037 addcc c_12,t_1,c_12
1038 bcs,a %xcc,.+8
1039 add c_3,t_2,c_3 !=
1040 lduw bp(3),b_3
1041 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
1042 addcc c_12,t_1,t_1
1043 bcs,a %xcc,.+8 !=
1044 add c_3,t_2,c_3
1045 srlx t_1,32,c_12
1046 stuw t_1,rp(2) !r[2]=c3;
1047 or c_12,c_3,c_12 !=
1048
1049 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
1050 addcc c_12,t_1,c_12
1051 clr c_3
1052 bcs,a %xcc,.+8 !=
1053 add c_3,t_2,c_3
1054 mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
1055 addcc c_12,t_1,c_12
1056 bcs,a %xcc,.+8 !=
1057 add c_3,t_2,c_3
1058 lduw ap(3),a_3
1059 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
1060 addcc c_12,t_1,c_12 !=
1061 bcs,a %xcc,.+8
1062 add c_3,t_2,c_3
1063 mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
1064 addcc c_12,t_1,t_1 !=
1065 bcs,a %xcc,.+8
1066 add c_3,t_2,c_3
1067 srlx t_1,32,c_12
1068 stuw t_1,rp(3) !=!r[3]=c1;
1069 or c_12,c_3,c_12
1070
1071 mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1072 addcc c_12,t_1,c_12
1073 clr c_3 !=
1074 bcs,a %xcc,.+8
1075 add c_3,t_2,c_3
1076 mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1077 addcc c_12,t_1,c_12 !=
1078 bcs,a %xcc,.+8
1079 add c_3,t_2,c_3
1080 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
1081 addcc c_12,t_1,t_1 !=
1082 bcs,a %xcc,.+8
1083 add c_3,t_2,c_3
1084 srlx t_1,32,c_12
1085 stuw t_1,rp(4) !=!r[4]=c2;
1086 or c_12,c_3,c_12
1087
1088 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1089 addcc c_12,t_1,c_12
1090 clr c_3 !=
1091 bcs,a %xcc,.+8
1092 add c_3,t_2,c_3
1093 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1094 addcc c_12,t_1,t_1 !=
1095 bcs,a %xcc,.+8
1096 add c_3,t_2,c_3
1097 srlx t_1,32,c_12
1098 stuw t_1,rp(5) !=!r[5]=c3;
1099 or c_12,c_3,c_12
1100
1101 mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1102 addcc c_12,t_1,t_1
1103 srlx t_1,32,c_12 !=
1104 stuw t_1,rp(6) !r[6]=c1;
1105 stuw c_12,rp(7) !r[7]=c2;
1106
1107 ret
1108 restore %g0,%g0,%o0
1109
1110.type bn_mul_comba4,#function
1111.size bn_mul_comba4,(.-bn_mul_comba4)
1112
1113.align 32
1114
1115.global bn_sqr_comba8
1116bn_sqr_comba8:
1117 save %sp,FRAME_SIZE,%sp
1118 mov 1,t_2
1119 lduw ap(0),a_0
1120 sllx t_2,32,t_2
1121 lduw ap(1),a_1
1122 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1123 srlx t_1,32,c_12
1124 stuw t_1,rp(0) !r[0]=c1;
1125
1126 lduw ap(2),a_2
1127 mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1128 addcc c_12,t_1,c_12
1129 clr c_3
1130 bcs,a %xcc,.+8
1131 add c_3,t_2,c_3
1132 addcc c_12,t_1,t_1
1133 bcs,a %xcc,.+8
1134 add c_3,t_2,c_3
1135 srlx t_1,32,c_12
1136 stuw t_1,rp(1) !r[1]=c2;
1137 or c_12,c_3,c_12
1138
1139 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1140 addcc c_12,t_1,c_12
1141 clr c_3
1142 bcs,a %xcc,.+8
1143 add c_3,t_2,c_3
1144 addcc c_12,t_1,c_12
1145 bcs,a %xcc,.+8
1146 add c_3,t_2,c_3
1147 lduw ap(3),a_3
1148 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1149 addcc c_12,t_1,t_1
1150 bcs,a %xcc,.+8
1151 add c_3,t_2,c_3
1152 srlx t_1,32,c_12
1153 stuw t_1,rp(2) !r[2]=c3;
1154 or c_12,c_3,c_12
1155
1156 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1157 addcc c_12,t_1,c_12
1158 clr c_3
1159 bcs,a %xcc,.+8
1160 add c_3,t_2,c_3
1161 addcc c_12,t_1,c_12
1162 bcs,a %xcc,.+8
1163 add c_3,t_2,c_3
1164 lduw ap(4),a_4
1165 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1166 addcc c_12,t_1,c_12
1167 bcs,a %xcc,.+8
1168 add c_3,t_2,c_3
1169 addcc c_12,t_1,t_1
1170 bcs,a %xcc,.+8
1171 add c_3,t_2,c_3
1172 srlx t_1,32,c_12
1173 st t_1,rp(3) !r[3]=c1;
1174 or c_12,c_3,c_12
1175
1176 mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1177 addcc c_12,t_1,c_12
1178 clr c_3
1179 bcs,a %xcc,.+8
1180 add c_3,t_2,c_3
1181 addcc c_12,t_1,c_12
1182 bcs,a %xcc,.+8
1183 add c_3,t_2,c_3
1184 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1185 addcc c_12,t_1,c_12
1186 bcs,a %xcc,.+8
1187 add c_3,t_2,c_3
1188 addcc c_12,t_1,c_12
1189 bcs,a %xcc,.+8
1190 add c_3,t_2,c_3
1191 lduw ap(5),a_5
1192 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1193 addcc c_12,t_1,t_1
1194 bcs,a %xcc,.+8
1195 add c_3,t_2,c_3
1196 srlx t_1,32,c_12
1197 stuw t_1,rp(4) !r[4]=c2;
1198 or c_12,c_3,c_12
1199
1200 mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1201 addcc c_12,t_1,c_12
1202 clr c_3
1203 bcs,a %xcc,.+8
1204 add c_3,t_2,c_3
1205 addcc c_12,t_1,c_12
1206 bcs,a %xcc,.+8
1207 add c_3,t_2,c_3
1208 mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1209 addcc c_12,t_1,c_12
1210 bcs,a %xcc,.+8
1211 add c_3,t_2,c_3
1212 addcc c_12,t_1,c_12
1213 bcs,a %xcc,.+8
1214 add c_3,t_2,c_3
1215 lduw ap(6),a_6
1216 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1217 addcc c_12,t_1,c_12
1218 bcs,a %xcc,.+8
1219 add c_3,t_2,c_3
1220 addcc c_12,t_1,t_1
1221 bcs,a %xcc,.+8
1222 add c_3,t_2,c_3
1223 srlx t_1,32,c_12
1224 stuw t_1,rp(5) !r[5]=c3;
1225 or c_12,c_3,c_12
1226
1227 mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1228 addcc c_12,t_1,c_12
1229 clr c_3
1230 bcs,a %xcc,.+8
1231 add c_3,t_2,c_3
1232 addcc c_12,t_1,c_12
1233 bcs,a %xcc,.+8
1234 add c_3,t_2,c_3
1235 mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1236 addcc c_12,t_1,c_12
1237 bcs,a %xcc,.+8
1238 add c_3,t_2,c_3
1239 addcc c_12,t_1,c_12
1240 bcs,a %xcc,.+8
1241 add c_3,t_2,c_3
1242 mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1243 addcc c_12,t_1,c_12
1244 bcs,a %xcc,.+8
1245 add c_3,t_2,c_3
1246 addcc c_12,t_1,c_12
1247 bcs,a %xcc,.+8
1248 add c_3,t_2,c_3
1249 lduw ap(7),a_7
1250 mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1251 addcc c_12,t_1,t_1
1252 bcs,a %xcc,.+8
1253 add c_3,t_2,c_3
1254 srlx t_1,32,c_12
1255 stuw t_1,rp(6) !r[6]=c1;
1256 or c_12,c_3,c_12
1257
1258 mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1259 addcc c_12,t_1,c_12
1260 clr c_3
1261 bcs,a %xcc,.+8
1262 add c_3,t_2,c_3
1263 addcc c_12,t_1,c_12
1264 bcs,a %xcc,.+8
1265 add c_3,t_2,c_3
1266 mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1267 addcc c_12,t_1,c_12
1268 bcs,a %xcc,.+8
1269 add c_3,t_2,c_3
1270 addcc c_12,t_1,c_12
1271 bcs,a %xcc,.+8
1272 add c_3,t_2,c_3
1273 mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1274 addcc c_12,t_1,c_12
1275 bcs,a %xcc,.+8
1276 add c_3,t_2,c_3
1277 addcc c_12,t_1,c_12
1278 bcs,a %xcc,.+8
1279 add c_3,t_2,c_3
1280 mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1281 addcc c_12,t_1,c_12
1282 bcs,a %xcc,.+8
1283 add c_3,t_2,c_3
1284 addcc c_12,t_1,t_1
1285 bcs,a %xcc,.+8
1286 add c_3,t_2,c_3
1287 srlx t_1,32,c_12
1288 stuw t_1,rp(7) !r[7]=c2;
1289 or c_12,c_3,c_12
1290
1291 mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1292 addcc c_12,t_1,c_12
1293 clr c_3
1294 bcs,a %xcc,.+8
1295 add c_3,t_2,c_3
1296 addcc c_12,t_1,c_12
1297 bcs,a %xcc,.+8
1298 add c_3,t_2,c_3
1299 mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1300 addcc c_12,t_1,c_12
1301 bcs,a %xcc,.+8
1302 add c_3,t_2,c_3
1303 addcc c_12,t_1,c_12
1304 bcs,a %xcc,.+8
1305 add c_3,t_2,c_3
1306 mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1307 addcc c_12,t_1,c_12
1308 bcs,a %xcc,.+8
1309 add c_3,t_2,c_3
1310 addcc c_12,t_1,c_12
1311 bcs,a %xcc,.+8
1312 add c_3,t_2,c_3
1313 mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1314 addcc c_12,t_1,t_1
1315 bcs,a %xcc,.+8
1316 add c_3,t_2,c_3
1317 srlx t_1,32,c_12
1318 stuw t_1,rp(8) !r[8]=c3;
1319 or c_12,c_3,c_12
1320
1321 mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1322 addcc c_12,t_1,c_12
1323 clr c_3
1324 bcs,a %xcc,.+8
1325 add c_3,t_2,c_3
1326 addcc c_12,t_1,c_12
1327 bcs,a %xcc,.+8
1328 add c_3,t_2,c_3
1329 mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1330 addcc c_12,t_1,c_12
1331 bcs,a %xcc,.+8
1332 add c_3,t_2,c_3
1333 addcc c_12,t_1,c_12
1334 bcs,a %xcc,.+8
1335 add c_3,t_2,c_3
1336 mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1337 addcc c_12,t_1,c_12
1338 bcs,a %xcc,.+8
1339 add c_3,t_2,c_3
1340 addcc c_12,t_1,t_1
1341 bcs,a %xcc,.+8
1342 add c_3,t_2,c_3
1343 srlx t_1,32,c_12
1344 stuw t_1,rp(9) !r[9]=c1;
1345 or c_12,c_3,c_12
1346
1347 mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1348 addcc c_12,t_1,c_12
1349 clr c_3
1350 bcs,a %xcc,.+8
1351 add c_3,t_2,c_3
1352 addcc c_12,t_1,c_12
1353 bcs,a %xcc,.+8
1354 add c_3,t_2,c_3
1355 mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1356 addcc c_12,t_1,c_12
1357 bcs,a %xcc,.+8
1358 add c_3,t_2,c_3
1359 addcc c_12,t_1,c_12
1360 bcs,a %xcc,.+8
1361 add c_3,t_2,c_3
1362 mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1363 addcc c_12,t_1,t_1
1364 bcs,a %xcc,.+8
1365 add c_3,t_2,c_3
1366 srlx t_1,32,c_12
1367 stuw t_1,rp(10) !r[10]=c2;
1368 or c_12,c_3,c_12
1369
1370 mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2);
1371 addcc c_12,t_1,c_12
1372 clr c_3
1373 bcs,a %xcc,.+8
1374 add c_3,t_2,c_3
1375 addcc c_12,t_1,c_12
1376 bcs,a %xcc,.+8
1377 add c_3,t_2,c_3
1378 mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2);
1379 addcc c_12,t_1,c_12
1380 bcs,a %xcc,.+8
1381 add c_3,t_2,c_3
1382 addcc c_12,t_1,t_1
1383 bcs,a %xcc,.+8
1384 add c_3,t_2,c_3
1385 srlx t_1,32,c_12
1386 stuw t_1,rp(11) !r[11]=c3;
1387 or c_12,c_3,c_12
1388
1389 mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1390 addcc c_12,t_1,c_12
1391 clr c_3
1392 bcs,a %xcc,.+8
1393 add c_3,t_2,c_3
1394 addcc c_12,t_1,c_12
1395 bcs,a %xcc,.+8
1396 add c_3,t_2,c_3
1397 mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1398 addcc c_12,t_1,t_1
1399 bcs,a %xcc,.+8
1400 add c_3,t_2,c_3
1401 srlx t_1,32,c_12
1402 stuw t_1,rp(12) !r[12]=c1;
1403 or c_12,c_3,c_12
1404
1405 mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1406 addcc c_12,t_1,c_12
1407 clr c_3
1408 bcs,a %xcc,.+8
1409 add c_3,t_2,c_3
1410 addcc c_12,t_1,t_1
1411 bcs,a %xcc,.+8
1412 add c_3,t_2,c_3
1413 srlx t_1,32,c_12
1414 stuw t_1,rp(13) !r[13]=c2;
1415 or c_12,c_3,c_12
1416
1417 mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1418 addcc c_12,t_1,t_1
1419 srlx t_1,32,c_12
1420 stuw t_1,rp(14) !r[14]=c3;
1421 stuw c_12,rp(15) !r[15]=c1;
1422
1423 ret
1424 restore %g0,%g0,%o0
1425
1426.type bn_sqr_comba8,#function
1427.size bn_sqr_comba8,(.-bn_sqr_comba8)
1428
1429.align 32
1430
1431.global bn_sqr_comba4
1432/*
1433 * void bn_sqr_comba4(r,a)
1434 * BN_ULONG *r,*a;
1435 */
1436bn_sqr_comba4:
1437 save %sp,FRAME_SIZE,%sp
1438 mov 1,t_2
1439 lduw ap(0),a_0
1440 sllx t_2,32,t_2
1441 lduw ap(1),a_1
1442 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1443 srlx t_1,32,c_12
1444 stuw t_1,rp(0) !r[0]=c1;
1445
1446 lduw ap(2),a_2
1447 mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1);
1448 addcc c_12,t_1,c_12
1449 clr c_3
1450 bcs,a %xcc,.+8
1451 add c_3,t_2,c_3
1452 addcc c_12,t_1,t_1
1453 bcs,a %xcc,.+8
1454 add c_3,t_2,c_3
1455 srlx t_1,32,c_12
1456 stuw t_1,rp(1) !r[1]=c2;
1457 or c_12,c_3,c_12
1458
1459 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1460 addcc c_12,t_1,c_12
1461 clr c_3
1462 bcs,a %xcc,.+8
1463 add c_3,t_2,c_3
1464 addcc c_12,t_1,c_12
1465 bcs,a %xcc,.+8
1466 add c_3,t_2,c_3
1467 lduw ap(3),a_3
1468 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1469 addcc c_12,t_1,t_1
1470 bcs,a %xcc,.+8
1471 add c_3,t_2,c_3
1472 srlx t_1,32,c_12
1473 stuw t_1,rp(2) !r[2]=c3;
1474 or c_12,c_3,c_12
1475
1476 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1477 addcc c_12,t_1,c_12
1478 clr c_3
1479 bcs,a %xcc,.+8
1480 add c_3,t_2,c_3
1481 addcc c_12,t_1,c_12
1482 bcs,a %xcc,.+8
1483 add c_3,t_2,c_3
1484 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1485 addcc c_12,t_1,c_12
1486 bcs,a %xcc,.+8
1487 add c_3,t_2,c_3
1488 addcc c_12,t_1,t_1
1489 bcs,a %xcc,.+8
1490 add c_3,t_2,c_3
1491 srlx t_1,32,c_12
1492 stuw t_1,rp(3) !r[3]=c1;
1493 or c_12,c_3,c_12
1494
1495 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1496 addcc c_12,t_1,c_12
1497 clr c_3
1498 bcs,a %xcc,.+8
1499 add c_3,t_2,c_3
1500 addcc c_12,t_1,c_12
1501 bcs,a %xcc,.+8
1502 add c_3,t_2,c_3
1503 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1504 addcc c_12,t_1,t_1
1505 bcs,a %xcc,.+8
1506 add c_3,t_2,c_3
1507 srlx t_1,32,c_12
1508 stuw t_1,rp(4) !r[4]=c2;
1509 or c_12,c_3,c_12
1510
1511 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1512 addcc c_12,t_1,c_12
1513 clr c_3
1514 bcs,a %xcc,.+8
1515 add c_3,t_2,c_3
1516 addcc c_12,t_1,t_1
1517 bcs,a %xcc,.+8
1518 add c_3,t_2,c_3
1519 srlx t_1,32,c_12
1520 stuw t_1,rp(5) !r[5]=c3;
1521 or c_12,c_3,c_12
1522
1523 mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1524 addcc c_12,t_1,t_1
1525 srlx t_1,32,c_12
1526 stuw t_1,rp(6) !r[6]=c1;
1527 stuw c_12,rp(7) !r[7]=c2;
1528
1529 ret
1530 restore %g0,%g0,%o0
1531
1532.type bn_sqr_comba4,#function
1533.size bn_sqr_comba4,(.-bn_sqr_comba4)
1534
1535.align 32
diff --git a/src/lib/libcrypto/bn/asm/x86.pl b/src/lib/libcrypto/bn/asm/x86.pl
new file mode 100644
index 0000000000..1bc4f1bb27
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86.pl
@@ -0,0 +1,28 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6require("x86/mul_add.pl");
7require("x86/mul.pl");
8require("x86/sqr.pl");
9require("x86/div.pl");
10require("x86/add.pl");
11require("x86/sub.pl");
12require("x86/comba.pl");
13
14&asm_init($ARGV[0],$0);
15
16&bn_mul_add_words("bn_mul_add_words");
17&bn_mul_words("bn_mul_words");
18&bn_sqr_words("bn_sqr_words");
19&bn_div_words("bn_div_words");
20&bn_add_words("bn_add_words");
21&bn_sub_words("bn_sub_words");
22&bn_mul_comba("bn_mul_comba8",8);
23&bn_mul_comba("bn_mul_comba4",4);
24&bn_sqr_comba("bn_sqr_comba8",8);
25&bn_sqr_comba("bn_sqr_comba4",4);
26
27&asm_finish();
28
diff --git a/src/lib/libcrypto/bn/asm/x86/add.pl b/src/lib/libcrypto/bn/asm/x86/add.pl
new file mode 100644
index 0000000000..0b5cf583e3
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/add.pl
@@ -0,0 +1,76 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $a="esi";
12 $b="edi";
13 $c="eax";
14 $r="ebx";
15 $tmp1="ecx";
16 $tmp2="edx";
17 $num="ebp";
18
19 &mov($r,&wparam(0)); # get r
20 &mov($a,&wparam(1)); # get a
21 &mov($b,&wparam(2)); # get b
22 &mov($num,&wparam(3)); # get num
23 &xor($c,$c); # clear carry
24 &and($num,0xfffffff8); # num / 8
25
26 &jz(&label("aw_finish"));
27
28 &set_label("aw_loop",0);
29 for ($i=0; $i<8; $i++)
30 {
31 &comment("Round $i");
32
33 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
34 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
35 &add($tmp1,$c);
36 &mov($c,0);
37 &adc($c,$c);
38 &add($tmp1,$tmp2);
39 &adc($c,0);
40 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
41 }
42
43 &comment("");
44 &add($a,32);
45 &add($b,32);
46 &add($r,32);
47 &sub($num,8);
48 &jnz(&label("aw_loop"));
49
50 &set_label("aw_finish",0);
51 &mov($num,&wparam(3)); # get num
52 &and($num,7);
53 &jz(&label("aw_end"));
54
55 for ($i=0; $i<7; $i++)
56 {
57 &comment("Tail Round $i");
58 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
59 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60 &add($tmp1,$c);
61 &mov($c,0);
62 &adc($c,$c);
63 &add($tmp1,$tmp2);
64 &adc($c,0);
65 &dec($num) if ($i != 6);
66 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
67 &jz(&label("aw_end")) if ($i != 6);
68 }
69 &set_label("aw_end",0);
70
71# &mov("eax",$c); # $c is "eax"
72
73 &function_end($name);
74 }
75
761;
diff --git a/src/lib/libcrypto/bn/asm/x86/comba.pl b/src/lib/libcrypto/bn/asm/x86/comba.pl
new file mode 100644
index 0000000000..2291253629
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/comba.pl
@@ -0,0 +1,277 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub mul_add_c
5 {
6 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
7
8 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
9 # words, and 1 if load return value
10
11 &comment("mul a[$ai]*b[$bi]");
12
13 # "eax" and "edx" will always be pre-loaded.
14 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
15 # &mov("edx",&DWP($bi*4,$b,"",0));
16
17 &mul("edx");
18 &add($c0,"eax");
19 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
20 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
21 ###
22 &adc($c1,"edx");
23 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
24 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
25 ###
26 &adc($c2,0);
27 # is pos > 1, it means it is the last loop
28 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
29 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
30 }
31
32sub sqr_add_c
33 {
34 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
35
36 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
37 # words, and 1 if load return value
38
39 &comment("sqr a[$ai]*a[$bi]");
40
41 # "eax" and "edx" will always be pre-loaded.
42 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
43 # &mov("edx",&DWP($bi*4,$b,"",0));
44
45 if ($ai == $bi)
46 { &mul("eax");}
47 else
48 { &mul("edx");}
49 &add($c0,"eax");
50 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
51 ###
52 &adc($c1,"edx");
53 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
54 ###
55 &adc($c2,0);
56 # is pos > 1, it means it is the last loop
57 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
58 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
59 }
60
61sub sqr_add_c2
62 {
63 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
64
65 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
66 # words, and 1 if load return value
67
68 &comment("sqr a[$ai]*a[$bi]");
69
70 # "eax" and "edx" will always be pre-loaded.
71 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
72 # &mov("edx",&DWP($bi*4,$a,"",0));
73
74 if ($ai == $bi)
75 { &mul("eax");}
76 else
77 { &mul("edx");}
78 &add("eax","eax");
79 ###
80 &adc("edx","edx");
81 ###
82 &adc($c2,0);
83 &add($c0,"eax");
84 &adc($c1,"edx");
85 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
86 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
87 &adc($c2,0);
88 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
89 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
90 ###
91 }
92
93sub bn_mul_comba
94 {
95 local($name,$num)=@_;
96 local($a,$b,$c0,$c1,$c2);
97 local($i,$as,$ae,$bs,$be,$ai,$bi);
98 local($tot,$end);
99
100 &function_begin_B($name,"");
101
102 $c0="ebx";
103 $c1="ecx";
104 $c2="ebp";
105 $a="esi";
106 $b="edi";
107
108 $as=0;
109 $ae=0;
110 $bs=0;
111 $be=0;
112 $tot=$num+$num-1;
113
114 &push("esi");
115 &mov($a,&wparam(1));
116 &push("edi");
117 &mov($b,&wparam(2));
118 &push("ebp");
119 &push("ebx");
120
121 &xor($c0,$c0);
122 &mov("eax",&DWP(0,$a,"",0)); # load the first word
123 &xor($c1,$c1);
124 &mov("edx",&DWP(0,$b,"",0)); # load the first second
125
126 for ($i=0; $i<$tot; $i++)
127 {
128 $ai=$as;
129 $bi=$bs;
130 $end=$be+1;
131
132 &comment("################## Calculate word $i");
133
134 for ($j=$bs; $j<$end; $j++)
135 {
136 &xor($c2,$c2) if ($j == $bs);
137 if (($j+1) == $end)
138 {
139 $v=1;
140 $v=2 if (($i+1) == $tot);
141 }
142 else
143 { $v=0; }
144 if (($j+1) != $end)
145 {
146 $na=($ai-1);
147 $nb=($bi+1);
148 }
149 else
150 {
151 $na=$as+($i < ($num-1));
152 $nb=$bs+($i >= ($num-1));
153 }
154#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
155 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
156 if ($v)
157 {
158 &comment("saved r[$i]");
159 # &mov("eax",&wparam(0));
160 # &mov(&DWP($i*4,"eax","",0),$c0);
161 ($c0,$c1,$c2)=($c1,$c2,$c0);
162 }
163 $ai--;
164 $bi++;
165 }
166 $as++ if ($i < ($num-1));
167 $ae++ if ($i >= ($num-1));
168
169 $bs++ if ($i >= ($num-1));
170 $be++ if ($i < ($num-1));
171 }
172 &comment("save r[$i]");
173 # &mov("eax",&wparam(0));
174 &mov(&DWP($i*4,"eax","",0),$c0);
175
176 &pop("ebx");
177 &pop("ebp");
178 &pop("edi");
179 &pop("esi");
180 &ret();
181 &function_end_B($name);
182 }
183
184sub bn_sqr_comba
185 {
186 local($name,$num)=@_;
187 local($r,$a,$c0,$c1,$c2)=@_;
188 local($i,$as,$ae,$bs,$be,$ai,$bi);
189 local($b,$tot,$end,$half);
190
191 &function_begin_B($name,"");
192
193 $c0="ebx";
194 $c1="ecx";
195 $c2="ebp";
196 $a="esi";
197 $r="edi";
198
199 &push("esi");
200 &push("edi");
201 &push("ebp");
202 &push("ebx");
203 &mov($r,&wparam(0));
204 &mov($a,&wparam(1));
205 &xor($c0,$c0);
206 &xor($c1,$c1);
207 &mov("eax",&DWP(0,$a,"",0)); # load the first word
208
209 $as=0;
210 $ae=0;
211 $bs=0;
212 $be=0;
213 $tot=$num+$num-1;
214
215 for ($i=0; $i<$tot; $i++)
216 {
217 $ai=$as;
218 $bi=$bs;
219 $end=$be+1;
220
221 &comment("############### Calculate word $i");
222 for ($j=$bs; $j<$end; $j++)
223 {
224 &xor($c2,$c2) if ($j == $bs);
225 if (($ai-1) < ($bi+1))
226 {
227 $v=1;
228 $v=2 if ($i+1) == $tot;
229 }
230 else
231 { $v=0; }
232 if (!$v)
233 {
234 $na=$ai-1;
235 $nb=$bi+1;
236 }
237 else
238 {
239 $na=$as+($i < ($num-1));
240 $nb=$bs+($i >= ($num-1));
241 }
242 if ($ai == $bi)
243 {
244 &sqr_add_c($r,$a,$ai,$bi,
245 $c0,$c1,$c2,$v,$i,$na,$nb);
246 }
247 else
248 {
249 &sqr_add_c2($r,$a,$ai,$bi,
250 $c0,$c1,$c2,$v,$i,$na,$nb);
251 }
252 if ($v)
253 {
254 &comment("saved r[$i]");
255 #&mov(&DWP($i*4,$r,"",0),$c0);
256 ($c0,$c1,$c2)=($c1,$c2,$c0);
257 last;
258 }
259 $ai--;
260 $bi++;
261 }
262 $as++ if ($i < ($num-1));
263 $ae++ if ($i >= ($num-1));
264
265 $bs++ if ($i >= ($num-1));
266 $be++ if ($i < ($num-1));
267 }
268 &mov(&DWP($i*4,$r,"",0),$c0);
269 &pop("ebx");
270 &pop("ebp");
271 &pop("edi");
272 &pop("esi");
273 &ret();
274 &function_end_B($name);
275 }
276
2771;
diff --git a/src/lib/libcrypto/bn/asm/x86/div.pl b/src/lib/libcrypto/bn/asm/x86/div.pl
new file mode 100644
index 0000000000..0e90152caa
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/div.pl
@@ -0,0 +1,15 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_div_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9 &mov("edx",&wparam(0)); #
10 &mov("eax",&wparam(1)); #
11 &mov("ebx",&wparam(2)); #
12 &div("ebx");
13 &function_end($name);
14 }
151;
diff --git a/src/lib/libcrypto/bn/asm/x86/mul.pl b/src/lib/libcrypto/bn/asm/x86/mul.pl
new file mode 100644
index 0000000000..674cb9b055
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/mul.pl
@@ -0,0 +1,77 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $Low="eax";
12 $High="edx";
13 $a="ebx";
14 $w="ecx";
15 $r="edi";
16 $c="esi";
17 $num="ebp";
18
19 &xor($c,$c); # clear carry
20 &mov($r,&wparam(0)); #
21 &mov($a,&wparam(1)); #
22 &mov($num,&wparam(2)); #
23 &mov($w,&wparam(3)); #
24
25 &and($num,0xfffffff8); # num / 8
26 &jz(&label("mw_finish"));
27
28 &set_label("mw_loop",0);
29 for ($i=0; $i<32; $i+=4)
30 {
31 &comment("Round $i");
32
33 &mov("eax",&DWP($i,$a,"",0)); # *a
34 &mul($w); # *a * w
35 &add("eax",$c); # L(t)+=c
36 # XXX
37
38 &adc("edx",0); # H(t)+=carry
39 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
40
41 &mov($c,"edx"); # c= H(t);
42 }
43
44 &comment("");
45 &add($a,32);
46 &add($r,32);
47 &sub($num,8);
48 &jz(&label("mw_finish"));
49 &jmp(&label("mw_loop"));
50
51 &set_label("mw_finish",0);
52 &mov($num,&wparam(2)); # get num
53 &and($num,7);
54 &jnz(&label("mw_finish2"));
55 &jmp(&label("mw_end"));
56
57 &set_label("mw_finish2",1);
58 for ($i=0; $i<7; $i++)
59 {
60 &comment("Tail Round $i");
61 &mov("eax",&DWP($i*4,$a,"",0));# *a
62 &mul($w); # *a * w
63 &add("eax",$c); # L(t)+=c
64 # XXX
65 &adc("edx",0); # H(t)+=carry
66 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
67 &mov($c,"edx"); # c= H(t);
68 &dec($num) if ($i != 7-1);
69 &jz(&label("mw_end")) if ($i != 7-1);
70 }
71 &set_label("mw_end",0);
72 &mov("eax",$c);
73
74 &function_end($name);
75 }
76
771;
diff --git a/src/lib/libcrypto/bn/asm/x86/mul_add.pl b/src/lib/libcrypto/bn/asm/x86/mul_add.pl
new file mode 100644
index 0000000000..61830d3a90
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/mul_add.pl
@@ -0,0 +1,87 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $Low="eax";
12 $High="edx";
13 $a="ebx";
14 $w="ebp";
15 $r="edi";
16 $c="esi";
17
18 &xor($c,$c); # clear carry
19 &mov($r,&wparam(0)); #
20
21 &mov("ecx",&wparam(2)); #
22 &mov($a,&wparam(1)); #
23
24 &and("ecx",0xfffffff8); # num / 8
25 &mov($w,&wparam(3)); #
26
27 &push("ecx"); # Up the stack for a tmp variable
28
29 &jz(&label("maw_finish"));
30
31 &set_label("maw_loop",0);
32
33 &mov(&swtmp(0),"ecx"); #
34
35 for ($i=0; $i<32; $i+=4)
36 {
37 &comment("Round $i");
38
39 &mov("eax",&DWP($i,$a,"",0)); # *a
40 &mul($w); # *a * w
41 &add("eax",$c); # L(t)+= *r
42 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
43 &adc("edx",0); # H(t)+=carry
44 &add("eax",$c); # L(t)+=c
45 &adc("edx",0); # H(t)+=carry
46 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
47 &mov($c,"edx"); # c= H(t);
48 }
49
50 &comment("");
51 &mov("ecx",&swtmp(0)); #
52 &add($a,32);
53 &add($r,32);
54 &sub("ecx",8);
55 &jnz(&label("maw_loop"));
56
57 &set_label("maw_finish",0);
58 &mov("ecx",&wparam(2)); # get num
59 &and("ecx",7);
60 &jnz(&label("maw_finish2")); # helps branch prediction
61 &jmp(&label("maw_end"));
62
63 &set_label("maw_finish2",1);
64 for ($i=0; $i<7; $i++)
65 {
66 &comment("Tail Round $i");
67 &mov("eax",&DWP($i*4,$a,"",0));# *a
68 &mul($w); # *a * w
69 &add("eax",$c); # L(t)+=c
70 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
71 &adc("edx",0); # H(t)+=carry
72 &add("eax",$c);
73 &adc("edx",0); # H(t)+=carry
74 &dec("ecx") if ($i != 7-1);
75 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
76 &mov($c,"edx"); # c= H(t);
77 &jz(&label("maw_end")) if ($i != 7-1);
78 }
79 &set_label("maw_end",0);
80 &mov("eax",$c);
81
82 &pop("ecx"); # clear variable from
83
84 &function_end($name);
85 }
86
871;
diff --git a/src/lib/libcrypto/bn/asm/x86/sqr.pl b/src/lib/libcrypto/bn/asm/x86/sqr.pl
new file mode 100644
index 0000000000..1f90993cf6
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/sqr.pl
@@ -0,0 +1,60 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $r="esi";
12 $a="edi";
13 $num="ebx";
14
15 &mov($r,&wparam(0)); #
16 &mov($a,&wparam(1)); #
17 &mov($num,&wparam(2)); #
18
19 &and($num,0xfffffff8); # num / 8
20 &jz(&label("sw_finish"));
21
22 &set_label("sw_loop",0);
23 for ($i=0; $i<32; $i+=4)
24 {
25 &comment("Round $i");
26 &mov("eax",&DWP($i,$a,"",0)); # *a
27 # XXX
28 &mul("eax"); # *a * *a
29 &mov(&DWP($i*2,$r,"",0),"eax"); #
30 &mov(&DWP($i*2+4,$r,"",0),"edx");#
31 }
32
33 &comment("");
34 &add($a,32);
35 &add($r,64);
36 &sub($num,8);
37 &jnz(&label("sw_loop"));
38
39 &set_label("sw_finish",0);
40 &mov($num,&wparam(2)); # get num
41 &and($num,7);
42 &jz(&label("sw_end"));
43
44 for ($i=0; $i<7; $i++)
45 {
46 &comment("Tail Round $i");
47 &mov("eax",&DWP($i*4,$a,"",0)); # *a
48 # XXX
49 &mul("eax"); # *a * *a
50 &mov(&DWP($i*8,$r,"",0),"eax"); #
51 &dec($num) if ($i != 7-1);
52 &mov(&DWP($i*8+4,$r,"",0),"edx");
53 &jz(&label("sw_end")) if ($i != 7-1);
54 }
55 &set_label("sw_end",0);
56
57 &function_end($name);
58 }
59
601;
diff --git a/src/lib/libcrypto/bn/asm/x86/sub.pl b/src/lib/libcrypto/bn/asm/x86/sub.pl
new file mode 100644
index 0000000000..837b0e1b07
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/sub.pl
@@ -0,0 +1,76 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $a="esi";
12 $b="edi";
13 $c="eax";
14 $r="ebx";
15 $tmp1="ecx";
16 $tmp2="edx";
17 $num="ebp";
18
19 &mov($r,&wparam(0)); # get r
20 &mov($a,&wparam(1)); # get a
21 &mov($b,&wparam(2)); # get b
22 &mov($num,&wparam(3)); # get num
23 &xor($c,$c); # clear carry
24 &and($num,0xfffffff8); # num / 8
25
26 &jz(&label("aw_finish"));
27
28 &set_label("aw_loop",0);
29 for ($i=0; $i<8; $i++)
30 {
31 &comment("Round $i");
32
33 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
34 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
35 &sub($tmp1,$c);
36 &mov($c,0);
37 &adc($c,$c);
38 &sub($tmp1,$tmp2);
39 &adc($c,0);
40 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
41 }
42
43 &comment("");
44 &add($a,32);
45 &add($b,32);
46 &add($r,32);
47 &sub($num,8);
48 &jnz(&label("aw_loop"));
49
50 &set_label("aw_finish",0);
51 &mov($num,&wparam(3)); # get num
52 &and($num,7);
53 &jz(&label("aw_end"));
54
55 for ($i=0; $i<7; $i++)
56 {
57 &comment("Tail Round $i");
58 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
59 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60 &sub($tmp1,$c);
61 &mov($c,0);
62 &adc($c,$c);
63 &sub($tmp1,$tmp2);
64 &adc($c,0);
65 &dec($num) if ($i != 6);
66 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
67 &jz(&label("aw_end")) if ($i != 6);
68 }
69 &set_label("aw_end",0);
70
71# &mov("eax",$c); # $c is "eax"
72
73 &function_end($name);
74 }
75
761;
diff --git a/src/lib/libcrypto/bn/asm/x86_64-gcc.c b/src/lib/libcrypto/bn/asm/x86_64-gcc.c
new file mode 100644
index 0000000000..7378344251
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86_64-gcc.c
@@ -0,0 +1,593 @@
1/*
2 * x86_64 BIGNUM accelerator version 0.1, December 2002.
3 *
4 * Implemented by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5 * project.
6 *
7 * Rights for redistribution and usage in source and binary forms are
8 * granted according to the OpenSSL license. Warranty of any kind is
9 * disclaimed.
10 *
11 * Q. Version 0.1? It doesn't sound like Andy, he used to assign real
12 * versions, like 1.0...
13 * A. Well, that's because this code is basically a quick-n-dirty
14 * proof-of-concept hack. As you can see it's implemented with
15 * inline assembler, which means that you're bound to GCC and that
16 * there might be enough room for further improvement.
17 *
18 * Q. Why inline assembler?
19 * A. x86_64 features own ABI which I'm not familiar with. This is
20 * why I decided to let the compiler take care of subroutine
21 * prologue/epilogue as well as register allocation. For reference.
22 * Win64 implements different ABI for AMD64, different from Linux.
23 *
24 * Q. How much faster does it get?
25 * A. 'apps/openssl speed rsa dsa' output with no-asm:
26 *
27 * sign verify sign/s verify/s
28 * rsa 512 bits 0.0006s 0.0001s 1683.8 18456.2
29 * rsa 1024 bits 0.0028s 0.0002s 356.0 6407.0
30 * rsa 2048 bits 0.0172s 0.0005s 58.0 1957.8
31 * rsa 4096 bits 0.1155s 0.0018s 8.7 555.6
32 * sign verify sign/s verify/s
33 * dsa 512 bits 0.0005s 0.0006s 2100.8 1768.3
34 * dsa 1024 bits 0.0014s 0.0018s 692.3 559.2
35 * dsa 2048 bits 0.0049s 0.0061s 204.7 165.0
36 *
37 * 'apps/openssl speed rsa dsa' output with this module:
38 *
39 * sign verify sign/s verify/s
40 * rsa 512 bits 0.0004s 0.0000s 2767.1 33297.9
41 * rsa 1024 bits 0.0012s 0.0001s 867.4 14674.7
42 * rsa 2048 bits 0.0061s 0.0002s 164.0 5270.0
43 * rsa 4096 bits 0.0384s 0.0006s 26.1 1650.8
44 * sign verify sign/s verify/s
45 * dsa 512 bits 0.0002s 0.0003s 4442.2 3786.3
46 * dsa 1024 bits 0.0005s 0.0007s 1835.1 1497.4
47 * dsa 2048 bits 0.0016s 0.0020s 620.4 504.6
48 *
49 * For the reference. IA-32 assembler implementation performs
50 * very much like 64-bit code compiled with no-asm on the same
51 * machine.
52 */
53
54#define BN_ULONG unsigned long
55
56/*
57 * "m"(a), "+m"(r) is the way to favor DirectPath µ-code;
58 * "g"(0) let the compiler to decide where does it
59 * want to keep the value of zero;
60 */
61#define mul_add(r,a,word,carry) do { \
62 register BN_ULONG high,low; \
63 asm ("mulq %3" \
64 : "=a"(low),"=d"(high) \
65 : "a"(word),"m"(a) \
66 : "cc"); \
67 asm ("addq %2,%0; adcq %3,%1" \
68 : "+r"(carry),"+d"(high)\
69 : "a"(low),"g"(0) \
70 : "cc"); \
71 asm ("addq %2,%0; adcq %3,%1" \
72 : "+m"(r),"+d"(high) \
73 : "r"(carry),"g"(0) \
74 : "cc"); \
75 carry=high; \
76 } while (0)
77
78#define mul(r,a,word,carry) do { \
79 register BN_ULONG high,low; \
80 asm ("mulq %3" \
81 : "=a"(low),"=d"(high) \
82 : "a"(word),"g"(a) \
83 : "cc"); \
84 asm ("addq %2,%0; adcq %3,%1" \
85 : "+r"(carry),"+d"(high)\
86 : "a"(low),"g"(0) \
87 : "cc"); \
88 (r)=carry, carry=high; \
89 } while (0)
90
91#define sqr(r0,r1,a) \
92 asm ("mulq %2" \
93 : "=a"(r0),"=d"(r1) \
94 : "a"(a) \
95 : "cc");
96
97BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
98 {
99 BN_ULONG c1=0;
100
101 if (num <= 0) return(c1);
102
103 while (num&~3)
104 {
105 mul_add(rp[0],ap[0],w,c1);
106 mul_add(rp[1],ap[1],w,c1);
107 mul_add(rp[2],ap[2],w,c1);
108 mul_add(rp[3],ap[3],w,c1);
109 ap+=4; rp+=4; num-=4;
110 }
111 if (num)
112 {
113 mul_add(rp[0],ap[0],w,c1); if (--num==0) return c1;
114 mul_add(rp[1],ap[1],w,c1); if (--num==0) return c1;
115 mul_add(rp[2],ap[2],w,c1); return c1;
116 }
117
118 return(c1);
119 }
120
121BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
122 {
123 BN_ULONG c1=0;
124
125 if (num <= 0) return(c1);
126
127 while (num&~3)
128 {
129 mul(rp[0],ap[0],w,c1);
130 mul(rp[1],ap[1],w,c1);
131 mul(rp[2],ap[2],w,c1);
132 mul(rp[3],ap[3],w,c1);
133 ap+=4; rp+=4; num-=4;
134 }
135 if (num)
136 {
137 mul(rp[0],ap[0],w,c1); if (--num == 0) return c1;
138 mul(rp[1],ap[1],w,c1); if (--num == 0) return c1;
139 mul(rp[2],ap[2],w,c1);
140 }
141 return(c1);
142 }
143
144void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
145 {
146 if (n <= 0) return;
147
148 while (n&~3)
149 {
150 sqr(r[0],r[1],a[0]);
151 sqr(r[2],r[3],a[1]);
152 sqr(r[4],r[5],a[2]);
153 sqr(r[6],r[7],a[3]);
154 a+=4; r+=8; n-=4;
155 }
156 if (n)
157 {
158 sqr(r[0],r[1],a[0]); if (--n == 0) return;
159 sqr(r[2],r[3],a[1]); if (--n == 0) return;
160 sqr(r[4],r[5],a[2]);
161 }
162 }
163
164BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
165{ BN_ULONG ret,waste;
166
167 asm ("divq %4"
168 : "=a"(ret),"=d"(waste)
169 : "a"(l),"d"(h),"g"(d)
170 : "cc");
171
172 return ret;
173}
174
175BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
176{ BN_ULONG ret=0,i=0;
177
178 if (n <= 0) return 0;
179
180 asm (
181 " subq %2,%2 \n"
182 ".align 16 \n"
183 "1: movq (%4,%2,8),%0 \n"
184 " adcq (%5,%2,8),%0 \n"
185 " movq %0,(%3,%2,8) \n"
186 " leaq 1(%2),%2 \n"
187 " loop 1b \n"
188 " sbbq %0,%0 \n"
189 : "=&a"(ret),"+c"(n),"=&r"(i)
190 : "r"(rp),"r"(ap),"r"(bp)
191 : "cc"
192 );
193
194 return ret&1;
195}
196
197#ifndef SIMICS
198BN_ULONG bn_sub_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
199{ BN_ULONG ret=0,i=0;
200
201 if (n <= 0) return 0;
202
203 asm (
204 " subq %2,%2 \n"
205 ".align 16 \n"
206 "1: movq (%4,%2,8),%0 \n"
207 " sbbq (%5,%2,8),%0 \n"
208 " movq %0,(%3,%2,8) \n"
209 " leaq 1(%2),%2 \n"
210 " loop 1b \n"
211 " sbbq %0,%0 \n"
212 : "=&a"(ret),"+c"(n),"=&r"(i)
213 : "r"(rp),"r"(ap),"r"(bp)
214 : "cc"
215 );
216
217 return ret&1;
218}
219#else
220/* Simics 1.4<7 has buggy sbbq:-( */
221#define BN_MASK2 0xffffffffffffffffL
222BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
223 {
224 BN_ULONG t1,t2;
225 int c=0;
226
227 if (n <= 0) return((BN_ULONG)0);
228
229 for (;;)
230 {
231 t1=a[0]; t2=b[0];
232 r[0]=(t1-t2-c)&BN_MASK2;
233 if (t1 != t2) c=(t1 < t2);
234 if (--n <= 0) break;
235
236 t1=a[1]; t2=b[1];
237 r[1]=(t1-t2-c)&BN_MASK2;
238 if (t1 != t2) c=(t1 < t2);
239 if (--n <= 0) break;
240
241 t1=a[2]; t2=b[2];
242 r[2]=(t1-t2-c)&BN_MASK2;
243 if (t1 != t2) c=(t1 < t2);
244 if (--n <= 0) break;
245
246 t1=a[3]; t2=b[3];
247 r[3]=(t1-t2-c)&BN_MASK2;
248 if (t1 != t2) c=(t1 < t2);
249 if (--n <= 0) break;
250
251 a+=4;
252 b+=4;
253 r+=4;
254 }
255 return(c);
256 }
257#endif
258
259/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
260/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
261/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
262/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
263
264#if 0
265/* original macros are kept for reference purposes */
266#define mul_add_c(a,b,c0,c1,c2) { \
267 BN_ULONG ta=(a),tb=(b); \
268 t1 = ta * tb; \
269 t2 = BN_UMULT_HIGH(ta,tb); \
270 c0 += t1; t2 += (c0<t1)?1:0; \
271 c1 += t2; c2 += (c1<t2)?1:0; \
272 }
273
274#define mul_add_c2(a,b,c0,c1,c2) { \
275 BN_ULONG ta=(a),tb=(b),t0; \
276 t1 = BN_UMULT_HIGH(ta,tb); \
277 t0 = ta * tb; \
278 t2 = t1+t1; c2 += (t2<t1)?1:0; \
279 t1 = t0+t0; t2 += (t1<t0)?1:0; \
280 c0 += t1; t2 += (c0<t1)?1:0; \
281 c1 += t2; c2 += (c1<t2)?1:0; \
282 }
283#else
284#define mul_add_c(a,b,c0,c1,c2) do { \
285 asm ("mulq %3" \
286 : "=a"(t1),"=d"(t2) \
287 : "a"(a),"m"(b) \
288 : "cc"); \
289 asm ("addq %2,%0; adcq %3,%1" \
290 : "+r"(c0),"+d"(t2) \
291 : "a"(t1),"g"(0) \
292 : "cc"); \
293 asm ("addq %2,%0; adcq %3,%1" \
294 : "+r"(c1),"+r"(c2) \
295 : "d"(t2),"g"(0) \
296 : "cc"); \
297 } while (0)
298
299#define sqr_add_c(a,i,c0,c1,c2) do { \
300 asm ("mulq %2" \
301 : "=a"(t1),"=d"(t2) \
302 : "a"(a[i]) \
303 : "cc"); \
304 asm ("addq %2,%0; adcq %3,%1" \
305 : "+r"(c0),"+d"(t2) \
306 : "a"(t1),"g"(0) \
307 : "cc"); \
308 asm ("addq %2,%0; adcq %3,%1" \
309 : "+r"(c1),"+r"(c2) \
310 : "d"(t2),"g"(0) \
311 : "cc"); \
312 } while (0)
313
314#define mul_add_c2(a,b,c0,c1,c2) do { \
315 asm ("mulq %3" \
316 : "=a"(t1),"=d"(t2) \
317 : "a"(a),"m"(b) \
318 : "cc"); \
319 asm ("addq %0,%0; adcq %2,%1" \
320 : "+d"(t2),"+r"(c2) \
321 : "g"(0) \
322 : "cc"); \
323 asm ("addq %0,%0; adcq %2,%1" \
324 : "+a"(t1),"+d"(t2) \
325 : "g"(0) \
326 : "cc"); \
327 asm ("addq %2,%0; adcq %3,%1" \
328 : "+r"(c0),"+d"(t2) \
329 : "a"(t1),"g"(0) \
330 : "cc"); \
331 asm ("addq %2,%0; adcq %3,%1" \
332 : "+r"(c1),"+r"(c2) \
333 : "d"(t2),"g"(0) \
334 : "cc"); \
335 } while (0)
336#endif
337
338#define sqr_add_c2(a,i,j,c0,c1,c2) \
339 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
340
341void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
342 {
343 BN_ULONG t1,t2;
344 BN_ULONG c1,c2,c3;
345
346 c1=0;
347 c2=0;
348 c3=0;
349 mul_add_c(a[0],b[0],c1,c2,c3);
350 r[0]=c1;
351 c1=0;
352 mul_add_c(a[0],b[1],c2,c3,c1);
353 mul_add_c(a[1],b[0],c2,c3,c1);
354 r[1]=c2;
355 c2=0;
356 mul_add_c(a[2],b[0],c3,c1,c2);
357 mul_add_c(a[1],b[1],c3,c1,c2);
358 mul_add_c(a[0],b[2],c3,c1,c2);
359 r[2]=c3;
360 c3=0;
361 mul_add_c(a[0],b[3],c1,c2,c3);
362 mul_add_c(a[1],b[2],c1,c2,c3);
363 mul_add_c(a[2],b[1],c1,c2,c3);
364 mul_add_c(a[3],b[0],c1,c2,c3);
365 r[3]=c1;
366 c1=0;
367 mul_add_c(a[4],b[0],c2,c3,c1);
368 mul_add_c(a[3],b[1],c2,c3,c1);
369 mul_add_c(a[2],b[2],c2,c3,c1);
370 mul_add_c(a[1],b[3],c2,c3,c1);
371 mul_add_c(a[0],b[4],c2,c3,c1);
372 r[4]=c2;
373 c2=0;
374 mul_add_c(a[0],b[5],c3,c1,c2);
375 mul_add_c(a[1],b[4],c3,c1,c2);
376 mul_add_c(a[2],b[3],c3,c1,c2);
377 mul_add_c(a[3],b[2],c3,c1,c2);
378 mul_add_c(a[4],b[1],c3,c1,c2);
379 mul_add_c(a[5],b[0],c3,c1,c2);
380 r[5]=c3;
381 c3=0;
382 mul_add_c(a[6],b[0],c1,c2,c3);
383 mul_add_c(a[5],b[1],c1,c2,c3);
384 mul_add_c(a[4],b[2],c1,c2,c3);
385 mul_add_c(a[3],b[3],c1,c2,c3);
386 mul_add_c(a[2],b[4],c1,c2,c3);
387 mul_add_c(a[1],b[5],c1,c2,c3);
388 mul_add_c(a[0],b[6],c1,c2,c3);
389 r[6]=c1;
390 c1=0;
391 mul_add_c(a[0],b[7],c2,c3,c1);
392 mul_add_c(a[1],b[6],c2,c3,c1);
393 mul_add_c(a[2],b[5],c2,c3,c1);
394 mul_add_c(a[3],b[4],c2,c3,c1);
395 mul_add_c(a[4],b[3],c2,c3,c1);
396 mul_add_c(a[5],b[2],c2,c3,c1);
397 mul_add_c(a[6],b[1],c2,c3,c1);
398 mul_add_c(a[7],b[0],c2,c3,c1);
399 r[7]=c2;
400 c2=0;
401 mul_add_c(a[7],b[1],c3,c1,c2);
402 mul_add_c(a[6],b[2],c3,c1,c2);
403 mul_add_c(a[5],b[3],c3,c1,c2);
404 mul_add_c(a[4],b[4],c3,c1,c2);
405 mul_add_c(a[3],b[5],c3,c1,c2);
406 mul_add_c(a[2],b[6],c3,c1,c2);
407 mul_add_c(a[1],b[7],c3,c1,c2);
408 r[8]=c3;
409 c3=0;
410 mul_add_c(a[2],b[7],c1,c2,c3);
411 mul_add_c(a[3],b[6],c1,c2,c3);
412 mul_add_c(a[4],b[5],c1,c2,c3);
413 mul_add_c(a[5],b[4],c1,c2,c3);
414 mul_add_c(a[6],b[3],c1,c2,c3);
415 mul_add_c(a[7],b[2],c1,c2,c3);
416 r[9]=c1;
417 c1=0;
418 mul_add_c(a[7],b[3],c2,c3,c1);
419 mul_add_c(a[6],b[4],c2,c3,c1);
420 mul_add_c(a[5],b[5],c2,c3,c1);
421 mul_add_c(a[4],b[6],c2,c3,c1);
422 mul_add_c(a[3],b[7],c2,c3,c1);
423 r[10]=c2;
424 c2=0;
425 mul_add_c(a[4],b[7],c3,c1,c2);
426 mul_add_c(a[5],b[6],c3,c1,c2);
427 mul_add_c(a[6],b[5],c3,c1,c2);
428 mul_add_c(a[7],b[4],c3,c1,c2);
429 r[11]=c3;
430 c3=0;
431 mul_add_c(a[7],b[5],c1,c2,c3);
432 mul_add_c(a[6],b[6],c1,c2,c3);
433 mul_add_c(a[5],b[7],c1,c2,c3);
434 r[12]=c1;
435 c1=0;
436 mul_add_c(a[6],b[7],c2,c3,c1);
437 mul_add_c(a[7],b[6],c2,c3,c1);
438 r[13]=c2;
439 c2=0;
440 mul_add_c(a[7],b[7],c3,c1,c2);
441 r[14]=c3;
442 r[15]=c1;
443 }
444
445void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
446 {
447 BN_ULONG t1,t2;
448 BN_ULONG c1,c2,c3;
449
450 c1=0;
451 c2=0;
452 c3=0;
453 mul_add_c(a[0],b[0],c1,c2,c3);
454 r[0]=c1;
455 c1=0;
456 mul_add_c(a[0],b[1],c2,c3,c1);
457 mul_add_c(a[1],b[0],c2,c3,c1);
458 r[1]=c2;
459 c2=0;
460 mul_add_c(a[2],b[0],c3,c1,c2);
461 mul_add_c(a[1],b[1],c3,c1,c2);
462 mul_add_c(a[0],b[2],c3,c1,c2);
463 r[2]=c3;
464 c3=0;
465 mul_add_c(a[0],b[3],c1,c2,c3);
466 mul_add_c(a[1],b[2],c1,c2,c3);
467 mul_add_c(a[2],b[1],c1,c2,c3);
468 mul_add_c(a[3],b[0],c1,c2,c3);
469 r[3]=c1;
470 c1=0;
471 mul_add_c(a[3],b[1],c2,c3,c1);
472 mul_add_c(a[2],b[2],c2,c3,c1);
473 mul_add_c(a[1],b[3],c2,c3,c1);
474 r[4]=c2;
475 c2=0;
476 mul_add_c(a[2],b[3],c3,c1,c2);
477 mul_add_c(a[3],b[2],c3,c1,c2);
478 r[5]=c3;
479 c3=0;
480 mul_add_c(a[3],b[3],c1,c2,c3);
481 r[6]=c1;
482 r[7]=c2;
483 }
484
485void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
486 {
487 BN_ULONG t1,t2;
488 BN_ULONG c1,c2,c3;
489
490 c1=0;
491 c2=0;
492 c3=0;
493 sqr_add_c(a,0,c1,c2,c3);
494 r[0]=c1;
495 c1=0;
496 sqr_add_c2(a,1,0,c2,c3,c1);
497 r[1]=c2;
498 c2=0;
499 sqr_add_c(a,1,c3,c1,c2);
500 sqr_add_c2(a,2,0,c3,c1,c2);
501 r[2]=c3;
502 c3=0;
503 sqr_add_c2(a,3,0,c1,c2,c3);
504 sqr_add_c2(a,2,1,c1,c2,c3);
505 r[3]=c1;
506 c1=0;
507 sqr_add_c(a,2,c2,c3,c1);
508 sqr_add_c2(a,3,1,c2,c3,c1);
509 sqr_add_c2(a,4,0,c2,c3,c1);
510 r[4]=c2;
511 c2=0;
512 sqr_add_c2(a,5,0,c3,c1,c2);
513 sqr_add_c2(a,4,1,c3,c1,c2);
514 sqr_add_c2(a,3,2,c3,c1,c2);
515 r[5]=c3;
516 c3=0;
517 sqr_add_c(a,3,c1,c2,c3);
518 sqr_add_c2(a,4,2,c1,c2,c3);
519 sqr_add_c2(a,5,1,c1,c2,c3);
520 sqr_add_c2(a,6,0,c1,c2,c3);
521 r[6]=c1;
522 c1=0;
523 sqr_add_c2(a,7,0,c2,c3,c1);
524 sqr_add_c2(a,6,1,c2,c3,c1);
525 sqr_add_c2(a,5,2,c2,c3,c1);
526 sqr_add_c2(a,4,3,c2,c3,c1);
527 r[7]=c2;
528 c2=0;
529 sqr_add_c(a,4,c3,c1,c2);
530 sqr_add_c2(a,5,3,c3,c1,c2);
531 sqr_add_c2(a,6,2,c3,c1,c2);
532 sqr_add_c2(a,7,1,c3,c1,c2);
533 r[8]=c3;
534 c3=0;
535 sqr_add_c2(a,7,2,c1,c2,c3);
536 sqr_add_c2(a,6,3,c1,c2,c3);
537 sqr_add_c2(a,5,4,c1,c2,c3);
538 r[9]=c1;
539 c1=0;
540 sqr_add_c(a,5,c2,c3,c1);
541 sqr_add_c2(a,6,4,c2,c3,c1);
542 sqr_add_c2(a,7,3,c2,c3,c1);
543 r[10]=c2;
544 c2=0;
545 sqr_add_c2(a,7,4,c3,c1,c2);
546 sqr_add_c2(a,6,5,c3,c1,c2);
547 r[11]=c3;
548 c3=0;
549 sqr_add_c(a,6,c1,c2,c3);
550 sqr_add_c2(a,7,5,c1,c2,c3);
551 r[12]=c1;
552 c1=0;
553 sqr_add_c2(a,7,6,c2,c3,c1);
554 r[13]=c2;
555 c2=0;
556 sqr_add_c(a,7,c3,c1,c2);
557 r[14]=c3;
558 r[15]=c1;
559 }
560
561void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
562 {
563 BN_ULONG t1,t2;
564 BN_ULONG c1,c2,c3;
565
566 c1=0;
567 c2=0;
568 c3=0;
569 sqr_add_c(a,0,c1,c2,c3);
570 r[0]=c1;
571 c1=0;
572 sqr_add_c2(a,1,0,c2,c3,c1);
573 r[1]=c2;
574 c2=0;
575 sqr_add_c(a,1,c3,c1,c2);
576 sqr_add_c2(a,2,0,c3,c1,c2);
577 r[2]=c3;
578 c3=0;
579 sqr_add_c2(a,3,0,c1,c2,c3);
580 sqr_add_c2(a,2,1,c1,c2,c3);
581 r[3]=c1;
582 c1=0;
583 sqr_add_c(a,2,c2,c3,c1);
584 sqr_add_c2(a,3,1,c2,c3,c1);
585 r[4]=c2;
586 c2=0;
587 sqr_add_c2(a,3,2,c3,c1,c2);
588 r[5]=c3;
589 c3=0;
590 sqr_add_c(a,3,c1,c2,c3);
591 r[6]=c1;
592 r[7]=c2;
593 }
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
new file mode 100644
index 0000000000..3da6d8ced9
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn.h
@@ -0,0 +1,549 @@
1/* crypto/bn/bn.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BN_H
60#define HEADER_BN_H
61
62#include <openssl/e_os2.h>
63#ifndef OPENSSL_NO_FP_API
64#include <stdio.h> /* FILE */
65#endif
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71#ifdef OPENSSL_SYS_VMS
72#undef BN_LLONG /* experimental, so far... */
73#endif
74
75#define BN_MUL_COMBA
76#define BN_SQR_COMBA
77#define BN_RECURSION
78
79/* This next option uses the C libraries (2 word)/(1 word) function.
80 * If it is not defined, I use my C version (which is slower).
81 * The reason for this flag is that when the particular C compiler
82 * library routine is used, and the library is linked with a different
83 * compiler, the library is missing. This mostly happens when the
84 * library is built with gcc and then linked using normal cc. This would
85 * be a common occurrence because gcc normally produces code that is
86 * 2 times faster than system compilers for the big number stuff.
87 * For machines with only one compiler (or shared libraries), this should
88 * be on. Again this in only really a problem on machines
89 * using "long long's", are 32bit, and are not using my assembler code. */
90#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \
91 defined(OPENSSL_SYS_WIN32) || defined(linux)
92# ifndef BN_DIV2W
93# define BN_DIV2W
94# endif
95#endif
96
97/* assuming long is 64bit - this is the DEC Alpha
98 * unsigned long long is only 64 bits :-(, don't define
99 * BN_LLONG for the DEC Alpha */
100#ifdef SIXTY_FOUR_BIT_LONG
101#define BN_ULLONG unsigned long long
102#define BN_ULONG unsigned long
103#define BN_LONG long
104#define BN_BITS 128
105#define BN_BYTES 8
106#define BN_BITS2 64
107#define BN_BITS4 32
108#define BN_MASK (0xffffffffffffffffffffffffffffffffLL)
109#define BN_MASK2 (0xffffffffffffffffL)
110#define BN_MASK2l (0xffffffffL)
111#define BN_MASK2h (0xffffffff00000000L)
112#define BN_MASK2h1 (0xffffffff80000000L)
113#define BN_TBIT (0x8000000000000000L)
114#define BN_DEC_CONV (10000000000000000000UL)
115#define BN_DEC_FMT1 "%lu"
116#define BN_DEC_FMT2 "%019lu"
117#define BN_DEC_NUM 19
118#endif
119
120/* This is where the long long data type is 64 bits, but long is 32.
121 * For machines where there are 64bit registers, this is the mode to use.
122 * IRIX, on R4000 and above should use this mode, along with the relevant
123 * assembler code :-). Do NOT define BN_LLONG.
124 */
125#ifdef SIXTY_FOUR_BIT
126#undef BN_LLONG
127#undef BN_ULLONG
128#define BN_ULONG unsigned long long
129#define BN_LONG long long
130#define BN_BITS 128
131#define BN_BYTES 8
132#define BN_BITS2 64
133#define BN_BITS4 32
134#define BN_MASK2 (0xffffffffffffffffLL)
135#define BN_MASK2l (0xffffffffL)
136#define BN_MASK2h (0xffffffff00000000LL)
137#define BN_MASK2h1 (0xffffffff80000000LL)
138#define BN_TBIT (0x8000000000000000LL)
139#define BN_DEC_CONV (10000000000000000000ULL)
140#define BN_DEC_FMT1 "%llu"
141#define BN_DEC_FMT2 "%019llu"
142#define BN_DEC_NUM 19
143#endif
144
145#ifdef THIRTY_TWO_BIT
146#if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
147#define BN_ULLONG unsigned _int64
148#else
149#define BN_ULLONG unsigned long long
150#endif
151#define BN_ULONG unsigned long
152#define BN_LONG long
153#define BN_BITS 64
154#define BN_BYTES 4
155#define BN_BITS2 32
156#define BN_BITS4 16
157#ifdef OPENSSL_SYS_WIN32
158/* VC++ doesn't like the LL suffix */
159#define BN_MASK (0xffffffffffffffffL)
160#else
161#define BN_MASK (0xffffffffffffffffLL)
162#endif
163#define BN_MASK2 (0xffffffffL)
164#define BN_MASK2l (0xffff)
165#define BN_MASK2h1 (0xffff8000L)
166#define BN_MASK2h (0xffff0000L)
167#define BN_TBIT (0x80000000L)
168#define BN_DEC_CONV (1000000000L)
169#define BN_DEC_FMT1 "%lu"
170#define BN_DEC_FMT2 "%09lu"
171#define BN_DEC_NUM 9
172#endif
173
174#ifdef SIXTEEN_BIT
175#ifndef BN_DIV2W
176#define BN_DIV2W
177#endif
178#define BN_ULLONG unsigned long
179#define BN_ULONG unsigned short
180#define BN_LONG short
181#define BN_BITS 32
182#define BN_BYTES 2
183#define BN_BITS2 16
184#define BN_BITS4 8
185#define BN_MASK (0xffffffff)
186#define BN_MASK2 (0xffff)
187#define BN_MASK2l (0xff)
188#define BN_MASK2h1 (0xff80)
189#define BN_MASK2h (0xff00)
190#define BN_TBIT (0x8000)
191#define BN_DEC_CONV (100000)
192#define BN_DEC_FMT1 "%u"
193#define BN_DEC_FMT2 "%05u"
194#define BN_DEC_NUM 5
195#endif
196
197#ifdef EIGHT_BIT
198#ifndef BN_DIV2W
199#define BN_DIV2W
200#endif
201#define BN_ULLONG unsigned short
202#define BN_ULONG unsigned char
203#define BN_LONG char
204#define BN_BITS 16
205#define BN_BYTES 1
206#define BN_BITS2 8
207#define BN_BITS4 4
208#define BN_MASK (0xffff)
209#define BN_MASK2 (0xff)
210#define BN_MASK2l (0xf)
211#define BN_MASK2h1 (0xf8)
212#define BN_MASK2h (0xf0)
213#define BN_TBIT (0x80)
214#define BN_DEC_CONV (100)
215#define BN_DEC_FMT1 "%u"
216#define BN_DEC_FMT2 "%02u"
217#define BN_DEC_NUM 2
218#endif
219
220#define BN_DEFAULT_BITS 1280
221
222#ifdef BIGNUM
223#undef BIGNUM
224#endif
225
226#define BN_FLG_MALLOCED 0x01
227#define BN_FLG_STATIC_DATA 0x02
228#define BN_FLG_FREE 0x8000 /* used for debuging */
229#define BN_set_flags(b,n) ((b)->flags|=(n))
230#define BN_get_flags(b,n) ((b)->flags&(n))
231
232typedef struct bignum_st
233 {
234 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
235 int top; /* Index of last used d +1. */
236 /* The next are internal book keeping for bn_expand. */
237 int dmax; /* Size of the d array. */
238 int neg; /* one if the number is negative */
239 int flags;
240 } BIGNUM;
241
242/* Used for temp variables (declaration hidden in bn_lcl.h) */
243typedef struct bignum_ctx BN_CTX;
244
245typedef struct bn_blinding_st
246 {
247 int init;
248 BIGNUM *A;
249 BIGNUM *Ai;
250 BIGNUM *mod; /* just a reference */
251 unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
252 * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
253 } BN_BLINDING;
254
255/* Used for montgomery multiplication */
256typedef struct bn_mont_ctx_st
257 {
258 int ri; /* number of bits in R */
259 BIGNUM RR; /* used to convert to montgomery form */
260 BIGNUM N; /* The modulus */
261 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
262 * (Ni is only stored for bignum algorithm) */
263 BN_ULONG n0; /* least significant word of Ni */
264 int flags;
265 } BN_MONT_CTX;
266
267/* Used for reciprocal division/mod functions
268 * It cannot be shared between threads
269 */
270typedef struct bn_recp_ctx_st
271 {
272 BIGNUM N; /* the divisor */
273 BIGNUM Nr; /* the reciprocal */
274 int num_bits;
275 int shift;
276 int flags;
277 } BN_RECP_CTX;
278
279#define BN_prime_checks 0 /* default: select number of iterations
280 based on the size of the number */
281
282/* number of Miller-Rabin iterations for an error rate of less than 2^-80
283 * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook
284 * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];
285 * original paper: Damgaard, Landrock, Pomerance: Average case error estimates
286 * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */
287#define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \
288 (b) >= 850 ? 3 : \
289 (b) >= 650 ? 4 : \
290 (b) >= 550 ? 5 : \
291 (b) >= 450 ? 6 : \
292 (b) >= 400 ? 7 : \
293 (b) >= 350 ? 8 : \
294 (b) >= 300 ? 9 : \
295 (b) >= 250 ? 12 : \
296 (b) >= 200 ? 15 : \
297 (b) >= 150 ? 18 : \
298 /* b >= 100 */ 27)
299
300#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
301
302/* Note that BN_abs_is_word does not work reliably for w == 0 */
303#define BN_abs_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
304#define BN_is_zero(a) (((a)->top == 0) || BN_abs_is_word(a,0))
305#define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg)
306#define BN_is_word(a,w) ((w) ? BN_abs_is_word((a),(w)) && !(a)->neg : \
307 BN_is_zero((a)))
308#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
309
310#define BN_one(a) (BN_set_word((a),1))
311#define BN_zero(a) (BN_set_word((a),0))
312
313/*#define BN_ascii2bn(a) BN_hex2bn(a) */
314/*#define BN_bn2ascii(a) BN_bn2hex(a) */
315
316const BIGNUM *BN_value_one(void);
317char * BN_options(void);
318BN_CTX *BN_CTX_new(void);
319void BN_CTX_init(BN_CTX *c);
320void BN_CTX_free(BN_CTX *c);
321void BN_CTX_start(BN_CTX *ctx);
322BIGNUM *BN_CTX_get(BN_CTX *ctx);
323void BN_CTX_end(BN_CTX *ctx);
324int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
325int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
326int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
327int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
328int BN_num_bits(const BIGNUM *a);
329int BN_num_bits_word(BN_ULONG);
330BIGNUM *BN_new(void);
331void BN_init(BIGNUM *);
332void BN_clear_free(BIGNUM *a);
333BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
334void BN_swap(BIGNUM *a, BIGNUM *b);
335BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
336int BN_bn2bin(const BIGNUM *a, unsigned char *to);
337BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret);
338int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
339int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
340int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
341int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
342int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
343int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
344int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
345
346int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
347 BN_CTX *ctx);
348#define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))
349int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
350int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
351int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
352int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
353int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
354int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
355 const BIGNUM *m, BN_CTX *ctx);
356int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
357int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
358int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);
359int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx);
360int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m);
361
362BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
363BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
364int BN_mul_word(BIGNUM *a, BN_ULONG w);
365int BN_add_word(BIGNUM *a, BN_ULONG w);
366int BN_sub_word(BIGNUM *a, BN_ULONG w);
367int BN_set_word(BIGNUM *a, BN_ULONG w);
368BN_ULONG BN_get_word(const BIGNUM *a);
369
370int BN_cmp(const BIGNUM *a, const BIGNUM *b);
371void BN_free(BIGNUM *a);
372int BN_is_bit_set(const BIGNUM *a, int n);
373int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
374int BN_lshift1(BIGNUM *r, const BIGNUM *a);
375int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx);
376
377int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
378 const BIGNUM *m,BN_CTX *ctx);
379int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
380 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
381int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p,
382 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
383int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,
384 const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m,
385 BN_CTX *ctx,BN_MONT_CTX *m_ctx);
386int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
387 const BIGNUM *m,BN_CTX *ctx);
388
389int BN_mask_bits(BIGNUM *a,int n);
390#ifndef OPENSSL_NO_FP_API
391int BN_print_fp(FILE *fp, const BIGNUM *a);
392#endif
393#ifdef HEADER_BIO_H
394int BN_print(BIO *fp, const BIGNUM *a);
395#else
396int BN_print(void *fp, const BIGNUM *a);
397#endif
398int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx);
399int BN_rshift(BIGNUM *r, const BIGNUM *a, int n);
400int BN_rshift1(BIGNUM *r, const BIGNUM *a);
401void BN_clear(BIGNUM *a);
402BIGNUM *BN_dup(const BIGNUM *a);
403int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
404int BN_set_bit(BIGNUM *a, int n);
405int BN_clear_bit(BIGNUM *a, int n);
406char * BN_bn2hex(const BIGNUM *a);
407char * BN_bn2dec(const BIGNUM *a);
408int BN_hex2bn(BIGNUM **a, const char *str);
409int BN_dec2bn(BIGNUM **a, const char *str);
410int BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx);
411int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */
412BIGNUM *BN_mod_inverse(BIGNUM *ret,
413 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
414BIGNUM *BN_mod_sqrt(BIGNUM *ret,
415 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
416BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,
417 const BIGNUM *add, const BIGNUM *rem,
418 void (*callback)(int,int,void *),void *cb_arg);
419int BN_is_prime(const BIGNUM *p,int nchecks,
420 void (*callback)(int,int,void *),
421 BN_CTX *ctx,void *cb_arg);
422int BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
423 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg,
424 int do_trial_division);
425
426BN_MONT_CTX *BN_MONT_CTX_new(void );
427void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
428int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,
429 BN_MONT_CTX *mont, BN_CTX *ctx);
430#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
431 (r),(a),&((mont)->RR),(mont),(ctx))
432int BN_from_montgomery(BIGNUM *r,const BIGNUM *a,
433 BN_MONT_CTX *mont, BN_CTX *ctx);
434void BN_MONT_CTX_free(BN_MONT_CTX *mont);
435int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx);
436BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
437
438BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
439void BN_BLINDING_free(BN_BLINDING *b);
440int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
441int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
442int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
443
444void BN_set_params(int mul,int high,int low,int mont);
445int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
446
447void BN_RECP_CTX_init(BN_RECP_CTX *recp);
448BN_RECP_CTX *BN_RECP_CTX_new(void);
449void BN_RECP_CTX_free(BN_RECP_CTX *recp);
450int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
451int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
452 BN_RECP_CTX *recp,BN_CTX *ctx);
453int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
454 const BIGNUM *m, BN_CTX *ctx);
455int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
456 BN_RECP_CTX *recp, BN_CTX *ctx);
457
458/* library internal functions */
459
460#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
461 (a):bn_expand2((a),(bits)/BN_BITS2+1))
462#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
463BIGNUM *bn_expand2(BIGNUM *a, int words);
464BIGNUM *bn_dup_expand(const BIGNUM *a, int words);
465
466#define bn_fix_top(a) \
467 { \
468 BN_ULONG *ftl; \
469 if ((a)->top > 0) \
470 { \
471 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
472 if (*(ftl--)) break; \
473 } \
474 }
475
476BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
477BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
478void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num);
479BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
480BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
481BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
482
483#ifdef BN_DEBUG
484void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
485# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
486 fprintf(stderr,"\n");}
487# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
488#else
489# define bn_print(a)
490# define bn_dump(a,b)
491#endif
492
493int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);
494
495/* BEGIN ERROR CODES */
496/* The following lines are auto generated by the script mkerr.pl. Any changes
497 * made after this point may be overwritten when the script is next run.
498 */
499void ERR_load_BN_strings(void);
500
501/* Error codes for the BN functions. */
502
503/* Function codes. */
504#define BN_F_BN_BLINDING_CONVERT 100
505#define BN_F_BN_BLINDING_INVERT 101
506#define BN_F_BN_BLINDING_NEW 102
507#define BN_F_BN_BLINDING_UPDATE 103
508#define BN_F_BN_BN2DEC 104
509#define BN_F_BN_BN2HEX 105
510#define BN_F_BN_CTX_GET 116
511#define BN_F_BN_CTX_NEW 106
512#define BN_F_BN_DIV 107
513#define BN_F_BN_EXPAND2 108
514#define BN_F_BN_EXPAND_INTERNAL 120
515#define BN_F_BN_MOD_EXP2_MONT 118
516#define BN_F_BN_MOD_EXP_MONT 109
517#define BN_F_BN_MOD_EXP_MONT_WORD 117
518#define BN_F_BN_MOD_INVERSE 110
519#define BN_F_BN_MOD_LSHIFT_QUICK 119
520#define BN_F_BN_MOD_MUL_RECIPROCAL 111
521#define BN_F_BN_MOD_SQRT 121
522#define BN_F_BN_MPI2BN 112
523#define BN_F_BN_NEW 113
524#define BN_F_BN_RAND 114
525#define BN_F_BN_RAND_RANGE 122
526#define BN_F_BN_USUB 115
527
528/* Reason codes. */
529#define BN_R_ARG2_LT_ARG3 100
530#define BN_R_BAD_RECIPROCAL 101
531#define BN_R_BIGNUM_TOO_LONG 114
532#define BN_R_CALLED_WITH_EVEN_MODULUS 102
533#define BN_R_DIV_BY_ZERO 103
534#define BN_R_ENCODING_ERROR 104
535#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
536#define BN_R_INPUT_NOT_REDUCED 110
537#define BN_R_INVALID_LENGTH 106
538#define BN_R_INVALID_RANGE 115
539#define BN_R_NOT_A_SQUARE 111
540#define BN_R_NOT_INITIALIZED 107
541#define BN_R_NO_INVERSE 108
542#define BN_R_P_IS_NOT_PRIME 112
543#define BN_R_TOO_MANY_ITERATIONS 113
544#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
545
546#ifdef __cplusplus
547}
548#endif
549#endif
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
new file mode 100644
index 0000000000..6cba07e9f6
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_add.c
@@ -0,0 +1,309 @@
1/* crypto/bn/bn_add.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63/* r can == a or b */
64int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
65 {
66 const BIGNUM *tmp;
67 int a_neg = a->neg;
68
69 bn_check_top(a);
70 bn_check_top(b);
71
72 /* a + b a+b
73 * a + -b a-b
74 * -a + b b-a
75 * -a + -b -(a+b)
76 */
77 if (a_neg ^ b->neg)
78 {
79 /* only one is negative */
80 if (a_neg)
81 { tmp=a; a=b; b=tmp; }
82
83 /* we are now a - b */
84
85 if (BN_ucmp(a,b) < 0)
86 {
87 if (!BN_usub(r,b,a)) return(0);
88 r->neg=1;
89 }
90 else
91 {
92 if (!BN_usub(r,a,b)) return(0);
93 r->neg=0;
94 }
95 return(1);
96 }
97
98 if (!BN_uadd(r,a,b)) return(0);
99 if (a_neg) /* both are neg */
100 r->neg=1;
101 else
102 r->neg=0;
103 return(1);
104 }
105
106/* unsigned add of b to a, r must be large enough */
107int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
108 {
109 register int i;
110 int max,min;
111 BN_ULONG *ap,*bp,*rp,carry,t1;
112 const BIGNUM *tmp;
113
114 bn_check_top(a);
115 bn_check_top(b);
116
117 if (a->top < b->top)
118 { tmp=a; a=b; b=tmp; }
119 max=a->top;
120 min=b->top;
121
122 if (bn_wexpand(r,max+1) == NULL)
123 return(0);
124
125 r->top=max;
126
127
128 ap=a->d;
129 bp=b->d;
130 rp=r->d;
131 carry=0;
132
133 carry=bn_add_words(rp,ap,bp,min);
134 rp+=min;
135 ap+=min;
136 bp+=min;
137 i=min;
138
139 if (carry)
140 {
141 while (i < max)
142 {
143 i++;
144 t1= *(ap++);
145 if ((*(rp++)=(t1+1)&BN_MASK2) >= t1)
146 {
147 carry=0;
148 break;
149 }
150 }
151 if ((i >= max) && carry)
152 {
153 *(rp++)=1;
154 r->top++;
155 }
156 }
157 if (rp != ap)
158 {
159 for (; i<max; i++)
160 *(rp++)= *(ap++);
161 }
162 /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
163 r->neg = 0;
164 return(1);
165 }
166
167/* unsigned subtraction of b from a, a must be larger than b. */
168int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
169 {
170 int max,min;
171 register BN_ULONG t1,t2,*ap,*bp,*rp;
172 int i,carry;
173#if defined(IRIX_CC_BUG) && !defined(LINT)
174 int dummy;
175#endif
176
177 bn_check_top(a);
178 bn_check_top(b);
179
180 if (a->top < b->top) /* hmm... should not be happening */
181 {
182 BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
183 return(0);
184 }
185
186 max=a->top;
187 min=b->top;
188 if (bn_wexpand(r,max) == NULL) return(0);
189
190 ap=a->d;
191 bp=b->d;
192 rp=r->d;
193
194#if 1
195 carry=0;
196 for (i=0; i<min; i++)
197 {
198 t1= *(ap++);
199 t2= *(bp++);
200 if (carry)
201 {
202 carry=(t1 <= t2);
203 t1=(t1-t2-1)&BN_MASK2;
204 }
205 else
206 {
207 carry=(t1 < t2);
208 t1=(t1-t2)&BN_MASK2;
209 }
210#if defined(IRIX_CC_BUG) && !defined(LINT)
211 dummy=t1;
212#endif
213 *(rp++)=t1&BN_MASK2;
214 }
215#else
216 carry=bn_sub_words(rp,ap,bp,min);
217 ap+=min;
218 bp+=min;
219 rp+=min;
220 i=min;
221#endif
222 if (carry) /* subtracted */
223 {
224 while (i < max)
225 {
226 i++;
227 t1= *(ap++);
228 t2=(t1-1)&BN_MASK2;
229 *(rp++)=t2;
230 if (t1 > t2) break;
231 }
232 }
233#if 0
234 memcpy(rp,ap,sizeof(*rp)*(max-i));
235#else
236 if (rp != ap)
237 {
238 for (;;)
239 {
240 if (i++ >= max) break;
241 rp[0]=ap[0];
242 if (i++ >= max) break;
243 rp[1]=ap[1];
244 if (i++ >= max) break;
245 rp[2]=ap[2];
246 if (i++ >= max) break;
247 rp[3]=ap[3];
248 rp+=4;
249 ap+=4;
250 }
251 }
252#endif
253
254 r->top=max;
255 r->neg=0;
256 bn_fix_top(r);
257 return(1);
258 }
259
260int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
261 {
262 int max;
263 int add=0,neg=0;
264 const BIGNUM *tmp;
265
266 bn_check_top(a);
267 bn_check_top(b);
268
269 /* a - b a-b
270 * a - -b a+b
271 * -a - b -(a+b)
272 * -a - -b b-a
273 */
274 if (a->neg)
275 {
276 if (b->neg)
277 { tmp=a; a=b; b=tmp; }
278 else
279 { add=1; neg=1; }
280 }
281 else
282 {
283 if (b->neg) { add=1; neg=0; }
284 }
285
286 if (add)
287 {
288 if (!BN_uadd(r,a,b)) return(0);
289 r->neg=neg;
290 return(1);
291 }
292
293 /* We are actually doing a - b :-) */
294
295 max=(a->top > b->top)?a->top:b->top;
296 if (bn_wexpand(r,max) == NULL) return(0);
297 if (BN_ucmp(a,b) < 0)
298 {
299 if (!BN_usub(r,b,a)) return(0);
300 r->neg=1;
301 }
302 else
303 {
304 if (!BN_usub(r,a,b)) return(0);
305 r->neg=0;
306 }
307 return(1);
308 }
309
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
new file mode 100644
index 0000000000..be8aa3ffc5
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_asm.c
@@ -0,0 +1,832 @@
1/* crypto/bn/bn_asm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef BN_DEBUG
60# undef NDEBUG /* avoid conflicting definitions */
61# define NDEBUG
62#endif
63
64#include <stdio.h>
65#include <assert.h>
66#include "cryptlib.h"
67#include "bn_lcl.h"
68
69#if defined(BN_LLONG) || defined(BN_UMULT_HIGH)
70
71BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
72 {
73 BN_ULONG c1=0;
74
75 assert(num >= 0);
76 if (num <= 0) return(c1);
77
78 while (num&~3)
79 {
80 mul_add(rp[0],ap[0],w,c1);
81 mul_add(rp[1],ap[1],w,c1);
82 mul_add(rp[2],ap[2],w,c1);
83 mul_add(rp[3],ap[3],w,c1);
84 ap+=4; rp+=4; num-=4;
85 }
86 if (num)
87 {
88 mul_add(rp[0],ap[0],w,c1); if (--num==0) return c1;
89 mul_add(rp[1],ap[1],w,c1); if (--num==0) return c1;
90 mul_add(rp[2],ap[2],w,c1); return c1;
91 }
92
93 return(c1);
94 }
95
96BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
97 {
98 BN_ULONG c1=0;
99
100 assert(num >= 0);
101 if (num <= 0) return(c1);
102
103 while (num&~3)
104 {
105 mul(rp[0],ap[0],w,c1);
106 mul(rp[1],ap[1],w,c1);
107 mul(rp[2],ap[2],w,c1);
108 mul(rp[3],ap[3],w,c1);
109 ap+=4; rp+=4; num-=4;
110 }
111 if (num)
112 {
113 mul(rp[0],ap[0],w,c1); if (--num == 0) return c1;
114 mul(rp[1],ap[1],w,c1); if (--num == 0) return c1;
115 mul(rp[2],ap[2],w,c1);
116 }
117 return(c1);
118 }
119
120void bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
121 {
122 assert(n >= 0);
123 if (n <= 0) return;
124 while (n&~3)
125 {
126 sqr(r[0],r[1],a[0]);
127 sqr(r[2],r[3],a[1]);
128 sqr(r[4],r[5],a[2]);
129 sqr(r[6],r[7],a[3]);
130 a+=4; r+=8; n-=4;
131 }
132 if (n)
133 {
134 sqr(r[0],r[1],a[0]); if (--n == 0) return;
135 sqr(r[2],r[3],a[1]); if (--n == 0) return;
136 sqr(r[4],r[5],a[2]);
137 }
138 }
139
140#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
141
142BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
143 {
144 BN_ULONG c=0;
145 BN_ULONG bl,bh;
146
147 assert(num >= 0);
148 if (num <= 0) return((BN_ULONG)0);
149
150 bl=LBITS(w);
151 bh=HBITS(w);
152
153 for (;;)
154 {
155 mul_add(rp[0],ap[0],bl,bh,c);
156 if (--num == 0) break;
157 mul_add(rp[1],ap[1],bl,bh,c);
158 if (--num == 0) break;
159 mul_add(rp[2],ap[2],bl,bh,c);
160 if (--num == 0) break;
161 mul_add(rp[3],ap[3],bl,bh,c);
162 if (--num == 0) break;
163 ap+=4;
164 rp+=4;
165 }
166 return(c);
167 }
168
169BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
170 {
171 BN_ULONG carry=0;
172 BN_ULONG bl,bh;
173
174 assert(num >= 0);
175 if (num <= 0) return((BN_ULONG)0);
176
177 bl=LBITS(w);
178 bh=HBITS(w);
179
180 for (;;)
181 {
182 mul(rp[0],ap[0],bl,bh,carry);
183 if (--num == 0) break;
184 mul(rp[1],ap[1],bl,bh,carry);
185 if (--num == 0) break;
186 mul(rp[2],ap[2],bl,bh,carry);
187 if (--num == 0) break;
188 mul(rp[3],ap[3],bl,bh,carry);
189 if (--num == 0) break;
190 ap+=4;
191 rp+=4;
192 }
193 return(carry);
194 }
195
196void bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
197 {
198 assert(n >= 0);
199 if (n <= 0) return;
200 for (;;)
201 {
202 sqr64(r[0],r[1],a[0]);
203 if (--n == 0) break;
204
205 sqr64(r[2],r[3],a[1]);
206 if (--n == 0) break;
207
208 sqr64(r[4],r[5],a[2]);
209 if (--n == 0) break;
210
211 sqr64(r[6],r[7],a[3]);
212 if (--n == 0) break;
213
214 a+=4;
215 r+=8;
216 }
217 }
218
219#endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
220
221#if defined(BN_LLONG) && defined(BN_DIV2W)
222
223BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
224 {
225 return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d));
226 }
227
228#else
229
230/* Divide h,l by d and return the result. */
231/* I need to test this some more :-( */
232BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
233 {
234 BN_ULONG dh,dl,q,ret=0,th,tl,t;
235 int i,count=2;
236
237 if (d == 0) return(BN_MASK2);
238
239 i=BN_num_bits_word(d);
240 assert((i == BN_BITS2) || (h > (BN_ULONG)1<<i));
241
242 i=BN_BITS2-i;
243 if (h >= d) h-=d;
244
245 if (i)
246 {
247 d<<=i;
248 h=(h<<i)|(l>>(BN_BITS2-i));
249 l<<=i;
250 }
251 dh=(d&BN_MASK2h)>>BN_BITS4;
252 dl=(d&BN_MASK2l);
253 for (;;)
254 {
255 if ((h>>BN_BITS4) == dh)
256 q=BN_MASK2l;
257 else
258 q=h/dh;
259
260 th=q*dh;
261 tl=dl*q;
262 for (;;)
263 {
264 t=h-th;
265 if ((t&BN_MASK2h) ||
266 ((tl) <= (
267 (t<<BN_BITS4)|
268 ((l&BN_MASK2h)>>BN_BITS4))))
269 break;
270 q--;
271 th-=dh;
272 tl-=dl;
273 }
274 t=(tl>>BN_BITS4);
275 tl=(tl<<BN_BITS4)&BN_MASK2h;
276 th+=t;
277
278 if (l < tl) th++;
279 l-=tl;
280 if (h < th)
281 {
282 h+=d;
283 q--;
284 }
285 h-=th;
286
287 if (--count == 0) break;
288
289 ret=q<<BN_BITS4;
290 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
291 l=(l&BN_MASK2l)<<BN_BITS4;
292 }
293 ret|=q;
294 return(ret);
295 }
296#endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */
297
298#ifdef BN_LLONG
299BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
300 {
301 BN_ULLONG ll=0;
302
303 assert(n >= 0);
304 if (n <= 0) return((BN_ULONG)0);
305
306 for (;;)
307 {
308 ll+=(BN_ULLONG)a[0]+b[0];
309 r[0]=(BN_ULONG)ll&BN_MASK2;
310 ll>>=BN_BITS2;
311 if (--n <= 0) break;
312
313 ll+=(BN_ULLONG)a[1]+b[1];
314 r[1]=(BN_ULONG)ll&BN_MASK2;
315 ll>>=BN_BITS2;
316 if (--n <= 0) break;
317
318 ll+=(BN_ULLONG)a[2]+b[2];
319 r[2]=(BN_ULONG)ll&BN_MASK2;
320 ll>>=BN_BITS2;
321 if (--n <= 0) break;
322
323 ll+=(BN_ULLONG)a[3]+b[3];
324 r[3]=(BN_ULONG)ll&BN_MASK2;
325 ll>>=BN_BITS2;
326 if (--n <= 0) break;
327
328 a+=4;
329 b+=4;
330 r+=4;
331 }
332 return((BN_ULONG)ll);
333 }
334#else /* !BN_LLONG */
335BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
336 {
337 BN_ULONG c,l,t;
338
339 assert(n >= 0);
340 if (n <= 0) return((BN_ULONG)0);
341
342 c=0;
343 for (;;)
344 {
345 t=a[0];
346 t=(t+c)&BN_MASK2;
347 c=(t < c);
348 l=(t+b[0])&BN_MASK2;
349 c+=(l < t);
350 r[0]=l;
351 if (--n <= 0) break;
352
353 t=a[1];
354 t=(t+c)&BN_MASK2;
355 c=(t < c);
356 l=(t+b[1])&BN_MASK2;
357 c+=(l < t);
358 r[1]=l;
359 if (--n <= 0) break;
360
361 t=a[2];
362 t=(t+c)&BN_MASK2;
363 c=(t < c);
364 l=(t+b[2])&BN_MASK2;
365 c+=(l < t);
366 r[2]=l;
367 if (--n <= 0) break;
368
369 t=a[3];
370 t=(t+c)&BN_MASK2;
371 c=(t < c);
372 l=(t+b[3])&BN_MASK2;
373 c+=(l < t);
374 r[3]=l;
375 if (--n <= 0) break;
376
377 a+=4;
378 b+=4;
379 r+=4;
380 }
381 return((BN_ULONG)c);
382 }
383#endif /* !BN_LLONG */
384
385BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
386 {
387 BN_ULONG t1,t2;
388 int c=0;
389
390 assert(n >= 0);
391 if (n <= 0) return((BN_ULONG)0);
392
393 for (;;)
394 {
395 t1=a[0]; t2=b[0];
396 r[0]=(t1-t2-c)&BN_MASK2;
397 if (t1 != t2) c=(t1 < t2);
398 if (--n <= 0) break;
399
400 t1=a[1]; t2=b[1];
401 r[1]=(t1-t2-c)&BN_MASK2;
402 if (t1 != t2) c=(t1 < t2);
403 if (--n <= 0) break;
404
405 t1=a[2]; t2=b[2];
406 r[2]=(t1-t2-c)&BN_MASK2;
407 if (t1 != t2) c=(t1 < t2);
408 if (--n <= 0) break;
409
410 t1=a[3]; t2=b[3];
411 r[3]=(t1-t2-c)&BN_MASK2;
412 if (t1 != t2) c=(t1 < t2);
413 if (--n <= 0) break;
414
415 a+=4;
416 b+=4;
417 r+=4;
418 }
419 return(c);
420 }
421
422#ifdef BN_MUL_COMBA
423
424#undef bn_mul_comba8
425#undef bn_mul_comba4
426#undef bn_sqr_comba8
427#undef bn_sqr_comba4
428
429/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
430/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
431/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
432/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
433
434#ifdef BN_LLONG
435#define mul_add_c(a,b,c0,c1,c2) \
436 t=(BN_ULLONG)a*b; \
437 t1=(BN_ULONG)Lw(t); \
438 t2=(BN_ULONG)Hw(t); \
439 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
440 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
441
442#define mul_add_c2(a,b,c0,c1,c2) \
443 t=(BN_ULLONG)a*b; \
444 tt=(t+t)&BN_MASK; \
445 if (tt < t) c2++; \
446 t1=(BN_ULONG)Lw(tt); \
447 t2=(BN_ULONG)Hw(tt); \
448 c0=(c0+t1)&BN_MASK2; \
449 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
450 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
451
452#define sqr_add_c(a,i,c0,c1,c2) \
453 t=(BN_ULLONG)a[i]*a[i]; \
454 t1=(BN_ULONG)Lw(t); \
455 t2=(BN_ULONG)Hw(t); \
456 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
457 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
458
459#define sqr_add_c2(a,i,j,c0,c1,c2) \
460 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
461
462#elif defined(BN_UMULT_HIGH)
463
464#define mul_add_c(a,b,c0,c1,c2) { \
465 BN_ULONG ta=(a),tb=(b); \
466 t1 = ta * tb; \
467 t2 = BN_UMULT_HIGH(ta,tb); \
468 c0 += t1; t2 += (c0<t1)?1:0; \
469 c1 += t2; c2 += (c1<t2)?1:0; \
470 }
471
472#define mul_add_c2(a,b,c0,c1,c2) { \
473 BN_ULONG ta=(a),tb=(b),t0; \
474 t1 = BN_UMULT_HIGH(ta,tb); \
475 t0 = ta * tb; \
476 t2 = t1+t1; c2 += (t2<t1)?1:0; \
477 t1 = t0+t0; t2 += (t1<t0)?1:0; \
478 c0 += t1; t2 += (c0<t1)?1:0; \
479 c1 += t2; c2 += (c1<t2)?1:0; \
480 }
481
482#define sqr_add_c(a,i,c0,c1,c2) { \
483 BN_ULONG ta=(a)[i]; \
484 t1 = ta * ta; \
485 t2 = BN_UMULT_HIGH(ta,ta); \
486 c0 += t1; t2 += (c0<t1)?1:0; \
487 c1 += t2; c2 += (c1<t2)?1:0; \
488 }
489
490#define sqr_add_c2(a,i,j,c0,c1,c2) \
491 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
492
493#else /* !BN_LLONG */
494#define mul_add_c(a,b,c0,c1,c2) \
495 t1=LBITS(a); t2=HBITS(a); \
496 bl=LBITS(b); bh=HBITS(b); \
497 mul64(t1,t2,bl,bh); \
498 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
499 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
500
501#define mul_add_c2(a,b,c0,c1,c2) \
502 t1=LBITS(a); t2=HBITS(a); \
503 bl=LBITS(b); bh=HBITS(b); \
504 mul64(t1,t2,bl,bh); \
505 if (t2 & BN_TBIT) c2++; \
506 t2=(t2+t2)&BN_MASK2; \
507 if (t1 & BN_TBIT) t2++; \
508 t1=(t1+t1)&BN_MASK2; \
509 c0=(c0+t1)&BN_MASK2; \
510 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
511 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
512
513#define sqr_add_c(a,i,c0,c1,c2) \
514 sqr64(t1,t2,(a)[i]); \
515 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
516 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
517
518#define sqr_add_c2(a,i,j,c0,c1,c2) \
519 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
520#endif /* !BN_LLONG */
521
522void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
523 {
524#ifdef BN_LLONG
525 BN_ULLONG t;
526#else
527 BN_ULONG bl,bh;
528#endif
529 BN_ULONG t1,t2;
530 BN_ULONG c1,c2,c3;
531
532 c1=0;
533 c2=0;
534 c3=0;
535 mul_add_c(a[0],b[0],c1,c2,c3);
536 r[0]=c1;
537 c1=0;
538 mul_add_c(a[0],b[1],c2,c3,c1);
539 mul_add_c(a[1],b[0],c2,c3,c1);
540 r[1]=c2;
541 c2=0;
542 mul_add_c(a[2],b[0],c3,c1,c2);
543 mul_add_c(a[1],b[1],c3,c1,c2);
544 mul_add_c(a[0],b[2],c3,c1,c2);
545 r[2]=c3;
546 c3=0;
547 mul_add_c(a[0],b[3],c1,c2,c3);
548 mul_add_c(a[1],b[2],c1,c2,c3);
549 mul_add_c(a[2],b[1],c1,c2,c3);
550 mul_add_c(a[3],b[0],c1,c2,c3);
551 r[3]=c1;
552 c1=0;
553 mul_add_c(a[4],b[0],c2,c3,c1);
554 mul_add_c(a[3],b[1],c2,c3,c1);
555 mul_add_c(a[2],b[2],c2,c3,c1);
556 mul_add_c(a[1],b[3],c2,c3,c1);
557 mul_add_c(a[0],b[4],c2,c3,c1);
558 r[4]=c2;
559 c2=0;
560 mul_add_c(a[0],b[5],c3,c1,c2);
561 mul_add_c(a[1],b[4],c3,c1,c2);
562 mul_add_c(a[2],b[3],c3,c1,c2);
563 mul_add_c(a[3],b[2],c3,c1,c2);
564 mul_add_c(a[4],b[1],c3,c1,c2);
565 mul_add_c(a[5],b[0],c3,c1,c2);
566 r[5]=c3;
567 c3=0;
568 mul_add_c(a[6],b[0],c1,c2,c3);
569 mul_add_c(a[5],b[1],c1,c2,c3);
570 mul_add_c(a[4],b[2],c1,c2,c3);
571 mul_add_c(a[3],b[3],c1,c2,c3);
572 mul_add_c(a[2],b[4],c1,c2,c3);
573 mul_add_c(a[1],b[5],c1,c2,c3);
574 mul_add_c(a[0],b[6],c1,c2,c3);
575 r[6]=c1;
576 c1=0;
577 mul_add_c(a[0],b[7],c2,c3,c1);
578 mul_add_c(a[1],b[6],c2,c3,c1);
579 mul_add_c(a[2],b[5],c2,c3,c1);
580 mul_add_c(a[3],b[4],c2,c3,c1);
581 mul_add_c(a[4],b[3],c2,c3,c1);
582 mul_add_c(a[5],b[2],c2,c3,c1);
583 mul_add_c(a[6],b[1],c2,c3,c1);
584 mul_add_c(a[7],b[0],c2,c3,c1);
585 r[7]=c2;
586 c2=0;
587 mul_add_c(a[7],b[1],c3,c1,c2);
588 mul_add_c(a[6],b[2],c3,c1,c2);
589 mul_add_c(a[5],b[3],c3,c1,c2);
590 mul_add_c(a[4],b[4],c3,c1,c2);
591 mul_add_c(a[3],b[5],c3,c1,c2);
592 mul_add_c(a[2],b[6],c3,c1,c2);
593 mul_add_c(a[1],b[7],c3,c1,c2);
594 r[8]=c3;
595 c3=0;
596 mul_add_c(a[2],b[7],c1,c2,c3);
597 mul_add_c(a[3],b[6],c1,c2,c3);
598 mul_add_c(a[4],b[5],c1,c2,c3);
599 mul_add_c(a[5],b[4],c1,c2,c3);
600 mul_add_c(a[6],b[3],c1,c2,c3);
601 mul_add_c(a[7],b[2],c1,c2,c3);
602 r[9]=c1;
603 c1=0;
604 mul_add_c(a[7],b[3],c2,c3,c1);
605 mul_add_c(a[6],b[4],c2,c3,c1);
606 mul_add_c(a[5],b[5],c2,c3,c1);
607 mul_add_c(a[4],b[6],c2,c3,c1);
608 mul_add_c(a[3],b[7],c2,c3,c1);
609 r[10]=c2;
610 c2=0;
611 mul_add_c(a[4],b[7],c3,c1,c2);
612 mul_add_c(a[5],b[6],c3,c1,c2);
613 mul_add_c(a[6],b[5],c3,c1,c2);
614 mul_add_c(a[7],b[4],c3,c1,c2);
615 r[11]=c3;
616 c3=0;
617 mul_add_c(a[7],b[5],c1,c2,c3);
618 mul_add_c(a[6],b[6],c1,c2,c3);
619 mul_add_c(a[5],b[7],c1,c2,c3);
620 r[12]=c1;
621 c1=0;
622 mul_add_c(a[6],b[7],c2,c3,c1);
623 mul_add_c(a[7],b[6],c2,c3,c1);
624 r[13]=c2;
625 c2=0;
626 mul_add_c(a[7],b[7],c3,c1,c2);
627 r[14]=c3;
628 r[15]=c1;
629 }
630
631void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
632 {
633#ifdef BN_LLONG
634 BN_ULLONG t;
635#else
636 BN_ULONG bl,bh;
637#endif
638 BN_ULONG t1,t2;
639 BN_ULONG c1,c2,c3;
640
641 c1=0;
642 c2=0;
643 c3=0;
644 mul_add_c(a[0],b[0],c1,c2,c3);
645 r[0]=c1;
646 c1=0;
647 mul_add_c(a[0],b[1],c2,c3,c1);
648 mul_add_c(a[1],b[0],c2,c3,c1);
649 r[1]=c2;
650 c2=0;
651 mul_add_c(a[2],b[0],c3,c1,c2);
652 mul_add_c(a[1],b[1],c3,c1,c2);
653 mul_add_c(a[0],b[2],c3,c1,c2);
654 r[2]=c3;
655 c3=0;
656 mul_add_c(a[0],b[3],c1,c2,c3);
657 mul_add_c(a[1],b[2],c1,c2,c3);
658 mul_add_c(a[2],b[1],c1,c2,c3);
659 mul_add_c(a[3],b[0],c1,c2,c3);
660 r[3]=c1;
661 c1=0;
662 mul_add_c(a[3],b[1],c2,c3,c1);
663 mul_add_c(a[2],b[2],c2,c3,c1);
664 mul_add_c(a[1],b[3],c2,c3,c1);
665 r[4]=c2;
666 c2=0;
667 mul_add_c(a[2],b[3],c3,c1,c2);
668 mul_add_c(a[3],b[2],c3,c1,c2);
669 r[5]=c3;
670 c3=0;
671 mul_add_c(a[3],b[3],c1,c2,c3);
672 r[6]=c1;
673 r[7]=c2;
674 }
675
676void bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a)
677 {
678#ifdef BN_LLONG
679 BN_ULLONG t,tt;
680#else
681 BN_ULONG bl,bh;
682#endif
683 BN_ULONG t1,t2;
684 BN_ULONG c1,c2,c3;
685
686 c1=0;
687 c2=0;
688 c3=0;
689 sqr_add_c(a,0,c1,c2,c3);
690 r[0]=c1;
691 c1=0;
692 sqr_add_c2(a,1,0,c2,c3,c1);
693 r[1]=c2;
694 c2=0;
695 sqr_add_c(a,1,c3,c1,c2);
696 sqr_add_c2(a,2,0,c3,c1,c2);
697 r[2]=c3;
698 c3=0;
699 sqr_add_c2(a,3,0,c1,c2,c3);
700 sqr_add_c2(a,2,1,c1,c2,c3);
701 r[3]=c1;
702 c1=0;
703 sqr_add_c(a,2,c2,c3,c1);
704 sqr_add_c2(a,3,1,c2,c3,c1);
705 sqr_add_c2(a,4,0,c2,c3,c1);
706 r[4]=c2;
707 c2=0;
708 sqr_add_c2(a,5,0,c3,c1,c2);
709 sqr_add_c2(a,4,1,c3,c1,c2);
710 sqr_add_c2(a,3,2,c3,c1,c2);
711 r[5]=c3;
712 c3=0;
713 sqr_add_c(a,3,c1,c2,c3);
714 sqr_add_c2(a,4,2,c1,c2,c3);
715 sqr_add_c2(a,5,1,c1,c2,c3);
716 sqr_add_c2(a,6,0,c1,c2,c3);
717 r[6]=c1;
718 c1=0;
719 sqr_add_c2(a,7,0,c2,c3,c1);
720 sqr_add_c2(a,6,1,c2,c3,c1);
721 sqr_add_c2(a,5,2,c2,c3,c1);
722 sqr_add_c2(a,4,3,c2,c3,c1);
723 r[7]=c2;
724 c2=0;
725 sqr_add_c(a,4,c3,c1,c2);
726 sqr_add_c2(a,5,3,c3,c1,c2);
727 sqr_add_c2(a,6,2,c3,c1,c2);
728 sqr_add_c2(a,7,1,c3,c1,c2);
729 r[8]=c3;
730 c3=0;
731 sqr_add_c2(a,7,2,c1,c2,c3);
732 sqr_add_c2(a,6,3,c1,c2,c3);
733 sqr_add_c2(a,5,4,c1,c2,c3);
734 r[9]=c1;
735 c1=0;
736 sqr_add_c(a,5,c2,c3,c1);
737 sqr_add_c2(a,6,4,c2,c3,c1);
738 sqr_add_c2(a,7,3,c2,c3,c1);
739 r[10]=c2;
740 c2=0;
741 sqr_add_c2(a,7,4,c3,c1,c2);
742 sqr_add_c2(a,6,5,c3,c1,c2);
743 r[11]=c3;
744 c3=0;
745 sqr_add_c(a,6,c1,c2,c3);
746 sqr_add_c2(a,7,5,c1,c2,c3);
747 r[12]=c1;
748 c1=0;
749 sqr_add_c2(a,7,6,c2,c3,c1);
750 r[13]=c2;
751 c2=0;
752 sqr_add_c(a,7,c3,c1,c2);
753 r[14]=c3;
754 r[15]=c1;
755 }
756
757void bn_sqr_comba4(BN_ULONG *r, const BN_ULONG *a)
758 {
759#ifdef BN_LLONG
760 BN_ULLONG t,tt;
761#else
762 BN_ULONG bl,bh;
763#endif
764 BN_ULONG t1,t2;
765 BN_ULONG c1,c2,c3;
766
767 c1=0;
768 c2=0;
769 c3=0;
770 sqr_add_c(a,0,c1,c2,c3);
771 r[0]=c1;
772 c1=0;
773 sqr_add_c2(a,1,0,c2,c3,c1);
774 r[1]=c2;
775 c2=0;
776 sqr_add_c(a,1,c3,c1,c2);
777 sqr_add_c2(a,2,0,c3,c1,c2);
778 r[2]=c3;
779 c3=0;
780 sqr_add_c2(a,3,0,c1,c2,c3);
781 sqr_add_c2(a,2,1,c1,c2,c3);
782 r[3]=c1;
783 c1=0;
784 sqr_add_c(a,2,c2,c3,c1);
785 sqr_add_c2(a,3,1,c2,c3,c1);
786 r[4]=c2;
787 c2=0;
788 sqr_add_c2(a,3,2,c3,c1,c2);
789 r[5]=c3;
790 c3=0;
791 sqr_add_c(a,3,c1,c2,c3);
792 r[6]=c1;
793 r[7]=c2;
794 }
795#else /* !BN_MUL_COMBA */
796
797/* hmm... is it faster just to do a multiply? */
798#undef bn_sqr_comba4
799void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
800 {
801 BN_ULONG t[8];
802 bn_sqr_normal(r,a,4,t);
803 }
804
805#undef bn_sqr_comba8
806void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
807 {
808 BN_ULONG t[16];
809 bn_sqr_normal(r,a,8,t);
810 }
811
812void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
813 {
814 r[4]=bn_mul_words( &(r[0]),a,4,b[0]);
815 r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]);
816 r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]);
817 r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]);
818 }
819
820void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
821 {
822 r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
823 r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
824 r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
825 r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
826 r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
827 r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
828 r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
829 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
830 }
831
832#endif /* !BN_MUL_COMBA */
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c
new file mode 100644
index 0000000000..2d287e6d1b
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_blind.c
@@ -0,0 +1,144 @@
1/* crypto/bn/bn_blind.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63BN_BLINDING *BN_BLINDING_new(BIGNUM *A, BIGNUM *Ai, BIGNUM *mod)
64 {
65 BN_BLINDING *ret=NULL;
66
67 bn_check_top(Ai);
68 bn_check_top(mod);
69
70 if ((ret=(BN_BLINDING *)OPENSSL_malloc(sizeof(BN_BLINDING))) == NULL)
71 {
72 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
75 memset(ret,0,sizeof(BN_BLINDING));
76 if ((ret->A=BN_new()) == NULL) goto err;
77 if ((ret->Ai=BN_new()) == NULL) goto err;
78 if (!BN_copy(ret->A,A)) goto err;
79 if (!BN_copy(ret->Ai,Ai)) goto err;
80 ret->mod=mod;
81 return(ret);
82err:
83 if (ret != NULL) BN_BLINDING_free(ret);
84 return(NULL);
85 }
86
87void BN_BLINDING_free(BN_BLINDING *r)
88 {
89 if(r == NULL)
90 return;
91
92 if (r->A != NULL) BN_free(r->A );
93 if (r->Ai != NULL) BN_free(r->Ai);
94 OPENSSL_free(r);
95 }
96
97int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
98 {
99 int ret=0;
100
101 if ((b->A == NULL) || (b->Ai == NULL))
102 {
103 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);
104 goto err;
105 }
106
107 if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;
108 if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;
109
110 ret=1;
111err:
112 return(ret);
113 }
114
115int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
116 {
117 bn_check_top(n);
118
119 if ((b->A == NULL) || (b->Ai == NULL))
120 {
121 BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED);
122 return(0);
123 }
124 return(BN_mod_mul(n,n,b->A,b->mod,ctx));
125 }
126
127int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
128 {
129 int ret;
130
131 bn_check_top(n);
132 if ((b->A == NULL) || (b->Ai == NULL))
133 {
134 BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);
135 return(0);
136 }
137 if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)
138 {
139 if (!BN_BLINDING_update(b,ctx))
140 return(0);
141 }
142 return(ret);
143 }
144
diff --git a/src/lib/libcrypto/bn/bn_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
new file mode 100644
index 0000000000..7daf19eb84
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_ctx.c
@@ -0,0 +1,155 @@
1/* crypto/bn/bn_ctx.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#ifndef BN_CTX_DEBUG
58# undef NDEBUG /* avoid conflicting definitions */
59# define NDEBUG
60#endif
61
62#include <stdio.h>
63#include <assert.h>
64
65#include "cryptlib.h"
66#include "bn_lcl.h"
67
68
69BN_CTX *BN_CTX_new(void)
70 {
71 BN_CTX *ret;
72
73 ret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));
74 if (ret == NULL)
75 {
76 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
77 return(NULL);
78 }
79
80 BN_CTX_init(ret);
81 ret->flags=BN_FLG_MALLOCED;
82 return(ret);
83 }
84
85void BN_CTX_init(BN_CTX *ctx)
86 {
87#if 0 /* explicit version */
88 int i;
89 ctx->tos = 0;
90 ctx->flags = 0;
91 ctx->depth = 0;
92 ctx->too_many = 0;
93 for (i = 0; i < BN_CTX_NUM; i++)
94 BN_init(&(ctx->bn[i]));
95#else
96 memset(ctx, 0, sizeof *ctx);
97#endif
98 }
99
100void BN_CTX_free(BN_CTX *ctx)
101 {
102 int i;
103
104 if (ctx == NULL) return;
105 assert(ctx->depth == 0);
106
107 for (i=0; i < BN_CTX_NUM; i++)
108 BN_clear_free(&(ctx->bn[i]));
109 if (ctx->flags & BN_FLG_MALLOCED)
110 OPENSSL_free(ctx);
111 }
112
113void BN_CTX_start(BN_CTX *ctx)
114 {
115 if (ctx->depth < BN_CTX_NUM_POS)
116 ctx->pos[ctx->depth] = ctx->tos;
117 ctx->depth++;
118 }
119
120
121BIGNUM *BN_CTX_get(BN_CTX *ctx)
122 {
123 /* Note: If BN_CTX_get is ever changed to allocate BIGNUMs dynamically,
124 * make sure that if BN_CTX_get fails once it will return NULL again
125 * until BN_CTX_end is called. (This is so that callers have to check
126 * only the last return value.)
127 */
128 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
129 {
130 if (!ctx->too_many)
131 {
132 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
133 /* disable error code until BN_CTX_end is called: */
134 ctx->too_many = 1;
135 }
136 return NULL;
137 }
138 return (&(ctx->bn[ctx->tos++]));
139 }
140
141void BN_CTX_end(BN_CTX *ctx)
142 {
143 if (ctx == NULL) return;
144 assert(ctx->depth > 0);
145 if (ctx->depth == 0)
146 /* should never happen, but we can tolerate it if not in
147 * debug mode (could be a 'goto err' in the calling function
148 * before BN_CTX_start was reached) */
149 BN_CTX_start(ctx);
150
151 ctx->too_many = 0;
152 ctx->depth--;
153 if (ctx->depth < BN_CTX_NUM_POS)
154 ctx->tos = ctx->pos[ctx->depth];
155 }
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
new file mode 100644
index 0000000000..580d1201bc
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_div.c
@@ -0,0 +1,387 @@
1/* crypto/bn/bn_div.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/bn.h>
61#include "cryptlib.h"
62#include "bn_lcl.h"
63
64
65/* The old slow way */
66#if 0
67int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
68 BN_CTX *ctx)
69 {
70 int i,nm,nd;
71 int ret = 0;
72 BIGNUM *D;
73
74 bn_check_top(m);
75 bn_check_top(d);
76 if (BN_is_zero(d))
77 {
78 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
79 return(0);
80 }
81
82 if (BN_ucmp(m,d) < 0)
83 {
84 if (rem != NULL)
85 { if (BN_copy(rem,m) == NULL) return(0); }
86 if (dv != NULL) BN_zero(dv);
87 return(1);
88 }
89
90 BN_CTX_start(ctx);
91 D = BN_CTX_get(ctx);
92 if (dv == NULL) dv = BN_CTX_get(ctx);
93 if (rem == NULL) rem = BN_CTX_get(ctx);
94 if (D == NULL || dv == NULL || rem == NULL)
95 goto end;
96
97 nd=BN_num_bits(d);
98 nm=BN_num_bits(m);
99 if (BN_copy(D,d) == NULL) goto end;
100 if (BN_copy(rem,m) == NULL) goto end;
101
102 /* The next 2 are needed so we can do a dv->d[0]|=1 later
103 * since BN_lshift1 will only work once there is a value :-) */
104 BN_zero(dv);
105 bn_wexpand(dv,1);
106 dv->top=1;
107
108 if (!BN_lshift(D,D,nm-nd)) goto end;
109 for (i=nm-nd; i>=0; i--)
110 {
111 if (!BN_lshift1(dv,dv)) goto end;
112 if (BN_ucmp(rem,D) >= 0)
113 {
114 dv->d[0]|=1;
115 if (!BN_usub(rem,rem,D)) goto end;
116 }
117/* CAN IMPROVE (and have now :=) */
118 if (!BN_rshift1(D,D)) goto end;
119 }
120 rem->neg=BN_is_zero(rem)?0:m->neg;
121 dv->neg=m->neg^d->neg;
122 ret = 1;
123 end:
124 BN_CTX_end(ctx);
125 return(ret);
126 }
127
128#else
129
130#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \
131 && !defined(PEDANTIC) && !defined(BN_DIV3W)
132# if defined(__GNUC__) && __GNUC__>=2
133# if defined(__i386) || defined (__i386__)
134 /*
135 * There were two reasons for implementing this template:
136 * - GNU C generates a call to a function (__udivdi3 to be exact)
137 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
138 * understand why...);
139 * - divl doesn't only calculate quotient, but also leaves
140 * remainder in %edx which we can definitely use here:-)
141 *
142 * <appro@fy.chalmers.se>
143 */
144# define bn_div_words(n0,n1,d0) \
145 ({ asm volatile ( \
146 "divl %4" \
147 : "=a"(q), "=d"(rem) \
148 : "a"(n1), "d"(n0), "g"(d0) \
149 : "cc"); \
150 q; \
151 })
152# define REMAINDER_IS_ALREADY_CALCULATED
153# elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
154 /*
155 * Same story here, but it's 128-bit by 64-bit division. Wow!
156 * <appro@fy.chalmers.se>
157 */
158# define bn_div_words(n0,n1,d0) \
159 ({ asm volatile ( \
160 "divq %4" \
161 : "=a"(q), "=d"(rem) \
162 : "a"(n1), "d"(n0), "g"(d0) \
163 : "cc"); \
164 q; \
165 })
166# define REMAINDER_IS_ALREADY_CALCULATED
167# endif /* __<cpu> */
168# endif /* __GNUC__ */
169#endif /* OPENSSL_NO_ASM */
170
171
172/* BN_div computes dv := num / divisor, rounding towards zero, and sets up
173 * rm such that dv*divisor + rm = num holds.
174 * Thus:
175 * dv->neg == num->neg ^ divisor->neg (unless the result is zero)
176 * rm->neg == num->neg (unless the remainder is zero)
177 * If 'dv' or 'rm' is NULL, the respective value is not returned.
178 */
179int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
180 BN_CTX *ctx)
181 {
182 int norm_shift,i,j,loop;
183 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
184 BN_ULONG *resp,*wnump;
185 BN_ULONG d0,d1;
186 int num_n,div_n;
187
188 bn_check_top(num);
189 bn_check_top(divisor);
190
191 if (BN_is_zero(divisor))
192 {
193 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
194 return(0);
195 }
196
197 if (BN_ucmp(num,divisor) < 0)
198 {
199 if (rm != NULL)
200 { if (BN_copy(rm,num) == NULL) return(0); }
201 if (dv != NULL) BN_zero(dv);
202 return(1);
203 }
204
205 BN_CTX_start(ctx);
206 tmp=BN_CTX_get(ctx);
207 snum=BN_CTX_get(ctx);
208 sdiv=BN_CTX_get(ctx);
209 if (dv == NULL)
210 res=BN_CTX_get(ctx);
211 else res=dv;
212 if (sdiv == NULL || res == NULL) goto err;
213 tmp->neg=0;
214
215 /* First we normalise the numbers */
216 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
217 if (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;
218 sdiv->neg=0;
219 norm_shift+=BN_BITS2;
220 if (!(BN_lshift(snum,num,norm_shift))) goto err;
221 snum->neg=0;
222 div_n=sdiv->top;
223 num_n=snum->top;
224 loop=num_n-div_n;
225
226 /* Lets setup a 'window' into snum
227 * This is the part that corresponds to the current
228 * 'area' being divided */
229 BN_init(&wnum);
230 wnum.d= &(snum->d[loop]);
231 wnum.top= div_n;
232 wnum.dmax= snum->dmax+1; /* a bit of a lie */
233
234 /* Get the top 2 words of sdiv */
235 /* i=sdiv->top; */
236 d0=sdiv->d[div_n-1];
237 d1=(div_n == 1)?0:sdiv->d[div_n-2];
238
239 /* pointer to the 'top' of snum */
240 wnump= &(snum->d[num_n-1]);
241
242 /* Setup to 'res' */
243 res->neg= (num->neg^divisor->neg);
244 if (!bn_wexpand(res,(loop+1))) goto err;
245 res->top=loop;
246 resp= &(res->d[loop-1]);
247
248 /* space for temp */
249 if (!bn_wexpand(tmp,(div_n+1))) goto err;
250
251 if (BN_ucmp(&wnum,sdiv) >= 0)
252 {
253 if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
254 *resp=1;
255 res->d[res->top-1]=1;
256 }
257 else
258 res->top--;
259 if (res->top == 0)
260 res->neg = 0;
261 resp--;
262
263 for (i=0; i<loop-1; i++)
264 {
265 BN_ULONG q,l0;
266#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)
267 BN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);
268 q=bn_div_3_words(wnump,d1,d0);
269#else
270 BN_ULONG n0,n1,rem=0;
271
272 n0=wnump[0];
273 n1=wnump[-1];
274 if (n0 == d0)
275 q=BN_MASK2;
276 else /* n0 < d0 */
277 {
278#ifdef BN_LLONG
279 BN_ULLONG t2;
280
281#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
282 q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
283#else
284 q=bn_div_words(n0,n1,d0);
285#ifdef BN_DEBUG_LEVITTE
286 fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
287X) -> 0x%08X\n",
288 n0, n1, d0, q);
289#endif
290#endif
291
292#ifndef REMAINDER_IS_ALREADY_CALCULATED
293 /*
294 * rem doesn't have to be BN_ULLONG. The least we
295 * know it's less that d0, isn't it?
296 */
297 rem=(n1-q*d0)&BN_MASK2;
298#endif
299 t2=(BN_ULLONG)d1*q;
300
301 for (;;)
302 {
303 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
304 break;
305 q--;
306 rem += d0;
307 if (rem < d0) break; /* don't let rem overflow */
308 t2 -= d1;
309 }
310#else /* !BN_LLONG */
311 BN_ULONG t2l,t2h,ql,qh;
312
313 q=bn_div_words(n0,n1,d0);
314#ifdef BN_DEBUG_LEVITTE
315 fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
316X) -> 0x%08X\n",
317 n0, n1, d0, q);
318#endif
319#ifndef REMAINDER_IS_ALREADY_CALCULATED
320 rem=(n1-q*d0)&BN_MASK2;
321#endif
322
323#if defined(BN_UMULT_LOHI)
324 BN_UMULT_LOHI(t2l,t2h,d1,q);
325#elif defined(BN_UMULT_HIGH)
326 t2l = d1 * q;
327 t2h = BN_UMULT_HIGH(d1,q);
328#else
329 t2l=LBITS(d1); t2h=HBITS(d1);
330 ql =LBITS(q); qh =HBITS(q);
331 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
332#endif
333
334 for (;;)
335 {
336 if ((t2h < rem) ||
337 ((t2h == rem) && (t2l <= wnump[-2])))
338 break;
339 q--;
340 rem += d0;
341 if (rem < d0) break; /* don't let rem overflow */
342 if (t2l < d1) t2h--; t2l -= d1;
343 }
344#endif /* !BN_LLONG */
345 }
346#endif /* !BN_DIV3W */
347
348 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
349 wnum.d--; wnum.top++;
350 tmp->d[div_n]=l0;
351 for (j=div_n+1; j>0; j--)
352 if (tmp->d[j-1]) break;
353 tmp->top=j;
354
355 j=wnum.top;
356 if (!BN_sub(&wnum,&wnum,tmp)) goto err;
357
358 snum->top=snum->top+wnum.top-j;
359
360 if (wnum.neg)
361 {
362 q--;
363 j=wnum.top;
364 if (!BN_add(&wnum,&wnum,sdiv)) goto err;
365 snum->top+=wnum.top-j;
366 }
367 *(resp--)=q;
368 wnump--;
369 }
370 if (rm != NULL)
371 {
372 /* Keep a copy of the neg flag in num because if rm==num
373 * BN_rshift() will overwrite it.
374 */
375 int neg = num->neg;
376 BN_rshift(rm,snum,norm_shift);
377 if (!BN_is_zero(rm))
378 rm->neg = neg;
379 }
380 BN_CTX_end(ctx);
381 return(1);
382err:
383 BN_CTX_end(ctx);
384 return(0);
385 }
386
387#endif
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
new file mode 100644
index 0000000000..fb84ee96d8
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_err.c
@@ -0,0 +1,131 @@
1/* crypto/bn/bn_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/bn.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA BN_str_functs[]=
68 {
69{ERR_PACK(0,BN_F_BN_BLINDING_CONVERT,0), "BN_BLINDING_convert"},
70{ERR_PACK(0,BN_F_BN_BLINDING_INVERT,0), "BN_BLINDING_invert"},
71{ERR_PACK(0,BN_F_BN_BLINDING_NEW,0), "BN_BLINDING_new"},
72{ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"},
73{ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"},
74{ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"},
75{ERR_PACK(0,BN_F_BN_CTX_GET,0), "BN_CTX_get"},
76{ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"},
77{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"},
78{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"},
79{ERR_PACK(0,BN_F_BN_EXPAND_INTERNAL,0), "BN_EXPAND_INTERNAL"},
80{ERR_PACK(0,BN_F_BN_MOD_EXP2_MONT,0), "BN_mod_exp2_mont"},
81{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"},
82{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT_WORD,0), "BN_mod_exp_mont_word"},
83{ERR_PACK(0,BN_F_BN_MOD_INVERSE,0), "BN_mod_inverse"},
84{ERR_PACK(0,BN_F_BN_MOD_LSHIFT_QUICK,0), "BN_mod_lshift_quick"},
85{ERR_PACK(0,BN_F_BN_MOD_MUL_RECIPROCAL,0), "BN_mod_mul_reciprocal"},
86{ERR_PACK(0,BN_F_BN_MOD_SQRT,0), "BN_mod_sqrt"},
87{ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"},
88{ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"},
89{ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"},
90{ERR_PACK(0,BN_F_BN_RAND_RANGE,0), "BN_rand_range"},
91{ERR_PACK(0,BN_F_BN_USUB,0), "BN_usub"},
92{0,NULL}
93 };
94
95static ERR_STRING_DATA BN_str_reasons[]=
96 {
97{BN_R_ARG2_LT_ARG3 ,"arg2 lt arg3"},
98{BN_R_BAD_RECIPROCAL ,"bad reciprocal"},
99{BN_R_BIGNUM_TOO_LONG ,"bignum too long"},
100{BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"},
101{BN_R_DIV_BY_ZERO ,"div by zero"},
102{BN_R_ENCODING_ERROR ,"encoding error"},
103{BN_R_EXPAND_ON_STATIC_BIGNUM_DATA ,"expand on static bignum data"},
104{BN_R_INPUT_NOT_REDUCED ,"input not reduced"},
105{BN_R_INVALID_LENGTH ,"invalid length"},
106{BN_R_INVALID_RANGE ,"invalid range"},
107{BN_R_NOT_A_SQUARE ,"not a square"},
108{BN_R_NOT_INITIALIZED ,"not initialized"},
109{BN_R_NO_INVERSE ,"no inverse"},
110{BN_R_P_IS_NOT_PRIME ,"p is not prime"},
111{BN_R_TOO_MANY_ITERATIONS ,"too many iterations"},
112{BN_R_TOO_MANY_TEMPORARY_VARIABLES ,"too many temporary variables"},
113{0,NULL}
114 };
115
116#endif
117
118void ERR_load_BN_strings(void)
119 {
120 static int init=1;
121
122 if (init)
123 {
124 init=0;
125#ifndef OPENSSL_NO_ERR
126 ERR_load_strings(ERR_LIB_BN,BN_str_functs);
127 ERR_load_strings(ERR_LIB_BN,BN_str_reasons);
128#endif
129
130 }
131 }
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
new file mode 100644
index 0000000000..afdfd580fb
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -0,0 +1,747 @@
1/* crypto/bn/bn_exp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-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
113#include "cryptlib.h"
114#include "bn_lcl.h"
115
116#define TABLE_SIZE 32
117
118/* this one works - simple but works */
119int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
120 {
121 int i,bits,ret=0;
122 BIGNUM *v,*rr;
123
124 BN_CTX_start(ctx);
125 if ((r == a) || (r == p))
126 rr = BN_CTX_get(ctx);
127 else
128 rr = r;
129 if ((v = BN_CTX_get(ctx)) == NULL) goto err;
130
131 if (BN_copy(v,a) == NULL) goto err;
132 bits=BN_num_bits(p);
133
134 if (BN_is_odd(p))
135 { if (BN_copy(rr,a) == NULL) goto err; }
136 else { if (!BN_one(rr)) goto err; }
137
138 for (i=1; i<bits; i++)
139 {
140 if (!BN_sqr(v,v,ctx)) goto err;
141 if (BN_is_bit_set(p,i))
142 {
143 if (!BN_mul(rr,rr,v,ctx)) goto err;
144 }
145 }
146 ret=1;
147err:
148 if (r != rr) BN_copy(r,rr);
149 BN_CTX_end(ctx);
150 return(ret);
151 }
152
153
154int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
155 BN_CTX *ctx)
156 {
157 int ret;
158
159 bn_check_top(a);
160 bn_check_top(p);
161 bn_check_top(m);
162
163 /* For even modulus m = 2^k*m_odd, it might make sense to compute
164 * a^p mod m_odd and a^p mod 2^k separately (with Montgomery
165 * exponentiation for the odd part), using appropriate exponent
166 * reductions, and combine the results using the CRT.
167 *
168 * For now, we use Montgomery only if the modulus is odd; otherwise,
169 * exponentiation using the reciprocal-based quick remaindering
170 * algorithm is used.
171 *
172 * (Timing obtained with expspeed.c [computations a^p mod m
173 * where a, p, m are of the same length: 256, 512, 1024, 2048,
174 * 4096, 8192 bits], compared to the running time of the
175 * standard algorithm:
176 *
177 * BN_mod_exp_mont 33 .. 40 % [AMD K6-2, Linux, debug configuration]
178 * 55 .. 77 % [UltraSparc processor, but
179 * debug-solaris-sparcv8-gcc conf.]
180 *
181 * BN_mod_exp_recp 50 .. 70 % [AMD K6-2, Linux, debug configuration]
182 * 62 .. 118 % [UltraSparc, debug-solaris-sparcv8-gcc]
183 *
184 * On the Sparc, BN_mod_exp_recp was faster than BN_mod_exp_mont
185 * at 2048 and more bits, but at 512 and 1024 bits, it was
186 * slower even than the standard algorithm!
187 *
188 * "Real" timings [linux-elf, solaris-sparcv9-gcc configurations]
189 * should be obtained when the new Montgomery reduction code
190 * has been integrated into OpenSSL.)
191 */
192
193#define MONT_MUL_MOD
194#define MONT_EXP_WORD
195#define RECP_MUL_MOD
196
197#ifdef MONT_MUL_MOD
198 /* I have finally been able to take out this pre-condition of
199 * the top bit being set. It was caused by an error in BN_div
200 * with negatives. There was also another problem when for a^b%m
201 * a >= m. eay 07-May-97 */
202/* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */
203
204 if (BN_is_odd(m))
205 {
206# ifdef MONT_EXP_WORD
207 if (a->top == 1 && !a->neg)
208 {
209 BN_ULONG A = a->d[0];
210 ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);
211 }
212 else
213# endif
214 ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);
215 }
216 else
217#endif
218#ifdef RECP_MUL_MOD
219 { ret=BN_mod_exp_recp(r,a,p,m,ctx); }
220#else
221 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
222#endif
223
224 return(ret);
225 }
226
227
228int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
229 const BIGNUM *m, BN_CTX *ctx)
230 {
231 int i,j,bits,ret=0,wstart,wend,window,wvalue;
232 int start=1,ts=0;
233 BIGNUM *aa;
234 BIGNUM val[TABLE_SIZE];
235 BN_RECP_CTX recp;
236
237 bits=BN_num_bits(p);
238
239 if (bits == 0)
240 {
241 ret = BN_one(r);
242 return ret;
243 }
244
245 BN_CTX_start(ctx);
246 if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
247
248 BN_RECP_CTX_init(&recp);
249 if (m->neg)
250 {
251 /* ignore sign of 'm' */
252 if (!BN_copy(aa, m)) goto err;
253 aa->neg = 0;
254 if (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;
255 }
256 else
257 {
258 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
259 }
260
261 BN_init(&(val[0]));
262 ts=1;
263
264 if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
265 if (BN_is_zero(&(val[0])))
266 {
267 ret = BN_zero(r);
268 goto err;
269 }
270
271 window = BN_window_bits_for_exponent_size(bits);
272 if (window > 1)
273 {
274 if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))
275 goto err; /* 2 */
276 j=1<<(window-1);
277 for (i=1; i<j; i++)
278 {
279 BN_init(&val[i]);
280 if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))
281 goto err;
282 }
283 ts=i;
284 }
285
286 start=1; /* This is used to avoid multiplication etc
287 * when there is only the value '1' in the
288 * buffer. */
289 wvalue=0; /* The 'value' of the window */
290 wstart=bits-1; /* The top bit of the window */
291 wend=0; /* The bottom bit of the window */
292
293 if (!BN_one(r)) goto err;
294
295 for (;;)
296 {
297 if (BN_is_bit_set(p,wstart) == 0)
298 {
299 if (!start)
300 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
301 goto err;
302 if (wstart == 0) break;
303 wstart--;
304 continue;
305 }
306 /* We now have wstart on a 'set' bit, we now need to work out
307 * how bit a window to do. To do this we need to scan
308 * forward until the last set bit before the end of the
309 * window */
310 j=wstart;
311 wvalue=1;
312 wend=0;
313 for (i=1; i<window; i++)
314 {
315 if (wstart-i < 0) break;
316 if (BN_is_bit_set(p,wstart-i))
317 {
318 wvalue<<=(i-wend);
319 wvalue|=1;
320 wend=i;
321 }
322 }
323
324 /* wend is the size of the current window */
325 j=wend+1;
326 /* add the 'bytes above' */
327 if (!start)
328 for (i=0; i<j; i++)
329 {
330 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
331 goto err;
332 }
333
334 /* wvalue will be an odd number < 2^window */
335 if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))
336 goto err;
337
338 /* move the 'window' down further */
339 wstart-=wend+1;
340 wvalue=0;
341 start=0;
342 if (wstart < 0) break;
343 }
344 ret=1;
345err:
346 BN_CTX_end(ctx);
347 for (i=0; i<ts; i++)
348 BN_clear_free(&(val[i]));
349 BN_RECP_CTX_free(&recp);
350 return(ret);
351 }
352
353
354int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
355 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
356 {
357 int i,j,bits,ret=0,wstart,wend,window,wvalue;
358 int start=1,ts=0;
359 BIGNUM *d,*r;
360 const BIGNUM *aa;
361 BIGNUM val[TABLE_SIZE];
362 BN_MONT_CTX *mont=NULL;
363
364 bn_check_top(a);
365 bn_check_top(p);
366 bn_check_top(m);
367
368 if (!(m->d[0] & 1))
369 {
370 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
371 return(0);
372 }
373 bits=BN_num_bits(p);
374 if (bits == 0)
375 {
376 ret = BN_one(rr);
377 return ret;
378 }
379
380 BN_CTX_start(ctx);
381 d = BN_CTX_get(ctx);
382 r = BN_CTX_get(ctx);
383 if (d == NULL || r == NULL) goto err;
384
385 /* If this is not done, things will break in the montgomery
386 * part */
387
388 if (in_mont != NULL)
389 mont=in_mont;
390 else
391 {
392 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
393 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
394 }
395
396 BN_init(&val[0]);
397 ts=1;
398 if (a->neg || BN_ucmp(a,m) >= 0)
399 {
400 if (!BN_nnmod(&(val[0]),a,m,ctx))
401 goto err;
402 aa= &(val[0]);
403 }
404 else
405 aa=a;
406 if (BN_is_zero(aa))
407 {
408 ret = BN_zero(rr);
409 goto err;
410 }
411 if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
412
413 window = BN_window_bits_for_exponent_size(bits);
414 if (window > 1)
415 {
416 if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
417 j=1<<(window-1);
418 for (i=1; i<j; i++)
419 {
420 BN_init(&(val[i]));
421 if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))
422 goto err;
423 }
424 ts=i;
425 }
426
427 start=1; /* This is used to avoid multiplication etc
428 * when there is only the value '1' in the
429 * buffer. */
430 wvalue=0; /* The 'value' of the window */
431 wstart=bits-1; /* The top bit of the window */
432 wend=0; /* The bottom bit of the window */
433
434 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
435 for (;;)
436 {
437 if (BN_is_bit_set(p,wstart) == 0)
438 {
439 if (!start)
440 {
441 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
442 goto err;
443 }
444 if (wstart == 0) break;
445 wstart--;
446 continue;
447 }
448 /* We now have wstart on a 'set' bit, we now need to work out
449 * how bit a window to do. To do this we need to scan
450 * forward until the last set bit before the end of the
451 * window */
452 j=wstart;
453 wvalue=1;
454 wend=0;
455 for (i=1; i<window; i++)
456 {
457 if (wstart-i < 0) break;
458 if (BN_is_bit_set(p,wstart-i))
459 {
460 wvalue<<=(i-wend);
461 wvalue|=1;
462 wend=i;
463 }
464 }
465
466 /* wend is the size of the current window */
467 j=wend+1;
468 /* add the 'bytes above' */
469 if (!start)
470 for (i=0; i<j; i++)
471 {
472 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
473 goto err;
474 }
475
476 /* wvalue will be an odd number < 2^window */
477 if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))
478 goto err;
479
480 /* move the 'window' down further */
481 wstart-=wend+1;
482 wvalue=0;
483 start=0;
484 if (wstart < 0) break;
485 }
486 if (!BN_from_montgomery(rr,r,mont,ctx)) goto err;
487 ret=1;
488err:
489 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
490 BN_CTX_end(ctx);
491 for (i=0; i<ts; i++)
492 BN_clear_free(&(val[i]));
493 return(ret);
494 }
495
496int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
497 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
498 {
499 BN_MONT_CTX *mont = NULL;
500 int b, bits, ret=0;
501 int r_is_one;
502 BN_ULONG w, next_w;
503 BIGNUM *d, *r, *t;
504 BIGNUM *swap_tmp;
505#define BN_MOD_MUL_WORD(r, w, m) \
506 (BN_mul_word(r, (w)) && \
507 (/* BN_ucmp(r, (m)) < 0 ? 1 :*/ \
508 (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))
509 /* BN_MOD_MUL_WORD is only used with 'w' large,
510 * so the BN_ucmp test is probably more overhead
511 * than always using BN_mod (which uses BN_copy if
512 * a similar test returns true). */
513 /* We can use BN_mod and do not need BN_nnmod because our
514 * accumulator is never negative (the result of BN_mod does
515 * not depend on the sign of the modulus).
516 */
517#define BN_TO_MONTGOMERY_WORD(r, w, mont) \
518 (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))
519
520 bn_check_top(p);
521 bn_check_top(m);
522
523 if (m->top == 0 || !(m->d[0] & 1))
524 {
525 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);
526 return(0);
527 }
528 if (m->top == 1)
529 a %= m->d[0]; /* make sure that 'a' is reduced */
530
531 bits = BN_num_bits(p);
532 if (bits == 0)
533 {
534 ret = BN_one(rr);
535 return ret;
536 }
537 if (a == 0)
538 {
539 ret = BN_zero(rr);
540 return ret;
541 }
542
543 BN_CTX_start(ctx);
544 d = BN_CTX_get(ctx);
545 r = BN_CTX_get(ctx);
546 t = BN_CTX_get(ctx);
547 if (d == NULL || r == NULL || t == NULL) goto err;
548
549 if (in_mont != NULL)
550 mont=in_mont;
551 else
552 {
553 if ((mont = BN_MONT_CTX_new()) == NULL) goto err;
554 if (!BN_MONT_CTX_set(mont, m, ctx)) goto err;
555 }
556
557 r_is_one = 1; /* except for Montgomery factor */
558
559 /* bits-1 >= 0 */
560
561 /* The result is accumulated in the product r*w. */
562 w = a; /* bit 'bits-1' of 'p' is always set */
563 for (b = bits-2; b >= 0; b--)
564 {
565 /* First, square r*w. */
566 next_w = w*w;
567 if ((next_w/w) != w) /* overflow */
568 {
569 if (r_is_one)
570 {
571 if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;
572 r_is_one = 0;
573 }
574 else
575 {
576 if (!BN_MOD_MUL_WORD(r, w, m)) goto err;
577 }
578 next_w = 1;
579 }
580 w = next_w;
581 if (!r_is_one)
582 {
583 if (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) goto err;
584 }
585
586 /* Second, multiply r*w by 'a' if exponent bit is set. */
587 if (BN_is_bit_set(p, b))
588 {
589 next_w = w*a;
590 if ((next_w/a) != w) /* overflow */
591 {
592 if (r_is_one)
593 {
594 if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;
595 r_is_one = 0;
596 }
597 else
598 {
599 if (!BN_MOD_MUL_WORD(r, w, m)) goto err;
600 }
601 next_w = a;
602 }
603 w = next_w;
604 }
605 }
606
607 /* Finally, set r:=r*w. */
608 if (w != 1)
609 {
610 if (r_is_one)
611 {
612 if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;
613 r_is_one = 0;
614 }
615 else
616 {
617 if (!BN_MOD_MUL_WORD(r, w, m)) goto err;
618 }
619 }
620
621 if (r_is_one) /* can happen only if a == 1*/
622 {
623 if (!BN_one(rr)) goto err;
624 }
625 else
626 {
627 if (!BN_from_montgomery(rr, r, mont, ctx)) goto err;
628 }
629 ret = 1;
630err:
631 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
632 BN_CTX_end(ctx);
633 return(ret);
634 }
635
636
637/* The old fallback, simple version :-) */
638int BN_mod_exp_simple(BIGNUM *r,
639 const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
640 BN_CTX *ctx)
641 {
642 int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;
643 int start=1;
644 BIGNUM *d;
645 BIGNUM val[TABLE_SIZE];
646
647 bits=BN_num_bits(p);
648
649 if (bits == 0)
650 {
651 ret = BN_one(r);
652 return ret;
653 }
654
655 BN_CTX_start(ctx);
656 if ((d = BN_CTX_get(ctx)) == NULL) goto err;
657
658 BN_init(&(val[0]));
659 ts=1;
660 if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
661 if (BN_is_zero(&(val[0])))
662 {
663 ret = BN_zero(r);
664 goto err;
665 }
666
667 window = BN_window_bits_for_exponent_size(bits);
668 if (window > 1)
669 {
670 if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
671 goto err; /* 2 */
672 j=1<<(window-1);
673 for (i=1; i<j; i++)
674 {
675 BN_init(&(val[i]));
676 if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))
677 goto err;
678 }
679 ts=i;
680 }
681
682 start=1; /* This is used to avoid multiplication etc
683 * when there is only the value '1' in the
684 * buffer. */
685 wvalue=0; /* The 'value' of the window */
686 wstart=bits-1; /* The top bit of the window */
687 wend=0; /* The bottom bit of the window */
688
689 if (!BN_one(r)) goto err;
690
691 for (;;)
692 {
693 if (BN_is_bit_set(p,wstart) == 0)
694 {
695 if (!start)
696 if (!BN_mod_mul(r,r,r,m,ctx))
697 goto err;
698 if (wstart == 0) break;
699 wstart--;
700 continue;
701 }
702 /* We now have wstart on a 'set' bit, we now need to work out
703 * how bit a window to do. To do this we need to scan
704 * forward until the last set bit before the end of the
705 * window */
706 j=wstart;
707 wvalue=1;
708 wend=0;
709 for (i=1; i<window; i++)
710 {
711 if (wstart-i < 0) break;
712 if (BN_is_bit_set(p,wstart-i))
713 {
714 wvalue<<=(i-wend);
715 wvalue|=1;
716 wend=i;
717 }
718 }
719
720 /* wend is the size of the current window */
721 j=wend+1;
722 /* add the 'bytes above' */
723 if (!start)
724 for (i=0; i<j; i++)
725 {
726 if (!BN_mod_mul(r,r,r,m,ctx))
727 goto err;
728 }
729
730 /* wvalue will be an odd number < 2^window */
731 if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))
732 goto err;
733
734 /* move the 'window' down further */
735 wstart-=wend+1;
736 wvalue=0;
737 start=0;
738 if (wstart < 0) break;
739 }
740 ret=1;
741err:
742 BN_CTX_end(ctx);
743 for (i=0; i<ts; i++)
744 BN_clear_free(&(val[i]));
745 return(ret);
746 }
747
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
new file mode 100644
index 0000000000..73ccd58a83
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_exp2.c
@@ -0,0 +1,313 @@
1/* crypto/bn/bn_exp2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include "cryptlib.h"
114#include "bn_lcl.h"
115
116#define TABLE_SIZE 32
117
118int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
119 const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
120 BN_CTX *ctx, BN_MONT_CTX *in_mont)
121 {
122 int i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2;
123 int r_is_one=1,ts1=0,ts2=0;
124 BIGNUM *d,*r;
125 const BIGNUM *a_mod_m;
126 BIGNUM val1[TABLE_SIZE], val2[TABLE_SIZE];
127 BN_MONT_CTX *mont=NULL;
128
129 bn_check_top(a1);
130 bn_check_top(p1);
131 bn_check_top(a2);
132 bn_check_top(p2);
133 bn_check_top(m);
134
135 if (!(m->d[0] & 1))
136 {
137 BNerr(BN_F_BN_MOD_EXP2_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
138 return(0);
139 }
140 bits1=BN_num_bits(p1);
141 bits2=BN_num_bits(p2);
142 if ((bits1 == 0) && (bits2 == 0))
143 {
144 ret = BN_one(rr);
145 return ret;
146 }
147
148 bits=(bits1 > bits2)?bits1:bits2;
149
150 BN_CTX_start(ctx);
151 d = BN_CTX_get(ctx);
152 r = BN_CTX_get(ctx);
153 if (d == NULL || r == NULL) goto err;
154
155 if (in_mont != NULL)
156 mont=in_mont;
157 else
158 {
159 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
160 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
161 }
162
163 window1 = BN_window_bits_for_exponent_size(bits1);
164 window2 = BN_window_bits_for_exponent_size(bits2);
165
166 /*
167 * Build table for a1: val1[i] := a1^(2*i + 1) mod m for i = 0 .. 2^(window1-1)
168 */
169 BN_init(&val1[0]);
170 ts1=1;
171 if (a1->neg || BN_ucmp(a1,m) >= 0)
172 {
173 if (!BN_mod(&(val1[0]),a1,m,ctx))
174 goto err;
175 a_mod_m = &(val1[0]);
176 }
177 else
178 a_mod_m = a1;
179 if (BN_is_zero(a_mod_m))
180 {
181 ret = BN_zero(rr);
182 goto err;
183 }
184
185 if (!BN_to_montgomery(&(val1[0]),a_mod_m,mont,ctx)) goto err;
186 if (window1 > 1)
187 {
188 if (!BN_mod_mul_montgomery(d,&(val1[0]),&(val1[0]),mont,ctx)) goto err;
189
190 j=1<<(window1-1);
191 for (i=1; i<j; i++)
192 {
193 BN_init(&(val1[i]));
194 if (!BN_mod_mul_montgomery(&(val1[i]),&(val1[i-1]),d,mont,ctx))
195 goto err;
196 }
197 ts1=i;
198 }
199
200
201 /*
202 * Build table for a2: val2[i] := a2^(2*i + 1) mod m for i = 0 .. 2^(window2-1)
203 */
204 BN_init(&val2[0]);
205 ts2=1;
206 if (a2->neg || BN_ucmp(a2,m) >= 0)
207 {
208 if (!BN_mod(&(val2[0]),a2,m,ctx))
209 goto err;
210 a_mod_m = &(val2[0]);
211 }
212 else
213 a_mod_m = a2;
214 if (BN_is_zero(a_mod_m))
215 {
216 ret = BN_zero(rr);
217 goto err;
218 }
219 if (!BN_to_montgomery(&(val2[0]),a_mod_m,mont,ctx)) goto err;
220 if (window2 > 1)
221 {
222 if (!BN_mod_mul_montgomery(d,&(val2[0]),&(val2[0]),mont,ctx)) goto err;
223
224 j=1<<(window2-1);
225 for (i=1; i<j; i++)
226 {
227 BN_init(&(val2[i]));
228 if (!BN_mod_mul_montgomery(&(val2[i]),&(val2[i-1]),d,mont,ctx))
229 goto err;
230 }
231 ts2=i;
232 }
233
234
235 /* Now compute the power product, using independent windows. */
236 r_is_one=1;
237 wvalue1=0; /* The 'value' of the first window */
238 wvalue2=0; /* The 'value' of the second window */
239 wpos1=0; /* If wvalue1 > 0, the bottom bit of the first window */
240 wpos2=0; /* If wvalue2 > 0, the bottom bit of the second window */
241
242 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
243 for (b=bits-1; b>=0; b--)
244 {
245 if (!r_is_one)
246 {
247 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
248 goto err;
249 }
250
251 if (!wvalue1)
252 if (BN_is_bit_set(p1, b))
253 {
254 /* consider bits b-window1+1 .. b for this window */
255 i = b-window1+1;
256 while (!BN_is_bit_set(p1, i)) /* works for i<0 */
257 i++;
258 wpos1 = i;
259 wvalue1 = 1;
260 for (i = b-1; i >= wpos1; i--)
261 {
262 wvalue1 <<= 1;
263 if (BN_is_bit_set(p1, i))
264 wvalue1++;
265 }
266 }
267
268 if (!wvalue2)
269 if (BN_is_bit_set(p2, b))
270 {
271 /* consider bits b-window2+1 .. b for this window */
272 i = b-window2+1;
273 while (!BN_is_bit_set(p2, i))
274 i++;
275 wpos2 = i;
276 wvalue2 = 1;
277 for (i = b-1; i >= wpos2; i--)
278 {
279 wvalue2 <<= 1;
280 if (BN_is_bit_set(p2, i))
281 wvalue2++;
282 }
283 }
284
285 if (wvalue1 && b == wpos1)
286 {
287 /* wvalue1 is odd and < 2^window1 */
288 if (!BN_mod_mul_montgomery(r,r,&(val1[wvalue1>>1]),mont,ctx))
289 goto err;
290 wvalue1 = 0;
291 r_is_one = 0;
292 }
293
294 if (wvalue2 && b == wpos2)
295 {
296 /* wvalue2 is odd and < 2^window2 */
297 if (!BN_mod_mul_montgomery(r,r,&(val2[wvalue2>>1]),mont,ctx))
298 goto err;
299 wvalue2 = 0;
300 r_is_one = 0;
301 }
302 }
303 BN_from_montgomery(rr,r,mont,ctx);
304 ret=1;
305err:
306 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
307 BN_CTX_end(ctx);
308 for (i=0; i<ts1; i++)
309 BN_clear_free(&(val1[i]));
310 for (i=0; i<ts2; i++)
311 BN_clear_free(&(val2[i]));
312 return(ret);
313 }
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
new file mode 100644
index 0000000000..7649f63fd2
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_gcd.c
@@ -0,0 +1,490 @@
1/* crypto/bn/bn_gcd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include "bn_lcl.h"
114
115static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
116
117int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
118 {
119 BIGNUM *a,*b,*t;
120 int ret=0;
121
122 bn_check_top(in_a);
123 bn_check_top(in_b);
124
125 BN_CTX_start(ctx);
126 a = BN_CTX_get(ctx);
127 b = BN_CTX_get(ctx);
128 if (a == NULL || b == NULL) goto err;
129
130 if (BN_copy(a,in_a) == NULL) goto err;
131 if (BN_copy(b,in_b) == NULL) goto err;
132 a->neg = 0;
133 b->neg = 0;
134
135 if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; }
136 t=euclid(a,b);
137 if (t == NULL) goto err;
138
139 if (BN_copy(r,t) == NULL) goto err;
140 ret=1;
141err:
142 BN_CTX_end(ctx);
143 return(ret);
144 }
145
146static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
147 {
148 BIGNUM *t;
149 int shifts=0;
150
151 bn_check_top(a);
152 bn_check_top(b);
153
154 /* 0 <= b <= a */
155 while (!BN_is_zero(b))
156 {
157 /* 0 < b <= a */
158
159 if (BN_is_odd(a))
160 {
161 if (BN_is_odd(b))
162 {
163 if (!BN_sub(a,a,b)) goto err;
164 if (!BN_rshift1(a,a)) goto err;
165 if (BN_cmp(a,b) < 0)
166 { t=a; a=b; b=t; }
167 }
168 else /* a odd - b even */
169 {
170 if (!BN_rshift1(b,b)) goto err;
171 if (BN_cmp(a,b) < 0)
172 { t=a; a=b; b=t; }
173 }
174 }
175 else /* a is even */
176 {
177 if (BN_is_odd(b))
178 {
179 if (!BN_rshift1(a,a)) goto err;
180 if (BN_cmp(a,b) < 0)
181 { t=a; a=b; b=t; }
182 }
183 else /* a even - b even */
184 {
185 if (!BN_rshift1(a,a)) goto err;
186 if (!BN_rshift1(b,b)) goto err;
187 shifts++;
188 }
189 }
190 /* 0 <= b <= a */
191 }
192
193 if (shifts)
194 {
195 if (!BN_lshift(a,a,shifts)) goto err;
196 }
197 return(a);
198err:
199 return(NULL);
200 }
201
202
203/* solves ax == 1 (mod n) */
204BIGNUM *BN_mod_inverse(BIGNUM *in,
205 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
206 {
207 BIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;
208 BIGNUM *ret=NULL;
209 int sign;
210
211 bn_check_top(a);
212 bn_check_top(n);
213
214 BN_CTX_start(ctx);
215 A = BN_CTX_get(ctx);
216 B = BN_CTX_get(ctx);
217 X = BN_CTX_get(ctx);
218 D = BN_CTX_get(ctx);
219 M = BN_CTX_get(ctx);
220 Y = BN_CTX_get(ctx);
221 T = BN_CTX_get(ctx);
222 if (T == NULL) goto err;
223
224 if (in == NULL)
225 R=BN_new();
226 else
227 R=in;
228 if (R == NULL) goto err;
229
230 BN_one(X);
231 BN_zero(Y);
232 if (BN_copy(B,a) == NULL) goto err;
233 if (BN_copy(A,n) == NULL) goto err;
234 A->neg = 0;
235 if (B->neg || (BN_ucmp(B, A) >= 0))
236 {
237 if (!BN_nnmod(B, B, A, ctx)) goto err;
238 }
239 sign = -1;
240 /* From B = a mod |n|, A = |n| it follows that
241 *
242 * 0 <= B < A,
243 * -sign*X*a == B (mod |n|),
244 * sign*Y*a == A (mod |n|).
245 */
246
247 if (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))
248 {
249 /* Binary inversion algorithm; requires odd modulus.
250 * This is faster than the general algorithm if the modulus
251 * is sufficiently small (about 400 .. 500 bits on 32-bit
252 * sytems, but much more on 64-bit systems) */
253 int shift;
254
255 while (!BN_is_zero(B))
256 {
257 /*
258 * 0 < B < |n|,
259 * 0 < A <= |n|,
260 * (1) -sign*X*a == B (mod |n|),
261 * (2) sign*Y*a == A (mod |n|)
262 */
263
264 /* Now divide B by the maximum possible power of two in the integers,
265 * and divide X by the same value mod |n|.
266 * When we're done, (1) still holds. */
267 shift = 0;
268 while (!BN_is_bit_set(B, shift)) /* note that 0 < B */
269 {
270 shift++;
271
272 if (BN_is_odd(X))
273 {
274 if (!BN_uadd(X, X, n)) goto err;
275 }
276 /* now X is even, so we can easily divide it by two */
277 if (!BN_rshift1(X, X)) goto err;
278 }
279 if (shift > 0)
280 {
281 if (!BN_rshift(B, B, shift)) goto err;
282 }
283
284
285 /* Same for A and Y. Afterwards, (2) still holds. */
286 shift = 0;
287 while (!BN_is_bit_set(A, shift)) /* note that 0 < A */
288 {
289 shift++;
290
291 if (BN_is_odd(Y))
292 {
293 if (!BN_uadd(Y, Y, n)) goto err;
294 }
295 /* now Y is even */
296 if (!BN_rshift1(Y, Y)) goto err;
297 }
298 if (shift > 0)
299 {
300 if (!BN_rshift(A, A, shift)) goto err;
301 }
302
303
304 /* We still have (1) and (2).
305 * Both A and B are odd.
306 * The following computations ensure that
307 *
308 * 0 <= B < |n|,
309 * 0 < A < |n|,
310 * (1) -sign*X*a == B (mod |n|),
311 * (2) sign*Y*a == A (mod |n|),
312 *
313 * and that either A or B is even in the next iteration.
314 */
315 if (BN_ucmp(B, A) >= 0)
316 {
317 /* -sign*(X + Y)*a == B - A (mod |n|) */
318 if (!BN_uadd(X, X, Y)) goto err;
319 /* NB: we could use BN_mod_add_quick(X, X, Y, n), but that
320 * actually makes the algorithm slower */
321 if (!BN_usub(B, B, A)) goto err;
322 }
323 else
324 {
325 /* sign*(X + Y)*a == A - B (mod |n|) */
326 if (!BN_uadd(Y, Y, X)) goto err;
327 /* as above, BN_mod_add_quick(Y, Y, X, n) would slow things down */
328 if (!BN_usub(A, A, B)) goto err;
329 }
330 }
331 }
332 else
333 {
334 /* general inversion algorithm */
335
336 while (!BN_is_zero(B))
337 {
338 BIGNUM *tmp;
339
340 /*
341 * 0 < B < A,
342 * (*) -sign*X*a == B (mod |n|),
343 * sign*Y*a == A (mod |n|)
344 */
345
346 /* (D, M) := (A/B, A%B) ... */
347 if (BN_num_bits(A) == BN_num_bits(B))
348 {
349 if (!BN_one(D)) goto err;
350 if (!BN_sub(M,A,B)) goto err;
351 }
352 else if (BN_num_bits(A) == BN_num_bits(B) + 1)
353 {
354 /* A/B is 1, 2, or 3 */
355 if (!BN_lshift1(T,B)) goto err;
356 if (BN_ucmp(A,T) < 0)
357 {
358 /* A < 2*B, so D=1 */
359 if (!BN_one(D)) goto err;
360 if (!BN_sub(M,A,B)) goto err;
361 }
362 else
363 {
364 /* A >= 2*B, so D=2 or D=3 */
365 if (!BN_sub(M,A,T)) goto err;
366 if (!BN_add(D,T,B)) goto err; /* use D (:= 3*B) as temp */
367 if (BN_ucmp(A,D) < 0)
368 {
369 /* A < 3*B, so D=2 */
370 if (!BN_set_word(D,2)) goto err;
371 /* M (= A - 2*B) already has the correct value */
372 }
373 else
374 {
375 /* only D=3 remains */
376 if (!BN_set_word(D,3)) goto err;
377 /* currently M = A - 2*B, but we need M = A - 3*B */
378 if (!BN_sub(M,M,B)) goto err;
379 }
380 }
381 }
382 else
383 {
384 if (!BN_div(D,M,A,B,ctx)) goto err;
385 }
386
387 /* Now
388 * A = D*B + M;
389 * thus we have
390 * (**) sign*Y*a == D*B + M (mod |n|).
391 */
392
393 tmp=A; /* keep the BIGNUM object, the value does not matter */
394
395 /* (A, B) := (B, A mod B) ... */
396 A=B;
397 B=M;
398 /* ... so we have 0 <= B < A again */
399
400 /* Since the former M is now B and the former B is now A,
401 * (**) translates into
402 * sign*Y*a == D*A + B (mod |n|),
403 * i.e.
404 * sign*Y*a - D*A == B (mod |n|).
405 * Similarly, (*) translates into
406 * -sign*X*a == A (mod |n|).
407 *
408 * Thus,
409 * sign*Y*a + D*sign*X*a == B (mod |n|),
410 * i.e.
411 * sign*(Y + D*X)*a == B (mod |n|).
412 *
413 * So if we set (X, Y, sign) := (Y + D*X, X, -sign), we arrive back at
414 * -sign*X*a == B (mod |n|),
415 * sign*Y*a == A (mod |n|).
416 * Note that X and Y stay non-negative all the time.
417 */
418
419 /* most of the time D is very small, so we can optimize tmp := D*X+Y */
420 if (BN_is_one(D))
421 {
422 if (!BN_add(tmp,X,Y)) goto err;
423 }
424 else
425 {
426 if (BN_is_word(D,2))
427 {
428 if (!BN_lshift1(tmp,X)) goto err;
429 }
430 else if (BN_is_word(D,4))
431 {
432 if (!BN_lshift(tmp,X,2)) goto err;
433 }
434 else if (D->top == 1)
435 {
436 if (!BN_copy(tmp,X)) goto err;
437 if (!BN_mul_word(tmp,D->d[0])) goto err;
438 }
439 else
440 {
441 if (!BN_mul(tmp,D,X,ctx)) goto err;
442 }
443 if (!BN_add(tmp,tmp,Y)) goto err;
444 }
445
446 M=Y; /* keep the BIGNUM object, the value does not matter */
447 Y=X;
448 X=tmp;
449 sign = -sign;
450 }
451 }
452
453 /*
454 * The while loop (Euclid's algorithm) ends when
455 * A == gcd(a,n);
456 * we have
457 * sign*Y*a == A (mod |n|),
458 * where Y is non-negative.
459 */
460
461 if (sign < 0)
462 {
463 if (!BN_sub(Y,n,Y)) goto err;
464 }
465 /* Now Y*a == A (mod |n|). */
466
467
468 if (BN_is_one(A))
469 {
470 /* Y*a == 1 (mod |n|) */
471 if (!Y->neg && BN_ucmp(Y,n) < 0)
472 {
473 if (!BN_copy(R,Y)) goto err;
474 }
475 else
476 {
477 if (!BN_nnmod(R,Y,n,ctx)) goto err;
478 }
479 }
480 else
481 {
482 BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);
483 goto err;
484 }
485 ret=R;
486err:
487 if ((ret == NULL) && (in == NULL)) BN_free(R);
488 BN_CTX_end(ctx);
489 return(ret);
490 }
diff --git a/src/lib/libcrypto/bn/bn_kron.c b/src/lib/libcrypto/bn/bn_kron.c
new file mode 100644
index 0000000000..49f75594ae
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_kron.c
@@ -0,0 +1,182 @@
1/* crypto/bn/bn_kron.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "bn_lcl.h"
57
58
59/* least significant word */
60#define BN_lsw(n) (((n)->top == 0) ? (BN_ULONG) 0 : (n)->d[0])
61
62/* Returns -2 for errors because both -1 and 0 are valid results. */
63int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
64 {
65 int i;
66 int ret = -2; /* avoid 'uninitialized' warning */
67 int err = 0;
68 BIGNUM *A, *B, *tmp;
69 /* In 'tab', only odd-indexed entries are relevant:
70 * For any odd BIGNUM n,
71 * tab[BN_lsw(n) & 7]
72 * is $(-1)^{(n^2-1)/8}$ (using TeX notation).
73 * Note that the sign of n does not matter.
74 */
75 static const int tab[8] = {0, 1, 0, -1, 0, -1, 0, 1};
76
77 BN_CTX_start(ctx);
78 A = BN_CTX_get(ctx);
79 B = BN_CTX_get(ctx);
80 if (B == NULL) goto end;
81
82 err = !BN_copy(A, a);
83 if (err) goto end;
84 err = !BN_copy(B, b);
85 if (err) goto end;
86
87 /*
88 * Kronecker symbol, imlemented according to Henri Cohen,
89 * "A Course in Computational Algebraic Number Theory"
90 * (algorithm 1.4.10).
91 */
92
93 /* Cohen's step 1: */
94
95 if (BN_is_zero(B))
96 {
97 ret = BN_abs_is_word(A, 1);
98 goto end;
99 }
100
101 /* Cohen's step 2: */
102
103 if (!BN_is_odd(A) && !BN_is_odd(B))
104 {
105 ret = 0;
106 goto end;
107 }
108
109 /* now B is non-zero */
110 i = 0;
111 while (!BN_is_bit_set(B, i))
112 i++;
113 err = !BN_rshift(B, B, i);
114 if (err) goto end;
115 if (i & 1)
116 {
117 /* i is odd */
118 /* (thus B was even, thus A must be odd!) */
119
120 /* set 'ret' to $(-1)^{(A^2-1)/8}$ */
121 ret = tab[BN_lsw(A) & 7];
122 }
123 else
124 {
125 /* i is even */
126 ret = 1;
127 }
128
129 if (B->neg)
130 {
131 B->neg = 0;
132 if (A->neg)
133 ret = -ret;
134 }
135
136 /* now B is positive and odd, so what remains to be done is
137 * to compute the Jacobi symbol (A/B) and multiply it by 'ret' */
138
139 while (1)
140 {
141 /* Cohen's step 3: */
142
143 /* B is positive and odd */
144
145 if (BN_is_zero(A))
146 {
147 ret = BN_is_one(B) ? ret : 0;
148 goto end;
149 }
150
151 /* now A is non-zero */
152 i = 0;
153 while (!BN_is_bit_set(A, i))
154 i++;
155 err = !BN_rshift(A, A, i);
156 if (err) goto end;
157 if (i & 1)
158 {
159 /* i is odd */
160 /* multiply 'ret' by $(-1)^{(B^2-1)/8}$ */
161 ret = ret * tab[BN_lsw(B) & 7];
162 }
163
164 /* Cohen's step 4: */
165 /* multiply 'ret' by $(-1)^{(A-1)(B-1)/4}$ */
166 if ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)
167 ret = -ret;
168
169 /* (A, B) := (B mod |A|, |A|) */
170 err = !BN_nnmod(B, B, A, ctx);
171 if (err) goto end;
172 tmp = A; A = B; B = tmp;
173 tmp->neg = 0;
174 }
175
176 end:
177 BN_CTX_end(ctx);
178 if (err)
179 return -2;
180 else
181 return ret;
182 }
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
new file mode 100644
index 0000000000..253e195e23
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_lcl.h
@@ -0,0 +1,453 @@
1/* crypto/bn/bn_lcl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_BN_LCL_H
113#define HEADER_BN_LCL_H
114
115#include <openssl/bn.h>
116
117#ifdef __cplusplus
118extern "C" {
119#endif
120
121
122/* Used for temp variables */
123#define BN_CTX_NUM 32
124#define BN_CTX_NUM_POS 12
125struct bignum_ctx
126 {
127 int tos;
128 BIGNUM bn[BN_CTX_NUM];
129 int flags;
130 int depth;
131 int pos[BN_CTX_NUM_POS];
132 int too_many;
133 } /* BN_CTX */;
134
135
136/*
137 * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions
138 *
139 *
140 * For window size 'w' (w >= 2) and a random 'b' bits exponent,
141 * the number of multiplications is a constant plus on average
142 *
143 * 2^(w-1) + (b-w)/(w+1);
144 *
145 * here 2^(w-1) is for precomputing the table (we actually need
146 * entries only for windows that have the lowest bit set), and
147 * (b-w)/(w+1) is an approximation for the expected number of
148 * w-bit windows, not counting the first one.
149 *
150 * Thus we should use
151 *
152 * w >= 6 if b > 671
153 * w = 5 if 671 > b > 239
154 * w = 4 if 239 > b > 79
155 * w = 3 if 79 > b > 23
156 * w <= 2 if 23 > b
157 *
158 * (with draws in between). Very small exponents are often selected
159 * with low Hamming weight, so we use w = 1 for b <= 23.
160 */
161#if 1
162#define BN_window_bits_for_exponent_size(b) \
163 ((b) > 671 ? 6 : \
164 (b) > 239 ? 5 : \
165 (b) > 79 ? 4 : \
166 (b) > 23 ? 3 : 1)
167#else
168/* Old SSLeay/OpenSSL table.
169 * Maximum window size was 5, so this table differs for b==1024;
170 * but it coincides for other interesting values (b==160, b==512).
171 */
172#define BN_window_bits_for_exponent_size(b) \
173 ((b) > 255 ? 5 : \
174 (b) > 127 ? 4 : \
175 (b) > 17 ? 3 : 1)
176#endif
177
178
179
180/* Pentium pro 16,16,16,32,64 */
181/* Alpha 16,16,16,16.64 */
182#define BN_MULL_SIZE_NORMAL (16) /* 32 */
183#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 less than */
184#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */
185#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */
186#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */
187
188#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
189/*
190 * BN_UMULT_HIGH section.
191 *
192 * No, I'm not trying to overwhelm you when stating that the
193 * product of N-bit numbers is 2*N bits wide:-) No, I don't expect
194 * you to be impressed when I say that if the compiler doesn't
195 * support 2*N integer type, then you have to replace every N*N
196 * multiplication with 4 (N/2)*(N/2) accompanied by some shifts
197 * and additions which unavoidably results in severe performance
198 * penalties. Of course provided that the hardware is capable of
199 * producing 2*N result... That's when you normally start
200 * considering assembler implementation. However! It should be
201 * pointed out that some CPUs (most notably Alpha, PowerPC and
202 * upcoming IA-64 family:-) provide *separate* instruction
203 * calculating the upper half of the product placing the result
204 * into a general purpose register. Now *if* the compiler supports
205 * inline assembler, then it's not impossible to implement the
206 * "bignum" routines (and have the compiler optimize 'em)
207 * exhibiting "native" performance in C. That's what BN_UMULT_HIGH
208 * macro is about:-)
209 *
210 * <appro@fy.chalmers.se>
211 */
212# if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT))
213# if defined(__DECC)
214# include <c_asm.h>
215# define BN_UMULT_HIGH(a,b) (BN_ULONG)asm("umulh %a0,%a1,%v0",(a),(b))
216# elif defined(__GNUC__)
217# define BN_UMULT_HIGH(a,b) ({ \
218 register BN_ULONG ret; \
219 asm ("umulh %1,%2,%0" \
220 : "=r"(ret) \
221 : "r"(a), "r"(b)); \
222 ret; })
223# endif /* compiler */
224# elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG)
225# if defined(__GNUC__)
226# define BN_UMULT_HIGH(a,b) ({ \
227 register BN_ULONG ret; \
228 asm ("mulhdu %0,%1,%2" \
229 : "=r"(ret) \
230 : "r"(a), "r"(b)); \
231 ret; })
232# endif /* compiler */
233# elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
234# if defined(__GNUC__)
235# define BN_UMULT_HIGH(a,b) ({ \
236 register BN_ULONG ret,discard; \
237 asm ("mulq %3" \
238 : "=a"(discard),"=d"(ret) \
239 : "a"(a), "g"(b) \
240 : "cc"); \
241 ret; })
242# define BN_UMULT_LOHI(low,high,a,b) \
243 asm ("mulq %3" \
244 : "=a"(low),"=d"(high) \
245 : "a"(a),"g"(b) \
246 : "cc");
247# endif
248# endif /* cpu */
249#endif /* OPENSSL_NO_ASM */
250
251/*************************************************************
252 * Using the long long type
253 */
254#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
255#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
256
257/* This is used for internal error checking and is not normally used */
258#ifdef BN_DEBUG
259# include <assert.h>
260# define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->dmax);
261#else
262# define bn_check_top(a)
263#endif
264
265/* This macro is to add extra stuff for development checking */
266#ifdef BN_DEBUG
267#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA))
268#else
269#define bn_set_max(r)
270#endif
271
272/* These macros are used to 'take' a section of a bignum for read only use */
273#define bn_set_low(r,a,n) \
274 { \
275 (r)->top=((a)->top > (n))?(n):(a)->top; \
276 (r)->d=(a)->d; \
277 (r)->neg=(a)->neg; \
278 (r)->flags|=BN_FLG_STATIC_DATA; \
279 bn_set_max(r); \
280 }
281
282#define bn_set_high(r,a,n) \
283 { \
284 if ((a)->top > (n)) \
285 { \
286 (r)->top=(a)->top-n; \
287 (r)->d= &((a)->d[n]); \
288 } \
289 else \
290 (r)->top=0; \
291 (r)->neg=(a)->neg; \
292 (r)->flags|=BN_FLG_STATIC_DATA; \
293 bn_set_max(r); \
294 }
295
296#ifdef BN_LLONG
297#define mul_add(r,a,w,c) { \
298 BN_ULLONG t; \
299 t=(BN_ULLONG)w * (a) + (r) + (c); \
300 (r)= Lw(t); \
301 (c)= Hw(t); \
302 }
303
304#define mul(r,a,w,c) { \
305 BN_ULLONG t; \
306 t=(BN_ULLONG)w * (a) + (c); \
307 (r)= Lw(t); \
308 (c)= Hw(t); \
309 }
310
311#define sqr(r0,r1,a) { \
312 BN_ULLONG t; \
313 t=(BN_ULLONG)(a)*(a); \
314 (r0)=Lw(t); \
315 (r1)=Hw(t); \
316 }
317
318#elif defined(BN_UMULT_HIGH)
319#define mul_add(r,a,w,c) { \
320 BN_ULONG high,low,ret,tmp=(a); \
321 ret = (r); \
322 high= BN_UMULT_HIGH(w,tmp); \
323 ret += (c); \
324 low = (w) * tmp; \
325 (c) = (ret<(c))?1:0; \
326 (c) += high; \
327 ret += low; \
328 (c) += (ret<low)?1:0; \
329 (r) = ret; \
330 }
331
332#define mul(r,a,w,c) { \
333 BN_ULONG high,low,ret,ta=(a); \
334 low = (w) * ta; \
335 high= BN_UMULT_HIGH(w,ta); \
336 ret = low + (c); \
337 (c) = high; \
338 (c) += (ret<low)?1:0; \
339 (r) = ret; \
340 }
341
342#define sqr(r0,r1,a) { \
343 BN_ULONG tmp=(a); \
344 (r0) = tmp * tmp; \
345 (r1) = BN_UMULT_HIGH(tmp,tmp); \
346 }
347
348#else
349/*************************************************************
350 * No long long type
351 */
352
353#define LBITS(a) ((a)&BN_MASK2l)
354#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l)
355#define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2)
356
357#define LLBITS(a) ((a)&BN_MASKl)
358#define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl)
359#define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2)
360
361#define mul64(l,h,bl,bh) \
362 { \
363 BN_ULONG m,m1,lt,ht; \
364 \
365 lt=l; \
366 ht=h; \
367 m =(bh)*(lt); \
368 lt=(bl)*(lt); \
369 m1=(bl)*(ht); \
370 ht =(bh)*(ht); \
371 m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS((BN_ULONG)1); \
372 ht+=HBITS(m); \
373 m1=L2HBITS(m); \
374 lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
375 (l)=lt; \
376 (h)=ht; \
377 }
378
379#define sqr64(lo,ho,in) \
380 { \
381 BN_ULONG l,h,m; \
382 \
383 h=(in); \
384 l=LBITS(h); \
385 h=HBITS(h); \
386 m =(l)*(h); \
387 l*=l; \
388 h*=h; \
389 h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
390 m =(m&BN_MASK2l)<<(BN_BITS4+1); \
391 l=(l+m)&BN_MASK2; if (l < m) h++; \
392 (lo)=l; \
393 (ho)=h; \
394 }
395
396#define mul_add(r,a,bl,bh,c) { \
397 BN_ULONG l,h; \
398 \
399 h= (a); \
400 l=LBITS(h); \
401 h=HBITS(h); \
402 mul64(l,h,(bl),(bh)); \
403 \
404 /* non-multiply part */ \
405 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
406 (c)=(r); \
407 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
408 (c)=h&BN_MASK2; \
409 (r)=l; \
410 }
411
412#define mul(r,a,bl,bh,c) { \
413 BN_ULONG l,h; \
414 \
415 h= (a); \
416 l=LBITS(h); \
417 h=HBITS(h); \
418 mul64(l,h,(bl),(bh)); \
419 \
420 /* non-multiply part */ \
421 l+=(c); if ((l&BN_MASK2) < (c)) h++; \
422 (c)=h&BN_MASK2; \
423 (r)=l&BN_MASK2; \
424 }
425#endif /* !BN_LLONG */
426
427void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);
428void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
429void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
430void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp);
431void bn_sqr_comba8(BN_ULONG *r,const BN_ULONG *a);
432void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a);
433int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n);
434int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
435 int cl, int dl);
436#ifdef BN_RECURSION
437void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
438 BN_ULONG *t);
439void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
440 int n, BN_ULONG *t);
441void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,
442 BN_ULONG *t);
443void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2,
444 BN_ULONG *t);
445void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t);
446#endif
447void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
448
449#ifdef __cplusplus
450}
451#endif
452
453#endif
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
new file mode 100644
index 0000000000..e1660450bc
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -0,0 +1,824 @@
1/* crypto/bn/bn_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef BN_DEBUG
60# undef NDEBUG /* avoid conflicting definitions */
61# define NDEBUG
62#endif
63
64#include <assert.h>
65#include <limits.h>
66#include <stdio.h>
67#include "cryptlib.h"
68#include "bn_lcl.h"
69
70const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT;
71
72/* For a 32 bit machine
73 * 2 - 4 == 128
74 * 3 - 8 == 256
75 * 4 - 16 == 512
76 * 5 - 32 == 1024
77 * 6 - 64 == 2048
78 * 7 - 128 == 4096
79 * 8 - 256 == 8192
80 */
81static int bn_limit_bits=0;
82static int bn_limit_num=8; /* (1<<bn_limit_bits) */
83static int bn_limit_bits_low=0;
84static int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */
85static int bn_limit_bits_high=0;
86static int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */
87static int bn_limit_bits_mont=0;
88static int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */
89
90void BN_set_params(int mult, int high, int low, int mont)
91 {
92 if (mult >= 0)
93 {
94 if (mult > (sizeof(int)*8)-1)
95 mult=sizeof(int)*8-1;
96 bn_limit_bits=mult;
97 bn_limit_num=1<<mult;
98 }
99 if (high >= 0)
100 {
101 if (high > (sizeof(int)*8)-1)
102 high=sizeof(int)*8-1;
103 bn_limit_bits_high=high;
104 bn_limit_num_high=1<<high;
105 }
106 if (low >= 0)
107 {
108 if (low > (sizeof(int)*8)-1)
109 low=sizeof(int)*8-1;
110 bn_limit_bits_low=low;
111 bn_limit_num_low=1<<low;
112 }
113 if (mont >= 0)
114 {
115 if (mont > (sizeof(int)*8)-1)
116 mont=sizeof(int)*8-1;
117 bn_limit_bits_mont=mont;
118 bn_limit_num_mont=1<<mont;
119 }
120 }
121
122int BN_get_params(int which)
123 {
124 if (which == 0) return(bn_limit_bits);
125 else if (which == 1) return(bn_limit_bits_high);
126 else if (which == 2) return(bn_limit_bits_low);
127 else if (which == 3) return(bn_limit_bits_mont);
128 else return(0);
129 }
130
131const BIGNUM *BN_value_one(void)
132 {
133 static BN_ULONG data_one=1L;
134 static BIGNUM const_one={&data_one,1,1,0};
135
136 return(&const_one);
137 }
138
139char *BN_options(void)
140 {
141 static int init=0;
142 static char data[16];
143
144 if (!init)
145 {
146 init++;
147#ifdef BN_LLONG
148 BIO_snprintf(data,sizeof data,"bn(%d,%d)",
149 (int)sizeof(BN_ULLONG)*8,(int)sizeof(BN_ULONG)*8);
150#else
151 BIO_snprintf(data,sizeof data,"bn(%d,%d)",
152 (int)sizeof(BN_ULONG)*8,(int)sizeof(BN_ULONG)*8);
153#endif
154 }
155 return(data);
156 }
157
158int BN_num_bits_word(BN_ULONG l)
159 {
160 static const char bits[256]={
161 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
162 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
163 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
164 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
165 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
166 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
167 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
168 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
169 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
170 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
171 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
172 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
173 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
174 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
175 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
176 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
177 };
178
179#if defined(SIXTY_FOUR_BIT_LONG)
180 if (l & 0xffffffff00000000L)
181 {
182 if (l & 0xffff000000000000L)
183 {
184 if (l & 0xff00000000000000L)
185 {
186 return(bits[(int)(l>>56)]+56);
187 }
188 else return(bits[(int)(l>>48)]+48);
189 }
190 else
191 {
192 if (l & 0x0000ff0000000000L)
193 {
194 return(bits[(int)(l>>40)]+40);
195 }
196 else return(bits[(int)(l>>32)]+32);
197 }
198 }
199 else
200#else
201#ifdef SIXTY_FOUR_BIT
202 if (l & 0xffffffff00000000LL)
203 {
204 if (l & 0xffff000000000000LL)
205 {
206 if (l & 0xff00000000000000LL)
207 {
208 return(bits[(int)(l>>56)]+56);
209 }
210 else return(bits[(int)(l>>48)]+48);
211 }
212 else
213 {
214 if (l & 0x0000ff0000000000LL)
215 {
216 return(bits[(int)(l>>40)]+40);
217 }
218 else return(bits[(int)(l>>32)]+32);
219 }
220 }
221 else
222#endif
223#endif
224 {
225#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
226 if (l & 0xffff0000L)
227 {
228 if (l & 0xff000000L)
229 return(bits[(int)(l>>24L)]+24);
230 else return(bits[(int)(l>>16L)]+16);
231 }
232 else
233#endif
234 {
235#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
236 if (l & 0xff00L)
237 return(bits[(int)(l>>8)]+8);
238 else
239#endif
240 return(bits[(int)(l )] );
241 }
242 }
243 }
244
245int BN_num_bits(const BIGNUM *a)
246 {
247 BN_ULONG l;
248 int i;
249
250 bn_check_top(a);
251
252 if (a->top == 0) return(0);
253 l=a->d[a->top-1];
254 assert(l != 0);
255 i=(a->top-1)*BN_BITS2;
256 return(i+BN_num_bits_word(l));
257 }
258
259void BN_clear_free(BIGNUM *a)
260 {
261 int i;
262
263 if (a == NULL) return;
264 if (a->d != NULL)
265 {
266 OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0]));
267 if (!(BN_get_flags(a,BN_FLG_STATIC_DATA)))
268 OPENSSL_free(a->d);
269 }
270 i=BN_get_flags(a,BN_FLG_MALLOCED);
271 OPENSSL_cleanse(a,sizeof(BIGNUM));
272 if (i)
273 OPENSSL_free(a);
274 }
275
276void BN_free(BIGNUM *a)
277 {
278 if (a == NULL) return;
279 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
280 OPENSSL_free(a->d);
281 a->flags|=BN_FLG_FREE; /* REMOVE? */
282 if (a->flags & BN_FLG_MALLOCED)
283 OPENSSL_free(a);
284 }
285
286void BN_init(BIGNUM *a)
287 {
288 memset(a,0,sizeof(BIGNUM));
289 }
290
291BIGNUM *BN_new(void)
292 {
293 BIGNUM *ret;
294
295 if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
296 {
297 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
298 return(NULL);
299 }
300 ret->flags=BN_FLG_MALLOCED;
301 ret->top=0;
302 ret->neg=0;
303 ret->dmax=0;
304 ret->d=NULL;
305 return(ret);
306 }
307
308/* This is used both by bn_expand2() and bn_dup_expand() */
309/* The caller MUST check that words > b->dmax before calling this */
310static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
311 {
312 BN_ULONG *A,*a = NULL;
313 const BN_ULONG *B;
314 int i;
315
316 if (words > (INT_MAX/(4*BN_BITS2)))
317 {
318 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_BIGNUM_TOO_LONG);
319 return NULL;
320 }
321
322 bn_check_top(b);
323 if (BN_get_flags(b,BN_FLG_STATIC_DATA))
324 {
325 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
326 return(NULL);
327 }
328 a=A=(BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG)*(words+1));
329 if (A == NULL)
330 {
331 BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
332 return(NULL);
333 }
334#if 1
335 B=b->d;
336 /* Check if the previous number needs to be copied */
337 if (B != NULL)
338 {
339 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
340 {
341 /*
342 * The fact that the loop is unrolled
343 * 4-wise is a tribute to Intel. It's
344 * the one that doesn't have enough
345 * registers to accomodate more data.
346 * I'd unroll it 8-wise otherwise:-)
347 *
348 * <appro@fy.chalmers.se>
349 */
350 BN_ULONG a0,a1,a2,a3;
351 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
352 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
353 }
354 switch (b->top&3)
355 {
356 case 3: A[2]=B[2];
357 case 2: A[1]=B[1];
358 case 1: A[0]=B[0];
359 case 0: /* workaround for ultrix cc: without 'case 0', the optimizer does
360 * the switch table by doing a=top&3; a--; goto jump_table[a];
361 * which fails for top== 0 */
362 ;
363 }
364 }
365
366 /* Now need to zero any data between b->top and b->max */
367 /* XXX Why? */
368
369 A= &(a[b->top]);
370 for (i=(words - b->top)>>3; i>0; i--,A+=8)
371 {
372 A[0]=0; A[1]=0; A[2]=0; A[3]=0;
373 A[4]=0; A[5]=0; A[6]=0; A[7]=0;
374 }
375 for (i=(words - b->top)&7; i>0; i--,A++)
376 A[0]=0;
377#else
378 memset(A,0,sizeof(BN_ULONG)*(words+1));
379 memcpy(A,b->d,sizeof(b->d[0])*b->top);
380#endif
381
382 return(a);
383 }
384
385/* This is an internal function that can be used instead of bn_expand2()
386 * when there is a need to copy BIGNUMs instead of only expanding the
387 * data part, while still expanding them.
388 * Especially useful when needing to expand BIGNUMs that are declared
389 * 'const' and should therefore not be changed.
390 * The reason to use this instead of a BN_dup() followed by a bn_expand2()
391 * is memory allocation overhead. A BN_dup() followed by a bn_expand2()
392 * will allocate new memory for the BIGNUM data twice, and free it once,
393 * while bn_dup_expand() makes sure allocation is made only once.
394 */
395
396BIGNUM *bn_dup_expand(const BIGNUM *b, int words)
397 {
398 BIGNUM *r = NULL;
399
400 /* This function does not work if
401 * words <= b->dmax && top < words
402 * because BN_dup() does not preserve 'dmax'!
403 * (But bn_dup_expand() is not used anywhere yet.)
404 */
405
406 if (words > b->dmax)
407 {
408 BN_ULONG *a = bn_expand_internal(b, words);
409
410 if (a)
411 {
412 r = BN_new();
413 if (r)
414 {
415 r->top = b->top;
416 r->dmax = words;
417 r->neg = b->neg;
418 r->d = a;
419 }
420 else
421 {
422 /* r == NULL, BN_new failure */
423 OPENSSL_free(a);
424 }
425 }
426 /* If a == NULL, there was an error in allocation in
427 bn_expand_internal(), and NULL should be returned */
428 }
429 else
430 {
431 r = BN_dup(b);
432 }
433
434 return r;
435 }
436
437/* This is an internal function that should not be used in applications.
438 * It ensures that 'b' has enough room for a 'words' word number number.
439 * It is mostly used by the various BIGNUM routines. If there is an error,
440 * NULL is returned. If not, 'b' is returned. */
441
442BIGNUM *bn_expand2(BIGNUM *b, int words)
443 {
444 if (words > b->dmax)
445 {
446 BN_ULONG *a = bn_expand_internal(b, words);
447
448 if (a)
449 {
450 if (b->d)
451 OPENSSL_free(b->d);
452 b->d=a;
453 b->dmax=words;
454 }
455 else
456 b = NULL;
457 }
458 return b;
459 }
460
461BIGNUM *BN_dup(const BIGNUM *a)
462 {
463 BIGNUM *r, *t;
464
465 if (a == NULL) return NULL;
466
467 bn_check_top(a);
468
469 t = BN_new();
470 if (t == NULL) return(NULL);
471 r = BN_copy(t, a);
472 /* now r == t || r == NULL */
473 if (r == NULL)
474 BN_free(t);
475 return r;
476 }
477
478BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
479 {
480 int i;
481 BN_ULONG *A;
482 const BN_ULONG *B;
483
484 bn_check_top(b);
485
486 if (a == b) return(a);
487 if (bn_wexpand(a,b->top) == NULL) return(NULL);
488
489#if 1
490 A=a->d;
491 B=b->d;
492 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
493 {
494 BN_ULONG a0,a1,a2,a3;
495 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
496 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
497 }
498 switch (b->top&3)
499 {
500 case 3: A[2]=B[2];
501 case 2: A[1]=B[1];
502 case 1: A[0]=B[0];
503 case 0: ; /* ultrix cc workaround, see comments in bn_expand_internal */
504 }
505#else
506 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
507#endif
508
509/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
510 a->top=b->top;
511 if ((a->top == 0) && (a->d != NULL))
512 a->d[0]=0;
513 a->neg=b->neg;
514 return(a);
515 }
516
517void BN_swap(BIGNUM *a, BIGNUM *b)
518 {
519 int flags_old_a, flags_old_b;
520 BN_ULONG *tmp_d;
521 int tmp_top, tmp_dmax, tmp_neg;
522
523 flags_old_a = a->flags;
524 flags_old_b = b->flags;
525
526 tmp_d = a->d;
527 tmp_top = a->top;
528 tmp_dmax = a->dmax;
529 tmp_neg = a->neg;
530
531 a->d = b->d;
532 a->top = b->top;
533 a->dmax = b->dmax;
534 a->neg = b->neg;
535
536 b->d = tmp_d;
537 b->top = tmp_top;
538 b->dmax = tmp_dmax;
539 b->neg = tmp_neg;
540
541 a->flags = (flags_old_a & BN_FLG_MALLOCED) | (flags_old_b & BN_FLG_STATIC_DATA);
542 b->flags = (flags_old_b & BN_FLG_MALLOCED) | (flags_old_a & BN_FLG_STATIC_DATA);
543 }
544
545
546void BN_clear(BIGNUM *a)
547 {
548 if (a->d != NULL)
549 memset(a->d,0,a->dmax*sizeof(a->d[0]));
550 a->top=0;
551 a->neg=0;
552 }
553
554BN_ULONG BN_get_word(const BIGNUM *a)
555 {
556 int i,n;
557 BN_ULONG ret=0;
558
559 n=BN_num_bytes(a);
560 if (n > sizeof(BN_ULONG))
561 return(BN_MASK2);
562 for (i=a->top-1; i>=0; i--)
563 {
564#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
565 ret<<=BN_BITS4; /* stops the compiler complaining */
566 ret<<=BN_BITS4;
567#else
568 ret=0;
569#endif
570 ret|=a->d[i];
571 }
572 return(ret);
573 }
574
575int BN_set_word(BIGNUM *a, BN_ULONG w)
576 {
577 int i,n;
578 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
579
580 n=sizeof(BN_ULONG)/BN_BYTES;
581 a->neg=0;
582 a->top=0;
583 a->d[0]=(BN_ULONG)w&BN_MASK2;
584 if (a->d[0] != 0) a->top=1;
585 for (i=1; i<n; i++)
586 {
587 /* the following is done instead of
588 * w>>=BN_BITS2 so compilers don't complain
589 * on builds where sizeof(long) == BN_TYPES */
590#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
591 w>>=BN_BITS4;
592 w>>=BN_BITS4;
593#else
594 w=0;
595#endif
596 a->d[i]=(BN_ULONG)w&BN_MASK2;
597 if (a->d[i] != 0) a->top=i+1;
598 }
599 return(1);
600 }
601
602BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
603 {
604 unsigned int i,m;
605 unsigned int n;
606 BN_ULONG l;
607
608 if (ret == NULL) ret=BN_new();
609 if (ret == NULL) return(NULL);
610 l=0;
611 n=len;
612 if (n == 0)
613 {
614 ret->top=0;
615 return(ret);
616 }
617 if (bn_expand(ret,(int)(n+2)*8) == NULL)
618 return(NULL);
619 i=((n-1)/BN_BYTES)+1;
620 m=((n-1)%(BN_BYTES));
621 ret->top=i;
622 ret->neg=0;
623 while (n-- > 0)
624 {
625 l=(l<<8L)| *(s++);
626 if (m-- == 0)
627 {
628 ret->d[--i]=l;
629 l=0;
630 m=BN_BYTES-1;
631 }
632 }
633 /* need to call this due to clear byte at top if avoiding
634 * having the top bit set (-ve number) */
635 bn_fix_top(ret);
636 return(ret);
637 }
638
639/* ignore negative */
640int BN_bn2bin(const BIGNUM *a, unsigned char *to)
641 {
642 int n,i;
643 BN_ULONG l;
644
645 n=i=BN_num_bytes(a);
646 while (i-- > 0)
647 {
648 l=a->d[i/BN_BYTES];
649 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
650 }
651 return(n);
652 }
653
654int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
655 {
656 int i;
657 BN_ULONG t1,t2,*ap,*bp;
658
659 bn_check_top(a);
660 bn_check_top(b);
661
662 i=a->top-b->top;
663 if (i != 0) return(i);
664 ap=a->d;
665 bp=b->d;
666 for (i=a->top-1; i>=0; i--)
667 {
668 t1= ap[i];
669 t2= bp[i];
670 if (t1 != t2)
671 return(t1 > t2?1:-1);
672 }
673 return(0);
674 }
675
676int BN_cmp(const BIGNUM *a, const BIGNUM *b)
677 {
678 int i;
679 int gt,lt;
680 BN_ULONG t1,t2;
681
682 if ((a == NULL) || (b == NULL))
683 {
684 if (a != NULL)
685 return(-1);
686 else if (b != NULL)
687 return(1);
688 else
689 return(0);
690 }
691
692 bn_check_top(a);
693 bn_check_top(b);
694
695 if (a->neg != b->neg)
696 {
697 if (a->neg)
698 return(-1);
699 else return(1);
700 }
701 if (a->neg == 0)
702 { gt=1; lt= -1; }
703 else { gt= -1; lt=1; }
704
705 if (a->top > b->top) return(gt);
706 if (a->top < b->top) return(lt);
707 for (i=a->top-1; i>=0; i--)
708 {
709 t1=a->d[i];
710 t2=b->d[i];
711 if (t1 > t2) return(gt);
712 if (t1 < t2) return(lt);
713 }
714 return(0);
715 }
716
717int BN_set_bit(BIGNUM *a, int n)
718 {
719 int i,j,k;
720
721 i=n/BN_BITS2;
722 j=n%BN_BITS2;
723 if (a->top <= i)
724 {
725 if (bn_wexpand(a,i+1) == NULL) return(0);
726 for(k=a->top; k<i+1; k++)
727 a->d[k]=0;
728 a->top=i+1;
729 }
730
731 a->d[i]|=(((BN_ULONG)1)<<j);
732 return(1);
733 }
734
735int BN_clear_bit(BIGNUM *a, int n)
736 {
737 int i,j;
738
739 i=n/BN_BITS2;
740 j=n%BN_BITS2;
741 if (a->top <= i) return(0);
742
743 a->d[i]&=(~(((BN_ULONG)1)<<j));
744 bn_fix_top(a);
745 return(1);
746 }
747
748int BN_is_bit_set(const BIGNUM *a, int n)
749 {
750 int i,j;
751
752 if (n < 0) return(0);
753 i=n/BN_BITS2;
754 j=n%BN_BITS2;
755 if (a->top <= i) return(0);
756 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
757 }
758
759int BN_mask_bits(BIGNUM *a, int n)
760 {
761 int b,w;
762
763 w=n/BN_BITS2;
764 b=n%BN_BITS2;
765 if (w >= a->top) return(0);
766 if (b == 0)
767 a->top=w;
768 else
769 {
770 a->top=w+1;
771 a->d[w]&= ~(BN_MASK2<<b);
772 }
773 bn_fix_top(a);
774 return(1);
775 }
776
777int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
778 {
779 int i;
780 BN_ULONG aa,bb;
781
782 aa=a[n-1];
783 bb=b[n-1];
784 if (aa != bb) return((aa > bb)?1:-1);
785 for (i=n-2; i>=0; i--)
786 {
787 aa=a[i];
788 bb=b[i];
789 if (aa != bb) return((aa > bb)?1:-1);
790 }
791 return(0);
792 }
793
794/* Here follows a specialised variants of bn_cmp_words(). It has the
795 property of performing the operation on arrays of different sizes.
796 The sizes of those arrays is expressed through cl, which is the
797 common length ( basicall, min(len(a),len(b)) ), and dl, which is the
798 delta between the two lengths, calculated as len(a)-len(b).
799 All lengths are the number of BN_ULONGs... */
800
801int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
802 int cl, int dl)
803 {
804 int n,i;
805 n = cl-1;
806
807 if (dl < 0)
808 {
809 for (i=dl; i<0; i++)
810 {
811 if (b[n-i] != 0)
812 return -1; /* a < b */
813 }
814 }
815 if (dl > 0)
816 {
817 for (i=dl; i>0; i--)
818 {
819 if (a[n+i] != 0)
820 return 1; /* a > b */
821 }
822 }
823 return bn_cmp_words(a,b,cl);
824 }
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c
new file mode 100644
index 0000000000..5cf82480d7
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_mod.c
@@ -0,0 +1,296 @@
1/* crypto/bn/bn_mod.c */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
58 * All rights reserved.
59 *
60 * This package is an SSL implementation written
61 * by Eric Young (eay@cryptsoft.com).
62 * The implementation was written so as to conform with Netscapes SSL.
63 *
64 * This library is free for commercial and non-commercial use as long as
65 * the following conditions are aheared to. The following conditions
66 * apply to all code found in this distribution, be it the RC4, RSA,
67 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
68 * included with this distribution is covered by the same copyright terms
69 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
70 *
71 * Copyright remains Eric Young's, and as such any Copyright notices in
72 * the code are not to be removed.
73 * If this package is used in a product, Eric Young should be given attribution
74 * as the author of the parts of the library used.
75 * This can be in the form of a textual message at program startup or
76 * in documentation (online or textual) provided with the package.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * "This product includes cryptographic software written by
89 * Eric Young (eay@cryptsoft.com)"
90 * The word 'cryptographic' can be left out if the rouines from the library
91 * being used are not cryptographic related :-).
92 * 4. If you include any Windows specific code (or a derivative thereof) from
93 * the apps directory (application code) you must include an acknowledgement:
94 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
95 *
96 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
97 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
100 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
101 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
102 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
103 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
104 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
105 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
106 * SUCH DAMAGE.
107 *
108 * The licence and distribution terms for any publically available version or
109 * derivative of this code cannot be changed. i.e. this code cannot simply be
110 * copied and put under another distribution licence
111 * [including the GNU Public Licence.]
112 */
113
114#include "cryptlib.h"
115#include "bn_lcl.h"
116
117
118#if 0 /* now just a #define */
119int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
120 {
121 return(BN_div(NULL,rem,m,d,ctx));
122 /* note that rem->neg == m->neg (unless the remainder is zero) */
123 }
124#endif
125
126
127int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
128 {
129 /* like BN_mod, but returns non-negative remainder
130 * (i.e., 0 <= r < |d| always holds) */
131
132 if (!(BN_mod(r,m,d,ctx)))
133 return 0;
134 if (!r->neg)
135 return 1;
136 /* now -|d| < r < 0, so we have to set r := r + |d| */
137 return (d->neg ? BN_sub : BN_add)(r, r, d);
138}
139
140
141int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
142 {
143 if (!BN_add(r, a, b)) return 0;
144 return BN_nnmod(r, r, m, ctx);
145 }
146
147
148/* BN_mod_add variant that may be used if both a and b are non-negative
149 * and less than m */
150int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
151 {
152 if (!BN_add(r, a, b)) return 0;
153 if (BN_ucmp(r, m) >= 0)
154 return BN_usub(r, r, m);
155 return 1;
156 }
157
158
159int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
160 {
161 if (!BN_sub(r, a, b)) return 0;
162 return BN_nnmod(r, r, m, ctx);
163 }
164
165
166/* BN_mod_sub variant that may be used if both a and b are non-negative
167 * and less than m */
168int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
169 {
170 if (!BN_sub(r, a, b)) return 0;
171 if (r->neg)
172 return BN_add(r, r, m);
173 return 1;
174 }
175
176
177/* slow but works */
178int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
179 BN_CTX *ctx)
180 {
181 BIGNUM *t;
182 int ret=0;
183
184 bn_check_top(a);
185 bn_check_top(b);
186 bn_check_top(m);
187
188 BN_CTX_start(ctx);
189 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
190 if (a == b)
191 { if (!BN_sqr(t,a,ctx)) goto err; }
192 else
193 { if (!BN_mul(t,a,b,ctx)) goto err; }
194 if (!BN_nnmod(r,t,m,ctx)) goto err;
195 ret=1;
196err:
197 BN_CTX_end(ctx);
198 return(ret);
199 }
200
201
202int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
203 {
204 if (!BN_sqr(r, a, ctx)) return 0;
205 /* r->neg == 0, thus we don't need BN_nnmod */
206 return BN_mod(r, r, m, ctx);
207 }
208
209
210int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
211 {
212 if (!BN_lshift1(r, a)) return 0;
213 return BN_nnmod(r, r, m, ctx);
214 }
215
216
217/* BN_mod_lshift1 variant that may be used if a is non-negative
218 * and less than m */
219int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
220 {
221 if (!BN_lshift1(r, a)) return 0;
222 if (BN_cmp(r, m) >= 0)
223 return BN_sub(r, r, m);
224 return 1;
225 }
226
227
228int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx)
229 {
230 BIGNUM *abs_m = NULL;
231 int ret;
232
233 if (!BN_nnmod(r, a, m, ctx)) return 0;
234
235 if (m->neg)
236 {
237 abs_m = BN_dup(m);
238 if (abs_m == NULL) return 0;
239 abs_m->neg = 0;
240 }
241
242 ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m));
243
244 if (abs_m)
245 BN_free(abs_m);
246 return ret;
247 }
248
249
250/* BN_mod_lshift variant that may be used if a is non-negative
251 * and less than m */
252int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m)
253 {
254 if (r != a)
255 {
256 if (BN_copy(r, a) == NULL) return 0;
257 }
258
259 while (n > 0)
260 {
261 int max_shift;
262
263 /* 0 < r < m */
264 max_shift = BN_num_bits(m) - BN_num_bits(r);
265 /* max_shift >= 0 */
266
267 if (max_shift < 0)
268 {
269 BNerr(BN_F_BN_MOD_LSHIFT_QUICK, BN_R_INPUT_NOT_REDUCED);
270 return 0;
271 }
272
273 if (max_shift > n)
274 max_shift = n;
275
276 if (max_shift)
277 {
278 if (!BN_lshift(r, r, max_shift)) return 0;
279 n -= max_shift;
280 }
281 else
282 {
283 if (!BN_lshift1(r, r)) return 0;
284 --n;
285 }
286
287 /* BN_num_bits(r) <= BN_num_bits(m) */
288
289 if (BN_cmp(r, m) >= 0)
290 {
291 if (!BN_sub(r, r, m)) return 0;
292 }
293 }
294
295 return 1;
296 }
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
new file mode 100644
index 0000000000..b79b1b60da
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -0,0 +1,349 @@
1/* crypto/bn/bn_mont.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 * Details about Montgomery multiplication algorithms can be found at
61 * http://security.ece.orst.edu/publications.html, e.g.
62 * http://security.ece.orst.edu/koc/papers/j37acmon.pdf and
63 * sections 3.8 and 4.2 in http://security.ece.orst.edu/koc/papers/r01rsasw.pdf
64 */
65
66#include <stdio.h>
67#include "cryptlib.h"
68#include "bn_lcl.h"
69
70#define MONT_WORD /* use the faster word-based algorithm */
71
72int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
73 BN_MONT_CTX *mont, BN_CTX *ctx)
74 {
75 BIGNUM *tmp;
76 int ret=0;
77
78 BN_CTX_start(ctx);
79 tmp = BN_CTX_get(ctx);
80 if (tmp == NULL) goto err;
81
82 bn_check_top(tmp);
83 if (a == b)
84 {
85 if (!BN_sqr(tmp,a,ctx)) goto err;
86 }
87 else
88 {
89 if (!BN_mul(tmp,a,b,ctx)) goto err;
90 }
91 /* reduce from aRR to aR */
92 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
93 ret=1;
94err:
95 BN_CTX_end(ctx);
96 return(ret);
97 }
98
99int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
100 BN_CTX *ctx)
101 {
102 int retn=0;
103
104#ifdef MONT_WORD
105 BIGNUM *n,*r;
106 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
107 int al,nl,max,i,x,ri;
108
109 BN_CTX_start(ctx);
110 if ((r = BN_CTX_get(ctx)) == NULL) goto err;
111
112 if (!BN_copy(r,a)) goto err;
113 n= &(mont->N);
114
115 ap=a->d;
116 /* mont->ri is the size of mont->N in bits (rounded up
117 to the word size) */
118 al=ri=mont->ri/BN_BITS2;
119
120 nl=n->top;
121 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
122
123 max=(nl+al+1); /* allow for overflow (no?) XXX */
124 if (bn_wexpand(r,max) == NULL) goto err;
125 if (bn_wexpand(ret,max) == NULL) goto err;
126
127 r->neg=a->neg^n->neg;
128 np=n->d;
129 rp=r->d;
130 nrp= &(r->d[nl]);
131
132 /* clear the top words of T */
133#if 1
134 for (i=r->top; i<max; i++) /* memset? XXX */
135 r->d[i]=0;
136#else
137 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
138#endif
139
140 r->top=max;
141 n0=mont->n0;
142
143#ifdef BN_COUNT
144 fprintf(stderr,"word BN_from_montgomery %d * %d\n",nl,nl);
145#endif
146 for (i=0; i<nl; i++)
147 {
148#ifdef __TANDEM
149 {
150 long long t1;
151 long long t2;
152 long long t3;
153 t1 = rp[0] * (n0 & 0177777);
154 t2 = 037777600000l;
155 t2 = n0 & t2;
156 t3 = rp[0] & 0177777;
157 t2 = (t3 * t2) & BN_MASK2;
158 t1 = t1 + t2;
159 v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);
160 }
161#else
162 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
163#endif
164 nrp++;
165 rp++;
166 if (((nrp[-1]+=v)&BN_MASK2) >= v)
167 continue;
168 else
169 {
170 if (((++nrp[0])&BN_MASK2) != 0) continue;
171 if (((++nrp[1])&BN_MASK2) != 0) continue;
172 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
173 }
174 }
175 bn_fix_top(r);
176
177 /* mont->ri will be a multiple of the word size */
178#if 0
179 BN_rshift(ret,r,mont->ri);
180#else
181 ret->neg = r->neg;
182 x=ri;
183 rp=ret->d;
184 ap= &(r->d[x]);
185 if (r->top < x)
186 al=0;
187 else
188 al=r->top-x;
189 ret->top=al;
190 al-=4;
191 for (i=0; i<al; i+=4)
192 {
193 BN_ULONG t1,t2,t3,t4;
194
195 t1=ap[i+0];
196 t2=ap[i+1];
197 t3=ap[i+2];
198 t4=ap[i+3];
199 rp[i+0]=t1;
200 rp[i+1]=t2;
201 rp[i+2]=t3;
202 rp[i+3]=t4;
203 }
204 al+=4;
205 for (; i<al; i++)
206 rp[i]=ap[i];
207#endif
208#else /* !MONT_WORD */
209 BIGNUM *t1,*t2;
210
211 BN_CTX_start(ctx);
212 t1 = BN_CTX_get(ctx);
213 t2 = BN_CTX_get(ctx);
214 if (t1 == NULL || t2 == NULL) goto err;
215
216 if (!BN_copy(t1,a)) goto err;
217 BN_mask_bits(t1,mont->ri);
218
219 if (!BN_mul(t2,t1,&mont->Ni,ctx)) goto err;
220 BN_mask_bits(t2,mont->ri);
221
222 if (!BN_mul(t1,t2,&mont->N,ctx)) goto err;
223 if (!BN_add(t2,a,t1)) goto err;
224 if (!BN_rshift(ret,t2,mont->ri)) goto err;
225#endif /* MONT_WORD */
226
227 if (BN_ucmp(ret, &(mont->N)) >= 0)
228 {
229 if (!BN_usub(ret,ret,&(mont->N))) goto err;
230 }
231 retn=1;
232 err:
233 BN_CTX_end(ctx);
234 return(retn);
235 }
236
237BN_MONT_CTX *BN_MONT_CTX_new(void)
238 {
239 BN_MONT_CTX *ret;
240
241 if ((ret=(BN_MONT_CTX *)OPENSSL_malloc(sizeof(BN_MONT_CTX))) == NULL)
242 return(NULL);
243
244 BN_MONT_CTX_init(ret);
245 ret->flags=BN_FLG_MALLOCED;
246 return(ret);
247 }
248
249void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
250 {
251 ctx->ri=0;
252 BN_init(&(ctx->RR));
253 BN_init(&(ctx->N));
254 BN_init(&(ctx->Ni));
255 ctx->flags=0;
256 }
257
258void BN_MONT_CTX_free(BN_MONT_CTX *mont)
259 {
260 if(mont == NULL)
261 return;
262
263 BN_free(&(mont->RR));
264 BN_free(&(mont->N));
265 BN_free(&(mont->Ni));
266 if (mont->flags & BN_FLG_MALLOCED)
267 OPENSSL_free(mont);
268 }
269
270int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
271 {
272 BIGNUM Ri,*R;
273
274 BN_init(&Ri);
275 R= &(mont->RR); /* grab RR as a temp */
276 if (!BN_copy(&(mont->N),mod)) goto err; /* Set N */
277 mont->N.neg = 0;
278
279#ifdef MONT_WORD
280 {
281 BIGNUM tmod;
282 BN_ULONG buf[2];
283
284 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
285 if (!(BN_zero(R))) goto err;
286 if (!(BN_set_bit(R,BN_BITS2))) goto err; /* R */
287
288 buf[0]=mod->d[0]; /* tmod = N mod word size */
289 buf[1]=0;
290 tmod.d=buf;
291 tmod.top=1;
292 tmod.dmax=2;
293 tmod.neg=0;
294 /* Ri = R^-1 mod N*/
295 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
296 goto err;
297 if (!BN_lshift(&Ri,&Ri,BN_BITS2)) goto err; /* R*Ri */
298 if (!BN_is_zero(&Ri))
299 {
300 if (!BN_sub_word(&Ri,1)) goto err;
301 }
302 else /* if N mod word size == 1 */
303 {
304 if (!BN_set_word(&Ri,BN_MASK2)) goto err; /* Ri-- (mod word size) */
305 }
306 if (!BN_div(&Ri,NULL,&Ri,&tmod,ctx)) goto err;
307 /* Ni = (R*Ri-1)/N,
308 * keep only least significant word: */
309 mont->n0 = (Ri.top > 0) ? Ri.d[0] : 0;
310 BN_free(&Ri);
311 }
312#else /* !MONT_WORD */
313 { /* bignum version */
314 mont->ri=BN_num_bits(&mont->N);
315 if (!BN_zero(R)) goto err;
316 if (!BN_set_bit(R,mont->ri)) goto err; /* R = 2^ri */
317 /* Ri = R^-1 mod N*/
318 if ((BN_mod_inverse(&Ri,R,&mont->N,ctx)) == NULL)
319 goto err;
320 if (!BN_lshift(&Ri,&Ri,mont->ri)) goto err; /* R*Ri */
321 if (!BN_sub_word(&Ri,1)) goto err;
322 /* Ni = (R*Ri-1) / N */
323 if (!BN_div(&(mont->Ni),NULL,&Ri,&mont->N,ctx)) goto err;
324 BN_free(&Ri);
325 }
326#endif
327
328 /* setup RR for conversions */
329 if (!BN_zero(&(mont->RR))) goto err;
330 if (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;
331 if (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;
332
333 return(1);
334err:
335 return(0);
336 }
337
338BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
339 {
340 if (to == from) return(to);
341
342 if (!BN_copy(&(to->RR),&(from->RR))) return NULL;
343 if (!BN_copy(&(to->N),&(from->N))) return NULL;
344 if (!BN_copy(&(to->Ni),&(from->Ni))) return NULL;
345 to->ri=from->ri;
346 to->n0=from->n0;
347 return(to);
348 }
349
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
new file mode 100644
index 0000000000..05fa9d1e9a
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_mpi.c
@@ -0,0 +1,129 @@
1/* crypto/bn/bn_mpi.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63int BN_bn2mpi(const BIGNUM *a, unsigned char *d)
64 {
65 int bits;
66 int num=0;
67 int ext=0;
68 long l;
69
70 bits=BN_num_bits(a);
71 num=(bits+7)/8;
72 if (bits > 0)
73 {
74 ext=((bits & 0x07) == 0);
75 }
76 if (d == NULL)
77 return(num+4+ext);
78
79 l=num+ext;
80 d[0]=(unsigned char)(l>>24)&0xff;
81 d[1]=(unsigned char)(l>>16)&0xff;
82 d[2]=(unsigned char)(l>> 8)&0xff;
83 d[3]=(unsigned char)(l )&0xff;
84 if (ext) d[4]=0;
85 num=BN_bn2bin(a,&(d[4+ext]));
86 if (a->neg)
87 d[4]|=0x80;
88 return(num+4+ext);
89 }
90
91BIGNUM *BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a)
92 {
93 long len;
94 int neg=0;
95
96 if (n < 4)
97 {
98 BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH);
99 return(NULL);
100 }
101 len=((long)d[0]<<24)|((long)d[1]<<16)|((int)d[2]<<8)|(int)d[3];
102 if ((len+4) != n)
103 {
104 BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR);
105 return(NULL);
106 }
107
108 if (a == NULL) a=BN_new();
109 if (a == NULL) return(NULL);
110
111 if (len == 0)
112 {
113 a->neg=0;
114 a->top=0;
115 return(a);
116 }
117 d+=4;
118 if ((*d) & 0x80)
119 neg=1;
120 if (BN_bin2bn(d,(int)len,a) == NULL)
121 return(NULL);
122 a->neg=neg;
123 if (neg)
124 {
125 BN_clear_bit(a,BN_num_bits(a)-1);
126 }
127 return(a);
128 }
129
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c
new file mode 100644
index 0000000000..3ae3822bc2
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_mul.c
@@ -0,0 +1,802 @@
1/* crypto/bn/bn_mul.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63#ifdef BN_RECURSION
64/* Karatsuba recursive multiplication algorithm
65 * (cf. Knuth, The Art of Computer Programming, Vol. 2) */
66
67/* r is 2*n2 words in size,
68 * a and b are both n2 words in size.
69 * n2 must be a power of 2.
70 * We multiply and return the result.
71 * t must be 2*n2 words in size
72 * We calculate
73 * a[0]*b[0]
74 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
75 * a[1]*b[1]
76 */
77void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
78 BN_ULONG *t)
79 {
80 int n=n2/2,c1,c2;
81 unsigned int neg,zero;
82 BN_ULONG ln,lo,*p;
83
84# ifdef BN_COUNT
85 printf(" bn_mul_recursive %d * %d\n",n2,n2);
86# endif
87# ifdef BN_MUL_COMBA
88# if 0
89 if (n2 == 4)
90 {
91 bn_mul_comba4(r,a,b);
92 return;
93 }
94# endif
95 if (n2 == 8)
96 {
97 bn_mul_comba8(r,a,b);
98 return;
99 }
100# endif /* BN_MUL_COMBA */
101 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
102 {
103 /* This should not happen */
104 bn_mul_normal(r,a,n2,b,n2);
105 return;
106 }
107 /* r=(a[0]-a[1])*(b[1]-b[0]) */
108 c1=bn_cmp_words(a,&(a[n]),n);
109 c2=bn_cmp_words(&(b[n]),b,n);
110 zero=neg=0;
111 switch (c1*3+c2)
112 {
113 case -4:
114 bn_sub_words(t, &(a[n]),a, n); /* - */
115 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
116 break;
117 case -3:
118 zero=1;
119 break;
120 case -2:
121 bn_sub_words(t, &(a[n]),a, n); /* - */
122 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
123 neg=1;
124 break;
125 case -1:
126 case 0:
127 case 1:
128 zero=1;
129 break;
130 case 2:
131 bn_sub_words(t, a, &(a[n]),n); /* + */
132 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
133 neg=1;
134 break;
135 case 3:
136 zero=1;
137 break;
138 case 4:
139 bn_sub_words(t, a, &(a[n]),n);
140 bn_sub_words(&(t[n]),&(b[n]),b, n);
141 break;
142 }
143
144# ifdef BN_MUL_COMBA
145 if (n == 4)
146 {
147 if (!zero)
148 bn_mul_comba4(&(t[n2]),t,&(t[n]));
149 else
150 memset(&(t[n2]),0,8*sizeof(BN_ULONG));
151
152 bn_mul_comba4(r,a,b);
153 bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));
154 }
155 else if (n == 8)
156 {
157 if (!zero)
158 bn_mul_comba8(&(t[n2]),t,&(t[n]));
159 else
160 memset(&(t[n2]),0,16*sizeof(BN_ULONG));
161
162 bn_mul_comba8(r,a,b);
163 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));
164 }
165 else
166# endif /* BN_MUL_COMBA */
167 {
168 p= &(t[n2*2]);
169 if (!zero)
170 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
171 else
172 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
173 bn_mul_recursive(r,a,b,n,p);
174 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);
175 }
176
177 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
178 * r[10] holds (a[0]*b[0])
179 * r[32] holds (b[1]*b[1])
180 */
181
182 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
183
184 if (neg) /* if t[32] is negative */
185 {
186 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
187 }
188 else
189 {
190 /* Might have a carry */
191 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
192 }
193
194 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
195 * r[10] holds (a[0]*b[0])
196 * r[32] holds (b[1]*b[1])
197 * c1 holds the carry bits
198 */
199 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
200 if (c1)
201 {
202 p= &(r[n+n2]);
203 lo= *p;
204 ln=(lo+c1)&BN_MASK2;
205 *p=ln;
206
207 /* The overflow will stop before we over write
208 * words we should not overwrite */
209 if (ln < (BN_ULONG)c1)
210 {
211 do {
212 p++;
213 lo= *p;
214 ln=(lo+1)&BN_MASK2;
215 *p=ln;
216 } while (ln == 0);
217 }
218 }
219 }
220
221/* n+tn is the word length
222 * t needs to be n*4 is size, as does r */
223void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
224 int n, BN_ULONG *t)
225 {
226 int i,j,n2=n*2;
227 int c1,c2,neg,zero;
228 BN_ULONG ln,lo,*p;
229
230# ifdef BN_COUNT
231 printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
232# endif
233 if (n < 8)
234 {
235 i=tn+n;
236 bn_mul_normal(r,a,i,b,i);
237 return;
238 }
239
240 /* r=(a[0]-a[1])*(b[1]-b[0]) */
241 c1=bn_cmp_words(a,&(a[n]),n);
242 c2=bn_cmp_words(&(b[n]),b,n);
243 zero=neg=0;
244 switch (c1*3+c2)
245 {
246 case -4:
247 bn_sub_words(t, &(a[n]),a, n); /* - */
248 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
249 break;
250 case -3:
251 zero=1;
252 /* break; */
253 case -2:
254 bn_sub_words(t, &(a[n]),a, n); /* - */
255 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
256 neg=1;
257 break;
258 case -1:
259 case 0:
260 case 1:
261 zero=1;
262 /* break; */
263 case 2:
264 bn_sub_words(t, a, &(a[n]),n); /* + */
265 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
266 neg=1;
267 break;
268 case 3:
269 zero=1;
270 /* break; */
271 case 4:
272 bn_sub_words(t, a, &(a[n]),n);
273 bn_sub_words(&(t[n]),&(b[n]),b, n);
274 break;
275 }
276 /* The zero case isn't yet implemented here. The speedup
277 would probably be negligible. */
278# if 0
279 if (n == 4)
280 {
281 bn_mul_comba4(&(t[n2]),t,&(t[n]));
282 bn_mul_comba4(r,a,b);
283 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
284 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
285 }
286 else
287# endif
288 if (n == 8)
289 {
290 bn_mul_comba8(&(t[n2]),t,&(t[n]));
291 bn_mul_comba8(r,a,b);
292 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
293 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
294 }
295 else
296 {
297 p= &(t[n2*2]);
298 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
299 bn_mul_recursive(r,a,b,n,p);
300 i=n/2;
301 /* If there is only a bottom half to the number,
302 * just do it */
303 j=tn-i;
304 if (j == 0)
305 {
306 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);
307 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));
308 }
309 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */
310 {
311 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),
312 j,i,p);
313 memset(&(r[n2+tn*2]),0,
314 sizeof(BN_ULONG)*(n2-tn*2));
315 }
316 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
317 {
318 memset(&(r[n2]),0,sizeof(BN_ULONG)*n2);
319 if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)
320 {
321 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
322 }
323 else
324 {
325 for (;;)
326 {
327 i/=2;
328 if (i < tn)
329 {
330 bn_mul_part_recursive(&(r[n2]),
331 &(a[n]),&(b[n]),
332 tn-i,i,p);
333 break;
334 }
335 else if (i == tn)
336 {
337 bn_mul_recursive(&(r[n2]),
338 &(a[n]),&(b[n]),
339 i,p);
340 break;
341 }
342 }
343 }
344 }
345 }
346
347 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
348 * r[10] holds (a[0]*b[0])
349 * r[32] holds (b[1]*b[1])
350 */
351
352 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
353
354 if (neg) /* if t[32] is negative */
355 {
356 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
357 }
358 else
359 {
360 /* Might have a carry */
361 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
362 }
363
364 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
365 * r[10] holds (a[0]*b[0])
366 * r[32] holds (b[1]*b[1])
367 * c1 holds the carry bits
368 */
369 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
370 if (c1)
371 {
372 p= &(r[n+n2]);
373 lo= *p;
374 ln=(lo+c1)&BN_MASK2;
375 *p=ln;
376
377 /* The overflow will stop before we over write
378 * words we should not overwrite */
379 if (ln < (BN_ULONG)c1)
380 {
381 do {
382 p++;
383 lo= *p;
384 ln=(lo+1)&BN_MASK2;
385 *p=ln;
386 } while (ln == 0);
387 }
388 }
389 }
390
391/* a and b must be the same size, which is n2.
392 * r needs to be n2 words and t needs to be n2*2
393 */
394void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
395 BN_ULONG *t)
396 {
397 int n=n2/2;
398
399# ifdef BN_COUNT
400 printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
401# endif
402
403 bn_mul_recursive(r,a,b,n,&(t[0]));
404 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
405 {
406 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2]));
407 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
408 bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2]));
409 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
410 }
411 else
412 {
413 bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n);
414 bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n);
415 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
416 bn_add_words(&(r[n]),&(r[n]),&(t[n]),n);
417 }
418 }
419
420/* a and b must be the same size, which is n2.
421 * r needs to be n2 words and t needs to be n2*2
422 * l is the low words of the output.
423 * t needs to be n2*3
424 */
425void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
426 BN_ULONG *t)
427 {
428 int i,n;
429 int c1,c2;
430 int neg,oneg,zero;
431 BN_ULONG ll,lc,*lp,*mp;
432
433# ifdef BN_COUNT
434 printf(" bn_mul_high %d * %d\n",n2,n2);
435# endif
436 n=n2/2;
437
438 /* Calculate (al-ah)*(bh-bl) */
439 neg=zero=0;
440 c1=bn_cmp_words(&(a[0]),&(a[n]),n);
441 c2=bn_cmp_words(&(b[n]),&(b[0]),n);
442 switch (c1*3+c2)
443 {
444 case -4:
445 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
446 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
447 break;
448 case -3:
449 zero=1;
450 break;
451 case -2:
452 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
453 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
454 neg=1;
455 break;
456 case -1:
457 case 0:
458 case 1:
459 zero=1;
460 break;
461 case 2:
462 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
463 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
464 neg=1;
465 break;
466 case 3:
467 zero=1;
468 break;
469 case 4:
470 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
471 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
472 break;
473 }
474
475 oneg=neg;
476 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */
477 /* r[10] = (a[1]*b[1]) */
478# ifdef BN_MUL_COMBA
479 if (n == 8)
480 {
481 bn_mul_comba8(&(t[0]),&(r[0]),&(r[n]));
482 bn_mul_comba8(r,&(a[n]),&(b[n]));
483 }
484 else
485# endif
486 {
487 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
488 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
489 }
490
491 /* s0 == low(al*bl)
492 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
493 * We know s0 and s1 so the only unknown is high(al*bl)
494 * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl))
495 * high(al*bl) == s1 - (r[0]+l[0]+t[0])
496 */
497 if (l != NULL)
498 {
499 lp= &(t[n2+n]);
500 c1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n));
501 }
502 else
503 {
504 c1=0;
505 lp= &(r[0]);
506 }
507
508 if (neg)
509 neg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n));
510 else
511 {
512 bn_add_words(&(t[n2]),lp,&(t[0]),n);
513 neg=0;
514 }
515
516 if (l != NULL)
517 {
518 bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n);
519 }
520 else
521 {
522 lp= &(t[n2+n]);
523 mp= &(t[n2]);
524 for (i=0; i<n; i++)
525 lp[i]=((~mp[i])+1)&BN_MASK2;
526 }
527
528 /* s[0] = low(al*bl)
529 * t[3] = high(al*bl)
530 * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign
531 * r[10] = (a[1]*b[1])
532 */
533 /* R[10] = al*bl
534 * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0])
535 * R[32] = ah*bh
536 */
537 /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow)
538 * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow)
539 * R[3]=r[1]+(carry/borrow)
540 */
541 if (l != NULL)
542 {
543 lp= &(t[n2]);
544 c1= (int)(bn_add_words(lp,&(t[n2+n]),&(l[0]),n));
545 }
546 else
547 {
548 lp= &(t[n2+n]);
549 c1=0;
550 }
551 c1+=(int)(bn_add_words(&(t[n2]),lp, &(r[0]),n));
552 if (oneg)
553 c1-=(int)(bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n));
554 else
555 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n));
556
557 c2 =(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n));
558 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(r[n]),n));
559 if (oneg)
560 c2-=(int)(bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n));
561 else
562 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n]),n));
563
564 if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */
565 {
566 i=0;
567 if (c1 > 0)
568 {
569 lc=c1;
570 do {
571 ll=(r[i]+lc)&BN_MASK2;
572 r[i++]=ll;
573 lc=(lc > ll);
574 } while (lc);
575 }
576 else
577 {
578 lc= -c1;
579 do {
580 ll=r[i];
581 r[i++]=(ll-lc)&BN_MASK2;
582 lc=(lc > ll);
583 } while (lc);
584 }
585 }
586 if (c2 != 0) /* Add starting at r[1] */
587 {
588 i=n;
589 if (c2 > 0)
590 {
591 lc=c2;
592 do {
593 ll=(r[i]+lc)&BN_MASK2;
594 r[i++]=ll;
595 lc=(lc > ll);
596 } while (lc);
597 }
598 else
599 {
600 lc= -c2;
601 do {
602 ll=r[i];
603 r[i++]=(ll-lc)&BN_MASK2;
604 lc=(lc > ll);
605 } while (lc);
606 }
607 }
608 }
609#endif /* BN_RECURSION */
610
611int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
612 {
613 int top,al,bl;
614 BIGNUM *rr;
615 int ret = 0;
616#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
617 int i;
618#endif
619#ifdef BN_RECURSION
620 BIGNUM *t;
621 int j,k;
622#endif
623
624#ifdef BN_COUNT
625 printf("BN_mul %d * %d\n",a->top,b->top);
626#endif
627
628 bn_check_top(a);
629 bn_check_top(b);
630 bn_check_top(r);
631
632 al=a->top;
633 bl=b->top;
634
635 if ((al == 0) || (bl == 0))
636 {
637 if (!BN_zero(r)) goto err;
638 return(1);
639 }
640 top=al+bl;
641
642 BN_CTX_start(ctx);
643 if ((r == a) || (r == b))
644 {
645 if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
646 }
647 else
648 rr = r;
649 rr->neg=a->neg^b->neg;
650
651#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
652 i = al-bl;
653#endif
654#ifdef BN_MUL_COMBA
655 if (i == 0)
656 {
657# if 0
658 if (al == 4)
659 {
660 if (bn_wexpand(rr,8) == NULL) goto err;
661 rr->top=8;
662 bn_mul_comba4(rr->d,a->d,b->d);
663 goto end;
664 }
665# endif
666 if (al == 8)
667 {
668 if (bn_wexpand(rr,16) == NULL) goto err;
669 rr->top=16;
670 bn_mul_comba8(rr->d,a->d,b->d);
671 goto end;
672 }
673 }
674#endif /* BN_MUL_COMBA */
675#ifdef BN_RECURSION
676 if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))
677 {
678 if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA) && bl<b->dmax)
679 {
680#if 0 /* tribute to const-ification, bl<b->dmax above covers for this */
681 if (bn_wexpand(b,al) == NULL) goto err;
682#endif
683 b->d[bl]=0;
684 bl++;
685 i--;
686 }
687 else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA) && al<a->dmax)
688 {
689#if 0 /* tribute to const-ification, al<a->dmax above covers for this */
690 if (bn_wexpand(a,bl) == NULL) goto err;
691#endif
692 a->d[al]=0;
693 al++;
694 i++;
695 }
696 if (i == 0)
697 {
698 /* symmetric and > 4 */
699 /* 16 or larger */
700 j=BN_num_bits_word((BN_ULONG)al);
701 j=1<<(j-1);
702 k=j+j;
703 t = BN_CTX_get(ctx);
704 if (al == j) /* exact multiple */
705 {
706 if (bn_wexpand(t,k*2) == NULL) goto err;
707 if (bn_wexpand(rr,k*2) == NULL) goto err;
708 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
709 rr->top=top;
710 goto end;
711 }
712#if 0 /* tribute to const-ification, rsa/dsa performance is not affected */
713 else
714 {
715 if (bn_wexpand(a,k) == NULL ) goto err;
716 if (bn_wexpand(b,k) == NULL ) goto err;
717 if (bn_wexpand(t,k*4) == NULL ) goto err;
718 if (bn_wexpand(rr,k*4) == NULL ) goto err;
719 for (i=a->top; i<k; i++)
720 a->d[i]=0;
721 for (i=b->top; i<k; i++)
722 b->d[i]=0;
723 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
724 }
725 rr->top=top;
726 goto end;
727#endif
728 }
729 }
730#endif /* BN_RECURSION */
731 if (bn_wexpand(rr,top) == NULL) goto err;
732 rr->top=top;
733 bn_mul_normal(rr->d,a->d,al,b->d,bl);
734
735#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
736end:
737#endif
738 bn_fix_top(rr);
739 if (r != rr) BN_copy(r,rr);
740 ret=1;
741err:
742 BN_CTX_end(ctx);
743 return(ret);
744 }
745
746void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
747 {
748 BN_ULONG *rr;
749
750#ifdef BN_COUNT
751 printf(" bn_mul_normal %d * %d\n",na,nb);
752#endif
753
754 if (na < nb)
755 {
756 int itmp;
757 BN_ULONG *ltmp;
758
759 itmp=na; na=nb; nb=itmp;
760 ltmp=a; a=b; b=ltmp;
761
762 }
763 rr= &(r[na]);
764 rr[0]=bn_mul_words(r,a,na,b[0]);
765
766 for (;;)
767 {
768 if (--nb <= 0) return;
769 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
770 if (--nb <= 0) return;
771 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
772 if (--nb <= 0) return;
773 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
774 if (--nb <= 0) return;
775 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
776 rr+=4;
777 r+=4;
778 b+=4;
779 }
780 }
781
782void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
783 {
784#ifdef BN_COUNT
785 printf(" bn_mul_low_normal %d * %d\n",n,n);
786#endif
787 bn_mul_words(r,a,n,b[0]);
788
789 for (;;)
790 {
791 if (--n <= 0) return;
792 bn_mul_add_words(&(r[1]),a,n,b[1]);
793 if (--n <= 0) return;
794 bn_mul_add_words(&(r[2]),a,n,b[2]);
795 if (--n <= 0) return;
796 bn_mul_add_words(&(r[3]),a,n,b[3]);
797 if (--n <= 0) return;
798 bn_mul_add_words(&(r[4]),a,n,b[4]);
799 r+=4;
800 b+=4;
801 }
802 }
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
new file mode 100644
index 0000000000..f422172f16
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_prime.c
@@ -0,0 +1,468 @@
1/* crypto/bn/bn_prime.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <time.h>
114#include "cryptlib.h"
115#include "bn_lcl.h"
116#include <openssl/rand.h>
117
118/* The quick sieve algorithm approach to weeding out primes is
119 * Philip Zimmermann's, as implemented in PGP. I have had a read of
120 * his comments and implemented my own version.
121 */
122#include "bn_prime.h"
123
124static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
125 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont);
126static int probable_prime(BIGNUM *rnd, int bits);
127static int probable_prime_dh(BIGNUM *rnd, int bits,
128 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
129static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
130 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
131
132BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
133 const BIGNUM *add, const BIGNUM *rem,
134 void (*callback)(int,int,void *), void *cb_arg)
135 {
136 BIGNUM *rnd=NULL;
137 BIGNUM t;
138 int found=0;
139 int i,j,c1=0;
140 BN_CTX *ctx;
141 int checks = BN_prime_checks_for_size(bits);
142
143 BN_init(&t);
144 ctx=BN_CTX_new();
145 if (ctx == NULL) goto err;
146 if (ret == NULL)
147 {
148 if ((rnd=BN_new()) == NULL) goto err;
149 }
150 else
151 rnd=ret;
152loop:
153 /* make a random number and set the top and bottom bits */
154 if (add == NULL)
155 {
156 if (!probable_prime(rnd,bits)) goto err;
157 }
158 else
159 {
160 if (safe)
161 {
162 if (!probable_prime_dh_safe(rnd,bits,add,rem,ctx))
163 goto err;
164 }
165 else
166 {
167 if (!probable_prime_dh(rnd,bits,add,rem,ctx))
168 goto err;
169 }
170 }
171 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
172 if (callback != NULL) callback(0,c1++,cb_arg);
173
174 if (!safe)
175 {
176 i=BN_is_prime_fasttest(rnd,checks,callback,ctx,cb_arg,0);
177 if (i == -1) goto err;
178 if (i == 0) goto loop;
179 }
180 else
181 {
182 /* for "safe prime" generation,
183 * check that (p-1)/2 is prime.
184 * Since a prime is odd, We just
185 * need to divide by 2 */
186 if (!BN_rshift1(&t,rnd)) goto err;
187
188 for (i=0; i<checks; i++)
189 {
190 j=BN_is_prime_fasttest(rnd,1,callback,ctx,cb_arg,0);
191 if (j == -1) goto err;
192 if (j == 0) goto loop;
193
194 j=BN_is_prime_fasttest(&t,1,callback,ctx,cb_arg,0);
195 if (j == -1) goto err;
196 if (j == 0) goto loop;
197
198 if (callback != NULL) callback(2,c1-1,cb_arg);
199 /* We have a safe prime test pass */
200 }
201 }
202 /* we have a prime :-) */
203 found = 1;
204err:
205 if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
206 BN_free(&t);
207 if (ctx != NULL) BN_CTX_free(ctx);
208 return(found ? rnd : NULL);
209 }
210
211int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
212 BN_CTX *ctx_passed, void *cb_arg)
213 {
214 return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
215 }
216
217int BN_is_prime_fasttest(const BIGNUM *a, int checks,
218 void (*callback)(int,int,void *),
219 BN_CTX *ctx_passed, void *cb_arg,
220 int do_trial_division)
221 {
222 int i, j, ret = -1;
223 int k;
224 BN_CTX *ctx = NULL;
225 BIGNUM *A1, *A1_odd, *check; /* taken from ctx */
226 BN_MONT_CTX *mont = NULL;
227 const BIGNUM *A = NULL;
228
229 if (BN_cmp(a, BN_value_one()) <= 0)
230 return 0;
231
232 if (checks == BN_prime_checks)
233 checks = BN_prime_checks_for_size(BN_num_bits(a));
234
235 /* first look for small factors */
236 if (!BN_is_odd(a))
237 /* a is even => a is prime if and only if a == 2 */
238 return BN_is_word(a, 2);
239
240 if (do_trial_division)
241 {
242 for (i = 1; i < NUMPRIMES; i++)
243 if (BN_mod_word(a, primes[i]) == 0)
244 return 0;
245 if (callback != NULL) callback(1, -1, cb_arg);
246 }
247
248 if (ctx_passed != NULL)
249 ctx = ctx_passed;
250 else
251 if ((ctx=BN_CTX_new()) == NULL)
252 goto err;
253 BN_CTX_start(ctx);
254
255 /* A := abs(a) */
256 if (a->neg)
257 {
258 BIGNUM *t;
259 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
260 BN_copy(t, a);
261 t->neg = 0;
262 A = t;
263 }
264 else
265 A = a;
266 A1 = BN_CTX_get(ctx);
267 A1_odd = BN_CTX_get(ctx);
268 check = BN_CTX_get(ctx);
269 if (check == NULL) goto err;
270
271 /* compute A1 := A - 1 */
272 if (!BN_copy(A1, A))
273 goto err;
274 if (!BN_sub_word(A1, 1))
275 goto err;
276 if (BN_is_zero(A1))
277 {
278 ret = 0;
279 goto err;
280 }
281
282 /* write A1 as A1_odd * 2^k */
283 k = 1;
284 while (!BN_is_bit_set(A1, k))
285 k++;
286 if (!BN_rshift(A1_odd, A1, k))
287 goto err;
288
289 /* Montgomery setup for computations mod A */
290 mont = BN_MONT_CTX_new();
291 if (mont == NULL)
292 goto err;
293 if (!BN_MONT_CTX_set(mont, A, ctx))
294 goto err;
295
296 for (i = 0; i < checks; i++)
297 {
298 if (!BN_pseudo_rand_range(check, A1))
299 goto err;
300 if (!BN_add_word(check, 1))
301 goto err;
302 /* now 1 <= check < A */
303
304 j = witness(check, A, A1, A1_odd, k, ctx, mont);
305 if (j == -1) goto err;
306 if (j)
307 {
308 ret=0;
309 goto err;
310 }
311 if (callback != NULL) callback(1,i,cb_arg);
312 }
313 ret=1;
314err:
315 if (ctx != NULL)
316 {
317 BN_CTX_end(ctx);
318 if (ctx_passed == NULL)
319 BN_CTX_free(ctx);
320 }
321 if (mont != NULL)
322 BN_MONT_CTX_free(mont);
323
324 return(ret);
325 }
326
327static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
328 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont)
329 {
330 if (!BN_mod_exp_mont(w, w, a1_odd, a, ctx, mont)) /* w := w^a1_odd mod a */
331 return -1;
332 if (BN_is_one(w))
333 return 0; /* probably prime */
334 if (BN_cmp(w, a1) == 0)
335 return 0; /* w == -1 (mod a), 'a' is probably prime */
336 while (--k)
337 {
338 if (!BN_mod_mul(w, w, w, a, ctx)) /* w := w^2 mod a */
339 return -1;
340 if (BN_is_one(w))
341 return 1; /* 'a' is composite, otherwise a previous 'w' would
342 * have been == -1 (mod 'a') */
343 if (BN_cmp(w, a1) == 0)
344 return 0; /* w == -1 (mod a), 'a' is probably prime */
345 }
346 /* If we get here, 'w' is the (a-1)/2-th power of the original 'w',
347 * and it is neither -1 nor +1 -- so 'a' cannot be prime */
348 return 1;
349 }
350
351static int probable_prime(BIGNUM *rnd, int bits)
352 {
353 int i;
354 BN_ULONG mods[NUMPRIMES];
355 BN_ULONG delta,d;
356
357again:
358 if (!BN_rand(rnd,bits,1,1)) return(0);
359 /* we now have a random number 'rand' to test. */
360 for (i=1; i<NUMPRIMES; i++)
361 mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
362 delta=0;
363 loop: for (i=1; i<NUMPRIMES; i++)
364 {
365 /* check that rnd is not a prime and also
366 * that gcd(rnd-1,primes) == 1 (except for 2) */
367 if (((mods[i]+delta)%primes[i]) <= 1)
368 {
369 d=delta;
370 delta+=2;
371 /* perhaps need to check for overflow of
372 * delta (but delta can be up to 2^32)
373 * 21-May-98 eay - added overflow check */
374 if (delta < d) goto again;
375 goto loop;
376 }
377 }
378 if (!BN_add_word(rnd,delta)) return(0);
379 return(1);
380 }
381
382static int probable_prime_dh(BIGNUM *rnd, int bits,
383 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)
384 {
385 int i,ret=0;
386 BIGNUM *t1;
387
388 BN_CTX_start(ctx);
389 if ((t1 = BN_CTX_get(ctx)) == NULL) goto err;
390
391 if (!BN_rand(rnd,bits,0,1)) goto err;
392
393 /* we need ((rnd-rem) % add) == 0 */
394
395 if (!BN_mod(t1,rnd,add,ctx)) goto err;
396 if (!BN_sub(rnd,rnd,t1)) goto err;
397 if (rem == NULL)
398 { if (!BN_add_word(rnd,1)) goto err; }
399 else
400 { if (!BN_add(rnd,rnd,rem)) goto err; }
401
402 /* we now have a random number 'rand' to test. */
403
404 loop: for (i=1; i<NUMPRIMES; i++)
405 {
406 /* check that rnd is a prime */
407 if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
408 {
409 if (!BN_add(rnd,rnd,add)) goto err;
410 goto loop;
411 }
412 }
413 ret=1;
414err:
415 BN_CTX_end(ctx);
416 return(ret);
417 }
418
419static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
420 const BIGNUM *rem, BN_CTX *ctx)
421 {
422 int i,ret=0;
423 BIGNUM *t1,*qadd,*q;
424
425 bits--;
426 BN_CTX_start(ctx);
427 t1 = BN_CTX_get(ctx);
428 q = BN_CTX_get(ctx);
429 qadd = BN_CTX_get(ctx);
430 if (qadd == NULL) goto err;
431
432 if (!BN_rshift1(qadd,padd)) goto err;
433
434 if (!BN_rand(q,bits,0,1)) goto err;
435
436 /* we need ((rnd-rem) % add) == 0 */
437 if (!BN_mod(t1,q,qadd,ctx)) goto err;
438 if (!BN_sub(q,q,t1)) goto err;
439 if (rem == NULL)
440 { if (!BN_add_word(q,1)) goto err; }
441 else
442 {
443 if (!BN_rshift1(t1,rem)) goto err;
444 if (!BN_add(q,q,t1)) goto err;
445 }
446
447 /* we now have a random number 'rand' to test. */
448 if (!BN_lshift1(p,q)) goto err;
449 if (!BN_add_word(p,1)) goto err;
450
451 loop: for (i=1; i<NUMPRIMES; i++)
452 {
453 /* check that p and q are prime */
454 /* check that for p and q
455 * gcd(p-1,primes) == 1 (except for 2) */
456 if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) ||
457 (BN_mod_word(q,(BN_ULONG)primes[i]) == 0))
458 {
459 if (!BN_add(p,p,padd)) goto err;
460 if (!BN_add(q,q,qadd)) goto err;
461 goto loop;
462 }
463 }
464 ret=1;
465err:
466 BN_CTX_end(ctx);
467 return(ret);
468 }
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h
new file mode 100644
index 0000000000..b7cf9a9bfe
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_prime.h
@@ -0,0 +1,325 @@
1/* Auto generated by bn_prime.pl */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef EIGHT_BIT
60#define NUMPRIMES 2048
61#else
62#define NUMPRIMES 54
63#endif
64static const unsigned int primes[NUMPRIMES]=
65 {
66 2, 3, 5, 7, 11, 13, 17, 19,
67 23, 29, 31, 37, 41, 43, 47, 53,
68 59, 61, 67, 71, 73, 79, 83, 89,
69 97, 101, 103, 107, 109, 113, 127, 131,
70 137, 139, 149, 151, 157, 163, 167, 173,
71 179, 181, 191, 193, 197, 199, 211, 223,
72 227, 229, 233, 239, 241, 251,
73#ifndef EIGHT_BIT
74 257, 263,
75 269, 271, 277, 281, 283, 293, 307, 311,
76 313, 317, 331, 337, 347, 349, 353, 359,
77 367, 373, 379, 383, 389, 397, 401, 409,
78 419, 421, 431, 433, 439, 443, 449, 457,
79 461, 463, 467, 479, 487, 491, 499, 503,
80 509, 521, 523, 541, 547, 557, 563, 569,
81 571, 577, 587, 593, 599, 601, 607, 613,
82 617, 619, 631, 641, 643, 647, 653, 659,
83 661, 673, 677, 683, 691, 701, 709, 719,
84 727, 733, 739, 743, 751, 757, 761, 769,
85 773, 787, 797, 809, 811, 821, 823, 827,
86 829, 839, 853, 857, 859, 863, 877, 881,
87 883, 887, 907, 911, 919, 929, 937, 941,
88 947, 953, 967, 971, 977, 983, 991, 997,
89 1009,1013,1019,1021,1031,1033,1039,1049,
90 1051,1061,1063,1069,1087,1091,1093,1097,
91 1103,1109,1117,1123,1129,1151,1153,1163,
92 1171,1181,1187,1193,1201,1213,1217,1223,
93 1229,1231,1237,1249,1259,1277,1279,1283,
94 1289,1291,1297,1301,1303,1307,1319,1321,
95 1327,1361,1367,1373,1381,1399,1409,1423,
96 1427,1429,1433,1439,1447,1451,1453,1459,
97 1471,1481,1483,1487,1489,1493,1499,1511,
98 1523,1531,1543,1549,1553,1559,1567,1571,
99 1579,1583,1597,1601,1607,1609,1613,1619,
100 1621,1627,1637,1657,1663,1667,1669,1693,
101 1697,1699,1709,1721,1723,1733,1741,1747,
102 1753,1759,1777,1783,1787,1789,1801,1811,
103 1823,1831,1847,1861,1867,1871,1873,1877,
104 1879,1889,1901,1907,1913,1931,1933,1949,
105 1951,1973,1979,1987,1993,1997,1999,2003,
106 2011,2017,2027,2029,2039,2053,2063,2069,
107 2081,2083,2087,2089,2099,2111,2113,2129,
108 2131,2137,2141,2143,2153,2161,2179,2203,
109 2207,2213,2221,2237,2239,2243,2251,2267,
110 2269,2273,2281,2287,2293,2297,2309,2311,
111 2333,2339,2341,2347,2351,2357,2371,2377,
112 2381,2383,2389,2393,2399,2411,2417,2423,
113 2437,2441,2447,2459,2467,2473,2477,2503,
114 2521,2531,2539,2543,2549,2551,2557,2579,
115 2591,2593,2609,2617,2621,2633,2647,2657,
116 2659,2663,2671,2677,2683,2687,2689,2693,
117 2699,2707,2711,2713,2719,2729,2731,2741,
118 2749,2753,2767,2777,2789,2791,2797,2801,
119 2803,2819,2833,2837,2843,2851,2857,2861,
120 2879,2887,2897,2903,2909,2917,2927,2939,
121 2953,2957,2963,2969,2971,2999,3001,3011,
122 3019,3023,3037,3041,3049,3061,3067,3079,
123 3083,3089,3109,3119,3121,3137,3163,3167,
124 3169,3181,3187,3191,3203,3209,3217,3221,
125 3229,3251,3253,3257,3259,3271,3299,3301,
126 3307,3313,3319,3323,3329,3331,3343,3347,
127 3359,3361,3371,3373,3389,3391,3407,3413,
128 3433,3449,3457,3461,3463,3467,3469,3491,
129 3499,3511,3517,3527,3529,3533,3539,3541,
130 3547,3557,3559,3571,3581,3583,3593,3607,
131 3613,3617,3623,3631,3637,3643,3659,3671,
132 3673,3677,3691,3697,3701,3709,3719,3727,
133 3733,3739,3761,3767,3769,3779,3793,3797,
134 3803,3821,3823,3833,3847,3851,3853,3863,
135 3877,3881,3889,3907,3911,3917,3919,3923,
136 3929,3931,3943,3947,3967,3989,4001,4003,
137 4007,4013,4019,4021,4027,4049,4051,4057,
138 4073,4079,4091,4093,4099,4111,4127,4129,
139 4133,4139,4153,4157,4159,4177,4201,4211,
140 4217,4219,4229,4231,4241,4243,4253,4259,
141 4261,4271,4273,4283,4289,4297,4327,4337,
142 4339,4349,4357,4363,4373,4391,4397,4409,
143 4421,4423,4441,4447,4451,4457,4463,4481,
144 4483,4493,4507,4513,4517,4519,4523,4547,
145 4549,4561,4567,4583,4591,4597,4603,4621,
146 4637,4639,4643,4649,4651,4657,4663,4673,
147 4679,4691,4703,4721,4723,4729,4733,4751,
148 4759,4783,4787,4789,4793,4799,4801,4813,
149 4817,4831,4861,4871,4877,4889,4903,4909,
150 4919,4931,4933,4937,4943,4951,4957,4967,
151 4969,4973,4987,4993,4999,5003,5009,5011,
152 5021,5023,5039,5051,5059,5077,5081,5087,
153 5099,5101,5107,5113,5119,5147,5153,5167,
154 5171,5179,5189,5197,5209,5227,5231,5233,
155 5237,5261,5273,5279,5281,5297,5303,5309,
156 5323,5333,5347,5351,5381,5387,5393,5399,
157 5407,5413,5417,5419,5431,5437,5441,5443,
158 5449,5471,5477,5479,5483,5501,5503,5507,
159 5519,5521,5527,5531,5557,5563,5569,5573,
160 5581,5591,5623,5639,5641,5647,5651,5653,
161 5657,5659,5669,5683,5689,5693,5701,5711,
162 5717,5737,5741,5743,5749,5779,5783,5791,
163 5801,5807,5813,5821,5827,5839,5843,5849,
164 5851,5857,5861,5867,5869,5879,5881,5897,
165 5903,5923,5927,5939,5953,5981,5987,6007,
166 6011,6029,6037,6043,6047,6053,6067,6073,
167 6079,6089,6091,6101,6113,6121,6131,6133,
168 6143,6151,6163,6173,6197,6199,6203,6211,
169 6217,6221,6229,6247,6257,6263,6269,6271,
170 6277,6287,6299,6301,6311,6317,6323,6329,
171 6337,6343,6353,6359,6361,6367,6373,6379,
172 6389,6397,6421,6427,6449,6451,6469,6473,
173 6481,6491,6521,6529,6547,6551,6553,6563,
174 6569,6571,6577,6581,6599,6607,6619,6637,
175 6653,6659,6661,6673,6679,6689,6691,6701,
176 6703,6709,6719,6733,6737,6761,6763,6779,
177 6781,6791,6793,6803,6823,6827,6829,6833,
178 6841,6857,6863,6869,6871,6883,6899,6907,
179 6911,6917,6947,6949,6959,6961,6967,6971,
180 6977,6983,6991,6997,7001,7013,7019,7027,
181 7039,7043,7057,7069,7079,7103,7109,7121,
182 7127,7129,7151,7159,7177,7187,7193,7207,
183 7211,7213,7219,7229,7237,7243,7247,7253,
184 7283,7297,7307,7309,7321,7331,7333,7349,
185 7351,7369,7393,7411,7417,7433,7451,7457,
186 7459,7477,7481,7487,7489,7499,7507,7517,
187 7523,7529,7537,7541,7547,7549,7559,7561,
188 7573,7577,7583,7589,7591,7603,7607,7621,
189 7639,7643,7649,7669,7673,7681,7687,7691,
190 7699,7703,7717,7723,7727,7741,7753,7757,
191 7759,7789,7793,7817,7823,7829,7841,7853,
192 7867,7873,7877,7879,7883,7901,7907,7919,
193 7927,7933,7937,7949,7951,7963,7993,8009,
194 8011,8017,8039,8053,8059,8069,8081,8087,
195 8089,8093,8101,8111,8117,8123,8147,8161,
196 8167,8171,8179,8191,8209,8219,8221,8231,
197 8233,8237,8243,8263,8269,8273,8287,8291,
198 8293,8297,8311,8317,8329,8353,8363,8369,
199 8377,8387,8389,8419,8423,8429,8431,8443,
200 8447,8461,8467,8501,8513,8521,8527,8537,
201 8539,8543,8563,8573,8581,8597,8599,8609,
202 8623,8627,8629,8641,8647,8663,8669,8677,
203 8681,8689,8693,8699,8707,8713,8719,8731,
204 8737,8741,8747,8753,8761,8779,8783,8803,
205 8807,8819,8821,8831,8837,8839,8849,8861,
206 8863,8867,8887,8893,8923,8929,8933,8941,
207 8951,8963,8969,8971,8999,9001,9007,9011,
208 9013,9029,9041,9043,9049,9059,9067,9091,
209 9103,9109,9127,9133,9137,9151,9157,9161,
210 9173,9181,9187,9199,9203,9209,9221,9227,
211 9239,9241,9257,9277,9281,9283,9293,9311,
212 9319,9323,9337,9341,9343,9349,9371,9377,
213 9391,9397,9403,9413,9419,9421,9431,9433,
214 9437,9439,9461,9463,9467,9473,9479,9491,
215 9497,9511,9521,9533,9539,9547,9551,9587,
216 9601,9613,9619,9623,9629,9631,9643,9649,
217 9661,9677,9679,9689,9697,9719,9721,9733,
218 9739,9743,9749,9767,9769,9781,9787,9791,
219 9803,9811,9817,9829,9833,9839,9851,9857,
220 9859,9871,9883,9887,9901,9907,9923,9929,
221 9931,9941,9949,9967,9973,10007,10009,10037,
222 10039,10061,10067,10069,10079,10091,10093,10099,
223 10103,10111,10133,10139,10141,10151,10159,10163,
224 10169,10177,10181,10193,10211,10223,10243,10247,
225 10253,10259,10267,10271,10273,10289,10301,10303,
226 10313,10321,10331,10333,10337,10343,10357,10369,
227 10391,10399,10427,10429,10433,10453,10457,10459,
228 10463,10477,10487,10499,10501,10513,10529,10531,
229 10559,10567,10589,10597,10601,10607,10613,10627,
230 10631,10639,10651,10657,10663,10667,10687,10691,
231 10709,10711,10723,10729,10733,10739,10753,10771,
232 10781,10789,10799,10831,10837,10847,10853,10859,
233 10861,10867,10883,10889,10891,10903,10909,10937,
234 10939,10949,10957,10973,10979,10987,10993,11003,
235 11027,11047,11057,11059,11069,11071,11083,11087,
236 11093,11113,11117,11119,11131,11149,11159,11161,
237 11171,11173,11177,11197,11213,11239,11243,11251,
238 11257,11261,11273,11279,11287,11299,11311,11317,
239 11321,11329,11351,11353,11369,11383,11393,11399,
240 11411,11423,11437,11443,11447,11467,11471,11483,
241 11489,11491,11497,11503,11519,11527,11549,11551,
242 11579,11587,11593,11597,11617,11621,11633,11657,
243 11677,11681,11689,11699,11701,11717,11719,11731,
244 11743,11777,11779,11783,11789,11801,11807,11813,
245 11821,11827,11831,11833,11839,11863,11867,11887,
246 11897,11903,11909,11923,11927,11933,11939,11941,
247 11953,11959,11969,11971,11981,11987,12007,12011,
248 12037,12041,12043,12049,12071,12073,12097,12101,
249 12107,12109,12113,12119,12143,12149,12157,12161,
250 12163,12197,12203,12211,12227,12239,12241,12251,
251 12253,12263,12269,12277,12281,12289,12301,12323,
252 12329,12343,12347,12373,12377,12379,12391,12401,
253 12409,12413,12421,12433,12437,12451,12457,12473,
254 12479,12487,12491,12497,12503,12511,12517,12527,
255 12539,12541,12547,12553,12569,12577,12583,12589,
256 12601,12611,12613,12619,12637,12641,12647,12653,
257 12659,12671,12689,12697,12703,12713,12721,12739,
258 12743,12757,12763,12781,12791,12799,12809,12821,
259 12823,12829,12841,12853,12889,12893,12899,12907,
260 12911,12917,12919,12923,12941,12953,12959,12967,
261 12973,12979,12983,13001,13003,13007,13009,13033,
262 13037,13043,13049,13063,13093,13099,13103,13109,
263 13121,13127,13147,13151,13159,13163,13171,13177,
264 13183,13187,13217,13219,13229,13241,13249,13259,
265 13267,13291,13297,13309,13313,13327,13331,13337,
266 13339,13367,13381,13397,13399,13411,13417,13421,
267 13441,13451,13457,13463,13469,13477,13487,13499,
268 13513,13523,13537,13553,13567,13577,13591,13597,
269 13613,13619,13627,13633,13649,13669,13679,13681,
270 13687,13691,13693,13697,13709,13711,13721,13723,
271 13729,13751,13757,13759,13763,13781,13789,13799,
272 13807,13829,13831,13841,13859,13873,13877,13879,
273 13883,13901,13903,13907,13913,13921,13931,13933,
274 13963,13967,13997,13999,14009,14011,14029,14033,
275 14051,14057,14071,14081,14083,14087,14107,14143,
276 14149,14153,14159,14173,14177,14197,14207,14221,
277 14243,14249,14251,14281,14293,14303,14321,14323,
278 14327,14341,14347,14369,14387,14389,14401,14407,
279 14411,14419,14423,14431,14437,14447,14449,14461,
280 14479,14489,14503,14519,14533,14537,14543,14549,
281 14551,14557,14561,14563,14591,14593,14621,14627,
282 14629,14633,14639,14653,14657,14669,14683,14699,
283 14713,14717,14723,14731,14737,14741,14747,14753,
284 14759,14767,14771,14779,14783,14797,14813,14821,
285 14827,14831,14843,14851,14867,14869,14879,14887,
286 14891,14897,14923,14929,14939,14947,14951,14957,
287 14969,14983,15013,15017,15031,15053,15061,15073,
288 15077,15083,15091,15101,15107,15121,15131,15137,
289 15139,15149,15161,15173,15187,15193,15199,15217,
290 15227,15233,15241,15259,15263,15269,15271,15277,
291 15287,15289,15299,15307,15313,15319,15329,15331,
292 15349,15359,15361,15373,15377,15383,15391,15401,
293 15413,15427,15439,15443,15451,15461,15467,15473,
294 15493,15497,15511,15527,15541,15551,15559,15569,
295 15581,15583,15601,15607,15619,15629,15641,15643,
296 15647,15649,15661,15667,15671,15679,15683,15727,
297 15731,15733,15737,15739,15749,15761,15767,15773,
298 15787,15791,15797,15803,15809,15817,15823,15859,
299 15877,15881,15887,15889,15901,15907,15913,15919,
300 15923,15937,15959,15971,15973,15991,16001,16007,
301 16033,16057,16061,16063,16067,16069,16073,16087,
302 16091,16097,16103,16111,16127,16139,16141,16183,
303 16187,16189,16193,16217,16223,16229,16231,16249,
304 16253,16267,16273,16301,16319,16333,16339,16349,
305 16361,16363,16369,16381,16411,16417,16421,16427,
306 16433,16447,16451,16453,16477,16481,16487,16493,
307 16519,16529,16547,16553,16561,16567,16573,16603,
308 16607,16619,16631,16633,16649,16651,16657,16661,
309 16673,16691,16693,16699,16703,16729,16741,16747,
310 16759,16763,16787,16811,16823,16829,16831,16843,
311 16871,16879,16883,16889,16901,16903,16921,16927,
312 16931,16937,16943,16963,16979,16981,16987,16993,
313 17011,17021,17027,17029,17033,17041,17047,17053,
314 17077,17093,17099,17107,17117,17123,17137,17159,
315 17167,17183,17189,17191,17203,17207,17209,17231,
316 17239,17257,17291,17293,17299,17317,17321,17327,
317 17333,17341,17351,17359,17377,17383,17387,17389,
318 17393,17401,17417,17419,17431,17443,17449,17467,
319 17471,17477,17483,17489,17491,17497,17509,17519,
320 17539,17551,17569,17573,17579,17581,17597,17599,
321 17609,17623,17627,17657,17659,17669,17681,17683,
322 17707,17713,17729,17737,17747,17749,17761,17783,
323 17789,17791,17807,17827,17837,17839,17851,17863,
324#endif
325 };
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl
new file mode 100644
index 0000000000..9fc3765486
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_prime.pl
@@ -0,0 +1,117 @@
1#!/usr/local/bin/perl
2# bn_prime.pl
3
4$num=2048;
5$num=$ARGV[0] if ($#ARGV >= 0);
6
7push(@primes,2);
8$p=1;
9loop: while ($#primes < $num-1)
10 {
11 $p+=2;
12 $s=int(sqrt($p));
13
14 for ($i=0; $primes[$i]<=$s; $i++)
15 {
16 next loop if (($p%$primes[$i]) == 0);
17 }
18 push(@primes,$p);
19 }
20
21# print <<"EOF";
22# /* Auto generated by bn_prime.pl */
23# /* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au).
24# * All rights reserved.
25# * Copyright remains Eric Young's, and as such any Copyright notices in
26# * the code are not to be removed.
27# * See the COPYRIGHT file in the SSLeay distribution for more details.
28# */
29#
30# EOF
31
32print <<\EOF;
33/* Auto generated by bn_prime.pl */
34/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
35 * All rights reserved.
36 *
37 * This package is an SSL implementation written
38 * by Eric Young (eay@cryptsoft.com).
39 * The implementation was written so as to conform with Netscapes SSL.
40 *
41 * This library is free for commercial and non-commercial use as long as
42 * the following conditions are aheared to. The following conditions
43 * apply to all code found in this distribution, be it the RC4, RSA,
44 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
45 * included with this distribution is covered by the same copyright terms
46 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
47 *
48 * Copyright remains Eric Young's, and as such any Copyright notices in
49 * the code are not to be removed.
50 * If this package is used in a product, Eric Young should be given attribution
51 * as the author of the parts of the library used.
52 * This can be in the form of a textual message at program startup or
53 * in documentation (online or textual) provided with the package.
54 *
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
57 * are met:
58 * 1. Redistributions of source code must retain the copyright
59 * notice, this list of conditions and the following disclaimer.
60 * 2. Redistributions in binary form must reproduce the above copyright
61 * notice, this list of conditions and the following disclaimer in the
62 * documentation and/or other materials provided with the distribution.
63 * 3. All advertising materials mentioning features or use of this software
64 * must display the following acknowledgement:
65 * "This product includes cryptographic software written by
66 * Eric Young (eay@cryptsoft.com)"
67 * The word 'cryptographic' can be left out if the rouines from the library
68 * being used are not cryptographic related :-).
69 * 4. If you include any Windows specific code (or a derivative thereof) from
70 * the apps directory (application code) you must include an acknowledgement:
71 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
72 *
73 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
74 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
77 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
78 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
79 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
80 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
81 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
82 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
83 * SUCH DAMAGE.
84 *
85 * The licence and distribution terms for any publically available version or
86 * derivative of this code cannot be changed. i.e. this code cannot simply be
87 * copied and put under another distribution licence
88 * [including the GNU Public Licence.]
89 */
90
91EOF
92
93for ($i=0; $i <= $#primes; $i++)
94 {
95 if ($primes[$i] > 256)
96 {
97 $eight=$i;
98 last;
99 }
100 }
101
102printf "#ifndef EIGHT_BIT\n";
103printf "#define NUMPRIMES %d\n",$num;
104printf "#else\n";
105printf "#define NUMPRIMES %d\n",$eight;
106printf "#endif\n";
107print "static const unsigned int primes[NUMPRIMES]=\n\t{\n\t";
108$init=0;
109for ($i=0; $i <= $#primes; $i++)
110 {
111 printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++);
112 printf("\n\t") if (($i%8) == 0) && ($i != 0);
113 printf("%4d,",$primes[$i]);
114 }
115print "\n#endif\n\t};\n";
116
117
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
new file mode 100644
index 0000000000..acba7ed7ee
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -0,0 +1,333 @@
1/* crypto/bn/bn_print.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include "bn_lcl.h"
64
65static const char *Hex="0123456789ABCDEF";
66
67/* Must 'OPENSSL_free' the returned data */
68char *BN_bn2hex(const BIGNUM *a)
69 {
70 int i,j,v,z=0;
71 char *buf;
72 char *p;
73
74 buf=(char *)OPENSSL_malloc(a->top*BN_BYTES*2+2);
75 if (buf == NULL)
76 {
77 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE);
78 goto err;
79 }
80 p=buf;
81 if (a->neg) *(p++)='-';
82 if (BN_is_zero(a)) *(p++)='0';
83 for (i=a->top-1; i >=0; i--)
84 {
85 for (j=BN_BITS2-8; j >= 0; j-=8)
86 {
87 /* strip leading zeros */
88 v=((int)(a->d[i]>>(long)j))&0xff;
89 if (z || (v != 0))
90 {
91 *(p++)=Hex[v>>4];
92 *(p++)=Hex[v&0x0f];
93 z=1;
94 }
95 }
96 }
97 *p='\0';
98err:
99 return(buf);
100 }
101
102/* Must 'OPENSSL_free' the returned data */
103char *BN_bn2dec(const BIGNUM *a)
104 {
105 int i=0,num;
106 char *buf=NULL;
107 char *p;
108 BIGNUM *t=NULL;
109 BN_ULONG *bn_data=NULL,*lp;
110
111 i=BN_num_bits(a)*3;
112 num=(i/10+i/1000+3)+1;
113 bn_data=(BN_ULONG *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG));
114 buf=(char *)OPENSSL_malloc(num+3);
115 if ((buf == NULL) || (bn_data == NULL))
116 {
117 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE);
118 goto err;
119 }
120 if ((t=BN_dup(a)) == NULL) goto err;
121
122#define BUF_REMAIN (num+3 - (size_t)(p - buf))
123 p=buf;
124 lp=bn_data;
125 if (t->neg) *(p++)='-';
126 if (BN_is_zero(t))
127 {
128 *(p++)='0';
129 *(p++)='\0';
130 }
131 else
132 {
133 i=0;
134 while (!BN_is_zero(t))
135 {
136 *lp=BN_div_word(t,BN_DEC_CONV);
137 lp++;
138 }
139 lp--;
140 /* We now have a series of blocks, BN_DEC_NUM chars
141 * in length, where the last one needs truncation.
142 * The blocks need to be reversed in order. */
143 BIO_snprintf(p,BUF_REMAIN,BN_DEC_FMT1,*lp);
144 while (*p) p++;
145 while (lp != bn_data)
146 {
147 lp--;
148 BIO_snprintf(p,BUF_REMAIN,BN_DEC_FMT2,*lp);
149 while (*p) p++;
150 }
151 }
152err:
153 if (bn_data != NULL) OPENSSL_free(bn_data);
154 if (t != NULL) BN_free(t);
155 return(buf);
156 }
157
158int BN_hex2bn(BIGNUM **bn, const char *a)
159 {
160 BIGNUM *ret=NULL;
161 BN_ULONG l=0;
162 int neg=0,h,m,i,j,k,c;
163 int num;
164
165 if ((a == NULL) || (*a == '\0')) return(0);
166
167 if (*a == '-') { neg=1; a++; }
168
169 for (i=0; isxdigit((unsigned char) a[i]); i++)
170 ;
171
172 num=i+neg;
173 if (bn == NULL) return(num);
174
175 /* a is the start of the hex digits, and it is 'i' long */
176 if (*bn == NULL)
177 {
178 if ((ret=BN_new()) == NULL) return(0);
179 }
180 else
181 {
182 ret= *bn;
183 BN_zero(ret);
184 }
185
186 /* i is the number of hex digests; */
187 if (bn_expand(ret,i*4) == NULL) goto err;
188
189 j=i; /* least significant 'hex' */
190 m=0;
191 h=0;
192 while (j > 0)
193 {
194 m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j;
195 l=0;
196 for (;;)
197 {
198 c=a[j-m];
199 if ((c >= '0') && (c <= '9')) k=c-'0';
200 else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10;
201 else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10;
202 else k=0; /* paranoia */
203 l=(l<<4)|k;
204
205 if (--m <= 0)
206 {
207 ret->d[h++]=l;
208 break;
209 }
210 }
211 j-=(BN_BYTES*2);
212 }
213 ret->top=h;
214 bn_fix_top(ret);
215 ret->neg=neg;
216
217 *bn=ret;
218 return(num);
219err:
220 if (*bn == NULL) BN_free(ret);
221 return(0);
222 }
223
224int BN_dec2bn(BIGNUM **bn, const char *a)
225 {
226 BIGNUM *ret=NULL;
227 BN_ULONG l=0;
228 int neg=0,i,j;
229 int num;
230
231 if ((a == NULL) || (*a == '\0')) return(0);
232 if (*a == '-') { neg=1; a++; }
233
234 for (i=0; isdigit((unsigned char) a[i]); i++)
235 ;
236
237 num=i+neg;
238 if (bn == NULL) return(num);
239
240 /* a is the start of the digits, and it is 'i' long.
241 * We chop it into BN_DEC_NUM digits at a time */
242 if (*bn == NULL)
243 {
244 if ((ret=BN_new()) == NULL) return(0);
245 }
246 else
247 {
248 ret= *bn;
249 BN_zero(ret);
250 }
251
252 /* i is the number of digests, a bit of an over expand; */
253 if (bn_expand(ret,i*4) == NULL) goto err;
254
255 j=BN_DEC_NUM-(i%BN_DEC_NUM);
256 if (j == BN_DEC_NUM) j=0;
257 l=0;
258 while (*a)
259 {
260 l*=10;
261 l+= *a-'0';
262 a++;
263 if (++j == BN_DEC_NUM)
264 {
265 BN_mul_word(ret,BN_DEC_CONV);
266 BN_add_word(ret,l);
267 l=0;
268 j=0;
269 }
270 }
271 ret->neg=neg;
272
273 bn_fix_top(ret);
274 *bn=ret;
275 return(num);
276err:
277 if (*bn == NULL) BN_free(ret);
278 return(0);
279 }
280
281#ifndef OPENSSL_NO_BIO
282#ifndef OPENSSL_NO_FP_API
283int BN_print_fp(FILE *fp, const BIGNUM *a)
284 {
285 BIO *b;
286 int ret;
287
288 if ((b=BIO_new(BIO_s_file())) == NULL)
289 return(0);
290 BIO_set_fp(b,fp,BIO_NOCLOSE);
291 ret=BN_print(b,a);
292 BIO_free(b);
293 return(ret);
294 }
295#endif
296
297int BN_print(BIO *bp, const BIGNUM *a)
298 {
299 int i,j,v,z=0;
300 int ret=0;
301
302 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;
303 if ((BN_is_zero(a)) && (BIO_write(bp,"0",1) != 1)) goto end;
304 for (i=a->top-1; i >=0; i--)
305 {
306 for (j=BN_BITS2-4; j >= 0; j-=4)
307 {
308 /* strip leading zeros */
309 v=((int)(a->d[i]>>(long)j))&0x0f;
310 if (z || (v != 0))
311 {
312 if (BIO_write(bp,&(Hex[v]),1) != 1)
313 goto end;
314 z=1;
315 }
316 }
317 }
318 ret=1;
319end:
320 return(ret);
321 }
322#endif
323
324#ifdef BN_DEBUG
325void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n)
326 {
327 int i;
328 fprintf(o, "%s=", a);
329 for (i=n-1;i>=0;i--)
330 fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */
331 fprintf(o, "\n");
332 }
333#endif
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
new file mode 100644
index 0000000000..893c9d2af9
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -0,0 +1,291 @@
1/* crypto/bn/bn_rand.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <time.h>
114#include "cryptlib.h"
115#include "bn_lcl.h"
116#include <openssl/rand.h>
117
118static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
119 {
120 unsigned char *buf=NULL;
121 int ret=0,bit,bytes,mask;
122 time_t tim;
123
124 if (bits == 0)
125 {
126 BN_zero(rnd);
127 return 1;
128 }
129
130 bytes=(bits+7)/8;
131 bit=(bits-1)%8;
132 mask=0xff<<(bit+1);
133
134 buf=(unsigned char *)OPENSSL_malloc(bytes);
135 if (buf == NULL)
136 {
137 BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);
138 goto err;
139 }
140
141 /* make a random number and set the top and bottom bits */
142 time(&tim);
143 RAND_add(&tim,sizeof(tim),0);
144
145 if (pseudorand)
146 {
147 if (RAND_pseudo_bytes(buf, bytes) == -1)
148 goto err;
149 }
150 else
151 {
152 if (RAND_bytes(buf, bytes) <= 0)
153 goto err;
154 }
155
156#if 1
157 if (pseudorand == 2)
158 {
159 /* generate patterns that are more likely to trigger BN
160 library bugs */
161 int i;
162 unsigned char c;
163
164 for (i = 0; i < bytes; i++)
165 {
166 RAND_pseudo_bytes(&c, 1);
167 if (c >= 128 && i > 0)
168 buf[i] = buf[i-1];
169 else if (c < 42)
170 buf[i] = 0;
171 else if (c < 84)
172 buf[i] = 255;
173 }
174 }
175#endif
176
177 if (top != -1)
178 {
179 if (top)
180 {
181 if (bit == 0)
182 {
183 buf[0]=1;
184 buf[1]|=0x80;
185 }
186 else
187 {
188 buf[0]|=(3<<(bit-1));
189 }
190 }
191 else
192 {
193 buf[0]|=(1<<bit);
194 }
195 }
196 buf[0] &= ~mask;
197 if (bottom) /* set bottom bit if requested */
198 buf[bytes-1]|=1;
199 if (!BN_bin2bn(buf,bytes,rnd)) goto err;
200 ret=1;
201err:
202 if (buf != NULL)
203 {
204 OPENSSL_cleanse(buf,bytes);
205 OPENSSL_free(buf);
206 }
207 return(ret);
208 }
209
210int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
211 {
212 return bnrand(0, rnd, bits, top, bottom);
213 }
214
215int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
216 {
217 return bnrand(1, rnd, bits, top, bottom);
218 }
219
220#if 1
221int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
222 {
223 return bnrand(2, rnd, bits, top, bottom);
224 }
225#endif
226
227
228/* random number r: 0 <= r < range */
229static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
230 {
231 int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand;
232 int n;
233
234 if (range->neg || BN_is_zero(range))
235 {
236 BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);
237 return 0;
238 }
239
240 n = BN_num_bits(range); /* n > 0 */
241
242 /* BN_is_bit_set(range, n - 1) always holds */
243
244 if (n == 1)
245 {
246 if (!BN_zero(r)) return 0;
247 }
248 else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3))
249 {
250 /* range = 100..._2,
251 * so 3*range (= 11..._2) is exactly one bit longer than range */
252 do
253 {
254 if (!bn_rand(r, n + 1, -1, 0)) return 0;
255 /* If r < 3*range, use r := r MOD range
256 * (which is either r, r - range, or r - 2*range).
257 * Otherwise, iterate once more.
258 * Since 3*range = 11..._2, each iteration succeeds with
259 * probability >= .75. */
260 if (BN_cmp(r ,range) >= 0)
261 {
262 if (!BN_sub(r, r, range)) return 0;
263 if (BN_cmp(r, range) >= 0)
264 if (!BN_sub(r, r, range)) return 0;
265 }
266 }
267 while (BN_cmp(r, range) >= 0);
268 }
269 else
270 {
271 do
272 {
273 /* range = 11..._2 or range = 101..._2 */
274 if (!bn_rand(r, n, -1, 0)) return 0;
275 }
276 while (BN_cmp(r, range) >= 0);
277 }
278
279 return 1;
280 }
281
282
283int BN_rand_range(BIGNUM *r, BIGNUM *range)
284 {
285 return bn_rand_range(0, r, range);
286 }
287
288int BN_pseudo_rand_range(BIGNUM *r, BIGNUM *range)
289 {
290 return bn_rand_range(1, r, range);
291 }
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
new file mode 100644
index 0000000000..ef5fdd4708
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -0,0 +1,230 @@
1/* crypto/bn/bn_recp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63void BN_RECP_CTX_init(BN_RECP_CTX *recp)
64 {
65 BN_init(&(recp->N));
66 BN_init(&(recp->Nr));
67 recp->num_bits=0;
68 recp->flags=0;
69 }
70
71BN_RECP_CTX *BN_RECP_CTX_new(void)
72 {
73 BN_RECP_CTX *ret;
74
75 if ((ret=(BN_RECP_CTX *)OPENSSL_malloc(sizeof(BN_RECP_CTX))) == NULL)
76 return(NULL);
77
78 BN_RECP_CTX_init(ret);
79 ret->flags=BN_FLG_MALLOCED;
80 return(ret);
81 }
82
83void BN_RECP_CTX_free(BN_RECP_CTX *recp)
84 {
85 if(recp == NULL)
86 return;
87
88 BN_free(&(recp->N));
89 BN_free(&(recp->Nr));
90 if (recp->flags & BN_FLG_MALLOCED)
91 OPENSSL_free(recp);
92 }
93
94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
95 {
96 if (!BN_copy(&(recp->N),d)) return 0;
97 if (!BN_zero(&(recp->Nr))) return 0;
98 recp->num_bits=BN_num_bits(d);
99 recp->shift=0;
100 return(1);
101 }
102
103int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
104 BN_RECP_CTX *recp, BN_CTX *ctx)
105 {
106 int ret=0;
107 BIGNUM *a;
108 const BIGNUM *ca;
109
110 BN_CTX_start(ctx);
111 if ((a = BN_CTX_get(ctx)) == NULL) goto err;
112 if (y != NULL)
113 {
114 if (x == y)
115 { if (!BN_sqr(a,x,ctx)) goto err; }
116 else
117 { if (!BN_mul(a,x,y,ctx)) goto err; }
118 ca = a;
119 }
120 else
121 ca=x; /* Just do the mod */
122
123 ret = BN_div_recp(NULL,r,ca,recp,ctx);
124err:
125 BN_CTX_end(ctx);
126 return(ret);
127 }
128
129int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
130 BN_RECP_CTX *recp, BN_CTX *ctx)
131 {
132 int i,j,ret=0;
133 BIGNUM *a,*b,*d,*r;
134
135 BN_CTX_start(ctx);
136 a=BN_CTX_get(ctx);
137 b=BN_CTX_get(ctx);
138 if (dv != NULL)
139 d=dv;
140 else
141 d=BN_CTX_get(ctx);
142 if (rem != NULL)
143 r=rem;
144 else
145 r=BN_CTX_get(ctx);
146 if (a == NULL || b == NULL || d == NULL || r == NULL) goto err;
147
148 if (BN_ucmp(m,&(recp->N)) < 0)
149 {
150 if (!BN_zero(d)) return 0;
151 if (!BN_copy(r,m)) return 0;
152 BN_CTX_end(ctx);
153 return(1);
154 }
155
156 /* We want the remainder
157 * Given input of ABCDEF / ab
158 * we need multiply ABCDEF by 3 digests of the reciprocal of ab
159 *
160 */
161
162 /* i := max(BN_num_bits(m), 2*BN_num_bits(N)) */
163 i=BN_num_bits(m);
164 j=recp->num_bits<<1;
165 if (j>i) i=j;
166
167 /* Nr := round(2^i / N) */
168 if (i != recp->shift)
169 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
170 i,ctx); /* BN_reciprocal returns i, or -1 for an error */
171 if (recp->shift == -1) goto err;
172
173 /* d := |round(round(m / 2^BN_num_bits(N)) * recp->Nr / 2^(i - BN_num_bits(N)))|
174 * = |round(round(m / 2^BN_num_bits(N)) * round(2^i / N) / 2^(i - BN_num_bits(N)))|
175 * <= |(m / 2^BN_num_bits(N)) * (2^i / N) * (2^BN_num_bits(N) / 2^i)|
176 * = |m/N|
177 */
178 if (!BN_rshift(a,m,recp->num_bits)) goto err;
179 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
180 if (!BN_rshift(d,b,i-recp->num_bits)) goto err;
181 d->neg=0;
182
183 if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
184 if (!BN_usub(r,m,b)) goto err;
185 r->neg=0;
186
187#if 1
188 j=0;
189 while (BN_ucmp(r,&(recp->N)) >= 0)
190 {
191 if (j++ > 2)
192 {
193 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
194 goto err;
195 }
196 if (!BN_usub(r,r,&(recp->N))) goto err;
197 if (!BN_add_word(d,1)) goto err;
198 }
199#endif
200
201 r->neg=BN_is_zero(r)?0:m->neg;
202 d->neg=m->neg^recp->N.neg;
203 ret=1;
204err:
205 BN_CTX_end(ctx);
206 return(ret);
207 }
208
209/* len is the expected size of the result
210 * We actually calculate with an extra word of precision, so
211 * we can do faster division if the remainder is not required.
212 */
213/* r := 2^len / m */
214int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx)
215 {
216 int ret= -1;
217 BIGNUM t;
218
219 BN_init(&t);
220
221 if (!BN_zero(&t)) goto err;
222 if (!BN_set_bit(&t,len)) goto err;
223
224 if (!BN_div(r,NULL,&t,m,ctx)) goto err;
225
226 ret=len;
227err:
228 BN_free(&t);
229 return(ret);
230 }
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c
new file mode 100644
index 0000000000..70f785ea18
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_shift.c
@@ -0,0 +1,205 @@
1/* crypto/bn/bn_shift.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63int BN_lshift1(BIGNUM *r, const BIGNUM *a)
64 {
65 register BN_ULONG *ap,*rp,t,c;
66 int i;
67
68 if (r != a)
69 {
70 r->neg=a->neg;
71 if (bn_wexpand(r,a->top+1) == NULL) return(0);
72 r->top=a->top;
73 }
74 else
75 {
76 if (bn_wexpand(r,a->top+1) == NULL) return(0);
77 }
78 ap=a->d;
79 rp=r->d;
80 c=0;
81 for (i=0; i<a->top; i++)
82 {
83 t= *(ap++);
84 *(rp++)=((t<<1)|c)&BN_MASK2;
85 c=(t & BN_TBIT)?1:0;
86 }
87 if (c)
88 {
89 *rp=1;
90 r->top++;
91 }
92 return(1);
93 }
94
95int BN_rshift1(BIGNUM *r, const BIGNUM *a)
96 {
97 BN_ULONG *ap,*rp,t,c;
98 int i;
99
100 if (BN_is_zero(a))
101 {
102 BN_zero(r);
103 return(1);
104 }
105 if (a != r)
106 {
107 if (bn_wexpand(r,a->top) == NULL) return(0);
108 r->top=a->top;
109 r->neg=a->neg;
110 }
111 ap=a->d;
112 rp=r->d;
113 c=0;
114 for (i=a->top-1; i>=0; i--)
115 {
116 t=ap[i];
117 rp[i]=((t>>1)&BN_MASK2)|c;
118 c=(t&1)?BN_TBIT:0;
119 }
120 bn_fix_top(r);
121 return(1);
122 }
123
124int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
125 {
126 int i,nw,lb,rb;
127 BN_ULONG *t,*f;
128 BN_ULONG l;
129
130 r->neg=a->neg;
131 nw=n/BN_BITS2;
132 if (bn_wexpand(r,a->top+nw+1) == NULL) return(0);
133 lb=n%BN_BITS2;
134 rb=BN_BITS2-lb;
135 f=a->d;
136 t=r->d;
137 t[a->top+nw]=0;
138 if (lb == 0)
139 for (i=a->top-1; i>=0; i--)
140 t[nw+i]=f[i];
141 else
142 for (i=a->top-1; i>=0; i--)
143 {
144 l=f[i];
145 t[nw+i+1]|=(l>>rb)&BN_MASK2;
146 t[nw+i]=(l<<lb)&BN_MASK2;
147 }
148 memset(t,0,nw*sizeof(t[0]));
149/* for (i=0; i<nw; i++)
150 t[i]=0;*/
151 r->top=a->top+nw+1;
152 bn_fix_top(r);
153 return(1);
154 }
155
156int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
157 {
158 int i,j,nw,lb,rb;
159 BN_ULONG *t,*f;
160 BN_ULONG l,tmp;
161
162 nw=n/BN_BITS2;
163 rb=n%BN_BITS2;
164 lb=BN_BITS2-rb;
165 if (nw > a->top || a->top == 0)
166 {
167 BN_zero(r);
168 return(1);
169 }
170 if (r != a)
171 {
172 r->neg=a->neg;
173 if (bn_wexpand(r,a->top-nw+1) == NULL) return(0);
174 }
175 else
176 {
177 if (n == 0)
178 return 1; /* or the copying loop will go berserk */
179 }
180
181 f= &(a->d[nw]);
182 t=r->d;
183 j=a->top-nw;
184 r->top=j;
185
186 if (rb == 0)
187 {
188 for (i=j+1; i > 0; i--)
189 *(t++)= *(f++);
190 }
191 else
192 {
193 l= *(f++);
194 for (i=1; i<j; i++)
195 {
196 tmp =(l>>rb)&BN_MASK2;
197 l= *(f++);
198 *(t++) =(tmp|(l<<lb))&BN_MASK2;
199 }
200 *(t++) =(l>>rb)&BN_MASK2;
201 }
202 *t=0;
203 bn_fix_top(r);
204 return(1);
205 }
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
new file mode 100644
index 0000000000..c1d0cca438
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -0,0 +1,288 @@
1/* crypto/bn/bn_sqr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63/* r must not be a */
64/* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */
65int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
66 {
67 int max,al;
68 int ret = 0;
69 BIGNUM *tmp,*rr;
70
71#ifdef BN_COUNT
72 fprintf(stderr,"BN_sqr %d * %d\n",a->top,a->top);
73#endif
74 bn_check_top(a);
75
76 al=a->top;
77 if (al <= 0)
78 {
79 r->top=0;
80 return(1);
81 }
82
83 BN_CTX_start(ctx);
84 rr=(a != r) ? r : BN_CTX_get(ctx);
85 tmp=BN_CTX_get(ctx);
86 if (tmp == NULL) goto err;
87
88 max=(al+al);
89 if (bn_wexpand(rr,max+1) == NULL) goto err;
90
91 if (al == 4)
92 {
93#ifndef BN_SQR_COMBA
94 BN_ULONG t[8];
95 bn_sqr_normal(rr->d,a->d,4,t);
96#else
97 bn_sqr_comba4(rr->d,a->d);
98#endif
99 }
100 else if (al == 8)
101 {
102#ifndef BN_SQR_COMBA
103 BN_ULONG t[16];
104 bn_sqr_normal(rr->d,a->d,8,t);
105#else
106 bn_sqr_comba8(rr->d,a->d);
107#endif
108 }
109 else
110 {
111#if defined(BN_RECURSION)
112 if (al < BN_SQR_RECURSIVE_SIZE_NORMAL)
113 {
114 BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];
115 bn_sqr_normal(rr->d,a->d,al,t);
116 }
117 else
118 {
119 int j,k;
120
121 j=BN_num_bits_word((BN_ULONG)al);
122 j=1<<(j-1);
123 k=j+j;
124 if (al == j)
125 {
126 if (bn_wexpand(tmp,k*2) == NULL) goto err;
127 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
128 }
129 else
130 {
131 if (bn_wexpand(tmp,max) == NULL) goto err;
132 bn_sqr_normal(rr->d,a->d,al,tmp->d);
133 }
134 }
135#else
136 if (bn_wexpand(tmp,max) == NULL) goto err;
137 bn_sqr_normal(rr->d,a->d,al,tmp->d);
138#endif
139 }
140
141 rr->top=max;
142 rr->neg=0;
143 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
144 if (rr != r) BN_copy(r,rr);
145 ret = 1;
146 err:
147 BN_CTX_end(ctx);
148 return(ret);
149 }
150
151/* tmp must have 2*n words */
152void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
153 {
154 int i,j,max;
155 const BN_ULONG *ap;
156 BN_ULONG *rp;
157
158 max=n*2;
159 ap=a;
160 rp=r;
161 rp[0]=rp[max-1]=0;
162 rp++;
163 j=n;
164
165 if (--j > 0)
166 {
167 ap++;
168 rp[j]=bn_mul_words(rp,ap,j,ap[-1]);
169 rp+=2;
170 }
171
172 for (i=n-2; i>0; i--)
173 {
174 j--;
175 ap++;
176 rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);
177 rp+=2;
178 }
179
180 bn_add_words(r,r,r,max);
181
182 /* There will not be a carry */
183
184 bn_sqr_words(tmp,a,n);
185
186 bn_add_words(r,r,tmp,max);
187 }
188
189#ifdef BN_RECURSION
190/* r is 2*n words in size,
191 * a and b are both n words in size. (There's not actually a 'b' here ...)
192 * n must be a power of 2.
193 * We multiply and return the result.
194 * t must be 2*n words in size
195 * We calculate
196 * a[0]*b[0]
197 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
198 * a[1]*b[1]
199 */
200void bn_sqr_recursive(BN_ULONG *r, const BN_ULONG *a, int n2, BN_ULONG *t)
201 {
202 int n=n2/2;
203 int zero,c1;
204 BN_ULONG ln,lo,*p;
205
206#ifdef BN_COUNT
207 fprintf(stderr," bn_sqr_recursive %d * %d\n",n2,n2);
208#endif
209 if (n2 == 4)
210 {
211#ifndef BN_SQR_COMBA
212 bn_sqr_normal(r,a,4,t);
213#else
214 bn_sqr_comba4(r,a);
215#endif
216 return;
217 }
218 else if (n2 == 8)
219 {
220#ifndef BN_SQR_COMBA
221 bn_sqr_normal(r,a,8,t);
222#else
223 bn_sqr_comba8(r,a);
224#endif
225 return;
226 }
227 if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL)
228 {
229 bn_sqr_normal(r,a,n2,t);
230 return;
231 }
232 /* r=(a[0]-a[1])*(a[1]-a[0]) */
233 c1=bn_cmp_words(a,&(a[n]),n);
234 zero=0;
235 if (c1 > 0)
236 bn_sub_words(t,a,&(a[n]),n);
237 else if (c1 < 0)
238 bn_sub_words(t,&(a[n]),a,n);
239 else
240 zero=1;
241
242 /* The result will always be negative unless it is zero */
243 p= &(t[n2*2]);
244
245 if (!zero)
246 bn_sqr_recursive(&(t[n2]),t,n,p);
247 else
248 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
249 bn_sqr_recursive(r,a,n,p);
250 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p);
251
252 /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero
253 * r[10] holds (a[0]*b[0])
254 * r[32] holds (b[1]*b[1])
255 */
256
257 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
258
259 /* t[32] is negative */
260 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
261
262 /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1])
263 * r[10] holds (a[0]*a[0])
264 * r[32] holds (a[1]*a[1])
265 * c1 holds the carry bits
266 */
267 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
268 if (c1)
269 {
270 p= &(r[n+n2]);
271 lo= *p;
272 ln=(lo+c1)&BN_MASK2;
273 *p=ln;
274
275 /* The overflow will stop before we over write
276 * words we should not overwrite */
277 if (ln < (BN_ULONG)c1)
278 {
279 do {
280 p++;
281 lo= *p;
282 ln=(lo+1)&BN_MASK2;
283 *p=ln;
284 } while (ln == 0);
285 }
286 }
287 }
288#endif
diff --git a/src/lib/libcrypto/bn/bn_sqrt.c b/src/lib/libcrypto/bn/bn_sqrt.c
new file mode 100644
index 0000000000..e2a1105dc8
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_sqrt.c
@@ -0,0 +1,387 @@
1/* crypto/bn/bn_mod.c */
2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * and Bodo Moeller for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include "cryptlib.h"
59#include "bn_lcl.h"
60
61
62BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
63/* Returns 'ret' such that
64 * ret^2 == a (mod p),
65 * using the Tonelli/Shanks algorithm (cf. Henri Cohen, "A Course
66 * in Algebraic Computational Number Theory", algorithm 1.5.1).
67 * 'p' must be prime!
68 * If 'a' is not a square, this is not necessarily detected by
69 * the algorithms; a bogus result must be expected in this case.
70 */
71 {
72 BIGNUM *ret = in;
73 int err = 1;
74 int r;
75 BIGNUM *b, *q, *t, *x, *y;
76 int e, i, j;
77
78 if (!BN_is_odd(p) || BN_abs_is_word(p, 1))
79 {
80 if (BN_abs_is_word(p, 2))
81 {
82 if (ret == NULL)
83 ret = BN_new();
84 if (ret == NULL)
85 goto end;
86 if (!BN_set_word(ret, BN_is_bit_set(a, 0)))
87 {
88 BN_free(ret);
89 return NULL;
90 }
91 return ret;
92 }
93
94 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
95 return(NULL);
96 }
97
98 if (BN_is_zero(a) || BN_is_one(a))
99 {
100 if (ret == NULL)
101 ret = BN_new();
102 if (ret == NULL)
103 goto end;
104 if (!BN_set_word(ret, BN_is_one(a)))
105 {
106 BN_free(ret);
107 return NULL;
108 }
109 return ret;
110 }
111
112#if 0 /* if BN_mod_sqrt is used with correct input, this just wastes time */
113 r = BN_kronecker(a, p, ctx);
114 if (r < -1) return NULL;
115 if (r == -1)
116 {
117 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
118 return(NULL);
119 }
120#endif
121
122 BN_CTX_start(ctx);
123 b = BN_CTX_get(ctx);
124 q = BN_CTX_get(ctx);
125 t = BN_CTX_get(ctx);
126 x = BN_CTX_get(ctx);
127 y = BN_CTX_get(ctx);
128 if (y == NULL) goto end;
129
130 if (ret == NULL)
131 ret = BN_new();
132 if (ret == NULL) goto end;
133
134 /* now write |p| - 1 as 2^e*q where q is odd */
135 e = 1;
136 while (!BN_is_bit_set(p, e))
137 e++;
138 /* we'll set q later (if needed) */
139
140 if (e == 1)
141 {
142 /* The easy case: (|p|-1)/2 is odd, so 2 has an inverse
143 * modulo (|p|-1)/2, and square roots can be computed
144 * directly by modular exponentiation.
145 * We have
146 * 2 * (|p|+1)/4 == 1 (mod (|p|-1)/2),
147 * so we can use exponent (|p|+1)/4, i.e. (|p|-3)/4 + 1.
148 */
149 if (!BN_rshift(q, p, 2)) goto end;
150 q->neg = 0;
151 if (!BN_add_word(q, 1)) goto end;
152 if (!BN_mod_exp(ret, a, q, p, ctx)) goto end;
153 err = 0;
154 goto end;
155 }
156
157 if (e == 2)
158 {
159 /* |p| == 5 (mod 8)
160 *
161 * In this case 2 is always a non-square since
162 * Legendre(2,p) = (-1)^((p^2-1)/8) for any odd prime.
163 * So if a really is a square, then 2*a is a non-square.
164 * Thus for
165 * b := (2*a)^((|p|-5)/8),
166 * i := (2*a)*b^2
167 * we have
168 * i^2 = (2*a)^((1 + (|p|-5)/4)*2)
169 * = (2*a)^((p-1)/2)
170 * = -1;
171 * so if we set
172 * x := a*b*(i-1),
173 * then
174 * x^2 = a^2 * b^2 * (i^2 - 2*i + 1)
175 * = a^2 * b^2 * (-2*i)
176 * = a*(-i)*(2*a*b^2)
177 * = a*(-i)*i
178 * = a.
179 *
180 * (This is due to A.O.L. Atkin,
181 * <URL: http://listserv.nodak.edu/scripts/wa.exe?A2=ind9211&L=nmbrthry&O=T&P=562>,
182 * November 1992.)
183 */
184
185 /* make sure that a is reduced modulo p */
186 if (a->neg || BN_ucmp(a, p) >= 0)
187 {
188 if (!BN_nnmod(x, a, p, ctx)) goto end;
189 a = x; /* use x as temporary variable */
190 }
191
192 /* t := 2*a */
193 if (!BN_mod_lshift1_quick(t, a, p)) goto end;
194
195 /* b := (2*a)^((|p|-5)/8) */
196 if (!BN_rshift(q, p, 3)) goto end;
197 q->neg = 0;
198 if (!BN_mod_exp(b, t, q, p, ctx)) goto end;
199
200 /* y := b^2 */
201 if (!BN_mod_sqr(y, b, p, ctx)) goto end;
202
203 /* t := (2*a)*b^2 - 1*/
204 if (!BN_mod_mul(t, t, y, p, ctx)) goto end;
205 if (!BN_sub_word(t, 1)) goto end;
206
207 /* x = a*b*t */
208 if (!BN_mod_mul(x, a, b, p, ctx)) goto end;
209 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
210
211 if (!BN_copy(ret, x)) goto end;
212 err = 0;
213 goto end;
214 }
215
216 /* e > 2, so we really have to use the Tonelli/Shanks algorithm.
217 * First, find some y that is not a square. */
218 if (!BN_copy(q, p)) goto end; /* use 'q' as temp */
219 q->neg = 0;
220 i = 2;
221 do
222 {
223 /* For efficiency, try small numbers first;
224 * if this fails, try random numbers.
225 */
226 if (i < 22)
227 {
228 if (!BN_set_word(y, i)) goto end;
229 }
230 else
231 {
232 if (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0)) goto end;
233 if (BN_ucmp(y, p) >= 0)
234 {
235 if (!(p->neg ? BN_add : BN_sub)(y, y, p)) goto end;
236 }
237 /* now 0 <= y < |p| */
238 if (BN_is_zero(y))
239 if (!BN_set_word(y, i)) goto end;
240 }
241
242 r = BN_kronecker(y, q, ctx); /* here 'q' is |p| */
243 if (r < -1) goto end;
244 if (r == 0)
245 {
246 /* m divides p */
247 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
248 goto end;
249 }
250 }
251 while (r == 1 && ++i < 82);
252
253 if (r != -1)
254 {
255 /* Many rounds and still no non-square -- this is more likely
256 * a bug than just bad luck.
257 * Even if p is not prime, we should have found some y
258 * such that r == -1.
259 */
260 BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);
261 goto end;
262 }
263
264 /* Here's our actual 'q': */
265 if (!BN_rshift(q, q, e)) goto end;
266
267 /* Now that we have some non-square, we can find an element
268 * of order 2^e by computing its q'th power. */
269 if (!BN_mod_exp(y, y, q, p, ctx)) goto end;
270 if (BN_is_one(y))
271 {
272 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
273 goto end;
274 }
275
276 /* Now we know that (if p is indeed prime) there is an integer
277 * k, 0 <= k < 2^e, such that
278 *
279 * a^q * y^k == 1 (mod p).
280 *
281 * As a^q is a square and y is not, k must be even.
282 * q+1 is even, too, so there is an element
283 *
284 * X := a^((q+1)/2) * y^(k/2),
285 *
286 * and it satisfies
287 *
288 * X^2 = a^q * a * y^k
289 * = a,
290 *
291 * so it is the square root that we are looking for.
292 */
293
294 /* t := (q-1)/2 (note that q is odd) */
295 if (!BN_rshift1(t, q)) goto end;
296
297 /* x := a^((q-1)/2) */
298 if (BN_is_zero(t)) /* special case: p = 2^e + 1 */
299 {
300 if (!BN_nnmod(t, a, p, ctx)) goto end;
301 if (BN_is_zero(t))
302 {
303 /* special case: a == 0 (mod p) */
304 if (!BN_zero(ret)) goto end;
305 err = 0;
306 goto end;
307 }
308 else
309 if (!BN_one(x)) goto end;
310 }
311 else
312 {
313 if (!BN_mod_exp(x, a, t, p, ctx)) goto end;
314 if (BN_is_zero(x))
315 {
316 /* special case: a == 0 (mod p) */
317 if (!BN_zero(ret)) goto end;
318 err = 0;
319 goto end;
320 }
321 }
322
323 /* b := a*x^2 (= a^q) */
324 if (!BN_mod_sqr(b, x, p, ctx)) goto end;
325 if (!BN_mod_mul(b, b, a, p, ctx)) goto end;
326
327 /* x := a*x (= a^((q+1)/2)) */
328 if (!BN_mod_mul(x, x, a, p, ctx)) goto end;
329
330 while (1)
331 {
332 /* Now b is a^q * y^k for some even k (0 <= k < 2^E
333 * where E refers to the original value of e, which we
334 * don't keep in a variable), and x is a^((q+1)/2) * y^(k/2).
335 *
336 * We have a*b = x^2,
337 * y^2^(e-1) = -1,
338 * b^2^(e-1) = 1.
339 */
340
341 if (BN_is_one(b))
342 {
343 if (!BN_copy(ret, x)) goto end;
344 err = 0;
345 goto end;
346 }
347
348
349 /* find smallest i such that b^(2^i) = 1 */
350 i = 1;
351 if (!BN_mod_sqr(t, b, p, ctx)) goto end;
352 while (!BN_is_one(t))
353 {
354 i++;
355 if (i == e)
356 {
357 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
358 goto end;
359 }
360 if (!BN_mod_mul(t, t, t, p, ctx)) goto end;
361 }
362
363
364 /* t := y^2^(e - i - 1) */
365 if (!BN_copy(t, y)) goto end;
366 for (j = e - i - 1; j > 0; j--)
367 {
368 if (!BN_mod_sqr(t, t, p, ctx)) goto end;
369 }
370 if (!BN_mod_mul(y, t, t, p, ctx)) goto end;
371 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
372 if (!BN_mod_mul(b, b, y, p, ctx)) goto end;
373 e = i;
374 }
375
376 end:
377 if (err)
378 {
379 if (ret != NULL && ret != in)
380 {
381 BN_clear_free(ret);
382 }
383 ret = NULL;
384 }
385 BN_CTX_end(ctx);
386 return ret;
387 }
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
new file mode 100644
index 0000000000..de610ce54c
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -0,0 +1,208 @@
1/* crypto/bn/bn_word.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
64 {
65#ifndef BN_LLONG
66 BN_ULONG ret=0;
67#else
68 BN_ULLONG ret=0;
69#endif
70 int i;
71
72 w&=BN_MASK2;
73 for (i=a->top-1; i>=0; i--)
74 {
75#ifndef BN_LLONG
76 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w;
77 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w;
78#else
79 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%
80 (BN_ULLONG)w);
81#endif
82 }
83 return((BN_ULONG)ret);
84 }
85
86BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
87 {
88 BN_ULONG ret;
89 int i;
90
91 if (a->top == 0) return(0);
92 ret=0;
93 w&=BN_MASK2;
94 for (i=a->top-1; i>=0; i--)
95 {
96 BN_ULONG l,d;
97
98 l=a->d[i];
99 d=bn_div_words(ret,l,w);
100 ret=(l-((d*w)&BN_MASK2))&BN_MASK2;
101 a->d[i]=d;
102 }
103 if ((a->top > 0) && (a->d[a->top-1] == 0))
104 a->top--;
105 return(ret);
106 }
107
108int BN_add_word(BIGNUM *a, BN_ULONG w)
109 {
110 BN_ULONG l;
111 int i;
112
113 if ((w & BN_MASK2) == 0)
114 return(1);
115
116 if (a->neg)
117 {
118 a->neg=0;
119 i=BN_sub_word(a,w);
120 if (!BN_is_zero(a))
121 a->neg=!(a->neg);
122 return(i);
123 }
124 w&=BN_MASK2;
125 if (bn_wexpand(a,a->top+1) == NULL) return(0);
126 i=0;
127 for (;;)
128 {
129 if (i >= a->top)
130 l=w;
131 else
132 l=(a->d[i]+(BN_ULONG)w)&BN_MASK2;
133 a->d[i]=l;
134 if (w > l)
135 w=1;
136 else
137 break;
138 i++;
139 }
140 if (i >= a->top)
141 a->top++;
142 return(1);
143 }
144
145int BN_sub_word(BIGNUM *a, BN_ULONG w)
146 {
147 int i;
148
149 if ((w & BN_MASK2) == 0)
150 return(1);
151
152 if (BN_is_zero(a) || a->neg)
153 {
154 a->neg=0;
155 i=BN_add_word(a,w);
156 a->neg=1;
157 return(i);
158 }
159
160 w&=BN_MASK2;
161 if ((a->top == 1) && (a->d[0] < w))
162 {
163 a->d[0]=w-a->d[0];
164 a->neg=1;
165 return(1);
166 }
167 i=0;
168 for (;;)
169 {
170 if (a->d[i] >= w)
171 {
172 a->d[i]-=w;
173 break;
174 }
175 else
176 {
177 a->d[i]=(a->d[i]-w)&BN_MASK2;
178 i++;
179 w=1;
180 }
181 }
182 if ((a->d[i] == 0) && (i == (a->top-1)))
183 a->top--;
184 return(1);
185 }
186
187int BN_mul_word(BIGNUM *a, BN_ULONG w)
188 {
189 BN_ULONG ll;
190
191 w&=BN_MASK2;
192 if (a->top)
193 {
194 if (w == 0)
195 BN_zero(a);
196 else
197 {
198 ll=bn_mul_words(a->d,a->d,a->top,w);
199 if (ll)
200 {
201 if (bn_wexpand(a,a->top+1) == NULL) return(0);
202 a->d[a->top++]=ll;
203 }
204 }
205 }
206 return(1);
207 }
208
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c
index 685007d330..79d813d85e 100644
--- a/src/lib/libcrypto/bn/bntest.c
+++ b/src/lib/libcrypto/bn/bntest.c
@@ -86,7 +86,6 @@ int test_mont(BIO *bp,BN_CTX *ctx);
86int test_mod(BIO *bp,BN_CTX *ctx); 86int test_mod(BIO *bp,BN_CTX *ctx);
87int test_mod_mul(BIO *bp,BN_CTX *ctx); 87int test_mod_mul(BIO *bp,BN_CTX *ctx);
88int test_mod_exp(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); 89int test_exp(BIO *bp,BN_CTX *ctx);
91int test_kron(BIO *bp,BN_CTX *ctx); 90int test_kron(BIO *bp,BN_CTX *ctx);
92int test_sqrt(BIO *bp,BN_CTX *ctx); 91int test_sqrt(BIO *bp,BN_CTX *ctx);
@@ -214,10 +213,6 @@ int main(int argc, char *argv[])
214 if (!test_mod_exp(out,ctx)) goto err; 213 if (!test_mod_exp(out,ctx)) goto err;
215 BIO_flush(out); 214 BIO_flush(out);
216 215
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"); 216 message(out,"BN_exp");
222 if (!test_exp(out,ctx)) goto err; 217 if (!test_exp(out,ctx)) goto err;
223 BIO_flush(out); 218 BIO_flush(out);
@@ -785,58 +780,7 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx)
785 BN_bntest_rand(b,2+i,0,0); /**/ 780 BN_bntest_rand(b,2+i,0,0); /**/
786 781
787 if (!BN_mod_exp(d,a,b,c,ctx)) 782 if (!BN_mod_exp(d,a,b,c,ctx))
788 return(00); 783 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 784
841 if (bp != NULL) 785 if (bp != NULL)
842 { 786 {
@@ -887,7 +831,7 @@ int test_exp(BIO *bp, BN_CTX *ctx)
887 BN_bntest_rand(b,2+i,0,0); /**/ 831 BN_bntest_rand(b,2+i,0,0); /**/
888 832
889 if (!BN_exp(d,a,b,ctx)) 833 if (!BN_exp(d,a,b,ctx))
890 return(00); 834 return(0);
891 835
892 if (bp != NULL) 836 if (bp != NULL)
893 { 837 {
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c
index 4d5f221f33..07a1bcf51c 100644
--- a/src/lib/libcrypto/bn/expspeed.c
+++ b/src/lib/libcrypto/bn/expspeed.c
@@ -321,7 +321,7 @@ void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx)
321#else /* TEST_SQRT */ 321#else /* TEST_SQRT */
322 "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d" 322 "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d"
323#endif 323#endif
324 " -> %8.6fms %5.1f (%ld)\n", 324 " -> %8.3fms %5.1f (%ld)\n",
325#ifdef TEST_SQRT 325#ifdef TEST_SQRT
326 P_MOD_64, 326 P_MOD_64,
327#endif 327#endif
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c
index 28aaac2ac1..b09cf88705 100644
--- a/src/lib/libcrypto/bn/exptest.c
+++ b/src/lib/libcrypto/bn/exptest.c
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
77 BIO *out=NULL; 77 BIO *out=NULL;
78 int i,ret; 78 int i,ret;
79 unsigned char c; 79 unsigned char c;
80 BIGNUM *r_mont,*r_mont_const,*r_recp,*r_simple,*a,*b,*m; 80 BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m;
81 81
82 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't 82 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't
83 * even check its return value 83 * even check its return value
@@ -88,7 +88,6 @@ int main(int argc, char *argv[])
88 ctx=BN_CTX_new(); 88 ctx=BN_CTX_new();
89 if (ctx == NULL) EXIT(1); 89 if (ctx == NULL) EXIT(1);
90 r_mont=BN_new(); 90 r_mont=BN_new();
91 r_mont_const=BN_new();
92 r_recp=BN_new(); 91 r_recp=BN_new();
93 r_simple=BN_new(); 92 r_simple=BN_new();
94 a=BN_new(); 93 a=BN_new();
@@ -144,17 +143,8 @@ int main(int argc, char *argv[])
144 EXIT(1); 143 EXIT(1);
145 } 144 }
146 145
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 146 if (BN_cmp(r_simple, r_mont) == 0
156 && BN_cmp(r_simple,r_recp) == 0 147 && BN_cmp(r_simple,r_recp) == 0)
157 && BN_cmp(r_simple,r_mont_const) == 0)
158 { 148 {
159 printf("."); 149 printf(".");
160 fflush(stdout); 150 fflush(stdout);
@@ -163,8 +153,6 @@ int main(int argc, char *argv[])
163 { 153 {
164 if (BN_cmp(r_simple,r_mont) != 0) 154 if (BN_cmp(r_simple,r_mont) != 0)
165 printf("\nsimple and mont results differ\n"); 155 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) 156 if (BN_cmp(r_simple,r_recp) != 0)
169 printf("\nsimple and recp results differ\n"); 157 printf("\nsimple and recp results differ\n");
170 158
@@ -174,13 +162,11 @@ int main(int argc, char *argv[])
174 printf("\nsimple ="); BN_print(out,r_simple); 162 printf("\nsimple ="); BN_print(out,r_simple);
175 printf("\nrecp ="); BN_print(out,r_recp); 163 printf("\nrecp ="); BN_print(out,r_recp);
176 printf("\nmont ="); BN_print(out,r_mont); 164 printf("\nmont ="); BN_print(out,r_mont);
177 printf("\nmont_ct ="); BN_print(out,r_mont_const);
178 printf("\n"); 165 printf("\n");
179 EXIT(1); 166 EXIT(1);
180 } 167 }
181 } 168 }
182 BN_free(r_mont); 169 BN_free(r_mont);
183 BN_free(r_mont_const);
184 BN_free(r_recp); 170 BN_free(r_recp);
185 BN_free(r_simple); 171 BN_free(r_simple);
186 BN_free(a); 172 BN_free(a);
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
new file mode 100644
index 0000000000..5eee653e14
--- /dev/null
+++ b/src/lib/libcrypto/buffer/buf_err.c
@@ -0,0 +1,95 @@
1/* crypto/buffer/buf_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/buffer.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA BUF_str_functs[]=
68 {
69{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"},
70{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"},
71{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"},
72{0,NULL}
73 };
74
75static ERR_STRING_DATA BUF_str_reasons[]=
76 {
77{0,NULL}
78 };
79
80#endif
81
82void ERR_load_BUF_strings(void)
83 {
84 static int init=1;
85
86 if (init)
87 {
88 init=0;
89#ifndef OPENSSL_NO_ERR
90 ERR_load_strings(ERR_LIB_BUF,BUF_str_functs);
91 ERR_load_strings(ERR_LIB_BUF,BUF_str_reasons);
92#endif
93
94 }
95 }
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
new file mode 100644
index 0000000000..d96487e7db
--- /dev/null
+++ b/src/lib/libcrypto/buffer/buffer.c
@@ -0,0 +1,202 @@
1/* crypto/buffer/buffer.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62
63BUF_MEM *BUF_MEM_new(void)
64 {
65 BUF_MEM *ret;
66
67 ret=OPENSSL_malloc(sizeof(BUF_MEM));
68 if (ret == NULL)
69 {
70 BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);
71 return(NULL);
72 }
73 ret->length=0;
74 ret->max=0;
75 ret->data=NULL;
76 return(ret);
77 }
78
79void BUF_MEM_free(BUF_MEM *a)
80 {
81 if(a == NULL)
82 return;
83
84 if (a->data != NULL)
85 {
86 memset(a->data,0,(unsigned int)a->max);
87 OPENSSL_free(a->data);
88 }
89 OPENSSL_free(a);
90 }
91
92int BUF_MEM_grow(BUF_MEM *str, int len)
93 {
94 char *ret;
95 unsigned int n;
96
97 if (str->length >= len)
98 {
99 str->length=len;
100 return(len);
101 }
102 if (str->max >= len)
103 {
104 memset(&str->data[str->length],0,len-str->length);
105 str->length=len;
106 return(len);
107 }
108 n=(len+3)/3*4;
109 if (str->data == NULL)
110 ret=OPENSSL_malloc(n);
111 else
112 ret=OPENSSL_realloc(str->data,n);
113 if (ret == NULL)
114 {
115 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
116 len=0;
117 }
118 else
119 {
120 str->data=ret;
121 str->max=n;
122 memset(&str->data[str->length],0,len-str->length);
123 str->length=len;
124 }
125 return(len);
126 }
127
128int BUF_MEM_grow_clean(BUF_MEM *str, int len)
129 {
130 char *ret;
131 unsigned int n;
132
133 if (str->length >= len)
134 {
135 memset(&str->data[len],0,str->length-len);
136 str->length=len;
137 return(len);
138 }
139 if (str->max >= len)
140 {
141 memset(&str->data[str->length],0,len-str->length);
142 str->length=len;
143 return(len);
144 }
145 n=(len+3)/3*4;
146 if (str->data == NULL)
147 ret=OPENSSL_malloc(n);
148 else
149 ret=OPENSSL_realloc_clean(str->data,str->max,n);
150 if (ret == NULL)
151 {
152 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
153 len=0;
154 }
155 else
156 {
157 str->data=ret;
158 str->max=n;
159 memset(&str->data[str->length],0,len-str->length);
160 str->length=len;
161 }
162 return(len);
163 }
164
165char *BUF_strdup(const char *str)
166 {
167 char *ret;
168 int n;
169
170 if (str == NULL) return(NULL);
171
172 n=strlen(str);
173 ret=OPENSSL_malloc(n+1);
174 if (ret == NULL)
175 {
176 BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
177 return(NULL);
178 }
179 memcpy(ret,str,n+1);
180 return(ret);
181 }
182
183size_t BUF_strlcpy(char *dst, const char *src, size_t size)
184 {
185 size_t l = 0;
186 for(; size > 1 && *src; size--)
187 {
188 *dst++ = *src++;
189 l++;
190 }
191 if (size)
192 *dst = '\0';
193 return l + strlen(src);
194 }
195
196size_t BUF_strlcat(char *dst, const char *src, size_t size)
197 {
198 size_t l = 0;
199 for(; size > 0 && *dst; size--, dst++)
200 l++;
201 return l + BUF_strlcpy(dst, src, size);
202 }
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h
new file mode 100644
index 0000000000..465dc34f3f
--- /dev/null
+++ b/src/lib/libcrypto/buffer/buffer.h
@@ -0,0 +1,105 @@
1/* crypto/buffer/buffer.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BUFFER_H
60#define HEADER_BUFFER_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <stddef.h>
67#include <sys/types.h>
68
69typedef struct buf_mem_st
70 {
71 int length; /* current number of bytes */
72 char *data;
73 int max; /* size of buffer */
74 } BUF_MEM;
75
76BUF_MEM *BUF_MEM_new(void);
77void BUF_MEM_free(BUF_MEM *a);
78int BUF_MEM_grow(BUF_MEM *str, int len);
79int BUF_MEM_grow_clean(BUF_MEM *str, int len);
80char * BUF_strdup(const char *str);
81
82/* safe string functions */
83size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
84size_t BUF_strlcat(char *dst,const char *src,size_t siz);
85
86
87/* BEGIN ERROR CODES */
88/* The following lines are auto generated by the script mkerr.pl. Any changes
89 * made after this point may be overwritten when the script is next run.
90 */
91void ERR_load_BUF_strings(void);
92
93/* Error codes for the BUF functions. */
94
95/* Function codes. */
96#define BUF_F_BUF_MEM_GROW 100
97#define BUF_F_BUF_MEM_NEW 101
98#define BUF_F_BUF_STRDUP 102
99
100/* Reason codes. */
101
102#ifdef __cplusplus
103}
104#endif
105#endif
diff --git a/src/lib/libcrypto/cast/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
new file mode 100644
index 0000000000..0ed55d1905
--- /dev/null
+++ b/src/lib/libcrypto/cast/asm/cast-586.pl
@@ -0,0 +1,176 @@
1#!/usr/local/bin/perl
2
3# define for pentium pro friendly version
4$ppro=1;
5
6push(@INC,"perlasm","../../perlasm");
7require "x86asm.pl";
8require "cbc.pl";
9
10&asm_init($ARGV[0],"cast-586.pl",$ARGV[$#ARGV] eq "386");
11
12$CAST_ROUNDS=16;
13$L="edi";
14$R="esi";
15$K="ebp";
16$tmp1="ecx";
17$tmp2="ebx";
18$tmp3="eax";
19$tmp4="edx";
20$S1="CAST_S_table0";
21$S2="CAST_S_table1";
22$S3="CAST_S_table2";
23$S4="CAST_S_table3";
24
25@F1=("add","xor","sub");
26@F2=("xor","sub","add");
27@F3=("sub","add","xor");
28
29&CAST_encrypt("CAST_encrypt",1);
30&CAST_encrypt("CAST_decrypt",0);
31&cbc("CAST_cbc_encrypt","CAST_encrypt","CAST_decrypt",1,4,5,3,-1,-1) unless $main'openbsd;
32
33&asm_finish();
34
35sub CAST_encrypt {
36 local($name,$enc)=@_;
37
38 local($win_ex)=<<"EOF";
39EXTERN _CAST_S_table0:DWORD
40EXTERN _CAST_S_table1:DWORD
41EXTERN _CAST_S_table2:DWORD
42EXTERN _CAST_S_table3:DWORD
43EOF
44 &main::external_label(
45 "CAST_S_table0",
46 "CAST_S_table1",
47 "CAST_S_table2",
48 "CAST_S_table3",
49 );
50
51 &function_begin_B($name,$win_ex);
52
53 &comment("");
54
55 &push("ebp");
56 &push("ebx");
57 &mov($tmp2,&wparam(0));
58 &mov($K,&wparam(1));
59 &push("esi");
60 &push("edi");
61
62 &comment("Load the 2 words");
63 &mov($L,&DWP(0,$tmp2,"",0));
64 &mov($R,&DWP(4,$tmp2,"",0));
65
66 &comment('Get short key flag');
67 &mov($tmp3,&DWP(128,$K,"",0));
68 if($enc) {
69 &push($tmp3);
70 } else {
71 &or($tmp3,$tmp3);
72 &jnz(&label('cast_dec_skip'));
73 }
74
75 &xor($tmp3, $tmp3);
76
77 # encrypting part
78
79 if ($enc) {
80 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
81 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
82 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
83 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
84 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
85 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
86 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
87 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
88 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
89 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
90 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
91 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
92 &comment('test short key flag');
93 &pop($tmp4);
94 &or($tmp4,$tmp4);
95 &jnz(&label('cast_enc_done'));
96 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
97 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
98 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
99 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
100 } else {
101 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
102 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
103 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
104 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
105 &set_label('cast_dec_skip');
106 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
107 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
108 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
109 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
110 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
111 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
112 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
113 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
114 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
115 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
116 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
117 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
118 }
119
120 &set_label('cast_enc_done') if $enc;
121# Why the nop? - Ben 17/1/99
122 &nop();
123 &mov($tmp3,&wparam(0));
124 &mov(&DWP(4,$tmp3,"",0),$L);
125 &mov(&DWP(0,$tmp3,"",0),$R);
126 &function_end($name);
127}
128
129sub E_CAST {
130 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4)=@_;
131 # Ri needs to have 16 pre added.
132
133 &comment("round $i");
134 &mov( $tmp4, &DWP($i*8,$K,"",1));
135
136 &mov( $tmp1, &DWP($i*8+4,$K,"",1));
137 &$OP1( $tmp4, $R);
138
139 &rotl( $tmp4, &LB($tmp1));
140
141 if ($ppro) {
142 &mov( $tmp2, $tmp4); # B
143 &xor( $tmp1, $tmp1);
144
145 &movb( &LB($tmp1), &HB($tmp4)); # A
146 &and( $tmp2, 0xff);
147
148 &shr( $tmp4, 16); #
149 &xor( $tmp3, $tmp3);
150 } else {
151 &mov( $tmp2, $tmp4); # B
152 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD
153
154 &shr( $tmp4, 16); #
155 &and( $tmp2, 0xff);
156 }
157
158 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD
159 &and( $tmp4, 0xff); # D
160
161 &mov( $tmp1, &DWP($S1,"",$tmp1,4));
162 &mov( $tmp2, &DWP($S2,"",$tmp2,4));
163
164 &$OP2( $tmp1, $tmp2);
165 &mov( $tmp2, &DWP($S3,"",$tmp3,4));
166
167 &$OP3( $tmp1, $tmp2);
168 &mov( $tmp2, &DWP($S4,"",$tmp4,4));
169
170 &$OP1( $tmp1, $tmp2);
171 # XXX
172
173 &xor( $L, $tmp1);
174 # XXX
175}
176
diff --git a/src/lib/libcrypto/cast/c_cfb64.c b/src/lib/libcrypto/cast/c_cfb64.c
new file mode 100644
index 0000000000..514c005c32
--- /dev/null
+++ b/src/lib/libcrypto/cast/c_cfb64.c
@@ -0,0 +1,122 @@
1/* crypto/cast/c_cfb64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/cast.h>
60#include "cast_lcl.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 long length, CAST_KEY *schedule, unsigned char *ivec,
69 int *num, int enc)
70 {
71 register CAST_LONG v0,v1,t;
72 register int n= *num;
73 register long l=length;
74 CAST_LONG ti[2];
75 unsigned char *iv,c,cc;
76
77 iv=ivec;
78 if (enc)
79 {
80 while (l--)
81 {
82 if (n == 0)
83 {
84 n2l(iv,v0); ti[0]=v0;
85 n2l(iv,v1); ti[1]=v1;
86 CAST_encrypt((CAST_LONG *)ti,schedule);
87 iv=ivec;
88 t=ti[0]; l2n(t,iv);
89 t=ti[1]; l2n(t,iv);
90 iv=ivec;
91 }
92 c= *(in++)^iv[n];
93 *(out++)=c;
94 iv[n]=c;
95 n=(n+1)&0x07;
96 }
97 }
98 else
99 {
100 while (l--)
101 {
102 if (n == 0)
103 {
104 n2l(iv,v0); ti[0]=v0;
105 n2l(iv,v1); ti[1]=v1;
106 CAST_encrypt((CAST_LONG *)ti,schedule);
107 iv=ivec;
108 t=ti[0]; l2n(t,iv);
109 t=ti[1]; l2n(t,iv);
110 iv=ivec;
111 }
112 cc= *(in++);
113 c=iv[n];
114 iv[n]=cc;
115 *(out++)=c^cc;
116 n=(n+1)&0x07;
117 }
118 }
119 v0=v1=ti[0]=ti[1]=t=c=cc=0;
120 *num=n;
121 }
122
diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c
new file mode 100644
index 0000000000..0b3da9ad87
--- /dev/null
+++ b/src/lib/libcrypto/cast/c_ecb.c
@@ -0,0 +1,80 @@
1/* crypto/cast/c_ecb.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/cast.h>
60#include "cast_lcl.h"
61#include <openssl/opensslv.h>
62
63const char *CAST_version="CAST" OPENSSL_VERSION_PTEXT;
64
65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
66 CAST_KEY *ks, int enc)
67 {
68 CAST_LONG l,d[2];
69
70 n2l(in,l); d[0]=l;
71 n2l(in,l); d[1]=l;
72 if (enc)
73 CAST_encrypt(d,ks);
74 else
75 CAST_decrypt(d,ks);
76 l=d[0]; l2n(l,out);
77 l=d[1]; l2n(l,out);
78 l=d[0]=d[1]=0;
79 }
80
diff --git a/src/lib/libcrypto/cast/c_enc.c b/src/lib/libcrypto/cast/c_enc.c
new file mode 100644
index 0000000000..e80f65b698
--- /dev/null
+++ b/src/lib/libcrypto/cast/c_enc.c
@@ -0,0 +1,209 @@
1/* crypto/cast/c_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/cast.h>
60#include "cast_lcl.h"
61
62#ifndef OPENBSD_CAST_ASM
63void CAST_encrypt(CAST_LONG *data, CAST_KEY *key)
64 {
65 register CAST_LONG l,r,*k,t;
66
67 k= &(key->data[0]);
68 l=data[0];
69 r=data[1];
70
71 E_CAST( 0,k,l,r,+,^,-);
72 E_CAST( 1,k,r,l,^,-,+);
73 E_CAST( 2,k,l,r,-,+,^);
74 E_CAST( 3,k,r,l,+,^,-);
75 E_CAST( 4,k,l,r,^,-,+);
76 E_CAST( 5,k,r,l,-,+,^);
77 E_CAST( 6,k,l,r,+,^,-);
78 E_CAST( 7,k,r,l,^,-,+);
79 E_CAST( 8,k,l,r,-,+,^);
80 E_CAST( 9,k,r,l,+,^,-);
81 E_CAST(10,k,l,r,^,-,+);
82 E_CAST(11,k,r,l,-,+,^);
83 if(!key->short_key)
84 {
85 E_CAST(12,k,l,r,+,^,-);
86 E_CAST(13,k,r,l,^,-,+);
87 E_CAST(14,k,l,r,-,+,^);
88 E_CAST(15,k,r,l,+,^,-);
89 }
90
91 data[1]=l&0xffffffffL;
92 data[0]=r&0xffffffffL;
93 }
94
95void CAST_decrypt(CAST_LONG *data, CAST_KEY *key)
96 {
97 register CAST_LONG l,r,*k,t;
98
99 k= &(key->data[0]);
100 l=data[0];
101 r=data[1];
102
103 if(!key->short_key)
104 {
105 E_CAST(15,k,l,r,+,^,-);
106 E_CAST(14,k,r,l,-,+,^);
107 E_CAST(13,k,l,r,^,-,+);
108 E_CAST(12,k,r,l,+,^,-);
109 }
110 E_CAST(11,k,l,r,-,+,^);
111 E_CAST(10,k,r,l,^,-,+);
112 E_CAST( 9,k,l,r,+,^,-);
113 E_CAST( 8,k,r,l,-,+,^);
114 E_CAST( 7,k,l,r,^,-,+);
115 E_CAST( 6,k,r,l,+,^,-);
116 E_CAST( 5,k,l,r,-,+,^);
117 E_CAST( 4,k,r,l,^,-,+);
118 E_CAST( 3,k,l,r,+,^,-);
119 E_CAST( 2,k,r,l,-,+,^);
120 E_CAST( 1,k,l,r,^,-,+);
121 E_CAST( 0,k,r,l,+,^,-);
122
123 data[1]=l&0xffffffffL;
124 data[0]=r&0xffffffffL;
125 }
126#endif
127
128void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
129 CAST_KEY *ks, unsigned char *iv, int enc)
130 {
131 register CAST_LONG tin0,tin1;
132 register CAST_LONG tout0,tout1,xor0,xor1;
133 register long l=length;
134 CAST_LONG tin[2];
135
136 if (enc)
137 {
138 n2l(iv,tout0);
139 n2l(iv,tout1);
140 iv-=8;
141 for (l-=8; l>=0; l-=8)
142 {
143 n2l(in,tin0);
144 n2l(in,tin1);
145 tin0^=tout0;
146 tin1^=tout1;
147 tin[0]=tin0;
148 tin[1]=tin1;
149 CAST_encrypt(tin,ks);
150 tout0=tin[0];
151 tout1=tin[1];
152 l2n(tout0,out);
153 l2n(tout1,out);
154 }
155 if (l != -8)
156 {
157 n2ln(in,tin0,tin1,l+8);
158 tin0^=tout0;
159 tin1^=tout1;
160 tin[0]=tin0;
161 tin[1]=tin1;
162 CAST_encrypt(tin,ks);
163 tout0=tin[0];
164 tout1=tin[1];
165 l2n(tout0,out);
166 l2n(tout1,out);
167 }
168 l2n(tout0,iv);
169 l2n(tout1,iv);
170 }
171 else
172 {
173 n2l(iv,xor0);
174 n2l(iv,xor1);
175 iv-=8;
176 for (l-=8; l>=0; l-=8)
177 {
178 n2l(in,tin0);
179 n2l(in,tin1);
180 tin[0]=tin0;
181 tin[1]=tin1;
182 CAST_decrypt(tin,ks);
183 tout0=tin[0]^xor0;
184 tout1=tin[1]^xor1;
185 l2n(tout0,out);
186 l2n(tout1,out);
187 xor0=tin0;
188 xor1=tin1;
189 }
190 if (l != -8)
191 {
192 n2l(in,tin0);
193 n2l(in,tin1);
194 tin[0]=tin0;
195 tin[1]=tin1;
196 CAST_decrypt(tin,ks);
197 tout0=tin[0]^xor0;
198 tout1=tin[1]^xor1;
199 l2nn(tout0,tout1,out,l+8);
200 xor0=tin0;
201 xor1=tin1;
202 }
203 l2n(xor0,iv);
204 l2n(xor1,iv);
205 }
206 tin0=tin1=tout0=tout1=xor0=xor1=0;
207 tin[0]=tin[1]=0;
208 }
209
diff --git a/src/lib/libcrypto/cast/c_ofb64.c b/src/lib/libcrypto/cast/c_ofb64.c
new file mode 100644
index 0000000000..fd0469a62f
--- /dev/null
+++ b/src/lib/libcrypto/cast/c_ofb64.c
@@ -0,0 +1,111 @@
1/* crypto/cast/c_ofb64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/cast.h>
60#include "cast_lcl.h"
61
62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
67 long length, CAST_KEY *schedule, unsigned char *ivec,
68 int *num)
69 {
70 register CAST_LONG v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 unsigned char d[8];
74 register char *dp;
75 CAST_LONG ti[2];
76 unsigned char *iv;
77 int save=0;
78
79 iv=ivec;
80 n2l(iv,v0);
81 n2l(iv,v1);
82 ti[0]=v0;
83 ti[1]=v1;
84 dp=(char *)d;
85 l2n(v0,dp);
86 l2n(v1,dp);
87 while (l--)
88 {
89 if (n == 0)
90 {
91 CAST_encrypt((CAST_LONG *)ti,schedule);
92 dp=(char *)d;
93 t=ti[0]; l2n(t,dp);
94 t=ti[1]; l2n(t,dp);
95 save++;
96 }
97 *(out++)= *(in++)^d[n];
98 n=(n+1)&0x07;
99 }
100 if (save)
101 {
102 v0=ti[0];
103 v1=ti[1];
104 iv=ivec;
105 l2n(v0,iv);
106 l2n(v1,iv);
107 }
108 t=v0=v1=ti[0]=ti[1]=0;
109 *num=n;
110 }
111
diff --git a/src/lib/libcrypto/cast/c_skey.c b/src/lib/libcrypto/cast/c_skey.c
new file mode 100644
index 0000000000..dc4791a8cf
--- /dev/null
+++ b/src/lib/libcrypto/cast/c_skey.c
@@ -0,0 +1,168 @@
1/* crypto/cast/c_skey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/crypto.h>
60#include <openssl/cast.h>
61
62#include "cast_lcl.h"
63#include "cast_s.h"
64
65#define CAST_exp(l,A,a,n) \
66 A[n/4]=l; \
67 a[n+3]=(l )&0xff; \
68 a[n+2]=(l>> 8)&0xff; \
69 a[n+1]=(l>>16)&0xff; \
70 a[n+0]=(l>>24)&0xff;
71
72#define S4 CAST_S_table4
73#define S5 CAST_S_table5
74#define S6 CAST_S_table6
75#define S7 CAST_S_table7
76
77FIPS_NON_FIPS_VCIPHER_Init(CAST)
78 {
79 CAST_LONG x[16];
80 CAST_LONG z[16];
81 CAST_LONG k[32];
82 CAST_LONG X[4],Z[4];
83 CAST_LONG l,*K;
84 int i;
85
86 for (i=0; i<16; i++) x[i]=0;
87 if (len > 16) len=16;
88 for (i=0; i<len; i++)
89 x[i]=data[i];
90 if(len <= 10)
91 key->short_key=1;
92 else
93 key->short_key=0;
94
95 K= &k[0];
96 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;
97 X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL;
98 X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL;
99 X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL;
100
101 for (;;)
102 {
103 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
104 CAST_exp(l,Z,z, 0);
105 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
106 CAST_exp(l,Z,z, 4);
107 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
108 CAST_exp(l,Z,z, 8);
109 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
110 CAST_exp(l,Z,z,12);
111
112 K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]];
113 K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]];
114 K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]];
115 K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]];
116
117 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
118 CAST_exp(l,X,x, 0);
119 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
120 CAST_exp(l,X,x, 4);
121 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
122 CAST_exp(l,X,x, 8);
123 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
124 CAST_exp(l,X,x,12);
125
126 K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]];
127 K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]];
128 K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]];
129 K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]];
130
131 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
132 CAST_exp(l,Z,z, 0);
133 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
134 CAST_exp(l,Z,z, 4);
135 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
136 CAST_exp(l,Z,z, 8);
137 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
138 CAST_exp(l,Z,z,12);
139
140 K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]];
141 K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]];
142 K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]];
143 K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]];
144
145 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
146 CAST_exp(l,X,x, 0);
147 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
148 CAST_exp(l,X,x, 4);
149 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
150 CAST_exp(l,X,x, 8);
151 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
152 CAST_exp(l,X,x,12);
153
154 K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]];
155 K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]];
156 K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]];
157 K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]];
158 if (K != k) break;
159 K+=16;
160 }
161
162 for (i=0; i<16; i++)
163 {
164 key->data[i*2]=k[i];
165 key->data[i*2+1]=((k[i+16])+16)&0x1f;
166 }
167 }
168
diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h
new file mode 100644
index 0000000000..9e300178d9
--- /dev/null
+++ b/src/lib/libcrypto/cast/cast.h
@@ -0,0 +1,106 @@
1/* crypto/cast/cast.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CAST_H
60#define HEADER_CAST_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef OPENSSL_NO_CAST
67#error CAST is disabled.
68#endif
69
70#define CAST_ENCRYPT 1
71#define CAST_DECRYPT 0
72
73#define CAST_LONG unsigned long
74
75#define CAST_BLOCK 8
76#define CAST_KEY_LENGTH 16
77
78typedef struct cast_key_st
79 {
80 CAST_LONG data[32];
81 int short_key; /* Use reduced rounds for short key */
82 } CAST_KEY;
83
84
85#ifdef OPENSSL_FIPS
86void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
87#endif
88void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
89void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,
90 int enc);
91void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);
92void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);
93void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
94 CAST_KEY *ks, unsigned char *iv, int enc);
95void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
96 long length, CAST_KEY *schedule, unsigned char *ivec,
97 int *num, int enc);
98void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
99 long length, CAST_KEY *schedule, unsigned char *ivec,
100 int *num);
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif
diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h
new file mode 100644
index 0000000000..37f41cc6a4
--- /dev/null
+++ b/src/lib/libcrypto/cast/cast_lcl.h
@@ -0,0 +1,232 @@
1/* crypto/cast/cast_lcl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59
60#include "e_os.h"
61
62#ifdef OPENSSL_SYS_WIN32
63#include <stdlib.h>
64#endif
65
66
67#ifdef OPENSSL_BUILD_SHLIBCRYPTO
68# undef OPENSSL_EXTERN
69# define OPENSSL_EXTERN OPENSSL_EXPORT
70#endif
71
72#undef c2l
73#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
74 l|=((unsigned long)(*((c)++)))<< 8L, \
75 l|=((unsigned long)(*((c)++)))<<16L, \
76 l|=((unsigned long)(*((c)++)))<<24L)
77
78/* NOTE - c is not incremented as per c2l */
79#undef c2ln
80#define c2ln(c,l1,l2,n) { \
81 c+=n; \
82 l1=l2=0; \
83 switch (n) { \
84 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
85 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
86 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
87 case 5: l2|=((unsigned long)(*(--(c)))); \
88 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
89 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
90 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
91 case 1: l1|=((unsigned long)(*(--(c)))); \
92 } \
93 }
94
95#undef l2c
96#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
97 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
98 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
99 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
100
101/* NOTE - c is not incremented as per l2c */
102#undef l2cn
103#define l2cn(l1,l2,c,n) { \
104 c+=n; \
105 switch (n) { \
106 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
107 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
108 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
109 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
110 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
111 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
112 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
113 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
114 } \
115 }
116
117/* NOTE - c is not incremented as per n2l */
118#define n2ln(c,l1,l2,n) { \
119 c+=n; \
120 l1=l2=0; \
121 switch (n) { \
122 case 8: l2 =((unsigned long)(*(--(c)))) ; \
123 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
124 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
125 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
126 case 4: l1 =((unsigned long)(*(--(c)))) ; \
127 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
128 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
129 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
130 } \
131 }
132
133/* NOTE - c is not incremented as per l2n */
134#define l2nn(l1,l2,c,n) { \
135 c+=n; \
136 switch (n) { \
137 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
138 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
139 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
140 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
141 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
142 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
143 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
144 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
145 } \
146 }
147
148#undef n2l
149#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
150 l|=((unsigned long)(*((c)++)))<<16L, \
151 l|=((unsigned long)(*((c)++)))<< 8L, \
152 l|=((unsigned long)(*((c)++))))
153
154#undef l2n
155#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
156 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
157 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
158 *((c)++)=(unsigned char)(((l) )&0xff))
159
160#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
161#define ROTL(a,n) (_lrotl(a,n))
162#else
163#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
164#endif
165
166#define C_M 0x3fc
167#define C_0 22L
168#define C_1 14L
169#define C_2 6L
170#define C_3 2L /* left shift */
171
172/* The rotate has an extra 16 added to it to help the x86 asm */
173#if defined(CAST_PTR)
174#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
175 { \
176 int i; \
177 t=(key[n*2] OP1 R)&0xffffffffL; \
178 i=key[n*2+1]; \
179 t=ROTL(t,i); \
180 L^= (((((*(CAST_LONG *)((unsigned char *) \
181 CAST_S_table0+((t>>C_2)&C_M)) OP2 \
182 *(CAST_LONG *)((unsigned char *) \
183 CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
184 *(CAST_LONG *)((unsigned char *) \
185 CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
186 *(CAST_LONG *)((unsigned char *) \
187 CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
188 }
189#elif defined(CAST_PTR2)
190#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
191 { \
192 int i; \
193 CAST_LONG u,v,w; \
194 w=(key[n*2] OP1 R)&0xffffffffL; \
195 i=key[n*2+1]; \
196 w=ROTL(w,i); \
197 u=w>>C_2; \
198 v=w<<C_3; \
199 u&=C_M; \
200 v&=C_M; \
201 t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
202 u=w>>C_0; \
203 t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
204 v=w>>C_1; \
205 u&=C_M; \
206 v&=C_M; \
207 t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
208 t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
209 L^=(t&0xffffffff); \
210 }
211#else
212#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
213 { \
214 CAST_LONG a,b,c,d; \
215 t=(key[n*2] OP1 R)&0xffffffff; \
216 t=ROTL(t,(key[n*2+1])); \
217 a=CAST_S_table0[(t>> 8)&0xff]; \
218 b=CAST_S_table1[(t )&0xff]; \
219 c=CAST_S_table2[(t>>24)&0xff]; \
220 d=CAST_S_table3[(t>>16)&0xff]; \
221 L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
222 }
223#endif
224
225OPENSSL_EXTERN const CAST_LONG CAST_S_table0[256];
226OPENSSL_EXTERN const CAST_LONG CAST_S_table1[256];
227OPENSSL_EXTERN const CAST_LONG CAST_S_table2[256];
228OPENSSL_EXTERN const CAST_LONG CAST_S_table3[256];
229OPENSSL_EXTERN const CAST_LONG CAST_S_table4[256];
230OPENSSL_EXTERN const CAST_LONG CAST_S_table5[256];
231OPENSSL_EXTERN const CAST_LONG CAST_S_table6[256];
232OPENSSL_EXTERN const CAST_LONG CAST_S_table7[256];
diff --git a/src/lib/libcrypto/cast/cast_s.h b/src/lib/libcrypto/cast/cast_s.h
new file mode 100644
index 0000000000..c483fd5e43
--- /dev/null
+++ b/src/lib/libcrypto/cast/cast_s.h
@@ -0,0 +1,585 @@
1/* crypto/cast/cast_s.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58OPENSSL_GLOBAL const CAST_LONG CAST_S_table0[256]={
59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a,
60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949,
61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675,
62 0x6e63a0e0,0x15c361d2,0xc2e7661d,0x22d4ff8e,
63 0x28683b6f,0xc07fd059,0xff2379c8,0x775f50e2,
64 0x43c340d3,0xdf2f8656,0x887ca41a,0xa2d2bd2d,
65 0xa1c9e0d6,0x346c4819,0x61b76d87,0x22540f2f,
66 0x2abe32e1,0xaa54166b,0x22568e3a,0xa2d341d0,
67 0x66db40c8,0xa784392f,0x004dff2f,0x2db9d2de,
68 0x97943fac,0x4a97c1d8,0x527644b7,0xb5f437a7,
69 0xb82cbaef,0xd751d159,0x6ff7f0ed,0x5a097a1f,
70 0x827b68d0,0x90ecf52e,0x22b0c054,0xbc8e5935,
71 0x4b6d2f7f,0x50bb64a2,0xd2664910,0xbee5812d,
72 0xb7332290,0xe93b159f,0xb48ee411,0x4bff345d,
73 0xfd45c240,0xad31973f,0xc4f6d02e,0x55fc8165,
74 0xd5b1caad,0xa1ac2dae,0xa2d4b76d,0xc19b0c50,
75 0x882240f2,0x0c6e4f38,0xa4e4bfd7,0x4f5ba272,
76 0x564c1d2f,0xc59c5319,0xb949e354,0xb04669fe,
77 0xb1b6ab8a,0xc71358dd,0x6385c545,0x110f935d,
78 0x57538ad5,0x6a390493,0xe63d37e0,0x2a54f6b3,
79 0x3a787d5f,0x6276a0b5,0x19a6fcdf,0x7a42206a,
80 0x29f9d4d5,0xf61b1891,0xbb72275e,0xaa508167,
81 0x38901091,0xc6b505eb,0x84c7cb8c,0x2ad75a0f,
82 0x874a1427,0xa2d1936b,0x2ad286af,0xaa56d291,
83 0xd7894360,0x425c750d,0x93b39e26,0x187184c9,
84 0x6c00b32d,0x73e2bb14,0xa0bebc3c,0x54623779,
85 0x64459eab,0x3f328b82,0x7718cf82,0x59a2cea6,
86 0x04ee002e,0x89fe78e6,0x3fab0950,0x325ff6c2,
87 0x81383f05,0x6963c5c8,0x76cb5ad6,0xd49974c9,
88 0xca180dcf,0x380782d5,0xc7fa5cf6,0x8ac31511,
89 0x35e79e13,0x47da91d0,0xf40f9086,0xa7e2419e,
90 0x31366241,0x051ef495,0xaa573b04,0x4a805d8d,
91 0x548300d0,0x00322a3c,0xbf64cddf,0xba57a68e,
92 0x75c6372b,0x50afd341,0xa7c13275,0x915a0bf5,
93 0x6b54bfab,0x2b0b1426,0xab4cc9d7,0x449ccd82,
94 0xf7fbf265,0xab85c5f3,0x1b55db94,0xaad4e324,
95 0xcfa4bd3f,0x2deaa3e2,0x9e204d02,0xc8bd25ac,
96 0xeadf55b3,0xd5bd9e98,0xe31231b2,0x2ad5ad6c,
97 0x954329de,0xadbe4528,0xd8710f69,0xaa51c90f,
98 0xaa786bf6,0x22513f1e,0xaa51a79b,0x2ad344cc,
99 0x7b5a41f0,0xd37cfbad,0x1b069505,0x41ece491,
100 0xb4c332e6,0x032268d4,0xc9600acc,0xce387e6d,
101 0xbf6bb16c,0x6a70fb78,0x0d03d9c9,0xd4df39de,
102 0xe01063da,0x4736f464,0x5ad328d8,0xb347cc96,
103 0x75bb0fc3,0x98511bfb,0x4ffbcc35,0xb58bcf6a,
104 0xe11f0abc,0xbfc5fe4a,0xa70aec10,0xac39570a,
105 0x3f04442f,0x6188b153,0xe0397a2e,0x5727cb79,
106 0x9ceb418f,0x1cacd68d,0x2ad37c96,0x0175cb9d,
107 0xc69dff09,0xc75b65f0,0xd9db40d8,0xec0e7779,
108 0x4744ead4,0xb11c3274,0xdd24cb9e,0x7e1c54bd,
109 0xf01144f9,0xd2240eb1,0x9675b3fd,0xa3ac3755,
110 0xd47c27af,0x51c85f4d,0x56907596,0xa5bb15e6,
111 0x580304f0,0xca042cf1,0x011a37ea,0x8dbfaadb,
112 0x35ba3e4a,0x3526ffa0,0xc37b4d09,0xbc306ed9,
113 0x98a52666,0x5648f725,0xff5e569d,0x0ced63d0,
114 0x7c63b2cf,0x700b45e1,0xd5ea50f1,0x85a92872,
115 0xaf1fbda7,0xd4234870,0xa7870bf3,0x2d3b4d79,
116 0x42e04198,0x0cd0ede7,0x26470db8,0xf881814c,
117 0x474d6ad7,0x7c0c5e5c,0xd1231959,0x381b7298,
118 0xf5d2f4db,0xab838653,0x6e2f1e23,0x83719c9e,
119 0xbd91e046,0x9a56456e,0xdc39200c,0x20c8c571,
120 0x962bda1c,0xe1e696ff,0xb141ab08,0x7cca89b9,
121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d,
122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf,
123 };
124OPENSSL_GLOBAL const CAST_LONG CAST_S_table1[256]={
125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380,
126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651,
127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba,
128 0x99c430ef,0x5f0c0794,0x18dcdb7d,0xa1d6eff3,
129 0xa0b52f7b,0x59e83605,0xee15b094,0xe9ffd909,
130 0xdc440086,0xef944459,0xba83ccb3,0xe0c3cdfb,
131 0xd1da4181,0x3b092ab1,0xf997f1c1,0xa5e6cf7b,
132 0x01420ddb,0xe4e7ef5b,0x25a1ff41,0xe180f806,
133 0x1fc41080,0x179bee7a,0xd37ac6a9,0xfe5830a4,
134 0x98de8b7f,0x77e83f4e,0x79929269,0x24fa9f7b,
135 0xe113c85b,0xacc40083,0xd7503525,0xf7ea615f,
136 0x62143154,0x0d554b63,0x5d681121,0xc866c359,
137 0x3d63cf73,0xcee234c0,0xd4d87e87,0x5c672b21,
138 0x071f6181,0x39f7627f,0x361e3084,0xe4eb573b,
139 0x602f64a4,0xd63acd9c,0x1bbc4635,0x9e81032d,
140 0x2701f50c,0x99847ab4,0xa0e3df79,0xba6cf38c,
141 0x10843094,0x2537a95e,0xf46f6ffe,0xa1ff3b1f,
142 0x208cfb6a,0x8f458c74,0xd9e0a227,0x4ec73a34,
143 0xfc884f69,0x3e4de8df,0xef0e0088,0x3559648d,
144 0x8a45388c,0x1d804366,0x721d9bfd,0xa58684bb,
145 0xe8256333,0x844e8212,0x128d8098,0xfed33fb4,
146 0xce280ae1,0x27e19ba5,0xd5a6c252,0xe49754bd,
147 0xc5d655dd,0xeb667064,0x77840b4d,0xa1b6a801,
148 0x84db26a9,0xe0b56714,0x21f043b7,0xe5d05860,
149 0x54f03084,0x066ff472,0xa31aa153,0xdadc4755,
150 0xb5625dbf,0x68561be6,0x83ca6b94,0x2d6ed23b,
151 0xeccf01db,0xa6d3d0ba,0xb6803d5c,0xaf77a709,
152 0x33b4a34c,0x397bc8d6,0x5ee22b95,0x5f0e5304,
153 0x81ed6f61,0x20e74364,0xb45e1378,0xde18639b,
154 0x881ca122,0xb96726d1,0x8049a7e8,0x22b7da7b,
155 0x5e552d25,0x5272d237,0x79d2951c,0xc60d894c,
156 0x488cb402,0x1ba4fe5b,0xa4b09f6b,0x1ca815cf,
157 0xa20c3005,0x8871df63,0xb9de2fcb,0x0cc6c9e9,
158 0x0beeff53,0xe3214517,0xb4542835,0x9f63293c,
159 0xee41e729,0x6e1d2d7c,0x50045286,0x1e6685f3,
160 0xf33401c6,0x30a22c95,0x31a70850,0x60930f13,
161 0x73f98417,0xa1269859,0xec645c44,0x52c877a9,
162 0xcdff33a6,0xa02b1741,0x7cbad9a2,0x2180036f,
163 0x50d99c08,0xcb3f4861,0xc26bd765,0x64a3f6ab,
164 0x80342676,0x25a75e7b,0xe4e6d1fc,0x20c710e6,
165 0xcdf0b680,0x17844d3b,0x31eef84d,0x7e0824e4,
166 0x2ccb49eb,0x846a3bae,0x8ff77888,0xee5d60f6,
167 0x7af75673,0x2fdd5cdb,0xa11631c1,0x30f66f43,
168 0xb3faec54,0x157fd7fa,0xef8579cc,0xd152de58,
169 0xdb2ffd5e,0x8f32ce19,0x306af97a,0x02f03ef8,
170 0x99319ad5,0xc242fa0f,0xa7e3ebb0,0xc68e4906,
171 0xb8da230c,0x80823028,0xdcdef3c8,0xd35fb171,
172 0x088a1bc8,0xbec0c560,0x61a3c9e8,0xbca8f54d,
173 0xc72feffa,0x22822e99,0x82c570b4,0xd8d94e89,
174 0x8b1c34bc,0x301e16e6,0x273be979,0xb0ffeaa6,
175 0x61d9b8c6,0x00b24869,0xb7ffce3f,0x08dc283b,
176 0x43daf65a,0xf7e19798,0x7619b72f,0x8f1c9ba4,
177 0xdc8637a0,0x16a7d3b1,0x9fc393b7,0xa7136eeb,
178 0xc6bcc63e,0x1a513742,0xef6828bc,0x520365d6,
179 0x2d6a77ab,0x3527ed4b,0x821fd216,0x095c6e2e,
180 0xdb92f2fb,0x5eea29cb,0x145892f5,0x91584f7f,
181 0x5483697b,0x2667a8cc,0x85196048,0x8c4bacea,
182 0x833860d4,0x0d23e0f9,0x6c387e8a,0x0ae6d249,
183 0xb284600c,0xd835731d,0xdcb1c647,0xac4c56ea,
184 0x3ebd81b3,0x230eabb0,0x6438bc87,0xf0b5b1fa,
185 0x8f5ea2b3,0xfc184642,0x0a036b7a,0x4fb089bd,
186 0x649da589,0xa345415e,0x5c038323,0x3e5d3bb9,
187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef,
188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1,
189 };
190OPENSSL_GLOBAL const CAST_LONG CAST_S_table2[256]={
191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907,
192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90,
193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae,
194 0x920e8806,0xf0ad0548,0xe13c8d83,0x927010d5,
195 0x11107d9f,0x07647db9,0xb2e3e4d4,0x3d4f285e,
196 0xb9afa820,0xfade82e0,0xa067268b,0x8272792e,
197 0x553fb2c0,0x489ae22b,0xd4ef9794,0x125e3fbc,
198 0x21fffcee,0x825b1bfd,0x9255c5ed,0x1257a240,
199 0x4e1a8302,0xbae07fff,0x528246e7,0x8e57140e,
200 0x3373f7bf,0x8c9f8188,0xa6fc4ee8,0xc982b5a5,
201 0xa8c01db7,0x579fc264,0x67094f31,0xf2bd3f5f,
202 0x40fff7c1,0x1fb78dfc,0x8e6bd2c1,0x437be59b,
203 0x99b03dbf,0xb5dbc64b,0x638dc0e6,0x55819d99,
204 0xa197c81c,0x4a012d6e,0xc5884a28,0xccc36f71,
205 0xb843c213,0x6c0743f1,0x8309893c,0x0feddd5f,
206 0x2f7fe850,0xd7c07f7e,0x02507fbf,0x5afb9a04,
207 0xa747d2d0,0x1651192e,0xaf70bf3e,0x58c31380,
208 0x5f98302e,0x727cc3c4,0x0a0fb402,0x0f7fef82,
209 0x8c96fdad,0x5d2c2aae,0x8ee99a49,0x50da88b8,
210 0x8427f4a0,0x1eac5790,0x796fb449,0x8252dc15,
211 0xefbd7d9b,0xa672597d,0xada840d8,0x45f54504,
212 0xfa5d7403,0xe83ec305,0x4f91751a,0x925669c2,
213 0x23efe941,0xa903f12e,0x60270df2,0x0276e4b6,
214 0x94fd6574,0x927985b2,0x8276dbcb,0x02778176,
215 0xf8af918d,0x4e48f79e,0x8f616ddf,0xe29d840e,
216 0x842f7d83,0x340ce5c8,0x96bbb682,0x93b4b148,
217 0xef303cab,0x984faf28,0x779faf9b,0x92dc560d,
218 0x224d1e20,0x8437aa88,0x7d29dc96,0x2756d3dc,
219 0x8b907cee,0xb51fd240,0xe7c07ce3,0xe566b4a1,
220 0xc3e9615e,0x3cf8209d,0x6094d1e3,0xcd9ca341,
221 0x5c76460e,0x00ea983b,0xd4d67881,0xfd47572c,
222 0xf76cedd9,0xbda8229c,0x127dadaa,0x438a074e,
223 0x1f97c090,0x081bdb8a,0x93a07ebe,0xb938ca15,
224 0x97b03cff,0x3dc2c0f8,0x8d1ab2ec,0x64380e51,
225 0x68cc7bfb,0xd90f2788,0x12490181,0x5de5ffd4,
226 0xdd7ef86a,0x76a2e214,0xb9a40368,0x925d958f,
227 0x4b39fffa,0xba39aee9,0xa4ffd30b,0xfaf7933b,
228 0x6d498623,0x193cbcfa,0x27627545,0x825cf47a,
229 0x61bd8ba0,0xd11e42d1,0xcead04f4,0x127ea392,
230 0x10428db7,0x8272a972,0x9270c4a8,0x127de50b,
231 0x285ba1c8,0x3c62f44f,0x35c0eaa5,0xe805d231,
232 0x428929fb,0xb4fcdf82,0x4fb66a53,0x0e7dc15b,
233 0x1f081fab,0x108618ae,0xfcfd086d,0xf9ff2889,
234 0x694bcc11,0x236a5cae,0x12deca4d,0x2c3f8cc5,
235 0xd2d02dfe,0xf8ef5896,0xe4cf52da,0x95155b67,
236 0x494a488c,0xb9b6a80c,0x5c8f82bc,0x89d36b45,
237 0x3a609437,0xec00c9a9,0x44715253,0x0a874b49,
238 0xd773bc40,0x7c34671c,0x02717ef6,0x4feb5536,
239 0xa2d02fff,0xd2bf60c4,0xd43f03c0,0x50b4ef6d,
240 0x07478cd1,0x006e1888,0xa2e53f55,0xb9e6d4bc,
241 0xa2048016,0x97573833,0xd7207d67,0xde0f8f3d,
242 0x72f87b33,0xabcc4f33,0x7688c55d,0x7b00a6b0,
243 0x947b0001,0x570075d2,0xf9bb88f8,0x8942019e,
244 0x4264a5ff,0x856302e0,0x72dbd92b,0xee971b69,
245 0x6ea22fde,0x5f08ae2b,0xaf7a616d,0xe5c98767,
246 0xcf1febd2,0x61efc8c2,0xf1ac2571,0xcc8239c2,
247 0x67214cb8,0xb1e583d1,0xb7dc3e62,0x7f10bdce,
248 0xf90a5c38,0x0ff0443d,0x606e6dc6,0x60543a49,
249 0x5727c148,0x2be98a1d,0x8ab41738,0x20e1be24,
250 0xaf96da0f,0x68458425,0x99833be5,0x600d457d,
251 0x282f9350,0x8334b362,0xd91d1120,0x2b6d8da0,
252 0x642b1e31,0x9c305a00,0x52bce688,0x1b03588a,
253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5,
254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783,
255 };
256OPENSSL_GLOBAL const CAST_LONG CAST_S_table3[256]={
257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298,
258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1,
259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120,
260 0xfd059d43,0x6497b7b1,0xf3641f63,0x241e4adf,
261 0x28147f5f,0x4fa2b8cd,0xc9430040,0x0cc32220,
262 0xfdd30b30,0xc0a5374f,0x1d2d00d9,0x24147b15,
263 0xee4d111a,0x0fca5167,0x71ff904c,0x2d195ffe,
264 0x1a05645f,0x0c13fefe,0x081b08ca,0x05170121,
265 0x80530100,0xe83e5efe,0xac9af4f8,0x7fe72701,
266 0xd2b8ee5f,0x06df4261,0xbb9e9b8a,0x7293ea25,
267 0xce84ffdf,0xf5718801,0x3dd64b04,0xa26f263b,
268 0x7ed48400,0x547eebe6,0x446d4ca0,0x6cf3d6f5,
269 0x2649abdf,0xaea0c7f5,0x36338cc1,0x503f7e93,
270 0xd3772061,0x11b638e1,0x72500e03,0xf80eb2bb,
271 0xabe0502e,0xec8d77de,0x57971e81,0xe14f6746,
272 0xc9335400,0x6920318f,0x081dbb99,0xffc304a5,
273 0x4d351805,0x7f3d5ce3,0xa6c866c6,0x5d5bcca9,
274 0xdaec6fea,0x9f926f91,0x9f46222f,0x3991467d,
275 0xa5bf6d8e,0x1143c44f,0x43958302,0xd0214eeb,
276 0x022083b8,0x3fb6180c,0x18f8931e,0x281658e6,
277 0x26486e3e,0x8bd78a70,0x7477e4c1,0xb506e07c,
278 0xf32d0a25,0x79098b02,0xe4eabb81,0x28123b23,
279 0x69dead38,0x1574ca16,0xdf871b62,0x211c40b7,
280 0xa51a9ef9,0x0014377b,0x041e8ac8,0x09114003,
281 0xbd59e4d2,0xe3d156d5,0x4fe876d5,0x2f91a340,
282 0x557be8de,0x00eae4a7,0x0ce5c2ec,0x4db4bba6,
283 0xe756bdff,0xdd3369ac,0xec17b035,0x06572327,
284 0x99afc8b0,0x56c8c391,0x6b65811c,0x5e146119,
285 0x6e85cb75,0xbe07c002,0xc2325577,0x893ff4ec,
286 0x5bbfc92d,0xd0ec3b25,0xb7801ab7,0x8d6d3b24,
287 0x20c763ef,0xc366a5fc,0x9c382880,0x0ace3205,
288 0xaac9548a,0xeca1d7c7,0x041afa32,0x1d16625a,
289 0x6701902c,0x9b757a54,0x31d477f7,0x9126b031,
290 0x36cc6fdb,0xc70b8b46,0xd9e66a48,0x56e55a79,
291 0x026a4ceb,0x52437eff,0x2f8f76b4,0x0df980a5,
292 0x8674cde3,0xedda04eb,0x17a9be04,0x2c18f4df,
293 0xb7747f9d,0xab2af7b4,0xefc34d20,0x2e096b7c,
294 0x1741a254,0xe5b6a035,0x213d42f6,0x2c1c7c26,
295 0x61c2f50f,0x6552daf9,0xd2c231f8,0x25130f69,
296 0xd8167fa2,0x0418f2c8,0x001a96a6,0x0d1526ab,
297 0x63315c21,0x5e0a72ec,0x49bafefd,0x187908d9,
298 0x8d0dbd86,0x311170a7,0x3e9b640c,0xcc3e10d7,
299 0xd5cad3b6,0x0caec388,0xf73001e1,0x6c728aff,
300 0x71eae2a1,0x1f9af36e,0xcfcbd12f,0xc1de8417,
301 0xac07be6b,0xcb44a1d8,0x8b9b0f56,0x013988c3,
302 0xb1c52fca,0xb4be31cd,0xd8782806,0x12a3a4e2,
303 0x6f7de532,0x58fd7eb6,0xd01ee900,0x24adffc2,
304 0xf4990fc5,0x9711aac5,0x001d7b95,0x82e5e7d2,
305 0x109873f6,0x00613096,0xc32d9521,0xada121ff,
306 0x29908415,0x7fbb977f,0xaf9eb3db,0x29c9ed2a,
307 0x5ce2a465,0xa730f32c,0xd0aa3fe8,0x8a5cc091,
308 0xd49e2ce7,0x0ce454a9,0xd60acd86,0x015f1919,
309 0x77079103,0xdea03af6,0x78a8565e,0xdee356df,
310 0x21f05cbe,0x8b75e387,0xb3c50651,0xb8a5c3ef,
311 0xd8eeb6d2,0xe523be77,0xc2154529,0x2f69efdf,
312 0xafe67afb,0xf470c4b2,0xf3e0eb5b,0xd6cc9876,
313 0x39e4460c,0x1fda8538,0x1987832f,0xca007367,
314 0xa99144f8,0x296b299e,0x492fc295,0x9266beab,
315 0xb5676e69,0x9bd3ddda,0xdf7e052f,0xdb25701c,
316 0x1b5e51ee,0xf65324e6,0x6afce36c,0x0316cc04,
317 0x8644213e,0xb7dc59d0,0x7965291f,0xccd6fd43,
318 0x41823979,0x932bcdf6,0xb657c34d,0x4edfd282,
319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e,
320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2,
321 };
322OPENSSL_GLOBAL const CAST_LONG CAST_S_table4[256]={
323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911,
324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f,
325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00,
326 0x2ab722d8,0x386381cb,0xacf6243a,0x69befd7a,
327 0xe6a2e77f,0xf0c720cd,0xc4494816,0xccf5c180,
328 0x38851640,0x15b0a848,0xe68b18cb,0x4caadeff,
329 0x5f480a01,0x0412b2aa,0x259814fc,0x41d0efe2,
330 0x4e40b48d,0x248eb6fb,0x8dba1cfe,0x41a99b02,
331 0x1a550a04,0xba8f65cb,0x7251f4e7,0x95a51725,
332 0xc106ecd7,0x97a5980a,0xc539b9aa,0x4d79fe6a,
333 0xf2f3f763,0x68af8040,0xed0c9e56,0x11b4958b,
334 0xe1eb5a88,0x8709e6b0,0xd7e07156,0x4e29fea7,
335 0x6366e52d,0x02d1c000,0xc4ac8e05,0x9377f571,
336 0x0c05372a,0x578535f2,0x2261be02,0xd642a0c9,
337 0xdf13a280,0x74b55bd2,0x682199c0,0xd421e5ec,
338 0x53fb3ce8,0xc8adedb3,0x28a87fc9,0x3d959981,
339 0x5c1ff900,0xfe38d399,0x0c4eff0b,0x062407ea,
340 0xaa2f4fb1,0x4fb96976,0x90c79505,0xb0a8a774,
341 0xef55a1ff,0xe59ca2c2,0xa6b62d27,0xe66a4263,
342 0xdf65001f,0x0ec50966,0xdfdd55bc,0x29de0655,
343 0x911e739a,0x17af8975,0x32c7911c,0x89f89468,
344 0x0d01e980,0x524755f4,0x03b63cc9,0x0cc844b2,
345 0xbcf3f0aa,0x87ac36e9,0xe53a7426,0x01b3d82b,
346 0x1a9e7449,0x64ee2d7e,0xcddbb1da,0x01c94910,
347 0xb868bf80,0x0d26f3fd,0x9342ede7,0x04a5c284,
348 0x636737b6,0x50f5b616,0xf24766e3,0x8eca36c1,
349 0x136e05db,0xfef18391,0xfb887a37,0xd6e7f7d4,
350 0xc7fb7dc9,0x3063fcdf,0xb6f589de,0xec2941da,
351 0x26e46695,0xb7566419,0xf654efc5,0xd08d58b7,
352 0x48925401,0xc1bacb7f,0xe5ff550f,0xb6083049,
353 0x5bb5d0e8,0x87d72e5a,0xab6a6ee1,0x223a66ce,
354 0xc62bf3cd,0x9e0885f9,0x68cb3e47,0x086c010f,
355 0xa21de820,0xd18b69de,0xf3f65777,0xfa02c3f6,
356 0x407edac3,0xcbb3d550,0x1793084d,0xb0d70eba,
357 0x0ab378d5,0xd951fb0c,0xded7da56,0x4124bbe4,
358 0x94ca0b56,0x0f5755d1,0xe0e1e56e,0x6184b5be,
359 0x580a249f,0x94f74bc0,0xe327888e,0x9f7b5561,
360 0xc3dc0280,0x05687715,0x646c6bd7,0x44904db3,
361 0x66b4f0a3,0xc0f1648a,0x697ed5af,0x49e92ff6,
362 0x309e374f,0x2cb6356a,0x85808573,0x4991f840,
363 0x76f0ae02,0x083be84d,0x28421c9a,0x44489406,
364 0x736e4cb8,0xc1092910,0x8bc95fc6,0x7d869cf4,
365 0x134f616f,0x2e77118d,0xb31b2be1,0xaa90b472,
366 0x3ca5d717,0x7d161bba,0x9cad9010,0xaf462ba2,
367 0x9fe459d2,0x45d34559,0xd9f2da13,0xdbc65487,
368 0xf3e4f94e,0x176d486f,0x097c13ea,0x631da5c7,
369 0x445f7382,0x175683f4,0xcdc66a97,0x70be0288,
370 0xb3cdcf72,0x6e5dd2f3,0x20936079,0x459b80a5,
371 0xbe60e2db,0xa9c23101,0xeba5315c,0x224e42f2,
372 0x1c5c1572,0xf6721b2c,0x1ad2fff3,0x8c25404e,
373 0x324ed72f,0x4067b7fd,0x0523138e,0x5ca3bc78,
374 0xdc0fd66e,0x75922283,0x784d6b17,0x58ebb16e,
375 0x44094f85,0x3f481d87,0xfcfeae7b,0x77b5ff76,
376 0x8c2302bf,0xaaf47556,0x5f46b02a,0x2b092801,
377 0x3d38f5f7,0x0ca81f36,0x52af4a8a,0x66d5e7c0,
378 0xdf3b0874,0x95055110,0x1b5ad7a8,0xf61ed5ad,
379 0x6cf6e479,0x20758184,0xd0cefa65,0x88f7be58,
380 0x4a046826,0x0ff6f8f3,0xa09c7f70,0x5346aba0,
381 0x5ce96c28,0xe176eda3,0x6bac307f,0x376829d2,
382 0x85360fa9,0x17e3fe2a,0x24b79767,0xf5a96b20,
383 0xd6cd2595,0x68ff1ebf,0x7555442c,0xf19f06be,
384 0xf9e0659a,0xeeb9491d,0x34010718,0xbb30cab8,
385 0xe822fe15,0x88570983,0x750e6249,0xda627e55,
386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4,
387 };
388OPENSSL_GLOBAL const CAST_LONG CAST_S_table5[256]={
389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c,
390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac,
391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9,
392 0x1ab6a6b8,0xde5ebe39,0xf38ff732,0x8989b138,
393 0x33f14961,0xc01937bd,0xf506c6da,0xe4625e7e,
394 0xa308ea99,0x4e23e33c,0x79cbd7cc,0x48a14367,
395 0xa3149619,0xfec94bd5,0xa114174a,0xeaa01866,
396 0xa084db2d,0x09a8486f,0xa888614a,0x2900af98,
397 0x01665991,0xe1992863,0xc8f30c60,0x2e78ef3c,
398 0xd0d51932,0xcf0fec14,0xf7ca07d2,0xd0a82072,
399 0xfd41197e,0x9305a6b0,0xe86be3da,0x74bed3cd,
400 0x372da53c,0x4c7f4448,0xdab5d440,0x6dba0ec3,
401 0x083919a7,0x9fbaeed9,0x49dbcfb0,0x4e670c53,
402 0x5c3d9c01,0x64bdb941,0x2c0e636a,0xba7dd9cd,
403 0xea6f7388,0xe70bc762,0x35f29adb,0x5c4cdd8d,
404 0xf0d48d8c,0xb88153e2,0x08a19866,0x1ae2eac8,
405 0x284caf89,0xaa928223,0x9334be53,0x3b3a21bf,
406 0x16434be3,0x9aea3906,0xefe8c36e,0xf890cdd9,
407 0x80226dae,0xc340a4a3,0xdf7e9c09,0xa694a807,
408 0x5b7c5ecc,0x221db3a6,0x9a69a02f,0x68818a54,
409 0xceb2296f,0x53c0843a,0xfe893655,0x25bfe68a,
410 0xb4628abc,0xcf222ebf,0x25ac6f48,0xa9a99387,
411 0x53bddb65,0xe76ffbe7,0xe967fd78,0x0ba93563,
412 0x8e342bc1,0xe8a11be9,0x4980740d,0xc8087dfc,
413 0x8de4bf99,0xa11101a0,0x7fd37975,0xda5a26c0,
414 0xe81f994f,0x9528cd89,0xfd339fed,0xb87834bf,
415 0x5f04456d,0x22258698,0xc9c4c83b,0x2dc156be,
416 0x4f628daa,0x57f55ec5,0xe2220abe,0xd2916ebf,
417 0x4ec75b95,0x24f2c3c0,0x42d15d99,0xcd0d7fa0,
418 0x7b6e27ff,0xa8dc8af0,0x7345c106,0xf41e232f,
419 0x35162386,0xe6ea8926,0x3333b094,0x157ec6f2,
420 0x372b74af,0x692573e4,0xe9a9d848,0xf3160289,
421 0x3a62ef1d,0xa787e238,0xf3a5f676,0x74364853,
422 0x20951063,0x4576698d,0xb6fad407,0x592af950,
423 0x36f73523,0x4cfb6e87,0x7da4cec0,0x6c152daa,
424 0xcb0396a8,0xc50dfe5d,0xfcd707ab,0x0921c42f,
425 0x89dff0bb,0x5fe2be78,0x448f4f33,0x754613c9,
426 0x2b05d08d,0x48b9d585,0xdc049441,0xc8098f9b,
427 0x7dede786,0xc39a3373,0x42410005,0x6a091751,
428 0x0ef3c8a6,0x890072d6,0x28207682,0xa9a9f7be,
429 0xbf32679d,0xd45b5b75,0xb353fd00,0xcbb0e358,
430 0x830f220a,0x1f8fb214,0xd372cf08,0xcc3c4a13,
431 0x8cf63166,0x061c87be,0x88c98f88,0x6062e397,
432 0x47cf8e7a,0xb6c85283,0x3cc2acfb,0x3fc06976,
433 0x4e8f0252,0x64d8314d,0xda3870e3,0x1e665459,
434 0xc10908f0,0x513021a5,0x6c5b68b7,0x822f8aa0,
435 0x3007cd3e,0x74719eef,0xdc872681,0x073340d4,
436 0x7e432fd9,0x0c5ec241,0x8809286c,0xf592d891,
437 0x08a930f6,0x957ef305,0xb7fbffbd,0xc266e96f,
438 0x6fe4ac98,0xb173ecc0,0xbc60b42a,0x953498da,
439 0xfba1ae12,0x2d4bd736,0x0f25faab,0xa4f3fceb,
440 0xe2969123,0x257f0c3d,0x9348af49,0x361400bc,
441 0xe8816f4a,0x3814f200,0xa3f94043,0x9c7a54c2,
442 0xbc704f57,0xda41e7f9,0xc25ad33a,0x54f4a084,
443 0xb17f5505,0x59357cbe,0xedbd15c8,0x7f97c5ab,
444 0xba5ac7b5,0xb6f6deaf,0x3a479c3a,0x5302da25,
445 0x653d7e6a,0x54268d49,0x51a477ea,0x5017d55b,
446 0xd7d25d88,0x44136c76,0x0404a8c8,0xb8e5a121,
447 0xb81a928a,0x60ed5869,0x97c55b96,0xeaec991b,
448 0x29935913,0x01fdb7f1,0x088e8dfa,0x9ab6f6f5,
449 0x3b4cbf9f,0x4a5de3ab,0xe6051d35,0xa0e1d855,
450 0xd36b4cf1,0xf544edeb,0xb0e93524,0xbebb8fbd,
451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454,
452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f,
453 };
454OPENSSL_GLOBAL const CAST_LONG CAST_S_table6[256]={
455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693,
456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f,
457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82,
458 0x2cb2cb11,0xb232e75c,0x4b3695f2,0xb28707de,
459 0xa05fbcf6,0xcd4181e9,0xe150210c,0xe24ef1bd,
460 0xb168c381,0xfde4e789,0x5c79b0d8,0x1e8bfd43,
461 0x4d495001,0x38be4341,0x913cee1d,0x92a79c3f,
462 0x089766be,0xbaeeadf4,0x1286becf,0xb6eacb19,
463 0x2660c200,0x7565bde4,0x64241f7a,0x8248dca9,
464 0xc3b3ad66,0x28136086,0x0bd8dfa8,0x356d1cf2,
465 0x107789be,0xb3b2e9ce,0x0502aa8f,0x0bc0351e,
466 0x166bf52a,0xeb12ff82,0xe3486911,0xd34d7516,
467 0x4e7b3aff,0x5f43671b,0x9cf6e037,0x4981ac83,
468 0x334266ce,0x8c9341b7,0xd0d854c0,0xcb3a6c88,
469 0x47bc2829,0x4725ba37,0xa66ad22b,0x7ad61f1e,
470 0x0c5cbafa,0x4437f107,0xb6e79962,0x42d2d816,
471 0x0a961288,0xe1a5c06e,0x13749e67,0x72fc081a,
472 0xb1d139f7,0xf9583745,0xcf19df58,0xbec3f756,
473 0xc06eba30,0x07211b24,0x45c28829,0xc95e317f,
474 0xbc8ec511,0x38bc46e9,0xc6e6fa14,0xbae8584a,
475 0xad4ebc46,0x468f508b,0x7829435f,0xf124183b,
476 0x821dba9f,0xaff60ff4,0xea2c4e6d,0x16e39264,
477 0x92544a8b,0x009b4fc3,0xaba68ced,0x9ac96f78,
478 0x06a5b79a,0xb2856e6e,0x1aec3ca9,0xbe838688,
479 0x0e0804e9,0x55f1be56,0xe7e5363b,0xb3a1f25d,
480 0xf7debb85,0x61fe033c,0x16746233,0x3c034c28,
481 0xda6d0c74,0x79aac56c,0x3ce4e1ad,0x51f0c802,
482 0x98f8f35a,0x1626a49f,0xeed82b29,0x1d382fe3,
483 0x0c4fb99a,0xbb325778,0x3ec6d97b,0x6e77a6a9,
484 0xcb658b5c,0xd45230c7,0x2bd1408b,0x60c03eb7,
485 0xb9068d78,0xa33754f4,0xf430c87d,0xc8a71302,
486 0xb96d8c32,0xebd4e7be,0xbe8b9d2d,0x7979fb06,
487 0xe7225308,0x8b75cf77,0x11ef8da4,0xe083c858,
488 0x8d6b786f,0x5a6317a6,0xfa5cf7a0,0x5dda0033,
489 0xf28ebfb0,0xf5b9c310,0xa0eac280,0x08b9767a,
490 0xa3d9d2b0,0x79d34217,0x021a718d,0x9ac6336a,
491 0x2711fd60,0x438050e3,0x069908a8,0x3d7fedc4,
492 0x826d2bef,0x4eeb8476,0x488dcf25,0x36c9d566,
493 0x28e74e41,0xc2610aca,0x3d49a9cf,0xbae3b9df,
494 0xb65f8de6,0x92aeaf64,0x3ac7d5e6,0x9ea80509,
495 0xf22b017d,0xa4173f70,0xdd1e16c3,0x15e0d7f9,
496 0x50b1b887,0x2b9f4fd5,0x625aba82,0x6a017962,
497 0x2ec01b9c,0x15488aa9,0xd716e740,0x40055a2c,
498 0x93d29a22,0xe32dbf9a,0x058745b9,0x3453dc1e,
499 0xd699296e,0x496cff6f,0x1c9f4986,0xdfe2ed07,
500 0xb87242d1,0x19de7eae,0x053e561a,0x15ad6f8c,
501 0x66626c1c,0x7154c24c,0xea082b2a,0x93eb2939,
502 0x17dcb0f0,0x58d4f2ae,0x9ea294fb,0x52cf564c,
503 0x9883fe66,0x2ec40581,0x763953c3,0x01d6692e,
504 0xd3a0c108,0xa1e7160e,0xe4f2dfa6,0x693ed285,
505 0x74904698,0x4c2b0edd,0x4f757656,0x5d393378,
506 0xa132234f,0x3d321c5d,0xc3f5e194,0x4b269301,
507 0xc79f022f,0x3c997e7e,0x5e4f9504,0x3ffafbbd,
508 0x76f7ad0e,0x296693f4,0x3d1fce6f,0xc61e45be,
509 0xd3b5ab34,0xf72bf9b7,0x1b0434c0,0x4e72b567,
510 0x5592a33d,0xb5229301,0xcfd2a87f,0x60aeb767,
511 0x1814386b,0x30bcc33d,0x38a0c07d,0xfd1606f2,
512 0xc363519b,0x589dd390,0x5479f8e6,0x1cb8d647,
513 0x97fd61a9,0xea7759f4,0x2d57539d,0x569a58cf,
514 0xe84e63ad,0x462e1b78,0x6580f87e,0xf3817914,
515 0x91da55f4,0x40a230f3,0xd1988f35,0xb6e318d2,
516 0x3ffa50bc,0x3d40f021,0xc3c0bdae,0x4958c24c,
517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada,
518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3,
519 };
520OPENSSL_GLOBAL const CAST_LONG CAST_S_table7[256]={
521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095,
522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5,
523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174,
524 0x2a42931c,0x76e38111,0xb12def3a,0x37ddddfc,
525 0xde9adeb1,0x0a0cc32c,0xbe197029,0x84a00940,
526 0xbb243a0f,0xb4d137cf,0xb44e79f0,0x049eedfd,
527 0x0b15a15d,0x480d3168,0x8bbbde5a,0x669ded42,
528 0xc7ece831,0x3f8f95e7,0x72df191b,0x7580330d,
529 0x94074251,0x5c7dcdfa,0xabbe6d63,0xaa402164,
530 0xb301d40a,0x02e7d1ca,0x53571dae,0x7a3182a2,
531 0x12a8ddec,0xfdaa335d,0x176f43e8,0x71fb46d4,
532 0x38129022,0xce949ad4,0xb84769ad,0x965bd862,
533 0x82f3d055,0x66fb9767,0x15b80b4e,0x1d5b47a0,
534 0x4cfde06f,0xc28ec4b8,0x57e8726e,0x647a78fc,
535 0x99865d44,0x608bd593,0x6c200e03,0x39dc5ff6,
536 0x5d0b00a3,0xae63aff2,0x7e8bd632,0x70108c0c,
537 0xbbd35049,0x2998df04,0x980cf42a,0x9b6df491,
538 0x9e7edd53,0x06918548,0x58cb7e07,0x3b74ef2e,
539 0x522fffb1,0xd24708cc,0x1c7e27cd,0xa4eb215b,
540 0x3cf1d2e2,0x19b47a38,0x424f7618,0x35856039,
541 0x9d17dee7,0x27eb35e6,0xc9aff67b,0x36baf5b8,
542 0x09c467cd,0xc18910b1,0xe11dbf7b,0x06cd1af8,
543 0x7170c608,0x2d5e3354,0xd4de495a,0x64c6d006,
544 0xbcc0c62c,0x3dd00db3,0x708f8f34,0x77d51b42,
545 0x264f620f,0x24b8d2bf,0x15c1b79e,0x46a52564,
546 0xf8d7e54e,0x3e378160,0x7895cda5,0x859c15a5,
547 0xe6459788,0xc37bc75f,0xdb07ba0c,0x0676a3ab,
548 0x7f229b1e,0x31842e7b,0x24259fd7,0xf8bef472,
549 0x835ffcb8,0x6df4c1f2,0x96f5b195,0xfd0af0fc,
550 0xb0fe134c,0xe2506d3d,0x4f9b12ea,0xf215f225,
551 0xa223736f,0x9fb4c428,0x25d04979,0x34c713f8,
552 0xc4618187,0xea7a6e98,0x7cd16efc,0x1436876c,
553 0xf1544107,0xbedeee14,0x56e9af27,0xa04aa441,
554 0x3cf7c899,0x92ecbae6,0xdd67016d,0x151682eb,
555 0xa842eedf,0xfdba60b4,0xf1907b75,0x20e3030f,
556 0x24d8c29e,0xe139673b,0xefa63fb8,0x71873054,
557 0xb6f2cf3b,0x9f326442,0xcb15a4cc,0xb01a4504,
558 0xf1e47d8d,0x844a1be5,0xbae7dfdc,0x42cbda70,
559 0xcd7dae0a,0x57e85b7a,0xd53f5af6,0x20cf4d8c,
560 0xcea4d428,0x79d130a4,0x3486ebfb,0x33d3cddc,
561 0x77853b53,0x37effcb5,0xc5068778,0xe580b3e6,
562 0x4e68b8f4,0xc5c8b37e,0x0d809ea2,0x398feb7c,
563 0x132a4f94,0x43b7950e,0x2fee7d1c,0x223613bd,
564 0xdd06caa2,0x37df932b,0xc4248289,0xacf3ebc3,
565 0x5715f6b7,0xef3478dd,0xf267616f,0xc148cbe4,
566 0x9052815e,0x5e410fab,0xb48a2465,0x2eda7fa4,
567 0xe87b40e4,0xe98ea084,0x5889e9e1,0xefd390fc,
568 0xdd07d35b,0xdb485694,0x38d7e5b2,0x57720101,
569 0x730edebc,0x5b643113,0x94917e4f,0x503c2fba,
570 0x646f1282,0x7523d24a,0xe0779695,0xf9c17a8f,
571 0x7a5b2121,0xd187b896,0x29263a4d,0xba510cdf,
572 0x81f47c9f,0xad1163ed,0xea7b5965,0x1a00726e,
573 0x11403092,0x00da6d77,0x4a0cdd61,0xad1f4603,
574 0x605bdfb0,0x9eedc364,0x22ebe6a8,0xcee7d28a,
575 0xa0e736a0,0x5564a6b9,0x10853209,0xc7eb8f37,
576 0x2de705ca,0x8951570f,0xdf09822b,0xbd691a6c,
577 0xaa12e4f2,0x87451c0f,0xe0f6a27a,0x3ada4819,
578 0x4cf1764f,0x0d771c2b,0x67cdb156,0x350d8384,
579 0x5938fa0f,0x42399ef3,0x36997b07,0x0e84093d,
580 0x4aa93e61,0x8360d87b,0x1fa98b0c,0x1149382c,
581 0xe97625a5,0x0614d1b7,0x0e25244b,0x0c768347,
582 0x589e8d82,0x0d2059d1,0xa466bb1e,0xf8da0a82,
583 0x04f19130,0xba6e4ec0,0x99265164,0x1ee7230d,
584 0x50b2ad80,0xeaee6801,0x8db2a283,0xea8bf59e,
585 };
diff --git a/src/lib/libcrypto/comp/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_rle.c b/src/lib/libcrypto/comp/c_rle.c
new file mode 100644
index 0000000000..efd366fa22
--- /dev/null
+++ b/src/lib/libcrypto/comp/c_rle.c
@@ -0,0 +1,62 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
8 unsigned int olen, unsigned char *in, unsigned int ilen);
9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
10 unsigned int olen, unsigned char *in, unsigned int ilen);
11
12static COMP_METHOD rle_method={
13 NID_rle_compression,
14 LN_rle_compression,
15 NULL,
16 NULL,
17 rle_compress_block,
18 rle_expand_block,
19 NULL,
20 NULL,
21 };
22
23COMP_METHOD *COMP_rle(void)
24 {
25 return(&rle_method);
26 }
27
28static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
29 unsigned int olen, unsigned char *in, unsigned int ilen)
30 {
31 /* int i; */
32
33 if (olen < (ilen+1))
34 {
35 /* ZZZZZZZZZZZZZZZZZZZZZZ */
36 return(-1);
37 }
38
39 *(out++)=0;
40 memcpy(out,in,ilen);
41 return(ilen+1);
42 }
43
44static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
45 unsigned int olen, unsigned char *in, unsigned int ilen)
46 {
47 int i;
48
49 if (olen < (ilen-1))
50 {
51 /* ZZZZZZZZZZZZZZZZZZZZZZ */
52 return(-1);
53 }
54
55 i= *(in++);
56 if (i == 0)
57 {
58 memcpy(out,in,ilen-1);
59 }
60 return(ilen-1);
61 }
62
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
new file mode 100644
index 0000000000..1bd2850d15
--- /dev/null
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -0,0 +1,271 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6#include <openssl/err.h>
7
8COMP_METHOD *COMP_zlib(void );
9
10static COMP_METHOD zlib_method_nozlib={
11 NID_undef,
12 "(undef)",
13 NULL,
14 NULL,
15 NULL,
16 NULL,
17 NULL,
18 NULL,
19 };
20
21#ifndef ZLIB
22#undef ZLIB_SHARED
23#else
24
25#include <zlib.h>
26
27static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen);
29static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
30 unsigned int olen, unsigned char *in, unsigned int ilen);
31
32static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
33 uLong sourceLen);
34
35static COMP_METHOD zlib_method={
36 NID_zlib_compression,
37 LN_zlib_compression,
38 NULL,
39 NULL,
40 zlib_compress_block,
41 zlib_expand_block,
42 NULL,
43 NULL,
44 };
45
46/*
47 * When OpenSSL is built on Windows, we do not want to require that
48 * the ZLIB.DLL be available in order for the OpenSSL DLLs to
49 * work. Therefore, all ZLIB routines are loaded at run time
50 * and we do not link to a .LIB file.
51 */
52#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
53# include <windows.h>
54
55# define Z_CALLCONV _stdcall
56# define ZLIB_SHARED
57#else
58# define Z_CALLCONV
59#endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
60
61#ifdef ZLIB_SHARED
62#include <openssl/dso.h>
63
64/* Prototypes for built in stubs */
65static int stub_compress(Bytef *dest,uLongf *destLen,
66 const Bytef *source, uLong sourceLen);
67static int stub_inflateEnd(z_streamp strm);
68static int stub_inflate(z_streamp strm, int flush);
69static int stub_inflateInit_(z_streamp strm, const char * version,
70 int stream_size);
71
72/* Function pointers */
73typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen,
74 const Bytef *source, uLong sourceLen);
75typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm);
76typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush);
77typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm,
78 const char * version, int stream_size);
79static compress_ft p_compress=NULL;
80static inflateEnd_ft p_inflateEnd=NULL;
81static inflate_ft p_inflate=NULL;
82static inflateInit__ft p_inflateInit_=NULL;
83
84static int zlib_loaded = 0; /* only attempt to init func pts once */
85static DSO *zlib_dso = NULL;
86
87#define compress stub_compress
88#define inflateEnd stub_inflateEnd
89#define inflate stub_inflate
90#define inflateInit_ stub_inflateInit_
91#endif /* ZLIB_SHARED */
92
93static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
94 unsigned int olen, unsigned char *in, unsigned int ilen)
95 {
96 unsigned long l;
97 int i;
98 int clear=1;
99
100 if (ilen > 128)
101 {
102 out[0]=1;
103 l=olen-1;
104 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
105 if (i != Z_OK)
106 return(-1);
107 if (ilen > l)
108 {
109 clear=0;
110 l++;
111 }
112 }
113 if (clear)
114 {
115 out[0]=0;
116 memcpy(&(out[1]),in,ilen);
117 l=ilen+1;
118 }
119#ifdef DEBUG_ZLIB
120 fprintf(stderr,"compress(%4d)->%4d %s\n",
121 ilen,(int)l,(clear)?"clear":"zlib");
122#endif
123 return((int)l);
124 }
125
126static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
127 unsigned int olen, unsigned char *in, unsigned int ilen)
128 {
129 unsigned long l;
130 int i;
131
132 if (in[0])
133 {
134 l=olen;
135 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
136 if (i != Z_OK)
137 return(-1);
138 }
139 else
140 {
141 memcpy(out,&(in[1]),ilen-1);
142 l=ilen-1;
143 }
144#ifdef DEBUG_ZLIB
145 fprintf(stderr,"expand (%4d)->%4d %s\n",
146 ilen,(int)l,in[0]?"zlib":"clear");
147#endif
148 return((int)l);
149 }
150
151static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
152 uLong sourceLen)
153{
154 z_stream stream;
155 int err;
156
157 stream.next_in = (Bytef*)source;
158 stream.avail_in = (uInt)sourceLen;
159 /* Check for source > 64K on 16-bit machine: */
160 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
161
162 stream.next_out = dest;
163 stream.avail_out = (uInt)*destLen;
164 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
165
166 stream.zalloc = (alloc_func)0;
167 stream.zfree = (free_func)0;
168
169 err = inflateInit(&stream);
170 if (err != Z_OK) return err;
171
172 err = inflate(&stream, Z_FINISH);
173 if (err != Z_STREAM_END) {
174 inflateEnd(&stream);
175 return err;
176 }
177 *destLen = stream.total_out;
178
179 err = inflateEnd(&stream);
180 return err;
181}
182
183#endif
184
185COMP_METHOD *COMP_zlib(void)
186 {
187 COMP_METHOD *meth = &zlib_method_nozlib;
188
189#ifdef ZLIB_SHARED
190 if (!zlib_loaded)
191 {
192#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
193 zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0);
194 if (!zlib_dso)
195 {
196 zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0);
197 if (zlib_dso)
198 {
199 /* Clear the errors from the first failed
200 DSO_load() */
201 ERR_clear_error();
202 }
203 }
204#else
205 zlib_dso = DSO_load(NULL, "z", NULL, 0);
206#endif
207 if (zlib_dso != NULL)
208 {
209 p_compress
210 = (compress_ft) DSO_bind_func(zlib_dso,
211 "compress");
212 p_inflateEnd
213 = (inflateEnd_ft) DSO_bind_func(zlib_dso,
214 "inflateEnd");
215 p_inflate
216 = (inflate_ft) DSO_bind_func(zlib_dso,
217 "inflate");
218 p_inflateInit_
219 = (inflateInit__ft) DSO_bind_func(zlib_dso,
220 "inflateInit_");
221 zlib_loaded++;
222 }
223 }
224
225#endif
226#if defined(ZLIB) || defined(ZLIB_SHARED)
227 meth = &zlib_method;
228#endif
229
230 return(meth);
231 }
232
233#ifdef ZLIB_SHARED
234/* Stubs for each function to be dynamicly loaded */
235static int
236stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen)
237 {
238 if (p_compress)
239 return(p_compress(dest,destLen,source,sourceLen));
240 else
241 return(Z_MEM_ERROR);
242 }
243
244static int
245stub_inflateEnd(z_streamp strm)
246 {
247 if ( p_inflateEnd )
248 return(p_inflateEnd(strm));
249 else
250 return(Z_MEM_ERROR);
251 }
252
253static int
254stub_inflate(z_streamp strm, int flush)
255 {
256 if ( p_inflate )
257 return(p_inflate(strm,flush));
258 else
259 return(Z_MEM_ERROR);
260 }
261
262static int
263stub_inflateInit_(z_streamp strm, const char * version, int stream_size)
264 {
265 if ( p_inflateInit_ )
266 return(p_inflateInit_(strm,version,stream_size));
267 else
268 return(Z_MEM_ERROR);
269 }
270
271#endif /* ZLIB_SHARED */
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
new file mode 100644
index 0000000000..ab48b78ae9
--- /dev/null
+++ b/src/lib/libcrypto/comp/comp.h
@@ -0,0 +1,59 @@
1
2#ifndef HEADER_COMP_H
3#define HEADER_COMP_H
4
5#include <openssl/crypto.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef struct comp_method_st
12 {
13 int type; /* NID for compression library */
14 const char *name; /* A text string to identify the library */
15 int (*init)();
16 void (*finish)();
17 int (*compress)();
18 int (*expand)();
19 long (*ctrl)();
20 long (*callback_ctrl)();
21 } COMP_METHOD;
22
23typedef struct comp_ctx_st
24 {
25 COMP_METHOD *meth;
26 unsigned long compress_in;
27 unsigned long compress_out;
28 unsigned long expand_in;
29 unsigned long expand_out;
30
31 CRYPTO_EX_DATA ex_data;
32 } COMP_CTX;
33
34
35COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
36void COMP_CTX_free(COMP_CTX *ctx);
37int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
38 unsigned char *in, int ilen);
39int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
40 unsigned char *in, int ilen);
41COMP_METHOD *COMP_rle(void );
42COMP_METHOD *COMP_zlib(void );
43
44/* BEGIN ERROR CODES */
45/* The following lines are auto generated by the script mkerr.pl. Any changes
46 * made after this point may be overwritten when the script is next run.
47 */
48void ERR_load_COMP_strings(void);
49
50/* Error codes for the COMP functions. */
51
52/* Function codes. */
53
54/* Reason codes. */
55
56#ifdef __cplusplus
57}
58#endif
59#endif
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
new file mode 100644
index 0000000000..1652b8c2c4
--- /dev/null
+++ b/src/lib/libcrypto/comp/comp_err.c
@@ -0,0 +1,92 @@
1/* crypto/comp/comp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/comp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA COMP_str_functs[]=
68 {
69{0,NULL}
70 };
71
72static ERR_STRING_DATA COMP_str_reasons[]=
73 {
74{0,NULL}
75 };
76
77#endif
78
79void ERR_load_COMP_strings(void)
80 {
81 static int init=1;
82
83 if (init)
84 {
85 init=0;
86#ifndef OPENSSL_NO_ERR
87 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs);
88 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons);
89#endif
90
91 }
92 }
diff --git a/src/lib/libcrypto/comp/comp_lib.c b/src/lib/libcrypto/comp/comp_lib.c
new file mode 100644
index 0000000000..beb98ce8cc
--- /dev/null
+++ b/src/lib/libcrypto/comp/comp_lib.c
@@ -0,0 +1,78 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
8 {
9 COMP_CTX *ret;
10
11 if ((ret=(COMP_CTX *)OPENSSL_malloc(sizeof(COMP_CTX))) == NULL)
12 {
13 /* ZZZZZZZZZZZZZZZZ */
14 return(NULL);
15 }
16 memset(ret,0,sizeof(COMP_CTX));
17 ret->meth=meth;
18 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
19 {
20 OPENSSL_free(ret);
21 ret=NULL;
22 }
23#if 0
24 else
25 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
26#endif
27 return(ret);
28 }
29
30void COMP_CTX_free(COMP_CTX *ctx)
31 {
32 /* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */
33
34 if(ctx == NULL)
35 return;
36
37 if (ctx->meth->finish != NULL)
38 ctx->meth->finish(ctx);
39
40 OPENSSL_free(ctx);
41 }
42
43int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
44 unsigned char *in, int ilen)
45 {
46 int ret;
47 if (ctx->meth->compress == NULL)
48 {
49 /* ZZZZZZZZZZZZZZZZZ */
50 return(-1);
51 }
52 ret=ctx->meth->compress(ctx,out,olen,in,ilen);
53 if (ret > 0)
54 {
55 ctx->compress_in+=ilen;
56 ctx->compress_out+=ret;
57 }
58 return(ret);
59 }
60
61int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
62 unsigned char *in, int ilen)
63 {
64 int ret;
65
66 if (ctx->meth->expand == NULL)
67 {
68 /* ZZZZZZZZZZZZZZZZZ */
69 return(-1);
70 }
71 ret=ctx->meth->expand(ctx,out,olen,in,ilen);
72 if (ret > 0)
73 {
74 ctx->expand_in+=ilen;
75 ctx->expand_out+=ret;
76 }
77 return(ret);
78 }
diff --git a/src/lib/libcrypto/conf/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/README b/src/lib/libcrypto/conf/README
new file mode 100644
index 0000000000..ca58d0240f
--- /dev/null
+++ b/src/lib/libcrypto/conf/README
@@ -0,0 +1,78 @@
1WARNING WARNING WARNING!!!
2
3This stuff is experimental, may change radically or be deleted altogether
4before OpenSSL 0.9.7 release. You have been warned!
5
6Configuration modules. These are a set of modules which can perform
7various configuration functions.
8
9Currently the routines should be called at most once when an application
10starts up: that is before it starts any threads.
11
12The routines read a configuration file set up like this:
13
14-----
15#default section
16openssl_init=init_section
17
18[init_section]
19
20module1=value1
21#Second instance of module1
22module1.1=valueX
23module2=value2
24module3=dso_literal
25module4=dso_section
26
27[dso_section]
28
29path=/some/path/to/some/dso.so
30other_stuff=other_value
31----
32
33When this file is loaded a configuration module with the specified
34string (module* in the above example) is looked up and its init
35function called as:
36
37int conf_init_func(CONF_IMODULE *md, CONF *cnf);
38
39The function can then take whatever action is appropriate, for example
40further lookups based on the value. Multiple instances of the same
41config module can be loaded.
42
43When the application closes down the modules are cleaned up by calling
44an optional finish function:
45
46void conf_finish_func(CONF_IMODULE *md);
47
48The finish functions are called in reverse order: that is the last module
49loaded is the first one cleaned up.
50
51If no module exists with a given name then an attempt is made to load
52a DSO with the supplied name. This might mean that "module3" attempts
53to load a DSO called libmodule3.so or module3.dll for example. An explicit
54DSO name can be given by including a separate section as in the module4 example
55above.
56
57The DSO is expected to at least contain an initialization function:
58
59int OPENSSL_init(CONF_IMODULE *md, CONF *cnf);
60
61and may also include a finish function:
62
63void OPENSSL_finish(CONF_IMODULE *md);
64
65Static modules can also be added using,
66
67int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func *ffunc);
68
69where "name" is the name in the configuration file this function corresponds to.
70
71A set of builtin modules (currently only an ASN1 non functional test module) can be
72added by calling OPENSSL_load_builtin_modules().
73
74The function OPENSSL_config() is intended as a simple configuration function that
75any application can call to perform various default configuration tasks. It uses the
76file openssl.cnf in the usual locations.
77
78
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
new file mode 100644
index 0000000000..f4671442ab
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf.h
@@ -0,0 +1,250 @@
1/* crypto/conf/conf.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CONF_H
60#define HEADER_CONF_H
61
62#include <openssl/bio.h>
63#include <openssl/lhash.h>
64#include <openssl/stack.h>
65#include <openssl/safestack.h>
66#include <openssl/e_os2.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72typedef struct
73 {
74 char *section;
75 char *name;
76 char *value;
77 } CONF_VALUE;
78
79DECLARE_STACK_OF(CONF_VALUE)
80DECLARE_STACK_OF(CONF_MODULE)
81DECLARE_STACK_OF(CONF_IMODULE)
82
83struct conf_st;
84typedef struct conf_st CONF;
85struct conf_method_st;
86typedef struct conf_method_st CONF_METHOD;
87
88struct conf_method_st
89 {
90 const char *name;
91 CONF *(*create)(CONF_METHOD *meth);
92 int (*init)(CONF *conf);
93 int (*destroy)(CONF *conf);
94 int (*destroy_data)(CONF *conf);
95 int (*load_bio)(CONF *conf, BIO *bp, long *eline);
96 int (*dump)(const CONF *conf, BIO *bp);
97 int (*is_number)(const CONF *conf, char c);
98 int (*to_int)(const CONF *conf, char c);
99 int (*load)(CONF *conf, const char *name, long *eline);
100 };
101
102/* Module definitions */
103
104typedef struct conf_imodule_st CONF_IMODULE;
105typedef struct conf_module_st CONF_MODULE;
106
107/* DSO module function typedefs */
108typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf);
109typedef void conf_finish_func(CONF_IMODULE *md);
110
111#define CONF_MFLAGS_IGNORE_ERRORS 0x1
112#define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
113#define CONF_MFLAGS_SILENT 0x4
114#define CONF_MFLAGS_NO_DSO 0x8
115#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
116
117int CONF_set_default_method(CONF_METHOD *meth);
118void CONF_set_nconf(CONF *conf,LHASH *hash);
119LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
120#ifndef OPENSSL_NO_FP_API
121LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
122#endif
123LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
124STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section);
125char *CONF_get_string(LHASH *conf,const char *group,const char *name);
126long CONF_get_number(LHASH *conf,const char *group,const char *name);
127void CONF_free(LHASH *conf);
128int CONF_dump_fp(LHASH *conf, FILE *out);
129int CONF_dump_bio(LHASH *conf, BIO *out);
130
131void OPENSSL_config(const char *config_name);
132void OPENSSL_no_config(void);
133
134/* New conf code. The semantics are different from the functions above.
135 If that wasn't the case, the above functions would have been replaced */
136
137struct conf_st
138 {
139 CONF_METHOD *meth;
140 void *meth_data;
141 LHASH *data;
142 };
143
144CONF *NCONF_new(CONF_METHOD *meth);
145CONF_METHOD *NCONF_default(void);
146CONF_METHOD *NCONF_WIN32(void);
147#if 0 /* Just to give you an idea of what I have in mind */
148CONF_METHOD *NCONF_XML(void);
149#endif
150void NCONF_free(CONF *conf);
151void NCONF_free_data(CONF *conf);
152
153int NCONF_load(CONF *conf,const char *file,long *eline);
154#ifndef OPENSSL_NO_FP_API
155int NCONF_load_fp(CONF *conf, FILE *fp,long *eline);
156#endif
157int NCONF_load_bio(CONF *conf, BIO *bp,long *eline);
158STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section);
159char *NCONF_get_string(const CONF *conf,const char *group,const char *name);
160int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
161 long *result);
162int NCONF_dump_fp(const CONF *conf, FILE *out);
163int NCONF_dump_bio(const CONF *conf, BIO *out);
164
165#if 0 /* The following function has no error checking,
166 and should therefore be avoided */
167long NCONF_get_number(CONF *conf,char *group,char *name);
168#else
169#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
170#endif
171
172/* Module functions */
173
174int CONF_modules_load(const CONF *cnf, const char *appname,
175 unsigned long flags);
176int CONF_modules_load_file(const char *filename, const char *appname,
177 unsigned long flags);
178void CONF_modules_unload(int all);
179void CONF_modules_finish(void);
180void CONF_modules_free(void);
181int CONF_module_add(const char *name, conf_init_func *ifunc,
182 conf_finish_func *ffunc);
183
184const char *CONF_imodule_get_name(const CONF_IMODULE *md);
185const char *CONF_imodule_get_value(const CONF_IMODULE *md);
186void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
187void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
188CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
189unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
190void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
191void *CONF_module_get_usr_data(CONF_MODULE *pmod);
192void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
193
194char *CONF_get1_default_config_file(void);
195
196int CONF_parse_list(const char *list, int sep, int nospc,
197 int (*list_cb)(const char *elem, int len, void *usr), void *arg);
198
199void OPENSSL_load_builtin_modules(void);
200
201/* BEGIN ERROR CODES */
202/* The following lines are auto generated by the script mkerr.pl. Any changes
203 * made after this point may be overwritten when the script is next run.
204 */
205void ERR_load_CONF_strings(void);
206
207/* Error codes for the CONF functions. */
208
209/* Function codes. */
210#define CONF_F_CONF_DUMP_FP 104
211#define CONF_F_CONF_LOAD 100
212#define CONF_F_CONF_LOAD_BIO 102
213#define CONF_F_CONF_LOAD_FP 103
214#define CONF_F_CONF_MODULES_LOAD 116
215#define CONF_F_MODULE_INIT 115
216#define CONF_F_MODULE_LOAD_DSO 117
217#define CONF_F_MODULE_RUN 118
218#define CONF_F_NCONF_DUMP_BIO 105
219#define CONF_F_NCONF_DUMP_FP 106
220#define CONF_F_NCONF_GET_NUMBER 107
221#define CONF_F_NCONF_GET_NUMBER_E 112
222#define CONF_F_NCONF_GET_SECTION 108
223#define CONF_F_NCONF_GET_STRING 109
224#define CONF_F_NCONF_LOAD 113
225#define CONF_F_NCONF_LOAD_BIO 110
226#define CONF_F_NCONF_LOAD_FP 114
227#define CONF_F_NCONF_NEW 111
228#define CONF_F_STR_COPY 101
229
230/* Reason codes. */
231#define CONF_R_ERROR_LOADING_DSO 110
232#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
233#define CONF_R_MISSING_EQUAL_SIGN 101
234#define CONF_R_MISSING_FINISH_FUNCTION 111
235#define CONF_R_MISSING_INIT_FUNCTION 112
236#define CONF_R_MODULE_INITIALIZATION_ERROR 109
237#define CONF_R_NO_CLOSE_BRACE 102
238#define CONF_R_NO_CONF 105
239#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
240#define CONF_R_NO_SECTION 107
241#define CONF_R_NO_SUCH_FILE 114
242#define CONF_R_NO_VALUE 108
243#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
244#define CONF_R_UNKNOWN_MODULE_NAME 113
245#define CONF_R_VARIABLE_HAS_NO_VALUE 104
246
247#ifdef __cplusplus
248}
249#endif
250#endif
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c
new file mode 100644
index 0000000000..0032baa711
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_api.c
@@ -0,0 +1,308 @@
1/* conf_api.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Part of the code in here was originally in conf.c, which is now removed */
60
61#ifndef CONF_DEBUG
62# undef NDEBUG /* avoid conflicting definitions */
63# define NDEBUG
64#endif
65
66#include <assert.h>
67#include <string.h>
68#include <openssl/conf.h>
69#include <openssl/conf_api.h>
70#include "e_os.h"
71
72static void value_free_hash(CONF_VALUE *a, LHASH *conf);
73static void value_free_stack(CONF_VALUE *a,LHASH *conf);
74static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *)
75static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *)
76/* We don't use function pointer casting or wrapper functions - but cast each
77 * callback parameter inside the callback functions. */
78/* static unsigned long hash(CONF_VALUE *v); */
79static unsigned long hash(const void *v_void);
80/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */
81static int cmp_conf(const void *a_void,const void *b_void);
82
83/* Up until OpenSSL 0.9.5a, this was get_section */
84CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)
85 {
86 CONF_VALUE *v,vv;
87
88 if ((conf == NULL) || (section == NULL)) return(NULL);
89 vv.name=NULL;
90 vv.section=(char *)section;
91 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
92 return(v);
93 }
94
95/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
96STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
97 const char *section)
98 {
99 CONF_VALUE *v;
100
101 v=_CONF_get_section(conf,section);
102 if (v != NULL)
103 return((STACK_OF(CONF_VALUE) *)v->value);
104 else
105 return(NULL);
106 }
107
108int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
109 {
110 CONF_VALUE *v = NULL;
111 STACK_OF(CONF_VALUE) *ts;
112
113 ts = (STACK_OF(CONF_VALUE) *)section->value;
114
115 value->section=section->section;
116 if (!sk_CONF_VALUE_push(ts,value))
117 {
118 return 0;
119 }
120
121 v = (CONF_VALUE *)lh_insert(conf->data, value);
122 if (v != NULL)
123 {
124 sk_CONF_VALUE_delete_ptr(ts,v);
125 OPENSSL_free(v->name);
126 OPENSSL_free(v->value);
127 OPENSSL_free(v);
128 }
129 return 1;
130 }
131
132char *_CONF_get_string(const CONF *conf, const char *section, const char *name)
133 {
134 CONF_VALUE *v,vv;
135 char *p;
136
137 if (name == NULL) return(NULL);
138 if (conf != NULL)
139 {
140 if (section != NULL)
141 {
142 vv.name=(char *)name;
143 vv.section=(char *)section;
144 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
145 if (v != NULL) return(v->value);
146 if (strcmp(section,"ENV") == 0)
147 {
148 p=Getenv(name);
149 if (p != NULL) return(p);
150 }
151 }
152 vv.section="default";
153 vv.name=(char *)name;
154 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
155 if (v != NULL)
156 return(v->value);
157 else
158 return(NULL);
159 }
160 else
161 return(Getenv(name));
162 }
163
164#if 0 /* There's no way to provide error checking with this function, so
165 force implementors of the higher levels to get a string and read
166 the number themselves. */
167long _CONF_get_number(CONF *conf, char *section, char *name)
168 {
169 char *str;
170 long ret=0;
171
172 str=_CONF_get_string(conf,section,name);
173 if (str == NULL) return(0);
174 for (;;)
175 {
176 if (conf->meth->is_number(conf, *str))
177 ret=ret*10+conf->meth->to_int(conf, *str);
178 else
179 return(ret);
180 str++;
181 }
182 }
183#endif
184
185int _CONF_new_data(CONF *conf)
186 {
187 if (conf == NULL)
188 {
189 return 0;
190 }
191 if (conf->data == NULL)
192 if ((conf->data = lh_new(hash, cmp_conf)) == NULL)
193 {
194 return 0;
195 }
196 return 1;
197 }
198
199void _CONF_free_data(CONF *conf)
200 {
201 if (conf == NULL || conf->data == NULL) return;
202
203 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
204 * works as expected */
205 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash),
206 conf->data);
207
208 /* We now have only 'section' entries in the hash table.
209 * Due to problems with */
210
211 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack),
212 conf->data);
213 lh_free(conf->data);
214 }
215
216static void value_free_hash(CONF_VALUE *a, LHASH *conf)
217 {
218 if (a->name != NULL)
219 {
220 a=(CONF_VALUE *)lh_delete(conf,a);
221 }
222 }
223
224static void value_free_stack(CONF_VALUE *a, LHASH *conf)
225 {
226 CONF_VALUE *vv;
227 STACK *sk;
228 int i;
229
230 if (a->name != NULL) return;
231
232 sk=(STACK *)a->value;
233 for (i=sk_num(sk)-1; i>=0; i--)
234 {
235 vv=(CONF_VALUE *)sk_value(sk,i);
236 OPENSSL_free(vv->value);
237 OPENSSL_free(vv->name);
238 OPENSSL_free(vv);
239 }
240 if (sk != NULL) sk_free(sk);
241 OPENSSL_free(a->section);
242 OPENSSL_free(a);
243 }
244
245/* static unsigned long hash(CONF_VALUE *v) */
246static unsigned long hash(const void *v_void)
247 {
248 CONF_VALUE *v = (CONF_VALUE *)v_void;
249 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
250 }
251
252/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */
253static int cmp_conf(const void *a_void,const void *b_void)
254 {
255 int i;
256 CONF_VALUE *a = (CONF_VALUE *)a_void;
257 CONF_VALUE *b = (CONF_VALUE *)b_void;
258
259 if (a->section != b->section)
260 {
261 i=strcmp(a->section,b->section);
262 if (i) return(i);
263 }
264
265 if ((a->name != NULL) && (b->name != NULL))
266 {
267 i=strcmp(a->name,b->name);
268 return(i);
269 }
270 else if (a->name == b->name)
271 return(0);
272 else
273 return((a->name == NULL)?-1:1);
274 }
275
276/* Up until OpenSSL 0.9.5a, this was new_section */
277CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
278 {
279 STACK *sk=NULL;
280 int ok=0,i;
281 CONF_VALUE *v=NULL,*vv;
282
283 if ((sk=sk_new_null()) == NULL)
284 goto err;
285 if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
286 goto err;
287 i=strlen(section)+1;
288 if ((v->section=(char *)OPENSSL_malloc(i)) == NULL)
289 goto err;
290
291 memcpy(v->section,section,i);
292 v->name=NULL;
293 v->value=(char *)sk;
294
295 vv=(CONF_VALUE *)lh_insert(conf->data,v);
296 assert(vv == NULL);
297 ok=1;
298err:
299 if (!ok)
300 {
301 if (sk != NULL) sk_free(sk);
302 if (v != NULL) OPENSSL_free(v);
303 v=NULL;
304 }
305 return(v);
306 }
307
308IMPLEMENT_STACK_OF(CONF_VALUE)
diff --git a/src/lib/libcrypto/conf/conf_api.h b/src/lib/libcrypto/conf/conf_api.h
new file mode 100644
index 0000000000..87a954aff6
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_api.h
@@ -0,0 +1,89 @@
1/* conf_api.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CONF_API_H
60#define HEADER_CONF_API_H
61
62#include <openssl/lhash.h>
63#include <openssl/conf.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* Up until OpenSSL 0.9.5a, this was new_section */
70CONF_VALUE *_CONF_new_section(CONF *conf, const char *section);
71/* Up until OpenSSL 0.9.5a, this was get_section */
72CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section);
73/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
74STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
75 const char *section);
76
77int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
78char *_CONF_get_string(const CONF *conf, const char *section,
79 const char *name);
80long _CONF_get_number(const CONF *conf, const char *section, const char *name);
81
82int _CONF_new_data(CONF *conf);
83void _CONF_free_data(CONF *conf);
84
85#ifdef __cplusplus
86}
87#endif
88#endif
89
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
new file mode 100644
index 0000000000..b5a876ae68
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -0,0 +1,745 @@
1/* crypto/conf/conf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Part of the code in here was originally in conf.c, which is now removed */
60
61#include <stdio.h>
62#include <string.h>
63#include <openssl/stack.h>
64#include <openssl/lhash.h>
65#include <openssl/conf.h>
66#include <openssl/conf_api.h>
67#include "conf_def.h"
68#include <openssl/buffer.h>
69#include <openssl/err.h>
70#include "cryptlib.h"
71
72static char *eat_ws(CONF *conf, char *p);
73static char *eat_alpha_numeric(CONF *conf, char *p);
74static void clear_comments(CONF *conf, char *p);
75static int str_copy(CONF *conf,char *section,char **to, char *from);
76static char *scan_quote(CONF *conf, char *p);
77static char *scan_dquote(CONF *conf, char *p);
78#define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
79
80static CONF *def_create(CONF_METHOD *meth);
81static int def_init_default(CONF *conf);
82static int def_init_WIN32(CONF *conf);
83static int def_destroy(CONF *conf);
84static int def_destroy_data(CONF *conf);
85static int def_load(CONF *conf, const char *name, long *eline);
86static int def_load_bio(CONF *conf, BIO *bp, long *eline);
87static int def_dump(const CONF *conf, BIO *bp);
88static int def_is_number(const CONF *conf, char c);
89static int def_to_int(const CONF *conf, char c);
90
91const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT;
92
93static CONF_METHOD default_method = {
94 "OpenSSL default",
95 def_create,
96 def_init_default,
97 def_destroy,
98 def_destroy_data,
99 def_load_bio,
100 def_dump,
101 def_is_number,
102 def_to_int,
103 def_load
104 };
105
106static CONF_METHOD WIN32_method = {
107 "WIN32",
108 def_create,
109 def_init_WIN32,
110 def_destroy,
111 def_destroy_data,
112 def_load_bio,
113 def_dump,
114 def_is_number,
115 def_to_int,
116 def_load
117 };
118
119CONF_METHOD *NCONF_default()
120 {
121 return &default_method;
122 }
123CONF_METHOD *NCONF_WIN32()
124 {
125 return &WIN32_method;
126 }
127
128static CONF *def_create(CONF_METHOD *meth)
129 {
130 CONF *ret;
131
132 ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
133 if (ret)
134 if (meth->init(ret) == 0)
135 {
136 OPENSSL_free(ret);
137 ret = NULL;
138 }
139 return ret;
140 }
141
142static int def_init_default(CONF *conf)
143 {
144 if (conf == NULL)
145 return 0;
146
147 conf->meth = &default_method;
148 conf->meth_data = (void *)CONF_type_default;
149 conf->data = NULL;
150
151 return 1;
152 }
153
154static int def_init_WIN32(CONF *conf)
155 {
156 if (conf == NULL)
157 return 0;
158
159 conf->meth = &WIN32_method;
160 conf->meth_data = (void *)CONF_type_win32;
161 conf->data = NULL;
162
163 return 1;
164 }
165
166static int def_destroy(CONF *conf)
167 {
168 if (def_destroy_data(conf))
169 {
170 OPENSSL_free(conf);
171 return 1;
172 }
173 return 0;
174 }
175
176static int def_destroy_data(CONF *conf)
177 {
178 if (conf == NULL)
179 return 0;
180 _CONF_free_data(conf);
181 return 1;
182 }
183
184static int def_load(CONF *conf, const char *name, long *line)
185 {
186 int ret;
187 BIO *in=NULL;
188
189#ifdef OPENSSL_SYS_VMS
190 in=BIO_new_file(name, "r");
191#else
192 in=BIO_new_file(name, "rb");
193#endif
194 if (in == NULL)
195 {
196 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
197 CONFerr(CONF_F_CONF_LOAD,CONF_R_NO_SUCH_FILE);
198 else
199 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
200 return 0;
201 }
202
203 ret = def_load_bio(conf, in, line);
204 BIO_free(in);
205
206 return ret;
207 }
208
209static int def_load_bio(CONF *conf, BIO *in, long *line)
210 {
211/* The macro BUFSIZE conflicts with a system macro in VxWorks */
212#define CONFBUFSIZE 512
213 int bufnum=0,i,ii;
214 BUF_MEM *buff=NULL;
215 char *s,*p,*end;
216 int again,n;
217 long eline=0;
218 char btmp[DECIMAL_SIZE(eline)+1];
219 CONF_VALUE *v=NULL,*tv;
220 CONF_VALUE *sv=NULL;
221 char *section=NULL,*buf;
222 STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
223 char *start,*psection,*pname;
224 void *h = (void *)(conf->data);
225
226 if ((buff=BUF_MEM_new()) == NULL)
227 {
228 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
229 goto err;
230 }
231
232 section=(char *)OPENSSL_malloc(10);
233 if (section == NULL)
234 {
235 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
236 goto err;
237 }
238 BUF_strlcpy(section,"default",10);
239
240 if (_CONF_new_data(conf) == 0)
241 {
242 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
243 goto err;
244 }
245
246 sv=_CONF_new_section(conf,section);
247 if (sv == NULL)
248 {
249 CONFerr(CONF_F_CONF_LOAD_BIO,
250 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
251 goto err;
252 }
253 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
254
255 bufnum=0;
256 again=0;
257 for (;;)
258 {
259 if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE))
260 {
261 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
262 goto err;
263 }
264 p= &(buff->data[bufnum]);
265 *p='\0';
266 BIO_gets(in, p, CONFBUFSIZE-1);
267 p[CONFBUFSIZE-1]='\0';
268 ii=i=strlen(p);
269 if (i == 0 && !again) break;
270 again=0;
271 while (i > 0)
272 {
273 if ((p[i-1] != '\r') && (p[i-1] != '\n'))
274 break;
275 else
276 i--;
277 }
278 /* we removed some trailing stuff so there is a new
279 * line on the end. */
280 if (ii && i == ii)
281 again=1; /* long line */
282 else
283 {
284 p[i]='\0';
285 eline++; /* another input line */
286 }
287
288 /* we now have a line with trailing \r\n removed */
289
290 /* i is the number of bytes */
291 bufnum+=i;
292
293 v=NULL;
294 /* check for line continuation */
295 if (bufnum >= 1)
296 {
297 /* If we have bytes and the last char '\\' and
298 * second last char is not '\\' */
299 p= &(buff->data[bufnum-1]);
300 if (IS_ESC(conf,p[0]) &&
301 ((bufnum <= 1) || !IS_ESC(conf,p[-1])))
302 {
303 bufnum--;
304 again=1;
305 }
306 }
307 if (again) continue;
308 bufnum=0;
309 buf=buff->data;
310
311 clear_comments(conf, buf);
312 n=strlen(buf);
313 s=eat_ws(conf, buf);
314 if (IS_EOF(conf,*s)) continue; /* blank line */
315 if (*s == '[')
316 {
317 char *ss;
318
319 s++;
320 start=eat_ws(conf, s);
321 ss=start;
322again:
323 end=eat_alpha_numeric(conf, ss);
324 p=eat_ws(conf, end);
325 if (*p != ']')
326 {
327 if (*p != '\0')
328 {
329 ss=p;
330 goto again;
331 }
332 CONFerr(CONF_F_CONF_LOAD_BIO,
333 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
334 goto err;
335 }
336 *end='\0';
337 if (!str_copy(conf,NULL,&section,start)) goto err;
338 if ((sv=_CONF_get_section(conf,section)) == NULL)
339 sv=_CONF_new_section(conf,section);
340 if (sv == NULL)
341 {
342 CONFerr(CONF_F_CONF_LOAD_BIO,
343 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
344 goto err;
345 }
346 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
347 continue;
348 }
349 else
350 {
351 pname=s;
352 psection=NULL;
353 end=eat_alpha_numeric(conf, s);
354 if ((end[0] == ':') && (end[1] == ':'))
355 {
356 *end='\0';
357 end+=2;
358 psection=pname;
359 pname=end;
360 end=eat_alpha_numeric(conf, end);
361 }
362 p=eat_ws(conf, end);
363 if (*p != '=')
364 {
365 CONFerr(CONF_F_CONF_LOAD_BIO,
366 CONF_R_MISSING_EQUAL_SIGN);
367 goto err;
368 }
369 *end='\0';
370 p++;
371 start=eat_ws(conf, p);
372 while (!IS_EOF(conf,*p))
373 p++;
374 p--;
375 while ((p != start) && (IS_WS(conf,*p)))
376 p--;
377 p++;
378 *p='\0';
379
380 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
381 {
382 CONFerr(CONF_F_CONF_LOAD_BIO,
383 ERR_R_MALLOC_FAILURE);
384 goto err;
385 }
386 if (psection == NULL) psection=section;
387 v->name=(char *)OPENSSL_malloc(strlen(pname)+1);
388 v->value=NULL;
389 if (v->name == NULL)
390 {
391 CONFerr(CONF_F_CONF_LOAD_BIO,
392 ERR_R_MALLOC_FAILURE);
393 goto err;
394 }
395 BUF_strlcpy(v->name,pname,strlen(pname)+1);
396 if (!str_copy(conf,psection,&(v->value),start)) goto err;
397
398 if (strcmp(psection,section) != 0)
399 {
400 if ((tv=_CONF_get_section(conf,psection))
401 == NULL)
402 tv=_CONF_new_section(conf,psection);
403 if (tv == NULL)
404 {
405 CONFerr(CONF_F_CONF_LOAD_BIO,
406 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
407 goto err;
408 }
409 ts=(STACK_OF(CONF_VALUE) *)tv->value;
410 }
411 else
412 {
413 tv=sv;
414 ts=section_sk;
415 }
416#if 1
417 if (_CONF_add_string(conf, tv, v) == 0)
418 {
419 CONFerr(CONF_F_CONF_LOAD_BIO,
420 ERR_R_MALLOC_FAILURE);
421 goto err;
422 }
423#else
424 v->section=tv->section;
425 if (!sk_CONF_VALUE_push(ts,v))
426 {
427 CONFerr(CONF_F_CONF_LOAD_BIO,
428 ERR_R_MALLOC_FAILURE);
429 goto err;
430 }
431 vv=(CONF_VALUE *)lh_insert(conf->data,v);
432 if (vv != NULL)
433 {
434 sk_CONF_VALUE_delete_ptr(ts,vv);
435 OPENSSL_free(vv->name);
436 OPENSSL_free(vv->value);
437 OPENSSL_free(vv);
438 }
439#endif
440 v=NULL;
441 }
442 }
443 if (buff != NULL) BUF_MEM_free(buff);
444 if (section != NULL) OPENSSL_free(section);
445 return(1);
446err:
447 if (buff != NULL) BUF_MEM_free(buff);
448 if (section != NULL) OPENSSL_free(section);
449 if (line != NULL) *line=eline;
450 BIO_snprintf(btmp,sizeof btmp,"%ld",eline);
451 ERR_add_error_data(2,"line ",btmp);
452 if ((h != conf->data) && (conf->data != NULL))
453 {
454 CONF_free(conf->data);
455 conf->data=NULL;
456 }
457 if (v != NULL)
458 {
459 if (v->name != NULL) OPENSSL_free(v->name);
460 if (v->value != NULL) OPENSSL_free(v->value);
461 if (v != NULL) OPENSSL_free(v);
462 }
463 return(0);
464 }
465
466static void clear_comments(CONF *conf, char *p)
467 {
468 char *to;
469
470 to=p;
471 for (;;)
472 {
473 if (IS_FCOMMENT(conf,*p))
474 {
475 *p='\0';
476 return;
477 }
478 if (!IS_WS(conf,*p))
479 {
480 break;
481 }
482 p++;
483 }
484
485 for (;;)
486 {
487 if (IS_COMMENT(conf,*p))
488 {
489 *p='\0';
490 return;
491 }
492 if (IS_DQUOTE(conf,*p))
493 {
494 p=scan_dquote(conf, p);
495 continue;
496 }
497 if (IS_QUOTE(conf,*p))
498 {
499 p=scan_quote(conf, p);
500 continue;
501 }
502 if (IS_ESC(conf,*p))
503 {
504 p=scan_esc(conf,p);
505 continue;
506 }
507 if (IS_EOF(conf,*p))
508 return;
509 else
510 p++;
511 }
512 }
513
514static int str_copy(CONF *conf, char *section, char **pto, char *from)
515 {
516 int q,r,rr=0,to=0,len=0;
517 char *s,*e,*rp,*p,*rrp,*np,*cp,v;
518 BUF_MEM *buf;
519
520 if ((buf=BUF_MEM_new()) == NULL) return(0);
521
522 len=strlen(from)+1;
523 if (!BUF_MEM_grow(buf,len)) goto err;
524
525 for (;;)
526 {
527 if (IS_QUOTE(conf,*from))
528 {
529 q= *from;
530 from++;
531 while (!IS_EOF(conf,*from) && (*from != q))
532 {
533 if (IS_ESC(conf,*from))
534 {
535 from++;
536 if (IS_EOF(conf,*from)) break;
537 }
538 buf->data[to++]= *(from++);
539 }
540 if (*from == q) from++;
541 }
542 else if (IS_DQUOTE(conf,*from))
543 {
544 q= *from;
545 from++;
546 while (!IS_EOF(conf,*from))
547 {
548 if (*from == q)
549 {
550 if (*(from+1) == q)
551 {
552 from++;
553 }
554 else
555 {
556 break;
557 }
558 }
559 buf->data[to++]= *(from++);
560 }
561 if (*from == q) from++;
562 }
563 else if (IS_ESC(conf,*from))
564 {
565 from++;
566 v= *(from++);
567 if (IS_EOF(conf,v)) break;
568 else if (v == 'r') v='\r';
569 else if (v == 'n') v='\n';
570 else if (v == 'b') v='\b';
571 else if (v == 't') v='\t';
572 buf->data[to++]= v;
573 }
574 else if (IS_EOF(conf,*from))
575 break;
576 else if (*from == '$')
577 {
578 /* try to expand it */
579 rrp=NULL;
580 s= &(from[1]);
581 if (*s == '{')
582 q='}';
583 else if (*s == '(')
584 q=')';
585 else q=0;
586
587 if (q) s++;
588 cp=section;
589 e=np=s;
590 while (IS_ALPHA_NUMERIC(conf,*e))
591 e++;
592 if ((e[0] == ':') && (e[1] == ':'))
593 {
594 cp=np;
595 rrp=e;
596 rr= *e;
597 *rrp='\0';
598 e+=2;
599 np=e;
600 while (IS_ALPHA_NUMERIC(conf,*e))
601 e++;
602 }
603 r= *e;
604 *e='\0';
605 rp=e;
606 if (q)
607 {
608 if (r != q)
609 {
610 CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
611 goto err;
612 }
613 e++;
614 }
615 /* So at this point we have
616 * ns which is the start of the name string which is
617 * '\0' terminated.
618 * cs which is the start of the section string which is
619 * '\0' terminated.
620 * e is the 'next point after'.
621 * r and s are the chars replaced by the '\0'
622 * rp and sp is where 'r' and 's' came from.
623 */
624 p=_CONF_get_string(conf,cp,np);
625 if (rrp != NULL) *rrp=rr;
626 *rp=r;
627 if (p == NULL)
628 {
629 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
630 goto err;
631 }
632 BUF_MEM_grow_clean(buf,(strlen(p)+len-(e-from)));
633 while (*p)
634 buf->data[to++]= *(p++);
635
636 /* Since we change the pointer 'from', we also have
637 to change the perceived length of the string it
638 points at. /RL */
639 len -= e-from;
640 from=e;
641 }
642 else
643 buf->data[to++]= *(from++);
644 }
645 buf->data[to]='\0';
646 if (*pto != NULL) OPENSSL_free(*pto);
647 *pto=buf->data;
648 OPENSSL_free(buf);
649 return(1);
650err:
651 if (buf != NULL) BUF_MEM_free(buf);
652 return(0);
653 }
654
655static char *eat_ws(CONF *conf, char *p)
656 {
657 while (IS_WS(conf,*p) && (!IS_EOF(conf,*p)))
658 p++;
659 return(p);
660 }
661
662static char *eat_alpha_numeric(CONF *conf, char *p)
663 {
664 for (;;)
665 {
666 if (IS_ESC(conf,*p))
667 {
668 p=scan_esc(conf,p);
669 continue;
670 }
671 if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
672 return(p);
673 p++;
674 }
675 }
676
677static char *scan_quote(CONF *conf, char *p)
678 {
679 int q= *p;
680
681 p++;
682 while (!(IS_EOF(conf,*p)) && (*p != q))
683 {
684 if (IS_ESC(conf,*p))
685 {
686 p++;
687 if (IS_EOF(conf,*p)) return(p);
688 }
689 p++;
690 }
691 if (*p == q) p++;
692 return(p);
693 }
694
695
696static char *scan_dquote(CONF *conf, char *p)
697 {
698 int q= *p;
699
700 p++;
701 while (!(IS_EOF(conf,*p)))
702 {
703 if (*p == q)
704 {
705 if (*(p+1) == q)
706 {
707 p++;
708 }
709 else
710 {
711 break;
712 }
713 }
714 p++;
715 }
716 if (*p == q) p++;
717 return(p);
718 }
719
720static void dump_value(CONF_VALUE *a, BIO *out)
721 {
722 if (a->name)
723 BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
724 else
725 BIO_printf(out, "[[%s]]\n", a->section);
726 }
727
728static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *)
729
730static int def_dump(const CONF *conf, BIO *out)
731 {
732 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out);
733 return 1;
734 }
735
736static int def_is_number(const CONF *conf, char c)
737 {
738 return IS_NUMBER(conf,c);
739 }
740
741static int def_to_int(const CONF *conf, char c)
742 {
743 return c - '0';
744 }
745
diff --git a/src/lib/libcrypto/conf/conf_def.h b/src/lib/libcrypto/conf/conf_def.h
new file mode 100644
index 0000000000..92a7d8ad77
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_def.h
@@ -0,0 +1,180 @@
1/* crypto/conf/conf_def.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* THIS FILE WAS AUTOMAGICALLY GENERATED!
60 Please modify and use keysets.pl to regenerate it. */
61
62#define CONF_NUMBER 1
63#define CONF_UPPER 2
64#define CONF_LOWER 4
65#define CONF_UNDER 256
66#define CONF_PUNCTUATION 512
67#define CONF_WS 16
68#define CONF_ESC 32
69#define CONF_QUOTE 64
70#define CONF_DQUOTE 1024
71#define CONF_COMMENT 128
72#define CONF_FCOMMENT 2048
73#define CONF_EOF 8
74#define CONF_HIGHBIT 4096
75#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
76#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
77#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
78 CONF_PUNCTUATION)
79
80#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
81#ifndef CHARSET_EBCDIC
82#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
83#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
84#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
85#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
86#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
87#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
88#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
89#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
90 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
91#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
92#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
93#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
94
95#else /*CHARSET_EBCDIC*/
96
97#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
98#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
99#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
100#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
101#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
102#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
103#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
104#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
105 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
106#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
107#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
108#define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
109#endif /*CHARSET_EBCDIC*/
110
111static unsigned short CONF_type_default[256]={
112 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
113 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
114 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
115 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
116 0x0010,0x0200,0x0040,0x0080,0x0000,0x0200,0x0200,0x0040,
117 0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
118 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
119 0x0001,0x0001,0x0000,0x0200,0x0000,0x0000,0x0000,0x0200,
120 0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
121 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
122 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
123 0x0002,0x0002,0x0002,0x0000,0x0020,0x0000,0x0200,0x0100,
124 0x0040,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
125 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
126 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
127 0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
128 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
129 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
130 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
131 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
132 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
133 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
134 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
135 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
136 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
137 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
138 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
139 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
140 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
141 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
142 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
143 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
144 };
145
146static unsigned short CONF_type_win32[256]={
147 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
148 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
149 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
150 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
151 0x0010,0x0200,0x0400,0x0000,0x0000,0x0200,0x0200,0x0000,
152 0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
153 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
154 0x0001,0x0001,0x0000,0x0A00,0x0000,0x0000,0x0000,0x0200,
155 0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
156 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
157 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
158 0x0002,0x0002,0x0002,0x0000,0x0000,0x0000,0x0200,0x0100,
159 0x0000,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
160 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
161 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
162 0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
163 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
164 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
165 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
166 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
167 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
168 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
169 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
170 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
171 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
172 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
173 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
174 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
175 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
176 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
177 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
178 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
179 };
180
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
new file mode 100644
index 0000000000..ee07bfe9d9
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_err.c
@@ -0,0 +1,126 @@
1/* crypto/conf/conf_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/conf.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CONF_str_functs[]=
68 {
69{ERR_PACK(0,CONF_F_CONF_DUMP_FP,0), "CONF_dump_fp"},
70{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
71{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
72{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
73{ERR_PACK(0,CONF_F_CONF_MODULES_LOAD,0), "CONF_modules_load"},
74{ERR_PACK(0,CONF_F_MODULE_INIT,0), "MODULE_INIT"},
75{ERR_PACK(0,CONF_F_MODULE_LOAD_DSO,0), "MODULE_LOAD_DSO"},
76{ERR_PACK(0,CONF_F_MODULE_RUN,0), "MODULE_RUN"},
77{ERR_PACK(0,CONF_F_NCONF_DUMP_BIO,0), "NCONF_dump_bio"},
78{ERR_PACK(0,CONF_F_NCONF_DUMP_FP,0), "NCONF_dump_fp"},
79{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER,0), "NCONF_get_number"},
80{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER_E,0), "NCONF_get_number_e"},
81{ERR_PACK(0,CONF_F_NCONF_GET_SECTION,0), "NCONF_get_section"},
82{ERR_PACK(0,CONF_F_NCONF_GET_STRING,0), "NCONF_get_string"},
83{ERR_PACK(0,CONF_F_NCONF_LOAD,0), "NCONF_load"},
84{ERR_PACK(0,CONF_F_NCONF_LOAD_BIO,0), "NCONF_load_bio"},
85{ERR_PACK(0,CONF_F_NCONF_LOAD_FP,0), "NCONF_load_fp"},
86{ERR_PACK(0,CONF_F_NCONF_NEW,0), "NCONF_new"},
87{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
88{0,NULL}
89 };
90
91static ERR_STRING_DATA CONF_str_reasons[]=
92 {
93{CONF_R_ERROR_LOADING_DSO ,"error loading dso"},
94{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"},
95{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"},
96{CONF_R_MISSING_FINISH_FUNCTION ,"missing finish function"},
97{CONF_R_MISSING_INIT_FUNCTION ,"missing init function"},
98{CONF_R_MODULE_INITIALIZATION_ERROR ,"module initialization error"},
99{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
100{CONF_R_NO_CONF ,"no conf"},
101{CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE ,"no conf or environment variable"},
102{CONF_R_NO_SECTION ,"no section"},
103{CONF_R_NO_SUCH_FILE ,"no such file"},
104{CONF_R_NO_VALUE ,"no value"},
105{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
106{CONF_R_UNKNOWN_MODULE_NAME ,"unknown module name"},
107{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
108{0,NULL}
109 };
110
111#endif
112
113void ERR_load_CONF_strings(void)
114 {
115 static int init=1;
116
117 if (init)
118 {
119 init=0;
120#ifndef OPENSSL_NO_ERR
121 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs);
122 ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons);
123#endif
124
125 }
126 }
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
new file mode 100644
index 0000000000..6a3cf109dd
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_lib.c
@@ -0,0 +1,401 @@
1/* conf_lib.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include <openssl/err.h>
62#include <openssl/conf.h>
63#include <openssl/conf_api.h>
64#include <openssl/lhash.h>
65
66const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
67
68static CONF_METHOD *default_CONF_method=NULL;
69
70/* Init a 'CONF' structure from an old LHASH */
71
72void CONF_set_nconf(CONF *conf, LHASH *hash)
73 {
74 if (default_CONF_method == NULL)
75 default_CONF_method = NCONF_default();
76
77 default_CONF_method->init(conf);
78 conf->data = hash;
79 }
80
81/* The following section contains the "CONF classic" functions,
82 rewritten in terms of the new CONF interface. */
83
84int CONF_set_default_method(CONF_METHOD *meth)
85 {
86 default_CONF_method = meth;
87 return 1;
88 }
89
90LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
91 {
92 LHASH *ltmp;
93 BIO *in=NULL;
94
95#ifdef OPENSSL_SYS_VMS
96 in=BIO_new_file(file, "r");
97#else
98 in=BIO_new_file(file, "rb");
99#endif
100 if (in == NULL)
101 {
102 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
103 return NULL;
104 }
105
106 ltmp = CONF_load_bio(conf, in, eline);
107 BIO_free(in);
108
109 return ltmp;
110 }
111
112#ifndef OPENSSL_NO_FP_API
113LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
114 {
115 BIO *btmp;
116 LHASH *ltmp;
117 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
118 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
119 return NULL;
120 }
121 ltmp = CONF_load_bio(conf, btmp, eline);
122 BIO_free(btmp);
123 return ltmp;
124 }
125#endif
126
127LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
128 {
129 CONF ctmp;
130 int ret;
131
132 CONF_set_nconf(&ctmp, conf);
133
134 ret = NCONF_load_bio(&ctmp, bp, eline);
135 if (ret)
136 return ctmp.data;
137 return NULL;
138 }
139
140STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section)
141 {
142 if (conf == NULL)
143 {
144 return NULL;
145 }
146 else
147 {
148 CONF ctmp;
149 CONF_set_nconf(&ctmp, conf);
150 return NCONF_get_section(&ctmp, section);
151 }
152 }
153
154char *CONF_get_string(LHASH *conf,const char *group,const char *name)
155 {
156 if (conf == NULL)
157 {
158 return NCONF_get_string(NULL, group, name);
159 }
160 else
161 {
162 CONF ctmp;
163 CONF_set_nconf(&ctmp, conf);
164 return NCONF_get_string(&ctmp, group, name);
165 }
166 }
167
168long CONF_get_number(LHASH *conf,const char *group,const char *name)
169 {
170 int status;
171 long result = 0;
172
173 if (conf == NULL)
174 {
175 status = NCONF_get_number_e(NULL, group, name, &result);
176 }
177 else
178 {
179 CONF ctmp;
180 CONF_set_nconf(&ctmp, conf);
181 status = NCONF_get_number_e(&ctmp, group, name, &result);
182 }
183
184 if (status == 0)
185 {
186 /* This function does not believe in errors... */
187 ERR_get_error();
188 }
189 return result;
190 }
191
192void CONF_free(LHASH *conf)
193 {
194 CONF ctmp;
195 CONF_set_nconf(&ctmp, conf);
196 NCONF_free_data(&ctmp);
197 }
198
199#ifndef OPENSSL_NO_FP_API
200int CONF_dump_fp(LHASH *conf, FILE *out)
201 {
202 BIO *btmp;
203 int ret;
204
205 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
206 CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB);
207 return 0;
208 }
209 ret = CONF_dump_bio(conf, btmp);
210 BIO_free(btmp);
211 return ret;
212 }
213#endif
214
215int CONF_dump_bio(LHASH *conf, BIO *out)
216 {
217 CONF ctmp;
218 CONF_set_nconf(&ctmp, conf);
219 return NCONF_dump_bio(&ctmp, out);
220 }
221
222/* The following section contains the "New CONF" functions. They are
223 completely centralised around a new CONF structure that may contain
224 basically anything, but at least a method pointer and a table of data.
225 These functions are also written in terms of the bridge functions used
226 by the "CONF classic" functions, for consistency. */
227
228CONF *NCONF_new(CONF_METHOD *meth)
229 {
230 CONF *ret;
231
232 if (meth == NULL)
233 meth = NCONF_default();
234
235 ret = meth->create(meth);
236 if (ret == NULL)
237 {
238 CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
239 return(NULL);
240 }
241
242 return ret;
243 }
244
245void NCONF_free(CONF *conf)
246 {
247 if (conf == NULL)
248 return;
249 conf->meth->destroy(conf);
250 }
251
252void NCONF_free_data(CONF *conf)
253 {
254 if (conf == NULL)
255 return;
256 conf->meth->destroy_data(conf);
257 }
258
259int NCONF_load(CONF *conf, const char *file, long *eline)
260 {
261 if (conf == NULL)
262 {
263 CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF);
264 return 0;
265 }
266
267 return conf->meth->load(conf, file, eline);
268 }
269
270#ifndef OPENSSL_NO_FP_API
271int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
272 {
273 BIO *btmp;
274 int ret;
275 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
276 {
277 CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB);
278 return 0;
279 }
280 ret = NCONF_load_bio(conf, btmp, eline);
281 BIO_free(btmp);
282 return ret;
283 }
284#endif
285
286int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
287 {
288 if (conf == NULL)
289 {
290 CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF);
291 return 0;
292 }
293
294 return conf->meth->load_bio(conf, bp, eline);
295 }
296
297STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section)
298 {
299 if (conf == NULL)
300 {
301 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF);
302 return NULL;
303 }
304
305 if (section == NULL)
306 {
307 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_SECTION);
308 return NULL;
309 }
310
311 return _CONF_get_section_values(conf, section);
312 }
313
314char *NCONF_get_string(const CONF *conf,const char *group,const char *name)
315 {
316 char *s = _CONF_get_string(conf, group, name);
317
318 /* Since we may get a value from an environment variable even
319 if conf is NULL, let's check the value first */
320 if (s) return s;
321
322 if (conf == NULL)
323 {
324 CONFerr(CONF_F_NCONF_GET_STRING,
325 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
326 return NULL;
327 }
328 CONFerr(CONF_F_NCONF_GET_STRING,
329 CONF_R_NO_VALUE);
330 ERR_add_error_data(4,"group=",group," name=",name);
331 return NULL;
332 }
333
334int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
335 long *result)
336 {
337 char *str;
338
339 if (result == NULL)
340 {
341 CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER);
342 return 0;
343 }
344
345 str = NCONF_get_string(conf,group,name);
346
347 if (str == NULL)
348 return 0;
349
350 for (*result = 0;conf->meth->is_number(conf, *str);)
351 {
352 *result = (*result)*10 + conf->meth->to_int(conf, *str);
353 str++;
354 }
355
356 return 1;
357 }
358
359#ifndef OPENSSL_NO_FP_API
360int NCONF_dump_fp(const CONF *conf, FILE *out)
361 {
362 BIO *btmp;
363 int ret;
364 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
365 CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB);
366 return 0;
367 }
368 ret = NCONF_dump_bio(conf, btmp);
369 BIO_free(btmp);
370 return ret;
371 }
372#endif
373
374int NCONF_dump_bio(const CONF *conf, BIO *out)
375 {
376 if (conf == NULL)
377 {
378 CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF);
379 return 0;
380 }
381
382 return conf->meth->dump(conf, out);
383 }
384
385
386/* This function should be avoided */
387#if 0
388long NCONF_get_number(CONF *conf,char *group,char *name)
389 {
390 int status;
391 long ret=0;
392
393 status = NCONF_get_number_e(conf, group, name, &ret);
394 if (status == 0)
395 {
396 /* This function does not believe in errors... */
397 ERR_get_error();
398 }
399 return ret;
400 }
401#endif
diff --git a/src/lib/libcrypto/conf/conf_mall.c b/src/lib/libcrypto/conf/conf_mall.c
new file mode 100644
index 0000000000..4ba40cf44c
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_mall.c
@@ -0,0 +1,80 @@
1/* conf_mall.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70/* Load all OpenSSL builtin modules */
71
72void OPENSSL_load_builtin_modules(void)
73 {
74 /* Add builtin modules here */
75 ASN1_add_oid_module();
76#ifndef OPENSSL_NO_ENGINE
77 ENGINE_add_conf_module();
78#endif
79 }
80
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c
new file mode 100644
index 0000000000..d45adea851
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_mod.c
@@ -0,0 +1,616 @@
1/* conf_mod.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/dso.h>
65#include <openssl/x509.h>
66
67
68#define DSO_mod_init_name "OPENSSL_init"
69#define DSO_mod_finish_name "OPENSSL_finish"
70
71
72/* This structure contains a data about supported modules.
73 * entries in this table correspond to either dynamic or
74 * static modules.
75 */
76
77struct conf_module_st
78 {
79 /* DSO of this module or NULL if static */
80 DSO *dso;
81 /* Name of the module */
82 char *name;
83 /* Init function */
84 conf_init_func *init;
85 /* Finish function */
86 conf_finish_func *finish;
87 /* Number of successfully initialized modules */
88 int links;
89 void *usr_data;
90 };
91
92
93/* This structure contains information about modules that have been
94 * successfully initialized. There may be more than one entry for a
95 * given module.
96 */
97
98struct conf_imodule_st
99 {
100 CONF_MODULE *pmod;
101 char *name;
102 char *value;
103 unsigned long flags;
104 void *usr_data;
105 };
106
107static STACK_OF(CONF_MODULE) *supported_modules = NULL;
108static STACK_OF(CONF_IMODULE) *initialized_modules = NULL;
109
110static void module_free(CONF_MODULE *md);
111static void module_finish(CONF_IMODULE *imod);
112static int module_run(const CONF *cnf, char *name, char *value,
113 unsigned long flags);
114static CONF_MODULE *module_add(DSO *dso, const char *name,
115 conf_init_func *ifunc, conf_finish_func *ffunc);
116static CONF_MODULE *module_find(char *name);
117static int module_init(CONF_MODULE *pmod, char *name, char *value,
118 const CONF *cnf);
119static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
120 unsigned long flags);
121
122/* Main function: load modules from a CONF structure */
123
124int CONF_modules_load(const CONF *cnf, const char *appname,
125 unsigned long flags)
126 {
127 STACK_OF(CONF_VALUE) *values;
128 CONF_VALUE *vl;
129 char *vsection;
130
131 int ret, i;
132
133 if (!cnf)
134 return 1;
135
136 if (appname == NULL)
137 appname = "openssl_conf";
138
139 vsection = NCONF_get_string(cnf, NULL, appname);
140
141 if (!vsection)
142 {
143 ERR_clear_error();
144 return 1;
145 }
146
147 values = NCONF_get_section(cnf, vsection);
148
149 if (!values)
150 return 0;
151
152 for (i = 0; i < sk_CONF_VALUE_num(values); i++)
153 {
154 vl = sk_CONF_VALUE_value(values, i);
155 ret = module_run(cnf, vl->name, vl->value, flags);
156 if (ret <= 0)
157 if(!(flags & CONF_MFLAGS_IGNORE_ERRORS))
158 return ret;
159 }
160
161 return 1;
162
163 }
164
165int CONF_modules_load_file(const char *filename, const char *appname,
166 unsigned long flags)
167 {
168 char *file = NULL;
169 CONF *conf = NULL;
170 int ret = 0;
171 conf = NCONF_new(NULL);
172 if (!conf)
173 goto err;
174
175 if (filename == NULL)
176 {
177 file = CONF_get1_default_config_file();
178 if (!file)
179 goto err;
180 }
181 else
182 file = (char *)filename;
183
184 if (NCONF_load(conf, file, NULL) <= 0)
185 {
186 if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) &&
187 (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE))
188 {
189 ERR_clear_error();
190 ret = 1;
191 }
192 goto err;
193 }
194
195 ret = CONF_modules_load(conf, appname, flags);
196
197 err:
198 if (filename == NULL)
199 OPENSSL_free(file);
200 NCONF_free(conf);
201
202 return ret;
203 }
204
205static int module_run(const CONF *cnf, char *name, char *value,
206 unsigned long flags)
207 {
208 CONF_MODULE *md;
209 int ret;
210
211 md = module_find(name);
212
213 /* Module not found: try to load DSO */
214 if (!md && !(flags & CONF_MFLAGS_NO_DSO))
215 md = module_load_dso(cnf, name, value, flags);
216
217 if (!md)
218 {
219 if (!(flags & CONF_MFLAGS_SILENT))
220 {
221 CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME);
222 ERR_add_error_data(2, "module=", name);
223 }
224 return -1;
225 }
226
227 ret = module_init(md, name, value, cnf);
228
229 if (ret <= 0)
230 {
231 if (!(flags & CONF_MFLAGS_SILENT))
232 {
233 char rcode[DECIMAL_SIZE(ret)+1];
234 CONFerr(CONF_F_CONF_MODULES_LOAD, CONF_R_MODULE_INITIALIZATION_ERROR);
235 BIO_snprintf(rcode, sizeof rcode, "%-8d", ret);
236 ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode);
237 }
238 }
239
240 return ret;
241 }
242
243/* Load a module from a DSO */
244static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
245 unsigned long flags)
246 {
247 DSO *dso = NULL;
248 conf_init_func *ifunc;
249 conf_finish_func *ffunc;
250 char *path = NULL;
251 int errcode = 0;
252 CONF_MODULE *md;
253 /* Look for alternative path in module section */
254 path = NCONF_get_string(cnf, value, "path");
255 if (!path)
256 {
257 ERR_get_error();
258 path = name;
259 }
260 dso = DSO_load(NULL, path, NULL, 0);
261 if (!dso)
262 {
263 errcode = CONF_R_ERROR_LOADING_DSO;
264 goto err;
265 }
266 ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name);
267 if (!ifunc)
268 {
269 errcode = CONF_R_MISSING_INIT_FUNCTION;
270 goto err;
271 }
272 ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name);
273 /* All OK, add module */
274 md = module_add(dso, name, ifunc, ffunc);
275
276 if (!md)
277 goto err;
278
279 return md;
280
281 err:
282 if (dso)
283 DSO_free(dso);
284 CONFerr(CONF_F_MODULE_LOAD_DSO, errcode);
285 ERR_add_error_data(4, "module=", name, ", path=", path);
286 return NULL;
287 }
288
289/* add module to list */
290static CONF_MODULE *module_add(DSO *dso, const char *name,
291 conf_init_func *ifunc, conf_finish_func *ffunc)
292 {
293 CONF_MODULE *tmod = NULL;
294 if (supported_modules == NULL)
295 supported_modules = sk_CONF_MODULE_new_null();
296 if (supported_modules == NULL)
297 return NULL;
298 tmod = OPENSSL_malloc(sizeof(CONF_MODULE));
299 if (tmod == NULL)
300 return NULL;
301
302 tmod->dso = dso;
303 tmod->name = BUF_strdup(name);
304 tmod->init = ifunc;
305 tmod->finish = ffunc;
306 tmod->links = 0;
307
308 if (!sk_CONF_MODULE_push(supported_modules, tmod))
309 {
310 OPENSSL_free(tmod);
311 return NULL;
312 }
313
314 return tmod;
315 }
316
317/* Find a module from the list. We allow module names of the
318 * form modname.XXXX to just search for modname to allow the
319 * same module to be initialized more than once.
320 */
321
322static CONF_MODULE *module_find(char *name)
323 {
324 CONF_MODULE *tmod;
325 int i, nchar;
326 char *p;
327 p = strrchr(name, '.');
328
329 if (p)
330 nchar = p - name;
331 else
332 nchar = strlen(name);
333
334 for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++)
335 {
336 tmod = sk_CONF_MODULE_value(supported_modules, i);
337 if (!strncmp(tmod->name, name, nchar))
338 return tmod;
339 }
340
341 return NULL;
342
343 }
344
345/* initialize a module */
346static int module_init(CONF_MODULE *pmod, char *name, char *value,
347 const CONF *cnf)
348 {
349 int ret = 1;
350 int init_called = 0;
351 CONF_IMODULE *imod = NULL;
352
353 /* Otherwise add initialized module to list */
354 imod = OPENSSL_malloc(sizeof(CONF_IMODULE));
355 if (!imod)
356 goto err;
357
358 imod->pmod = pmod;
359 imod->name = BUF_strdup(name);
360 imod->value = BUF_strdup(value);
361 imod->usr_data = NULL;
362
363 if (!imod->name || !imod->value)
364 goto memerr;
365
366 /* Try to initialize module */
367 if(pmod->init)
368 {
369 ret = pmod->init(imod, cnf);
370 init_called = 1;
371 /* Error occurred, exit */
372 if (ret <= 0)
373 goto err;
374 }
375
376 if (initialized_modules == NULL)
377 {
378 initialized_modules = sk_CONF_IMODULE_new_null();
379 if (!initialized_modules)
380 {
381 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
382 goto err;
383 }
384 }
385
386 if (!sk_CONF_IMODULE_push(initialized_modules, imod))
387 {
388 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
389 goto err;
390 }
391
392 pmod->links++;
393
394 return ret;
395
396 err:
397
398 /* We've started the module so we'd better finish it */
399 if (pmod->finish && init_called)
400 pmod->finish(imod);
401
402 memerr:
403 if (imod)
404 {
405 if (imod->name)
406 OPENSSL_free(imod->name);
407 if (imod->value)
408 OPENSSL_free(imod->value);
409 OPENSSL_free(imod);
410 }
411
412 return -1;
413
414 }
415
416/* Unload any dynamic modules that have a link count of zero:
417 * i.e. have no active initialized modules. If 'all' is set
418 * then all modules are unloaded including static ones.
419 */
420
421void CONF_modules_unload(int all)
422 {
423 int i;
424 CONF_MODULE *md;
425 CONF_modules_finish();
426 /* unload modules in reverse order */
427 for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--)
428 {
429 md = sk_CONF_MODULE_value(supported_modules, i);
430 /* If static or in use and 'all' not set ignore it */
431 if (((md->links > 0) || !md->dso) && !all)
432 continue;
433 /* Since we're working in reverse this is OK */
434 sk_CONF_MODULE_delete(supported_modules, i);
435 module_free(md);
436 }
437 if (sk_CONF_MODULE_num(supported_modules) == 0)
438 {
439 sk_CONF_MODULE_free(supported_modules);
440 supported_modules = NULL;
441 }
442 }
443
444/* unload a single module */
445static void module_free(CONF_MODULE *md)
446 {
447 if (md->dso)
448 DSO_free(md->dso);
449 OPENSSL_free(md->name);
450 OPENSSL_free(md);
451 }
452
453/* finish and free up all modules instances */
454
455void CONF_modules_finish(void)
456 {
457 CONF_IMODULE *imod;
458 while (sk_CONF_IMODULE_num(initialized_modules) > 0)
459 {
460 imod = sk_CONF_IMODULE_pop(initialized_modules);
461 module_finish(imod);
462 }
463 sk_CONF_IMODULE_free(initialized_modules);
464 initialized_modules = NULL;
465 }
466
467/* finish a module instance */
468
469static void module_finish(CONF_IMODULE *imod)
470 {
471 if (imod->pmod->finish)
472 imod->pmod->finish(imod);
473 imod->pmod->links--;
474 OPENSSL_free(imod->name);
475 OPENSSL_free(imod->value);
476 OPENSSL_free(imod);
477 }
478
479/* Add a static module to OpenSSL */
480
481int CONF_module_add(const char *name, conf_init_func *ifunc,
482 conf_finish_func *ffunc)
483 {
484 if (module_add(NULL, name, ifunc, ffunc))
485 return 1;
486 else
487 return 0;
488 }
489
490void CONF_modules_free(void)
491 {
492 CONF_modules_finish();
493 CONF_modules_unload(1);
494 }
495
496/* Utility functions */
497
498const char *CONF_imodule_get_name(const CONF_IMODULE *md)
499 {
500 return md->name;
501 }
502
503const char *CONF_imodule_get_value(const CONF_IMODULE *md)
504 {
505 return md->value;
506 }
507
508void *CONF_imodule_get_usr_data(const CONF_IMODULE *md)
509 {
510 return md->usr_data;
511 }
512
513void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data)
514 {
515 md->usr_data = usr_data;
516 }
517
518CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md)
519 {
520 return md->pmod;
521 }
522
523unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md)
524 {
525 return md->flags;
526 }
527
528void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags)
529 {
530 md->flags = flags;
531 }
532
533void *CONF_module_get_usr_data(CONF_MODULE *pmod)
534 {
535 return pmod->usr_data;
536 }
537
538void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
539 {
540 pmod->usr_data = usr_data;
541 }
542
543/* Return default config file name */
544
545char *CONF_get1_default_config_file(void)
546 {
547 char *file;
548 int len;
549
550 file = getenv("OPENSSL_CONF");
551 if (file)
552 return BUF_strdup(file);
553
554 len = strlen(X509_get_default_cert_area());
555#ifndef OPENSSL_SYS_VMS
556 len++;
557#endif
558 len += strlen(OPENSSL_CONF);
559
560 file = OPENSSL_malloc(len + 1);
561
562 if (!file)
563 return NULL;
564 BUF_strlcpy(file,X509_get_default_cert_area(),len + 1);
565#ifndef OPENSSL_SYS_VMS
566 BUF_strlcat(file,"/",len + 1);
567#endif
568 BUF_strlcat(file,OPENSSL_CONF,len + 1);
569
570 return file;
571 }
572
573/* This function takes a list separated by 'sep' and calls the
574 * callback function giving the start and length of each member
575 * optionally stripping leading and trailing whitespace. This can
576 * be used to parse comma separated lists for example.
577 */
578
579int CONF_parse_list(const char *list_, int sep, int nospc,
580 int (*list_cb)(const char *elem, int len, void *usr), void *arg)
581 {
582 int ret;
583 const char *lstart, *tmpend, *p;
584 lstart = list_;
585
586 for(;;)
587 {
588 if (nospc)
589 {
590 while(*lstart && isspace((unsigned char)*lstart))
591 lstart++;
592 }
593 p = strchr(lstart, sep);
594 if (p == lstart || !*lstart)
595 ret = list_cb(NULL, 0, arg);
596 else
597 {
598 if (p)
599 tmpend = p - 1;
600 else
601 tmpend = lstart + strlen(lstart) - 1;
602 if (nospc)
603 {
604 while(isspace((unsigned char)*tmpend))
605 tmpend--;
606 }
607 ret = list_cb(lstart, tmpend - lstart + 1, arg);
608 }
609 if (ret <= 0)
610 return ret;
611 if (p == NULL)
612 return 1;
613 lstart = p + 1;
614 }
615 }
616
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c
new file mode 100644
index 0000000000..e15c2e5546
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_sap.c
@@ -0,0 +1,111 @@
1/* conf_sap.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70/* This is the automatic configuration loader: it is called automatically by
71 * OpenSSL when any of a number of standard initialisation functions are called,
72 * unless this is overridden by calling OPENSSL_no_config()
73 */
74
75static int openssl_configured = 0;
76
77void OPENSSL_config(const char *config_name)
78 {
79 if (openssl_configured)
80 return;
81
82 OPENSSL_load_builtin_modules();
83#ifndef OPENSSL_NO_ENGINE
84 /* Need to load ENGINEs */
85 ENGINE_load_builtin_engines();
86#endif
87 /* Add others here? */
88
89
90 ERR_clear_error();
91 if (CONF_modules_load_file(NULL, NULL,
92 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
93 {
94 BIO *bio_err;
95 ERR_load_crypto_strings();
96 if ((bio_err=BIO_new_fp(stderr, BIO_NOCLOSE)) != NULL)
97 {
98 BIO_printf(bio_err,"Auto configuration failed\n");
99 ERR_print_errors(bio_err);
100 BIO_free(bio_err);
101 }
102 exit(1);
103 }
104
105 return;
106 }
107
108void OPENSSL_no_config()
109 {
110 openssl_configured = 1;
111 }
diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl
new file mode 100644
index 0000000000..50ed67fa52
--- /dev/null
+++ b/src/lib/libcrypto/conf/keysets.pl
@@ -0,0 +1,185 @@
1#!/usr/local/bin/perl
2
3$NUMBER=0x01;
4$UPPER=0x02;
5$LOWER=0x04;
6$UNDER=0x100;
7$PUNCTUATION=0x200;
8$WS=0x10;
9$ESC=0x20;
10$QUOTE=0x40;
11$DQUOTE=0x400;
12$COMMENT=0x80;
13$FCOMMENT=0x800;
14$EOF=0x08;
15$HIGHBIT=0x1000;
16
17foreach (0 .. 255)
18 {
19 $v=0;
20 $c=sprintf("%c",$_);
21 $v|=$NUMBER if ($c =~ /[0-9]/);
22 $v|=$UPPER if ($c =~ /[A-Z]/);
23 $v|=$LOWER if ($c =~ /[a-z]/);
24 $v|=$UNDER if ($c =~ /_/);
25 $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
26 $v|=$WS if ($c =~ /[ \t\r\n]/);
27 $v|=$ESC if ($c =~ /\\/);
28 $v|=$QUOTE if ($c =~ /['`"]/); # for emacs: "`'}/)
29 $v|=$COMMENT if ($c =~ /\#/);
30 $v|=$EOF if ($c =~ /\0/);
31 $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
32
33 push(@V_def,$v);
34 }
35
36foreach (0 .. 255)
37 {
38 $v=0;
39 $c=sprintf("%c",$_);
40 $v|=$NUMBER if ($c =~ /[0-9]/);
41 $v|=$UPPER if ($c =~ /[A-Z]/);
42 $v|=$LOWER if ($c =~ /[a-z]/);
43 $v|=$UNDER if ($c =~ /_/);
44 $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
45 $v|=$WS if ($c =~ /[ \t\r\n]/);
46 $v|=$DQUOTE if ($c =~ /["]/); # for emacs: "}/)
47 $v|=$FCOMMENT if ($c =~ /;/);
48 $v|=$EOF if ($c =~ /\0/);
49 $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
50
51 push(@V_w32,$v);
52 }
53
54print <<"EOF";
55/* crypto/conf/conf_def.h */
56/* Copyright (C) 1995-1998 Eric Young (eay\@cryptsoft.com)
57 * All rights reserved.
58 *
59 * This package is an SSL implementation written
60 * by Eric Young (eay\@cryptsoft.com).
61 * The implementation was written so as to conform with Netscapes SSL.
62 *
63 * This library is free for commercial and non-commercial use as long as
64 * the following conditions are aheared to. The following conditions
65 * apply to all code found in this distribution, be it the RC4, RSA,
66 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
67 * included with this distribution is covered by the same copyright terms
68 * except that the holder is Tim Hudson (tjh\@cryptsoft.com).
69 *
70 * Copyright remains Eric Young's, and as such any Copyright notices in
71 * the code are not to be removed.
72 * If this package is used in a product, Eric Young should be given attribution
73 * as the author of the parts of the library used.
74 * This can be in the form of a textual message at program startup or
75 * in documentation (online or textual) provided with the package.
76 *
77 * Redistribution and use in source and binary forms, with or without
78 * modification, are permitted provided that the following conditions
79 * are met:
80 * 1. Redistributions of source code must retain the copyright
81 * notice, this list of conditions and the following disclaimer.
82 * 2. Redistributions in binary form must reproduce the above copyright
83 * notice, this list of conditions and the following disclaimer in the
84 * documentation and/or other materials provided with the distribution.
85 * 3. All advertising materials mentioning features or use of this software
86 * must display the following acknowledgement:
87 * "This product includes cryptographic software written by
88 * Eric Young (eay\@cryptsoft.com)"
89 * The word 'cryptographic' can be left out if the rouines from the library
90 * being used are not cryptographic related :-).
91 * 4. If you include any Windows specific code (or a derivative thereof) from
92 * the apps directory (application code) you must include an acknowledgement:
93 * "This product includes software written by Tim Hudson (tjh\@cryptsoft.com)"
94 *
95 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
96 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
99 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
100 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
101 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
103 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
104 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 * SUCH DAMAGE.
106 *
107 * The licence and distribution terms for any publically available version or
108 * derivative of this code cannot be changed. i.e. this code cannot simply be
109 * copied and put under another distribution licence
110 * [including the GNU Public Licence.]
111 */
112
113/* THIS FILE WAS AUTOMAGICALLY GENERATED!
114 Please modify and use keysets.pl to regenerate it. */
115
116#define CONF_NUMBER $NUMBER
117#define CONF_UPPER $UPPER
118#define CONF_LOWER $LOWER
119#define CONF_UNDER $UNDER
120#define CONF_PUNCTUATION $PUNCTUATION
121#define CONF_WS $WS
122#define CONF_ESC $ESC
123#define CONF_QUOTE $QUOTE
124#define CONF_DQUOTE $DQUOTE
125#define CONF_COMMENT $COMMENT
126#define CONF_FCOMMENT $FCOMMENT
127#define CONF_EOF $EOF
128#define CONF_HIGHBIT $HIGHBIT
129#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
130#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
131#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\
132 CONF_PUNCTUATION)
133
134#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
135#ifndef CHARSET_EBCDIC
136#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
137#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
138#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
139#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
140#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
141#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
142#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
143#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
144 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
145#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
146#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
147#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
148
149#else /*CHARSET_EBCDIC*/
150
151#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
152#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
153#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
154#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
155#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
156#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
157#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
158#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
159 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
160#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
161#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
162#define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
163#endif /*CHARSET_EBCDIC*/
164
165EOF
166
167print "static unsigned short CONF_type_default[256]={";
168
169for ($i=0; $i<256; $i++)
170 {
171 print "\n\t" if ($i % 8) == 0;
172 printf "0x%04X,",$V_def[$i];
173 }
174
175print "\n\t};\n\n";
176
177print "static unsigned short CONF_type_win32[256]={";
178
179for ($i=0; $i<256; $i++)
180 {
181 print "\n\t" if ($i % 8) == 0;
182 printf "0x%04X,",$V_w32[$i];
183 }
184
185print "\n\t};\n\n";
diff --git a/src/lib/libcrypto/conf/ssleay.cnf b/src/lib/libcrypto/conf/ssleay.cnf
new file mode 100644
index 0000000000..ed33af601e
--- /dev/null
+++ b/src/lib/libcrypto/conf/ssleay.cnf
@@ -0,0 +1,78 @@
1#
2# This is a test configuration file for use in SSLeay etc...
3#
4
5init = 5
6in\#it1 =10
7init2='10'
8init3='10\''
9init4="10'"
10init5='='10\'' again'
11
12SSLeay::version = 0.5.0
13
14[genrsa]
15default_bits = 512
16SSLEAY::version = 0.5.0
17
18[gendh]
19default_bits = 512
20def_generator = 2
21
22[s_client]
23cipher1 = DES_CBC_MD5:DES_CBC_SHA:DES_EDE_SHA:RC4_MD5\
24cipher2 = 'DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5'
25cipher3 = "DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5"
26cipher4 = DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5
27
28[ default ]
29cert_dir = $ENV::HOME/.ca_certs
30
31HOME = /tmp/eay
32
33tmp_cert_dir = $HOME/.ca_certs
34tmp2_cert_dir = thisis$(HOME)stuff
35
36LOGNAME = Eric Young (home=$HOME)
37
38[ special ]
39
40H=$HOME
41H=$default::HOME
42H=$ENV::HOME
43#
44# SSLeay example configuration file.
45# This is mostly being used for generation of certificate requests.
46#
47
48RANDFILE = $HOME/.rand
49
50[ req ]
51default_bits = 512
52default_keyfile = privkey.pem
53
54Attribute_type_1 = countryName
55Attribute_text_1 = Country Name (2 letter code)
56Attribute_default_1 = AU
57
58Attribute_type_2 = stateOrProvinceName
59Attribute_text_2 = State or Province Name (full name)
60Attribute_default_2 = Queensland
61
62Attribute_type_3 = localityName
63Attribute_text_3 = Locality Name (eg, city)
64
65Attribute_type_4 = organizationName
66Attribute_text_4 = Organization Name (eg, company)
67Attribute_default_4 = Mincom Pty Ltd
68
69Attribute_type_5 = organizationalUnitName
70Attribute_text_5 = Organizational Unit Name (eg, section)
71Attribute_default_5 = TR
72
73Attribute_type_6 = commonName
74Attribute_text_6 = Common Name (eg, YOUR name)
75
76Attribute_type_7 = emailAddress
77Attribute_text_7 = Email Address
78
diff --git a/src/lib/libcrypto/cpt_err.c b/src/lib/libcrypto/cpt_err.c
new file mode 100644
index 0000000000..1b4a1cb4d4
--- /dev/null
+++ b/src/lib/libcrypto/cpt_err.c
@@ -0,0 +1,102 @@
1/* crypto/cpt_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/crypto.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CRYPTO_str_functs[]=
68 {
69{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"},
70{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,0), "CRYPTO_get_new_dynlockid"},
71{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"},
72{ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"},
73{ERR_PACK(0,CRYPTO_F_DEF_ADD_INDEX,0), "DEF_ADD_INDEX"},
74{ERR_PACK(0,CRYPTO_F_DEF_GET_CLASS,0), "DEF_GET_CLASS"},
75{ERR_PACK(0,CRYPTO_F_INT_DUP_EX_DATA,0), "INT_DUP_EX_DATA"},
76{ERR_PACK(0,CRYPTO_F_INT_FREE_EX_DATA,0), "INT_FREE_EX_DATA"},
77{ERR_PACK(0,CRYPTO_F_INT_NEW_EX_DATA,0), "INT_NEW_EX_DATA"},
78{0,NULL}
79 };
80
81static ERR_STRING_DATA CRYPTO_str_reasons[]=
82 {
83{CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK ,"no dynlock create callback"},
84{0,NULL}
85 };
86
87#endif
88
89void ERR_load_CRYPTO_strings(void)
90 {
91 static int init=1;
92
93 if (init)
94 {
95 init=0;
96#ifndef OPENSSL_NO_ERR
97 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs);
98 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_reasons);
99#endif
100
101 }
102 }
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
new file mode 100644
index 0000000000..fef0afb29f
--- /dev/null
+++ b/src/lib/libcrypto/cryptlib.c
@@ -0,0 +1,632 @@
1/* crypto/cryptlib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/crypto.h>
63#include <openssl/safestack.h>
64
65#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
66static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
67#endif
68
69DECLARE_STACK_OF(CRYPTO_dynlock)
70IMPLEMENT_STACK_OF(CRYPTO_dynlock)
71
72/* real #defines in crypto.h, keep these upto date */
73static const char* lock_names[CRYPTO_NUM_LOCKS] =
74 {
75 "<<ERROR>>",
76 "err",
77 "ex_data",
78 "x509",
79 "x509_info",
80 "x509_pkey",
81 "x509_crl",
82 "x509_req",
83 "dsa",
84 "rsa",
85 "evp_pkey",
86 "x509_store",
87 "ssl_ctx",
88 "ssl_cert",
89 "ssl_session",
90 "ssl_sess_cert",
91 "ssl",
92 "ssl_method",
93 "rand",
94 "rand2",
95 "debug_malloc",
96 "BIO",
97 "gethostbyname",
98 "getservbyname",
99 "readdir",
100 "RSA_blinding",
101 "dh",
102 "debug_malloc2",
103 "dso",
104 "dynlock",
105 "engine",
106 "ui",
107 "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */
108 "fips",
109 "fips2",
110#if CRYPTO_NUM_LOCKS != 35
111# error "Inconsistency between crypto.h and cryptlib.c"
112#endif
113 };
114
115/* This is for applications to allocate new type names in the non-dynamic
116 array of lock names. These are numbered with positive numbers. */
117static STACK *app_locks=NULL;
118
119/* For applications that want a more dynamic way of handling threads, the
120 following stack is used. These are externally numbered with negative
121 numbers. */
122static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
123
124
125static void (MS_FAR *locking_callback)(int mode,int type,
126 const char *file,int line)=NULL;
127static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
128 int type,const char *file,int line)=NULL;
129static unsigned long (MS_FAR *id_callback)(void)=NULL;
130static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
131 (const char *file,int line)=NULL;
132static void (MS_FAR *dynlock_lock_callback)(int mode,
133 struct CRYPTO_dynlock_value *l, const char *file,int line)=NULL;
134static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
135 const char *file,int line)=NULL;
136
137int CRYPTO_get_new_lockid(char *name)
138 {
139 char *str;
140 int i;
141
142#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
143 /* A hack to make Visual C++ 5.0 work correctly when linking as
144 * a DLL using /MT. Without this, the application cannot use
145 * and floating point printf's.
146 * It also seems to be needed for Visual C 1.5 (win16) */
147 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
148#endif
149
150 if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
151 {
152 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
153 return(0);
154 }
155 if ((str=BUF_strdup(name)) == NULL)
156 {
157 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
158 return(0);
159 }
160 i=sk_push(app_locks,str);
161 if (!i)
162 OPENSSL_free(str);
163 else
164 i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
165 return(i);
166 }
167
168int CRYPTO_num_locks(void)
169 {
170 return CRYPTO_NUM_LOCKS;
171 }
172
173int CRYPTO_get_new_dynlockid(void)
174 {
175 int i = 0;
176 CRYPTO_dynlock *pointer = NULL;
177
178 if (dynlock_create_callback == NULL)
179 {
180 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK);
181 return(0);
182 }
183 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
184 if ((dyn_locks == NULL)
185 && ((dyn_locks=sk_CRYPTO_dynlock_new_null()) == NULL))
186 {
187 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
188 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
189 return(0);
190 }
191 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
192
193 pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock));
194 if (pointer == NULL)
195 {
196 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
197 return(0);
198 }
199 pointer->references = 1;
200 pointer->data = dynlock_create_callback(__FILE__,__LINE__);
201 if (pointer->data == NULL)
202 {
203 OPENSSL_free(pointer);
204 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
205 return(0);
206 }
207
208 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
209 /* First, try to find an existing empty slot */
210 i=sk_CRYPTO_dynlock_find(dyn_locks,NULL);
211 /* If there was none, push, thereby creating a new one */
212 if (i == -1)
213 /* Since sk_push() returns the number of items on the
214 stack, not the location of the pushed item, we need
215 to transform the returned number into a position,
216 by decreasing it. */
217 i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1;
218 else
219 /* If we found a place with a NULL pointer, put our pointer
220 in it. */
221 sk_CRYPTO_dynlock_set(dyn_locks,i,pointer);
222 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
223
224 if (i == -1)
225 {
226 dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
227 OPENSSL_free(pointer);
228 }
229 else
230 i += 1; /* to avoid 0 */
231 return -i;
232 }
233
234void CRYPTO_destroy_dynlockid(int i)
235 {
236 CRYPTO_dynlock *pointer = NULL;
237 if (i)
238 i = -i-1;
239 if (dynlock_destroy_callback == NULL)
240 return;
241
242 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
243
244 if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks))
245 {
246 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
247 return;
248 }
249 pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
250 if (pointer != NULL)
251 {
252 --pointer->references;
253#ifdef REF_CHECK
254 if (pointer->references < 0)
255 {
256 fprintf(stderr,"CRYPTO_destroy_dynlockid, bad reference count\n");
257 abort();
258 }
259 else
260#endif
261 if (pointer->references <= 0)
262 {
263 sk_CRYPTO_dynlock_set(dyn_locks, i, NULL);
264 }
265 else
266 pointer = NULL;
267 }
268 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
269
270 if (pointer)
271 {
272 dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
273 OPENSSL_free(pointer);
274 }
275 }
276
277struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i)
278 {
279 CRYPTO_dynlock *pointer = NULL;
280 if (i)
281 i = -i-1;
282
283 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
284
285 if (dyn_locks != NULL && i < sk_CRYPTO_dynlock_num(dyn_locks))
286 pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
287 if (pointer)
288 pointer->references++;
289
290 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
291
292 if (pointer)
293 return pointer->data;
294 return NULL;
295 }
296
297struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))
298 (const char *file,int line)
299 {
300 return(dynlock_create_callback);
301 }
302
303void (*CRYPTO_get_dynlock_lock_callback(void))(int mode,
304 struct CRYPTO_dynlock_value *l, const char *file,int line)
305 {
306 return(dynlock_lock_callback);
307 }
308
309void (*CRYPTO_get_dynlock_destroy_callback(void))
310 (struct CRYPTO_dynlock_value *l, const char *file,int line)
311 {
312 return(dynlock_destroy_callback);
313 }
314
315void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*func)
316 (const char *file, int line))
317 {
318 dynlock_create_callback=func;
319 }
320
321void CRYPTO_set_dynlock_lock_callback(void (*func)(int mode,
322 struct CRYPTO_dynlock_value *l, const char *file, int line))
323 {
324 dynlock_lock_callback=func;
325 }
326
327void CRYPTO_set_dynlock_destroy_callback(void (*func)
328 (struct CRYPTO_dynlock_value *l, const char *file, int line))
329 {
330 dynlock_destroy_callback=func;
331 }
332
333
334void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
335 int line)
336 {
337 return(locking_callback);
338 }
339
340int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
341 const char *file,int line)
342 {
343 return(add_lock_callback);
344 }
345
346void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
347 const char *file,int line))
348 {
349 locking_callback=func;
350 }
351
352void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
353 const char *file,int line))
354 {
355 add_lock_callback=func;
356 }
357
358unsigned long (*CRYPTO_get_id_callback(void))(void)
359 {
360 return(id_callback);
361 }
362
363void CRYPTO_set_id_callback(unsigned long (*func)(void))
364 {
365 id_callback=func;
366 }
367
368unsigned long CRYPTO_thread_id(void)
369 {
370 unsigned long ret=0;
371
372 if (id_callback == NULL)
373 {
374#ifdef OPENSSL_SYS_WIN16
375 ret=(unsigned long)GetCurrentTask();
376#elif defined(OPENSSL_SYS_WIN32)
377 ret=(unsigned long)GetCurrentThreadId();
378#elif defined(GETPID_IS_MEANINGLESS)
379 ret=1L;
380#else
381 ret=(unsigned long)getpid();
382#endif
383 }
384 else
385 ret=id_callback();
386 return(ret);
387 }
388
389void CRYPTO_lock(int mode, int type, const char *file, int line)
390 {
391#ifdef LOCK_DEBUG
392 {
393 char *rw_text,*operation_text;
394
395 if (mode & CRYPTO_LOCK)
396 operation_text="lock ";
397 else if (mode & CRYPTO_UNLOCK)
398 operation_text="unlock";
399 else
400 operation_text="ERROR ";
401
402 if (mode & CRYPTO_READ)
403 rw_text="r";
404 else if (mode & CRYPTO_WRITE)
405 rw_text="w";
406 else
407 rw_text="ERROR";
408
409 fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
410 CRYPTO_thread_id(), rw_text, operation_text,
411 CRYPTO_get_lock_name(type), file, line);
412 }
413#endif
414 if (type < 0)
415 {
416 if (dynlock_lock_callback != NULL)
417 {
418 struct CRYPTO_dynlock_value *pointer
419 = CRYPTO_get_dynlock_value(type);
420
421 OPENSSL_assert(pointer != NULL);
422
423 dynlock_lock_callback(mode, pointer, file, line);
424
425 CRYPTO_destroy_dynlockid(type);
426 }
427 }
428 else
429 if (locking_callback != NULL)
430 locking_callback(mode,type,file,line);
431 }
432
433int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
434 int line)
435 {
436 int ret = 0;
437
438 if (add_lock_callback != NULL)
439 {
440#ifdef LOCK_DEBUG
441 int before= *pointer;
442#endif
443
444 ret=add_lock_callback(pointer,amount,type,file,line);
445#ifdef LOCK_DEBUG
446 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
447 CRYPTO_thread_id(),
448 before,amount,ret,
449 CRYPTO_get_lock_name(type),
450 file,line);
451#endif
452 }
453 else
454 {
455 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
456
457 ret= *pointer+amount;
458#ifdef LOCK_DEBUG
459 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
460 CRYPTO_thread_id(),
461 *pointer,amount,ret,
462 CRYPTO_get_lock_name(type),
463 file,line);
464#endif
465 *pointer=ret;
466 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
467 }
468 return(ret);
469 }
470
471const char *CRYPTO_get_lock_name(int type)
472 {
473 if (type < 0)
474 return("dynamic");
475 else if (type < CRYPTO_NUM_LOCKS)
476 return(lock_names[type]);
477 else if (type-CRYPTO_NUM_LOCKS > sk_num(app_locks))
478 return("ERROR");
479 else
480 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
481 }
482
483#if defined(_WIN32) && defined(_WINDLL)
484
485/* All we really need to do is remove the 'error' state when a thread
486 * detaches */
487
488BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
489 LPVOID lpvReserved)
490 {
491 switch(fdwReason)
492 {
493 case DLL_PROCESS_ATTACH:
494 break;
495 case DLL_THREAD_ATTACH:
496 break;
497 case DLL_THREAD_DETACH:
498 ERR_remove_state(0);
499 break;
500 case DLL_PROCESS_DETACH:
501 break;
502 }
503 return(TRUE);
504 }
505#endif
506
507void OpenSSLDie(const char *file,int line,const char *assertion)
508 {
509 fprintf(stderr,
510 "%s(%d): OpenSSL internal error, assertion failed: %s\n",
511 file,line,assertion);
512 abort();
513 }
514
515#ifdef OPENSSL_FIPS
516static int fips_started = 0;
517static int fips_mode = 0;
518static void *fips_rand_check = 0;
519static unsigned long fips_thread = 0;
520
521void fips_set_started(void)
522 {
523 fips_started = 1;
524 }
525
526int fips_is_started(void)
527 {
528 return fips_started;
529 }
530
531int fips_is_owning_thread(void)
532 {
533 int ret = 0;
534
535 if (fips_is_started())
536 {
537 CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
538 if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
539 ret = 1;
540 CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
541 }
542 return ret;
543 }
544
545int fips_set_owning_thread(void)
546 {
547 int ret = 0;
548
549 if (fips_is_started())
550 {
551 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
552 if (fips_thread == 0)
553 {
554 fips_thread = CRYPTO_thread_id();
555 ret = 1;
556 }
557 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
558 }
559 return ret;
560 }
561
562int fips_clear_owning_thread(void)
563 {
564 int ret = 0;
565
566 if (fips_is_started())
567 {
568 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
569 if (fips_thread == CRYPTO_thread_id())
570 {
571 fips_thread = 0;
572 ret = 1;
573 }
574 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
575 }
576 return ret;
577 }
578
579void fips_set_mode(int onoff)
580 {
581 int owning_thread = fips_is_owning_thread();
582
583 if (fips_is_started())
584 {
585 if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS);
586 fips_mode = onoff;
587 if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS);
588 }
589 }
590
591void fips_set_rand_check(void *rand_check)
592 {
593 int owning_thread = fips_is_owning_thread();
594
595 if (fips_is_started())
596 {
597 if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS);
598 fips_rand_check = rand_check;
599 if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS);
600 }
601 }
602
603int FIPS_mode(void)
604 {
605 int ret = 0;
606 int owning_thread = fips_is_owning_thread();
607
608 if (fips_is_started())
609 {
610 if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS);
611 ret = fips_mode;
612 if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS);
613 }
614 return ret;
615 }
616
617void *FIPS_rand_check(void)
618 {
619 void *ret = 0;
620 int owning_thread = fips_is_owning_thread();
621
622 if (fips_is_started())
623 {
624 if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS);
625 ret = fips_rand_check;
626 if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS);
627 }
628 return ret;
629 }
630
631#endif /* OPENSSL_FIPS */
632
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h
new file mode 100644
index 0000000000..0d6b9d59f0
--- /dev/null
+++ b/src/lib/libcrypto/cryptlib.h
@@ -0,0 +1,100 @@
1/* crypto/cryptlib.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CRYPTLIB_H
60#define HEADER_CRYPTLIB_H
61
62#include <stdlib.h>
63#include <string.h>
64
65#include "e_os.h"
66
67#include <openssl/crypto.h>
68#include <openssl/buffer.h>
69#include <openssl/bio.h>
70#include <openssl/err.h>
71#include <openssl/opensslconf.h>
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77#ifndef OPENSSL_SYS_VMS
78#define X509_CERT_AREA OPENSSLDIR
79#define X509_CERT_DIR OPENSSLDIR "/certs"
80#define X509_CERT_FILE OPENSSLDIR "/cert.pem"
81#define X509_PRIVATE_DIR OPENSSLDIR "/private"
82#else
83#define X509_CERT_AREA "SSLROOT:[000000]"
84#define X509_CERT_DIR "SSLCERTS:"
85#define X509_CERT_FILE "SSLCERTS:cert.pem"
86#define X509_PRIVATE_DIR "SSLPRIVATE:"
87#endif
88
89#define X509_CERT_DIR_EVP "SSL_CERT_DIR"
90#define X509_CERT_FILE_EVP "SSL_CERT_FILE"
91
92/* size of string representations */
93#define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
94#define HEX_SIZE(type) (sizeof(type)*2)
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif
diff --git a/src/lib/libcrypto/crypto-lib.com b/src/lib/libcrypto/crypto-lib.com
index 427c321f25..c044ce0099 100644
--- a/src/lib/libcrypto/crypto-lib.com
+++ b/src/lib/libcrypto/crypto-lib.com
@@ -184,10 +184,10 @@ $ 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,"+ - 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,"+ - 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+","+ - 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" 187 "bn_recp,bn_mont,bn_mpi,bn_exp2"
188$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ - 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,"+ - 189 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk,rsa_null,"+ -
190 "rsa_pss,rsa_x931,rsa_asn1" 190 "rsa_asn1"
191$ LIB_EC = "ec_lib,ecp_smpl,ecp_mont,ecp_recp,ecp_nist,ec_cvt,ec_mult,"+ - 191$ LIB_EC = "ec_lib,ecp_smpl,ecp_mont,ecp_recp,ecp_nist,ec_cvt,ec_mult,"+ -
192 "ec_err" 192 "ec_err"
193$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err,dsa_ossl" 193$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err,dsa_ossl"
@@ -265,15 +265,10 @@ $ LIB_KRB5 = "krb5_asn"
265$! 265$!
266$! Setup exceptional compilations 266$! Setup exceptional compilations
267$! 267$!
268$ ! Add definitions for no threads on OpenVMS 7.1 and higher
269$ COMPILEWITH_CC3 = ",bss_rtcp," 268$ COMPILEWITH_CC3 = ",bss_rtcp,"
270$ ! Disable the DOLLARID warning
271$ COMPILEWITH_CC4 = ",a_utctm,bss_log,o_time," 269$ COMPILEWITH_CC4 = ",a_utctm,bss_log,o_time,"
272$ ! Disable disjoint optimization
273$ COMPILEWITH_CC5 = ",md2_dgst,md4_dgst,md5_dgst,mdc2dgst," + - 270$ COMPILEWITH_CC5 = ",md2_dgst,md4_dgst,md5_dgst,mdc2dgst," + -
274 "sha_dgst,sha1dgst,rmd_dgst,bf_enc," 271 "sha_dgst,sha1dgst,rmd_dgst,bf_enc,"
275$ ! Disable the MIXLINKAGE warning
276$ COMPILEWITH_CC6 = ",enc_read,set_key,"
277$! 272$!
278$! Figure Out What Other Modules We Are To Build. 273$! Figure Out What Other Modules We Are To Build.
279$! 274$!
@@ -502,12 +497,7 @@ $ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
502$ THEN 497$ THEN
503$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE' 498$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
504$ ELSE 499$ ELSE
505$ IF COMPILEWITH_CC6 - FILE_NAME0 .NES. COMPILEWITH_CC6 500$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
506$ THEN
507$ CC6/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
508$ ELSE
509$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
510$ ENDIF
511$ ENDIF 501$ ENDIF
512$ ENDIF 502$ ENDIF
513$ ENDIF 503$ ENDIF
@@ -970,7 +960,7 @@ $ CCDEFS = "TCPIP_TYPE_''P4',DSO_VMS"
970$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS 960$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
971$ CCEXTRAFLAGS = "" 961$ CCEXTRAFLAGS = ""
972$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS 962$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
973$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR" 963$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX"
974$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN - 964$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
975 CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS 965 CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
976$! 966$!
@@ -1087,18 +1077,14 @@ $ THEN
1087$ IF CCDISABLEWARNINGS .EQS. "" 1077$ IF CCDISABLEWARNINGS .EQS. ""
1088$ THEN 1078$ THEN
1089$ CC4DISABLEWARNINGS = "DOLLARID" 1079$ CC4DISABLEWARNINGS = "DOLLARID"
1090$ CC6DISABLEWARNINGS = "MIXLINKAGE"
1091$ ELSE 1080$ ELSE
1092$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID" 1081$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
1093$ CC6DISABLEWARNINGS = CCDISABLEWARNINGS + ",MIXLINKAGE"
1094$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))" 1082$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1095$ ENDIF 1083$ ENDIF
1096$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))" 1084$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
1097$ CC6DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC6DISABLEWARNINGS + "))"
1098$ ELSE 1085$ ELSE
1099$ CCDISABLEWARNINGS = "" 1086$ CCDISABLEWARNINGS = ""
1100$ CC4DISABLEWARNINGS = "" 1087$ CC4DISABLEWARNINGS = ""
1101$ CC6DISABLEWARNINGS = ""
1102$ ENDIF 1088$ ENDIF
1103$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS 1089$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1104$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS 1090$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
@@ -1109,7 +1095,6 @@ $ ELSE
1109$ CC5 = CC + "/NOOPTIMIZE" 1095$ CC5 = CC + "/NOOPTIMIZE"
1110$ ENDIF 1096$ ENDIF
1111$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS 1097$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1112$ CC6 = CC - CCDISABLEWARNINGS + CC6DISABLEWARNINGS
1113$! 1098$!
1114$! Show user the result 1099$! Show user the result
1115$! 1100$!
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h
new file mode 100644
index 0000000000..4d1dfac7f1
--- /dev/null
+++ b/src/lib/libcrypto/crypto.h
@@ -0,0 +1,521 @@
1/* crypto/crypto.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CRYPTO_H
60#define HEADER_CRYPTO_H
61
62#include <stdlib.h>
63
64#ifndef OPENSSL_NO_FP_API
65#include <stdio.h>
66#endif
67
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70#include <openssl/opensslv.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
75
76/* Resolve problems on some operating systems with symbol names that clash
77 one way or another */
78#include <openssl/symhacks.h>
79
80#ifdef __cplusplus
81extern "C" {
82#endif
83
84/* Backward compatibility to SSLeay */
85/* This is more to be used to check the correct DLL is being used
86 * in the MS world. */
87#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
88#define SSLEAY_VERSION 0
89/* #define SSLEAY_OPTIONS 1 no longer supported */
90#define SSLEAY_CFLAGS 2
91#define SSLEAY_BUILT_ON 3
92#define SSLEAY_PLATFORM 4
93#define SSLEAY_DIR 5
94
95/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
96 * names in cryptlib.c
97 */
98
99#define CRYPTO_LOCK_ERR 1
100#define CRYPTO_LOCK_EX_DATA 2
101#define CRYPTO_LOCK_X509 3
102#define CRYPTO_LOCK_X509_INFO 4
103#define CRYPTO_LOCK_X509_PKEY 5
104#define CRYPTO_LOCK_X509_CRL 6
105#define CRYPTO_LOCK_X509_REQ 7
106#define CRYPTO_LOCK_DSA 8
107#define CRYPTO_LOCK_RSA 9
108#define CRYPTO_LOCK_EVP_PKEY 10
109#define CRYPTO_LOCK_X509_STORE 11
110#define CRYPTO_LOCK_SSL_CTX 12
111#define CRYPTO_LOCK_SSL_CERT 13
112#define CRYPTO_LOCK_SSL_SESSION 14
113#define CRYPTO_LOCK_SSL_SESS_CERT 15
114#define CRYPTO_LOCK_SSL 16
115#define CRYPTO_LOCK_SSL_METHOD 17
116#define CRYPTO_LOCK_RAND 18
117#define CRYPTO_LOCK_RAND2 19
118#define CRYPTO_LOCK_MALLOC 20
119#define CRYPTO_LOCK_BIO 21
120#define CRYPTO_LOCK_GETHOSTBYNAME 22
121#define CRYPTO_LOCK_GETSERVBYNAME 23
122#define CRYPTO_LOCK_READDIR 24
123#define CRYPTO_LOCK_RSA_BLINDING 25
124#define CRYPTO_LOCK_DH 26
125#define CRYPTO_LOCK_MALLOC2 27
126#define CRYPTO_LOCK_DSO 28
127#define CRYPTO_LOCK_DYNLOCK 29
128#define CRYPTO_LOCK_ENGINE 30
129#define CRYPTO_LOCK_UI 31
130#define CRYPTO_LOCK_HWCRHK 32 /* This is a HACK which will disappear in 0.9.8 */
131#define CRYPTO_LOCK_FIPS 33
132#define CRYPTO_LOCK_FIPS2 34
133#define CRYPTO_NUM_LOCKS 35
134
135#define CRYPTO_LOCK 1
136#define CRYPTO_UNLOCK 2
137#define CRYPTO_READ 4
138#define CRYPTO_WRITE 8
139
140#ifndef OPENSSL_NO_LOCKING
141#ifndef CRYPTO_w_lock
142#define CRYPTO_w_lock(type) \
143 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
144#define CRYPTO_w_unlock(type) \
145 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
146#define CRYPTO_r_lock(type) \
147 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
148#define CRYPTO_r_unlock(type) \
149 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
150#define CRYPTO_add(addr,amount,type) \
151 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
152#endif
153#else
154#define CRYPTO_w_lock(a)
155#define CRYPTO_w_unlock(a)
156#define CRYPTO_r_lock(a)
157#define CRYPTO_r_unlock(a)
158#define CRYPTO_add(a,b,c) ((*(a))+=(b))
159#endif
160
161/* Some applications as well as some parts of OpenSSL need to allocate
162 and deallocate locks in a dynamic fashion. The following typedef
163 makes this possible in a type-safe manner. */
164/* struct CRYPTO_dynlock_value has to be defined by the application. */
165typedef struct
166 {
167 int references;
168 struct CRYPTO_dynlock_value *data;
169 } CRYPTO_dynlock;
170
171
172/* The following can be used to detect memory leaks in the SSLeay library.
173 * It used, it turns on malloc checking */
174
175#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */
176#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */
177#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
178#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
179
180/* The following are bit values to turn on or off options connected to the
181 * malloc checking functionality */
182
183/* Adds time to the memory checking information */
184#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */
185/* Adds thread number to the memory checking information */
186#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */
187
188#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
189
190
191/* predec of the BIO type */
192typedef struct bio_st BIO_dummy;
193
194typedef struct crypto_ex_data_st
195 {
196 STACK *sk;
197 int dummy; /* gcc is screwing up this data structure :-( */
198 } CRYPTO_EX_DATA;
199
200/* Called when a new object is created */
201typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
202 int idx, long argl, void *argp);
203/* Called when an object is free()ed */
204typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
205 int idx, long argl, void *argp);
206/* Called when we need to dup an object */
207typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
208 int idx, long argl, void *argp);
209
210/* This stuff is basically class callback functions
211 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */
212
213typedef struct crypto_ex_data_func_st
214 {
215 long argl; /* Arbitary long */
216 void *argp; /* Arbitary void * */
217 CRYPTO_EX_new *new_func;
218 CRYPTO_EX_free *free_func;
219 CRYPTO_EX_dup *dup_func;
220 } CRYPTO_EX_DATA_FUNCS;
221
222DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
223
224/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
225 * entry.
226 */
227
228#define CRYPTO_EX_INDEX_BIO 0
229#define CRYPTO_EX_INDEX_SSL 1
230#define CRYPTO_EX_INDEX_SSL_CTX 2
231#define CRYPTO_EX_INDEX_SSL_SESSION 3
232#define CRYPTO_EX_INDEX_X509_STORE 4
233#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
234#define CRYPTO_EX_INDEX_RSA 6
235#define CRYPTO_EX_INDEX_DSA 7
236#define CRYPTO_EX_INDEX_DH 8
237#define CRYPTO_EX_INDEX_ENGINE 9
238#define CRYPTO_EX_INDEX_X509 10
239#define CRYPTO_EX_INDEX_UI 11
240
241/* Dynamically assigned indexes start from this value (don't use directly, use
242 * via CRYPTO_ex_data_new_class). */
243#define CRYPTO_EX_INDEX_USER 100
244
245
246/* This is the default callbacks, but we can have others as well:
247 * this is needed in Win32 where the application malloc and the
248 * library malloc may not be the same.
249 */
250#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
251 malloc, realloc, free)
252
253#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
254# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
255# define CRYPTO_MDEBUG
256# endif
257#endif
258
259/* Set standard debugging functions (not done by default
260 * unless CRYPTO_MDEBUG is defined) */
261#define CRYPTO_malloc_debug_init() do {\
262 CRYPTO_set_mem_debug_functions(\
263 CRYPTO_dbg_malloc,\
264 CRYPTO_dbg_realloc,\
265 CRYPTO_dbg_free,\
266 CRYPTO_dbg_set_options,\
267 CRYPTO_dbg_get_options);\
268 } while(0)
269
270int CRYPTO_mem_ctrl(int mode);
271int CRYPTO_is_mem_check_on(void);
272
273/* for applications */
274#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
275#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
276
277/* for library-internal use */
278#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
279#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
280#define is_MemCheck_on() CRYPTO_is_mem_check_on()
281
282#define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__)
283#define OPENSSL_realloc(addr,num) \
284 CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
285#define OPENSSL_realloc_clean(addr,old_num,num) \
286 CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__)
287#define OPENSSL_remalloc(addr,num) \
288 CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
289#define OPENSSL_freeFunc CRYPTO_free
290#define OPENSSL_free(addr) CRYPTO_free(addr)
291
292#define OPENSSL_malloc_locked(num) \
293 CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
294#define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr)
295
296
297const char *SSLeay_version(int type);
298unsigned long SSLeay(void);
299
300int OPENSSL_issetugid(void);
301
302/* An opaque type representing an implementation of "ex_data" support */
303typedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL;
304/* Return an opaque pointer to the current "ex_data" implementation */
305const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void);
306/* Sets the "ex_data" implementation to be used (if it's not too late) */
307int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i);
308/* Get a new "ex_data" class, and return the corresponding "class_index" */
309int CRYPTO_ex_data_new_class(void);
310/* Within a given class, get/register a new index */
311int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
312 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
313 CRYPTO_EX_free *free_func);
314/* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given
315 * class (invokes whatever per-class callbacks are applicable) */
316int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
317int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
318 CRYPTO_EX_DATA *from);
319void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
320/* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index
321 * (relative to the class type involved) */
322int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
323void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad,int idx);
324/* This function cleans up all "ex_data" state. It mustn't be called under
325 * potential race-conditions. */
326void CRYPTO_cleanup_all_ex_data(void);
327
328int CRYPTO_get_new_lockid(char *name);
329
330int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
331void CRYPTO_lock(int mode, int type,const char *file,int line);
332void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
333 const char *file,int line));
334void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
335 int line);
336void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
337 const char *file, int line));
338int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
339 const char *file,int line);
340void CRYPTO_set_id_callback(unsigned long (*func)(void));
341unsigned long (*CRYPTO_get_id_callback(void))(void);
342unsigned long CRYPTO_thread_id(void);
343const char *CRYPTO_get_lock_name(int type);
344int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
345 int line);
346
347int CRYPTO_get_new_dynlockid(void);
348void CRYPTO_destroy_dynlockid(int i);
349struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i);
350void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, int line));
351void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line));
352void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, const char *file, int line));
353struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file,int line);
354void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file,int line);
355void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file,int line);
356
357/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions --
358 * call the latter last if you need different functions */
359int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
360int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
361int CRYPTO_set_mem_ex_functions(void *(*m)(size_t,const char *,int),
362 void *(*r)(void *,size_t,const char *,int),
363 void (*f)(void *));
364int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t,const char *,int),
365 void (*free_func)(void *));
366int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
367 void (*r)(void *,void *,int,const char *,int,int),
368 void (*f)(void *,int),
369 void (*so)(long),
370 long (*go)(void));
371void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
372void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
373void CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int),
374 void *(**r)(void *, size_t,const char *,int),
375 void (**f)(void *));
376void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t,const char *,int),
377 void (**f)(void *));
378void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
379 void (**r)(void *,void *,int,const char *,int,int),
380 void (**f)(void *,int),
381 void (**so)(long),
382 long (**go)(void));
383
384void *CRYPTO_malloc_locked(int num, const char *file, int line);
385void CRYPTO_free_locked(void *);
386void *CRYPTO_malloc(int num, const char *file, int line);
387void CRYPTO_free(void *);
388void *CRYPTO_realloc(void *addr,int num, const char *file, int line);
389void *CRYPTO_realloc_clean(void *addr,int old_num,int num,const char *file,
390 int line);
391void *CRYPTO_remalloc(void *addr,int num, const char *file, int line);
392
393void OPENSSL_cleanse(void *ptr, size_t len);
394
395void CRYPTO_set_mem_debug_options(long bits);
396long CRYPTO_get_mem_debug_options(void);
397
398#define CRYPTO_push_info(info) \
399 CRYPTO_push_info_(info, __FILE__, __LINE__);
400int CRYPTO_push_info_(const char *info, const char *file, int line);
401int CRYPTO_pop_info(void);
402int CRYPTO_remove_all_info(void);
403
404
405/* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;
406 * used as default in CRYPTO_MDEBUG compilations): */
407/* The last argument has the following significance:
408 *
409 * 0: called before the actual memory allocation has taken place
410 * 1: called after the actual memory allocation has taken place
411 */
412void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p);
413void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p);
414void CRYPTO_dbg_free(void *addr,int before_p);
415/* Tell the debugging code about options. By default, the following values
416 * apply:
417 *
418 * 0: Clear all options.
419 * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option.
420 * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option.
421 * V_CRYPTO_MDEBUG_ALL (3): 1 + 2
422 */
423void CRYPTO_dbg_set_options(long bits);
424long CRYPTO_dbg_get_options(void);
425
426
427#ifndef OPENSSL_NO_FP_API
428void CRYPTO_mem_leaks_fp(FILE *);
429#endif
430void CRYPTO_mem_leaks(struct bio_st *bio);
431/* unsigned long order, char *file, int line, int num_bytes, char *addr */
432typedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *);
433void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);
434
435/* die if we have to */
436void OpenSSLDie(const char *file,int line,const char *assertion);
437#define OPENSSL_assert(e) ((e) ? (void)0 : OpenSSLDie(__FILE__, __LINE__, #e))
438
439#ifdef OPENSSL_FIPS
440int FIPS_mode(void);
441void *FIPS_rand_check(void);
442
443#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
444 alg " previous FIPS forbidden algorithm error ignored");
445
446#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
447 #alg " Algorithm forbidden in FIPS mode");
448
449#ifdef OPENSSL_FIPS_STRICT
450#define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg)
451#else
452#define FIPS_BAD_ALGORITHM(alg) \
453 { \
454 FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \
455 ERR_add_error_data(2, "Algorithm=", #alg); \
456 return 0; \
457 }
458#endif
459
460/* Low level digest API blocking macro */
461
462#define FIPS_NON_FIPS_MD_Init(alg) \
463 int alg##_Init(alg##_CTX *c) \
464 { \
465 if (FIPS_mode()) \
466 FIPS_BAD_ALGORITHM(alg) \
467 return private_##alg##_Init(c); \
468 } \
469 int private_##alg##_Init(alg##_CTX *c)
470
471/* For ciphers the API often varies from cipher to cipher and each needs to
472 * be treated as a special case. Variable key length ciphers (Blowfish, RC4,
473 * CAST) however are very similar and can use a blocking macro.
474 */
475
476#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
477 void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \
478 { \
479 if (FIPS_mode()) \
480 FIPS_BAD_ABORT(alg) \
481 private_##alg##_set_key(key, len, data); \
482 } \
483 void private_##alg##_set_key(alg##_KEY *key, int len, \
484 const unsigned char *data)
485
486#else
487
488#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
489 void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data)
490
491#define FIPS_NON_FIPS_MD_Init(alg) \
492 int alg##_Init(alg##_CTX *c)
493
494#endif /* def OPENSSL_FIPS */
495
496/* BEGIN ERROR CODES */
497/* The following lines are auto generated by the script mkerr.pl. Any changes
498 * made after this point may be overwritten when the script is next run.
499 */
500void ERR_load_CRYPTO_strings(void);
501
502/* Error codes for the CRYPTO functions. */
503
504/* Function codes. */
505#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
506#define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID 103
507#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
508#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
509#define CRYPTO_F_DEF_ADD_INDEX 104
510#define CRYPTO_F_DEF_GET_CLASS 105
511#define CRYPTO_F_INT_DUP_EX_DATA 106
512#define CRYPTO_F_INT_FREE_EX_DATA 107
513#define CRYPTO_F_INT_NEW_EX_DATA 108
514
515/* Reason codes. */
516#define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100
517
518#ifdef __cplusplus
519}
520#endif
521#endif
diff --git a/src/lib/libcrypto/cversion.c b/src/lib/libcrypto/cversion.c
new file mode 100644
index 0000000000..beeeb14013
--- /dev/null
+++ b/src/lib/libcrypto/cversion.c
@@ -0,0 +1,120 @@
1/* crypto/cversion.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/crypto.h>
63
64#ifndef NO_WINDOWS_BRAINDEATH
65#include "buildinf.h"
66#endif
67
68const char *SSLeay_version(int t)
69 {
70 if (t == SSLEAY_VERSION)
71 return OPENSSL_VERSION_TEXT;
72 if (t == SSLEAY_BUILT_ON)
73 {
74#ifdef DATE
75 static char buf[sizeof(DATE)+11];
76
77 BIO_snprintf(buf,sizeof buf,"built on: %s",DATE);
78 return(buf);
79#else
80 return("built on: date not available");
81#endif
82 }
83 if (t == SSLEAY_CFLAGS)
84 {
85#ifdef CFLAGS
86 static char buf[sizeof(CFLAGS)+11];
87
88 BIO_snprintf(buf,sizeof buf,"compiler: %s",CFLAGS);
89 return(buf);
90#else
91 return("compiler: information not available");
92#endif
93 }
94 if (t == SSLEAY_PLATFORM)
95 {
96#ifdef PLATFORM
97 static char buf[sizeof(PLATFORM)+11];
98
99 BIO_snprintf(buf,sizeof buf,"platform: %s", PLATFORM);
100 return(buf);
101#else
102 return("platform: information not available");
103#endif
104 }
105 if (t == SSLEAY_DIR)
106 {
107#ifdef OPENSSLDIR
108 return "OPENSSLDIR: \"" OPENSSLDIR "\"";
109#else
110 return "OPENSSLDIR: N/A";
111#endif
112 }
113 return("not available");
114 }
115
116unsigned long SSLeay(void)
117 {
118 return(SSLEAY_VERSION_NUMBER);
119 }
120
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT
new file mode 100644
index 0000000000..5469e1e469
--- /dev/null
+++ b/src/lib/libcrypto/des/COPYRIGHT
@@ -0,0 +1,50 @@
1Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2All rights reserved.
3
4This package is an DES implementation written by Eric Young (eay@cryptsoft.com).
5The implementation was written so as to conform with MIT's libdes.
6
7This library is free for commercial and non-commercial use as long as
8the following conditions are aheared to. The following conditions
9apply to all code found in this distribution.
10
11Copyright remains Eric Young's, and as such any Copyright notices in
12the code are not to be removed.
13If this package is used in a product, Eric Young should be given attribution
14as the author of that the SSL library. This can be in the form of a textual
15message at program startup or in documentation (online or textual) provided
16with the package.
17
18Redistribution and use in source and binary forms, with or without
19modification, are permitted provided that the following conditions
20are met:
211. Redistributions of source code must retain the copyright
22 notice, this list of conditions and the following disclaimer.
232. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
263. All advertising materials mentioning features or use of this software
27 must display the following acknowledgement:
28 This product includes software developed by Eric Young (eay@cryptsoft.com)
29
30THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
31ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40SUCH DAMAGE.
41
42The license and distribution terms for any publically available version or
43derivative of this code cannot be changed. i.e. this code cannot simply be
44copied and put under another distrubution license
45[including the GNU Public License.]
46
47The reason behind this being stated in this direct manner is past
48experience in code simply being copied and the attribution removed
49from it and then being distributed as part of other packages. This
50implementation was a non-trivial and unpaid effort.
diff --git a/src/lib/libcrypto/des/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/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
new file mode 100644
index 0000000000..1d04ed6def
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/crypt586.pl
@@ -0,0 +1,208 @@
1#!/usr/local/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5# I've added the stuff needed for crypt() but I've not worried about making
6# things perfect.
7#
8
9push(@INC,"perlasm","../../perlasm");
10require "x86asm.pl";
11
12&asm_init($ARGV[0],"crypt586.pl");
13
14$L="edi";
15$R="esi";
16
17&external_label("DES_SPtrans");
18&fcrypt_body("fcrypt_body");
19&asm_finish();
20
21sub fcrypt_body
22 {
23 local($name,$do_ip)=@_;
24
25 &function_begin($name,"EXTRN _DES_SPtrans:DWORD");
26
27 &comment("");
28 &comment("Load the 2 words");
29 $trans="ebp";
30
31 &xor( $L, $L);
32 &xor( $R, $R);
33
34 # PIC-ification:-)
35 &picmeup("edx","DES_SPtrans");
36 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
37 #else { &lea("edx",&DWP("DES_SPtrans")); }
38 &push("edx"); # becomes &swtmp(1)
39 #
40 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
41
42 &push(&DWC(25)); # add a variable
43
44 &set_label("start");
45 for ($i=0; $i<16; $i+=2)
46 {
47 &comment("");
48 &comment("Round $i");
49 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
50
51 &comment("");
52 &comment("Round ".sprintf("%d",$i+1));
53 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
54 }
55 &mov("ebx", &swtmp(0));
56 &mov("eax", $L);
57 &dec("ebx");
58 &mov($L, $R);
59 &mov($R, "eax");
60 &mov(&swtmp(0), "ebx");
61 &jnz(&label("start"));
62
63 &comment("");
64 &comment("FP");
65 &mov("edx",&wparam(0));
66
67 &FP_new($R,$L,"eax",3);
68 &mov(&DWP(0,"edx","",0),"eax");
69 &mov(&DWP(4,"edx","",0),$L);
70
71 &add("esp",8); # remove variables
72
73 &function_end($name);
74 }
75
76sub D_ENCRYPT
77 {
78 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
79
80 &mov( $u, &wparam(2)); # 2
81 &mov( $t, $R);
82 &shr( $t, 16); # 1
83 &mov( $tmp2, &wparam(3)); # 2
84 &xor( $t, $R); # 1
85
86 &and( $u, $t); # 2
87 &and( $t, $tmp2); # 2
88
89 &mov( $tmp1, $u);
90 &shl( $tmp1, 16); # 1
91 &mov( $tmp2, $t);
92 &shl( $tmp2, 16); # 1
93 &xor( $u, $tmp1); # 2
94 &xor( $t, $tmp2); # 2
95 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
96 &xor( $u, $tmp1);
97 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
98 &xor( $u, $R);
99 &xor( $t, $R);
100 &xor( $t, $tmp2);
101
102 &and( $u, "0xfcfcfcfc" ); # 2
103 &xor( $tmp1, $tmp1); # 1
104 &and( $t, "0xcfcfcfcf" ); # 2
105 &xor( $tmp2, $tmp2);
106 &movb( &LB($tmp1), &LB($u) );
107 &movb( &LB($tmp2), &HB($u) );
108 &rotr( $t, 4 );
109 &mov( $trans, &swtmp(1));
110 &xor( $L, &DWP(" ",$trans,$tmp1,0));
111 &movb( &LB($tmp1), &LB($t) );
112 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
113 &movb( &LB($tmp2), &HB($t) );
114 &shr( $u, 16);
115 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
116 &movb( &LB($tmp1), &HB($u) );
117 &shr( $t, 16);
118 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
119 &movb( &LB($tmp2), &HB($t) );
120 &and( $u, "0xff" );
121 &and( $t, "0xff" );
122 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
123 &xor( $L, $tmp1);
124 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
125 &xor( $L, $tmp1);
126 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
127 &xor( $L, $tmp1);
128 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
129 &xor( $L, $tmp1);
130 &mov( $trans, &wparam(1));
131 }
132
133sub n2a
134 {
135 sprintf("%d",$_[0]);
136 }
137
138# now has a side affect of rotating $a by $shift
139sub R_PERM_OP
140 {
141 local($a,$b,$tt,$shift,$mask,$last)=@_;
142
143 &rotl( $a, $shift ) if ($shift != 0);
144 &mov( $tt, $a );
145 &xor( $a, $b );
146 &and( $a, $mask );
147 if ($notlast eq $b)
148 {
149 &xor( $b, $a );
150 &xor( $tt, $a );
151 }
152 else
153 {
154 &xor( $tt, $a );
155 &xor( $b, $a );
156 }
157 &comment("");
158 }
159
160sub IP_new
161 {
162 local($l,$r,$tt,$lr)=@_;
163
164 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
165 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
166 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
167 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
168 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
169
170 if ($lr != 3)
171 {
172 if (($lr-3) < 0)
173 { &rotr($tt, 3-$lr); }
174 else { &rotl($tt, $lr-3); }
175 }
176 if ($lr != 2)
177 {
178 if (($lr-2) < 0)
179 { &rotr($r, 2-$lr); }
180 else { &rotl($r, $lr-2); }
181 }
182 }
183
184sub FP_new
185 {
186 local($l,$r,$tt,$lr)=@_;
187
188 if ($lr != 2)
189 {
190 if (($lr-2) < 0)
191 { &rotl($r, 2-$lr); }
192 else { &rotr($r, $lr-2); }
193 }
194 if ($lr != 3)
195 {
196 if (($lr-3) < 0)
197 { &rotl($l, 3-$lr); }
198 else { &rotr($l, $lr-3); }
199 }
200
201 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
202 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
203 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
204 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
205 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
206 &rotr($tt , 4);
207 }
208
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
new file mode 100644
index 0000000000..60d577cc8d
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -0,0 +1,255 @@
1#!/usr/local/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5#
6
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9require "cbc.pl";
10require "desboth.pl";
11
12# base code is in microsft
13# op dest, source
14# format.
15#
16
17&asm_init($ARGV[0],"des-586.pl");
18
19$L="edi";
20$R="esi";
21
22&external_label("DES_SPtrans");
23&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0);
25
26if (!$main'openbsd)
27 {
28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
33
34&asm_finish();
35
36sub DES_encrypt
37 {
38 local($name,$do_ip)=@_;
39
40 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
41
42 &push("esi");
43 &push("edi");
44
45 &comment("");
46 &comment("Load the 2 words");
47 $trans="ebp";
48
49 if ($do_ip)
50 {
51 &mov($R,&wparam(0));
52 &xor( "ecx", "ecx" );
53
54 &push("ebx");
55 &push("ebp");
56
57 &mov("eax",&DWP(0,$R,"",0));
58 &mov("ebx",&wparam(2)); # get encrypt flag
59 &mov($L,&DWP(4,$R,"",0));
60 &comment("");
61 &comment("IP");
62 &IP_new("eax",$L,$R,3);
63 }
64 else
65 {
66 &mov("eax",&wparam(0));
67 &xor( "ecx", "ecx" );
68
69 &push("ebx");
70 &push("ebp");
71
72 &mov($R,&DWP(0,"eax","",0));
73 &mov("ebx",&wparam(2)); # get encrypt flag
74 &rotl($R,3);
75 &mov($L,&DWP(4,"eax","",0));
76 &rotl($L,3);
77 }
78
79 # PIC-ification:-)
80 &picmeup($trans,"DES_SPtrans");
81 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); }
82 #else { &lea($trans,&DWP("DES_SPtrans")); }
83
84 &mov( "ecx", &wparam(1) );
85 &cmp("ebx","0");
86 &je(&label("start_decrypt"));
87
88 for ($i=0; $i<16; $i+=2)
89 {
90 &comment("");
91 &comment("Round $i");
92 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
93
94 &comment("");
95 &comment("Round ".sprintf("%d",$i+1));
96 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
97 }
98 &jmp(&label("end"));
99
100 &set_label("start_decrypt");
101
102 for ($i=15; $i>0; $i-=2)
103 {
104 &comment("");
105 &comment("Round $i");
106 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
107 &comment("");
108 &comment("Round ".sprintf("%d",$i-1));
109 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
110 }
111
112 &set_label("end");
113
114 if ($do_ip)
115 {
116 &comment("");
117 &comment("FP");
118 &mov("edx",&wparam(0));
119 &FP_new($L,$R,"eax",3);
120
121 &mov(&DWP(0,"edx","",0),"eax");
122 &mov(&DWP(4,"edx","",0),$R);
123 }
124 else
125 {
126 &comment("");
127 &comment("Fixup");
128 &rotr($L,3); # r
129 &mov("eax",&wparam(0));
130 &rotr($R,3); # l
131 &mov(&DWP(0,"eax","",0),$L);
132 &mov(&DWP(4,"eax","",0),$R);
133 }
134
135 &pop("ebp");
136 &pop("ebx");
137 &pop("edi");
138 &pop("esi");
139 &ret();
140
141 &function_end_B($name);
142 }
143
144sub D_ENCRYPT
145 {
146 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
147
148 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
149 &xor( $tmp1, $tmp1);
150 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
151 &xor( $u, $R);
152 &xor( $tmp2, $tmp2);
153 &xor( $t, $R);
154 &and( $u, "0xfcfcfcfc" );
155 &and( $t, "0xcfcfcfcf" );
156 &movb( &LB($tmp1), &LB($u) );
157 &movb( &LB($tmp2), &HB($u) );
158 &rotr( $t, 4 );
159 &xor( $L, &DWP(" ",$trans,$tmp1,0));
160 &movb( &LB($tmp1), &LB($t) );
161 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
162 &movb( &LB($tmp2), &HB($t) );
163 &shr( $u, 16);
164 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
165 &movb( &LB($tmp1), &HB($u) );
166 &shr( $t, 16);
167 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
168 &movb( &LB($tmp2), &HB($t) );
169 &and( $u, "0xff" );
170 &and( $t, "0xff" );
171 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
172 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
173 &mov( $tmp2, &wparam(1) );
174 &xor( $L, &DWP("0x400",$trans,$u,0));
175 &xor( $L, &DWP("0x500",$trans,$t,0));
176 }
177
178sub n2a
179 {
180 sprintf("%d",$_[0]);
181 }
182
183# now has a side affect of rotating $a by $shift
184sub R_PERM_OP
185 {
186 local($a,$b,$tt,$shift,$mask,$last)=@_;
187
188 &rotl( $a, $shift ) if ($shift != 0);
189 &mov( $tt, $a );
190 &xor( $a, $b );
191 &and( $a, $mask );
192 # This can never succeed, and besides it is difficult to see what the
193 # idea was - Ben 13 Feb 99
194 if (!$last eq $b)
195 {
196 &xor( $b, $a );
197 &xor( $tt, $a );
198 }
199 else
200 {
201 &xor( $tt, $a );
202 &xor( $b, $a );
203 }
204 &comment("");
205 }
206
207sub IP_new
208 {
209 local($l,$r,$tt,$lr)=@_;
210
211 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
212 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
213 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
214 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
215 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
216
217 if ($lr != 3)
218 {
219 if (($lr-3) < 0)
220 { &rotr($tt, 3-$lr); }
221 else { &rotl($tt, $lr-3); }
222 }
223 if ($lr != 2)
224 {
225 if (($lr-2) < 0)
226 { &rotr($r, 2-$lr); }
227 else { &rotl($r, $lr-2); }
228 }
229 }
230
231sub FP_new
232 {
233 local($l,$r,$tt,$lr)=@_;
234
235 if ($lr != 2)
236 {
237 if (($lr-2) < 0)
238 { &rotl($r, 2-$lr); }
239 else { &rotr($r, $lr-2); }
240 }
241 if ($lr != 3)
242 {
243 if (($lr-3) < 0)
244 { &rotl($l, 3-$lr); }
245 else { &rotr($l, $lr-3); }
246 }
247
248 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
249 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
250 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
251 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
252 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
253 &rotr($tt , 4);
254 }
255
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
new file mode 100644
index 0000000000..eec00886e4
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/desboth.pl
@@ -0,0 +1,79 @@
1#!/usr/local/bin/perl
2
3$L="edi";
4$R="esi";
5
6sub DES_encrypt3
7 {
8 local($name,$enc)=@_;
9
10 &function_begin_B($name,"");
11 &push("ebx");
12 &mov("ebx",&wparam(0));
13
14 &push("ebp");
15 &push("esi");
16
17 &push("edi");
18
19 &comment("");
20 &comment("Load the data words");
21 &mov($L,&DWP(0,"ebx","",0));
22 &mov($R,&DWP(4,"ebx","",0));
23 &stack_push(3);
24
25 &comment("");
26 &comment("IP");
27 &IP_new($L,$R,"edx",0);
28
29 # put them back
30
31 if ($enc)
32 {
33 &mov(&DWP(4,"ebx","",0),$R);
34 &mov("eax",&wparam(1));
35 &mov(&DWP(0,"ebx","",0),"edx");
36 &mov("edi",&wparam(2));
37 &mov("esi",&wparam(3));
38 }
39 else
40 {
41 &mov(&DWP(4,"ebx","",0),$R);
42 &mov("esi",&wparam(1));
43 &mov(&DWP(0,"ebx","",0),"edx");
44 &mov("edi",&wparam(2));
45 &mov("eax",&wparam(3));
46 }
47 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx");
50 &call("DES_encrypt2");
51 &mov(&swtmp(2), (DWC(($enc)?"0":"1")));
52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx");
54 &call("DES_encrypt2");
55 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
56 &mov(&swtmp(1), "esi");
57 &mov(&swtmp(0), "ebx");
58 &call("DES_encrypt2");
59
60 &stack_pop(3);
61 &mov($L,&DWP(0,"ebx","",0));
62 &mov($R,&DWP(4,"ebx","",0));
63
64 &comment("");
65 &comment("FP");
66 &FP_new($L,$R,"eax",0);
67
68 &mov(&DWP(0,"ebx","",0),"eax");
69 &mov(&DWP(4,"ebx","",0),$R);
70
71 &pop("edi");
72 &pop("esi");
73 &pop("ebp");
74 &pop("ebx");
75 &ret();
76 &function_end_B($name);
77 }
78
79
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
new file mode 100644
index 0000000000..09a7ba56aa
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc_cksm.c
@@ -0,0 +1,106 @@
1/* crypto/des/cbc_cksm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output,
62 long length, DES_key_schedule *schedule,
63 const_DES_cblock *ivec)
64 {
65 register DES_LONG tout0,tout1,tin0,tin1;
66 register long l=length;
67 DES_LONG tin[2];
68 unsigned char *out = &(*output)[0];
69 const unsigned char *iv = &(*ivec)[0];
70
71 c2l(iv,tout0);
72 c2l(iv,tout1);
73 for (; l>0; l-=8)
74 {
75 if (l >= 8)
76 {
77 c2l(in,tin0);
78 c2l(in,tin1);
79 }
80 else
81 c2ln(in,tin0,tin1,l);
82
83 tin0^=tout0; tin[0]=tin0;
84 tin1^=tout1; tin[1]=tin1;
85 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
86 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
87 tout0=tin[0];
88 tout1=tin[1];
89 }
90 if (out != NULL)
91 {
92 l2c(tout0,out);
93 l2c(tout1,out);
94 }
95 tout0=tin0=tin1=tin[0]=tin[1]=0;
96 /*
97 Transform the data in tout1 so that it will
98 match the return value that the MIT Kerberos
99 mit_des_cbc_cksum API returns.
100 */
101 tout1 = ((tout1 >> 24L) & 0x000000FF)
102 | ((tout1 >> 8L) & 0x0000FF00)
103 | ((tout1 << 8L) & 0x00FF0000)
104 | ((tout1 << 24L) & 0xFF000000);
105 return(tout1);
106 }
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
new file mode 100644
index 0000000000..677903ae4e
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc_enc.c
@@ -0,0 +1,61 @@
1/* crypto/des/cbc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#define CBC_ENC_C__DONT_UPDATE_IV
60
61#include "ncbc_enc.c" /* des_cbc_encrypt */
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
new file mode 100644
index 0000000000..f3c6018528
--- /dev/null
+++ b/src/lib/libcrypto/des/cfb64ede.c
@@ -0,0 +1,254 @@
1/* crypto/des/cfb64ede.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60#include "e_os.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 long length, DES_key_schedule *ks1,
69 DES_key_schedule *ks2, DES_key_schedule *ks3,
70 DES_cblock *ivec, int *num, int enc)
71 {
72 register DES_LONG v0,v1;
73 register long l=length;
74 register int n= *num;
75 DES_LONG ti[2];
76 unsigned char *iv,c,cc;
77
78 iv=&(*ivec)[0];
79 if (enc)
80 {
81 while (l--)
82 {
83 if (n == 0)
84 {
85 c2l(iv,v0);
86 c2l(iv,v1);
87
88 ti[0]=v0;
89 ti[1]=v1;
90 DES_encrypt3(ti,ks1,ks2,ks3);
91 v0=ti[0];
92 v1=ti[1];
93
94 iv = &(*ivec)[0];
95 l2c(v0,iv);
96 l2c(v1,iv);
97 iv = &(*ivec)[0];
98 }
99 c= *(in++)^iv[n];
100 *(out++)=c;
101 iv[n]=c;
102 n=(n+1)&0x07;
103 }
104 }
105 else
106 {
107 while (l--)
108 {
109 if (n == 0)
110 {
111 c2l(iv,v0);
112 c2l(iv,v1);
113
114 ti[0]=v0;
115 ti[1]=v1;
116 DES_encrypt3(ti,ks1,ks2,ks3);
117 v0=ti[0];
118 v1=ti[1];
119
120 iv = &(*ivec)[0];
121 l2c(v0,iv);
122 l2c(v1,iv);
123 iv = &(*ivec)[0];
124 }
125 cc= *(in++);
126 c=iv[n];
127 iv[n]=cc;
128 *(out++)=c^cc;
129 n=(n+1)&0x07;
130 }
131 }
132 v0=v1=ti[0]=ti[1]=c=cc=0;
133 *num=n;
134 }
135
136#ifdef undef /* MACRO */
137void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
138 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec),
139 int *num, int enc)
140 {
141 DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
142 }
143#endif
144
145/* This is compatible with the single key CFB-r for DES, even thought that's
146 * not what EVP needs.
147 */
148
149void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
150 int numbits,long length,DES_key_schedule *ks1,
151 DES_key_schedule *ks2,DES_key_schedule *ks3,
152 DES_cblock *ivec,int enc)
153 {
154 register DES_LONG d0,d1,v0,v1;
155 register long l=length;
156 register int num=numbits,n=(numbits+7)/8,i;
157 DES_LONG ti[2];
158 unsigned char *iv;
159 unsigned char ovec[16];
160
161 if (num > 64) return;
162 iv = &(*ivec)[0];
163 c2l(iv,v0);
164 c2l(iv,v1);
165 if (enc)
166 {
167 while (l >= n)
168 {
169 l-=n;
170 ti[0]=v0;
171 ti[1]=v1;
172 DES_encrypt3(ti,ks1,ks2,ks3);
173 c2ln(in,d0,d1,n);
174 in+=n;
175 d0^=ti[0];
176 d1^=ti[1];
177 l2cn(d0,d1,out,n);
178 out+=n;
179 /* 30-08-94 - eay - changed because l>>32 and
180 * l<<32 are bad under gcc :-( */
181 if (num == 32)
182 { v0=v1; v1=d0; }
183 else if (num == 64)
184 { v0=d0; v1=d1; }
185 else
186 {
187 iv=&ovec[0];
188 l2c(v0,iv);
189 l2c(v1,iv);
190 l2c(d0,iv);
191 l2c(d1,iv);
192 /* shift ovec left most of the bits... */
193 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
194 /* now the remaining bits */
195 if(num%8 != 0)
196 for(i=0 ; i < 8 ; ++i)
197 {
198 ovec[i]<<=num%8;
199 ovec[i]|=ovec[i+1]>>(8-num%8);
200 }
201 iv=&ovec[0];
202 c2l(iv,v0);
203 c2l(iv,v1);
204 }
205 }
206 }
207 else
208 {
209 while (l >= n)
210 {
211 l-=n;
212 ti[0]=v0;
213 ti[1]=v1;
214 DES_encrypt3(ti,ks1,ks2,ks3);
215 c2ln(in,d0,d1,n);
216 in+=n;
217 /* 30-08-94 - eay - changed because l>>32 and
218 * l<<32 are bad under gcc :-( */
219 if (num == 32)
220 { v0=v1; v1=d0; }
221 else if (num == 64)
222 { v0=d0; v1=d1; }
223 else
224 {
225 iv=&ovec[0];
226 l2c(v0,iv);
227 l2c(v1,iv);
228 l2c(d0,iv);
229 l2c(d1,iv);
230 /* shift ovec left most of the bits... */
231 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
232 /* now the remaining bits */
233 if(num%8 != 0)
234 for(i=0 ; i < 8 ; ++i)
235 {
236 ovec[i]<<=num%8;
237 ovec[i]|=ovec[i+1]>>(8-num%8);
238 }
239 iv=&ovec[0];
240 c2l(iv,v0);
241 c2l(iv,v1);
242 }
243 d0^=ti[0];
244 d1^=ti[1];
245 l2cn(d0,d1,out,n);
246 out+=n;
247 }
248 }
249 iv = &(*ivec)[0];
250 l2c(v0,iv);
251 l2c(v1,iv);
252 v0=v1=d0=d1=ti[0]=ti[1]=0;
253 }
254
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
new file mode 100644
index 0000000000..5ec8683e40
--- /dev/null
+++ b/src/lib/libcrypto/des/cfb64enc.c
@@ -0,0 +1,121 @@
1/* crypto/des/cfb64enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output encrypted as though 64bit cfb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65
66void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67 long length, DES_key_schedule *schedule,
68 DES_cblock *ivec, int *num, int enc)
69 {
70 register DES_LONG v0,v1;
71 register long l=length;
72 register int n= *num;
73 DES_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv = &(*ivec)[0];
77 if (enc)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 c2l(iv,v0); ti[0]=v0;
84 c2l(iv,v1); ti[1]=v1;
85 DES_encrypt1(ti,schedule,DES_ENCRYPT);
86 iv = &(*ivec)[0];
87 v0=ti[0]; l2c(v0,iv);
88 v0=ti[1]; l2c(v0,iv);
89 iv = &(*ivec)[0];
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 c2l(iv,v0); ti[0]=v0;
104 c2l(iv,v1); ti[1]=v1;
105 DES_encrypt1(ti,schedule,DES_ENCRYPT);
106 iv = &(*ivec)[0];
107 v0=ti[0]; l2c(v0,iv);
108 v0=ti[1]; l2c(v0,iv);
109 iv = &(*ivec)[0];
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
new file mode 100644
index 0000000000..03cabb223c
--- /dev/null
+++ b/src/lib/libcrypto/des/cfb_enc.c
@@ -0,0 +1,174 @@
1/* crypto/des/cfb_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "e_os.h"
60#include "des_locl.h"
61
62/* The input and output are loaded in multiples of 8 bits.
63 * What this means is that if you hame numbits=12 and length=2
64 * the first 12 bits will be retrieved from the first byte and half
65 * the second. The second 12 bits will come from the 3rd and half the 4th
66 * byte.
67 */
68/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it
69 * will not be compatible with any encryption prior to that date. Ben. */
70void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
71 long length, DES_key_schedule *schedule, DES_cblock *ivec,
72 int enc)
73 {
74 register DES_LONG d0,d1,v0,v1;
75 register unsigned long l=length,n=(numbits+7)/8;
76 register int num=numbits,i;
77 DES_LONG ti[2];
78 unsigned char *iv;
79 unsigned char ovec[16];
80
81 if (num > 64) return;
82 iv = &(*ivec)[0];
83 c2l(iv,v0);
84 c2l(iv,v1);
85 if (enc)
86 {
87 while (l >= n)
88 {
89 l-=n;
90 ti[0]=v0;
91 ti[1]=v1;
92 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
93 c2ln(in,d0,d1,n);
94 in+=n;
95 d0^=ti[0];
96 d1^=ti[1];
97 l2cn(d0,d1,out,n);
98 out+=n;
99 /* 30-08-94 - eay - changed because l>>32 and
100 * l<<32 are bad under gcc :-( */
101 if (num == 32)
102 { v0=v1; v1=d0; }
103 else if (num == 64)
104 { v0=d0; v1=d1; }
105 else
106 {
107 iv=&ovec[0];
108 l2c(v0,iv);
109 l2c(v1,iv);
110 l2c(d0,iv);
111 l2c(d1,iv);
112 /* shift ovec left most of the bits... */
113 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
114 /* now the remaining bits */
115 if(num%8 != 0)
116 for(i=0 ; i < 8 ; ++i)
117 {
118 ovec[i]<<=num%8;
119 ovec[i]|=ovec[i+1]>>(8-num%8);
120 }
121 iv=&ovec[0];
122 c2l(iv,v0);
123 c2l(iv,v1);
124 }
125 }
126 }
127 else
128 {
129 while (l >= n)
130 {
131 l-=n;
132 ti[0]=v0;
133 ti[1]=v1;
134 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
135 c2ln(in,d0,d1,n);
136 in+=n;
137 /* 30-08-94 - eay - changed because l>>32 and
138 * l<<32 are bad under gcc :-( */
139 if (num == 32)
140 { v0=v1; v1=d0; }
141 else if (num == 64)
142 { v0=d0; v1=d1; }
143 else
144 {
145 iv=&ovec[0];
146 l2c(v0,iv);
147 l2c(v1,iv);
148 l2c(d0,iv);
149 l2c(d1,iv);
150 /* shift ovec left most of the bits... */
151 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
152 /* now the remaining bits */
153 if(num%8 != 0)
154 for(i=0 ; i < 8 ; ++i)
155 {
156 ovec[i]<<=num%8;
157 ovec[i]|=ovec[i+1]>>(8-num%8);
158 }
159 iv=&ovec[0];
160 c2l(iv,v0);
161 c2l(iv,v1);
162 }
163 d0^=ti[0];
164 d1^=ti[1];
165 l2cn(d0,d1,out,n);
166 out+=n;
167 }
168 }
169 iv = &(*ivec)[0];
170 l2c(v0,iv);
171 l2c(v1,iv);
172 v0=v1=d0=d1=ti[0]=ti[1]=0;
173 }
174
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
new file mode 100644
index 0000000000..81bd874edd
--- /dev/null
+++ b/src/lib/libcrypto/des/des.h
@@ -0,0 +1,246 @@
1/* crypto/des/des.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_H
60#define HEADER_DES_H
61
62#ifdef OPENSSL_NO_DES
63#error DES is disabled.
64#endif
65
66#include <openssl/opensslconf.h> /* DES_LONG */
67#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
68
69#ifdef OPENSSL_BUILD_SHLIBCRYPTO
70# undef OPENSSL_EXTERN
71# define OPENSSL_EXTERN OPENSSL_EXPORT
72#endif
73
74#define des_SPtrans DES_SPtrans
75
76#ifdef __cplusplus
77extern "C" {
78#endif
79
80typedef unsigned char DES_cblock[8];
81typedef /* const */ unsigned char const_DES_cblock[8];
82/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
83 * and const_DES_cblock * are incompatible pointer types. */
84
85typedef struct DES_ks
86 {
87 union
88 {
89 DES_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks[16];
94 } DES_key_schedule;
95
96#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
97# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
98# define OPENSSL_ENABLE_OLD_DES_SUPPORT
99# endif
100#endif
101
102#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
103# include <openssl/des_old.h>
104#endif
105
106#define DES_KEY_SZ (sizeof(DES_cblock))
107#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
108
109#define DES_ENCRYPT 1
110#define DES_DECRYPT 0
111
112#define DES_CBC_MODE 0
113#define DES_PCBC_MODE 1
114
115#define DES_ecb2_encrypt(i,o,k1,k2,e) \
116 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
117
118#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
119 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
120
121#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
122 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
123
124#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
125 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
126
127OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
128#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
129OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
130#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
131
132const char *DES_options(void);
133void DES_ecb3_encrypt(const unsigned char *input, unsigned char *output,
134 DES_key_schedule *ks1,DES_key_schedule *ks2,
135 DES_key_schedule *ks3, int enc);
136DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
137 long length,DES_key_schedule *schedule,
138 const_DES_cblock *ivec);
139/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
140void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
141 long length,DES_key_schedule *schedule,DES_cblock *ivec,
142 int enc);
143void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
144 long length,DES_key_schedule *schedule,DES_cblock *ivec,
145 int enc);
146void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
147 long length,DES_key_schedule *schedule,DES_cblock *ivec,
148 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
149void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
150 long length,DES_key_schedule *schedule,DES_cblock *ivec,
151 int enc);
152void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
153 DES_key_schedule *ks,int enc);
154
155/* This is the DES encryption function that gets called by just about
156 every other DES routine in the library. You should not use this
157 function except to implement 'modes' of DES. I say this because the
158 functions that call this routine do the conversion from 'char *' to
159 long, and this needs to be done to make sure 'non-aligned' memory
160 access do not occur. The characters are loaded 'little endian'.
161 Data is a pointer to 2 unsigned long's and ks is the
162 DES_key_schedule to use. enc, is non zero specifies encryption,
163 zero if decryption. */
164void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
165
166/* This functions is the same as DES_encrypt1() except that the DES
167 initial permutation (IP) and final permutation (FP) have been left
168 out. As for DES_encrypt1(), you should not use this function.
169 It is used by the routines in the library that implement triple DES.
170 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
171 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
172void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
173
174void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
175 DES_key_schedule *ks2, DES_key_schedule *ks3);
176void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
177 DES_key_schedule *ks2, DES_key_schedule *ks3);
178void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
179 long length,
180 DES_key_schedule *ks1,DES_key_schedule *ks2,
181 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
182void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
183 long length,
184 DES_key_schedule *ks1,DES_key_schedule *ks2,
185 DES_key_schedule *ks3,
186 DES_cblock *ivec1,DES_cblock *ivec2,
187 int enc);
188void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
189 long length,DES_key_schedule *ks1,
190 DES_key_schedule *ks2,DES_key_schedule *ks3,
191 DES_cblock *ivec,int *num,int enc);
192void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
193 int numbits,long length,DES_key_schedule *ks1,
194 DES_key_schedule *ks2,DES_key_schedule *ks3,
195 DES_cblock *ivec,int enc);
196void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
197 long length,DES_key_schedule *ks1,
198 DES_key_schedule *ks2,DES_key_schedule *ks3,
199 DES_cblock *ivec,int *num);
200
201void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
202 DES_cblock *out_white);
203
204int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
205 DES_cblock *iv);
206int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
207 DES_cblock *iv);
208char *DES_fcrypt(const char *buf,const char *salt, char *ret);
209char *DES_crypt(const char *buf,const char *salt);
210void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
211 long length,DES_key_schedule *schedule,DES_cblock *ivec);
212void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
213 long length,DES_key_schedule *schedule,DES_cblock *ivec,
214 int enc);
215DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
216 long length,int out_count,DES_cblock *seed);
217int DES_random_key(DES_cblock *ret);
218void DES_set_odd_parity(DES_cblock *key);
219int DES_check_key_parity(const_DES_cblock *key);
220int DES_is_weak_key(const_DES_cblock *key);
221/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
222 * DES_set_key_checked if global variable DES_check_key is set,
223 * DES_set_key_unchecked otherwise. */
224int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
225int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
226int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
227void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
228void DES_string_to_key(const char *str,DES_cblock *key);
229void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
230void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
231 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
232 int enc);
233void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
234 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
235
236int DES_read_password(DES_cblock *key, const char *prompt, int verify);
237int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
238 int verify);
239
240#define DES_fixup_key_parity DES_set_odd_parity
241
242#ifdef __cplusplus
243}
244#endif
245
246#endif
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
new file mode 100644
index 0000000000..6a49ec4a55
--- /dev/null
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -0,0 +1,417 @@
1/* crypto/des/des_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61#ifndef OPENSSL_FIPS
62#ifndef OPENBSD_DES_ASM
63
64void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
65 {
66 register DES_LONG l,r,t,u;
67#ifdef DES_PTR
68 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
69#endif
70#ifndef DES_UNROLL
71 register int i;
72#endif
73 register DES_LONG *s;
74
75 r=data[0];
76 l=data[1];
77
78 IP(r,l);
79 /* Things have been modified so that the initial rotate is
80 * done outside the loop. This required the
81 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
82 * One perl script later and things have a 5% speed up on a sparc2.
83 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
84 * for pointing this out. */
85 /* clear the top bits on machines with 8byte longs */
86 /* shift left by 2 */
87 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL;
89
90 s=ks->ks->deslong;
91 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */
93 if (enc)
94 {
95#ifdef DES_UNROLL
96 D_ENCRYPT(l,r, 0); /* 1 */
97 D_ENCRYPT(r,l, 2); /* 2 */
98 D_ENCRYPT(l,r, 4); /* 3 */
99 D_ENCRYPT(r,l, 6); /* 4 */
100 D_ENCRYPT(l,r, 8); /* 5 */
101 D_ENCRYPT(r,l,10); /* 6 */
102 D_ENCRYPT(l,r,12); /* 7 */
103 D_ENCRYPT(r,l,14); /* 8 */
104 D_ENCRYPT(l,r,16); /* 9 */
105 D_ENCRYPT(r,l,18); /* 10 */
106 D_ENCRYPT(l,r,20); /* 11 */
107 D_ENCRYPT(r,l,22); /* 12 */
108 D_ENCRYPT(l,r,24); /* 13 */
109 D_ENCRYPT(r,l,26); /* 14 */
110 D_ENCRYPT(l,r,28); /* 15 */
111 D_ENCRYPT(r,l,30); /* 16 */
112#else
113 for (i=0; i<32; i+=8)
114 {
115 D_ENCRYPT(l,r,i+0); /* 1 */
116 D_ENCRYPT(r,l,i+2); /* 2 */
117 D_ENCRYPT(l,r,i+4); /* 3 */
118 D_ENCRYPT(r,l,i+6); /* 4 */
119 }
120#endif
121 }
122 else
123 {
124#ifdef DES_UNROLL
125 D_ENCRYPT(l,r,30); /* 16 */
126 D_ENCRYPT(r,l,28); /* 15 */
127 D_ENCRYPT(l,r,26); /* 14 */
128 D_ENCRYPT(r,l,24); /* 13 */
129 D_ENCRYPT(l,r,22); /* 12 */
130 D_ENCRYPT(r,l,20); /* 11 */
131 D_ENCRYPT(l,r,18); /* 10 */
132 D_ENCRYPT(r,l,16); /* 9 */
133 D_ENCRYPT(l,r,14); /* 8 */
134 D_ENCRYPT(r,l,12); /* 7 */
135 D_ENCRYPT(l,r,10); /* 6 */
136 D_ENCRYPT(r,l, 8); /* 5 */
137 D_ENCRYPT(l,r, 6); /* 4 */
138 D_ENCRYPT(r,l, 4); /* 3 */
139 D_ENCRYPT(l,r, 2); /* 2 */
140 D_ENCRYPT(r,l, 0); /* 1 */
141#else
142 for (i=30; i>0; i-=8)
143 {
144 D_ENCRYPT(l,r,i-0); /* 16 */
145 D_ENCRYPT(r,l,i-2); /* 15 */
146 D_ENCRYPT(l,r,i-4); /* 14 */
147 D_ENCRYPT(r,l,i-6); /* 13 */
148 }
149#endif
150 }
151
152 /* rotate and clear the top bits on machines with 8byte longs */
153 l=ROTATE(l,3)&0xffffffffL;
154 r=ROTATE(r,3)&0xffffffffL;
155
156 FP(r,l);
157 data[0]=l;
158 data[1]=r;
159 l=r=t=u=0;
160 }
161
162void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
163 {
164 register DES_LONG l,r,t,u;
165#ifdef DES_PTR
166 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
167#endif
168#ifndef DES_UNROLL
169 register int i;
170#endif
171 register DES_LONG *s;
172
173 r=data[0];
174 l=data[1];
175
176 /* Things have been modified so that the initial rotate is
177 * done outside the loop. This required the
178 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
179 * One perl script later and things have a 5% speed up on a sparc2.
180 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
181 * for pointing this out. */
182 /* clear the top bits on machines with 8byte longs */
183 r=ROTATE(r,29)&0xffffffffL;
184 l=ROTATE(l,29)&0xffffffffL;
185
186 s=ks->ks->deslong;
187 /* I don't know if it is worth the effort of loop unrolling the
188 * inner loop */
189 if (enc)
190 {
191#ifdef DES_UNROLL
192 D_ENCRYPT(l,r, 0); /* 1 */
193 D_ENCRYPT(r,l, 2); /* 2 */
194 D_ENCRYPT(l,r, 4); /* 3 */
195 D_ENCRYPT(r,l, 6); /* 4 */
196 D_ENCRYPT(l,r, 8); /* 5 */
197 D_ENCRYPT(r,l,10); /* 6 */
198 D_ENCRYPT(l,r,12); /* 7 */
199 D_ENCRYPT(r,l,14); /* 8 */
200 D_ENCRYPT(l,r,16); /* 9 */
201 D_ENCRYPT(r,l,18); /* 10 */
202 D_ENCRYPT(l,r,20); /* 11 */
203 D_ENCRYPT(r,l,22); /* 12 */
204 D_ENCRYPT(l,r,24); /* 13 */
205 D_ENCRYPT(r,l,26); /* 14 */
206 D_ENCRYPT(l,r,28); /* 15 */
207 D_ENCRYPT(r,l,30); /* 16 */
208#else
209 for (i=0; i<32; i+=8)
210 {
211 D_ENCRYPT(l,r,i+0); /* 1 */
212 D_ENCRYPT(r,l,i+2); /* 2 */
213 D_ENCRYPT(l,r,i+4); /* 3 */
214 D_ENCRYPT(r,l,i+6); /* 4 */
215 }
216#endif
217 }
218 else
219 {
220#ifdef DES_UNROLL
221 D_ENCRYPT(l,r,30); /* 16 */
222 D_ENCRYPT(r,l,28); /* 15 */
223 D_ENCRYPT(l,r,26); /* 14 */
224 D_ENCRYPT(r,l,24); /* 13 */
225 D_ENCRYPT(l,r,22); /* 12 */
226 D_ENCRYPT(r,l,20); /* 11 */
227 D_ENCRYPT(l,r,18); /* 10 */
228 D_ENCRYPT(r,l,16); /* 9 */
229 D_ENCRYPT(l,r,14); /* 8 */
230 D_ENCRYPT(r,l,12); /* 7 */
231 D_ENCRYPT(l,r,10); /* 6 */
232 D_ENCRYPT(r,l, 8); /* 5 */
233 D_ENCRYPT(l,r, 6); /* 4 */
234 D_ENCRYPT(r,l, 4); /* 3 */
235 D_ENCRYPT(l,r, 2); /* 2 */
236 D_ENCRYPT(r,l, 0); /* 1 */
237#else
238 for (i=30; i>0; i-=8)
239 {
240 D_ENCRYPT(l,r,i-0); /* 16 */
241 D_ENCRYPT(r,l,i-2); /* 15 */
242 D_ENCRYPT(l,r,i-4); /* 14 */
243 D_ENCRYPT(r,l,i-6); /* 13 */
244 }
245#endif
246 }
247 /* rotate and clear the top bits on machines with 8byte longs */
248 data[0]=ROTATE(l,3)&0xffffffffL;
249 data[1]=ROTATE(r,3)&0xffffffffL;
250 l=r=t=u=0;
251 }
252#endif
253
254void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
255 DES_key_schedule *ks2, DES_key_schedule *ks3)
256 {
257 register DES_LONG l,r;
258
259 l=data[0];
260 r=data[1];
261 IP(l,r);
262 data[0]=l;
263 data[1]=r;
264 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
265 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
266 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
267 l=data[0];
268 r=data[1];
269 FP(r,l);
270 data[0]=l;
271 data[1]=r;
272 }
273
274void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
275 DES_key_schedule *ks2, DES_key_schedule *ks3)
276 {
277 register DES_LONG l,r;
278
279 l=data[0];
280 r=data[1];
281 IP(l,r);
282 data[0]=l;
283 data[1]=r;
284 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
285 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
286 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
287 l=data[0];
288 r=data[1];
289 FP(r,l);
290 data[0]=l;
291 data[1]=r;
292 }
293
294#endif /* ndef OPENSSL_FIPS */
295
296#ifndef DES_DEFAULT_OPTIONS
297
298#if !defined(OPENSSL_FIPS_DES_ASM)
299
300#undef CBC_ENC_C__DONT_UPDATE_IV
301#include "ncbc_enc.c" /* DES_ncbc_encrypt */
302
303void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
304 long length, DES_key_schedule *ks1,
305 DES_key_schedule *ks2, DES_key_schedule *ks3,
306 DES_cblock *ivec, int enc)
307 {
308 register DES_LONG tin0,tin1;
309 register DES_LONG tout0,tout1,xor0,xor1;
310 register const unsigned char *in;
311 unsigned char *out;
312 register long l=length;
313 DES_LONG tin[2];
314 unsigned char *iv;
315
316 in=input;
317 out=output;
318 iv = &(*ivec)[0];
319
320 if (enc)
321 {
322 c2l(iv,tout0);
323 c2l(iv,tout1);
324 for (l-=8; l>=0; l-=8)
325 {
326 c2l(in,tin0);
327 c2l(in,tin1);
328 tin0^=tout0;
329 tin1^=tout1;
330
331 tin[0]=tin0;
332 tin[1]=tin1;
333 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
334 tout0=tin[0];
335 tout1=tin[1];
336
337 l2c(tout0,out);
338 l2c(tout1,out);
339 }
340 if (l != -8)
341 {
342 c2ln(in,tin0,tin1,l+8);
343 tin0^=tout0;
344 tin1^=tout1;
345
346 tin[0]=tin0;
347 tin[1]=tin1;
348 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
349 tout0=tin[0];
350 tout1=tin[1];
351
352 l2c(tout0,out);
353 l2c(tout1,out);
354 }
355 iv = &(*ivec)[0];
356 l2c(tout0,iv);
357 l2c(tout1,iv);
358 }
359 else
360 {
361 register DES_LONG t0,t1;
362
363 c2l(iv,xor0);
364 c2l(iv,xor1);
365 for (l-=8; l>=0; l-=8)
366 {
367 c2l(in,tin0);
368 c2l(in,tin1);
369
370 t0=tin0;
371 t1=tin1;
372
373 tin[0]=tin0;
374 tin[1]=tin1;
375 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
376 tout0=tin[0];
377 tout1=tin[1];
378
379 tout0^=xor0;
380 tout1^=xor1;
381 l2c(tout0,out);
382 l2c(tout1,out);
383 xor0=t0;
384 xor1=t1;
385 }
386 if (l != -8)
387 {
388 c2l(in,tin0);
389 c2l(in,tin1);
390
391 t0=tin0;
392 t1=tin1;
393
394 tin[0]=tin0;
395 tin[1]=tin1;
396 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
397 tout0=tin[0];
398 tout1=tin[1];
399
400 tout0^=xor0;
401 tout1^=xor1;
402 l2cn(tout0,tout1,out,l+8);
403 xor0=t0;
404 xor1=t1;
405 }
406
407 iv = &(*ivec)[0];
408 l2c(xor0,iv);
409 l2c(xor1,iv);
410 }
411 tin0=tin1=tout0=tout1=xor0=xor1=0;
412 tin[0]=tin[1]=0;
413 }
414
415#endif /* !defined(OPENSSL_FIPS_DES_ASM) */
416
417#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
new file mode 100644
index 0000000000..e44e8e98b2
--- /dev/null
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -0,0 +1,428 @@
1/* crypto/des/des_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H
61
62#include <openssl/e_os2.h>
63
64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS
67#endif
68#endif
69
70#include <stdio.h>
71#include <stdlib.h>
72
73#ifndef OPENSSL_SYS_MSDOS
74#if !defined(OPENSSL_SYS_VMS) || defined(__DECC)
75#ifdef OPENSSL_UNISTD
76# include OPENSSL_UNISTD
77#else
78# include <unistd.h>
79#endif
80#include <math.h>
81#endif
82#endif
83#include <openssl/des.h>
84
85#ifdef OPENSSL_SYS_MSDOS /* Visual C++ 2.1 (Windows NT/95) */
86#include <stdlib.h>
87#include <errno.h>
88#include <time.h>
89#include <io.h>
90#endif
91
92#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
93#include <string.h>
94#endif
95
96#ifdef OPENSSL_BUILD_SHLIBCRYPTO
97# undef OPENSSL_EXTERN
98# define OPENSSL_EXTERN OPENSSL_EXPORT
99#endif
100
101#define ITERATIONS 16
102#define HALF_ITERATIONS 8
103
104/* used in des_read and des_write */
105#define MAXWRITE (1024*16)
106#define BSIZE (MAXWRITE+4)
107
108#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
109 l|=((DES_LONG)(*((c)++)))<< 8L, \
110 l|=((DES_LONG)(*((c)++)))<<16L, \
111 l|=((DES_LONG)(*((c)++)))<<24L)
112
113/* NOTE - c is not incremented as per c2l */
114#define c2ln(c,l1,l2,n) { \
115 c+=n; \
116 l1=l2=0; \
117 switch (n) { \
118 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
119 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
120 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
121 case 5: l2|=((DES_LONG)(*(--(c)))); \
122 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
123 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
124 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
125 case 1: l1|=((DES_LONG)(*(--(c)))); \
126 } \
127 }
128
129#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
130 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
131 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
132 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
133
134/* replacements for htonl and ntohl since I have no idea what to do
135 * when faced with machines with 8 byte longs. */
136#define HDRSIZE 4
137
138#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
139 l|=((DES_LONG)(*((c)++)))<<16L, \
140 l|=((DES_LONG)(*((c)++)))<< 8L, \
141 l|=((DES_LONG)(*((c)++))))
142
143#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
144 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
145 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
146 *((c)++)=(unsigned char)(((l) )&0xff))
147
148/* NOTE - c is not incremented as per l2c */
149#define l2cn(l1,l2,c,n) { \
150 c+=n; \
151 switch (n) { \
152 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
153 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
154 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
155 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
156 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
157 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
158 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
159 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
160 } \
161 }
162
163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
164#define ROTATE(a,n) (_lrotr(a,n))
165#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
166# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
167# define ROTATE(a,n) ({ register unsigned int ret; \
168 asm ("rorl %1,%0" \
169 : "=r"(ret) \
170 : "I"(n),"0"(a) \
171 : "cc"); \
172 ret; \
173 })
174# endif
175#endif
176#ifndef ROTATE
177#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
178#endif
179
180/* Don't worry about the LOAD_DATA() stuff, that is used by
181 * fcrypt() to add it's little bit to the front */
182
183#ifdef DES_FCRYPT
184
185#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
186 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
187
188#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
189 t=R^(R>>16L); \
190 u=t&E0; t&=E1; \
191 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
192 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
193#else
194#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
195#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
196 u=R^s[S ]; \
197 t=R^s[S+1]
198#endif
199
200/* The changes to this macro may help or hinder, depending on the
201 * compiler and the architecture. gcc2 always seems to do well :-).
202 * Inspired by Dana How <how@isl.stanford.edu>
203 * DO NOT use the alternative version on machines with 8 byte longs.
204 * It does not seem to work on the Alpha, even when DES_LONG is 4
205 * bytes, probably an issue of accessing non-word aligned objects :-( */
206#ifdef DES_PTR
207
208/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
209 * is no reason to not xor all the sub items together. This potentially
210 * saves a register since things can be xored directly into L */
211
212#if defined(DES_RISC1) || defined(DES_RISC2)
213#ifdef DES_RISC1
214#define D_ENCRYPT(LL,R,S) { \
215 unsigned int u1,u2,u3; \
216 LOAD_DATA(R,S,u,t,E0,E1,u1); \
217 u2=(int)u>>8L; \
218 u1=(int)u&0xfc; \
219 u2&=0xfc; \
220 t=ROTATE(t,4); \
221 u>>=16L; \
222 LL^= *(const DES_LONG *)(des_SP +u1); \
223 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
224 u3=(int)(u>>8L); \
225 u1=(int)u&0xfc; \
226 u3&=0xfc; \
227 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
228 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
229 u2=(int)t>>8L; \
230 u1=(int)t&0xfc; \
231 u2&=0xfc; \
232 t>>=16L; \
233 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
234 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
235 u3=(int)t>>8L; \
236 u1=(int)t&0xfc; \
237 u3&=0xfc; \
238 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
239 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
240#endif
241#ifdef DES_RISC2
242#define D_ENCRYPT(LL,R,S) { \
243 unsigned int u1,u2,s1,s2; \
244 LOAD_DATA(R,S,u,t,E0,E1,u1); \
245 u2=(int)u>>8L; \
246 u1=(int)u&0xfc; \
247 u2&=0xfc; \
248 t=ROTATE(t,4); \
249 LL^= *(const DES_LONG *)(des_SP +u1); \
250 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
251 s1=(int)(u>>16L); \
252 s2=(int)(u>>24L); \
253 s1&=0xfc; \
254 s2&=0xfc; \
255 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
256 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
257 u2=(int)t>>8L; \
258 u1=(int)t&0xfc; \
259 u2&=0xfc; \
260 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
261 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
262 s1=(int)(t>>16L); \
263 s2=(int)(t>>24L); \
264 s1&=0xfc; \
265 s2&=0xfc; \
266 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
267 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
268#endif
269#else
270#define D_ENCRYPT(LL,R,S) { \
271 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
272 t=ROTATE(t,4); \
273 LL^= \
274 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
275 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
276 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
277 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
278 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
279 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
280 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
281 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
282#endif
283
284#else /* original version */
285
286#if defined(DES_RISC1) || defined(DES_RISC2)
287#ifdef DES_RISC1
288#define D_ENCRYPT(LL,R,S) {\
289 unsigned int u1,u2,u3; \
290 LOAD_DATA(R,S,u,t,E0,E1,u1); \
291 u>>=2L; \
292 t=ROTATE(t,6); \
293 u2=(int)u>>8L; \
294 u1=(int)u&0x3f; \
295 u2&=0x3f; \
296 u>>=16L; \
297 LL^=DES_SPtrans[0][u1]; \
298 LL^=DES_SPtrans[2][u2]; \
299 u3=(int)u>>8L; \
300 u1=(int)u&0x3f; \
301 u3&=0x3f; \
302 LL^=DES_SPtrans[4][u1]; \
303 LL^=DES_SPtrans[6][u3]; \
304 u2=(int)t>>8L; \
305 u1=(int)t&0x3f; \
306 u2&=0x3f; \
307 t>>=16L; \
308 LL^=DES_SPtrans[1][u1]; \
309 LL^=DES_SPtrans[3][u2]; \
310 u3=(int)t>>8L; \
311 u1=(int)t&0x3f; \
312 u3&=0x3f; \
313 LL^=DES_SPtrans[5][u1]; \
314 LL^=DES_SPtrans[7][u3]; }
315#endif
316#ifdef DES_RISC2
317#define D_ENCRYPT(LL,R,S) {\
318 unsigned int u1,u2,s1,s2; \
319 LOAD_DATA(R,S,u,t,E0,E1,u1); \
320 u>>=2L; \
321 t=ROTATE(t,6); \
322 u2=(int)u>>8L; \
323 u1=(int)u&0x3f; \
324 u2&=0x3f; \
325 LL^=DES_SPtrans[0][u1]; \
326 LL^=DES_SPtrans[2][u2]; \
327 s1=(int)u>>16L; \
328 s2=(int)u>>24L; \
329 s1&=0x3f; \
330 s2&=0x3f; \
331 LL^=DES_SPtrans[4][s1]; \
332 LL^=DES_SPtrans[6][s2]; \
333 u2=(int)t>>8L; \
334 u1=(int)t&0x3f; \
335 u2&=0x3f; \
336 LL^=DES_SPtrans[1][u1]; \
337 LL^=DES_SPtrans[3][u2]; \
338 s1=(int)t>>16; \
339 s2=(int)t>>24L; \
340 s1&=0x3f; \
341 s2&=0x3f; \
342 LL^=DES_SPtrans[5][s1]; \
343 LL^=DES_SPtrans[7][s2]; }
344#endif
345
346#else
347
348#define D_ENCRYPT(LL,R,S) {\
349 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
350 t=ROTATE(t,4); \
351 LL^=\
352 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
353 DES_SPtrans[2][(u>>10L)&0x3f]^ \
354 DES_SPtrans[4][(u>>18L)&0x3f]^ \
355 DES_SPtrans[6][(u>>26L)&0x3f]^ \
356 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
357 DES_SPtrans[3][(t>>10L)&0x3f]^ \
358 DES_SPtrans[5][(t>>18L)&0x3f]^ \
359 DES_SPtrans[7][(t>>26L)&0x3f]; }
360#endif
361#endif
362
363 /* IP and FP
364 * The problem is more of a geometric problem that random bit fiddling.
365 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
366 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
367 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
368 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
369
370 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
371 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
372 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
373 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
374
375 The output has been subject to swaps of the form
376 0 1 -> 3 1 but the odd and even bits have been put into
377 2 3 2 0
378 different words. The main trick is to remember that
379 t=((l>>size)^r)&(mask);
380 r^=t;
381 l^=(t<<size);
382 can be used to swap and move bits between words.
383
384 So l = 0 1 2 3 r = 16 17 18 19
385 4 5 6 7 20 21 22 23
386 8 9 10 11 24 25 26 27
387 12 13 14 15 28 29 30 31
388 becomes (for size == 2 and mask == 0x3333)
389 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
390 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
391 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
392 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
393
394 Thanks for hints from Richard Outerbridge - he told me IP&FP
395 could be done in 15 xor, 10 shifts and 5 ands.
396 When I finally started to think of the problem in 2D
397 I first got ~42 operations without xors. When I remembered
398 how to use xors :-) I got it to its final state.
399 */
400#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
401 (b)^=(t),\
402 (a)^=((t)<<(n)))
403
404#define IP(l,r) \
405 { \
406 register DES_LONG tt; \
407 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
408 PERM_OP(l,r,tt,16,0x0000ffffL); \
409 PERM_OP(r,l,tt, 2,0x33333333L); \
410 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
411 PERM_OP(r,l,tt, 1,0x55555555L); \
412 }
413
414#define FP(l,r) \
415 { \
416 register DES_LONG tt; \
417 PERM_OP(l,r,tt, 1,0x55555555L); \
418 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
419 PERM_OP(l,r,tt, 2,0x33333333L); \
420 PERM_OP(r,l,tt,16,0x0000ffffL); \
421 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
422 }
423
424OPENSSL_EXTERN const DES_LONG DES_SPtrans[8][64];
425
426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
427 DES_LONG Eswap0, DES_LONG Eswap1);
428#endif
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h
index 1d840b474a..1d8bf65101 100644
--- a/src/lib/libcrypto/des/des_old.h
+++ b/src/lib/libcrypto/des/des_old.h
@@ -88,14 +88,14 @@
88 * 88 *
89 */ 89 */
90 90
91#ifndef HEADER_DES_H 91#ifndef HEADER_DES_OLD_H
92#define HEADER_DES_H 92#define HEADER_DES_OLD_H
93 93
94#ifdef OPENSSL_NO_DES 94#ifdef OPENSSL_NO_DES
95#error DES is disabled. 95#error DES is disabled.
96#endif 96#endif
97 97
98#ifndef HEADER_NEW_DES_H 98#ifndef HEADER_DES_H
99#error You must include des.h, not des_old.h directly. 99#error You must include des.h, not des_old.h directly.
100#endif 100#endif
101 101
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
new file mode 100644
index 0000000000..fa0c9c4d4f
--- /dev/null
+++ b/src/lib/libcrypto/des/ecb3_enc.c
@@ -0,0 +1,81 @@
1/* crypto/des/ecb3_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void DES_ecb3_encrypt(const unsigned char *in, unsigned char *out,
62 DES_key_schedule *ks1, DES_key_schedule *ks2,
63 DES_key_schedule *ks3,
64 int enc)
65 {
66 register DES_LONG l0,l1;
67 DES_LONG ll[2];
68
69 c2l(in,l0);
70 c2l(in,l1);
71 ll[0]=l0;
72 ll[1]=l1;
73 if (enc)
74 DES_encrypt3(ll,ks1,ks2,ks3);
75 else
76 DES_decrypt3(ll,ks1,ks2,ks3);
77 l0=ll[0];
78 l1=ll[1];
79 l2c(l0,out);
80 l2c(l1,out);
81 }
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
new file mode 100644
index 0000000000..784aa5ba23
--- /dev/null
+++ b/src/lib/libcrypto/des/ecb_enc.c
@@ -0,0 +1,123 @@
1/* crypto/des/ecb_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60#include "des_ver.h"
61#include "spr.h"
62#include <openssl/opensslv.h>
63#include <openssl/bio.h>
64
65OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
66OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
67
68const char *DES_options(void)
69 {
70 static int init=1;
71 static char buf[32];
72
73 if (init)
74 {
75 const char *ptr,*unroll,*risc,*size;
76
77#ifdef DES_PTR
78 ptr="ptr";
79#else
80 ptr="idx";
81#endif
82#if defined(DES_RISC1) || defined(DES_RISC2)
83#ifdef DES_RISC1
84 risc="risc1";
85#endif
86#ifdef DES_RISC2
87 risc="risc2";
88#endif
89#else
90 risc="cisc";
91#endif
92#ifdef DES_UNROLL
93 unroll="16";
94#else
95 unroll="4";
96#endif
97 if (sizeof(DES_LONG) != sizeof(long))
98 size="int";
99 else
100 size="long";
101 BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
102 size);
103 init=0;
104 }
105 return(buf);
106 }
107
108
109void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
110 DES_key_schedule *ks, int enc)
111 {
112 register DES_LONG l;
113 DES_LONG ll[2];
114 const unsigned char *in = &(*input)[0];
115 unsigned char *out = &(*output)[0];
116
117 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l;
119 DES_encrypt1(ll,ks,enc);
120 l=ll[0]; l2c(l,out);
121 l=ll[1]; l2c(l,out);
122 l=ll[0]=ll[1]=0;
123 }
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
new file mode 100644
index 0000000000..fa45aa272b
--- /dev/null
+++ b/src/lib/libcrypto/des/ede_cbcm_enc.c
@@ -0,0 +1,197 @@
1/* ede_cbcm_enc.c */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60
61This is an implementation of Triple DES Cipher Block Chaining with Output
62Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
63
64Note that there is a known attack on this by Biham and Knudsen but it takes
65a lot of work:
66
67http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68
69*/
70
71#ifndef OPENSSL_NO_DESCBCM
72#include "des_locl.h"
73
74void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
75 long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
76 DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2,
77 int enc)
78 {
79 register DES_LONG tin0,tin1;
80 register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
81 register long l=length;
82 DES_LONG tin[2];
83 unsigned char *iv1,*iv2;
84
85 iv1 = &(*ivec1)[0];
86 iv2 = &(*ivec2)[0];
87
88 if (enc)
89 {
90 c2l(iv1,m0);
91 c2l(iv1,m1);
92 c2l(iv2,tout0);
93 c2l(iv2,tout1);
94 for (l-=8; l>=-7; l-=8)
95 {
96 tin[0]=m0;
97 tin[1]=m1;
98 DES_encrypt1(tin,ks3,1);
99 m0=tin[0];
100 m1=tin[1];
101
102 if(l < 0)
103 {
104 c2ln(in,tin0,tin1,l+8);
105 }
106 else
107 {
108 c2l(in,tin0);
109 c2l(in,tin1);
110 }
111 tin0^=tout0;
112 tin1^=tout1;
113
114 tin[0]=tin0;
115 tin[1]=tin1;
116 DES_encrypt1(tin,ks1,1);
117 tin[0]^=m0;
118 tin[1]^=m1;
119 DES_encrypt1(tin,ks2,0);
120 tin[0]^=m0;
121 tin[1]^=m1;
122 DES_encrypt1(tin,ks1,1);
123 tout0=tin[0];
124 tout1=tin[1];
125
126 l2c(tout0,out);
127 l2c(tout1,out);
128 }
129 iv1=&(*ivec1)[0];
130 l2c(m0,iv1);
131 l2c(m1,iv1);
132
133 iv2=&(*ivec2)[0];
134 l2c(tout0,iv2);
135 l2c(tout1,iv2);
136 }
137 else
138 {
139 register DES_LONG t0,t1;
140
141 c2l(iv1,m0);
142 c2l(iv1,m1);
143 c2l(iv2,xor0);
144 c2l(iv2,xor1);
145 for (l-=8; l>=-7; l-=8)
146 {
147 tin[0]=m0;
148 tin[1]=m1;
149 DES_encrypt1(tin,ks3,1);
150 m0=tin[0];
151 m1=tin[1];
152
153 c2l(in,tin0);
154 c2l(in,tin1);
155
156 t0=tin0;
157 t1=tin1;
158
159 tin[0]=tin0;
160 tin[1]=tin1;
161 DES_encrypt1(tin,ks1,0);
162 tin[0]^=m0;
163 tin[1]^=m1;
164 DES_encrypt1(tin,ks2,1);
165 tin[0]^=m0;
166 tin[1]^=m1;
167 DES_encrypt1(tin,ks1,0);
168 tout0=tin[0];
169 tout1=tin[1];
170
171 tout0^=xor0;
172 tout1^=xor1;
173 if(l < 0)
174 {
175 l2cn(tout0,tout1,out,l+8);
176 }
177 else
178 {
179 l2c(tout0,out);
180 l2c(tout1,out);
181 }
182 xor0=t0;
183 xor1=t1;
184 }
185
186 iv1=&(*ivec1)[0];
187 l2c(m0,iv1);
188 l2c(m1,iv1);
189
190 iv2=&(*ivec2)[0];
191 l2c(xor0,iv2);
192 l2c(xor1,iv2);
193 }
194 tin0=tin1=tout0=tout1=xor0=xor1=0;
195 tin[0]=tin[1]=0;
196 }
197#endif
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
new file mode 100644
index 0000000000..c70fb686b8
--- /dev/null
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -0,0 +1,228 @@
1/* crypto/des/enc_read.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include "des_locl.h"
63
64/* This has some uglies in it but it works - even over sockets. */
65/*extern int errno;*/
66OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
67
68
69/*
70 * WARNINGS:
71 *
72 * - The data format used by DES_enc_write() and DES_enc_read()
73 * has a cryptographic weakness: When asked to write more
74 * than MAXWRITE bytes, DES_enc_write will split the data
75 * into several chunks that are all encrypted
76 * using the same IV. So don't use these functions unless you
77 * are sure you know what you do (in which case you might
78 * not want to use them anyway).
79 *
80 * - This code cannot handle non-blocking sockets.
81 *
82 * - This function uses an internal state and thus cannot be
83 * used on multiple files.
84 */
85
86
87int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
88 DES_cblock *iv)
89 {
90 /* data to be unencrypted */
91 int net_num=0;
92 static unsigned char *net=NULL;
93 /* extra unencrypted data
94 * for when a block of 100 comes in but is des_read one byte at
95 * a time. */
96 static unsigned char *unnet=NULL;
97 static int unnet_start=0;
98 static int unnet_left=0;
99 static unsigned char *tmpbuf=NULL;
100 int i;
101 long num=0,rnum;
102 unsigned char *p;
103
104 if (tmpbuf == NULL)
105 {
106 tmpbuf=OPENSSL_malloc(BSIZE);
107 if (tmpbuf == NULL) return(-1);
108 }
109 if (net == NULL)
110 {
111 net=OPENSSL_malloc(BSIZE);
112 if (net == NULL) return(-1);
113 }
114 if (unnet == NULL)
115 {
116 unnet=OPENSSL_malloc(BSIZE);
117 if (unnet == NULL) return(-1);
118 }
119 /* left over data from last decrypt */
120 if (unnet_left != 0)
121 {
122 if (unnet_left < len)
123 {
124 /* we still still need more data but will return
125 * with the number of bytes we have - should always
126 * check the return value */
127 memcpy(buf,&(unnet[unnet_start]),
128 unnet_left);
129 /* eay 26/08/92 I had the next 2 lines
130 * reversed :-( */
131 i=unnet_left;
132 unnet_start=unnet_left=0;
133 }
134 else
135 {
136 memcpy(buf,&(unnet[unnet_start]),len);
137 unnet_start+=len;
138 unnet_left-=len;
139 i=len;
140 }
141 return(i);
142 }
143
144 /* We need to get more data. */
145 if (len > MAXWRITE) len=MAXWRITE;
146
147 /* first - get the length */
148 while (net_num < HDRSIZE)
149 {
150 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
151#ifdef EINTR
152 if ((i == -1) && (errno == EINTR)) continue;
153#endif
154 if (i <= 0) return(0);
155 net_num+=i;
156 }
157
158 /* we now have at net_num bytes in net */
159 p=net;
160 /* num=0; */
161 n2l(p,num);
162 /* num should be rounded up to the next group of eight
163 * we make sure that we have read a multiple of 8 bytes from the net.
164 */
165 if ((num > MAXWRITE) || (num < 0)) /* error */
166 return(-1);
167 rnum=(num < 8)?8:((num+7)/8*8);
168
169 net_num=0;
170 while (net_num < rnum)
171 {
172 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
173#ifdef EINTR
174 if ((i == -1) && (errno == EINTR)) continue;
175#endif
176 if (i <= 0) return(0);
177 net_num+=i;
178 }
179
180 /* Check if there will be data left over. */
181 if (len < num)
182 {
183 if (DES_rw_mode & DES_PCBC_MODE)
184 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
185 else
186 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
187 memcpy(buf,unnet,len);
188 unnet_start=len;
189 unnet_left=num-len;
190
191 /* The following line is done because we return num
192 * as the number of bytes read. */
193 num=len;
194 }
195 else
196 {
197 /* >output is a multiple of 8 byes, if len < rnum
198 * >we must be careful. The user must be aware that this
199 * >routine will write more bytes than he asked for.
200 * >The length of the buffer must be correct.
201 * FIXED - Should be ok now 18-9-90 - eay */
202 if (len < rnum)
203 {
204
205 if (DES_rw_mode & DES_PCBC_MODE)
206 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv,
207 DES_DECRYPT);
208 else
209 DES_cbc_encrypt(net,tmpbuf,num,sched,iv,
210 DES_DECRYPT);
211
212 /* eay 26/08/92 fix a bug that returned more
213 * bytes than you asked for (returned len bytes :-( */
214 memcpy(buf,tmpbuf,num);
215 }
216 else
217 {
218 if (DES_rw_mode & DES_PCBC_MODE)
219 DES_pcbc_encrypt(net,buf,num,sched,iv,
220 DES_DECRYPT);
221 else
222 DES_cbc_encrypt(net,buf,num,sched,iv,
223 DES_DECRYPT);
224 }
225 }
226 return num;
227 }
228
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
new file mode 100644
index 0000000000..af5b8c2349
--- /dev/null
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -0,0 +1,171 @@
1/* crypto/des/enc_writ.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <errno.h>
60#include <time.h>
61#include <stdio.h>
62#include "cryptlib.h"
63#include "des_locl.h"
64#include <openssl/rand.h>
65
66/*
67 * WARNINGS:
68 *
69 * - The data format used by DES_enc_write() and DES_enc_read()
70 * has a cryptographic weakness: When asked to write more
71 * than MAXWRITE bytes, DES_enc_write will split the data
72 * into several chunks that are all encrypted
73 * using the same IV. So don't use these functions unless you
74 * are sure you know what you do (in which case you might
75 * not want to use them anyway).
76 *
77 * - This code cannot handle non-blocking sockets.
78 */
79
80int DES_enc_write(int fd, const void *_buf, int len,
81 DES_key_schedule *sched, DES_cblock *iv)
82 {
83#ifdef _LIBC
84 extern unsigned long time();
85 extern int write();
86#endif
87 const unsigned char *buf=_buf;
88 long rnum;
89 int i,j,k,outnum;
90 static unsigned char *outbuf=NULL;
91 unsigned char shortbuf[8];
92 unsigned char *p;
93 const unsigned char *cp;
94 static int start=1;
95
96 if (outbuf == NULL)
97 {
98 outbuf=OPENSSL_malloc(BSIZE+HDRSIZE);
99 if (outbuf == NULL) return(-1);
100 }
101 /* If we are sending less than 8 bytes, the same char will look
102 * the same if we don't pad it out with random bytes */
103 if (start)
104 {
105 start=0;
106 }
107
108 /* lets recurse if we want to send the data in small chunks */
109 if (len > MAXWRITE)
110 {
111 j=0;
112 for (i=0; i<len; i+=k)
113 {
114 k=DES_enc_write(fd,&(buf[i]),
115 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
116 if (k < 0)
117 return(k);
118 else
119 j+=k;
120 }
121 return(j);
122 }
123
124 /* write length first */
125 p=outbuf;
126 l2n(len,p);
127
128 /* pad short strings */
129 if (len < 8)
130 {
131 cp=shortbuf;
132 memcpy(shortbuf,buf,len);
133 RAND_pseudo_bytes(shortbuf+len, 8-len);
134 rnum=8;
135 }
136 else
137 {
138 cp=buf;
139 rnum=((len+7)/8*8); /* round up to nearest eight */
140 }
141
142 if (DES_rw_mode & DES_PCBC_MODE)
143 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
144 DES_ENCRYPT);
145 else
146 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
147 DES_ENCRYPT);
148
149 /* output */
150 outnum=rnum+HDRSIZE;
151
152 for (j=0; j<outnum; j+=i)
153 {
154 /* eay 26/08/92 I was not doing writing from where we
155 * got up to. */
156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
157 if (i == -1)
158 {
159#ifdef EINTR
160 if (errno == EINTR)
161 i=0;
162 else
163#endif
164 /* This is really a bad error - very bad
165 * It will stuff-up both ends. */
166 return(-1);
167 }
168 }
169
170 return(len);
171 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
new file mode 100644
index 0000000000..2758c32656
--- /dev/null
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -0,0 +1,173 @@
1/* NOCW */
2#include <stdio.h>
3#ifdef _OSD_POSIX
4#ifndef CHARSET_EBCDIC
5#define CHARSET_EBCDIC 1
6#endif
7#endif
8#ifdef CHARSET_EBCDIC
9#include <openssl/ebcdic.h>
10#endif
11
12/* This version of crypt has been developed from my MIT compatible
13 * DES library.
14 * Eric Young (eay@cryptsoft.com)
15 */
16
17/* Modification by Jens Kupferschmidt (Cu)
18 * I have included directive PARA for shared memory computers.
19 * I have included a directive LONGCRYPT to using this routine to cipher
20 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
21 * definition is the maximum of length of password and can changed. I have
22 * defined 24.
23 */
24
25#include "des_locl.h"
26
27/* Added more values to handle illegal salt values the way normal
28 * crypt() implementations do. The patch was sent by
29 * Bjorn Gronvall <bg@sics.se>
30 */
31static unsigned const char con_salt[128]={
320xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
330xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
340xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
350xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
360xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
370xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
380x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
390x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
400x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
410x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
420x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
430x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
440x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
450x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
460x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
470x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
48};
49
50static unsigned const char cov_2char[64]={
510x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
520x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
530x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
540x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
550x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
560x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
570x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
59};
60
61void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
62 DES_LONG Eswap0, DES_LONG Eswap1);
63
64char *DES_crypt(const char *buf, const char *salt)
65 {
66 static char buff[14];
67
68#ifndef CHARSET_EBCDIC
69 return(DES_fcrypt(buf,salt,buff));
70#else
71 char e_salt[2+1];
72 char e_buf[32+1]; /* replace 32 by 8 ? */
73 char *ret;
74
75 /* Copy at most 2 chars of salt */
76 if ((e_salt[0] = salt[0]) != '\0')
77 e_salt[1] = salt[1];
78
79 /* Copy at most 32 chars of password */
80 strncpy (e_buf, buf, sizeof(e_buf));
81
82 /* Make sure we have a delimiter */
83 e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0';
84
85 /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */
86 ebcdic2ascii(e_salt, e_salt, sizeof e_salt);
87
88 /* Convert the cleartext password to ASCII */
89 ebcdic2ascii(e_buf, e_buf, sizeof e_buf);
90
91 /* Encrypt it (from/to ASCII) */
92 ret = DES_fcrypt(e_buf,e_salt,buff);
93
94 /* Convert the result back to EBCDIC */
95 ascii2ebcdic(ret, ret, strlen(ret));
96
97 return ret;
98#endif
99 }
100
101
102char *DES_fcrypt(const char *buf, const char *salt, char *ret)
103 {
104 unsigned int i,j,x,y;
105 DES_LONG Eswap0,Eswap1;
106 DES_LONG out[2],ll;
107 DES_cblock key;
108 DES_key_schedule ks;
109 unsigned char bb[9];
110 unsigned char *b=bb;
111 unsigned char c,u;
112
113 /* eay 25/08/92
114 * If you call crypt("pwd","*") as often happens when you
115 * have * as the pwd field in /etc/passwd, the function
116 * returns *\0XXXXXXXXX
117 * The \0 makes the string look like * so the pwd "*" would
118 * crypt to "*". This was found when replacing the crypt in
119 * our shared libraries. People found that the disabled
120 * accounts effectively had no passwd :-(. */
121#ifndef CHARSET_EBCDIC
122 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
123 Eswap0=con_salt[x]<<2;
124 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
125 Eswap1=con_salt[x]<<6;
126#else
127 x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]);
128 Eswap0=con_salt[x]<<2;
129 x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]);
130 Eswap1=con_salt[x]<<6;
131#endif
132
133/* EAY
134r=strlen(buf);
135r=(r+7)/8;
136*/
137 for (i=0; i<8; i++)
138 {
139 c= *(buf++);
140 if (!c) break;
141 key[i]=(c<<1);
142 }
143 for (; i<8; i++)
144 key[i]=0;
145
146 DES_set_key_unchecked(&key,&ks);
147 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1);
148
149 ll=out[0]; l2c(ll,b);
150 ll=out[1]; l2c(ll,b);
151 y=0;
152 u=0x80;
153 bb[8]=0;
154 for (i=2; i<13; i++)
155 {
156 c=0;
157 for (j=0; j<6; j++)
158 {
159 c<<=1;
160 if (bb[y] & u) c|=1;
161 u>>=1;
162 if (!u)
163 {
164 y++;
165 u=0x80;
166 }
167 }
168 ret[i]=cov_2char[c];
169 }
170 ret[13]='\0';
171 return(ret);
172 }
173
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
new file mode 100644
index 0000000000..1390138787
--- /dev/null
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -0,0 +1,145 @@
1/* crypto/des/fcrypt_b.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60
61/* This version of crypt has been developed from my MIT compatible
62 * DES library.
63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
64 * Eric Young (eay@cryptsoft.com)
65 */
66
67#define DES_FCRYPT
68#include "des_locl.h"
69#undef DES_FCRYPT
70
71#undef PERM_OP
72#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
73 (b)^=(t),\
74 (a)^=((t)<<(n)))
75
76#undef HPERM_OP
77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
78 (a)=(a)^(t)^(t>>(16-(n))))\
79
80void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
81 DES_LONG Eswap1)
82 {
83 register DES_LONG l,r,t,u;
84#ifdef DES_PTR
85 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
86#endif
87 register DES_LONG *s;
88 register int j;
89 register DES_LONG E0,E1;
90
91 l=0;
92 r=0;
93
94 s=(DES_LONG *)ks;
95 E0=Eswap0;
96 E1=Eswap1;
97
98 for (j=0; j<25; j++)
99 {
100#ifndef DES_UNROLL
101 register int i;
102
103 for (i=0; i<32; i+=8)
104 {
105 D_ENCRYPT(l,r,i+0); /* 1 */
106 D_ENCRYPT(r,l,i+2); /* 2 */
107 D_ENCRYPT(l,r,i+4); /* 1 */
108 D_ENCRYPT(r,l,i+6); /* 2 */
109 }
110#else
111 D_ENCRYPT(l,r, 0); /* 1 */
112 D_ENCRYPT(r,l, 2); /* 2 */
113 D_ENCRYPT(l,r, 4); /* 3 */
114 D_ENCRYPT(r,l, 6); /* 4 */
115 D_ENCRYPT(l,r, 8); /* 5 */
116 D_ENCRYPT(r,l,10); /* 6 */
117 D_ENCRYPT(l,r,12); /* 7 */
118 D_ENCRYPT(r,l,14); /* 8 */
119 D_ENCRYPT(l,r,16); /* 9 */
120 D_ENCRYPT(r,l,18); /* 10 */
121 D_ENCRYPT(l,r,20); /* 11 */
122 D_ENCRYPT(r,l,22); /* 12 */
123 D_ENCRYPT(l,r,24); /* 13 */
124 D_ENCRYPT(r,l,26); /* 14 */
125 D_ENCRYPT(l,r,28); /* 15 */
126 D_ENCRYPT(r,l,30); /* 16 */
127#endif
128
129 t=l;
130 l=r;
131 r=t;
132 }
133 l=ROTATE(l,3)&0xffffffffL;
134 r=ROTATE(r,3)&0xffffffffL;
135
136 PERM_OP(l,r,t, 1,0x55555555L);
137 PERM_OP(r,l,t, 8,0x00ff00ffL);
138 PERM_OP(l,r,t, 2,0x33333333L);
139 PERM_OP(r,l,t,16,0x0000ffffL);
140 PERM_OP(l,r,t, 4,0x0f0f0f0fL);
141
142 out[0]=r;
143 out[1]=l;
144 }
145
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
new file mode 100644
index 0000000000..fda23d522f
--- /dev/null
+++ b/src/lib/libcrypto/des/ncbc_enc.c
@@ -0,0 +1,148 @@
1/* crypto/des/ncbc_enc.c */
2/*
3 * #included by:
4 * cbc_enc.c (DES_cbc_encrypt)
5 * des_enc.c (DES_ncbc_encrypt)
6 */
7/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
8 * All rights reserved.
9 *
10 * This package is an SSL implementation written
11 * by Eric Young (eay@cryptsoft.com).
12 * The implementation was written so as to conform with Netscapes SSL.
13 *
14 * This library is free for commercial and non-commercial use as long as
15 * the following conditions are aheared to. The following conditions
16 * apply to all code found in this distribution, be it the RC4, RSA,
17 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
18 * included with this distribution is covered by the same copyright terms
19 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
20 *
21 * Copyright remains Eric Young's, and as such any Copyright notices in
22 * the code are not to be removed.
23 * If this package is used in a product, Eric Young should be given attribution
24 * as the author of the parts of the library used.
25 * This can be in the form of a textual message at program startup or
26 * in documentation (online or textual) provided with the package.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * "This product includes cryptographic software written by
39 * Eric Young (eay@cryptsoft.com)"
40 * The word 'cryptographic' can be left out if the rouines from the library
41 * being used are not cryptographic related :-).
42 * 4. If you include any Windows specific code (or a derivative thereof) from
43 * the apps directory (application code) you must include an acknowledgement:
44 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
45 *
46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * The licence and distribution terms for any publically available version or
59 * derivative of this code cannot be changed. i.e. this code cannot simply be
60 * copied and put under another distribution licence
61 * [including the GNU Public Licence.]
62 */
63
64#include "des_locl.h"
65
66#ifdef CBC_ENC_C__DONT_UPDATE_IV
67void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
68 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
69#else
70void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
71 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
72#endif
73 {
74 register DES_LONG tin0,tin1;
75 register DES_LONG tout0,tout1,xor0,xor1;
76 register long l=length;
77 DES_LONG tin[2];
78 unsigned char *iv;
79
80 iv = &(*ivec)[0];
81
82 if (enc)
83 {
84 c2l(iv,tout0);
85 c2l(iv,tout1);
86 for (l-=8; l>=0; l-=8)
87 {
88 c2l(in,tin0);
89 c2l(in,tin1);
90 tin0^=tout0; tin[0]=tin0;
91 tin1^=tout1; tin[1]=tin1;
92 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
93 tout0=tin[0]; l2c(tout0,out);
94 tout1=tin[1]; l2c(tout1,out);
95 }
96 if (l != -8)
97 {
98 c2ln(in,tin0,tin1,l+8);
99 tin0^=tout0; tin[0]=tin0;
100 tin1^=tout1; tin[1]=tin1;
101 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
102 tout0=tin[0]; l2c(tout0,out);
103 tout1=tin[1]; l2c(tout1,out);
104 }
105#ifndef CBC_ENC_C__DONT_UPDATE_IV
106 iv = &(*ivec)[0];
107 l2c(tout0,iv);
108 l2c(tout1,iv);
109#endif
110 }
111 else
112 {
113 c2l(iv,xor0);
114 c2l(iv,xor1);
115 for (l-=8; l>=0; l-=8)
116 {
117 c2l(in,tin0); tin[0]=tin0;
118 c2l(in,tin1); tin[1]=tin1;
119 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
120 tout0=tin[0]^xor0;
121 tout1=tin[1]^xor1;
122 l2c(tout0,out);
123 l2c(tout1,out);
124 xor0=tin0;
125 xor1=tin1;
126 }
127 if (l != -8)
128 {
129 c2l(in,tin0); tin[0]=tin0;
130 c2l(in,tin1); tin[1]=tin1;
131 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
132 tout0=tin[0]^xor0;
133 tout1=tin[1]^xor1;
134 l2cn(tout0,tout1,out,l+8);
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 xor0=tin0;
137 xor1=tin1;
138#endif
139 }
140#ifndef CBC_ENC_C__DONT_UPDATE_IV
141 iv = &(*ivec)[0];
142 l2c(xor0,iv);
143 l2c(xor1,iv);
144#endif
145 }
146 tin0=tin1=tout0=tout1=xor0=xor1=0;
147 tin[0]=tin[1]=0;
148 }
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c
new file mode 100644
index 0000000000..26bbf9a6a7
--- /dev/null
+++ b/src/lib/libcrypto/des/ofb64ede.c
@@ -0,0 +1,125 @@
1/* crypto/des/ofb64ede.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void DES_ede3_ofb64_encrypt(register const unsigned char *in,
66 register unsigned char *out, long length,
67 DES_key_schedule *k1, DES_key_schedule *k2,
68 DES_key_schedule *k3, DES_cblock *ivec,
69 int *num)
70 {
71 register DES_LONG v0,v1;
72 register int n= *num;
73 register long l=length;
74 DES_cblock d;
75 register char *dp;
76 DES_LONG ti[2];
77 unsigned char *iv;
78 int save=0;
79
80 iv = &(*ivec)[0];
81 c2l(iv,v0);
82 c2l(iv,v1);
83 ti[0]=v0;
84 ti[1]=v1;
85 dp=(char *)d;
86 l2c(v0,dp);
87 l2c(v1,dp);
88 while (l--)
89 {
90 if (n == 0)
91 {
92 /* ti[0]=v0; */
93 /* ti[1]=v1; */
94 DES_encrypt3(ti,k1,k2,k3);
95 v0=ti[0];
96 v1=ti[1];
97
98 dp=(char *)d;
99 l2c(v0,dp);
100 l2c(v1,dp);
101 save++;
102 }
103 *(out++)= *(in++)^d[n];
104 n=(n+1)&0x07;
105 }
106 if (save)
107 {
108/* v0=ti[0];
109 v1=ti[1];*/
110 iv = &(*ivec)[0];
111 l2c(v0,iv);
112 l2c(v1,iv);
113 }
114 v0=v1=ti[0]=ti[1]=0;
115 *num=n;
116 }
117
118#ifdef undef /* MACRO */
119void DES_ede2_ofb64_encrypt(register unsigned char *in,
120 register unsigned char *out, long length, DES_key_schedule k1,
121 DES_key_schedule k2, DES_cblock (*ivec), int *num)
122 {
123 DES_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
124 }
125#endif
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
new file mode 100644
index 0000000000..8ca3d49dea
--- /dev/null
+++ b/src/lib/libcrypto/des/ofb64enc.c
@@ -0,0 +1,110 @@
1/* crypto/des/ofb64enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void DES_ofb64_encrypt(register const unsigned char *in,
66 register unsigned char *out, long length,
67 DES_key_schedule *schedule, DES_cblock *ivec, int *num)
68 {
69 register DES_LONG v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 DES_cblock d;
73 register unsigned char *dp;
74 DES_LONG ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv = &(*ivec)[0];
79 c2l(iv,v0);
80 c2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=d;
84 l2c(v0,dp);
85 l2c(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 DES_encrypt1(ti,schedule,DES_ENCRYPT);
91 dp=d;
92 t=ti[0]; l2c(t,dp);
93 t=ti[1]; l2c(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv = &(*ivec)[0];
104 l2c(v0,iv);
105 l2c(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c
new file mode 100644
index 0000000000..e887a3c6f4
--- /dev/null
+++ b/src/lib/libcrypto/des/ofb_enc.c
@@ -0,0 +1,135 @@
1/* crypto/des/ofb_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output are loaded in multiples of 8 bits.
62 * What this means is that if you hame numbits=12 and length=2
63 * the first 12 bits will be retrieved from the first byte and half
64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte.
66 */
67void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68 long length, DES_key_schedule *schedule,
69 DES_cblock *ivec)
70 {
71 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
72 register DES_LONG mask0,mask1;
73 register long l=length;
74 register int num=numbits;
75 DES_LONG ti[2];
76 unsigned char *iv;
77
78 if (num > 64) return;
79 if (num > 32)
80 {
81 mask0=0xffffffffL;
82 if (num >= 64)
83 mask1=mask0;
84 else
85 mask1=(1L<<(num-32))-1;
86 }
87 else
88 {
89 if (num == 32)
90 mask0=0xffffffffL;
91 else
92 mask0=(1L<<num)-1;
93 mask1=0x00000000L;
94 }
95
96 iv = &(*ivec)[0];
97 c2l(iv,v0);
98 c2l(iv,v1);
99 ti[0]=v0;
100 ti[1]=v1;
101 while (l-- > 0)
102 {
103 ti[0]=v0;
104 ti[1]=v1;
105 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
106 vv0=ti[0];
107 vv1=ti[1];
108 c2ln(in,d0,d1,n);
109 in+=n;
110 d0=(d0^vv0)&mask0;
111 d1=(d1^vv1)&mask1;
112 l2cn(d0,d1,out,n);
113 out+=n;
114
115 if (num == 32)
116 { v0=v1; v1=vv0; }
117 else if (num == 64)
118 { v0=vv0; v1=vv1; }
119 else if (num > 32) /* && num != 64 */
120 {
121 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL;
122 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL;
123 }
124 else /* num < 32 */
125 {
126 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
127 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
128 }
129 }
130 iv = &(*ivec)[0];
131 l2c(v0,iv);
132 l2c(v1,iv);
133 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
134 }
135
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
new file mode 100644
index 0000000000..17a40f9520
--- /dev/null
+++ b/src/lib/libcrypto/des/pcbc_enc.c
@@ -0,0 +1,123 @@
1/* crypto/des/pcbc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
62 long length, DES_key_schedule *schedule,
63 DES_cblock *ivec, int enc)
64 {
65 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
66 DES_LONG tin[2];
67 const unsigned char *in;
68 unsigned char *out,*iv;
69
70 in=input;
71 out=output;
72 iv = &(*ivec)[0];
73
74 if (enc)
75 {
76 c2l(iv,xor0);
77 c2l(iv,xor1);
78 for (; length>0; length-=8)
79 {
80 if (length >= 8)
81 {
82 c2l(in,sin0);
83 c2l(in,sin1);
84 }
85 else
86 c2ln(in,sin0,sin1,length);
87 tin[0]=sin0^xor0;
88 tin[1]=sin1^xor1;
89 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
90 tout0=tin[0];
91 tout1=tin[1];
92 xor0=sin0^tout0;
93 xor1=sin1^tout1;
94 l2c(tout0,out);
95 l2c(tout1,out);
96 }
97 }
98 else
99 {
100 c2l(iv,xor0); c2l(iv,xor1);
101 for (; length>0; length-=8)
102 {
103 c2l(in,sin0);
104 c2l(in,sin1);
105 tin[0]=sin0;
106 tin[1]=sin1;
107 DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT);
108 tout0=tin[0]^xor0;
109 tout1=tin[1]^xor1;
110 if (length >= 8)
111 {
112 l2c(tout0,out);
113 l2c(tout1,out);
114 }
115 else
116 l2cn(tout0,tout1,out,length);
117 xor0=tout0^sin0;
118 xor1=tout1^sin1;
119 }
120 }
121 tin[0]=tin[1]=0;
122 sin0=sin1=xor0=xor1=tout0=tout1=0;
123 }
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
new file mode 100644
index 0000000000..dac201227e
--- /dev/null
+++ b/src/lib/libcrypto/des/qud_cksm.c
@@ -0,0 +1,139 @@
1/* crypto/des/qud_cksm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer
60 * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40
61 * This module in only based on the code in this paper and is
62 * almost definitely not the same as the MIT implementation.
63 */
64#include "des_locl.h"
65
66/* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */
67#define Q_B0(a) (((DES_LONG)(a)))
68#define Q_B1(a) (((DES_LONG)(a))<<8)
69#define Q_B2(a) (((DES_LONG)(a))<<16)
70#define Q_B3(a) (((DES_LONG)(a))<<24)
71
72/* used to scramble things a bit */
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L)
75
76DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
77 long length, int out_count, DES_cblock *seed)
78 {
79 DES_LONG z0,z1,t0,t1;
80 int i;
81 long l;
82 const unsigned char *cp;
83#ifdef _CRAY
84 struct lp_st { int a:32; int b:32; } *lp;
85#else
86 DES_LONG *lp;
87#endif
88
89 if (out_count < 1) out_count=1;
90#ifdef _CRAY
91 lp = (struct lp_st *) &(output[0])[0];
92#else
93 lp = (DES_LONG *) &(output[0])[0];
94#endif
95
96 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
97 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
98
99 for (i=0; ((i<4)&&(i<out_count)); i++)
100 {
101 cp=input;
102 l=length;
103 while (l > 0)
104 {
105 if (l > 1)
106 {
107 t0= (DES_LONG)(*(cp++));
108 t0|=(DES_LONG)Q_B1(*(cp++));
109 l--;
110 }
111 else
112 t0= (DES_LONG)(*(cp++));
113 l--;
114 /* add */
115 t0+=z0;
116 t0&=0xffffffffL;
117 t1=z1;
118 /* square, well sort of square */
119 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
120 &0xffffffffL)%0x7fffffffL;
121 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
122 }
123 if (lp != NULL)
124 {
125 /* The MIT library assumes that the checksum is
126 * composed of 2*out_count 32 bit ints */
127#ifdef _CRAY
128 (*lp).a = z0;
129 (*lp).b = z1;
130 lp++;
131#else
132 *lp++ = z0;
133 *lp++ = z1;
134#endif
135 }
136 }
137 return(z0);
138 }
139
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
new file mode 100644
index 0000000000..2398165568
--- /dev/null
+++ b/src/lib/libcrypto/des/rand_key.c
@@ -0,0 +1,68 @@
1/* crypto/des/rand_key.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/des.h>
57#include <openssl/rand.h>
58
59int DES_random_key(DES_cblock *ret)
60 {
61 do
62 {
63 if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1)
64 return (0);
65 } while (DES_is_weak_key(ret));
66 DES_set_odd_parity(ret);
67 return (1);
68 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
new file mode 100644
index 0000000000..8881d46a7a
--- /dev/null
+++ b/src/lib/libcrypto/des/set_key.c
@@ -0,0 +1,411 @@
1/* crypto/des/set_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* set_key.c v 1.4 eay 24/9/91
60 * 1.4 Speed up by 400% :-)
61 * 1.3 added register declarations.
62 * 1.2 unrolled make_key_sched a bit more
63 * 1.1 added norm_expand_bits
64 * 1.0 First working version
65 */
66#include "des_locl.h"
67
68#ifndef OPENSSL_FIPS
69
70OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
71
72static const unsigned char odd_parity[256]={
73 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
74 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
75 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
76 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
77 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
78 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
79 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
80112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
81128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
82145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
83161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
84176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
85193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
86208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
87224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
88241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
89
90void DES_set_odd_parity(DES_cblock *key)
91 {
92 int i;
93
94 for (i=0; i<DES_KEY_SZ; i++)
95 (*key)[i]=odd_parity[(*key)[i]];
96 }
97
98int DES_check_key_parity(const_DES_cblock *key)
99 {
100 int i;
101
102 for (i=0; i<DES_KEY_SZ; i++)
103 {
104 if ((*key)[i] != odd_parity[(*key)[i]])
105 return(0);
106 }
107 return(1);
108 }
109
110/* Weak and semi week keys as take from
111 * %A D.W. Davies
112 * %A W.L. Price
113 * %T Security for Computer Networks
114 * %I John Wiley & Sons
115 * %D 1984
116 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
117 * (and actual cblock values).
118 */
119#define NUM_WEAK_KEY 16
120static DES_cblock weak_keys[NUM_WEAK_KEY]={
121 /* weak keys */
122 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
123 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
124 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
125 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
126 /* semi-weak keys */
127 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
128 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
129 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
130 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
131 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
132 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
133 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
134 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
135 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
136 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
137 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
138 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
139
140int DES_is_weak_key(const_DES_cblock *key)
141 {
142 int i;
143
144 for (i=0; i<NUM_WEAK_KEY; i++)
145 /* Added == 0 to comparison, I obviously don't run
146 * this section very often :-(, thanks to
147 * engineering@MorningStar.Com for the fix
148 * eay 93/06/29
149 * Another problem, I was comparing only the first 4
150 * bytes, 97/03/18 */
151 if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
152 return(0);
153 }
154
155/* NOW DEFINED IN des_local.h
156 * See ecb_encrypt.c for a pseudo description of these macros.
157 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
158 * (b)^=(t),\
159 * (a)=((a)^((t)<<(n))))
160 */
161
162#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
163 (a)=(a)^(t)^(t>>(16-(n))))
164
165static const DES_LONG des_skb[8][64]={
166 {
167 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
168 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
169 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
170 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
171 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
172 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
173 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
174 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
175 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
176 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
177 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
178 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
179 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
180 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
181 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
182 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
183 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
184 },{
185 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
186 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
187 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
188 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
189 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
190 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
191 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
192 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
193 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
194 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
195 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
196 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
197 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
198 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
199 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
200 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
201 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
202 },{
203 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
204 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
205 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
206 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
207 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
208 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
209 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
210 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
211 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
212 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
213 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
214 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
215 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
216 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
217 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
218 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
219 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
220 },{
221 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
222 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
223 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
224 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
225 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
226 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
227 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
228 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
229 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
230 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
231 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
232 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
233 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
234 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
235 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
236 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
237 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
238 },{
239 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
240 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
241 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
242 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
243 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
244 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
245 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
246 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
247 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
248 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
249 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
250 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
251 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
252 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
253 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
254 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
255 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
256 },{
257 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
258 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
259 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
260 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
261 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
262 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
263 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
264 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
265 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
266 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
267 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
268 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
269 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
270 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
271 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
272 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
273 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
274 },{
275 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
276 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
277 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
278 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
279 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
280 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
281 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
282 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
283 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
284 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
285 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
286 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
287 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
288 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
289 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
290 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
291 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
292 },{
293 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
294 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
295 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
296 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
297 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
298 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
299 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
300 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
301 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
302 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
303 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
304 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
305 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
306 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
307 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
308 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
309 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
310 }};
311
312int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
313 {
314 if (DES_check_key)
315 {
316 return DES_set_key_checked(key, schedule);
317 }
318 else
319 {
320 DES_set_key_unchecked(key, schedule);
321 return 0;
322 }
323 }
324
325/* return 0 if key parity is odd (correct),
326 * return -1 if key parity error,
327 * return -2 if illegal weak key.
328 */
329int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
330 {
331 if (!DES_check_key_parity(key))
332 return(-1);
333 if (DES_is_weak_key(key))
334 return(-2);
335 DES_set_key_unchecked(key, schedule);
336 return 0;
337 }
338
339void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
340 {
341 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
342 register DES_LONG c,d,t,s,t2;
343 register const unsigned char *in;
344 register DES_LONG *k;
345 register int i;
346
347#ifdef OPENBSD_DEV_CRYPTO
348 memcpy(schedule->key,key,sizeof schedule->key);
349 schedule->session=NULL;
350#endif
351 k = &schedule->ks->deslong[0];
352 in = &(*key)[0];
353
354 c2l(in,c);
355 c2l(in,d);
356
357 /* do PC1 in 47 simple operations :-)
358 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
359 * for the inspiration. :-) */
360 PERM_OP (d,c,t,4,0x0f0f0f0fL);
361 HPERM_OP(c,t,-2,0xcccc0000L);
362 HPERM_OP(d,t,-2,0xcccc0000L);
363 PERM_OP (d,c,t,1,0x55555555L);
364 PERM_OP (c,d,t,8,0x00ff00ffL);
365 PERM_OP (d,c,t,1,0x55555555L);
366 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
367 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
368 c&=0x0fffffffL;
369
370 for (i=0; i<ITERATIONS; i++)
371 {
372 if (shifts2[i])
373 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
374 else
375 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
376 c&=0x0fffffffL;
377 d&=0x0fffffffL;
378 /* could be a few less shifts but I am to lazy at this
379 * point in time to investigate */
380 s= des_skb[0][ (c )&0x3f ]|
381 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
382 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
383 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
384 ((c>>22L)&0x38)];
385 t= des_skb[4][ (d )&0x3f ]|
386 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
387 des_skb[6][ (d>>15L)&0x3f ]|
388 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
389
390 /* table contained 0213 4657 */
391 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
392 *(k++)=ROTATE(t2,30)&0xffffffffL;
393
394 t2=((s>>16L)|(t&0xffff0000L));
395 *(k++)=ROTATE(t2,26)&0xffffffffL;
396 }
397 }
398
399int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
400 {
401 return(DES_set_key(key,schedule));
402 }
403/*
404#undef des_fixup_key_parity
405void des_fixup_key_parity(des_cblock *key)
406 {
407 des_set_odd_parity(key);
408 }
409*/
410
411#endif /* ndef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
new file mode 100644
index 0000000000..b91936a5a5
--- /dev/null
+++ b/src/lib/libcrypto/des/spr.h
@@ -0,0 +1,204 @@
1/* crypto/des/spr.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59OPENSSL_GLOBAL const DES_LONG DES_SPtrans[8][64]={
60{
61/* nibble 0 */
620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
630x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
640x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
650x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
660x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
670x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
680x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
690x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
700x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
710x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
720x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
730x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
740x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
750x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
760x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
770x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
78},{
79/* nibble 1 */
800x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
810x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
820x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
830x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
840x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
850x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
860x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
870x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
880x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
890x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
900x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
910x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
920x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
930x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
940x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
950x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
96},{
97/* nibble 2 */
980x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
990x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
1000x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
1010x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
1020x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
1030x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
1040x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
1050x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
1060x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
1070x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
1080x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
1090x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
1100x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
1110x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
1120x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
1130x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
114},{
115/* nibble 3 */
1160x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
1170x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
1180x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
1190x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
1200x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
1210x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
1220x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
1230x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
1240x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
1250x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
1260x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
1270x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
1280x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
1290x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
1300x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
1310x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
132},{
133/* nibble 4 */
1340x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
1350x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
1360x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
1370x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
1380x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
1390x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
1400x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
1410x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
1420x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
1430x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
1440x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
1450x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
1460x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
1470x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
1480x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
1490x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
150},{
151/* nibble 5 */
1520x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
1530x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
1540x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
1550x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
1560x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
1570x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
1580x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
1590x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
1600x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
1610x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
1620x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
1630x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
1640x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
1650x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
1660x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
1670x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
168},{
169/* nibble 6 */
1700x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
1710x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
1720x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
1730x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
1740x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
1750x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
1760x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
1770x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
1780x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
1790x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
1800x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
1810x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
1820x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
1830x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
1840x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
1850x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
186},{
187/* nibble 7 */
1880x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
1890x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
1900x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
1910x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
1920x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
1930x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
1940x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
1950x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
1960x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
1970x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
1980x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
1990x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
2000x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
2010x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
2020x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
2030x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
204}};
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
new file mode 100644
index 0000000000..0373db469c
--- /dev/null
+++ b/src/lib/libcrypto/des/str2key.c
@@ -0,0 +1,173 @@
1/* crypto/des/str2key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void DES_string_to_key(const char *str, DES_cblock *key)
62 {
63 DES_key_schedule ks;
64 int i,length;
65 register unsigned char j;
66
67 memset(key,0,8);
68 length=strlen(str);
69#ifdef OLD_STR_TO_KEY
70 for (i=0; i<length; i++)
71 (*key)[i%8]^=(str[i]<<1);
72#else /* MIT COMPATIBLE */
73 for (i=0; i<length; i++)
74 {
75 j=str[i];
76 if ((i%16) < 8)
77 (*key)[i%8]^=(j<<1);
78 else
79 {
80 /* Reverse the bit order 05/05/92 eay */
81 j=((j<<4)&0xf0)|((j>>4)&0x0f);
82 j=((j<<2)&0xcc)|((j>>2)&0x33);
83 j=((j<<1)&0xaa)|((j>>1)&0x55);
84 (*key)[7-(i%8)]^=j;
85 }
86 }
87#endif
88 DES_set_odd_parity(key);
89#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
90 if(DES_is_weak_key(key))
91 (*key)[7] ^= 0xF0;
92 DES_set_key(key,&ks);
93#else
94 DES_set_key_unchecked(key,&ks);
95#endif
96 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
97 OPENSSL_cleanse(&ks,sizeof(ks));
98 DES_set_odd_parity(key);
99 }
100
101void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
102 {
103 DES_key_schedule ks;
104 int i,length;
105 register unsigned char j;
106
107 memset(key1,0,8);
108 memset(key2,0,8);
109 length=strlen(str);
110#ifdef OLD_STR_TO_KEY
111 if (length <= 8)
112 {
113 for (i=0; i<length; i++)
114 {
115 (*key2)[i]=(*key1)[i]=(str[i]<<1);
116 }
117 }
118 else
119 {
120 for (i=0; i<length; i++)
121 {
122 if ((i/8)&1)
123 (*key2)[i%8]^=(str[i]<<1);
124 else
125 (*key1)[i%8]^=(str[i]<<1);
126 }
127 }
128#else /* MIT COMPATIBLE */
129 for (i=0; i<length; i++)
130 {
131 j=str[i];
132 if ((i%32) < 16)
133 {
134 if ((i%16) < 8)
135 (*key1)[i%8]^=(j<<1);
136 else
137 (*key2)[i%8]^=(j<<1);
138 }
139 else
140 {
141 j=((j<<4)&0xf0)|((j>>4)&0x0f);
142 j=((j<<2)&0xcc)|((j>>2)&0x33);
143 j=((j<<1)&0xaa)|((j>>1)&0x55);
144 if ((i%16) < 8)
145 (*key1)[7-(i%8)]^=j;
146 else
147 (*key2)[7-(i%8)]^=j;
148 }
149 }
150 if (length <= 8) memcpy(key2,key1,8);
151#endif
152 DES_set_odd_parity(key1);
153 DES_set_odd_parity(key2);
154#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
155 if(DES_is_weak_key(key1))
156 (*key1)[7] ^= 0xF0;
157 DES_set_key(key1,&ks);
158#else
159 DES_set_key_unchecked(key1,&ks);
160#endif
161 DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1);
162#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
163 if(DES_is_weak_key(key2))
164 (*key2)[7] ^= 0xF0;
165 DES_set_key(key2,&ks);
166#else
167 DES_set_key_unchecked(key2,&ks);
168#endif
169 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
170 OPENSSL_cleanse(&ks,sizeof(ks));
171 DES_set_odd_parity(key1);
172 DES_set_odd_parity(key2);
173 }
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc
index f6ec8e8831..0864285ef6 100644
--- a/src/lib/libcrypto/des/times/usparc.cc
+++ b/src/lib/libcrypto/des/times/usparc.cc
@@ -2,7 +2,7 @@ solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2 2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts' 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. 4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I belive the difference is tied up in optimisation that the compiler 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 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 7routines are being linked from a library. I'll record the higher
8speed since if performance is everything, you can always inline 8speed since if performance is everything, you can always inline
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
new file mode 100644
index 0000000000..47246eb466
--- /dev/null
+++ b/src/lib/libcrypto/des/xcbc_enc.c
@@ -0,0 +1,195 @@
1/* crypto/des/xcbc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* RSA's DESX */
62
63static unsigned char desx_white_in2out[256]={
640xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
650x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
660x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
670x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C,
680x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60,
690x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA,
700xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E,
710xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF,
720x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6,
730xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3,
740x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C,
750xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2,
760x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5,
770x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5,
780x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F,
790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
80 };
81
82void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
83 DES_cblock *out_white)
84 {
85 int out0,out1;
86 int i;
87 const unsigned char *key = &(*des_key)[0];
88 const unsigned char *in = &(*in_white)[0];
89 unsigned char *out = &(*out_white)[0];
90
91 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
92 out0=out1=0;
93 for (i=0; i<8; i++)
94 {
95 out[i]=key[i]^desx_white_in2out[out0^out1];
96 out0=out1;
97 out1=(int)out[i&0x07];
98 }
99
100 out0=out[0];
101 out1=out[i];
102 for (i=0; i<8; i++)
103 {
104 out[i]=in[i]^desx_white_in2out[out0^out1];
105 out0=out1;
106 out1=(int)out[i&0x07];
107 }
108 }
109
110void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
111 long length, DES_key_schedule *schedule,
112 DES_cblock *ivec, const_DES_cblock *inw,
113 const_DES_cblock *outw, int enc)
114 {
115 register DES_LONG tin0,tin1;
116 register DES_LONG tout0,tout1,xor0,xor1;
117 register DES_LONG inW0,inW1,outW0,outW1;
118 register const unsigned char *in2;
119 register long l=length;
120 DES_LONG tin[2];
121 unsigned char *iv;
122
123 in2 = &(*inw)[0];
124 c2l(in2,inW0);
125 c2l(in2,inW1);
126 in2 = &(*outw)[0];
127 c2l(in2,outW0);
128 c2l(in2,outW1);
129
130 iv = &(*ivec)[0];
131
132 if (enc)
133 {
134 c2l(iv,tout0);
135 c2l(iv,tout1);
136 for (l-=8; l>=0; l-=8)
137 {
138 c2l(in,tin0);
139 c2l(in,tin1);
140 tin0^=tout0^inW0; tin[0]=tin0;
141 tin1^=tout1^inW1; tin[1]=tin1;
142 DES_encrypt1(tin,schedule,DES_ENCRYPT);
143 tout0=tin[0]^outW0; l2c(tout0,out);
144 tout1=tin[1]^outW1; l2c(tout1,out);
145 }
146 if (l != -8)
147 {
148 c2ln(in,tin0,tin1,l+8);
149 tin0^=tout0^inW0; tin[0]=tin0;
150 tin1^=tout1^inW1; tin[1]=tin1;
151 DES_encrypt1(tin,schedule,DES_ENCRYPT);
152 tout0=tin[0]^outW0; l2c(tout0,out);
153 tout1=tin[1]^outW1; l2c(tout1,out);
154 }
155 iv = &(*ivec)[0];
156 l2c(tout0,iv);
157 l2c(tout1,iv);
158 }
159 else
160 {
161 c2l(iv,xor0);
162 c2l(iv,xor1);
163 for (l-=8; l>0; l-=8)
164 {
165 c2l(in,tin0); tin[0]=tin0^outW0;
166 c2l(in,tin1); tin[1]=tin1^outW1;
167 DES_encrypt1(tin,schedule,DES_DECRYPT);
168 tout0=tin[0]^xor0^inW0;
169 tout1=tin[1]^xor1^inW1;
170 l2c(tout0,out);
171 l2c(tout1,out);
172 xor0=tin0;
173 xor1=tin1;
174 }
175 if (l != -8)
176 {
177 c2l(in,tin0); tin[0]=tin0^outW0;
178 c2l(in,tin1); tin[1]=tin1^outW1;
179 DES_encrypt1(tin,schedule,DES_DECRYPT);
180 tout0=tin[0]^xor0^inW0;
181 tout1=tin[1]^xor1^inW1;
182 l2cn(tout0,tout1,out,l+8);
183 xor0=tin0;
184 xor1=tin1;
185 }
186
187 iv = &(*ivec)[0];
188 l2c(xor0,iv);
189 l2c(xor1,iv);
190 }
191 tin0=tin1=tout0=tout1=xor0=xor1=0;
192 inW0=inW1=outW0=outW1=0;
193 tin[0]=tin[1]=0;
194 }
195
diff --git a/src/lib/libcrypto/dh/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
new file mode 100644
index 0000000000..0aff7fe21f
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh.h
@@ -0,0 +1,213 @@
1/* crypto/dh/dh.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DH_H
60#define HEADER_DH_H
61
62#ifdef OPENSSL_NO_DH
63#error DH is disabled.
64#endif
65
66#ifndef OPENSSL_NO_BIO
67#include <openssl/bio.h>
68#endif
69#include <openssl/bn.h>
70#include <openssl/crypto.h>
71#include <openssl/ossl_typ.h>
72
73#define DH_FLAG_CACHE_MONT_P 0x01
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79typedef struct dh_st DH;
80
81typedef struct dh_method {
82 const char *name;
83 /* Methods here */
84 int (*generate_key)(DH *dh);
85 int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh);
86 int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a,
87 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
88 BN_MONT_CTX *m_ctx); /* Can be null */
89
90 int (*init)(DH *dh);
91 int (*finish)(DH *dh);
92 int flags;
93 char *app_data;
94} DH_METHOD;
95
96struct dh_st
97 {
98 /* This first argument is used to pick up errors when
99 * a DH is passed instead of a EVP_PKEY */
100 int pad;
101 int version;
102 BIGNUM *p;
103 BIGNUM *g;
104 int length; /* optional */
105 BIGNUM *pub_key; /* g^x */
106 BIGNUM *priv_key; /* x */
107
108 int flags;
109 char *method_mont_p;
110 /* Place holders if we want to do X9.42 DH */
111 BIGNUM *q;
112 BIGNUM *j;
113 unsigned char *seed;
114 int seedlen;
115 BIGNUM *counter;
116
117 int references;
118 CRYPTO_EX_DATA ex_data;
119 const DH_METHOD *meth;
120 ENGINE *engine;
121 };
122
123#define DH_GENERATOR_2 2
124/* #define DH_GENERATOR_3 3 */
125#define DH_GENERATOR_5 5
126
127/* DH_check error codes */
128#define DH_CHECK_P_NOT_PRIME 0x01
129#define DH_CHECK_P_NOT_SAFE_PRIME 0x02
130#define DH_UNABLE_TO_CHECK_GENERATOR 0x04
131#define DH_NOT_SUITABLE_GENERATOR 0x08
132
133/* DH_check_pub_key error codes */
134#define DH_CHECK_PUBKEY_TOO_SMALL 0x01
135#define DH_CHECK_PUBKEY_TOO_LARGE 0x02
136
137/* primes p where (p-1)/2 is prime too are called "safe"; we define
138 this for backward compatibility: */
139#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME
140
141#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
142 (char *(*)())d2i_DHparams,(char *)(x))
143#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
144 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
145#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
146 (unsigned char *)(x))
147#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
148 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
149#ifdef __cplusplus
150#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \
151 (unsigned char *)(x))
152#else
153#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
154 (unsigned char *)(x))
155#endif
156
157const DH_METHOD *DH_OpenSSL(void);
158
159void DH_set_default_method(const DH_METHOD *meth);
160const DH_METHOD *DH_get_default_method(void);
161int DH_set_method(DH *dh, const DH_METHOD *meth);
162DH *DH_new_method(ENGINE *engine);
163
164DH * DH_new(void);
165void DH_free(DH *dh);
166int DH_up_ref(DH *dh);
167int DH_size(const DH *dh);
168int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
169 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
170int DH_set_ex_data(DH *d, int idx, void *arg);
171void *DH_get_ex_data(DH *d, int idx);
172DH * DH_generate_parameters(int prime_len,int generator,
173 void (*callback)(int,int,void *),void *cb_arg);
174int DH_check(const DH *dh,int *codes);
175int DH_check_pub_key(const DH *dh,const BIGNUM *pub_key, int *codes);
176int DH_generate_key(DH *dh);
177int DH_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);
178DH * d2i_DHparams(DH **a,const unsigned char **pp, long length);
179int i2d_DHparams(const DH *a,unsigned char **pp);
180#ifndef OPENSSL_NO_FP_API
181int DHparams_print_fp(FILE *fp, const DH *x);
182#endif
183#ifndef OPENSSL_NO_BIO
184int DHparams_print(BIO *bp, const DH *x);
185#else
186int DHparams_print(char *bp, const DH *x);
187#endif
188
189/* BEGIN ERROR CODES */
190/* The following lines are auto generated by the script mkerr.pl. Any changes
191 * made after this point may be overwritten when the script is next run.
192 */
193void ERR_load_DH_strings(void);
194
195/* Error codes for the DH functions. */
196
197/* Function codes. */
198#define DH_F_DHPARAMS_PRINT 100
199#define DH_F_DHPARAMS_PRINT_FP 101
200#define DH_F_DH_COMPUTE_KEY 102
201#define DH_F_DH_GENERATE_KEY 103
202#define DH_F_DH_GENERATE_PARAMETERS 104
203#define DH_F_DH_NEW_METHOD 105
204
205/* Reason codes. */
206#define DH_R_BAD_GENERATOR 101
207#define DH_R_NO_PRIVATE_VALUE 100
208#define DH_R_INVALID_PUBKEY 102
209
210#ifdef __cplusplus
211}
212#endif
213#endif
diff --git a/src/lib/libcrypto/dh/dh_asn1.c b/src/lib/libcrypto/dh/dh_asn1.c
new file mode 100644
index 0000000000..769b5b68c5
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh_asn1.c
@@ -0,0 +1,87 @@
1/* dh_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/dh.h>
63#include <openssl/objects.h>
64#include <openssl/asn1t.h>
65
66/* Override the default free and new methods */
67static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
68{
69 if(operation == ASN1_OP_NEW_PRE) {
70 *pval = (ASN1_VALUE *)DH_new();
71 if(*pval) return 2;
72 return 0;
73 } else if(operation == ASN1_OP_FREE_PRE) {
74 DH_free((DH *)*pval);
75 *pval = NULL;
76 return 2;
77 }
78 return 1;
79}
80
81ASN1_SEQUENCE_cb(DHparams, dh_cb) = {
82 ASN1_SIMPLE(DH, p, BIGNUM),
83 ASN1_SIMPLE(DH, g, BIGNUM),
84 ASN1_OPT(DH, length, ZLONG),
85} ASN1_SEQUENCE_END_cb(DH, DHparams)
86
87IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DH, DHparams, DHparams)
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
new file mode 100644
index 0000000000..17debff62d
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh_check.c
@@ -0,0 +1,146 @@
1/* crypto/dh/dh_check.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/dh.h>
63
64/* Check that p is a safe prime and
65 * if g is 2, 3 or 5, check that is is a suitable generator
66 * where
67 * for 2, p mod 24 == 11
68 * for 3, p mod 12 == 5
69 * for 5, p mod 10 == 3 or 7
70 * should hold.
71 */
72
73#ifndef OPENSSL_FIPS
74
75int DH_check(const DH *dh, int *ret)
76 {
77 int ok=0;
78 BN_CTX *ctx=NULL;
79 BN_ULONG l;
80 BIGNUM *q=NULL;
81
82 *ret=0;
83 ctx=BN_CTX_new();
84 if (ctx == NULL) goto err;
85 q=BN_new();
86 if (q == NULL) goto err;
87
88 if (BN_is_word(dh->g,DH_GENERATOR_2))
89 {
90 l=BN_mod_word(dh->p,24);
91 if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
92 }
93#if 0
94 else if (BN_is_word(dh->g,DH_GENERATOR_3))
95 {
96 l=BN_mod_word(dh->p,12);
97 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
98 }
99#endif
100 else if (BN_is_word(dh->g,DH_GENERATOR_5))
101 {
102 l=BN_mod_word(dh->p,10);
103 if ((l != 3) && (l != 7))
104 *ret|=DH_NOT_SUITABLE_GENERATOR;
105 }
106 else
107 *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
108
109 if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
110 *ret|=DH_CHECK_P_NOT_PRIME;
111 else
112 {
113 if (!BN_rshift1(q,dh->p)) goto err;
114 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
115 *ret|=DH_CHECK_P_NOT_SAFE_PRIME;
116 }
117 ok=1;
118err:
119 if (ctx != NULL) BN_CTX_free(ctx);
120 if (q != NULL) BN_free(q);
121 return(ok);
122 }
123
124int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
125 {
126 int ok=0;
127 BIGNUM *q=NULL;
128
129 *ret=0;
130 q=BN_new();
131 if (q == NULL) goto err;
132 BN_set_word(q,1);
133 if (BN_cmp(pub_key,q) <= 0)
134 *ret|=DH_CHECK_PUBKEY_TOO_SMALL;
135 BN_copy(q,dh->p);
136 BN_sub_word(q,1);
137 if (BN_cmp(pub_key,q) >= 0)
138 *ret|=DH_CHECK_PUBKEY_TOO_LARGE;
139
140 ok = 1;
141err:
142 if (q != NULL) BN_free(q);
143 return(ok);
144 }
145
146#endif
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
new file mode 100644
index 0000000000..914b8a9c53
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh_err.c
@@ -0,0 +1,101 @@
1/* crypto/dh/dh_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dh.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA DH_str_functs[]=
68 {
69{ERR_PACK(0,DH_F_DHPARAMS_PRINT,0), "DHparams_print"},
70{ERR_PACK(0,DH_F_DHPARAMS_PRINT_FP,0), "DHparams_print_fp"},
71{ERR_PACK(0,DH_F_DH_COMPUTE_KEY,0), "DH_compute_key"},
72{ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"},
73{ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"},
74{ERR_PACK(0,DH_F_DH_NEW_METHOD,0), "DH_new_method"},
75{0,NULL}
76 };
77
78static ERR_STRING_DATA DH_str_reasons[]=
79 {
80{DH_R_BAD_GENERATOR ,"bad generator"},
81{DH_R_NO_PRIVATE_VALUE ,"no private value"},
82{DH_R_INVALID_PUBKEY ,"invalid public key"},
83{0,NULL}
84 };
85
86#endif
87
88void ERR_load_DH_strings(void)
89 {
90 static int init=1;
91
92 if (init)
93 {
94 init=0;
95#ifndef OPENSSL_NO_ERR
96 ERR_load_strings(ERR_LIB_DH,DH_str_functs);
97 ERR_load_strings(ERR_LIB_DH,DH_str_reasons);
98#endif
99
100 }
101 }
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
new file mode 100644
index 0000000000..23777f5a16
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh_gen.c
@@ -0,0 +1,175 @@
1/* crypto/dh/dh_gen.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/dh.h>
63
64/* We generate DH parameters as follows
65 * find a prime q which is prime_len/2 bits long.
66 * p=(2*q)+1 or (p-1)/2 = q
67 * For this case, g is a generator if
68 * g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
69 * Since the factors of p-1 are q and 2, we just need to check
70 * g^2 mod p != 1 and g^q mod p != 1.
71 *
72 * Having said all that,
73 * there is another special case method for the generators 2, 3 and 5.
74 * for 2, p mod 24 == 11
75 * for 3, p mod 12 == 5 <<<<< does not work for safe primes.
76 * for 5, p mod 10 == 3 or 7
77 *
78 * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
79 * special generators and for answering some of my questions.
80 *
81 * I've implemented the second simple method :-).
82 * Since DH should be using a safe prime (both p and q are prime),
83 * this generator function can take a very very long time to run.
84 */
85/* Actually there is no reason to insist that 'generator' be a generator.
86 * It's just as OK (and in some sense better) to use a generator of the
87 * order-q subgroup.
88 */
89
90#ifndef OPENSSL_FIPS
91
92DH *DH_generate_parameters(int prime_len, int generator,
93 void (*callback)(int,int,void *), void *cb_arg)
94 {
95 BIGNUM *p=NULL,*t1,*t2;
96 DH *ret=NULL;
97 int g,ok= -1;
98 BN_CTX *ctx=NULL;
99
100 ret=DH_new();
101 if (ret == NULL) goto err;
102 ctx=BN_CTX_new();
103 if (ctx == NULL) goto err;
104 BN_CTX_start(ctx);
105 t1 = BN_CTX_get(ctx);
106 t2 = BN_CTX_get(ctx);
107 if (t1 == NULL || t2 == NULL) goto err;
108
109 if (generator <= 1)
110 {
111 DHerr(DH_F_DH_GENERATE_PARAMETERS, DH_R_BAD_GENERATOR);
112 goto err;
113 }
114 if (generator == DH_GENERATOR_2)
115 {
116 if (!BN_set_word(t1,24)) goto err;
117 if (!BN_set_word(t2,11)) goto err;
118 g=2;
119 }
120#if 0 /* does not work for safe primes */
121 else if (generator == DH_GENERATOR_3)
122 {
123 if (!BN_set_word(t1,12)) goto err;
124 if (!BN_set_word(t2,5)) goto err;
125 g=3;
126 }
127#endif
128 else if (generator == DH_GENERATOR_5)
129 {
130 if (!BN_set_word(t1,10)) goto err;
131 if (!BN_set_word(t2,3)) goto err;
132 /* BN_set_word(t3,7); just have to miss
133 * out on these ones :-( */
134 g=5;
135 }
136 else
137 {
138 /* in the general case, don't worry if 'generator' is a
139 * generator or not: since we are using safe primes,
140 * it will generate either an order-q or an order-2q group,
141 * which both is OK */
142 if (!BN_set_word(t1,2)) goto err;
143 if (!BN_set_word(t2,1)) goto err;
144 g=generator;
145 }
146
147 p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
148 if (p == NULL) goto err;
149 if (callback != NULL) callback(3,0,cb_arg);
150 ret->p=p;
151 ret->g=BN_new();
152 if (ret->g == NULL) goto err;
153 if (!BN_set_word(ret->g,g)) goto err;
154 ok=1;
155err:
156 if (ok == -1)
157 {
158 DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB);
159 ok=0;
160 }
161
162 if (ctx != NULL)
163 {
164 BN_CTX_end(ctx);
165 BN_CTX_free(ctx);
166 }
167 if (!ok && (ret != NULL))
168 {
169 DH_free(ret);
170 ret=NULL;
171 }
172 return(ret);
173 }
174
175#endif
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
new file mode 100644
index 0000000000..648766a6ec
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -0,0 +1,233 @@
1/* crypto/dh/dh_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rand.h>
63#include <openssl/dh.h>
64
65#ifndef OPENSSL_FIPS
66
67static int generate_key(DH *dh);
68static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
69static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
70 const BIGNUM *a, const BIGNUM *p,
71 const BIGNUM *m, BN_CTX *ctx,
72 BN_MONT_CTX *m_ctx);
73static int dh_init(DH *dh);
74static int dh_finish(DH *dh);
75
76int DH_generate_key(DH *dh)
77 {
78 return dh->meth->generate_key(dh);
79 }
80
81int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
82 {
83 return dh->meth->compute_key(key, pub_key, dh);
84 }
85
86static DH_METHOD dh_ossl = {
87"OpenSSL DH Method",
88generate_key,
89compute_key,
90dh_bn_mod_exp,
91dh_init,
92dh_finish,
930,
94NULL
95};
96
97const DH_METHOD *DH_OpenSSL(void)
98{
99 return &dh_ossl;
100}
101
102static int generate_key(DH *dh)
103 {
104 int ok=0;
105 int generate_new_key=0;
106 unsigned l;
107 BN_CTX *ctx;
108 BN_MONT_CTX *mont;
109 BIGNUM *pub_key=NULL,*priv_key=NULL;
110
111 ctx = BN_CTX_new();
112 if (ctx == NULL) goto err;
113
114 if (dh->priv_key == NULL)
115 {
116 priv_key=BN_new();
117 if (priv_key == NULL) goto err;
118 generate_new_key=1;
119 }
120 else
121 priv_key=dh->priv_key;
122
123 if (dh->pub_key == NULL)
124 {
125 pub_key=BN_new();
126 if (pub_key == NULL) goto err;
127 }
128 else
129 pub_key=dh->pub_key;
130
131 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
132 {
133 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
134 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
135 dh->p,ctx)) goto err;
136 }
137 mont=(BN_MONT_CTX *)dh->method_mont_p;
138
139 if (generate_new_key)
140 {
141 l = dh->length ? dh->length : BN_num_bits(dh->p)-1; /* secret exponent length */
142 if (!BN_rand(priv_key, l, 0, 0)) goto err;
143 }
144 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, priv_key,dh->p,ctx,mont))
145 goto err;
146
147 dh->pub_key=pub_key;
148 dh->priv_key=priv_key;
149 ok=1;
150err:
151 if (ok != 1)
152 DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);
153
154 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
155 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
156 BN_CTX_free(ctx);
157 return(ok);
158 }
159
160static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
161 {
162 BN_CTX *ctx;
163 BN_MONT_CTX *mont;
164 BIGNUM *tmp;
165 int ret= -1;
166 int check_result;
167
168 ctx = BN_CTX_new();
169 if (ctx == NULL) goto err;
170 BN_CTX_start(ctx);
171 tmp = BN_CTX_get(ctx);
172
173 if (dh->priv_key == NULL)
174 {
175 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
176 goto err;
177 }
178 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
179 {
180 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
181 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
182 dh->p,ctx)) goto err;
183 }
184
185 mont=(BN_MONT_CTX *)dh->method_mont_p;
186
187 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result)
188 {
189 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_INVALID_PUBKEY);
190 goto err;
191 }
192 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
193 {
194 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
195 goto err;
196 }
197
198 ret=BN_bn2bin(tmp,key);
199err:
200 BN_CTX_end(ctx);
201 BN_CTX_free(ctx);
202 return(ret);
203 }
204
205static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
206 const BIGNUM *a, const BIGNUM *p,
207 const BIGNUM *m, BN_CTX *ctx,
208 BN_MONT_CTX *m_ctx)
209 {
210 if (a->top == 1)
211 {
212 BN_ULONG A = a->d[0];
213 return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx);
214 }
215 else
216 return BN_mod_exp_mont(r,a,p,m,ctx,m_ctx);
217 }
218
219
220static int dh_init(DH *dh)
221 {
222 dh->flags |= DH_FLAG_CACHE_MONT_P;
223 return(1);
224 }
225
226static int dh_finish(DH *dh)
227 {
228 if(dh->method_mont_p)
229 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
230 return(1);
231 }
232
233#endif
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
new file mode 100644
index 0000000000..09965ee2ea
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -0,0 +1,247 @@
1/* crypto/dh/dh_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/dh.h>
63#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h>
65#endif
66
67const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
68
69static const DH_METHOD *default_DH_method = NULL;
70
71void DH_set_default_method(const DH_METHOD *meth)
72 {
73 default_DH_method = meth;
74 }
75
76const DH_METHOD *DH_get_default_method(void)
77 {
78 if(!default_DH_method)
79 default_DH_method = DH_OpenSSL();
80 return default_DH_method;
81 }
82
83int DH_set_method(DH *dh, const DH_METHOD *meth)
84 {
85 /* NB: The caller is specifically setting a method, so it's not up to us
86 * to deal with which ENGINE it comes from. */
87 const DH_METHOD *mtmp;
88 mtmp = dh->meth;
89 if (mtmp->finish) mtmp->finish(dh);
90#ifndef OPENSSL_NO_ENGINE
91 if (dh->engine)
92 {
93 ENGINE_finish(dh->engine);
94 dh->engine = NULL;
95 }
96#endif
97 dh->meth = meth;
98 if (meth->init) meth->init(dh);
99 return 1;
100 }
101
102DH *DH_new(void)
103 {
104 return DH_new_method(NULL);
105 }
106
107DH *DH_new_method(ENGINE *engine)
108 {
109 DH *ret;
110
111 ret=(DH *)OPENSSL_malloc(sizeof(DH));
112 if (ret == NULL)
113 {
114 DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);
115 return(NULL);
116 }
117
118 ret->meth = DH_get_default_method();
119#ifndef OPENSSL_NO_ENGINE
120 if (engine)
121 {
122 if (!ENGINE_init(engine))
123 {
124 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
125 OPENSSL_free(ret);
126 return NULL;
127 }
128 ret->engine = engine;
129 }
130 else
131 ret->engine = ENGINE_get_default_DH();
132 if(ret->engine)
133 {
134 ret->meth = ENGINE_get_DH(ret->engine);
135 if(!ret->meth)
136 {
137 DHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB);
138 ENGINE_finish(ret->engine);
139 OPENSSL_free(ret);
140 return NULL;
141 }
142 }
143#endif
144
145 ret->pad=0;
146 ret->version=0;
147 ret->p=NULL;
148 ret->g=NULL;
149 ret->length=0;
150 ret->pub_key=NULL;
151 ret->priv_key=NULL;
152 ret->q=NULL;
153 ret->j=NULL;
154 ret->seed = NULL;
155 ret->seedlen = 0;
156 ret->counter = NULL;
157 ret->method_mont_p=NULL;
158 ret->references = 1;
159 ret->flags=ret->meth->flags;
160 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
161 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
162 {
163#ifndef OPENSSL_NO_ENGINE
164 if (ret->engine)
165 ENGINE_finish(ret->engine);
166#endif
167 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
168 OPENSSL_free(ret);
169 ret=NULL;
170 }
171 return(ret);
172 }
173
174void DH_free(DH *r)
175 {
176 int i;
177 if(r == NULL) return;
178 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
179#ifdef REF_PRINT
180 REF_PRINT("DH",r);
181#endif
182 if (i > 0) return;
183#ifdef REF_CHECK
184 if (i < 0)
185 {
186 fprintf(stderr,"DH_free, bad reference count\n");
187 abort();
188 }
189#endif
190
191 if (r->meth->finish)
192 r->meth->finish(r);
193#ifndef OPENSSL_NO_ENGINE
194 if (r->engine)
195 ENGINE_finish(r->engine);
196#endif
197
198 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data);
199
200 if (r->p != NULL) BN_clear_free(r->p);
201 if (r->g != NULL) BN_clear_free(r->g);
202 if (r->q != NULL) BN_clear_free(r->q);
203 if (r->j != NULL) BN_clear_free(r->j);
204 if (r->seed) OPENSSL_free(r->seed);
205 if (r->counter != NULL) BN_clear_free(r->counter);
206 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
207 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
208 OPENSSL_free(r);
209 }
210
211int DH_up_ref(DH *r)
212 {
213 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DH);
214#ifdef REF_PRINT
215 REF_PRINT("DH",r);
216#endif
217#ifdef REF_CHECK
218 if (i < 2)
219 {
220 fprintf(stderr, "DH_up, bad reference count\n");
221 abort();
222 }
223#endif
224 return ((i > 1) ? 1 : 0);
225 }
226
227int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
228 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
229 {
230 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, argl, argp,
231 new_func, dup_func, free_func);
232 }
233
234int DH_set_ex_data(DH *d, int idx, void *arg)
235 {
236 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
237 }
238
239void *DH_get_ex_data(DH *d, int idx)
240 {
241 return(CRYPTO_get_ex_data(&d->ex_data,idx));
242 }
243
244int DH_size(const DH *dh)
245 {
246 return(BN_num_bytes(dh->p));
247 }
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c
index b76dede771..d75077f9fa 100644
--- a/src/lib/libcrypto/dh/dhtest.c
+++ b/src/lib/libcrypto/dh/dhtest.c
@@ -136,10 +136,6 @@ int main(int argc, char *argv[])
136 b->g=BN_dup(a->g); 136 b->g=BN_dup(a->g);
137 if ((b->p == NULL) || (b->g == NULL)) goto err; 137 if ((b->p == NULL) || (b->g == NULL)) goto err;
138 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; 139 if (!DH_generate_key(a)) goto err;
144 BIO_puts(out,"pri 1="); 140 BIO_puts(out,"pri 1=");
145 BN_print(out,a->priv_key); 141 BN_print(out,a->priv_key);
diff --git a/src/lib/libcrypto/doc/DH_generate_key.pod b/src/lib/libcrypto/doc/DH_generate_key.pod
new file mode 100644
index 0000000000..81f09fdf45
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_generate_key.pod
@@ -0,0 +1,50 @@
1=pod
2
3=head1 NAME
4
5DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_generate_key(DH *dh);
12
13 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
14
15=head1 DESCRIPTION
16
17DH_generate_key() performs the first step of a Diffie-Hellman key
18exchange by generating private and public DH values. By calling
19DH_compute_key(), these are combined with the other party's public
20value to compute the shared key.
21
22DH_generate_key() expects B<dh> to contain the shared parameters
23B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
24unless B<dh-E<gt>priv_key> is already set, and computes the
25corresponding public value B<dh-E<gt>pub_key>, which can then be
26published.
27
28DH_compute_key() computes the shared secret from the private DH value
29in B<dh> and the other party's public value in B<pub_key> and stores
30it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
31
32=head1 RETURN VALUES
33
34DH_generate_key() returns 1 on success, 0 otherwise.
35
36DH_compute_key() returns the size of the shared secret on success, -1
37on error.
38
39The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 SEE ALSO
42
43L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)>
44
45=head1 HISTORY
46
47DH_generate_key() and DH_compute_key() are available in all versions
48of SSLeay and OpenSSL.
49
50=cut
diff --git a/src/lib/libcrypto/doc/DH_generate_parameters.pod b/src/lib/libcrypto/doc/DH_generate_parameters.pod
new file mode 100644
index 0000000000..9081e9ea7c
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_generate_parameters.pod
@@ -0,0 +1,73 @@
1=pod
2
3=head1 NAME
4
5DH_generate_parameters, DH_check - generate and check Diffie-Hellman parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *DH_generate_parameters(int prime_len, int generator,
12 void (*callback)(int, int, void *), void *cb_arg);
13
14 int DH_check(DH *dh, int *codes);
15
16=head1 DESCRIPTION
17
18DH_generate_parameters() generates Diffie-Hellman parameters that can
19be shared among a group of users, and returns them in a newly
20allocated B<DH> structure. The pseudo-random number generator must be
21seeded prior to calling DH_generate_parameters().
22
23B<prime_len> is the length in bits of the safe prime to be generated.
24B<generator> is a small number E<gt> 1, typically 2 or 5.
25
26A callback function may be used to provide feedback about the progress
27of the key generation. If B<callback> is not B<NULL>, it will be
28called as described in L<BN_generate_prime(3)|BN_generate_prime(3)> while a random prime
29number is generated, and when a prime has been found, B<callback(3,
300, cb_arg)> is called.
31
32DH_check() validates Diffie-Hellman parameters. It checks that B<p> is
33a safe prime, and that B<g> is a suitable generator. In the case of an
34error, the bit flags DH_CHECK_P_NOT_SAFE_PRIME or
35DH_NOT_SUITABLE_GENERATOR are set in B<*codes>.
36DH_UNABLE_TO_CHECK_GENERATOR is set if the generator cannot be
37checked, i.e. it does not equal 2 or 5.
38
39=head1 RETURN VALUES
40
41DH_generate_parameters() returns a pointer to the DH structure, or
42NULL if the parameter generation fails. The error codes can be
43obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
44
45DH_check() returns 1 if the check could be performed, 0 otherwise.
46
47=head1 NOTES
48
49DH_generate_parameters() may run for several hours before finding a
50suitable prime.
51
52The parameters generated by DH_generate_parameters() are not to be
53used in signature schemes.
54
55=head1 BUGS
56
57If B<generator> is not 2 or 5, B<dh-E<gt>g>=B<generator> is not
58a usable generator.
59
60=head1 SEE ALSO
61
62L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
63L<DH_free(3)|DH_free(3)>
64
65=head1 HISTORY
66
67DH_check() is available in all versions of SSLeay and OpenSSL.
68The B<cb_arg> argument to DH_generate_parameters() was added in SSLeay 0.9.0.
69
70In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
71instead of DH_CHECK_P_NOT_SAFE_PRIME.
72
73=cut
diff --git a/src/lib/libcrypto/doc/DH_get_ex_new_index.pod b/src/lib/libcrypto/doc/DH_get_ex_new_index.pod
new file mode 100644
index 0000000000..fa5eab2650
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_get_ex_new_index.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data - add application specific data to DH structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DH_set_ex_data(DH *d, int idx, void *arg);
17
18 char *DH_get_ex_data(DH *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DH
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dh(3)|dh(3)>
30
31=head1 HISTORY
32
33DH_get_ex_new_index(), DH_set_ex_data() and DH_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DH_new.pod b/src/lib/libcrypto/doc/DH_new.pod
new file mode 100644
index 0000000000..60c930093e
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_new.pod
@@ -0,0 +1,40 @@
1=pod
2
3=head1 NAME
4
5DH_new, DH_free - allocate and free DH objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH* DH_new(void);
12
13 void DH_free(DH *dh);
14
15=head1 DESCRIPTION
16
17DH_new() allocates and initializes a B<DH> structure.
18
19DH_free() frees the B<DH> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DH_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28DH_free() returns no value.
29
30=head1 SEE ALSO
31
32L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
33L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
34L<DH_generate_key(3)|DH_generate_key(3)>
35
36=head1 HISTORY
37
38DH_new() and DH_free() are available in all versions of SSLeay and OpenSSL.
39
40=cut
diff --git a/src/lib/libcrypto/doc/DH_set_method.pod b/src/lib/libcrypto/doc/DH_set_method.pod
new file mode 100644
index 0000000000..73261fc467
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_set_method.pod
@@ -0,0 +1,129 @@
1=pod
2
3=head1 NAME
4
5DH_set_default_method, DH_get_default_method,
6DH_set_method, DH_new_method, DH_OpenSSL - select DH method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11 #include <openssl/engine.h>
12
13 void DH_set_default_method(const DH_METHOD *meth);
14
15 const DH_METHOD *DH_get_default_method(void);
16
17 int DH_set_method(DH *dh, const DH_METHOD *meth);
18
19 DH *DH_new_method(ENGINE *engine);
20
21 const DH_METHOD *DH_OpenSSL(void);
22
23=head1 DESCRIPTION
24
25A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
26operations. By modifying the method, alternative implementations
27such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
28important information about how these DH API functions are affected by the use
29of B<ENGINE> API calls.
30
31Initially, the default DH_METHOD is the OpenSSL internal implementation, as
32returned by DH_OpenSSL().
33
34DH_set_default_method() makes B<meth> the default method for all DH
35structures created later. B<NB>: This is true only whilst no ENGINE has been set
36as a default for DH, so this function is no longer recommended.
37
38DH_get_default_method() returns a pointer to the current default DH_METHOD.
39However, the meaningfulness of this result is dependant on whether the ENGINE
40API is being used, so this function is no longer recommended.
41
42DH_set_method() selects B<meth> to perform all operations using the key B<dh>.
43This will replace the DH_METHOD used by the DH key and if the previous method
44was supplied by an ENGINE, the handle to that ENGINE will be released during the
45change. It is possible to have DH keys that only work with certain DH_METHOD
46implementations (eg. from an ENGINE module that supports embedded
47hardware-protected keys), and in such cases attempting to change the DH_METHOD
48for the key can have unexpected results.
49
50DH_new_method() allocates and initializes a DH structure so that B<engine> will
51be used for the DH operations. If B<engine> is NULL, the default ENGINE for DH
52operations is used, and if no default ENGINE is set, the DH_METHOD controlled by
53DH_set_default_method() is used.
54
55=head1 THE DH_METHOD STRUCTURE
56
57 typedef struct dh_meth_st
58 {
59 /* name of the implementation */
60 const char *name;
61
62 /* generate private and public DH values for key agreement */
63 int (*generate_key)(DH *dh);
64
65 /* compute shared secret */
66 int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
67
68 /* compute r = a ^ p mod m (May be NULL for some implementations) */
69 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
70 const BIGNUM *m, BN_CTX *ctx,
71 BN_MONT_CTX *m_ctx);
72
73 /* called at DH_new */
74 int (*init)(DH *dh);
75
76 /* called at DH_free */
77 int (*finish)(DH *dh);
78
79 int flags;
80
81 char *app_data; /* ?? */
82
83 } DH_METHOD;
84
85=head1 RETURN VALUES
86
87DH_OpenSSL() and DH_get_default_method() return pointers to the respective
88B<DH_METHOD>s.
89
90DH_set_default_method() returns no value.
91
92DH_set_method() returns non-zero if the provided B<meth> was successfully set as
93the method for B<dh> (including unloading the ENGINE handle if the previous
94method was supplied by an ENGINE).
95
96DH_new_method() returns NULL and sets an error code that can be obtained by
97L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
98returns a pointer to the newly allocated structure.
99
100=head1 NOTES
101
102As of version 0.9.7, DH_METHOD implementations are grouped together with other
103algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
104default ENGINE is specified for DH functionality using an ENGINE API function,
105that will override any DH defaults set using the DH API (ie.
106DH_set_default_method()). For this reason, the ENGINE API is the recommended way
107to control default implementations for use in DH and other cryptographic
108algorithms.
109
110=head1 SEE ALSO
111
112L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
113
114=head1 HISTORY
115
116DH_set_default_method(), DH_get_default_method(), DH_set_method(),
117DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
118
119DH_set_default_openssl_method() and DH_get_default_openssl_method() replaced
120DH_set_default_method() and DH_get_default_method() respectively, and
121DH_set_method() and DH_new_method() were altered to use B<ENGINE>s rather than
122B<DH_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
1230.9.7, the handling of defaults in the ENGINE API was restructured so that this
124change was reversed, and behaviour of the other functions resembled more closely
125the previous behaviour. The behaviour of defaults in the ENGINE API now
126transparently overrides the behaviour of defaults in the DH API without
127requiring changing these function prototypes.
128
129=cut
diff --git a/src/lib/libcrypto/doc/DH_size.pod b/src/lib/libcrypto/doc/DH_size.pod
new file mode 100644
index 0000000000..97f26fda78
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DH_size - get Diffie-Hellman prime size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_size(DH *dh);
12
13=head1 DESCRIPTION
14
15This function returns the Diffie-Hellman size in bytes. It can be used
16to determine how much memory must be allocated for the shared secret
17computed by DH_compute_key().
18
19B<dh-E<gt>p> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dh(3)|dh(3)>, L<DH_generate_key(3)|DH_generate_key(3)>
28
29=head1 HISTORY
30
31DH_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/DSA_SIG_new.pod b/src/lib/libcrypto/doc/DSA_SIG_new.pod
new file mode 100644
index 0000000000..3ac6140038
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_SIG_new.pod
@@ -0,0 +1,40 @@
1=pod
2
3=head1 NAME
4
5DSA_SIG_new, DSA_SIG_free - allocate and free DSA signature objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_SIG_new(void);
12
13 void DSA_SIG_free(DSA_SIG *a);
14
15=head1 DESCRIPTION
16
17DSA_SIG_new() allocates and initializes a B<DSA_SIG> structure.
18
19DSA_SIG_free() frees the B<DSA_SIG> structure and its components. The
20values are erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_SIG_new() returns B<NULL> and sets an
25error code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_SIG_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
34L<DSA_do_sign(3)|DSA_do_sign(3)>
35
36=head1 HISTORY
37
38DSA_SIG_new() and DSA_SIG_free() were added in OpenSSL 0.9.3.
39
40=cut
diff --git a/src/lib/libcrypto/doc/DSA_do_sign.pod b/src/lib/libcrypto/doc/DSA_do_sign.pod
new file mode 100644
index 0000000000..5dfc733b20
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_do_sign.pod
@@ -0,0 +1,47 @@
1=pod
2
3=head1 NAME
4
5DSA_do_sign, DSA_do_verify - raw DSA signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
12
13 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
14 DSA_SIG *sig, DSA *dsa);
15
16=head1 DESCRIPTION
17
18DSA_do_sign() computes a digital signature on the B<len> byte message
19digest B<dgst> using the private key B<dsa> and returns it in a
20newly allocated B<DSA_SIG> structure.
21
22L<DSA_sign_setup(3)|DSA_sign_setup(3)> may be used to precompute part
23of the signing operation in case signature generation is
24time-critical.
25
26DSA_do_verify() verifies that the signature B<sig> matches a given
27message digest B<dgst> of size B<len>. B<dsa> is the signer's public
28key.
29
30=head1 RETURN VALUES
31
32DSA_do_sign() returns the signature, NULL on error. DSA_do_verify()
33returns 1 for a valid signature, 0 for an incorrect signature and -1
34on error. The error codes can be obtained by
35L<ERR_get_error(3)|ERR_get_error(3)>.
36
37=head1 SEE ALSO
38
39L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
40L<DSA_SIG_new(3)|DSA_SIG_new(3)>,
41L<DSA_sign(3)|DSA_sign(3)>
42
43=head1 HISTORY
44
45DSA_do_sign() and DSA_do_verify() were added in OpenSSL 0.9.3.
46
47=cut
diff --git a/src/lib/libcrypto/doc/DSA_dup_DH.pod b/src/lib/libcrypto/doc/DSA_dup_DH.pod
new file mode 100644
index 0000000000..7f6f0d1115
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_dup_DH.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DSA_dup_DH - create a DH structure out of DSA structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DH * DSA_dup_DH(const DSA *r);
12
13=head1 DESCRIPTION
14
15DSA_dup_DH() duplicates DSA parameters/keys as DH parameters/keys. q
16is lost during that conversion, but the resulting DH parameters
17contain its length.
18
19=head1 RETURN VALUE
20
21DSA_dup_DH() returns the new B<DH> structure, and NULL on error. The
22error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
23
24=head1 NOTE
25
26Be careful to avoid small subgroup attacks when using this.
27
28=head1 SEE ALSO
29
30L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
31
32=head1 HISTORY
33
34DSA_dup_DH() was added in OpenSSL 0.9.4.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DSA_generate_key.pod b/src/lib/libcrypto/doc/DSA_generate_key.pod
new file mode 100644
index 0000000000..af83ccfaa1
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_generate_key.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_key - generate DSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_generate_key(DSA *a);
12
13=head1 DESCRIPTION
14
15DSA_generate_key() expects B<a> to contain DSA parameters. It generates
16a new key pair and stores it in B<a-E<gt>pub_key> and B<a-E<gt>priv_key>.
17
18The PRNG must be seeded prior to calling DSA_generate_key().
19
20=head1 RETURN VALUE
21
22DSA_generate_key() returns 1 on success, 0 otherwise.
23The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
28L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>
29
30=head1 HISTORY
31
32DSA_generate_key() is available since SSLeay 0.8.
33
34=cut
diff --git a/src/lib/libcrypto/doc/DSA_generate_parameters.pod b/src/lib/libcrypto/doc/DSA_generate_parameters.pod
new file mode 100644
index 0000000000..be7c924ff8
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_generate_parameters.pod
@@ -0,0 +1,105 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_parameters - generate DSA parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA *DSA_generate_parameters(int bits, unsigned char *seed,
12 int seed_len, int *counter_ret, unsigned long *h_ret,
13 void (*callback)(int, int, void *), void *cb_arg);
14
15=head1 DESCRIPTION
16
17DSA_generate_parameters() generates primes p and q and a generator g
18for use in the DSA.
19
20B<bits> is the length of the prime to be generated; the DSS allows a
21maximum of 1024 bits.
22
23If B<seed> is B<NULL> or B<seed_len> E<lt> 20, the primes will be
24generated at random. Otherwise, the seed is used to generate
25them. If the given seed does not yield a prime q, a new random
26seed is chosen and placed at B<seed>.
27
28DSA_generate_parameters() places the iteration count in
29*B<counter_ret> and a counter used for finding a generator in
30*B<h_ret>, unless these are B<NULL>.
31
32A callback function may be used to provide feedback about the progress
33of the key generation. If B<callback> is not B<NULL>, it will be
34called as follows:
35
36=over 4
37
38=item *
39
40When a candidate for q is generated, B<callback(0, m++, cb_arg)> is called
41(m is 0 for the first candidate).
42
43=item *
44
45When a candidate for q has passed a test by trial division,
46B<callback(1, -1, cb_arg)> is called.
47While a candidate for q is tested by Miller-Rabin primality tests,
48B<callback(1, i, cb_arg)> is called in the outer loop
49(once for each witness that confirms that the candidate may be prime);
50i is the loop counter (starting at 0).
51
52=item *
53
54When a prime q has been found, B<callback(2, 0, cb_arg)> and
55B<callback(3, 0, cb_arg)> are called.
56
57=item *
58
59Before a candidate for p (other than the first) is generated and tested,
60B<callback(0, counter, cb_arg)> is called.
61
62=item *
63
64When a candidate for p has passed the test by trial division,
65B<callback(1, -1, cb_arg)> is called.
66While it is tested by the Miller-Rabin primality test,
67B<callback(1, i, cb_arg)> is called in the outer loop
68(once for each witness that confirms that the candidate may be prime).
69i is the loop counter (starting at 0).
70
71=item *
72
73When p has been found, B<callback(2, 1, cb_arg)> is called.
74
75=item *
76
77When the generator has been found, B<callback(3, 1, cb_arg)> is called.
78
79=back
80
81=head1 RETURN VALUE
82
83DSA_generate_parameters() returns a pointer to the DSA structure, or
84B<NULL> if the parameter generation fails. The error codes can be
85obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
86
87=head1 BUGS
88
89Seed lengths E<gt> 20 are not supported.
90
91=head1 SEE ALSO
92
93L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
94L<DSA_free(3)|DSA_free(3)>
95
96=head1 HISTORY
97
98DSA_generate_parameters() appeared in SSLeay 0.8. The B<cb_arg>
99argument was added in SSLeay 0.9.0.
100In versions up to OpenSSL 0.9.4, B<callback(1, ...)> was called
101in the inner loop of the Miller-Rabin test whenever it reached the
102squaring step (the parameters to B<callback> did not reveal how many
103witnesses had been tested); since OpenSSL 0.9.5, B<callback(1, ...)>
104is called as in BN_is_prime(3), i.e. once for each witness.
105=cut
diff --git a/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod
new file mode 100644
index 0000000000..4612e708ec
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data - add application specific data to DSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/DSA.h>
10
11 int DSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DSA_set_ex_data(DSA *d, int idx, void *arg);
17
18 char *DSA_get_ex_data(DSA *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DSA
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dsa(3)|dsa(3)>
30
31=head1 HISTORY
32
33DSA_get_ex_new_index(), DSA_set_ex_data() and DSA_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DSA_new.pod b/src/lib/libcrypto/doc/DSA_new.pod
new file mode 100644
index 0000000000..48e9b82a09
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_new.pod
@@ -0,0 +1,42 @@
1=pod
2
3=head1 NAME
4
5DSA_new, DSA_free - allocate and free DSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA* DSA_new(void);
12
13 void DSA_free(DSA *dsa);
14
15=head1 DESCRIPTION
16
17DSA_new() allocates and initializes a B<DSA> structure. It is equivalent to
18calling DSA_new_method(NULL).
19
20DSA_free() frees the B<DSA> structure and its components. The values are
21erased before the memory is returned to the system.
22
23=head1 RETURN VALUES
24
25If the allocation fails, DSA_new() returns B<NULL> and sets an error
26code that can be obtained by
27L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
28to the newly allocated structure.
29
30DSA_free() returns no value.
31
32=head1 SEE ALSO
33
34L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
35L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
36L<DSA_generate_key(3)|DSA_generate_key(3)>
37
38=head1 HISTORY
39
40DSA_new() and DSA_free() are available in all versions of SSLeay and OpenSSL.
41
42=cut
diff --git a/src/lib/libcrypto/doc/DSA_set_method.pod b/src/lib/libcrypto/doc/DSA_set_method.pod
new file mode 100644
index 0000000000..bc3cfb1f0a
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_set_method.pod
@@ -0,0 +1,143 @@
1=pod
2
3=head1 NAME
4
5DSA_set_default_method, DSA_get_default_method,
6DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dsa.h>
11 #include <openssl/engine.h>
12
13 void DSA_set_default_method(const DSA_METHOD *meth);
14
15 const DSA_METHOD *DSA_get_default_method(void);
16
17 int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
18
19 DSA *DSA_new_method(ENGINE *engine);
20
21 DSA_METHOD *DSA_OpenSSL(void);
22
23=head1 DESCRIPTION
24
25A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
26operations. By modifying the method, alternative implementations
27such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
28important information about how these DSA API functions are affected by the use
29of B<ENGINE> API calls.
30
31Initially, the default DSA_METHOD is the OpenSSL internal implementation,
32as returned by DSA_OpenSSL().
33
34DSA_set_default_method() makes B<meth> the default method for all DSA
35structures created later. B<NB>: This is true only whilst no ENGINE has
36been set as a default for DSA, so this function is no longer recommended.
37
38DSA_get_default_method() returns a pointer to the current default
39DSA_METHOD. However, the meaningfulness of this result is dependant on
40whether the ENGINE API is being used, so this function is no longer
41recommended.
42
43DSA_set_method() selects B<meth> to perform all operations using the key
44B<rsa>. This will replace the DSA_METHOD used by the DSA key and if the
45previous method was supplied by an ENGINE, the handle to that ENGINE will
46be released during the change. It is possible to have DSA keys that only
47work with certain DSA_METHOD implementations (eg. from an ENGINE module
48that supports embedded hardware-protected keys), and in such cases
49attempting to change the DSA_METHOD for the key can have unexpected
50results.
51
52DSA_new_method() allocates and initializes a DSA structure so that B<engine>
53will be used for the DSA operations. If B<engine> is NULL, the default engine
54for DSA operations is used, and if no default ENGINE is set, the DSA_METHOD
55controlled by DSA_set_default_method() is used.
56
57=head1 THE DSA_METHOD STRUCTURE
58
59struct
60 {
61 /* name of the implementation */
62 const char *name;
63
64 /* sign */
65 DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
66 DSA *dsa);
67
68 /* pre-compute k^-1 and r */
69 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
70 BIGNUM **rp);
71
72 /* verify */
73 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
74 DSA_SIG *sig, DSA *dsa);
75
76 /* compute rr = a1^p1 * a2^p2 mod m (May be NULL for some
77 implementations) */
78 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
79 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
80 BN_CTX *ctx, BN_MONT_CTX *in_mont);
81
82 /* compute r = a ^ p mod m (May be NULL for some implementations) */
83 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
84 const BIGNUM *p, const BIGNUM *m,
85 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
86
87 /* called at DSA_new */
88 int (*init)(DSA *DSA);
89
90 /* called at DSA_free */
91 int (*finish)(DSA *DSA);
92
93 int flags;
94
95 char *app_data; /* ?? */
96
97 } DSA_METHOD;
98
99=head1 RETURN VALUES
100
101DSA_OpenSSL() and DSA_get_default_method() return pointers to the respective
102B<DSA_METHOD>s.
103
104DSA_set_default_method() returns no value.
105
106DSA_set_method() returns non-zero if the provided B<meth> was successfully set as
107the method for B<dsa> (including unloading the ENGINE handle if the previous
108method was supplied by an ENGINE).
109
110DSA_new_method() returns NULL and sets an error code that can be
111obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
112fails. Otherwise it returns a pointer to the newly allocated structure.
113
114=head1 NOTES
115
116As of version 0.9.7, DSA_METHOD implementations are grouped together with other
117algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
118default ENGINE is specified for DSA functionality using an ENGINE API function,
119that will override any DSA defaults set using the DSA API (ie.
120DSA_set_default_method()). For this reason, the ENGINE API is the recommended way
121to control default implementations for use in DSA and other cryptographic
122algorithms.
123
124=head1 SEE ALSO
125
126L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
127
128=head1 HISTORY
129
130DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
131DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
132
133DSA_set_default_openssl_method() and DSA_get_default_openssl_method() replaced
134DSA_set_default_method() and DSA_get_default_method() respectively, and
135DSA_set_method() and DSA_new_method() were altered to use B<ENGINE>s rather than
136B<DSA_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
1370.9.7, the handling of defaults in the ENGINE API was restructured so that this
138change was reversed, and behaviour of the other functions resembled more closely
139the previous behaviour. The behaviour of defaults in the ENGINE API now
140transparently overrides the behaviour of defaults in the DSA API without
141requiring changing these function prototypes.
142
143=cut
diff --git a/src/lib/libcrypto/doc/DSA_sign.pod b/src/lib/libcrypto/doc/DSA_sign.pod
new file mode 100644
index 0000000000..97389e8ec8
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_sign.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5DSA_sign, DSA_sign_setup, DSA_verify - DSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_sign(int type, const unsigned char *dgst, int len,
12 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
13
14 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
15 BIGNUM **rp);
16
17 int DSA_verify(int type, const unsigned char *dgst, int len,
18 unsigned char *sigbuf, int siglen, DSA *dsa);
19
20=head1 DESCRIPTION
21
22DSA_sign() computes a digital signature on the B<len> byte message
23digest B<dgst> using the private key B<dsa> and places its ASN.1 DER
24encoding at B<sigret>. The length of the signature is places in
25*B<siglen>. B<sigret> must point to DSA_size(B<dsa>) bytes of memory.
26
27DSA_sign_setup() may be used to precompute part of the signing
28operation in case signature generation is time-critical. It expects
29B<dsa> to contain DSA parameters. It places the precomputed values
30in newly allocated B<BIGNUM>s at *B<kinvp> and *B<rp>, after freeing
31the old ones unless *B<kinvp> and *B<rp> are NULL. These values may
32be passed to DSA_sign() in B<dsa-E<gt>kinv> and B<dsa-E<gt>r>.
33B<ctx> is a pre-allocated B<BN_CTX> or NULL.
34
35DSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
36matches a given message digest B<dgst> of size B<len>.
37B<dsa> is the signer's public key.
38
39The B<type> parameter is ignored.
40
41The PRNG must be seeded before DSA_sign() (or DSA_sign_setup())
42is called.
43
44=head1 RETURN VALUES
45
46DSA_sign() and DSA_sign_setup() return 1 on success, 0 on error.
47DSA_verify() returns 1 for a valid signature, 0 for an incorrect
48signature and -1 on error. The error codes can be obtained by
49L<ERR_get_error(3)|ERR_get_error(3)>.
50
51=head1 CONFORMING TO
52
53US Federal Information Processing Standard FIPS 186 (Digital Signature
54Standard, DSS), ANSI X9.30
55
56=head1 SEE ALSO
57
58L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
59L<DSA_do_sign(3)|DSA_do_sign(3)>
60
61=head1 HISTORY
62
63DSA_sign() and DSA_verify() are available in all versions of SSLeay.
64DSA_sign_setup() was added in SSLeay 0.8.
65
66=cut
diff --git a/src/lib/libcrypto/doc/DSA_size.pod b/src/lib/libcrypto/doc/DSA_size.pod
new file mode 100644
index 0000000000..ba4f650361
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DSA_size - get DSA signature size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_size(const DSA *dsa);
12
13=head1 DESCRIPTION
14
15This function returns the size of an ASN.1 encoded DSA signature in
16bytes. It can be used to determine how much memory must be allocated
17for a DSA signature.
18
19B<dsa-E<gt>q> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<DSA_sign(3)|DSA_sign(3)>
28
29=head1 HISTORY
30
31DSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/ERR_GET_LIB.pod b/src/lib/libcrypto/doc/ERR_GET_LIB.pod
new file mode 100644
index 0000000000..2a129da036
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_GET_LIB.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5ERR_GET_LIB, ERR_GET_FUNC, ERR_GET_REASON - get library, function and
6reason code
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 int ERR_GET_LIB(unsigned long e);
13
14 int ERR_GET_FUNC(unsigned long e);
15
16 int ERR_GET_REASON(unsigned long e);
17
18=head1 DESCRIPTION
19
20The error code returned by ERR_get_error() consists of a library
21number, function code and reason code. ERR_GET_LIB(), ERR_GET_FUNC()
22and ERR_GET_REASON() can be used to extract these.
23
24The library number and function code describe where the error
25occurred, the reason code is the information about what went wrong.
26
27Each sub-library of OpenSSL has a unique library number; function and
28reason codes are unique within each sub-library. Note that different
29libraries may use the same value to signal different functions and
30reasons.
31
32B<ERR_R_...> reason codes such as B<ERR_R_MALLOC_FAILURE> are globally
33unique. However, when checking for sub-library specific reason codes,
34be sure to also compare the library number.
35
36ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are macros.
37
38=head1 RETURN VALUES
39
40The library number, function code and reason code respectively.
41
42=head1 SEE ALSO
43
44L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
45
46=head1 HISTORY
47
48ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are available in
49all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libcrypto/doc/ERR_clear_error.pod b/src/lib/libcrypto/doc/ERR_clear_error.pod
new file mode 100644
index 0000000000..566e1f4e31
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_clear_error.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5ERR_clear_error - clear the error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_clear_error(void);
12
13=head1 DESCRIPTION
14
15ERR_clear_error() empties the current thread's error queue.
16
17=head1 RETURN VALUES
18
19ERR_clear_error() has no return value.
20
21=head1 SEE ALSO
22
23L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
24
25=head1 HISTORY
26
27ERR_clear_error() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libcrypto/doc/ERR_error_string.pod b/src/lib/libcrypto/doc/ERR_error_string.pod
new file mode 100644
index 0000000000..cdfa7fe1fe
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_error_string.pod
@@ -0,0 +1,73 @@
1=pod
2
3=head1 NAME
4
5ERR_error_string, ERR_error_string_n, ERR_lib_error_string,
6ERR_func_error_string, ERR_reason_error_string - obtain human-readable
7error message
8
9=head1 SYNOPSIS
10
11 #include <openssl/err.h>
12
13 char *ERR_error_string(unsigned long e, char *buf);
14 void ERR_error_string_n(unsigned long e, char *buf, size_t len);
15
16 const char *ERR_lib_error_string(unsigned long e);
17 const char *ERR_func_error_string(unsigned long e);
18 const char *ERR_reason_error_string(unsigned long e);
19
20=head1 DESCRIPTION
21
22ERR_error_string() generates a human-readable string representing the
23error code I<e>, and places it at I<buf>. I<buf> must be at least 120
24bytes long. If I<buf> is B<NULL>, the error string is placed in a
25static buffer.
26ERR_error_string_n() is a variant of ERR_error_string() that writes
27at most I<len> characters (including the terminating 0)
28and truncates the string if necessary.
29For ERR_error_string_n(), I<buf> may not be B<NULL>.
30
31The string will have the following format:
32
33 error:[error code]:[library name]:[function name]:[reason string]
34
35I<error code> is an 8 digit hexadecimal number, I<library name>,
36I<function name> and I<reason string> are ASCII text.
37
38ERR_lib_error_string(), ERR_func_error_string() and
39ERR_reason_error_string() return the library name, function
40name and reason string respectively.
41
42The OpenSSL error strings should be loaded by calling
43L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)> or, for SSL
44applications, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
45first.
46If there is no text string registered for the given error code,
47the error string will contain the numeric code.
48
49L<ERR_print_errors(3)|ERR_print_errors(3)> can be used to print
50all error codes currently in the queue.
51
52=head1 RETURN VALUES
53
54ERR_error_string() returns a pointer to a static buffer containing the
55string if I<buf> B<== NULL>, I<buf> otherwise.
56
57ERR_lib_error_string(), ERR_func_error_string() and
58ERR_reason_error_string() return the strings, and B<NULL> if
59none is registered for the error code.
60
61=head1 SEE ALSO
62
63L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
64L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
65L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
66L<ERR_print_errors(3)|ERR_print_errors(3)>
67
68=head1 HISTORY
69
70ERR_error_string() is available in all versions of SSLeay and OpenSSL.
71ERR_error_string_n() was added in OpenSSL 0.9.6.
72
73=cut
diff --git a/src/lib/libcrypto/doc/ERR_get_error.pod b/src/lib/libcrypto/doc/ERR_get_error.pod
new file mode 100644
index 0000000000..34443045fc
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_get_error.pod
@@ -0,0 +1,76 @@
1=pod
2
3=head1 NAME
4
5ERR_get_error, ERR_peek_error, ERR_peek_last_error,
6ERR_get_error_line, ERR_peek_error_line, ERR_peek_last_error_line,
7ERR_get_error_line_data, ERR_peek_error_line_data,
8ERR_peek_last_error_line_data - obtain error code and data
9
10=head1 SYNOPSIS
11
12 #include <openssl/err.h>
13
14 unsigned long ERR_get_error(void);
15 unsigned long ERR_peek_error(void);
16 unsigned long ERR_peek_last_error(void);
17
18 unsigned long ERR_get_error_line(const char **file, int *line);
19 unsigned long ERR_peek_error_line(const char **file, int *line);
20 unsigned long ERR_peek_last_error_line(const char **file, int *line);
21
22 unsigned long ERR_get_error_line_data(const char **file, int *line,
23 const char **data, int *flags);
24 unsigned long ERR_peek_error_line_data(const char **file, int *line,
25 const char **data, int *flags);
26 unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
27 const char **data, int *flags);
28
29=head1 DESCRIPTION
30
31ERR_get_error() returns the earliest error code from the thread's error
32queue and removes the entry. This function can be called repeatedly
33until there are no more error codes to return.
34
35ERR_peek_error() returns the earliest error code from the thread's
36error queue without modifying it.
37
38ERR_peek_last_error() returns the latest error code from the thread's
39error queue without modifying it.
40
41See L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> for obtaining information about
42location and reason of the error, and
43L<ERR_error_string(3)|ERR_error_string(3)> for human-readable error
44messages.
45
46ERR_get_error_line(), ERR_peek_error_line() and
47ERR_peek_last_error_line() are the same as the above, but they
48additionally store the file name and line number where
49the error occurred in *B<file> and *B<line>, unless these are B<NULL>.
50
51ERR_get_error_line_data(), ERR_peek_error_line_data() and
52ERR_get_last_error_line_data() store additional data and flags
53associated with the error code in *B<data>
54and *B<flags>, unless these are B<NULL>. *B<data> contains a string
55if *B<flags>&B<ERR_TXT_STRING>. If it has been allocated by OPENSSL_malloc(),
56*B<flags>&B<ERR_TXT_MALLOCED> is true.
57
58=head1 RETURN VALUES
59
60The error code, or 0 if there is no error in the queue.
61
62=head1 SEE ALSO
63
64L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
65L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>
66
67=head1 HISTORY
68
69ERR_get_error(), ERR_peek_error(), ERR_get_error_line() and
70ERR_peek_error_line() are available in all versions of SSLeay and
71OpenSSL. ERR_get_error_line_data() and ERR_peek_error_line_data()
72were added in SSLeay 0.9.0.
73ERR_peek_last_error(), ERR_peek_last_error_line() and
74ERR_peek_last_error_line_data() were added in OpenSSL 0.9.7.
75
76=cut
diff --git a/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod b/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod
new file mode 100644
index 0000000000..9bdec75a46
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5ERR_load_crypto_strings, SSL_load_error_strings, ERR_free_strings -
6load and free error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_crypto_strings(void);
13 void ERR_free_strings(void);
14
15 #include <openssl/ssl.h>
16
17 void SSL_load_error_strings(void);
18
19=head1 DESCRIPTION
20
21ERR_load_crypto_strings() registers the error strings for all
22B<libcrypto> functions. SSL_load_error_strings() does the same,
23but also registers the B<libssl> error strings.
24
25One of these functions should be called before generating
26textual error messages. However, this is not required when memory
27usage is an issue.
28
29ERR_free_strings() frees all previously loaded error strings.
30
31=head1 RETURN VALUES
32
33ERR_load_crypto_strings(), SSL_load_error_strings() and
34ERR_free_strings() return no values.
35
36=head1 SEE ALSO
37
38L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>
39
40=head1 HISTORY
41
42ERR_load_error_strings(), SSL_load_error_strings() and
43ERR_free_strings() are available in all versions of SSLeay and
44OpenSSL.
45
46=cut
diff --git a/src/lib/libcrypto/doc/ERR_load_strings.pod b/src/lib/libcrypto/doc/ERR_load_strings.pod
new file mode 100644
index 0000000000..5acdd0edbc
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_load_strings.pod
@@ -0,0 +1,54 @@
1=pod
2
3=head1 NAME
4
5ERR_load_strings, ERR_PACK, ERR_get_next_error_library - load
6arbitrary error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
13
14 int ERR_get_next_error_library(void);
15
16 unsigned long ERR_PACK(int lib, int func, int reason);
17
18=head1 DESCRIPTION
19
20ERR_load_strings() registers error strings for library number B<lib>.
21
22B<str> is an array of error string data:
23
24 typedef struct ERR_string_data_st
25 {
26 unsigned long error;
27 char *string;
28 } ERR_STRING_DATA;
29
30The error code is generated from the library number and a function and
31reason code: B<error> = ERR_PACK(B<lib>, B<func>, B<reason>).
32ERR_PACK() is a macro.
33
34The last entry in the array is {0,0}.
35
36ERR_get_next_error_library() can be used to assign library numbers
37to user libraries at runtime.
38
39=head1 RETURN VALUE
40
41ERR_load_strings() returns no value. ERR_PACK() return the error code.
42ERR_get_next_error_library() returns a new library number.
43
44=head1 SEE ALSO
45
46L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
47
48=head1 HISTORY
49
50ERR_load_error_strings() and ERR_PACK() are available in all versions
51of SSLeay and OpenSSL. ERR_get_next_error_library() was added in
52SSLeay 0.9.0.
53
54=cut
diff --git a/src/lib/libcrypto/doc/ERR_print_errors.pod b/src/lib/libcrypto/doc/ERR_print_errors.pod
new file mode 100644
index 0000000000..b100a5fa2b
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_print_errors.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5ERR_print_errors, ERR_print_errors_fp - print error messages
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_print_errors(BIO *bp);
12 void ERR_print_errors_fp(FILE *fp);
13
14=head1 DESCRIPTION
15
16ERR_print_errors() is a convenience function that prints the error
17strings for all errors that OpenSSL has recorded to B<bp>, thus
18emptying the error queue.
19
20ERR_print_errors_fp() is the same, except that the output goes to a
21B<FILE>.
22
23
24The error strings will have the following format:
25
26 [pid]:error:[error code]:[library name]:[function name]:[reason string]:[file name]:[line]:[optional text message]
27
28I<error code> is an 8 digit hexadecimal number. I<library name>,
29I<function name> and I<reason string> are ASCII text, as is I<optional
30text message> if one was set for the respective error code.
31
32If there is no text string registered for the given error code,
33the error string will contain the numeric code.
34
35=head1 RETURN VALUES
36
37ERR_print_errors() and ERR_print_errors_fp() return no values.
38
39=head1 SEE ALSO
40
41L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
42L<ERR_get_error(3)|ERR_get_error(3)>,
43L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
44L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
45
46=head1 HISTORY
47
48ERR_print_errors() and ERR_print_errors_fp()
49are available in all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libcrypto/doc/ERR_put_error.pod b/src/lib/libcrypto/doc/ERR_put_error.pod
new file mode 100644
index 0000000000..acd241fbe4
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_put_error.pod
@@ -0,0 +1,44 @@
1=pod
2
3=head1 NAME
4
5ERR_put_error, ERR_add_error_data - record an error
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_put_error(int lib, int func, int reason, const char *file,
12 int line);
13
14 void ERR_add_error_data(int num, ...);
15
16=head1 DESCRIPTION
17
18ERR_put_error() adds an error code to the thread's error queue. It
19signals that the error of reason code B<reason> occurred in function
20B<func> of library B<lib>, in line number B<line> of B<file>.
21This function is usually called by a macro.
22
23ERR_add_error_data() associates the concatenation of its B<num> string
24arguments with the error code added last.
25
26L<ERR_load_strings(3)|ERR_load_strings(3)> can be used to register
27error strings so that the application can a generate human-readable
28error messages for the error code.
29
30=head1 RETURN VALUES
31
32ERR_put_error() and ERR_add_error_data() return
33no values.
34
35=head1 SEE ALSO
36
37L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
38
39=head1 HISTORY
40
41ERR_put_error() is available in all versions of SSLeay and OpenSSL.
42ERR_add_error_data() was added in SSLeay 0.9.0.
43
44=cut
diff --git a/src/lib/libcrypto/doc/ERR_remove_state.pod b/src/lib/libcrypto/doc/ERR_remove_state.pod
new file mode 100644
index 0000000000..72925fb9f4
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_remove_state.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5ERR_remove_state - free a thread's error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_remove_state(unsigned long pid);
12
13=head1 DESCRIPTION
14
15ERR_remove_state() frees the error queue associated with thread B<pid>.
16If B<pid> == 0, the current thread will have its error queue removed.
17
18Since error queue data structures are allocated automatically for new
19threads, they must be freed when threads are terminated in order to
20avoid memory leaks.
21
22=head1 RETURN VALUE
23
24ERR_remove_state() returns no value.
25
26=head1 SEE ALSO
27
28L<err(3)|err(3)>
29
30=head1 HISTORY
31
32ERR_remove_state() is available in all versions of SSLeay and OpenSSL.
33
34=cut
diff --git a/src/lib/libcrypto/doc/EVP_BytesToKey.pod b/src/lib/libcrypto/doc/EVP_BytesToKey.pod
new file mode 100644
index 0000000000..016381f3e9
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_BytesToKey.pod
@@ -0,0 +1,67 @@
1=pod
2
3=head1 NAME
4
5EVP_BytesToKey - password based encryption routine
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
12 const unsigned char *salt,
13 const unsigned char *data, int datal, int count,
14 unsigned char *key,unsigned char *iv);
15
16=head1 DESCRIPTION
17
18EVP_BytesToKey() derives a key and IV from various parameters. B<type> is
19the cipher to derive the key and IV for. B<md> is the message digest to use.
20The B<salt> paramter is used as a salt in the derivation: it should point to
21an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing
22B<datal> bytes which is used to derive the keying data. B<count> is the
23iteration count to use. The derived key and IV will be written to B<key>
24and B<iv> respectively.
25
26=head1 NOTES
27
28A typical application of this function is to derive keying material for an
29encryption algorithm from a password in the B<data> parameter.
30
31Increasing the B<count> parameter slows down the algorithm which makes it
32harder for an attacker to peform a brute force attack using a large number
33of candidate passwords.
34
35If the total key and IV length is less than the digest length and
36B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5
37otherwise a non standard extension is used to derive the extra data.
38
39Newer applications should use more standard algorithms such as PKCS#5
40v2.0 for key derivation.
41
42=head1 KEY DERIVATION ALGORITHM
43
44The key and IV is derived by concatenating D_1, D_2, etc until
45enough data is available for the key and IV. D_i is defined as:
46
47 D_i = HASH^count(D_(i-1) || data || salt)
48
49where || denotes concatentaion, D_0 is empty, HASH is the digest
50algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data)
51is HASH(HASH(data)) and so on.
52
53The initial bytes are used for the key and the subsequent bytes for
54the IV.
55
56=head1 RETURN VALUES
57
58EVP_BytesToKey() returns the size of the derived key in bytes.
59
60=head1 SEE ALSO
61
62L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
64
65=head1 HISTORY
66
67=cut
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
new file mode 100644
index 0000000000..faa992286b
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod
@@ -0,0 +1,256 @@
1=pod
2
3=head1 NAME
4
5EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate,
6EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE,
7EVP_MD_CTX_copy_ex, EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size,
8EVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type,
9EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2,
10EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj -
11EVP digest routines
12
13=head1 SYNOPSIS
14
15 #include <openssl/evp.h>
16
17 void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
18 EVP_MD_CTX *EVP_MD_CTX_create(void);
19
20 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
21 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
22 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
23 unsigned int *s);
24
25 int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
26 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
27
28 int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
29
30 int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
31 int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
32 unsigned int *s);
33
34 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
35
36 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
37
38
39 #define EVP_MD_type(e) ((e)->type)
40 #define EVP_MD_pkey_type(e) ((e)->pkey_type)
41 #define EVP_MD_size(e) ((e)->md_size)
42 #define EVP_MD_block_size(e) ((e)->block_size)
43
44 #define EVP_MD_CTX_md(e) (e)->digest)
45 #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
46 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
47 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
48
49 const EVP_MD *EVP_md_null(void);
50 const EVP_MD *EVP_md2(void);
51 const EVP_MD *EVP_md5(void);
52 const EVP_MD *EVP_sha(void);
53 const EVP_MD *EVP_sha1(void);
54 const EVP_MD *EVP_dss(void);
55 const EVP_MD *EVP_dss1(void);
56 const EVP_MD *EVP_mdc2(void);
57 const EVP_MD *EVP_ripemd160(void);
58
59 const EVP_MD *EVP_get_digestbyname(const char *name);
60 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
61 #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
62
63=head1 DESCRIPTION
64
65The EVP digest routines are a high level interface to message digests.
66
67EVP_MD_CTX_init() initializes digest contet B<ctx>.
68
69EVP_MD_CTX_create() allocates, initializes and returns a digest contet.
70
71EVP_DigestInit_ex() sets up digest context B<ctx> to use a digest
72B<type> from ENGINE B<impl>. B<ctx> must be initialized before calling this
73function. B<type> will typically be supplied by a functionsuch as EVP_sha1().
74If B<impl> is NULL then the default implementation of digest B<type> is used.
75
76EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
77digest context B<ctx>. This function can be called several times on the
78same B<ctx> to hash additional data.
79
80EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places
81it in B<md>. If the B<s> parameter is not NULL then the number of
82bytes of data written (i.e. the length of the digest) will be written
83to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
84After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate()
85can be made, but EVP_DigestInit_ex() can be called to initialize a new
86digest operation.
87
88EVP_MD_CTX_cleanup() cleans up digest context B<ctx>, it should be called
89after a digest context is no longer needed.
90
91EVP_MD_CTX_destroy() cleans up digest context B<ctx> and frees up the
92space allocated to it, it should be called only on a context created
93using EVP_MD_CTX_create().
94
95EVP_MD_CTX_copy_ex() can be used to copy the message digest state from
96B<in> to B<out>. This is useful if large amounts of data are to be
97hashed which only differ in the last few bytes. B<out> must be initialized
98before calling this function.
99
100EVP_DigestInit() behaves in the same way as EVP_DigestInit_ex() except
101the passed context B<ctx> does not have to be initialized, and it always
102uses the default digest implementation.
103
104EVP_DigestFinal() is similar to EVP_DigestFinal_ex() except the digest
105contet B<ctx> is automatically cleaned up.
106
107EVP_MD_CTX_copy() is similar to EVP_MD_CTX_copy_ex() except the destination
108B<out> does not have to be initialized.
109
110EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
111when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
112hash.
113
114EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the
115message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure.
116
117EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER
118representing the given message digest when passed an B<EVP_MD> structure.
119For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is
120normally used when setting ASN1 OIDs.
121
122EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed
123B<EVP_MD_CTX>.
124
125EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated
126with this digest. For example EVP_sha1() is associated with RSA so this will
127return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature
128algorithms may not be retained in future versions of OpenSSL.
129
130EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160()
131return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest
132algorithms respectively. The associated signature algorithm is RSA in each case.
133
134EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest
135algorithms but using DSS (DSA) for the signature algorithm.
136
137EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it
138returns is of zero length.
139
140EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
141return an B<EVP_MD> structure when passed a digest name, a digest NID or
142an ASN1_OBJECT structure respectively. The digest table must be initialized
143using, for example, OpenSSL_add_all_digests() for these functions to work.
144
145=head1 RETURN VALUES
146
147EVP_DigestInit_ex(), EVP_DigestUpdate() and EVP_DigestFinal_ex() return 1 for
148success and 0 for failure.
149
150EVP_MD_CTX_copy_ex() returns 1 if successful or 0 for failure.
151
152EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
153corresponding OBJECT IDENTIFIER or NID_undef if none exists.
154
155EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(e), EVP_MD_size(),
156EVP_MD_CTX_block_size() and EVP_MD_block_size() return the digest or block
157size in bytes.
158
159EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_dss(),
160EVP_dss1(), EVP_mdc2() and EVP_ripemd160() return pointers to the
161corresponding EVP_MD structures.
162
163EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
164return either an B<EVP_MD> structure or NULL if an error occurs.
165
166=head1 NOTES
167
168The B<EVP> interface to message digests should almost always be used in
169preference to the low level interfaces. This is because the code then becomes
170transparent to the digest used and much more flexible.
171
172SHA1 is the digest of choice for new applications. The other digest algorithms
173are still in common use.
174
175For most applications the B<impl> parameter to EVP_DigestInit_ex() will be
176set to NULL to use the default digest implementation.
177
178The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are
179obsolete but are retained to maintain compatibility with existing code. New
180applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and
181EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
182instead of initializing and cleaning it up on each call and allow non default
183implementations of digests to be specified.
184
185In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use
186memory leaks will occur.
187
188=head1 EXAMPLE
189
190This example digests the data "Test Message\n" and "Hello World\n", using the
191digest name passed on the command line.
192
193 #include <stdio.h>
194 #include <openssl/evp.h>
195
196 main(int argc, char *argv[])
197 {
198 EVP_MD_CTX mdctx;
199 const EVP_MD *md;
200 char mess1[] = "Test Message\n";
201 char mess2[] = "Hello World\n";
202 unsigned char md_value[EVP_MAX_MD_SIZE];
203 int md_len, i;
204
205 OpenSSL_add_all_digests();
206
207 if(!argv[1]) {
208 printf("Usage: mdtest digestname\n");
209 exit(1);
210 }
211
212 md = EVP_get_digestbyname(argv[1]);
213
214 if(!md) {
215 printf("Unknown message digest %s\n", argv[1]);
216 exit(1);
217 }
218
219 EVP_MD_CTX_init(&mdctx);
220 EVP_DigestInit_ex(&mdctx, md, NULL);
221 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
222 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
223 EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
224 EVP_MD_CTX_cleanup(&mdctx);
225
226 printf("Digest is: ");
227 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
228 printf("\n");
229 }
230
231=head1 BUGS
232
233The link between digests and signing algorithms results in a situation where
234EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS
235even though they are identical digests.
236
237=head1 SEE ALSO
238
239L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
240L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD160(3)|RIPEMD160(3)>,
241L<SHA1(3)|SHA1(3)>
242
243=head1 HISTORY
244
245EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
246available in all versions of SSLeay and OpenSSL.
247
248EVP_MD_CTX_init(), EVP_MD_CTX_create(), EVP_MD_CTX_copy_ex(),
249EVP_MD_CTX_cleanup(), EVP_MD_CTX_destroy(), EVP_DigestInit_ex()
250and EVP_DigestFinal_ex() were added in OpenSSL 0.9.7.
251
252EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(),
253EVP_dss(), EVP_dss1(), EVP_mdc2() and EVP_ripemd160() were
254changed to return truely const EVP_MD * in OpenSSL 0.9.7.
255
256=cut
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
new file mode 100644
index 0000000000..40e525dd56
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
@@ -0,0 +1,511 @@
1=pod
2
3=head1 NAME
4
5EVP_CIPHER_CTX_init, EVP_EncryptInit_ex, EVP_EncryptUpdate,
6EVP_EncryptFinal_ex, EVP_DecryptInit_ex, EVP_DecryptUpdate,
7EVP_DecryptFinal_ex, EVP_CipherInit_ex, EVP_CipherUpdate,
8EVP_CipherFinal_ex, EVP_CIPHER_CTX_set_key_length,
9EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX_cleanup, EVP_EncryptInit,
10EVP_EncryptFinal, EVP_DecryptInit, EVP_DecryptFinal,
11EVP_CipherInit, EVP_CipherFinal, EVP_get_cipherbyname,
12EVP_get_cipherbynid, EVP_get_cipherbyobj, EVP_CIPHER_nid,
13EVP_CIPHER_block_size, EVP_CIPHER_key_length, EVP_CIPHER_iv_length,
14EVP_CIPHER_flags, EVP_CIPHER_mode, EVP_CIPHER_type, EVP_CIPHER_CTX_cipher,
15EVP_CIPHER_CTX_nid, EVP_CIPHER_CTX_block_size, EVP_CIPHER_CTX_key_length,
16EVP_CIPHER_CTX_iv_length, EVP_CIPHER_CTX_get_app_data,
17EVP_CIPHER_CTX_set_app_data, EVP_CIPHER_CTX_type, EVP_CIPHER_CTX_flags,
18EVP_CIPHER_CTX_mode, EVP_CIPHER_param_to_asn1, EVP_CIPHER_asn1_to_param,
19EVP_CIPHER_CTX_set_padding - EVP cipher routines
20
21=head1 SYNOPSIS
22
23 #include <openssl/evp.h>
24
25 int EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
26
27 int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
28 ENGINE *impl, unsigned char *key, unsigned char *iv);
29 int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
30 int *outl, unsigned char *in, int inl);
31 int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out,
32 int *outl);
33
34 int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
35 ENGINE *impl, unsigned char *key, unsigned char *iv);
36 int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
37 int *outl, unsigned char *in, int inl);
38 int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
39 int *outl);
40
41 int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
42 ENGINE *impl, unsigned char *key, unsigned char *iv, int enc);
43 int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
44 int *outl, unsigned char *in, int inl);
45 int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
46 int *outl);
47
48 int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
49 unsigned char *key, unsigned char *iv);
50 int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
51 int *outl);
52
53 int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
54 unsigned char *key, unsigned char *iv);
55 int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
56 int *outl);
57
58 int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
59 unsigned char *key, unsigned char *iv, int enc);
60 int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
61 int *outl);
62
63 int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding);
64 int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
65 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
66 int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
67
68 const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
69 #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
70 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
71
72 #define EVP_CIPHER_nid(e) ((e)->nid)
73 #define EVP_CIPHER_block_size(e) ((e)->block_size)
74 #define EVP_CIPHER_key_length(e) ((e)->key_len)
75 #define EVP_CIPHER_iv_length(e) ((e)->iv_len)
76 #define EVP_CIPHER_flags(e) ((e)->flags)
77 #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE)
78 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
79
80 #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
81 #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
82 #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
83 #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
84 #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
85 #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
86 #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
87 #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
88 #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
89 #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
90
91 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
92 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
93
94=head1 DESCRIPTION
95
96The EVP cipher routines are a high level interface to certain
97symmetric ciphers.
98
99EVP_CIPHER_CTX_init() initializes cipher contex B<ctx>.
100
101EVP_EncryptInit_ex() sets up cipher context B<ctx> for encryption
102with cipher B<type> from ENGINE B<impl>. B<ctx> must be initialized
103before calling this function. B<type> is normally supplied
104by a function such as EVP_des_cbc(). If B<impl> is NULL then the
105default implementation is used. B<key> is the symmetric key to use
106and B<iv> is the IV to use (if necessary), the actual number of bytes
107used for the key and IV depends on the cipher. It is possible to set
108all parameters to NULL except B<type> in an initial call and supply
109the remaining parameters in subsequent calls, all of which have B<type>
110set to NULL. This is done when the default cipher parameters are not
111appropriate.
112
113EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and
114writes the encrypted version to B<out>. This function can be called
115multiple times to encrypt successive blocks of data. The amount
116of data written depends on the block alignment of the encrypted data:
117as a result the amount of data written may be anything from zero bytes
118to (inl + cipher_block_size - 1) so B<outl> should contain sufficient
119room. The actual number of bytes written is placed in B<outl>.
120
121If padding is enabled (the default) then EVP_EncryptFinal_ex() encrypts
122the "final" data, that is any data that remains in a partial block.
123It uses L<standard block padding|/NOTES> (aka PKCS padding). The encrypted
124final data is written to B<out> which should have sufficient space for
125one cipher block. The number of bytes written is placed in B<outl>. After
126this function is called the encryption operation is finished and no further
127calls to EVP_EncryptUpdate() should be made.
128
129If padding is disabled then EVP_EncryptFinal_ex() will not encrypt any more
130data and it will return an error if any data remains in a partial block:
131that is if the total data length is not a multiple of the block size.
132
133EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the
134corresponding decryption operations. EVP_DecryptFinal() will return an
135error code if padding is enabled and the final block is not correctly
136formatted. The parameters and restrictions are identical to the encryption
137operations except that if padding is enabled the decrypted data buffer B<out>
138passed to EVP_DecryptUpdate() should have sufficient room for
139(B<inl> + cipher_block_size) bytes unless the cipher block size is 1 in
140which case B<inl> bytes is sufficient.
141
142EVP_CipherInit_ex(), EVP_CipherUpdate() and EVP_CipherFinal_ex() are
143functions that can be used for decryption or encryption. The operation
144performed depends on the value of the B<enc> parameter. It should be set
145to 1 for encryption, 0 for decryption and -1 to leave the value unchanged
146(the actual value of 'enc' being supplied in a previous call).
147
148EVP_CIPHER_CTX_cleanup() clears all information from a cipher context
149and free up any allocated memory associate with it. It should be called
150after all operations using a cipher are complete so sensitive information
151does not remain in memory.
152
153EVP_EncryptInit(), EVP_DecryptInit() and EVP_CipherInit() behave in a
154similar way to EVP_EncryptInit_ex(), EVP_DecryptInit_ex and
155EVP_CipherInit_ex() except the B<ctx> paramter does not need to be
156initialized and they always use the default cipher implementation.
157
158EVP_EncryptFinal(), EVP_DecryptFinal() and EVP_CipherFinal() behave in a
159similar way to EVP_EncryptFinal_ex(), EVP_DecryptFinal_ex() and
160EVP_CipherFinal_ex() except B<ctx> is automatically cleaned up
161after the call.
162
163EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
164return an EVP_CIPHER structure when passed a cipher name, a NID or an
165ASN1_OBJECT structure.
166
167EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when
168passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID
169value is an internal value which may not have a corresponding OBJECT
170IDENTIFIER.
171
172EVP_CIPHER_CTX_set_padding() enables or disables padding. By default
173encryption operations are padded using standard block padding and the
174padding is checked and removed when decrypting. If the B<pad> parameter
175is zero then no padding is performed, the total amount of data encrypted
176or decrypted must then be a multiple of the block size or an error will
177occur.
178
179EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
180length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
181structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length
182for all ciphers. Note: although EVP_CIPHER_key_length() is fixed for a
183given cipher, the value of EVP_CIPHER_CTX_key_length() may be different
184for variable key length ciphers.
185
186EVP_CIPHER_CTX_set_key_length() sets the key length of the cipher ctx.
187If the cipher is a fixed length cipher then attempting to set the key
188length to any value other than the fixed value is an error.
189
190EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
191length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>.
192It will return zero if the cipher does not use an IV. The constant
193B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers.
194
195EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
196size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
197structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block
198length for all ciphers.
199
200EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed
201cipher or context. This "type" is the actual NID of the cipher OBJECT
202IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and
203128 bit RC2 have the same NID. If the cipher does not have an object
204identifier or does not have ASN1 support this function will return
205B<NID_undef>.
206
207EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed
208an B<EVP_CIPHER_CTX> structure.
209
210EVP_CIPHER_mode() and EVP_CIPHER_CTX_mode() return the block cipher mode:
211EVP_CIPH_ECB_MODE, EVP_CIPH_CBC_MODE, EVP_CIPH_CFB_MODE or
212EVP_CIPH_OFB_MODE. If the cipher is a stream cipher then
213EVP_CIPH_STREAM_CIPHER is returned.
214
215EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based
216on the passed cipher. This will typically include any parameters and an
217IV. The cipher IV (if any) must be set when this call is made. This call
218should be made before the cipher is actually "used" (before any
219EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function
220may fail if the cipher does not have any ASN1 support.
221
222EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1
223AlgorithmIdentifier "parameter". The precise effect depends on the cipher
224In the case of RC2, for example, it will set the IV and effective key length.
225This function should be called after the base cipher type is set but before
226the key is set. For example EVP_CipherInit() will be called with the IV and
227key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally
228EVP_CipherInit() again with all parameters except the key set to NULL. It is
229possible for this function to fail if the cipher does not have any ASN1 support
230or the parameters cannot be set (for example the RC2 effective key length
231is not supported.
232
233EVP_CIPHER_CTX_ctrl() allows various cipher specific parameters to be determined
234and set. Currently only the RC2 effective key length and the number of rounds of
235RC5 can be set.
236
237=head1 RETURN VALUES
238
239EVP_CIPHER_CTX_init, EVP_EncryptInit_ex(), EVP_EncryptUpdate() and
240EVP_EncryptFinal_ex() return 1 for success and 0 for failure.
241
242EVP_DecryptInit_ex() and EVP_DecryptUpdate() return 1 for success and 0 for failure.
243EVP_DecryptFinal_ex() returns 0 if the decrypt failed or 1 for success.
244
245EVP_CipherInit_ex() and EVP_CipherUpdate() return 1 for success and 0 for failure.
246EVP_CipherFinal_ex() returns 0 for a decryption failure or 1 for success.
247
248EVP_CIPHER_CTX_cleanup() returns 1 for success and 0 for failure.
249
250EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
251return an B<EVP_CIPHER> structure or NULL on error.
252
253EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID.
254
255EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
256size.
257
258EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
259length.
260
261EVP_CIPHER_CTX_set_padding() always returns 1.
262
263EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
264length or zero if the cipher does not use an IV.
265
266EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's
267OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER.
268
269EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure.
270
271EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for
272success or zero for failure.
273
274=head1 CIPHER LISTING
275
276All algorithms have a fixed key length unless otherwise stated.
277
278=over 4
279
280=item EVP_enc_null()
281
282Null cipher: does nothing.
283
284=item EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void)
285
286DES in CBC, ECB, CFB and OFB modes respectively.
287
288=item EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void), EVP_des_ede_cfb(void)
289
290Two key triple DES in CBC, ECB, CFB and OFB modes respectively.
291
292=item EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void), EVP_des_ede3_cfb(void)
293
294Three key triple DES in CBC, ECB, CFB and OFB modes respectively.
295
296=item EVP_desx_cbc(void)
297
298DESX algorithm in CBC mode.
299
300=item EVP_rc4(void)
301
302RC4 stream cipher. This is a variable key length cipher with default key length 128 bits.
303
304=item EVP_rc4_40(void)
305
306RC4 stream cipher with 40 bit key length. This is obsolete and new code should use EVP_rc4()
307and the EVP_CIPHER_CTX_set_key_length() function.
308
309=item EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), EVP_idea_ofb(void), EVP_idea_cbc(void)
310
311IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively.
312
313=item EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void)
314
315RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
316length cipher with an additional parameter called "effective key bits" or "effective key length".
317By default both are set to 128 bits.
318
319=item EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void)
320
321RC2 algorithm in CBC mode with a default key length and effective key length of 40 and 64 bits.
322These are obsolete and new code should use EVP_rc2_cbc(), EVP_CIPHER_CTX_set_key_length() and
323EVP_CIPHER_CTX_ctrl() to set the key length and effective key length.
324
325=item EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void);
326
327Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
328length cipher.
329
330=item EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), EVP_cast5_ofb(void)
331
332CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
333length cipher.
334
335=item EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void)
336
337RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key length
338cipher with an additional "number of rounds" parameter. By default the key length is set to 128
339bits and 12 rounds.
340
341=back
342
343=head1 NOTES
344
345Where possible the B<EVP> interface to symmetric ciphers should be used in
346preference to the low level interfaces. This is because the code then becomes
347transparent to the cipher used and much more flexible.
348
349PKCS padding works by adding B<n> padding bytes of value B<n> to make the total
350length of the encrypted data a multiple of the block size. Padding is always
351added so if the data is already a multiple of the block size B<n> will equal
352the block size. For example if the block size is 8 and 11 bytes are to be
353encrypted then 5 padding bytes of value 5 will be added.
354
355When decrypting the final block is checked to see if it has the correct form.
356
357Although the decryption operation can produce an error if padding is enabled,
358it is not a strong test that the input data or key is correct. A random block
359has better than 1 in 256 chance of being of the correct format and problems with
360the input data earlier on will not produce a final decrypt error.
361
362If padding is disabled then the decryption operation will always succeed if
363the total amount of data decrypted is a multiple of the block size.
364
365The functions EVP_EncryptInit(), EVP_EncryptFinal(), EVP_DecryptInit(),
366EVP_CipherInit() and EVP_CipherFinal() are obsolete but are retained for
367compatibility with existing code. New code should use EVP_EncryptInit_ex(),
368EVP_EncryptFinal_ex(), EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(),
369EVP_CipherInit_ex() and EVP_CipherFinal_ex() because they can reuse an
370existing context without allocating and freeing it up on each call.
371
372=head1 BUGS
373
374For RC5 the number of rounds can currently only be set to 8, 12 or 16. This is
375a limitation of the current RC5 code rather than the EVP interface.
376
377EVP_MAX_KEY_LENGTH and EVP_MAX_IV_LENGTH only refer to the internal ciphers with
378default key lengths. If custom ciphers exceed these values the results are
379unpredictable. This is because it has become standard practice to define a
380generic key as a fixed unsigned char array containing EVP_MAX_KEY_LENGTH bytes.
381
382The ASN1 code is incomplete (and sometimes inaccurate) it has only been tested
383for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC mode.
384
385=head1 EXAMPLES
386
387Get the number of rounds used in RC5:
388
389 int nrounds;
390 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds);
391
392Get the RC2 effective key length:
393
394 int key_bits;
395 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits);
396
397Set the number of rounds used in RC5:
398
399 int nrounds;
400 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL);
401
402Set the effective key length used in RC2:
403
404 int key_bits;
405 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
406
407Encrypt a string using blowfish:
408
409 int do_crypt(char *outfile)
410 {
411 unsigned char outbuf[1024];
412 int outlen, tmplen;
413 /* Bogus key and IV: we'd normally set these from
414 * another source.
415 */
416 unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
417 unsigned char iv[] = {1,2,3,4,5,6,7,8};
418 char intext[] = "Some Crypto Text";
419 EVP_CIPHER_CTX ctx;
420 FILE *out;
421 EVP_CIPHER_CTX_init(&ctx);
422 EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);
423
424 if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext)))
425 {
426 /* Error */
427 return 0;
428 }
429 /* Buffer passed to EVP_EncryptFinal() must be after data just
430 * encrypted to avoid overwriting it.
431 */
432 if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen))
433 {
434 /* Error */
435 return 0;
436 }
437 outlen += tmplen;
438 EVP_CIPHER_CTX_cleanup(&ctx);
439 /* Need binary mode for fopen because encrypted data is
440 * binary data. Also cannot use strlen() on it because
441 * it wont be null terminated and may contain embedded
442 * nulls.
443 */
444 out = fopen(outfile, "wb");
445 fwrite(outbuf, 1, outlen, out);
446 fclose(out);
447 return 1;
448 }
449
450The ciphertext from the above example can be decrypted using the B<openssl>
451utility with the command line:
452
453 S<openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F -iv 0102030405060708 -d>
454
455General encryption, decryption function example using FILE I/O and RC2 with an
45680 bit key:
457
458 int do_crypt(FILE *in, FILE *out, int do_encrypt)
459 {
460 /* Allow enough space in output buffer for additional block */
461 inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
462 int inlen, outlen;
463 /* Bogus key and IV: we'd normally set these from
464 * another source.
465 */
466 unsigned char key[] = "0123456789";
467 unsigned char iv[] = "12345678";
468 /* Don't set key or IV because we will modify the parameters */
469 EVP_CIPHER_CTX_init(&ctx);
470 EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt);
471 EVP_CIPHER_CTX_set_key_length(&ctx, 10);
472 /* We finished modifying parameters so now we can set key and IV */
473 EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt);
474
475 for(;;)
476 {
477 inlen = fread(inbuf, 1, 1024, in);
478 if(inlen <= 0) break;
479 if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen))
480 {
481 /* Error */
482 EVP_CIPHER_CTX_cleanup(&ctx);
483 return 0;
484 }
485 fwrite(outbuf, 1, outlen, out);
486 }
487 if(!EVP_CipherFinal_ex(&ctx, outbuf, &outlen))
488 {
489 /* Error */
490 EVP_CIPHER_CTX_cleanup(&ctx);
491 return 0;
492 }
493 fwrite(outbuf, 1, outlen, out);
494
495 EVP_CIPHER_CTX_cleanup(&ctx);
496 return 1;
497 }
498
499
500=head1 SEE ALSO
501
502L<evp(3)|evp(3)>
503
504=head1 HISTORY
505
506EVP_CIPHER_CTX_init(), EVP_EncryptInit_ex(), EVP_EncryptFinal_ex(),
507EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), EVP_CipherInit_ex(),
508EVP_CipherFinal_ex() and EVP_CIPHER_CTX_set_padding() appeared in
509OpenSSL 0.9.7.
510
511=cut
diff --git a/src/lib/libcrypto/doc/EVP_OpenInit.pod b/src/lib/libcrypto/doc/EVP_OpenInit.pod
new file mode 100644
index 0000000000..2e710da945
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_OpenInit.pod
@@ -0,0 +1,63 @@
1=pod
2
3=head1 NAME
4
5EVP_OpenInit, EVP_OpenUpdate, EVP_OpenFinal - EVP envelope decryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
12 int ekl,unsigned char *iv,EVP_PKEY *priv);
13 int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18=head1 DESCRIPTION
19
20The EVP envelope routines are a high level interface to envelope
21decryption. They decrypt a public key encrypted symmetric key and
22then decrypt data using it.
23
24EVP_OpenInit() initializes a cipher context B<ctx> for decryption
25with cipher B<type>. It decrypts the encrypted symmetric key of length
26B<ekl> bytes passed in the B<ek> parameter using the private key B<priv>.
27The IV is supplied in the B<iv> parameter.
28
29EVP_OpenUpdate() and EVP_OpenFinal() have exactly the same properties
30as the EVP_DecryptUpdate() and EVP_DecryptFinal() routines, as
31documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
32page.
33
34=head1 NOTES
35
36It is possible to call EVP_OpenInit() twice in the same way as
37EVP_DecryptInit(). The first call should have B<priv> set to NULL
38and (after setting any cipher parameters) it should be called again
39with B<type> set to NULL.
40
41If the cipher passed in the B<type> parameter is a variable length
42cipher then the key length will be set to the value of the recovered
43key length. If the cipher is a fixed length cipher then the recovered
44key length must match the fixed cipher length.
45
46=head1 RETURN VALUES
47
48EVP_OpenInit() returns 0 on error or a non zero integer (actually the
49recovered secret key size) if successful.
50
51EVP_OpenUpdate() returns 1 for success or 0 for failure.
52
53EVP_OpenFinal() returns 0 if the decrypt failed or 1 for success.
54
55=head1 SEE ALSO
56
57L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
58L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
59L<EVP_SealInit(3)|EVP_SealInit(3)>
60
61=head1 HISTORY
62
63=cut
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_new.pod b/src/lib/libcrypto/doc/EVP_PKEY_new.pod
new file mode 100644
index 0000000000..10687e458d
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_PKEY_new.pod
@@ -0,0 +1,47 @@
1=pod
2
3=head1 NAME
4
5EVP_PKEY_new, EVP_PKEY_free - private key allocation functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 EVP_PKEY *EVP_PKEY_new(void);
12 void EVP_PKEY_free(EVP_PKEY *key);
13
14
15=head1 DESCRIPTION
16
17The EVP_PKEY_new() function allocates an empty B<EVP_PKEY>
18structure which is used by OpenSSL to store private keys.
19
20EVP_PKEY_free() frees up the private key B<key>.
21
22=head1 NOTES
23
24The B<EVP_PKEY> structure is used by various OpenSSL functions
25which require a general private key without reference to any
26particular algorithm.
27
28The structure returned by EVP_PKEY_new() is empty. To add a
29private key to this empty structure the functions described in
30L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> should be used.
31
32=head1 RETURN VALUES
33
34EVP_PKEY_new() returns either the newly allocated B<EVP_PKEY>
35structure of B<NULL> if an error occurred.
36
37EVP_PKEY_free() does not return a value.
38
39=head1 SEE ALSO
40
41L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)>
42
43=head1 HISTORY
44
45TBA
46
47=cut
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod b/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod
new file mode 100644
index 0000000000..2db692e271
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod
@@ -0,0 +1,80 @@
1=pod
2
3=head1 NAME
4
5EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
6EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
7EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY,
8EVP_PKEY_type - EVP_PKEY assignment functions.
9
10=head1 SYNOPSIS
11
12 #include <openssl/evp.h>
13
14 int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key);
15 int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key);
16 int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key);
17 int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
18
19 RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
20 DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
21 DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
22 EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
23
24 int EVP_PKEY_assign_RSA(EVP_PKEY *pkey,RSA *key);
25 int EVP_PKEY_assign_DSA(EVP_PKEY *pkey,DSA *key);
26 int EVP_PKEY_assign_DH(EVP_PKEY *pkey,DH *key);
27 int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
28
29 int EVP_PKEY_type(int type);
30
31=head1 DESCRIPTION
32
33EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
34EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>.
35
36EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
37EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or
38B<NULL> if the key is not of the correct type.
39
40EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
41and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key>
42however these use the supplied B<key> internally and so B<key>
43will be freed when the parent B<pkey> is freed.
44
45EVP_PKEY_type() returns the type of key corresponding to the value
46B<type>. The type of a key can be obtained with
47EVP_PKEY_type(pkey->type). The return value will be EVP_PKEY_RSA,
48EVP_PKEY_DSA, EVP_PKEY_DH or EVP_PKEY_EC for the corresponding
49key types or NID_undef if the key type is unassigned.
50
51=head1 NOTES
52
53In accordance with the OpenSSL naming convention the key obtained
54from or assigned to the B<pkey> using the B<1> functions must be
55freed as well as B<pkey>.
56
57EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
58EVP_PKEY_assign_EC_KEY() are implemented as macros.
59
60=head1 RETURN VALUES
61
62EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
63EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure.
64
65EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
66EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if
67an error occurred.
68
69EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
70and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure.
71
72=head1 SEE ALSO
73
74L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>
75
76=head1 HISTORY
77
78TBA
79
80=cut
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod
new file mode 100644
index 0000000000..48a0e29954
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_SealInit.pod
@@ -0,0 +1,85 @@
1=pod
2
3=head1 NAME
4
5EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
12 unsigned char **ek, int *ekl, unsigned char *iv,
13 EVP_PKEY **pubk, int npubk);
14 int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
15 int *outl, unsigned char *in, int inl);
16 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
17 int *outl);
18
19=head1 DESCRIPTION
20
21The EVP envelope routines are a high level interface to envelope
22encryption. They generate a random key and IV (if required) then
23"envelope" it by using public key encryption. Data can then be
24encrypted using this key.
25
26EVP_SealInit() initializes a cipher context B<ctx> for encryption
27with cipher B<type> using a random secret key and IV. B<type> is normally
28supplied by a function such as EVP_des_cbc(). The secret key is encrypted
29using one or more public keys, this allows the same encrypted data to be
30decrypted using any of the corresponding private keys. B<ek> is an array of
31buffers where the public key encrypted secret key will be written, each buffer
32must contain enough room for the corresponding encrypted key: that is
33B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual
34size of each encrypted secret key is written to the array B<ekl>. B<pubk> is
35an array of B<npubk> public keys.
36
37The B<iv> parameter is a buffer where the generated IV is written to. It must
38contain enough room for the corresponding cipher's IV, as determined by (for
39example) EVP_CIPHER_iv_length(type).
40
41If the cipher does not require an IV then the B<iv> parameter is ignored
42and can be B<NULL>.
43
44EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties
45as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as
46documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
47page.
48
49=head1 RETURN VALUES
50
51EVP_SealInit() returns 0 on error or B<npubk> if successful.
52
53EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for
54failure.
55
56=head1 NOTES
57
58Because a random secret key is generated the random number generator
59must be seeded before calling EVP_SealInit().
60
61The public key must be RSA because it is the only OpenSSL public key
62algorithm that supports key transport.
63
64Envelope encryption is the usual method of using public key encryption
65on large amounts of data, this is because public key encryption is slow
66but symmetric encryption is fast. So symmetric encryption is used for
67bulk encryption and the small random symmetric key used is transferred
68using public key encryption.
69
70It is possible to call EVP_SealInit() twice in the same way as
71EVP_EncryptInit(). The first call should have B<npubk> set to 0
72and (after setting any cipher parameters) it should be called again
73with B<type> set to NULL.
74
75=head1 SEE ALSO
76
77L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
78L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
79L<EVP_OpenInit(3)|EVP_OpenInit(3)>
80
81=head1 HISTORY
82
83EVP_SealFinal() did not return a value before OpenSSL 0.9.7.
84
85=cut
diff --git a/src/lib/libcrypto/doc/EVP_SignInit.pod b/src/lib/libcrypto/doc/EVP_SignInit.pod
new file mode 100644
index 0000000000..0bace24938
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_SignInit.pod
@@ -0,0 +1,95 @@
1=pod
2
3=head1 NAME
4
5EVP_SignInit, EVP_SignUpdate, EVP_SignFinal - EVP signing functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
12 int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey);
14
15 void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
16
17 int EVP_PKEY_size(EVP_PKEY *pkey);
18
19=head1 DESCRIPTION
20
21The EVP signature routines are a high level interface to digital
22signatures.
23
24EVP_SignInit_ex() sets up signing context B<ctx> to use digest
25B<type> from ENGINE B<impl>. B<ctx> must be initialized with
26EVP_MD_CTX_init() before calling this function.
27
28EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
29signature context B<ctx>. This function can be called several times on the
30same B<ctx> to include additional data.
31
32EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey> and
33places the signature in B<sig>. The number of bytes of data written (i.e. the
34length of the signature) will be written to the integer at B<s>, at most
35EVP_PKEY_size(pkey) bytes will be written.
36
37EVP_SignInit() initializes a signing context B<ctx> to use the default
38implementation of digest B<type>.
39
40EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
41signature returned by EVP_SignFinal() may be smaller.
42
43=head1 RETURN VALUES
44
45EVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1
46for success and 0 for failure.
47
48EVP_PKEY_size() returns the maximum size of a signature in bytes.
49
50The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
51
52=head1 NOTES
53
54The B<EVP> interface to digital signatures should almost always be used in
55preference to the low level interfaces. This is because the code then becomes
56transparent to the algorithm used and much more flexible.
57
58Due to the link between message digests and public key algorithms the correct
59digest algorithm must be used with the correct public key type. A list of
60algorithms and associated public key algorithms appears in
61L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
62
63When signing with DSA private keys the random number generator must be seeded
64or the operation will fail. The random number generator does not need to be
65seeded for RSA signatures.
66
67The call to EVP_SignFinal() internally finalizes a copy of the digest context.
68This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
69later to digest and sign additional data.
70
71Since only a copy of the digest context is ever finalized the context must
72be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
73will occur.
74
75=head1 BUGS
76
77Older versions of this documentation wrongly stated that calls to
78EVP_SignUpdate() could not be made after calling EVP_SignFinal().
79
80=head1 SEE ALSO
81
82L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
83L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
84L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
85L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD(3)|RIPEMD(3)>,
86L<SHA1(3)|SHA1(3)>, L<digest(1)|digest(1)>
87
88=head1 HISTORY
89
90EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
91available in all versions of SSLeay and OpenSSL.
92
93EVP_SignInit_ex() was added in OpenSSL 0.9.7.
94
95=cut
diff --git a/src/lib/libcrypto/doc/EVP_VerifyInit.pod b/src/lib/libcrypto/doc/EVP_VerifyInit.pod
new file mode 100644
index 0000000000..b6afaedee5
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_VerifyInit.pod
@@ -0,0 +1,86 @@
1=pod
2
3=head1 NAME
4
5EVP_VerifyInit, EVP_VerifyUpdate, EVP_VerifyFinal - EVP signature verification functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
12 int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, unsigned int siglen,EVP_PKEY *pkey);
14
15 int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type);
16
17=head1 DESCRIPTION
18
19The EVP signature verification routines are a high level interface to digital
20signatures.
21
22EVP_VerifyInit_ex() sets up verification context B<ctx> to use digest
23B<type> from ENGINE B<impl>. B<ctx> must be initialized by calling
24EVP_MD_CTX_init() before calling this function.
25
26EVP_VerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
27verification context B<ctx>. This function can be called several times on the
28same B<ctx> to include additional data.
29
30EVP_VerifyFinal() verifies the data in B<ctx> using the public key B<pkey>
31and against the B<siglen> bytes at B<sigbuf>.
32
33EVP_VerifyInit() initializes verification context B<ctx> to use the default
34implementation of digest B<type>.
35
36=head1 RETURN VALUES
37
38EVP_VerifyInit_ex() and EVP_VerifyUpdate() return 1 for success and 0 for
39failure.
40
41EVP_VerifyFinal() returns 1 for a correct signature, 0 for failure and -1 if some
42other error occurred.
43
44The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
45
46=head1 NOTES
47
48The B<EVP> interface to digital signatures should almost always be used in
49preference to the low level interfaces. This is because the code then becomes
50transparent to the algorithm used and much more flexible.
51
52Due to the link between message digests and public key algorithms the correct
53digest algorithm must be used with the correct public key type. A list of
54algorithms and associated public key algorithms appears in
55L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
56
57The call to EVP_VerifyFinal() internally finalizes a copy of the digest context.
58This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can be called
59later to digest and verify additional data.
60
61Since only a copy of the digest context is ever finalized the context must
62be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
63will occur.
64
65=head1 BUGS
66
67Older versions of this documentation wrongly stated that calls to
68EVP_VerifyUpdate() could not be made after calling EVP_VerifyFinal().
69
70=head1 SEE ALSO
71
72L<evp(3)|evp(3)>,
73L<EVP_SignInit(3)|EVP_SignInit(3)>,
74L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
75L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
76L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
77L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
78
79=head1 HISTORY
80
81EVP_VerifyInit(), EVP_VerifyUpdate() and EVP_VerifyFinal() are
82available in all versions of SSLeay and OpenSSL.
83
84EVP_VerifyInit_ex() was added in OpenSSL 0.9.7
85
86=cut
diff --git a/src/lib/libcrypto/doc/OBJ_nid2obj.pod b/src/lib/libcrypto/doc/OBJ_nid2obj.pod
new file mode 100644
index 0000000000..7dcc07923f
--- /dev/null
+++ b/src/lib/libcrypto/doc/OBJ_nid2obj.pod
@@ -0,0 +1,149 @@
1=pod
2
3=head1 NAME
4
5OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid,
6OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility
7functions
8
9=head1 SYNOPSIS
10
11 ASN1_OBJECT * OBJ_nid2obj(int n);
12 const char * OBJ_nid2ln(int n);
13 const char * OBJ_nid2sn(int n);
14
15 int OBJ_obj2nid(const ASN1_OBJECT *o);
16 int OBJ_ln2nid(const char *ln);
17 int OBJ_sn2nid(const char *sn);
18
19 int OBJ_txt2nid(const char *s);
20
21 ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
22 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
23
24 int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
25 ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
26
27 int OBJ_create(const char *oid,const char *sn,const char *ln);
28 void OBJ_cleanup(void);
29
30=head1 DESCRIPTION
31
32The ASN1 object utility functions process ASN1_OBJECT structures which are
33a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
34
35OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID B<n> to
36an ASN1_OBJECT structure, its long name and its short name respectively,
37or B<NULL> is an error occurred.
38
39OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
40for the object B<o>, the long name <ln> or the short name <sn> respectively
41or NID_undef if an error occurred.
42
43OBJ_txt2nid() returns NID corresponding to text string <s>. B<s> can be
44a long name, a short name or the numerical respresentation of an object.
45
46OBJ_txt2obj() converts the text string B<s> into an ASN1_OBJECT structure.
47If B<no_name> is 0 then long names and short names will be interpreted
48as well as numerical forms. If B<no_name> is 1 only the numerical form
49is acceptable.
50
51OBJ_obj2txt() converts the B<ASN1_OBJECT> B<a> into a textual representation.
52The representation is written as a null terminated string to B<buf>
53at most B<buf_len> bytes are written, truncating the result if necessary.
54The total amount of space required is returned. If B<no_name> is 0 then
55if the object has a long or short name then that will be used, otherwise
56the numerical form will be used. If B<no_name> is 1 then the numerical
57form will always be used.
58
59OBJ_cmp() compares B<a> to B<b>. If the two are identical 0 is returned.
60
61OBJ_dup() returns a copy of B<o>.
62
63OBJ_create() adds a new object to the internal table. B<oid> is the
64numerical form of the object, B<sn> the short name and B<ln> the
65long name. A new NID is returned for the created object.
66
67OBJ_cleanup() cleans up OpenSSLs internal object table: this should
68be called before an application exits if any new objects were added
69using OBJ_create().
70
71=head1 NOTES
72
73Objects in OpenSSL can have a short name, a long name and a numerical
74identifier (NID) associated with them. A standard set of objects is
75represented in an internal table. The appropriate values are defined
76in the header file B<objects.h>.
77
78For example the OID for commonName has the following definitions:
79
80 #define SN_commonName "CN"
81 #define LN_commonName "commonName"
82 #define NID_commonName 13
83
84New objects can be added by calling OBJ_create().
85
86Table objects have certain advantages over other objects: for example
87their NIDs can be used in a C language switch statement. They are
88also static constant structures which are shared: that is there
89is only a single constant structure for each table object.
90
91Objects which are not in the table have the NID value NID_undef.
92
93Objects do not need to be in the internal tables to be processed,
94the functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
95form of an OID.
96
97=head1 EXAMPLES
98
99Create an object for B<commonName>:
100
101 ASN1_OBJECT *o;
102 o = OBJ_nid2obj(NID_commonName);
103
104Check if an object is B<commonName>
105
106 if (OBJ_obj2nid(obj) == NID_commonName)
107 /* Do something */
108
109Create a new NID and initialize an object from it:
110
111 int new_nid;
112 ASN1_OBJECT *obj;
113 new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
114
115 obj = OBJ_nid2obj(new_nid);
116
117Create a new object directly:
118
119 obj = OBJ_txt2obj("1.2.3.4", 1);
120
121=head1 BUGS
122
123OBJ_obj2txt() is awkward and messy to use: it doesn't follow the
124convention of other OpenSSL functions where the buffer can be set
125to B<NULL> to determine the amount of data that should be written.
126Instead B<buf> must point to a valid buffer and B<buf_len> should
127be set to a positive value. A buffer length of 80 should be more
128than enough to handle any OID encountered in practice.
129
130=head1 RETURN VALUES
131
132OBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
133error occurred.
134
135OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
136on error.
137
138OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
139a NID or B<NID_undef> on error.
140
141=head1 SEE ALSO
142
143L<ERR_get_error(3)|ERR_get_error(3)>
144
145=head1 HISTORY
146
147TBA
148
149=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod b/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
new file mode 100644
index 0000000000..c39ac35e78
--- /dev/null
+++ b/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
@@ -0,0 +1,101 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_VERSION_NUMBER, SSLeay, SSLeay_version - get OpenSSL version number
6
7=head1 SYNOPSIS
8
9 #include <openssl/opensslv.h>
10 #define OPENSSL_VERSION_NUMBER 0xnnnnnnnnnL
11
12 #include <openssl/crypto.h>
13 long SSLeay(void);
14 const char *SSLeay_version(int t);
15
16=head1 DESCRIPTION
17
18OPENSSL_VERSION_NUMBER is a numeric release version identifier:
19
20 MMNNFFPPS: major minor fix patch status
21
22The status nibble has one of the values 0 for development, 1 to e for betas
231 to 14, and f for release.
24
25for example
26
27 0x000906000 == 0.9.6 dev
28 0x000906023 == 0.9.6b beta 3
29 0x00090605f == 0.9.6e release
30
31Versions prior to 0.9.3 have identifiers E<lt> 0x0930.
32Versions between 0.9.3 and 0.9.5 had a version identifier with this
33interpretation:
34
35 MMNNFFRBB major minor fix final beta/patch
36
37for example
38
39 0x000904100 == 0.9.4 release
40 0x000905000 == 0.9.5 dev
41
42Version 0.9.5a had an interim interpretation that is like the current one,
43except the patch level got the highest bit set, to keep continuity. The
44number was therefore 0x0090581f.
45
46
47For backward compatibility, SSLEAY_VERSION_NUMBER is also defined.
48
49SSLeay() returns this number. The return value can be compared to the
50macro to make sure that the correct version of the library has been
51loaded, especially when using DLLs on Windows systems.
52
53SSLeay_version() returns different strings depending on B<t>:
54
55=over 4
56
57=item SSLEAY_VERSION
58
59The text variant of the version number and the release date. For example,
60"OpenSSL 0.9.5a 1 Apr 2000".
61
62=item SSLEAY_CFLAGS
63
64The compiler flags set for the compilation process in the form
65"compiler: ..." if available or "compiler: information not available"
66otherwise.
67
68=item SSLEAY_BUILT_ON
69
70The date of the build process in the form "built on: ..." if available
71or "built on: date not available" otherwise.
72
73=item SSLEAY_PLATFORM
74
75The "Configure" target of the library build in the form "platform: ..."
76if available or "platform: information not available" otherwise.
77
78=item SSLEAY_DIR
79
80The "OPENSSLDIR" setting of the library build in the form "OPENSSLDIR: "...""
81if available or "OPENSSLDIR: N/A" otherwise.
82
83=back
84
85For an unknown B<t>, the text "not available" is returned.
86
87=head1 RETURN VALUE
88
89The version number.
90
91=head1 SEE ALSO
92
93L<crypto(3)|crypto(3)>
94
95=head1 HISTORY
96
97SSLeay() and SSLEAY_VERSION_NUMBER are available in all versions of SSLeay and OpenSSL.
98OPENSSL_VERSION_NUMBER is available in all versions of OpenSSL.
99B<SSLEAY_DIR> was added in OpenSSL 0.9.7.
100
101=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_config.pod b/src/lib/libcrypto/doc/OPENSSL_config.pod
new file mode 100644
index 0000000000..16600620cc
--- /dev/null
+++ b/src/lib/libcrypto/doc/OPENSSL_config.pod
@@ -0,0 +1,82 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_config, OPENSSL_no_config - simple OpenSSL configuration functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/conf.h>
10
11 void OPENSSL_config(const char *config_name);
12 void OPENSSL_no_config(void);
13
14=head1 DESCRIPTION
15
16OPENSSL_config() configures OpenSSL using the standard B<openssl.cnf>
17configuration file name using B<config_name>. If B<config_name> is NULL then
18the default name B<openssl_conf> will be used. Any errors are ignored. Further
19calls to OPENSSL_config() will have no effect. The configuration file format
20is documented in the L<conf(5)|conf(5)> manual page.
21
22OPENSSL_no_config() disables configuration. If called before OPENSSL_config()
23no configuration takes place.
24
25=head1 NOTES
26
27It is B<strongly> recommended that B<all> new applications call OPENSSL_config()
28or the more sophisticated functions such as CONF_modules_load() during
29initialization (that is before starting any threads). By doing this
30an application does not need to keep track of all configuration options
31and some new functionality can be supported automatically.
32
33It is also possible to automatically call OPENSSL_config() when an application
34calls OPENSSL_add_all_algorithms() by compiling an application with the
35preprocessor symbol B<OPENSSL_LOAD_CONF> #define'd. In this way configuration
36can be added without source changes.
37
38The environment variable B<OPENSSL_CONFIG> can be set to specify the location
39of the configuration file.
40
41Currently ASN1 OBJECTs and ENGINE configuration can be performed future
42versions of OpenSSL will add new configuration options.
43
44There are several reasons why calling the OpenSSL configuration routines is
45advisable. For example new ENGINE functionality was added to OpenSSL 0.9.7.
46In OpenSSL 0.9.7 control functions can be supported by ENGINEs, this can be
47used (among other things) to load dynamic ENGINEs from shared libraries (DSOs).
48However very few applications currently support the control interface and so
49very few can load and use dynamic ENGINEs. Equally in future more sophisticated
50ENGINEs will require certain control operations to customize them. If an
51application calls OPENSSL_config() it doesn't need to know or care about
52ENGINE control operations because they can be performed by editing a
53configuration file.
54
55Applications should free up configuration at application closedown by calling
56CONF_modules_free().
57
58=head1 RESTRICTIONS
59
60The OPENSSL_config() function is designed to be a very simple "call it and
61forget it" function. As a result its behaviour is somewhat limited. It ignores
62all errors silently and it can only load from the standard configuration file
63location for example.
64
65It is however B<much> better than nothing. Applications which need finer
66control over their configuration functionality should use the configuration
67functions such as CONF_load_modules() directly.
68
69=head1 RETURN VALUES
70
71Neither OPENSSL_config() nor OPENSSL_no_config() return a value.
72
73=head1 SEE ALSO
74
75L<conf(5)|conf(5)>, L<CONF_load_modules_file(3)|CONF_load_modules_file(3)>,
76L<CONF_modules_free(3),CONF_modules_free(3)>
77
78=head1 HISTORY
79
80OPENSSL_config() and OPENSSL_no_config() first appeared in OpenSSL 0.9.7
81
82=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod b/src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod
new file mode 100644
index 0000000000..f14dfaf005
--- /dev/null
+++ b/src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_load_builtin_modules - add standard configuration modules
6
7=head1 SYNOPSIS
8
9 #include <openssl/conf.h>
10
11 void OPENSSL_load_builtin_modules(void);
12 void ASN1_add_oid_module(void);
13 ENGINE_add_conf_module();
14
15=head1 DESCRIPTION
16
17The function OPENSSL_load_builtin_modules() adds all the standard OpenSSL
18configuration modules to the internal list. They can then be used by the
19OpenSSL configuration code.
20
21ASN1_add_oid_module() adds just the ASN1 OBJECT module.
22
23ENGINE_add_conf_module() adds just the ENGINE configuration module.
24
25=head1 NOTES
26
27If the simple configuration function OPENSSL_config() is called then
28OPENSSL_load_builtin_modules() is called automatically.
29
30Applications which use the configuration functions directly will need to
31call OPENSSL_load_builtin_modules() themselves I<before> any other
32configuration code.
33
34Applications should call OPENSSL_load_builtin_modules() to load all
35configuration modules instead of adding modules selectively: otherwise
36functionality may be missing from the application if an when new
37modules are added.
38
39=head1 RETURN VALUE
40
41None of the functions return a value.
42
43=head1 SEE ALSO
44
45L<conf(3)|conf(3)>, L<OPENSSL_config(3)|OPENSSL_config(3)>
46
47=head1 HISTORY
48
49These functions first appeared in OpenSSL 0.9.7.
50
51=cut
diff --git a/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod b/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
new file mode 100644
index 0000000000..e63411b5bb
--- /dev/null
+++ b/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5OpenSSL_add_all_algorithms, OpenSSL_add_all_ciphers, OpenSSL_add_all_digests -
6add algorithms to internal table
7
8=head1 SYNOPSIS
9
10 #include <openssl/evp.h>
11
12 void OpenSSL_add_all_algorithms(void);
13 void OpenSSL_add_all_ciphers(void);
14 void OpenSSL_add_all_digests(void);
15
16 void EVP_cleanup(void);
17
18=head1 DESCRIPTION
19
20OpenSSL keeps an internal table of digest algorithms and ciphers. It uses
21this table to lookup ciphers via functions such as EVP_get_cipher_byname().
22
23OpenSSL_add_all_digests() adds all digest algorithms to the table.
24
25OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and
26ciphers).
27
28OpenSSL_add_all_ciphers() adds all encryption algorithms to the table including
29password based encryption algorithms.
30
31EVP_cleanup() removes all ciphers and digests from the table.
32
33=head1 RETURN VALUES
34
35None of the functions return a value.
36
37=head1 NOTES
38
39A typical application will call OpenSSL_add_all_algorithms() initially and
40EVP_cleanup() before exiting.
41
42An application does not need to add algorithms to use them explicitly, for example
43by EVP_sha1(). It just needs to add them if it (or any of the functions it calls)
44needs to lookup algorithms.
45
46The cipher and digest lookup functions are used in many parts of the library. If
47the table is not initialized several functions will misbehave and complain they
48cannot find algorithms. This includes the PEM, PKCS#12, SSL and S/MIME libraries.
49This is a common query in the OpenSSL mailing lists.
50
51Calling OpenSSL_add_all_algorithms() links in all algorithms: as a result a
52statically linked executable can be quite large. If this is important it is possible
53to just add the required ciphers and digests.
54
55=head1 BUGS
56
57Although the functions do not return error codes it is possible for them to fail.
58This will only happen as a result of a memory allocation failure so this is not
59too much of a problem in practice.
60
61=head1 SEE ALSO
62
63L<evp(3)|evp(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
64L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
65
66=cut
diff --git a/src/lib/libcrypto/doc/PKCS12_create.pod b/src/lib/libcrypto/doc/PKCS12_create.pod
new file mode 100644
index 0000000000..48f3bb8cb8
--- /dev/null
+++ b/src/lib/libcrypto/doc/PKCS12_create.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5PKCS12_create - create a PKCS#12 structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/pkcs12.h>
10
11 PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, STACK_OF(X509) *ca,
12 int nid_key, int nid_cert, int iter, int mac_iter, int keytype);
13
14=head1 DESCRIPTION
15
16PKCS12_create() creates a PKCS#12 structure.
17
18B<pass> is the passphrase to use. B<name> is the B<friendlyName> to use for
19the supplied certifictate and key. B<pkey> is the private key to include in
20the structure and B<cert> its corresponding certificates. B<ca>, if not B<NULL>
21is an optional set of certificates to also include in the structure.
22
23B<nid_key> and B<nid_cert> are the encryption algorithms that should be used
24for the key and certificate respectively. B<iter> is the encryption algorithm
25iteration count to use and B<mac_iter> is the MAC iteration count to use.
26B<keytype> is the type of key.
27
28=head1 NOTES
29
30The parameters B<nid_key>, B<nid_cert>, B<iter>, B<mac_iter> and B<keytype>
31can all be set to zero and sensible defaults will be used.
32
33These defaults are: 40 bit RC2 encryption for certificates, triple DES
34encryption for private keys, a key iteration count of PKCS12_DEFAULT_ITER
35(currently 2048) and a MAC iteration count of 1.
36
37The default MAC iteration count is 1 in order to retain compatibility with
38old software which did not interpret MAC iteration counts. If such compatibility
39is not required then B<mac_iter> should be set to PKCS12_DEFAULT_ITER.
40
41B<keytype> adds a flag to the store private key. This is a non standard extension
42that is only currently interpreted by MSIE. If set to zero the flag is omitted,
43if set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX>
44it can be used for signing and encryption. This option was useful for old
45export grade software which could use signing only keys of arbitrary size but
46had restrictions on the permissible sizes of keys which could be used for
47encryption.
48
49=head1 SEE ALSO
50
51L<d2i_PKCS12(3)|d2i_PKCS12(3)>
52
53=head1 HISTORY
54
55PKCS12_create was added in OpenSSL 0.9.3
56
57=cut
diff --git a/src/lib/libcrypto/doc/PKCS12_parse.pod b/src/lib/libcrypto/doc/PKCS12_parse.pod
new file mode 100644
index 0000000000..51344f883a
--- /dev/null
+++ b/src/lib/libcrypto/doc/PKCS12_parse.pod
@@ -0,0 +1,50 @@
1=pod
2
3=head1 NAME
4
5PKCS12_parse - parse a PKCS#12 structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/pkcs12.h>
10
11int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);
12
13=head1 DESCRIPTION
14
15PKCS12_parse() parses a PKCS12 structure.
16
17B<p12> is the B<PKCS12> structure to parse. B<pass> is the passphrase to use.
18If successful the private key will be written to B<*pkey>, the corresponding
19certificate to B<*cert> and any additional certificates to B<*ca>.
20
21=head1 NOTES
22
23The parameters B<pkey> and B<cert> cannot be B<NULL>. B<ca> can be <NULL>
24in which case additional certificates will be discarded. B<*ca> can also
25be a valid STACK in which case additional certificates are appended to
26B<*ca>. If B<*ca> is B<NULL> a new STACK will be allocated.
27
28The B<friendlyName> and B<localKeyID> attributes (if present) on each certificate
29will be stored in the B<alias> and B<keyid> attributes of the B<X509> structure.
30
31=head1 BUGS
32
33Only a single private key and corresponding certificate is returned by this function.
34More complex PKCS#12 files with multiple private keys will only return the first
35match.
36
37Only B<friendlyName> and B<localKeyID> attributes are currently stored in certificates.
38Other attributes are discarded.
39
40Attributes currently cannot be store in the private key B<EVP_PKEY> structure.
41
42=head1 SEE ALSO
43
44L<d2i_PKCS12(3)|d2i_PKCS12(3)>
45
46=head1 HISTORY
47
48PKCS12_parse was added in OpenSSL 0.9.3
49
50=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_decrypt.pod b/src/lib/libcrypto/doc/PKCS7_decrypt.pod
new file mode 100644
index 0000000000..b0ca067b89
--- /dev/null
+++ b/src/lib/libcrypto/doc/PKCS7_decrypt.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5PKCS7_decrypt - decrypt content from a PKCS#7 envelopedData structure
6
7=head1 SYNOPSIS
8
9int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
10
11=head1 DESCRIPTION
12
13PKCS7_decrypt() extracts and decrypts the content from a PKCS#7 envelopedData
14structure. B<pkey> is the private key of the recipient, B<cert> is the
15recipients certificate, B<data> is a BIO to write the content to and
16B<flags> is an optional set of flags.
17
18=head1 NOTES
19
20OpenSSL_add_all_algorithms() (or equivalent) should be called before using this
21function or errors about unknown algorithms will occur.
22
23Although the recipients certificate is not needed to decrypt the data it is needed
24to locate the appropriate (of possible several) recipients in the PKCS#7 structure.
25
26The following flags can be passed in the B<flags> parameter.
27
28If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
29from the content. If the content is not of type B<text/plain> then an error is
30returned.
31
32=head1 RETURN VALUES
33
34PKCS7_decrypt() returns either 1 for success or 0 for failure.
35The error can be obtained from ERR_get_error(3)
36
37=head1 BUGS
38
39PKCS7_decrypt() must be passed the correct recipient key and certificate. It would
40be better if it could look up the correct key and certificate from a database.
41
42The lack of single pass processing and need to hold all data in memory as
43mentioned in PKCS7_sign() also applies to PKCS7_verify().
44
45=head1 SEE ALSO
46
47L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
48
49=head1 HISTORY
50
51PKCS7_decrypt() was added to OpenSSL 0.9.5
52
53=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_encrypt.pod b/src/lib/libcrypto/doc/PKCS7_encrypt.pod
new file mode 100644
index 0000000000..1a507b22a2
--- /dev/null
+++ b/src/lib/libcrypto/doc/PKCS7_encrypt.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5PKCS7_encrypt - create a PKCS#7 envelopedData structure
6
7=head1 SYNOPSIS
8
9PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags);
10
11=head1 DESCRIPTION
12
13PKCS7_encrypt() creates and returns a PKCS#7 envelopedData structure. B<certs>
14is a list of recipient certificates. B<in> is the content to be encrypted.
15B<cipher> is the symmetric cipher to use. B<flags> is an optional set of flags.
16
17=head1 NOTES
18
19Only RSA keys are supported in PKCS#7 and envelopedData so the recipient certificates
20supplied to this function must all contain RSA public keys, though they do not have to
21be signed using the RSA algorithm.
22
23EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use because
24most clients will support it.
25
26Some old "export grade" clients may only support weak encryption using 40 or 64 bit
27RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc() respectively.
28
29The algorithm passed in the B<cipher> parameter must support ASN1 encoding of its
30parameters.
31
32Many browsers implement a "sign and encrypt" option which is simply an S/MIME
33envelopedData containing an S/MIME signed message. This can be readily produced
34by storing the S/MIME signed message in a memory BIO and passing it to
35PKCS7_encrypt().
36
37The following flags can be passed in the B<flags> parameter.
38
39If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended
40to the data.
41
42Normally the supplied content is translated into MIME canonical format (as required
43by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation occurs. This
44option should be used if the supplied data is in binary format otherwise the translation
45will corrupt it. If B<PKCS7_BINARY> is set then B<PKCS7_TEXT> is ignored.
46
47=head1 RETURN VALUES
48
49PKCS7_encrypt() returns either a valid PKCS7 structure or NULL if an error occurred.
50The error can be obtained from ERR_get_error(3).
51
52=head1 BUGS
53
54The lack of single pass processing and need to hold all data in memory as
55mentioned in PKCS7_sign() also applies to PKCS7_verify().
56
57=head1 SEE ALSO
58
59L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
60
61=head1 HISTORY
62
63PKCS7_decrypt() was added to OpenSSL 0.9.5
64
65=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_sign.pod b/src/lib/libcrypto/doc/PKCS7_sign.pod
new file mode 100644
index 0000000000..fc7e649b34
--- /dev/null
+++ b/src/lib/libcrypto/doc/PKCS7_sign.pod
@@ -0,0 +1,85 @@
1=pod
2
3=head1 NAME
4
5PKCS7_sign - create a PKCS#7 signedData structure
6
7=head1 SYNOPSIS
8
9PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags);
10
11=head1 DESCRIPTION
12
13PKCS7_sign() creates and returns a PKCS#7 signedData structure. B<signcert>
14is the certificate to sign with, B<pkey> is the corresponsding private key.
15B<certs> is an optional additional set of certificates to include in the
16PKCS#7 structure (for example any intermediate CAs in the chain).
17
18The data to be signed is read from BIO B<data>.
19
20B<flags> is an optional set of flags.
21
22=head1 NOTES
23
24Any of the following flags (ored together) can be passed in the B<flags> parameter.
25
26Many S/MIME clients expect the signed content to include valid MIME headers. If
27the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended
28to the data.
29
30If B<PKCS7_NOCERTS> is set the signer's certificate will not be included in the
31PKCS7 structure, the signer's certificate must still be supplied in the B<signcert>
32parameter though. This can reduce the size of the signature if the signers certificate
33can be obtained by other means: for example a previously signed message.
34
35The data being signed is included in the PKCS7 structure, unless B<PKCS7_DETACHED>
36is set in which case it is omitted. This is used for PKCS7 detached signatures
37which are used in S/MIME plaintext signed messages for example.
38
39Normally the supplied content is translated into MIME canonical format (as required
40by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation occurs. This
41option should be used if the supplied data is in binary format otherwise the translation
42will corrupt it.
43
44The signedData structure includes several PKCS#7 autenticatedAttributes including
45the signing time, the PKCS#7 content type and the supported list of ciphers in
46an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no authenticatedAttributes
47will be used. If B<PKCS7_NOSMIMECAP> is set then just the SMIMECapabilities are
48omitted.
49
50If present the SMIMECapabilities attribute indicates support for the following
51algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any
52of these algorithms is disabled then it will not be included.
53
54=head1 BUGS
55
56PKCS7_sign() is somewhat limited. It does not support multiple signers, some
57advanced attributes such as counter signatures are not supported.
58
59The SHA1 digest algorithm is currently always used.
60
61When the signed data is not detached it will be stored in memory within the
62B<PKCS7> structure. This effectively limits the size of messages which can be
63signed due to memory restraints. There should be a way to sign data without
64having to hold it all in memory, this would however require fairly major
65revisions of the OpenSSL ASN1 code.
66
67Clear text signing does not store the content in memory but the way PKCS7_sign()
68operates means that two passes of the data must typically be made: one to compute
69the signatures and a second to output the data along with the signature. There
70should be a way to process the data with only a single pass.
71
72=head1 RETURN VALUES
73
74PKCS7_sign() returns either a valid PKCS7 structure or NULL if an error occurred.
75The error can be obtained from ERR_get_error(3).
76
77=head1 SEE ALSO
78
79L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_verify(3)|PKCS7_verify(3)>
80
81=head1 HISTORY
82
83PKCS7_sign() was added to OpenSSL 0.9.5
84
85=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_verify.pod b/src/lib/libcrypto/doc/PKCS7_verify.pod
new file mode 100644
index 0000000000..07c9fdad40
--- /dev/null
+++ b/src/lib/libcrypto/doc/PKCS7_verify.pod
@@ -0,0 +1,116 @@
1=pod
2
3=head1 NAME
4
5PKCS7_verify - verify a PKCS#7 signedData structure
6
7=head1 SYNOPSIS
8
9int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, int flags);
10
11int PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
12
13=head1 DESCRIPTION
14
15PKCS7_verify() verifies a PKCS#7 signedData structure. B<p7> is the PKCS7
16structure to verify. B<certs> is a set of certificates in which to search for
17the signer's certificate. B<store> is a trusted certficate store (used for
18chain verification). B<indata> is the signed data if the content is not
19present in B<p7> (that is it is detached). The content is written to B<out>
20if it is not NULL.
21
22B<flags> is an optional set of flags, which can be used to modify the verify
23operation.
24
25PKCS7_get0_signers() retrieves the signer's certificates from B<p7>, it does
26B<not> check their validity or whether any signatures are valid. The B<certs>
27and B<flags> parameters have the same meanings as in PKCS7_verify().
28
29=head1 VERIFY PROCESS
30
31Normally the verify process proceeds as follows.
32
33Initially some sanity checks are performed on B<p7>. The type of B<p7> must
34be signedData. There must be at least one signature on the data and if
35the content is detached B<indata> cannot be B<NULL>.
36
37An attempt is made to locate all the signer's certificates, first looking in
38the B<certs> parameter (if it is not B<NULL>) and then looking in any certificates
39contained in the B<p7> structure itself. If any signer's certificates cannot be
40located the operation fails.
41
42Each signer's certificate is chain verified using the B<smimesign> purpose and
43the supplied trusted certificate store. Any internal certificates in the message
44are used as untrusted CAs. If any chain verify fails an error code is returned.
45
46Finally the signed content is read (and written to B<out> is it is not NULL) and
47the signature's checked.
48
49If all signature's verify correctly then the function is successful.
50
51Any of the following flags (ored together) can be passed in the B<flags> parameter
52to change the default verify behaviour. Only the flag B<PKCS7_NOINTERN> is
53meaningful to PKCS7_get0_signers().
54
55If B<PKCS7_NOINTERN> is set the certificates in the message itself are not
56searched when locating the signer's certificate. This means that all the signers
57certificates must be in the B<certs> parameter.
58
59If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
60from the content. If the content is not of type B<text/plain> then an error is
61returned.
62
63If B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified.
64
65If B<PKCS7_NOCHAIN> is set then the certificates contained in the message are
66not used as untrusted CAs. This means that the whole verify chain (apart from
67the signer's certificate) must be contained in the trusted store.
68
69If B<PKCS7_NOSIGS> is set then the signatures on the data are not checked.
70
71=head1 NOTES
72
73One application of B<PKCS7_NOINTERN> is to only accept messages signed by
74a small number of certificates. The acceptable certificates would be passed
75in the B<certs> parameter. In this case if the signer is not one of the
76certificates supplied in B<certs> then the verify will fail because the
77signer cannot be found.
78
79Care should be taken when modifying the default verify behaviour, for example
80setting B<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification
81and any signed message will be considered valid. This combination is however
82useful if one merely wishes to write the content to B<out> and its validity
83is not considered important.
84
85Chain verification should arguably be performed using the signing time rather
86than the current time. However since the signing time is supplied by the
87signer it cannot be trusted without additional evidence (such as a trusted
88timestamp).
89
90=head1 RETURN VALUES
91
92PKCS7_verify() returns 1 for a successful verification and zero or a negative
93value if an error occurs.
94
95PKCS7_get0_signers() returns all signers or B<NULL> if an error occurred.
96
97The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
98
99=head1 BUGS
100
101The trusted certificate store is not searched for the signers certificate,
102this is primarily due to the inadequacies of the current B<X509_STORE>
103functionality.
104
105The lack of single pass processing and need to hold all data in memory as
106mentioned in PKCS7_sign() also applies to PKCS7_verify().
107
108=head1 SEE ALSO
109
110L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>
111
112=head1 HISTORY
113
114PKCS7_verify() was added to OpenSSL 0.9.5
115
116=cut
diff --git a/src/lib/libcrypto/doc/RAND_add.pod b/src/lib/libcrypto/doc/RAND_add.pod
new file mode 100644
index 0000000000..67c66f3e0c
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_add.pod
@@ -0,0 +1,77 @@
1=pod
2
3=head1 NAME
4
5RAND_add, RAND_seed, RAND_status, RAND_event, RAND_screen - add
6entropy to the PRNG
7
8=head1 SYNOPSIS
9
10 #include <openssl/rand.h>
11
12 void RAND_seed(const void *buf, int num);
13
14 void RAND_add(const void *buf, int num, double entropy);
15
16 int RAND_status(void);
17
18 int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam);
19 void RAND_screen(void);
20
21=head1 DESCRIPTION
22
23RAND_add() mixes the B<num> bytes at B<buf> into the PRNG state. Thus,
24if the data at B<buf> are unpredictable to an adversary, this
25increases the uncertainty about the state and makes the PRNG output
26less predictable. Suitable input comes from user interaction (random
27key presses, mouse movements) and certain hardware events. The
28B<entropy> argument is (the lower bound of) an estimate of how much
29randomness is contained in B<buf>, measured in bytes. Details about
30sources of randomness and how to estimate their entropy can be found
31in the literature, e.g. RFC 1750.
32
33RAND_add() may be called with sensitive data such as user entered
34passwords. The seed values cannot be recovered from the PRNG output.
35
36OpenSSL makes sure that the PRNG state is unique for each thread. On
37systems that provide C</dev/urandom>, the randomness device is used
38to seed the PRNG transparently. However, on all other systems, the
39application is responsible for seeding the PRNG by calling RAND_add(),
40L<RAND_egd(3)|RAND_egd(3)>
41or L<RAND_load_file(3)|RAND_load_file(3)>.
42
43RAND_seed() is equivalent to RAND_add() when B<num == entropy>.
44
45RAND_event() collects the entropy from Windows events such as mouse
46movements and other user interaction. It should be called with the
47B<iMsg>, B<wParam> and B<lParam> arguments of I<all> messages sent to
48the window procedure. It will estimate the entropy contained in the
49event message (if any), and add it to the PRNG. The program can then
50process the messages as usual.
51
52The RAND_screen() function is available for the convenience of Windows
53programmers. It adds the current contents of the screen to the PRNG.
54For applications that can catch Windows events, seeding the PRNG by
55calling RAND_event() is a significantly better source of
56randomness. It should be noted that both methods cannot be used on
57servers that run without user interaction.
58
59=head1 RETURN VALUES
60
61RAND_status() and RAND_event() return 1 if the PRNG has been seeded
62with enough data, 0 otherwise.
63
64The other functions do not return values.
65
66=head1 SEE ALSO
67
68L<rand(3)|rand(3)>, L<RAND_egd(3)|RAND_egd(3)>,
69L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
70
71=head1 HISTORY
72
73RAND_seed() and RAND_screen() are available in all versions of SSLeay
74and OpenSSL. RAND_add() and RAND_status() have been added in OpenSSL
750.9.5, RAND_event() in OpenSSL 0.9.5a.
76
77=cut
diff --git a/src/lib/libcrypto/doc/RAND_bytes.pod b/src/lib/libcrypto/doc/RAND_bytes.pod
new file mode 100644
index 0000000000..ce6329ce54
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_bytes.pod
@@ -0,0 +1,47 @@
1=pod
2
3=head1 NAME
4
5RAND_bytes, RAND_pseudo_bytes - generate random data
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 int RAND_bytes(unsigned char *buf, int num);
12
13 int RAND_pseudo_bytes(unsigned char *buf, int num);
14
15=head1 DESCRIPTION
16
17RAND_bytes() puts B<num> cryptographically strong pseudo-random bytes
18into B<buf>. An error occurs if the PRNG has not been seeded with
19enough randomness to ensure an unpredictable byte sequence.
20
21RAND_pseudo_bytes() puts B<num> pseudo-random bytes into B<buf>.
22Pseudo-random byte sequences generated by RAND_pseudo_bytes() will be
23unique if they are of sufficient length, but are not necessarily
24unpredictable. They can be used for non-cryptographic purposes and for
25certain purposes in cryptographic protocols, but usually not for key
26generation etc.
27
28=head1 RETURN VALUES
29
30RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
31obtained by L<ERR_get_error(3)|ERR_get_error(3)>. RAND_pseudo_bytes() returns 1 if the
32bytes generated are cryptographically strong, 0 otherwise. Both
33functions return -1 if they are not supported by the current RAND
34method.
35
36=head1 SEE ALSO
37
38L<rand(3)|rand(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
39L<RAND_add(3)|RAND_add(3)>
40
41=head1 HISTORY
42
43RAND_bytes() is available in all versions of SSLeay and OpenSSL. It
44has a return value since OpenSSL 0.9.5. RAND_pseudo_bytes() was added
45in OpenSSL 0.9.5.
46
47=cut
diff --git a/src/lib/libcrypto/doc/RAND_cleanup.pod b/src/lib/libcrypto/doc/RAND_cleanup.pod
new file mode 100644
index 0000000000..3a8f0749a8
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_cleanup.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5RAND_cleanup - erase the PRNG state
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_cleanup(void);
12
13=head1 DESCRIPTION
14
15RAND_cleanup() erases the memory used by the PRNG.
16
17=head1 RETURN VALUE
18
19RAND_cleanup() returns no value.
20
21=head1 SEE ALSO
22
23L<rand(3)|rand(3)>
24
25=head1 HISTORY
26
27RAND_cleanup() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libcrypto/doc/RAND_load_file.pod b/src/lib/libcrypto/doc/RAND_load_file.pod
new file mode 100644
index 0000000000..d8c134e621
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_load_file.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 const char *RAND_file_name(char *buf, size_t num);
12
13 int RAND_load_file(const char *filename, long max_bytes);
14
15 int RAND_write_file(const char *filename);
16
17=head1 DESCRIPTION
18
19RAND_file_name() generates a default path for the random seed
20file. B<buf> points to a buffer of size B<num> in which to store the
21filename. The seed file is $RANDFILE if that environment variable is
22set, $HOME/.rnd otherwise. If $HOME is not set either, or B<num> is
23too small for the path name, an error occurs.
24
25RAND_load_file() reads a number of bytes from file B<filename> and
26adds them to the PRNG. If B<max_bytes> is non-negative,
27up to to B<max_bytes> are read; starting with OpenSSL 0.9.5,
28if B<max_bytes> is -1, the complete file is read.
29
30RAND_write_file() writes a number of random bytes (currently 1024) to
31file B<filename> which can be used to initialize the PRNG by calling
32RAND_load_file() in a later session.
33
34=head1 RETURN VALUES
35
36RAND_load_file() returns the number of bytes read.
37
38RAND_write_file() returns the number of bytes written, and -1 if the
39bytes written were generated without appropriate seed.
40
41RAND_file_name() returns a pointer to B<buf> on success, and NULL on
42error.
43
44=head1 SEE ALSO
45
46L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
47
48=head1 HISTORY
49
50RAND_load_file(), RAND_write_file() and RAND_file_name() are available in
51all versions of SSLeay and OpenSSL.
52
53=cut
diff --git a/src/lib/libcrypto/doc/RAND_set_rand_method.pod b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
new file mode 100644
index 0000000000..c9bb6d9f27
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
@@ -0,0 +1,83 @@
1=pod
2
3=head1 NAME
4
5RAND_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND method
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_set_rand_method(const RAND_METHOD *meth);
12
13 const RAND_METHOD *RAND_get_rand_method(void);
14
15 RAND_METHOD *RAND_SSLeay(void);
16
17=head1 DESCRIPTION
18
19A B<RAND_METHOD> specifies the functions that OpenSSL uses for random number
20generation. By modifying the method, alternative implementations such as
21hardware RNGs may be used. IMPORTANT: See the NOTES section for important
22information about how these RAND API functions are affected by the use of
23B<ENGINE> API calls.
24
25Initially, the default RAND_METHOD is the OpenSSL internal implementation, as
26returned by RAND_SSLeay().
27
28RAND_set_default_method() makes B<meth> the method for PRNG use. B<NB>: This is
29true only whilst no ENGINE has been set as a default for RAND, so this function
30is no longer recommended.
31
32RAND_get_default_method() returns a pointer to the current RAND_METHOD.
33However, the meaningfulness of this result is dependant on whether the ENGINE
34API is being used, so this function is no longer recommended.
35
36=head1 THE RAND_METHOD STRUCTURE
37
38 typedef struct rand_meth_st
39 {
40 void (*seed)(const void *buf, int num);
41 int (*bytes)(unsigned char *buf, int num);
42 void (*cleanup)(void);
43 void (*add)(const void *buf, int num, int entropy);
44 int (*pseudorand)(unsigned char *buf, int num);
45 int (*status)(void);
46 } RAND_METHOD;
47
48The components point to the implementation of RAND_seed(),
49RAND_bytes(), RAND_cleanup(), RAND_add(), RAND_pseudo_rand()
50and RAND_status().
51Each component may be NULL if the function is not implemented.
52
53=head1 RETURN VALUES
54
55RAND_set_rand_method() returns no value. RAND_get_rand_method() and
56RAND_SSLeay() return pointers to the respective methods.
57
58=head1 NOTES
59
60As of version 0.9.7, RAND_METHOD implementations are grouped together with other
61algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
62default ENGINE is specified for RAND functionality using an ENGINE API function,
63that will override any RAND defaults set using the RAND API (ie.
64RAND_set_rand_method()). For this reason, the ENGINE API is the recommended way
65to control default implementations for use in RAND and other cryptographic
66algorithms.
67
68=head1 SEE ALSO
69
70L<rand(3)|rand(3)>, L<engine(3)|engine(3)>
71
72=head1 HISTORY
73
74RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are
75available in all versions of OpenSSL.
76
77In the engine version of version 0.9.6, RAND_set_rand_method() was altered to
78take an ENGINE pointer as its argument. As of version 0.9.7, that has been
79reverted as the ENGINE API transparently overrides RAND defaults if used,
80otherwise RAND API functions work as before. RAND_set_rand_engine() was also
81introduced in version 0.9.7.
82
83=cut
diff --git a/src/lib/libcrypto/doc/RSA_blinding_on.pod b/src/lib/libcrypto/doc/RSA_blinding_on.pod
new file mode 100644
index 0000000000..fd2c69abd8
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_blinding_on.pod
@@ -0,0 +1,43 @@
1=pod
2
3=head1 NAME
4
5RSA_blinding_on, RSA_blinding_off - protect the RSA operation from timing attacks
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
12
13 void RSA_blinding_off(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA is vulnerable to timing attacks. In a setup where attackers can
18measure the time of RSA decryption or signature operations, blinding
19must be used to protect the RSA operation from that attack.
20
21RSA_blinding_on() turns blinding on for key B<rsa> and generates a
22random blinding factor. B<ctx> is B<NULL> or a pre-allocated and
23initialized B<BN_CTX>. The random number generator must be seeded
24prior to calling RSA_blinding_on().
25
26RSA_blinding_off() turns blinding off and frees the memory used for
27the blinding factor.
28
29=head1 RETURN VALUES
30
31RSA_blinding_on() returns 1 on success, and 0 if an error occurred.
32
33RSA_blinding_off() returns no value.
34
35=head1 SEE ALSO
36
37L<rsa(3)|rsa(3)>, L<rand(3)|rand(3)>
38
39=head1 HISTORY
40
41RSA_blinding_on() and RSA_blinding_off() appeared in SSLeay 0.9.0.
42
43=cut
diff --git a/src/lib/libcrypto/doc/RSA_check_key.pod b/src/lib/libcrypto/doc/RSA_check_key.pod
new file mode 100644
index 0000000000..a5198f3db5
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_check_key.pod
@@ -0,0 +1,67 @@
1=pod
2
3=head1 NAME
4
5RSA_check_key - validate private RSA keys
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_check_key(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function validates RSA keys. It checks that B<p> and B<q> are
16in fact prime, and that B<n = p*q>.
17
18It also checks that B<d*e = 1 mod (p-1*q-1)>,
19and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
20
21As such, this function can not be used with any arbitrary RSA key object,
22even if it is otherwise fit for regular RSA operation. See B<NOTES> for more
23information.
24
25=head1 RETURN VALUE
26
27RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
28-1 is returned if an error occurs while checking the key.
29
30If the key is invalid or an error occurred, the reason code can be
31obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
32
33=head1 NOTES
34
35This function does not work on RSA public keys that have only the modulus
36and public exponent elements populated. It performs integrity checks on all
37the RSA key material, so the RSA key structure must contain all the private
38key data too.
39
40Unlike most other RSA functions, this function does B<not> work
41transparently with any underlying ENGINE implementation because it uses the
42key data in the RSA structure directly. An ENGINE implementation can
43override the way key data is stored and handled, and can even provide
44support for HSM keys - in which case the RSA structure may contain B<no>
45key data at all! If the ENGINE in question is only being used for
46acceleration or analysis purposes, then in all likelihood the RSA key data
47is complete and untouched, but this can't be assumed in the general case.
48
49=head1 BUGS
50
51A method of verifying the RSA key using opaque RSA API functions might need
52to be considered. Right now RSA_check_key() simply uses the RSA structure
53elements directly, bypassing the RSA_METHOD table altogether (and
54completely violating encapsulation and object-orientation in the process).
55The best fix will probably be to introduce a "check_key()" handler to the
56RSA_METHOD function table so that alternative implementations can also
57provide their own verifiers.
58
59=head1 SEE ALSO
60
61L<rsa(3)|rsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
62
63=head1 HISTORY
64
65RSA_check_key() appeared in OpenSSL 0.9.4.
66
67=cut
diff --git a/src/lib/libcrypto/doc/RSA_generate_key.pod b/src/lib/libcrypto/doc/RSA_generate_key.pod
new file mode 100644
index 0000000000..52dbb14a53
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_generate_key.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5RSA_generate_key - generate RSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA *RSA_generate_key(int num, unsigned long e,
12 void (*callback)(int,int,void *), void *cb_arg);
13
14=head1 DESCRIPTION
15
16RSA_generate_key() generates a key pair and returns it in a newly
17allocated B<RSA> structure. The pseudo-random number generator must
18be seeded prior to calling RSA_generate_key().
19
20The modulus size will be B<num> bits, and the public exponent will be
21B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
22The exponent is an odd number, typically 3, 17 or 65537.
23
24A callback function may be used to provide feedback about the
25progress of the key generation. If B<callback> is not B<NULL>, it
26will be called as follows:
27
28=over 4
29
30=item *
31
32While a random prime number is generated, it is called as
33described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
34
35=item *
36
37When the n-th randomly generated prime is rejected as not
38suitable for the key, B<callback(2, n, cb_arg)> is called.
39
40=item *
41
42When a random p has been found with p-1 relatively prime to B<e>,
43it is called as B<callback(3, 0, cb_arg)>.
44
45=back
46
47The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
48
49=head1 RETURN VALUE
50
51If key generation fails, RSA_generate_key() returns B<NULL>; the
52error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
53
54=head1 BUGS
55
56B<callback(2, x, cb_arg)> is used with two different meanings.
57
58RSA_generate_key() goes into an infinite loop for illegal input values.
59
60=head1 SEE ALSO
61
62L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
63L<RSA_free(3)|RSA_free(3)>
64
65=head1 HISTORY
66
67The B<cb_arg> argument was added in SSLeay 0.9.0.
68
69=cut
diff --git a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
new file mode 100644
index 0000000000..46cc8f5359
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
@@ -0,0 +1,120 @@
1=pod
2
3=head1 NAME
4
5RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - add application specific data to RSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int RSA_set_ex_data(RSA *r, int idx, void *arg);
17
18 void *RSA_get_ex_data(RSA *r, int idx);
19
20 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp);
24 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
25 int idx, long argl, void *argp);
26
27=head1 DESCRIPTION
28
29Several OpenSSL structures can have application specific data attached to them.
30This has several potential uses, it can be used to cache data associated with
31a structure (for example the hash of some part of the structure) or some
32additional data (for example a handle to the data in an external library).
33
34Since the application data can be anything at all it is passed and retrieved
35as a B<void *> type.
36
37The B<RSA_get_ex_new_index()> function is initially called to "register" some
38new application specific data. It takes three optional function pointers which
39are called when the parent structure (in this case an RSA structure) is
40initially created, when it is copied and when it is freed up. If any or all of
41these function pointer arguments are not used they should be set to NULL. The
42precise manner in which these function pointers are called is described in more
43detail below. B<RSA_get_ex_new_index()> also takes additional long and pointer
44parameters which will be passed to the supplied functions but which otherwise
45have no special meaning. It returns an B<index> which should be stored
46(typically in a static variable) and passed used in the B<idx> parameter in
47the remaining functions. Each successful call to B<RSA_get_ex_new_index()>
48will return an index greater than any previously returned, this is important
49because the optional functions are called in order of increasing index value.
50
51B<RSA_set_ex_data()> is used to set application specific data, the data is
52supplied in the B<arg> parameter and its precise meaning is up to the
53application.
54
55B<RSA_get_ex_data()> is used to retrieve application specific data. The data
56is returned to the application, this will be the same value as supplied to
57a previous B<RSA_set_ex_data()> call.
58
59B<new_func()> is called when a structure is initially allocated (for example
60with B<RSA_new()>. The parent structure members will not have any meaningful
61values at this point. This function will typically be used to allocate any
62application specific structure.
63
64B<free_func()> is called when a structure is being freed up. The dynamic parent
65structure members should not be accessed because they will be freed up when
66this function is called.
67
68B<new_func()> and B<free_func()> take the same parameters. B<parent> is a
69pointer to the parent RSA structure. B<ptr> is a the application specific data
70(this wont be of much use in B<new_func()>. B<ad> is a pointer to the
71B<CRYPTO_EX_DATA> structure from the parent RSA structure: the functions
72B<CRYPTO_get_ex_data()> and B<CRYPTO_set_ex_data()> can be called to manipulate
73it. The B<idx> parameter is the index: this will be the same value returned by
74B<RSA_get_ex_new_index()> when the functions were initially registered. Finally
75the B<argl> and B<argp> parameters are the values originally passed to the same
76corresponding parameters when B<RSA_get_ex_new_index()> was called.
77
78B<dup_func()> is called when a structure is being copied. Pointers to the
79destination and source B<CRYPTO_EX_DATA> structures are passed in the B<to> and
80B<from> parameters respectively. The B<from_d> parameter is passed a pointer to
81the source application data when the function is called, when the function returns
82the value is copied to the destination: the application can thus modify the data
83pointed to by B<from_d> and have different values in the source and destination.
84The B<idx>, B<argl> and B<argp> parameters are the same as those in B<new_func()>
85and B<free_func()>.
86
87=head1 RETURN VALUES
88
89B<RSA_get_ex_new_index()> returns a new index or -1 on failure (note 0 is a valid
90index value).
91
92B<RSA_set_ex_data()> returns 1 on success or 0 on failure.
93
94B<RSA_get_ex_data()> returns the application data or 0 on failure. 0 may also
95be valid application data but currently it can only fail if given an invalid B<idx>
96parameter.
97
98B<new_func()> and B<dup_func()> should return 0 for failure and 1 for success.
99
100On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
101
102=head1 BUGS
103
104B<dup_func()> is currently never called.
105
106The return value of B<new_func()> is ignored.
107
108The B<new_func()> function isn't very useful because no meaningful values are
109present in the parent RSA structure when it is called.
110
111=head1 SEE ALSO
112
113L<rsa(3)|rsa(3)>, L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
114
115=head1 HISTORY
116
117RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data() are
118available since SSLeay 0.9.0.
119
120=cut
diff --git a/src/lib/libcrypto/doc/RSA_new.pod b/src/lib/libcrypto/doc/RSA_new.pod
new file mode 100644
index 0000000000..3d15b92824
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_new.pod
@@ -0,0 +1,41 @@
1=pod
2
3=head1 NAME
4
5RSA_new, RSA_free - allocate and free RSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12
13 void RSA_free(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA_new() allocates and initializes an B<RSA> structure. It is equivalent to
18calling RSA_new_method(NULL).
19
20RSA_free() frees the B<RSA> structure and its components. The key is
21erased before the memory is returned to the system.
22
23=head1 RETURN VALUES
24
25If the allocation fails, RSA_new() returns B<NULL> and sets an error
26code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
27a pointer to the newly allocated structure.
28
29RSA_free() returns no value.
30
31=head1 SEE ALSO
32
33L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>,
34L<RSA_generate_key(3)|RSA_generate_key(3)>,
35L<RSA_new_method(3)|RSA_new_method(3)>
36
37=head1 HISTORY
38
39RSA_new() and RSA_free() are available in all versions of SSLeay and OpenSSL.
40
41=cut
diff --git a/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod b/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod
new file mode 100644
index 0000000000..b8f678fe72
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod
@@ -0,0 +1,124 @@
1=pod
2
3=head1 NAME
4
5RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
6RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
7RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
8RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
9RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
10padding
11
12=head1 SYNOPSIS
13
14 #include <openssl/rsa.h>
15
16 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
17 unsigned char *f, int fl);
18
19 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
20 unsigned char *f, int fl, int rsa_len);
21
22 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
23 unsigned char *f, int fl);
24
25 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
26 unsigned char *f, int fl, int rsa_len);
27
28 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
29 unsigned char *f, int fl, unsigned char *p, int pl);
30
31 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
32 unsigned char *f, int fl, int rsa_len, unsigned char *p, int pl);
33
34 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
35 unsigned char *f, int fl);
36
37 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
38 unsigned char *f, int fl, int rsa_len);
39
40 int RSA_padding_add_none(unsigned char *to, int tlen,
41 unsigned char *f, int fl);
42
43 int RSA_padding_check_none(unsigned char *to, int tlen,
44 unsigned char *f, int fl, int rsa_len);
45
46=head1 DESCRIPTION
47
48The RSA_padding_xxx_xxx() functions are called from the RSA encrypt,
49decrypt, sign and verify functions. Normally they should not be called
50from application programs.
51
52However, they can also be called directly to implement padding for other
53asymmetric ciphers. RSA_padding_add_PKCS1_OAEP() and
54RSA_padding_check_PKCS1_OAEP() may be used in an application combined
55with B<RSA_NO_PADDING> in order to implement OAEP with an encoding
56parameter.
57
58RSA_padding_add_xxx() encodes B<fl> bytes from B<f> so as to fit into
59B<tlen> bytes and stores the result at B<to>. An error occurs if B<fl>
60does not meet the size requirements of the encoding method.
61
62The following encoding methods are implemented:
63
64=over 4
65
66=item PKCS1_type_1
67
68PKCS #1 v2.0 EMSA-PKCS1-v1_5 (PKCS #1 v1.5 block type 1); used for signatures
69
70=item PKCS1_type_2
71
72PKCS #1 v2.0 EME-PKCS1-v1_5 (PKCS #1 v1.5 block type 2)
73
74=item PKCS1_OAEP
75
76PKCS #1 v2.0 EME-OAEP
77
78=item SSLv23
79
80PKCS #1 EME-PKCS1-v1_5 with SSL-specific modification
81
82=item none
83
84simply copy the data
85
86=back
87
88The random number generator must be seeded prior to calling
89RSA_padding_add_xxx().
90
91RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
92a valid encoding for a B<rsa_len> byte RSA key in the respective
93encoding method and stores the recovered data of at most B<tlen> bytes
94(for B<RSA_NO_PADDING>: of size B<tlen>)
95at B<to>.
96
97For RSA_padding_xxx_OAEP(), B<p> points to the encoding parameter
98of length B<pl>. B<p> may be B<NULL> if B<pl> is 0.
99
100=head1 RETURN VALUES
101
102The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
103The RSA_padding_check_xxx() functions return the length of the
104recovered data, -1 on error. Error codes can be obtained by calling
105L<ERR_get_error(3)|ERR_get_error(3)>.
106
107=head1 SEE ALSO
108
109L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
110L<RSA_private_decrypt(3)|RSA_private_decrypt(3)>,
111L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
112
113=head1 HISTORY
114
115RSA_padding_add_PKCS1_type_1(), RSA_padding_check_PKCS1_type_1(),
116RSA_padding_add_PKCS1_type_2(), RSA_padding_check_PKCS1_type_2(),
117RSA_padding_add_SSLv23(), RSA_padding_check_SSLv23(),
118RSA_padding_add_none() and RSA_padding_check_none() appeared in
119SSLeay 0.9.0.
120
121RSA_padding_add_PKCS1_OAEP() and RSA_padding_check_PKCS1_OAEP() were
122added in OpenSSL 0.9.2b.
123
124=cut
diff --git a/src/lib/libcrypto/doc/RSA_print.pod b/src/lib/libcrypto/doc/RSA_print.pod
new file mode 100644
index 0000000000..c971e91f4d
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_print.pod
@@ -0,0 +1,49 @@
1=pod
2
3=head1 NAME
4
5RSA_print, RSA_print_fp,
6DSAparams_print, DSAparams_print_fp, DSA_print, DSA_print_fp,
7DHparams_print, DHparams_print_fp - print cryptographic parameters
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 int RSA_print(BIO *bp, RSA *x, int offset);
14 int RSA_print_fp(FILE *fp, RSA *x, int offset);
15
16 #include <openssl/dsa.h>
17
18 int DSAparams_print(BIO *bp, DSA *x);
19 int DSAparams_print_fp(FILE *fp, DSA *x);
20 int DSA_print(BIO *bp, DSA *x, int offset);
21 int DSA_print_fp(FILE *fp, DSA *x, int offset);
22
23 #include <openssl/dh.h>
24
25 int DHparams_print(BIO *bp, DH *x);
26 int DHparams_print_fp(FILE *fp, DH *x);
27
28=head1 DESCRIPTION
29
30A human-readable hexadecimal output of the components of the RSA
31key, DSA parameters or key or DH parameters is printed to B<bp> or B<fp>.
32
33The output lines are indented by B<offset> spaces.
34
35=head1 RETURN VALUES
36
37These functions return 1 on success, 0 on error.
38
39=head1 SEE ALSO
40
41L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
42
43=head1 HISTORY
44
45RSA_print(), RSA_print_fp(), DSA_print(), DSA_print_fp(), DH_print(),
46DH_print_fp() are available in all versions of SSLeay and OpenSSL.
47DSAparams_print() and DSAparams_print_fp() were added in SSLeay 0.8.
48
49=cut
diff --git a/src/lib/libcrypto/doc/RSA_private_encrypt.pod b/src/lib/libcrypto/doc/RSA_private_encrypt.pod
new file mode 100644
index 0000000000..746a80c79e
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_private_encrypt.pod
@@ -0,0 +1,70 @@
1=pod
2
3=head1 NAME
4
5RSA_private_encrypt, RSA_public_decrypt - low level signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_private_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_public_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19These functions handle RSA signatures at a low level.
20
21RSA_private_encrypt() signs the B<flen> bytes at B<from> (usually a
22message digest with an algorithm identifier) using the private key
23B<rsa> and stores the signature in B<to>. B<to> must point to
24B<RSA_size(rsa)> bytes of memory.
25
26B<padding> denotes one of the following modes:
27
28=over 4
29
30=item RSA_PKCS1_PADDING
31
32PKCS #1 v1.5 padding. This function does not handle the
33B<algorithmIdentifier> specified in PKCS #1. When generating or
34verifying PKCS #1 signatures, L<RSA_sign(3)|RSA_sign(3)> and L<RSA_verify(3)|RSA_verify(3)> should be
35used.
36
37=item RSA_NO_PADDING
38
39Raw RSA signature. This mode should I<only> be used to implement
40cryptographically sound padding modes in the application code.
41Signing user data directly with RSA is insecure.
42
43=back
44
45RSA_public_decrypt() recovers the message digest from the B<flen>
46bytes long signature at B<from> using the signer's public key
47B<rsa>. B<to> must point to a memory section large enough to hold the
48message digest (which is smaller than B<RSA_size(rsa) -
4911>). B<padding> is the padding mode that was used to sign the data.
50
51=head1 RETURN VALUES
52
53RSA_private_encrypt() returns the size of the signature (i.e.,
54RSA_size(rsa)). RSA_public_decrypt() returns the size of the
55recovered message digest.
56
57On error, -1 is returned; the error codes can be
58obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
59
60=head1 SEE ALSO
61
62L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>,
63L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
64
65=head1 HISTORY
66
67The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
68available since SSLeay 0.9.0.
69
70=cut
diff --git a/src/lib/libcrypto/doc/RSA_public_encrypt.pod b/src/lib/libcrypto/doc/RSA_public_encrypt.pod
new file mode 100644
index 0000000000..ab0fe3b2cd
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_public_encrypt.pod
@@ -0,0 +1,84 @@
1=pod
2
3=head1 NAME
4
5RSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_public_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_private_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19RSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a
20session key) using the public key B<rsa> and stores the ciphertext in
21B<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory.
22
23B<padding> denotes one of the following modes:
24
25=over 4
26
27=item RSA_PKCS1_PADDING
28
29PKCS #1 v1.5 padding. This currently is the most widely used mode.
30
31=item RSA_PKCS1_OAEP_PADDING
32
33EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
34encoding parameter. This mode is recommended for all new applications.
35
36=item RSA_SSLV23_PADDING
37
38PKCS #1 v1.5 padding with an SSL-specific modification that denotes
39that the server is SSL3 capable.
40
41=item RSA_NO_PADDING
42
43Raw RSA encryption. This mode should I<only> be used to implement
44cryptographically sound padding modes in the application code.
45Encrypting user data directly with RSA is insecure.
46
47=back
48
49B<flen> must be less than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
50based padding modes, less than RSA_size(B<rsa>) - 41 for
51RSA_PKCS1_OAEP_PADDING and exactly RSA_size(B<rsa>) for RSA_NO_PADDING.
52The random number generator must be seeded prior to calling
53RSA_public_encrypt().
54
55RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
56private key B<rsa> and stores the plaintext in B<to>. B<to> must point
57to a memory section large enough to hold the decrypted data (which is
58smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
59was used to encrypt the data.
60
61=head1 RETURN VALUES
62
63RSA_public_encrypt() returns the size of the encrypted data (i.e.,
64RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
65recovered plaintext.
66
67On error, -1 is returned; the error codes can be
68obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
69
70=head1 CONFORMING TO
71
72SSL, PKCS #1 v2.0
73
74=head1 SEE ALSO
75
76L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
77L<RSA_size(3)|RSA_size(3)>
78
79=head1 HISTORY
80
81The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
82available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.
83
84=cut
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod
new file mode 100644
index 0000000000..0a305f6b14
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_set_method.pod
@@ -0,0 +1,202 @@
1=pod
2
3=head1 NAME
4
5RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6RSA_get_method, RSA_PKCS1_SSLeay, RSA_null_method, RSA_flags,
7RSA_new_method - select RSA method
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 void RSA_set_default_method(const RSA_METHOD *meth);
14
15 RSA_METHOD *RSA_get_default_method(void);
16
17 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
18
19 RSA_METHOD *RSA_get_method(const RSA *rsa);
20
21 RSA_METHOD *RSA_PKCS1_SSLeay(void);
22
23 RSA_METHOD *RSA_null_method(void);
24
25 int RSA_flags(const RSA *rsa);
26
27 RSA *RSA_new_method(RSA_METHOD *method);
28
29=head1 DESCRIPTION
30
31An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
32operations. By modifying the method, alternative implementations such as
33hardware accelerators may be used. IMPORTANT: See the NOTES section for
34important information about how these RSA API functions are affected by the
35use of B<ENGINE> API calls.
36
37Initially, the default RSA_METHOD is the OpenSSL internal implementation,
38as returned by RSA_PKCS1_SSLeay().
39
40RSA_set_default_method() makes B<meth> the default method for all RSA
41structures created later. B<NB>: This is true only whilst no ENGINE has
42been set as a default for RSA, so this function is no longer recommended.
43
44RSA_get_default_method() returns a pointer to the current default
45RSA_METHOD. However, the meaningfulness of this result is dependant on
46whether the ENGINE API is being used, so this function is no longer
47recommended.
48
49RSA_set_method() selects B<meth> to perform all operations using the key
50B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
51previous method was supplied by an ENGINE, the handle to that ENGINE will
52be released during the change. It is possible to have RSA keys that only
53work with certain RSA_METHOD implementations (eg. from an ENGINE module
54that supports embedded hardware-protected keys), and in such cases
55attempting to change the RSA_METHOD for the key can have unexpected
56results.
57
58RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
59This method may or may not be supplied by an ENGINE implementation, but if
60it is, the return value can only be guaranteed to be valid as long as the
61RSA key itself is valid and does not have its implementation changed by
62RSA_set_method().
63
64RSA_flags() returns the B<flags> that are set for B<rsa>'s current
65RSA_METHOD. See the BUGS section.
66
67RSA_new_method() allocates and initializes an RSA structure so that
68B<engine> will be used for the RSA operations. If B<engine> is NULL, the
69default ENGINE for RSA operations is used, and if no default ENGINE is set,
70the RSA_METHOD controlled by RSA_set_default_method() is used.
71
72RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
73
74RSA_new_method() allocates and initializes an B<RSA> structure so that
75B<method> will be used for the RSA operations. If B<method> is B<NULL>,
76the default method is used.
77
78=head1 THE RSA_METHOD STRUCTURE
79
80 typedef struct rsa_meth_st
81 {
82 /* name of the implementation */
83 const char *name;
84
85 /* encrypt */
86 int (*rsa_pub_enc)(int flen, unsigned char *from,
87 unsigned char *to, RSA *rsa, int padding);
88
89 /* verify arbitrary data */
90 int (*rsa_pub_dec)(int flen, unsigned char *from,
91 unsigned char *to, RSA *rsa, int padding);
92
93 /* sign arbitrary data */
94 int (*rsa_priv_enc)(int flen, unsigned char *from,
95 unsigned char *to, RSA *rsa, int padding);
96
97 /* decrypt */
98 int (*rsa_priv_dec)(int flen, unsigned char *from,
99 unsigned char *to, RSA *rsa, int padding);
100
101 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
102 implementations) */
103 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
104
105 /* compute r = a ^ p mod m (May be NULL for some implementations) */
106 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
107 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
108
109 /* called at RSA_new */
110 int (*init)(RSA *rsa);
111
112 /* called at RSA_free */
113 int (*finish)(RSA *rsa);
114
115 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
116 * operations, even if p,q,dmp1,dmq1,iqmp
117 * are NULL
118 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
119 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
120 */
121 int flags;
122
123 char *app_data; /* ?? */
124
125 /* sign. For backward compatibility, this is used only
126 * if (flags & RSA_FLAG_SIGN_VER)
127 */
128 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
129 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
130
131 /* verify. For backward compatibility, this is used only
132 * if (flags & RSA_FLAG_SIGN_VER)
133 */
134 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
135 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
136
137 } RSA_METHOD;
138
139=head1 RETURN VALUES
140
141RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method()
142and RSA_get_method() return pointers to the respective RSA_METHODs.
143
144RSA_set_default_method() returns no value.
145
146RSA_set_method() returns a pointer to the old RSA_METHOD implementation
147that was replaced. However, this return value should probably be ignored
148because if it was supplied by an ENGINE, the pointer could be invalidated
149at any time if the ENGINE is unloaded (in fact it could be unloaded as a
150result of the RSA_set_method() function releasing its handle to the
151ENGINE). For this reason, the return type may be replaced with a B<void>
152declaration in a future release.
153
154RSA_new_method() returns NULL and sets an error code that can be obtained
155by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
156it returns a pointer to the newly allocated structure.
157
158=head1 NOTES
159
160As of version 0.9.7, RSA_METHOD implementations are grouped together with
161other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE>
162modules. If a default ENGINE is specified for RSA functionality using an
163ENGINE API function, that will override any RSA defaults set using the RSA
164API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the
165recommended way to control default implementations for use in RSA and other
166cryptographic algorithms.
167
168=head1 BUGS
169
170The behaviour of RSA_flags() is a mis-feature that is left as-is for now
171to avoid creating compatibility problems. RSA functionality, such as the
172encryption functions, are controlled by the B<flags> value in the RSA key
173itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
174(which is what this function returns). If the flags element of an RSA key
175is changed, the changes will be honoured by RSA functionality but will not
176be reflected in the return value of the RSA_flags() function - in effect
177RSA_flags() behaves more like an RSA_default_flags() function (which does
178not currently exist).
179
180=head1 SEE ALSO
181
182L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
183
184=head1 HISTORY
185
186RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
187RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
188well as the rsa_sign and rsa_verify components of RSA_METHOD were
189added in OpenSSL 0.9.4.
190
191RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
192replaced RSA_set_default_method() and RSA_get_default_method()
193respectively, and RSA_set_method() and RSA_new_method() were altered to use
194B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine
195version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE
196API was restructured so that this change was reversed, and behaviour of the
197other functions resembled more closely the previous behaviour. The
198behaviour of defaults in the ENGINE API now transparently overrides the
199behaviour of defaults in the RSA API without requiring changing these
200function prototypes.
201
202=cut
diff --git a/src/lib/libcrypto/doc/RSA_sign.pod b/src/lib/libcrypto/doc/RSA_sign.pod
new file mode 100644
index 0000000000..71688a665e
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_sign.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5RSA_sign, RSA_verify - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
12 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
13
14 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
15 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
16
17=head1 DESCRIPTION
18
19RSA_sign() signs the message digest B<m> of size B<m_len> using the
20private key B<rsa> as specified in PKCS #1 v2.0. It stores the
21signature in B<sigret> and the signature size in B<siglen>. B<sigret>
22must point to RSA_size(B<rsa>) bytes of memory.
23
24B<type> denotes the message digest algorithm that was used to generate
25B<m>. It usually is one of B<NID_sha1>, B<NID_ripemd160> and B<NID_md5>;
26see L<objects(3)|objects(3)> for details. If B<type> is B<NID_md5_sha1>,
27an SSL signature (MD5 and SHA1 message digests with PKCS #1 padding
28and no algorithm identifier) is created.
29
30RSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
31matches a given message digest B<m> of size B<m_len>. B<type> denotes
32the message digest algorithm that was used to generate the signature.
33B<rsa> is the signer's public key.
34
35=head1 RETURN VALUES
36
37RSA_sign() returns 1 on success, 0 otherwise. RSA_verify() returns 1
38on successful verification, 0 otherwise.
39
40The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
41
42=head1 BUGS
43
44Certain signatures with an improper algorithm identifier are accepted
45for compatibility with SSLeay 0.4.5 :-)
46
47=head1 CONFORMING TO
48
49SSL, PKCS #1 v2.0
50
51=head1 SEE ALSO
52
53L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>,
54L<rsa(3)|rsa(3)>, L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
55L<RSA_public_decrypt(3)|RSA_public_decrypt(3)>
56
57=head1 HISTORY
58
59RSA_sign() and RSA_verify() are available in all versions of SSLeay
60and OpenSSL.
61
62=cut
diff --git a/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod
new file mode 100644
index 0000000000..e70380bbfc
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod
@@ -0,0 +1,59 @@
1=pod
2
3=head1 NAME
4
5RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
12 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
13 RSA *rsa);
14
15 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
16 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
17 RSA *rsa);
18
19=head1 DESCRIPTION
20
21RSA_sign_ASN1_OCTET_STRING() signs the octet string B<m> of size
22B<m_len> using the private key B<rsa> represented in DER using PKCS #1
23padding. It stores the signature in B<sigret> and the signature size
24in B<siglen>. B<sigret> must point to B<RSA_size(rsa)> bytes of
25memory.
26
27B<dummy> is ignored.
28
29The random number generator must be seeded prior to calling RSA_sign_ASN1_OCTET_STRING().
30
31RSA_verify_ASN1_OCTET_STRING() verifies that the signature B<sigbuf>
32of size B<siglen> is the DER representation of a given octet string
33B<m> of size B<m_len>. B<dummy> is ignored. B<rsa> is the signer's
34public key.
35
36=head1 RETURN VALUES
37
38RSA_sign_ASN1_OCTET_STRING() returns 1 on success, 0 otherwise.
39RSA_verify_ASN1_OCTET_STRING() returns 1 on successful verification, 0
40otherwise.
41
42The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
43
44=head1 BUGS
45
46These functions serve no recognizable purpose.
47
48=head1 SEE ALSO
49
50L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>,
51L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>,
52L<RSA_verify(3)|RSA_verify(3)>
53
54=head1 HISTORY
55
56RSA_sign_ASN1_OCTET_STRING() and RSA_verify_ASN1_OCTET_STRING() were
57added in SSLeay 0.8.
58
59=cut
diff --git a/src/lib/libcrypto/doc/RSA_size.pod b/src/lib/libcrypto/doc/RSA_size.pod
new file mode 100644
index 0000000000..5b7f835f95
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5RSA_size - get RSA modulus size
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_size(const RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function returns the RSA modulus size in bytes. It can be used to
16determine how much memory must be allocated for an RSA encrypted
17value.
18
19B<rsa-E<gt>n> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<rsa(3)|rsa(3)>
28
29=head1 HISTORY
30
31RSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod b/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod
new file mode 100644
index 0000000000..ffafa37887
--- /dev/null
+++ b/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod
@@ -0,0 +1,71 @@
1=pod
2
3=head1 NAME
4
5SMIME_read_PKCS7 - parse S/MIME message.
6
7=head1 SYNOPSIS
8
9PKCS7 *SMIME_read_PKCS7(BIO *in, BIO **bcont);
10
11=head1 DESCRIPTION
12
13SMIME_read_PKCS7() parses a message in S/MIME format.
14
15B<in> is a BIO to read the message from.
16
17If cleartext signing is used then the content is saved in
18a memory bio which is written to B<*bcont>, otherwise
19B<*bcont> is set to B<NULL>.
20
21The parsed PKCS#7 structure is returned or B<NULL> if an
22error occurred.
23
24=head1 NOTES
25
26If B<*bcont> is not B<NULL> then the message is clear text
27signed. B<*bcont> can then be passed to PKCS7_verify() with
28the B<PKCS7_DETACHED> flag set.
29
30Otherwise the type of the returned structure can be determined
31using PKCS7_type().
32
33To support future functionality if B<bcont> is not B<NULL>
34B<*bcont> should be initialized to B<NULL>. For example:
35
36 BIO *cont = NULL;
37 PKCS7 *p7;
38
39 p7 = SMIME_read_PKCS7(in, &cont);
40
41=head1 BUGS
42
43The MIME parser used by SMIME_read_PKCS7() is somewhat primitive.
44While it will handle most S/MIME messages more complex compound
45formats may not work.
46
47The parser assumes that the PKCS7 structure is always base64
48encoded and will not handle the case where it is in binary format
49or uses quoted printable format.
50
51The use of a memory BIO to hold the signed content limits the size
52of message which can be processed due to memory restraints: a
53streaming single pass option should be available.
54
55=head1 RETURN VALUES
56
57SMIME_read_PKCS7() returns a valid B<PKCS7> structure or B<NULL>
58is an error occurred. The error can be obtained from ERR_get_error(3).
59
60=head1 SEE ALSO
61
62L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_type(3)|PKCS7_type(3)>
63L<SMIME_read_PKCS7(3)|SMIME_read_PKCS7(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
64L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
65L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
66
67=head1 HISTORY
68
69SMIME_read_PKCS7() was added to OpenSSL 0.9.5
70
71=cut
diff --git a/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod b/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod
new file mode 100644
index 0000000000..2cfad2e049
--- /dev/null
+++ b/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod
@@ -0,0 +1,59 @@
1=pod
2
3=head1 NAME
4
5SMIME_write_PKCS7 - convert PKCS#7 structure to S/MIME format.
6
7=head1 SYNOPSIS
8
9int SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags);
10
11=head1 DESCRIPTION
12
13SMIME_write_PKCS7() adds the appropriate MIME headers to a PKCS#7
14structure to produce an S/MIME message.
15
16B<out> is the BIO to write the data to. B<p7> is the appropriate
17B<PKCS7> structure. If cleartext signing (B<multipart/signed>) is
18being used then the signed data must be supplied in the B<data>
19argument. B<flags> is an optional set of flags.
20
21=head1 NOTES
22
23The following flags can be passed in the B<flags> parameter.
24
25If B<PKCS7_DETACHED> is set then cleartext signing will be used,
26this option only makes sense for signedData where B<PKCS7_DETACHED>
27is also set when PKCS7_sign() is also called.
28
29If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain>
30are added to the content, this only makes sense if B<PKCS7_DETACHED>
31is also set.
32
33If cleartext signing is being used then the data must be read twice:
34once to compute the signature in PKCS7_sign() and once to output the
35S/MIME message.
36
37=head1 BUGS
38
39SMIME_write_PKCS7() always base64 encodes PKCS#7 structures, there
40should be an option to disable this.
41
42There should really be a way to produce cleartext signing using only
43a single pass of the data.
44
45=head1 RETURN VALUES
46
47SMIME_write_PKCS7() returns 1 for success or 0 for failure.
48
49=head1 SEE ALSO
50
51L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
52L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
53L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
54
55=head1 HISTORY
56
57SMIME_write_PKCS7() was added to OpenSSL 0.9.5
58
59=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
new file mode 100644
index 0000000000..11b35f6fd3
--- /dev/null
+++ b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
@@ -0,0 +1,72 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_ENTRY_get_object, X509_NAME_ENTRY_get_data,
6X509_NAME_ENTRY_set_object, X509_NAME_ENTRY_set_data,
7X509_NAME_ENTRY_create_by_txt, X509_NAME_ENTRY_create_by_NID,
8X509_NAME_ENTRY_create_by_OBJ - X509_NAME_ENTRY utility functions
9
10=head1 SYNOPSIS
11
12ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
13ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
14
15int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj);
16int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, const unsigned char *bytes, int len);
17
18X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, const char *field, int type, const unsigned char *bytes, int len);
19X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,unsigned char *bytes, int len);
20X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len);
21
22=head1 DESCRIPTION
23
24X509_NAME_ENTRY_get_object() retrieves the field name of B<ne> in
25and B<ASN1_OBJECT> structure.
26
27X509_NAME_ENTRY_get_data() retrieves the field value of B<ne> in
28and B<ASN1_STRING> structure.
29
30X509_NAME_ENTRY_set_object() sets the field name of B<ne> to B<obj>.
31
32X509_NAME_ENTRY_set_data() sets the field value of B<ne> to string type
33B<type> and value determined by B<bytes> and B<len>.
34
35X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID()
36and X509_NAME_ENTRY_create_by_OBJ() create and return an
37B<X509_NAME_ENTRY> structure.
38
39=head1 NOTES
40
41X509_NAME_ENTRY_get_object() and X509_NAME_ENTRY_get_data() can be
42used to examine an B<X509_NAME_ENTRY> function as returned by
43X509_NAME_get_entry() for example.
44
45X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID(),
46and X509_NAME_ENTRY_create_by_OBJ() create and return an
47
48X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_OBJ(),
49X509_NAME_ENTRY_create_by_NID() and X509_NAME_ENTRY_set_data()
50are seldom used in practice because B<X509_NAME_ENTRY> structures
51are almost always part of B<X509_NAME> structures and the
52corresponding B<X509_NAME> functions are typically used to
53create and add new entries in a single operation.
54
55The arguments of these functions support similar options to the similarly
56named ones of the corresponding B<X509_NAME> functions such as
57X509_NAME_add_entry_by_txt(). So for example B<type> can be set to
58B<MBSTRING_ASC> but in the case of X509_set_data() the field name must be
59set first so the relevant field information can be looked up internally.
60
61=head1 RETURN VALUES
62
63=head1 SEE ALSO
64
65L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>,
66L<OBJ_nid2obj(3),OBJ_nid2obj(3)>
67
68=head1 HISTORY
69
70TBA
71
72=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
new file mode 100644
index 0000000000..e2ab4b0d2b
--- /dev/null
+++ b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
@@ -0,0 +1,114 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ, X509_NAME_add_entry_by_NID,
6X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions
7
8=head1 SYNOPSIS
9
10int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set);
11
12int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set);
13
14int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set);
15
16int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set);
17
18X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
19
20=head1 DESCRIPTION
21
22X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ() and
23X509_NAME_add_entry_by_NID() add a field whose name is defined
24by a string B<field>, an object B<obj> or a NID B<nid> respectively.
25The field value to be added is in B<bytes> of length B<len>. If
26B<len> is -1 then the field length is calculated internally using
27strlen(bytes).
28
29The type of field is determined by B<type> which can either be a
30definition of the type of B<bytes> (such as B<MBSTRING_ASC>) or a
31standard ASN1 type (such as B<V_ASN1_IA5STRING>). The new entry is
32added to a position determined by B<loc> and B<set>.
33
34X509_NAME_add_entry() adds a copy of B<X509_NAME_ENTRY> structure B<ne>
35to B<name>. The new entry is added to a position determined by B<loc>
36and B<set>. Since a copy of B<ne> is added B<ne> must be freed up after
37the call.
38
39X509_NAME_delete_entry() deletes an entry from B<name> at position
40B<loc>. The deleted entry is returned and must be freed up.
41
42=head1 NOTES
43
44The use of string types such as B<MBSTRING_ASC> or B<MBSTRING_UTF8>
45is strongly recommened for the B<type> parameter. This allows the
46internal code to correctly determine the type of the field and to
47apply length checks according to the relevant standards. This is
48done using ASN1_STRING_set_by_NID().
49
50If instead an ASN1 type is used no checks are performed and the
51supplied data in B<bytes> is used directly.
52
53In X509_NAME_add_entry_by_txt() the B<field> string represents
54the field name using OBJ_txt2obj(field, 0).
55
56The B<loc> and B<set> parameters determine where a new entry should
57be added. For almost all applications B<loc> can be set to -1 and B<set>
58to 0. This adds a new entry to the end of B<name> as a single valued
59RelativeDistinguishedName (RDN).
60
61B<loc> actually determines the index where the new entry is inserted:
62if it is -1 it is appended.
63
64B<set> determines how the new type is added. If it is zero a
65new RDN is created.
66
67If B<set> is -1 or 1 it is added to the previous or next RDN
68structure respectively. This will then be a multivalued RDN:
69since multivalues RDNs are very seldom used B<set> is almost
70always set to zero.
71
72=head1 EXAMPLES
73
74Create an B<X509_NAME> structure:
75
76"C=UK, O=Disorganized Organization, CN=Joe Bloggs"
77
78 X509_NAME *nm;
79 nm = X509_NAME_new();
80 if (nm == NULL)
81 /* Some error */
82 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
83 "C", "UK", -1, -1, 0))
84 /* Error */
85 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
86 "O", "Disorganized Organization", -1, -1, 0))
87 /* Error */
88 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
89 "CN", "Joe Bloggs", -1, -1, 0))
90 /* Error */
91
92=head1 RETURN VALUES
93
94X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ(),
95X509_NAME_add_entry_by_NID() and X509_NAME_add_entry() return 1 for
96success of 0 if an error occurred.
97
98X509_NAME_delete_entry() returns either the deleted B<X509_NAME_ENTRY>
99structure of B<NULL> if an error occurred.
100
101=head1 BUGS
102
103B<type> can still be set to B<V_ASN1_APP_CHOOSE> to use a
104different algorithm to determine field types. Since this form does
105not understand multicharacter types, performs no length checks and
106can result in invalid field types its use is strongly discouraged.
107
108=head1 SEE ALSO
109
110L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>
111
112=head1 HISTORY
113
114=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
new file mode 100644
index 0000000000..333323d734
--- /dev/null
+++ b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
@@ -0,0 +1,106 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ, X509_NAME_get_entry,
6X509_NAME_entry_count, X509_NAME_get_text_by_NID, X509_NAME_get_text_by_OBJ -
7X509_NAME lookup and enumeration functions
8
9=head1 SYNOPSIS
10
11int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
12int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, int lastpos);
13
14int X509_NAME_entry_count(X509_NAME *name);
15X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
16
17int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf,int len);
18int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,int len);
19
20=head1 DESCRIPTION
21
22These functions allow an B<X509_NAME> structure to be examined. The
23B<X509_NAME> structure is the same as the B<Name> type defined in
24RFC2459 (and elsewhere) and used for example in certificate subject
25and issuer names.
26
27X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() retrieve
28the next index matching B<nid> or B<obj> after B<lastpos>. B<lastpos>
29should initially be set to -1. If there are no more entries -1 is returned.
30
31X509_NAME_entry_count() returns the total number of entries in B<name>.
32
33X509_NAME_get_entry() retrieves the B<X509_NAME_ENTRY> from B<name>
34corresponding to index B<loc>. Acceptable values for B<loc> run from
350 to (X509_NAME_entry_count(name) - 1). The value returned is an
36internal pointer which must not be freed.
37
38X509_NAME_get_text_by_NID(), X509_NAME_get_text_by_OBJ() retrieve
39the "text" from the first entry in B<name> which matches B<nid> or
40B<obj>, if no such entry exists -1 is returned. At most B<len> bytes
41will be written and the text written to B<buf> will be null
42terminated. The length of the output string written is returned
43excluding the terminating null. If B<buf> is <NULL> then the amount
44of space needed in B<buf> (excluding the final null) is returned.
45
46=head1 NOTES
47
48X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() are
49legacy functions which have various limitations which make them
50of minimal use in practice. They can only find the first matching
51entry and will copy the contents of the field verbatim: this can
52be highly confusing if the target is a muticharacter string type
53like a BMPString or a UTF8String.
54
55For a more general solution X509_NAME_get_index_by_NID() or
56X509_NAME_get_index_by_OBJ() should be used followed by
57X509_NAME_get_entry() on any matching indices and then the
58various B<X509_NAME_ENTRY> utility functions on the result.
59
60=head1 EXAMPLES
61
62Process all entries:
63
64 int i;
65 X509_NAME_ENTRY *e;
66
67 for (i = 0; i < X509_NAME_entry_count(nm); i++)
68 {
69 e = X509_NAME_get_entry(nm, i);
70 /* Do something with e */
71 }
72
73Process all commonName entries:
74
75 int loc;
76 X509_NAME_ENTRY *e;
77
78 loc = -1;
79 for (;;)
80 {
81 lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
82 if (lastpos == -1)
83 break;
84 e = X509_NAME_get_entry(nm, lastpos);
85 /* Do something with e */
86 }
87
88=head1 RETURN VALUES
89
90X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ()
91return the index of the next matching entry or -1 if not found.
92
93X509_NAME_entry_count() returns the total number of entries.
94
95X509_NAME_get_entry() returns an B<X509_NAME> pointer to the
96requested entry or B<NULL> if the index is invalid.
97
98=head1 SEE ALSO
99
100L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>
101
102=head1 HISTORY
103
104TBA
105
106=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_print_ex.pod b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
new file mode 100644
index 0000000000..919b908919
--- /dev/null
+++ b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
@@ -0,0 +1,105 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_print_ex, X509_NAME_print_ex_fp, X509_NAME_print,
6X509_NAME_oneline - X509_NAME printing routines.
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);
13 int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);
14 char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
15 int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
16
17=head1 DESCRIPTION
18
19X509_NAME_print_ex() prints a human readable version of B<nm> to BIO B<out>. Each
20line (for multiline formats) is indented by B<indent> spaces. The output format
21can be extensively customised by use of the B<flags> parameter.
22
23X509_NAME_print_ex_fp() is identical to X509_NAME_print_ex() except the output is
24written to FILE pointer B<fp>.
25
26X509_NAME_oneline() prints an ASCII version of B<a> to B<buf>. At most B<size>
27bytes will be written. If B<buf> is B<NULL> then a buffer is dynamically allocated
28and returned, otherwise B<buf> is returned.
29
30X509_NAME_print() prints out B<name> to B<bp> indenting each line by B<obase>
31characters. Multiple lines are used if the output (including indent) exceeds
3280 characters.
33
34=head1 NOTES
35
36The functions X509_NAME_oneline() and X509_NAME_print() are legacy functions which
37produce a non standard output form, they don't handle multi character fields and
38have various quirks and inconsistencies. Their use is strongly discouraged in new
39applications.
40
41Although there are a large number of possible flags for most purposes
42B<XN_FLAG_ONELINE>, B<XN_FLAG_MULTILINE> or B<XN_FLAG_RFC2253> will suffice.
43As noted on the L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> manual page
44for UTF8 terminals the B<ASN1_STRFLGS_ESC_MSB> should be unset: so for example
45B<XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB> would be used.
46
47The complete set of the flags supported by X509_NAME_print_ex() is listed below.
48
49Several options can be ored together.
50
51The options B<XN_FLAG_SEP_COMMA_PLUS>, B<XN_FLAG_SEP_CPLUS_SPC>,
52B<XN_FLAG_SEP_SPLUS_SPC> and B<XN_FLAG_SEP_MULTILINE> determine the field separators
53to use. Two distinct separators are used between distinct RelativeDistinguishedName
54components and separate values in the same RDN for a multi-valued RDN. Multi-valued
55RDNs are currently very rare so the second separator will hardly ever be used.
56
57B<XN_FLAG_SEP_COMMA_PLUS> uses comma and plus as separators. B<XN_FLAG_SEP_CPLUS_SPC>
58uses comma and plus with spaces: this is more readable that plain comma and plus.
59B<XN_FLAG_SEP_SPLUS_SPC> uses spaced semicolon and plus. B<XN_FLAG_SEP_MULTILINE> uses
60spaced newline and plus respectively.
61
62If B<XN_FLAG_DN_REV> is set the whole DN is printed in reversed order.
63
64The fields B<XN_FLAG_FN_SN>, B<XN_FLAG_FN_LN>, B<XN_FLAG_FN_OID>,
65B<XN_FLAG_FN_NONE> determine how a field name is displayed. It will
66use the short name (e.g. CN) the long name (e.g. commonName) always
67use OID numerical form (normally OIDs are only used if the field name is not
68recognised) and no field name respectively.
69
70If B<XN_FLAG_SPC_EQ> is set then spaces will be placed around the '=' character
71separating field names and values.
72
73If B<XN_FLAG_DUMP_UNKNOWN_FIELDS> is set then the encoding of unknown fields is
74printed instead of the values.
75
76If B<XN_FLAG_FN_ALIGN> is set then field names are padded to 20 characters: this
77is only of use for multiline format.
78
79Additionally all the options supported by ASN1_STRING_print_ex() can be used to
80control how each field value is displayed.
81
82In addition a number options can be set for commonly used formats.
83
84B<XN_FLAG_RFC2253> sets options which produce an output compatible with RFC2253 it
85is equivalent to:
86 B<ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS>
87
88
89B<XN_FLAG_ONELINE> is a more readable one line format it is the same as:
90 B<ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN>
91
92B<XN_FLAG_MULTILINE> is a multiline format is is the same as:
93 B<ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | XN_FLAG_SEP_MULTILINE | XN_FLAG_SPC_EQ | XN_FLAG_FN_LN | XN_FLAG_FN_ALIGN>
94
95B<XN_FLAG_COMPAT> uses a format identical to X509_NAME_print(): in fact it calls X509_NAME_print() internally.
96
97=head1 SEE ALSO
98
99L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)>
100
101=head1 HISTORY
102
103TBA
104
105=cut
diff --git a/src/lib/libcrypto/doc/X509_new.pod b/src/lib/libcrypto/doc/X509_new.pod
new file mode 100644
index 0000000000..fd5fc65ce1
--- /dev/null
+++ b/src/lib/libcrypto/doc/X509_new.pod
@@ -0,0 +1,37 @@
1=pod
2
3=head1 NAME
4
5X509_new, X509_free - X509 certificate ASN1 allocation functions
6
7=head1 SYNOPSIS
8
9 X509 *X509_new(void);
10 void X509_free(X509 *a);
11
12=head1 DESCRIPTION
13
14The X509 ASN1 allocation routines, allocate and free an
15X509 structure, which represents an X509 certificate.
16
17X509_new() allocates and initializes a X509 structure.
18
19X509_free() frees up the B<X509> structure B<a>.
20
21=head1 RETURN VALUES
22
23If the allocation fails, X509_new() returns B<NULL> and sets an error
24code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
25Otherwise it returns a pointer to the newly allocated structure.
26
27X509_free() returns no value.
28
29=head1 SEE ALSO
30
31L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509(3)|d2i_X509(3)>
32
33=head1 HISTORY
34
35X509_new() and X509_free() are available in all versions of SSLeay and OpenSSL.
36
37=cut
diff --git a/src/lib/libcrypto/doc/bn.pod b/src/lib/libcrypto/doc/bn.pod
new file mode 100644
index 0000000000..210dfeac08
--- /dev/null
+++ b/src/lib/libcrypto/doc/bn.pod
@@ -0,0 +1,158 @@
1=pod
2
3=head1 NAME
4
5bn - multiprecision integer arithmetics
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_new(void);
12 void BN_free(BIGNUM *a);
13 void BN_init(BIGNUM *);
14 void BN_clear(BIGNUM *a);
15 void BN_clear_free(BIGNUM *a);
16
17 BN_CTX *BN_CTX_new(void);
18 void BN_CTX_init(BN_CTX *c);
19 void BN_CTX_free(BN_CTX *c);
20
21 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
22 BIGNUM *BN_dup(const BIGNUM *a);
23
24 BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b);
25
26 int BN_num_bytes(const BIGNUM *a);
27 int BN_num_bits(const BIGNUM *a);
28 int BN_num_bits_word(BN_ULONG w);
29
30 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
31 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
32 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
33 int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
34 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
35 BN_CTX *ctx);
36 int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
37 int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
38 int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
39 BN_CTX *ctx);
40 int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
41 BN_CTX *ctx);
42 int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
43 BN_CTX *ctx);
44 int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
45 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
46 int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
47 const BIGNUM *m, BN_CTX *ctx);
48 int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
49
50 int BN_add_word(BIGNUM *a, BN_ULONG w);
51 int BN_sub_word(BIGNUM *a, BN_ULONG w);
52 int BN_mul_word(BIGNUM *a, BN_ULONG w);
53 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
54 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
55
56 int BN_cmp(BIGNUM *a, BIGNUM *b);
57 int BN_ucmp(BIGNUM *a, BIGNUM *b);
58 int BN_is_zero(BIGNUM *a);
59 int BN_is_one(BIGNUM *a);
60 int BN_is_word(BIGNUM *a, BN_ULONG w);
61 int BN_is_odd(BIGNUM *a);
62
63 int BN_zero(BIGNUM *a);
64 int BN_one(BIGNUM *a);
65 const BIGNUM *BN_value_one(void);
66 int BN_set_word(BIGNUM *a, unsigned long w);
67 unsigned long BN_get_word(BIGNUM *a);
68
69 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
70 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
71 int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
72 int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
73
74 BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
75 BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
76 int BN_is_prime(const BIGNUM *p, int nchecks,
77 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
78
79 int BN_set_bit(BIGNUM *a, int n);
80 int BN_clear_bit(BIGNUM *a, int n);
81 int BN_is_bit_set(const BIGNUM *a, int n);
82 int BN_mask_bits(BIGNUM *a, int n);
83 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
84 int BN_lshift1(BIGNUM *r, BIGNUM *a);
85 int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
86 int BN_rshift1(BIGNUM *r, BIGNUM *a);
87
88 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
89 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
90 char *BN_bn2hex(const BIGNUM *a);
91 char *BN_bn2dec(const BIGNUM *a);
92 int BN_hex2bn(BIGNUM **a, const char *str);
93 int BN_dec2bn(BIGNUM **a, const char *str);
94 int BN_print(BIO *fp, const BIGNUM *a);
95 int BN_print_fp(FILE *fp, const BIGNUM *a);
96 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
97 BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
98
99 BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
100 BN_CTX *ctx);
101
102 BN_RECP_CTX *BN_RECP_CTX_new(void);
103 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
104 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
105 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
106 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
107 BN_RECP_CTX *recp, BN_CTX *ctx);
108
109 BN_MONT_CTX *BN_MONT_CTX_new(void);
110 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
111 void BN_MONT_CTX_free(BN_MONT_CTX *mont);
112 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
113 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
114 int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
115 BN_MONT_CTX *mont, BN_CTX *ctx);
116 int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
117 BN_CTX *ctx);
118 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
119 BN_CTX *ctx);
120
121
122=head1 DESCRIPTION
123
124This library performs arithmetic operations on integers of arbitrary
125size. It was written for use in public key cryptography, such as RSA
126and Diffie-Hellman.
127
128It uses dynamic memory allocation for storing its data structures.
129That means that there is no limit on the size of the numbers
130manipulated by these functions, but return values must always be
131checked in case a memory allocation error has occurred.
132
133The basic object in this library is a B<BIGNUM>. It is used to hold a
134single large integer. This type should be considered opaque and fields
135should not be modified or accessed directly.
136
137The creation of B<BIGNUM> objects is described in L<BN_new(3)|BN_new(3)>;
138L<BN_add(3)|BN_add(3)> describes most of the arithmetic operations.
139Comparison is described in L<BN_cmp(3)|BN_cmp(3)>; L<BN_zero(3)|BN_zero(3)>
140describes certain assignments, L<BN_rand(3)|BN_rand(3)> the generation of
141random numbers, L<BN_generate_prime(3)|BN_generate_prime(3)> deals with prime
142numbers and L<BN_set_bit(3)|BN_set_bit(3)> with bit operations. The conversion
143of B<BIGNUM>s to external formats is described in L<BN_bn2bin(3)|BN_bn2bin(3)>.
144
145=head1 SEE ALSO
146
147L<bn_internal(3)|bn_internal(3)>,
148L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
149L<BN_new(3)|BN_new(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
150L<BN_copy(3)|BN_copy(3)>, L<BN_swap(3)|BN_swap(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>,
151L<BN_add(3)|BN_add(3)>, L<BN_add_word(3)|BN_add_word(3)>,
152L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
153L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
154L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
155L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
156L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>
157
158=cut
diff --git a/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod b/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod
new file mode 100644
index 0000000000..45bb18492c
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5d2i_ASN1_OBJECT, i2d_ASN1_OBJECT - ASN1 OBJECT IDENTIFIER functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/objects.h>
10
11 ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, long length);
12 int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an ASN1 OBJECT IDENTIFIER.
17
18Othewise these behave in a similar way to d2i_X509() and i2d_X509()
19described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
20
21=head1 SEE ALSO
22
23L<d2i_X509(3)|d2i_X509(3)>
24
25=head1 HISTORY
26
27TBA
28
29=cut
diff --git a/src/lib/libcrypto/doc/d2i_DHparams.pod b/src/lib/libcrypto/doc/d2i_DHparams.pod
new file mode 100644
index 0000000000..1e98aebeca
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_DHparams.pod
@@ -0,0 +1,30 @@
1=pod
2
3=head1 NAME
4
5d2i_DHparams, i2d_DHparams - PKCS#3 DH parameter functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *d2i_DHparams(DH **a, unsigned char **pp, long length);
12 int i2d_DHparams(DH *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode PKCS#3 DH parameters using the
17DHparameter structure described in PKCS#3.
18
19Othewise these behave in a similar way to d2i_X509() and i2d_X509()
20described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
21
22=head1 SEE ALSO
23
24L<d2i_X509(3)|d2i_X509(3)>
25
26=head1 HISTORY
27
28TBA
29
30=cut
diff --git a/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod
new file mode 100644
index 0000000000..22c1b50f22
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod
@@ -0,0 +1,83 @@
1=pod
2
3=head1 NAME
4
5d2i_DSAPublicKey, i2d_DSAPublicKey, d2i_DSAPrivateKey, i2d_DSAPrivateKey,
6d2i_DSA_PUBKEY, i2d_DSA_PUBKEY, d2i_DSA_SIG, i2d_DSA_SIG - DSA key encoding
7and parsing functions.
8
9=head1 SYNOPSIS
10
11 #include <openssl/dsa.h>
12 #include <openssl/x509.h>
13
14 DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
15
16 int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
17
18 DSA * d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length);
19
20 int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp);
21
22 DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
23
24 int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
25
26 DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
27
28 int i2d_DSAparams(const DSA *a, unsigned char **pp);
29
30 DSA * d2i_DSA_SIG(DSA_SIG **a, const unsigned char **pp, long length);
31
32 int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
33
34=head1 DESCRIPTION
35
36d2i_DSAPublicKey() and i2d_DSAPublicKey() decode and encode the DSA public key
37components structure.
38
39d2i_DSA_PUBKEY() and i2d_DSA_PUBKEY() decode and encode an DSA public key using
40a SubjectPublicKeyInfo (certificate public key) structure.
41
42d2i_DSAPrivateKey(), i2d_DSAPrivateKey() decode and encode the DSA private key
43components.
44
45d2i_DSAparams(), i2d_DSAparams() decode and encode the DSA parameters using
46a B<Dss-Parms> structure as defined in RFC2459.
47
48d2i_DSA_SIG(), i2d_DSA_SIG() decode and encode a DSA signature using a
49B<Dss-Sig-Value> structure as defined in RFC2459.
50
51The usage of all of these functions is similar to the d2i_X509() and
52i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
53
54=head1 NOTES
55
56The B<DSA> structure passed to the private key encoding functions should have
57all the private key components present.
58
59The data encoded by the private key functions is unencrypted and therefore
60offers no private key security.
61
62The B<DSA_PUBKEY> functions should be used in preference to the B<DSAPublicKey>
63functions when encoding public keys because they use a standard format.
64
65The B<DSAPublicKey> functions use an non standard format the actual data encoded
66depends on the value of the B<write_params> field of the B<a> key parameter.
67If B<write_params> is zero then only the B<pub_key> field is encoded as an
68B<INTEGER>. If B<write_params> is 1 then a B<SEQUENCE> consisting of the
69B<p>, B<q>, B<g> and B<pub_key> respectively fields are encoded.
70
71The B<DSAPrivateKey> functions also use a non standard structure consiting
72consisting of a SEQUENCE containing the B<p>, B<q>, B<g> and B<pub_key> and
73B<priv_key> fields respectively.
74
75=head1 SEE ALSO
76
77L<d2i_X509(3)|d2i_X509(3)>
78
79=head1 HISTORY
80
81TBA
82
83=cut
diff --git a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
new file mode 100644
index 0000000000..279b29c873
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
@@ -0,0 +1,67 @@
1=pod
2
3=head1 NAME
4
5d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey,
6d2i_RSA_PUBKEY, i2d_RSA_PUBKEY, i2d_Netscape_RSA,
7d2i_Netscape_RSA - RSA public and private key encoding functions.
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12 #include <openssl/x509.h>
13
14 RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
15
16 int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
17
18 RSA * d2i_RSA_PUBKEY(RSA **a, unsigned char **pp, long length);
19
20 int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp);
21
22 RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
23
24 int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
25
26 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
27
28 RSA * d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
29
30=head1 DESCRIPTION
31
32d2i_RSAPublicKey() and i2d_RSAPublicKey() decode and encode a PKCS#1 RSAPublicKey
33structure.
34
35d2i_RSA_PUBKEY() and i2d_RSA_PUBKEY() decode and encode an RSA public key using
36a SubjectPublicKeyInfo (certificate public key) structure.
37
38d2i_RSAPrivateKey(), i2d_RSAPrivateKey() decode and encode a PKCS#1 RSAPrivateKey
39structure.
40
41d2i_Netscape_RSA(), i2d_Netscape_RSA() decode and encode an RSA private key in
42NET format.
43
44The usage of all of these functions is similar to the d2i_X509() and
45i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
46
47=head1 NOTES
48
49The B<RSA> structure passed to the private key encoding functions should have
50all the PKCS#1 private key components present.
51
52The data encoded by the private key functions is unencrypted and therefore
53offers no private key security.
54
55The NET format functions are present to provide compatibility with certain very
56old software. This format has some severe security weaknesses and should be
57avoided if possible.
58
59=head1 SEE ALSO
60
61L<d2i_X509(3)|d2i_X509(3)>
62
63=head1 HISTORY
64
65TBA
66
67=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509.pod b/src/lib/libcrypto/doc/d2i_X509.pod
new file mode 100644
index 0000000000..5e3c3d0985
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_X509.pod
@@ -0,0 +1,231 @@
1=pod
2
3=head1 NAME
4
5d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio,
6i2d_X509_fp - X509 encode and decode functions
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 X509 *d2i_X509(X509 **px, unsigned char **in, int len);
13 int i2d_X509(X509 *x, unsigned char **out);
14
15 X509 *d2i_X509_bio(BIO *bp, X509 **x);
16 X509 *d2i_X509_fp(FILE *fp, X509 **x);
17
18 int i2d_X509_bio(X509 *x, BIO *bp);
19 int i2d_X509_fp(X509 *x, FILE *fp);
20
21=head1 DESCRIPTION
22
23The X509 encode and decode routines encode and parse an
24B<X509> structure, which represents an X509 certificate.
25
26d2i_X509() attempts to decode B<len> bytes at B<*out>. If
27successful a pointer to the B<X509> structure is returned. If an error
28occurred then B<NULL> is returned. If B<px> is not B<NULL> then the
29returned structure is written to B<*px>. If B<*px> is not B<NULL>
30then it is assumed that B<*px> contains a valid B<X509>
31structure and an attempt is made to reuse it. If the call is
32successful B<*out> is incremented to the byte following the
33parsed data.
34
35i2d_X509() encodes the structure pointed to by B<x> into DER format.
36If B<out> is not B<NULL> is writes the DER encoded data to the buffer
37at B<*out>, and increments it to point after the data just written.
38If the return value is negative an error occurred, otherwise it
39returns the length of the encoded data.
40
41For OpenSSL 0.9.7 and later if B<*out> is B<NULL> memory will be
42allocated for a buffer and the encoded data written to it. In this
43case B<*out> is not incremented and it points to the start of the
44data just written.
45
46d2i_X509_bio() is similar to d2i_X509() except it attempts
47to parse data from BIO B<bp>.
48
49d2i_X509_fp() is similar to d2i_X509() except it attempts
50to parse data from FILE pointer B<fp>.
51
52i2d_X509_bio() is similar to i2d_X509() except it writes
53the encoding of the structure B<x> to BIO B<bp> and it
54returns 1 for success and 0 for failure.
55
56i2d_X509_fp() is similar to i2d_X509() except it writes
57the encoding of the structure B<x> to BIO B<bp> and it
58returns 1 for success and 0 for failure.
59
60=head1 NOTES
61
62The letters B<i> and B<d> in for example B<i2d_X509> stand for
63"internal" (that is an internal C structure) and "DER". So that
64B<i2d_X509> converts from internal to DER.
65
66The functions can also understand B<BER> forms.
67
68The actual X509 structure passed to i2d_X509() must be a valid
69populated B<X509> structure it can B<not> simply be fed with an
70empty structure such as that returned by X509_new().
71
72The encoded data is in binary form and may contain embedded zeroes.
73Therefore any FILE pointers or BIOs should be opened in binary mode.
74Functions such as B<strlen()> will B<not> return the correct length
75of the encoded structure.
76
77The ways that B<*in> and B<*out> are incremented after the operation
78can trap the unwary. See the B<WARNINGS> section for some common
79errors.
80
81The reason for the auto increment behaviour is to reflect a typical
82usage of ASN1 functions: after one structure is encoded or decoded
83another will processed after it.
84
85=head1 EXAMPLES
86
87Allocate and encode the DER encoding of an X509 structure:
88
89 int len;
90 unsigned char *buf, *p;
91
92 len = i2d_X509(x, NULL);
93
94 buf = OPENSSL_malloc(len);
95
96 if (buf == NULL)
97 /* error */
98
99 p = buf;
100
101 i2d_X509(x, &p);
102
103If you are using OpenSSL 0.9.7 or later then this can be
104simplified to:
105
106
107 int len;
108 unsigned char *buf;
109
110 buf = NULL;
111
112 len = i2d_X509(x, &buf);
113
114 if (len < 0)
115 /* error */
116
117Attempt to decode a buffer:
118
119 X509 *x;
120
121 unsigned char *buf, *p;
122
123 int len;
124
125 /* Something to setup buf and len */
126
127 p = buf;
128
129 x = d2i_X509(NULL, &p, len);
130
131 if (x == NULL)
132 /* Some error */
133
134Alternative technique:
135
136 X509 *x;
137
138 unsigned char *buf, *p;
139
140 int len;
141
142 /* Something to setup buf and len */
143
144 p = buf;
145
146 x = NULL;
147
148 if(!d2i_X509(&x, &p, len))
149 /* Some error */
150
151
152=head1 WARNINGS
153
154The use of temporary variable is mandatory. A common
155mistake is to attempt to use a buffer directly as follows:
156
157 int len;
158 unsigned char *buf;
159
160 len = i2d_X509(x, NULL);
161
162 buf = OPENSSL_malloc(len);
163
164 if (buf == NULL)
165 /* error */
166
167 i2d_X509(x, &buf);
168
169 /* Other stuff ... */
170
171 OPENSSL_free(buf);
172
173This code will result in B<buf> apparently containing garbage because
174it was incremented after the call to point after the data just written.
175Also B<buf> will no longer contain the pointer allocated by B<OPENSSL_malloc()>
176and the subsequent call to B<OPENSSL_free()> may well crash.
177
178The auto allocation feature (setting buf to NULL) only works on OpenSSL
1790.9.7 and later. Attempts to use it on earlier versions will typically
180cause a segmentation violation.
181
182Another trap to avoid is misuse of the B<xp> argument to B<d2i_X509()>:
183
184 X509 *x;
185
186 if (!d2i_X509(&x, &p, len))
187 /* Some error */
188
189This will probably crash somewhere in B<d2i_X509()>. The reason for this
190is that the variable B<x> is uninitialized and an attempt will be made to
191interpret its (invalid) value as an B<X509> structure, typically causing
192a segmentation violation. If B<x> is set to NULL first then this will not
193happen.
194
195=head1 BUGS
196
197In some versions of OpenSSL the "reuse" behaviour of d2i_X509() when
198B<*px> is valid is broken and some parts of the reused structure may
199persist if they are not present in the new one. As a result the use
200of this "reuse" behaviour is strongly discouraged.
201
202i2d_X509() will not return an error in many versions of OpenSSL,
203if mandatory fields are not initialized due to a programming error
204then the encoded structure may contain invalid data or omit the
205fields entirely and will not be parsed by d2i_X509(). This may be
206fixed in future so code should not assume that i2d_X509() will
207always succeed.
208
209=head1 RETURN VALUES
210
211d2i_X509(), d2i_X509_bio() and d2i_X509_fp() return a valid B<X509> structure
212or B<NULL> if an error occurs. The error code that can be obtained by
213L<ERR_get_error(3)|ERR_get_error(3)>.
214
215i2d_X509(), i2d_X509_bio() and i2d_X509_fp() return a the number of bytes
216successfully encoded or a negative value if an error occurs. The error code
217can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
218
219i2d_X509_bio() and i2d_X509_fp() returns 1 for success and 0 if an error
220occurs The error code can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
221
222=head1 SEE ALSO
223
224L<ERR_get_error(3)|ERR_get_error(3)>
225
226=head1 HISTORY
227
228d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp
229are available in all versions of SSLeay and OpenSSL.
230
231=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod b/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod
new file mode 100644
index 0000000000..9e5cd92ca7
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod
@@ -0,0 +1,30 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_ALGOR, i2d_X509_ALGOR - AlgorithmIdentifier functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/x509.h>
10
11 X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length);
12 int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an B<X509_ALGOR> structure which is
17equivalent to the B<AlgorithmIdentifier> structure.
18
19Othewise these behave in a similar way to d2i_X509() and i2d_X509()
20described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
21
22=head1 SEE ALSO
23
24L<d2i_X509(3)|d2i_X509(3)>
25
26=head1 HISTORY
27
28TBA
29
30=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_CRL.pod b/src/lib/libcrypto/doc/d2i_X509_CRL.pod
new file mode 100644
index 0000000000..06c5b23c09
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_X509_CRL.pod
@@ -0,0 +1,37 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_CRL, i2d_X509_CRL, d2i_X509_CRL_bio, d2i_509_CRL_fp,
6i2d_X509_CRL_bio, i2d_X509_CRL_fp - PKCS#10 certificate request functions.
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length);
13 int i2d_X509_CRL(X509_CRL *a, unsigned char **pp);
14
15 X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **x);
16 X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **x);
17
18 int i2d_X509_CRL_bio(X509_CRL *x, BIO *bp);
19 int i2d_X509_CRL_fp(X509_CRL *x, FILE *fp);
20
21=head1 DESCRIPTION
22
23These functions decode and encode an X509 CRL (certificate revocation
24list).
25
26Othewise the functions behave in a similar way to d2i_X509() and i2d_X509()
27described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
28
29=head1 SEE ALSO
30
31L<d2i_X509(3)|d2i_X509(3)>
32
33=head1 HISTORY
34
35TBA
36
37=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_NAME.pod b/src/lib/libcrypto/doc/d2i_X509_NAME.pod
new file mode 100644
index 0000000000..343ffe1519
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_X509_NAME.pod
@@ -0,0 +1,31 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_NAME, i2d_X509_NAME - X509_NAME encoding functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/x509.h>
10
11 X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length);
12 int i2d_X509_NAME(X509_NAME *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an B<X509_NAME> structure which is the
17the same as the B<Name> type defined in RFC2459 (and elsewhere) and used
18for example in certificate subject and issuer names.
19
20Othewise the functions behave in a similar way to d2i_X509() and i2d_X509()
21described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
22
23=head1 SEE ALSO
24
25L<d2i_X509(3)|d2i_X509(3)>
26
27=head1 HISTORY
28
29TBA
30
31=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_REQ.pod b/src/lib/libcrypto/doc/d2i_X509_REQ.pod
new file mode 100644
index 0000000000..be4ad68257
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_X509_REQ.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_REQ, i2d_X509_REQ, d2i_X509_REQ_bio, d2i_X509_REQ_fp,
6i2d_X509_REQ_bio, i2d_X509_REQ_fp - PKCS#10 certificate request functions.
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length);
13 int i2d_X509_REQ(X509_REQ *a, unsigned char **pp);
14
15 X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **x);
16 X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **x);
17
18 int i2d_X509_REQ_bio(X509_REQ *x, BIO *bp);
19 int i2d_X509_REQ_fp(X509_REQ *x, FILE *fp);
20
21=head1 DESCRIPTION
22
23These functions decode and encode a PKCS#10 certificate request.
24
25Othewise these behave in a similar way to d2i_X509() and i2d_X509()
26described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
27
28=head1 SEE ALSO
29
30L<d2i_X509(3)|d2i_X509(3)>
31
32=head1 HISTORY
33
34TBA
35
36=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_SIG.pod b/src/lib/libcrypto/doc/d2i_X509_SIG.pod
new file mode 100644
index 0000000000..e48fd79a51
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_X509_SIG.pod
@@ -0,0 +1,30 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_SIG, i2d_X509_SIG - DigestInfo functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/x509.h>
10
11 X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length);
12 int i2d_X509_SIG(X509_SIG *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an X509_SIG structure which is
17equivalent to the B<DigestInfo> structure defined in PKCS#1 and PKCS#7.
18
19Othewise these behave in a similar way to d2i_X509() and i2d_X509()
20described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
21
22=head1 SEE ALSO
23
24L<d2i_X509(3)|d2i_X509(3)>
25
26=head1 HISTORY
27
28TBA
29
30=cut
diff --git a/src/lib/libcrypto/doc/dh.pod b/src/lib/libcrypto/doc/dh.pod
new file mode 100644
index 0000000000..c3ccd06207
--- /dev/null
+++ b/src/lib/libcrypto/doc/dh.pod
@@ -0,0 +1,78 @@
1=pod
2
3=head1 NAME
4
5dh - Diffie-Hellman key agreement
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10 #include <openssl/engine.h>
11
12 DH * DH_new(void);
13 void DH_free(DH *dh);
14
15 int DH_size(const DH *dh);
16
17 DH * DH_generate_parameters(int prime_len, int generator,
18 void (*callback)(int, int, void *), void *cb_arg);
19 int DH_check(const DH *dh, int *codes);
20
21 int DH_generate_key(DH *dh);
22 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
23
24 void DH_set_default_method(const DH_METHOD *meth);
25 const DH_METHOD *DH_get_default_method(void);
26 int DH_set_method(DH *dh, const DH_METHOD *meth);
27 DH *DH_new_method(ENGINE *engine);
28 const DH_METHOD *DH_OpenSSL(void);
29
30 int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
31 int (*dup_func)(), void (*free_func)());
32 int DH_set_ex_data(DH *d, int idx, char *arg);
33 char *DH_get_ex_data(DH *d, int idx);
34
35 DH * d2i_DHparams(DH **a, unsigned char **pp, long length);
36 int i2d_DHparams(const DH *a, unsigned char **pp);
37
38 int DHparams_print_fp(FILE *fp, const DH *x);
39 int DHparams_print(BIO *bp, const DH *x);
40
41=head1 DESCRIPTION
42
43These functions implement the Diffie-Hellman key agreement protocol.
44The generation of shared DH parameters is described in
45L<DH_generate_parameters(3)|DH_generate_parameters(3)>; L<DH_generate_key(3)|DH_generate_key(3)> describes how
46to perform a key agreement.
47
48The B<DH> structure consists of several BIGNUM components.
49
50 struct
51 {
52 BIGNUM *p; // prime number (shared)
53 BIGNUM *g; // generator of Z_p (shared)
54 BIGNUM *priv_key; // private DH value x
55 BIGNUM *pub_key; // public DH value g^x
56 // ...
57 };
58 DH
59
60Note that DH keys may use non-standard B<DH_METHOD> implementations,
61either directly or by the use of B<ENGINE> modules. In some cases (eg. an
62ENGINE providing support for hardware-embedded keys), these BIGNUM values
63will not be used by the implementation or may be used for alternative data
64storage. For this reason, applications should generally avoid using DH
65structure elements directly and instead use API functions to query or
66modify keys.
67
68=head1 SEE ALSO
69
70L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
71L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<engine(3)|engine(3)>,
72L<DH_set_method(3)|DH_set_method(3)>, L<DH_new(3)|DH_new(3)>,
73L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>,
74L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
75L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>,
76L<RSA_print(3)|RSA_print(3)>
77
78=cut
diff --git a/src/lib/libcrypto/doc/dsa.pod b/src/lib/libcrypto/doc/dsa.pod
new file mode 100644
index 0000000000..ae2e5d81f9
--- /dev/null
+++ b/src/lib/libcrypto/doc/dsa.pod
@@ -0,0 +1,113 @@
1=pod
2
3=head1 NAME
4
5dsa - Digital Signature Algorithm
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10 #include <openssl/engine.h>
11
12 DSA * DSA_new(void);
13 void DSA_free(DSA *dsa);
14
15 int DSA_size(const DSA *dsa);
16
17 DSA * DSA_generate_parameters(int bits, unsigned char *seed,
18 int seed_len, int *counter_ret, unsigned long *h_ret,
19 void (*callback)(int, int, void *), void *cb_arg);
20
21 DH * DSA_dup_DH(const DSA *r);
22
23 int DSA_generate_key(DSA *dsa);
24
25 int DSA_sign(int dummy, const unsigned char *dgst, int len,
26 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
27 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
28 BIGNUM **rp);
29 int DSA_verify(int dummy, const unsigned char *dgst, int len,
30 const unsigned char *sigbuf, int siglen, DSA *dsa);
31
32 void DSA_set_default_method(const DSA_METHOD *meth);
33 const DSA_METHOD *DSA_get_default_method(void);
34 int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
35 DSA *DSA_new_method(ENGINE *engine);
36 const DSA_METHOD *DSA_OpenSSL(void);
37
38 int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
39 int (*dup_func)(), void (*free_func)());
40 int DSA_set_ex_data(DSA *d, int idx, char *arg);
41 char *DSA_get_ex_data(DSA *d, int idx);
42
43 DSA_SIG *DSA_SIG_new(void);
44 void DSA_SIG_free(DSA_SIG *a);
45 int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
46 DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
47
48 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
49 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
50 DSA_SIG *sig, DSA *dsa);
51
52 DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
53 DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
54 DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
55 int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
56 int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
57 int i2d_DSAparams(const DSA *a,unsigned char **pp);
58
59 int DSAparams_print(BIO *bp, const DSA *x);
60 int DSAparams_print_fp(FILE *fp, const DSA *x);
61 int DSA_print(BIO *bp, const DSA *x, int off);
62 int DSA_print_fp(FILE *bp, const DSA *x, int off);
63
64=head1 DESCRIPTION
65
66These functions implement the Digital Signature Algorithm (DSA). The
67generation of shared DSA parameters is described in
68L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>;
69L<DSA_generate_key(3)|DSA_generate_key(3)> describes how to
70generate a signature key. Signature generation and verification are
71described in L<DSA_sign(3)|DSA_sign(3)>.
72
73The B<DSA> structure consists of several BIGNUM components.
74
75 struct
76 {
77 BIGNUM *p; // prime number (public)
78 BIGNUM *q; // 160-bit subprime, q | p-1 (public)
79 BIGNUM *g; // generator of subgroup (public)
80 BIGNUM *priv_key; // private key x
81 BIGNUM *pub_key; // public key y = g^x
82 // ...
83 }
84 DSA;
85
86In public keys, B<priv_key> is NULL.
87
88Note that DSA keys may use non-standard B<DSA_METHOD> implementations,
89either directly or by the use of B<ENGINE> modules. In some cases (eg. an
90ENGINE providing support for hardware-embedded keys), these BIGNUM values
91will not be used by the implementation or may be used for alternative data
92storage. For this reason, applications should generally avoid using DSA
93structure elements directly and instead use API functions to query or
94modify keys.
95
96=head1 CONFORMING TO
97
98US Federal Information Processing Standard FIPS 186 (Digital Signature
99Standard, DSS), ANSI X9.30
100
101=head1 SEE ALSO
102
103L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
104L<rsa(3)|rsa(3)>, L<SHA1(3)|SHA1(3)>, L<DSA_new(3)|DSA_new(3)>,
105L<DSA_size(3)|DSA_size(3)>,
106L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
107L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
108L<DSA_generate_key(3)|DSA_generate_key(3)>,
109L<DSA_sign(3)|DSA_sign(3)>, L<DSA_set_method(3)|DSA_set_method(3)>,
110L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
111L<RSA_print(3)|RSA_print(3)>
112
113=cut
diff --git a/src/lib/libcrypto/doc/engine.pod b/src/lib/libcrypto/doc/engine.pod
new file mode 100644
index 0000000000..c77dad5562
--- /dev/null
+++ b/src/lib/libcrypto/doc/engine.pod
@@ -0,0 +1,621 @@
1=pod
2
3=head1 NAME
4
5engine - ENGINE cryptographic module support
6
7=head1 SYNOPSIS
8
9 #include <openssl/engine.h>
10
11 ENGINE *ENGINE_get_first(void);
12 ENGINE *ENGINE_get_last(void);
13 ENGINE *ENGINE_get_next(ENGINE *e);
14 ENGINE *ENGINE_get_prev(ENGINE *e);
15
16 int ENGINE_add(ENGINE *e);
17 int ENGINE_remove(ENGINE *e);
18
19 ENGINE *ENGINE_by_id(const char *id);
20
21 int ENGINE_init(ENGINE *e);
22 int ENGINE_finish(ENGINE *e);
23
24 void ENGINE_load_openssl(void);
25 void ENGINE_load_dynamic(void);
26 void ENGINE_load_cswift(void);
27 void ENGINE_load_chil(void);
28 void ENGINE_load_atalla(void);
29 void ENGINE_load_nuron(void);
30 void ENGINE_load_ubsec(void);
31 void ENGINE_load_aep(void);
32 void ENGINE_load_sureware(void);
33 void ENGINE_load_4758cca(void);
34 void ENGINE_load_openbsd_dev_crypto(void);
35 void ENGINE_load_builtin_engines(void);
36
37 void ENGINE_cleanup(void);
38
39 ENGINE *ENGINE_get_default_RSA(void);
40 ENGINE *ENGINE_get_default_DSA(void);
41 ENGINE *ENGINE_get_default_DH(void);
42 ENGINE *ENGINE_get_default_RAND(void);
43 ENGINE *ENGINE_get_cipher_engine(int nid);
44 ENGINE *ENGINE_get_digest_engine(int nid);
45
46 int ENGINE_set_default_RSA(ENGINE *e);
47 int ENGINE_set_default_DSA(ENGINE *e);
48 int ENGINE_set_default_DH(ENGINE *e);
49 int ENGINE_set_default_RAND(ENGINE *e);
50 int ENGINE_set_default_ciphers(ENGINE *e);
51 int ENGINE_set_default_digests(ENGINE *e);
52 int ENGINE_set_default_string(ENGINE *e, const char *list);
53
54 int ENGINE_set_default(ENGINE *e, unsigned int flags);
55
56 unsigned int ENGINE_get_table_flags(void);
57 void ENGINE_set_table_flags(unsigned int flags);
58
59 int ENGINE_register_RSA(ENGINE *e);
60 void ENGINE_unregister_RSA(ENGINE *e);
61 void ENGINE_register_all_RSA(void);
62 int ENGINE_register_DSA(ENGINE *e);
63 void ENGINE_unregister_DSA(ENGINE *e);
64 void ENGINE_register_all_DSA(void);
65 int ENGINE_register_DH(ENGINE *e);
66 void ENGINE_unregister_DH(ENGINE *e);
67 void ENGINE_register_all_DH(void);
68 int ENGINE_register_RAND(ENGINE *e);
69 void ENGINE_unregister_RAND(ENGINE *e);
70 void ENGINE_register_all_RAND(void);
71 int ENGINE_register_ciphers(ENGINE *e);
72 void ENGINE_unregister_ciphers(ENGINE *e);
73 void ENGINE_register_all_ciphers(void);
74 int ENGINE_register_digests(ENGINE *e);
75 void ENGINE_unregister_digests(ENGINE *e);
76 void ENGINE_register_all_digests(void);
77 int ENGINE_register_complete(ENGINE *e);
78 int ENGINE_register_all_complete(void);
79
80 int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
81 int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
82 int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
83 long i, void *p, void (*f)(), int cmd_optional);
84 int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
85 int cmd_optional);
86
87 int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
88 void *ENGINE_get_ex_data(const ENGINE *e, int idx);
89
90 int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
91 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
92
93 ENGINE *ENGINE_new(void);
94 int ENGINE_free(ENGINE *e);
95
96 int ENGINE_set_id(ENGINE *e, const char *id);
97 int ENGINE_set_name(ENGINE *e, const char *name);
98 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
99 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
100 int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
101 int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
102 int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
103 int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
104 int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
105 int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
106 int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
107 int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
108 int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
109 int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
110 int ENGINE_set_flags(ENGINE *e, int flags);
111 int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
112
113 const char *ENGINE_get_id(const ENGINE *e);
114 const char *ENGINE_get_name(const ENGINE *e);
115 const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
116 const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
117 const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
118 const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
119 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
120 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
121 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
122 ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
123 ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
124 ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
125 ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
126 ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
127 const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
128 const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
129 int ENGINE_get_flags(const ENGINE *e);
130 const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
131
132 EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
133 UI_METHOD *ui_method, void *callback_data);
134 EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
135 UI_METHOD *ui_method, void *callback_data);
136
137 void ENGINE_add_conf_module(void);
138
139=head1 DESCRIPTION
140
141These functions create, manipulate, and use cryptographic modules in the
142form of B<ENGINE> objects. These objects act as containers for
143implementations of cryptographic algorithms, and support a
144reference-counted mechanism to allow them to be dynamically loaded in and
145out of the running application.
146
147The cryptographic functionality that can be provided by an B<ENGINE>
148implementation includes the following abstractions;
149
150 RSA_METHOD - for providing alternative RSA implementations
151 DSA_METHOD, DH_METHOD, RAND_METHOD - alternative DSA, DH, and RAND
152 EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
153 EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
154 key-loading - loading public and/or private EVP_PKEY keys
155
156=head2 Reference counting and handles
157
158Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be
159treated as handles - ie. not only as pointers, but also as references to
160the underlying ENGINE object. Ie. you should obtain a new reference when
161making copies of an ENGINE pointer if the copies will be used (and
162released) independantly.
163
164ENGINE objects have two levels of reference-counting to match the way in
165which the objects are used. At the most basic level, each ENGINE pointer is
166inherently a B<structural> reference - you need a structural reference
167simply to refer to the pointer value at all, as this kind of reference is
168your guarantee that the structure can not be deallocated until you release
169your reference.
170
171However, a structural reference provides no guarantee that the ENGINE has
172been initiliased to be usable to perform any of its cryptographic
173implementations - and indeed it's quite possible that most ENGINEs will not
174initialised at all on standard setups, as ENGINEs are typically used to
175support specialised hardware. To use an ENGINE's functionality, you need a
176B<functional> reference. This kind of reference can be considered a
177specialised form of structural reference, because each functional reference
178implicitly contains a structural reference as well - however to avoid
179difficult-to-find programming bugs, it is recommended to treat the two
180kinds of reference independantly. If you have a functional reference to an
181ENGINE, you have a guarantee that the ENGINE has been initialised ready to
182perform cryptographic operations and will not be uninitialised or cleaned
183up until after you have released your reference.
184
185We will discuss the two kinds of reference separately, including how to
186tell which one you are dealing with at any given point in time (after all
187they are both simply (ENGINE *) pointers, the difference is in the way they
188are used).
189
190I<Structural references>
191
192This basic type of reference is typically used for creating new ENGINEs
193dynamically, iterating across OpenSSL's internal linked-list of loaded
194ENGINEs, reading information about an ENGINE, etc. Essentially a structural
195reference is sufficient if you only need to query or manipulate the data of
196an ENGINE implementation rather than use its functionality.
197
198The ENGINE_new() function returns a structural reference to a new (empty)
199ENGINE object. Other than that, structural references come from return
200values to various ENGINE API functions such as; ENGINE_by_id(),
201ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next(),
202ENGINE_get_prev(). All structural references should be released by a
203corresponding to call to the ENGINE_free() function - the ENGINE object
204itself will only actually be cleaned up and deallocated when the last
205structural reference is released.
206
207It should also be noted that many ENGINE API function calls that accept a
208structural reference will internally obtain another reference - typically
209this happens whenever the supplied ENGINE will be needed by OpenSSL after
210the function has returned. Eg. the function to add a new ENGINE to
211OpenSSL's internal list is ENGINE_add() - if this function returns success,
212then OpenSSL will have stored a new structural reference internally so the
213caller is still responsible for freeing their own reference with
214ENGINE_free() when they are finished with it. In a similar way, some
215functions will automatically release the structural reference passed to it
216if part of the function's job is to do so. Eg. the ENGINE_get_next() and
217ENGINE_get_prev() functions are used for iterating across the internal
218ENGINE list - they will return a new structural reference to the next (or
219previous) ENGINE in the list or NULL if at the end (or beginning) of the
220list, but in either case the structural reference passed to the function is
221released on behalf of the caller.
222
223To clarify a particular function's handling of references, one should
224always consult that function's documentation "man" page, or failing that
225the openssl/engine.h header file includes some hints.
226
227I<Functional references>
228
229As mentioned, functional references exist when the cryptographic
230functionality of an ENGINE is required to be available. A functional
231reference can be obtained in one of two ways; from an existing structural
232reference to the required ENGINE, or by asking OpenSSL for the default
233operational ENGINE for a given cryptographic purpose.
234
235To obtain a functional reference from an existing structural reference,
236call the ENGINE_init() function. This returns zero if the ENGINE was not
237already operational and couldn't be successfully initialised (eg. lack of
238system drivers, no special hardware attached, etc), otherwise it will
239return non-zero to indicate that the ENGINE is now operational and will
240have allocated a new B<functional> reference to the ENGINE. In this case,
241the supplied ENGINE pointer is, from the point of the view of the caller,
242both a structural reference and a functional reference - so if the caller
243intends to use it as a functional reference it should free the structural
244reference with ENGINE_free() first. If the caller wishes to use it only as
245a structural reference (eg. if the ENGINE_init() call was simply to test if
246the ENGINE seems available/online), then it should free the functional
247reference; all functional references are released by the ENGINE_finish()
248function.
249
250The second way to get a functional reference is by asking OpenSSL for a
251default implementation for a given task, eg. by ENGINE_get_default_RSA(),
252ENGINE_get_default_cipher_engine(), etc. These are discussed in the next
253section, though they are not usually required by application programmers as
254they are used automatically when creating and using the relevant
255algorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc.
256
257=head2 Default implementations
258
259For each supported abstraction, the ENGINE code maintains an internal table
260of state to control which implementations are available for a given
261abstraction and which should be used by default. These implementations are
262registered in the tables separated-out by an 'nid' index, because
263abstractions like EVP_CIPHER and EVP_DIGEST support many distinct
264algorithms and modes - ENGINEs will support different numbers and
265combinations of these. In the case of other abstractions like RSA, DSA,
266etc, there is only one "algorithm" so all implementations implicitly
267register using the same 'nid' index. ENGINEs can be B<registered> into
268these tables to make themselves available for use automatically by the
269various abstractions, eg. RSA. For illustrative purposes, we continue with
270the RSA example, though all comments apply similarly to the other
271abstractions (they each get their own table and linkage to the
272corresponding section of openssl code).
273
274When a new RSA key is being created, ie. in RSA_new_method(), a
275"get_default" call will be made to the ENGINE subsystem to process the RSA
276state table and return a functional reference to an initialised ENGINE
277whose RSA_METHOD should be used. If no ENGINE should (or can) be used, it
278will return NULL and the RSA key will operate with a NULL ENGINE handle by
279using the conventional RSA implementation in OpenSSL (and will from then on
280behave the way it used to before the ENGINE API existed - for details see
281L<RSA_new_method(3)|RSA_new_method(3)>).
282
283Each state table has a flag to note whether it has processed this
284"get_default" query since the table was last modified, because to process
285this question it must iterate across all the registered ENGINEs in the
286table trying to initialise each of them in turn, in case one of them is
287operational. If it returns a functional reference to an ENGINE, it will
288also cache another reference to speed up processing future queries (without
289needing to iterate across the table). Likewise, it will cache a NULL
290response if no ENGINE was available so that future queries won't repeat the
291same iteration unless the state table changes. This behaviour can also be
292changed; if the ENGINE_TABLE_FLAG_NOINIT flag is set (using
293ENGINE_set_table_flags()), no attempted initialisations will take place,
294instead the only way for the state table to return a non-NULL ENGINE to the
295"get_default" query will be if one is expressly set in the table. Eg.
296ENGINE_set_default_RSA() does the same job as ENGINE_register_RSA() except
297that it also sets the state table's cached response for the "get_default"
298query.
299
300In the case of abstractions like EVP_CIPHER, where implementations are
301indexed by 'nid', these flags and cached-responses are distinct for each
302'nid' value.
303
304It is worth illustrating the difference between "registration" of ENGINEs
305into these per-algorithm state tables and using the alternative
306"set_default" functions. The latter handles both "registration" and also
307setting the cached "default" ENGINE in each relevant state table - so
308registered ENGINEs will only have a chance to be initialised for use as a
309default if a default ENGINE wasn't already set for the same state table.
310Eg. if ENGINE X supports cipher nids {A,B} and RSA, ENGINE Y supports
311ciphers {A} and DSA, and the following code is executed;
312
313 ENGINE_register_complete(X);
314 ENGINE_set_default(Y, ENGINE_METHOD_ALL);
315 e1 = ENGINE_get_default_RSA();
316 e2 = ENGINE_get_cipher_engine(A);
317 e3 = ENGINE_get_cipher_engine(B);
318 e4 = ENGINE_get_default_DSA();
319 e5 = ENGINE_get_cipher_engine(C);
320
321The results would be as follows;
322
323 assert(e1 == X);
324 assert(e2 == Y);
325 assert(e3 == X);
326 assert(e4 == Y);
327 assert(e5 == NULL);
328
329=head2 Application requirements
330
331This section will explain the basic things an application programmer should
332support to make the most useful elements of the ENGINE functionality
333available to the user. The first thing to consider is whether the
334programmer wishes to make alternative ENGINE modules available to the
335application and user. OpenSSL maintains an internal linked list of
336"visible" ENGINEs from which it has to operate - at start-up, this list is
337empty and in fact if an application does not call any ENGINE API calls and
338it uses static linking against openssl, then the resulting application
339binary will not contain any alternative ENGINE code at all. So the first
340consideration is whether any/all available ENGINE implementations should be
341made visible to OpenSSL - this is controlled by calling the various "load"
342functions, eg.
343
344 /* Make the "dynamic" ENGINE available */
345 void ENGINE_load_dynamic(void);
346 /* Make the CryptoSwift hardware acceleration support available */
347 void ENGINE_load_cswift(void);
348 /* Make support for nCipher's "CHIL" hardware available */
349 void ENGINE_load_chil(void);
350 ...
351 /* Make ALL ENGINE implementations bundled with OpenSSL available */
352 void ENGINE_load_builtin_engines(void);
353
354Having called any of these functions, ENGINE objects would have been
355dynamically allocated and populated with these implementations and linked
356into OpenSSL's internal linked list. At this point it is important to
357mention an important API function;
358
359 void ENGINE_cleanup(void);
360
361If no ENGINE API functions are called at all in an application, then there
362are no inherent memory leaks to worry about from the ENGINE functionality,
363however if any ENGINEs are "load"ed, even if they are never registered or
364used, it is necessary to use the ENGINE_cleanup() function to
365correspondingly cleanup before program exit, if the caller wishes to avoid
366memory leaks. This mechanism uses an internal callback registration table
367so that any ENGINE API functionality that knows it requires cleanup can
368register its cleanup details to be called during ENGINE_cleanup(). This
369approach allows ENGINE_cleanup() to clean up after any ENGINE functionality
370at all that your program uses, yet doesn't automatically create linker
371dependencies to all possible ENGINE functionality - only the cleanup
372callbacks required by the functionality you do use will be required by the
373linker.
374
375The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
376the program and loaded into memory at run-time) does not mean they are
377"registered" or called into use by OpenSSL automatically - that behaviour
378is something for the application to have control over. Some applications
379will want to allow the user to specify exactly which ENGINE they want used
380if any is to be used at all. Others may prefer to load all support and have
381OpenSSL automatically use at run-time any ENGINE that is able to
382successfully initialise - ie. to assume that this corresponds to
383acceleration hardware attached to the machine or some such thing. There are
384probably numerous other ways in which applications may prefer to handle
385things, so we will simply illustrate the consequences as they apply to a
386couple of simple cases and leave developers to consider these and the
387source code to openssl's builtin utilities as guides.
388
389I<Using a specific ENGINE implementation>
390
391Here we'll assume an application has been configured by its user or admin
392to want to use the "ACME" ENGINE if it is available in the version of
393OpenSSL the application was compiled with. If it is available, it should be
394used by default for all RSA, DSA, and symmetric cipher operation, otherwise
395OpenSSL should use its builtin software as per usual. The following code
396illustrates how to approach this;
397
398 ENGINE *e;
399 const char *engine_id = "ACME";
400 ENGINE_load_builtin_engines();
401 e = ENGINE_by_id(engine_id);
402 if(!e)
403 /* the engine isn't available */
404 return;
405 if(!ENGINE_init(e)) {
406 /* the engine couldn't initialise, release 'e' */
407 ENGINE_free(e);
408 return;
409 }
410 if(!ENGINE_set_default_RSA(e))
411 /* This should only happen when 'e' can't initialise, but the previous
412 * statement suggests it did. */
413 abort();
414 ENGINE_set_default_DSA(e);
415 ENGINE_set_default_ciphers(e);
416 /* Release the functional reference from ENGINE_init() */
417 ENGINE_finish(e);
418 /* Release the structural reference from ENGINE_by_id() */
419 ENGINE_free(e);
420
421I<Automatically using builtin ENGINE implementations>
422
423Here we'll assume we want to load and register all ENGINE implementations
424bundled with OpenSSL, such that for any cryptographic algorithm required by
425OpenSSL - if there is an ENGINE that implements it and can be initialise,
426it should be used. The following code illustrates how this can work;
427
428 /* Load all bundled ENGINEs into memory and make them visible */
429 ENGINE_load_builtin_engines();
430 /* Register all of them for every algorithm they collectively implement */
431 ENGINE_register_all_complete();
432
433That's all that's required. Eg. the next time OpenSSL tries to set up an
434RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to
435ENGINE_init() and if any of those succeed, that ENGINE will be set as the
436default for use with RSA from then on.
437
438=head2 Advanced configuration support
439
440There is a mechanism supported by the ENGINE framework that allows each
441ENGINE implementation to define an arbitrary set of configuration
442"commands" and expose them to OpenSSL and any applications based on
443OpenSSL. This mechanism is entirely based on the use of name-value pairs
444and and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
445applications want to provide a transparent way for users to provide
446arbitrary configuration "directives" directly to such ENGINEs. It is also
447possible for the application to dynamically interrogate the loaded ENGINE
448implementations for the names, descriptions, and input flags of their
449available "control commands", providing a more flexible configuration
450scheme. However, if the user is expected to know which ENGINE device he/she
451is using (in the case of specialised hardware, this goes without saying)
452then applications may not need to concern themselves with discovering the
453supported control commands and simply prefer to allow settings to passed
454into ENGINEs exactly as they are provided by the user.
455
456Before illustrating how control commands work, it is worth mentioning what
457they are typically used for. Broadly speaking there are two uses for
458control commands; the first is to provide the necessary details to the
459implementation (which may know nothing at all specific to the host system)
460so that it can be initialised for use. This could include the path to any
461driver or config files it needs to load, required network addresses,
462smart-card identifiers, passwords to initialise password-protected devices,
463logging information, etc etc. This class of commands typically needs to be
464passed to an ENGINE B<before> attempting to initialise it, ie. before
465calling ENGINE_init(). The other class of commands consist of settings or
466operations that tweak certain behaviour or cause certain operations to take
467place, and these commands may work either before or after ENGINE_init(), or
468in same cases both. ENGINE implementations should provide indications of
469this in the descriptions attached to builtin control commands and/or in
470external product documentation.
471
472I<Issuing control commands to an ENGINE>
473
474Let's illustrate by example; a function for which the caller supplies the
475name of the ENGINE it wishes to use, a table of string-pairs for use before
476initialisation, and another table for use after initialisation. Note that
477the string-pairs used for control commands consist of a command "name"
478followed by the command "parameter" - the parameter could be NULL in some
479cases but the name can not. This function should initialise the ENGINE
480(issuing the "pre" commands beforehand and the "post" commands afterwards)
481and set it as the default for everything except RAND and then return a
482boolean success or failure.
483
484 int generic_load_engine_fn(const char *engine_id,
485 const char **pre_cmds, int pre_num,
486 const char **post_cmds, int post_num)
487 {
488 ENGINE *e = ENGINE_by_id(engine_id);
489 if(!e) return 0;
490 while(pre_num--) {
491 if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
492 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
493 pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
494 ENGINE_free(e);
495 return 0;
496 }
497 pre_cmds += 2;
498 }
499 if(!ENGINE_init(e)) {
500 fprintf(stderr, "Failed initialisation\n");
501 ENGINE_free(e);
502 return 0;
503 }
504 /* ENGINE_init() returned a functional reference, so free the structural
505 * reference from ENGINE_by_id(). */
506 ENGINE_free(e);
507 while(post_num--) {
508 if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
509 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
510 post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
511 ENGINE_finish(e);
512 return 0;
513 }
514 post_cmds += 2;
515 }
516 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
517 /* Success */
518 return 1;
519 }
520
521Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
522relax the semantics of the function - if set non-zero it will only return
523failure if the ENGINE supported the given command name but failed while
524executing it, if the ENGINE doesn't support the command name it will simply
525return success without doing anything. In this case we assume the user is
526only supplying commands specific to the given ENGINE so we set this to
527FALSE.
528
529I<Discovering supported control commands>
530
531It is possible to discover at run-time the names, numerical-ids, descriptions
532and input parameters of the control commands supported from a structural
533reference to any ENGINE. It is first important to note that some control
534commands are defined by OpenSSL itself and it will intercept and handle these
535control commands on behalf of the ENGINE, ie. the ENGINE's ctrl() handler is not
536used for the control command. openssl/engine.h defines a symbol,
537ENGINE_CMD_BASE, that all control commands implemented by ENGINEs from. Any
538command value lower than this symbol is considered a "generic" command is
539handled directly by the OpenSSL core routines.
540
541It is using these "core" control commands that one can discover the the control
542commands implemented by a given ENGINE, specifically the commands;
543
544 #define ENGINE_HAS_CTRL_FUNCTION 10
545 #define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
546 #define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
547 #define ENGINE_CTRL_GET_CMD_FROM_NAME 13
548 #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
549 #define ENGINE_CTRL_GET_NAME_FROM_CMD 15
550 #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
551 #define ENGINE_CTRL_GET_DESC_FROM_CMD 17
552 #define ENGINE_CTRL_GET_CMD_FLAGS 18
553
554Whilst these commands are automatically processed by the OpenSSL framework code,
555they use various properties exposed by each ENGINE by which to process these
556queries. An ENGINE has 3 properties it exposes that can affect this behaviour;
557it can supply a ctrl() handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in
558the ENGINE's flags, and it can expose an array of control command descriptions.
559If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will
560simply pass all these "core" control commands directly to the ENGINE's ctrl()
561handler (and thus, it must have supplied one), so it is up to the ENGINE to
562reply to these "discovery" commands itself. If that flag is not set, then the
563OpenSSL framework code will work with the following rules;
564
565 if no ctrl() handler supplied;
566 ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
567 all other commands fail.
568 if a ctrl() handler was supplied but no array of control commands;
569 ENGINE_HAS_CTRL_FUNCTION returns TRUE,
570 all other commands fail.
571 if a ctrl() handler and array of control commands was supplied;
572 ENGINE_HAS_CTRL_FUNCTION returns TRUE,
573 all other commands proceed processing ...
574
575If the ENGINE's array of control commands is empty then all other commands will
576fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the identifier of
577the first command supported by the ENGINE, ENGINE_GET_NEXT_CMD_TYPE takes the
578identifier of a command supported by the ENGINE and returns the next command
579identifier or fails if there are no more, ENGINE_CMD_FROM_NAME takes a string
580name for a command and returns the corresponding identifier or fails if no such
581command name exists, and the remaining commands take a command identifier and
582return properties of the corresponding commands. All except
583ENGINE_CTRL_GET_FLAGS return the string length of a command name or description,
584or populate a supplied character buffer with a copy of the command name or
585description. ENGINE_CTRL_GET_FLAGS returns a bitwise-OR'd mask of the following
586possible values;
587
588 #define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
589 #define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
590 #define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
591 #define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
592
593If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are purely
594informational to the caller - this flag will prevent the command being usable
595for any higher-level ENGINE functions such as ENGINE_ctrl_cmd_string().
596"INTERNAL" commands are not intended to be exposed to text-based configuration
597by applications, administrations, users, etc. These can support arbitrary
598operations via ENGINE_ctrl(), including passing to and/or from the control
599commands data of any arbitrary type. These commands are supported in the
600discovery mechanisms simply to allow applications determinie if an ENGINE
601supports certain specific commands it might want to use (eg. application "foo"
602might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" -
603and ENGINE could therefore decide whether or not to support this "foo"-specific
604extension).
605
606=head2 Future developments
607
608The ENGINE API and internal architecture is currently being reviewed. Slated for
609possible release in 0.9.8 is support for transparent loading of "dynamic"
610ENGINEs (built as self-contained shared-libraries). This would allow ENGINE
611implementations to be provided independantly of OpenSSL libraries and/or
612OpenSSL-based applications, and would also remove any requirement for
613applications to explicitly use the "dynamic" ENGINE to bind to shared-library
614implementations.
615
616=head1 SEE ALSO
617
618L<rsa(3)|rsa(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rand(3)|rand(3)>,
619L<RSA_new_method(3)|RSA_new_method(3)>
620
621=cut
diff --git a/src/lib/libcrypto/doc/evp.pod b/src/lib/libcrypto/doc/evp.pod
new file mode 100644
index 0000000000..b3ca14314f
--- /dev/null
+++ b/src/lib/libcrypto/doc/evp.pod
@@ -0,0 +1,45 @@
1=pod
2
3=head1 NAME
4
5evp - high-level cryptographic functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11=head1 DESCRIPTION
12
13The EVP library provides a high-level interface to cryptographic
14functions.
15
16B<EVP_Seal>I<...> and B<EVP_Open>I<...> provide public key encryption
17and decryption to implement digital "envelopes".
18
19The B<EVP_Sign>I<...> and B<EVP_Verify>I<...> functions implement
20digital signatures.
21
22Symmetric encryption is available with the B<EVP_Encrypt>I<...>
23functions. The B<EVP_Digest>I<...> functions provide message digests.
24
25Algorithms are loaded with OpenSSL_add_all_algorithms(3).
26
27All the symmetric algorithms (ciphers) and digests can be replaced by ENGINE
28modules providing alternative implementations. If ENGINE implementations of
29ciphers or digests are registered as defaults, then the various EVP functions
30will automatically use those implementations automatically in preference to
31built in software implementations. For more information, consult the engine(3)
32man page.
33
34=head1 SEE ALSO
35
36L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
37L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
38L<EVP_OpenInit(3)|EVP_OpenInit(3)>,
39L<EVP_SealInit(3)|EVP_SealInit(3)>,
40L<EVP_SignInit(3)|EVP_SignInit(3)>,
41L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
42L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,
43L<engine(3)|engine(3)>
44
45=cut
diff --git a/src/lib/libcrypto/doc/lh_stats.pod b/src/lib/libcrypto/doc/lh_stats.pod
new file mode 100644
index 0000000000..3eeaa72e52
--- /dev/null
+++ b/src/lib/libcrypto/doc/lh_stats.pod
@@ -0,0 +1,60 @@
1=pod
2
3=head1 NAME
4
5lh_stats, lh_node_stats, lh_node_usage_stats, lh_stats_bio,
6lh_node_stats_bio, lh_node_usage_stats_bio - LHASH statistics
7
8=head1 SYNOPSIS
9
10 #include <openssl/lhash.h>
11
12 void lh_stats(LHASH *table, FILE *out);
13 void lh_node_stats(LHASH *table, FILE *out);
14 void lh_node_usage_stats(LHASH *table, FILE *out);
15
16 void lh_stats_bio(LHASH *table, BIO *out);
17 void lh_node_stats_bio(LHASH *table, BIO *out);
18 void lh_node_usage_stats_bio(LHASH *table, BIO *out);
19
20=head1 DESCRIPTION
21
22The B<LHASH> structure records statistics about most aspects of
23accessing the hash table. This is mostly a legacy of Eric Young
24writing this library for the reasons of implementing what looked like
25a nice algorithm rather than for a particular software product.
26
27lh_stats() prints out statistics on the size of the hash table, how
28many entries are in it, and the number and result of calls to the
29routines in this library.
30
31lh_node_stats() prints the number of entries for each 'bucket' in the
32hash table.
33
34lh_node_usage_stats() prints out a short summary of the state of the
35hash table. It prints the 'load' and the 'actual load'. The load is
36the average number of data items per 'bucket' in the hash table. The
37'actual load' is the average number of items per 'bucket', but only
38for buckets which contain entries. So the 'actual load' is the
39average number of searches that will need to find an item in the hash
40table, while the 'load' is the average number that will be done to
41record a miss.
42
43lh_stats_bio(), lh_node_stats_bio() and lh_node_usage_stats_bio()
44are the same as the above, except that the output goes to a B<BIO>.
45
46=head1 RETURN VALUES
47
48These functions do not return values.
49
50=head1 SEE ALSO
51
52L<bio(3)|bio(3)>, L<lhash(3)|lhash(3)>
53
54=head1 HISTORY
55
56These functions are available in all versions of SSLeay and OpenSSL.
57
58This manpage is derived from the SSLeay documentation.
59
60=cut
diff --git a/src/lib/libcrypto/doc/rsa.pod b/src/lib/libcrypto/doc/rsa.pod
new file mode 100644
index 0000000000..45ac53ffc1
--- /dev/null
+++ b/src/lib/libcrypto/doc/rsa.pod
@@ -0,0 +1,123 @@
1=pod
2
3=head1 NAME
4
5rsa - RSA public key cryptosystem
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10 #include <openssl/engine.h>
11
12 RSA * RSA_new(void);
13 void RSA_free(RSA *rsa);
14
15 int RSA_public_encrypt(int flen, unsigned char *from,
16 unsigned char *to, RSA *rsa, int padding);
17 int RSA_private_decrypt(int flen, unsigned char *from,
18 unsigned char *to, RSA *rsa, int padding);
19 int RSA_private_encrypt(int flen, unsigned char *from,
20 unsigned char *to, RSA *rsa,int padding);
21 int RSA_public_decrypt(int flen, unsigned char *from,
22 unsigned char *to, RSA *rsa,int padding);
23
24 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
25 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
26 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
27 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
28
29 int RSA_size(const RSA *rsa);
30
31 RSA *RSA_generate_key(int num, unsigned long e,
32 void (*callback)(int,int,void *), void *cb_arg);
33
34 int RSA_check_key(RSA *rsa);
35
36 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
37 void RSA_blinding_off(RSA *rsa);
38
39 void RSA_set_default_method(const RSA_METHOD *meth);
40 const RSA_METHOD *RSA_get_default_method(void);
41 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
42 const RSA_METHOD *RSA_get_method(const RSA *rsa);
43 RSA_METHOD *RSA_PKCS1_SSLeay(void);
44 RSA_METHOD *RSA_null_method(void);
45 int RSA_flags(const RSA *rsa);
46 RSA *RSA_new_method(ENGINE *engine);
47
48 int RSA_print(BIO *bp, RSA *x, int offset);
49 int RSA_print_fp(FILE *fp, RSA *x, int offset);
50
51 int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
52 int (*dup_func)(), void (*free_func)());
53 int RSA_set_ex_data(RSA *r,int idx,char *arg);
54 char *RSA_get_ex_data(RSA *r, int idx);
55
56 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
57 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
58 RSA *rsa);
59 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
60 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
61 RSA *rsa);
62
63=head1 DESCRIPTION
64
65These functions implement RSA public key encryption and signatures
66as defined in PKCS #1 v2.0 [RFC 2437].
67
68The B<RSA> structure consists of several BIGNUM components. It can
69contain public as well as private RSA keys:
70
71 struct
72 {
73 BIGNUM *n; // public modulus
74 BIGNUM *e; // public exponent
75 BIGNUM *d; // private exponent
76 BIGNUM *p; // secret prime factor
77 BIGNUM *q; // secret prime factor
78 BIGNUM *dmp1; // d mod (p-1)
79 BIGNUM *dmq1; // d mod (q-1)
80 BIGNUM *iqmp; // q^-1 mod p
81 // ...
82 };
83 RSA
84
85In public keys, the private exponent and the related secret values are
86B<NULL>.
87
88B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private
89keys, but the RSA operations are much faster when these values are
90available.
91
92Note that RSA keys may use non-standard B<RSA_METHOD> implementations,
93either directly or by the use of B<ENGINE> modules. In some cases (eg. an
94ENGINE providing support for hardware-embedded keys), these BIGNUM values
95will not be used by the implementation or may be used for alternative data
96storage. For this reason, applications should generally avoid using RSA
97structure elements directly and instead use API functions to query or
98modify keys.
99
100=head1 CONFORMING TO
101
102SSL, PKCS #1 v2.0
103
104=head1 PATENTS
105
106RSA was covered by a US patent which expired in September 2000.
107
108=head1 SEE ALSO
109
110L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
111L<rand(3)|rand(3)>, L<engine(3)|engine(3)>, L<RSA_new(3)|RSA_new(3)>,
112L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
113L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
114L<RSA_generate_key(3)|RSA_generate_key(3)>,
115L<RSA_check_key(3)|RSA_check_key(3)>,
116L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
117L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
118L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
119L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
120L<RSA_sign_ASN1_OCTET_STRING(3)|RSA_sign_ASN1_OCTET_STRING(3)>,
121L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)>
122
123=cut
diff --git a/src/lib/libcrypto/dsa/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/dsa.h b/src/lib/libcrypto/dsa/dsa.h
new file mode 100644
index 0000000000..225ff391f9
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa.h
@@ -0,0 +1,254 @@
1/* crypto/dsa/dsa.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 * The DSS routines are based on patches supplied by
61 * Steven Schoch <schoch@sheba.arc.nasa.gov>. He basically did the
62 * work and I have just tweaked them a little to fit into my
63 * stylistic vision for SSLeay :-) */
64
65#ifndef HEADER_DSA_H
66#define HEADER_DSA_H
67
68#ifdef OPENSSL_NO_DSA
69#error DSA is disabled.
70#endif
71
72#ifndef OPENSSL_NO_BIO
73#include <openssl/bio.h>
74#endif
75#include <openssl/bn.h>
76#include <openssl/crypto.h>
77#include <openssl/ossl_typ.h>
78#ifndef OPENSSL_NO_DH
79# include <openssl/dh.h>
80#endif
81
82#define DSA_FLAG_CACHE_MONT_P 0x01
83
84#if defined(OPENSSL_FIPS)
85#define FIPS_DSA_SIZE_T int
86#endif
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92typedef struct dsa_st DSA;
93
94typedef struct DSA_SIG_st
95 {
96 BIGNUM *r;
97 BIGNUM *s;
98 } DSA_SIG;
99
100typedef struct dsa_method {
101 const char *name;
102 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
103 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
104 BIGNUM **rp);
105 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
106 DSA_SIG *sig, DSA *dsa);
107 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
108 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
109 BN_MONT_CTX *in_mont);
110 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
111 const BIGNUM *m, BN_CTX *ctx,
112 BN_MONT_CTX *m_ctx); /* Can be null */
113 int (*init)(DSA *dsa);
114 int (*finish)(DSA *dsa);
115 int flags;
116 char *app_data;
117} DSA_METHOD;
118
119struct dsa_st
120 {
121 /* This first variable is used to pick up errors where
122 * a DSA is passed instead of of a EVP_PKEY */
123 int pad;
124 long version;
125 int write_params;
126 BIGNUM *p;
127 BIGNUM *q; /* == 20 */
128 BIGNUM *g;
129
130 BIGNUM *pub_key; /* y public key */
131 BIGNUM *priv_key; /* x private key */
132
133 BIGNUM *kinv; /* Signing pre-calc */
134 BIGNUM *r; /* Signing pre-calc */
135
136 int flags;
137 /* Normally used to cache montgomery values */
138 char *method_mont_p;
139 int references;
140 CRYPTO_EX_DATA ex_data;
141 const DSA_METHOD *meth;
142 /* functional reference if 'meth' is ENGINE-provided */
143 ENGINE *engine;
144 };
145
146#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
147 (char *(*)())d2i_DSAparams,(char *)(x))
148#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
149 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
150#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
151 (unsigned char *)(x))
152#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
153 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
154#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
155 (unsigned char *)(x))
156
157
158DSA_SIG * DSA_SIG_new(void);
159void DSA_SIG_free(DSA_SIG *a);
160int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
161DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
162
163DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
164int DSA_do_verify(const unsigned char *dgst,int dgst_len,
165 DSA_SIG *sig,DSA *dsa);
166
167const DSA_METHOD *DSA_OpenSSL(void);
168
169void DSA_set_default_method(const DSA_METHOD *);
170const DSA_METHOD *DSA_get_default_method(void);
171int DSA_set_method(DSA *dsa, const DSA_METHOD *);
172
173DSA * DSA_new(void);
174DSA * DSA_new_method(ENGINE *engine);
175void DSA_free (DSA *r);
176/* "up" the DSA object's reference count */
177int DSA_up_ref(DSA *r);
178int DSA_size(const DSA *);
179 /* next 4 return -1 on error */
180int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
181int DSA_sign(int type,const unsigned char *dgst,int dlen,
182 unsigned char *sig, unsigned int *siglen, DSA *dsa);
183int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
184 const unsigned char *sigbuf, int siglen, DSA *dsa);
185int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
186 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
187int DSA_set_ex_data(DSA *d, int idx, void *arg);
188void *DSA_get_ex_data(DSA *d, int idx);
189
190DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
191DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
192DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
193DSA * DSA_generate_parameters(int bits,
194 unsigned char *seed,int seed_len,
195 int *counter_ret, unsigned long *h_ret,void
196 (*callback)(int, int, void *),void *cb_arg);
197int DSA_generate_key(DSA *a);
198int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
199int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
200int i2d_DSAparams(const DSA *a,unsigned char **pp);
201
202#ifndef OPENSSL_NO_BIO
203int DSAparams_print(BIO *bp, const DSA *x);
204int DSA_print(BIO *bp, const DSA *x, int off);
205#endif
206#ifndef OPENSSL_NO_FP_API
207int DSAparams_print_fp(FILE *fp, const DSA *x);
208int DSA_print_fp(FILE *bp, const DSA *x, int off);
209#endif
210
211#define DSS_prime_checks 50
212/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
213 * 50 rounds of Rabin-Miller */
214#define DSA_is_prime(n, callback, cb_arg) \
215 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
216
217#ifndef OPENSSL_NO_DH
218/* Convert DSA structure (key or just parameters) into DH structure
219 * (be careful to avoid small subgroup attacks when using this!) */
220DH *DSA_dup_DH(const DSA *r);
221#endif
222
223/* BEGIN ERROR CODES */
224/* The following lines are auto generated by the script mkerr.pl. Any changes
225 * made after this point may be overwritten when the script is next run.
226 */
227void ERR_load_DSA_strings(void);
228
229/* Error codes for the DSA functions. */
230
231/* Function codes. */
232#define DSA_F_D2I_DSA_SIG 110
233#define DSA_F_DSAPARAMS_PRINT 100
234#define DSA_F_DSAPARAMS_PRINT_FP 101
235#define DSA_F_DSA_DO_SIGN 112
236#define DSA_F_DSA_DO_VERIFY 113
237#define DSA_F_DSA_NEW_METHOD 103
238#define DSA_F_DSA_PRINT 104
239#define DSA_F_DSA_PRINT_FP 105
240#define DSA_F_DSA_SIGN 106
241#define DSA_F_DSA_SIGN_SETUP 107
242#define DSA_F_DSA_SIG_NEW 109
243#define DSA_F_DSA_VERIFY 108
244#define DSA_F_I2D_DSA_SIG 111
245#define DSA_F_SIG_CB 114
246
247/* Reason codes. */
248#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
249#define DSA_R_MISSING_PARAMETERS 101
250
251#ifdef __cplusplus
252}
253#endif
254#endif
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
new file mode 100644
index 0000000000..23fce555aa
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -0,0 +1,140 @@
1/* dsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dsa.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64
65/* Override the default new methods */
66static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
67{
68 if(operation == ASN1_OP_NEW_PRE) {
69 DSA_SIG *sig;
70 sig = OPENSSL_malloc(sizeof(DSA_SIG));
71 sig->r = NULL;
72 sig->s = NULL;
73 *pval = (ASN1_VALUE *)sig;
74 if(sig) return 2;
75 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
76 return 0;
77 }
78 return 1;
79}
80
81ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
82 ASN1_SIMPLE(DSA_SIG, r, CBIGNUM),
83 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
84} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
85
86IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)
87
88/* Override the default free and new methods */
89static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
90{
91 if(operation == ASN1_OP_NEW_PRE) {
92 *pval = (ASN1_VALUE *)DSA_new();
93 if(*pval) return 2;
94 return 0;
95 } else if(operation == ASN1_OP_FREE_PRE) {
96 DSA_free((DSA *)*pval);
97 *pval = NULL;
98 return 2;
99 }
100 return 1;
101}
102
103ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
104 ASN1_SIMPLE(DSA, version, LONG),
105 ASN1_SIMPLE(DSA, p, BIGNUM),
106 ASN1_SIMPLE(DSA, q, BIGNUM),
107 ASN1_SIMPLE(DSA, g, BIGNUM),
108 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
109 ASN1_SIMPLE(DSA, priv_key, BIGNUM)
110} ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
111
112IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPrivateKey, DSAPrivateKey)
113
114ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
115 ASN1_SIMPLE(DSA, p, BIGNUM),
116 ASN1_SIMPLE(DSA, q, BIGNUM),
117 ASN1_SIMPLE(DSA, g, BIGNUM),
118} ASN1_SEQUENCE_END_cb(DSA, DSAparams)
119
120IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)
121
122/* DSA public key is a bit trickier... its effectively a CHOICE type
123 * decided by a field called write_params which can either write out
124 * just the public key as an INTEGER or the parameters and public key
125 * in a SEQUENCE
126 */
127
128ASN1_SEQUENCE(dsa_pub_internal) = {
129 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
130 ASN1_SIMPLE(DSA, p, BIGNUM),
131 ASN1_SIMPLE(DSA, q, BIGNUM),
132 ASN1_SIMPLE(DSA, g, BIGNUM)
133} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)
134
135ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
136 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
137 ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
138} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
139
140IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
new file mode 100644
index 0000000000..79aa4ff526
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_err.c
@@ -0,0 +1,108 @@
1/* crypto/dsa/dsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dsa.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA DSA_str_functs[]=
68 {
69{ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"},
70{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"},
71{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"},
72{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"},
73{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"},
74{ERR_PACK(0,DSA_F_DSA_NEW_METHOD,0), "DSA_new_method"},
75{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"},
76{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"},
77{ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"},
78{ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"},
79{ERR_PACK(0,DSA_F_DSA_SIG_NEW,0), "DSA_SIG_new"},
80{ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"},
81{ERR_PACK(0,DSA_F_I2D_DSA_SIG,0), "i2d_DSA_SIG"},
82{ERR_PACK(0,DSA_F_SIG_CB,0), "SIG_CB"},
83{0,NULL}
84 };
85
86static ERR_STRING_DATA DSA_str_reasons[]=
87 {
88{DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
89{DSA_R_MISSING_PARAMETERS ,"missing parameters"},
90{0,NULL}
91 };
92
93#endif
94
95void ERR_load_DSA_strings(void)
96 {
97 static int init=1;
98
99 if (init)
100 {
101 init=0;
102#ifndef OPENSSL_NO_ERR
103 ERR_load_strings(ERR_LIB_DSA,DSA_str_functs);
104 ERR_load_strings(ERR_LIB_DSA,DSA_str_reasons);
105#endif
106
107 }
108 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
new file mode 100644
index 0000000000..e40afeea51
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_gen.c
@@ -0,0 +1,305 @@
1/* crypto/dsa/dsa_gen.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#undef GENUINE_DSA
60
61#ifdef GENUINE_DSA
62/* Parameter generation follows the original release of FIPS PUB 186,
63 * Appendix 2.2 (i.e. use SHA as defined in FIPS PUB 180) */
64#define HASH EVP_sha()
65#else
66/* Parameter generation follows the updated Appendix 2.2 for FIPS PUB 186,
67 * also Appendix 2.2 of FIPS PUB 186-1 (i.e. use SHA as defined in
68 * FIPS PUB 180-1) */
69#define HASH EVP_sha1()
70#endif
71
72#ifndef OPENSSL_NO_SHA
73
74#include <stdio.h>
75#include <time.h>
76#include "cryptlib.h"
77#include <openssl/evp.h>
78#include <openssl/bn.h>
79#include <openssl/dsa.h>
80#include <openssl/rand.h>
81#include <openssl/sha.h>
82
83#ifndef OPENSSL_FIPS
84DSA *DSA_generate_parameters(int bits,
85 unsigned char *seed_in, int seed_len,
86 int *counter_ret, unsigned long *h_ret,
87 void (*callback)(int, int, void *),
88 void *cb_arg)
89 {
90 int ok=0;
91 unsigned char seed[SHA_DIGEST_LENGTH];
92 unsigned char md[SHA_DIGEST_LENGTH];
93 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
94 BIGNUM *r0,*W,*X,*c,*test;
95 BIGNUM *g=NULL,*q=NULL,*p=NULL;
96 BN_MONT_CTX *mont=NULL;
97 int k,n=0,i,b,m=0;
98 int counter=0;
99 int r=0;
100 BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL;
101 unsigned int h=2;
102 DSA *ret=NULL;
103
104 if (bits < 512) bits=512;
105 bits=(bits+63)/64*64;
106
107 if (seed_len < 20)
108 seed_in = NULL; /* seed buffer too small -- ignore */
109 if (seed_len > 20)
110 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
111 * but our internal buffers are restricted to 160 bits*/
112 if ((seed_in != NULL) && (seed_len == 20))
113 memcpy(seed,seed_in,seed_len);
114
115 if ((ctx=BN_CTX_new()) == NULL) goto err;
116 if ((ctx2=BN_CTX_new()) == NULL) goto err;
117 if ((ctx3=BN_CTX_new()) == NULL) goto err;
118 if ((ret=DSA_new()) == NULL) goto err;
119
120 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
121
122 BN_CTX_start(ctx2);
123 r0 = BN_CTX_get(ctx2);
124 g = BN_CTX_get(ctx2);
125 W = BN_CTX_get(ctx2);
126 q = BN_CTX_get(ctx2);
127 X = BN_CTX_get(ctx2);
128 c = BN_CTX_get(ctx2);
129 p = BN_CTX_get(ctx2);
130 test = BN_CTX_get(ctx2);
131 if (test == NULL) goto err;
132
133 if (!BN_lshift(test,BN_value_one(),bits-1)) goto err;
134
135 for (;;)
136 {
137 for (;;) /* find q */
138 {
139 int seed_is_random;
140
141 /* step 1 */
142 if (callback != NULL) callback(0,m++,cb_arg);
143
144 if (!seed_len)
145 {
146 RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
147 seed_is_random = 1;
148 }
149 else
150 {
151 seed_is_random = 0;
152 seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
153 }
154 memcpy(buf,seed,SHA_DIGEST_LENGTH);
155 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
156 /* precompute "SEED + 1" for step 7: */
157 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
158 {
159 buf[i]++;
160 if (buf[i] != 0) break;
161 }
162
163 /* step 2 */
164 EVP_Digest(seed,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
165 EVP_Digest(buf,SHA_DIGEST_LENGTH,buf2,NULL,HASH, NULL);
166 for (i=0; i<SHA_DIGEST_LENGTH; i++)
167 md[i]^=buf2[i];
168
169 /* step 3 */
170 md[0]|=0x80;
171 md[SHA_DIGEST_LENGTH-1]|=0x01;
172 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
173
174 /* step 4 */
175 r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random);
176 if (r > 0)
177 break;
178 if (r != 0)
179 goto err;
180
181 /* do a callback call */
182 /* step 5 */
183 }
184
185 if (callback != NULL) callback(2,0,cb_arg);
186 if (callback != NULL) callback(3,0,cb_arg);
187
188 /* step 6 */
189 counter=0;
190 /* "offset = 2" */
191
192 n=(bits-1)/160;
193 b=(bits-1)-n*160;
194
195 for (;;)
196 {
197 if (callback != NULL && counter != 0)
198 callback(0,counter,cb_arg);
199
200 /* step 7 */
201 if (!BN_zero(W)) goto err;
202 /* now 'buf' contains "SEED + offset - 1" */
203 for (k=0; k<=n; k++)
204 {
205 /* obtain "SEED + offset + k" by incrementing: */
206 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
207 {
208 buf[i]++;
209 if (buf[i] != 0) break;
210 }
211
212 EVP_Digest(buf,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
213
214 /* step 8 */
215 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
216 goto err;
217 if (!BN_lshift(r0,r0,160*k)) goto err;
218 if (!BN_add(W,W,r0)) goto err;
219 }
220
221 /* more of step 8 */
222 if (!BN_mask_bits(W,bits-1)) goto err;
223 if (!BN_copy(X,W)) goto err;
224 if (!BN_add(X,X,test)) goto err;
225
226 /* step 9 */
227 if (!BN_lshift1(r0,q)) goto err;
228 if (!BN_mod(c,X,r0,ctx)) goto err;
229 if (!BN_sub(r0,c,BN_value_one())) goto err;
230 if (!BN_sub(p,X,r0)) goto err;
231
232 /* step 10 */
233 if (BN_cmp(p,test) >= 0)
234 {
235 /* step 11 */
236 r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1);
237 if (r > 0)
238 goto end; /* found it */
239 if (r != 0)
240 goto err;
241 }
242
243 /* step 13 */
244 counter++;
245 /* "offset = offset + n + 1" */
246
247 /* step 14 */
248 if (counter >= 4096) break;
249 }
250 }
251end:
252 if (callback != NULL) callback(2,1,cb_arg);
253
254 /* We now need to generate g */
255 /* Set r0=(p-1)/q */
256 if (!BN_sub(test,p,BN_value_one())) goto err;
257 if (!BN_div(r0,NULL,test,q,ctx)) goto err;
258
259 if (!BN_set_word(test,h)) goto err;
260 if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
261
262 for (;;)
263 {
264 /* g=test^r0%p */
265 if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
266 if (!BN_is_one(g)) break;
267 if (!BN_add(test,test,BN_value_one())) goto err;
268 h++;
269 }
270
271 if (callback != NULL) callback(3,1,cb_arg);
272
273 ok=1;
274err:
275 if (!ok)
276 {
277 if (ret != NULL) DSA_free(ret);
278 }
279 else
280 {
281 ret->p=BN_dup(p);
282 ret->q=BN_dup(q);
283 ret->g=BN_dup(g);
284 if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
285 {
286 ok=0;
287 goto err;
288 }
289 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
290 if (counter_ret != NULL) *counter_ret=counter;
291 if (h_ret != NULL) *h_ret=h;
292 }
293 if (ctx != NULL) BN_CTX_free(ctx);
294 if (ctx2 != NULL)
295 {
296 BN_CTX_end(ctx2);
297 BN_CTX_free(ctx2);
298 }
299 if (ctx3 != NULL) BN_CTX_free(ctx3);
300 if (mont != NULL) BN_MONT_CTX_free(mont);
301 return(ok?ret:NULL);
302 }
303#endif /* ndef OPENSSL_FIPS */
304#endif /* ndef OPENSSL_NO_SHA */
305
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
new file mode 100644
index 0000000000..30607ca579
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_key.c
@@ -0,0 +1,107 @@
1/* crypto/dsa/dsa_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SHA
60#include <stdio.h>
61#include <time.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66
67#ifndef OPENSSL_FIPS
68int DSA_generate_key(DSA *dsa)
69 {
70 int ok=0;
71 BN_CTX *ctx=NULL;
72 BIGNUM *pub_key=NULL,*priv_key=NULL;
73
74 if ((ctx=BN_CTX_new()) == NULL) goto err;
75
76 if (dsa->priv_key == NULL)
77 {
78 if ((priv_key=BN_new()) == NULL) goto err;
79 }
80 else
81 priv_key=dsa->priv_key;
82
83 do
84 if (!BN_rand_range(priv_key,dsa->q)) goto err;
85 while (BN_is_zero(priv_key));
86
87 if (dsa->pub_key == NULL)
88 {
89 if ((pub_key=BN_new()) == NULL) goto err;
90 }
91 else
92 pub_key=dsa->pub_key;
93
94 if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;
95
96 dsa->priv_key=priv_key;
97 dsa->pub_key=pub_key;
98 ok=1;
99
100err:
101 if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
102 if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
103 if (ctx != NULL) BN_CTX_free(ctx);
104 return(ok);
105 }
106#endif
107#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
new file mode 100644
index 0000000000..4171af24c6
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -0,0 +1,308 @@
1/* crypto/dsa/dsa_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/asn1.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
71
72static const DSA_METHOD *default_DSA_method = NULL;
73
74void DSA_set_default_method(const DSA_METHOD *meth)
75 {
76 default_DSA_method = meth;
77 }
78
79const DSA_METHOD *DSA_get_default_method(void)
80 {
81 if(!default_DSA_method)
82 default_DSA_method = DSA_OpenSSL();
83 return default_DSA_method;
84 }
85
86DSA *DSA_new(void)
87 {
88 return DSA_new_method(NULL);
89 }
90
91int DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
92 {
93 /* NB: The caller is specifically setting a method, so it's not up to us
94 * to deal with which ENGINE it comes from. */
95 const DSA_METHOD *mtmp;
96 mtmp = dsa->meth;
97 if (mtmp->finish) mtmp->finish(dsa);
98#ifndef OPENSSL_NO_ENGINE
99 if (dsa->engine)
100 {
101 ENGINE_finish(dsa->engine);
102 dsa->engine = NULL;
103 }
104#endif
105 dsa->meth = meth;
106 if (meth->init) meth->init(dsa);
107 return 1;
108 }
109
110DSA *DSA_new_method(ENGINE *engine)
111 {
112 DSA *ret;
113
114 ret=(DSA *)OPENSSL_malloc(sizeof(DSA));
115 if (ret == NULL)
116 {
117 DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
118 return(NULL);
119 }
120 ret->meth = DSA_get_default_method();
121#ifndef OPENSSL_NO_ENGINE
122 if (engine)
123 {
124 if (!ENGINE_init(engine))
125 {
126 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
127 OPENSSL_free(ret);
128 return NULL;
129 }
130 ret->engine = engine;
131 }
132 else
133 ret->engine = ENGINE_get_default_DSA();
134 if(ret->engine)
135 {
136 ret->meth = ENGINE_get_DSA(ret->engine);
137 if(!ret->meth)
138 {
139 DSAerr(DSA_F_DSA_NEW_METHOD,
140 ERR_R_ENGINE_LIB);
141 ENGINE_finish(ret->engine);
142 OPENSSL_free(ret);
143 return NULL;
144 }
145 }
146#endif
147
148 ret->pad=0;
149 ret->version=0;
150 ret->write_params=1;
151 ret->p=NULL;
152 ret->q=NULL;
153 ret->g=NULL;
154
155 ret->pub_key=NULL;
156 ret->priv_key=NULL;
157
158 ret->kinv=NULL;
159 ret->r=NULL;
160 ret->method_mont_p=NULL;
161
162 ret->references=1;
163 ret->flags=ret->meth->flags;
164 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
165 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
166 {
167#ifndef OPENSSL_NO_ENGINE
168 if (ret->engine)
169 ENGINE_finish(ret->engine);
170#endif
171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
172 OPENSSL_free(ret);
173 ret=NULL;
174 }
175
176 return(ret);
177 }
178
179void DSA_free(DSA *r)
180 {
181 int i;
182
183 if (r == NULL) return;
184
185 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
186#ifdef REF_PRINT
187 REF_PRINT("DSA",r);
188#endif
189 if (i > 0) return;
190#ifdef REF_CHECK
191 if (i < 0)
192 {
193 fprintf(stderr,"DSA_free, bad reference count\n");
194 abort();
195 }
196#endif
197
198 if(r->meth->finish)
199 r->meth->finish(r);
200#ifndef OPENSSL_NO_ENGINE
201 if(r->engine)
202 ENGINE_finish(r->engine);
203#endif
204
205 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
206
207 if (r->p != NULL) BN_clear_free(r->p);
208 if (r->q != NULL) BN_clear_free(r->q);
209 if (r->g != NULL) BN_clear_free(r->g);
210 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
211 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
212 if (r->kinv != NULL) BN_clear_free(r->kinv);
213 if (r->r != NULL) BN_clear_free(r->r);
214 OPENSSL_free(r);
215 }
216
217int DSA_up_ref(DSA *r)
218 {
219 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
220#ifdef REF_PRINT
221 REF_PRINT("DSA",r);
222#endif
223#ifdef REF_CHECK
224 if (i < 2)
225 {
226 fprintf(stderr, "DSA_up_ref, bad reference count\n");
227 abort();
228 }
229#endif
230 return ((i > 1) ? 1 : 0);
231 }
232
233int DSA_size(const DSA *r)
234 {
235 int ret,i;
236 ASN1_INTEGER bs;
237 unsigned char buf[4]; /* 4 bytes looks really small.
238 However, i2d_ASN1_INTEGER() will not look
239 beyond the first byte, as long as the second
240 parameter is NULL. */
241
242 i=BN_num_bits(r->q);
243 bs.length=(i+7)/8;
244 bs.data=buf;
245 bs.type=V_ASN1_INTEGER;
246 /* If the top bit is set the asn1 encoding is 1 larger. */
247 buf[0]=0xff;
248
249 i=i2d_ASN1_INTEGER(&bs,NULL);
250 i+=i; /* r and s */
251 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
252 return(ret);
253 }
254
255int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
256 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
257 {
258 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, argl, argp,
259 new_func, dup_func, free_func);
260 }
261
262int DSA_set_ex_data(DSA *d, int idx, void *arg)
263 {
264 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
265 }
266
267void *DSA_get_ex_data(DSA *d, int idx)
268 {
269 return(CRYPTO_get_ex_data(&d->ex_data,idx));
270 }
271
272#ifndef OPENSSL_NO_DH
273DH *DSA_dup_DH(const DSA *r)
274 {
275 /* DSA has p, q, g, optional pub_key, optional priv_key.
276 * DH has p, optional length, g, optional pub_key, optional priv_key.
277 */
278
279 DH *ret = NULL;
280
281 if (r == NULL)
282 goto err;
283 ret = DH_new();
284 if (ret == NULL)
285 goto err;
286 if (r->p != NULL)
287 if ((ret->p = BN_dup(r->p)) == NULL)
288 goto err;
289 if (r->q != NULL)
290 ret->length = BN_num_bits(r->q);
291 if (r->g != NULL)
292 if ((ret->g = BN_dup(r->g)) == NULL)
293 goto err;
294 if (r->pub_key != NULL)
295 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
296 goto err;
297 if (r->priv_key != NULL)
298 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
299 goto err;
300
301 return ret;
302
303 err:
304 if (ret != NULL)
305 DH_free(ret);
306 return NULL;
307 }
308#endif
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
new file mode 100644
index 0000000000..f1a85afcde
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -0,0 +1,350 @@
1/* crypto/dsa/dsa_ossl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67
68#ifndef OPENSSL_FIPS
69static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
70static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
71static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
72 DSA *dsa);
73static int dsa_init(DSA *dsa);
74static int dsa_finish(DSA *dsa);
75static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
76 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
77 BN_MONT_CTX *in_mont);
78static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
79 const BIGNUM *m, BN_CTX *ctx,
80 BN_MONT_CTX *m_ctx);
81
82static DSA_METHOD openssl_dsa_meth = {
83"OpenSSL DSA method",
84dsa_do_sign,
85dsa_sign_setup,
86dsa_do_verify,
87dsa_mod_exp,
88dsa_bn_mod_exp,
89dsa_init,
90dsa_finish,
910,
92NULL
93};
94
95const DSA_METHOD *DSA_OpenSSL(void)
96{
97 return &openssl_dsa_meth;
98}
99
100static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
101 {
102 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
103 BIGNUM m;
104 BIGNUM xr;
105 BN_CTX *ctx=NULL;
106 int i,reason=ERR_R_BN_LIB;
107 DSA_SIG *ret=NULL;
108
109 BN_init(&m);
110 BN_init(&xr);
111
112 if (!dsa->p || !dsa->q || !dsa->g)
113 {
114 reason=DSA_R_MISSING_PARAMETERS;
115 goto err;
116 }
117
118 s=BN_new();
119 if (s == NULL) goto err;
120
121 i=BN_num_bytes(dsa->q); /* should be 20 */
122 if ((dlen > i) || (dlen > 50))
123 {
124 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
125 goto err;
126 }
127
128 ctx=BN_CTX_new();
129 if (ctx == NULL) goto err;
130
131 if ((dsa->kinv == NULL) || (dsa->r == NULL))
132 {
133 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
134 }
135 else
136 {
137 kinv=dsa->kinv;
138 dsa->kinv=NULL;
139 r=dsa->r;
140 dsa->r=NULL;
141 }
142
143 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
144
145 /* Compute s = inv(k) (m + xr) mod q */
146 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
147 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
148 if (BN_cmp(s,dsa->q) > 0)
149 BN_sub(s,s,dsa->q);
150 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
151
152 ret=DSA_SIG_new();
153 if (ret == NULL) goto err;
154 ret->r = r;
155 ret->s = s;
156
157err:
158 if (!ret)
159 {
160 DSAerr(DSA_F_DSA_DO_SIGN,reason);
161 BN_free(r);
162 BN_free(s);
163 }
164 if (ctx != NULL) BN_CTX_free(ctx);
165 BN_clear_free(&m);
166 BN_clear_free(&xr);
167 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
168 BN_clear_free(kinv);
169 return(ret);
170 }
171
172static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
173 {
174 BN_CTX *ctx;
175 BIGNUM k,*kinv=NULL,*r=NULL;
176 int ret=0;
177
178 if (!dsa->p || !dsa->q || !dsa->g)
179 {
180 DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);
181 return 0;
182 }
183
184 BN_init(&k);
185
186 if (ctx_in == NULL)
187 {
188 if ((ctx=BN_CTX_new()) == NULL) goto err;
189 }
190 else
191 ctx=ctx_in;
192
193 if ((r=BN_new()) == NULL) goto err;
194 kinv=NULL;
195
196 /* Get random k */
197 do
198 if (!BN_rand_range(&k, dsa->q)) goto err;
199 while (BN_is_zero(&k));
200
201 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
202 {
203 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
204 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
205 dsa->p,ctx)) goto err;
206 }
207
208 /* Compute r = (g^k mod p) mod q */
209 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx,
210 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
211 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
212
213 /* Compute part of 's = inv(k) (m + xr) mod q' */
214 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
215
216 if (*kinvp != NULL) BN_clear_free(*kinvp);
217 *kinvp=kinv;
218 kinv=NULL;
219 if (*rp != NULL) BN_clear_free(*rp);
220 *rp=r;
221 ret=1;
222err:
223 if (!ret)
224 {
225 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
226 if (kinv != NULL) BN_clear_free(kinv);
227 if (r != NULL) BN_clear_free(r);
228 }
229 if (ctx_in == NULL) BN_CTX_free(ctx);
230 if (kinv != NULL) BN_clear_free(kinv);
231 BN_clear_free(&k);
232 return(ret);
233 }
234
235static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
236 DSA *dsa)
237 {
238 BN_CTX *ctx;
239 BIGNUM u1,u2,t1;
240 BN_MONT_CTX *mont=NULL;
241 int ret = -1;
242 if (!dsa->p || !dsa->q || !dsa->g)
243 {
244 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
245 return -1;
246 }
247
248 BN_init(&u1);
249 BN_init(&u2);
250 BN_init(&t1);
251
252 if ((ctx=BN_CTX_new()) == NULL) goto err;
253
254 if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
255 {
256 ret = 0;
257 goto err;
258 }
259 if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
260 {
261 ret = 0;
262 goto err;
263 }
264
265 /* Calculate W = inv(S) mod Q
266 * save W in u2 */
267 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
268
269 /* save M in u1 */
270 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
271
272 /* u1 = M * w mod q */
273 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
274
275 /* u2 = r * w mod q */
276 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
277
278 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
279 {
280 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
281 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
282 dsa->p,ctx)) goto err;
283 }
284 mont=(BN_MONT_CTX *)dsa->method_mont_p;
285
286#if 0
287 {
288 BIGNUM t2;
289
290 BN_init(&t2);
291 /* v = ( g^u1 * y^u2 mod p ) mod q */
292 /* let t1 = g ^ u1 mod p */
293 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
294 /* let t2 = y ^ u2 mod p */
295 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
296 /* let u1 = t1 * t2 mod p */
297 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
298 BN_free(&t2);
299 }
300 /* let u1 = u1 mod q */
301 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
302#else
303 {
304 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
305 dsa->p,ctx,mont)) goto err;
306 /* BN_copy(&u1,&t1); */
307 /* let u1 = u1 mod q */
308 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
309 }
310#endif
311 /* V is now in u1. If the signature is correct, it will be
312 * equal to R. */
313 ret=(BN_ucmp(&u1, sig->r) == 0);
314
315 err:
316 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
317 if (ctx != NULL) BN_CTX_free(ctx);
318 BN_free(&u1);
319 BN_free(&u2);
320 BN_free(&t1);
321 return(ret);
322 }
323
324static int dsa_init(DSA *dsa)
325{
326 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
327 return(1);
328}
329
330static int dsa_finish(DSA *dsa)
331{
332 if(dsa->method_mont_p)
333 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
334 return(1);
335}
336
337static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
338 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
339 BN_MONT_CTX *in_mont)
340{
341 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
342}
343
344static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
345 const BIGNUM *m, BN_CTX *ctx,
346 BN_MONT_CTX *m_ctx)
347{
348 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
349}
350#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
new file mode 100644
index 0000000000..3c9753bac3
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_sign.c
@@ -0,0 +1,104 @@
1/* crypto/dsa/dsa_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67#ifndef OPENSSL_NO_ENGINE
68#include <openssl/engine.h>
69#endif
70#include <openssl/fips.h>
71
72DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
73 {
74#ifdef OPENSSL_FIPS
75 if(FIPS_mode() && !FIPS_dsa_check(dsa))
76 return NULL;
77#endif
78 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
79 }
80
81int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
82 unsigned int *siglen, DSA *dsa)
83 {
84 DSA_SIG *s;
85 s=DSA_do_sign(dgst,dlen,dsa);
86 if (s == NULL)
87 {
88 *siglen=0;
89 return(0);
90 }
91 *siglen=i2d_DSA_SIG(s,&sig);
92 DSA_SIG_free(s);
93 return(1);
94 }
95
96int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
97 {
98#ifdef OPENSSL_FIPS
99 if(FIPS_mode() && !FIPS_dsa_check(dsa))
100 return 0;
101#endif
102 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
103 }
104
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
new file mode 100644
index 0000000000..8ef0c45025
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_vrf.c
@@ -0,0 +1,102 @@
1/* crypto/dsa/dsa_vrf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67#include <openssl/asn1_mac.h>
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71#include <openssl/fips.h>
72
73int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
74 DSA *dsa)
75 {
76#ifdef OPENSSL_FIPS
77 if(FIPS_mode() && !FIPS_dsa_check(dsa))
78 return -1;
79#endif
80 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
81 }
82
83/* data has already been hashed (probably with SHA or SHA-1). */
84/* returns
85 * 1: correct signature
86 * 0: incorrect signature
87 * -1: error
88 */
89int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
90 const unsigned char *sigbuf, int siglen, DSA *dsa)
91 {
92 DSA_SIG *s;
93 int ret=-1;
94
95 s = DSA_SIG_new();
96 if (s == NULL) return(ret);
97 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
98 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
99err:
100 DSA_SIG_free(s);
101 return(ret);
102 }
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c
index 55a3756aff..4734ce4af8 100644
--- a/src/lib/libcrypto/dsa/dsatest.c
+++ b/src/lib/libcrypto/dsa/dsatest.c
@@ -194,19 +194,10 @@ int main(int argc, char **argv)
194 BIO_printf(bio_err,"g value is wrong\n"); 194 BIO_printf(bio_err,"g value is wrong\n");
195 goto end; 195 goto end;
196 } 196 }
197
198 dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME;
199 DSA_generate_key(dsa); 197 DSA_generate_key(dsa);
200 DSA_sign(0, str1, 20, sig, &siglen, dsa); 198 DSA_sign(0, str1, 20, sig, &siglen, dsa);
201 if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) 199 if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
202 ret=1; 200 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: 201end:
211 if (!ret) 202 if (!ret)
212 ERR_print_errors(bio_err); 203 ERR_print_errors(bio_err);
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/dso.h b/src/lib/libcrypto/dso/dso.h
new file mode 100644
index 0000000000..aa721f7feb
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso.h
@@ -0,0 +1,322 @@
1/* dso.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_DSO_H
60#define HEADER_DSO_H
61
62#include <openssl/crypto.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/* These values are used as commands to DSO_ctrl() */
69#define DSO_CTRL_GET_FLAGS 1
70#define DSO_CTRL_SET_FLAGS 2
71#define DSO_CTRL_OR_FLAGS 3
72
73/* By default, DSO_load() will translate the provided filename into a form
74 * typical for the platform (more specifically the DSO_METHOD) using the
75 * dso_name_converter function of the method. Eg. win32 will transform "blah"
76 * into "blah.dll", and dlfcn will transform it into "libblah.so". The
77 * behaviour can be overriden by setting the name_converter callback in the DSO
78 * object (using DSO_set_name_converter()). This callback could even utilise
79 * the DSO_METHOD's converter too if it only wants to override behaviour for
80 * one or two possible DSO methods. However, the following flag can be set in a
81 * DSO to prevent *any* native name-translation at all - eg. if the caller has
82 * prompted the user for a path to a driver library so the filename should be
83 * interpreted as-is. */
84#define DSO_FLAG_NO_NAME_TRANSLATION 0x01
85/* An extra flag to give if only the extension should be added as
86 * translation. This is obviously only of importance on Unix and
87 * other operating systems where the translation also may prefix
88 * the name with something, like 'lib', and ignored everywhere else.
89 * This flag is also ignored if DSO_FLAG_NO_NAME_TRANSLATION is used
90 * at the same time. */
91#define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02
92
93/* The following flag controls the translation of symbol names to upper
94 * case. This is currently only being implemented for OpenVMS.
95 */
96#define DSO_FLAG_UPCASE_SYMBOL 0x10
97
98
99typedef void (*DSO_FUNC_TYPE)(void);
100
101typedef struct dso_st DSO;
102
103/* The function prototype used for method functions (or caller-provided
104 * callbacks) that transform filenames. They are passed a DSO structure pointer
105 * (or NULL if they are to be used independantly of a DSO object) and a
106 * filename to transform. They should either return NULL (if there is an error
107 * condition) or a newly allocated string containing the transformed form that
108 * the caller will need to free with OPENSSL_free() when done. */
109typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
110
111typedef struct dso_meth_st
112 {
113 const char *name;
114 /* Loads a shared library, NB: new DSO_METHODs must ensure that a
115 * successful load populates the loaded_filename field, and likewise a
116 * successful unload OPENSSL_frees and NULLs it out. */
117 int (*dso_load)(DSO *dso);
118 /* Unloads a shared library */
119 int (*dso_unload)(DSO *dso);
120 /* Binds a variable */
121 void *(*dso_bind_var)(DSO *dso, const char *symname);
122 /* Binds a function - assumes a return type of DSO_FUNC_TYPE.
123 * This should be cast to the real function prototype by the
124 * caller. Platforms that don't have compatible representations
125 * for different prototypes (this is possible within ANSI C)
126 * are highly unlikely to have shared libraries at all, let
127 * alone a DSO_METHOD implemented for them. */
128 DSO_FUNC_TYPE (*dso_bind_func)(DSO *dso, const char *symname);
129
130/* I don't think this would actually be used in any circumstances. */
131#if 0
132 /* Unbinds a variable */
133 int (*dso_unbind_var)(DSO *dso, char *symname, void *symptr);
134 /* Unbinds a function */
135 int (*dso_unbind_func)(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
136#endif
137 /* The generic (yuck) "ctrl()" function. NB: Negative return
138 * values (rather than zero) indicate errors. */
139 long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg);
140 /* The default DSO_METHOD-specific function for converting filenames to
141 * a canonical native form. */
142 DSO_NAME_CONVERTER_FUNC dso_name_converter;
143
144 /* [De]Initialisation handlers. */
145 int (*init)(DSO *dso);
146 int (*finish)(DSO *dso);
147 } DSO_METHOD;
148
149/**********************************************************************/
150/* The low-level handle type used to refer to a loaded shared library */
151
152struct dso_st
153 {
154 DSO_METHOD *meth;
155 /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS
156 * doesn't use anything but will need to cache the filename
157 * for use in the dso_bind handler. All in all, let each
158 * method control its own destiny. "Handles" and such go in
159 * a STACK. */
160 STACK *meth_data;
161 int references;
162 int flags;
163 /* For use by applications etc ... use this for your bits'n'pieces,
164 * don't touch meth_data! */
165 CRYPTO_EX_DATA ex_data;
166 /* If this callback function pointer is set to non-NULL, then it will
167 * be used on DSO_load() in place of meth->dso_name_converter. NB: This
168 * should normally set using DSO_set_name_converter(). */
169 DSO_NAME_CONVERTER_FUNC name_converter;
170 /* This is populated with (a copy of) the platform-independant
171 * filename used for this DSO. */
172 char *filename;
173 /* This is populated with (a copy of) the translated filename by which
174 * the DSO was actually loaded. It is NULL iff the DSO is not currently
175 * loaded. NB: This is here because the filename translation process
176 * may involve a callback being invoked more than once not only to
177 * convert to a platform-specific form, but also to try different
178 * filenames in the process of trying to perform a load. As such, this
179 * variable can be used to indicate (a) whether this DSO structure
180 * corresponds to a loaded library or not, and (b) the filename with
181 * which it was actually loaded. */
182 char *loaded_filename;
183 };
184
185
186DSO * DSO_new(void);
187DSO * DSO_new_method(DSO_METHOD *method);
188int DSO_free(DSO *dso);
189int DSO_flags(DSO *dso);
190int DSO_up_ref(DSO *dso);
191long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg);
192
193/* This function sets the DSO's name_converter callback. If it is non-NULL,
194 * then it will be used instead of the associated DSO_METHOD's function. If
195 * oldcb is non-NULL then it is set to the function pointer value being
196 * replaced. Return value is non-zero for success. */
197int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
198 DSO_NAME_CONVERTER_FUNC *oldcb);
199/* These functions can be used to get/set the platform-independant filename
200 * used for a DSO. NB: set will fail if the DSO is already loaded. */
201const char *DSO_get_filename(DSO *dso);
202int DSO_set_filename(DSO *dso, const char *filename);
203/* This function will invoke the DSO's name_converter callback to translate a
204 * filename, or if the callback isn't set it will instead use the DSO_METHOD's
205 * converter. If "filename" is NULL, the "filename" in the DSO itself will be
206 * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is
207 * simply duplicated. NB: This function is usually called from within a
208 * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that
209 * caller-created DSO_METHODs can do the same thing. A non-NULL return value
210 * will need to be OPENSSL_free()'d. */
211char *DSO_convert_filename(DSO *dso, const char *filename);
212/* If the DSO is currently loaded, this returns the filename that it was loaded
213 * under, otherwise it returns NULL. So it is also useful as a test as to
214 * whether the DSO is currently loaded. NB: This will not necessarily return
215 * the same value as DSO_convert_filename(dso, dso->filename), because the
216 * DSO_METHOD's load function may have tried a variety of filenames (with
217 * and/or without the aid of the converters) before settling on the one it
218 * actually loaded. */
219const char *DSO_get_loaded_filename(DSO *dso);
220
221void DSO_set_default_method(DSO_METHOD *meth);
222DSO_METHOD *DSO_get_default_method(void);
223DSO_METHOD *DSO_get_method(DSO *dso);
224DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth);
225
226/* The all-singing all-dancing load function, you normally pass NULL
227 * for the first and third parameters. Use DSO_up and DSO_free for
228 * subsequent reference count handling. Any flags passed in will be set
229 * in the constructed DSO after its init() function but before the
230 * load operation. If 'dso' is non-NULL, 'flags' is ignored. */
231DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags);
232
233/* This function binds to a variable inside a shared library. */
234void *DSO_bind_var(DSO *dso, const char *symname);
235
236/* This function binds to a function inside a shared library. */
237DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname);
238
239/* This method is the default, but will beg, borrow, or steal whatever
240 * method should be the default on any particular platform (including
241 * DSO_METH_null() if necessary). */
242DSO_METHOD *DSO_METHOD_openssl(void);
243
244/* This method is defined for all platforms - if a platform has no
245 * DSO support then this will be the only method! */
246DSO_METHOD *DSO_METHOD_null(void);
247
248/* If DSO_DLFCN is defined, the standard dlfcn.h-style functions
249 * (dlopen, dlclose, dlsym, etc) will be used and incorporated into
250 * this method. If not, this method will return NULL. */
251DSO_METHOD *DSO_METHOD_dlfcn(void);
252
253/* If DSO_DL is defined, the standard dl.h-style functions (shl_load,
254 * shl_unload, shl_findsym, etc) will be used and incorporated into
255 * this method. If not, this method will return NULL. */
256DSO_METHOD *DSO_METHOD_dl(void);
257
258/* If WIN32 is defined, use DLLs. If not, return NULL. */
259DSO_METHOD *DSO_METHOD_win32(void);
260
261/* If VMS is defined, use shared images. If not, return NULL. */
262DSO_METHOD *DSO_METHOD_vms(void);
263
264/* BEGIN ERROR CODES */
265/* The following lines are auto generated by the script mkerr.pl. Any changes
266 * made after this point may be overwritten when the script is next run.
267 */
268void ERR_load_DSO_strings(void);
269
270/* Error codes for the DSO functions. */
271
272/* Function codes. */
273#define DSO_F_DLFCN_BIND_FUNC 100
274#define DSO_F_DLFCN_BIND_VAR 101
275#define DSO_F_DLFCN_LOAD 102
276#define DSO_F_DLFCN_NAME_CONVERTER 123
277#define DSO_F_DLFCN_UNLOAD 103
278#define DSO_F_DL_BIND_FUNC 104
279#define DSO_F_DL_BIND_VAR 105
280#define DSO_F_DL_LOAD 106
281#define DSO_F_DL_NAME_CONVERTER 124
282#define DSO_F_DL_UNLOAD 107
283#define DSO_F_DSO_BIND_FUNC 108
284#define DSO_F_DSO_BIND_VAR 109
285#define DSO_F_DSO_CONVERT_FILENAME 126
286#define DSO_F_DSO_CTRL 110
287#define DSO_F_DSO_FREE 111
288#define DSO_F_DSO_GET_FILENAME 127
289#define DSO_F_DSO_GET_LOADED_FILENAME 128
290#define DSO_F_DSO_LOAD 112
291#define DSO_F_DSO_NEW_METHOD 113
292#define DSO_F_DSO_SET_FILENAME 129
293#define DSO_F_DSO_SET_NAME_CONVERTER 122
294#define DSO_F_DSO_UP_REF 114
295#define DSO_F_VMS_BIND_VAR 115
296#define DSO_F_VMS_LOAD 116
297#define DSO_F_VMS_UNLOAD 117
298#define DSO_F_WIN32_BIND_FUNC 118
299#define DSO_F_WIN32_BIND_VAR 119
300#define DSO_F_WIN32_LOAD 120
301#define DSO_F_WIN32_NAME_CONVERTER 125
302#define DSO_F_WIN32_UNLOAD 121
303
304/* Reason codes. */
305#define DSO_R_CTRL_FAILED 100
306#define DSO_R_DSO_ALREADY_LOADED 110
307#define DSO_R_FILENAME_TOO_BIG 101
308#define DSO_R_FINISH_FAILED 102
309#define DSO_R_LOAD_FAILED 103
310#define DSO_R_NAME_TRANSLATION_FAILED 109
311#define DSO_R_NO_FILENAME 111
312#define DSO_R_NULL_HANDLE 104
313#define DSO_R_SET_FILENAME_FAILED 112
314#define DSO_R_STACK_ERROR 105
315#define DSO_R_SYM_FAILURE 106
316#define DSO_R_UNLOAD_FAILED 107
317#define DSO_R_UNSUPPORTED 108
318
319#ifdef __cplusplus
320}
321#endif
322#endif
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c
index f7b4dfc0c3..79d2cb4d8c 100644
--- a/src/lib/libcrypto/dso/dso_dl.c
+++ b/src/lib/libcrypto/dso/dso_dl.c
@@ -126,8 +126,7 @@ static int dl_load(DSO *dso)
126 DSOerr(DSO_F_DL_LOAD,DSO_R_NO_FILENAME); 126 DSOerr(DSO_F_DL_LOAD,DSO_R_NO_FILENAME);
127 goto err; 127 goto err;
128 } 128 }
129 ptr = shl_load(filename, BIND_IMMEDIATE | 129 ptr = shl_load(filename, BIND_IMMEDIATE|DYNAMIC_PATH, 0L);
130 (dso->flags&DSO_FLAG_NO_NAME_TRANSLATION?0:DYNAMIC_PATH), 0L);
131 if(ptr == NULL) 130 if(ptr == NULL)
132 { 131 {
133 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED); 132 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED);
@@ -282,36 +281,4 @@ static char *dl_name_converter(DSO *dso, const char *filename)
282 return(translated); 281 return(translated);
283 } 282 }
284 283
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 */ 284#endif /* DSO_DL */
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c
new file mode 100644
index 0000000000..2e72969431
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_dlfcn.c
@@ -0,0 +1,293 @@
1/* dso_dlfcn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63#ifndef DSO_DLFCN
64DSO_METHOD *DSO_METHOD_dlfcn(void)
65 {
66 return NULL;
67 }
68#else
69
70#ifdef HAVE_DLFCN_H
71#include <dlfcn.h>
72#endif
73
74/* Part of the hack in "dlfcn_load" ... */
75#define DSO_MAX_TRANSLATED_SIZE 256
76
77static int dlfcn_load(DSO *dso);
78static int dlfcn_unload(DSO *dso);
79static void *dlfcn_bind_var(DSO *dso, const char *symname);
80static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname);
81#if 0
82static int dlfcn_unbind(DSO *dso, char *symname, void *symptr);
83static int dlfcn_init(DSO *dso);
84static int dlfcn_finish(DSO *dso);
85static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
86#endif
87static char *dlfcn_name_converter(DSO *dso, const char *filename);
88
89static DSO_METHOD dso_meth_dlfcn = {
90 "OpenSSL 'dlfcn' shared library method",
91 dlfcn_load,
92 dlfcn_unload,
93 dlfcn_bind_var,
94 dlfcn_bind_func,
95/* For now, "unbind" doesn't exist */
96#if 0
97 NULL, /* unbind_var */
98 NULL, /* unbind_func */
99#endif
100 NULL, /* ctrl */
101 dlfcn_name_converter,
102 NULL, /* init */
103 NULL /* finish */
104 };
105
106DSO_METHOD *DSO_METHOD_dlfcn(void)
107 {
108 return(&dso_meth_dlfcn);
109 }
110
111/* Prior to using the dlopen() function, we should decide on the flag
112 * we send. There's a few different ways of doing this and it's a
113 * messy venn-diagram to match up which platforms support what. So
114 * as we don't have autoconf yet, I'm implementing a hack that could
115 * be hacked further relatively easily to deal with cases as we find
116 * them. Initially this is to cope with OpenBSD. */
117#if defined(__OpenBSD__) || defined(__NetBSD__)
118# ifdef DL_LAZY
119# define DLOPEN_FLAG DL_LAZY
120# else
121# ifdef RTLD_NOW
122# define DLOPEN_FLAG RTLD_NOW
123# else
124# define DLOPEN_FLAG 0
125# endif
126# endif
127#else
128# ifdef OPENSSL_SYS_SUNOS
129# define DLOPEN_FLAG 1
130# else
131# define DLOPEN_FLAG RTLD_NOW /* Hope this works everywhere else */
132# endif
133#endif
134
135/* For this DSO_METHOD, our meth_data STACK will contain;
136 * (i) the handle (void*) returned from dlopen().
137 */
138
139static int dlfcn_load(DSO *dso)
140 {
141 void *ptr = NULL;
142 /* See applicable comments in dso_dl.c */
143 char *filename = DSO_convert_filename(dso, NULL);
144
145 if(filename == NULL)
146 {
147 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
148 goto err;
149 }
150 ptr = dlopen(filename, DLOPEN_FLAG);
151 if(ptr == NULL)
152 {
153 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED);
154 ERR_add_error_data(4, "filename(", filename, "): ", dlerror());
155 goto err;
156 }
157 if(!sk_push(dso->meth_data, (char *)ptr))
158 {
159 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR);
160 goto err;
161 }
162 /* Success */
163 dso->loaded_filename = filename;
164 return(1);
165err:
166 /* Cleanup! */
167 if(filename != NULL)
168 OPENSSL_free(filename);
169 if(ptr != NULL)
170 dlclose(ptr);
171 return(0);
172}
173
174static int dlfcn_unload(DSO *dso)
175 {
176 void *ptr;
177 if(dso == NULL)
178 {
179 DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
180 return(0);
181 }
182 if(sk_num(dso->meth_data) < 1)
183 return(1);
184 ptr = (void *)sk_pop(dso->meth_data);
185 if(ptr == NULL)
186 {
187 DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE);
188 /* Should push the value back onto the stack in
189 * case of a retry. */
190 sk_push(dso->meth_data, (char *)ptr);
191 return(0);
192 }
193 /* For now I'm not aware of any errors associated with dlclose() */
194 dlclose(ptr);
195 return(1);
196 }
197
198static void *dlfcn_bind_var(DSO *dso, const char *symname)
199 {
200 void *ptr, *sym;
201
202 if((dso == NULL) || (symname == NULL))
203 {
204 DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
205 return(NULL);
206 }
207 if(sk_num(dso->meth_data) < 1)
208 {
209 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR);
210 return(NULL);
211 }
212 ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
213 if(ptr == NULL)
214 {
215 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE);
216 return(NULL);
217 }
218 sym = dlsym(ptr, symname);
219 if(sym == NULL)
220 {
221 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE);
222 ERR_add_error_data(4, "symname(", symname, "): ", dlerror());
223 return(NULL);
224 }
225 return(sym);
226 }
227
228static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
229 {
230 void *ptr;
231 DSO_FUNC_TYPE sym;
232
233 if((dso == NULL) || (symname == NULL))
234 {
235 DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
236 return(NULL);
237 }
238 if(sk_num(dso->meth_data) < 1)
239 {
240 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR);
241 return(NULL);
242 }
243 ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
244 if(ptr == NULL)
245 {
246 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE);
247 return(NULL);
248 }
249 sym = (DSO_FUNC_TYPE)dlsym(ptr, symname);
250 if(sym == NULL)
251 {
252 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE);
253 ERR_add_error_data(4, "symname(", symname, "): ", dlerror());
254 return(NULL);
255 }
256 return(sym);
257 }
258
259static char *dlfcn_name_converter(DSO *dso, const char *filename)
260 {
261 char *translated;
262 int len, rsize, transform;
263
264 len = strlen(filename);
265 rsize = len + 1;
266 transform = (strstr(filename, "/") == NULL);
267 if(transform)
268 {
269 /* We will convert this to "%s.so" or "lib%s.so" */
270 rsize += 3; /* The length of ".so" */
271 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
272 rsize += 3; /* The length of "lib" */
273 }
274 translated = OPENSSL_malloc(rsize);
275 if(translated == NULL)
276 {
277 DSOerr(DSO_F_DLFCN_NAME_CONVERTER,
278 DSO_R_NAME_TRANSLATION_FAILED);
279 return(NULL);
280 }
281 if(transform)
282 {
283 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
284 snprintf(translated, rsize, "lib%s.so", filename);
285 else
286 snprintf(translated, rsize, "%s.so", filename);
287 }
288 else
289 snprintf(translated, rsize, "%s", filename);
290 return(translated);
291 }
292
293#endif /* DSO_DLFCN */
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c
new file mode 100644
index 0000000000..cf452de1aa
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_err.c
@@ -0,0 +1,135 @@
1/* crypto/dso/dso_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dso.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA DSO_str_functs[]=
68 {
69{ERR_PACK(0,DSO_F_DLFCN_BIND_FUNC,0), "DLFCN_BIND_FUNC"},
70{ERR_PACK(0,DSO_F_DLFCN_BIND_VAR,0), "DLFCN_BIND_VAR"},
71{ERR_PACK(0,DSO_F_DLFCN_LOAD,0), "DLFCN_LOAD"},
72{ERR_PACK(0,DSO_F_DLFCN_NAME_CONVERTER,0), "DLFCN_NAME_CONVERTER"},
73{ERR_PACK(0,DSO_F_DLFCN_UNLOAD,0), "DLFCN_UNLOAD"},
74{ERR_PACK(0,DSO_F_DL_BIND_FUNC,0), "DL_BIND_FUNC"},
75{ERR_PACK(0,DSO_F_DL_BIND_VAR,0), "DL_BIND_VAR"},
76{ERR_PACK(0,DSO_F_DL_LOAD,0), "DL_LOAD"},
77{ERR_PACK(0,DSO_F_DL_NAME_CONVERTER,0), "DL_NAME_CONVERTER"},
78{ERR_PACK(0,DSO_F_DL_UNLOAD,0), "DL_UNLOAD"},
79{ERR_PACK(0,DSO_F_DSO_BIND_FUNC,0), "DSO_bind_func"},
80{ERR_PACK(0,DSO_F_DSO_BIND_VAR,0), "DSO_bind_var"},
81{ERR_PACK(0,DSO_F_DSO_CONVERT_FILENAME,0), "DSO_convert_filename"},
82{ERR_PACK(0,DSO_F_DSO_CTRL,0), "DSO_ctrl"},
83{ERR_PACK(0,DSO_F_DSO_FREE,0), "DSO_free"},
84{ERR_PACK(0,DSO_F_DSO_GET_FILENAME,0), "DSO_get_filename"},
85{ERR_PACK(0,DSO_F_DSO_GET_LOADED_FILENAME,0), "DSO_get_loaded_filename"},
86{ERR_PACK(0,DSO_F_DSO_LOAD,0), "DSO_load"},
87{ERR_PACK(0,DSO_F_DSO_NEW_METHOD,0), "DSO_new_method"},
88{ERR_PACK(0,DSO_F_DSO_SET_FILENAME,0), "DSO_set_filename"},
89{ERR_PACK(0,DSO_F_DSO_SET_NAME_CONVERTER,0), "DSO_set_name_converter"},
90{ERR_PACK(0,DSO_F_DSO_UP_REF,0), "DSO_up_ref"},
91{ERR_PACK(0,DSO_F_VMS_BIND_VAR,0), "VMS_BIND_VAR"},
92{ERR_PACK(0,DSO_F_VMS_LOAD,0), "VMS_LOAD"},
93{ERR_PACK(0,DSO_F_VMS_UNLOAD,0), "VMS_UNLOAD"},
94{ERR_PACK(0,DSO_F_WIN32_BIND_FUNC,0), "WIN32_BIND_FUNC"},
95{ERR_PACK(0,DSO_F_WIN32_BIND_VAR,0), "WIN32_BIND_VAR"},
96{ERR_PACK(0,DSO_F_WIN32_LOAD,0), "WIN32_LOAD"},
97{ERR_PACK(0,DSO_F_WIN32_NAME_CONVERTER,0), "WIN32_NAME_CONVERTER"},
98{ERR_PACK(0,DSO_F_WIN32_UNLOAD,0), "WIN32_UNLOAD"},
99{0,NULL}
100 };
101
102static ERR_STRING_DATA DSO_str_reasons[]=
103 {
104{DSO_R_CTRL_FAILED ,"control command failed"},
105{DSO_R_DSO_ALREADY_LOADED ,"dso already loaded"},
106{DSO_R_FILENAME_TOO_BIG ,"filename too big"},
107{DSO_R_FINISH_FAILED ,"cleanup method function failed"},
108{DSO_R_LOAD_FAILED ,"could not load the shared library"},
109{DSO_R_NAME_TRANSLATION_FAILED ,"name translation failed"},
110{DSO_R_NO_FILENAME ,"no filename"},
111{DSO_R_NULL_HANDLE ,"a null shared library handle was used"},
112{DSO_R_SET_FILENAME_FAILED ,"set filename failed"},
113{DSO_R_STACK_ERROR ,"the meth_data stack is corrupt"},
114{DSO_R_SYM_FAILURE ,"could not bind to the requested symbol name"},
115{DSO_R_UNLOAD_FAILED ,"could not unload the shared library"},
116{DSO_R_UNSUPPORTED ,"functionality not supported"},
117{0,NULL}
118 };
119
120#endif
121
122void ERR_load_DSO_strings(void)
123 {
124 static int init=1;
125
126 if (init)
127 {
128 init=0;
129#ifndef OPENSSL_NO_ERR
130 ERR_load_strings(ERR_LIB_DSO,DSO_str_functs);
131 ERR_load_strings(ERR_LIB_DSO,DSO_str_reasons);
132#endif
133
134 }
135 }
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
new file mode 100644
index 0000000000..48d9fdb25e
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_lib.c
@@ -0,0 +1,439 @@
1/* dso_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63
64static DSO_METHOD *default_DSO_meth = NULL;
65
66DSO *DSO_new(void)
67 {
68 return(DSO_new_method(NULL));
69 }
70
71void DSO_set_default_method(DSO_METHOD *meth)
72 {
73 default_DSO_meth = meth;
74 }
75
76DSO_METHOD *DSO_get_default_method(void)
77 {
78 return(default_DSO_meth);
79 }
80
81DSO_METHOD *DSO_get_method(DSO *dso)
82 {
83 return(dso->meth);
84 }
85
86DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth)
87 {
88 DSO_METHOD *mtmp;
89 mtmp = dso->meth;
90 dso->meth = meth;
91 return(mtmp);
92 }
93
94DSO *DSO_new_method(DSO_METHOD *meth)
95 {
96 DSO *ret;
97
98 if(default_DSO_meth == NULL)
99 /* We default to DSO_METH_openssl() which in turn defaults
100 * to stealing the "best available" method. Will fallback
101 * to DSO_METH_null() in the worst case. */
102 default_DSO_meth = DSO_METHOD_openssl();
103 ret = (DSO *)OPENSSL_malloc(sizeof(DSO));
104 if(ret == NULL)
105 {
106 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
107 return(NULL);
108 }
109 memset(ret, 0, sizeof(DSO));
110 ret->meth_data = sk_new_null();
111 if(ret->meth_data == NULL)
112 {
113 /* sk_new doesn't generate any errors so we do */
114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
115 OPENSSL_free(ret);
116 return(NULL);
117 }
118 if(meth == NULL)
119 ret->meth = default_DSO_meth;
120 else
121 ret->meth = meth;
122 ret->references = 1;
123 if((ret->meth->init != NULL) && !ret->meth->init(ret))
124 {
125 OPENSSL_free(ret);
126 ret=NULL;
127 }
128 return(ret);
129 }
130
131int DSO_free(DSO *dso)
132 {
133 int i;
134
135 if(dso == NULL)
136 {
137 DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER);
138 return(0);
139 }
140
141 i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO);
142#ifdef REF_PRINT
143 REF_PRINT("DSO",dso);
144#endif
145 if(i > 0) return(1);
146#ifdef REF_CHECK
147 if(i < 0)
148 {
149 fprintf(stderr,"DSO_free, bad reference count\n");
150 abort();
151 }
152#endif
153
154 if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso))
155 {
156 DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED);
157 return(0);
158 }
159
160 if((dso->meth->finish != NULL) && !dso->meth->finish(dso))
161 {
162 DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED);
163 return(0);
164 }
165
166 sk_free(dso->meth_data);
167 if(dso->filename != NULL)
168 OPENSSL_free(dso->filename);
169 if(dso->loaded_filename != NULL)
170 OPENSSL_free(dso->loaded_filename);
171
172 OPENSSL_free(dso);
173 return(1);
174 }
175
176int DSO_flags(DSO *dso)
177 {
178 return((dso == NULL) ? 0 : dso->flags);
179 }
180
181
182int DSO_up_ref(DSO *dso)
183 {
184 if (dso == NULL)
185 {
186 DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
187 return(0);
188 }
189
190 CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO);
191 return(1);
192 }
193
194DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
195 {
196 DSO *ret;
197 int allocated = 0;
198
199 if(dso == NULL)
200 {
201 ret = DSO_new_method(meth);
202 if(ret == NULL)
203 {
204 DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE);
205 goto err;
206 }
207 allocated = 1;
208 /* Pass the provided flags to the new DSO object */
209 if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
210 {
211 DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
212 goto err;
213 }
214 }
215 else
216 ret = dso;
217 /* Don't load if we're currently already loaded */
218 if(ret->filename != NULL)
219 {
220 DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED);
221 goto err;
222 }
223 /* filename can only be NULL if we were passed a dso that already has
224 * one set. */
225 if(filename != NULL)
226 if(!DSO_set_filename(ret, filename))
227 {
228 DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED);
229 goto err;
230 }
231 filename = ret->filename;
232 if(filename == NULL)
233 {
234 DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME);
235 goto err;
236 }
237 if(ret->meth->dso_load == NULL)
238 {
239 DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
240 goto err;
241 }
242 if(!ret->meth->dso_load(ret))
243 {
244 DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED);
245 goto err;
246 }
247 /* Load succeeded */
248 return(ret);
249err:
250 if(allocated)
251 DSO_free(ret);
252 return(NULL);
253 }
254
255void *DSO_bind_var(DSO *dso, const char *symname)
256 {
257 void *ret = NULL;
258
259 if((dso == NULL) || (symname == NULL))
260 {
261 DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
262 return(NULL);
263 }
264 if(dso->meth->dso_bind_var == NULL)
265 {
266 DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED);
267 return(NULL);
268 }
269 if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL)
270 {
271 DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE);
272 return(NULL);
273 }
274 /* Success */
275 return(ret);
276 }
277
278DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
279 {
280 DSO_FUNC_TYPE ret = NULL;
281
282 if((dso == NULL) || (symname == NULL))
283 {
284 DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
285 return(NULL);
286 }
287 if(dso->meth->dso_bind_func == NULL)
288 {
289 DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED);
290 return(NULL);
291 }
292 if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL)
293 {
294 DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE);
295 return(NULL);
296 }
297 /* Success */
298 return(ret);
299 }
300
301/* I don't really like these *_ctrl functions very much to be perfectly
302 * honest. For one thing, I think I have to return a negative value for
303 * any error because possible DSO_ctrl() commands may return values
304 * such as "size"s that can legitimately be zero (making the standard
305 * "if(DSO_cmd(...))" form that works almost everywhere else fail at
306 * odd times. I'd prefer "output" values to be passed by reference and
307 * the return value as success/failure like usual ... but we conform
308 * when we must... :-) */
309long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
310 {
311 if(dso == NULL)
312 {
313 DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER);
314 return(-1);
315 }
316 /* We should intercept certain generic commands and only pass control
317 * to the method-specific ctrl() function if it's something we don't
318 * handle. */
319 switch(cmd)
320 {
321 case DSO_CTRL_GET_FLAGS:
322 return dso->flags;
323 case DSO_CTRL_SET_FLAGS:
324 dso->flags = (int)larg;
325 return(0);
326 case DSO_CTRL_OR_FLAGS:
327 dso->flags |= (int)larg;
328 return(0);
329 default:
330 break;
331 }
332 if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL))
333 {
334 DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED);
335 return(-1);
336 }
337 return(dso->meth->dso_ctrl(dso,cmd,larg,parg));
338 }
339
340int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
341 DSO_NAME_CONVERTER_FUNC *oldcb)
342 {
343 if(dso == NULL)
344 {
345 DSOerr(DSO_F_DSO_SET_NAME_CONVERTER,
346 ERR_R_PASSED_NULL_PARAMETER);
347 return(0);
348 }
349 if(oldcb)
350 *oldcb = dso->name_converter;
351 dso->name_converter = cb;
352 return(1);
353 }
354
355const char *DSO_get_filename(DSO *dso)
356 {
357 if(dso == NULL)
358 {
359 DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
360 return(NULL);
361 }
362 return(dso->filename);
363 }
364
365int DSO_set_filename(DSO *dso, const char *filename)
366 {
367 char *copied;
368
369 if((dso == NULL) || (filename == NULL))
370 {
371 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
372 return(0);
373 }
374 if(dso->loaded_filename)
375 {
376 DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED);
377 return(0);
378 }
379 /* We'll duplicate filename */
380 copied = OPENSSL_malloc(strlen(filename) + 1);
381 if(copied == NULL)
382 {
383 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
384 return(0);
385 }
386 BUF_strlcpy(copied, filename, strlen(filename) + 1);
387 if(dso->filename)
388 OPENSSL_free(dso->filename);
389 dso->filename = copied;
390 return(1);
391 }
392
393char *DSO_convert_filename(DSO *dso, const char *filename)
394 {
395 char *result = NULL;
396
397 if(dso == NULL)
398 {
399 DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
400 return(NULL);
401 }
402 if(filename == NULL)
403 filename = dso->filename;
404 if(filename == NULL)
405 {
406 DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME);
407 return(NULL);
408 }
409 if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
410 {
411 if(dso->name_converter != NULL)
412 result = dso->name_converter(dso, filename);
413 else if(dso->meth->dso_name_converter != NULL)
414 result = dso->meth->dso_name_converter(dso, filename);
415 }
416 if(result == NULL)
417 {
418 result = OPENSSL_malloc(strlen(filename) + 1);
419 if(result == NULL)
420 {
421 DSOerr(DSO_F_DSO_CONVERT_FILENAME,
422 ERR_R_MALLOC_FAILURE);
423 return(NULL);
424 }
425 BUF_strlcpy(result, filename, strlen(filename) + 1);
426 }
427 return(result);
428 }
429
430const char *DSO_get_loaded_filename(DSO *dso)
431 {
432 if(dso == NULL)
433 {
434 DSOerr(DSO_F_DSO_GET_LOADED_FILENAME,
435 ERR_R_PASSED_NULL_PARAMETER);
436 return(NULL);
437 }
438 return(dso->loaded_filename);
439 }
diff --git a/src/lib/libcrypto/dso/dso_null.c b/src/lib/libcrypto/dso/dso_null.c
new file mode 100644
index 0000000000..fa13a7cb0f
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_null.c
@@ -0,0 +1,86 @@
1/* dso_null.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* This "NULL" method is provided as the fallback for systems that have
60 * no appropriate support for "shared-libraries". */
61
62#include <stdio.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65
66static DSO_METHOD dso_meth_null = {
67 "NULL shared library method",
68 NULL, /* load */
69 NULL, /* unload */
70 NULL, /* bind_var */
71 NULL, /* bind_func */
72/* For now, "unbind" doesn't exist */
73#if 0
74 NULL, /* unbind_var */
75 NULL, /* unbind_func */
76#endif
77 NULL, /* ctrl */
78 NULL, /* init */
79 NULL /* finish */
80 };
81
82DSO_METHOD *DSO_METHOD_null(void)
83 {
84 return(&dso_meth_null);
85 }
86
diff --git a/src/lib/libcrypto/dso/dso_openssl.c b/src/lib/libcrypto/dso/dso_openssl.c
new file mode 100644
index 0000000000..a4395ebffe
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_openssl.c
@@ -0,0 +1,81 @@
1/* dso_openssl.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63/* We just pinch the method from an appropriate "default" method. */
64
65DSO_METHOD *DSO_METHOD_openssl(void)
66 {
67#ifdef DEF_DSO_METHOD
68 return(DEF_DSO_METHOD());
69#elif defined(DSO_DLFCN)
70 return(DSO_METHOD_dlfcn());
71#elif defined(DSO_DL)
72 return(DSO_METHOD_dl());
73#elif defined(DSO_WIN32)
74 return(DSO_METHOD_win32());
75#elif defined(DSO_VMS)
76 return(DSO_METHOD_vms());
77#else
78 return(DSO_METHOD_null());
79#endif
80 }
81
diff --git a/src/lib/libcrypto/dso/dso_win32.c b/src/lib/libcrypto/dso/dso_win32.c
index cc4ac68696..3fa90eb27c 100644
--- a/src/lib/libcrypto/dso/dso_win32.c
+++ b/src/lib/libcrypto/dso/dso_win32.c
@@ -68,25 +68,6 @@ DSO_METHOD *DSO_METHOD_win32(void)
68 } 68 }
69#else 69#else
70 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" ... */ 71/* Part of the hack in "win32_load" ... */
91#define DSO_MAX_TRANSLATED_SIZE 256 72#define DSO_MAX_TRANSLATED_SIZE 256
92 73
@@ -141,7 +122,7 @@ static int win32_load(DSO *dso)
141 DSOerr(DSO_F_WIN32_LOAD,DSO_R_NO_FILENAME); 122 DSOerr(DSO_F_WIN32_LOAD,DSO_R_NO_FILENAME);
142 goto err; 123 goto err;
143 } 124 }
144 h = LoadLibraryA(filename); 125 h = LoadLibrary(filename);
145 if(h == NULL) 126 if(h == NULL)
146 { 127 {
147 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED); 128 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED);
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
new file mode 100644
index 0000000000..6d6a9b7127
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec.h
@@ -0,0 +1,243 @@
1/* crypto/ec/ec.h */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#ifndef HEADER_EC_H
57#define HEADER_EC_H
58
59#ifdef OPENSSL_NO_EC
60#error EC is disabled.
61#endif
62
63#include <openssl/bn.h>
64#include <openssl/symhacks.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70
71typedef enum {
72 /* values as defined in X9.62 (ECDSA) and elsewhere */
73 POINT_CONVERSION_COMPRESSED = 2,
74 POINT_CONVERSION_UNCOMPRESSED = 4,
75 POINT_CONVERSION_HYBRID = 6
76} point_conversion_form_t;
77
78
79typedef struct ec_method_st EC_METHOD;
80
81typedef struct ec_group_st
82 /*
83 EC_METHOD *meth;
84 -- field definition
85 -- curve coefficients
86 -- optional generator with associated information (order, cofactor)
87 -- optional extra data (TODO: precomputed table for fast computation of multiples of generator)
88 */
89 EC_GROUP;
90
91typedef struct ec_point_st EC_POINT;
92
93
94/* EC_METHODs for curves over GF(p).
95 * EC_GFp_simple_method provides the basis for the optimized methods.
96 */
97const EC_METHOD *EC_GFp_simple_method(void);
98const EC_METHOD *EC_GFp_mont_method(void);
99#if 0
100const EC_METHOD *EC_GFp_recp_method(void); /* TODO */
101const EC_METHOD *EC_GFp_nist_method(void); /* TODO */
102#endif
103
104
105EC_GROUP *EC_GROUP_new(const EC_METHOD *);
106void EC_GROUP_free(EC_GROUP *);
107void EC_GROUP_clear_free(EC_GROUP *);
108int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
109
110const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
111
112
113/* We don't have types for field specifications and field elements in general.
114 * Otherwise we could declare
115 * int EC_GROUP_set_curve(EC_GROUP *, .....);
116 */
117int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
118int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
119
120/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp()
121 * after choosing an appropriate EC_METHOD */
122EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
123
124int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
125EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
126int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
127int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
128
129EC_POINT *EC_POINT_new(const EC_GROUP *);
130void EC_POINT_free(EC_POINT *);
131void EC_POINT_clear_free(EC_POINT *);
132int EC_POINT_copy(EC_POINT *, const EC_POINT *);
133
134const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
135
136int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
137int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
138 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
139int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
140 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
141int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
142 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
143int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
144 BIGNUM *x, BIGNUM *y, BN_CTX *);
145int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
146 const BIGNUM *x, int y_bit, BN_CTX *);
147
148size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
149 unsigned char *buf, size_t len, BN_CTX *);
150int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
151 const unsigned char *buf, size_t len, BN_CTX *);
152
153int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
154int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
155int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
156
157int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
158int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
159int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
160
161int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
162int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
163
164
165int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
166int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
167int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
168
169
170
171/* BEGIN ERROR CODES */
172/* The following lines are auto generated by the script mkerr.pl. Any changes
173 * made after this point may be overwritten when the script is next run.
174 */
175void ERR_load_EC_strings(void);
176
177/* Error codes for the EC functions. */
178
179/* Function codes. */
180#define EC_F_COMPUTE_WNAF 143
181#define EC_F_EC_GFP_MONT_FIELD_DECODE 133
182#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
183#define EC_F_EC_GFP_MONT_FIELD_MUL 131
184#define EC_F_EC_GFP_MONT_FIELD_SQR 132
185#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
186#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
187#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
188#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
189#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
190#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
191#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
192#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
193#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
194#define EC_F_EC_GROUP_COPY 106
195#define EC_F_EC_GROUP_GET0_GENERATOR 139
196#define EC_F_EC_GROUP_GET_COFACTOR 140
197#define EC_F_EC_GROUP_GET_CURVE_GFP 130
198#define EC_F_EC_GROUP_GET_ORDER 141
199#define EC_F_EC_GROUP_NEW 108
200#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
201#define EC_F_EC_GROUP_SET_CURVE_GFP 109
202#define EC_F_EC_GROUP_SET_EXTRA_DATA 110
203#define EC_F_EC_GROUP_SET_GENERATOR 111
204#define EC_F_EC_POINTS_MAKE_AFFINE 136
205#define EC_F_EC_POINTS_MUL 138
206#define EC_F_EC_POINT_ADD 112
207#define EC_F_EC_POINT_CMP 113
208#define EC_F_EC_POINT_COPY 114
209#define EC_F_EC_POINT_DBL 115
210#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
211#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
212#define EC_F_EC_POINT_IS_AT_INFINITY 118
213#define EC_F_EC_POINT_IS_ON_CURVE 119
214#define EC_F_EC_POINT_MAKE_AFFINE 120
215#define EC_F_EC_POINT_NEW 121
216#define EC_F_EC_POINT_OCT2POINT 122
217#define EC_F_EC_POINT_POINT2OCT 123
218#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
219#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
220#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
221#define EC_F_EC_POINT_SET_TO_INFINITY 127
222#define EC_F_GFP_MONT_GROUP_SET_CURVE_GFP 135
223
224/* Reason codes. */
225#define EC_R_BUFFER_TOO_SMALL 100
226#define EC_R_INCOMPATIBLE_OBJECTS 101
227#define EC_R_INVALID_ARGUMENT 112
228#define EC_R_INVALID_COMPRESSED_POINT 110
229#define EC_R_INVALID_COMPRESSION_BIT 109
230#define EC_R_INVALID_ENCODING 102
231#define EC_R_INVALID_FIELD 103
232#define EC_R_INVALID_FORM 104
233#define EC_R_NOT_INITIALIZED 111
234#define EC_R_POINT_AT_INFINITY 106
235#define EC_R_POINT_IS_NOT_ON_CURVE 107
236#define EC_R_SLOT_FULL 108
237#define EC_R_UNDEFINED_GENERATOR 113
238#define EC_R_UNKNOWN_ORDER 114
239
240#ifdef __cplusplus
241}
242#endif
243#endif
diff --git a/src/lib/libcrypto/ec/ec_cvt.c b/src/lib/libcrypto/ec/ec_cvt.c
new file mode 100644
index 0000000000..45b0ec33a0
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec_cvt.c
@@ -0,0 +1,80 @@
1/* crypto/ec/ec_cvt.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58
59EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
60 {
61 const EC_METHOD *meth;
62 EC_GROUP *ret;
63
64 /* Finally, this will use EC_GFp_nist_method if 'p' is a special
65 * prime with optimized modular arithmetics (for NIST curves)
66 */
67 meth = EC_GFp_mont_method();
68
69 ret = EC_GROUP_new(meth);
70 if (ret == NULL)
71 return NULL;
72
73 if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
74 {
75 EC_GROUP_clear_free(ret);
76 return NULL;
77 }
78
79 return ret;
80 }
diff --git a/src/lib/libcrypto/ec/ec_err.c b/src/lib/libcrypto/ec/ec_err.c
new file mode 100644
index 0000000000..d37b6aba87
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec_err.c
@@ -0,0 +1,149 @@
1/* crypto/ec/ec_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ec.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA EC_str_functs[]=
68 {
69{ERR_PACK(0,EC_F_COMPUTE_WNAF,0), "COMPUTE_WNAF"},
70{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_DECODE,0), "ec_GFp_mont_field_decode"},
71{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_ENCODE,0), "ec_GFp_mont_field_encode"},
72{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_MUL,0), "ec_GFp_mont_field_mul"},
73{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_SQR,0), "ec_GFp_mont_field_sqr"},
74{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP,0), "ec_GFp_simple_group_set_curve_GFp"},
75{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0), "ec_GFp_simple_group_set_generator"},
76{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_MAKE_AFFINE,0), "ec_GFp_simple_make_affine"},
77{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_OCT2POINT,0), "ec_GFp_simple_oct2point"},
78{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT2OCT,0), "ec_GFp_simple_point2oct"},
79{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE,0), "ec_GFp_simple_points_make_affine"},
80{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP,0), "ec_GFp_simple_point_get_affine_coordinates_GFp"},
81{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP,0), "ec_GFp_simple_point_set_affine_coordinates_GFp"},
82{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP,0), "ec_GFp_simple_set_compressed_coordinates_GFp"},
83{ERR_PACK(0,EC_F_EC_GROUP_COPY,0), "EC_GROUP_copy"},
84{ERR_PACK(0,EC_F_EC_GROUP_GET0_GENERATOR,0), "EC_GROUP_get0_generator"},
85{ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"},
86{ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"},
87{ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"},
88{ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"},
89{ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"},
90{ERR_PACK(0,EC_F_EC_GROUP_SET_CURVE_GFP,0), "EC_GROUP_set_curve_GFp"},
91{ERR_PACK(0,EC_F_EC_GROUP_SET_EXTRA_DATA,0), "EC_GROUP_set_extra_data"},
92{ERR_PACK(0,EC_F_EC_GROUP_SET_GENERATOR,0), "EC_GROUP_set_generator"},
93{ERR_PACK(0,EC_F_EC_POINTS_MAKE_AFFINE,0), "EC_POINTs_make_affine"},
94{ERR_PACK(0,EC_F_EC_POINTS_MUL,0), "EC_POINTs_mul"},
95{ERR_PACK(0,EC_F_EC_POINT_ADD,0), "EC_POINT_add"},
96{ERR_PACK(0,EC_F_EC_POINT_CMP,0), "EC_POINT_cmp"},
97{ERR_PACK(0,EC_F_EC_POINT_COPY,0), "EC_POINT_copy"},
98{ERR_PACK(0,EC_F_EC_POINT_DBL,0), "EC_POINT_dbl"},
99{ERR_PACK(0,EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP,0), "EC_POINT_get_affine_coordinates_GFp"},
100{ERR_PACK(0,EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_get_Jprojective_coordinates_GFp"},
101{ERR_PACK(0,EC_F_EC_POINT_IS_AT_INFINITY,0), "EC_POINT_is_at_infinity"},
102{ERR_PACK(0,EC_F_EC_POINT_IS_ON_CURVE,0), "EC_POINT_is_on_curve"},
103{ERR_PACK(0,EC_F_EC_POINT_MAKE_AFFINE,0), "EC_POINT_make_affine"},
104{ERR_PACK(0,EC_F_EC_POINT_NEW,0), "EC_POINT_new"},
105{ERR_PACK(0,EC_F_EC_POINT_OCT2POINT,0), "EC_POINT_oct2point"},
106{ERR_PACK(0,EC_F_EC_POINT_POINT2OCT,0), "EC_POINT_point2oct"},
107{ERR_PACK(0,EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP,0), "EC_POINT_set_affine_coordinates_GFp"},
108{ERR_PACK(0,EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP,0), "EC_POINT_set_compressed_coordinates_GFp"},
109{ERR_PACK(0,EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_set_Jprojective_coordinates_GFp"},
110{ERR_PACK(0,EC_F_EC_POINT_SET_TO_INFINITY,0), "EC_POINT_set_to_infinity"},
111{ERR_PACK(0,EC_F_GFP_MONT_GROUP_SET_CURVE_GFP,0), "GFP_MONT_GROUP_SET_CURVE_GFP"},
112{0,NULL}
113 };
114
115static ERR_STRING_DATA EC_str_reasons[]=
116 {
117{EC_R_BUFFER_TOO_SMALL ,"buffer too small"},
118{EC_R_INCOMPATIBLE_OBJECTS ,"incompatible objects"},
119{EC_R_INVALID_ARGUMENT ,"invalid argument"},
120{EC_R_INVALID_COMPRESSED_POINT ,"invalid compressed point"},
121{EC_R_INVALID_COMPRESSION_BIT ,"invalid compression bit"},
122{EC_R_INVALID_ENCODING ,"invalid encoding"},
123{EC_R_INVALID_FIELD ,"invalid field"},
124{EC_R_INVALID_FORM ,"invalid form"},
125{EC_R_NOT_INITIALIZED ,"not initialized"},
126{EC_R_POINT_AT_INFINITY ,"point at infinity"},
127{EC_R_POINT_IS_NOT_ON_CURVE ,"point is not on curve"},
128{EC_R_SLOT_FULL ,"slot full"},
129{EC_R_UNDEFINED_GENERATOR ,"undefined generator"},
130{EC_R_UNKNOWN_ORDER ,"unknown order"},
131{0,NULL}
132 };
133
134#endif
135
136void ERR_load_EC_strings(void)
137 {
138 static int init=1;
139
140 if (init)
141 {
142 init=0;
143#ifndef OPENSSL_NO_ERR
144 ERR_load_strings(ERR_LIB_EC,EC_str_functs);
145 ERR_load_strings(ERR_LIB_EC,EC_str_reasons);
146#endif
147
148 }
149 }
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h
new file mode 100644
index 0000000000..cc4cf27755
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec_lcl.h
@@ -0,0 +1,277 @@
1/* crypto/ec/ec_lcl.h */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57#include <stdlib.h>
58
59#include <openssl/ec.h>
60
61
62/* Structure details are not part of the exported interface,
63 * so all this may change in future versions. */
64
65struct ec_method_st {
66 /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */
67 int (*group_init)(EC_GROUP *);
68 void (*group_finish)(EC_GROUP *);
69 void (*group_clear_finish)(EC_GROUP *);
70 int (*group_copy)(EC_GROUP *, const EC_GROUP *);
71
72 /* used by EC_GROUP_set_curve_GFp and EC_GROUP_get_curve_GFp: */
73 int (*group_set_curve_GFp)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
74 int (*group_get_curve_GFp)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
75
76 /* used by EC_GROUP_set_generator, EC_GROUP_get0_generator,
77 * EC_GROUP_get_order, EC_GROUP_get_cofactor:
78 */
79 int (*group_set_generator)(EC_GROUP *, const EC_POINT *generator,
80 const BIGNUM *order, const BIGNUM *cofactor);
81 EC_POINT *(*group_get0_generator)(const EC_GROUP *);
82 int (*group_get_order)(const EC_GROUP *, BIGNUM *order, BN_CTX *);
83 int (*group_get_cofactor)(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
84
85 /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */
86 int (*point_init)(EC_POINT *);
87 void (*point_finish)(EC_POINT *);
88 void (*point_clear_finish)(EC_POINT *);
89 int (*point_copy)(EC_POINT *, const EC_POINT *);
90
91 /* used by EC_POINT_set_to_infinity,
92 * EC_POINT_set_Jprojective_coordinates_GFp, EC_POINT_get_Jprojective_coordinates_GFp,
93 * EC_POINT_set_affine_coordinates_GFp, EC_POINT_get_affine_coordinates_GFp,
94 * EC_POINT_set_compressed_coordinates_GFp:
95 */
96 int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *);
97 int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
98 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
99 int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
100 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
101 int (*point_set_affine_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
102 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
103 int (*point_get_affine_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
104 BIGNUM *x, BIGNUM *y, BN_CTX *);
105 int (*point_set_compressed_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
106 const BIGNUM *x, int y_bit, BN_CTX *);
107
108 /* used by EC_POINT_point2oct, EC_POINT_oct2point: */
109 size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
110 unsigned char *buf, size_t len, BN_CTX *);
111 int (*oct2point)(const EC_GROUP *, EC_POINT *,
112 const unsigned char *buf, size_t len, BN_CTX *);
113
114 /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */
115 int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
116 int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
117 int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
118
119 /* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */
120 int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *);
121 int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
122 int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
123
124 /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */
125 int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *);
126 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
127
128
129 /* internal functions */
130
131 /* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that
132 * the same implementations of point operations can be used with different
133 * optimized implementations of expensive field operations: */
134 int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
135 int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
136
137 int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
138 int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */
139 int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *);
140} /* EC_METHOD */;
141
142
143struct ec_group_st {
144 const EC_METHOD *meth;
145
146 void *extra_data;
147 void *(*extra_data_dup_func)(void *);
148 void (*extra_data_free_func)(void *);
149 void (*extra_data_clear_free_func)(void *);
150
151 /* All members except 'meth' and 'extra_data...' are handled by
152 * the method functions, even if they appear generic */
153
154 BIGNUM field; /* Field specification.
155 * For curves over GF(p), this is the modulus. */
156
157 BIGNUM a, b; /* Curve coefficients.
158 * (Here the assumption is that BIGNUMs can be used
159 * or abused for all kinds of fields, not just GF(p).)
160 * For characteristic > 3, the curve is defined
161 * by a Weierstrass equation of the form
162 * y^2 = x^3 + a*x + b.
163 */
164 int a_is_minus3; /* enable optimized point arithmetics for special case */
165
166 EC_POINT *generator; /* optional */
167 BIGNUM order, cofactor;
168
169 void *field_data1; /* method-specific (e.g., Montgomery structure) */
170 void *field_data2; /* method-specific */
171} /* EC_GROUP */;
172
173
174/* Basically a 'mixin' for extra data, but available for EC_GROUPs only
175 * (with visibility limited to 'package' level for now).
176 * We use the function pointers as index for retrieval; this obviates
177 * global ex_data-style index tables.
178 * (Currently, we have one slot only, but is is possible to extend this
179 * if necessary.) */
180int EC_GROUP_set_extra_data(EC_GROUP *, void *extra_data, void *(*extra_data_dup_func)(void *),
181 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
182void *EC_GROUP_get_extra_data(const EC_GROUP *, void *(*extra_data_dup_func)(void *),
183 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
184void EC_GROUP_free_extra_data(EC_GROUP *);
185void EC_GROUP_clear_free_extra_data(EC_GROUP *);
186
187
188
189struct ec_point_st {
190 const EC_METHOD *meth;
191
192 /* All members except 'meth' are handled by the method functions,
193 * even if they appear generic */
194
195 BIGNUM X;
196 BIGNUM Y;
197 BIGNUM Z; /* Jacobian projective coordinates:
198 * (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 */
199 int Z_is_one; /* enable optimized point arithmetics for special case */
200} /* EC_POINT */;
201
202
203
204/* method functions in ecp_smpl.c */
205int ec_GFp_simple_group_init(EC_GROUP *);
206void ec_GFp_simple_group_finish(EC_GROUP *);
207void ec_GFp_simple_group_clear_finish(EC_GROUP *);
208int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
209int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
210int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
211int ec_GFp_simple_group_set_generator(EC_GROUP *, const EC_POINT *generator,
212 const BIGNUM *order, const BIGNUM *cofactor);
213EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *);
214int ec_GFp_simple_group_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
215int ec_GFp_simple_group_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
216int ec_GFp_simple_point_init(EC_POINT *);
217void ec_GFp_simple_point_finish(EC_POINT *);
218void ec_GFp_simple_point_clear_finish(EC_POINT *);
219int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *);
220int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
221int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
222 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
223int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
224 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
225int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
226 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
227int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
228 BIGNUM *x, BIGNUM *y, BN_CTX *);
229int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
230 const BIGNUM *x, int y_bit, BN_CTX *);
231size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
232 unsigned char *buf, size_t len, BN_CTX *);
233int ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *,
234 const unsigned char *buf, size_t len, BN_CTX *);
235int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
236int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
237int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
238int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
239int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
240int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
241int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
242int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
243int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
244int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
245
246
247/* method functions in ecp_mont.c */
248int ec_GFp_mont_group_init(EC_GROUP *);
249int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
250void ec_GFp_mont_group_finish(EC_GROUP *);
251void ec_GFp_mont_group_clear_finish(EC_GROUP *);
252int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
253int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
254int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
255int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
256int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
257int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
258
259
260/* method functions in ecp_recp.c */
261int ec_GFp_recp_group_init(EC_GROUP *);
262int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
263void ec_GFp_recp_group_finish(EC_GROUP *);
264void ec_GFp_recp_group_clear_finish(EC_GROUP *);
265int ec_GFp_recp_group_copy(EC_GROUP *, const EC_GROUP *);
266int ec_GFp_recp_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
267int ec_GFp_recp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
268
269
270/* method functions in ecp_nist.c */
271int ec_GFp_nist_group_init(EC_GROUP *);
272int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
273void ec_GFp_nist_group_finish(EC_GROUP *);
274void ec_GFp_nist_group_clear_finish(EC_GROUP *);
275int ec_GFp_nist_group_copy(EC_GROUP *, const EC_GROUP *);
276int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
277int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
new file mode 100644
index 0000000000..deb522060f
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -0,0 +1,656 @@
1/* crypto/ec/ec_lib.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57
58#include <openssl/err.h>
59#include <openssl/opensslv.h>
60
61#include "ec_lcl.h"
62
63static const char EC_version[] = "EC" OPENSSL_VERSION_PTEXT;
64
65
66/* functions for EC_GROUP objects */
67
68EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
69 {
70 EC_GROUP *ret;
71
72 if (meth == NULL)
73 {
74 ECerr(EC_F_EC_GROUP_NEW, ERR_R_PASSED_NULL_PARAMETER);
75 return NULL;
76 }
77 if (meth->group_init == 0)
78 {
79 ECerr(EC_F_EC_GROUP_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
80 return NULL;
81 }
82
83 ret = OPENSSL_malloc(sizeof *ret);
84 if (ret == NULL)
85 {
86 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89
90 ret->meth = meth;
91
92 ret->extra_data = NULL;
93 ret->extra_data_dup_func = 0;
94 ret->extra_data_free_func = 0;
95 ret->extra_data_clear_free_func = 0;
96
97 if (!meth->group_init(ret))
98 {
99 OPENSSL_free(ret);
100 return NULL;
101 }
102
103 return ret;
104 }
105
106
107void EC_GROUP_free(EC_GROUP *group)
108 {
109 if (!group) return;
110
111 if (group->meth->group_finish != 0)
112 group->meth->group_finish(group);
113
114 EC_GROUP_free_extra_data(group);
115
116 OPENSSL_free(group);
117 }
118
119
120void EC_GROUP_clear_free(EC_GROUP *group)
121 {
122 if (!group) return;
123
124 if (group->meth->group_clear_finish != 0)
125 group->meth->group_clear_finish(group);
126 else if (group->meth != NULL && group->meth->group_finish != 0)
127 group->meth->group_finish(group);
128
129 EC_GROUP_clear_free_extra_data(group);
130
131 OPENSSL_cleanse(group, sizeof *group);
132 OPENSSL_free(group);
133 }
134
135
136int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
137 {
138 if (dest->meth->group_copy == 0)
139 {
140 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
141 return 0;
142 }
143 if (dest->meth != src->meth)
144 {
145 ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);
146 return 0;
147 }
148 if (dest == src)
149 return 1;
150
151 EC_GROUP_clear_free_extra_data(dest);
152 if (src->extra_data_dup_func)
153 {
154 if (src->extra_data != NULL)
155 {
156 dest->extra_data = src->extra_data_dup_func(src->extra_data);
157 if (dest->extra_data == NULL)
158 return 0;
159 }
160
161 dest->extra_data_dup_func = src->extra_data_dup_func;
162 dest->extra_data_free_func = src->extra_data_free_func;
163 dest->extra_data_clear_free_func = src->extra_data_clear_free_func;
164 }
165
166 return dest->meth->group_copy(dest, src);
167 }
168
169
170const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
171 {
172 return group->meth;
173 }
174
175
176int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
177 {
178 if (group->meth->group_set_curve_GFp == 0)
179 {
180 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
181 return 0;
182 }
183 return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
184 }
185
186
187int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
188 {
189 if (group->meth->group_get_curve_GFp == 0)
190 {
191 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
192 return 0;
193 }
194 return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
195 }
196
197
198int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
199 {
200 if (group->meth->group_set_generator == 0)
201 {
202 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
203 return 0;
204 }
205 return group->meth->group_set_generator(group, generator, order, cofactor);
206 }
207
208
209EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
210 {
211 if (group->meth->group_get0_generator == 0)
212 {
213 ECerr(EC_F_EC_GROUP_GET0_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
214 return 0;
215 }
216 return group->meth->group_get0_generator(group);
217 }
218
219
220int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
221 {
222 if (group->meth->group_get_order == 0)
223 {
224 ECerr(EC_F_EC_GROUP_GET_ORDER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
225 return 0;
226 }
227 return group->meth->group_get_order(group, order, ctx);
228 }
229
230
231int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
232 {
233 if (group->meth->group_get_cofactor == 0)
234 {
235 ECerr(EC_F_EC_GROUP_GET_COFACTOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
236 return 0;
237 }
238 return group->meth->group_get_cofactor(group, cofactor, ctx);
239 }
240
241
242/* this has 'package' visibility */
243int EC_GROUP_set_extra_data(EC_GROUP *group, void *extra_data, void *(*extra_data_dup_func)(void *),
244 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
245 {
246 if ((group->extra_data != NULL)
247 || (group->extra_data_dup_func != 0)
248 || (group->extra_data_free_func != 0)
249 || (group->extra_data_clear_free_func != 0))
250 {
251 ECerr(EC_F_EC_GROUP_SET_EXTRA_DATA, EC_R_SLOT_FULL);
252 return 0;
253 }
254
255 group->extra_data = extra_data;
256 group->extra_data_dup_func = extra_data_dup_func;
257 group->extra_data_free_func = extra_data_free_func;
258 group->extra_data_clear_free_func = extra_data_clear_free_func;
259 return 1;
260 }
261
262
263/* this has 'package' visibility */
264void *EC_GROUP_get_extra_data(const EC_GROUP *group, void *(*extra_data_dup_func)(void *),
265 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
266 {
267 if ((group->extra_data_dup_func != extra_data_dup_func)
268 || (group->extra_data_free_func != extra_data_free_func)
269 || (group->extra_data_clear_free_func != extra_data_clear_free_func))
270 {
271#if 0 /* this was an error in 0.9.7, but that does not make a lot of sense */
272 ECerr(..._F_EC_GROUP_GET_EXTRA_DATA, ..._R_NO_SUCH_EXTRA_DATA);
273#endif
274 return NULL;
275 }
276
277 return group->extra_data;
278 }
279
280
281/* this has 'package' visibility */
282void EC_GROUP_free_extra_data(EC_GROUP *group)
283 {
284 if (group->extra_data_free_func)
285 group->extra_data_free_func(group->extra_data);
286 group->extra_data = NULL;
287 group->extra_data_dup_func = 0;
288 group->extra_data_free_func = 0;
289 group->extra_data_clear_free_func = 0;
290 }
291
292
293/* this has 'package' visibility */
294void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
295 {
296 if (group->extra_data_clear_free_func)
297 group->extra_data_clear_free_func(group->extra_data);
298 else if (group->extra_data_free_func)
299 group->extra_data_free_func(group->extra_data);
300 group->extra_data = NULL;
301 group->extra_data_dup_func = 0;
302 group->extra_data_free_func = 0;
303 group->extra_data_clear_free_func = 0;
304 }
305
306
307
308/* functions for EC_POINT objects */
309
310EC_POINT *EC_POINT_new(const EC_GROUP *group)
311 {
312 EC_POINT *ret;
313
314 if (group == NULL)
315 {
316 ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);
317 return NULL;
318 }
319 if (group->meth->point_init == 0)
320 {
321 ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
322 return NULL;
323 }
324
325 ret = OPENSSL_malloc(sizeof *ret);
326 if (ret == NULL)
327 {
328 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);
329 return NULL;
330 }
331
332 ret->meth = group->meth;
333
334 if (!ret->meth->point_init(ret))
335 {
336 OPENSSL_free(ret);
337 return NULL;
338 }
339
340 return ret;
341 }
342
343
344void EC_POINT_free(EC_POINT *point)
345 {
346 if (!point) return;
347
348 if (point->meth->point_finish != 0)
349 point->meth->point_finish(point);
350 OPENSSL_free(point);
351 }
352
353
354void EC_POINT_clear_free(EC_POINT *point)
355 {
356 if (!point) return;
357
358 if (point->meth->point_clear_finish != 0)
359 point->meth->point_clear_finish(point);
360 else if (point->meth != NULL && point->meth->point_finish != 0)
361 point->meth->point_finish(point);
362 OPENSSL_cleanse(point, sizeof *point);
363 OPENSSL_free(point);
364 }
365
366
367int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
368 {
369 if (dest->meth->point_copy == 0)
370 {
371 ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
372 return 0;
373 }
374 if (dest->meth != src->meth)
375 {
376 ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS);
377 return 0;
378 }
379 if (dest == src)
380 return 1;
381 return dest->meth->point_copy(dest, src);
382 }
383
384
385const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
386 {
387 return point->meth;
388 }
389
390
391int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
392 {
393 if (group->meth->point_set_to_infinity == 0)
394 {
395 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
396 return 0;
397 }
398 if (group->meth != point->meth)
399 {
400 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
401 return 0;
402 }
403 return group->meth->point_set_to_infinity(group, point);
404 }
405
406
407int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
408 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
409 {
410 if (group->meth->point_set_Jprojective_coordinates_GFp == 0)
411 {
412 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
413 return 0;
414 }
415 if (group->meth != point->meth)
416 {
417 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
418 return 0;
419 }
420 return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
421 }
422
423
424int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
425 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
426 {
427 if (group->meth->point_get_Jprojective_coordinates_GFp == 0)
428 {
429 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
430 return 0;
431 }
432 if (group->meth != point->meth)
433 {
434 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
435 return 0;
436 }
437 return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
438 }
439
440
441int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
442 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
443 {
444 if (group->meth->point_set_affine_coordinates_GFp == 0)
445 {
446 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
447 return 0;
448 }
449 if (group->meth != point->meth)
450 {
451 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
452 return 0;
453 }
454 return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
455 }
456
457
458int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
459 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
460 {
461 if (group->meth->point_get_affine_coordinates_GFp == 0)
462 {
463 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
464 return 0;
465 }
466 if (group->meth != point->meth)
467 {
468 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
469 return 0;
470 }
471 return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
472 }
473
474
475int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
476 const BIGNUM *x, int y_bit, BN_CTX *ctx)
477 {
478 if (group->meth->point_set_compressed_coordinates_GFp == 0)
479 {
480 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
481 return 0;
482 }
483 if (group->meth != point->meth)
484 {
485 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
486 return 0;
487 }
488 return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
489 }
490
491
492size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
493 unsigned char *buf, size_t len, BN_CTX *ctx)
494 {
495 if (group->meth->point2oct == 0)
496 {
497 ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
498 return 0;
499 }
500 if (group->meth != point->meth)
501 {
502 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS);
503 return 0;
504 }
505 return group->meth->point2oct(group, point, form, buf, len, ctx);
506 }
507
508
509int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
510 const unsigned char *buf, size_t len, BN_CTX *ctx)
511 {
512 if (group->meth->oct2point == 0)
513 {
514 ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
515 return 0;
516 }
517 if (group->meth != point->meth)
518 {
519 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS);
520 return 0;
521 }
522 return group->meth->oct2point(group, point, buf, len, ctx);
523 }
524
525
526int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
527 {
528 if (group->meth->add == 0)
529 {
530 ECerr(EC_F_EC_POINT_ADD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
531 return 0;
532 }
533 if ((group->meth != r->meth) || (r->meth != a->meth) || (a->meth != b->meth))
534 {
535 ECerr(EC_F_EC_POINT_ADD, EC_R_INCOMPATIBLE_OBJECTS);
536 return 0;
537 }
538 return group->meth->add(group, r, a, b, ctx);
539 }
540
541
542int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
543 {
544 if (group->meth->dbl == 0)
545 {
546 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
547 return 0;
548 }
549 if ((group->meth != r->meth) || (r->meth != a->meth))
550 {
551 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
552 return 0;
553 }
554 return group->meth->dbl(group, r, a, ctx);
555 }
556
557
558int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
559 {
560 if (group->meth->dbl == 0)
561 {
562 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
563 return 0;
564 }
565 if (group->meth != a->meth)
566 {
567 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
568 return 0;
569 }
570 return group->meth->invert(group, a, ctx);
571 }
572
573
574int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
575 {
576 if (group->meth->is_at_infinity == 0)
577 {
578 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
579 return 0;
580 }
581 if (group->meth != point->meth)
582 {
583 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
584 return 0;
585 }
586 return group->meth->is_at_infinity(group, point);
587 }
588
589
590int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
591 {
592 if (group->meth->is_on_curve == 0)
593 {
594 ECerr(EC_F_EC_POINT_IS_ON_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
595 return 0;
596 }
597 if (group->meth != point->meth)
598 {
599 ECerr(EC_F_EC_POINT_IS_ON_CURVE, EC_R_INCOMPATIBLE_OBJECTS);
600 return 0;
601 }
602 return group->meth->is_on_curve(group, point, ctx);
603 }
604
605
606int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
607 {
608 if (group->meth->point_cmp == 0)
609 {
610 ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
611 return 0;
612 }
613 if ((group->meth != a->meth) || (a->meth != b->meth))
614 {
615 ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS);
616 return 0;
617 }
618 return group->meth->point_cmp(group, a, b, ctx);
619 }
620
621
622int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
623 {
624 if (group->meth->make_affine == 0)
625 {
626 ECerr(EC_F_EC_POINT_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
627 return 0;
628 }
629 if (group->meth != point->meth)
630 {
631 ECerr(EC_F_EC_POINT_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
632 return 0;
633 }
634 return group->meth->make_affine(group, point, ctx);
635 }
636
637
638int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
639 {
640 size_t i;
641
642 if (group->meth->points_make_affine == 0)
643 {
644 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
645 return 0;
646 }
647 for (i = 0; i < num; i++)
648 {
649 if (group->meth != points[i]->meth)
650 {
651 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
652 return 0;
653 }
654 }
655 return group->meth->points_make_affine(group, num, points, ctx);
656 }
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
new file mode 100644
index 0000000000..16822a73cf
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -0,0 +1,485 @@
1/* crypto/ec/ec_mult.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/err.h>
57
58#include "ec_lcl.h"
59
60
61/* TODO: optional precomputation of multiples of the generator */
62
63
64
65/*
66 * wNAF-based interleaving multi-exponentation method
67 * (<URL:http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html#multiexp>)
68 */
69
70
71/* Determine the width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
72 * This is an array r[] of values that are either zero or odd with an
73 * absolute value less than 2^w satisfying
74 * scalar = \sum_j r[j]*2^j
75 * where at most one of any w+1 consecutive digits is non-zero.
76 */
77static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len, BN_CTX *ctx)
78 {
79 BIGNUM *c;
80 int ok = 0;
81 signed char *r = NULL;
82 int sign = 1;
83 int bit, next_bit, mask;
84 size_t len = 0, j;
85
86 BN_CTX_start(ctx);
87 c = BN_CTX_get(ctx);
88 if (c == NULL) goto err;
89
90 if (w <= 0 || w > 7) /* 'signed char' can represent integers with absolute values less than 2^7 */
91 {
92 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
93 goto err;
94 }
95 bit = 1 << w; /* at most 128 */
96 next_bit = bit << 1; /* at most 256 */
97 mask = next_bit - 1; /* at most 255 */
98
99 if (!BN_copy(c, scalar)) goto err;
100 if (c->neg)
101 {
102 sign = -1;
103 c->neg = 0;
104 }
105
106 len = BN_num_bits(c) + 1; /* wNAF may be one digit longer than binary representation */
107 r = OPENSSL_malloc(len);
108 if (r == NULL) goto err;
109
110 j = 0;
111 while (!BN_is_zero(c))
112 {
113 int u = 0;
114
115 if (BN_is_odd(c))
116 {
117 if (c->d == NULL || c->top == 0)
118 {
119 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
120 goto err;
121 }
122 u = c->d[0] & mask;
123 if (u & bit)
124 {
125 u -= next_bit;
126 /* u < 0 */
127 if (!BN_add_word(c, -u)) goto err;
128 }
129 else
130 {
131 /* u > 0 */
132 if (!BN_sub_word(c, u)) goto err;
133 }
134
135 if (u <= -bit || u >= bit || !(u & 1) || c->neg)
136 {
137 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
138 goto err;
139 }
140 }
141
142 r[j++] = sign * u;
143
144 if (BN_is_odd(c))
145 {
146 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
147 goto err;
148 }
149 if (!BN_rshift1(c, c)) goto err;
150 }
151
152 if (j > len)
153 {
154 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
155 goto err;
156 }
157 len = j;
158 ok = 1;
159
160 err:
161 BN_CTX_end(ctx);
162 if (!ok)
163 {
164 OPENSSL_free(r);
165 r = NULL;
166 }
167 if (ok)
168 *ret_len = len;
169 return r;
170 }
171
172
173/* TODO: table should be optimised for the wNAF-based implementation,
174 * sometimes smaller windows will give better performance
175 * (thus the boundaries should be increased)
176 */
177#define EC_window_bits_for_scalar_size(b) \
178 ((size_t) \
179 ((b) >= 2000 ? 6 : \
180 (b) >= 800 ? 5 : \
181 (b) >= 300 ? 4 : \
182 (b) >= 70 ? 3 : \
183 (b) >= 20 ? 2 : \
184 1))
185
186/* Compute
187 * \sum scalars[i]*points[i],
188 * also including
189 * scalar*generator
190 * in the addition if scalar != NULL
191 */
192int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
193 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
194 {
195 BN_CTX *new_ctx = NULL;
196 EC_POINT *generator = NULL;
197 EC_POINT *tmp = NULL;
198 size_t totalnum;
199 size_t i, j;
200 int k;
201 int r_is_inverted = 0;
202 int r_is_at_infinity = 1;
203 size_t *wsize = NULL; /* individual window sizes */
204 signed char **wNAF = NULL; /* individual wNAFs */
205 size_t *wNAF_len = NULL;
206 size_t max_len = 0;
207 size_t num_val;
208 EC_POINT **val = NULL; /* precomputation */
209 EC_POINT **v;
210 EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' */
211 int ret = 0;
212
213 if (group->meth != r->meth)
214 {
215 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
216 return 0;
217 }
218
219 if ((scalar == NULL) && (num == 0))
220 {
221 return EC_POINT_set_to_infinity(group, r);
222 }
223
224 if (scalar != NULL)
225 {
226 generator = EC_GROUP_get0_generator(group);
227 if (generator == NULL)
228 {
229 ECerr(EC_F_EC_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);
230 return 0;
231 }
232 }
233
234 for (i = 0; i < num; i++)
235 {
236 if (group->meth != points[i]->meth)
237 {
238 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
239 return 0;
240 }
241 }
242
243 totalnum = num + (scalar != NULL);
244
245 wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);
246 wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);
247 wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);
248 if (wNAF != NULL)
249 {
250 wNAF[0] = NULL; /* preliminary pivot */
251 }
252 if (wsize == NULL || wNAF_len == NULL || wNAF == NULL) goto err;
253
254 /* num_val := total number of points to precompute */
255 num_val = 0;
256 for (i = 0; i < totalnum; i++)
257 {
258 size_t bits;
259
260 bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);
261 wsize[i] = EC_window_bits_for_scalar_size(bits);
262 num_val += 1u << (wsize[i] - 1);
263 }
264
265 /* all precomputed points go into a single array 'val',
266 * 'val_sub[i]' is a pointer to the subarray for the i-th point */
267 val = OPENSSL_malloc((num_val + 1) * sizeof val[0]);
268 if (val == NULL) goto err;
269 val[num_val] = NULL; /* pivot element */
270
271 val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);
272 if (val_sub == NULL) goto err;
273
274 /* allocate points for precomputation */
275 v = val;
276 for (i = 0; i < totalnum; i++)
277 {
278 val_sub[i] = v;
279 for (j = 0; j < (1u << (wsize[i] - 1)); j++)
280 {
281 *v = EC_POINT_new(group);
282 if (*v == NULL) goto err;
283 v++;
284 }
285 }
286 if (!(v == val + num_val))
287 {
288 ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);
289 goto err;
290 }
291
292 if (ctx == NULL)
293 {
294 ctx = new_ctx = BN_CTX_new();
295 if (ctx == NULL)
296 goto err;
297 }
298
299 tmp = EC_POINT_new(group);
300 if (tmp == NULL) goto err;
301
302 /* prepare precomputed values:
303 * val_sub[i][0] := points[i]
304 * val_sub[i][1] := 3 * points[i]
305 * val_sub[i][2] := 5 * points[i]
306 * ...
307 */
308 for (i = 0; i < totalnum; i++)
309 {
310 if (i < num)
311 {
312 if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err;
313 }
314 else
315 {
316 if (!EC_POINT_copy(val_sub[i][0], generator)) goto err;
317 }
318
319 if (wsize[i] > 1)
320 {
321 if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err;
322 for (j = 1; j < (1u << (wsize[i] - 1)); j++)
323 {
324 if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;
325 }
326 }
327
328 wNAF[i + 1] = NULL; /* make sure we always have a pivot */
329 wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i], ctx);
330 if (wNAF[i] == NULL) goto err;
331 if (wNAF_len[i] > max_len)
332 max_len = wNAF_len[i];
333 }
334
335#if 1 /* optional; EC_window_bits_for_scalar_size assumes we do this step */
336 if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err;
337#endif
338
339 r_is_at_infinity = 1;
340
341 for (k = max_len - 1; k >= 0; k--)
342 {
343 if (!r_is_at_infinity)
344 {
345 if (!EC_POINT_dbl(group, r, r, ctx)) goto err;
346 }
347
348 for (i = 0; i < totalnum; i++)
349 {
350 if (wNAF_len[i] > (size_t)k)
351 {
352 int digit = wNAF[i][k];
353 int is_neg;
354
355 if (digit)
356 {
357 is_neg = digit < 0;
358
359 if (is_neg)
360 digit = -digit;
361
362 if (is_neg != r_is_inverted)
363 {
364 if (!r_is_at_infinity)
365 {
366 if (!EC_POINT_invert(group, r, ctx)) goto err;
367 }
368 r_is_inverted = !r_is_inverted;
369 }
370
371 /* digit > 0 */
372
373 if (r_is_at_infinity)
374 {
375 if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err;
376 r_is_at_infinity = 0;
377 }
378 else
379 {
380 if (!EC_POINT_add(group, r, r, val_sub[i][digit >> 1], ctx)) goto err;
381 }
382 }
383 }
384 }
385 }
386
387 if (r_is_at_infinity)
388 {
389 if (!EC_POINT_set_to_infinity(group, r)) goto err;
390 }
391 else
392 {
393 if (r_is_inverted)
394 if (!EC_POINT_invert(group, r, ctx)) goto err;
395 }
396
397 ret = 1;
398
399 err:
400 if (new_ctx != NULL)
401 BN_CTX_free(new_ctx);
402 if (tmp != NULL)
403 EC_POINT_free(tmp);
404 if (wsize != NULL)
405 OPENSSL_free(wsize);
406 if (wNAF_len != NULL)
407 OPENSSL_free(wNAF_len);
408 if (wNAF != NULL)
409 {
410 signed char **w;
411
412 for (w = wNAF; *w != NULL; w++)
413 OPENSSL_free(*w);
414
415 OPENSSL_free(wNAF);
416 }
417 if (val != NULL)
418 {
419 for (v = val; *v != NULL; v++)
420 EC_POINT_clear_free(*v);
421
422 OPENSSL_free(val);
423 }
424 if (val_sub != NULL)
425 {
426 OPENSSL_free(val_sub);
427 }
428 return ret;
429 }
430
431
432int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
433 {
434 const EC_POINT *points[1];
435 const BIGNUM *scalars[1];
436
437 points[0] = point;
438 scalars[0] = p_scalar;
439
440 return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
441 }
442
443
444int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
445 {
446 const EC_POINT *generator;
447 BN_CTX *new_ctx = NULL;
448 BIGNUM *order;
449 int ret = 0;
450
451 generator = EC_GROUP_get0_generator(group);
452 if (generator == NULL)
453 {
454 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
455 return 0;
456 }
457
458 if (ctx == NULL)
459 {
460 ctx = new_ctx = BN_CTX_new();
461 if (ctx == NULL)
462 return 0;
463 }
464
465 BN_CTX_start(ctx);
466 order = BN_CTX_get(ctx);
467 if (order == NULL) goto err;
468
469 if (!EC_GROUP_get_order(group, order, ctx)) return 0;
470 if (BN_is_zero(order))
471 {
472 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
473 goto err;
474 }
475
476 /* TODO */
477
478 ret = 1;
479
480 err:
481 BN_CTX_end(ctx);
482 if (new_ctx != NULL)
483 BN_CTX_free(new_ctx);
484 return ret;
485 }
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
new file mode 100644
index 0000000000..7b30d4c38a
--- /dev/null
+++ b/src/lib/libcrypto/ec/ecp_mont.c
@@ -0,0 +1,304 @@
1/* crypto/ec/ecp_mont.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/err.h>
57
58#include "ec_lcl.h"
59
60
61const EC_METHOD *EC_GFp_mont_method(void)
62 {
63 static const EC_METHOD ret = {
64 ec_GFp_mont_group_init,
65 ec_GFp_mont_group_finish,
66 ec_GFp_mont_group_clear_finish,
67 ec_GFp_mont_group_copy,
68 ec_GFp_mont_group_set_curve_GFp,
69 ec_GFp_simple_group_get_curve_GFp,
70 ec_GFp_simple_group_set_generator,
71 ec_GFp_simple_group_get0_generator,
72 ec_GFp_simple_group_get_order,
73 ec_GFp_simple_group_get_cofactor,
74 ec_GFp_simple_point_init,
75 ec_GFp_simple_point_finish,
76 ec_GFp_simple_point_clear_finish,
77 ec_GFp_simple_point_copy,
78 ec_GFp_simple_point_set_to_infinity,
79 ec_GFp_simple_set_Jprojective_coordinates_GFp,
80 ec_GFp_simple_get_Jprojective_coordinates_GFp,
81 ec_GFp_simple_point_set_affine_coordinates_GFp,
82 ec_GFp_simple_point_get_affine_coordinates_GFp,
83 ec_GFp_simple_set_compressed_coordinates_GFp,
84 ec_GFp_simple_point2oct,
85 ec_GFp_simple_oct2point,
86 ec_GFp_simple_add,
87 ec_GFp_simple_dbl,
88 ec_GFp_simple_invert,
89 ec_GFp_simple_is_at_infinity,
90 ec_GFp_simple_is_on_curve,
91 ec_GFp_simple_cmp,
92 ec_GFp_simple_make_affine,
93 ec_GFp_simple_points_make_affine,
94 ec_GFp_mont_field_mul,
95 ec_GFp_mont_field_sqr,
96 ec_GFp_mont_field_encode,
97 ec_GFp_mont_field_decode,
98 ec_GFp_mont_field_set_to_one };
99
100 return &ret;
101 }
102
103
104int ec_GFp_mont_group_init(EC_GROUP *group)
105 {
106 int ok;
107
108 ok = ec_GFp_simple_group_init(group);
109 group->field_data1 = NULL;
110 group->field_data2 = NULL;
111 return ok;
112 }
113
114
115int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
116 {
117 BN_CTX *new_ctx = NULL;
118 BN_MONT_CTX *mont = NULL;
119 BIGNUM *one = NULL;
120 int ret = 0;
121
122 if (group->field_data1 != NULL)
123 {
124 BN_MONT_CTX_free(group->field_data1);
125 group->field_data1 = NULL;
126 }
127 if (group->field_data2 != NULL)
128 {
129 BN_free(group->field_data2);
130 group->field_data2 = NULL;
131 }
132
133 if (ctx == NULL)
134 {
135 ctx = new_ctx = BN_CTX_new();
136 if (ctx == NULL)
137 return 0;
138 }
139
140 mont = BN_MONT_CTX_new();
141 if (mont == NULL) goto err;
142 if (!BN_MONT_CTX_set(mont, p, ctx))
143 {
144 ECerr(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP, ERR_R_BN_LIB);
145 goto err;
146 }
147 one = BN_new();
148 if (one == NULL) goto err;
149 if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) goto err;
150
151 group->field_data1 = mont;
152 mont = NULL;
153 group->field_data2 = one;
154 one = NULL;
155
156 ret = ec_GFp_simple_group_set_curve_GFp(group, p, a, b, ctx);
157
158 if (!ret)
159 {
160 BN_MONT_CTX_free(group->field_data1);
161 group->field_data1 = NULL;
162 BN_free(group->field_data2);
163 group->field_data2 = NULL;
164 }
165
166 err:
167 if (new_ctx != NULL)
168 BN_CTX_free(new_ctx);
169 if (mont != NULL)
170 BN_MONT_CTX_free(mont);
171 return ret;
172 }
173
174
175void ec_GFp_mont_group_finish(EC_GROUP *group)
176 {
177 if (group->field_data1 != NULL)
178 {
179 BN_MONT_CTX_free(group->field_data1);
180 group->field_data1 = NULL;
181 }
182 if (group->field_data2 != NULL)
183 {
184 BN_free(group->field_data2);
185 group->field_data2 = NULL;
186 }
187 ec_GFp_simple_group_finish(group);
188 }
189
190
191void ec_GFp_mont_group_clear_finish(EC_GROUP *group)
192 {
193 if (group->field_data1 != NULL)
194 {
195 BN_MONT_CTX_free(group->field_data1);
196 group->field_data1 = NULL;
197 }
198 if (group->field_data2 != NULL)
199 {
200 BN_clear_free(group->field_data2);
201 group->field_data2 = NULL;
202 }
203 ec_GFp_simple_group_clear_finish(group);
204 }
205
206
207int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
208 {
209 if (dest->field_data1 != NULL)
210 {
211 BN_MONT_CTX_free(dest->field_data1);
212 dest->field_data1 = NULL;
213 }
214 if (dest->field_data2 != NULL)
215 {
216 BN_clear_free(dest->field_data2);
217 dest->field_data2 = NULL;
218 }
219
220 if (!ec_GFp_simple_group_copy(dest, src)) return 0;
221
222 if (src->field_data1 != NULL)
223 {
224 dest->field_data1 = BN_MONT_CTX_new();
225 if (dest->field_data1 == NULL) return 0;
226 if (!BN_MONT_CTX_copy(dest->field_data1, src->field_data1)) goto err;
227 }
228 if (src->field_data2 != NULL)
229 {
230 dest->field_data2 = BN_dup(src->field_data2);
231 if (dest->field_data2 == NULL) goto err;
232 }
233
234 return 1;
235
236 err:
237 if (dest->field_data1 != NULL)
238 {
239 BN_MONT_CTX_free(dest->field_data1);
240 dest->field_data1 = NULL;
241 }
242 return 0;
243 }
244
245
246int ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
247 {
248 if (group->field_data1 == NULL)
249 {
250 ECerr(EC_F_EC_GFP_MONT_FIELD_MUL, EC_R_NOT_INITIALIZED);
251 return 0;
252 }
253
254 return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx);
255 }
256
257
258int ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
259 {
260 if (group->field_data1 == NULL)
261 {
262 ECerr(EC_F_EC_GFP_MONT_FIELD_SQR, EC_R_NOT_INITIALIZED);
263 return 0;
264 }
265
266 return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx);
267 }
268
269
270int ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
271 {
272 if (group->field_data1 == NULL)
273 {
274 ECerr(EC_F_EC_GFP_MONT_FIELD_ENCODE, EC_R_NOT_INITIALIZED);
275 return 0;
276 }
277
278 return BN_to_montgomery(r, a, (BN_MONT_CTX *)group->field_data1, ctx);
279 }
280
281
282int ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
283 {
284 if (group->field_data1 == NULL)
285 {
286 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
287 return 0;
288 }
289
290 return BN_from_montgomery(r, a, group->field_data1, ctx);
291 }
292
293
294int ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx)
295 {
296 if (group->field_data2 == NULL)
297 {
298 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
299 return 0;
300 }
301
302 if (!BN_copy(r, group->field_data2)) return 0;
303 return 1;
304 }
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
new file mode 100644
index 0000000000..ed07748675
--- /dev/null
+++ b/src/lib/libcrypto/ec/ecp_nist.c
@@ -0,0 +1,134 @@
1/* crypto/ec/ecp_nist.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58#if 0
59const EC_METHOD *EC_GFp_nist_method(void)
60 {
61 static const EC_METHOD ret = {
62 ec_GFp_nist_group_init,
63 ec_GFp_nist_group_finish,
64 ec_GFp_nist_group_clear_finish,
65 ec_GFp_nist_group_copy,
66 ec_GFp_nist_group_set_curve_GFp,
67 ec_GFp_simple_group_get_curve_GFp,
68 ec_GFp_simple_group_set_generator,
69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
72 ec_GFp_simple_point_init,
73 ec_GFp_simple_point_finish,
74 ec_GFp_simple_point_clear_finish,
75 ec_GFp_simple_point_copy,
76 ec_GFp_simple_point_set_to_infinity,
77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
79 ec_GFp_simple_point_set_affine_coordinates_GFp,
80 ec_GFp_simple_point_get_affine_coordinates_GFp,
81 ec_GFp_simple_set_compressed_coordinates_GFp,
82 ec_GFp_simple_point2oct,
83 ec_GFp_simple_oct2point,
84 ec_GFp_simple_add,
85 ec_GFp_simple_dbl,
86 ec_GFp_simple_invert,
87 ec_GFp_simple_is_at_infinity,
88 ec_GFp_simple_is_on_curve,
89 ec_GFp_simple_cmp,
90 ec_GFp_simple_make_affine,
91 ec_GFp_simple_points_make_affine,
92 ec_GFp_nist_field_mul,
93 ec_GFp_nist_field_sqr,
94 0 /* field_encode */,
95 0 /* field_decode */,
96 0 /* field_set_to_one */ };
97
98 return &ret;
99 }
100#endif
101
102
103int ec_GFp_nist_group_init(EC_GROUP *group)
104 {
105 int ok;
106
107 ok = ec_GFp_simple_group_init(group);
108 group->field_data1 = NULL;
109 return ok;
110 }
111
112
113int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
114/* TODO */
115
116
117void ec_GFp_nist_group_finish(EC_GROUP *group);
118/* TODO */
119
120
121void ec_GFp_nist_group_clear_finish(EC_GROUP *group);
122/* TODO */
123
124
125int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
126/* TODO */
127
128
129int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
130/* TODO */
131
132
133int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
134/* TODO */
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
new file mode 100644
index 0000000000..e9a51fb87a
--- /dev/null
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -0,0 +1,1717 @@
1/* crypto/ec/ecp_smpl.c */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <openssl/err.h>
59
60#include "ec_lcl.h"
61
62
63const EC_METHOD *EC_GFp_simple_method(void)
64 {
65 static const EC_METHOD ret = {
66 ec_GFp_simple_group_init,
67 ec_GFp_simple_group_finish,
68 ec_GFp_simple_group_clear_finish,
69 ec_GFp_simple_group_copy,
70 ec_GFp_simple_group_set_curve_GFp,
71 ec_GFp_simple_group_get_curve_GFp,
72 ec_GFp_simple_group_set_generator,
73 ec_GFp_simple_group_get0_generator,
74 ec_GFp_simple_group_get_order,
75 ec_GFp_simple_group_get_cofactor,
76 ec_GFp_simple_point_init,
77 ec_GFp_simple_point_finish,
78 ec_GFp_simple_point_clear_finish,
79 ec_GFp_simple_point_copy,
80 ec_GFp_simple_point_set_to_infinity,
81 ec_GFp_simple_set_Jprojective_coordinates_GFp,
82 ec_GFp_simple_get_Jprojective_coordinates_GFp,
83 ec_GFp_simple_point_set_affine_coordinates_GFp,
84 ec_GFp_simple_point_get_affine_coordinates_GFp,
85 ec_GFp_simple_set_compressed_coordinates_GFp,
86 ec_GFp_simple_point2oct,
87 ec_GFp_simple_oct2point,
88 ec_GFp_simple_add,
89 ec_GFp_simple_dbl,
90 ec_GFp_simple_invert,
91 ec_GFp_simple_is_at_infinity,
92 ec_GFp_simple_is_on_curve,
93 ec_GFp_simple_cmp,
94 ec_GFp_simple_make_affine,
95 ec_GFp_simple_points_make_affine,
96 ec_GFp_simple_field_mul,
97 ec_GFp_simple_field_sqr,
98 0 /* field_encode */,
99 0 /* field_decode */,
100 0 /* field_set_to_one */ };
101
102 return &ret;
103 }
104
105
106int ec_GFp_simple_group_init(EC_GROUP *group)
107 {
108 BN_init(&group->field);
109 BN_init(&group->a);
110 BN_init(&group->b);
111 group->a_is_minus3 = 0;
112 group->generator = NULL;
113 BN_init(&group->order);
114 BN_init(&group->cofactor);
115 return 1;
116 }
117
118
119void ec_GFp_simple_group_finish(EC_GROUP *group)
120 {
121 BN_free(&group->field);
122 BN_free(&group->a);
123 BN_free(&group->b);
124 if (group->generator != NULL)
125 EC_POINT_free(group->generator);
126 BN_free(&group->order);
127 BN_free(&group->cofactor);
128 }
129
130
131void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
132 {
133 BN_clear_free(&group->field);
134 BN_clear_free(&group->a);
135 BN_clear_free(&group->b);
136 if (group->generator != NULL)
137 {
138 EC_POINT_clear_free(group->generator);
139 group->generator = NULL;
140 }
141 BN_clear_free(&group->order);
142 BN_clear_free(&group->cofactor);
143 }
144
145
146int ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
147 {
148 if (!BN_copy(&dest->field, &src->field)) return 0;
149 if (!BN_copy(&dest->a, &src->a)) return 0;
150 if (!BN_copy(&dest->b, &src->b)) return 0;
151
152 dest->a_is_minus3 = src->a_is_minus3;
153
154 if (src->generator != NULL)
155 {
156 if (dest->generator == NULL)
157 {
158 dest->generator = EC_POINT_new(dest);
159 if (dest->generator == NULL) return 0;
160 }
161 if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
162 }
163 else
164 {
165 /* src->generator == NULL */
166 if (dest->generator != NULL)
167 {
168 EC_POINT_clear_free(dest->generator);
169 dest->generator = NULL;
170 }
171 }
172
173 if (!BN_copy(&dest->order, &src->order)) return 0;
174 if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
175
176 return 1;
177 }
178
179
180int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *group,
181 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
182 {
183 int ret = 0;
184 BN_CTX *new_ctx = NULL;
185 BIGNUM *tmp_a;
186
187 /* p must be a prime > 3 */
188 if (BN_num_bits(p) <= 2 || !BN_is_odd(p))
189 {
190 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP, EC_R_INVALID_FIELD);
191 return 0;
192 }
193
194 if (ctx == NULL)
195 {
196 ctx = new_ctx = BN_CTX_new();
197 if (ctx == NULL)
198 return 0;
199 }
200
201 BN_CTX_start(ctx);
202 tmp_a = BN_CTX_get(ctx);
203 if (tmp_a == NULL) goto err;
204
205 /* group->field */
206 if (!BN_copy(&group->field, p)) goto err;
207 group->field.neg = 0;
208
209 /* group->a */
210 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
211 if (group->meth->field_encode)
212 { if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }
213 else
214 if (!BN_copy(&group->a, tmp_a)) goto err;
215
216 /* group->b */
217 if (!BN_nnmod(&group->b, b, p, ctx)) goto err;
218 if (group->meth->field_encode)
219 if (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;
220
221 /* group->a_is_minus3 */
222 if (!BN_add_word(tmp_a, 3)) goto err;
223 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
224
225 ret = 1;
226
227 err:
228 BN_CTX_end(ctx);
229 if (new_ctx != NULL)
230 BN_CTX_free(new_ctx);
231 return ret;
232 }
233
234
235int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
236 {
237 int ret = 0;
238 BN_CTX *new_ctx = NULL;
239
240 if (p != NULL)
241 {
242 if (!BN_copy(p, &group->field)) return 0;
243 }
244
245 if (a != NULL || b != NULL)
246 {
247 if (group->meth->field_decode)
248 {
249 if (ctx == NULL)
250 {
251 ctx = new_ctx = BN_CTX_new();
252 if (ctx == NULL)
253 return 0;
254 }
255 if (a != NULL)
256 {
257 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
258 }
259 if (b != NULL)
260 {
261 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
262 }
263 }
264 else
265 {
266 if (a != NULL)
267 {
268 if (!BN_copy(a, &group->a)) goto err;
269 }
270 if (b != NULL)
271 {
272 if (!BN_copy(b, &group->b)) goto err;
273 }
274 }
275 }
276
277 ret = 1;
278
279 err:
280 if (new_ctx)
281 BN_CTX_free(new_ctx);
282 return ret;
283 }
284
285
286
287int ec_GFp_simple_group_set_generator(EC_GROUP *group, const EC_POINT *generator,
288 const BIGNUM *order, const BIGNUM *cofactor)
289 {
290 if (generator == NULL)
291 {
292 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
293 return 0 ;
294 }
295
296 if (group->generator == NULL)
297 {
298 group->generator = EC_POINT_new(group);
299 if (group->generator == NULL) return 0;
300 }
301 if (!EC_POINT_copy(group->generator, generator)) return 0;
302
303 if (order != NULL)
304 { if (!BN_copy(&group->order, order)) return 0; }
305 else
306 { if (!BN_zero(&group->order)) return 0; }
307
308 if (cofactor != NULL)
309 { if (!BN_copy(&group->cofactor, cofactor)) return 0; }
310 else
311 { if (!BN_zero(&group->cofactor)) return 0; }
312
313 return 1;
314 }
315
316
317EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *group)
318 {
319 return group->generator;
320 }
321
322
323int ec_GFp_simple_group_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
324 {
325 if (!BN_copy(order, &group->order))
326 return 0;
327
328 return !BN_is_zero(&group->order);
329 }
330
331
332int ec_GFp_simple_group_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
333 {
334 if (!BN_copy(cofactor, &group->cofactor))
335 return 0;
336
337 return !BN_is_zero(&group->cofactor);
338 }
339
340
341int ec_GFp_simple_point_init(EC_POINT *point)
342 {
343 BN_init(&point->X);
344 BN_init(&point->Y);
345 BN_init(&point->Z);
346 point->Z_is_one = 0;
347
348 return 1;
349 }
350
351
352void ec_GFp_simple_point_finish(EC_POINT *point)
353 {
354 BN_free(&point->X);
355 BN_free(&point->Y);
356 BN_free(&point->Z);
357 }
358
359
360void ec_GFp_simple_point_clear_finish(EC_POINT *point)
361 {
362 BN_clear_free(&point->X);
363 BN_clear_free(&point->Y);
364 BN_clear_free(&point->Z);
365 point->Z_is_one = 0;
366 }
367
368
369int ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
370 {
371 if (!BN_copy(&dest->X, &src->X)) return 0;
372 if (!BN_copy(&dest->Y, &src->Y)) return 0;
373 if (!BN_copy(&dest->Z, &src->Z)) return 0;
374 dest->Z_is_one = src->Z_is_one;
375
376 return 1;
377 }
378
379
380int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
381 {
382 point->Z_is_one = 0;
383 return (BN_zero(&point->Z));
384 }
385
386
387int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
388 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
389 {
390 BN_CTX *new_ctx = NULL;
391 int ret = 0;
392
393 if (ctx == NULL)
394 {
395 ctx = new_ctx = BN_CTX_new();
396 if (ctx == NULL)
397 return 0;
398 }
399
400 if (x != NULL)
401 {
402 if (!BN_nnmod(&point->X, x, &group->field, ctx)) goto err;
403 if (group->meth->field_encode)
404 {
405 if (!group->meth->field_encode(group, &point->X, &point->X, ctx)) goto err;
406 }
407 }
408
409 if (y != NULL)
410 {
411 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) goto err;
412 if (group->meth->field_encode)
413 {
414 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx)) goto err;
415 }
416 }
417
418 if (z != NULL)
419 {
420 int Z_is_one;
421
422 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) goto err;
423 Z_is_one = BN_is_one(&point->Z);
424 if (group->meth->field_encode)
425 {
426 if (Z_is_one && (group->meth->field_set_to_one != 0))
427 {
428 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) goto err;
429 }
430 else
431 {
432 if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) goto err;
433 }
434 }
435 point->Z_is_one = Z_is_one;
436 }
437
438 ret = 1;
439
440 err:
441 if (new_ctx != NULL)
442 BN_CTX_free(new_ctx);
443 return ret;
444 }
445
446
447int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
448 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
449 {
450 BN_CTX *new_ctx = NULL;
451 int ret = 0;
452
453 if (group->meth->field_decode != 0)
454 {
455 if (ctx == NULL)
456 {
457 ctx = new_ctx = BN_CTX_new();
458 if (ctx == NULL)
459 return 0;
460 }
461
462 if (x != NULL)
463 {
464 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
465 }
466 if (y != NULL)
467 {
468 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
469 }
470 if (z != NULL)
471 {
472 if (!group->meth->field_decode(group, z, &point->Z, ctx)) goto err;
473 }
474 }
475 else
476 {
477 if (x != NULL)
478 {
479 if (!BN_copy(x, &point->X)) goto err;
480 }
481 if (y != NULL)
482 {
483 if (!BN_copy(y, &point->Y)) goto err;
484 }
485 if (z != NULL)
486 {
487 if (!BN_copy(z, &point->Z)) goto err;
488 }
489 }
490
491 ret = 1;
492
493 err:
494 if (new_ctx != NULL)
495 BN_CTX_free(new_ctx);
496 return ret;
497 }
498
499
500int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
501 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
502 {
503 if (x == NULL || y == NULL)
504 {
505 /* unlike for projective coordinates, we do not tolerate this */
506 ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_PASSED_NULL_PARAMETER);
507 return 0;
508 }
509
510 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
511 }
512
513
514int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
515 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
516 {
517 BN_CTX *new_ctx = NULL;
518 BIGNUM *X, *Y, *Z, *Z_1, *Z_2, *Z_3;
519 const BIGNUM *X_, *Y_, *Z_;
520 int ret = 0;
521
522 if (EC_POINT_is_at_infinity(group, point))
523 {
524 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_POINT_AT_INFINITY);
525 return 0;
526 }
527
528 if (ctx == NULL)
529 {
530 ctx = new_ctx = BN_CTX_new();
531 if (ctx == NULL)
532 return 0;
533 }
534
535 BN_CTX_start(ctx);
536 X = BN_CTX_get(ctx);
537 Y = BN_CTX_get(ctx);
538 Z = BN_CTX_get(ctx);
539 Z_1 = BN_CTX_get(ctx);
540 Z_2 = BN_CTX_get(ctx);
541 Z_3 = BN_CTX_get(ctx);
542 if (Z_3 == NULL) goto err;
543
544 /* transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3) */
545
546 if (group->meth->field_decode)
547 {
548 if (!group->meth->field_decode(group, X, &point->X, ctx)) goto err;
549 if (!group->meth->field_decode(group, Y, &point->Y, ctx)) goto err;
550 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
551 X_ = X; Y_ = Y; Z_ = Z;
552 }
553 else
554 {
555 X_ = &point->X;
556 Y_ = &point->Y;
557 Z_ = &point->Z;
558 }
559
560 if (BN_is_one(Z_))
561 {
562 if (x != NULL)
563 {
564 if (!BN_copy(x, X_)) goto err;
565 }
566 if (y != NULL)
567 {
568 if (!BN_copy(y, Y_)) goto err;
569 }
570 }
571 else
572 {
573 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
574 {
575 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_BN_LIB);
576 goto err;
577 }
578
579 if (group->meth->field_encode == 0)
580 {
581 /* field_sqr works on standard representation */
582 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;
583 }
584 else
585 {
586 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) goto err;
587 }
588
589 if (x != NULL)
590 {
591 if (group->meth->field_encode == 0)
592 {
593 /* field_mul works on standard representation */
594 if (!group->meth->field_mul(group, x, X_, Z_2, ctx)) goto err;
595 }
596 else
597 {
598 if (!BN_mod_mul(x, X_, Z_2, &group->field, ctx)) goto err;
599 }
600 }
601
602 if (y != NULL)
603 {
604 if (group->meth->field_encode == 0)
605 {
606 /* field_mul works on standard representation */
607 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;
608 if (!group->meth->field_mul(group, y, Y_, Z_3, ctx)) goto err;
609
610 }
611 else
612 {
613 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
614 if (!BN_mod_mul(y, Y_, Z_3, &group->field, ctx)) goto err;
615 }
616 }
617 }
618
619 ret = 1;
620
621 err:
622 BN_CTX_end(ctx);
623 if (new_ctx != NULL)
624 BN_CTX_free(new_ctx);
625 return ret;
626 }
627
628
629int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
630 const BIGNUM *x_, int y_bit, BN_CTX *ctx)
631 {
632 BN_CTX *new_ctx = NULL;
633 BIGNUM *tmp1, *tmp2, *x, *y;
634 int ret = 0;
635
636 if (ctx == NULL)
637 {
638 ctx = new_ctx = BN_CTX_new();
639 if (ctx == NULL)
640 return 0;
641 }
642
643 y_bit = (y_bit != 0);
644
645 BN_CTX_start(ctx);
646 tmp1 = BN_CTX_get(ctx);
647 tmp2 = BN_CTX_get(ctx);
648 x = BN_CTX_get(ctx);
649 y = BN_CTX_get(ctx);
650 if (y == NULL) goto err;
651
652 /* Recover y. We have a Weierstrass equation
653 * y^2 = x^3 + a*x + b,
654 * so y is one of the square roots of x^3 + a*x + b.
655 */
656
657 /* tmp1 := x^3 */
658 if (!BN_nnmod(x, x_, &group->field,ctx)) goto err;
659 if (group->meth->field_decode == 0)
660 {
661 /* field_{sqr,mul} work on standard representation */
662 if (!group->meth->field_sqr(group, tmp2, x_, ctx)) goto err;
663 if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx)) goto err;
664 }
665 else
666 {
667 if (!BN_mod_sqr(tmp2, x_, &group->field, ctx)) goto err;
668 if (!BN_mod_mul(tmp1, tmp2, x_, &group->field, ctx)) goto err;
669 }
670
671 /* tmp1 := tmp1 + a*x */
672 if (group->a_is_minus3)
673 {
674 if (!BN_mod_lshift1_quick(tmp2, x, &group->field)) goto err;
675 if (!BN_mod_add_quick(tmp2, tmp2, x, &group->field)) goto err;
676 if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
677 }
678 else
679 {
680 if (group->meth->field_decode)
681 {
682 if (!group->meth->field_decode(group, tmp2, &group->a, ctx)) goto err;
683 if (!BN_mod_mul(tmp2, tmp2, x, &group->field, ctx)) goto err;
684 }
685 else
686 {
687 /* field_mul works on standard representation */
688 if (!group->meth->field_mul(group, tmp2, &group->a, x, ctx)) goto err;
689 }
690
691 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
692 }
693
694 /* tmp1 := tmp1 + b */
695 if (group->meth->field_decode)
696 {
697 if (!group->meth->field_decode(group, tmp2, &group->b, ctx)) goto err;
698 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
699 }
700 else
701 {
702 if (!BN_mod_add_quick(tmp1, tmp1, &group->b, &group->field)) goto err;
703 }
704
705 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx))
706 {
707 unsigned long err = ERR_peek_error();
708
709 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE)
710 {
711 (void)ERR_get_error();
712 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
713 }
714 else
715 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_BN_LIB);
716 goto err;
717 }
718 /* If tmp1 is not a square (i.e. there is no point on the curve with
719 * our x), then y now is a nonsense value too */
720
721 if (y_bit != BN_is_odd(y))
722 {
723 if (BN_is_zero(y))
724 {
725 int kron;
726
727 kron = BN_kronecker(x, &group->field, ctx);
728 if (kron == -2) goto err;
729
730 if (kron == 1)
731 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSION_BIT);
732 else
733 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
734 goto err;
735 }
736 if (!BN_usub(y, &group->field, y)) goto err;
737 }
738 if (y_bit != BN_is_odd(y))
739 {
740 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_INTERNAL_ERROR);
741 goto err;
742 }
743
744 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
745
746 ret = 1;
747
748 err:
749 BN_CTX_end(ctx);
750 if (new_ctx != NULL)
751 BN_CTX_free(new_ctx);
752 return ret;
753 }
754
755
756size_t ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
757 unsigned char *buf, size_t len, BN_CTX *ctx)
758 {
759 size_t ret;
760 BN_CTX *new_ctx = NULL;
761 int used_ctx = 0;
762 BIGNUM *x, *y;
763 size_t field_len, i, skip;
764
765 if ((form != POINT_CONVERSION_COMPRESSED)
766 && (form != POINT_CONVERSION_UNCOMPRESSED)
767 && (form != POINT_CONVERSION_HYBRID))
768 {
769 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_INVALID_FORM);
770 goto err;
771 }
772
773 if (EC_POINT_is_at_infinity(group, point))
774 {
775 /* encodes to a single 0 octet */
776 if (buf != NULL)
777 {
778 if (len < 1)
779 {
780 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
781 return 0;
782 }
783 buf[0] = 0;
784 }
785 return 1;
786 }
787
788
789 /* ret := required output buffer length */
790 field_len = BN_num_bytes(&group->field);
791 ret = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
792
793 /* if 'buf' is NULL, just return required length */
794 if (buf != NULL)
795 {
796 if (len < ret)
797 {
798 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
799 goto err;
800 }
801
802 if (ctx == NULL)
803 {
804 ctx = new_ctx = BN_CTX_new();
805 if (ctx == NULL)
806 return 0;
807 }
808
809 BN_CTX_start(ctx);
810 used_ctx = 1;
811 x = BN_CTX_get(ctx);
812 y = BN_CTX_get(ctx);
813 if (y == NULL) goto err;
814
815 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
816
817 if ((form == POINT_CONVERSION_COMPRESSED || form == POINT_CONVERSION_HYBRID) && BN_is_odd(y))
818 buf[0] = form + 1;
819 else
820 buf[0] = form;
821
822 i = 1;
823
824 skip = field_len - BN_num_bytes(x);
825 if (skip > field_len)
826 {
827 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
828 goto err;
829 }
830 while (skip > 0)
831 {
832 buf[i++] = 0;
833 skip--;
834 }
835 skip = BN_bn2bin(x, buf + i);
836 i += skip;
837 if (i != 1 + field_len)
838 {
839 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
840 goto err;
841 }
842
843 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID)
844 {
845 skip = field_len - BN_num_bytes(y);
846 if (skip > field_len)
847 {
848 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
849 goto err;
850 }
851 while (skip > 0)
852 {
853 buf[i++] = 0;
854 skip--;
855 }
856 skip = BN_bn2bin(y, buf + i);
857 i += skip;
858 }
859
860 if (i != ret)
861 {
862 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
863 goto err;
864 }
865 }
866
867 if (used_ctx)
868 BN_CTX_end(ctx);
869 if (new_ctx != NULL)
870 BN_CTX_free(new_ctx);
871 return ret;
872
873 err:
874 if (used_ctx)
875 BN_CTX_end(ctx);
876 if (new_ctx != NULL)
877 BN_CTX_free(new_ctx);
878 return 0;
879 }
880
881
882int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
883 const unsigned char *buf, size_t len, BN_CTX *ctx)
884 {
885 point_conversion_form_t form;
886 int y_bit;
887 BN_CTX *new_ctx = NULL;
888 BIGNUM *x, *y;
889 size_t field_len, enc_len;
890 int ret = 0;
891
892 if (len == 0)
893 {
894 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);
895 return 0;
896 }
897 form = buf[0];
898 y_bit = form & 1;
899 form = form & ~1U;
900 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
901 && (form != POINT_CONVERSION_UNCOMPRESSED)
902 && (form != POINT_CONVERSION_HYBRID))
903 {
904 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
905 return 0;
906 }
907 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit)
908 {
909 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
910 return 0;
911 }
912
913 if (form == 0)
914 {
915 if (len != 1)
916 {
917 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
918 return 0;
919 }
920
921 return EC_POINT_set_to_infinity(group, point);
922 }
923
924 field_len = BN_num_bytes(&group->field);
925 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
926
927 if (len != enc_len)
928 {
929 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
930 return 0;
931 }
932
933 if (ctx == NULL)
934 {
935 ctx = new_ctx = BN_CTX_new();
936 if (ctx == NULL)
937 return 0;
938 }
939
940 BN_CTX_start(ctx);
941 x = BN_CTX_get(ctx);
942 y = BN_CTX_get(ctx);
943 if (y == NULL) goto err;
944
945 if (!BN_bin2bn(buf + 1, field_len, x)) goto err;
946 if (BN_ucmp(x, &group->field) >= 0)
947 {
948 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
949 goto err;
950 }
951
952 if (form == POINT_CONVERSION_COMPRESSED)
953 {
954 if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) goto err;
955 }
956 else
957 {
958 if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) goto err;
959 if (BN_ucmp(y, &group->field) >= 0)
960 {
961 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
962 goto err;
963 }
964 if (form == POINT_CONVERSION_HYBRID)
965 {
966 if (y_bit != BN_is_odd(y))
967 {
968 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
969 goto err;
970 }
971 }
972
973 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
974 }
975
976 if (!EC_POINT_is_on_curve(group, point, ctx)) /* test required by X9.62 */
977 {
978 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE);
979 goto err;
980 }
981
982 ret = 1;
983
984 err:
985 BN_CTX_end(ctx);
986 if (new_ctx != NULL)
987 BN_CTX_free(new_ctx);
988 return ret;
989 }
990
991
992int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
993 {
994 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
995 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
996 const BIGNUM *p;
997 BN_CTX *new_ctx = NULL;
998 BIGNUM *n0, *n1, *n2, *n3, *n4, *n5, *n6;
999 int ret = 0;
1000
1001 if (a == b)
1002 return EC_POINT_dbl(group, r, a, ctx);
1003 if (EC_POINT_is_at_infinity(group, a))
1004 return EC_POINT_copy(r, b);
1005 if (EC_POINT_is_at_infinity(group, b))
1006 return EC_POINT_copy(r, a);
1007
1008 field_mul = group->meth->field_mul;
1009 field_sqr = group->meth->field_sqr;
1010 p = &group->field;
1011
1012 if (ctx == NULL)
1013 {
1014 ctx = new_ctx = BN_CTX_new();
1015 if (ctx == NULL)
1016 return 0;
1017 }
1018
1019 BN_CTX_start(ctx);
1020 n0 = BN_CTX_get(ctx);
1021 n1 = BN_CTX_get(ctx);
1022 n2 = BN_CTX_get(ctx);
1023 n3 = BN_CTX_get(ctx);
1024 n4 = BN_CTX_get(ctx);
1025 n5 = BN_CTX_get(ctx);
1026 n6 = BN_CTX_get(ctx);
1027 if (n6 == NULL) goto end;
1028
1029 /* Note that in this function we must not read components of 'a' or 'b'
1030 * once we have written the corresponding components of 'r'.
1031 * ('r' might be one of 'a' or 'b'.)
1032 */
1033
1034 /* n1, n2 */
1035 if (b->Z_is_one)
1036 {
1037 if (!BN_copy(n1, &a->X)) goto end;
1038 if (!BN_copy(n2, &a->Y)) goto end;
1039 /* n1 = X_a */
1040 /* n2 = Y_a */
1041 }
1042 else
1043 {
1044 if (!field_sqr(group, n0, &b->Z, ctx)) goto end;
1045 if (!field_mul(group, n1, &a->X, n0, ctx)) goto end;
1046 /* n1 = X_a * Z_b^2 */
1047
1048 if (!field_mul(group, n0, n0, &b->Z, ctx)) goto end;
1049 if (!field_mul(group, n2, &a->Y, n0, ctx)) goto end;
1050 /* n2 = Y_a * Z_b^3 */
1051 }
1052
1053 /* n3, n4 */
1054 if (a->Z_is_one)
1055 {
1056 if (!BN_copy(n3, &b->X)) goto end;
1057 if (!BN_copy(n4, &b->Y)) goto end;
1058 /* n3 = X_b */
1059 /* n4 = Y_b */
1060 }
1061 else
1062 {
1063 if (!field_sqr(group, n0, &a->Z, ctx)) goto end;
1064 if (!field_mul(group, n3, &b->X, n0, ctx)) goto end;
1065 /* n3 = X_b * Z_a^2 */
1066
1067 if (!field_mul(group, n0, n0, &a->Z, ctx)) goto end;
1068 if (!field_mul(group, n4, &b->Y, n0, ctx)) goto end;
1069 /* n4 = Y_b * Z_a^3 */
1070 }
1071
1072 /* n5, n6 */
1073 if (!BN_mod_sub_quick(n5, n1, n3, p)) goto end;
1074 if (!BN_mod_sub_quick(n6, n2, n4, p)) goto end;
1075 /* n5 = n1 - n3 */
1076 /* n6 = n2 - n4 */
1077
1078 if (BN_is_zero(n5))
1079 {
1080 if (BN_is_zero(n6))
1081 {
1082 /* a is the same point as b */
1083 BN_CTX_end(ctx);
1084 ret = EC_POINT_dbl(group, r, a, ctx);
1085 ctx = NULL;
1086 goto end;
1087 }
1088 else
1089 {
1090 /* a is the inverse of b */
1091 if (!BN_zero(&r->Z)) goto end;
1092 r->Z_is_one = 0;
1093 ret = 1;
1094 goto end;
1095 }
1096 }
1097
1098 /* 'n7', 'n8' */
1099 if (!BN_mod_add_quick(n1, n1, n3, p)) goto end;
1100 if (!BN_mod_add_quick(n2, n2, n4, p)) goto end;
1101 /* 'n7' = n1 + n3 */
1102 /* 'n8' = n2 + n4 */
1103
1104 /* Z_r */
1105 if (a->Z_is_one && b->Z_is_one)
1106 {
1107 if (!BN_copy(&r->Z, n5)) goto end;
1108 }
1109 else
1110 {
1111 if (a->Z_is_one)
1112 { if (!BN_copy(n0, &b->Z)) goto end; }
1113 else if (b->Z_is_one)
1114 { if (!BN_copy(n0, &a->Z)) goto end; }
1115 else
1116 { if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) goto end; }
1117 if (!field_mul(group, &r->Z, n0, n5, ctx)) goto end;
1118 }
1119 r->Z_is_one = 0;
1120 /* Z_r = Z_a * Z_b * n5 */
1121
1122 /* X_r */
1123 if (!field_sqr(group, n0, n6, ctx)) goto end;
1124 if (!field_sqr(group, n4, n5, ctx)) goto end;
1125 if (!field_mul(group, n3, n1, n4, ctx)) goto end;
1126 if (!BN_mod_sub_quick(&r->X, n0, n3, p)) goto end;
1127 /* X_r = n6^2 - n5^2 * 'n7' */
1128
1129 /* 'n9' */
1130 if (!BN_mod_lshift1_quick(n0, &r->X, p)) goto end;
1131 if (!BN_mod_sub_quick(n0, n3, n0, p)) goto end;
1132 /* n9 = n5^2 * 'n7' - 2 * X_r */
1133
1134 /* Y_r */
1135 if (!field_mul(group, n0, n0, n6, ctx)) goto end;
1136 if (!field_mul(group, n5, n4, n5, ctx)) goto end; /* now n5 is n5^3 */
1137 if (!field_mul(group, n1, n2, n5, ctx)) goto end;
1138 if (!BN_mod_sub_quick(n0, n0, n1, p)) goto end;
1139 if (BN_is_odd(n0))
1140 if (!BN_add(n0, n0, p)) goto end;
1141 /* now 0 <= n0 < 2*p, and n0 is even */
1142 if (!BN_rshift1(&r->Y, n0)) goto end;
1143 /* Y_r = (n6 * 'n9' - 'n8' * 'n5^3') / 2 */
1144
1145 ret = 1;
1146
1147 end:
1148 if (ctx) /* otherwise we already called BN_CTX_end */
1149 BN_CTX_end(ctx);
1150 if (new_ctx != NULL)
1151 BN_CTX_free(new_ctx);
1152 return ret;
1153 }
1154
1155
1156int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
1157 {
1158 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1159 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1160 const BIGNUM *p;
1161 BN_CTX *new_ctx = NULL;
1162 BIGNUM *n0, *n1, *n2, *n3;
1163 int ret = 0;
1164
1165 if (EC_POINT_is_at_infinity(group, a))
1166 {
1167 if (!BN_zero(&r->Z)) return 0;
1168 r->Z_is_one = 0;
1169 return 1;
1170 }
1171
1172 field_mul = group->meth->field_mul;
1173 field_sqr = group->meth->field_sqr;
1174 p = &group->field;
1175
1176 if (ctx == NULL)
1177 {
1178 ctx = new_ctx = BN_CTX_new();
1179 if (ctx == NULL)
1180 return 0;
1181 }
1182
1183 BN_CTX_start(ctx);
1184 n0 = BN_CTX_get(ctx);
1185 n1 = BN_CTX_get(ctx);
1186 n2 = BN_CTX_get(ctx);
1187 n3 = BN_CTX_get(ctx);
1188 if (n3 == NULL) goto err;
1189
1190 /* Note that in this function we must not read components of 'a'
1191 * once we have written the corresponding components of 'r'.
1192 * ('r' might the same as 'a'.)
1193 */
1194
1195 /* n1 */
1196 if (a->Z_is_one)
1197 {
1198 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1199 if (!BN_mod_lshift1_quick(n1, n0, p)) goto err;
1200 if (!BN_mod_add_quick(n0, n0, n1, p)) goto err;
1201 if (!BN_mod_add_quick(n1, n0, &group->a, p)) goto err;
1202 /* n1 = 3 * X_a^2 + a_curve */
1203 }
1204 else if (group->a_is_minus3)
1205 {
1206 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1207 if (!BN_mod_add_quick(n0, &a->X, n1, p)) goto err;
1208 if (!BN_mod_sub_quick(n2, &a->X, n1, p)) goto err;
1209 if (!field_mul(group, n1, n0, n2, ctx)) goto err;
1210 if (!BN_mod_lshift1_quick(n0, n1, p)) goto err;
1211 if (!BN_mod_add_quick(n1, n0, n1, p)) goto err;
1212 /* n1 = 3 * (X_a + Z_a^2) * (X_a - Z_a^2)
1213 * = 3 * X_a^2 - 3 * Z_a^4 */
1214 }
1215 else
1216 {
1217 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1218 if (!BN_mod_lshift1_quick(n1, n0, p)) goto err;
1219 if (!BN_mod_add_quick(n0, n0, n1, p)) goto err;
1220 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1221 if (!field_sqr(group, n1, n1, ctx)) goto err;
1222 if (!field_mul(group, n1, n1, &group->a, ctx)) goto err;
1223 if (!BN_mod_add_quick(n1, n1, n0, p)) goto err;
1224 /* n1 = 3 * X_a^2 + a_curve * Z_a^4 */
1225 }
1226
1227 /* Z_r */
1228 if (a->Z_is_one)
1229 {
1230 if (!BN_copy(n0, &a->Y)) goto err;
1231 }
1232 else
1233 {
1234 if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) goto err;
1235 }
1236 if (!BN_mod_lshift1_quick(&r->Z, n0, p)) goto err;
1237 r->Z_is_one = 0;
1238 /* Z_r = 2 * Y_a * Z_a */
1239
1240 /* n2 */
1241 if (!field_sqr(group, n3, &a->Y, ctx)) goto err;
1242 if (!field_mul(group, n2, &a->X, n3, ctx)) goto err;
1243 if (!BN_mod_lshift_quick(n2, n2, 2, p)) goto err;
1244 /* n2 = 4 * X_a * Y_a^2 */
1245
1246 /* X_r */
1247 if (!BN_mod_lshift1_quick(n0, n2, p)) goto err;
1248 if (!field_sqr(group, &r->X, n1, ctx)) goto err;
1249 if (!BN_mod_sub_quick(&r->X, &r->X, n0, p)) goto err;
1250 /* X_r = n1^2 - 2 * n2 */
1251
1252 /* n3 */
1253 if (!field_sqr(group, n0, n3, ctx)) goto err;
1254 if (!BN_mod_lshift_quick(n3, n0, 3, p)) goto err;
1255 /* n3 = 8 * Y_a^4 */
1256
1257 /* Y_r */
1258 if (!BN_mod_sub_quick(n0, n2, &r->X, p)) goto err;
1259 if (!field_mul(group, n0, n1, n0, ctx)) goto err;
1260 if (!BN_mod_sub_quick(&r->Y, n0, n3, p)) goto err;
1261 /* Y_r = n1 * (n2 - X_r) - n3 */
1262
1263 ret = 1;
1264
1265 err:
1266 BN_CTX_end(ctx);
1267 if (new_ctx != NULL)
1268 BN_CTX_free(new_ctx);
1269 return ret;
1270 }
1271
1272
1273int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1274 {
1275 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
1276 /* point is its own inverse */
1277 return 1;
1278
1279 return BN_usub(&point->Y, &group->field, &point->Y);
1280 }
1281
1282
1283int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
1284 {
1285 return BN_is_zero(&point->Z);
1286 }
1287
1288
1289int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
1290 {
1291 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1292 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1293 const BIGNUM *p;
1294 BN_CTX *new_ctx = NULL;
1295 BIGNUM *rh, *tmp1, *tmp2, *Z4, *Z6;
1296 int ret = -1;
1297
1298 if (EC_POINT_is_at_infinity(group, point))
1299 return 1;
1300
1301 field_mul = group->meth->field_mul;
1302 field_sqr = group->meth->field_sqr;
1303 p = &group->field;
1304
1305 if (ctx == NULL)
1306 {
1307 ctx = new_ctx = BN_CTX_new();
1308 if (ctx == NULL)
1309 return -1;
1310 }
1311
1312 BN_CTX_start(ctx);
1313 rh = BN_CTX_get(ctx);
1314 tmp1 = BN_CTX_get(ctx);
1315 tmp2 = BN_CTX_get(ctx);
1316 Z4 = BN_CTX_get(ctx);
1317 Z6 = BN_CTX_get(ctx);
1318 if (Z6 == NULL) goto err;
1319
1320 /* We have a curve defined by a Weierstrass equation
1321 * y^2 = x^3 + a*x + b.
1322 * The point to consider is given in Jacobian projective coordinates
1323 * where (X, Y, Z) represents (x, y) = (X/Z^2, Y/Z^3).
1324 * Substituting this and multiplying by Z^6 transforms the above equation into
1325 * Y^2 = X^3 + a*X*Z^4 + b*Z^6.
1326 * To test this, we add up the right-hand side in 'rh'.
1327 */
1328
1329 /* rh := X^3 */
1330 if (!field_sqr(group, rh, &point->X, ctx)) goto err;
1331 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1332
1333 if (!point->Z_is_one)
1334 {
1335 if (!field_sqr(group, tmp1, &point->Z, ctx)) goto err;
1336 if (!field_sqr(group, Z4, tmp1, ctx)) goto err;
1337 if (!field_mul(group, Z6, Z4, tmp1, ctx)) goto err;
1338
1339 /* rh := rh + a*X*Z^4 */
1340 if (!field_mul(group, tmp1, &point->X, Z4, ctx)) goto err;
1341 if (group->a_is_minus3)
1342 {
1343 if (!BN_mod_lshift1_quick(tmp2, tmp1, p)) goto err;
1344 if (!BN_mod_add_quick(tmp2, tmp2, tmp1, p)) goto err;
1345 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1346 }
1347 else
1348 {
1349 if (!field_mul(group, tmp2, tmp1, &group->a, ctx)) goto err;
1350 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1351 }
1352
1353 /* rh := rh + b*Z^6 */
1354 if (!field_mul(group, tmp1, &group->b, Z6, ctx)) goto err;
1355 if (!BN_mod_add_quick(rh, rh, tmp1, p)) goto err;
1356 }
1357 else
1358 {
1359 /* point->Z_is_one */
1360
1361 /* rh := rh + a*X */
1362 if (group->a_is_minus3)
1363 {
1364 if (!BN_mod_lshift1_quick(tmp2, &point->X, p)) goto err;
1365 if (!BN_mod_add_quick(tmp2, tmp2, &point->X, p)) goto err;
1366 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1367 }
1368 else
1369 {
1370 if (!field_mul(group, tmp2, &point->X, &group->a, ctx)) goto err;
1371 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1372 }
1373
1374 /* rh := rh + b */
1375 if (!BN_mod_add_quick(rh, rh, &group->b, p)) goto err;
1376 }
1377
1378 /* 'lh' := Y^2 */
1379 if (!field_sqr(group, tmp1, &point->Y, ctx)) goto err;
1380
1381 ret = (0 == BN_cmp(tmp1, rh));
1382
1383 err:
1384 BN_CTX_end(ctx);
1385 if (new_ctx != NULL)
1386 BN_CTX_free(new_ctx);
1387 return ret;
1388 }
1389
1390
1391int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1392 {
1393 /* return values:
1394 * -1 error
1395 * 0 equal (in affine coordinates)
1396 * 1 not equal
1397 */
1398
1399 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1400 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1401 BN_CTX *new_ctx = NULL;
1402 BIGNUM *tmp1, *tmp2, *Za23, *Zb23;
1403 const BIGNUM *tmp1_, *tmp2_;
1404 int ret = -1;
1405
1406 if (EC_POINT_is_at_infinity(group, a))
1407 {
1408 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1409 }
1410
1411 if (a->Z_is_one && b->Z_is_one)
1412 {
1413 return ((BN_cmp(&a->X, &b->X) == 0) && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1;
1414 }
1415
1416 field_mul = group->meth->field_mul;
1417 field_sqr = group->meth->field_sqr;
1418
1419 if (ctx == NULL)
1420 {
1421 ctx = new_ctx = BN_CTX_new();
1422 if (ctx == NULL)
1423 return -1;
1424 }
1425
1426 BN_CTX_start(ctx);
1427 tmp1 = BN_CTX_get(ctx);
1428 tmp2 = BN_CTX_get(ctx);
1429 Za23 = BN_CTX_get(ctx);
1430 Zb23 = BN_CTX_get(ctx);
1431 if (Zb23 == NULL) goto end;
1432
1433 /* We have to decide whether
1434 * (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
1435 * or equivalently, whether
1436 * (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
1437 */
1438
1439 if (!b->Z_is_one)
1440 {
1441 if (!field_sqr(group, Zb23, &b->Z, ctx)) goto end;
1442 if (!field_mul(group, tmp1, &a->X, Zb23, ctx)) goto end;
1443 tmp1_ = tmp1;
1444 }
1445 else
1446 tmp1_ = &a->X;
1447 if (!a->Z_is_one)
1448 {
1449 if (!field_sqr(group, Za23, &a->Z, ctx)) goto end;
1450 if (!field_mul(group, tmp2, &b->X, Za23, ctx)) goto end;
1451 tmp2_ = tmp2;
1452 }
1453 else
1454 tmp2_ = &b->X;
1455
1456 /* compare X_a*Z_b^2 with X_b*Z_a^2 */
1457 if (BN_cmp(tmp1_, tmp2_) != 0)
1458 {
1459 ret = 1; /* points differ */
1460 goto end;
1461 }
1462
1463
1464 if (!b->Z_is_one)
1465 {
1466 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx)) goto end;
1467 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx)) goto end;
1468 /* tmp1_ = tmp1 */
1469 }
1470 else
1471 tmp1_ = &a->Y;
1472 if (!a->Z_is_one)
1473 {
1474 if (!field_mul(group, Za23, Za23, &a->Z, ctx)) goto end;
1475 if (!field_mul(group, tmp2, &b->Y, Za23, ctx)) goto end;
1476 /* tmp2_ = tmp2 */
1477 }
1478 else
1479 tmp2_ = &b->Y;
1480
1481 /* compare Y_a*Z_b^3 with Y_b*Z_a^3 */
1482 if (BN_cmp(tmp1_, tmp2_) != 0)
1483 {
1484 ret = 1; /* points differ */
1485 goto end;
1486 }
1487
1488 /* points are equal */
1489 ret = 0;
1490
1491 end:
1492 BN_CTX_end(ctx);
1493 if (new_ctx != NULL)
1494 BN_CTX_free(new_ctx);
1495 return ret;
1496 }
1497
1498
1499int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1500 {
1501 BN_CTX *new_ctx = NULL;
1502 BIGNUM *x, *y;
1503 int ret = 0;
1504
1505 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
1506 return 1;
1507
1508 if (ctx == NULL)
1509 {
1510 ctx = new_ctx = BN_CTX_new();
1511 if (ctx == NULL)
1512 return 0;
1513 }
1514
1515 BN_CTX_start(ctx);
1516 x = BN_CTX_get(ctx);
1517 y = BN_CTX_get(ctx);
1518 if (y == NULL) goto err;
1519
1520 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1521 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1522 if (!point->Z_is_one)
1523 {
1524 ECerr(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE, ERR_R_INTERNAL_ERROR);
1525 goto err;
1526 }
1527
1528 ret = 1;
1529
1530 err:
1531 BN_CTX_end(ctx);
1532 if (new_ctx != NULL)
1533 BN_CTX_free(new_ctx);
1534 return ret;
1535 }
1536
1537
1538int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1539 {
1540 BN_CTX *new_ctx = NULL;
1541 BIGNUM *tmp0, *tmp1;
1542 size_t pow2 = 0;
1543 BIGNUM **heap = NULL;
1544 size_t i;
1545 int ret = 0;
1546
1547 if (num == 0)
1548 return 1;
1549
1550 if (ctx == NULL)
1551 {
1552 ctx = new_ctx = BN_CTX_new();
1553 if (ctx == NULL)
1554 return 0;
1555 }
1556
1557 BN_CTX_start(ctx);
1558 tmp0 = BN_CTX_get(ctx);
1559 tmp1 = BN_CTX_get(ctx);
1560 if (tmp0 == NULL || tmp1 == NULL) goto err;
1561
1562 /* Before converting the individual points, compute inverses of all Z values.
1563 * Modular inversion is rather slow, but luckily we can do with a single
1564 * explicit inversion, plus about 3 multiplications per input value.
1565 */
1566
1567 pow2 = 1;
1568 while (num > pow2)
1569 pow2 <<= 1;
1570 /* Now pow2 is the smallest power of 2 satifsying pow2 >= num.
1571 * We need twice that. */
1572 pow2 <<= 1;
1573
1574 heap = OPENSSL_malloc(pow2 * sizeof heap[0]);
1575 if (heap == NULL) goto err;
1576
1577 /* The array is used as a binary tree, exactly as in heapsort:
1578 *
1579 * heap[1]
1580 * heap[2] heap[3]
1581 * heap[4] heap[5] heap[6] heap[7]
1582 * heap[8]heap[9] heap[10]heap[11] heap[12]heap[13] heap[14] heap[15]
1583 *
1584 * We put the Z's in the last line;
1585 * then we set each other node to the product of its two child-nodes (where
1586 * empty or 0 entries are treated as ones);
1587 * then we invert heap[1];
1588 * then we invert each other node by replacing it by the product of its
1589 * parent (after inversion) and its sibling (before inversion).
1590 */
1591 heap[0] = NULL;
1592 for (i = pow2/2 - 1; i > 0; i--)
1593 heap[i] = NULL;
1594 for (i = 0; i < num; i++)
1595 heap[pow2/2 + i] = &points[i]->Z;
1596 for (i = pow2/2 + num; i < pow2; i++)
1597 heap[i] = NULL;
1598
1599 /* set each node to the product of its children */
1600 for (i = pow2/2 - 1; i > 0; i--)
1601 {
1602 heap[i] = BN_new();
1603 if (heap[i] == NULL) goto err;
1604
1605 if (heap[2*i] != NULL)
1606 {
1607 if ((heap[2*i + 1] == NULL) || BN_is_zero(heap[2*i + 1]))
1608 {
1609 if (!BN_copy(heap[i], heap[2*i])) goto err;
1610 }
1611 else
1612 {
1613 if (BN_is_zero(heap[2*i]))
1614 {
1615 if (!BN_copy(heap[i], heap[2*i + 1])) goto err;
1616 }
1617 else
1618 {
1619 if (!group->meth->field_mul(group, heap[i],
1620 heap[2*i], heap[2*i + 1], ctx)) goto err;
1621 }
1622 }
1623 }
1624 }
1625
1626 /* invert heap[1] */
1627 if (!BN_is_zero(heap[1]))
1628 {
1629 if (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))
1630 {
1631 ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);
1632 goto err;
1633 }
1634 }
1635 if (group->meth->field_encode != 0)
1636 {
1637 /* in the Montgomery case, we just turned R*H (representing H)
1638 * into 1/(R*H), but we need R*(1/H) (representing 1/H);
1639 * i.e. we have need to multiply by the Montgomery factor twice */
1640 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1641 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1642 }
1643
1644 /* set other heap[i]'s to their inverses */
1645 for (i = 2; i < pow2/2 + num; i += 2)
1646 {
1647 /* i is even */
1648 if ((heap[i + 1] != NULL) && !BN_is_zero(heap[i + 1]))
1649 {
1650 if (!group->meth->field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx)) goto err;
1651 if (!group->meth->field_mul(group, tmp1, heap[i/2], heap[i], ctx)) goto err;
1652 if (!BN_copy(heap[i], tmp0)) goto err;
1653 if (!BN_copy(heap[i + 1], tmp1)) goto err;
1654 }
1655 else
1656 {
1657 if (!BN_copy(heap[i], heap[i/2])) goto err;
1658 }
1659 }
1660
1661 /* we have replaced all non-zero Z's by their inverses, now fix up all the points */
1662 for (i = 0; i < num; i++)
1663 {
1664 EC_POINT *p = points[i];
1665
1666 if (!BN_is_zero(&p->Z))
1667 {
1668 /* turn (X, Y, 1/Z) into (X/Z^2, Y/Z^3, 1) */
1669
1670 if (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;
1671 if (!group->meth->field_mul(group, &p->X, &p->X, tmp1, ctx)) goto err;
1672
1673 if (!group->meth->field_mul(group, tmp1, tmp1, &p->Z, ctx)) goto err;
1674 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp1, ctx)) goto err;
1675
1676 if (group->meth->field_set_to_one != 0)
1677 {
1678 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
1679 }
1680 else
1681 {
1682 if (!BN_one(&p->Z)) goto err;
1683 }
1684 p->Z_is_one = 1;
1685 }
1686 }
1687
1688 ret = 1;
1689
1690 err:
1691 BN_CTX_end(ctx);
1692 if (new_ctx != NULL)
1693 BN_CTX_free(new_ctx);
1694 if (heap != NULL)
1695 {
1696 /* heap[pow2/2] .. heap[pow2-1] have not been allocated locally! */
1697 for (i = pow2/2 - 1; i > 0; i--)
1698 {
1699 if (heap[i] != NULL)
1700 BN_clear_free(heap[i]);
1701 }
1702 OPENSSL_free(heap);
1703 }
1704 return ret;
1705 }
1706
1707
1708int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1709 {
1710 return BN_mod_mul(r, a, b, &group->field, ctx);
1711 }
1712
1713
1714int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1715 {
1716 return BN_mod_sqr(r, a, &group->field, ctx);
1717 }
diff --git a/src/lib/libcrypto/ec/ectest.c b/src/lib/libcrypto/ec/ectest.c
index 345d3e4289..fcf969f3cf 100644
--- a/src/lib/libcrypto/ec/ectest.c
+++ b/src/lib/libcrypto/ec/ectest.c
@@ -197,7 +197,7 @@ int main(int argc, char *argv[])
197 EC_GROUP *tmp; 197 EC_GROUP *tmp;
198 tmp = EC_GROUP_new(EC_GROUP_method_of(group)); 198 tmp = EC_GROUP_new(EC_GROUP_method_of(group));
199 if (!tmp) ABORT; 199 if (!tmp) ABORT;
200 if (!EC_GROUP_copy(tmp, group)); 200 if (!EC_GROUP_copy(tmp, group)) ABORT;
201 EC_GROUP_free(group); 201 EC_GROUP_free(group);
202 group = tmp; 202 group = tmp;
203 } 203 }
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/README b/src/lib/libcrypto/engine/README
new file mode 100644
index 0000000000..6b69b70f57
--- /dev/null
+++ b/src/lib/libcrypto/engine/README
@@ -0,0 +1,211 @@
1Notes: 2001-09-24
2-----------------
3
4This "description" (if one chooses to call it that) needed some major updating
5so here goes. This update addresses a change being made at the same time to
6OpenSSL, and it pretty much completely restructures the underlying mechanics of
7the "ENGINE" code. So it serves a double purpose of being a "ENGINE internals
8for masochists" document *and* a rather extensive commit log message. (I'd get
9lynched for sticking all this in CHANGES or the commit mails :-).
10
11ENGINE_TABLE underlies this restructuring, as described in the internal header
12"eng_int.h", implemented in eng_table.c, and used in each of the "class" files;
13tb_rsa.c, tb_dsa.c, etc.
14
15However, "EVP_CIPHER" underlies the motivation and design of ENGINE_TABLE so
16I'll mention a bit about that first. EVP_CIPHER (and most of this applies
17equally to EVP_MD for digests) is both a "method" and a algorithm/mode
18identifier that, in the current API, "lingers". These cipher description +
19implementation structures can be defined or obtained directly by applications,
20or can be loaded "en masse" into EVP storage so that they can be catalogued and
21searched in various ways, ie. two ways of encrypting with the "des_cbc"
22algorithm/mode pair are;
23
24(i) directly;
25 const EVP_CIPHER *cipher = EVP_des_cbc();
26 EVP_EncryptInit(&ctx, cipher, key, iv);
27 [ ... use EVP_EncryptUpdate() and EVP_EncryptFinal() ...]
28
29(ii) indirectly;
30 OpenSSL_add_all_ciphers();
31 cipher = EVP_get_cipherbyname("des_cbc");
32 EVP_EncryptInit(&ctx, cipher, key, iv);
33 [ ... etc ... ]
34
35The latter is more generally used because it also allows ciphers/digests to be
36looked up based on other identifiers which can be useful for automatic cipher
37selection, eg. in SSL/TLS, or by user-controllable configuration.
38
39The important point about this is that EVP_CIPHER definitions and structures are
40passed around with impunity and there is no safe way, without requiring massive
41rewrites of many applications, to assume that EVP_CIPHERs can be reference
42counted. One an EVP_CIPHER is exposed to the caller, neither it nor anything it
43comes from can "safely" be destroyed. Unless of course the way of getting to
44such ciphers is via entirely distinct API calls that didn't exist before.
45However existing API usage cannot be made to understand when an EVP_CIPHER
46pointer, that has been passed to the caller, is no longer being used.
47
48The other problem with the existing API w.r.t. to hooking EVP_CIPHER support
49into ENGINE is storage - the OBJ_NAME-based storage used by EVP to register
50ciphers simultaneously registers cipher *types* and cipher *implementations* -
51they are effectively the same thing, an "EVP_CIPHER" pointer. The problem with
52hooking in ENGINEs is that multiple ENGINEs may implement the same ciphers. The
53solution is necessarily that ENGINE-provided ciphers simply are not registered,
54stored, or exposed to the caller in the same manner as existing ciphers. This is
55especially necessary considering the fact ENGINE uses reference counts to allow
56for cleanup, modularity, and DSO support - yet EVP_CIPHERs, as exposed to
57callers in the current API, support no such controls.
58
59Another sticking point for integrating cipher support into ENGINE is linkage.
60Already there is a problem with the way ENGINE supports RSA, DSA, etc whereby
61they are available *because* they're part of a giant ENGINE called "openssl".
62Ie. all implementations *have* to come from an ENGINE, but we get round that by
63having a giant ENGINE with all the software support encapsulated. This creates
64linker hassles if nothing else - linking a 1-line application that calls 2 basic
65RSA functions (eg. "RSA_free(RSA_new());") will result in large quantities of
66ENGINE code being linked in *and* because of that DSA, DH, and RAND also. If we
67continue with this approach for EVP_CIPHER support (even if it *was* possible)
68we would lose our ability to link selectively by selectively loading certain
69implementations of certain functionality. Touching any part of any kind of
70crypto would result in massive static linkage of everything else. So the
71solution is to change the way ENGINE feeds existing "classes", ie. how the
72hooking to ENGINE works from RSA, DSA, DH, RAND, as well as adding new hooking
73for EVP_CIPHER, and EVP_MD.
74
75The way this is now being done is by mostly reverting back to how things used to
76work prior to ENGINE :-). Ie. RSA now has a "RSA_METHOD" pointer again - this
77was previously replaced by an "ENGINE" pointer and all RSA code that required
78the RSA_METHOD would call ENGINE_get_RSA() each time on its ENGINE handle to
79temporarily get and use the ENGINE's RSA implementation. Apart from being more
80efficient, switching back to each RSA having an RSA_METHOD pointer also allows
81us to conceivably operate with *no* ENGINE. As we'll see, this removes any need
82for a fallback ENGINE that encapsulates default implementations - we can simply
83have our RSA structure pointing its RSA_METHOD pointer to the software
84implementation and have its ENGINE pointer set to NULL.
85
86A look at the EVP_CIPHER hooking is most explanatory, the RSA, DSA (etc) cases
87turn out to be degenerate forms of the same thing. The EVP storage of ciphers,
88and the existing EVP API functions that return "software" implementations and
89descriptions remain untouched. However, the storage takes more meaning in terms
90of "cipher description" and less meaning in terms of "implementation". When an
91EVP_CIPHER_CTX is actually initialised with an EVP_CIPHER method and is about to
92begin en/decryption, the hooking to ENGINE comes into play. What happens is that
93cipher-specific ENGINE code is asked for an ENGINE pointer (a functional
94reference) for any ENGINE that is registered to perform the algo/mode that the
95provided EVP_CIPHER structure represents. Under normal circumstances, that
96ENGINE code will return NULL because no ENGINEs will have had any cipher
97implementations *registered*. As such, a NULL ENGINE pointer is stored in the
98EVP_CIPHER_CTX context, and the EVP_CIPHER structure is left hooked into the
99context and so is used as the implementation. Pretty much how things work now
100except we'd have a redundant ENGINE pointer set to NULL and doing nothing.
101
102Conversely, if an ENGINE *has* been registered to perform the algorithm/mode
103combination represented by the provided EVP_CIPHER, then a functional reference
104to that ENGINE will be returned to the EVP_CIPHER_CTX during initialisation.
105That functional reference will be stored in the context (and released on
106cleanup) - and having that reference provides a *safe* way to use an EVP_CIPHER
107definition that is private to the ENGINE. Ie. the EVP_CIPHER provided by the
108application will actually be replaced by an EVP_CIPHER from the registered
109ENGINE - it will support the same algorithm/mode as the original but will be a
110completely different implementation. Because this EVP_CIPHER isn't stored in the
111EVP storage, nor is it returned to applications from traditional API functions,
112there is no associated problem with it not having reference counts. And of
113course, when one of these "private" cipher implementations is hooked into
114EVP_CIPHER_CTX, it is done whilst the EVP_CIPHER_CTX holds a functional
115reference to the ENGINE that owns it, thus the use of the ENGINE's EVP_CIPHER is
116safe.
117
118The "cipher-specific ENGINE code" I mentioned is implemented in tb_cipher.c but
119in essence it is simply an instantiation of "ENGINE_TABLE" code for use by
120EVP_CIPHER code. tb_digest.c is virtually identical but, of course, it is for
121use by EVP_MD code. Ditto for tb_rsa.c, tb_dsa.c, etc. These instantiations of
122ENGINE_TABLE essentially provide linker-separation of the classes so that even
123if ENGINEs implement *all* possible algorithms, an application using only
124EVP_CIPHER code will link at most code relating to EVP_CIPHER, tb_cipher.c, core
125ENGINE code that is independant of class, and of course the ENGINE
126implementation that the application loaded. It will *not* however link any
127class-specific ENGINE code for digests, RSA, etc nor will it bleed over into
128other APIs, such as the RSA/DSA/etc library code.
129
130ENGINE_TABLE is a little more complicated than may seem necessary but this is
131mostly to avoid a lot of "init()"-thrashing on ENGINEs (that may have to load
132DSOs, and other expensive setup that shouldn't be thrashed unnecessarily) *and*
133to duplicate "default" behaviour. Basically an ENGINE_TABLE instantiation, for
134example tb_cipher.c, implements a hash-table keyed by integer "nid" values.
135These nids provide the uniquenness of an algorithm/mode - and each nid will hash
136to a potentially NULL "ENGINE_PILE". An ENGINE_PILE is essentially a list of
137pointers to ENGINEs that implement that particular 'nid'. Each "pile" uses some
138caching tricks such that requests on that 'nid' will be cached and all future
139requests will return immediately (well, at least with minimal operation) unless
140a change is made to the pile, eg. perhaps an ENGINE was unloaded. The reason is
141that an application could have support for 10 ENGINEs statically linked
142in, and the machine in question may not have any of the hardware those 10
143ENGINEs support. If each of those ENGINEs has a "des_cbc" implementation, we
144want to avoid every EVP_CIPHER_CTX setup from trying (and failing) to initialise
145each of those 10 ENGINEs. Instead, the first such request will try to do that
146and will either return (and cache) a NULL ENGINE pointer or will return a
147functional reference to the first that successfully initialised. In the latter
148case it will also cache an extra functional reference to the ENGINE as a
149"default" for that 'nid'. The caching is acknowledged by a 'uptodate' variable
150that is unset only if un/registration takes place on that pile. Ie. if
151implementations of "des_cbc" are added or removed. This behaviour can be
152tweaked; the ENGINE_TABLE_FLAG_NOINIT value can be passed to
153ENGINE_set_table_flags(), in which case the only ENGINEs that tb_cipher.c will
154try to initialise from the "pile" will be those that are already initialised
155(ie. it's simply an increment of the functional reference count, and no real
156"initialisation" will take place).
157
158RSA, DSA, DH, and RAND all have their own ENGINE_TABLE code as well, and the
159difference is that they all use an implicit 'nid' of 1. Whereas EVP_CIPHERs are
160actually qualitatively different depending on 'nid' (the "des_cbc" EVP_CIPHER is
161not an interoperable implementation of "aes_256_cbc"), RSA_METHODs are
162necessarily interoperable and don't have different flavours, only different
163implementations. In other words, the ENGINE_TABLE for RSA will either be empty,
164or will have a single ENGING_PILE hashed to by the 'nid' 1 and that pile
165represents ENGINEs that implement the single "type" of RSA there is.
166
167Cleanup - the registration and unregistration may pose questions about how
168cleanup works with the ENGINE_PILE doing all this caching nonsense (ie. when the
169application or EVP_CIPHER code releases its last reference to an ENGINE, the
170ENGINE_PILE code may still have references and thus those ENGINEs will stay
171hooked in forever). The way this is handled is via "unregistration". With these
172new ENGINE changes, an abstract ENGINE can be loaded and initialised, but that
173is an algorithm-agnostic process. Even if initialised, it will not have
174registered any of its implementations (to do so would link all class "table"
175code despite the fact the application may use only ciphers, for example). This
176is deliberately a distinct step. Moreover, registration and unregistration has
177nothing to do with whether an ENGINE is *functional* or not (ie. you can even
178register an ENGINE and its implementations without it being operational, you may
179not even have the drivers to make it operate). What actually happens with
180respect to cleanup is managed inside eng_lib.c with the "engine_cleanup_***"
181functions. These functions are internal-only and each part of ENGINE code that
182could require cleanup will, upon performing its first allocation, register a
183callback with the "engine_cleanup" code. The other part of this that makes it
184tick is that the ENGINE_TABLE instantiations (tb_***.c) use NULL as their
185initialised state. So if RSA code asks for an ENGINE and no ENGINE has
186registered an implementation, the code will simply return NULL and the tb_rsa.c
187state will be unchanged. Thus, no cleanup is required unless registration takes
188place. ENGINE_cleanup() will simply iterate across a list of registered cleanup
189callbacks calling each in turn, and will then internally delete its own storage
190(a STACK). When a cleanup callback is next registered (eg. if the cleanup() is
191part of a gracefull restart and the application wants to cleanup all state then
192start again), the internal STACK storage will be freshly allocated. This is much
193the same as the situation in the ENGINE_TABLE instantiations ... NULL is the
194initialised state, so only modification operations (not queries) will cause that
195code to have to register a cleanup.
196
197What else? The bignum callbacks and associated ENGINE functions have been
198removed for two obvious reasons; (i) there was no way to generalise them to the
199mechanism now used by RSA/DSA/..., because there's no such thing as a BIGNUM
200method, and (ii) because of (i), there was no meaningful way for library or
201application code to automatically hook and use ENGINE supplied bignum functions
202anyway. Also, ENGINE_cpy() has been removed (although an internal-only version
203exists) - the idea of providing an ENGINE_cpy() function probably wasn't a good
204one and now certainly doesn't make sense in any generalised way. Some of the
205RSA, DSA, DH, and RAND functions that were fiddled during the original ENGINE
206changes have now, as a consequence, been reverted back. This is because the
207hooking of ENGINE is now automatic (and passive, it can interally use a NULL
208ENGINE pointer to simply ignore ENGINE from then on).
209
210Hell, that should be enough for now ... comments welcome: geoff@openssl.org
211
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c
new file mode 100644
index 0000000000..0f6992a40d
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_all.c
@@ -0,0 +1,113 @@
1/* crypto/engine/eng_all.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/err.h>
60#include <openssl/engine.h>
61#include "eng_int.h"
62
63void ENGINE_load_builtin_engines(void)
64 {
65 /* There's no longer any need for an "openssl" ENGINE unless, one day,
66 * it is the *only* way for standard builtin implementations to be be
67 * accessed (ie. it would be possible to statically link binaries with
68 * *no* builtin implementations). */
69#if 0
70 ENGINE_load_openssl();
71#endif
72 ENGINE_load_dynamic();
73#ifndef OPENSSL_NO_HW
74#ifndef OPENSSL_NO_HW_CSWIFT
75 ENGINE_load_cswift();
76#endif
77#ifndef OPENSSL_NO_HW_NCIPHER
78 ENGINE_load_chil();
79#endif
80#ifndef OPENSSL_NO_HW_ATALLA
81 ENGINE_load_atalla();
82#endif
83#ifndef OPENSSL_NO_HW_NURON
84 ENGINE_load_nuron();
85#endif
86#ifndef OPENSSL_NO_HW_UBSEC
87 ENGINE_load_ubsec();
88#endif
89#ifndef OPENSSL_NO_HW_AEP
90 ENGINE_load_aep();
91#endif
92#ifndef OPENSSL_NO_HW_SUREWARE
93 ENGINE_load_sureware();
94#endif
95#ifndef OPENSSL_NO_HW_4758_CCA
96 ENGINE_load_4758cca();
97#endif
98#if defined(__OpenBSD__) || defined(__FreeBSD__)
99 ENGINE_load_cryptodev();
100#endif
101#endif
102 }
103
104#if defined(__OpenBSD__) || defined(__FreeBSD__)
105void ENGINE_setup_bsd_cryptodev(void) {
106 static int bsd_cryptodev_default_loaded = 0;
107 if (!bsd_cryptodev_default_loaded) {
108 ENGINE_load_cryptodev();
109 ENGINE_register_all_complete();
110 }
111 bsd_cryptodev_default_loaded=1;
112}
113#endif
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c
new file mode 100644
index 0000000000..cdf670901a
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_cnf.c
@@ -0,0 +1,242 @@
1/* eng_cnf.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/engine.h>
64
65/* #define ENGINE_CONF_DEBUG */
66
67/* ENGINE config module */
68
69static char *skip_dot(char *name)
70 {
71 char *p;
72 p = strchr(name, '.');
73 if (p)
74 return p + 1;
75 return name;
76 }
77
78static STACK_OF(ENGINE) *initialized_engines = NULL;
79
80static int int_engine_init(ENGINE *e)
81 {
82 if (!ENGINE_init(e))
83 return 0;
84 if (!initialized_engines)
85 initialized_engines = sk_ENGINE_new_null();
86 if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e))
87 {
88 ENGINE_finish(e);
89 return 0;
90 }
91 return 1;
92 }
93
94
95static int int_engine_configure(char *name, char *value, const CONF *cnf)
96 {
97 int i;
98 int ret = 0;
99 long do_init = -1;
100 STACK_OF(CONF_VALUE) *ecmds;
101 CONF_VALUE *ecmd;
102 char *ctrlname, *ctrlvalue;
103 ENGINE *e = NULL;
104 name = skip_dot(name);
105#ifdef ENGINE_CONF_DEBUG
106 fprintf(stderr, "Configuring engine %s\n", name);
107#endif
108 /* Value is a section containing ENGINE commands */
109 ecmds = NCONF_get_section(cnf, value);
110
111 if (!ecmds)
112 {
113 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR);
114 return 0;
115 }
116
117 for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++)
118 {
119 ecmd = sk_CONF_VALUE_value(ecmds, i);
120 ctrlname = skip_dot(ecmd->name);
121 ctrlvalue = ecmd->value;
122#ifdef ENGINE_CONF_DEBUG
123 fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue);
124#endif
125
126 /* First handle some special pseudo ctrls */
127
128 /* Override engine name to use */
129 if (!strcmp(ctrlname, "engine_id"))
130 name = ctrlvalue;
131 /* Load a dynamic ENGINE */
132 else if (!strcmp(ctrlname, "dynamic_path"))
133 {
134 e = ENGINE_by_id("dynamic");
135 if (!e)
136 goto err;
137 if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
138 goto err;
139 if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
140 goto err;
141 if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
142 goto err;
143 }
144 /* ... add other pseudos here ... */
145 else
146 {
147 /* At this point we need an ENGINE structural reference
148 * if we don't already have one.
149 */
150 if (!e)
151 {
152 e = ENGINE_by_id(name);
153 if (!e)
154 return 0;
155 }
156 /* Allow "EMPTY" to mean no value: this allows a valid
157 * "value" to be passed to ctrls of type NO_INPUT
158 */
159 if (!strcmp(ctrlvalue, "EMPTY"))
160 ctrlvalue = NULL;
161 else if (!strcmp(ctrlname, "init"))
162 {
163 if (!NCONF_get_number_e(cnf, value, "init", &do_init))
164 goto err;
165 if (do_init == 1)
166 {
167 if (!int_engine_init(e))
168 goto err;
169 }
170 else if (do_init != 0)
171 {
172 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE);
173 goto err;
174 }
175 }
176 else if (!strcmp(ctrlname, "default_algorithms"))
177 {
178 if (!ENGINE_set_default_string(e, ctrlvalue))
179 goto err;
180 }
181 else if (!ENGINE_ctrl_cmd_string(e,
182 ctrlname, ctrlvalue, 0))
183 return 0;
184 }
185
186
187
188 }
189 if (e && (do_init == -1) && !int_engine_init(e))
190 goto err;
191 ret = 1;
192 err:
193 if (e)
194 ENGINE_free(e);
195 return ret;
196 }
197
198
199static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
200 {
201 STACK_OF(CONF_VALUE) *elist;
202 CONF_VALUE *cval;
203 int i;
204#ifdef ENGINE_CONF_DEBUG
205 fprintf(stderr, "Called engine module: name %s, value %s\n",
206 CONF_imodule_get_name(md), CONF_imodule_get_value(md));
207#endif
208 /* Value is a section containing ENGINEs to configure */
209 elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
210
211 if (!elist)
212 {
213 ENGINEerr(ENGINE_F_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
214 return 0;
215 }
216
217 for (i = 0; i < sk_CONF_VALUE_num(elist); i++)
218 {
219 cval = sk_CONF_VALUE_value(elist, i);
220 if (!int_engine_configure(cval->name, cval->value, cnf))
221 return 0;
222 }
223
224 return 1;
225 }
226
227static void int_engine_module_finish(CONF_IMODULE *md)
228 {
229 ENGINE *e;
230 while ((e = sk_ENGINE_pop(initialized_engines)))
231 ENGINE_finish(e);
232 sk_ENGINE_free(initialized_engines);
233 initialized_engines = NULL;
234 }
235
236
237void ENGINE_add_conf_module(void)
238 {
239 CONF_module_add("engines",
240 int_engine_module_init,
241 int_engine_module_finish);
242 }
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
new file mode 100644
index 0000000000..412c73fb0f
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_ctrl.c
@@ -0,0 +1,391 @@
1/* crypto/engine/eng_ctrl.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* When querying a ENGINE-specific control command's 'description', this string
62 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
63static const char *int_no_description = "";
64
65/* These internal functions handle 'CMD'-related control commands when the
66 * ENGINE in question has asked us to take care of it (ie. the ENGINE did not
67 * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
68
69static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn)
70 {
71 if((defn->cmd_num == 0) || (defn->cmd_name == NULL))
72 return 1;
73 return 0;
74 }
75
76static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s)
77 {
78 int idx = 0;
79 while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0))
80 {
81 idx++;
82 defn++;
83 }
84 if(int_ctrl_cmd_is_null(defn))
85 /* The given name wasn't found */
86 return -1;
87 return idx;
88 }
89
90static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
91 {
92 int idx = 0;
93 /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
94 * our searches don't need to take any longer than necessary. */
95 while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num))
96 {
97 idx++;
98 defn++;
99 }
100 if(defn->cmd_num == num)
101 return idx;
102 /* The given cmd_num wasn't found */
103 return -1;
104 }
105
106static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
107 {
108 int idx;
109 char *s = (char *)p;
110 /* Take care of the easy one first (eg. it requires no searches) */
111 if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE)
112 {
113 if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns))
114 return 0;
115 return e->cmd_defns->cmd_num;
116 }
117 /* One or two commands require that "p" be a valid string buffer */
118 if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
119 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
120 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD))
121 {
122 if(s == NULL)
123 {
124 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
125 ERR_R_PASSED_NULL_PARAMETER);
126 return -1;
127 }
128 }
129 /* Now handle cmd_name -> cmd_num conversion */
130 if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME)
131 {
132 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name(
133 e->cmd_defns, s)) < 0))
134 {
135 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
136 ENGINE_R_INVALID_CMD_NAME);
137 return -1;
138 }
139 return e->cmd_defns[idx].cmd_num;
140 }
141 /* For the rest of the commands, the 'long' argument must specify a
142 * valie command number - so we need to conduct a search. */
143 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns,
144 (unsigned int)i)) < 0))
145 {
146 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
147 ENGINE_R_INVALID_CMD_NUMBER);
148 return -1;
149 }
150 /* Now the logic splits depending on command type */
151 switch(cmd)
152 {
153 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
154 idx++;
155 if(int_ctrl_cmd_is_null(e->cmd_defns + idx))
156 /* end-of-list */
157 return 0;
158 else
159 return e->cmd_defns[idx].cmd_num;
160 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
161 return strlen(e->cmd_defns[idx].cmd_name);
162 case ENGINE_CTRL_GET_NAME_FROM_CMD:
163 return BIO_snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1,
164 "%s", e->cmd_defns[idx].cmd_name);
165 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
166 if(e->cmd_defns[idx].cmd_desc)
167 return strlen(e->cmd_defns[idx].cmd_desc);
168 return strlen(int_no_description);
169 case ENGINE_CTRL_GET_DESC_FROM_CMD:
170 if(e->cmd_defns[idx].cmd_desc)
171 return BIO_snprintf(s,
172 strlen(e->cmd_defns[idx].cmd_desc) + 1,
173 "%s", e->cmd_defns[idx].cmd_desc);
174 return BIO_snprintf(s, strlen(int_no_description) + 1,"%s",
175 int_no_description);
176 case ENGINE_CTRL_GET_CMD_FLAGS:
177 return e->cmd_defns[idx].cmd_flags;
178 }
179 /* Shouldn't really be here ... */
180 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR);
181 return -1;
182 }
183
184int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
185 {
186 int ctrl_exists, ref_exists;
187 if(e == NULL)
188 {
189 ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
190 return 0;
191 }
192 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
193 ref_exists = ((e->struct_ref > 0) ? 1 : 0);
194 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
195 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
196 if(!ref_exists)
197 {
198 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE);
199 return 0;
200 }
201 /* Intercept any "root-level" commands before trying to hand them on to
202 * ctrl() handlers. */
203 switch(cmd)
204 {
205 case ENGINE_CTRL_HAS_CTRL_FUNCTION:
206 return ctrl_exists;
207 case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
208 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
209 case ENGINE_CTRL_GET_CMD_FROM_NAME:
210 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
211 case ENGINE_CTRL_GET_NAME_FROM_CMD:
212 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
213 case ENGINE_CTRL_GET_DESC_FROM_CMD:
214 case ENGINE_CTRL_GET_CMD_FLAGS:
215 if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
216 return int_ctrl_helper(e,cmd,i,p,f);
217 if(!ctrl_exists)
218 {
219 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
220 /* For these cmd-related functions, failure is indicated
221 * by a -1 return value (because 0 is used as a valid
222 * return in some places). */
223 return -1;
224 }
225 default:
226 break;
227 }
228 /* Anything else requires a ctrl() handler to exist. */
229 if(!ctrl_exists)
230 {
231 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
232 return 0;
233 }
234 return e->ctrl(e, cmd, i, p, f);
235 }
236
237int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
238 {
239 int flags;
240 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0)
241 {
242 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,
243 ENGINE_R_INVALID_CMD_NUMBER);
244 return 0;
245 }
246 if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
247 !(flags & ENGINE_CMD_FLAG_NUMERIC) &&
248 !(flags & ENGINE_CMD_FLAG_STRING))
249 return 0;
250 return 1;
251 }
252
253int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
254 long i, void *p, void (*f)(), int cmd_optional)
255 {
256 int num;
257
258 if((e == NULL) || (cmd_name == NULL))
259 {
260 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
261 ERR_R_PASSED_NULL_PARAMETER);
262 return 0;
263 }
264 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
265 ENGINE_CTRL_GET_CMD_FROM_NAME,
266 0, (void *)cmd_name, NULL)) <= 0))
267 {
268 /* If the command didn't *have* to be supported, we fake
269 * success. This allows certain settings to be specified for
270 * multiple ENGINEs and only require a change of ENGINE id
271 * (without having to selectively apply settings). Eg. changing
272 * from a hardware device back to the regular software ENGINE
273 * without editing the config file, etc. */
274 if(cmd_optional)
275 {
276 ERR_clear_error();
277 return 1;
278 }
279 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
280 ENGINE_R_INVALID_CMD_NAME);
281 return 0;
282 }
283 /* Force the result of the control command to 0 or 1, for the reasons
284 * mentioned before. */
285 if (ENGINE_ctrl(e, num, i, p, f))
286 return 1;
287 return 0;
288 }
289
290int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
291 int cmd_optional)
292 {
293 int num, flags;
294 long l;
295 char *ptr;
296 if((e == NULL) || (cmd_name == NULL))
297 {
298 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
299 ERR_R_PASSED_NULL_PARAMETER);
300 return 0;
301 }
302 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
303 ENGINE_CTRL_GET_CMD_FROM_NAME,
304 0, (void *)cmd_name, NULL)) <= 0))
305 {
306 /* If the command didn't *have* to be supported, we fake
307 * success. This allows certain settings to be specified for
308 * multiple ENGINEs and only require a change of ENGINE id
309 * (without having to selectively apply settings). Eg. changing
310 * from a hardware device back to the regular software ENGINE
311 * without editing the config file, etc. */
312 if(cmd_optional)
313 {
314 ERR_clear_error();
315 return 1;
316 }
317 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
318 ENGINE_R_INVALID_CMD_NAME);
319 return 0;
320 }
321 if(!ENGINE_cmd_is_executable(e, num))
322 {
323 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
324 ENGINE_R_CMD_NOT_EXECUTABLE);
325 return 0;
326 }
327 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0)
328 {
329 /* Shouldn't happen, given that ENGINE_cmd_is_executable()
330 * returned success. */
331 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
332 ENGINE_R_INTERNAL_LIST_ERROR);
333 return 0;
334 }
335 /* If the command takes no input, there must be no input. And vice
336 * versa. */
337 if(flags & ENGINE_CMD_FLAG_NO_INPUT)
338 {
339 if(arg != NULL)
340 {
341 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
342 ENGINE_R_COMMAND_TAKES_NO_INPUT);
343 return 0;
344 }
345 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
346 * rather than returning it as "return data". This is to ensure
347 * usage of these commands is consistent across applications and
348 * that certain applications don't understand it one way, and
349 * others another. */
350 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
351 return 1;
352 return 0;
353 }
354 /* So, we require input */
355 if(arg == NULL)
356 {
357 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
358 ENGINE_R_COMMAND_TAKES_INPUT);
359 return 0;
360 }
361 /* If it takes string input, that's easy */
362 if(flags & ENGINE_CMD_FLAG_STRING)
363 {
364 /* Same explanation as above */
365 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
366 return 1;
367 return 0;
368 }
369 /* If it doesn't take numeric either, then it is unsupported for use in
370 * a config-setting situation, which is what this function is for. This
371 * should never happen though, because ENGINE_cmd_is_executable() was
372 * used. */
373 if(!(flags & ENGINE_CMD_FLAG_NUMERIC))
374 {
375 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
376 ENGINE_R_INTERNAL_LIST_ERROR);
377 return 0;
378 }
379 l = strtol(arg, &ptr, 10);
380 if((arg == ptr) || (*ptr != '\0'))
381 {
382 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
383 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
384 return 0;
385 }
386 /* Force the result of the control command to 0 or 1, for the reasons
387 * mentioned before. */
388 if(ENGINE_ctrl(e, num, l, NULL, NULL))
389 return 1;
390 return 0;
391 }
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c
new file mode 100644
index 0000000000..4139a16e76
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_dyn.c
@@ -0,0 +1,460 @@
1/* crypto/engine/eng_dyn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include "eng_int.h"
64#include <openssl/engine.h>
65#include <openssl/dso.h>
66
67/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader
68 * should implement the hook-up functions with the following prototypes. */
69
70/* Our ENGINE handlers */
71static int dynamic_init(ENGINE *e);
72static int dynamic_finish(ENGINE *e);
73static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
74/* Predeclare our context type */
75typedef struct st_dynamic_data_ctx dynamic_data_ctx;
76/* The implementation for the important control command */
77static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx);
78
79#define DYNAMIC_CMD_SO_PATH ENGINE_CMD_BASE
80#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1)
81#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2)
82#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3)
83#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 4)
84
85/* The constants used when creating the ENGINE */
86static const char *engine_dynamic_id = "dynamic";
87static const char *engine_dynamic_name = "Dynamic engine loading support";
88static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = {
89 {DYNAMIC_CMD_SO_PATH,
90 "SO_PATH",
91 "Specifies the path to the new ENGINE shared library",
92 ENGINE_CMD_FLAG_STRING},
93 {DYNAMIC_CMD_NO_VCHECK,
94 "NO_VCHECK",
95 "Specifies to continue even if version checking fails (boolean)",
96 ENGINE_CMD_FLAG_NUMERIC},
97 {DYNAMIC_CMD_ID,
98 "ID",
99 "Specifies an ENGINE id name for loading",
100 ENGINE_CMD_FLAG_STRING},
101 {DYNAMIC_CMD_LIST_ADD,
102 "LIST_ADD",
103 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)",
104 ENGINE_CMD_FLAG_NUMERIC},
105 {DYNAMIC_CMD_LOAD,
106 "LOAD",
107 "Load up the ENGINE specified by other settings",
108 ENGINE_CMD_FLAG_NO_INPUT},
109 {0, NULL, NULL, 0}
110 };
111static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = {
112 {0, NULL, NULL, 0}
113 };
114
115/* Loading code stores state inside the ENGINE structure via the "ex_data"
116 * element. We load all our state into a single structure and use that as a
117 * single context in the "ex_data" stack. */
118struct st_dynamic_data_ctx
119 {
120 /* The DSO object we load that supplies the ENGINE code */
121 DSO *dynamic_dso;
122 /* The function pointer to the version checking shared library function */
123 dynamic_v_check_fn v_check;
124 /* The function pointer to the engine-binding shared library function */
125 dynamic_bind_engine bind_engine;
126 /* The default name/path for loading the shared library */
127 const char *DYNAMIC_LIBNAME;
128 /* Whether to continue loading on a version check failure */
129 int no_vcheck;
130 /* If non-NULL, stipulates the 'id' of the ENGINE to be loaded */
131 const char *engine_id;
132 /* If non-zero, a successfully loaded ENGINE should be added to the internal
133 * ENGINE list. If 2, the add must succeed or the entire load should fail. */
134 int list_add_value;
135 /* The symbol name for the version checking function */
136 const char *DYNAMIC_F1;
137 /* The symbol name for the "initialise ENGINE structure" function */
138 const char *DYNAMIC_F2;
139 };
140
141/* This is the "ex_data" index we obtain and reserve for use with our context
142 * structure. */
143static int dynamic_ex_data_idx = -1;
144
145/* Because our ex_data element may or may not get allocated depending on whether
146 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
147 * problem to solve. We can't declare a "new" handler for the ex_data as we
148 * don't want a dynamic_data_ctx in *all* ENGINE structures of all types (this
149 * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free"
150 * handler and that will get called if an ENGINE is being destroyed and there
151 * was an ex_data element corresponding to our context type. */
152static void dynamic_data_ctx_free_func(void *parent, void *ptr,
153 CRYPTO_EX_DATA *ad, int idx, long argl, void *argp)
154 {
155 if(ptr)
156 {
157 dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr;
158 if(ctx->dynamic_dso)
159 DSO_free(ctx->dynamic_dso);
160 if(ctx->DYNAMIC_LIBNAME)
161 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
162 if(ctx->engine_id)
163 OPENSSL_free((void*)ctx->engine_id);
164 OPENSSL_free(ctx);
165 }
166 }
167
168/* Construct the per-ENGINE context. We create it blindly and then use a lock to
169 * check for a race - if so, all but one of the threads "racing" will have
170 * wasted their time. The alternative involves creating everything inside the
171 * lock which is far worse. */
172static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
173 {
174 dynamic_data_ctx *c;
175 c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
176 if(!c)
177 {
178 ENGINEerr(ENGINE_F_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
179 return 0;
180 }
181 memset(c, 0, sizeof(dynamic_data_ctx));
182 c->dynamic_dso = NULL;
183 c->v_check = NULL;
184 c->bind_engine = NULL;
185 c->DYNAMIC_LIBNAME = NULL;
186 c->no_vcheck = 0;
187 c->engine_id = NULL;
188 c->list_add_value = 0;
189 c->DYNAMIC_F1 = "v_check";
190 c->DYNAMIC_F2 = "bind_engine";
191 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
192 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
193 dynamic_ex_data_idx)) == NULL)
194 {
195 /* Good, we're the first */
196 ENGINE_set_ex_data(e, dynamic_ex_data_idx, c);
197 *ctx = c;
198 c = NULL;
199 }
200 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
201 /* If we lost the race to set the context, c is non-NULL and *ctx is the
202 * context of the thread that won. */
203 if(c)
204 OPENSSL_free(c);
205 return 1;
206 }
207
208/* This function retrieves the context structure from an ENGINE's "ex_data", or
209 * if it doesn't exist yet, sets it up. */
210static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e)
211 {
212 dynamic_data_ctx *ctx;
213 if(dynamic_ex_data_idx < 0)
214 {
215 /* Create and register the ENGINE ex_data, and associate our
216 * "free" function with it to ensure any allocated contexts get
217 * freed when an ENGINE goes underground. */
218 int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL,
219 dynamic_data_ctx_free_func);
220 if(new_idx == -1)
221 {
222 ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX,ENGINE_R_NO_INDEX);
223 return NULL;
224 }
225 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
226 /* Avoid a race by checking again inside this lock */
227 if(dynamic_ex_data_idx < 0)
228 {
229 /* Good, someone didn't beat us to it */
230 dynamic_ex_data_idx = new_idx;
231 new_idx = -1;
232 }
233 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
234 /* In theory we could "give back" the index here if
235 * (new_idx>-1), but it's not possible and wouldn't gain us much
236 * if it were. */
237 }
238 ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx);
239 /* Check if the context needs to be created */
240 if((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx))
241 /* "set_data" will set errors if necessary */
242 return NULL;
243 return ctx;
244 }
245
246static ENGINE *engine_dynamic(void)
247 {
248 ENGINE *ret = ENGINE_new();
249 if(!ret)
250 return NULL;
251 if(!ENGINE_set_id(ret, engine_dynamic_id) ||
252 !ENGINE_set_name(ret, engine_dynamic_name) ||
253 !ENGINE_set_init_function(ret, dynamic_init) ||
254 !ENGINE_set_finish_function(ret, dynamic_finish) ||
255 !ENGINE_set_ctrl_function(ret, dynamic_ctrl) ||
256 !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) ||
257 !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns))
258 {
259 ENGINE_free(ret);
260 return NULL;
261 }
262 return ret;
263 }
264
265void ENGINE_load_dynamic(void)
266 {
267 ENGINE *toadd = engine_dynamic();
268 if(!toadd) return;
269 ENGINE_add(toadd);
270 /* If the "add" worked, it gets a structural reference. So either way,
271 * we release our just-created reference. */
272 ENGINE_free(toadd);
273 /* If the "add" didn't work, it was probably a conflict because it was
274 * already added (eg. someone calling ENGINE_load_blah then calling
275 * ENGINE_load_builtin_engines() perhaps). */
276 ERR_clear_error();
277 }
278
279static int dynamic_init(ENGINE *e)
280 {
281 /* We always return failure - the "dyanamic" engine itself can't be used
282 * for anything. */
283 return 0;
284 }
285
286static int dynamic_finish(ENGINE *e)
287 {
288 /* This should never be called on account of "dynamic_init" always
289 * failing. */
290 return 0;
291 }
292
293static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
294 {
295 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
296 int initialised;
297
298 if(!ctx)
299 {
300 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_NOT_LOADED);
301 return 0;
302 }
303 initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
304 /* All our control commands require the ENGINE to be uninitialised */
305 if(initialised)
306 {
307 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
308 ENGINE_R_ALREADY_LOADED);
309 return 0;
310 }
311 switch(cmd)
312 {
313 case DYNAMIC_CMD_SO_PATH:
314 /* a NULL 'p' or a string of zero-length is the same thing */
315 if(p && (strlen((const char *)p) < 1))
316 p = NULL;
317 if(ctx->DYNAMIC_LIBNAME)
318 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
319 if(p)
320 ctx->DYNAMIC_LIBNAME = BUF_strdup(p);
321 else
322 ctx->DYNAMIC_LIBNAME = NULL;
323 return (ctx->DYNAMIC_LIBNAME ? 1 : 0);
324 case DYNAMIC_CMD_NO_VCHECK:
325 ctx->no_vcheck = ((i == 0) ? 0 : 1);
326 return 1;
327 case DYNAMIC_CMD_ID:
328 /* a NULL 'p' or a string of zero-length is the same thing */
329 if(p && (strlen((const char *)p) < 1))
330 p = NULL;
331 if(ctx->engine_id)
332 OPENSSL_free((void*)ctx->engine_id);
333 if(p)
334 ctx->engine_id = BUF_strdup(p);
335 else
336 ctx->engine_id = NULL;
337 return (ctx->engine_id ? 1 : 0);
338 case DYNAMIC_CMD_LIST_ADD:
339 if((i < 0) || (i > 2))
340 {
341 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
342 ENGINE_R_INVALID_ARGUMENT);
343 return 0;
344 }
345 ctx->list_add_value = (int)i;
346 return 1;
347 case DYNAMIC_CMD_LOAD:
348 return dynamic_load(e, ctx);
349 default:
350 break;
351 }
352 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
353 return 0;
354 }
355
356static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
357 {
358 ENGINE cpy;
359 dynamic_fns fns;
360
361 if(!ctx->DYNAMIC_LIBNAME || ((ctx->dynamic_dso = DSO_load(NULL,
362 ctx->DYNAMIC_LIBNAME, NULL, 0)) == NULL))
363 {
364 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
365 ENGINE_R_DSO_NOT_FOUND);
366 return 0;
367 }
368 /* We have to find a bind function otherwise it'll always end badly */
369 if(!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func(
370 ctx->dynamic_dso, ctx->DYNAMIC_F2)))
371 {
372 ctx->bind_engine = NULL;
373 DSO_free(ctx->dynamic_dso);
374 ctx->dynamic_dso = NULL;
375 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
376 ENGINE_R_DSO_FAILURE);
377 return 0;
378 }
379 /* Do we perform version checking? */
380 if(!ctx->no_vcheck)
381 {
382 unsigned long vcheck_res = 0;
383 /* Now we try to find a version checking function and decide how
384 * to cope with failure if/when it fails. */
385 ctx->v_check = (dynamic_v_check_fn)DSO_bind_func(
386 ctx->dynamic_dso, ctx->DYNAMIC_F1);
387 if(ctx->v_check)
388 vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION);
389 /* We fail if the version checker veto'd the load *or* if it is
390 * deferring to us (by returning its version) and we think it is
391 * too old. */
392 if(vcheck_res < OSSL_DYNAMIC_OLDEST)
393 {
394 /* Fail */
395 ctx->bind_engine = NULL;
396 ctx->v_check = NULL;
397 DSO_free(ctx->dynamic_dso);
398 ctx->dynamic_dso = NULL;
399 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
400 ENGINE_R_VERSION_INCOMPATIBILITY);
401 return 0;
402 }
403 }
404 /* First binary copy the ENGINE structure so that we can roll back if
405 * the hand-over fails */
406 memcpy(&cpy, e, sizeof(ENGINE));
407 /* Provide the ERR, "ex_data", memory, and locking callbacks so the
408 * loaded library uses our state rather than its own. FIXME: As noted in
409 * engine.h, much of this would be simplified if each area of code
410 * provided its own "summary" structure of all related callbacks. It
411 * would also increase opaqueness. */
412 fns.err_fns = ERR_get_implementation();
413 fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
414 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
415 &fns.mem_fns.realloc_cb,
416 &fns.mem_fns.free_cb);
417 fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
418 fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback();
419 fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
420 fns.lock_fns.dynlock_lock_cb = CRYPTO_get_dynlock_lock_callback();
421 fns.lock_fns.dynlock_destroy_cb = CRYPTO_get_dynlock_destroy_callback();
422 /* Now that we've loaded the dynamic engine, make sure no "dynamic"
423 * ENGINE elements will show through. */
424 engine_set_all_null(e);
425
426 /* Try to bind the ENGINE onto our own ENGINE structure */
427 if(!ctx->bind_engine(e, ctx->engine_id, &fns))
428 {
429 ctx->bind_engine = NULL;
430 ctx->v_check = NULL;
431 DSO_free(ctx->dynamic_dso);
432 ctx->dynamic_dso = NULL;
433 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,ENGINE_R_INIT_FAILED);
434 /* Copy the original ENGINE structure back */
435 memcpy(e, &cpy, sizeof(ENGINE));
436 return 0;
437 }
438 /* Do we try to add this ENGINE to the internal list too? */
439 if(ctx->list_add_value > 0)
440 {
441 if(!ENGINE_add(e))
442 {
443 /* Do we tolerate this or fail? */
444 if(ctx->list_add_value > 1)
445 {
446 /* Fail - NB: By this time, it's too late to
447 * rollback, and trying to do so allows the
448 * bind_engine() code to have created leaks. We
449 * just have to fail where we are, after the
450 * ENGINE has changed. */
451 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
452 ENGINE_R_CONFLICTING_ENGINE_ID);
453 return 0;
454 }
455 /* Tolerate */
456 ERR_clear_error();
457 }
458 }
459 return 1;
460 }
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c
new file mode 100644
index 0000000000..814d95ee32
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_err.c
@@ -0,0 +1,166 @@
1/* crypto/engine/eng_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 <openssl/engine.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ENGINE_str_functs[]=
68 {
69{ERR_PACK(0,ENGINE_F_DYNAMIC_CTRL,0), "DYNAMIC_CTRL"},
70{ERR_PACK(0,ENGINE_F_DYNAMIC_GET_DATA_CTX,0), "DYNAMIC_GET_DATA_CTX"},
71{ERR_PACK(0,ENGINE_F_DYNAMIC_LOAD,0), "DYNAMIC_LOAD"},
72{ERR_PACK(0,ENGINE_F_ENGINE_ADD,0), "ENGINE_add"},
73{ERR_PACK(0,ENGINE_F_ENGINE_BY_ID,0), "ENGINE_by_id"},
74{ERR_PACK(0,ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,0), "ENGINE_cmd_is_executable"},
75{ERR_PACK(0,ENGINE_F_ENGINE_CTRL,0), "ENGINE_ctrl"},
76{ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD,0), "ENGINE_ctrl_cmd"},
77{ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD_STRING,0), "ENGINE_ctrl_cmd_string"},
78{ERR_PACK(0,ENGINE_F_ENGINE_FINISH,0), "ENGINE_finish"},
79{ERR_PACK(0,ENGINE_F_ENGINE_FREE,0), "ENGINE_free"},
80{ERR_PACK(0,ENGINE_F_ENGINE_GET_CIPHER,0), "ENGINE_get_cipher"},
81{ERR_PACK(0,ENGINE_F_ENGINE_GET_DEFAULT_TYPE,0), "ENGINE_GET_DEFAULT_TYPE"},
82{ERR_PACK(0,ENGINE_F_ENGINE_GET_DIGEST,0), "ENGINE_get_digest"},
83{ERR_PACK(0,ENGINE_F_ENGINE_GET_NEXT,0), "ENGINE_get_next"},
84{ERR_PACK(0,ENGINE_F_ENGINE_GET_PREV,0), "ENGINE_get_prev"},
85{ERR_PACK(0,ENGINE_F_ENGINE_INIT,0), "ENGINE_init"},
86{ERR_PACK(0,ENGINE_F_ENGINE_LIST_ADD,0), "ENGINE_LIST_ADD"},
87{ERR_PACK(0,ENGINE_F_ENGINE_LIST_REMOVE,0), "ENGINE_LIST_REMOVE"},
88{ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,0), "ENGINE_load_private_key"},
89{ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,0), "ENGINE_load_public_key"},
90{ERR_PACK(0,ENGINE_F_ENGINE_MODULE_INIT,0), "ENGINE_MODULE_INIT"},
91{ERR_PACK(0,ENGINE_F_ENGINE_NEW,0), "ENGINE_new"},
92{ERR_PACK(0,ENGINE_F_ENGINE_REMOVE,0), "ENGINE_remove"},
93{ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_STRING,0), "ENGINE_set_default_string"},
94{ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_TYPE,0), "ENGINE_SET_DEFAULT_TYPE"},
95{ERR_PACK(0,ENGINE_F_ENGINE_SET_ID,0), "ENGINE_set_id"},
96{ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"},
97{ERR_PACK(0,ENGINE_F_ENGINE_TABLE_REGISTER,0), "ENGINE_TABLE_REGISTER"},
98{ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"},
99{ERR_PACK(0,ENGINE_F_ENGINE_UP_REF,0), "ENGINE_up_ref"},
100{ERR_PACK(0,ENGINE_F_INT_CTRL_HELPER,0), "INT_CTRL_HELPER"},
101{ERR_PACK(0,ENGINE_F_INT_ENGINE_CONFIGURE,0), "INT_ENGINE_CONFIGURE"},
102{ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"},
103{ERR_PACK(0,ENGINE_F_SET_DATA_CTX,0), "SET_DATA_CTX"},
104{0,NULL}
105 };
106
107static ERR_STRING_DATA ENGINE_str_reasons[]=
108 {
109{ENGINE_R_ALREADY_LOADED ,"already loaded"},
110{ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER ,"argument is not a number"},
111{ENGINE_R_CMD_NOT_EXECUTABLE ,"cmd not executable"},
112{ENGINE_R_COMMAND_TAKES_INPUT ,"command takes input"},
113{ENGINE_R_COMMAND_TAKES_NO_INPUT ,"command takes no input"},
114{ENGINE_R_CONFLICTING_ENGINE_ID ,"conflicting engine id"},
115{ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
116{ENGINE_R_DH_NOT_IMPLEMENTED ,"dh not implemented"},
117{ENGINE_R_DSA_NOT_IMPLEMENTED ,"dsa not implemented"},
118{ENGINE_R_DSO_FAILURE ,"DSO failure"},
119{ENGINE_R_DSO_NOT_FOUND ,"dso not found"},
120{ENGINE_R_ENGINES_SECTION_ERROR ,"engines section error"},
121{ENGINE_R_ENGINE_IS_NOT_IN_LIST ,"engine is not in the list"},
122{ENGINE_R_ENGINE_SECTION_ERROR ,"engine section error"},
123{ENGINE_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
124{ENGINE_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
125{ENGINE_R_FINISH_FAILED ,"finish failed"},
126{ENGINE_R_GET_HANDLE_FAILED ,"could not obtain hardware handle"},
127{ENGINE_R_ID_OR_NAME_MISSING ,"'id' or 'name' missing"},
128{ENGINE_R_INIT_FAILED ,"init failed"},
129{ENGINE_R_INTERNAL_LIST_ERROR ,"internal list error"},
130{ENGINE_R_INVALID_ARGUMENT ,"invalid argument"},
131{ENGINE_R_INVALID_CMD_NAME ,"invalid cmd name"},
132{ENGINE_R_INVALID_CMD_NUMBER ,"invalid cmd number"},
133{ENGINE_R_INVALID_INIT_VALUE ,"invalid init value"},
134{ENGINE_R_INVALID_STRING ,"invalid string"},
135{ENGINE_R_NOT_INITIALISED ,"not initialised"},
136{ENGINE_R_NOT_LOADED ,"not loaded"},
137{ENGINE_R_NO_CONTROL_FUNCTION ,"no control function"},
138{ENGINE_R_NO_INDEX ,"no index"},
139{ENGINE_R_NO_LOAD_FUNCTION ,"no load function"},
140{ENGINE_R_NO_REFERENCE ,"no reference"},
141{ENGINE_R_NO_SUCH_ENGINE ,"no such engine"},
142{ENGINE_R_NO_UNLOAD_FUNCTION ,"no unload function"},
143{ENGINE_R_PROVIDE_PARAMETERS ,"provide parameters"},
144{ENGINE_R_RSA_NOT_IMPLEMENTED ,"rsa not implemented"},
145{ENGINE_R_UNIMPLEMENTED_CIPHER ,"unimplemented cipher"},
146{ENGINE_R_UNIMPLEMENTED_DIGEST ,"unimplemented digest"},
147{ENGINE_R_VERSION_INCOMPATIBILITY ,"version incompatibility"},
148{0,NULL}
149 };
150
151#endif
152
153void ERR_load_ENGINE_strings(void)
154 {
155 static int init=1;
156
157 if (init)
158 {
159 init=0;
160#ifndef OPENSSL_NO_ERR
161 ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_functs);
162 ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_reasons);
163#endif
164
165 }
166 }
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c
new file mode 100644
index 0000000000..7ccf7022ee
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_fat.c
@@ -0,0 +1,147 @@
1/* crypto/engine/eng_fat.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60#include <openssl/conf.h>
61
62int ENGINE_set_default(ENGINE *e, unsigned int flags)
63 {
64 if((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e))
65 return 0;
66 if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e))
67 return 0;
68#ifndef OPENSSL_NO_RSA
69 if((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e))
70 return 0;
71#endif
72#ifndef OPENSSL_NO_DSA
73 if((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e))
74 return 0;
75#endif
76#ifndef OPENSSL_NO_DH
77 if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
78 return 0;
79#endif
80 if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
81 return 0;
82 return 1;
83 }
84
85/* Set default algorithms using a string */
86
87static int int_def_cb(const char *alg, int len, void *arg)
88 {
89 unsigned int *pflags = arg;
90 if (!strncmp(alg, "ALL", len))
91 *pflags |= ENGINE_METHOD_ALL;
92 else if (!strncmp(alg, "RSA", len))
93 *pflags |= ENGINE_METHOD_RSA;
94 else if (!strncmp(alg, "DSA", len))
95 *pflags |= ENGINE_METHOD_DSA;
96 else if (!strncmp(alg, "DH", len))
97 *pflags |= ENGINE_METHOD_DH;
98 else if (!strncmp(alg, "RAND", len))
99 *pflags |= ENGINE_METHOD_RAND;
100 else if (!strncmp(alg, "CIPHERS", len))
101 *pflags |= ENGINE_METHOD_CIPHERS;
102 else if (!strncmp(alg, "DIGESTS", len))
103 *pflags |= ENGINE_METHOD_DIGESTS;
104 else
105 return 0;
106 return 1;
107 }
108
109
110int ENGINE_set_default_string(ENGINE *e, const char *def_list)
111 {
112 unsigned int flags = 0;
113 if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags))
114 {
115 ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING,
116 ENGINE_R_INVALID_STRING);
117 ERR_add_error_data(2, "str=",def_list);
118 return 0;
119 }
120 return ENGINE_set_default(e, flags);
121 }
122
123int ENGINE_register_complete(ENGINE *e)
124 {
125 ENGINE_register_ciphers(e);
126 ENGINE_register_digests(e);
127#ifndef OPENSSL_NO_RSA
128 ENGINE_register_RSA(e);
129#endif
130#ifndef OPENSSL_NO_DSA
131 ENGINE_register_DSA(e);
132#endif
133#ifndef OPENSSL_NO_DH
134 ENGINE_register_DH(e);
135#endif
136 ENGINE_register_RAND(e);
137 return 1;
138 }
139
140int ENGINE_register_all_complete(void)
141 {
142 ENGINE *e;
143
144 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
145 ENGINE_register_complete(e);
146 return 1;
147 }
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c
new file mode 100644
index 0000000000..170c1791b3
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_init.c
@@ -0,0 +1,157 @@
1/* crypto/engine/eng_init.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* Initialise a engine type for use (or up its functional reference count
62 * if it's already in use). This version is only used internally. */
63int engine_unlocked_init(ENGINE *e)
64 {
65 int to_return = 1;
66
67 if((e->funct_ref == 0) && e->init)
68 /* This is the first functional reference and the engine
69 * requires initialisation so we do it now. */
70 to_return = e->init(e);
71 if(to_return)
72 {
73 /* OK, we return a functional reference which is also a
74 * structural reference. */
75 e->struct_ref++;
76 e->funct_ref++;
77 engine_ref_debug(e, 0, 1)
78 engine_ref_debug(e, 1, 1)
79 }
80 return to_return;
81 }
82
83/* Free a functional reference to a engine type. This version is only used
84 * internally. */
85int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
86 {
87 int to_return = 1;
88
89 /* Reduce the functional reference count here so if it's the terminating
90 * case, we can release the lock safely and call the finish() handler
91 * without risk of a race. We get a race if we leave the count until
92 * after and something else is calling "finish" at the same time -
93 * there's a chance that both threads will together take the count from
94 * 2 to 0 without either calling finish(). */
95 e->funct_ref--;
96 engine_ref_debug(e, 1, -1);
97 if((e->funct_ref == 0) && e->finish)
98 {
99 if(unlock_for_handlers)
100 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
101 to_return = e->finish(e);
102 if(unlock_for_handlers)
103 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
104 if(!to_return)
105 return 0;
106 }
107#ifdef REF_CHECK
108 if(e->funct_ref < 0)
109 {
110 fprintf(stderr,"ENGINE_finish, bad functional reference count\n");
111 abort();
112 }
113#endif
114 /* Release the structural reference too */
115 if(!engine_free_util(e, 0))
116 {
117 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
118 return 0;
119 }
120 return to_return;
121 }
122
123/* The API (locked) version of "init" */
124int ENGINE_init(ENGINE *e)
125 {
126 int ret;
127 if(e == NULL)
128 {
129 ENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER);
130 return 0;
131 }
132 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
133 ret = engine_unlocked_init(e);
134 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
135 return ret;
136 }
137
138/* The API (locked) version of "finish" */
139int ENGINE_finish(ENGINE *e)
140 {
141 int to_return = 1;
142
143 if(e == NULL)
144 {
145 ENGINEerr(ENGINE_F_ENGINE_FINISH,ERR_R_PASSED_NULL_PARAMETER);
146 return 0;
147 }
148 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
149 to_return = engine_unlocked_finish(e, 1);
150 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
151 if(!to_return)
152 {
153 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
154 return 0;
155 }
156 return to_return;
157 }
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h
new file mode 100644
index 0000000000..38335f99cd
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_int.h
@@ -0,0 +1,185 @@
1/* crypto/engine/eng_int.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_ENGINE_INT_H
60#define HEADER_ENGINE_INT_H
61
62/* Take public definitions from engine.h */
63#include <openssl/engine.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* If we compile with this symbol defined, then both reference counts in the
70 * ENGINE structure will be monitored with a line of output on stderr for each
71 * change. This prints the engine's pointer address (truncated to unsigned int),
72 * "struct" or "funct" to indicate the reference type, the before and after
73 * reference count, and the file:line-number pair. The "engine_ref_debug"
74 * statements must come *after* the change. */
75#ifdef ENGINE_REF_COUNT_DEBUG
76
77#define engine_ref_debug(e, isfunct, diff) \
78 fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
79 (unsigned int)(e), (isfunct ? "funct" : "struct"), \
80 ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
81 ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
82 (__FILE__), (__LINE__));
83
84#else
85
86#define engine_ref_debug(e, isfunct, diff)
87
88#endif
89
90/* Any code that will need cleanup operations should use these functions to
91 * register callbacks. ENGINE_cleanup() will call all registered callbacks in
92 * order. NB: both the "add" functions assume CRYPTO_LOCK_ENGINE to already be
93 * held (in "write" mode). */
94typedef void (ENGINE_CLEANUP_CB)(void);
95typedef struct st_engine_cleanup_item
96 {
97 ENGINE_CLEANUP_CB *cb;
98 } ENGINE_CLEANUP_ITEM;
99DECLARE_STACK_OF(ENGINE_CLEANUP_ITEM)
100void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
101void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
102
103/* We need stacks of ENGINEs for use in eng_table.c */
104DECLARE_STACK_OF(ENGINE)
105
106/* If this symbol is defined then engine_table_select(), the function that is
107 * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults and
108 * functional references (etc), will display debugging summaries to stderr. */
109/* #define ENGINE_TABLE_DEBUG */
110
111/* This represents an implementation table. Dependent code should instantiate it
112 * as a (ENGINE_TABLE *) pointer value set initially to NULL. */
113typedef struct st_engine_table ENGINE_TABLE;
114int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
115 ENGINE *e, const int *nids, int num_nids, int setdefault);
116void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
117void engine_table_cleanup(ENGINE_TABLE **table);
118#ifndef ENGINE_TABLE_DEBUG
119ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
120#else
121ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l);
122#define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__)
123#endif
124
125/* Internal versions of API functions that have control over locking. These are
126 * used between C files when functionality needs to be shared but the caller may
127 * already be controlling of the CRYPTO_LOCK_ENGINE lock. */
128int engine_unlocked_init(ENGINE *e);
129int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
130int engine_free_util(ENGINE *e, int locked);
131
132/* This function will reset all "set"able values in an ENGINE to NULL. This
133 * won't touch reference counts or ex_data, but is equivalent to calling all the
134 * ENGINE_set_***() functions with a NULL value. */
135void engine_set_all_null(ENGINE *e);
136
137/* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed
138 * in engine.h. */
139
140/* This is a structure for storing implementations of various crypto
141 * algorithms and functions. */
142struct engine_st
143 {
144 const char *id;
145 const char *name;
146 const RSA_METHOD *rsa_meth;
147 const DSA_METHOD *dsa_meth;
148 const DH_METHOD *dh_meth;
149 const RAND_METHOD *rand_meth;
150 /* Cipher handling is via this callback */
151 ENGINE_CIPHERS_PTR ciphers;
152 /* Digest handling is via this callback */
153 ENGINE_DIGESTS_PTR digests;
154
155
156 ENGINE_GEN_INT_FUNC_PTR destroy;
157
158 ENGINE_GEN_INT_FUNC_PTR init;
159 ENGINE_GEN_INT_FUNC_PTR finish;
160 ENGINE_CTRL_FUNC_PTR ctrl;
161 ENGINE_LOAD_KEY_PTR load_privkey;
162 ENGINE_LOAD_KEY_PTR load_pubkey;
163
164 const ENGINE_CMD_DEFN *cmd_defns;
165 int flags;
166 /* reference count on the structure itself */
167 int struct_ref;
168 /* reference count on usability of the engine type. NB: This
169 * controls the loading and initialisation of any functionlity
170 * required by this engine, whereas the previous count is
171 * simply to cope with (de)allocation of this structure. Hence,
172 * running_ref <= struct_ref at all times. */
173 int funct_ref;
174 /* A place to store per-ENGINE data */
175 CRYPTO_EX_DATA ex_data;
176 /* Used to maintain the linked-list of engines. */
177 struct engine_st *prev;
178 struct engine_st *next;
179 };
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* HEADER_ENGINE_INT_H */
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c
new file mode 100644
index 0000000000..a66d0f08af
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_lib.c
@@ -0,0 +1,321 @@
1/* crypto/engine/eng_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h"
62#include <openssl/rand.h> /* FIXME: This shouldn't be needed */
63#include <openssl/engine.h>
64
65/* The "new"/"free" stuff first */
66
67ENGINE *ENGINE_new(void)
68 {
69 ENGINE *ret;
70
71 ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE));
72 if(ret == NULL)
73 {
74 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
75 return NULL;
76 }
77 memset(ret, 0, sizeof(ENGINE));
78 ret->struct_ref = 1;
79 engine_ref_debug(ret, 0, 1)
80 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data);
81 return ret;
82 }
83
84/* Placed here (close proximity to ENGINE_new) so that modifications to the
85 * elements of the ENGINE structure are more likely to be caught and changed
86 * here. */
87void engine_set_all_null(ENGINE *e)
88 {
89 e->id = NULL;
90 e->name = NULL;
91 e->rsa_meth = NULL;
92 e->dsa_meth = NULL;
93 e->dh_meth = NULL;
94 e->rand_meth = NULL;
95 e->ciphers = NULL;
96 e->digests = NULL;
97 e->destroy = NULL;
98 e->init = NULL;
99 e->finish = NULL;
100 e->ctrl = NULL;
101 e->load_privkey = NULL;
102 e->load_pubkey = NULL;
103 e->cmd_defns = NULL;
104 e->flags = 0;
105 }
106
107int engine_free_util(ENGINE *e, int locked)
108 {
109 int i;
110
111 if(e == NULL)
112 {
113 ENGINEerr(ENGINE_F_ENGINE_FREE,
114 ERR_R_PASSED_NULL_PARAMETER);
115 return 0;
116 }
117 if(locked)
118 i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE);
119 else
120 i = --e->struct_ref;
121 engine_ref_debug(e, 0, -1)
122 if (i > 0) return 1;
123#ifdef REF_CHECK
124 if (i < 0)
125 {
126 fprintf(stderr,"ENGINE_free, bad structural reference count\n");
127 abort();
128 }
129#endif
130 /* Give the ENGINE a chance to do any structural cleanup corresponding
131 * to allocation it did in its constructor (eg. unload error strings) */
132 if(e->destroy)
133 e->destroy(e);
134 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
135 OPENSSL_free(e);
136 return 1;
137 }
138
139int ENGINE_free(ENGINE *e)
140 {
141 return engine_free_util(e, 1);
142 }
143
144/* Cleanup stuff */
145
146/* ENGINE_cleanup() is coded such that anything that does work that will need
147 * cleanup can register a "cleanup" callback here. That way we don't get linker
148 * bloat by referring to all *possible* cleanups, but any linker bloat into code
149 * "X" will cause X's cleanup function to end up here. */
150static STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL;
151static int int_cleanup_check(int create)
152 {
153 if(cleanup_stack) return 1;
154 if(!create) return 0;
155 cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null();
156 return (cleanup_stack ? 1 : 0);
157 }
158static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)
159 {
160 ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof(
161 ENGINE_CLEANUP_ITEM));
162 if(!item) return NULL;
163 item->cb = cb;
164 return item;
165 }
166void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb)
167 {
168 ENGINE_CLEANUP_ITEM *item;
169 if(!int_cleanup_check(1)) return;
170 item = int_cleanup_item(cb);
171 if(item)
172 sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0);
173 }
174void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
175 {
176 ENGINE_CLEANUP_ITEM *item;
177 if(!int_cleanup_check(1)) return;
178 item = int_cleanup_item(cb);
179 if(item)
180 sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item);
181 }
182/* The API function that performs all cleanup */
183static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item)
184 {
185 (*(item->cb))();
186 OPENSSL_free(item);
187 }
188void ENGINE_cleanup(void)
189 {
190 if(int_cleanup_check(0))
191 {
192 sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack,
193 engine_cleanup_cb_free);
194 cleanup_stack = NULL;
195 }
196 /* FIXME: This should be handled (somehow) through RAND, eg. by it
197 * registering a cleanup callback. */
198 RAND_set_rand_method(NULL);
199 }
200
201/* Now the "ex_data" support */
202
203int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
204 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
205 {
206 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, argl, argp,
207 new_func, dup_func, free_func);
208 }
209
210int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)
211 {
212 return(CRYPTO_set_ex_data(&e->ex_data, idx, arg));
213 }
214
215void *ENGINE_get_ex_data(const ENGINE *e, int idx)
216 {
217 return(CRYPTO_get_ex_data(&e->ex_data, idx));
218 }
219
220/* Functions to get/set an ENGINE's elements - mainly to avoid exposing the
221 * ENGINE structure itself. */
222
223int ENGINE_set_id(ENGINE *e, const char *id)
224 {
225 if(id == NULL)
226 {
227 ENGINEerr(ENGINE_F_ENGINE_SET_ID,
228 ERR_R_PASSED_NULL_PARAMETER);
229 return 0;
230 }
231 e->id = id;
232 return 1;
233 }
234
235int ENGINE_set_name(ENGINE *e, const char *name)
236 {
237 if(name == NULL)
238 {
239 ENGINEerr(ENGINE_F_ENGINE_SET_NAME,
240 ERR_R_PASSED_NULL_PARAMETER);
241 return 0;
242 }
243 e->name = name;
244 return 1;
245 }
246
247int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f)
248 {
249 e->destroy = destroy_f;
250 return 1;
251 }
252
253int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f)
254 {
255 e->init = init_f;
256 return 1;
257 }
258
259int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f)
260 {
261 e->finish = finish_f;
262 return 1;
263 }
264
265int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f)
266 {
267 e->ctrl = ctrl_f;
268 return 1;
269 }
270
271int ENGINE_set_flags(ENGINE *e, int flags)
272 {
273 e->flags = flags;
274 return 1;
275 }
276
277int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns)
278 {
279 e->cmd_defns = defns;
280 return 1;
281 }
282
283const char *ENGINE_get_id(const ENGINE *e)
284 {
285 return e->id;
286 }
287
288const char *ENGINE_get_name(const ENGINE *e)
289 {
290 return e->name;
291 }
292
293ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e)
294 {
295 return e->destroy;
296 }
297
298ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e)
299 {
300 return e->init;
301 }
302
303ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e)
304 {
305 return e->finish;
306 }
307
308ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e)
309 {
310 return e->ctrl;
311 }
312
313int ENGINE_get_flags(const ENGINE *e)
314 {
315 return e->flags;
316 }
317
318const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
319 {
320 return e->cmd_defns;
321 }
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c
new file mode 100644
index 0000000000..1cc3217f4c
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_list.c
@@ -0,0 +1,394 @@
1/* crypto/engine/eng_list.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h"
62#include <openssl/engine.h>
63
64/* The linked-list of pointers to engine types. engine_list_head
65 * incorporates an implicit structural reference but engine_list_tail
66 * does not - the latter is a computational niceity and only points
67 * to something that is already pointed to by its predecessor in the
68 * list (or engine_list_head itself). In the same way, the use of the
69 * "prev" pointer in each ENGINE is to save excessive list iteration,
70 * it doesn't correspond to an extra structural reference. Hence,
71 * engine_list_head, and each non-null "next" pointer account for
72 * the list itself assuming exactly 1 structural reference on each
73 * list member. */
74static ENGINE *engine_list_head = NULL;
75static ENGINE *engine_list_tail = NULL;
76
77/* This cleanup function is only needed internally. If it should be called, we
78 * register it with the "ENGINE_cleanup()" stack to be called during cleanup. */
79
80static void engine_list_cleanup(void)
81 {
82 ENGINE *iterator = engine_list_head;
83
84 while(iterator != NULL)
85 {
86 ENGINE_remove(iterator);
87 iterator = engine_list_head;
88 }
89 return;
90 }
91
92/* These static functions starting with a lower case "engine_" always
93 * take place when CRYPTO_LOCK_ENGINE has been locked up. */
94static int engine_list_add(ENGINE *e)
95 {
96 int conflict = 0;
97 ENGINE *iterator = NULL;
98
99 if(e == NULL)
100 {
101 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
102 ERR_R_PASSED_NULL_PARAMETER);
103 return 0;
104 }
105 iterator = engine_list_head;
106 while(iterator && !conflict)
107 {
108 conflict = (strcmp(iterator->id, e->id) == 0);
109 iterator = iterator->next;
110 }
111 if(conflict)
112 {
113 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
114 ENGINE_R_CONFLICTING_ENGINE_ID);
115 return 0;
116 }
117 if(engine_list_head == NULL)
118 {
119 /* We are adding to an empty list. */
120 if(engine_list_tail)
121 {
122 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
123 ENGINE_R_INTERNAL_LIST_ERROR);
124 return 0;
125 }
126 engine_list_head = e;
127 e->prev = NULL;
128 /* The first time the list allocates, we should register the
129 * cleanup. */
130 engine_cleanup_add_last(engine_list_cleanup);
131 }
132 else
133 {
134 /* We are adding to the tail of an existing list. */
135 if((engine_list_tail == NULL) ||
136 (engine_list_tail->next != NULL))
137 {
138 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
139 ENGINE_R_INTERNAL_LIST_ERROR);
140 return 0;
141 }
142 engine_list_tail->next = e;
143 e->prev = engine_list_tail;
144 }
145 /* Having the engine in the list assumes a structural
146 * reference. */
147 e->struct_ref++;
148 engine_ref_debug(e, 0, 1)
149 /* However it came to be, e is the last item in the list. */
150 engine_list_tail = e;
151 e->next = NULL;
152 return 1;
153 }
154
155static int engine_list_remove(ENGINE *e)
156 {
157 ENGINE *iterator;
158
159 if(e == NULL)
160 {
161 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
162 ERR_R_PASSED_NULL_PARAMETER);
163 return 0;
164 }
165 /* We need to check that e is in our linked list! */
166 iterator = engine_list_head;
167 while(iterator && (iterator != e))
168 iterator = iterator->next;
169 if(iterator == NULL)
170 {
171 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
172 ENGINE_R_ENGINE_IS_NOT_IN_LIST);
173 return 0;
174 }
175 /* un-link e from the chain. */
176 if(e->next)
177 e->next->prev = e->prev;
178 if(e->prev)
179 e->prev->next = e->next;
180 /* Correct our head/tail if necessary. */
181 if(engine_list_head == e)
182 engine_list_head = e->next;
183 if(engine_list_tail == e)
184 engine_list_tail = e->prev;
185 engine_free_util(e, 0);
186 return 1;
187 }
188
189/* Get the first/last "ENGINE" type available. */
190ENGINE *ENGINE_get_first(void)
191 {
192 ENGINE *ret;
193
194 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
195 ret = engine_list_head;
196 if(ret)
197 {
198 ret->struct_ref++;
199 engine_ref_debug(ret, 0, 1)
200 }
201 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
202 return ret;
203 }
204
205ENGINE *ENGINE_get_last(void)
206 {
207 ENGINE *ret;
208
209 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
210 ret = engine_list_tail;
211 if(ret)
212 {
213 ret->struct_ref++;
214 engine_ref_debug(ret, 0, 1)
215 }
216 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
217 return ret;
218 }
219
220/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
221ENGINE *ENGINE_get_next(ENGINE *e)
222 {
223 ENGINE *ret = NULL;
224 if(e == NULL)
225 {
226 ENGINEerr(ENGINE_F_ENGINE_GET_NEXT,
227 ERR_R_PASSED_NULL_PARAMETER);
228 return 0;
229 }
230 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
231 ret = e->next;
232 if(ret)
233 {
234 /* Return a valid structural refernce to the next ENGINE */
235 ret->struct_ref++;
236 engine_ref_debug(ret, 0, 1)
237 }
238 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
239 /* Release the structural reference to the previous ENGINE */
240 ENGINE_free(e);
241 return ret;
242 }
243
244ENGINE *ENGINE_get_prev(ENGINE *e)
245 {
246 ENGINE *ret = NULL;
247 if(e == NULL)
248 {
249 ENGINEerr(ENGINE_F_ENGINE_GET_PREV,
250 ERR_R_PASSED_NULL_PARAMETER);
251 return 0;
252 }
253 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
254 ret = e->prev;
255 if(ret)
256 {
257 /* Return a valid structural reference to the next ENGINE */
258 ret->struct_ref++;
259 engine_ref_debug(ret, 0, 1)
260 }
261 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
262 /* Release the structural reference to the previous ENGINE */
263 ENGINE_free(e);
264 return ret;
265 }
266
267/* Add another "ENGINE" type into the list. */
268int ENGINE_add(ENGINE *e)
269 {
270 int to_return = 1;
271 if(e == NULL)
272 {
273 ENGINEerr(ENGINE_F_ENGINE_ADD,
274 ERR_R_PASSED_NULL_PARAMETER);
275 return 0;
276 }
277 if((e->id == NULL) || (e->name == NULL))
278 {
279 ENGINEerr(ENGINE_F_ENGINE_ADD,
280 ENGINE_R_ID_OR_NAME_MISSING);
281 }
282 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
283 if(!engine_list_add(e))
284 {
285 ENGINEerr(ENGINE_F_ENGINE_ADD,
286 ENGINE_R_INTERNAL_LIST_ERROR);
287 to_return = 0;
288 }
289 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
290 return to_return;
291 }
292
293/* Remove an existing "ENGINE" type from the array. */
294int ENGINE_remove(ENGINE *e)
295 {
296 int to_return = 1;
297 if(e == NULL)
298 {
299 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
300 ERR_R_PASSED_NULL_PARAMETER);
301 return 0;
302 }
303 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
304 if(!engine_list_remove(e))
305 {
306 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
307 ENGINE_R_INTERNAL_LIST_ERROR);
308 to_return = 0;
309 }
310 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
311 return to_return;
312 }
313
314static void engine_cpy(ENGINE *dest, const ENGINE *src)
315 {
316 dest->id = src->id;
317 dest->name = src->name;
318#ifndef OPENSSL_NO_RSA
319 dest->rsa_meth = src->rsa_meth;
320#endif
321#ifndef OPENSSL_NO_DSA
322 dest->dsa_meth = src->dsa_meth;
323#endif
324#ifndef OPENSSL_NO_DH
325 dest->dh_meth = src->dh_meth;
326#endif
327 dest->rand_meth = src->rand_meth;
328 dest->ciphers = src->ciphers;
329 dest->digests = src->digests;
330 dest->destroy = src->destroy;
331 dest->init = src->init;
332 dest->finish = src->finish;
333 dest->ctrl = src->ctrl;
334 dest->load_privkey = src->load_privkey;
335 dest->load_pubkey = src->load_pubkey;
336 dest->cmd_defns = src->cmd_defns;
337 dest->flags = src->flags;
338 }
339
340ENGINE *ENGINE_by_id(const char *id)
341 {
342 ENGINE *iterator;
343 if(id == NULL)
344 {
345 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
346 ERR_R_PASSED_NULL_PARAMETER);
347 return NULL;
348 }
349 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
350 iterator = engine_list_head;
351 while(iterator && (strcmp(id, iterator->id) != 0))
352 iterator = iterator->next;
353 if(iterator)
354 {
355 /* We need to return a structural reference. If this is an
356 * ENGINE type that returns copies, make a duplicate - otherwise
357 * increment the existing ENGINE's reference count. */
358 if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY)
359 {
360 ENGINE *cp = ENGINE_new();
361 if(!cp)
362 iterator = NULL;
363 else
364 {
365 engine_cpy(cp, iterator);
366 iterator = cp;
367 }
368 }
369 else
370 {
371 iterator->struct_ref++;
372 engine_ref_debug(iterator, 0, 1)
373 }
374 }
375 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
376 if(iterator == NULL)
377 {
378 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
379 ENGINE_R_NO_SUCH_ENGINE);
380 ERR_add_error_data(2, "id=", id);
381 }
382 return iterator;
383 }
384
385int ENGINE_up_ref(ENGINE *e)
386 {
387 if (e == NULL)
388 {
389 ENGINEerr(ENGINE_F_ENGINE_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
390 return 0;
391 }
392 CRYPTO_add(&e->struct_ref,1,CRYPTO_LOCK_ENGINE);
393 return 1;
394 }
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c
new file mode 100644
index 0000000000..54579eea2e
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_openssl.c
@@ -0,0 +1,361 @@
1/* crypto/engine/eng_openssl.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/engine.h>
64#include <openssl/dso.h>
65#include <openssl/pem.h>
66#include <openssl/evp.h>
67
68/* This testing gunk is implemented (and explained) lower down. It also assumes
69 * the application explicitly calls "ENGINE_load_openssl()" because this is no
70 * longer automatic in ENGINE_load_builtin_engines(). */
71#define TEST_ENG_OPENSSL_RC4
72#define TEST_ENG_OPENSSL_PKEY
73/* #define TEST_ENG_OPENSSL_RC4_OTHERS */
74#define TEST_ENG_OPENSSL_RC4_P_INIT
75/* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */
76#define TEST_ENG_OPENSSL_SHA
77/* #define TEST_ENG_OPENSSL_SHA_OTHERS */
78/* #define TEST_ENG_OPENSSL_SHA_P_INIT */
79/* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */
80/* #define TEST_ENG_OPENSSL_SHA_P_FINAL */
81
82/* Now check what of those algorithms are actually enabled */
83#ifdef OPENSSL_NO_RC4
84#undef TEST_ENG_OPENSSL_RC4
85#undef TEST_ENG_OPENSSL_RC4_OTHERS
86#undef TEST_ENG_OPENSSL_RC4_P_INIT
87#undef TEST_ENG_OPENSSL_RC4_P_CIPHER
88#endif
89#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) || defined(OPENSSL_NO_SHA1)
90#undef TEST_ENG_OPENSSL_SHA
91#undef TEST_ENG_OPENSSL_SHA_OTHERS
92#undef TEST_ENG_OPENSSL_SHA_P_INIT
93#undef TEST_ENG_OPENSSL_SHA_P_UPDATE
94#undef TEST_ENG_OPENSSL_SHA_P_FINAL
95#endif
96
97#ifdef TEST_ENG_OPENSSL_RC4
98static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
99 const int **nids, int nid);
100#endif
101#ifdef TEST_ENG_OPENSSL_SHA
102static int openssl_digests(ENGINE *e, const EVP_MD **digest,
103 const int **nids, int nid);
104#endif
105
106#ifdef TEST_ENG_OPENSSL_PKEY
107static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
108 UI_METHOD *ui_method, void *callback_data);
109#endif
110
111/* The constants used when creating the ENGINE */
112static const char *engine_openssl_id = "openssl";
113static const char *engine_openssl_name = "Software engine support";
114
115/* This internal function is used by ENGINE_openssl() and possibly by the
116 * "dynamic" ENGINE support too */
117static int bind_helper(ENGINE *e)
118 {
119 if(!ENGINE_set_id(e, engine_openssl_id)
120 || !ENGINE_set_name(e, engine_openssl_name)
121#ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
122#ifndef OPENSSL_NO_RSA
123 || !ENGINE_set_RSA(e, RSA_get_default_method())
124#endif
125#ifndef OPENSSL_NO_DSA
126 || !ENGINE_set_DSA(e, DSA_get_default_method())
127#endif
128#ifndef OPENSSL_NO_DH
129 || !ENGINE_set_DH(e, DH_get_default_method())
130#endif
131 || !ENGINE_set_RAND(e, RAND_SSLeay())
132#ifdef TEST_ENG_OPENSSL_RC4
133 || !ENGINE_set_ciphers(e, openssl_ciphers)
134#endif
135#ifdef TEST_ENG_OPENSSL_SHA
136 || !ENGINE_set_digests(e, openssl_digests)
137#endif
138#endif
139#ifdef TEST_ENG_OPENSSL_PKEY
140 || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
141#endif
142 )
143 return 0;
144 /* If we add errors to this ENGINE, ensure the error handling is setup here */
145 /* openssl_load_error_strings(); */
146 return 1;
147 }
148
149static ENGINE *engine_openssl(void)
150 {
151 ENGINE *ret = ENGINE_new();
152 if(!ret)
153 return NULL;
154 if(!bind_helper(ret))
155 {
156 ENGINE_free(ret);
157 return NULL;
158 }
159 return ret;
160 }
161
162void ENGINE_load_openssl(void)
163 {
164 ENGINE *toadd = engine_openssl();
165 if(!toadd) return;
166 ENGINE_add(toadd);
167 /* If the "add" worked, it gets a structural reference. So either way,
168 * we release our just-created reference. */
169 ENGINE_free(toadd);
170 ERR_clear_error();
171 }
172
173/* This stuff is needed if this ENGINE is being compiled into a self-contained
174 * shared-library. */
175#ifdef ENGINE_DYNAMIC_SUPPORT
176static int bind_fn(ENGINE *e, const char *id)
177 {
178 if(id && (strcmp(id, engine_openssl_id) != 0))
179 return 0;
180 if(!bind_helper(e))
181 return 0;
182 return 1;
183 }
184IMPLEMENT_DYNAMIC_CHECK_FN()
185IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
186#endif /* ENGINE_DYNAMIC_SUPPORT */
187
188#ifdef TEST_ENG_OPENSSL_RC4
189/* This section of code compiles an "alternative implementation" of two modes of
190 * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
191 * should under normal circumstances go via this support rather than the default
192 * EVP support. There are other symbols to tweak the testing;
193 * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
194 * we're asked for a cipher we don't support (should not happen).
195 * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
196 * the "init_key" handler is called.
197 * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
198 */
199#include <openssl/rc4.h>
200#define TEST_RC4_KEY_SIZE 16
201static int test_cipher_nids[] = {NID_rc4,NID_rc4_40};
202static int test_cipher_nids_number = 2;
203typedef struct {
204 unsigned char key[TEST_RC4_KEY_SIZE];
205 RC4_KEY ks;
206 } TEST_RC4_KEY;
207#define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
208static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
209 const unsigned char *iv, int enc)
210 {
211#ifdef TEST_ENG_OPENSSL_RC4_P_INIT
212 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
213#endif
214 memcpy(&test(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx));
215 RC4_set_key(&test(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
216 test(ctx)->key);
217 return 1;
218 }
219static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
220 const unsigned char *in, unsigned int inl)
221 {
222#ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
223 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
224#endif
225 RC4(&test(ctx)->ks,inl,in,out);
226 return 1;
227 }
228static const EVP_CIPHER test_r4_cipher=
229 {
230 NID_rc4,
231 1,TEST_RC4_KEY_SIZE,0,
232 EVP_CIPH_VARIABLE_LENGTH,
233 test_rc4_init_key,
234 test_rc4_cipher,
235 NULL,
236 sizeof(TEST_RC4_KEY),
237 NULL,
238 NULL,
239 NULL
240 };
241static const EVP_CIPHER test_r4_40_cipher=
242 {
243 NID_rc4_40,
244 1,5 /* 40 bit */,0,
245 EVP_CIPH_VARIABLE_LENGTH,
246 test_rc4_init_key,
247 test_rc4_cipher,
248 NULL,
249 sizeof(TEST_RC4_KEY),
250 NULL,
251 NULL,
252 NULL
253 };
254static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
255 const int **nids, int nid)
256 {
257 if(!cipher)
258 {
259 /* We are returning a list of supported nids */
260 *nids = test_cipher_nids;
261 return test_cipher_nids_number;
262 }
263 /* We are being asked for a specific cipher */
264 if(nid == NID_rc4)
265 *cipher = &test_r4_cipher;
266 else if(nid == NID_rc4_40)
267 *cipher = &test_r4_40_cipher;
268 else
269 {
270#ifdef TEST_ENG_OPENSSL_RC4_OTHERS
271 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
272 "nid %d\n", nid);
273#endif
274 *cipher = NULL;
275 return 0;
276 }
277 return 1;
278 }
279#endif
280
281#ifdef TEST_ENG_OPENSSL_SHA
282/* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
283#include <openssl/sha.h>
284static int test_digest_nids[] = {NID_sha1};
285static int test_digest_nids_number = 1;
286static int test_sha1_init(EVP_MD_CTX *ctx)
287 {
288#ifdef TEST_ENG_OPENSSL_SHA_P_INIT
289 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
290#endif
291 return SHA1_Init(ctx->md_data);
292 }
293static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
294 {
295#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
296 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
297#endif
298 return SHA1_Update(ctx->md_data,data,count);
299 }
300static int test_sha1_final(EVP_MD_CTX *ctx,unsigned char *md)
301 {
302#ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
303 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
304#endif
305 return SHA1_Final(md,ctx->md_data);
306 }
307static const EVP_MD test_sha_md=
308 {
309 NID_sha1,
310 NID_sha1WithRSAEncryption,
311 SHA_DIGEST_LENGTH,
312 0,
313 test_sha1_init,
314 test_sha1_update,
315 test_sha1_final,
316 NULL,
317 NULL,
318 EVP_PKEY_RSA_method,
319 SHA_CBLOCK,
320 sizeof(EVP_MD *)+sizeof(SHA_CTX),
321 };
322static int openssl_digests(ENGINE *e, const EVP_MD **digest,
323 const int **nids, int nid)
324 {
325 if(!digest)
326 {
327 /* We are returning a list of supported nids */
328 *nids = test_digest_nids;
329 return test_digest_nids_number;
330 }
331 /* We are being asked for a specific digest */
332 if(nid == NID_sha1)
333 *digest = &test_sha_md;
334 else
335 {
336#ifdef TEST_ENG_OPENSSL_SHA_OTHERS
337 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
338 "nid %d\n", nid);
339#endif
340 *digest = NULL;
341 return 0;
342 }
343 return 1;
344 }
345#endif
346
347#ifdef TEST_ENG_OPENSSL_PKEY
348static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
349 UI_METHOD *ui_method, void *callback_data)
350 {
351 BIO *in;
352 EVP_PKEY *key;
353 fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", key_id);
354 in = BIO_new_file(key_id, "r");
355 if (!in)
356 return NULL;
357 key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
358 BIO_free(in);
359 return key;
360 }
361#endif
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c
new file mode 100644
index 0000000000..8c69171511
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_pkey.c
@@ -0,0 +1,157 @@
1/* crypto/engine/eng_pkey.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* Basic get/set stuff */
62
63int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f)
64 {
65 e->load_privkey = loadpriv_f;
66 return 1;
67 }
68
69int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
70 {
71 e->load_pubkey = loadpub_f;
72 return 1;
73 }
74
75ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
76 {
77 return e->load_privkey;
78 }
79
80ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
81 {
82 return e->load_pubkey;
83 }
84
85/* API functions to load public/private keys */
86
87EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
88 UI_METHOD *ui_method, void *callback_data)
89 {
90 EVP_PKEY *pkey;
91
92 if(e == NULL)
93 {
94 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
95 ERR_R_PASSED_NULL_PARAMETER);
96 return 0;
97 }
98 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
99 if(e->funct_ref == 0)
100 {
101 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
102 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
103 ENGINE_R_NOT_INITIALISED);
104 return 0;
105 }
106 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
107 if (!e->load_privkey)
108 {
109 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
110 ENGINE_R_NO_LOAD_FUNCTION);
111 return 0;
112 }
113 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
114 if (!pkey)
115 {
116 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
117 ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
118 return 0;
119 }
120 return pkey;
121 }
122
123EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
124 UI_METHOD *ui_method, void *callback_data)
125 {
126 EVP_PKEY *pkey;
127
128 if(e == NULL)
129 {
130 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
131 ERR_R_PASSED_NULL_PARAMETER);
132 return 0;
133 }
134 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
135 if(e->funct_ref == 0)
136 {
137 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
138 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
139 ENGINE_R_NOT_INITIALISED);
140 return 0;
141 }
142 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
143 if (!e->load_pubkey)
144 {
145 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
146 ENGINE_R_NO_LOAD_FUNCTION);
147 return 0;
148 }
149 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
150 if (!pkey)
151 {
152 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
153 ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
154 return 0;
155 }
156 return pkey;
157 }
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c
new file mode 100644
index 0000000000..c69a84a8bf
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_table.c
@@ -0,0 +1,361 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* This is the type of item in the 'implementation' table. Each 'nid' hashes to
60 * a (potentially NULL) ENGINE_PILE structure which contains a stack of ENGINE*
61 * pointers. These pointers aren't references, because they're inserted and
62 * removed during ENGINE creation and ENGINE destruction. They point to ENGINEs
63 * that *exist* (ie. have a structural reference count greater than zero) rather
64 * than ENGINEs that are *functional*. Each pointer in those stacks are to
65 * ENGINEs that implements the algorithm corresponding to each 'nid'. */
66
67/* The type of the items in the table */
68typedef struct st_engine_pile
69 {
70 /* The 'nid' of the algorithm/mode this ENGINE_PILE structure represents
71 * */
72 int nid;
73 /* A stack of ENGINE pointers for ENGINEs that support this
74 * algorithm/mode. In the event that 'funct' is NULL, the first entry in
75 * this stack that initialises will be set as 'funct' and assumed as the
76 * default for operations of this type. */
77 STACK_OF(ENGINE) *sk;
78 /* The default ENGINE to perform this algorithm/mode. */
79 ENGINE *funct;
80 /* This value optimises engine_table_select(). If it is called it sets
81 * this value to 1. Any changes to this ENGINE_PILE resets it to zero.
82 * As such, no ENGINE_init() thrashing is done unless ENGINEs
83 * continually register (and/or unregister). */
84 int uptodate;
85 } ENGINE_PILE;
86
87/* The type of the hash table of ENGINE_PILE structures such that each are
88 * unique and keyed by the 'nid' value. */
89struct st_engine_table
90 {
91 LHASH piles;
92 }; /* ENGINE_TABLE */
93
94/* This value stores global options controlling behaviour of (mostly) the
95 * engine_table_select() function. It's a bitmask of flag values of the form
96 * ENGINE_TABLE_FLAG_*** (as defined in engine.h) and is controlled by the
97 * ENGINE_[get|set]_table_flags() function. */
98static unsigned int table_flags = 0;
99
100/* API function manipulating 'table_flags' */
101unsigned int ENGINE_get_table_flags(void)
102 {
103 return table_flags;
104 }
105void ENGINE_set_table_flags(unsigned int flags)
106 {
107 table_flags = flags;
108 }
109
110/* Internal functions for the "piles" hash table */
111static unsigned long engine_pile_hash(const ENGINE_PILE *c)
112 {
113 return c->nid;
114 }
115static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b)
116 {
117 return a->nid - b->nid;
118 }
119static IMPLEMENT_LHASH_HASH_FN(engine_pile_hash, const ENGINE_PILE *)
120static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *)
121static int int_table_check(ENGINE_TABLE **t, int create)
122 {
123 LHASH *lh;
124 if(*t)
125 return 1;
126 if(!create)
127 return 0;
128 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash),
129 LHASH_COMP_FN(engine_pile_cmp))) == NULL)
130 return 0;
131 *t = (ENGINE_TABLE *)lh;
132 return 1;
133 }
134
135/* Privately exposed (via eng_int.h) functions for adding and/or removing
136 * ENGINEs from the implementation table */
137int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
138 ENGINE *e, const int *nids, int num_nids, int setdefault)
139 {
140 int ret = 0, added = 0;
141 ENGINE_PILE tmplate, *fnd;
142 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
143 if(!(*table))
144 added = 1;
145 if(!int_table_check(table, 1))
146 goto end;
147 if(added)
148 /* The cleanup callback needs to be added */
149 engine_cleanup_add_first(cleanup);
150 while(num_nids--)
151 {
152 tmplate.nid = *nids;
153 fnd = lh_retrieve(&(*table)->piles, &tmplate);
154 if(!fnd)
155 {
156 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
157 if(!fnd)
158 goto end;
159 fnd->uptodate = 1;
160 fnd->nid = *nids;
161 fnd->sk = sk_ENGINE_new_null();
162 if(!fnd->sk)
163 {
164 OPENSSL_free(fnd);
165 goto end;
166 }
167 fnd->funct= NULL;
168 lh_insert(&(*table)->piles, fnd);
169 }
170 /* A registration shouldn't add duplciate entries */
171 sk_ENGINE_delete_ptr(fnd->sk, e);
172 /* if 'setdefault', this ENGINE goes to the head of the list */
173 if(!sk_ENGINE_push(fnd->sk, e))
174 goto end;
175 /* "touch" this ENGINE_PILE */
176 fnd->uptodate = 0;
177 if(setdefault)
178 {
179 if(!engine_unlocked_init(e))
180 {
181 ENGINEerr(ENGINE_F_ENGINE_TABLE_REGISTER,
182 ENGINE_R_INIT_FAILED);
183 goto end;
184 }
185 if(fnd->funct)
186 engine_unlocked_finish(fnd->funct, 0);
187 fnd->funct = e;
188 }
189 nids++;
190 }
191 ret = 1;
192end:
193 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
194 return ret;
195 }
196static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
197 {
198 int n;
199 /* Iterate the 'c->sk' stack removing any occurance of 'e' */
200 while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
201 {
202 sk_ENGINE_delete(pile->sk, n);
203 /* "touch" this ENGINE_CIPHER */
204 pile->uptodate = 0;
205 }
206 if(pile->funct == e)
207 {
208 engine_unlocked_finish(e, 0);
209 pile->funct = NULL;
210 }
211 }
212static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *)
213void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e)
214 {
215 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
216 if(int_table_check(table, 0))
217 lh_doall_arg(&(*table)->piles,
218 LHASH_DOALL_ARG_FN(int_unregister_cb), e);
219 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
220 }
221
222static void int_cleanup_cb(ENGINE_PILE *p)
223 {
224 sk_ENGINE_free(p->sk);
225 if(p->funct)
226 engine_unlocked_finish(p->funct, 0);
227 OPENSSL_free(p);
228 }
229static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb,ENGINE_PILE *)
230void engine_table_cleanup(ENGINE_TABLE **table)
231 {
232 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
233 if(*table)
234 {
235 lh_doall(&(*table)->piles, LHASH_DOALL_FN(int_cleanup_cb));
236 lh_free(&(*table)->piles);
237 *table = NULL;
238 }
239 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
240 }
241
242/* Exposed API function to get a functional reference from the implementation
243 * table (ie. try to get a functional reference from the tabled structural
244 * references) for a given cipher 'nid' */
245#ifndef ENGINE_TABLE_DEBUG
246ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
247#else
248ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l)
249#endif
250 {
251 ENGINE *ret = NULL;
252 ENGINE_PILE tmplate, *fnd=NULL;
253 int initres, loop = 0;
254
255 /* If 'engine_ciphers' is NULL, then it's absolutely *sure* that no
256 * ENGINEs have registered any implementations! */
257 if(!(*table))
258 {
259#ifdef ENGINE_TABLE_DEBUG
260 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
261 "registered for anything!\n", f, l, nid);
262#endif
263 return NULL;
264 }
265 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
266 /* Check again inside the lock otherwise we could race against cleanup
267 * operations. But don't worry about a fprintf(stderr). */
268 if(!int_table_check(table, 0))
269 goto end;
270 tmplate.nid = nid;
271 fnd = lh_retrieve(&(*table)->piles, &tmplate);
272 if(!fnd)
273 goto end;
274 if(fnd->funct && engine_unlocked_init(fnd->funct))
275 {
276#ifdef ENGINE_TABLE_DEBUG
277 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
278 "ENGINE '%s' cached\n", f, l, nid, fnd->funct->id);
279#endif
280 ret = fnd->funct;
281 goto end;
282 }
283 if(fnd->uptodate)
284 {
285 ret = fnd->funct;
286 goto end;
287 }
288trynext:
289 ret = sk_ENGINE_value(fnd->sk, loop++);
290 if(!ret)
291 {
292#ifdef ENGINE_TABLE_DEBUG
293 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
294 "registered implementations would initialise\n",
295 f, l, nid);
296#endif
297 goto end;
298 }
299#if 0
300 /* Don't need to get a reference if we hold the lock. If the locking has
301 * to change in future, that would be different ... */
302 ret->struct_ref++; engine_ref_debug(ret, 0, 1)
303#endif
304 /* Try and initialise the ENGINE if it's already functional *or* if the
305 * ENGINE_TABLE_FLAG_NOINIT flag is not set. */
306 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))
307 initres = engine_unlocked_init(ret);
308 else
309 initres = 0;
310#if 0
311 /* Release the structural reference */
312 ret->struct_ref--; engine_ref_debug(ret, 0, -1);
313#endif
314 if(initres)
315 {
316 /* If we didn't have a default (functional reference) for this
317 * 'nid' (or we had one but for whatever reason we're now
318 * initialising a different one), use this opportunity to set
319 * 'funct'. */
320 if((fnd->funct != ret) && engine_unlocked_init(ret))
321 {
322 /* If there was a previous default we release it. */
323 if(fnd->funct)
324 engine_unlocked_finish(fnd->funct, 0);
325 /* We got an extra functional reference for the
326 * per-'nid' default */
327 fnd->funct = ret;
328#ifdef ENGINE_TABLE_DEBUG
329 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "
330 "setting default to '%s'\n", f, l, nid, ret->id);
331#endif
332 }
333#ifdef ENGINE_TABLE_DEBUG
334 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
335 "newly initialised '%s'\n", f, l, nid, ret->id);
336#endif
337 goto end;
338 }
339 goto trynext;
340end:
341 /* Whatever happened - we should "untouch" our uptodate file seeing as
342 * we have tried our best to find a functional reference for 'nid'. If
343 * it failed, it is unlikely to succeed again until some future
344 * registrations (or unregistrations) have taken place that affect that
345 * 'nid'. */
346 if(fnd)
347 fnd->uptodate = 1;
348#ifdef ENGINE_TABLE_DEBUG
349 if(ret)
350 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
351 "ENGINE '%s'\n", f, l, nid, ret->id);
352 else
353 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
354 "'no matching ENGINE'\n", f, l, nid);
355#endif
356 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
357 /* Whatever happened, any failed init()s are not failures in this
358 * context, so clear our error state. */
359 ERR_clear_error();
360 return ret;
361 }
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h
new file mode 100644
index 0000000000..900f75ce8d
--- /dev/null
+++ b/src/lib/libcrypto/engine/engine.h
@@ -0,0 +1,729 @@
1/* openssl/engine.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_ENGINE_H
60#define HEADER_ENGINE_H
61
62#include <openssl/opensslconf.h>
63
64#ifdef OPENSSL_NO_ENGINE
65#error ENGINE is disabled.
66#endif
67
68#include <openssl/ossl_typ.h>
69#include <openssl/bn.h>
70#ifndef OPENSSL_NO_RSA
71#include <openssl/rsa.h>
72#endif
73#ifndef OPENSSL_NO_DSA
74#include <openssl/dsa.h>
75#endif
76#ifndef OPENSSL_NO_DH
77#include <openssl/dh.h>
78#endif
79#include <openssl/rand.h>
80#include <openssl/ui.h>
81#include <openssl/symhacks.h>
82#include <openssl/err.h>
83
84#ifdef __cplusplus
85extern "C" {
86#endif
87
88/* Fixups for missing algorithms */
89#ifdef OPENSSL_NO_RSA
90typedef void RSA_METHOD;
91#endif
92#ifdef OPENSSL_NO_DSA
93typedef void DSA_METHOD;
94#endif
95#ifdef OPENSSL_NO_DH
96typedef void DH_METHOD;
97#endif
98
99/* These flags are used to control combinations of algorithm (methods)
100 * by bitwise "OR"ing. */
101#define ENGINE_METHOD_RSA (unsigned int)0x0001
102#define ENGINE_METHOD_DSA (unsigned int)0x0002
103#define ENGINE_METHOD_DH (unsigned int)0x0004
104#define ENGINE_METHOD_RAND (unsigned int)0x0008
105#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040
106#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080
107/* Obvious all-or-nothing cases. */
108#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
109#define ENGINE_METHOD_NONE (unsigned int)0x0000
110
111/* This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used
112 * internally to control registration of ENGINE implementations, and can be set
113 * by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to
114 * initialise registered ENGINEs if they are not already initialised. */
115#define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001
116
117/* ENGINE flags that can be set by ENGINE_set_flags(). */
118/* #define ENGINE_FLAGS_MALLOCED 0x0001 */ /* Not used */
119
120/* This flag is for ENGINEs that wish to handle the various 'CMD'-related
121 * control commands on their own. Without this flag, ENGINE_ctrl() handles these
122 * control commands on behalf of the ENGINE using their "cmd_defns" data. */
123#define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002
124
125/* This flag is for ENGINEs who return new duplicate structures when found via
126 * "ENGINE_by_id()". When an ENGINE must store state (eg. if ENGINE_ctrl()
127 * commands are called in sequence as part of some stateful process like
128 * key-generation setup and execution), it can set this flag - then each attempt
129 * to obtain the ENGINE will result in it being copied into a new structure.
130 * Normally, ENGINEs don't declare this flag so ENGINE_by_id() just increments
131 * the existing ENGINE's structural reference count. */
132#define ENGINE_FLAGS_BY_ID_COPY (int)0x0004
133
134/* ENGINEs can support their own command types, and these flags are used in
135 * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input each
136 * command expects. Currently only numeric and string input is supported. If a
137 * control command supports none of the _NUMERIC, _STRING, or _NO_INPUT options,
138 * then it is regarded as an "internal" control command - and not for use in
139 * config setting situations. As such, they're not available to the
140 * ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() access. Changes to
141 * this list of 'command types' should be reflected carefully in
142 * ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). */
143
144/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */
145#define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
146/* accepts string input (cast from 'void*' to 'const char *', 4th parameter to
147 * ENGINE_ctrl) */
148#define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
149/* Indicates that the control command takes *no* input. Ie. the control command
150 * is unparameterised. */
151#define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
152/* Indicates that the control command is internal. This control command won't
153 * be shown in any output, and is only usable through the ENGINE_ctrl_cmd()
154 * function. */
155#define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
156
157/* NB: These 3 control commands are deprecated and should not be used. ENGINEs
158 * relying on these commands should compile conditional support for
159 * compatibility (eg. if these symbols are defined) but should also migrate the
160 * same functionality to their own ENGINE-specific control functions that can be
161 * "discovered" by calling applications. The fact these control commands
162 * wouldn't be "executable" (ie. usable by text-based config) doesn't change the
163 * fact that application code can find and use them without requiring per-ENGINE
164 * hacking. */
165
166/* These flags are used to tell the ctrl function what should be done.
167 * All command numbers are shared between all engines, even if some don't
168 * make sense to some engines. In such a case, they do nothing but return
169 * the error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. */
170#define ENGINE_CTRL_SET_LOGSTREAM 1
171#define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2
172#define ENGINE_CTRL_HUP 3 /* Close and reinitialise any
173 handles/connections etc. */
174#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */
175#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used
176 when calling the password
177 callback and the user
178 interface */
179
180/* These control commands allow an application to deal with an arbitrary engine
181 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE
182 * COMMANDS because zero is used to indicate 'end-of-list'. Other commands,
183 * including ENGINE-specific command types, return zero for an error.
184 *
185 * An ENGINE can choose to implement these ctrl functions, and can internally
186 * manage things however it chooses - it does so by setting the
187 * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise the
188 * ENGINE_ctrl() code handles this on the ENGINE's behalf using the cmd_defns
189 * data (set using ENGINE_set_cmd_defns()). This means an ENGINE's ctrl()
190 * handler need only implement its own commands - the above "meta" commands will
191 * be taken care of. */
192
193/* Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", then
194 * all the remaining control commands will return failure, so it is worth
195 * checking this first if the caller is trying to "discover" the engine's
196 * capabilities and doesn't want errors generated unnecessarily. */
197#define ENGINE_CTRL_HAS_CTRL_FUNCTION 10
198/* Returns a positive command number for the first command supported by the
199 * engine. Returns zero if no ctrl commands are supported. */
200#define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
201/* The 'long' argument specifies a command implemented by the engine, and the
202 * return value is the next command supported, or zero if there are no more. */
203#define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
204/* The 'void*' argument is a command name (cast from 'const char *'), and the
205 * return value is the command that corresponds to it. */
206#define ENGINE_CTRL_GET_CMD_FROM_NAME 13
207/* The next two allow a command to be converted into its corresponding string
208 * form. In each case, the 'long' argument supplies the command. In the NAME_LEN
209 * case, the return value is the length of the command name (not counting a
210 * trailing EOL). In the NAME case, the 'void*' argument must be a string buffer
211 * large enough, and it will be populated with the name of the command (WITH a
212 * trailing EOL). */
213#define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
214#define ENGINE_CTRL_GET_NAME_FROM_CMD 15
215/* The next two are similar but give a "short description" of a command. */
216#define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
217#define ENGINE_CTRL_GET_DESC_FROM_CMD 17
218/* With this command, the return value is the OR'd combination of
219 * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given
220 * engine-specific ctrl command expects. */
221#define ENGINE_CTRL_GET_CMD_FLAGS 18
222
223/* ENGINE implementations should start the numbering of their own control
224 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */
225#define ENGINE_CMD_BASE 200
226
227/* NB: These 2 nCipher "chil" control commands are deprecated, and their
228 * functionality is now available through ENGINE-specific control commands
229 * (exposed through the above-mentioned 'CMD'-handling). Code using these 2
230 * commands should be migrated to the more general command handling before these
231 * are removed. */
232
233/* Flags specific to the nCipher "chil" engine */
234#define ENGINE_CTRL_CHIL_SET_FORKCHECK 100
235 /* Depending on the value of the (long)i argument, this sets or
236 * unsets the SimpleForkCheck flag in the CHIL API to enable or
237 * disable checking and workarounds for applications that fork().
238 */
239#define ENGINE_CTRL_CHIL_NO_LOCKING 101
240 /* This prevents the initialisation function from providing mutex
241 * callbacks to the nCipher library. */
242
243/* If an ENGINE supports its own specific control commands and wishes the
244 * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on its
245 * behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN entries
246 * to ENGINE_set_cmd_defns(). It should also implement a ctrl() handler that
247 * supports the stated commands (ie. the "cmd_num" entries as described by the
248 * array). NB: The array must be ordered in increasing order of cmd_num.
249 * "null-terminated" means that the last ENGINE_CMD_DEFN element has cmd_num set
250 * to zero and/or cmd_name set to NULL. */
251typedef struct ENGINE_CMD_DEFN_st
252 {
253 unsigned int cmd_num; /* The command number */
254 const char *cmd_name; /* The command name itself */
255 const char *cmd_desc; /* A short description of the command */
256 unsigned int cmd_flags; /* The input the command expects */
257 } ENGINE_CMD_DEFN;
258
259/* Generic function pointer */
260typedef int (*ENGINE_GEN_FUNC_PTR)();
261/* Generic function pointer taking no arguments */
262typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);
263/* Specific control function pointer */
264typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)());
265/* Generic load_key function pointer */
266typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
267 UI_METHOD *ui_method, void *callback_data);
268/* These callback types are for an ENGINE's handler for cipher and digest logic.
269 * These handlers have these prototypes;
270 * int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid);
271 * int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid);
272 * Looking at how to implement these handlers in the case of cipher support, if
273 * the framework wants the EVP_CIPHER for 'nid', it will call;
274 * foo(e, &p_evp_cipher, NULL, nid); (return zero for failure)
275 * If the framework wants a list of supported 'nid's, it will call;
276 * foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error)
277 */
278/* Returns to a pointer to the array of supported cipher 'nid's. If the second
279 * parameter is non-NULL it is set to the size of the returned array. */
280typedef int (*ENGINE_CIPHERS_PTR)(ENGINE *, const EVP_CIPHER **, const int **, int);
281typedef int (*ENGINE_DIGESTS_PTR)(ENGINE *, const EVP_MD **, const int **, int);
282
283/* STRUCTURE functions ... all of these functions deal with pointers to ENGINE
284 * structures where the pointers have a "structural reference". This means that
285 * their reference is to allowed access to the structure but it does not imply
286 * that the structure is functional. To simply increment or decrement the
287 * structural reference count, use ENGINE_by_id and ENGINE_free. NB: This is not
288 * required when iterating using ENGINE_get_next as it will automatically
289 * decrement the structural reference count of the "current" ENGINE and
290 * increment the structural reference count of the ENGINE it returns (unless it
291 * is NULL). */
292
293/* Get the first/last "ENGINE" type available. */
294ENGINE *ENGINE_get_first(void);
295ENGINE *ENGINE_get_last(void);
296/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
297ENGINE *ENGINE_get_next(ENGINE *e);
298ENGINE *ENGINE_get_prev(ENGINE *e);
299/* Add another "ENGINE" type into the array. */
300int ENGINE_add(ENGINE *e);
301/* Remove an existing "ENGINE" type from the array. */
302int ENGINE_remove(ENGINE *e);
303/* Retrieve an engine from the list by its unique "id" value. */
304ENGINE *ENGINE_by_id(const char *id);
305/* Add all the built-in engines. */
306void ENGINE_load_openssl(void);
307void ENGINE_load_dynamic(void);
308void ENGINE_load_cswift(void);
309void ENGINE_load_chil(void);
310void ENGINE_load_atalla(void);
311void ENGINE_load_nuron(void);
312void ENGINE_load_ubsec(void);
313void ENGINE_load_aep(void);
314void ENGINE_load_sureware(void);
315void ENGINE_load_4758cca(void);
316void ENGINE_load_cryptodev(void);
317void ENGINE_load_builtin_engines(void);
318
319/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
320 * "registry" handling. */
321unsigned int ENGINE_get_table_flags(void);
322void ENGINE_set_table_flags(unsigned int flags);
323
324/* Manage registration of ENGINEs per "table". For each type, there are 3
325 * functions;
326 * ENGINE_register_***(e) - registers the implementation from 'e' (if it has one)
327 * ENGINE_unregister_***(e) - unregister the implementation from 'e'
328 * ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list
329 * Cleanup is automatically registered from each table when required, so
330 * ENGINE_cleanup() will reverse any "register" operations. */
331
332int ENGINE_register_RSA(ENGINE *e);
333void ENGINE_unregister_RSA(ENGINE *e);
334void ENGINE_register_all_RSA(void);
335
336int ENGINE_register_DSA(ENGINE *e);
337void ENGINE_unregister_DSA(ENGINE *e);
338void ENGINE_register_all_DSA(void);
339
340int ENGINE_register_DH(ENGINE *e);
341void ENGINE_unregister_DH(ENGINE *e);
342void ENGINE_register_all_DH(void);
343
344int ENGINE_register_RAND(ENGINE *e);
345void ENGINE_unregister_RAND(ENGINE *e);
346void ENGINE_register_all_RAND(void);
347
348int ENGINE_register_ciphers(ENGINE *e);
349void ENGINE_unregister_ciphers(ENGINE *e);
350void ENGINE_register_all_ciphers(void);
351
352int ENGINE_register_digests(ENGINE *e);
353void ENGINE_unregister_digests(ENGINE *e);
354void ENGINE_register_all_digests(void);
355
356/* These functions register all support from the above categories. Note, use of
357 * these functions can result in static linkage of code your application may not
358 * need. If you only need a subset of functionality, consider using more
359 * selective initialisation. */
360int ENGINE_register_complete(ENGINE *e);
361int ENGINE_register_all_complete(void);
362
363/* Send parametrised control commands to the engine. The possibilities to send
364 * down an integer, a pointer to data or a function pointer are provided. Any of
365 * the parameters may or may not be NULL, depending on the command number. In
366 * actuality, this function only requires a structural (rather than functional)
367 * reference to an engine, but many control commands may require the engine be
368 * functional. The caller should be aware of trying commands that require an
369 * operational ENGINE, and only use functional references in such situations. */
370int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
371
372/* This function tests if an ENGINE-specific command is usable as a "setting".
373 * Eg. in an application's config file that gets processed through
374 * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to
375 * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). */
376int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
377
378/* This function works like ENGINE_ctrl() with the exception of taking a
379 * command name instead of a command number, and can handle optional commands.
380 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to
381 * use the cmd_name and cmd_optional. */
382int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
383 long i, void *p, void (*f)(), int cmd_optional);
384
385/* This function passes a command-name and argument to an ENGINE. The cmd_name
386 * is converted to a command number and the control command is called using
387 * 'arg' as an argument (unless the ENGINE doesn't support such a command, in
388 * which case no control command is called). The command is checked for input
389 * flags, and if necessary the argument will be converted to a numeric value. If
390 * cmd_optional is non-zero, then if the ENGINE doesn't support the given
391 * cmd_name the return value will be success anyway. This function is intended
392 * for applications to use so that users (or config files) can supply
393 * engine-specific config data to the ENGINE at run-time to control behaviour of
394 * specific engines. As such, it shouldn't be used for calling ENGINE_ctrl()
395 * functions that return data, deal with binary data, or that are otherwise
396 * supposed to be used directly through ENGINE_ctrl() in application code. Any
397 * "return" data from an ENGINE_ctrl() operation in this function will be lost -
398 * the return value is interpreted as failure if the return value is zero,
399 * success otherwise, and this function returns a boolean value as a result. In
400 * other words, vendors of 'ENGINE'-enabled devices should write ENGINE
401 * implementations with parameterisations that work in this scheme, so that
402 * compliant ENGINE-based applications can work consistently with the same
403 * configuration for the same ENGINE-enabled devices, across applications. */
404int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
405 int cmd_optional);
406
407/* These functions are useful for manufacturing new ENGINE structures. They
408 * don't address reference counting at all - one uses them to populate an ENGINE
409 * structure with personalised implementations of things prior to using it
410 * directly or adding it to the builtin ENGINE list in OpenSSL. These are also
411 * here so that the ENGINE structure doesn't have to be exposed and break binary
412 * compatibility! */
413ENGINE *ENGINE_new(void);
414int ENGINE_free(ENGINE *e);
415int ENGINE_up_ref(ENGINE *e);
416int ENGINE_set_id(ENGINE *e, const char *id);
417int ENGINE_set_name(ENGINE *e, const char *name);
418int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
419int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
420int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
421int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
422int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
423int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
424int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
425int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
426int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
427int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
428int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
429int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
430int ENGINE_set_flags(ENGINE *e, int flags);
431int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
432/* These functions (and the "get" function lower down) allow control over any
433 * per-structure ENGINE data. */
434int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
435 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
436int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
437
438/* This function cleans up anything that needs it. Eg. the ENGINE_add() function
439 * automatically ensures the list cleanup function is registered to be called
440 * from ENGINE_cleanup(). Similarly, all ENGINE_register_*** functions ensure
441 * ENGINE_cleanup() will clean up after them. */
442void ENGINE_cleanup(void);
443
444/* These return values from within the ENGINE structure. These can be useful
445 * with functional references as well as structural references - it depends
446 * which you obtained. Using the result for functional purposes if you only
447 * obtained a structural reference may be problematic! */
448const char *ENGINE_get_id(const ENGINE *e);
449const char *ENGINE_get_name(const ENGINE *e);
450const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
451const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
452const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
453const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
454ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
455ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
456ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
457ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
458ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
459ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
460ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
461ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
462const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
463const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
464const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
465int ENGINE_get_flags(const ENGINE *e);
466void *ENGINE_get_ex_data(const ENGINE *e, int idx);
467
468/* FUNCTIONAL functions. These functions deal with ENGINE structures
469 * that have (or will) be initialised for use. Broadly speaking, the
470 * structural functions are useful for iterating the list of available
471 * engine types, creating new engine types, and other "list" operations.
472 * These functions actually deal with ENGINEs that are to be used. As
473 * such these functions can fail (if applicable) when particular
474 * engines are unavailable - eg. if a hardware accelerator is not
475 * attached or not functioning correctly. Each ENGINE has 2 reference
476 * counts; structural and functional. Every time a functional reference
477 * is obtained or released, a corresponding structural reference is
478 * automatically obtained or released too. */
479
480/* Initialise a engine type for use (or up its reference count if it's
481 * already in use). This will fail if the engine is not currently
482 * operational and cannot initialise. */
483int ENGINE_init(ENGINE *e);
484/* Free a functional reference to a engine type. This does not require
485 * a corresponding call to ENGINE_free as it also releases a structural
486 * reference. */
487int ENGINE_finish(ENGINE *e);
488
489/* The following functions handle keys that are stored in some secondary
490 * location, handled by the engine. The storage may be on a card or
491 * whatever. */
492EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
493 UI_METHOD *ui_method, void *callback_data);
494EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
495 UI_METHOD *ui_method, void *callback_data);
496
497/* This returns a pointer for the current ENGINE structure that
498 * is (by default) performing any RSA operations. The value returned
499 * is an incremented reference, so it should be free'd (ENGINE_finish)
500 * before it is discarded. */
501ENGINE *ENGINE_get_default_RSA(void);
502/* Same for the other "methods" */
503ENGINE *ENGINE_get_default_DSA(void);
504ENGINE *ENGINE_get_default_DH(void);
505ENGINE *ENGINE_get_default_RAND(void);
506/* These functions can be used to get a functional reference to perform
507 * ciphering or digesting corresponding to "nid". */
508ENGINE *ENGINE_get_cipher_engine(int nid);
509ENGINE *ENGINE_get_digest_engine(int nid);
510
511/* This sets a new default ENGINE structure for performing RSA
512 * operations. If the result is non-zero (success) then the ENGINE
513 * structure will have had its reference count up'd so the caller
514 * should still free their own reference 'e'. */
515int ENGINE_set_default_RSA(ENGINE *e);
516int ENGINE_set_default_string(ENGINE *e, const char *def_list);
517/* Same for the other "methods" */
518int ENGINE_set_default_DSA(ENGINE *e);
519int ENGINE_set_default_DH(ENGINE *e);
520int ENGINE_set_default_RAND(ENGINE *e);
521int ENGINE_set_default_ciphers(ENGINE *e);
522int ENGINE_set_default_digests(ENGINE *e);
523
524/* The combination "set" - the flags are bitwise "OR"d from the
525 * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()"
526 * function, this function can result in unnecessary static linkage. If your
527 * application requires only specific functionality, consider using more
528 * selective functions. */
529int ENGINE_set_default(ENGINE *e, unsigned int flags);
530
531void ENGINE_add_conf_module(void);
532
533/* Deprecated functions ... */
534/* int ENGINE_clear_defaults(void); */
535
536/**************************/
537/* DYNAMIC ENGINE SUPPORT */
538/**************************/
539
540/* Binary/behaviour compatibility levels */
541#define OSSL_DYNAMIC_VERSION (unsigned long)0x00010200
542/* Binary versions older than this are too old for us (whether we're a loader or
543 * a loadee) */
544#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00010200
545
546/* When compiling an ENGINE entirely as an external shared library, loadable by
547 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure
548 * type provides the calling application's (or library's) error functionality
549 * and memory management function pointers to the loaded library. These should
550 * be used/set in the loaded library code so that the loading application's
551 * 'state' will be used/changed in all operations. */
552typedef void *(*dyn_MEM_malloc_cb)(size_t);
553typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
554typedef void (*dyn_MEM_free_cb)(void *);
555typedef struct st_dynamic_MEM_fns {
556 dyn_MEM_malloc_cb malloc_cb;
557 dyn_MEM_realloc_cb realloc_cb;
558 dyn_MEM_free_cb free_cb;
559 } dynamic_MEM_fns;
560/* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use
561 * these types so we (and any other dependant code) can simplify a bit?? */
562typedef void (*dyn_lock_locking_cb)(int,int,const char *,int);
563typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int);
564typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)(
565 const char *,int);
566typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *,
567 const char *,int);
568typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *,
569 const char *,int);
570typedef struct st_dynamic_LOCK_fns {
571 dyn_lock_locking_cb lock_locking_cb;
572 dyn_lock_add_lock_cb lock_add_lock_cb;
573 dyn_dynlock_create_cb dynlock_create_cb;
574 dyn_dynlock_lock_cb dynlock_lock_cb;
575 dyn_dynlock_destroy_cb dynlock_destroy_cb;
576 } dynamic_LOCK_fns;
577/* The top-level structure */
578typedef struct st_dynamic_fns {
579 const ERR_FNS *err_fns;
580 const CRYPTO_EX_DATA_IMPL *ex_data_fns;
581 dynamic_MEM_fns mem_fns;
582 dynamic_LOCK_fns lock_fns;
583 } dynamic_fns;
584
585/* The version checking function should be of this prototype. NB: The
586 * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading code.
587 * If this function returns zero, it indicates a (potential) version
588 * incompatibility and the loaded library doesn't believe it can proceed.
589 * Otherwise, the returned value is the (latest) version supported by the
590 * loading library. The loader may still decide that the loaded code's version
591 * is unsatisfactory and could veto the load. The function is expected to
592 * be implemented with the symbol name "v_check", and a default implementation
593 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */
594typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
595#define IMPLEMENT_DYNAMIC_CHECK_FN() \
596 unsigned long v_check(unsigned long v) { \
597 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
598 return 0; }
599
600/* This function is passed the ENGINE structure to initialise with its own
601 * function and command settings. It should not adjust the structural or
602 * functional reference counts. If this function returns zero, (a) the load will
603 * be aborted, (b) the previous ENGINE state will be memcpy'd back onto the
604 * structure, and (c) the shared library will be unloaded. So implementations
605 * should do their own internal cleanup in failure circumstances otherwise they
606 * could leak. The 'id' parameter, if non-NULL, represents the ENGINE id that
607 * the loader is looking for. If this is NULL, the shared library can choose to
608 * return failure or to initialise a 'default' ENGINE. If non-NULL, the shared
609 * library must initialise only an ENGINE matching the passed 'id'. The function
610 * is expected to be implemented with the symbol name "bind_engine". A standard
611 * implementation can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where
612 * the parameter 'fn' is a callback function that populates the ENGINE structure
613 * and returns an int value (zero for failure). 'fn' should have prototype;
614 * [static] int fn(ENGINE *e, const char *id); */
615typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
616 const dynamic_fns *fns);
617#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
618 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
619 if (ERR_get_implementation() != fns->err_fns) \
620 { \
621 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
622 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
623 return 0; \
624 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
625 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
626 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
627 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
628 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
629 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
630 return 0; \
631 if(!ERR_set_implementation(fns->err_fns)) return 0; \
632 } \
633 if(!fn(e,id)) return 0; \
634 return 1; }
635
636#if defined(__OpenBSD__) || defined(__FreeBSD__)
637void ENGINE_setup_bsd_cryptodev(void);
638#endif
639
640/* BEGIN ERROR CODES */
641/* The following lines are auto generated by the script mkerr.pl. Any changes
642 * made after this point may be overwritten when the script is next run.
643 */
644void ERR_load_ENGINE_strings(void);
645
646/* Error codes for the ENGINE functions. */
647
648/* Function codes. */
649#define ENGINE_F_DYNAMIC_CTRL 180
650#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181
651#define ENGINE_F_DYNAMIC_LOAD 182
652#define ENGINE_F_ENGINE_ADD 105
653#define ENGINE_F_ENGINE_BY_ID 106
654#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170
655#define ENGINE_F_ENGINE_CTRL 142
656#define ENGINE_F_ENGINE_CTRL_CMD 178
657#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171
658#define ENGINE_F_ENGINE_FINISH 107
659#define ENGINE_F_ENGINE_FREE 108
660#define ENGINE_F_ENGINE_GET_CIPHER 185
661#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177
662#define ENGINE_F_ENGINE_GET_DIGEST 186
663#define ENGINE_F_ENGINE_GET_NEXT 115
664#define ENGINE_F_ENGINE_GET_PREV 116
665#define ENGINE_F_ENGINE_INIT 119
666#define ENGINE_F_ENGINE_LIST_ADD 120
667#define ENGINE_F_ENGINE_LIST_REMOVE 121
668#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
669#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
670#define ENGINE_F_ENGINE_MODULE_INIT 187
671#define ENGINE_F_ENGINE_NEW 122
672#define ENGINE_F_ENGINE_REMOVE 123
673#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
674#define ENGINE_F_ENGINE_SET_DEFAULT_TYPE 126
675#define ENGINE_F_ENGINE_SET_ID 129
676#define ENGINE_F_ENGINE_SET_NAME 130
677#define ENGINE_F_ENGINE_TABLE_REGISTER 184
678#define ENGINE_F_ENGINE_UNLOAD_KEY 152
679#define ENGINE_F_ENGINE_UP_REF 190
680#define ENGINE_F_INT_CTRL_HELPER 172
681#define ENGINE_F_INT_ENGINE_CONFIGURE 188
682#define ENGINE_F_LOG_MESSAGE 141
683#define ENGINE_F_SET_DATA_CTX 183
684
685/* Reason codes. */
686#define ENGINE_R_ALREADY_LOADED 100
687#define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133
688#define ENGINE_R_CMD_NOT_EXECUTABLE 134
689#define ENGINE_R_COMMAND_TAKES_INPUT 135
690#define ENGINE_R_COMMAND_TAKES_NO_INPUT 136
691#define ENGINE_R_CONFLICTING_ENGINE_ID 103
692#define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119
693#define ENGINE_R_DH_NOT_IMPLEMENTED 139
694#define ENGINE_R_DSA_NOT_IMPLEMENTED 140
695#define ENGINE_R_DSO_FAILURE 104
696#define ENGINE_R_DSO_NOT_FOUND 132
697#define ENGINE_R_ENGINES_SECTION_ERROR 148
698#define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105
699#define ENGINE_R_ENGINE_SECTION_ERROR 149
700#define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128
701#define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129
702#define ENGINE_R_FINISH_FAILED 106
703#define ENGINE_R_GET_HANDLE_FAILED 107
704#define ENGINE_R_ID_OR_NAME_MISSING 108
705#define ENGINE_R_INIT_FAILED 109
706#define ENGINE_R_INTERNAL_LIST_ERROR 110
707#define ENGINE_R_INVALID_ARGUMENT 143
708#define ENGINE_R_INVALID_CMD_NAME 137
709#define ENGINE_R_INVALID_CMD_NUMBER 138
710#define ENGINE_R_INVALID_INIT_VALUE 151
711#define ENGINE_R_INVALID_STRING 150
712#define ENGINE_R_NOT_INITIALISED 117
713#define ENGINE_R_NOT_LOADED 112
714#define ENGINE_R_NO_CONTROL_FUNCTION 120
715#define ENGINE_R_NO_INDEX 144
716#define ENGINE_R_NO_LOAD_FUNCTION 125
717#define ENGINE_R_NO_REFERENCE 130
718#define ENGINE_R_NO_SUCH_ENGINE 116
719#define ENGINE_R_NO_UNLOAD_FUNCTION 126
720#define ENGINE_R_PROVIDE_PARAMETERS 113
721#define ENGINE_R_RSA_NOT_IMPLEMENTED 141
722#define ENGINE_R_UNIMPLEMENTED_CIPHER 146
723#define ENGINE_R_UNIMPLEMENTED_DIGEST 147
724#define ENGINE_R_VERSION_INCOMPATIBILITY 145
725
726#ifdef __cplusplus
727}
728#endif
729#endif
diff --git a/src/lib/libcrypto/engine/hw_aep.c b/src/lib/libcrypto/engine/hw_aep.c
index 5f1772ea99..8b8380a582 100644
--- a/src/lib/libcrypto/engine/hw_aep.c
+++ b/src/lib/libcrypto/engine/hw_aep.c
@@ -474,7 +474,6 @@ static int aep_init(ENGINE *e)
474 474
475 if(aep_dso) 475 if(aep_dso)
476 DSO_free(aep_dso); 476 DSO_free(aep_dso);
477 aep_dso = NULL;
478 477
479 p_AEP_OpenConnection = NULL; 478 p_AEP_OpenConnection = NULL;
480 p_AEP_ModExp = NULL; 479 p_AEP_ModExp = NULL;
diff --git a/src/lib/libcrypto/engine/hw_atalla.c b/src/lib/libcrypto/engine/hw_atalla.c
index 2b8342bbdd..e9eff9fad1 100644
--- a/src/lib/libcrypto/engine/hw_atalla.c
+++ b/src/lib/libcrypto/engine/hw_atalla.c
@@ -375,7 +375,6 @@ static int atalla_init(ENGINE *e)
375err: 375err:
376 if(atalla_dso) 376 if(atalla_dso)
377 DSO_free(atalla_dso); 377 DSO_free(atalla_dso);
378 atalla_dso = NULL;
379 p_Atalla_GetHardwareConfig = NULL; 378 p_Atalla_GetHardwareConfig = NULL;
380 p_Atalla_RSAPrivateKeyOpFn = NULL; 379 p_Atalla_RSAPrivateKeyOpFn = NULL;
381 p_Atalla_GetPerformanceStatistics = NULL; 380 p_Atalla_GetPerformanceStatistics = NULL;
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c
index 3e7fff1c1e..d3b186c132 100644
--- a/src/lib/libcrypto/engine/hw_cryptodev.c
+++ b/src/lib/libcrypto/engine/hw_cryptodev.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2002-2004 Theo de Raadt
2 * Copyright (c) 2002 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2002 Bob Beck <beck@openbsd.org>
3 * Copyright (c) 2002 Theo de Raadt
4 * Copyright (c) 2002 Markus Friedl 4 * Copyright (c) 2002 Markus Friedl
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
@@ -49,11 +49,12 @@ ENGINE_load_cryptodev(void)
49 return; 49 return;
50} 50}
51 51
52#else 52#else
53 53
54#include <sys/types.h> 54#include <sys/types.h>
55#include <crypto/cryptodev.h> 55#include <crypto/cryptodev.h>
56#include <sys/ioctl.h> 56#include <sys/ioctl.h>
57
57#include <errno.h> 58#include <errno.h>
58#include <stdio.h> 59#include <stdio.h>
59#include <unistd.h> 60#include <unistd.h>
@@ -63,19 +64,34 @@ ENGINE_load_cryptodev(void)
63#include <errno.h> 64#include <errno.h>
64#include <string.h> 65#include <string.h>
65 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
66struct dev_crypto_state { 77struct dev_crypto_state {
67 struct session_op d_sess; 78 struct session_op d_sess;
68 int d_fd; 79 int d_fd;
69}; 80};
70 81
82struct dev_crypto_cipher {
83 int c_id;
84 int c_nid;
85 int c_ivmax;
86 int c_keylen;
87};
88
71static u_int32_t cryptodev_asymfeat = 0; 89static u_int32_t cryptodev_asymfeat = 0;
72 90
73static int get_asym_dev_crypto(void); 91static int get_asym_dev_crypto(void);
74static int open_dev_crypto(void); 92static int open_dev_crypto(void);
75static int get_dev_crypto(void); 93static int get_dev_crypto(void);
76static int cryptodev_max_iv(int cipher); 94static struct dev_crypto_cipher *cipher_nid_to_cryptodev(int nid);
77static int cryptodev_key_length_valid(int cipher, int len);
78static int cipher_nid_to_cryptodev(int nid);
79static int get_cryptodev_ciphers(const int **cnids); 95static int get_cryptodev_ciphers(const int **cnids);
80/*static int get_cryptodev_digests(const int **cnids);*/ 96/*static int get_cryptodev_digests(const int **cnids);*/
81static int cryptodev_usable_ciphers(const int **nids); 97static int cryptodev_usable_ciphers(const int **nids);
@@ -122,15 +138,12 @@ static const ENGINE_CMD_DEFN cryptodev_defns[] = {
122 { 0, NULL, NULL, 0 } 138 { 0, NULL, NULL, 0 }
123}; 139};
124 140
125static struct { 141static struct dev_crypto_cipher ciphers[] = {
126 int id;
127 int nid;
128 int ivmax;
129 int keylen;
130} ciphers[] = {
131 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, }, 142 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
132 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, }, 143 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
133 { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, }, 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, },
134 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, }, 147 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
135 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, }, 148 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, },
136 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, }, 149 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
@@ -153,7 +166,7 @@ static struct {
153#endif 166#endif
154 167
155/* 168/*
156 * Return a fd if /dev/crypto seems usable, 0 otherwise. 169 * Return a fd if /dev/crypto seems usable, -1 otherwise.
157 */ 170 */
158static int 171static int
159open_dev_crypto(void) 172open_dev_crypto(void)
@@ -180,8 +193,10 @@ get_dev_crypto(void)
180 193
181 if ((fd = open_dev_crypto()) == -1) 194 if ((fd = open_dev_crypto()) == -1)
182 return (-1); 195 return (-1);
183 if (ioctl(fd, CRIOGET, &retfd) == -1) 196 if (ioctl(fd, CRIOGET, &retfd) == -1) {
197 close(fd);
184 return (-1); 198 return (-1);
199 }
185 200
186 /* close on exec */ 201 /* close on exec */
187 if (fcntl(retfd, F_SETFD, 1) == -1) { 202 if (fcntl(retfd, F_SETFD, 1) == -1) {
@@ -202,48 +217,16 @@ get_asym_dev_crypto(void)
202 return fd; 217 return fd;
203} 218}
204 219
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 */ 220/* convert libcrypto nids to cryptodev */
238static int 221static struct dev_crypto_cipher *
239cipher_nid_to_cryptodev(int nid) 222cipher_nid_to_cryptodev(int nid)
240{ 223{
241 int i; 224 int i;
242 225
243 for (i = 0; ciphers[i].id; i++) 226 for (i = 0; ciphers[i].c_id; i++)
244 if (ciphers[i].nid == nid) 227 if (ciphers[i].c_nid == nid)
245 return (ciphers[i].id); 228 return (&ciphers[i]);
246 return (0); 229 return (NULL);
247} 230}
248 231
249/* 232/*
@@ -266,18 +249,45 @@ get_cryptodev_ciphers(const int **cnids)
266 memset(&sess, 0, sizeof(sess)); 249 memset(&sess, 0, sizeof(sess));
267 sess.key = (caddr_t)"123456781234567812345678"; 250 sess.key = (caddr_t)"123456781234567812345678";
268 251
269 for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { 252 for (i = 0; ciphers[i].c_id && count < CRYPTO_ALGORITHM_MAX; i++) {
270 if (ciphers[i].nid == NID_undef) 253 if (ciphers[i].c_nid == NID_undef)
271 continue; 254 continue;
272 sess.cipher = ciphers[i].id; 255 sess.cipher = ciphers[i].c_id;
273 sess.keylen = ciphers[i].keylen; 256 sess.keylen = ciphers[i].c_keylen;
274 sess.mac = 0; 257 sess.mac = 0;
275 if (ioctl(fd, CIOCGSESSION, &sess) != -1 && 258 if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
276 ioctl(fd, CIOCFSESSION, &sess.ses) != -1) 259 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
277 nids[count++] = ciphers[i].nid; 260 nids[count++] = ciphers[i].c_nid;
278 } 261 }
279 close(fd); 262 close(fd);
280 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
281 if (count > 0) 291 if (count > 0)
282 *cnids = nids; 292 *cnids = nids;
283 else 293 else
@@ -429,15 +439,15 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
429{ 439{
430 struct dev_crypto_state *state = ctx->cipher_data; 440 struct dev_crypto_state *state = ctx->cipher_data;
431 struct session_op *sess = &state->d_sess; 441 struct session_op *sess = &state->d_sess;
432 int cipher; 442 struct dev_crypto_cipher *cipher;
433 443
434 if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef) 444 if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NULL)
435 return (0); 445 return (0);
436 446
437 if (ctx->cipher->iv_len > cryptodev_max_iv(cipher)) 447 if (ctx->cipher->iv_len > cipher->c_ivmax)
438 return (0); 448 return (0);
439 449
440 if (!cryptodev_key_length_valid(cipher, ctx->key_len)) 450 if (ctx->key_len != cipher->c_keylen)
441 return (0); 451 return (0);
442 452
443 memset(sess, 0, sizeof(struct session_op)); 453 memset(sess, 0, sizeof(struct session_op));
@@ -447,7 +457,7 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
447 457
448 sess->key = (unsigned char *)key; 458 sess->key = (unsigned char *)key;
449 sess->keylen = ctx->key_len; 459 sess->keylen = ctx->key_len;
450 sess->cipher = cipher; 460 sess->cipher = cipher->c_id;
451 461
452 if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { 462 if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) {
453 close(state->d_fd); 463 close(state->d_fd);
@@ -552,7 +562,7 @@ const EVP_CIPHER cryptodev_cast_cbc = {
552 NULL 562 NULL
553}; 563};
554 564
555const EVP_CIPHER cryptodev_aes_cbc = { 565EVP_CIPHER cryptodev_aes_128_cbc = {
556 NID_aes_128_cbc, 566 NID_aes_128_cbc,
557 16, 16, 16, 567 16, 16, 16,
558 EVP_CIPH_CBC_MODE, 568 EVP_CIPH_CBC_MODE,
@@ -565,6 +575,209 @@ const EVP_CIPHER cryptodev_aes_cbc = {
565 NULL 575 NULL
566}; 576};
567 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(out)) {
697 bcopy(spare, out, inl);
698 free(spare);
699 }
700
701 if (ivp == ivs)
702 bcopy(ivp, iv, ctx->cipher->iv_len);
703
704 if (ctx->cipher->iv_len) {
705 if (ctx->encrypt)
706 iiv = (void *) out + inl - ctx->cipher->iv_len;
707 else
708 iiv = save_iv;
709 memcpy(ctx->iv, iiv, ctx->cipher->iv_len);
710 }
711 return (1);
712}
713
714static int
715xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
716 const unsigned char *iv, int enc)
717{
718 AES_KEY *k = ctx->cipher_data;
719#ifndef AES_ASM
720 int i;
721#endif
722
723 bzero(k, sizeof *k);
724 if (enc)
725 AES_set_encrypt_key(key, ctx->key_len * 8, k);
726 else
727 AES_set_decrypt_key(key, ctx->key_len * 8, k);
728
729#ifndef AES_ASM
730 /*
731 * XXX Damn OpenSSL byte swaps the expanded key!!
732 *
733 * XXX But only if we're using the C implementation of AES
734 */
735 for (i = 0; i < 4 * (AES_MAXNR + 1); i++)
736 k->rd_key[i] = htonl(k->rd_key[i]);
737#endif
738
739 return (1);
740}
741
742static int
743xcrypt_cleanup(EVP_CIPHER_CTX *ctx)
744{
745 bzero(ctx->cipher_data, ctx->cipher->ctx_size);
746 return (1);
747}
748
749static int
750check_viac3aes(void)
751{
752 int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value;
753 size_t size = sizeof(value);
754
755 if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size,
756 NULL, 0) < 0)
757 return (0);
758 if (value == 0)
759 return (0);
760
761 if (value & C3_HAS_AES) {
762 cryptodev_aes_128_cbc.init = xcrypt_init_key;
763 cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher;
764 cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup;
765 cryptodev_aes_128_cbc.ctx_size = sizeof(AES_KEY);
766
767 cryptodev_aes_192_cbc.init = xcrypt_init_key;
768 cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher;
769 cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup;
770 cryptodev_aes_192_cbc.ctx_size = sizeof(AES_KEY);
771
772 cryptodev_aes_256_cbc.init = xcrypt_init_key;
773 cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher;
774 cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup;
775 cryptodev_aes_256_cbc.ctx_size = sizeof(AES_KEY);
776 }
777 return (value);
778}
779#endif /* __i386__ */
780
568/* 781/*
569 * Registered by the ENGINE when used to find out how to deal with 782 * Registered by the ENGINE when used to find out how to deal with
570 * a particular NID in the ENGINE. this says what we'll do at the 783 * a particular NID in the ENGINE. this says what we'll do at the
@@ -591,7 +804,13 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
591 *cipher = &cryptodev_cast_cbc; 804 *cipher = &cryptodev_cast_cbc;
592 break; 805 break;
593 case NID_aes_128_cbc: 806 case NID_aes_128_cbc:
594 *cipher = &cryptodev_aes_cbc; 807 *cipher = &cryptodev_aes_128_cbc;
808 break;
809 case NID_aes_192_cbc:
810 *cipher = &cryptodev_aes_192_cbc;
811 break;
812 case NID_aes_256_cbc:
813 *cipher = &cryptodev_aes_256_cbc;
595 break; 814 break;
596 default: 815 default:
597 *cipher = NULL; 816 *cipher = NULL;
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c
index 1411fd8333..f128ee5a68 100644
--- a/src/lib/libcrypto/engine/hw_cswift.c
+++ b/src/lib/libcrypto/engine/hw_cswift.c
@@ -90,7 +90,6 @@ static int cswift_destroy(ENGINE *e);
90static int cswift_init(ENGINE *e); 90static int cswift_init(ENGINE *e);
91static int cswift_finish(ENGINE *e); 91static int cswift_finish(ENGINE *e);
92static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 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 93
95/* BIGNUM stuff */ 94/* BIGNUM stuff */
96static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 95static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -404,10 +403,7 @@ static int cswift_init(ENGINE *e)
404 return 1; 403 return 1;
405err: 404err:
406 if(cswift_dso) 405 if(cswift_dso)
407 {
408 DSO_free(cswift_dso); 406 DSO_free(cswift_dso);
409 cswift_dso = NULL;
410 }
411 p_CSwift_AcquireAccContext = NULL; 407 p_CSwift_AcquireAccContext = NULL;
412 p_CSwift_AttachKeyParam = NULL; 408 p_CSwift_AttachKeyParam = NULL;
413 p_CSwift_SimpleRequest = NULL; 409 p_CSwift_SimpleRequest = NULL;
@@ -557,29 +553,6 @@ err:
557 return to_return; 553 return to_return;
558 } 554 }
559 555
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 */ 556/* Un petit mod_exp chinois */
584static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 557static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
585 const BIGNUM *q, const BIGNUM *dmp1, 558 const BIGNUM *q, const BIGNUM *dmp1,
@@ -589,16 +562,15 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
589 SW_LARGENUMBER arg, res; 562 SW_LARGENUMBER arg, res;
590 SW_PARAM sw_param; 563 SW_PARAM sw_param;
591 SW_CONTEXT_HANDLE hac; 564 SW_CONTEXT_HANDLE hac;
592 BIGNUM *result = NULL; 565 BIGNUM *rsa_p = NULL;
566 BIGNUM *rsa_q = NULL;
567 BIGNUM *rsa_dmp1 = NULL;
568 BIGNUM *rsa_dmq1 = NULL;
569 BIGNUM *rsa_iqmp = NULL;
593 BIGNUM *argument = NULL; 570 BIGNUM *argument = NULL;
571 BIGNUM *result = NULL;
594 int to_return = 0; /* expect failure */ 572 int to_return = 0; /* expect failure */
595 int acquired = 0; 573 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 574
603 if(!get_context(&hac)) 575 if(!get_context(&hac))
604 { 576 {
@@ -606,55 +578,44 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
606 goto err; 578 goto err;
607 } 579 }
608 acquired = 1; 580 acquired = 1;
609
610 /* Prepare the params */ 581 /* Prepare the params */
611 argument = BN_new(); 582 BN_CTX_start(ctx);
612 result = BN_new(); 583 rsa_p = BN_CTX_get(ctx);
613 if(!result || !argument) 584 rsa_q = BN_CTX_get(ctx);
585 rsa_dmp1 = BN_CTX_get(ctx);
586 rsa_dmq1 = BN_CTX_get(ctx);
587 rsa_iqmp = BN_CTX_get(ctx);
588 argument = BN_CTX_get(ctx);
589 result = BN_CTX_get(ctx);
590 if(!result)
614 { 591 {
615 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL); 592 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL);
616 goto err; 593 goto err;
617 } 594 }
618 595 if(!bn_wexpand(rsa_p, p->top) || !bn_wexpand(rsa_q, q->top) ||
619 596 !bn_wexpand(rsa_dmp1, dmp1->top) ||
620 sw_param.type = SW_ALG_CRT; 597 !bn_wexpand(rsa_dmq1, dmq1->top) ||
621 /************************************************************************/ 598 !bn_wexpand(rsa_iqmp, iqmp->top) ||
622 /* 04/02/2003 */ 599 !bn_wexpand(argument, a->top) ||
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)) 600 !bn_wexpand(result, p->top + q->top))
653 { 601 {
654 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL); 602 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
655 goto err; 603 goto err;
656 } 604 }
657 605 sw_param.type = SW_ALG_CRT;
606 sw_param.up.crt.p.nbytes = BN_bn2bin(p, (unsigned char *)rsa_p->d);
607 sw_param.up.crt.p.value = (unsigned char *)rsa_p->d;
608 sw_param.up.crt.q.nbytes = BN_bn2bin(q, (unsigned char *)rsa_q->d);
609 sw_param.up.crt.q.value = (unsigned char *)rsa_q->d;
610 sw_param.up.crt.dmp1.nbytes = BN_bn2bin(dmp1,
611 (unsigned char *)rsa_dmp1->d);
612 sw_param.up.crt.dmp1.value = (unsigned char *)rsa_dmp1->d;
613 sw_param.up.crt.dmq1.nbytes = BN_bn2bin(dmq1,
614 (unsigned char *)rsa_dmq1->d);
615 sw_param.up.crt.dmq1.value = (unsigned char *)rsa_dmq1->d;
616 sw_param.up.crt.iqmp.nbytes = BN_bn2bin(iqmp,
617 (unsigned char *)rsa_iqmp->d);
618 sw_param.up.crt.iqmp.value = (unsigned char *)rsa_iqmp->d;
658 /* Attach the key params */ 619 /* Attach the key params */
659 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param); 620 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
660 switch(sw_status) 621 switch(sw_status)
@@ -693,22 +654,9 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
693 BN_bin2bn((unsigned char *)result->d, res.nbytes, r); 654 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
694 to_return = 1; 655 to_return = 1;
695err: 656err:
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) 657 if(acquired)
711 release_context(hac); 658 release_context(hac);
659 BN_CTX_end(ctx);
712 return to_return; 660 return to_return;
713 } 661 }
714 662
@@ -717,27 +665,6 @@ static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
717 { 665 {
718 BN_CTX *ctx; 666 BN_CTX *ctx;
719 int to_return = 0; 667 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 668
742 if((ctx = BN_CTX_new()) == NULL) 669 if((ctx = BN_CTX_new()) == NULL)
743 goto err; 670 goto err;
@@ -759,26 +686,6 @@ err:
759static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 686static 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) 687 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
761 { 688 {
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); 689 return cswift_mod_exp(r, a, p, m, ctx);
783 } 690 }
784 691
@@ -1023,10 +930,9 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
1023 SW_CONTEXT_HANDLE hac; 930 SW_CONTEXT_HANDLE hac;
1024 SW_STATUS swrc; 931 SW_STATUS swrc;
1025 SW_LARGENUMBER largenum; 932 SW_LARGENUMBER largenum;
933 size_t nbytes = 0;
1026 int acquired = 0; 934 int acquired = 0;
1027 int to_return = 0; /* assume failure */ 935 int to_return = 0; /* assume failure */
1028 unsigned char buf32[1024];
1029
1030 936
1031 if (!get_context(&hac)) 937 if (!get_context(&hac))
1032 { 938 {
@@ -1035,19 +941,17 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
1035 } 941 }
1036 acquired = 1; 942 acquired = 1;
1037 943
1038 /************************************************************************/ 944 while (nbytes < (size_t)num)
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 { 945 {
1046 largenum.value = buf;
1047 largenum.nbytes = sizeof(buf32);
1048 /* tell CryptoSwift how many bytes we want and where we want it. 946 /* tell CryptoSwift how many bytes we want and where we want it.
1049 * Note: - CryptoSwift cannot do more than 4096 bytes at a time. 947 * Note: - CryptoSwift cannot do more than 4096 bytes at a time.
1050 * - CryptoSwift can only do multiple of 32-bits. */ 948 * - CryptoSwift can only do multiple of 32-bits. */
949 largenum.value = (SW_BYTE *) buf + nbytes;
950 if (4096 > num - nbytes)
951 largenum.nbytes = num - nbytes;
952 else
953 largenum.nbytes = 4096;
954
1051 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1); 955 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
1052 if (swrc != SW_OK) 956 if (swrc != SW_OK)
1053 { 957 {
@@ -1057,30 +961,14 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
1057 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); 961 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf);
1058 goto err; 962 goto err;
1059 } 963 }
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 964
965 nbytes += largenum.nbytes;
966 }
1079 to_return = 1; /* success */ 967 to_return = 1; /* success */
968
1080err: 969err:
1081 if (acquired) 970 if (acquired)
1082 release_context(hac); 971 release_context(hac);
1083
1084 return to_return; 972 return to_return;
1085} 973}
1086 974
diff --git a/src/lib/libcrypto/engine/hw_ubsec.c b/src/lib/libcrypto/engine/hw_ubsec.c
index 8fb834af31..5234a08a07 100644
--- a/src/lib/libcrypto/engine/hw_ubsec.c
+++ b/src/lib/libcrypto/engine/hw_ubsec.c
@@ -454,7 +454,6 @@ static int ubsec_init(ENGINE *e)
454err: 454err:
455 if(ubsec_dso) 455 if(ubsec_dso)
456 DSO_free(ubsec_dso); 456 DSO_free(ubsec_dso);
457 ubsec_dso = NULL;
458 p_UBSEC_ubsec_bytes_to_bits = NULL; 457 p_UBSEC_ubsec_bytes_to_bits = NULL;
459 p_UBSEC_ubsec_bits_to_bytes = NULL; 458 p_UBSEC_ubsec_bits_to_bytes = NULL;
460 p_UBSEC_ubsec_open = NULL; 459 p_UBSEC_ubsec_open = NULL;
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c
new file mode 100644
index 0000000000..50b3cec1fa
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_cipher.c
@@ -0,0 +1,145 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that
60 * is used by EVP to hook in cipher code and cache defaults (etc), will display
61 * brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_CIPHER_DEBUG */
63
64static ENGINE_TABLE *cipher_table = NULL;
65
66void ENGINE_unregister_ciphers(ENGINE *e)
67 {
68 engine_table_unregister(&cipher_table, e);
69 }
70
71static void engine_unregister_all_ciphers(void)
72 {
73 engine_table_cleanup(&cipher_table);
74 }
75
76int ENGINE_register_ciphers(ENGINE *e)
77 {
78 if(e->ciphers)
79 {
80 const int *nids;
81 int num_nids = e->ciphers(e, NULL, &nids, 0);
82 if(num_nids > 0)
83 return engine_table_register(&cipher_table,
84 engine_unregister_all_ciphers, e, nids,
85 num_nids, 0);
86 }
87 return 1;
88 }
89
90void ENGINE_register_all_ciphers()
91 {
92 ENGINE *e;
93
94 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
95 ENGINE_register_ciphers(e);
96 }
97
98int ENGINE_set_default_ciphers(ENGINE *e)
99 {
100 if(e->ciphers)
101 {
102 const int *nids;
103 int num_nids = e->ciphers(e, NULL, &nids, 0);
104 if(num_nids > 0)
105 return engine_table_register(&cipher_table,
106 engine_unregister_all_ciphers, e, nids,
107 num_nids, 1);
108 }
109 return 1;
110 }
111
112/* Exposed API function to get a functional reference from the implementation
113 * table (ie. try to get a functional reference from the tabled structural
114 * references) for a given cipher 'nid' */
115ENGINE *ENGINE_get_cipher_engine(int nid)
116 {
117 return engine_table_select(&cipher_table, nid);
118 }
119
120/* Obtains a cipher implementation from an ENGINE functional reference */
121const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid)
122 {
123 const EVP_CIPHER *ret;
124 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
125 if(!fn || !fn(e, &ret, NULL, nid))
126 {
127 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER,
128 ENGINE_R_UNIMPLEMENTED_CIPHER);
129 return NULL;
130 }
131 return ret;
132 }
133
134/* Gets the cipher callback from an ENGINE structure */
135ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e)
136 {
137 return e->ciphers;
138 }
139
140/* Sets the cipher callback in an ENGINE structure */
141int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)
142 {
143 e->ciphers = f;
144 return 1;
145 }
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c
new file mode 100644
index 0000000000..e290e1702b
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_dh.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_DH(), the function that is
60 * used by DH to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DH_DEBUG */
63
64static ENGINE_TABLE *dh_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_DH(ENGINE *e)
68 {
69 engine_table_unregister(&dh_table, e);
70 }
71
72static void engine_unregister_all_DH(void)
73 {
74 engine_table_cleanup(&dh_table);
75 }
76
77int ENGINE_register_DH(ENGINE *e)
78 {
79 if(e->dh_meth)
80 return engine_table_register(&dh_table,
81 engine_unregister_all_DH, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_DH()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_DH(e);
91 }
92
93int ENGINE_set_default_DH(ENGINE *e)
94 {
95 if(e->dh_meth)
96 return engine_table_register(&dh_table,
97 engine_unregister_all_DH, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_DH(void)
105 {
106 return engine_table_select(&dh_table, dummy_nid);
107 }
108
109/* Obtains an DH implementation from an ENGINE functional reference */
110const DH_METHOD *ENGINE_get_DH(const ENGINE *e)
111 {
112 return e->dh_meth;
113 }
114
115/* Sets an DH implementation in an ENGINE structure */
116int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
117 {
118 e->dh_meth = dh_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c
new file mode 100644
index 0000000000..e82d2a17c9
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_digest.c
@@ -0,0 +1,145 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_digest_engine(), the function that
60 * is used by EVP to hook in digest code and cache defaults (etc), will display
61 * brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DIGEST_DEBUG */
63
64static ENGINE_TABLE *digest_table = NULL;
65
66void ENGINE_unregister_digests(ENGINE *e)
67 {
68 engine_table_unregister(&digest_table, e);
69 }
70
71static void engine_unregister_all_digests(void)
72 {
73 engine_table_cleanup(&digest_table);
74 }
75
76int ENGINE_register_digests(ENGINE *e)
77 {
78 if(e->digests)
79 {
80 const int *nids;
81 int num_nids = e->digests(e, NULL, &nids, 0);
82 if(num_nids > 0)
83 return engine_table_register(&digest_table,
84 engine_unregister_all_digests, e, nids,
85 num_nids, 0);
86 }
87 return 1;
88 }
89
90void ENGINE_register_all_digests()
91 {
92 ENGINE *e;
93
94 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
95 ENGINE_register_digests(e);
96 }
97
98int ENGINE_set_default_digests(ENGINE *e)
99 {
100 if(e->digests)
101 {
102 const int *nids;
103 int num_nids = e->digests(e, NULL, &nids, 0);
104 if(num_nids > 0)
105 return engine_table_register(&digest_table,
106 engine_unregister_all_digests, e, nids,
107 num_nids, 1);
108 }
109 return 1;
110 }
111
112/* Exposed API function to get a functional reference from the implementation
113 * table (ie. try to get a functional reference from the tabled structural
114 * references) for a given digest 'nid' */
115ENGINE *ENGINE_get_digest_engine(int nid)
116 {
117 return engine_table_select(&digest_table, nid);
118 }
119
120/* Obtains a digest implementation from an ENGINE functional reference */
121const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid)
122 {
123 const EVP_MD *ret;
124 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
125 if(!fn || !fn(e, &ret, NULL, nid))
126 {
127 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST,
128 ENGINE_R_UNIMPLEMENTED_DIGEST);
129 return NULL;
130 }
131 return ret;
132 }
133
134/* Gets the digest callback from an ENGINE structure */
135ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e)
136 {
137 return e->digests;
138 }
139
140/* Sets the digest callback in an ENGINE structure */
141int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f)
142 {
143 e->digests = f;
144 return 1;
145 }
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c
new file mode 100644
index 0000000000..80170591f2
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_dsa.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is
60 * used by DSA to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DSA_DEBUG */
63
64static ENGINE_TABLE *dsa_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_DSA(ENGINE *e)
68 {
69 engine_table_unregister(&dsa_table, e);
70 }
71
72static void engine_unregister_all_DSA(void)
73 {
74 engine_table_cleanup(&dsa_table);
75 }
76
77int ENGINE_register_DSA(ENGINE *e)
78 {
79 if(e->dsa_meth)
80 return engine_table_register(&dsa_table,
81 engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_DSA()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_DSA(e);
91 }
92
93int ENGINE_set_default_DSA(ENGINE *e)
94 {
95 if(e->dsa_meth)
96 return engine_table_register(&dsa_table,
97 engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_DSA(void)
105 {
106 return engine_table_select(&dsa_table, dummy_nid);
107 }
108
109/* Obtains an DSA implementation from an ENGINE functional reference */
110const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
111 {
112 return e->dsa_meth;
113 }
114
115/* Sets an DSA implementation in an ENGINE structure */
116int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
117 {
118 e->dsa_meth = dsa_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c
new file mode 100644
index 0000000000..69b67111bc
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_rand.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is
60 * used by RAND to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_RAND_DEBUG */
63
64static ENGINE_TABLE *rand_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_RAND(ENGINE *e)
68 {
69 engine_table_unregister(&rand_table, e);
70 }
71
72static void engine_unregister_all_RAND(void)
73 {
74 engine_table_cleanup(&rand_table);
75 }
76
77int ENGINE_register_RAND(ENGINE *e)
78 {
79 if(e->rand_meth)
80 return engine_table_register(&rand_table,
81 engine_unregister_all_RAND, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_RAND()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_RAND(e);
91 }
92
93int ENGINE_set_default_RAND(ENGINE *e)
94 {
95 if(e->rand_meth)
96 return engine_table_register(&rand_table,
97 engine_unregister_all_RAND, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_RAND(void)
105 {
106 return engine_table_select(&rand_table, dummy_nid);
107 }
108
109/* Obtains an RAND implementation from an ENGINE functional reference */
110const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e)
111 {
112 return e->rand_meth;
113 }
114
115/* Sets an RAND implementation in an ENGINE structure */
116int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
117 {
118 e->rand_meth = rand_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c
new file mode 100644
index 0000000000..fee4867f52
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_rsa.c
@@ -0,0 +1,120 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is
60 * used by RSA to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_RSA_DEBUG */
63
64static ENGINE_TABLE *rsa_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_RSA(ENGINE *e)
68 {
69 engine_table_unregister(&rsa_table, e);
70 }
71
72static void engine_unregister_all_RSA(void)
73 {
74 engine_table_cleanup(&rsa_table);
75 }
76
77int ENGINE_register_RSA(ENGINE *e)
78 {
79 if(e->rsa_meth)
80 return engine_table_register(&rsa_table,
81 engine_unregister_all_RSA, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_RSA()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_RSA(e);
91 }
92
93int ENGINE_set_default_RSA(ENGINE *e)
94 {
95 if(e->rsa_meth)
96 return engine_table_register(&rsa_table,
97 engine_unregister_all_RSA, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_RSA(void)
105 {
106 return engine_table_select(&rsa_table, dummy_nid);
107 }
108
109/* Obtains an RSA implementation from an ENGINE functional reference */
110const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
111 {
112 return e->rsa_meth;
113 }
114
115/* Sets an RSA implementation in an ENGINE structure */
116int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
117 {
118 e->rsa_meth = rsa_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/err/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
new file mode 100644
index 0000000000..c78790a54c
--- /dev/null
+++ b/src/lib/libcrypto/err/err.c
@@ -0,0 +1,1077 @@
1/* crypto/err/err.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <stdarg.h>
114#include <string.h>
115#include <openssl/lhash.h>
116#include <openssl/crypto.h>
117#include "cryptlib.h"
118#include <openssl/buffer.h>
119#include <openssl/bio.h>
120#include <openssl/err.h>
121
122static void err_load_strings(int lib, ERR_STRING_DATA *str);
123
124static void ERR_STATE_free(ERR_STATE *s);
125#ifndef OPENSSL_NO_ERR
126static ERR_STRING_DATA ERR_str_libraries[]=
127 {
128{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
129{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
130{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
131{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
132{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
133{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
134{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
135{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
136{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
137{ERR_PACK(ERR_LIB_DSA,0,0) ,"dsa routines"},
138{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
139{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
140{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"},
141{ERR_PACK(ERR_LIB_CRYPTO,0,0) ,"common libcrypto routines"},
142{ERR_PACK(ERR_LIB_EC,0,0) ,"elliptic curve routines"},
143{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
144{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
145{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
146{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
147{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
148{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
149{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"},
150{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
151{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"},
152{ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"},
153{0,NULL},
154 };
155
156static ERR_STRING_DATA ERR_str_functs[]=
157 {
158 {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
159 {ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
160 {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
161 {ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
162 {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
163 {ERR_PACK(0,SYS_F_BIND,0), "bind"},
164 {ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
165 {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
166#ifdef OPENSSL_SYS_WINDOWS
167 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
168#endif
169 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
170 {ERR_PACK(0,SYS_F_FREAD,0), "fread"},
171 {ERR_PACK(0,SYS_F_GETADDRINFO,0), "getaddrinfo"},
172 {0,NULL},
173 };
174
175static ERR_STRING_DATA ERR_str_reasons[]=
176 {
177{ERR_R_SYS_LIB ,"system lib"},
178{ERR_R_BN_LIB ,"BN lib"},
179{ERR_R_RSA_LIB ,"RSA lib"},
180{ERR_R_DH_LIB ,"DH lib"},
181{ERR_R_EVP_LIB ,"EVP lib"},
182{ERR_R_BUF_LIB ,"BUF lib"},
183{ERR_R_OBJ_LIB ,"OBJ lib"},
184{ERR_R_PEM_LIB ,"PEM lib"},
185{ERR_R_DSA_LIB ,"DSA lib"},
186{ERR_R_X509_LIB ,"X509 lib"},
187{ERR_R_ASN1_LIB ,"ASN1 lib"},
188{ERR_R_CONF_LIB ,"CONF lib"},
189{ERR_R_CRYPTO_LIB ,"CRYPTO lib"},
190{ERR_R_EC_LIB ,"EC lib"},
191{ERR_R_SSL_LIB ,"SSL lib"},
192{ERR_R_BIO_LIB ,"BIO lib"},
193{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
194{ERR_R_X509V3_LIB ,"X509V3 lib"},
195{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
196{ERR_R_RAND_LIB ,"RAND lib"},
197{ERR_R_DSO_LIB ,"DSO lib"},
198{ERR_R_ENGINE_LIB ,"ENGINE lib"},
199{ERR_R_OCSP_LIB ,"OCSP lib"},
200
201{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
202{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
203{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
204{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
205{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
206{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
207
208{ERR_R_FATAL ,"fatal"},
209{ERR_R_MALLOC_FAILURE ,"malloc failure"},
210{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
211{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
212{ERR_R_INTERNAL_ERROR ,"internal error"},
213
214{0,NULL},
215 };
216#endif
217
218
219/* Define the predeclared (but externally opaque) "ERR_FNS" type */
220struct st_ERR_FNS
221 {
222 /* Works on the "error_hash" string table */
223 LHASH *(*cb_err_get)(int create);
224 void (*cb_err_del)(void);
225 ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *);
226 ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *);
227 ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *);
228 /* Works on the "thread_hash" error-state table */
229 LHASH *(*cb_thread_get)(int create);
230 void (*cb_thread_release)(LHASH **hash);
231 ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *);
232 ERR_STATE *(*cb_thread_set_item)(ERR_STATE *);
233 void (*cb_thread_del_item)(const ERR_STATE *);
234 /* Returns the next available error "library" numbers */
235 int (*cb_get_next_lib)(void);
236 };
237
238/* Predeclarations of the "err_defaults" functions */
239static LHASH *int_err_get(int create);
240static void int_err_del(void);
241static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
242static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *);
243static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *);
244static LHASH *int_thread_get(int create);
245static void int_thread_release(LHASH **hash);
246static ERR_STATE *int_thread_get_item(const ERR_STATE *);
247static ERR_STATE *int_thread_set_item(ERR_STATE *);
248static void int_thread_del_item(const ERR_STATE *);
249static int int_err_get_next_lib(void);
250/* The static ERR_FNS table using these defaults functions */
251static const ERR_FNS err_defaults =
252 {
253 int_err_get,
254 int_err_del,
255 int_err_get_item,
256 int_err_set_item,
257 int_err_del_item,
258 int_thread_get,
259 int_thread_release,
260 int_thread_get_item,
261 int_thread_set_item,
262 int_thread_del_item,
263 int_err_get_next_lib
264 };
265
266/* The replacable table of ERR_FNS functions we use at run-time */
267static const ERR_FNS *err_fns = NULL;
268
269/* Eg. rather than using "err_get()", use "ERRFN(err_get)()". */
270#define ERRFN(a) err_fns->cb_##a
271
272/* The internal state used by "err_defaults" - as such, the setting, reading,
273 * creating, and deleting of this data should only be permitted via the
274 * "err_defaults" functions. This way, a linked module can completely defer all
275 * ERR state operation (together with requisite locking) to the implementations
276 * and state in the loading application. */
277static LHASH *int_error_hash = NULL;
278static LHASH *int_thread_hash = NULL;
279static int int_thread_hash_references = 0;
280static int int_err_library_number= ERR_LIB_USER;
281
282/* Internal function that checks whether "err_fns" is set and if not, sets it to
283 * the defaults. */
284static void err_fns_check(void)
285 {
286 if (err_fns) return;
287
288 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
289 if (!err_fns)
290 err_fns = &err_defaults;
291 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
292 }
293
294/* API functions to get or set the underlying ERR functions. */
295
296const ERR_FNS *ERR_get_implementation(void)
297 {
298 err_fns_check();
299 return err_fns;
300 }
301
302int ERR_set_implementation(const ERR_FNS *fns)
303 {
304 int ret = 0;
305
306 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
307 /* It's too late if 'err_fns' is non-NULL. BTW: not much point setting
308 * an error is there?! */
309 if (!err_fns)
310 {
311 err_fns = fns;
312 ret = 1;
313 }
314 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
315 return ret;
316 }
317
318/* These are the callbacks provided to "lh_new()" when creating the LHASH tables
319 * internal to the "err_defaults" implementation. */
320
321/* static unsigned long err_hash(ERR_STRING_DATA *a); */
322static unsigned long err_hash(const void *a_void);
323/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); */
324static int err_cmp(const void *a_void, const void *b_void);
325/* static unsigned long pid_hash(ERR_STATE *pid); */
326static unsigned long pid_hash(const void *pid_void);
327/* static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); */
328static int pid_cmp(const void *a_void,const void *pid_void);
329static unsigned long get_error_values(int inc,int top,const char **file,int *line,
330 const char **data,int *flags);
331
332/* The internal functions used in the "err_defaults" implementation */
333
334static LHASH *int_err_get(int create)
335 {
336 LHASH *ret = NULL;
337
338 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
339 if (!int_error_hash && create)
340 {
341 CRYPTO_push_info("int_err_get (err.c)");
342 int_error_hash = lh_new(err_hash, err_cmp);
343 CRYPTO_pop_info();
344 }
345 if (int_error_hash)
346 ret = int_error_hash;
347 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
348
349 return ret;
350 }
351
352static void int_err_del(void)
353 {
354 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
355 if (int_error_hash)
356 {
357 lh_free(int_error_hash);
358 int_error_hash = NULL;
359 }
360 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
361 }
362
363static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
364 {
365 ERR_STRING_DATA *p;
366 LHASH *hash;
367
368 err_fns_check();
369 hash = ERRFN(err_get)(0);
370 if (!hash)
371 return NULL;
372
373 CRYPTO_r_lock(CRYPTO_LOCK_ERR);
374 p = (ERR_STRING_DATA *)lh_retrieve(hash, d);
375 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
376
377 return p;
378 }
379
380static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
381 {
382 ERR_STRING_DATA *p;
383 LHASH *hash;
384
385 err_fns_check();
386 hash = ERRFN(err_get)(1);
387 if (!hash)
388 return NULL;
389
390 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
391 p = (ERR_STRING_DATA *)lh_insert(hash, d);
392 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
393
394 return p;
395 }
396
397static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
398 {
399 ERR_STRING_DATA *p;
400 LHASH *hash;
401
402 err_fns_check();
403 hash = ERRFN(err_get)(0);
404 if (!hash)
405 return NULL;
406
407 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
408 p = (ERR_STRING_DATA *)lh_delete(hash, d);
409 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
410
411 return p;
412 }
413
414static LHASH *int_thread_get(int create)
415 {
416 LHASH *ret = NULL;
417
418 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
419 if (!int_thread_hash && create)
420 {
421 CRYPTO_push_info("int_thread_get (err.c)");
422 int_thread_hash = lh_new(pid_hash, pid_cmp);
423 CRYPTO_pop_info();
424 }
425 if (int_thread_hash)
426 {
427 int_thread_hash_references++;
428 ret = int_thread_hash;
429 }
430 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
431 return ret;
432 }
433
434static void int_thread_release(LHASH **hash)
435 {
436 int i;
437
438 if (hash == NULL || *hash == NULL)
439 return;
440
441 i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);
442
443#ifdef REF_PRINT
444 fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR");
445#endif
446 if (i > 0) return;
447#ifdef REF_CHECK
448 if (i < 0)
449 {
450 fprintf(stderr,"int_thread_release, bad reference count\n");
451 abort(); /* ok */
452 }
453#endif
454 *hash = NULL;
455 }
456
457static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
458 {
459 ERR_STATE *p;
460 LHASH *hash;
461
462 err_fns_check();
463 hash = ERRFN(thread_get)(0);
464 if (!hash)
465 return NULL;
466
467 CRYPTO_r_lock(CRYPTO_LOCK_ERR);
468 p = (ERR_STATE *)lh_retrieve(hash, d);
469 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
470
471 ERRFN(thread_release)(&hash);
472 return p;
473 }
474
475static ERR_STATE *int_thread_set_item(ERR_STATE *d)
476 {
477 ERR_STATE *p;
478 LHASH *hash;
479
480 err_fns_check();
481 hash = ERRFN(thread_get)(1);
482 if (!hash)
483 return NULL;
484
485 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
486 p = (ERR_STATE *)lh_insert(hash, d);
487 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
488
489 ERRFN(thread_release)(&hash);
490 return p;
491 }
492
493static void int_thread_del_item(const ERR_STATE *d)
494 {
495 ERR_STATE *p;
496 LHASH *hash;
497
498 err_fns_check();
499 hash = ERRFN(thread_get)(0);
500 if (!hash)
501 return;
502
503 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
504 p = (ERR_STATE *)lh_delete(hash, d);
505 /* make sure we don't leak memory */
506 if (int_thread_hash_references == 1
507 && int_thread_hash && (lh_num_items(int_thread_hash) == 0))
508 {
509 lh_free(int_thread_hash);
510 int_thread_hash = NULL;
511 }
512 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
513
514 ERRFN(thread_release)(&hash);
515 if (p)
516 ERR_STATE_free(p);
517 }
518
519static int int_err_get_next_lib(void)
520 {
521 int ret;
522
523 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
524 ret = int_err_library_number++;
525 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
526
527 return ret;
528 }
529
530
531#ifndef OPENSSL_NO_ERR
532#define NUM_SYS_STR_REASONS 127
533#define LEN_SYS_STR_REASON 32
534
535static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
536/* SYS_str_reasons is filled with copies of strerror() results at
537 * initialization.
538 * 'errno' values up to 127 should cover all usual errors,
539 * others will be displayed numerically by ERR_error_string.
540 * It is crucial that we have something for each reason code
541 * that occurs in ERR_str_reasons, or bogus reason strings
542 * will be returned for SYSerr(), which always gets an errno
543 * value and never one of those 'standard' reason codes. */
544
545static void build_SYS_str_reasons()
546 {
547 /* OPENSSL_malloc cannot be used here, use static storage instead */
548 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
549 int i;
550 static int init = 1;
551
552 if (!init) return;
553
554 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
555
556 for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
557 {
558 ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
559
560 str->error = (unsigned long)i;
561 if (str->string == NULL)
562 {
563 char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
564 char *src = strerror(i);
565 if (src != NULL)
566 {
567 strncpy(*dest, src, sizeof *dest);
568 (*dest)[sizeof *dest - 1] = '\0';
569 str->string = *dest;
570 }
571 }
572 if (str->string == NULL)
573 str->string = "unknown";
574 }
575
576 /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
577 * as required by ERR_load_strings. */
578
579 init = 0;
580
581 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
582 }
583#endif
584
585#define err_clear_data(p,i) \
586 if (((p)->err_data[i] != NULL) && \
587 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
588 { \
589 OPENSSL_free((p)->err_data[i]); \
590 (p)->err_data[i]=NULL; \
591 } \
592 (p)->err_data_flags[i]=0;
593
594static void ERR_STATE_free(ERR_STATE *s)
595 {
596 int i;
597
598 if (s == NULL)
599 return;
600
601 for (i=0; i<ERR_NUM_ERRORS; i++)
602 {
603 err_clear_data(s,i);
604 }
605 OPENSSL_free(s);
606 }
607
608void ERR_load_ERR_strings(void)
609 {
610 err_fns_check();
611#ifndef OPENSSL_NO_ERR
612 err_load_strings(0,ERR_str_libraries);
613 err_load_strings(0,ERR_str_reasons);
614 err_load_strings(ERR_LIB_SYS,ERR_str_functs);
615 build_SYS_str_reasons();
616 err_load_strings(ERR_LIB_SYS,SYS_str_reasons);
617#endif
618 }
619
620static void err_load_strings(int lib, ERR_STRING_DATA *str)
621 {
622 while (str->error)
623 {
624 str->error|=ERR_PACK(lib,0,0);
625 ERRFN(err_set_item)(str);
626 str++;
627 }
628 }
629
630void ERR_load_strings(int lib, ERR_STRING_DATA *str)
631 {
632 ERR_load_ERR_strings();
633 err_load_strings(lib, str);
634 }
635
636void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
637 {
638 while (str->error)
639 {
640 str->error|=ERR_PACK(lib,0,0);
641 ERRFN(err_del_item)(str);
642 str++;
643 }
644 }
645
646void ERR_free_strings(void)
647 {
648 err_fns_check();
649 ERRFN(err_del)();
650 }
651
652/********************************************************/
653
654void ERR_put_error(int lib, int func, int reason, const char *file,
655 int line)
656 {
657 ERR_STATE *es;
658
659#ifdef _OSD_POSIX
660 /* In the BS2000-OSD POSIX subsystem, the compiler generates
661 * path names in the form "*POSIX(/etc/passwd)".
662 * This dirty hack strips them to something sensible.
663 * @@@ We shouldn't modify a const string, though.
664 */
665 if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
666 char *end;
667
668 /* Skip the "*POSIX(" prefix */
669 file += sizeof("*POSIX(")-1;
670 end = &file[strlen(file)-1];
671 if (*end == ')')
672 *end = '\0';
673 /* Optional: use the basename of the path only. */
674 if ((end = strrchr(file, '/')) != NULL)
675 file = &end[1];
676 }
677#endif
678 es=ERR_get_state();
679
680 es->top=(es->top+1)%ERR_NUM_ERRORS;
681 if (es->top == es->bottom)
682 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
683 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
684 es->err_file[es->top]=file;
685 es->err_line[es->top]=line;
686 err_clear_data(es,es->top);
687 }
688
689void ERR_clear_error(void)
690 {
691 int i;
692 ERR_STATE *es;
693
694 es=ERR_get_state();
695
696 for (i=0; i<ERR_NUM_ERRORS; i++)
697 {
698 es->err_buffer[i]=0;
699 err_clear_data(es,i);
700 es->err_file[i]=NULL;
701 es->err_line[i]= -1;
702 }
703 es->top=es->bottom=0;
704 }
705
706
707unsigned long ERR_get_error(void)
708 { return(get_error_values(1,0,NULL,NULL,NULL,NULL)); }
709
710unsigned long ERR_get_error_line(const char **file,
711 int *line)
712 { return(get_error_values(1,0,file,line,NULL,NULL)); }
713
714unsigned long ERR_get_error_line_data(const char **file, int *line,
715 const char **data, int *flags)
716 { return(get_error_values(1,0,file,line,data,flags)); }
717
718
719unsigned long ERR_peek_error(void)
720 { return(get_error_values(0,0,NULL,NULL,NULL,NULL)); }
721
722unsigned long ERR_peek_error_line(const char **file, int *line)
723 { return(get_error_values(0,0,file,line,NULL,NULL)); }
724
725unsigned long ERR_peek_error_line_data(const char **file, int *line,
726 const char **data, int *flags)
727 { return(get_error_values(0,0,file,line,data,flags)); }
728
729
730unsigned long ERR_peek_last_error(void)
731 { return(get_error_values(0,1,NULL,NULL,NULL,NULL)); }
732
733unsigned long ERR_peek_last_error_line(const char **file, int *line)
734 { return(get_error_values(0,1,file,line,NULL,NULL)); }
735
736unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
737 const char **data, int *flags)
738 { return(get_error_values(0,1,file,line,data,flags)); }
739
740
741static unsigned long get_error_values(int inc, int top, const char **file, int *line,
742 const char **data, int *flags)
743 {
744 int i=0;
745 ERR_STATE *es;
746 unsigned long ret;
747
748 es=ERR_get_state();
749
750 if (inc && top)
751 {
752 if (file) *file = "";
753 if (line) *line = 0;
754 if (data) *data = "";
755 if (flags) *flags = 0;
756
757 return ERR_R_INTERNAL_ERROR;
758 }
759
760 if (es->bottom == es->top) return 0;
761 if (top)
762 i=es->top; /* last error */
763 else
764 i=(es->bottom+1)%ERR_NUM_ERRORS; /* first error */
765
766 ret=es->err_buffer[i];
767 if (inc)
768 {
769 es->bottom=i;
770 es->err_buffer[i]=0;
771 }
772
773 if ((file != NULL) && (line != NULL))
774 {
775 if (es->err_file[i] == NULL)
776 {
777 *file="NA";
778 if (line != NULL) *line=0;
779 }
780 else
781 {
782 *file=es->err_file[i];
783 if (line != NULL) *line=es->err_line[i];
784 }
785 }
786
787 if (data == NULL)
788 {
789 if (inc)
790 {
791 err_clear_data(es, i);
792 }
793 }
794 else
795 {
796 if (es->err_data[i] == NULL)
797 {
798 *data="";
799 if (flags != NULL) *flags=0;
800 }
801 else
802 {
803 *data=es->err_data[i];
804 if (flags != NULL) *flags=es->err_data_flags[i];
805 }
806 }
807 return ret;
808 }
809
810void ERR_error_string_n(unsigned long e, char *buf, size_t len)
811 {
812 char lsbuf[64], fsbuf[64], rsbuf[64];
813 const char *ls,*fs,*rs;
814 unsigned long l,f,r;
815
816 l=ERR_GET_LIB(e);
817 f=ERR_GET_FUNC(e);
818 r=ERR_GET_REASON(e);
819
820 ls=ERR_lib_error_string(e);
821 fs=ERR_func_error_string(e);
822 rs=ERR_reason_error_string(e);
823
824 if (ls == NULL)
825 BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
826 if (fs == NULL)
827 BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
828 if (rs == NULL)
829 BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
830
831 BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf,
832 fs?fs:fsbuf, rs?rs:rsbuf);
833 if (strlen(buf) == len-1)
834 {
835 /* output may be truncated; make sure we always have 5
836 * colon-separated fields, i.e. 4 colons ... */
837#define NUM_COLONS 4
838 if (len > NUM_COLONS) /* ... if possible */
839 {
840 int i;
841 char *s = buf;
842
843 for (i = 0; i < NUM_COLONS; i++)
844 {
845 char *colon = strchr(s, ':');
846 if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
847 {
848 /* set colon no. i at last possible position
849 * (buf[len-1] is the terminating 0)*/
850 colon = &buf[len-1] - NUM_COLONS + i;
851 *colon = ':';
852 }
853 s = colon + 1;
854 }
855 }
856 }
857 }
858
859/* BAD for multi-threading: uses a local buffer if ret == NULL */
860/* ERR_error_string_n should be used instead for ret != NULL
861 * as ERR_error_string cannot know how large the buffer is */
862char *ERR_error_string(unsigned long e, char *ret)
863 {
864 static char buf[256];
865
866 if (ret == NULL) ret=buf;
867 ERR_error_string_n(e, ret, 256);
868
869 return ret;
870 }
871
872LHASH *ERR_get_string_table(void)
873 {
874 err_fns_check();
875 return ERRFN(err_get)(0);
876 }
877
878LHASH *ERR_get_err_state_table(void)
879 {
880 err_fns_check();
881 return ERRFN(thread_get)(0);
882 }
883
884void ERR_release_err_state_table(LHASH **hash)
885 {
886 err_fns_check();
887 ERRFN(thread_release)(hash);
888 }
889
890const char *ERR_lib_error_string(unsigned long e)
891 {
892 ERR_STRING_DATA d,*p;
893 unsigned long l;
894
895 err_fns_check();
896 l=ERR_GET_LIB(e);
897 d.error=ERR_PACK(l,0,0);
898 p=ERRFN(err_get_item)(&d);
899 return((p == NULL)?NULL:p->string);
900 }
901
902const char *ERR_func_error_string(unsigned long e)
903 {
904 ERR_STRING_DATA d,*p;
905 unsigned long l,f;
906
907 err_fns_check();
908 l=ERR_GET_LIB(e);
909 f=ERR_GET_FUNC(e);
910 d.error=ERR_PACK(l,f,0);
911 p=ERRFN(err_get_item)(&d);
912 return((p == NULL)?NULL:p->string);
913 }
914
915const char *ERR_reason_error_string(unsigned long e)
916 {
917 ERR_STRING_DATA d,*p=NULL;
918 unsigned long l,r;
919
920 err_fns_check();
921 l=ERR_GET_LIB(e);
922 r=ERR_GET_REASON(e);
923 d.error=ERR_PACK(l,0,r);
924 p=ERRFN(err_get_item)(&d);
925 if (!p)
926 {
927 d.error=ERR_PACK(0,0,r);
928 p=ERRFN(err_get_item)(&d);
929 }
930 return((p == NULL)?NULL:p->string);
931 }
932
933/* static unsigned long err_hash(ERR_STRING_DATA *a) */
934static unsigned long err_hash(const void *a_void)
935 {
936 unsigned long ret,l;
937
938 l=((ERR_STRING_DATA *)a_void)->error;
939 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
940 return(ret^ret%19*13);
941 }
942
943/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */
944static int err_cmp(const void *a_void, const void *b_void)
945 {
946 return((int)(((ERR_STRING_DATA *)a_void)->error -
947 ((ERR_STRING_DATA *)b_void)->error));
948 }
949
950/* static unsigned long pid_hash(ERR_STATE *a) */
951static unsigned long pid_hash(const void *a_void)
952 {
953 return(((ERR_STATE *)a_void)->pid*13);
954 }
955
956/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
957static int pid_cmp(const void *a_void, const void *b_void)
958 {
959 return((int)((long)((ERR_STATE *)a_void)->pid -
960 (long)((ERR_STATE *)b_void)->pid));
961 }
962
963void ERR_remove_state(unsigned long pid)
964 {
965 ERR_STATE tmp;
966
967 err_fns_check();
968 if (pid == 0)
969 pid=(unsigned long)CRYPTO_thread_id();
970 tmp.pid=pid;
971 /* thread_del_item automatically destroys the LHASH if the number of
972 * items reaches zero. */
973 ERRFN(thread_del_item)(&tmp);
974 }
975
976ERR_STATE *ERR_get_state(void)
977 {
978 static ERR_STATE fallback;
979 ERR_STATE *ret,tmp,*tmpp=NULL;
980 int i;
981 unsigned long pid;
982
983 err_fns_check();
984 pid=(unsigned long)CRYPTO_thread_id();
985 tmp.pid=pid;
986 ret=ERRFN(thread_get_item)(&tmp);
987
988 /* ret == the error state, if NULL, make a new one */
989 if (ret == NULL)
990 {
991 ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
992 if (ret == NULL) return(&fallback);
993 ret->pid=pid;
994 ret->top=0;
995 ret->bottom=0;
996 for (i=0; i<ERR_NUM_ERRORS; i++)
997 {
998 ret->err_data[i]=NULL;
999 ret->err_data_flags[i]=0;
1000 }
1001 tmpp = ERRFN(thread_set_item)(ret);
1002 /* To check if insertion failed, do a get. */
1003 if (ERRFN(thread_get_item)(ret) != ret)
1004 {
1005 ERR_STATE_free(ret); /* could not insert it */
1006 return(&fallback);
1007 }
1008 /* If a race occured in this function and we came second, tmpp
1009 * is the first one that we just replaced. */
1010 if (tmpp)
1011 ERR_STATE_free(tmpp);
1012 }
1013 return ret;
1014 }
1015
1016int ERR_get_next_error_library(void)
1017 {
1018 err_fns_check();
1019 return ERRFN(get_next_lib)();
1020 }
1021
1022void ERR_set_error_data(char *data, int flags)
1023 {
1024 ERR_STATE *es;
1025 int i;
1026
1027 es=ERR_get_state();
1028
1029 i=es->top;
1030 if (i == 0)
1031 i=ERR_NUM_ERRORS-1;
1032
1033 err_clear_data(es,i);
1034 es->err_data[i]=data;
1035 es->err_data_flags[i]=flags;
1036 }
1037
1038void ERR_add_error_data(int num, ...)
1039 {
1040 va_list args;
1041 int i,n,s;
1042 char *str,*p,*a;
1043
1044 s=80;
1045 str=OPENSSL_malloc(s+1);
1046 if (str == NULL) return;
1047 str[0]='\0';
1048
1049 va_start(args, num);
1050 n=0;
1051 for (i=0; i<num; i++)
1052 {
1053 a=va_arg(args, char*);
1054 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
1055 if (a != NULL)
1056 {
1057 n+=strlen(a);
1058 if (n > s)
1059 {
1060 s=n+20;
1061 p=OPENSSL_realloc(str,s+1);
1062 if (p == NULL)
1063 {
1064 OPENSSL_free(str);
1065 goto err;
1066 }
1067 else
1068 str=p;
1069 }
1070 BUF_strlcat(str,a,s+1);
1071 }
1072 }
1073 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
1074
1075err:
1076 va_end(args);
1077 }
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
new file mode 100644
index 0000000000..2efa18866a
--- /dev/null
+++ b/src/lib/libcrypto/err/err.h
@@ -0,0 +1,302 @@
1/* crypto/err/err.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ERR_H
60#define HEADER_ERR_H
61
62#ifndef OPENSSL_NO_FP_API
63#include <stdio.h>
64#include <stdlib.h>
65#endif
66
67#ifndef OPENSSL_NO_BIO
68#include <openssl/bio.h>
69#endif
70#ifndef OPENSSL_NO_LHASH
71#include <openssl/lhash.h>
72#endif
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78#ifndef OPENSSL_NO_ERR
79#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
80#else
81#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
82#endif
83
84#include <errno.h>
85
86#define ERR_TXT_MALLOCED 0x01
87#define ERR_TXT_STRING 0x02
88
89#define ERR_NUM_ERRORS 16
90typedef struct err_state_st
91 {
92 unsigned long pid;
93 unsigned long err_buffer[ERR_NUM_ERRORS];
94 char *err_data[ERR_NUM_ERRORS];
95 int err_data_flags[ERR_NUM_ERRORS];
96 const char *err_file[ERR_NUM_ERRORS];
97 int err_line[ERR_NUM_ERRORS];
98 int top,bottom;
99 } ERR_STATE;
100
101/* library */
102#define ERR_LIB_NONE 1
103#define ERR_LIB_SYS 2
104#define ERR_LIB_BN 3
105#define ERR_LIB_RSA 4
106#define ERR_LIB_DH 5
107#define ERR_LIB_EVP 6
108#define ERR_LIB_BUF 7
109#define ERR_LIB_OBJ 8
110#define ERR_LIB_PEM 9
111#define ERR_LIB_DSA 10
112#define ERR_LIB_X509 11
113/* #define ERR_LIB_METH 12 */
114#define ERR_LIB_ASN1 13
115#define ERR_LIB_CONF 14
116#define ERR_LIB_CRYPTO 15
117#define ERR_LIB_EC 16
118#define ERR_LIB_SSL 20
119/* #define ERR_LIB_SSL23 21 */
120/* #define ERR_LIB_SSL2 22 */
121/* #define ERR_LIB_SSL3 23 */
122/* #define ERR_LIB_RSAREF 30 */
123/* #define ERR_LIB_PROXY 31 */
124#define ERR_LIB_BIO 32
125#define ERR_LIB_PKCS7 33
126#define ERR_LIB_X509V3 34
127#define ERR_LIB_PKCS12 35
128#define ERR_LIB_RAND 36
129#define ERR_LIB_DSO 37
130#define ERR_LIB_ENGINE 38
131#define ERR_LIB_OCSP 39
132#define ERR_LIB_UI 40
133#define ERR_LIB_COMP 41
134#define ERR_LIB_FIPS 42
135
136#define ERR_LIB_USER 128
137
138#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),__FILE__,__LINE__)
139#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),__FILE__,__LINE__)
140#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),__FILE__,__LINE__)
141#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),__FILE__,__LINE__)
142#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),__FILE__,__LINE__)
143#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),__FILE__,__LINE__)
144#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),__FILE__,__LINE__)
145#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),__FILE__,__LINE__)
146#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),__FILE__,__LINE__)
147#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),__FILE__,__LINE__)
148#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),__FILE__,__LINE__)
149#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),__FILE__,__LINE__)
150#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),__FILE__,__LINE__)
151#define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),__FILE__,__LINE__)
152#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),__FILE__,__LINE__)
153#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),__FILE__,__LINE__)
154#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),__FILE__,__LINE__)
155#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),__FILE__,__LINE__)
156#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),__FILE__,__LINE__)
157#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),__FILE__,__LINE__)
158#define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),__FILE__,__LINE__)
159#define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),__FILE__,__LINE__)
160#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__)
161#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__)
162#define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),__FILE__,__LINE__)
163#define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),__FILE__,__LINE__)
164
165/* Borland C seems too stupid to be able to shift and do longs in
166 * the pre-processor :-( */
167#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \
168 ((((unsigned long)f)&0xfffL)*0x1000)| \
169 ((((unsigned long)r)&0xfffL)))
170#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL)
171#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL)
172#define ERR_GET_REASON(l) (int)((l)&0xfffL)
173#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL)
174
175
176/* OS functions */
177#define SYS_F_FOPEN 1
178#define SYS_F_CONNECT 2
179#define SYS_F_GETSERVBYNAME 3
180#define SYS_F_SOCKET 4
181#define SYS_F_IOCTLSOCKET 5
182#define SYS_F_BIND 6
183#define SYS_F_LISTEN 7
184#define SYS_F_ACCEPT 8
185#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
186#define SYS_F_OPENDIR 10
187#define SYS_F_FREAD 11
188#define SYS_F_GETADDRINFO 12
189
190
191/* reasons */
192#define ERR_R_SYS_LIB ERR_LIB_SYS /* 2 */
193#define ERR_R_BN_LIB ERR_LIB_BN /* 3 */
194#define ERR_R_RSA_LIB ERR_LIB_RSA /* 4 */
195#define ERR_R_DH_LIB ERR_LIB_DH /* 5 */
196#define ERR_R_EVP_LIB ERR_LIB_EVP /* 6 */
197#define ERR_R_BUF_LIB ERR_LIB_BUF /* 7 */
198#define ERR_R_OBJ_LIB ERR_LIB_OBJ /* 8 */
199#define ERR_R_PEM_LIB ERR_LIB_PEM /* 9 */
200#define ERR_R_DSA_LIB ERR_LIB_DSA /* 10 */
201#define ERR_R_X509_LIB ERR_LIB_X509 /* 11 */
202#define ERR_R_ASN1_LIB ERR_LIB_ASN1 /* 13 */
203#define ERR_R_CONF_LIB ERR_LIB_CONF /* 14 */
204#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO /* 15 */
205#define ERR_R_EC_LIB ERR_LIB_EC /* 16 */
206#define ERR_R_SSL_LIB ERR_LIB_SSL /* 20 */
207#define ERR_R_BIO_LIB ERR_LIB_BIO /* 32 */
208#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 /* 33 */
209#define ERR_R_X509V3_LIB ERR_LIB_X509V3 /* 34 */
210#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12 /* 35 */
211#define ERR_R_RAND_LIB ERR_LIB_RAND /* 36 */
212#define ERR_R_DSO_LIB ERR_LIB_DSO /* 37 */
213#define ERR_R_ENGINE_LIB ERR_LIB_ENGINE /* 38 */
214#define ERR_R_OCSP_LIB ERR_LIB_OCSP /* 39 */
215#define ERR_R_UI_LIB ERR_LIB_UI /* 40 */
216#define ERR_R_COMP_LIB ERR_LIB_COMP /* 41 */
217
218#define ERR_R_NESTED_ASN1_ERROR 58
219#define ERR_R_BAD_ASN1_OBJECT_HEADER 59
220#define ERR_R_BAD_GET_ASN1_OBJECT_CALL 60
221#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE 61
222#define ERR_R_ASN1_LENGTH_MISMATCH 62
223#define ERR_R_MISSING_ASN1_EOS 63
224
225/* fatal error */
226#define ERR_R_FATAL 64
227#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
228#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
229#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
230#define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL)
231
232/* 99 is the maximum possible ERR_R_... code, higher values
233 * are reserved for the individual libraries */
234
235
236typedef struct ERR_string_data_st
237 {
238 unsigned long error;
239 const char *string;
240 } ERR_STRING_DATA;
241
242void ERR_put_error(int lib, int func,int reason,const char *file,int line);
243void ERR_set_error_data(char *data,int flags);
244
245unsigned long ERR_get_error(void);
246unsigned long ERR_get_error_line(const char **file,int *line);
247unsigned long ERR_get_error_line_data(const char **file,int *line,
248 const char **data, int *flags);
249unsigned long ERR_peek_error(void);
250unsigned long ERR_peek_error_line(const char **file,int *line);
251unsigned long ERR_peek_error_line_data(const char **file,int *line,
252 const char **data,int *flags);
253unsigned long ERR_peek_last_error(void);
254unsigned long ERR_peek_last_error_line(const char **file,int *line);
255unsigned long ERR_peek_last_error_line_data(const char **file,int *line,
256 const char **data,int *flags);
257void ERR_clear_error(void );
258char *ERR_error_string(unsigned long e,char *buf);
259void ERR_error_string_n(unsigned long e, char *buf, size_t len);
260const char *ERR_lib_error_string(unsigned long e);
261const char *ERR_func_error_string(unsigned long e);
262const char *ERR_reason_error_string(unsigned long e);
263void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
264 void *u);
265#ifndef OPENSSL_NO_FP_API
266void ERR_print_errors_fp(FILE *fp);
267#endif
268#ifndef OPENSSL_NO_BIO
269void ERR_print_errors(BIO *bp);
270void ERR_add_error_data(int num, ...);
271#endif
272void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
273void ERR_unload_strings(int lib,ERR_STRING_DATA str[]);
274void ERR_load_ERR_strings(void);
275void ERR_load_crypto_strings(void);
276void ERR_free_strings(void);
277
278void ERR_remove_state(unsigned long pid); /* if zero we look it up */
279ERR_STATE *ERR_get_state(void);
280
281#ifndef OPENSSL_NO_LHASH
282LHASH *ERR_get_string_table(void);
283LHASH *ERR_get_err_state_table(void);
284void ERR_release_err_state_table(LHASH **hash);
285#endif
286
287int ERR_get_next_error_library(void);
288
289/* This opaque type encapsulates the low-level error-state functions */
290typedef struct st_ERR_FNS ERR_FNS;
291/* An application can use this function and provide the return value to loaded
292 * modules that should use the application's ERR state/functionality */
293const ERR_FNS *ERR_get_implementation(void);
294/* A loaded module should call this function prior to any ERR operations using
295 * the application's "ERR_FNS". */
296int ERR_set_implementation(const ERR_FNS *fns);
297
298#ifdef __cplusplus
299}
300#endif
301
302#endif
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
new file mode 100644
index 0000000000..4dc9300892
--- /dev/null
+++ b/src/lib/libcrypto/err/err_all.c
@@ -0,0 +1,137 @@
1/* crypto/err/err_all.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/asn1.h>
61#include <openssl/bn.h>
62#ifndef OPENSSL_NO_EC
63#include <openssl/ec.h>
64#endif
65#include <openssl/buffer.h>
66#include <openssl/bio.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70#ifndef OPENSSL_NO_DH
71#include <openssl/dh.h>
72#endif
73#ifndef OPENSSL_NO_DSA
74#include <openssl/dsa.h>
75#endif
76#include <openssl/evp.h>
77#include <openssl/objects.h>
78#include <openssl/pem2.h>
79#include <openssl/x509.h>
80#include <openssl/x509v3.h>
81#include <openssl/conf.h>
82#include <openssl/pkcs12.h>
83#include <openssl/rand.h>
84#include <openssl/dso.h>
85#ifndef OPENSSL_NO_ENGINE
86#include <openssl/engine.h>
87#endif
88#include <openssl/ocsp.h>
89#include <openssl/err.h>
90#include <openssl/fips.h>
91
92void ERR_load_crypto_strings(void)
93 {
94 static int done=0;
95
96 if (done) return;
97 done=1;
98#ifndef OPENSSL_NO_ERR
99 ERR_load_ERR_strings(); /* include error strings for SYSerr */
100 ERR_load_BN_strings();
101#ifndef OPENSSL_NO_RSA
102 ERR_load_RSA_strings();
103#endif
104#ifndef OPENSSL_NO_DH
105 ERR_load_DH_strings();
106#endif
107 ERR_load_EVP_strings();
108 ERR_load_BUF_strings();
109 ERR_load_OBJ_strings();
110 ERR_load_PEM_strings();
111#ifndef OPENSSL_NO_DSA
112 ERR_load_DSA_strings();
113#endif
114 ERR_load_X509_strings();
115 ERR_load_ASN1_strings();
116 ERR_load_CONF_strings();
117 ERR_load_CRYPTO_strings();
118#ifndef OPENSSL_NO_EC
119 ERR_load_EC_strings();
120#endif
121 /* skip ERR_load_SSL_strings() because it is not in this library */
122 ERR_load_BIO_strings();
123 ERR_load_PKCS7_strings();
124 ERR_load_X509V3_strings();
125 ERR_load_PKCS12_strings();
126 ERR_load_RAND_strings();
127 ERR_load_DSO_strings();
128#ifndef OPENSSL_NO_ENGINE
129 ERR_load_ENGINE_strings();
130#endif
131 ERR_load_OCSP_strings();
132 ERR_load_UI_strings();
133#endif
134#ifdef OPENSSL_FIPS
135 ERR_load_FIPS_strings();
136#endif
137 }
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c
new file mode 100644
index 0000000000..81e34bd6ce
--- /dev/null
+++ b/src/lib/libcrypto/err/err_prn.c
@@ -0,0 +1,106 @@
1/* crypto/err/err_prn.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/lhash.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65
66void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
67 void *u)
68 {
69 unsigned long l;
70 char buf[256];
71 char buf2[4096];
72 const char *file,*data;
73 int line,flags;
74 unsigned long es;
75
76 es=CRYPTO_thread_id();
77 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
78 {
79 ERR_error_string_n(l, buf, sizeof buf);
80 BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf,
81 file, line, (flags & ERR_TXT_STRING) ? data : "");
82 cb(buf2, strlen(buf2), u);
83 }
84 }
85
86#ifndef OPENSSL_NO_FP_API
87static int print_fp(const char *str, size_t len, void *fp)
88 {
89 return fprintf((FILE *)fp, "%s", str);
90 }
91void ERR_print_errors_fp(FILE *fp)
92 {
93 ERR_print_errors_cb(print_fp, fp);
94 }
95#endif
96
97static int print_bio(const char *str, size_t len, void *bp)
98 {
99 return BIO_write((BIO *)bp, str, len);
100 }
101void ERR_print_errors(BIO *bp)
102 {
103 ERR_print_errors_cb(print_bio, bp);
104 }
105
106
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec
new file mode 100644
index 0000000000..447a7f87ed
--- /dev/null
+++ b/src/lib/libcrypto/err/openssl.ec
@@ -0,0 +1,82 @@
1# crypto/err/openssl.ec
2
3# configuration file for util/mkerr.pl
4
5# files that may have to be rewritten by util/mkerr.pl
6L ERR NONE NONE
7L BN crypto/bn/bn.h crypto/bn/bn_err.c
8L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c
9L DH crypto/dh/dh.h crypto/dh/dh_err.c
10L EVP crypto/evp/evp.h crypto/evp/evp_err.c
11L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c
12L OBJ crypto/objects/objects.h crypto/objects/obj_err.c
13L PEM crypto/pem/pem.h crypto/pem/pem_err.c
14L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c
15L X509 crypto/x509/x509.h crypto/x509/x509_err.c
16L ASN1 crypto/asn1/asn1.h crypto/asn1/asn1_err.c
17L CONF crypto/conf/conf.h crypto/conf/conf_err.c
18L CRYPTO crypto/crypto.h crypto/cpt_err.c
19L EC crypto/ec/ec.h crypto/ec/ec_err.c
20L SSL ssl/ssl.h ssl/ssl_err.c
21L BIO crypto/bio/bio.h crypto/bio/bio_err.c
22L PKCS7 crypto/pkcs7/pkcs7.h crypto/pkcs7/pkcs7err.c
23L X509V3 crypto/x509v3/x509v3.h crypto/x509v3/v3err.c
24L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c
25L RAND crypto/rand/rand.h crypto/rand/rand_err.c
26L DSO crypto/dso/dso.h crypto/dso/dso_err.c
27L ENGINE crypto/engine/engine.h crypto/engine/eng_err.c
28L OCSP crypto/ocsp/ocsp.h crypto/ocsp/ocsp_err.c
29L UI crypto/ui/ui.h crypto/ui/ui_err.c
30L FIPS fips/fips.h fips/fips_err.h
31
32# additional header files to be scanned for function names
33L NONE crypto/x509/x509_vfy.h NONE
34L NONE crypto/ec/ec_lcl.h NONE
35
36
37F RSAREF_F_RSA_BN2BIN
38F RSAREF_F_RSA_PRIVATE_DECRYPT
39F RSAREF_F_RSA_PRIVATE_ENCRYPT
40F RSAREF_F_RSA_PUBLIC_DECRYPT
41F RSAREF_F_RSA_PUBLIC_ENCRYPT
42#F SSL_F_CLIENT_CERTIFICATE
43
44R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
45R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
46R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
47R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
48R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
49R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
50R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
51R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
52R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
53R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
54R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
55R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
56R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
57R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
58R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
59R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
60R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
61R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
62R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
63R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
64R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
65R SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
66R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
67
68R RSAREF_R_CONTENT_ENCODING 0x0400
69R RSAREF_R_DATA 0x0401
70R RSAREF_R_DIGEST_ALGORITHM 0x0402
71R RSAREF_R_ENCODING 0x0403
72R RSAREF_R_KEY 0x0404
73R RSAREF_R_KEY_ENCODING 0x0405
74R RSAREF_R_LEN 0x0406
75R RSAREF_R_MODULUS_LEN 0x0407
76R RSAREF_R_NEED_RANDOM 0x0408
77R RSAREF_R_PRIVATE_KEY 0x0409
78R RSAREF_R_PUBLIC_KEY 0x040a
79R RSAREF_R_SIGNATURE 0x040b
80R RSAREF_R_SIGNATURE_ENCODING 0x040c
81R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
82
diff --git a/src/lib/libcrypto/evp/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
new file mode 100644
index 0000000000..33349c2f98
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -0,0 +1,567 @@
1/* crypto/evp/bio_b64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int b64_write(BIO *h, const char *buf, int num);
66static int b64_read(BIO *h, char *buf, int size);
67/*static int b64_puts(BIO *h, const char *str); */
68/*static int b64_gets(BIO *h, char *str, int size); */
69static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int b64_new(BIO *h);
71static int b64_free(BIO *data);
72static long b64_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
73#define B64_BLOCK_SIZE 1024
74#define B64_BLOCK_SIZE2 768
75#define B64_NONE 0
76#define B64_ENCODE 1
77#define B64_DECODE 2
78
79typedef struct b64_struct
80 {
81 /*BIO *bio; moved to the BIO structure */
82 int buf_len;
83 int buf_off;
84 int tmp_len; /* used to find the start when decoding */
85 int tmp_nl; /* If true, scan until '\n' */
86 int encode;
87 int start; /* have we started decoding yet? */
88 int cont; /* <= 0 when finished */
89 EVP_ENCODE_CTX base64;
90 char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10];
91 char tmp[B64_BLOCK_SIZE];
92 } BIO_B64_CTX;
93
94static BIO_METHOD methods_b64=
95 {
96 BIO_TYPE_BASE64,"base64 encoding",
97 b64_write,
98 b64_read,
99 NULL, /* b64_puts, */
100 NULL, /* b64_gets, */
101 b64_ctrl,
102 b64_new,
103 b64_free,
104 b64_callback_ctrl,
105 };
106
107BIO_METHOD *BIO_f_base64(void)
108 {
109 return(&methods_b64);
110 }
111
112static int b64_new(BIO *bi)
113 {
114 BIO_B64_CTX *ctx;
115
116 ctx=(BIO_B64_CTX *)OPENSSL_malloc(sizeof(BIO_B64_CTX));
117 if (ctx == NULL) return(0);
118
119 ctx->buf_len=0;
120 ctx->tmp_len=0;
121 ctx->tmp_nl=0;
122 ctx->buf_off=0;
123 ctx->cont=1;
124 ctx->start=1;
125 ctx->encode=0;
126
127 bi->init=1;
128 bi->ptr=(char *)ctx;
129 bi->flags=0;
130 return(1);
131 }
132
133static int b64_free(BIO *a)
134 {
135 if (a == NULL) return(0);
136 OPENSSL_free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int b64_read(BIO *b, char *out, int outl)
144 {
145 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
146 BIO_B64_CTX *ctx;
147 unsigned char *p,*q;
148
149 if (out == NULL) return(0);
150 ctx=(BIO_B64_CTX *)b->ptr;
151
152 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
153
154 if (ctx->encode != B64_DECODE)
155 {
156 ctx->encode=B64_DECODE;
157 ctx->buf_len=0;
158 ctx->buf_off=0;
159 ctx->tmp_len=0;
160 EVP_DecodeInit(&(ctx->base64));
161 }
162
163 /* First check if there are bytes decoded/encoded */
164 if (ctx->buf_len > 0)
165 {
166 i=ctx->buf_len-ctx->buf_off;
167 if (i > outl) i=outl;
168 OPENSSL_assert(ctx->buf_off+i < sizeof ctx->buf);
169 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
170 ret=i;
171 out+=i;
172 outl-=i;
173 ctx->buf_off+=i;
174 if (ctx->buf_len == ctx->buf_off)
175 {
176 ctx->buf_len=0;
177 ctx->buf_off=0;
178 }
179 }
180
181 /* At this point, we have room of outl bytes and an empty
182 * buffer, so we should read in some more. */
183
184 ret_code=0;
185 while (outl > 0)
186 {
187
188 if (ctx->cont <= 0)
189 break;
190
191 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
192 B64_BLOCK_SIZE-ctx->tmp_len);
193
194 if (i <= 0)
195 {
196 ret_code=i;
197
198 /* Should be continue next time we are called? */
199 if (!BIO_should_retry(b->next_bio))
200 {
201 ctx->cont=i;
202 /* If buffer empty break */
203 if(ctx->tmp_len == 0)
204 break;
205 /* Fall through and process what we have */
206 else
207 i = 0;
208 }
209 /* else we retry and add more data to buffer */
210 else
211 break;
212 }
213 i+=ctx->tmp_len;
214 ctx->tmp_len = i;
215
216 /* We need to scan, a line at a time until we
217 * have a valid line if we are starting. */
218 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
219 {
220 /* ctx->start=1; */
221 ctx->tmp_len=0;
222 }
223 else if (ctx->start)
224 {
225 q=p=(unsigned char *)ctx->tmp;
226 for (j=0; j<i; j++)
227 {
228 if (*(q++) != '\n') continue;
229
230 /* due to a previous very long line,
231 * we need to keep on scanning for a '\n'
232 * before we even start looking for
233 * base64 encoded stuff. */
234 if (ctx->tmp_nl)
235 {
236 p=q;
237 ctx->tmp_nl=0;
238 continue;
239 }
240
241 k=EVP_DecodeUpdate(&(ctx->base64),
242 (unsigned char *)ctx->buf,
243 &num,p,q-p);
244 if ((k <= 0) && (num == 0) && (ctx->start))
245 EVP_DecodeInit(&ctx->base64);
246 else
247 {
248 if (p != (unsigned char *)
249 &(ctx->tmp[0]))
250 {
251 i-=(p- (unsigned char *)
252 &(ctx->tmp[0]));
253 for (x=0; x < i; x++)
254 ctx->tmp[x]=p[x];
255 }
256 EVP_DecodeInit(&ctx->base64);
257 ctx->start=0;
258 break;
259 }
260 p=q;
261 }
262
263 /* we fell off the end without starting */
264 if (j == i)
265 {
266 /* Is this is one long chunk?, if so, keep on
267 * reading until a new line. */
268 if (p == (unsigned char *)&(ctx->tmp[0]))
269 {
270 /* Check buffer full */
271 if (i == B64_BLOCK_SIZE)
272 {
273 ctx->tmp_nl=1;
274 ctx->tmp_len=0;
275 }
276 }
277 else if (p != q) /* finished on a '\n' */
278 {
279 n=q-p;
280 for (ii=0; ii<n; ii++)
281 ctx->tmp[ii]=p[ii];
282 ctx->tmp_len=n;
283 }
284 /* else finished on a '\n' */
285 continue;
286 }
287 else
288 ctx->tmp_len=0;
289 }
290 /* If buffer isn't full and we can retry then
291 * restart to read in more data.
292 */
293 else if ((i < B64_BLOCK_SIZE) && (ctx->cont > 0))
294 continue;
295
296 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
297 {
298 int z,jj;
299
300 jj=(i>>2)<<2;
301 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
302 (unsigned char *)ctx->tmp,jj);
303 if (jj > 2)
304 {
305 if (ctx->tmp[jj-1] == '=')
306 {
307 z--;
308 if (ctx->tmp[jj-2] == '=')
309 z--;
310 }
311 }
312 /* z is now number of output bytes and jj is the
313 * number consumed */
314 if (jj != i)
315 {
316 memcpy((unsigned char *)ctx->tmp,
317 (unsigned char *)&(ctx->tmp[jj]),i-jj);
318 ctx->tmp_len=i-jj;
319 }
320 ctx->buf_len=0;
321 if (z > 0)
322 {
323 ctx->buf_len=z;
324 i=1;
325 }
326 else
327 i=z;
328 }
329 else
330 {
331 i=EVP_DecodeUpdate(&(ctx->base64),
332 (unsigned char *)ctx->buf,&ctx->buf_len,
333 (unsigned char *)ctx->tmp,i);
334 ctx->tmp_len = 0;
335 }
336 ctx->buf_off=0;
337 if (i < 0)
338 {
339 ret_code=0;
340 ctx->buf_len=0;
341 break;
342 }
343
344 if (ctx->buf_len <= outl)
345 i=ctx->buf_len;
346 else
347 i=outl;
348
349 memcpy(out,ctx->buf,i);
350 ret+=i;
351 ctx->buf_off=i;
352 if (ctx->buf_off == ctx->buf_len)
353 {
354 ctx->buf_len=0;
355 ctx->buf_off=0;
356 }
357 outl-=i;
358 out+=i;
359 }
360 BIO_clear_retry_flags(b);
361 BIO_copy_next_retry(b);
362 return((ret == 0)?ret_code:ret);
363 }
364
365static int b64_write(BIO *b, const char *in, int inl)
366 {
367 int ret=inl,n,i;
368 BIO_B64_CTX *ctx;
369
370 ctx=(BIO_B64_CTX *)b->ptr;
371 BIO_clear_retry_flags(b);
372
373 if (ctx->encode != B64_ENCODE)
374 {
375 ctx->encode=B64_ENCODE;
376 ctx->buf_len=0;
377 ctx->buf_off=0;
378 ctx->tmp_len=0;
379 EVP_EncodeInit(&(ctx->base64));
380 }
381
382 n=ctx->buf_len-ctx->buf_off;
383 while (n > 0)
384 {
385 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
386 if (i <= 0)
387 {
388 BIO_copy_next_retry(b);
389 return(i);
390 }
391 ctx->buf_off+=i;
392 n-=i;
393 }
394 /* at this point all pending data has been written */
395 ctx->buf_off=0;
396 ctx->buf_len=0;
397
398 if ((in == NULL) || (inl <= 0)) return(0);
399
400 while (inl > 0)
401 {
402 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
403
404 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
405 {
406 if (ctx->tmp_len > 0)
407 {
408 n=3-ctx->tmp_len;
409 /* There's a teoretical possibility for this */
410 if (n > inl)
411 n=inl;
412 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
413 ctx->tmp_len+=n;
414 if (ctx->tmp_len < 3)
415 break;
416 ctx->buf_len=EVP_EncodeBlock(
417 (unsigned char *)ctx->buf,
418 (unsigned char *)ctx->tmp,
419 ctx->tmp_len);
420 /* Since we're now done using the temporary
421 buffer, the length should be 0'd */
422 ctx->tmp_len=0;
423 }
424 else
425 {
426 if (n < 3)
427 {
428 memcpy(&(ctx->tmp[0]),in,n);
429 ctx->tmp_len=n;
430 break;
431 }
432 n-=n%3;
433 ctx->buf_len=EVP_EncodeBlock(
434 (unsigned char *)ctx->buf,
435 (unsigned char *)in,n);
436 }
437 }
438 else
439 {
440 EVP_EncodeUpdate(&(ctx->base64),
441 (unsigned char *)ctx->buf,&ctx->buf_len,
442 (unsigned char *)in,n);
443 }
444 inl-=n;
445 in+=n;
446
447 ctx->buf_off=0;
448 n=ctx->buf_len;
449 while (n > 0)
450 {
451 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
452 if (i <= 0)
453 {
454 BIO_copy_next_retry(b);
455 return((ret == 0)?i:ret);
456 }
457 n-=i;
458 ctx->buf_off+=i;
459 }
460 ctx->buf_len=0;
461 ctx->buf_off=0;
462 }
463 return(ret);
464 }
465
466static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
467 {
468 BIO_B64_CTX *ctx;
469 long ret=1;
470 int i;
471
472 ctx=(BIO_B64_CTX *)b->ptr;
473
474 switch (cmd)
475 {
476 case BIO_CTRL_RESET:
477 ctx->cont=1;
478 ctx->start=1;
479 ctx->encode=B64_NONE;
480 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
481 break;
482 case BIO_CTRL_EOF: /* More to read */
483 if (ctx->cont <= 0)
484 ret=1;
485 else
486 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
487 break;
488 case BIO_CTRL_WPENDING: /* More to write in buffer */
489 ret=ctx->buf_len-ctx->buf_off;
490 if ((ret == 0) && (ctx->encode != B64_NONE)
491 && (ctx->base64.num != 0))
492 ret=1;
493 else if (ret <= 0)
494 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
495 break;
496 case BIO_CTRL_PENDING: /* More to read in buffer */
497 ret=ctx->buf_len-ctx->buf_off;
498 if (ret <= 0)
499 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
500 break;
501 case BIO_CTRL_FLUSH:
502 /* do a final write */
503again:
504 while (ctx->buf_len != ctx->buf_off)
505 {
506 i=b64_write(b,NULL,0);
507 if (i < 0)
508 return i;
509 }
510 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
511 {
512 if (ctx->tmp_len != 0)
513 {
514 ctx->buf_len=EVP_EncodeBlock(
515 (unsigned char *)ctx->buf,
516 (unsigned char *)ctx->tmp,
517 ctx->tmp_len);
518 ctx->buf_off=0;
519 ctx->tmp_len=0;
520 goto again;
521 }
522 }
523 else if (ctx->encode != B64_NONE && ctx->base64.num != 0)
524 {
525 ctx->buf_off=0;
526 EVP_EncodeFinal(&(ctx->base64),
527 (unsigned char *)ctx->buf,
528 &(ctx->buf_len));
529 /* push out the bytes */
530 goto again;
531 }
532 /* Finally flush the underlying BIO */
533 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
534 break;
535
536 case BIO_C_DO_STATE_MACHINE:
537 BIO_clear_retry_flags(b);
538 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
539 BIO_copy_next_retry(b);
540 break;
541
542 case BIO_CTRL_DUP:
543 break;
544 case BIO_CTRL_INFO:
545 case BIO_CTRL_GET:
546 case BIO_CTRL_SET:
547 default:
548 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
549 break;
550 }
551 return(ret);
552 }
553
554static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
555 {
556 long ret=1;
557
558 if (b->next_bio == NULL) return(0);
559 switch (cmd)
560 {
561 default:
562 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
563 break;
564 }
565 return(ret);
566 }
567
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
new file mode 100644
index 0000000000..ab81851503
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -0,0 +1,426 @@
1/* crypto/evp/bio_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int enc_write(BIO *h, const char *buf, int num);
66static int enc_read(BIO *h, char *buf, int size);
67/*static int enc_puts(BIO *h, const char *str); */
68/*static int enc_gets(BIO *h, char *str, int size); */
69static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int enc_new(BIO *h);
71static int enc_free(BIO *data);
72static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps);
73#define ENC_BLOCK_SIZE (1024*4)
74#define BUF_OFFSET EVP_MAX_BLOCK_LENGTH
75
76typedef struct enc_struct
77 {
78 int buf_len;
79 int buf_off;
80 int cont; /* <= 0 when finished */
81 int finished;
82 int ok; /* bad decrypt */
83 EVP_CIPHER_CTX cipher;
84 /* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate
85 * can return up to a block more data than is presented to it
86 */
87 char buf[ENC_BLOCK_SIZE+BUF_OFFSET+2];
88 } BIO_ENC_CTX;
89
90static BIO_METHOD methods_enc=
91 {
92 BIO_TYPE_CIPHER,"cipher",
93 enc_write,
94 enc_read,
95 NULL, /* enc_puts, */
96 NULL, /* enc_gets, */
97 enc_ctrl,
98 enc_new,
99 enc_free,
100 enc_callback_ctrl,
101 };
102
103BIO_METHOD *BIO_f_cipher(void)
104 {
105 return(&methods_enc);
106 }
107
108static int enc_new(BIO *bi)
109 {
110 BIO_ENC_CTX *ctx;
111
112 ctx=(BIO_ENC_CTX *)OPENSSL_malloc(sizeof(BIO_ENC_CTX));
113 if (ctx == NULL) return(0);
114 EVP_CIPHER_CTX_init(&ctx->cipher);
115
116 ctx->buf_len=0;
117 ctx->buf_off=0;
118 ctx->cont=1;
119 ctx->finished=0;
120 ctx->ok=1;
121
122 bi->init=0;
123 bi->ptr=(char *)ctx;
124 bi->flags=0;
125 return(1);
126 }
127
128static int enc_free(BIO *a)
129 {
130 BIO_ENC_CTX *b;
131
132 if (a == NULL) return(0);
133 b=(BIO_ENC_CTX *)a->ptr;
134 EVP_CIPHER_CTX_cleanup(&(b->cipher));
135 OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX));
136 OPENSSL_free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int enc_read(BIO *b, char *out, int outl)
144 {
145 int ret=0,i;
146 BIO_ENC_CTX *ctx;
147
148 if (out == NULL) return(0);
149 ctx=(BIO_ENC_CTX *)b->ptr;
150
151 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
152
153 /* First check if there are bytes decoded/encoded */
154 if (ctx->buf_len > 0)
155 {
156 i=ctx->buf_len-ctx->buf_off;
157 if (i > outl) i=outl;
158 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
159 ret=i;
160 out+=i;
161 outl-=i;
162 ctx->buf_off+=i;
163 if (ctx->buf_len == ctx->buf_off)
164 {
165 ctx->buf_len=0;
166 ctx->buf_off=0;
167 }
168 }
169
170 /* At this point, we have room of outl bytes and an empty
171 * buffer, so we should read in some more. */
172
173 while (outl > 0)
174 {
175 if (ctx->cont <= 0) break;
176
177 /* read in at IV offset, read the EVP_Cipher
178 * documentation about why */
179 i=BIO_read(b->next_bio,&(ctx->buf[BUF_OFFSET]),ENC_BLOCK_SIZE);
180
181 if (i <= 0)
182 {
183 /* Should be continue next time we are called? */
184 if (!BIO_should_retry(b->next_bio))
185 {
186 ctx->cont=i;
187 i=EVP_CipherFinal_ex(&(ctx->cipher),
188 (unsigned char *)ctx->buf,
189 &(ctx->buf_len));
190 ctx->ok=i;
191 ctx->buf_off=0;
192 }
193 else
194 {
195 ret=(ret == 0)?i:ret;
196 break;
197 }
198 }
199 else
200 {
201 EVP_CipherUpdate(&(ctx->cipher),
202 (unsigned char *)ctx->buf,&ctx->buf_len,
203 (unsigned char *)&(ctx->buf[BUF_OFFSET]),i);
204 ctx->cont=1;
205 /* Note: it is possible for EVP_CipherUpdate to
206 * decrypt zero bytes because this is or looks like
207 * the final block: if this happens we should retry
208 * and either read more data or decrypt the final
209 * block
210 */
211 if(ctx->buf_len == 0) continue;
212 }
213
214 if (ctx->buf_len <= outl)
215 i=ctx->buf_len;
216 else
217 i=outl;
218 if (i <= 0) break;
219 memcpy(out,ctx->buf,i);
220 ret+=i;
221 ctx->buf_off=i;
222 outl-=i;
223 out+=i;
224 }
225
226 BIO_clear_retry_flags(b);
227 BIO_copy_next_retry(b);
228 return((ret == 0)?ctx->cont:ret);
229 }
230
231static int enc_write(BIO *b, const char *in, int inl)
232 {
233 int ret=0,n,i;
234 BIO_ENC_CTX *ctx;
235
236 ctx=(BIO_ENC_CTX *)b->ptr;
237 ret=inl;
238
239 BIO_clear_retry_flags(b);
240 n=ctx->buf_len-ctx->buf_off;
241 while (n > 0)
242 {
243 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
244 if (i <= 0)
245 {
246 BIO_copy_next_retry(b);
247 return(i);
248 }
249 ctx->buf_off+=i;
250 n-=i;
251 }
252 /* at this point all pending data has been written */
253
254 if ((in == NULL) || (inl <= 0)) return(0);
255
256 ctx->buf_off=0;
257 while (inl > 0)
258 {
259 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
260 EVP_CipherUpdate(&(ctx->cipher),
261 (unsigned char *)ctx->buf,&ctx->buf_len,
262 (unsigned char *)in,n);
263 inl-=n;
264 in+=n;
265
266 ctx->buf_off=0;
267 n=ctx->buf_len;
268 while (n > 0)
269 {
270 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
271 if (i <= 0)
272 {
273 BIO_copy_next_retry(b);
274 return (ret == inl) ? i : ret - inl;
275 }
276 n-=i;
277 ctx->buf_off+=i;
278 }
279 ctx->buf_len=0;
280 ctx->buf_off=0;
281 }
282 BIO_copy_next_retry(b);
283 return(ret);
284 }
285
286static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
287 {
288 BIO *dbio;
289 BIO_ENC_CTX *ctx,*dctx;
290 long ret=1;
291 int i;
292 EVP_CIPHER_CTX **c_ctx;
293
294 ctx=(BIO_ENC_CTX *)b->ptr;
295
296 switch (cmd)
297 {
298 case BIO_CTRL_RESET:
299 ctx->ok=1;
300 ctx->finished=0;
301 EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
302 ctx->cipher.encrypt);
303 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
304 break;
305 case BIO_CTRL_EOF: /* More to read */
306 if (ctx->cont <= 0)
307 ret=1;
308 else
309 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
310 break;
311 case BIO_CTRL_WPENDING:
312 ret=ctx->buf_len-ctx->buf_off;
313 if (ret <= 0)
314 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
315 break;
316 case BIO_CTRL_PENDING: /* More to read in buffer */
317 ret=ctx->buf_len-ctx->buf_off;
318 if (ret <= 0)
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 break;
321 case BIO_CTRL_FLUSH:
322 /* do a final write */
323again:
324 while (ctx->buf_len != ctx->buf_off)
325 {
326 i=enc_write(b,NULL,0);
327 if (i < 0)
328 return i;
329 }
330
331 if (!ctx->finished)
332 {
333 ctx->finished=1;
334 ctx->buf_off=0;
335 ret=EVP_CipherFinal_ex(&(ctx->cipher),
336 (unsigned char *)ctx->buf,
337 &(ctx->buf_len));
338 ctx->ok=(int)ret;
339 if (ret <= 0) break;
340
341 /* push out the bytes */
342 goto again;
343 }
344
345 /* Finally flush the underlying BIO */
346 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
347 break;
348 case BIO_C_GET_CIPHER_STATUS:
349 ret=(long)ctx->ok;
350 break;
351 case BIO_C_DO_STATE_MACHINE:
352 BIO_clear_retry_flags(b);
353 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
354 BIO_copy_next_retry(b);
355 break;
356 case BIO_C_GET_CIPHER_CTX:
357 c_ctx=(EVP_CIPHER_CTX **)ptr;
358 (*c_ctx)= &(ctx->cipher);
359 b->init=1;
360 break;
361 case BIO_CTRL_DUP:
362 dbio=(BIO *)ptr;
363 dctx=(BIO_ENC_CTX *)dbio->ptr;
364 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
365 dbio->init=1;
366 break;
367 default:
368 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
369 break;
370 }
371 return(ret);
372 }
373
374static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
375 {
376 long ret=1;
377
378 if (b->next_bio == NULL) return(0);
379 switch (cmd)
380 {
381 default:
382 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
383 break;
384 }
385 return(ret);
386 }
387
388/*
389void BIO_set_cipher_ctx(b,c)
390BIO *b;
391EVP_CIPHER_ctx *c;
392 {
393 if (b == NULL) return;
394
395 if ((b->callback != NULL) &&
396 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
397 return;
398
399 b->init=1;
400 ctx=(BIO_ENC_CTX *)b->ptr;
401 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
402
403 if (b->callback != NULL)
404 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
405 }
406*/
407
408void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
409 unsigned char *i, int e)
410 {
411 BIO_ENC_CTX *ctx;
412
413 if (b == NULL) return;
414
415 if ((b->callback != NULL) &&
416 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
417 return;
418
419 b->init=1;
420 ctx=(BIO_ENC_CTX *)b->ptr;
421 EVP_CipherInit_ex(&(ctx->cipher),c,NULL, k,i,e);
422
423 if (b->callback != NULL)
424 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
425 }
426
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
new file mode 100644
index 0000000000..f4aa41ac4b
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_md.c
@@ -0,0 +1,264 @@
1/* crypto/evp/bio_md.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int md_write(BIO *h, char const *buf, int num);
69static int md_read(BIO *h, char *buf, int size);
70/*static int md_puts(BIO *h, const char *str); */
71static int md_gets(BIO *h, char *str, int size);
72static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2);
73static int md_new(BIO *h);
74static int md_free(BIO *data);
75static long md_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
76
77static BIO_METHOD methods_md=
78 {
79 BIO_TYPE_MD,"message digest",
80 md_write,
81 md_read,
82 NULL, /* md_puts, */
83 md_gets,
84 md_ctrl,
85 md_new,
86 md_free,
87 md_callback_ctrl,
88 };
89
90BIO_METHOD *BIO_f_md(void)
91 {
92 return(&methods_md);
93 }
94
95static int md_new(BIO *bi)
96 {
97 EVP_MD_CTX *ctx;
98
99 ctx=EVP_MD_CTX_create();
100 if (ctx == NULL) return(0);
101
102 bi->init=0;
103 bi->ptr=(char *)ctx;
104 bi->flags=0;
105 return(1);
106 }
107
108static int md_free(BIO *a)
109 {
110 if (a == NULL) return(0);
111 EVP_MD_CTX_destroy(a->ptr);
112 a->ptr=NULL;
113 a->init=0;
114 a->flags=0;
115 return(1);
116 }
117
118static int md_read(BIO *b, char *out, int outl)
119 {
120 int ret=0;
121 EVP_MD_CTX *ctx;
122
123 if (out == NULL) return(0);
124 ctx=b->ptr;
125
126 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
127
128 ret=BIO_read(b->next_bio,out,outl);
129 if (b->init)
130 {
131 if (ret > 0)
132 {
133 EVP_DigestUpdate(ctx,(unsigned char *)out,
134 (unsigned int)ret);
135 }
136 }
137 BIO_clear_retry_flags(b);
138 BIO_copy_next_retry(b);
139 return(ret);
140 }
141
142static int md_write(BIO *b, const char *in, int inl)
143 {
144 int ret=0;
145 EVP_MD_CTX *ctx;
146
147 if ((in == NULL) || (inl <= 0)) return(0);
148 ctx=b->ptr;
149
150 if ((ctx != NULL) && (b->next_bio != NULL))
151 ret=BIO_write(b->next_bio,in,inl);
152 if (b->init)
153 {
154 if (ret > 0)
155 {
156 EVP_DigestUpdate(ctx,(unsigned char *)in,
157 (unsigned int)ret);
158 }
159 }
160 BIO_clear_retry_flags(b);
161 BIO_copy_next_retry(b);
162 return(ret);
163 }
164
165static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
166 {
167 EVP_MD_CTX *ctx,*dctx,**pctx;
168 const EVP_MD **ppmd;
169 EVP_MD *md;
170 long ret=1;
171 BIO *dbio;
172
173 ctx=b->ptr;
174
175 switch (cmd)
176 {
177 case BIO_CTRL_RESET:
178 if (b->init)
179 ret = EVP_DigestInit_ex(ctx,ctx->digest, NULL);
180 else
181 ret=0;
182 if (ret > 0)
183 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
184 break;
185 case BIO_C_GET_MD:
186 if (b->init)
187 {
188 ppmd=ptr;
189 *ppmd=ctx->digest;
190 }
191 else
192 ret=0;
193 break;
194 case BIO_C_GET_MD_CTX:
195 pctx=ptr;
196 *pctx=ctx;
197 break;
198 case BIO_C_SET_MD_CTX:
199 if (b->init)
200 b->ptr=ptr;
201 else
202 ret=0;
203 break;
204 case BIO_C_DO_STATE_MACHINE:
205 BIO_clear_retry_flags(b);
206 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
207 BIO_copy_next_retry(b);
208 break;
209
210 case BIO_C_SET_MD:
211 md=ptr;
212 ret = EVP_DigestInit_ex(ctx,md, NULL);
213 if (ret > 0)
214 b->init=1;
215 break;
216 case BIO_CTRL_DUP:
217 dbio=ptr;
218 dctx=dbio->ptr;
219 EVP_MD_CTX_copy_ex(dctx,ctx);
220 b->init=1;
221 break;
222 default:
223 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
224 break;
225 }
226 return(ret);
227 }
228
229static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
230 {
231 long ret=1;
232
233 if (b->next_bio == NULL) return(0);
234 switch (cmd)
235 {
236 default:
237 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
238 break;
239 }
240 return(ret);
241 }
242
243static int md_gets(BIO *bp, char *buf, int size)
244 {
245 EVP_MD_CTX *ctx;
246 unsigned int ret;
247
248
249 ctx=bp->ptr;
250 if (size < ctx->digest->md_size)
251 return(0);
252 EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret);
253 return((int)ret);
254 }
255
256/*
257static int md_puts(bp,str)
258BIO *bp;
259char *str;
260 {
261 return(-1);
262 }
263*/
264
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
new file mode 100644
index 0000000000..fa60a73ead
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_all.c
@@ -0,0 +1,84 @@
1/* crypto/evp/c_all.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#ifndef OPENSSL_NO_ENGINE
63#include <openssl/engine.h>
64#endif
65
66#if 0
67#undef OpenSSL_add_all_algorithms
68
69void OpenSSL_add_all_algorithms(void)
70 {
71 OPENSSL_add_all_algorithms_noconf();
72 }
73#endif
74
75void OPENSSL_add_all_algorithms_noconf(void)
76 {
77 OpenSSL_add_all_ciphers();
78 OpenSSL_add_all_digests();
79#ifndef OPENSSL_NO_ENGINE
80# if defined(__OpenBSD__) || defined(__FreeBSD__)
81 ENGINE_setup_bsd_cryptodev();
82# endif
83#endif
84 }
diff --git a/src/lib/libcrypto/evp/c_alld.c b/src/lib/libcrypto/evp/c_alld.c
index 929ea56a3e..aae7bf7482 100644
--- a/src/lib/libcrypto/evp/c_alld.c
+++ b/src/lib/libcrypto/evp/c_alld.c
@@ -100,14 +100,4 @@ void OpenSSL_add_all_digests(void)
100 EVP_add_digest_alias(SN_ripemd160,"ripemd"); 100 EVP_add_digest_alias(SN_ripemd160,"ripemd");
101 EVP_add_digest_alias(SN_ripemd160,"rmd160"); 101 EVP_add_digest_alias(SN_ripemd160,"rmd160");
102#endif 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 } 103 }
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
new file mode 100644
index 0000000000..f21c63842c
--- /dev/null
+++ b/src/lib/libcrypto/evp/digest.c
@@ -0,0 +1,379 @@
1/* crypto/evp/digest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include "cryptlib.h"
114#include <openssl/objects.h>
115#include <openssl/evp.h>
116#ifndef OPENSSL_NO_ENGINE
117#include <openssl/engine.h>
118#endif
119
120void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
121 {
122 memset(ctx,'\0',sizeof *ctx);
123 }
124
125EVP_MD_CTX *EVP_MD_CTX_create(void)
126 {
127 EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
128
129 EVP_MD_CTX_init(ctx);
130
131 return ctx;
132 }
133
134int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
135 {
136 EVP_MD_CTX_init(ctx);
137 return EVP_DigestInit_ex(ctx, type, NULL);
138 }
139
140#ifdef OPENSSL_FIPS
141
142/* The purpose of these is to trap programs that attempt to use non FIPS
143 * algorithms in FIPS mode and ignore the errors.
144 */
145
146static int bad_init(EVP_MD_CTX *ctx)
147 { FIPS_ERROR_IGNORED("Digest init"); return 0;}
148
149static int bad_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
150 { FIPS_ERROR_IGNORED("Digest update"); return 0;}
151
152static int bad_final(EVP_MD_CTX *ctx,unsigned char *md)
153 { FIPS_ERROR_IGNORED("Digest Final"); return 0;}
154
155static const EVP_MD bad_md =
156 {
157 0,
158 0,
159 0,
160 0,
161 bad_init,
162 bad_update,
163 bad_final,
164 NULL,
165 NULL,
166 NULL,
167 0,
168 {0,0,0,0},
169 };
170
171#endif
172
173int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
174 {
175 EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
176#ifndef OPENSSL_NO_ENGINE
177 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
178 * so this context may already have an ENGINE! Try to avoid releasing
179 * the previous handle, re-querying for an ENGINE, and having a
180 * reinitialisation, when it may all be unecessary. */
181 if (ctx->engine && ctx->digest && (!type ||
182 (type && (type->type == ctx->digest->type))))
183 goto skip_to_init;
184 if (type)
185 {
186 /* Ensure an ENGINE left lying around from last time is cleared
187 * (the previous check attempted to avoid this if the same
188 * ENGINE and EVP_MD could be used). */
189 if(ctx->engine)
190 ENGINE_finish(ctx->engine);
191 if(impl)
192 {
193 if (!ENGINE_init(impl))
194 {
195 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
196 return 0;
197 }
198 }
199 else
200 /* Ask if an ENGINE is reserved for this job */
201 impl = ENGINE_get_digest_engine(type->type);
202 if(impl)
203 {
204 /* There's an ENGINE for this job ... (apparently) */
205 const EVP_MD *d = ENGINE_get_digest(impl, type->type);
206 if(!d)
207 {
208 /* Same comment from evp_enc.c */
209 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
210 return 0;
211 }
212 /* We'll use the ENGINE's private digest definition */
213 type = d;
214 /* Store the ENGINE functional reference so we know
215 * 'type' came from an ENGINE and we need to release
216 * it when done. */
217 ctx->engine = impl;
218 }
219 else
220 ctx->engine = NULL;
221 }
222 else
223 if(!ctx->digest)
224 {
225 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET);
226 return 0;
227 }
228#endif
229 if (ctx->digest != type)
230 {
231#ifdef OPENSSL_FIPS
232 if (FIPS_mode())
233 {
234 if (!(type->flags & EVP_MD_FLAG_FIPS)
235 && !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
236 {
237 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_DISABLED_FOR_FIPS);
238 ctx->digest = &bad_md;
239 return 0;
240 }
241 }
242#endif
243 if (ctx->digest && ctx->digest->ctx_size)
244 OPENSSL_free(ctx->md_data);
245 ctx->digest=type;
246 if (type->ctx_size)
247 ctx->md_data=OPENSSL_malloc(type->ctx_size);
248 }
249#ifndef OPENSSL_NO_ENGINE
250skip_to_init:
251#endif
252 return ctx->digest->init(ctx);
253 }
254
255int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
256 unsigned int count)
257 {
258 return ctx->digest->update(ctx,data,(unsigned long)count);
259 }
260
261/* The caller can assume that this removes any secret data from the context */
262int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
263 {
264 int ret;
265 ret = EVP_DigestFinal_ex(ctx, md, size);
266 EVP_MD_CTX_cleanup(ctx);
267 return ret;
268 }
269
270/* The caller can assume that this removes any secret data from the context */
271int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
272 {
273 int ret;
274
275 OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
276 ret=ctx->digest->final(ctx,md);
277 if (size != NULL)
278 *size=ctx->digest->md_size;
279 if (ctx->digest->cleanup)
280 {
281 ctx->digest->cleanup(ctx);
282 EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
283 }
284 memset(ctx->md_data,0,ctx->digest->ctx_size);
285 return ret;
286 }
287
288int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in)
289 {
290 EVP_MD_CTX_init(out);
291 return EVP_MD_CTX_copy_ex(out, in);
292 }
293
294int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
295 {
296 unsigned char *tmp_buf;
297 if ((in == NULL) || (in->digest == NULL))
298 {
299 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
300 return 0;
301 }
302#ifndef OPENSSL_NO_ENGINE
303 /* Make sure it's safe to copy a digest context using an ENGINE */
304 if (in->engine && !ENGINE_init(in->engine))
305 {
306 EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB);
307 return 0;
308 }
309#endif
310
311 if (out->digest == in->digest)
312 {
313 tmp_buf = out->md_data;
314 EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE);
315 }
316 else tmp_buf = NULL;
317 EVP_MD_CTX_cleanup(out);
318 memcpy(out,in,sizeof *out);
319
320 if (out->digest->ctx_size)
321 {
322 if (tmp_buf) out->md_data = tmp_buf;
323 else out->md_data=OPENSSL_malloc(out->digest->ctx_size);
324 memcpy(out->md_data,in->md_data,out->digest->ctx_size);
325 }
326
327 if (out->digest->copy)
328 return out->digest->copy(out,in);
329
330 return 1;
331 }
332
333int EVP_Digest(void *data, unsigned int count,
334 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl)
335 {
336 EVP_MD_CTX ctx;
337 int ret;
338
339 EVP_MD_CTX_init(&ctx);
340 EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
341 ret=EVP_DigestInit_ex(&ctx, type, impl)
342 && EVP_DigestUpdate(&ctx, data, count)
343 && EVP_DigestFinal_ex(&ctx, md, size);
344 EVP_MD_CTX_cleanup(&ctx);
345
346 return ret;
347 }
348
349void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
350 {
351 EVP_MD_CTX_cleanup(ctx);
352 OPENSSL_free(ctx);
353 }
354
355/* This call frees resources associated with the context */
356int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
357 {
358 /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
359 * because sometimes only copies of the context are ever finalised.
360 */
361 if (ctx->digest && ctx->digest->cleanup
362 && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
363 ctx->digest->cleanup(ctx);
364 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
365 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
366 {
367 OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size);
368 OPENSSL_free(ctx->md_data);
369 }
370#ifndef OPENSSL_NO_ENGINE
371 if(ctx->engine)
372 /* The EVP_MD we used belongs to an ENGINE, release the
373 * functional reference we held for this reason. */
374 ENGINE_finish(ctx->engine);
375#endif
376 memset(ctx,'\0',sizeof *ctx);
377
378 return 1;
379 }
diff --git a/src/lib/libcrypto/evp/e_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
new file mode 100644
index 0000000000..f35036c9d7
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -0,0 +1,118 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 */
50
51#ifndef OPENSSL_NO_AES
52#include <openssl/evp.h>
53#include <openssl/err.h>
54#include <string.h>
55#include <openssl/aes.h>
56#include "evp_locl.h"
57
58static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
59 const unsigned char *iv, int enc);
60
61typedef struct
62 {
63 AES_KEY ks;
64 } EVP_AES_KEY;
65
66#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx)
67
68IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
69 NID_aes_128, 16, 16, 16, 128,
70 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
71 EVP_CIPHER_set_asn1_iv,
72 EVP_CIPHER_get_asn1_iv,
73 NULL)
74IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
75 NID_aes_192, 16, 24, 16, 128,
76 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
77 EVP_CIPHER_set_asn1_iv,
78 EVP_CIPHER_get_asn1_iv,
79 NULL)
80IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
81 NID_aes_256, 16, 32, 16, 128,
82 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
83 EVP_CIPHER_set_asn1_iv,
84 EVP_CIPHER_get_asn1_iv,
85 NULL)
86
87#define IMPLEMENT_AES_CFBR(ksize,cbits,flags) IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16,flags)
88
89IMPLEMENT_AES_CFBR(128,1,0)
90IMPLEMENT_AES_CFBR(192,1,0)
91IMPLEMENT_AES_CFBR(256,1,0)
92
93IMPLEMENT_AES_CFBR(128,8,EVP_CIPH_FLAG_FIPS)
94IMPLEMENT_AES_CFBR(192,8,EVP_CIPH_FLAG_FIPS)
95IMPLEMENT_AES_CFBR(256,8,EVP_CIPH_FLAG_FIPS)
96
97static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
98 const unsigned char *iv, int enc)
99 {
100 int ret;
101
102 if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE
103 || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE
104 || enc)
105 ret=AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
106 else
107 ret=AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
108
109 if(ret < 0)
110 {
111 EVPerr(EVP_F_AES_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED);
112 return 0;
113 }
114
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c
new file mode 100644
index 0000000000..e74337567b
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_bf.c
@@ -0,0 +1,88 @@
1/* crypto/evp/e_bf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_BF
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/blowfish.h>
66
67static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv, int enc);
69
70typedef struct
71 {
72 BF_KEY ks;
73 } EVP_BF_KEY;
74
75#define data(ctx) EVP_C_DATA(EVP_BF_KEY,ctx)
76
77IMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
78 EVP_CIPH_VARIABLE_LENGTH, bf_init_key, NULL,
79 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
80
81static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
82 const unsigned char *iv, int enc)
83 {
84 BF_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
85 return 1;
86 }
87
88#endif
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c
new file mode 100644
index 0000000000..3400fef187
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_cast.c
@@ -0,0 +1,90 @@
1/* crypto/evp/e_cast.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_CAST
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/cast.h>
67
68static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71typedef struct
72 {
73 CAST_KEY ks;
74 } EVP_CAST_KEY;
75
76#define data(ctx) EVP_C_DATA(EVP_CAST_KEY,ctx)
77
78IMPLEMENT_BLOCK_CIPHER(cast5, ks, CAST, EVP_CAST_KEY,
79 NID_cast5, 8, CAST_KEY_LENGTH, 8, 64,
80 EVP_CIPH_VARIABLE_LENGTH, cast_init_key, NULL,
81 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
82
83static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
84 const unsigned char *iv, int enc)
85 {
86 CAST_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
87 return 1;
88 }
89
90#endif
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c
new file mode 100644
index 0000000000..46e2899825
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_des.c
@@ -0,0 +1,154 @@
1/* crypto/evp/e_des.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66
67static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv, int enc);
69
70/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
71
72static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
73 const unsigned char *in, unsigned int inl)
74{
75 BLOCK_CIPHER_ecb_loop()
76 DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);
77 return 1;
78}
79
80static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
81 const unsigned char *in, unsigned int inl)
82{
83 DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);
84 return 1;
85}
86
87static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
88 const unsigned char *in, unsigned int inl)
89{
90 DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data,
91 (DES_cblock *)ctx->iv, ctx->encrypt);
92 return 1;
93}
94
95static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97{
98 DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
99 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
100 return 1;
101}
102
103/* Although we have a CFB-r implementation for DES, it doesn't pack the right
104 way, so wrap it here */
105static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
106 const unsigned char *in, unsigned int inl)
107 {
108 unsigned int n;
109 unsigned char c[1],d[1];
110
111 for(n=0 ; n < inl ; ++n)
112 {
113 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
114 DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
115 ctx->encrypt);
116 out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
117 }
118 return 1;
119 }
120
121static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
122 const unsigned char *in, unsigned int inl)
123 {
124 DES_cfb_encrypt(in,out,8,inl,ctx->cipher_data,(DES_cblock *)ctx->iv,
125 ctx->encrypt);
126 return 1;
127 }
128
129BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
130 EVP_CIPH_FLAG_FIPS, des_init_key, NULL,
131 EVP_CIPHER_set_asn1_iv,
132 EVP_CIPHER_get_asn1_iv,
133 NULL)
134
135BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,
136 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
137 EVP_CIPHER_set_asn1_iv,
138 EVP_CIPHER_get_asn1_iv,NULL)
139
140BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,
141 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
142 EVP_CIPHER_set_asn1_iv,
143 EVP_CIPHER_get_asn1_iv,NULL)
144
145static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
146 const unsigned char *iv, int enc)
147 {
148 DES_cblock *deskey = (DES_cblock *)key;
149
150 DES_set_key_unchecked(deskey,ctx->cipher_data);
151 return 1;
152 }
153
154#endif
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c
new file mode 100644
index 0000000000..677322bf02
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_des3.c
@@ -0,0 +1,232 @@
1/* crypto/evp/e_des3.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66
67static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69
70static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
71 const unsigned char *iv,int enc);
72
73typedef struct
74 {
75 DES_key_schedule ks1;/* key schedule */
76 DES_key_schedule ks2;/* key schedule (for ede) */
77 DES_key_schedule ks3;/* key schedule (for ede3) */
78 } DES_EDE_KEY;
79
80#define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data)
81
82/* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */
83
84static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
85 const unsigned char *in, unsigned int inl)
86{
87 BLOCK_CIPHER_ecb_loop()
88 DES_ecb3_encrypt(in + i,out + i,
89 &data(ctx)->ks1, &data(ctx)->ks2,
90 &data(ctx)->ks3,
91 ctx->encrypt);
92 return 1;
93}
94
95static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97{
98 DES_ede3_ofb64_encrypt(in, out, (long)inl,
99 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
100 (DES_cblock *)ctx->iv, &ctx->num);
101 return 1;
102}
103
104static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
105 const unsigned char *in, unsigned int inl)
106{
107#ifdef KSSL_DEBUG
108 {
109 int i;
110 char *cp;
111 printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", ctx, ctx->buf_len);
112 printf("\t iv= ");
113 for(i=0;i<8;i++)
114 printf("%02X",ctx->iv[i]);
115 printf("\n");
116 }
117#endif /* KSSL_DEBUG */
118 DES_ede3_cbc_encrypt(in, out, (long)inl,
119 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
120 (DES_cblock *)ctx->iv, ctx->encrypt);
121 return 1;
122}
123
124static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
125 const unsigned char *in, unsigned int inl)
126{
127 DES_ede3_cfb64_encrypt(in, out, (long)inl,
128 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
129 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
130 return 1;
131}
132
133/* Although we have a CFB-r implementation for 3-DES, it doesn't pack the right
134 way, so wrap it here */
135static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
136 const unsigned char *in, unsigned int inl)
137 {
138 unsigned int n;
139 unsigned char c[1],d[1];
140
141 for(n=0 ; n < inl ; ++n)
142 {
143 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
144 DES_ede3_cfb_encrypt(c,d,1,1,
145 &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
146 (DES_cblock *)ctx->iv,ctx->encrypt);
147 out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
148 }
149
150 return 1;
151 }
152
153static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
154 const unsigned char *in, unsigned int inl)
155 {
156 DES_ede3_cfb_encrypt(in,out,8,inl,
157 &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
158 (DES_cblock *)ctx->iv,ctx->encrypt);
159 return 1;
160 }
161
162BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
163 EVP_CIPH_FLAG_FIPS, des_ede_init_key, NULL,
164 EVP_CIPHER_set_asn1_iv,
165 EVP_CIPHER_get_asn1_iv,
166 NULL)
167
168#define des_ede3_cfb64_cipher des_ede_cfb64_cipher
169#define des_ede3_ofb_cipher des_ede_ofb_cipher
170#define des_ede3_cbc_cipher des_ede_cbc_cipher
171#define des_ede3_ecb_cipher des_ede_ecb_cipher
172
173BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
174 EVP_CIPH_FLAG_FIPS, des_ede3_init_key, NULL,
175 EVP_CIPHER_set_asn1_iv,
176 EVP_CIPHER_get_asn1_iv,
177 NULL)
178
179BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1,
180 EVP_CIPH_FLAG_FIPS, des_ede3_init_key,NULL,
181 EVP_CIPHER_set_asn1_iv,
182 EVP_CIPHER_get_asn1_iv,NULL)
183
184BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8,
185 EVP_CIPH_FLAG_FIPS, des_ede3_init_key,NULL,
186 EVP_CIPHER_set_asn1_iv,
187 EVP_CIPHER_get_asn1_iv,NULL)
188
189static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
190 const unsigned char *iv, int enc)
191 {
192 DES_cblock *deskey = (DES_cblock *)key;
193
194 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
195 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
196 memcpy(&data(ctx)->ks3,&data(ctx)->ks1,
197 sizeof(data(ctx)->ks1));
198 return 1;
199 }
200
201static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
202 const unsigned char *iv, int enc)
203 {
204 DES_cblock *deskey = (DES_cblock *)key;
205#ifdef KSSL_DEBUG
206 {
207 int i;
208 printf("des_ede3_init_key(ctx=%lx)\n", ctx);
209 printf("\tKEY= ");
210 for(i=0;i<24;i++) printf("%02X",key[i]); printf("\n");
211 printf("\t IV= ");
212 for(i=0;i<8;i++) printf("%02X",iv[i]); printf("\n");
213 }
214#endif /* KSSL_DEBUG */
215
216 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
217 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
218 DES_set_key_unchecked(&deskey[2],&data(ctx)->ks3);
219
220 return 1;
221 }
222
223const EVP_CIPHER *EVP_des_ede(void)
224{
225 return &des_ede_ecb;
226}
227
228const EVP_CIPHER *EVP_des_ede3(void)
229{
230 return &des_ede3_ecb;
231}
232#endif
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
new file mode 100644
index 0000000000..b9efa75ae7
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_idea.c
@@ -0,0 +1,118 @@
1/* crypto/evp/e_idea.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_IDEA
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/idea.h>
67
68static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71/* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special
72 * case
73 */
74
75static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
76 const unsigned char *in, unsigned int inl)
77{
78 BLOCK_CIPHER_ecb_loop()
79 idea_ecb_encrypt(in + i, out + i, ctx->cipher_data);
80 return 1;
81}
82
83/* Can't use IMPLEMENT_BLOCK_CIPHER because idea_ecb_encrypt is different */
84
85typedef struct
86 {
87 IDEA_KEY_SCHEDULE ks;
88 } EVP_IDEA_KEY;
89
90BLOCK_CIPHER_func_cbc(idea, idea, EVP_IDEA_KEY, ks)
91BLOCK_CIPHER_func_ofb(idea, idea, 64, EVP_IDEA_KEY, ks)
92BLOCK_CIPHER_func_cfb(idea, idea, 64, EVP_IDEA_KEY, ks)
93
94BLOCK_CIPHER_defs(idea, IDEA_KEY_SCHEDULE, NID_idea, 8, 16, 8, 64,
95 0, idea_init_key, NULL,
96 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
97
98static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
99 const unsigned char *iv, int enc)
100 {
101 if(!enc) {
102 if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) enc = 1;
103 else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) enc = 1;
104 }
105 if (enc) idea_set_encrypt_key(key,ctx->cipher_data);
106 else
107 {
108 IDEA_KEY_SCHEDULE tmp;
109
110 idea_set_encrypt_key(key,&tmp);
111 idea_set_decrypt_key(&tmp,ctx->cipher_data);
112 OPENSSL_cleanse((unsigned char *)&tmp,
113 sizeof(IDEA_KEY_SCHEDULE));
114 }
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c
new file mode 100644
index 0000000000..a84b0f14b1
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_null.c
@@ -0,0 +1,101 @@
1/* crypto/evp/e_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63
64static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
65 const unsigned char *iv,int enc);
66static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
67 const unsigned char *in, unsigned int inl);
68static const EVP_CIPHER n_cipher=
69 {
70 NID_undef,
71 1,0,0,
72 EVP_CIPH_FLAG_FIPS,
73 null_init_key,
74 null_cipher,
75 NULL,
76 0,
77 NULL,
78 NULL,
79 NULL
80 };
81
82const EVP_CIPHER *EVP_enc_null(void)
83 {
84 return(&n_cipher);
85 }
86
87static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
88 const unsigned char *iv, int enc)
89 {
90 /* memset(&(ctx->c),0,sizeof(ctx->c));*/
91 return 1;
92 }
93
94static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
95 const unsigned char *in, unsigned int inl)
96 {
97 if (in != out)
98 memcpy((char *)out,(char *)in,(int)inl);
99 return 1;
100 }
101
diff --git a/src/lib/libcrypto/evp/e_old.c b/src/lib/libcrypto/evp/e_old.c
new file mode 100644
index 0000000000..92dc498945
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_old.c
@@ -0,0 +1,108 @@
1/* crypto/evp/e_old.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2004.
4 */
5/* ====================================================================
6 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/evp.h>
60
61/* Define some deprecated functions, so older programs
62 don't crash and burn too quickly. On Windows and VMS,
63 these will never be used, since functions and variables
64 in shared libraries are selected by entry point location,
65 not by name. */
66
67#ifndef OPENSSL_NO_BF
68#undef EVP_bf_cfb
69const EVP_CIPHER *EVP_bf_cfb(void) { return EVP_bf_cfb64(); }
70#endif
71
72#ifndef OPENSSL_NO_DES
73#undef EVP_des_cfb
74const EVP_CIPHER *EVP_des_cfb(void) { return EVP_des_cfb64(); }
75#undef EVP_des_ede3_cfb
76const EVP_CIPHER *EVP_des_ede3_cfb(void) { return EVP_des_ede3_cfb64(); }
77#undef EVP_des_ede_cfb
78const EVP_CIPHER *EVP_des_ede_cfb(void) { return EVP_des_ede_cfb64(); }
79#endif
80
81#ifndef OPENSSL_NO_IDEA
82#undef EVP_idea_cfb
83const EVP_CIPHER *EVP_idea_cfb(void) { return EVP_idea_cfb64(); }
84#endif
85
86#ifndef OPENSSL_NO_RC2
87#undef EVP_rc2_cfb
88const EVP_CIPHER *EVP_rc2_cfb(void) { return EVP_rc2_cfb64(); }
89#endif
90
91#ifndef OPENSSL_NO_CAST
92#undef EVP_cast5_cfb
93const EVP_CIPHER *EVP_cast5_cfb(void) { return EVP_cast5_cfb64(); }
94#endif
95
96#ifndef OPENSSL_NO_RC5
97#undef EVP_rc5_32_12_16_cfb
98const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void) { return EVP_rc5_32_12_16_cfb64(); }
99#endif
100
101#ifndef OPENSSL_NO_AES
102#undef EVP_aes_128_cfb
103const EVP_CIPHER *EVP_aes_128_cfb(void) { return EVP_aes_128_cfb128(); }
104#undef EVP_aes_192_cfb
105const EVP_CIPHER *EVP_aes_192_cfb(void) { return EVP_aes_192_cfb128(); }
106#undef EVP_aes_256_cfb
107const EVP_CIPHER *EVP_aes_256_cfb(void) { return EVP_aes_256_cfb128(); }
108#endif
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
new file mode 100644
index 0000000000..d42cbfd17e
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc2.c
@@ -0,0 +1,230 @@
1/* crypto/evp/e_rc2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RC2
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc2.h>
67
68static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70static int rc2_meth_to_magic(EVP_CIPHER_CTX *ctx);
71static int rc2_magic_to_meth(int i);
72static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
73static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
74static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
75
76typedef struct
77 {
78 int key_bits; /* effective key bits */
79 RC2_KEY ks; /* key schedule */
80 } EVP_RC2_KEY;
81
82#define data(ctx) ((EVP_RC2_KEY *)(ctx)->cipher_data)
83
84IMPLEMENT_BLOCK_CIPHER(rc2, ks, RC2, EVP_RC2_KEY, NID_rc2,
85 8,
86 RC2_KEY_LENGTH, 8, 64,
87 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
88 rc2_init_key, NULL,
89 rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv,
90 rc2_ctrl)
91
92#define RC2_40_MAGIC 0xa0
93#define RC2_64_MAGIC 0x78
94#define RC2_128_MAGIC 0x3a
95
96static const EVP_CIPHER r2_64_cbc_cipher=
97 {
98 NID_rc2_64_cbc,
99 8,8 /* 64 bit */,8,
100 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
101 rc2_init_key,
102 rc2_cbc_cipher,
103 NULL,
104 sizeof(EVP_RC2_KEY),
105 rc2_set_asn1_type_and_iv,
106 rc2_get_asn1_type_and_iv,
107 rc2_ctrl,
108 NULL
109 };
110
111static const EVP_CIPHER r2_40_cbc_cipher=
112 {
113 NID_rc2_40_cbc,
114 8,5 /* 40 bit */,8,
115 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
116 rc2_init_key,
117 rc2_cbc_cipher,
118 NULL,
119 sizeof(EVP_RC2_KEY),
120 rc2_set_asn1_type_and_iv,
121 rc2_get_asn1_type_and_iv,
122 rc2_ctrl,
123 NULL
124 };
125
126const EVP_CIPHER *EVP_rc2_64_cbc(void)
127 {
128 return(&r2_64_cbc_cipher);
129 }
130
131const EVP_CIPHER *EVP_rc2_40_cbc(void)
132 {
133 return(&r2_40_cbc_cipher);
134 }
135
136static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
137 const unsigned char *iv, int enc)
138 {
139 RC2_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
140 key,data(ctx)->key_bits);
141 return 1;
142 }
143
144static int rc2_meth_to_magic(EVP_CIPHER_CTX *e)
145 {
146 int i;
147
148 EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i);
149 if (i == 128) return(RC2_128_MAGIC);
150 else if (i == 64) return(RC2_64_MAGIC);
151 else if (i == 40) return(RC2_40_MAGIC);
152 else return(0);
153 }
154
155static int rc2_magic_to_meth(int i)
156 {
157 if (i == RC2_128_MAGIC) return 128;
158 else if (i == RC2_64_MAGIC) return 64;
159 else if (i == RC2_40_MAGIC) return 40;
160 else
161 {
162 EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
163 return(0);
164 }
165 }
166
167static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
168 {
169 long num=0;
170 int i=0,l;
171 int key_bits;
172 unsigned char iv[EVP_MAX_IV_LENGTH];
173
174 if (type != NULL)
175 {
176 l=EVP_CIPHER_CTX_iv_length(c);
177 OPENSSL_assert(l <= sizeof iv);
178 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l);
179 if (i != l)
180 return(-1);
181 key_bits =rc2_magic_to_meth((int)num);
182 if (!key_bits)
183 return(-1);
184 if(i > 0) EVP_CipherInit_ex(c, NULL, NULL, NULL, iv, -1);
185 EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
186 EVP_CIPHER_CTX_set_key_length(c, key_bits / 8);
187 }
188 return(i);
189 }
190
191static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
192 {
193 long num;
194 int i=0,j;
195
196 if (type != NULL)
197 {
198 num=rc2_meth_to_magic(c);
199 j=EVP_CIPHER_CTX_iv_length(c);
200 i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
201 }
202 return(i);
203 }
204
205static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
206 {
207 switch(type)
208 {
209 case EVP_CTRL_INIT:
210 data(c)->key_bits = EVP_CIPHER_CTX_key_length(c) * 8;
211 return 1;
212
213 case EVP_CTRL_GET_RC2_KEY_BITS:
214 *(int *)ptr = data(c)->key_bits;
215 return 1;
216
217 case EVP_CTRL_SET_RC2_KEY_BITS:
218 if(arg > 0)
219 {
220 data(c)->key_bits = arg;
221 return 1;
222 }
223 return 0;
224
225 default:
226 return -1;
227 }
228 }
229
230#endif
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
new file mode 100644
index 0000000000..8aa70585b9
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc4.c
@@ -0,0 +1,134 @@
1/* crypto/evp/e_rc4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RC4
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc4.h>
67
68/* FIXME: surely this is available elsewhere? */
69#define EVP_RC4_KEY_SIZE 16
70
71typedef struct
72 {
73 RC4_KEY ks; /* working key */
74 } EVP_RC4_KEY;
75
76#define data(ctx) ((EVP_RC4_KEY *)(ctx)->cipher_data)
77
78static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
79 const unsigned char *iv,int enc);
80static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
81 const unsigned char *in, unsigned int inl);
82static const EVP_CIPHER r4_cipher=
83 {
84 NID_rc4,
85 1,EVP_RC4_KEY_SIZE,0,
86 EVP_CIPH_VARIABLE_LENGTH,
87 rc4_init_key,
88 rc4_cipher,
89 NULL,
90 sizeof(EVP_RC4_KEY),
91 NULL,
92 NULL,
93 NULL
94 };
95
96static const EVP_CIPHER r4_40_cipher=
97 {
98 NID_rc4_40,
99 1,5 /* 40 bit */,0,
100 EVP_CIPH_VARIABLE_LENGTH,
101 rc4_init_key,
102 rc4_cipher,
103 NULL,
104 sizeof(EVP_RC4_KEY),
105 NULL,
106 NULL,
107 NULL
108 };
109
110const EVP_CIPHER *EVP_rc4(void)
111 {
112 return(&r4_cipher);
113 }
114
115const EVP_CIPHER *EVP_rc4_40(void)
116 {
117 return(&r4_40_cipher);
118 }
119
120static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
121 const unsigned char *iv, int enc)
122 {
123 RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
124 key);
125 return 1;
126 }
127
128static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
129 const unsigned char *in, unsigned int inl)
130 {
131 RC4(&data(ctx)->ks,inl,in,out);
132 return 1;
133 }
134#endif
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
new file mode 100644
index 0000000000..a6f849e93d
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -0,0 +1,122 @@
1/* crypto/evp/e_xcbc_d.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/des.h>
65
66static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv,int enc);
68static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
69 const unsigned char *in, unsigned int inl);
70
71
72typedef struct
73 {
74 DES_key_schedule ks;/* key schedule */
75 DES_cblock inw;
76 DES_cblock outw;
77 } DESX_CBC_KEY;
78
79#define data(ctx) ((DESX_CBC_KEY *)(ctx)->cipher_data)
80
81static const EVP_CIPHER d_xcbc_cipher=
82 {
83 NID_desx_cbc,
84 8,24,8,
85 EVP_CIPH_CBC_MODE,
86 desx_cbc_init_key,
87 desx_cbc_cipher,
88 NULL,
89 sizeof(DESX_CBC_KEY),
90 EVP_CIPHER_set_asn1_iv,
91 EVP_CIPHER_get_asn1_iv,
92 NULL
93 };
94
95const EVP_CIPHER *EVP_desx_cbc(void)
96 {
97 return(&d_xcbc_cipher);
98 }
99
100static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
101 const unsigned char *iv, int enc)
102 {
103 DES_cblock *deskey = (DES_cblock *)key;
104
105 DES_set_key_unchecked(deskey,&data(ctx)->ks);
106 memcpy(&data(ctx)->inw[0],&key[8],8);
107 memcpy(&data(ctx)->outw[0],&key[16],8);
108
109 return 1;
110 }
111
112static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
113 const unsigned char *in, unsigned int inl)
114 {
115 DES_xcbc_encrypt(in,out,inl,&data(ctx)->ks,
116 (DES_cblock *)&(ctx->iv[0]),
117 &data(ctx)->inw,
118 &data(ctx)->outw,
119 ctx->encrypt);
120 return 1;
121 }
122#endif
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
new file mode 100644
index 0000000000..08209357ce
--- /dev/null
+++ b/src/lib/libcrypto/evp/encode.c
@@ -0,0 +1,446 @@
1/* crypto/evp/encode.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62
63#ifndef CHARSET_EBCDIC
64#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
65#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f])
66#else
67/* We assume that PEM encoded files are EBCDIC files
68 * (i.e., printable text files). Convert them here while decoding.
69 * When encoding, output is EBCDIC (text) format again.
70 * (No need for conversion in the conv_bin2ascii macro, as the
71 * underlying textstring data_bin2ascii[] is already EBCDIC)
72 */
73#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
74#define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f])
75#endif
76
77/* 64 char lines
78 * pad input with 0
79 * left over chars are set to =
80 * 1 byte => xx==
81 * 2 bytes => xxx=
82 * 3 bytes => xxxx
83 */
84#define BIN_PER_LINE (64/4*3)
85#define CHUNKS_PER_LINE (64/4)
86#define CHAR_PER_LINE (64+1)
87
88static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
89abcdefghijklmnopqrstuvwxyz0123456789+/";
90
91/* 0xF0 is a EOLN
92 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
93 * 0xF2 is EOF
94 * 0xE0 is ignore at start of line.
95 * 0xFF is error
96 */
97
98#define B64_EOLN 0xF0
99#define B64_CR 0xF1
100#define B64_EOF 0xF2
101#define B64_WS 0xE0
102#define B64_ERROR 0xFF
103#define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3)
104
105static unsigned char data_ascii2bin[128]={
106 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
107 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
108 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
109 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
110 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
111 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F,
112 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
113 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
114 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
115 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
116 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
117 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
118 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
119 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
120 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
121 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
122 };
123
124void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
125 {
126 ctx->length=48;
127 ctx->num=0;
128 ctx->line_num=0;
129 }
130
131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
132 unsigned char *in, int inl)
133 {
134 int i,j;
135 unsigned int total=0;
136
137 *outl=0;
138 if (inl == 0) return;
139 OPENSSL_assert(ctx->length <= sizeof ctx->enc_data);
140 if ((ctx->num+inl) < ctx->length)
141 {
142 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
143 ctx->num+=inl;
144 return;
145 }
146 if (ctx->num != 0)
147 {
148 i=ctx->length-ctx->num;
149 memcpy(&(ctx->enc_data[ctx->num]),in,i);
150 in+=i;
151 inl-=i;
152 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
153 ctx->num=0;
154 out+=j;
155 *(out++)='\n';
156 *out='\0';
157 total=j+1;
158 }
159 while (inl >= ctx->length)
160 {
161 j=EVP_EncodeBlock(out,in,ctx->length);
162 in+=ctx->length;
163 inl-=ctx->length;
164 out+=j;
165 *(out++)='\n';
166 *out='\0';
167 total+=j+1;
168 }
169 if (inl != 0)
170 memcpy(&(ctx->enc_data[0]),in,inl);
171 ctx->num=inl;
172 *outl=total;
173 }
174
175void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
176 {
177 unsigned int ret=0;
178
179 if (ctx->num != 0)
180 {
181 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
182 out[ret++]='\n';
183 out[ret]='\0';
184 ctx->num=0;
185 }
186 *outl=ret;
187 }
188
189int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
190 {
191 int i,ret=0;
192 unsigned long l;
193
194 for (i=dlen; i > 0; i-=3)
195 {
196 if (i >= 3)
197 {
198 l= (((unsigned long)f[0])<<16L)|
199 (((unsigned long)f[1])<< 8L)|f[2];
200 *(t++)=conv_bin2ascii(l>>18L);
201 *(t++)=conv_bin2ascii(l>>12L);
202 *(t++)=conv_bin2ascii(l>> 6L);
203 *(t++)=conv_bin2ascii(l );
204 }
205 else
206 {
207 l=((unsigned long)f[0])<<16L;
208 if (i == 2) l|=((unsigned long)f[1]<<8L);
209
210 *(t++)=conv_bin2ascii(l>>18L);
211 *(t++)=conv_bin2ascii(l>>12L);
212 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
213 *(t++)='=';
214 }
215 ret+=4;
216 f+=3;
217 }
218
219 *t='\0';
220 return(ret);
221 }
222
223void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
224 {
225 ctx->length=30;
226 ctx->num=0;
227 ctx->line_num=0;
228 ctx->expect_nl=0;
229 }
230
231/* -1 for error
232 * 0 for last line
233 * 1 for full line
234 */
235int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
236 unsigned char *in, int inl)
237 {
238 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
239 unsigned char *d;
240
241 n=ctx->num;
242 d=ctx->enc_data;
243 ln=ctx->line_num;
244 exp_nl=ctx->expect_nl;
245
246 /* last line of input. */
247 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
248 { rv=0; goto end; }
249
250 /* We parse the input data */
251 for (i=0; i<inl; i++)
252 {
253 /* If the current line is > 80 characters, scream alot */
254 if (ln >= 80) { rv= -1; goto end; }
255
256 /* Get char and put it into the buffer */
257 tmp= *(in++);
258 v=conv_ascii2bin(tmp);
259 /* only save the good data :-) */
260 if (!B64_NOT_BASE64(v))
261 {
262 OPENSSL_assert(n < sizeof ctx->enc_data);
263 d[n++]=tmp;
264 ln++;
265 }
266 else if (v == B64_ERROR)
267 {
268 rv= -1;
269 goto end;
270 }
271
272 /* have we seen a '=' which is 'definitly' the last
273 * input line. seof will point to the character that
274 * holds it. and eof will hold how many characters to
275 * chop off. */
276 if (tmp == '=')
277 {
278 if (seof == -1) seof=n;
279 eof++;
280 }
281
282 if (v == B64_CR)
283 {
284 ln = 0;
285 if (exp_nl)
286 continue;
287 }
288
289 /* eoln */
290 if (v == B64_EOLN)
291 {
292 ln=0;
293 if (exp_nl)
294 {
295 exp_nl=0;
296 continue;
297 }
298 }
299 exp_nl=0;
300
301 /* If we are at the end of input and it looks like a
302 * line, process it. */
303 if (((i+1) == inl) && (((n&3) == 0) || eof))
304 {
305 v=B64_EOF;
306 /* In case things were given us in really small
307 records (so two '=' were given in separate
308 updates), eof may contain the incorrect number
309 of ending bytes to skip, so let's redo the count */
310 eof = 0;
311 if (d[n-1] == '=') eof++;
312 if (d[n-2] == '=') eof++;
313 /* There will never be more than two '=' */
314 }
315
316 if ((v == B64_EOF) || (n >= 64))
317 {
318 /* This is needed to work correctly on 64 byte input
319 * lines. We process the line and then need to
320 * accept the '\n' */
321 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
322 tmp2=v;
323 if (n > 0)
324 {
325 v=EVP_DecodeBlock(out,d,n);
326 if (v < 0) { rv=0; goto end; }
327 n=0;
328 ret+=(v-eof);
329 }
330 else
331 {
332 eof=1;
333 v=0;
334 }
335
336 /* This is the case where we have had a short
337 * but valid input line */
338 if ((v < ctx->length) && eof)
339 {
340 rv=0;
341 goto end;
342 }
343 else
344 ctx->length=v;
345
346 if (seof >= 0) { rv=0; goto end; }
347 out+=v;
348 }
349 }
350 rv=1;
351end:
352 *outl=ret;
353 ctx->num=n;
354 ctx->line_num=ln;
355 ctx->expect_nl=exp_nl;
356 return(rv);
357 }
358
359int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
360 {
361 int i,ret=0,a,b,c,d;
362 unsigned long l;
363
364 /* trim white space from the start of the line. */
365 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
366 {
367 f++;
368 n--;
369 }
370
371 /* strip off stuff at the end of the line
372 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
373 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
374 n--;
375
376 if (n%4 != 0) return(-1);
377
378 for (i=0; i<n; i+=4)
379 {
380 a=conv_ascii2bin(*(f++));
381 b=conv_ascii2bin(*(f++));
382 c=conv_ascii2bin(*(f++));
383 d=conv_ascii2bin(*(f++));
384 if ( (a & 0x80) || (b & 0x80) ||
385 (c & 0x80) || (d & 0x80))
386 return(-1);
387 l=( (((unsigned long)a)<<18L)|
388 (((unsigned long)b)<<12L)|
389 (((unsigned long)c)<< 6L)|
390 (((unsigned long)d) ));
391 *(t++)=(unsigned char)(l>>16L)&0xff;
392 *(t++)=(unsigned char)(l>> 8L)&0xff;
393 *(t++)=(unsigned char)(l )&0xff;
394 ret+=3;
395 }
396 return(ret);
397 }
398
399int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
400 {
401 int i;
402
403 *outl=0;
404 if (ctx->num != 0)
405 {
406 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
407 if (i < 0) return(-1);
408 ctx->num=0;
409 *outl=i;
410 return(1);
411 }
412 else
413 return(1);
414 }
415
416#ifdef undef
417int EVP_DecodeValid(unsigned char *buf, int len)
418 {
419 int i,num=0,bad=0;
420
421 if (len == 0) return(-1);
422 while (conv_ascii2bin(*buf) == B64_WS)
423 {
424 buf++;
425 len--;
426 if (len == 0) return(-1);
427 }
428
429 for (i=len; i >= 4; i-=4)
430 {
431 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
432 (conv_ascii2bin(buf[1]) >= 0x40) ||
433 (conv_ascii2bin(buf[2]) >= 0x40) ||
434 (conv_ascii2bin(buf[3]) >= 0x40))
435 return(-1);
436 buf+=4;
437 num+=1+(buf[2] != '=')+(buf[3] != '=');
438 }
439 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
440 return(num);
441 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
442 (conv_ascii2bin(buf[0]) == B64_EOLN))
443 return(num);
444 return(1);
445 }
446#endif
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
new file mode 100644
index 0000000000..09e597f631
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp.h
@@ -0,0 +1,900 @@
1/* crypto/evp/evp.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ENVELOPE_H
60#define HEADER_ENVELOPE_H
61
62#ifdef OPENSSL_ALGORITHM_DEFINES
63# include <openssl/opensslconf.h>
64#else
65# define OPENSSL_ALGORITHM_DEFINES
66# include <openssl/opensslconf.h>
67# undef OPENSSL_ALGORITHM_DEFINES
68#endif
69
70#include <openssl/ossl_typ.h>
71
72#include <openssl/symhacks.h>
73
74#ifndef OPENSSL_NO_BIO
75#include <openssl/bio.h>
76#endif
77
78#ifdef OPENSSL_FIPS
79#include <openssl/fips.h>
80#endif
81
82/*
83#define EVP_RC2_KEY_SIZE 16
84#define EVP_RC4_KEY_SIZE 16
85#define EVP_BLOWFISH_KEY_SIZE 16
86#define EVP_CAST5_KEY_SIZE 16
87#define EVP_RC5_32_12_16_KEY_SIZE 16
88*/
89#define EVP_MAX_MD_SIZE 64 /* to fit SHA512 */
90#define EVP_MAX_KEY_LENGTH 32
91#define EVP_MAX_IV_LENGTH 16
92#define EVP_MAX_BLOCK_LENGTH 32
93
94#define PKCS5_SALT_LEN 8
95/* Default PKCS#5 iteration count */
96#define PKCS5_DEFAULT_ITER 2048
97
98#include <openssl/objects.h>
99
100#define EVP_PK_RSA 0x0001
101#define EVP_PK_DSA 0x0002
102#define EVP_PK_DH 0x0004
103#define EVP_PKT_SIGN 0x0010
104#define EVP_PKT_ENC 0x0020
105#define EVP_PKT_EXCH 0x0040
106#define EVP_PKS_RSA 0x0100
107#define EVP_PKS_DSA 0x0200
108#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
109
110#define EVP_PKEY_NONE NID_undef
111#define EVP_PKEY_RSA NID_rsaEncryption
112#define EVP_PKEY_RSA2 NID_rsa
113#define EVP_PKEY_DSA NID_dsa
114#define EVP_PKEY_DSA1 NID_dsa_2
115#define EVP_PKEY_DSA2 NID_dsaWithSHA
116#define EVP_PKEY_DSA3 NID_dsaWithSHA1
117#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
118#define EVP_PKEY_DH NID_dhKeyAgreement
119
120#ifdef __cplusplus
121extern "C" {
122#endif
123
124/* Type needs to be a bit field
125 * Sub-type needs to be for variations on the method, as in, can it do
126 * arbitrary encryption.... */
127struct evp_pkey_st
128 {
129 int type;
130 int save_type;
131 int references;
132 union {
133 char *ptr;
134#ifndef OPENSSL_NO_RSA
135 struct rsa_st *rsa; /* RSA */
136#endif
137#ifndef OPENSSL_NO_DSA
138 struct dsa_st *dsa; /* DSA */
139#endif
140#ifndef OPENSSL_NO_DH
141 struct dh_st *dh; /* DH */
142#endif
143 } pkey;
144 int save_parameters;
145 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
146 } /* EVP_PKEY */;
147
148#define EVP_PKEY_MO_SIGN 0x0001
149#define EVP_PKEY_MO_VERIFY 0x0002
150#define EVP_PKEY_MO_ENCRYPT 0x0004
151#define EVP_PKEY_MO_DECRYPT 0x0008
152
153#if 0
154/* This structure is required to tie the message digest and signing together.
155 * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or
156 * oid, md and pkey.
157 * This is required because for various smart-card perform the digest and
158 * signing/verification on-board. To handle this case, the specific
159 * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
160 * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
161 * This can either be software or a token to provide the required low level
162 * routines.
163 */
164typedef struct evp_pkey_md_st
165 {
166 int oid;
167 EVP_MD *md;
168 EVP_PKEY_METHOD *pkey;
169 } EVP_PKEY_MD;
170
171#define EVP_rsa_md2() \
172 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
173 EVP_rsa_pkcs1(),EVP_md2())
174#define EVP_rsa_md5() \
175 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
176 EVP_rsa_pkcs1(),EVP_md5())
177#define EVP_rsa_sha0() \
178 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
179 EVP_rsa_pkcs1(),EVP_sha())
180#define EVP_rsa_sha1() \
181 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
182 EVP_rsa_pkcs1(),EVP_sha1())
183#define EVP_rsa_ripemd160() \
184 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
185 EVP_rsa_pkcs1(),EVP_ripemd160())
186#define EVP_rsa_mdc2() \
187 EVP_PKEY_MD_add(NID_mdc2WithRSA,\
188 EVP_rsa_octet_string(),EVP_mdc2())
189#define EVP_dsa_sha() \
190 EVP_PKEY_MD_add(NID_dsaWithSHA,\
191 EVP_dsa(),EVP_sha())
192#define EVP_dsa_sha1() \
193 EVP_PKEY_MD_add(NID_dsaWithSHA1,\
194 EVP_dsa(),EVP_sha1())
195
196typedef struct evp_pkey_method_st
197 {
198 char *name;
199 int flags;
200 int type; /* RSA, DSA, an SSLeay specific constant */
201 int oid; /* For the pub-key type */
202 int encrypt_oid; /* pub/priv key encryption */
203
204 int (*sign)();
205 int (*verify)();
206 struct {
207 int (*set)(); /* get and/or set the underlying type */
208 int (*get)();
209 int (*encrypt)();
210 int (*decrypt)();
211 int (*i2d)();
212 int (*d2i)();
213 int (*dup)();
214 } pub,priv;
215 int (*set_asn1_parameters)();
216 int (*get_asn1_parameters)();
217 } EVP_PKEY_METHOD;
218#endif
219
220#ifndef EVP_MD
221struct env_md_st
222 {
223 int type;
224 int pkey_type;
225 int md_size;
226 unsigned long flags;
227 int (*init)(EVP_MD_CTX *ctx);
228 int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
229 int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
230 int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
231 int (*cleanup)(EVP_MD_CTX *ctx);
232
233 /* FIXME: prototype these some day */
234 int (*sign)();
235 int (*verify)();
236 int required_pkey_type[5]; /*EVP_PKEY_xxx */
237 int block_size;
238 int ctx_size; /* how big does the ctx->md_data need to be */
239 } /* EVP_MD */;
240
241#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single
242 * block */
243#define EVP_MD_FLAG_FIPS 0x0400 /* Note if suitable for use in FIPS mode */
244
245#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
246
247#ifndef OPENSSL_NO_DSA
248#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
249 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
250 EVP_PKEY_DSA4,0}
251#else
252#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
253#endif
254
255#ifndef OPENSSL_NO_RSA
256#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
257 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
258#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
259 RSA_sign_ASN1_OCTET_STRING, \
260 RSA_verify_ASN1_OCTET_STRING, \
261 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
262#else
263#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
264#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
265#endif
266
267#endif /* !EVP_MD */
268
269struct env_md_ctx_st
270 {
271 const EVP_MD *digest;
272 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
273 unsigned long flags;
274 void *md_data;
275 } /* EVP_MD_CTX */;
276
277/* values for EVP_MD_CTX flags */
278
279#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called
280 * once only */
281#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been
282 * cleaned */
283#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data
284 * in EVP_MD_CTX_cleanup */
285
286#define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* Allow use of non FIPS digest
287 * in FIPS mode */
288
289struct evp_cipher_st
290 {
291 int nid;
292 int block_size;
293 int key_len; /* Default value for variable length ciphers */
294 int iv_len;
295 unsigned long flags; /* Various flags */
296 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
297 const unsigned char *iv, int enc); /* init key */
298 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
299 const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
300 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
301 int ctx_size; /* how big ctx->cipher_data needs to be */
302 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
303 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
304 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
305 void *app_data; /* Application data */
306 } /* EVP_CIPHER */;
307
308/* Values for cipher flags */
309
310/* Modes for ciphers */
311
312#define EVP_CIPH_STREAM_CIPHER 0x0
313#define EVP_CIPH_ECB_MODE 0x1
314#define EVP_CIPH_CBC_MODE 0x2
315#define EVP_CIPH_CFB_MODE 0x3
316#define EVP_CIPH_OFB_MODE 0x4
317#define EVP_CIPH_MODE 0x7
318/* Set if variable length cipher */
319#define EVP_CIPH_VARIABLE_LENGTH 0x8
320/* Set if the iv handling should be done by the cipher itself */
321#define EVP_CIPH_CUSTOM_IV 0x10
322/* Set if the cipher's init() function should be called if key is NULL */
323#define EVP_CIPH_ALWAYS_CALL_INIT 0x20
324/* Call ctrl() to init cipher parameters */
325#define EVP_CIPH_CTRL_INIT 0x40
326/* Don't use standard key length function */
327#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
328/* Don't use standard block padding */
329#define EVP_CIPH_NO_PADDING 0x100
330/* Note if suitable for use in FIPS mode */
331#define EVP_CIPH_FLAG_FIPS 0x400
332/* Allow non FIPS cipher in FIPS mode */
333#define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x800
334
335/* ctrl() values */
336
337#define EVP_CTRL_INIT 0x0
338#define EVP_CTRL_SET_KEY_LENGTH 0x1
339#define EVP_CTRL_GET_RC2_KEY_BITS 0x2
340#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
341#define EVP_CTRL_GET_RC5_ROUNDS 0x4
342#define EVP_CTRL_SET_RC5_ROUNDS 0x5
343#define EVP_CTRL_SET_ACSS_MODE 0x6
344
345typedef struct evp_cipher_info_st
346 {
347 const EVP_CIPHER *cipher;
348 unsigned char iv[EVP_MAX_IV_LENGTH];
349 } EVP_CIPHER_INFO;
350
351struct evp_cipher_ctx_st
352 {
353 const EVP_CIPHER *cipher;
354 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
355 int encrypt; /* encrypt or decrypt */
356 int buf_len; /* number we have left */
357
358 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
359 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
360 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
361 int num; /* used by cfb/ofb mode */
362
363 void *app_data; /* application stuff */
364 int key_len; /* May change for variable length cipher */
365 unsigned long flags; /* Various flags */
366 void *cipher_data; /* per EVP data */
367 int final_used;
368 int block_mask;
369 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
370 } /* EVP_CIPHER_CTX */;
371
372typedef struct evp_Encode_Ctx_st
373 {
374 int num; /* number saved in a partial encode/decode */
375 int length; /* The length is either the output line length
376 * (in input bytes) or the shortest input line
377 * length that is ok. Once decoding begins,
378 * the length is adjusted up each time a longer
379 * line is decoded */
380 unsigned char enc_data[80]; /* data to encode */
381 int line_num; /* number read on current line */
382 int expect_nl;
383 } EVP_ENCODE_CTX;
384
385/* Password based encryption function */
386typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
387 ASN1_TYPE *param, const EVP_CIPHER *cipher,
388 const EVP_MD *md, int en_de);
389
390#ifndef OPENSSL_NO_RSA
391#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
392 (char *)(rsa))
393#endif
394
395#ifndef OPENSSL_NO_DSA
396#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
397 (char *)(dsa))
398#endif
399
400#ifndef OPENSSL_NO_DH
401#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
402 (char *)(dh))
403#endif
404
405/* Add some extra combinations */
406#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
407#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
408#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
409#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
410
411#define EVP_MD_type(e) ((e)->type)
412#define EVP_MD_nid(e) EVP_MD_type(e)
413#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e))
414#define EVP_MD_pkey_type(e) ((e)->pkey_type)
415#define EVP_MD_size(e) ((e)->md_size)
416#define EVP_MD_block_size(e) ((e)->block_size)
417
418#define EVP_MD_CTX_md(e) ((e)->digest)
419#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
420#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
421#define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
422
423#define EVP_CIPHER_nid(e) ((e)->nid)
424#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e))
425#define EVP_CIPHER_block_size(e) ((e)->block_size)
426#define EVP_CIPHER_key_length(e) ((e)->key_len)
427#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
428#define EVP_CIPHER_flags(e) ((e)->flags)
429#define EVP_CIPHER_mode(e) (((e)->flags) & EVP_CIPH_MODE)
430
431#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
432#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
433#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
434#define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
435#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
436#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
437#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
438#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
439#define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
440#define EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
441#define EVP_CIPHER_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
442#define EVP_CIPHER_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
443#define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
444
445#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
446#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
447
448#define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
449#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
450#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
451#define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
452#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
453#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
454#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
455#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
456
457#ifdef CONST_STRICT
458void BIO_set_md(BIO *,const EVP_MD *md);
459#else
460# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
461#endif
462#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
463#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
464#define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp)
465#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
466#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
467
468#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
469
470#define EVP_add_cipher_alias(n,alias) \
471 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
472#define EVP_add_digest_alias(n,alias) \
473 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
474#define EVP_delete_cipher_alias(alias) \
475 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
476#define EVP_delete_digest_alias(alias) \
477 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
478
479void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
480int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
481EVP_MD_CTX *EVP_MD_CTX_create(void);
482void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
483int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
484#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
485#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
486#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
487int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
488int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
489 unsigned int cnt);
490int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
491int EVP_Digest(void *data, unsigned int count,
492 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);
493
494int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);
495int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
496int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
497
498int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
499void EVP_set_pw_prompt(char *prompt);
500char * EVP_get_pw_prompt(void);
501
502int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
503 const unsigned char *salt, const unsigned char *data,
504 int datal, int count, unsigned char *key,unsigned char *iv);
505
506int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
507 const unsigned char *key, const unsigned char *iv);
508int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
509 const unsigned char *key, const unsigned char *iv);
510int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
511 int *outl, const unsigned char *in, int inl);
512int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
513int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
514
515int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
516 const unsigned char *key, const unsigned char *iv);
517int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
518 const unsigned char *key, const unsigned char *iv);
519int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
520 int *outl, const unsigned char *in, int inl);
521int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
522int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
523
524int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
525 const unsigned char *key,const unsigned char *iv,
526 int enc);
527int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
528 const unsigned char *key,const unsigned char *iv,
529 int enc);
530int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
531 int *outl, const unsigned char *in, int inl);
532int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
533int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
534
535int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
536 EVP_PKEY *pkey);
537
538int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
539 unsigned int siglen,EVP_PKEY *pkey);
540
541int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,unsigned char *ek,
542 int ekl,unsigned char *iv,EVP_PKEY *priv);
543int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
544
545int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
546 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
547int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
548
549void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
550void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
551 int *outl,unsigned char *in,int inl);
552void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
553int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
554
555void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
556int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
557 unsigned char *in, int inl);
558int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
559 char *out, int *outl);
560int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
561
562void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
563int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
564int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
565int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
566int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
567
568#ifndef OPENSSL_NO_BIO
569BIO_METHOD *BIO_f_md(void);
570BIO_METHOD *BIO_f_base64(void);
571BIO_METHOD *BIO_f_cipher(void);
572BIO_METHOD *BIO_f_reliable(void);
573void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
574 unsigned char *i, int enc);
575#endif
576
577const EVP_MD *EVP_md_null(void);
578#ifndef OPENSSL_NO_MD2
579const EVP_MD *EVP_md2(void);
580#endif
581#ifndef OPENSSL_NO_MD4
582const EVP_MD *EVP_md4(void);
583#endif
584#ifndef OPENSSL_NO_MD5
585const EVP_MD *EVP_md5(void);
586#endif
587#ifndef OPENSSL_NO_SHA
588const EVP_MD *EVP_sha(void);
589const EVP_MD *EVP_sha1(void);
590const EVP_MD *EVP_dss(void);
591const EVP_MD *EVP_dss1(void);
592#endif
593#ifndef OPENSSL_NO_MDC2
594const EVP_MD *EVP_mdc2(void);
595#endif
596#ifndef OPENSSL_NO_RIPEMD
597const EVP_MD *EVP_ripemd160(void);
598#endif
599const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
600#ifndef OPENSSL_NO_DES
601const EVP_CIPHER *EVP_des_ecb(void);
602const EVP_CIPHER *EVP_des_ede(void);
603const EVP_CIPHER *EVP_des_ede3(void);
604const EVP_CIPHER *EVP_des_ede_ecb(void);
605const EVP_CIPHER *EVP_des_ede3_ecb(void);
606const EVP_CIPHER *EVP_des_cfb64(void);
607# define EVP_des_cfb EVP_des_cfb64
608const EVP_CIPHER *EVP_des_cfb1(void);
609const EVP_CIPHER *EVP_des_cfb8(void);
610const EVP_CIPHER *EVP_des_ede_cfb64(void);
611# define EVP_des_ede_cfb EVP_des_ede_cfb64
612#if 0
613const EVP_CIPHER *EVP_des_ede_cfb1(void);
614const EVP_CIPHER *EVP_des_ede_cfb8(void);
615#endif
616const EVP_CIPHER *EVP_des_ede3_cfb64(void);
617# define EVP_des_ede3_cfb EVP_des_ede3_cfb64
618const EVP_CIPHER *EVP_des_ede3_cfb1(void);
619const EVP_CIPHER *EVP_des_ede3_cfb8(void);
620const EVP_CIPHER *EVP_des_ofb(void);
621const EVP_CIPHER *EVP_des_ede_ofb(void);
622const EVP_CIPHER *EVP_des_ede3_ofb(void);
623const EVP_CIPHER *EVP_des_cbc(void);
624const EVP_CIPHER *EVP_des_ede_cbc(void);
625const EVP_CIPHER *EVP_des_ede3_cbc(void);
626const EVP_CIPHER *EVP_desx_cbc(void);
627/* This should now be supported through the dev_crypto ENGINE. But also, why are
628 * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */
629#if 0
630# ifdef OPENSSL_OPENBSD_DEV_CRYPTO
631const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);
632const EVP_CIPHER *EVP_dev_crypto_rc4(void);
633const EVP_MD *EVP_dev_crypto_md5(void);
634# endif
635#endif
636#endif
637#ifndef OPENSSL_NO_RC4
638const EVP_CIPHER *EVP_rc4(void);
639const EVP_CIPHER *EVP_rc4_40(void);
640#endif
641#ifndef OPENSSL_NO_IDEA
642const EVP_CIPHER *EVP_idea_ecb(void);
643const EVP_CIPHER *EVP_idea_cfb64(void);
644# define EVP_idea_cfb EVP_idea_cfb64
645const EVP_CIPHER *EVP_idea_ofb(void);
646const EVP_CIPHER *EVP_idea_cbc(void);
647#endif
648#ifndef OPENSSL_NO_RC2
649const EVP_CIPHER *EVP_rc2_ecb(void);
650const EVP_CIPHER *EVP_rc2_cbc(void);
651const EVP_CIPHER *EVP_rc2_40_cbc(void);
652const EVP_CIPHER *EVP_rc2_64_cbc(void);
653const EVP_CIPHER *EVP_rc2_cfb64(void);
654# define EVP_rc2_cfb EVP_rc2_cfb64
655const EVP_CIPHER *EVP_rc2_ofb(void);
656#endif
657#ifndef OPENSSL_NO_BF
658const EVP_CIPHER *EVP_bf_ecb(void);
659const EVP_CIPHER *EVP_bf_cbc(void);
660const EVP_CIPHER *EVP_bf_cfb64(void);
661# define EVP_bf_cfb EVP_bf_cfb64
662const EVP_CIPHER *EVP_bf_ofb(void);
663#endif
664#ifndef OPENSSL_NO_CAST
665const EVP_CIPHER *EVP_cast5_ecb(void);
666const EVP_CIPHER *EVP_cast5_cbc(void);
667const EVP_CIPHER *EVP_cast5_cfb64(void);
668# define EVP_cast5_cfb EVP_cast5_cfb64
669const EVP_CIPHER *EVP_cast5_ofb(void);
670#endif
671#ifndef OPENSSL_NO_RC5
672const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
673const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
674const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void);
675# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64
676const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
677#endif
678#ifndef OPENSSL_NO_AES
679const EVP_CIPHER *EVP_aes_128_ecb(void);
680const EVP_CIPHER *EVP_aes_128_cbc(void);
681const EVP_CIPHER *EVP_aes_128_cfb1(void);
682const EVP_CIPHER *EVP_aes_128_cfb8(void);
683const EVP_CIPHER *EVP_aes_128_cfb128(void);
684# define EVP_aes_128_cfb EVP_aes_128_cfb128
685const EVP_CIPHER *EVP_aes_128_ofb(void);
686#if 0
687const EVP_CIPHER *EVP_aes_128_ctr(void);
688#endif
689const EVP_CIPHER *EVP_aes_192_ecb(void);
690const EVP_CIPHER *EVP_aes_192_cbc(void);
691const EVP_CIPHER *EVP_aes_192_cfb1(void);
692const EVP_CIPHER *EVP_aes_192_cfb8(void);
693const EVP_CIPHER *EVP_aes_192_cfb128(void);
694# define EVP_aes_192_cfb EVP_aes_192_cfb128
695const EVP_CIPHER *EVP_aes_192_ofb(void);
696#if 0
697const EVP_CIPHER *EVP_aes_192_ctr(void);
698#endif
699const EVP_CIPHER *EVP_aes_256_ecb(void);
700const EVP_CIPHER *EVP_aes_256_cbc(void);
701const EVP_CIPHER *EVP_aes_256_cfb1(void);
702const EVP_CIPHER *EVP_aes_256_cfb8(void);
703const EVP_CIPHER *EVP_aes_256_cfb128(void);
704# define EVP_aes_256_cfb EVP_aes_256_cfb128
705const EVP_CIPHER *EVP_aes_256_ofb(void);
706#if 0
707const EVP_CIPHER *EVP_aes_256_ctr(void);
708#endif
709#endif
710#ifndef OPENSSL_NO_ACSS
711const EVP_CIPHER *EVP_acss(void);
712#endif
713
714void OPENSSL_add_all_algorithms_noconf(void);
715void OPENSSL_add_all_algorithms_conf(void);
716
717#ifdef OPENSSL_LOAD_CONF
718#define OpenSSL_add_all_algorithms() \
719 OPENSSL_add_all_algorithms_conf()
720#else
721#define OpenSSL_add_all_algorithms() \
722 OPENSSL_add_all_algorithms_noconf()
723#endif
724
725void OpenSSL_add_all_ciphers(void);
726void OpenSSL_add_all_digests(void);
727#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()
728#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()
729#define SSLeay_add_all_digests() OpenSSL_add_all_digests()
730
731int EVP_add_cipher(const EVP_CIPHER *cipher);
732int EVP_add_digest(const EVP_MD *digest);
733
734const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
735const EVP_MD *EVP_get_digestbyname(const char *name);
736void EVP_cleanup(void);
737
738int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
739 int enc_key_len,EVP_PKEY *private_key);
740int EVP_PKEY_encrypt(unsigned char *enc_key,
741 unsigned char *key,int key_len,EVP_PKEY *pub_key);
742int EVP_PKEY_type(int type);
743int EVP_PKEY_bits(EVP_PKEY *pkey);
744int EVP_PKEY_size(EVP_PKEY *pkey);
745int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
746
747#ifndef OPENSSL_NO_RSA
748struct rsa_st;
749int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key);
750struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
751#endif
752#ifndef OPENSSL_NO_DSA
753struct dsa_st;
754int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key);
755struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
756#endif
757#ifndef OPENSSL_NO_DH
758struct dh_st;
759int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);
760struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
761#endif
762
763
764EVP_PKEY * EVP_PKEY_new(void);
765void EVP_PKEY_free(EVP_PKEY *pkey);
766EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
767 long length);
768int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
769
770EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
771 long length);
772EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
773 long length);
774int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
775
776int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
777int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
778int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
779int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
780
781int EVP_CIPHER_type(const EVP_CIPHER *ctx);
782
783/* calls methods */
784int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
785int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
786
787/* These are used by EVP_CIPHER methods */
788int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
789int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
790
791/* PKCS5 password based encryption */
792int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
793 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
794 int en_de);
795int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
796 unsigned char *salt, int saltlen, int iter,
797 int keylen, unsigned char *out);
798int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
799 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
800 int en_de);
801
802void PKCS5_PBE_add(void);
803
804int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
805 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
806int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
807 EVP_PBE_KEYGEN *keygen);
808void EVP_PBE_cleanup(void);
809
810/* BEGIN ERROR CODES */
811/* The following lines are auto generated by the script mkerr.pl. Any changes
812 * made after this point may be overwritten when the script is next run.
813 */
814void ERR_load_EVP_strings(void);
815
816/* Error codes for the EVP functions. */
817
818/* Function codes. */
819#define EVP_F_AES_INIT_KEY 129
820#define EVP_F_D2I_PKEY 100
821#define EVP_F_EVP_ADD_CIPHER 130
822#define EVP_F_EVP_ADD_DIGEST 131
823#define EVP_F_EVP_CIPHERINIT 123
824#define EVP_F_EVP_CIPHER_CTX_CTRL 124
825#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
826#define EVP_F_EVP_DECRYPTFINAL 101
827#define EVP_F_EVP_DIGESTINIT 128
828#define EVP_F_EVP_ENCRYPTFINAL 127
829#define EVP_F_EVP_GET_CIPHERBYNAME 132
830#define EVP_F_EVP_GET_DIGESTBYNAME 133
831#define EVP_F_EVP_MD_CTX_COPY 110
832#define EVP_F_EVP_OPENINIT 102
833#define EVP_F_EVP_PBE_ALG_ADD 115
834#define EVP_F_EVP_PBE_CIPHERINIT 116
835#define EVP_F_EVP_PKCS82PKEY 111
836#define EVP_F_EVP_PKCS8_SET_BROKEN 112
837#define EVP_F_EVP_PKEY2PKCS8 113
838#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
839#define EVP_F_EVP_PKEY_DECRYPT 104
840#define EVP_F_EVP_PKEY_ENCRYPT 105
841#define EVP_F_EVP_PKEY_GET1_DH 119
842#define EVP_F_EVP_PKEY_GET1_DSA 120
843#define EVP_F_EVP_PKEY_GET1_RSA 121
844#define EVP_F_EVP_PKEY_NEW 106
845#define EVP_F_EVP_RIJNDAEL 126
846#define EVP_F_EVP_SIGNFINAL 107
847#define EVP_F_EVP_VERIFYFINAL 108
848#define EVP_F_PKCS5_PBE_KEYIVGEN 117
849#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
850#define EVP_F_RC2_MAGIC_TO_METH 109
851#define EVP_F_RC5_CTRL 125
852
853/* Reason codes. */
854#define EVP_R_AES_KEY_SETUP_FAILED 140
855#define EVP_R_BAD_BLOCK_LENGTH 136
856#define EVP_R_BAD_DECRYPT 100
857#define EVP_R_BAD_KEY_LENGTH 137
858#define EVP_R_BN_DECODE_ERROR 112
859#define EVP_R_BN_PUBKEY_ERROR 113
860#define EVP_R_CIPHER_PARAMETER_ERROR 122
861#define EVP_R_CTRL_NOT_IMPLEMENTED 132
862#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133
863#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138
864#define EVP_R_DECODE_ERROR 114
865#define EVP_R_DIFFERENT_KEY_TYPES 101
866#define EVP_R_DISABLED_FOR_FIPS 141
867#define EVP_R_ENCODE_ERROR 115
868#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
869#define EVP_R_EXPECTING_AN_RSA_KEY 127
870#define EVP_R_EXPECTING_A_DH_KEY 128
871#define EVP_R_EXPECTING_A_DSA_KEY 129
872#define EVP_R_INITIALIZATION_ERROR 134
873#define EVP_R_INPUT_NOT_INITIALIZED 111
874#define EVP_R_INVALID_KEY_LENGTH 130
875#define EVP_R_IV_TOO_LARGE 102
876#define EVP_R_KEYGEN_FAILURE 120
877#define EVP_R_MISSING_PARAMETERS 103
878#define EVP_R_NO_CIPHER_SET 131
879#define EVP_R_NO_DIGEST_SET 139
880#define EVP_R_NO_DSA_PARAMETERS 116
881#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
882#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
883#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
884#define EVP_R_PUBLIC_KEY_NOT_RSA 106
885#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
886#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135
887#define EVP_R_UNSUPPORTED_CIPHER 107
888#define EVP_R_UNSUPPORTED_KEYLENGTH 123
889#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
890#define EVP_R_UNSUPPORTED_KEY_SIZE 108
891#define EVP_R_UNSUPPORTED_PRF 125
892#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
893#define EVP_R_UNSUPPORTED_SALT_TYPE 126
894#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
895#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
896
897#ifdef __cplusplus
898}
899#endif
900#endif
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
new file mode 100644
index 0000000000..f549eeb437
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -0,0 +1,592 @@
1/* crypto/evp/evp_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/err.h>
63#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h>
65#endif
66#include "evp_locl.h"
67
68const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
69
70void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
71 {
72 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
73 /* ctx->cipher=NULL; */
74 }
75
76
77int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
78 const unsigned char *key, const unsigned char *iv, int enc)
79 {
80 if (cipher)
81 EVP_CIPHER_CTX_init(ctx);
82 return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
83 }
84
85#ifdef OPENSSL_FIPS
86
87/* The purpose of these is to trap programs that attempt to use non FIPS
88 * algorithms in FIPS mode and ignore the errors.
89 */
90
91int bad_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
92 const unsigned char *iv, int enc)
93 { FIPS_ERROR_IGNORED("Cipher init"); return 0;}
94
95int bad_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97 { FIPS_ERROR_IGNORED("Cipher update"); return 0;}
98
99/* NB: no cleanup because it is allowed after failed init */
100
101int bad_set_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
102 { FIPS_ERROR_IGNORED("Cipher set_asn1"); return 0;}
103int bad_get_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
104 { FIPS_ERROR_IGNORED("Cipher get_asn1"); return 0;}
105int bad_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
106 { FIPS_ERROR_IGNORED("Cipher ctrl"); return 0;}
107
108static const EVP_CIPHER bad_cipher =
109 {
110 0,
111 0,
112 0,
113 0,
114 0,
115 bad_init,
116 bad_do_cipher,
117 NULL,
118 0,
119 bad_set_asn1,
120 bad_get_asn1,
121 bad_ctrl,
122 NULL
123 };
124
125#endif
126
127int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
128 const unsigned char *key, const unsigned char *iv, int enc)
129 {
130 if (enc == -1)
131 enc = ctx->encrypt;
132 else
133 {
134 if (enc)
135 enc = 1;
136 ctx->encrypt = enc;
137 }
138#ifndef OPENSSL_NO_ENGINE
139 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
140 * so this context may already have an ENGINE! Try to avoid releasing
141 * the previous handle, re-querying for an ENGINE, and having a
142 * reinitialisation, when it may all be unecessary. */
143 if (ctx->engine && ctx->cipher && (!cipher ||
144 (cipher && (cipher->nid == ctx->cipher->nid))))
145 goto skip_to_init;
146#endif
147 if (cipher)
148 {
149 /* Ensure a context left lying around from last time is cleared
150 * (the previous check attempted to avoid this if the same
151 * ENGINE and EVP_CIPHER could be used). */
152 EVP_CIPHER_CTX_cleanup(ctx);
153
154 /* Restore encrypt field: it is zeroed by cleanup */
155 ctx->encrypt = enc;
156#ifndef OPENSSL_NO_ENGINE
157 if(impl)
158 {
159 if (!ENGINE_init(impl))
160 {
161 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
162 return 0;
163 }
164 }
165 else
166 /* Ask if an ENGINE is reserved for this job */
167 impl = ENGINE_get_cipher_engine(cipher->nid);
168 if(impl)
169 {
170 /* There's an ENGINE for this job ... (apparently) */
171 const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid);
172 if(!c)
173 {
174 /* One positive side-effect of US's export
175 * control history, is that we should at least
176 * be able to avoid using US mispellings of
177 * "initialisation"? */
178 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
179 return 0;
180 }
181 /* We'll use the ENGINE's private cipher definition */
182 cipher = c;
183 /* Store the ENGINE functional reference so we know
184 * 'cipher' came from an ENGINE and we need to release
185 * it when done. */
186 ctx->engine = impl;
187 }
188 else
189 ctx->engine = NULL;
190#endif
191 ctx->cipher=cipher;
192 if (ctx->cipher->ctx_size)
193 {
194 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
195 if (!ctx->cipher_data)
196 {
197 EVPerr(EVP_F_EVP_CIPHERINIT, ERR_R_MALLOC_FAILURE);
198 return 0;
199 }
200 }
201 else
202 {
203 ctx->cipher_data = NULL;
204 }
205 ctx->key_len = cipher->key_len;
206 ctx->flags = 0;
207 if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
208 {
209 if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
210 {
211 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
212 return 0;
213 }
214 }
215 }
216 else if(!ctx->cipher)
217 {
218 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET);
219 return 0;
220 }
221#ifndef OPENSSL_NO_ENGINE
222skip_to_init:
223#endif
224 /* we assume block size is a power of 2 in *cryptUpdate */
225 OPENSSL_assert(ctx->cipher->block_size == 1
226 || ctx->cipher->block_size == 8
227 || ctx->cipher->block_size == 16);
228
229 if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
230 switch(EVP_CIPHER_CTX_mode(ctx)) {
231
232 case EVP_CIPH_STREAM_CIPHER:
233 case EVP_CIPH_ECB_MODE:
234 break;
235
236 case EVP_CIPH_CFB_MODE:
237 case EVP_CIPH_OFB_MODE:
238
239 ctx->num = 0;
240
241 case EVP_CIPH_CBC_MODE:
242
243 OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof ctx->iv);
244 if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
245 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
246 break;
247
248 default:
249 return 0;
250 break;
251 }
252 }
253
254#ifdef OPENSSL_FIPS
255 /* After 'key' is set no further parameters changes are permissible.
256 * So only check for non FIPS enabling at this point.
257 */
258 if (key && FIPS_mode())
259 {
260 if (!(ctx->cipher->flags & EVP_CIPH_FLAG_FIPS)
261 & !(ctx->flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW))
262 {
263 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_DISABLED_FOR_FIPS);
264 ERR_add_error_data(2, "cipher=",
265 EVP_CIPHER_name(ctx->cipher));
266 ctx->cipher = &bad_cipher;
267 return 0;
268 }
269 }
270#endif
271
272 if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
273 if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
274 }
275 ctx->buf_len=0;
276 ctx->final_used=0;
277 ctx->block_mask=ctx->cipher->block_size-1;
278 return 1;
279 }
280
281int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
282 const unsigned char *in, int inl)
283 {
284 if (ctx->encrypt)
285 return EVP_EncryptUpdate(ctx,out,outl,in,inl);
286 else return EVP_DecryptUpdate(ctx,out,outl,in,inl);
287 }
288
289int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
290 {
291 if (ctx->encrypt)
292 return EVP_EncryptFinal_ex(ctx,out,outl);
293 else return EVP_DecryptFinal_ex(ctx,out,outl);
294 }
295
296int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
297 {
298 if (ctx->encrypt)
299 return EVP_EncryptFinal(ctx,out,outl);
300 else return EVP_DecryptFinal(ctx,out,outl);
301 }
302
303int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
304 const unsigned char *key, const unsigned char *iv)
305 {
306 return EVP_CipherInit(ctx, cipher, key, iv, 1);
307 }
308
309int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
310 const unsigned char *key, const unsigned char *iv)
311 {
312 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
313 }
314
315int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
316 const unsigned char *key, const unsigned char *iv)
317 {
318 return EVP_CipherInit(ctx, cipher, key, iv, 0);
319 }
320
321int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
322 const unsigned char *key, const unsigned char *iv)
323 {
324 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
325 }
326
327int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
328 const unsigned char *in, int inl)
329 {
330 int i,j,bl;
331
332 OPENSSL_assert(inl > 0);
333 if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
334 {
335 if(ctx->cipher->do_cipher(ctx,out,in,inl))
336 {
337 *outl=inl;
338 return 1;
339 }
340 else
341 {
342 *outl=0;
343 return 0;
344 }
345 }
346 i=ctx->buf_len;
347 bl=ctx->cipher->block_size;
348 OPENSSL_assert(bl <= sizeof ctx->buf);
349 if (i != 0)
350 {
351 if (i+inl < bl)
352 {
353 memcpy(&(ctx->buf[i]),in,inl);
354 ctx->buf_len+=inl;
355 *outl=0;
356 return 1;
357 }
358 else
359 {
360 j=bl-i;
361 memcpy(&(ctx->buf[i]),in,j);
362 if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0;
363 inl-=j;
364 in+=j;
365 out+=bl;
366 *outl=bl;
367 }
368 }
369 else
370 *outl = 0;
371 i=inl&(bl-1);
372 inl-=i;
373 if (inl > 0)
374 {
375 if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0;
376 *outl+=inl;
377 }
378
379 if (i != 0)
380 memcpy(ctx->buf,&(in[inl]),i);
381 ctx->buf_len=i;
382 return 1;
383 }
384
385int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
386 {
387 int ret;
388 ret = EVP_EncryptFinal_ex(ctx, out, outl);
389 return ret;
390 }
391
392int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
393 {
394 int i,n,b,bl,ret;
395
396 b=ctx->cipher->block_size;
397 OPENSSL_assert(b <= sizeof ctx->buf);
398 if (b == 1)
399 {
400 *outl=0;
401 return 1;
402 }
403 bl=ctx->buf_len;
404 if (ctx->flags & EVP_CIPH_NO_PADDING)
405 {
406 if(bl)
407 {
408 EVPerr(EVP_F_EVP_ENCRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
409 return 0;
410 }
411 *outl = 0;
412 return 1;
413 }
414
415 n=b-bl;
416 for (i=bl; i<b; i++)
417 ctx->buf[i]=n;
418 ret=ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
419
420
421 if(ret)
422 *outl=b;
423
424 return ret;
425 }
426
427int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
428 const unsigned char *in, int inl)
429 {
430 int b, fix_len;
431
432 if (inl == 0)
433 {
434 *outl=0;
435 return 1;
436 }
437
438 if (ctx->flags & EVP_CIPH_NO_PADDING)
439 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
440
441 b=ctx->cipher->block_size;
442 OPENSSL_assert(b <= sizeof ctx->final);
443
444 if(ctx->final_used)
445 {
446 memcpy(out,ctx->final,b);
447 out+=b;
448 fix_len = 1;
449 }
450 else
451 fix_len = 0;
452
453
454 if(!EVP_EncryptUpdate(ctx,out,outl,in,inl))
455 return 0;
456
457 /* if we have 'decrypted' a multiple of block size, make sure
458 * we have a copy of this last block */
459 if (b > 1 && !ctx->buf_len)
460 {
461 *outl-=b;
462 ctx->final_used=1;
463 memcpy(ctx->final,&out[*outl],b);
464 }
465 else
466 ctx->final_used = 0;
467
468 if (fix_len)
469 *outl += b;
470
471 return 1;
472 }
473
474int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
475 {
476 int ret;
477 ret = EVP_DecryptFinal_ex(ctx, out, outl);
478 return ret;
479 }
480
481int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
482 {
483 int i,b;
484 int n;
485
486 *outl=0;
487 b=ctx->cipher->block_size;
488 if (ctx->flags & EVP_CIPH_NO_PADDING)
489 {
490 if(ctx->buf_len)
491 {
492 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
493 return 0;
494 }
495 *outl = 0;
496 return 1;
497 }
498 if (b > 1)
499 {
500 if (ctx->buf_len || !ctx->final_used)
501 {
502 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
503 return(0);
504 }
505 OPENSSL_assert(b <= sizeof ctx->final);
506 n=ctx->final[b-1];
507 if (n > b)
508 {
509 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
510 return(0);
511 }
512 for (i=0; i<n; i++)
513 {
514 if (ctx->final[--b] != n)
515 {
516 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
517 return(0);
518 }
519 }
520 n=ctx->cipher->block_size-n;
521 for (i=0; i<n; i++)
522 out[i]=ctx->final[i];
523 *outl=n;
524 }
525 else
526 *outl=0;
527 return(1);
528 }
529
530int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
531 {
532 if (c->cipher != NULL)
533 {
534 if(c->cipher->cleanup && !c->cipher->cleanup(c))
535 return 0;
536 /* Cleanse cipher context data */
537 if (c->cipher_data)
538 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
539 }
540 if (c->cipher_data)
541 OPENSSL_free(c->cipher_data);
542#ifndef OPENSSL_NO_ENGINE
543 if (c->engine)
544 /* The EVP_CIPHER we used belongs to an ENGINE, release the
545 * functional reference we held for this reason. */
546 ENGINE_finish(c->engine);
547#endif
548 memset(c,0,sizeof(EVP_CIPHER_CTX));
549 return 1;
550 }
551
552int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
553 {
554 if(c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
555 return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL);
556 if(c->key_len == keylen) return 1;
557 if((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH))
558 {
559 c->key_len = keylen;
560 return 1;
561 }
562 EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,EVP_R_INVALID_KEY_LENGTH);
563 return 0;
564 }
565
566int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
567 {
568 if (pad) ctx->flags &= ~EVP_CIPH_NO_PADDING;
569 else ctx->flags |= EVP_CIPH_NO_PADDING;
570 return 1;
571 }
572
573int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
574{
575 int ret;
576 if(!ctx->cipher) {
577 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
578 return 0;
579 }
580
581 if(!ctx->cipher->ctrl) {
582 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
583 return 0;
584 }
585
586 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
587 if(ret == -1) {
588 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
589 return 0;
590 }
591 return ret;
592}
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
new file mode 100644
index 0000000000..40135d0729
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_err.c
@@ -0,0 +1,167 @@
1/* crypto/evp/evp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/evp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA EVP_str_functs[]=
68 {
69{ERR_PACK(0,EVP_F_AES_INIT_KEY,0), "AES_INIT_KEY"},
70{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
71{ERR_PACK(0,EVP_F_EVP_ADD_CIPHER,0), "EVP_add_cipher"},
72{ERR_PACK(0,EVP_F_EVP_ADD_DIGEST,0), "EVP_add_digest"},
73{ERR_PACK(0,EVP_F_EVP_CIPHERINIT,0), "EVP_CipherInit"},
74{ERR_PACK(0,EVP_F_EVP_CIPHER_CTX_CTRL,0), "EVP_CIPHER_CTX_ctrl"},
75{ERR_PACK(0,EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,0), "EVP_CIPHER_CTX_set_key_length"},
76{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
77{ERR_PACK(0,EVP_F_EVP_DIGESTINIT,0), "EVP_DigestInit"},
78{ERR_PACK(0,EVP_F_EVP_ENCRYPTFINAL,0), "EVP_EncryptFinal"},
79{ERR_PACK(0,EVP_F_EVP_GET_CIPHERBYNAME,0), "EVP_get_cipherbyname"},
80{ERR_PACK(0,EVP_F_EVP_GET_DIGESTBYNAME,0), "EVP_get_digestbyname"},
81{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"},
82{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
83{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"},
84{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"},
85{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"},
86{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"},
87{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"},
88{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
89{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
90{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
91{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DH,0), "EVP_PKEY_get1_DH"},
92{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DSA,0), "EVP_PKEY_get1_DSA"},
93{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_RSA,0), "EVP_PKEY_get1_RSA"},
94{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
95{ERR_PACK(0,EVP_F_EVP_RIJNDAEL,0), "EVP_RIJNDAEL"},
96{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
97{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
98{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"},
99{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"},
100{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
101{ERR_PACK(0,EVP_F_RC5_CTRL,0), "RC5_CTRL"},
102{0,NULL}
103 };
104
105static ERR_STRING_DATA EVP_str_reasons[]=
106 {
107{EVP_R_AES_KEY_SETUP_FAILED ,"aes key setup failed"},
108{EVP_R_BAD_BLOCK_LENGTH ,"bad block length"},
109{EVP_R_BAD_DECRYPT ,"bad decrypt"},
110{EVP_R_BAD_KEY_LENGTH ,"bad key length"},
111{EVP_R_BN_DECODE_ERROR ,"bn decode error"},
112{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"},
113{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"},
114{EVP_R_CTRL_NOT_IMPLEMENTED ,"ctrl not implemented"},
115{EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED ,"ctrl operation not implemented"},
116{EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH ,"data not multiple of block length"},
117{EVP_R_DECODE_ERROR ,"decode error"},
118{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
119{EVP_R_DISABLED_FOR_FIPS ,"disabled for fips"},
120{EVP_R_ENCODE_ERROR ,"encode error"},
121{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
122{EVP_R_EXPECTING_AN_RSA_KEY ,"expecting an rsa key"},
123{EVP_R_EXPECTING_A_DH_KEY ,"expecting a dh key"},
124{EVP_R_EXPECTING_A_DSA_KEY ,"expecting a dsa key"},
125{EVP_R_INITIALIZATION_ERROR ,"initialization error"},
126{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
127{EVP_R_INVALID_KEY_LENGTH ,"invalid key length"},
128{EVP_R_IV_TOO_LARGE ,"iv too large"},
129{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
130{EVP_R_MISSING_PARAMETERS ,"missing parameters"},
131{EVP_R_NO_CIPHER_SET ,"no cipher set"},
132{EVP_R_NO_DIGEST_SET ,"no digest set"},
133{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
134{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
135{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
136{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"},
137{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
138{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"},
139{EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS ,"unsuported number of rounds"},
140{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
141{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"},
142{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"},
143{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
144{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"},
145{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"},
146{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"},
147{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
148{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
149{0,NULL}
150 };
151
152#endif
153
154void ERR_load_EVP_strings(void)
155 {
156 static int init=1;
157
158 if (init)
159 {
160 init=0;
161#ifndef OPENSSL_NO_ERR
162 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
163 ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
164#endif
165
166 }
167 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
new file mode 100644
index 0000000000..5f387a94d3
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -0,0 +1,174 @@
1/* crypto/evp/evp_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/ui.h>
65
66/* should be init to zeros. */
67static char prompt_string[80];
68
69void EVP_set_pw_prompt(char *prompt)
70 {
71 if (prompt == NULL)
72 prompt_string[0]='\0';
73 else
74 {
75 strncpy(prompt_string,prompt,79);
76 prompt_string[79]='\0';
77 }
78 }
79
80char *EVP_get_pw_prompt(void)
81 {
82 if (prompt_string[0] == '\0')
83 return(NULL);
84 else
85 return(prompt_string);
86 }
87
88/* For historical reasons, the standard function for reading passwords is
89 * in the DES library -- if someone ever wants to disable DES,
90 * this function will fail */
91int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
92 {
93 int ret;
94 char buff[BUFSIZ];
95 UI *ui;
96
97 if ((prompt == NULL) && (prompt_string[0] != '\0'))
98 prompt=prompt_string;
99 ui = UI_new();
100 UI_add_input_string(ui,prompt,0,buf,0,(len>=BUFSIZ)?BUFSIZ-1:len);
101 if (verify)
102 UI_add_verify_string(ui,prompt,0,
103 buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf);
104 ret = UI_process(ui);
105 UI_free(ui);
106 OPENSSL_cleanse(buff,BUFSIZ);
107 return ret;
108 }
109
110int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
111 const unsigned char *salt, const unsigned char *data, int datal,
112 int count, unsigned char *key, unsigned char *iv)
113 {
114 EVP_MD_CTX c;
115 unsigned char md_buf[EVP_MAX_MD_SIZE];
116 int niv,nkey,addmd=0;
117 unsigned int mds=0,i;
118
119 nkey=type->key_len;
120 niv=type->iv_len;
121 OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
122 OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
123
124 if (data == NULL) return(nkey);
125
126 EVP_MD_CTX_init(&c);
127 for (;;)
128 {
129 EVP_DigestInit_ex(&c,md, NULL);
130 if (addmd++)
131 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
132 EVP_DigestUpdate(&c,data,datal);
133 if (salt != NULL)
134 EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN);
135 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
136
137 for (i=1; i<(unsigned int)count; i++)
138 {
139 EVP_DigestInit_ex(&c,md, NULL);
140 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
141 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
142 }
143 i=0;
144 if (nkey)
145 {
146 for (;;)
147 {
148 if (nkey == 0) break;
149 if (i == mds) break;
150 if (key != NULL)
151 *(key++)=md_buf[i];
152 nkey--;
153 i++;
154 }
155 }
156 if (niv && (i != mds))
157 {
158 for (;;)
159 {
160 if (niv == 0) break;
161 if (i == mds) break;
162 if (iv != NULL)
163 *(iv++)=md_buf[i];
164 niv--;
165 i++;
166 }
167 }
168 if ((nkey == 0) && (niv == 0)) break;
169 }
170 EVP_MD_CTX_cleanup(&c);
171 OPENSSL_cleanse(&(md_buf[0]),EVP_MAX_MD_SIZE);
172 return(type->key_len);
173 }
174
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
new file mode 100644
index 0000000000..a63ba19317
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -0,0 +1,168 @@
1/* crypto/evp/evp_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63
64int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
65 {
66 int ret;
67
68 if (c->cipher->set_asn1_parameters != NULL)
69 ret=c->cipher->set_asn1_parameters(c,type);
70 else
71 return -1;
72 return(ret);
73 }
74
75int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
76 {
77 int ret;
78
79 if (c->cipher->get_asn1_parameters != NULL)
80 ret=c->cipher->get_asn1_parameters(c,type);
81 else
82 return -1;
83 return(ret);
84 }
85
86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
87 {
88 int i=0,l;
89
90 if (type != NULL)
91 {
92 l=EVP_CIPHER_CTX_iv_length(c);
93 OPENSSL_assert(l <= sizeof c->iv);
94 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
95 if (i != l)
96 return(-1);
97 else if (i > 0)
98 memcpy(c->iv,c->oiv,l);
99 }
100 return(i);
101 }
102
103int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
104 {
105 int i=0,j;
106
107 if (type != NULL)
108 {
109 j=EVP_CIPHER_CTX_iv_length(c);
110 OPENSSL_assert(j <= sizeof c->iv);
111 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
112 }
113 return(i);
114 }
115
116/* Convert the various cipher NIDs and dummies to a proper OID NID */
117int EVP_CIPHER_type(const EVP_CIPHER *ctx)
118{
119 int nid;
120 ASN1_OBJECT *otmp;
121 nid = EVP_CIPHER_nid(ctx);
122
123 switch(nid) {
124
125 case NID_rc2_cbc:
126 case NID_rc2_64_cbc:
127 case NID_rc2_40_cbc:
128
129 return NID_rc2_cbc;
130
131 case NID_rc4:
132 case NID_rc4_40:
133
134 return NID_rc4;
135
136 case NID_aes_128_cfb128:
137 case NID_aes_128_cfb8:
138 case NID_aes_128_cfb1:
139
140 return NID_aes_128_cfb128;
141
142 case NID_aes_192_cfb128:
143 case NID_aes_192_cfb8:
144 case NID_aes_192_cfb1:
145
146 return NID_aes_192_cfb128;
147
148 case NID_aes_256_cfb128:
149 case NID_aes_256_cfb8:
150 case NID_aes_256_cfb1:
151
152 return NID_aes_256_cfb128;
153
154 case NID_des_cfb64:
155 case NID_des_cfb8:
156 case NID_des_cfb1:
157
158 return NID_des_cfb64;
159
160 default:
161 /* Check it has an OID and it is valid */
162 otmp = OBJ_nid2obj(nid);
163 if(!otmp || !otmp->data) nid = NID_undef;
164 ASN1_OBJECT_free(otmp);
165 return nid;
166 }
167}
168
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
new file mode 100644
index 0000000000..f8c5343620
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_locl.h
@@ -0,0 +1,252 @@
1/* evp_locl.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Macros to code block cipher wrappers */
60
61/* Wrapper functions for each cipher mode */
62
63#define BLOCK_CIPHER_ecb_loop() \
64 unsigned int i, bl; \
65 bl = ctx->cipher->block_size;\
66 if(inl < bl) return 1;\
67 inl -= bl; \
68 for(i=0; i <= inl; i+=bl) \
69
70#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
71static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
72{\
73 BLOCK_CIPHER_ecb_loop() \
74 cprefix##_ecb_encrypt(in + i, out + i, &((kstruct *)ctx->cipher_data)->ksched, ctx->encrypt);\
75 return 1;\
76}
77
78#define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
79static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
80{\
81 cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
82 return 1;\
83}
84
85#define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
86static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
87{\
88 cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
89 return 1;\
90}
91
92#define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
93static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
94{\
95 cprefix##_cfb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
96 return 1;\
97}
98
99#define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
100 BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
101 BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
102 BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
103 BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
104
105#define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
106 key_len, iv_len, flags, init_key, cleanup, \
107 set_asn1, get_asn1, ctrl) \
108static const EVP_CIPHER cname##_##mode = { \
109 nid##_##nmode, block_size, key_len, iv_len, \
110 flags | EVP_CIPH_##MODE##_MODE, \
111 init_key, \
112 cname##_##mode##_cipher, \
113 cleanup, \
114 sizeof(kstruct), \
115 set_asn1, get_asn1,\
116 ctrl, \
117 NULL \
118}; \
119const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
120
121#define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
122 iv_len, flags, init_key, cleanup, set_asn1, \
123 get_asn1, ctrl) \
124BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
125 iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
126
127#define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
128 iv_len, cbits, flags, init_key, cleanup, \
129 set_asn1, get_asn1, ctrl) \
130BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
131 key_len, iv_len, flags, init_key, cleanup, set_asn1, \
132 get_asn1, ctrl)
133
134#define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
135 iv_len, cbits, flags, init_key, cleanup, \
136 set_asn1, get_asn1, ctrl) \
137BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
138 key_len, iv_len, flags, init_key, cleanup, set_asn1, \
139 get_asn1, ctrl)
140
141#define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
142 iv_len, flags, init_key, cleanup, set_asn1, \
143 get_asn1, ctrl) \
144BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
145 iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
146
147#define BLOCK_CIPHER_defs(cname, kstruct, \
148 nid, block_size, key_len, iv_len, cbits, flags, \
149 init_key, cleanup, set_asn1, get_asn1, ctrl) \
150BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
151 init_key, cleanup, set_asn1, get_asn1, ctrl) \
152BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
153 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
154BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
155 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
156BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
157 init_key, cleanup, set_asn1, get_asn1, ctrl)
158
159
160/*
161#define BLOCK_CIPHER_defs(cname, kstruct, \
162 nid, block_size, key_len, iv_len, flags,\
163 init_key, cleanup, set_asn1, get_asn1, ctrl)\
164static const EVP_CIPHER cname##_cbc = {\
165 nid##_cbc, block_size, key_len, iv_len, \
166 flags | EVP_CIPH_CBC_MODE,\
167 init_key,\
168 cname##_cbc_cipher,\
169 cleanup,\
170 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
171 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
172 set_asn1, get_asn1,\
173 ctrl, \
174 NULL \
175};\
176const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
177static const EVP_CIPHER cname##_cfb = {\
178 nid##_cfb64, 1, key_len, iv_len, \
179 flags | EVP_CIPH_CFB_MODE,\
180 init_key,\
181 cname##_cfb_cipher,\
182 cleanup,\
183 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
184 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
185 set_asn1, get_asn1,\
186 ctrl,\
187 NULL \
188};\
189const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
190static const EVP_CIPHER cname##_ofb = {\
191 nid##_ofb64, 1, key_len, iv_len, \
192 flags | EVP_CIPH_OFB_MODE,\
193 init_key,\
194 cname##_ofb_cipher,\
195 cleanup,\
196 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
197 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
198 set_asn1, get_asn1,\
199 ctrl,\
200 NULL \
201};\
202const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
203static const EVP_CIPHER cname##_ecb = {\
204 nid##_ecb, block_size, key_len, iv_len, \
205 flags | EVP_CIPH_ECB_MODE,\
206 init_key,\
207 cname##_ecb_cipher,\
208 cleanup,\
209 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
210 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
211 set_asn1, get_asn1,\
212 ctrl,\
213 NULL \
214};\
215const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
216*/
217
218#define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
219 block_size, key_len, iv_len, cbits, \
220 flags, init_key, \
221 cleanup, set_asn1, get_asn1, ctrl) \
222 BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
223 BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
224 cbits, flags, init_key, cleanup, set_asn1, \
225 get_asn1, ctrl)
226
227#define EVP_C_DATA(kstruct, ctx) ((kstruct *)(ctx)->cipher_data)
228
229#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,flags) \
230 BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
231 BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
232 NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
233 flags, cipher##_init_key, NULL, \
234 EVP_CIPHER_set_asn1_iv, \
235 EVP_CIPHER_get_asn1_iv, \
236 NULL)
237
238#ifdef OPENSSL_FIPS
239#define RC2_set_key private_RC2_set_key
240#define RC4_set_key private_RC4_set_key
241#define CAST_set_key private_CAST_set_key
242#define RC5_32_set_key private_RC5_32_set_key
243#define BF_set_key private_BF_set_key
244#define idea_set_encrypt_key private_idea_set_encrypt_key
245
246#define MD5_Init private_MD5_Init
247#define MD4_Init private_MD4_Init
248#define MD2_Init private_MD2_Init
249#define MDC2_Init private_MDC2_Init
250#define SHA_Init private_SHA_Init
251
252#endif
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
new file mode 100644
index 0000000000..91e545a141
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -0,0 +1,136 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/x509.h>
63
64/* Password based encryption (PBE) functions */
65
66static STACK *pbe_algs;
67
68/* Setup a cipher context from a PBE algorithm */
69
70typedef struct {
71int pbe_nid;
72const EVP_CIPHER *cipher;
73const EVP_MD *md;
74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL;
76
77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{
80
81 EVP_PBE_CTL *pbetmp, pbelu;
82 int i;
83 pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
84 if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
85 else i = -1;
86
87 if (i == -1) {
88 char obj_tmp[80];
89 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
90 if (!pbe_obj) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
91 else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if(!pass) passlen = 0;
96 else if (passlen == -1) passlen = strlen(pass);
97 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
98 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
99 pbetmp->md, en_de);
100 if (!i) {
101 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
102 return 0;
103 }
104 return 1;
105}
106
107static int pbe_cmp(const char * const *a, const char * const *b)
108{
109 EVP_PBE_CTL **pbe1 = (EVP_PBE_CTL **) a, **pbe2 = (EVP_PBE_CTL **)b;
110 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
111}
112
113/* Add a PBE algorithm */
114
115int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
116 EVP_PBE_KEYGEN *keygen)
117{
118 EVP_PBE_CTL *pbe_tmp;
119 if (!pbe_algs) pbe_algs = sk_new(pbe_cmp);
120 if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) {
121 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
122 return 0;
123 }
124 pbe_tmp->pbe_nid = nid;
125 pbe_tmp->cipher = cipher;
126 pbe_tmp->md = md;
127 pbe_tmp->keygen = keygen;
128 sk_push (pbe_algs, (char *)pbe_tmp);
129 return 1;
130}
131
132void EVP_PBE_cleanup(void)
133{
134 sk_pop_free(pbe_algs, OPENSSL_freeFunc);
135 pbe_algs = NULL;
136}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
new file mode 100644
index 0000000000..47a69932a5
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -0,0 +1,468 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65#ifndef OPENSSL_NO_DSA
66static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
67#endif
68
69/* Extract a private key from a PKCS8 structure */
70
71EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
72{
73 EVP_PKEY *pkey = NULL;
74#ifndef OPENSSL_NO_RSA
75 RSA *rsa = NULL;
76#endif
77#ifndef OPENSSL_NO_DSA
78 DSA *dsa = NULL;
79 ASN1_INTEGER *privkey;
80 ASN1_TYPE *t1, *t2, *param = NULL;
81 STACK_OF(ASN1_TYPE) *ndsa = NULL;
82 BN_CTX *ctx = NULL;
83 int plen;
84#endif
85 X509_ALGOR *a;
86 unsigned char *p;
87 const unsigned char *cp;
88 int pkeylen;
89 char obj_tmp[80];
90
91 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
92 p8->broken = PKCS8_OK;
93 p = p8->pkey->value.octet_string->data;
94 pkeylen = p8->pkey->value.octet_string->length;
95 } else {
96 p8->broken = PKCS8_NO_OCTET;
97 p = p8->pkey->value.sequence->data;
98 pkeylen = p8->pkey->value.sequence->length;
99 }
100 if (!(pkey = EVP_PKEY_new())) {
101 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104 a = p8->pkeyalg;
105 switch (OBJ_obj2nid(a->algorithm))
106 {
107#ifndef OPENSSL_NO_RSA
108 case NID_rsaEncryption:
109 cp = p;
110 if (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef OPENSSL_NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen,
127 d2i_ASN1_TYPE,
128 ASN1_TYPE_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 goto dsaerr;
131 }
132 if(sk_ASN1_TYPE_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 goto dsaerr;
135 }
136 /* Handle Two broken types:
137 * SEQUENCE {parameters, priv_key}
138 * SEQUENCE {pub_key, priv_key}
139 */
140
141 t1 = sk_ASN1_TYPE_value(ndsa, 0);
142 t2 = sk_ASN1_TYPE_value(ndsa, 1);
143 if(t1->type == V_ASN1_SEQUENCE) {
144 p8->broken = PKCS8_EMBEDDED_PARAM;
145 param = t1;
146 } else if(a->parameter->type == V_ASN1_SEQUENCE) {
147 p8->broken = PKCS8_NS_DB;
148 param = a->parameter;
149 } else {
150 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
151 goto dsaerr;
152 }
153
154 if(t2->type != V_ASN1_INTEGER) {
155 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
156 goto dsaerr;
157 }
158 privkey = t2->value.integer;
159 } else {
160 if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
161 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
162 goto dsaerr;
163 }
164 param = p8->pkeyalg->parameter;
165 }
166 if (!param || (param->type != V_ASN1_SEQUENCE)) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
168 goto dsaerr;
169 }
170 cp = p = param->value.sequence->data;
171 plen = param->value.sequence->length;
172 if (!(dsa = d2i_DSAparams (NULL, &cp, plen))) {
173 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
174 goto dsaerr;
175 }
176 /* We have parameters now set private key */
177 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
178 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
179 goto dsaerr;
180 }
181 /* Calculate public key (ouch!) */
182 if (!(dsa->pub_key = BN_new())) {
183 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
184 goto dsaerr;
185 }
186 if (!(ctx = BN_CTX_new())) {
187 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
188 goto dsaerr;
189 }
190
191 if (!BN_mod_exp(dsa->pub_key, dsa->g,
192 dsa->priv_key, dsa->p, ctx)) {
193
194 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
195 goto dsaerr;
196 }
197
198 EVP_PKEY_assign_DSA(pkey, dsa);
199 BN_CTX_free (ctx);
200 if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
201 else ASN1_INTEGER_free(privkey);
202 break;
203 dsaerr:
204 BN_CTX_free (ctx);
205 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
206 DSA_free(dsa);
207 EVP_PKEY_free(pkey);
208 return NULL;
209 break;
210#endif
211 default:
212 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
213 if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
214 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
215 ERR_add_error_data(2, "TYPE=", obj_tmp);
216 EVP_PKEY_free (pkey);
217 return NULL;
218 }
219 return pkey;
220}
221
222PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
223{
224 return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK);
225}
226
227/* Turn a private key into a PKCS8 structure */
228
229PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
230{
231 PKCS8_PRIV_KEY_INFO *p8;
232
233 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
234 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
235 return NULL;
236 }
237 p8->broken = broken;
238 if (!ASN1_INTEGER_set(p8->version, 0)) {
239 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
240 PKCS8_PRIV_KEY_INFO_free (p8);
241 return NULL;
242 }
243 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
244 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
245 PKCS8_PRIV_KEY_INFO_free (p8);
246 return NULL;
247 }
248 p8->pkey->type = V_ASN1_OCTET_STRING;
249 switch (EVP_PKEY_type(pkey->type)) {
250#ifndef OPENSSL_NO_RSA
251 case EVP_PKEY_RSA:
252
253 if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
254
255 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
256 p8->pkeyalg->parameter->type = V_ASN1_NULL;
257 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
258 &p8->pkey->value.octet_string)) {
259 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
260 PKCS8_PRIV_KEY_INFO_free (p8);
261 return NULL;
262 }
263 break;
264#endif
265#ifndef OPENSSL_NO_DSA
266 case EVP_PKEY_DSA:
267 if(!dsa_pkey2pkcs8(p8, pkey)) {
268 PKCS8_PRIV_KEY_INFO_free (p8);
269 return NULL;
270 }
271
272 break;
273#endif
274 default:
275 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
276 PKCS8_PRIV_KEY_INFO_free (p8);
277 return NULL;
278 }
279 RAND_add(p8->pkey->value.octet_string->data,
280 p8->pkey->value.octet_string->length, 0);
281 return p8;
282}
283
284PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
285{
286 switch (broken) {
287
288 case PKCS8_OK:
289 p8->broken = PKCS8_OK;
290 return p8;
291 break;
292
293 case PKCS8_NO_OCTET:
294 p8->broken = PKCS8_NO_OCTET;
295 p8->pkey->type = V_ASN1_SEQUENCE;
296 return p8;
297 break;
298
299 default:
300 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
301 return NULL;
302 break;
303
304 }
305}
306
307#ifndef OPENSSL_NO_DSA
308static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
309{
310 ASN1_STRING *params = NULL;
311 ASN1_INTEGER *prkey = NULL;
312 ASN1_TYPE *ttmp = NULL;
313 STACK_OF(ASN1_TYPE) *ndsa = NULL;
314 unsigned char *p = NULL, *q;
315 int len;
316
317 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
318 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
319 if (!(p = OPENSSL_malloc(len))) {
320 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
321 goto err;
322 }
323 q = p;
324 i2d_DSAparams (pkey->pkey.dsa, &q);
325 if (!(params = ASN1_STRING_new())) {
326 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
327 goto err;
328 }
329 if (!ASN1_STRING_set(params, p, len)) {
330 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
331 goto err;
332 }
333 OPENSSL_free(p);
334 p = NULL;
335 /* Get private key into integer */
336 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
337 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
338 goto err;
339 }
340
341 switch(p8->broken) {
342
343 case PKCS8_OK:
344 case PKCS8_NO_OCTET:
345
346 if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,
347 &p8->pkey->value.octet_string)) {
348 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
349 goto err;
350 }
351
352 M_ASN1_INTEGER_free (prkey);
353 prkey = NULL;
354 p8->pkeyalg->parameter->value.sequence = params;
355 params = NULL;
356 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
357
358 break;
359
360 case PKCS8_NS_DB:
361
362 p8->pkeyalg->parameter->value.sequence = params;
363 params = NULL;
364 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
365 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
366 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
367 goto err;
368 }
369 if (!(ttmp = ASN1_TYPE_new())) {
370 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
371 goto err;
372 }
373 if (!(ttmp->value.integer =
374 BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) {
375 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
376 goto err;
377 }
378 ttmp->type = V_ASN1_INTEGER;
379 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
380 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
381 goto err;
382 }
383
384 if (!(ttmp = ASN1_TYPE_new())) {
385 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
386 goto err;
387 }
388 ttmp->value.integer = prkey;
389 prkey = NULL;
390 ttmp->type = V_ASN1_INTEGER;
391 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
392 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
393 goto err;
394 }
395 ttmp = NULL;
396
397 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
398 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
399 goto err;
400 }
401
402 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
403 &p8->pkey->value.octet_string->data,
404 &p8->pkey->value.octet_string->length)) {
405
406 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
407 goto err;
408 }
409 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
410 break;
411
412 case PKCS8_EMBEDDED_PARAM:
413
414 p8->pkeyalg->parameter->type = V_ASN1_NULL;
415 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
416 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
417 goto err;
418 }
419 if (!(ttmp = ASN1_TYPE_new())) {
420 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
421 goto err;
422 }
423 ttmp->value.sequence = params;
424 params = NULL;
425 ttmp->type = V_ASN1_SEQUENCE;
426 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
427 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
428 goto err;
429 }
430
431 if (!(ttmp = ASN1_TYPE_new())) {
432 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
433 goto err;
434 }
435 ttmp->value.integer = prkey;
436 prkey = NULL;
437 ttmp->type = V_ASN1_INTEGER;
438 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
439 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
440 goto err;
441 }
442 ttmp = NULL;
443
444 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
445 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
446 goto err;
447 }
448
449 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
450 &p8->pkey->value.octet_string->data,
451 &p8->pkey->value.octet_string->length)) {
452
453 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
454 goto err;
455 }
456 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
457 break;
458 }
459 return 1;
460err:
461 if (p != NULL) OPENSSL_free(p);
462 if (params != NULL) ASN1_STRING_free(params);
463 if (prkey != NULL) M_ASN1_INTEGER_free(prkey);
464 if (ttmp != NULL) ASN1_TYPE_free(ttmp);
465 if (ndsa != NULL) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
466 return 0;
467}
468#endif
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
new file mode 100644
index 0000000000..d393eb3400
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_dss.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_dss.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifndef OPENSSL_NO_SHA
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD dsa_md=
76 {
77 NID_dsaWithSHA,
78 NID_dsaWithSHA,
79 SHA_DIGEST_LENGTH,
80 EVP_MD_FLAG_FIPS,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_DSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_dss(void)
92 {
93 return(&dsa_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c
new file mode 100644
index 0000000000..f5668ebda0
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_dss1.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_dss1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD dss1_md=
76 {
77 NID_dsa,
78 NID_dsaWithSHA1,
79 SHA_DIGEST_LENGTH,
80 0,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_DSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_dss1(void)
92 {
93 return(&dss1_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/m_md4.c b/src/lib/libcrypto/evp/m_md4.c
new file mode 100644
index 0000000000..0605e4b707
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md4.c
@@ -0,0 +1,97 @@
1/* crypto/evp/m_md4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_MD4
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/md4.h>
67
68static int init(EVP_MD_CTX *ctx)
69 { return MD4_Init(ctx->md_data); }
70
71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
72 { return MD4_Update(ctx->md_data,data,count); }
73
74static int final(EVP_MD_CTX *ctx,unsigned char *md)
75 { return MD4_Final(md,ctx->md_data); }
76
77static const EVP_MD md4_md=
78 {
79 NID_md4,
80 NID_md4WithRSAEncryption,
81 MD4_DIGEST_LENGTH,
82 0,
83 init,
84 update,
85 final,
86 NULL,
87 NULL,
88 EVP_PKEY_RSA_method,
89 MD4_CBLOCK,
90 sizeof(EVP_MD *)+sizeof(MD4_CTX),
91 };
92
93const EVP_MD *EVP_md4(void)
94 {
95 return(&md4_md);
96 }
97#endif
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c
new file mode 100644
index 0000000000..752615d473
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md5.c
@@ -0,0 +1,97 @@
1/* crypto/evp/m_md5.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_MD5
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/md5.h>
67
68static int init(EVP_MD_CTX *ctx)
69 { return MD5_Init(ctx->md_data); }
70
71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
72 { return MD5_Update(ctx->md_data,data,count); }
73
74static int final(EVP_MD_CTX *ctx,unsigned char *md)
75 { return MD5_Final(md,ctx->md_data); }
76
77static const EVP_MD md5_md=
78 {
79 NID_md5,
80 NID_md5WithRSAEncryption,
81 MD5_DIGEST_LENGTH,
82 0,
83 init,
84 update,
85 final,
86 NULL,
87 NULL,
88 EVP_PKEY_RSA_method,
89 MD5_CBLOCK,
90 sizeof(EVP_MD *)+sizeof(MD5_CTX),
91 };
92
93const EVP_MD *EVP_md5(void)
94 {
95 return(&md5_md);
96 }
97#endif
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c
new file mode 100644
index 0000000000..f6f0a1d2c0
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_null.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65static int init(EVP_MD_CTX *ctx)
66 { return 1; }
67
68static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
69 { return 1; }
70
71static int final(EVP_MD_CTX *ctx,unsigned char *md)
72 { return 1; }
73
74static const EVP_MD null_md=
75 {
76 NID_undef,
77 NID_undef,
78 0,
79 0,
80 init,
81 update,
82 final,
83 NULL,
84 NULL,
85 EVP_PKEY_NULL_method,
86 0,
87 sizeof(EVP_MD *),
88 };
89
90const EVP_MD *EVP_md_null(void)
91 {
92 return(&null_md);
93 }
94
95
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c
new file mode 100644
index 0000000000..64725528dc
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_ripemd.c
@@ -0,0 +1,96 @@
1/* crypto/evp/m_ripemd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RIPEMD
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/ripemd.h>
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67static int init(EVP_MD_CTX *ctx)
68 { return RIPEMD160_Init(ctx->md_data); }
69
70static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
71 { return RIPEMD160_Update(ctx->md_data,data,count); }
72
73static int final(EVP_MD_CTX *ctx,unsigned char *md)
74 { return RIPEMD160_Final(md,ctx->md_data); }
75
76static const EVP_MD ripemd160_md=
77 {
78 NID_ripemd160,
79 NID_ripemd160WithRSA,
80 RIPEMD160_DIGEST_LENGTH,
81 0,
82 init,
83 update,
84 final,
85 NULL,
86 NULL,
87 EVP_PKEY_RSA_method,
88 RIPEMD160_CBLOCK,
89 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
90 };
91
92const EVP_MD *EVP_ripemd160(void)
93 {
94 return(&ripemd160_md);
95 }
96#endif
diff --git a/src/lib/libcrypto/evp/m_sha.c b/src/lib/libcrypto/evp/m_sha.c
index ed54909b16..d1785e5f74 100644
--- a/src/lib/libcrypto/evp/m_sha.c
+++ b/src/lib/libcrypto/evp/m_sha.c
@@ -59,9 +59,6 @@
59#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0) 59#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
60#include <stdio.h> 60#include <stdio.h>
61#include "cryptlib.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> 62#include <openssl/evp.h>
66#include "evp_locl.h" 63#include "evp_locl.h"
67#include <openssl/objects.h> 64#include <openssl/objects.h>
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
new file mode 100644
index 0000000000..fe4402389a
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_sha1.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_sha1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD sha1_md=
76 {
77 NID_sha1,
78 NID_sha1WithRSAEncryption,
79 SHA_DIGEST_LENGTH,
80 EVP_MD_FLAG_FIPS,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_RSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_sha1(void)
92 {
93 return(&sha1_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
new file mode 100644
index 0000000000..7712453046
--- /dev/null
+++ b/src/lib/libcrypto/evp/names.c
@@ -0,0 +1,126 @@
1/* crypto/evp/names.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#ifdef OPENSSL_FIPS
65#include <openssl/fips.h>
66#endif
67
68int EVP_add_cipher(const EVP_CIPHER *c)
69 {
70 int r;
71
72 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
73 if (r == 0) return(0);
74 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
75 return(r);
76 }
77
78int EVP_add_digest(const EVP_MD *md)
79 {
80 int r;
81 const char *name;
82
83 name=OBJ_nid2sn(md->type);
84 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
85 if (r == 0) return(0);
86 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
87 if (r == 0) return(0);
88
89 if (md->type != md->pkey_type)
90 {
91 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
92 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
93 if (r == 0) return(0);
94 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
95 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
96 }
97 return(r);
98 }
99
100const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
101 {
102 const EVP_CIPHER *cp;
103
104 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
105 return(cp);
106 }
107
108const EVP_MD *EVP_get_digestbyname(const char *name)
109 {
110 const EVP_MD *cp;
111
112 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
113 return(cp);
114 }
115
116void EVP_cleanup(void)
117 {
118 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
119 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
120 /* The above calls will only clean out the contents of the name
121 hash table, but not the hash table itself. The following line
122 does that part. -- Richard Levitte */
123 OBJ_NAME_cleanup(-1);
124
125 EVP_PBE_cleanup();
126 }
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
new file mode 100644
index 0000000000..a1874e83b2
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -0,0 +1,153 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/evp.h>
64
65/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
66 */
67
68void PKCS5_PBE_add(void)
69{
70#ifndef OPENSSL_NO_DES
71# ifndef OPENSSL_NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef OPENSSL_NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef OPENSSL_NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef OPENSSL_NO_RC2
85# ifndef OPENSSL_NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef OPENSSL_NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef OPENSSL_NO_SHA
94EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
95 PKCS5_PBE_keyivgen);
96# endif
97#endif
98#ifndef OPENSSL_NO_HMAC
99EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
100#endif
101}
102
103int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
104 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
105 int en_de)
106{
107 EVP_MD_CTX ctx;
108 unsigned char md_tmp[EVP_MAX_MD_SIZE];
109 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
110 int i;
111 PBEPARAM *pbe;
112 int saltlen, iter;
113 unsigned char *salt, *pbuf;
114
115 /* Extract useful info from parameter */
116 pbuf = param->value.sequence->data;
117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 if (!pbe->iter) iter = 1;
124 else iter = ASN1_INTEGER_get (pbe->iter);
125 salt = pbe->salt->data;
126 saltlen = pbe->salt->length;
127
128 if(!pass) passlen = 0;
129 else if(passlen == -1) passlen = strlen(pass);
130
131 EVP_MD_CTX_init(&ctx);
132 EVP_DigestInit_ex(&ctx, md, NULL);
133 EVP_DigestUpdate(&ctx, pass, passlen);
134 EVP_DigestUpdate(&ctx, salt, saltlen);
135 PBEPARAM_free(pbe);
136 EVP_DigestFinal_ex(&ctx, md_tmp, NULL);
137 for (i = 1; i < iter; i++) {
138 EVP_DigestInit_ex(&ctx, md, NULL);
139 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
140 EVP_DigestFinal_ex (&ctx, md_tmp, NULL);
141 }
142 EVP_MD_CTX_cleanup(&ctx);
143 OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= sizeof md_tmp);
144 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
145 OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16);
146 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
147 EVP_CIPHER_iv_length(cipher));
148 EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de);
149 OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE);
150 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
151 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
152 return 1;
153}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
new file mode 100644
index 0000000000..1f94e1ef88
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -0,0 +1,251 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#if !defined(OPENSSL_NO_HMAC) && !defined(OPENSSL_NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/evp.h>
64#include <openssl/hmac.h>
65
66/* set this to print out info about the keygen algorithm */
67/* #define DEBUG_PKCS5V2 */
68
69#ifdef DEBUG_PKCS5V2
70 static void h__dump (const unsigned char *p, int len);
71#endif
72
73/* This is an implementation of PKCS#5 v2.0 password based encryption key
74 * derivation function PBKDF2 using the only currently defined function HMAC
75 * with SHA1. Verified against test vectors posted by Peter Gutmann
76 * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
77 */
78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out)
82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
84 int cplen, j, k, tkeylen;
85 unsigned long i = 1;
86 HMAC_CTX hctx;
87
88 HMAC_CTX_init(&hctx);
89 p = out;
90 tkeylen = keylen;
91 if(!pass) passlen = 0;
92 else if(passlen == -1) passlen = strlen(pass);
93 while(tkeylen) {
94 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
95 else cplen = tkeylen;
96 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
97 * but just in case...
98 */
99 itmp[0] = (unsigned char)((i >> 24) & 0xff);
100 itmp[1] = (unsigned char)((i >> 16) & 0xff);
101 itmp[2] = (unsigned char)((i >> 8) & 0xff);
102 itmp[3] = (unsigned char)(i & 0xff);
103 HMAC_Init_ex(&hctx, pass, passlen, EVP_sha1(), NULL);
104 HMAC_Update(&hctx, salt, saltlen);
105 HMAC_Update(&hctx, itmp, 4);
106 HMAC_Final(&hctx, digtmp, NULL);
107 memcpy(p, digtmp, cplen);
108 for(j = 1; j < iter; j++) {
109 HMAC(EVP_sha1(), pass, passlen,
110 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
111 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
112 }
113 tkeylen-= cplen;
114 i++;
115 p+= cplen;
116 }
117 HMAC_CTX_cleanup(&hctx);
118#ifdef DEBUG_PKCS5V2
119 fprintf(stderr, "Password:\n");
120 h__dump (pass, passlen);
121 fprintf(stderr, "Salt:\n");
122 h__dump (salt, saltlen);
123 fprintf(stderr, "Iteration count %d\n", iter);
124 fprintf(stderr, "Key:\n");
125 h__dump (out, keylen);
126#endif
127 return 1;
128}
129
130#ifdef DO_TEST
131main()
132{
133 unsigned char out[4];
134 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
135 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
136 fprintf(stderr, "Out %02X %02X %02X %02X\n",
137 out[0], out[1], out[2], out[3]);
138}
139
140#endif
141
142/* Now the key derivation function itself. This is a bit evil because
143 * it has to check the ASN1 parameters are valid: and there are quite a
144 * few of them...
145 */
146
147int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
148 ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md,
149 int en_de)
150{
151 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
152 int saltlen, keylen, iter, plen;
153 PBE2PARAM *pbe2 = NULL;
154 const EVP_CIPHER *cipher;
155 PBKDF2PARAM *kdf = NULL;
156
157 pbuf = param->value.sequence->data;
158 plen = param->value.sequence->length;
159 if(!param || (param->type != V_ASN1_SEQUENCE) ||
160 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
161 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
162 return 0;
163 }
164
165 /* See if we recognise the key derivation function */
166
167 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
168 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
169 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
170 goto err;
171 }
172
173 /* lets see if we recognise the encryption algorithm.
174 */
175
176 cipher = EVP_get_cipherbyname(
177 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
178
179 if(!cipher) {
180 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
181 EVP_R_UNSUPPORTED_CIPHER);
182 goto err;
183 }
184
185 /* Fixup cipher based on AlgorithmIdentifier */
186 EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, en_de);
187 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
188 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
189 EVP_R_CIPHER_PARAMETER_ERROR);
190 goto err;
191 }
192 keylen = EVP_CIPHER_CTX_key_length(ctx);
193 OPENSSL_assert(keylen <= sizeof key);
194
195 /* Now decode key derivation function */
196
197 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
198 plen = pbe2->keyfunc->parameter->value.sequence->length;
199 if(!pbe2->keyfunc->parameter ||
200 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
201 !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
202 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
203 goto err;
204 }
205
206 PBE2PARAM_free(pbe2);
207 pbe2 = NULL;
208
209 /* Now check the parameters of the kdf */
210
211 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
212 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
213 EVP_R_UNSUPPORTED_KEYLENGTH);
214 goto err;
215 }
216
217 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
218 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
219 goto err;
220 }
221
222 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
223 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
224 EVP_R_UNSUPPORTED_SALT_TYPE);
225 goto err;
226 }
227
228 /* it seems that its all OK */
229 salt = kdf->salt->value.octet_string->data;
230 saltlen = kdf->salt->value.octet_string->length;
231 iter = ASN1_INTEGER_get(kdf->iter);
232 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
233 EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
234 OPENSSL_cleanse(key, keylen);
235 PBKDF2PARAM_free(kdf);
236 return 1;
237
238 err:
239 PBE2PARAM_free(pbe2);
240 PBKDF2PARAM_free(kdf);
241 return 0;
242}
243
244#ifdef DEBUG_PKCS5V2
245static void h__dump (const unsigned char *p, int len)
246{
247 for (; len --; p++) fprintf(stderr, "%02X ", *p);
248 fprintf(stderr, "\n");
249}
250#endif
251#endif
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
new file mode 100644
index 0000000000..8af620400e
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_dec.c
@@ -0,0 +1,87 @@
1/* crypto/evp/p_dec.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#ifndef OPENSSL_NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl,
70 EVP_PKEY *priv)
71 {
72 int ret= -1;
73
74#ifndef OPENSSL_NO_RSA
75 if (priv->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef OPENSSL_NO_RSA
80 goto err;
81 }
82
83 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING);
84err:
85#endif
86 return(ret);
87 }
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c
new file mode 100644
index 0000000000..656883b996
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_enc.c
@@ -0,0 +1,86 @@
1/* crypto/evp/p_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#ifndef OPENSSL_NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len,
70 EVP_PKEY *pubk)
71 {
72 int ret=0;
73
74#ifndef OPENSSL_NO_RSA
75 if (pubk->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef OPENSSL_NO_RSA
80 goto err;
81 }
82 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
83err:
84#endif
85 return(ret);
86 }
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
new file mode 100644
index 0000000000..215b94292a
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -0,0 +1,337 @@
1/* crypto/evp/p_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/evp.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66static void EVP_PKEY_free_it(EVP_PKEY *x);
67
68int EVP_PKEY_bits(EVP_PKEY *pkey)
69 {
70#ifndef OPENSSL_NO_RSA
71 if (pkey->type == EVP_PKEY_RSA)
72 return(BN_num_bits(pkey->pkey.rsa->n));
73 else
74#endif
75#ifndef OPENSSL_NO_DSA
76 if (pkey->type == EVP_PKEY_DSA)
77 return(BN_num_bits(pkey->pkey.dsa->p));
78#endif
79 return(0);
80 }
81
82int EVP_PKEY_size(EVP_PKEY *pkey)
83 {
84 if (pkey == NULL)
85 return(0);
86#ifndef OPENSSL_NO_RSA
87 if (pkey->type == EVP_PKEY_RSA)
88 return(RSA_size(pkey->pkey.rsa));
89 else
90#endif
91#ifndef OPENSSL_NO_DSA
92 if (pkey->type == EVP_PKEY_DSA)
93 return(DSA_size(pkey->pkey.dsa));
94#endif
95 return(0);
96 }
97
98int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
99 {
100#ifndef OPENSSL_NO_DSA
101 if (pkey->type == EVP_PKEY_DSA)
102 {
103 int ret=pkey->save_parameters;
104
105 if (mode >= 0)
106 pkey->save_parameters=mode;
107 return(ret);
108 }
109#endif
110 return(0);
111 }
112
113int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
114 {
115 if (to->type != from->type)
116 {
117 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
118 goto err;
119 }
120
121 if (EVP_PKEY_missing_parameters(from))
122 {
123 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
124 goto err;
125 }
126#ifndef OPENSSL_NO_DSA
127 if (to->type == EVP_PKEY_DSA)
128 {
129 BIGNUM *a;
130
131 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
132 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
133 to->pkey.dsa->p=a;
134
135 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
136 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
137 to->pkey.dsa->q=a;
138
139 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
140 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
141 to->pkey.dsa->g=a;
142 }
143#endif
144 return(1);
145err:
146 return(0);
147 }
148
149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
150 {
151#ifndef OPENSSL_NO_DSA
152 if (pkey->type == EVP_PKEY_DSA)
153 {
154 DSA *dsa;
155
156 dsa=pkey->pkey.dsa;
157 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
158 return(1);
159 }
160#endif
161 return(0);
162 }
163
164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
165 {
166#ifndef OPENSSL_NO_DSA
167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
168 {
169 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
170 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
171 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
172 return(0);
173 else
174 return(1);
175 }
176#endif
177 return(-1);
178 }
179
180EVP_PKEY *EVP_PKEY_new(void)
181 {
182 EVP_PKEY *ret;
183
184 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));
185 if (ret == NULL)
186 {
187 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
188 return(NULL);
189 }
190 ret->type=EVP_PKEY_NONE;
191 ret->references=1;
192 ret->pkey.ptr=NULL;
193 ret->attributes=NULL;
194 ret->save_parameters=1;
195 return(ret);
196 }
197
198int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
199 {
200 if (pkey == NULL) return(0);
201 if (pkey->pkey.ptr != NULL)
202 EVP_PKEY_free_it(pkey);
203 pkey->type=EVP_PKEY_type(type);
204 pkey->save_type=type;
205 pkey->pkey.ptr=key;
206 return(key != NULL);
207 }
208
209#ifndef OPENSSL_NO_RSA
210int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
211{
212 int ret = EVP_PKEY_assign_RSA(pkey, key);
213 if(ret)
214 RSA_up_ref(key);
215 return ret;
216}
217
218RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
219 {
220 if(pkey->type != EVP_PKEY_RSA) {
221 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
222 return NULL;
223 }
224 RSA_up_ref(pkey->pkey.rsa);
225 return pkey->pkey.rsa;
226}
227#endif
228
229#ifndef OPENSSL_NO_DSA
230int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
231{
232 int ret = EVP_PKEY_assign_DSA(pkey, key);
233 if(ret)
234 DSA_up_ref(key);
235 return ret;
236}
237
238DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
239 {
240 if(pkey->type != EVP_PKEY_DSA) {
241 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
242 return NULL;
243 }
244 DSA_up_ref(pkey->pkey.dsa);
245 return pkey->pkey.dsa;
246}
247#endif
248
249#ifndef OPENSSL_NO_DH
250
251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
252{
253 int ret = EVP_PKEY_assign_DH(pkey, key);
254 if(ret)
255 DH_up_ref(key);
256 return ret;
257}
258
259DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
260 {
261 if(pkey->type != EVP_PKEY_DH) {
262 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
263 return NULL;
264 }
265 DH_up_ref(pkey->pkey.dh);
266 return pkey->pkey.dh;
267}
268#endif
269
270int EVP_PKEY_type(int type)
271 {
272 switch (type)
273 {
274 case EVP_PKEY_RSA:
275 case EVP_PKEY_RSA2:
276 return(EVP_PKEY_RSA);
277 case EVP_PKEY_DSA:
278 case EVP_PKEY_DSA1:
279 case EVP_PKEY_DSA2:
280 case EVP_PKEY_DSA3:
281 case EVP_PKEY_DSA4:
282 return(EVP_PKEY_DSA);
283 case EVP_PKEY_DH:
284 return(EVP_PKEY_DH);
285 default:
286 return(NID_undef);
287 }
288 }
289
290void EVP_PKEY_free(EVP_PKEY *x)
291 {
292 int i;
293
294 if (x == NULL) return;
295
296 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
297#ifdef REF_PRINT
298 REF_PRINT("EVP_PKEY",x);
299#endif
300 if (i > 0) return;
301#ifdef REF_CHECK
302 if (i < 0)
303 {
304 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
305 abort();
306 }
307#endif
308 EVP_PKEY_free_it(x);
309 OPENSSL_free(x);
310 }
311
312static void EVP_PKEY_free_it(EVP_PKEY *x)
313 {
314 switch (x->type)
315 {
316#ifndef OPENSSL_NO_RSA
317 case EVP_PKEY_RSA:
318 case EVP_PKEY_RSA2:
319 RSA_free(x->pkey.rsa);
320 break;
321#endif
322#ifndef OPENSSL_NO_DSA
323 case EVP_PKEY_DSA:
324 case EVP_PKEY_DSA2:
325 case EVP_PKEY_DSA3:
326 case EVP_PKEY_DSA4:
327 DSA_free(x->pkey.dsa);
328 break;
329#endif
330#ifndef OPENSSL_NO_DH
331 case EVP_PKEY_DH:
332 DH_free(x->pkey.dh);
333 break;
334#endif
335 }
336 }
337
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
new file mode 100644
index 0000000000..5a933d1cda
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -0,0 +1,123 @@
1/* crypto/evp/p_open.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *ek,
67 int ekl, unsigned char *iv, EVP_PKEY *priv)
68 {
69 unsigned char *key=NULL;
70 int i,size=0,ret=0;
71
72 if(type) {
73 EVP_CIPHER_CTX_init(ctx);
74 if(!EVP_DecryptInit_ex(ctx,type,NULL, NULL,NULL)) return 0;
75 }
76
77 if(!priv) return 1;
78
79 if (priv->type != EVP_PKEY_RSA)
80 {
81 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
82 goto err;
83 }
84
85 size=RSA_size(priv->pkey.rsa);
86 key=(unsigned char *)OPENSSL_malloc(size+2);
87 if (key == NULL)
88 {
89 /* ERROR */
90 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93
94 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
95 if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i))
96 {
97 /* ERROR */
98 goto err;
99 }
100 if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv)) goto err;
101
102 ret=1;
103err:
104 if (key != NULL) OPENSSL_cleanse(key,size);
105 OPENSSL_free(key);
106 return(ret);
107 }
108
109int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 {
111 int i;
112
113 i=EVP_DecryptFinal_ex(ctx,out,outl);
114 EVP_DecryptInit_ex(ctx,NULL,NULL,NULL,NULL);
115 return(i);
116 }
117#else /* !OPENSSL_NO_RSA */
118
119# ifdef PEDANTIC
120static void *dummy=&dummy;
121# endif
122
123#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
new file mode 100644
index 0000000000..37e547fe72
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_seal.c
@@ -0,0 +1,115 @@
1/* crypto/evp/p_seal.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#ifndef OPENSSL_NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
70 int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int i;
74
75 if(type) {
76 EVP_CIPHER_CTX_init(ctx);
77 if(!EVP_EncryptInit_ex(ctx,type,NULL,NULL,NULL)) return 0;
78 }
79 if ((npubk <= 0) || !pubk)
80 return 1;
81 if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
82 return 0;
83 if (EVP_CIPHER_CTX_iv_length(ctx))
84 RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx));
85
86 if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv)) return 0;
87
88 for (i=0; i<npubk; i++)
89 {
90 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_CTX_key_length(ctx),
91 pubk[i]);
92 if (ekl[i] <= 0) return(-1);
93 }
94 return(npubk);
95 }
96
97/* MACRO
98void EVP_SealUpdate(ctx,out,outl,in,inl)
99EVP_CIPHER_CTX *ctx;
100unsigned char *out;
101int *outl;
102unsigned char *in;
103int inl;
104 {
105 EVP_EncryptUpdate(ctx,out,outl,in,inl);
106 }
107*/
108
109int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 {
111 int i;
112 i = EVP_EncryptFinal_ex(ctx,out,outl);
113 EVP_EncryptInit_ex(ctx,NULL,NULL,NULL,NULL);
114 return i;
115 }
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
new file mode 100644
index 0000000000..e4ae5906f5
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_sign.c
@@ -0,0 +1,114 @@
1/* crypto/evp/p_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifdef undef
66void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
67 {
68 EVP_DigestInit_ex(ctx,type);
69 }
70
71void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
72 unsigned int count)
73 {
74 EVP_DigestUpdate(ctx,data,count);
75 }
76#endif
77
78int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char m[EVP_MAX_MD_SIZE];
82 unsigned int m_len;
83 int i,ok=0,v;
84 MS_STATIC EVP_MD_CTX tmp_ctx;
85
86 *siglen=0;
87 EVP_MD_CTX_init(&tmp_ctx);
88 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
89 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
90 EVP_MD_CTX_cleanup(&tmp_ctx);
91 for (i=0; i<4; i++)
92 {
93 v=ctx->digest->required_pkey_type[i];
94 if (v == 0) break;
95 if (pkey->type == v)
96 {
97 ok=1;
98 break;
99 }
100 }
101 if (!ok)
102 {
103 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
104 return(0);
105 }
106 if (ctx->digest->sign == NULL)
107 {
108 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
109 return(0);
110 }
111 return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
112 pkey->pkey.ptr));
113 }
114
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
new file mode 100644
index 0000000000..d854d743a5
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_verify.c
@@ -0,0 +1,101 @@
1/* crypto/evp/p_verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
66 unsigned int siglen, EVP_PKEY *pkey)
67 {
68 unsigned char m[EVP_MAX_MD_SIZE];
69 unsigned int m_len;
70 int i,ok=0,v;
71 MS_STATIC EVP_MD_CTX tmp_ctx;
72
73 for (i=0; i<4; i++)
74 {
75 v=ctx->digest->required_pkey_type[i];
76 if (v == 0) break;
77 if (pkey->type == v)
78 {
79 ok=1;
80 break;
81 }
82 }
83 if (!ok)
84 {
85 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
86 return(-1);
87 }
88 EVP_MD_CTX_init(&tmp_ctx);
89 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
90 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
91 EVP_MD_CTX_cleanup(&tmp_ctx);
92 if (ctx->digest->verify == NULL)
93 {
94 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
95 return(0);
96 }
97
98 return(ctx->digest->verify(ctx->digest->type,m,m_len,
99 sigbuf,siglen,pkey->pkey.ptr));
100 }
101
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
new file mode 100644
index 0000000000..5b2e345c27
--- /dev/null
+++ b/src/lib/libcrypto/ex_data.c
@@ -0,0 +1,636 @@
1/* crypto/ex_data.c */
2
3/*
4 * Overhaul notes;
5 *
6 * This code is now *mostly* thread-safe. It is now easier to understand in what
7 * ways it is safe and in what ways it is not, which is an improvement. Firstly,
8 * all per-class stacks and index-counters for ex_data are stored in the same
9 * global LHASH table (keyed by class). This hash table uses locking for all
10 * access with the exception of CRYPTO_cleanup_all_ex_data(), which must only be
11 * called when no other threads can possibly race against it (even if it was
12 * locked, the race would mean it's possible the hash table might have been
13 * recreated after the cleanup). As classes can only be added to the hash table,
14 * and within each class, the stack of methods can only be incremented, the
15 * locking mechanics are simpler than they would otherwise be. For example, the
16 * new/dup/free ex_data functions will lock the hash table, copy the method
17 * pointers it needs from the relevant class, then unlock the hash table before
18 * actually applying those method pointers to the task of the new/dup/free
19 * operations. As they can't be removed from the method-stack, only
20 * supplemented, there's no race conditions associated with using them outside
21 * the lock. The get/set_ex_data functions are not locked because they do not
22 * involve this global state at all - they operate directly with a previously
23 * obtained per-class method index and a particular "ex_data" variable. These
24 * variables are usually instantiated per-context (eg. each RSA structure has
25 * one) so locking on read/write access to that variable can be locked locally
26 * if required (eg. using the "RSA" lock to synchronise access to a
27 * per-RSA-structure ex_data variable if required).
28 * [Geoff]
29 */
30
31/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
32 * All rights reserved.
33 *
34 * This package is an SSL implementation written
35 * by Eric Young (eay@cryptsoft.com).
36 * The implementation was written so as to conform with Netscapes SSL.
37 *
38 * This library is free for commercial and non-commercial use as long as
39 * the following conditions are aheared to. The following conditions
40 * apply to all code found in this distribution, be it the RC4, RSA,
41 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
42 * included with this distribution is covered by the same copyright terms
43 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
44 *
45 * Copyright remains Eric Young's, and as such any Copyright notices in
46 * the code are not to be removed.
47 * If this package is used in a product, Eric Young should be given attribution
48 * as the author of the parts of the library used.
49 * This can be in the form of a textual message at program startup or
50 * in documentation (online or textual) provided with the package.
51 *
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that the following conditions
54 * are met:
55 * 1. Redistributions of source code must retain the copyright
56 * notice, this list of conditions and the following disclaimer.
57 * 2. Redistributions in binary form must reproduce the above copyright
58 * notice, this list of conditions and the following disclaimer in the
59 * documentation and/or other materials provided with the distribution.
60 * 3. All advertising materials mentioning features or use of this software
61 * must display the following acknowledgement:
62 * "This product includes cryptographic software written by
63 * Eric Young (eay@cryptsoft.com)"
64 * The word 'cryptographic' can be left out if the rouines from the library
65 * being used are not cryptographic related :-).
66 * 4. If you include any Windows specific code (or a derivative thereof) from
67 * the apps directory (application code) you must include an acknowledgement:
68 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
69 *
70 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
71 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
74 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
75 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
76 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
77 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
78 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
79 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80 * SUCH DAMAGE.
81 *
82 * The licence and distribution terms for any publically available version or
83 * derivative of this code cannot be changed. i.e. this code cannot simply be
84 * copied and put under another distribution licence
85 * [including the GNU Public Licence.]
86 */
87/* ====================================================================
88 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
89 *
90 * Redistribution and use in source and binary forms, with or without
91 * modification, are permitted provided that the following conditions
92 * are met:
93 *
94 * 1. Redistributions of source code must retain the above copyright
95 * notice, this list of conditions and the following disclaimer.
96 *
97 * 2. Redistributions in binary form must reproduce the above copyright
98 * notice, this list of conditions and the following disclaimer in
99 * the documentation and/or other materials provided with the
100 * distribution.
101 *
102 * 3. All advertising materials mentioning features or use of this
103 * software must display the following acknowledgment:
104 * "This product includes software developed by the OpenSSL Project
105 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
106 *
107 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
108 * endorse or promote products derived from this software without
109 * prior written permission. For written permission, please contact
110 * openssl-core@openssl.org.
111 *
112 * 5. Products derived from this software may not be called "OpenSSL"
113 * nor may "OpenSSL" appear in their names without prior written
114 * permission of the OpenSSL Project.
115 *
116 * 6. Redistributions of any form whatsoever must retain the following
117 * acknowledgment:
118 * "This product includes software developed by the OpenSSL Project
119 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
120 *
121 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
122 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
123 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
124 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
125 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
126 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
127 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
128 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
129 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
130 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
131 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
132 * OF THE POSSIBILITY OF SUCH DAMAGE.
133 * ====================================================================
134 *
135 * This product includes cryptographic software written by Eric Young
136 * (eay@cryptsoft.com). This product includes software written by Tim
137 * Hudson (tjh@cryptsoft.com).
138 *
139 */
140
141#include <stdio.h>
142#include <stdlib.h>
143#include <openssl/buffer.h>
144#include <openssl/bio.h>
145#include <openssl/lhash.h>
146#include "cryptlib.h"
147
148/* What an "implementation of ex_data functionality" looks like */
149struct st_CRYPTO_EX_DATA_IMPL
150 {
151 /*********************/
152 /* GLOBAL OPERATIONS */
153 /* Return a new class index */
154 int (*cb_new_class)(void);
155 /* Cleanup all state used by the implementation */
156 void (*cb_cleanup)(void);
157 /************************/
158 /* PER-CLASS OPERATIONS */
159 /* Get a new method index within a class */
160 int (*cb_get_new_index)(int class_index, long argl, void *argp,
161 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
162 CRYPTO_EX_free *free_func);
163 /* Initialise a new CRYPTO_EX_DATA of a given class */
164 int (*cb_new_ex_data)(int class_index, void *obj,
165 CRYPTO_EX_DATA *ad);
166 /* Duplicate a CRYPTO_EX_DATA of a given class onto a copy */
167 int (*cb_dup_ex_data)(int class_index, CRYPTO_EX_DATA *to,
168 CRYPTO_EX_DATA *from);
169 /* Cleanup a CRYPTO_EX_DATA of a given class */
170 void (*cb_free_ex_data)(int class_index, void *obj,
171 CRYPTO_EX_DATA *ad);
172 };
173
174/* The implementation we use at run-time */
175static const CRYPTO_EX_DATA_IMPL *impl = NULL;
176
177/* To call "impl" functions, use this macro rather than referring to 'impl' directly, eg.
178 * EX_IMPL(get_new_index)(...); */
179#define EX_IMPL(a) impl->cb_##a
180
181/* Predeclare the "default" ex_data implementation */
182static int int_new_class(void);
183static void int_cleanup(void);
184static int int_get_new_index(int class_index, long argl, void *argp,
185 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
186 CRYPTO_EX_free *free_func);
187static int int_new_ex_data(int class_index, void *obj,
188 CRYPTO_EX_DATA *ad);
189static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
190 CRYPTO_EX_DATA *from);
191static void int_free_ex_data(int class_index, void *obj,
192 CRYPTO_EX_DATA *ad);
193static CRYPTO_EX_DATA_IMPL impl_default =
194 {
195 int_new_class,
196 int_cleanup,
197 int_get_new_index,
198 int_new_ex_data,
199 int_dup_ex_data,
200 int_free_ex_data
201 };
202
203/* Internal function that checks whether "impl" is set and if not, sets it to
204 * the default. */
205static void impl_check(void)
206 {
207 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
208 if(!impl)
209 impl = &impl_default;
210 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
211 }
212/* A macro wrapper for impl_check that first uses a non-locked test before
213 * invoking the function (which checks again inside a lock). */
214#define IMPL_CHECK if(!impl) impl_check();
215
216/* API functions to get/set the "ex_data" implementation */
217const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void)
218 {
219 IMPL_CHECK
220 return impl;
221 }
222int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i)
223 {
224 int toret = 0;
225 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
226 if(!impl)
227 {
228 impl = i;
229 toret = 1;
230 }
231 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
232 return toret;
233 }
234
235/****************************************************************************/
236/* Interal (default) implementation of "ex_data" support. API functions are
237 * further down. */
238
239/* The type that represents what each "class" used to implement locally. A STACK
240 * of CRYPTO_EX_DATA_FUNCS plus a index-counter. The 'class_index' is the global
241 * value representing the class that is used to distinguish these items. */
242typedef struct st_ex_class_item {
243 int class_index;
244 STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth;
245 int meth_num;
246} EX_CLASS_ITEM;
247
248/* When assigning new class indexes, this is our counter */
249static int ex_class = CRYPTO_EX_INDEX_USER;
250
251/* The global hash table of EX_CLASS_ITEM items */
252static LHASH *ex_data = NULL;
253
254/* The callbacks required in the "ex_data" hash table */
255static unsigned long ex_hash_cb(const void *a_void)
256 {
257 return ((const EX_CLASS_ITEM *)a_void)->class_index;
258 }
259static int ex_cmp_cb(const void *a_void, const void *b_void)
260 {
261 return (((const EX_CLASS_ITEM *)a_void)->class_index -
262 ((const EX_CLASS_ITEM *)b_void)->class_index);
263 }
264
265/* Internal functions used by the "impl_default" implementation to access the
266 * state */
267
268static int ex_data_check(void)
269 {
270 int toret = 1;
271 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
272 if(!ex_data && ((ex_data = lh_new(ex_hash_cb, ex_cmp_cb)) == NULL))
273 toret = 0;
274 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
275 return toret;
276 }
277/* This macros helps reduce the locking from repeated checks because the
278 * ex_data_check() function checks ex_data again inside a lock. */
279#define EX_DATA_CHECK(iffail) if(!ex_data && !ex_data_check()) {iffail}
280
281/* This "inner" callback is used by the callback function that follows it */
282static void def_cleanup_util_cb(CRYPTO_EX_DATA_FUNCS *funcs)
283 {
284 OPENSSL_free(funcs);
285 }
286
287/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from
288 * "ex_data" prior to the ex_data hash table being itself destroyed. Doesn't do
289 * any locking. */
290static void def_cleanup_cb(const void *a_void)
291 {
292 EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void;
293 sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb);
294 OPENSSL_free(item);
295 }
296
297/* Return the EX_CLASS_ITEM from the "ex_data" hash table that corresponds to a
298 * given class. Handles locking. */
299static EX_CLASS_ITEM *def_get_class(int class_index)
300 {
301 EX_CLASS_ITEM d, *p, *gen;
302 EX_DATA_CHECK(return NULL;)
303 d.class_index = class_index;
304 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
305 p = lh_retrieve(ex_data, &d);
306 if(!p)
307 {
308 gen = OPENSSL_malloc(sizeof(EX_CLASS_ITEM));
309 if(gen)
310 {
311 gen->class_index = class_index;
312 gen->meth_num = 0;
313 gen->meth = sk_CRYPTO_EX_DATA_FUNCS_new_null();
314 if(!gen->meth)
315 OPENSSL_free(gen);
316 else
317 {
318 /* Because we're inside the ex_data lock, the
319 * return value from the insert will be NULL */
320 lh_insert(ex_data, gen);
321 p = gen;
322 }
323 }
324 }
325 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
326 if(!p)
327 CRYPTOerr(CRYPTO_F_DEF_GET_CLASS,ERR_R_MALLOC_FAILURE);
328 return p;
329 }
330
331/* Add a new method to the given EX_CLASS_ITEM and return the corresponding
332 * index (or -1 for error). Handles locking. */
333static int def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
334 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
335 CRYPTO_EX_free *free_func)
336 {
337 int toret = -1;
338 CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)OPENSSL_malloc(
339 sizeof(CRYPTO_EX_DATA_FUNCS));
340 if(!a)
341 {
342 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX,ERR_R_MALLOC_FAILURE);
343 return -1;
344 }
345 a->argl=argl;
346 a->argp=argp;
347 a->new_func=new_func;
348 a->dup_func=dup_func;
349 a->free_func=free_func;
350 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
351 while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num)
352 {
353 if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL))
354 {
355 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX,ERR_R_MALLOC_FAILURE);
356 OPENSSL_free(a);
357 goto err;
358 }
359 }
360 toret = item->meth_num++;
361 sk_CRYPTO_EX_DATA_FUNCS_set(item->meth, toret, a);
362err:
363 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
364 return toret;
365 }
366
367/**************************************************************/
368/* The functions in the default CRYPTO_EX_DATA_IMPL structure */
369
370static int int_new_class(void)
371 {
372 int toret;
373 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
374 toret = ex_class++;
375 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
376 return toret;
377 }
378
379static void int_cleanup(void)
380 {
381 EX_DATA_CHECK(return;)
382 lh_doall(ex_data, def_cleanup_cb);
383 lh_free(ex_data);
384 ex_data = NULL;
385 impl = NULL;
386 }
387
388static int int_get_new_index(int class_index, long argl, void *argp,
389 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
390 CRYPTO_EX_free *free_func)
391 {
392 EX_CLASS_ITEM *item = def_get_class(class_index);
393 if(!item)
394 return -1;
395 return def_add_index(item, argl, argp, new_func, dup_func, free_func);
396 }
397
398/* Thread-safe by copying a class's array of "CRYPTO_EX_DATA_FUNCS" entries in
399 * the lock, then using them outside the lock. NB: Thread-safety only applies to
400 * the global "ex_data" state (ie. class definitions), not thread-safe on 'ad'
401 * itself. */
402static int int_new_ex_data(int class_index, void *obj,
403 CRYPTO_EX_DATA *ad)
404 {
405 int mx,i;
406 void *ptr;
407 CRYPTO_EX_DATA_FUNCS **storage = NULL;
408 EX_CLASS_ITEM *item = def_get_class(class_index);
409 if(!item)
410 /* error is already set */
411 return 0;
412 ad->sk = NULL;
413 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
414 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
415 if(mx > 0)
416 {
417 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
418 if(!storage)
419 goto skip;
420 for(i = 0; i < mx; i++)
421 storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i);
422 }
423skip:
424 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
425 if((mx > 0) && !storage)
426 {
427 CRYPTOerr(CRYPTO_F_INT_NEW_EX_DATA,ERR_R_MALLOC_FAILURE);
428 return 0;
429 }
430 for(i = 0; i < mx; i++)
431 {
432 if(storage[i] && storage[i]->new_func)
433 {
434 ptr = CRYPTO_get_ex_data(ad, i);
435 storage[i]->new_func(obj,ptr,ad,i,
436 storage[i]->argl,storage[i]->argp);
437 }
438 }
439 if(storage)
440 OPENSSL_free(storage);
441 return 1;
442 }
443
444/* Same thread-safety notes as for "int_new_ex_data" */
445static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
446 CRYPTO_EX_DATA *from)
447 {
448 int mx, j, i;
449 char *ptr;
450 CRYPTO_EX_DATA_FUNCS **storage = NULL;
451 EX_CLASS_ITEM *item;
452 if(!from->sk)
453 /* 'to' should be "blank" which *is* just like 'from' */
454 return 1;
455 if((item = def_get_class(class_index)) == NULL)
456 return 0;
457 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
458 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
459 j = sk_num(from->sk);
460 if(j < mx)
461 mx = j;
462 if(mx > 0)
463 {
464 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
465 if(!storage)
466 goto skip;
467 for(i = 0; i < mx; i++)
468 storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i);
469 }
470skip:
471 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
472 if((mx > 0) && !storage)
473 {
474 CRYPTOerr(CRYPTO_F_INT_DUP_EX_DATA,ERR_R_MALLOC_FAILURE);
475 return 0;
476 }
477 for(i = 0; i < mx; i++)
478 {
479 ptr = CRYPTO_get_ex_data(from, i);
480 if(storage[i] && storage[i]->dup_func)
481 storage[i]->dup_func(to,from,&ptr,i,
482 storage[i]->argl,storage[i]->argp);
483 CRYPTO_set_ex_data(to,i,ptr);
484 }
485 if(storage)
486 OPENSSL_free(storage);
487 return 1;
488 }
489
490/* Same thread-safety notes as for "int_new_ex_data" */
491static void int_free_ex_data(int class_index, void *obj,
492 CRYPTO_EX_DATA *ad)
493 {
494 int mx,i;
495 EX_CLASS_ITEM *item;
496 void *ptr;
497 CRYPTO_EX_DATA_FUNCS **storage = NULL;
498 if((item = def_get_class(class_index)) == NULL)
499 return;
500 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
501 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
502 if(mx > 0)
503 {
504 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
505 if(!storage)
506 goto skip;
507 for(i = 0; i < mx; i++)
508 storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i);
509 }
510skip:
511 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
512 if((mx > 0) && !storage)
513 {
514 CRYPTOerr(CRYPTO_F_INT_FREE_EX_DATA,ERR_R_MALLOC_FAILURE);
515 return;
516 }
517 for(i = 0; i < mx; i++)
518 {
519 if(storage[i] && storage[i]->free_func)
520 {
521 ptr = CRYPTO_get_ex_data(ad,i);
522 storage[i]->free_func(obj,ptr,ad,i,
523 storage[i]->argl,storage[i]->argp);
524 }
525 }
526 if(storage)
527 OPENSSL_free(storage);
528 if(ad->sk)
529 {
530 sk_free(ad->sk);
531 ad->sk=NULL;
532 }
533 }
534
535/********************************************************************/
536/* API functions that defer all "state" operations to the "ex_data"
537 * implementation we have set. */
538
539/* Obtain an index for a new class (not the same as getting a new index within
540 * an existing class - this is actually getting a new *class*) */
541int CRYPTO_ex_data_new_class(void)
542 {
543 IMPL_CHECK
544 return EX_IMPL(new_class)();
545 }
546
547/* Release all "ex_data" state to prevent memory leaks. This can't be made
548 * thread-safe without overhauling a lot of stuff, and shouldn't really be
549 * called under potential race-conditions anyway (it's for program shutdown
550 * after all). */
551void CRYPTO_cleanup_all_ex_data(void)
552 {
553 IMPL_CHECK
554 EX_IMPL(cleanup)();
555 }
556
557/* Inside an existing class, get/register a new index. */
558int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
559 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
560 CRYPTO_EX_free *free_func)
561 {
562 int ret = -1;
563
564 IMPL_CHECK
565 ret = EX_IMPL(get_new_index)(class_index,
566 argl, argp, new_func, dup_func, free_func);
567 return ret;
568 }
569
570/* Initialise a new CRYPTO_EX_DATA for use in a particular class - including
571 * calling new() callbacks for each index in the class used by this variable */
572int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
573 {
574 IMPL_CHECK
575 return EX_IMPL(new_ex_data)(class_index, obj, ad);
576 }
577
578/* Duplicate a CRYPTO_EX_DATA variable - including calling dup() callbacks for
579 * each index in the class used by this variable */
580int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
581 CRYPTO_EX_DATA *from)
582 {
583 IMPL_CHECK
584 return EX_IMPL(dup_ex_data)(class_index, to, from);
585 }
586
587/* Cleanup a CRYPTO_EX_DATA variable - including calling free() callbacks for
588 * each index in the class used by this variable */
589void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
590 {
591 IMPL_CHECK
592 EX_IMPL(free_ex_data)(class_index, obj, ad);
593 }
594
595/* For a given CRYPTO_EX_DATA variable, set the value corresponding to a
596 * particular index in the class used by this variable */
597int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
598 {
599 int i;
600
601 if (ad->sk == NULL)
602 {
603 if ((ad->sk=sk_new_null()) == NULL)
604 {
605 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
606 return(0);
607 }
608 }
609 i=sk_num(ad->sk);
610
611 while (i <= idx)
612 {
613 if (!sk_push(ad->sk,NULL))
614 {
615 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
616 return(0);
617 }
618 i++;
619 }
620 sk_set(ad->sk,idx,val);
621 return(1);
622 }
623
624/* For a given CRYPTO_EX_DATA_ variable, get the value corresponding to a
625 * particular index in the class used by this variable */
626void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
627 {
628 if (ad->sk == NULL)
629 return(0);
630 else if (idx >= sk_num(ad->sk))
631 return(0);
632 else
633 return(sk_value(ad->sk,idx));
634 }
635
636IMPLEMENT_STACK_OF(CRYPTO_EX_DATA_FUNCS)
diff --git a/src/lib/libcrypto/hmac/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
new file mode 100644
index 0000000000..06ee80761f
--- /dev/null
+++ b/src/lib/libcrypto/hmac/hmac.c
@@ -0,0 +1,189 @@
1/* crypto/hmac/hmac.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <openssl/hmac.h>
62#include "cryptlib.h"
63
64void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
65 const EVP_MD *md, ENGINE *impl)
66 {
67 int i,j,reset=0;
68 unsigned char pad[HMAC_MAX_MD_CBLOCK];
69
70 if (md != NULL)
71 {
72 reset=1;
73 ctx->md=md;
74 }
75 else
76 md=ctx->md;
77
78 if (key != NULL)
79 {
80#ifdef OPENSSL_FIPS
81 if (FIPS_mode() && !(md->flags & EVP_MD_FLAG_FIPS)
82 && (!(ctx->md_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
83 || !(ctx->i_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
84 || !(ctx->o_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)))
85 OpenSSLDie(__FILE__,__LINE__,
86 "HMAC: digest not allowed in FIPS mode");
87#endif
88
89 reset=1;
90 j=EVP_MD_block_size(md);
91 OPENSSL_assert(j <= sizeof ctx->key);
92 if (j < len)
93 {
94 EVP_DigestInit_ex(&ctx->md_ctx,md, impl);
95 EVP_DigestUpdate(&ctx->md_ctx,key,len);
96 EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key,
97 &ctx->key_length);
98 }
99 else
100 {
101 OPENSSL_assert(len <= sizeof ctx->key);
102 memcpy(ctx->key,key,len);
103 ctx->key_length=len;
104 }
105 if(ctx->key_length != HMAC_MAX_MD_CBLOCK)
106 memset(&ctx->key[ctx->key_length], 0,
107 HMAC_MAX_MD_CBLOCK - ctx->key_length);
108 }
109
110 if (reset)
111 {
112 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
113 pad[i]=0x36^ctx->key[i];
114 EVP_DigestInit_ex(&ctx->i_ctx,md, impl);
115 EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md));
116
117 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
118 pad[i]=0x5c^ctx->key[i];
119 EVP_DigestInit_ex(&ctx->o_ctx,md, impl);
120 EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md));
121 }
122 EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx);
123 }
124
125void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
126 const EVP_MD *md)
127 {
128 if(key && md)
129 HMAC_CTX_init(ctx);
130 HMAC_Init_ex(ctx,key,len,md, NULL);
131 }
132
133void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len)
134 {
135 EVP_DigestUpdate(&ctx->md_ctx,data,len);
136 }
137
138void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
139 {
140 int j;
141 unsigned int i;
142 unsigned char buf[EVP_MAX_MD_SIZE];
143
144 j=EVP_MD_block_size(ctx->md);
145
146 EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i);
147 EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx);
148 EVP_DigestUpdate(&ctx->md_ctx,buf,i);
149 EVP_DigestFinal_ex(&ctx->md_ctx,md,len);
150 }
151
152void HMAC_CTX_init(HMAC_CTX *ctx)
153 {
154 EVP_MD_CTX_init(&ctx->i_ctx);
155 EVP_MD_CTX_init(&ctx->o_ctx);
156 EVP_MD_CTX_init(&ctx->md_ctx);
157 }
158
159void HMAC_CTX_cleanup(HMAC_CTX *ctx)
160 {
161 EVP_MD_CTX_cleanup(&ctx->i_ctx);
162 EVP_MD_CTX_cleanup(&ctx->o_ctx);
163 EVP_MD_CTX_cleanup(&ctx->md_ctx);
164 memset(ctx,0,sizeof *ctx);
165 }
166
167unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
168 const unsigned char *d, int n, unsigned char *md,
169 unsigned int *md_len)
170 {
171 HMAC_CTX c;
172 static unsigned char m[EVP_MAX_MD_SIZE];
173
174 if (md == NULL) md=m;
175 HMAC_CTX_init(&c);
176 HMAC_Init(&c,key,key_len,evp_md);
177 HMAC_Update(&c,d,n);
178 HMAC_Final(&c,md,md_len);
179 HMAC_CTX_cleanup(&c);
180 return(md);
181 }
182
183void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
184 {
185 EVP_MD_CTX_set_flags(&ctx->i_ctx, flags);
186 EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
187 EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
188 }
189
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
new file mode 100644
index 0000000000..294ab3b36a
--- /dev/null
+++ b/src/lib/libcrypto/hmac/hmac.h
@@ -0,0 +1,107 @@
1/* crypto/hmac/hmac.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#ifndef HEADER_HMAC_H
59#define HEADER_HMAC_H
60
61#ifdef OPENSSL_NO_HMAC
62#error HMAC is disabled.
63#endif
64
65#include <openssl/evp.h>
66
67#define HMAC_MAX_MD_CBLOCK 64
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73typedef struct hmac_ctx_st
74 {
75 const EVP_MD *md;
76 EVP_MD_CTX md_ctx;
77 EVP_MD_CTX i_ctx;
78 EVP_MD_CTX o_ctx;
79 unsigned int key_length;
80 unsigned char key[HMAC_MAX_MD_CBLOCK];
81 } HMAC_CTX;
82
83#define HMAC_size(e) (EVP_MD_size((e)->md))
84
85
86void HMAC_CTX_init(HMAC_CTX *ctx);
87void HMAC_CTX_cleanup(HMAC_CTX *ctx);
88
89#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */
90
91void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
92 const EVP_MD *md); /* deprecated */
93void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
94 const EVP_MD *md, ENGINE *impl);
95void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
96void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
97unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
98 const unsigned char *d, int n, unsigned char *md,
99 unsigned int *md_len);
100
101void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
102
103#ifdef __cplusplus
104}
105#endif
106
107#endif
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
new file mode 100644
index 0000000000..bf41844fd7
--- /dev/null
+++ b/src/lib/libcrypto/idea/idea.h
@@ -0,0 +1,103 @@
1/* crypto/idea/idea.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_IDEA_H
60#define HEADER_IDEA_H
61
62#ifdef OPENSSL_NO_IDEA
63#error IDEA is disabled.
64#endif
65
66#define IDEA_ENCRYPT 1
67#define IDEA_DECRYPT 0
68
69#include <openssl/opensslconf.h> /* IDEA_INT */
70#define IDEA_BLOCK 8
71#define IDEA_KEY_LENGTH 16
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77typedef struct idea_key_st
78 {
79 IDEA_INT data[9][6];
80 } IDEA_KEY_SCHEDULE;
81
82const char *idea_options(void);
83void idea_ecb_encrypt(const unsigned char *in, unsigned char *out,
84 IDEA_KEY_SCHEDULE *ks);
85#ifdef OPENSSL_FIPS
86void private_idea_set_encrypt_key(const unsigned char *key,
87 IDEA_KEY_SCHEDULE *ks);
88#endif
89void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);
90void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
91void idea_cbc_encrypt(const unsigned char *in, unsigned char *out,
92 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
93void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,
94 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
95 int *num,int enc);
96void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out,
97 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);
98void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
99#ifdef __cplusplus
100}
101#endif
102
103#endif
diff --git a/src/lib/libcrypto/krb5/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.c b/src/lib/libcrypto/krb5/krb5_asn.c
new file mode 100644
index 0000000000..1fb741d2a0
--- /dev/null
+++ b/src/lib/libcrypto/krb5/krb5_asn.c
@@ -0,0 +1,167 @@
1/* krb5_asn.c */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,
3** using ocsp/{*.h,*asn*.c} as a starting point
4*/
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/krb5_asn.h>
61
62
63ASN1_SEQUENCE(KRB5_ENCDATA) = {
64 ASN1_EXP(KRB5_ENCDATA, etype, ASN1_INTEGER, 0),
65 ASN1_EXP_OPT(KRB5_ENCDATA, kvno, ASN1_INTEGER, 1),
66 ASN1_EXP(KRB5_ENCDATA, cipher, ASN1_OCTET_STRING,2)
67} ASN1_SEQUENCE_END(KRB5_ENCDATA)
68
69IMPLEMENT_ASN1_FUNCTIONS(KRB5_ENCDATA)
70
71
72ASN1_SEQUENCE(KRB5_PRINCNAME) = {
73 ASN1_EXP(KRB5_PRINCNAME, nametype, ASN1_INTEGER, 0),
74 ASN1_EXP_SEQUENCE_OF(KRB5_PRINCNAME, namestring, ASN1_GENERALSTRING, 1)
75} ASN1_SEQUENCE_END(KRB5_PRINCNAME)
76
77IMPLEMENT_ASN1_FUNCTIONS(KRB5_PRINCNAME)
78
79
80/* [APPLICATION 1] = 0x61 */
81ASN1_SEQUENCE(KRB5_TKTBODY) = {
82 ASN1_EXP(KRB5_TKTBODY, tktvno, ASN1_INTEGER, 0),
83 ASN1_EXP(KRB5_TKTBODY, realm, ASN1_GENERALSTRING, 1),
84 ASN1_EXP(KRB5_TKTBODY, sname, KRB5_PRINCNAME, 2),
85 ASN1_EXP(KRB5_TKTBODY, encdata, KRB5_ENCDATA, 3)
86} ASN1_SEQUENCE_END(KRB5_TKTBODY)
87
88IMPLEMENT_ASN1_FUNCTIONS(KRB5_TKTBODY)
89
90
91ASN1_ITEM_TEMPLATE(KRB5_TICKET) =
92 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 1,
93 KRB5_TICKET, KRB5_TKTBODY)
94ASN1_ITEM_TEMPLATE_END(KRB5_TICKET)
95
96IMPLEMENT_ASN1_FUNCTIONS(KRB5_TICKET)
97
98
99/* [APPLICATION 14] = 0x6e */
100ASN1_SEQUENCE(KRB5_APREQBODY) = {
101 ASN1_EXP(KRB5_APREQBODY, pvno, ASN1_INTEGER, 0),
102 ASN1_EXP(KRB5_APREQBODY, msgtype, ASN1_INTEGER, 1),
103 ASN1_EXP(KRB5_APREQBODY, apoptions, ASN1_BIT_STRING, 2),
104 ASN1_EXP(KRB5_APREQBODY, ticket, KRB5_TICKET, 3),
105 ASN1_EXP(KRB5_APREQBODY, authenticator, KRB5_ENCDATA, 4),
106} ASN1_SEQUENCE_END(KRB5_APREQBODY)
107
108IMPLEMENT_ASN1_FUNCTIONS(KRB5_APREQBODY)
109
110ASN1_ITEM_TEMPLATE(KRB5_APREQ) =
111 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 14,
112 KRB5_APREQ, KRB5_APREQBODY)
113ASN1_ITEM_TEMPLATE_END(KRB5_APREQ)
114
115IMPLEMENT_ASN1_FUNCTIONS(KRB5_APREQ)
116
117
118/* Authenticator stuff */
119
120ASN1_SEQUENCE(KRB5_CHECKSUM) = {
121 ASN1_EXP(KRB5_CHECKSUM, ctype, ASN1_INTEGER, 0),
122 ASN1_EXP(KRB5_CHECKSUM, checksum, ASN1_OCTET_STRING,1)
123} ASN1_SEQUENCE_END(KRB5_CHECKSUM)
124
125IMPLEMENT_ASN1_FUNCTIONS(KRB5_CHECKSUM)
126
127
128ASN1_SEQUENCE(KRB5_ENCKEY) = {
129 ASN1_EXP(KRB5_ENCKEY, ktype, ASN1_INTEGER, 0),
130 ASN1_EXP(KRB5_ENCKEY, keyvalue, ASN1_OCTET_STRING,1)
131} ASN1_SEQUENCE_END(KRB5_ENCKEY)
132
133IMPLEMENT_ASN1_FUNCTIONS(KRB5_ENCKEY)
134
135
136/* SEQ OF SEQ; see ASN1_EXP_SEQUENCE_OF_OPT() below */
137ASN1_SEQUENCE(KRB5_AUTHDATA) = {
138 ASN1_EXP(KRB5_AUTHDATA, adtype, ASN1_INTEGER, 0),
139 ASN1_EXP(KRB5_AUTHDATA, addata, ASN1_OCTET_STRING,1)
140} ASN1_SEQUENCE_END(KRB5_AUTHDATA)
141
142IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHDATA)
143
144
145/* [APPLICATION 2] = 0x62 */
146ASN1_SEQUENCE(KRB5_AUTHENTBODY) = {
147 ASN1_EXP(KRB5_AUTHENTBODY, avno, ASN1_INTEGER, 0),
148 ASN1_EXP(KRB5_AUTHENTBODY, crealm, ASN1_GENERALSTRING, 1),
149 ASN1_EXP(KRB5_AUTHENTBODY, cname, KRB5_PRINCNAME, 2),
150 ASN1_EXP_OPT(KRB5_AUTHENTBODY, cksum, KRB5_CHECKSUM, 3),
151 ASN1_EXP(KRB5_AUTHENTBODY, cusec, ASN1_INTEGER, 4),
152 ASN1_EXP(KRB5_AUTHENTBODY, ctime, ASN1_GENERALIZEDTIME, 5),
153 ASN1_EXP_OPT(KRB5_AUTHENTBODY, subkey, KRB5_ENCKEY, 6),
154 ASN1_EXP_OPT(KRB5_AUTHENTBODY, seqnum, ASN1_INTEGER, 7),
155 ASN1_EXP_SEQUENCE_OF_OPT
156 (KRB5_AUTHENTBODY, authorization, KRB5_AUTHDATA, 8),
157} ASN1_SEQUENCE_END(KRB5_AUTHENTBODY)
158
159IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)
160
161ASN1_ITEM_TEMPLATE(KRB5_AUTHENT) =
162 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 2,
163 KRB5_AUTHENT, KRB5_AUTHENTBODY)
164ASN1_ITEM_TEMPLATE_END(KRB5_AUTHENT)
165
166IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHENT)
167
diff --git a/src/lib/libcrypto/krb5/krb5_asn.h b/src/lib/libcrypto/krb5/krb5_asn.h
new file mode 100644
index 0000000000..3329477b07
--- /dev/null
+++ b/src/lib/libcrypto/krb5/krb5_asn.h
@@ -0,0 +1,256 @@
1/* krb5_asn.h */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,
3** using ocsp/{*.h,*asn*.c} as a starting point
4*/
5
6/* ====================================================================
7 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_KRB5_ASN_H
61#define HEADER_KRB5_ASN_H
62
63/*
64#include <krb5.h>
65*/
66#include <openssl/safestack.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72
73/* ASN.1 from Kerberos RFC 1510
74*/
75
76/* EncryptedData ::= SEQUENCE {
77** etype[0] INTEGER, -- EncryptionType
78** kvno[1] INTEGER OPTIONAL,
79** cipher[2] OCTET STRING -- ciphertext
80** }
81*/
82typedef struct krb5_encdata_st
83 {
84 ASN1_INTEGER *etype;
85 ASN1_INTEGER *kvno;
86 ASN1_OCTET_STRING *cipher;
87 } KRB5_ENCDATA;
88
89DECLARE_STACK_OF(KRB5_ENCDATA)
90
91/* PrincipalName ::= SEQUENCE {
92** name-type[0] INTEGER,
93** name-string[1] SEQUENCE OF GeneralString
94** }
95*/
96typedef struct krb5_princname_st
97 {
98 ASN1_INTEGER *nametype;
99 STACK_OF(ASN1_GENERALSTRING) *namestring;
100 } KRB5_PRINCNAME;
101
102DECLARE_STACK_OF(KRB5_PRINCNAME)
103
104
105/* Ticket ::= [APPLICATION 1] SEQUENCE {
106** tkt-vno[0] INTEGER,
107** realm[1] Realm,
108** sname[2] PrincipalName,
109** enc-part[3] EncryptedData
110** }
111*/
112typedef struct krb5_tktbody_st
113 {
114 ASN1_INTEGER *tktvno;
115 ASN1_GENERALSTRING *realm;
116 KRB5_PRINCNAME *sname;
117 KRB5_ENCDATA *encdata;
118 } KRB5_TKTBODY;
119
120typedef STACK_OF(KRB5_TKTBODY) KRB5_TICKET;
121DECLARE_STACK_OF(KRB5_TKTBODY)
122
123
124/* AP-REQ ::= [APPLICATION 14] SEQUENCE {
125** pvno[0] INTEGER,
126** msg-type[1] INTEGER,
127** ap-options[2] APOptions,
128** ticket[3] Ticket,
129** authenticator[4] EncryptedData
130** }
131**
132** APOptions ::= BIT STRING {
133** reserved(0), use-session-key(1), mutual-required(2) }
134*/
135typedef struct krb5_ap_req_st
136 {
137 ASN1_INTEGER *pvno;
138 ASN1_INTEGER *msgtype;
139 ASN1_BIT_STRING *apoptions;
140 KRB5_TICKET *ticket;
141 KRB5_ENCDATA *authenticator;
142 } KRB5_APREQBODY;
143
144typedef STACK_OF(KRB5_APREQBODY) KRB5_APREQ;
145DECLARE_STACK_OF(KRB5_APREQBODY)
146
147
148/* Authenticator Stuff */
149
150
151/* Checksum ::= SEQUENCE {
152** cksumtype[0] INTEGER,
153** checksum[1] OCTET STRING
154** }
155*/
156typedef struct krb5_checksum_st
157 {
158 ASN1_INTEGER *ctype;
159 ASN1_OCTET_STRING *checksum;
160 } KRB5_CHECKSUM;
161
162DECLARE_STACK_OF(KRB5_CHECKSUM)
163
164
165/* EncryptionKey ::= SEQUENCE {
166** keytype[0] INTEGER,
167** keyvalue[1] OCTET STRING
168** }
169*/
170typedef struct krb5_encryptionkey_st
171 {
172 ASN1_INTEGER *ktype;
173 ASN1_OCTET_STRING *keyvalue;
174 } KRB5_ENCKEY;
175
176DECLARE_STACK_OF(KRB5_ENCKEY)
177
178
179/* AuthorizationData ::= SEQUENCE OF SEQUENCE {
180** ad-type[0] INTEGER,
181** ad-data[1] OCTET STRING
182** }
183*/
184typedef struct krb5_authorization_st
185 {
186 ASN1_INTEGER *adtype;
187 ASN1_OCTET_STRING *addata;
188 } KRB5_AUTHDATA;
189
190DECLARE_STACK_OF(KRB5_AUTHDATA)
191
192
193/* -- Unencrypted authenticator
194** Authenticator ::= [APPLICATION 2] SEQUENCE {
195** authenticator-vno[0] INTEGER,
196** crealm[1] Realm,
197** cname[2] PrincipalName,
198** cksum[3] Checksum OPTIONAL,
199** cusec[4] INTEGER,
200** ctime[5] KerberosTime,
201** subkey[6] EncryptionKey OPTIONAL,
202** seq-number[7] INTEGER OPTIONAL,
203** authorization-data[8] AuthorizationData OPTIONAL
204** }
205*/
206typedef struct krb5_authenticator_st
207 {
208 ASN1_INTEGER *avno;
209 ASN1_GENERALSTRING *crealm;
210 KRB5_PRINCNAME *cname;
211 KRB5_CHECKSUM *cksum;
212 ASN1_INTEGER *cusec;
213 ASN1_GENERALIZEDTIME *ctime;
214 KRB5_ENCKEY *subkey;
215 ASN1_INTEGER *seqnum;
216 KRB5_AUTHDATA *authorization;
217 } KRB5_AUTHENTBODY;
218
219typedef STACK_OF(KRB5_AUTHENTBODY) KRB5_AUTHENT;
220DECLARE_STACK_OF(KRB5_AUTHENTBODY)
221
222
223/* DECLARE_ASN1_FUNCTIONS(type) = DECLARE_ASN1_FUNCTIONS_name(type, type) =
224** type *name##_new(void);
225** void name##_free(type *a);
226** DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) =
227** DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) =
228** type *d2i_##name(type **a, unsigned char **in, long len);
229** int i2d_##name(type *a, unsigned char **out);
230** DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it
231*/
232
233DECLARE_ASN1_FUNCTIONS(KRB5_ENCDATA)
234DECLARE_ASN1_FUNCTIONS(KRB5_PRINCNAME)
235DECLARE_ASN1_FUNCTIONS(KRB5_TKTBODY)
236DECLARE_ASN1_FUNCTIONS(KRB5_APREQBODY)
237DECLARE_ASN1_FUNCTIONS(KRB5_TICKET)
238DECLARE_ASN1_FUNCTIONS(KRB5_APREQ)
239
240DECLARE_ASN1_FUNCTIONS(KRB5_CHECKSUM)
241DECLARE_ASN1_FUNCTIONS(KRB5_ENCKEY)
242DECLARE_ASN1_FUNCTIONS(KRB5_AUTHDATA)
243DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)
244DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENT)
245
246
247/* BEGIN ERROR CODES */
248/* The following lines are auto generated by the script mkerr.pl. Any changes
249 * made after this point may be overwritten when the script is next run.
250 */
251
252#ifdef __cplusplus
253}
254#endif
255#endif
256
diff --git a/src/lib/libcrypto/lhash/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_stats.c b/src/lib/libcrypto/lhash/lh_stats.c
new file mode 100644
index 0000000000..5aa7766aa6
--- /dev/null
+++ b/src/lib/libcrypto/lhash/lh_stats.c
@@ -0,0 +1,248 @@
1/* crypto/lhash/lh_stats.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62/* If you wish to build this outside of SSLeay, remove the following lines
63 * and things should work as expected */
64#include "cryptlib.h"
65
66#ifndef OPENSSL_NO_BIO
67#include <openssl/bio.h>
68#endif
69#include <openssl/lhash.h>
70
71#ifdef OPENSSL_NO_BIO
72
73void lh_stats(LHASH *lh, FILE *out)
74 {
75 fprintf(out,"num_items = %lu\n",lh->num_items);
76 fprintf(out,"num_nodes = %u\n",lh->num_nodes);
77 fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
78 fprintf(out,"num_expands = %lu\n",lh->num_expands);
79 fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
80 fprintf(out,"num_contracts = %lu\n",lh->num_contracts);
81 fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
82 fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
83 fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
84 fprintf(out,"num_insert = %lu\n",lh->num_insert);
85 fprintf(out,"num_replace = %lu\n",lh->num_replace);
86 fprintf(out,"num_delete = %lu\n",lh->num_delete);
87 fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete);
88 fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve);
89 fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
90 fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
91#if 0
92 fprintf(out,"p = %u\n",lh->p);
93 fprintf(out,"pmax = %u\n",lh->pmax);
94 fprintf(out,"up_load = %lu\n",lh->up_load);
95 fprintf(out,"down_load = %lu\n",lh->down_load);
96#endif
97 }
98
99void lh_node_stats(LHASH *lh, FILE *out)
100 {
101 LHASH_NODE *n;
102 unsigned int i,num;
103
104 for (i=0; i<lh->num_nodes; i++)
105 {
106 for (n=lh->b[i],num=0; n != NULL; n=n->next)
107 num++;
108 fprintf(out,"node %6u -> %3u\n",i,num);
109 }
110 }
111
112void lh_node_usage_stats(LHASH *lh, FILE *out)
113 {
114 LHASH_NODE *n;
115 unsigned long num;
116 unsigned int i;
117 unsigned long total=0,n_used=0;
118
119 for (i=0; i<lh->num_nodes; i++)
120 {
121 for (n=lh->b[i],num=0; n != NULL; n=n->next)
122 num++;
123 if (num != 0)
124 {
125 n_used++;
126 total+=num;
127 }
128 }
129 fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
130 fprintf(out,"%lu items\n",total);
131 if (n_used == 0) return;
132 fprintf(out,"load %d.%02d actual load %d.%02d\n",
133 (int)(total/lh->num_nodes),
134 (int)((total%lh->num_nodes)*100/lh->num_nodes),
135 (int)(total/n_used),
136 (int)((total%n_used)*100/n_used));
137 }
138
139#else
140
141#ifndef OPENSSL_NO_FP_API
142void lh_stats(const LHASH *lh, FILE *fp)
143 {
144 BIO *bp;
145
146 bp=BIO_new(BIO_s_file());
147 if (bp == NULL) goto end;
148 BIO_set_fp(bp,fp,BIO_NOCLOSE);
149 lh_stats_bio(lh,bp);
150 BIO_free(bp);
151end:;
152 }
153
154void lh_node_stats(const LHASH *lh, FILE *fp)
155 {
156 BIO *bp;
157
158 bp=BIO_new(BIO_s_file());
159 if (bp == NULL) goto end;
160 BIO_set_fp(bp,fp,BIO_NOCLOSE);
161 lh_node_stats_bio(lh,bp);
162 BIO_free(bp);
163end:;
164 }
165
166void lh_node_usage_stats(const LHASH *lh, FILE *fp)
167 {
168 BIO *bp;
169
170 bp=BIO_new(BIO_s_file());
171 if (bp == NULL) goto end;
172 BIO_set_fp(bp,fp,BIO_NOCLOSE);
173 lh_node_usage_stats_bio(lh,bp);
174 BIO_free(bp);
175end:;
176 }
177
178#endif
179
180void lh_stats_bio(const LHASH *lh, BIO *out)
181 {
182 BIO_printf(out,"num_items = %lu\n",lh->num_items);
183 BIO_printf(out,"num_nodes = %u\n",lh->num_nodes);
184 BIO_printf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
185 BIO_printf(out,"num_expands = %lu\n",lh->num_expands);
186 BIO_printf(out,"num_expand_reallocs = %lu\n",
187 lh->num_expand_reallocs);
188 BIO_printf(out,"num_contracts = %lu\n",lh->num_contracts);
189 BIO_printf(out,"num_contract_reallocs = %lu\n",
190 lh->num_contract_reallocs);
191 BIO_printf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
192 BIO_printf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
193 BIO_printf(out,"num_insert = %lu\n",lh->num_insert);
194 BIO_printf(out,"num_replace = %lu\n",lh->num_replace);
195 BIO_printf(out,"num_delete = %lu\n",lh->num_delete);
196 BIO_printf(out,"num_no_delete = %lu\n",lh->num_no_delete);
197 BIO_printf(out,"num_retrieve = %lu\n",lh->num_retrieve);
198 BIO_printf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
199 BIO_printf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
200#if 0
201 BIO_printf(out,"p = %u\n",lh->p);
202 BIO_printf(out,"pmax = %u\n",lh->pmax);
203 BIO_printf(out,"up_load = %lu\n",lh->up_load);
204 BIO_printf(out,"down_load = %lu\n",lh->down_load);
205#endif
206 }
207
208void lh_node_stats_bio(const LHASH *lh, BIO *out)
209 {
210 LHASH_NODE *n;
211 unsigned int i,num;
212
213 for (i=0; i<lh->num_nodes; i++)
214 {
215 for (n=lh->b[i],num=0; n != NULL; n=n->next)
216 num++;
217 BIO_printf(out,"node %6u -> %3u\n",i,num);
218 }
219 }
220
221void lh_node_usage_stats_bio(const LHASH *lh, BIO *out)
222 {
223 LHASH_NODE *n;
224 unsigned long num;
225 unsigned int i;
226 unsigned long total=0,n_used=0;
227
228 for (i=0; i<lh->num_nodes; i++)
229 {
230 for (n=lh->b[i],num=0; n != NULL; n=n->next)
231 num++;
232 if (num != 0)
233 {
234 n_used++;
235 total+=num;
236 }
237 }
238 BIO_printf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
239 BIO_printf(out,"%lu items\n",total);
240 if (n_used == 0) return;
241 BIO_printf(out,"load %d.%02d actual load %d.%02d\n",
242 (int)(total/lh->num_nodes),
243 (int)((total%lh->num_nodes)*100/lh->num_nodes),
244 (int)(total/n_used),
245 (int)((total%n_used)*100/n_used));
246 }
247
248#endif
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
new file mode 100644
index 0000000000..0a16fcf27d
--- /dev/null
+++ b/src/lib/libcrypto/lhash/lhash.c
@@ -0,0 +1,470 @@
1/* crypto/lhash/lhash.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Code for dynamic hash table routines
60 * Author - Eric Young v 2.0
61 *
62 * 2.2 eay - added #include "crypto.h" so the memory leak checking code is
63 * present. eay 18-Jun-98
64 *
65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
66 *
67 * 2.0 eay - Fixed a bug that occurred when using lh_delete
68 * from inside lh_doall(). As entries were deleted,
69 * the 'table' was 'contract()ed', making some entries
70 * jump from the end of the table to the start, there by
71 * skipping the lh_doall() processing. eay - 4/12/95
72 *
73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
74 * were not being free()ed. 21/11/95
75 *
76 * 1.8 eay - Put the stats routines into a separate file, lh_stats.c
77 * 19/09/95
78 *
79 * 1.7 eay - Removed the fputs() for realloc failures - the code
80 * should silently tolerate them. I have also fixed things
81 * lint complained about 04/05/95
82 *
83 * 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92
84 *
85 * 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992
86 *
87 * 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91
88 *
89 * 1.3 eay - Fixed a few lint problems 19/3/1991
90 *
91 * 1.2 eay - Fixed lh_doall problem 13/3/1991
92 *
93 * 1.1 eay - Added lh_doall
94 *
95 * 1.0 eay - First version
96 */
97#include <stdio.h>
98#include <string.h>
99#include <stdlib.h>
100#include <openssl/crypto.h>
101#include <openssl/lhash.h>
102
103const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
104
105#undef MIN_NODES
106#define MIN_NODES 16
107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
109
110static void expand(LHASH *lh);
111static void contract(LHASH *lh);
112static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash);
113
114LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
115 {
116 LHASH *ret;
117 int i;
118
119 if ((ret=(LHASH *)OPENSSL_malloc(sizeof(LHASH))) == NULL)
120 goto err0;
121 if ((ret->b=(LHASH_NODE **)OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
122 goto err1;
123 for (i=0; i<MIN_NODES; i++)
124 ret->b[i]=NULL;
125 ret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);
126 ret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);
127 ret->num_nodes=MIN_NODES/2;
128 ret->num_alloc_nodes=MIN_NODES;
129 ret->p=0;
130 ret->pmax=MIN_NODES/2;
131 ret->up_load=UP_LOAD;
132 ret->down_load=DOWN_LOAD;
133 ret->num_items=0;
134
135 ret->num_expands=0;
136 ret->num_expand_reallocs=0;
137 ret->num_contracts=0;
138 ret->num_contract_reallocs=0;
139 ret->num_hash_calls=0;
140 ret->num_comp_calls=0;
141 ret->num_insert=0;
142 ret->num_replace=0;
143 ret->num_delete=0;
144 ret->num_no_delete=0;
145 ret->num_retrieve=0;
146 ret->num_retrieve_miss=0;
147 ret->num_hash_comps=0;
148
149 ret->error=0;
150 return(ret);
151err1:
152 OPENSSL_free(ret);
153err0:
154 return(NULL);
155 }
156
157void lh_free(LHASH *lh)
158 {
159 unsigned int i;
160 LHASH_NODE *n,*nn;
161
162 if (lh == NULL)
163 return;
164
165 for (i=0; i<lh->num_nodes; i++)
166 {
167 n=lh->b[i];
168 while (n != NULL)
169 {
170 nn=n->next;
171 OPENSSL_free(n);
172 n=nn;
173 }
174 }
175 OPENSSL_free(lh->b);
176 OPENSSL_free(lh);
177 }
178
179void *lh_insert(LHASH *lh, const void *data)
180 {
181 unsigned long hash;
182 LHASH_NODE *nn,**rn;
183 const void *ret;
184
185 lh->error=0;
186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
187 expand(lh);
188
189 rn=getrn(lh,data,&hash);
190
191 if (*rn == NULL)
192 {
193 if ((nn=(LHASH_NODE *)OPENSSL_malloc(sizeof(LHASH_NODE))) == NULL)
194 {
195 lh->error++;
196 return(NULL);
197 }
198 nn->data=data;
199 nn->next=NULL;
200#ifndef OPENSSL_NO_HASH_COMP
201 nn->hash=hash;
202#endif
203 *rn=nn;
204 ret=NULL;
205 lh->num_insert++;
206 lh->num_items++;
207 }
208 else /* replace same key */
209 {
210 ret= (*rn)->data;
211 (*rn)->data=data;
212 lh->num_replace++;
213 }
214 return((void *)ret);
215 }
216
217void *lh_delete(LHASH *lh, const void *data)
218 {
219 unsigned long hash;
220 LHASH_NODE *nn,**rn;
221 const void *ret;
222
223 lh->error=0;
224 rn=getrn(lh,data,&hash);
225
226 if (*rn == NULL)
227 {
228 lh->num_no_delete++;
229 return(NULL);
230 }
231 else
232 {
233 nn= *rn;
234 *rn=nn->next;
235 ret=nn->data;
236 OPENSSL_free(nn);
237 lh->num_delete++;
238 }
239
240 lh->num_items--;
241 if ((lh->num_nodes > MIN_NODES) &&
242 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
243 contract(lh);
244
245 return((void *)ret);
246 }
247
248void *lh_retrieve(LHASH *lh, const void *data)
249 {
250 unsigned long hash;
251 LHASH_NODE **rn;
252 const void *ret;
253
254 lh->error=0;
255 rn=getrn(lh,data,&hash);
256
257 if (*rn == NULL)
258 {
259 lh->num_retrieve_miss++;
260 return(NULL);
261 }
262 else
263 {
264 ret= (*rn)->data;
265 lh->num_retrieve++;
266 }
267 return((void *)ret);
268 }
269
270static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
271 LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)
272 {
273 int i;
274 LHASH_NODE *a,*n;
275
276 /* reverse the order so we search from 'top to bottom'
277 * We were having memory leaks otherwise */
278 for (i=lh->num_nodes-1; i>=0; i--)
279 {
280 a=lh->b[i];
281 while (a != NULL)
282 {
283 /* 28/05/91 - eay - n added so items can be deleted
284 * via lh_doall */
285 n=a->next;
286 if(use_arg)
287 func_arg(a->data,arg);
288 else
289 func(a->data);
290 a=n;
291 }
292 }
293 }
294
295void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func)
296 {
297 doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL);
298 }
299
300void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
301 {
302 doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);
303 }
304
305static void expand(LHASH *lh)
306 {
307 LHASH_NODE **n,**n1,**n2,*np;
308 unsigned int p,i,j;
309 unsigned long hash,nni;
310
311 lh->num_nodes++;
312 lh->num_expands++;
313 p=(int)lh->p++;
314 n1= &(lh->b[p]);
315 n2= &(lh->b[p+(int)lh->pmax]);
316 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
317 nni=lh->num_alloc_nodes;
318
319 for (np= *n1; np != NULL; )
320 {
321#ifndef OPENSSL_NO_HASH_COMP
322 hash=np->hash;
323#else
324 hash=lh->hash(np->data);
325 lh->num_hash_calls++;
326#endif
327 if ((hash%nni) != p)
328 { /* move it */
329 *n1= (*n1)->next;
330 np->next= *n2;
331 *n2=np;
332 }
333 else
334 n1= &((*n1)->next);
335 np= *n1;
336 }
337
338 if ((lh->p) >= lh->pmax)
339 {
340 j=(int)lh->num_alloc_nodes*2;
341 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
342 (unsigned int)sizeof(LHASH_NODE *)*j);
343 if (n == NULL)
344 {
345/* fputs("realloc error in lhash",stderr); */
346 lh->error++;
347 lh->p=0;
348 return;
349 }
350 /* else */
351 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
352 n[i]=NULL; /* 02/03/92 eay */
353 lh->pmax=lh->num_alloc_nodes;
354 lh->num_alloc_nodes=j;
355 lh->num_expand_reallocs++;
356 lh->p=0;
357 lh->b=n;
358 }
359 }
360
361static void contract(LHASH *lh)
362 {
363 LHASH_NODE **n,*n1,*np;
364
365 np=lh->b[lh->p+lh->pmax-1];
366 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
367 if (lh->p == 0)
368 {
369 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
370 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
371 if (n == NULL)
372 {
373/* fputs("realloc error in lhash",stderr); */
374 lh->error++;
375 return;
376 }
377 lh->num_contract_reallocs++;
378 lh->num_alloc_nodes/=2;
379 lh->pmax/=2;
380 lh->p=lh->pmax-1;
381 lh->b=n;
382 }
383 else
384 lh->p--;
385
386 lh->num_nodes--;
387 lh->num_contracts++;
388
389 n1=lh->b[(int)lh->p];
390 if (n1 == NULL)
391 lh->b[(int)lh->p]=np;
392 else
393 {
394 while (n1->next != NULL)
395 n1=n1->next;
396 n1->next=np;
397 }
398 }
399
400static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash)
401 {
402 LHASH_NODE **ret,*n1;
403 unsigned long hash,nn;
404 int (*cf)();
405
406 hash=(*(lh->hash))(data);
407 lh->num_hash_calls++;
408 *rhash=hash;
409
410 nn=hash%lh->pmax;
411 if (nn < lh->p)
412 nn=hash%lh->num_alloc_nodes;
413
414 cf=lh->comp;
415 ret= &(lh->b[(int)nn]);
416 for (n1= *ret; n1 != NULL; n1=n1->next)
417 {
418#ifndef OPENSSL_NO_HASH_COMP
419 lh->num_hash_comps++;
420 if (n1->hash != hash)
421 {
422 ret= &(n1->next);
423 continue;
424 }
425#endif
426 lh->num_comp_calls++;
427 if(cf(n1->data,data) == 0)
428 break;
429 ret= &(n1->next);
430 }
431 return(ret);
432 }
433
434/* The following hash seems to work very well on normal text strings
435 * no collisions on /usr/dict/words and it distributes on %2^n quite
436 * well, not as good as MD5, but still good.
437 */
438unsigned long lh_strhash(const char *c)
439 {
440 unsigned long ret=0;
441 long n;
442 unsigned long v;
443 int r;
444
445 if ((c == NULL) || (*c == '\0'))
446 return(ret);
447/*
448 unsigned char b[16];
449 MD5(c,strlen(c),b);
450 return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24));
451*/
452
453 n=0x100;
454 while (*c)
455 {
456 v=n|(*c);
457 n+=0x100;
458 r= (int)((v>>2)^v)&0x0f;
459 ret=(ret<<r)|(ret>>(32-r));
460 ret&=0xFFFFFFFFL;
461 ret^=v*v;
462 c++;
463 }
464 return((ret>>16)^ret);
465 }
466
467unsigned long lh_num_items(const LHASH *lh)
468 {
469 return lh ? lh->num_items : 0;
470 }
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
new file mode 100644
index 0000000000..dee8207333
--- /dev/null
+++ b/src/lib/libcrypto/lhash/lhash.h
@@ -0,0 +1,199 @@
1/* crypto/lhash/lhash.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Header for dynamic hash table routines
60 * Author - Eric Young
61 */
62
63#ifndef HEADER_LHASH_H
64#define HEADER_LHASH_H
65
66#ifndef OPENSSL_NO_FP_API
67#include <stdio.h>
68#endif
69
70#ifndef OPENSSL_NO_BIO
71#include <openssl/bio.h>
72#endif
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78typedef struct lhash_node_st
79 {
80 const void *data;
81 struct lhash_node_st *next;
82#ifndef OPENSSL_NO_HASH_COMP
83 unsigned long hash;
84#endif
85 } LHASH_NODE;
86
87typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
88typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
89typedef void (*LHASH_DOALL_FN_TYPE)(const void *);
90typedef void (*LHASH_DOALL_ARG_FN_TYPE)(const void *, void *);
91
92/* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.
93 * This way, callbacks can be provided to LHASH structures without function
94 * pointer casting and the macro-defined callbacks provide per-variable casting
95 * before deferring to the underlying type-specific callbacks. NB: It is
96 * possible to place a "static" in front of both the DECLARE and IMPLEMENT
97 * macros if the functions are strictly internal. */
98
99/* First: "hash" functions */
100#define DECLARE_LHASH_HASH_FN(f_name,o_type) \
101 unsigned long f_name##_LHASH_HASH(const void *);
102#define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
103 unsigned long f_name##_LHASH_HASH(const void *arg) { \
104 o_type a = (o_type)arg; \
105 return f_name(a); }
106#define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
107
108/* Second: "compare" functions */
109#define DECLARE_LHASH_COMP_FN(f_name,o_type) \
110 int f_name##_LHASH_COMP(const void *, const void *);
111#define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
112 int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
113 o_type a = (o_type)arg1; \
114 o_type b = (o_type)arg2; \
115 return f_name(a,b); }
116#define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
117
118/* Third: "doall" functions */
119#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
120 void f_name##_LHASH_DOALL(const void *);
121#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
122 void f_name##_LHASH_DOALL(const void *arg) { \
123 o_type a = (o_type)arg; \
124 f_name(a); }
125#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
126
127/* Fourth: "doall_arg" functions */
128#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
129 void f_name##_LHASH_DOALL_ARG(const void *, void *);
130#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
131 void f_name##_LHASH_DOALL_ARG(const void *arg1, void *arg2) { \
132 o_type a = (o_type)arg1; \
133 a_type b = (a_type)arg2; \
134 f_name(a,b); }
135#define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
136
137typedef struct lhash_st
138 {
139 LHASH_NODE **b;
140 LHASH_COMP_FN_TYPE comp;
141 LHASH_HASH_FN_TYPE hash;
142 unsigned int num_nodes;
143 unsigned int num_alloc_nodes;
144 unsigned int p;
145 unsigned int pmax;
146 unsigned long up_load; /* load times 256 */
147 unsigned long down_load; /* load times 256 */
148 unsigned long num_items;
149
150 unsigned long num_expands;
151 unsigned long num_expand_reallocs;
152 unsigned long num_contracts;
153 unsigned long num_contract_reallocs;
154 unsigned long num_hash_calls;
155 unsigned long num_comp_calls;
156 unsigned long num_insert;
157 unsigned long num_replace;
158 unsigned long num_delete;
159 unsigned long num_no_delete;
160 unsigned long num_retrieve;
161 unsigned long num_retrieve_miss;
162 unsigned long num_hash_comps;
163
164 int error;
165 } LHASH;
166
167#define LH_LOAD_MULT 256
168
169/* Indicates a malloc() error in the last call, this is only bad
170 * in lh_insert(). */
171#define lh_error(lh) ((lh)->error)
172
173LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
174void lh_free(LHASH *lh);
175void *lh_insert(LHASH *lh, const void *data);
176void *lh_delete(LHASH *lh, const void *data);
177void *lh_retrieve(LHASH *lh, const void *data);
178void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
179void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
180unsigned long lh_strhash(const char *c);
181unsigned long lh_num_items(const LHASH *lh);
182
183#ifndef OPENSSL_NO_FP_API
184void lh_stats(const LHASH *lh, FILE *out);
185void lh_node_stats(const LHASH *lh, FILE *out);
186void lh_node_usage_stats(const LHASH *lh, FILE *out);
187#endif
188
189#ifndef OPENSSL_NO_BIO
190void lh_stats_bio(const LHASH *lh, BIO *out);
191void lh_node_stats_bio(const LHASH *lh, BIO *out);
192void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
193#endif
194#ifdef __cplusplus
195}
196#endif
197
198#endif
199
diff --git a/src/lib/libcrypto/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_one.c b/src/lib/libcrypto/md2/md2_one.c
index 8c36ba5779..835160ef56 100644
--- a/src/lib/libcrypto/md2/md2_one.c
+++ b/src/lib/libcrypto/md2/md2_one.c
@@ -69,8 +69,7 @@ unsigned char *MD2(const unsigned char *d, unsigned long n, unsigned char *md)
69 static unsigned char m[MD2_DIGEST_LENGTH]; 69 static unsigned char m[MD2_DIGEST_LENGTH];
70 70
71 if (md == NULL) md=m; 71 if (md == NULL) md=m;
72 if (!MD2_Init(&c)) 72 MD2_Init(&c);
73 return NULL;
74#ifndef CHARSET_EBCDIC 73#ifndef CHARSET_EBCDIC
75 MD2_Update(&c,d,n); 74 MD2_Update(&c,d,n);
76#else 75#else
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h
new file mode 100644
index 0000000000..733da6acaf
--- /dev/null
+++ b/src/lib/libcrypto/md32_common.h
@@ -0,0 +1,649 @@
1/* crypto/md32_common.h */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 * This is a generic 32 bit "collector" for message digest algorithms.
58 * Whenever needed it collects input character stream into chunks of
59 * 32 bit values and invokes a block function that performs actual hash
60 * calculations.
61 *
62 * Porting guide.
63 *
64 * Obligatory macros:
65 *
66 * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
67 * this macro defines byte order of input stream.
68 * HASH_CBLOCK
69 * size of a unit chunk HASH_BLOCK operates on.
70 * HASH_LONG
71 * has to be at lest 32 bit wide, if it's wider, then
72 * HASH_LONG_LOG2 *has to* be defined along
73 * HASH_CTX
74 * context structure that at least contains following
75 * members:
76 * typedef struct {
77 * ...
78 * HASH_LONG Nl,Nh;
79 * HASH_LONG data[HASH_LBLOCK];
80 * int num;
81 * ...
82 * } HASH_CTX;
83 * HASH_UPDATE
84 * name of "Update" function, implemented here.
85 * HASH_TRANSFORM
86 * name of "Transform" function, implemented here.
87 * HASH_FINAL
88 * name of "Final" function, implemented here.
89 * HASH_BLOCK_HOST_ORDER
90 * name of "block" function treating *aligned* input message
91 * in host byte order, implemented externally.
92 * HASH_BLOCK_DATA_ORDER
93 * name of "block" function treating *unaligned* input message
94 * in original (data) byte order, implemented externally (it
95 * actually is optional if data and host are of the same
96 * "endianess").
97 * HASH_MAKE_STRING
98 * macro convering context variables to an ASCII hash string.
99 *
100 * Optional macros:
101 *
102 * B_ENDIAN or L_ENDIAN
103 * defines host byte-order.
104 * HASH_LONG_LOG2
105 * defaults to 2 if not states otherwise.
106 * HASH_LBLOCK
107 * assumed to be HASH_CBLOCK/4 if not stated otherwise.
108 * HASH_BLOCK_DATA_ORDER_ALIGNED
109 * alternative "block" function capable of treating
110 * aligned input message in original (data) order,
111 * implemented externally.
112 *
113 * MD5 example:
114 *
115 * #define DATA_ORDER_IS_LITTLE_ENDIAN
116 *
117 * #define HASH_LONG MD5_LONG
118 * #define HASH_LONG_LOG2 MD5_LONG_LOG2
119 * #define HASH_CTX MD5_CTX
120 * #define HASH_CBLOCK MD5_CBLOCK
121 * #define HASH_LBLOCK MD5_LBLOCK
122 * #define HASH_UPDATE MD5_Update
123 * #define HASH_TRANSFORM MD5_Transform
124 * #define HASH_FINAL MD5_Final
125 * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
126 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
127 *
128 * <appro@fy.chalmers.se>
129 */
130
131#include <openssl/crypto.h>
132#include <openssl/fips.h>
133#include <openssl/err.h>
134
135#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
136#error "DATA_ORDER must be defined!"
137#endif
138
139#ifndef HASH_CBLOCK
140#error "HASH_CBLOCK must be defined!"
141#endif
142#ifndef HASH_LONG
143#error "HASH_LONG must be defined!"
144#endif
145#ifndef HASH_CTX
146#error "HASH_CTX must be defined!"
147#endif
148
149#ifndef HASH_UPDATE
150#error "HASH_UPDATE must be defined!"
151#endif
152#ifndef HASH_TRANSFORM
153#error "HASH_TRANSFORM must be defined!"
154#endif
155#ifndef HASH_FINAL
156#error "HASH_FINAL must be defined!"
157#endif
158
159#ifndef HASH_BLOCK_HOST_ORDER
160#error "HASH_BLOCK_HOST_ORDER must be defined!"
161#endif
162
163#if 0
164/*
165 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
166 * isn't defined.
167 */
168#ifndef HASH_BLOCK_DATA_ORDER
169#error "HASH_BLOCK_DATA_ORDER must be defined!"
170#endif
171#endif
172
173#ifndef HASH_LBLOCK
174#define HASH_LBLOCK (HASH_CBLOCK/4)
175#endif
176
177#ifndef HASH_LONG_LOG2
178#define HASH_LONG_LOG2 2
179#endif
180
181/*
182 * Engage compiler specific rotate intrinsic function if available.
183 */
184#undef ROTATE
185#ifndef PEDANTIC
186# if 0 /* defined(_MSC_VER) */
187# define ROTATE(a,n) _lrotl(a,n)
188# elif defined(__MWERKS__)
189# if defined(__POWERPC__)
190# define ROTATE(a,n) __rlwinm(a,n,0,31)
191# elif defined(__MC68K__)
192 /* Motorola specific tweak. <appro@fy.chalmers.se> */
193# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
194# else
195# define ROTATE(a,n) __rol(a,n)
196# endif
197# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
198 /*
199 * Some GNU C inline assembler templates. Note that these are
200 * rotates by *constant* number of bits! But that's exactly
201 * what we need here...
202 *
203 * <appro@fy.chalmers.se>
204 */
205# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
206# define ROTATE(a,n) ({ register unsigned int ret; \
207 asm ( \
208 "roll %1,%0" \
209 : "=r"(ret) \
210 : "I"(n), "0"(a) \
211 : "cc"); \
212 ret; \
213 })
214# elif defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
215# define ROTATE(a,n) ({ register unsigned int ret; \
216 asm ( \
217 "rlwinm %0,%1,%2,0,31" \
218 : "=r"(ret) \
219 : "r"(a), "I"(n)); \
220 ret; \
221 })
222# endif
223# endif
224
225/*
226 * Engage compiler specific "fetch in reverse byte order"
227 * intrinsic function if available.
228 */
229# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
230 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
231# if (defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)) && !defined(I386_ONLY)
232# define BE_FETCH32(a) ({ register unsigned int l=(a);\
233 asm ( \
234 "bswapl %0" \
235 : "=r"(l) : "0"(l)); \
236 l; \
237 })
238# elif defined(__powerpc)
239# define LE_FETCH32(a) ({ register unsigned int l; \
240 asm ( \
241 "lwbrx %0,0,%1" \
242 : "=r"(l) \
243 : "r"(a)); \
244 l; \
245 })
246
247# elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC)
248# define LE_FETCH32(a) ({ register unsigned int l; \
249 asm ( \
250 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
251 : "=r"(l) \
252 : "r"(a)); \
253 l; \
254 })
255# endif
256# endif
257#endif /* PEDANTIC */
258
259#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
260/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
261#ifdef ROTATE
262/* 5 instructions with rotate instruction, else 9 */
263#define REVERSE_FETCH32(a,l) ( \
264 l=*(const HASH_LONG *)(a), \
265 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
266 )
267#else
268/* 6 instructions with rotate instruction, else 8 */
269#define REVERSE_FETCH32(a,l) ( \
270 l=*(const HASH_LONG *)(a), \
271 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
272 ROTATE(l,16) \
273 )
274/*
275 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
276 * It's rewritten as above for two reasons:
277 * - RISCs aren't good at long constants and have to explicitely
278 * compose 'em with several (well, usually 2) instructions in a
279 * register before performing the actual operation and (as you
280 * already realized:-) having same constant should inspire the
281 * compiler to permanently allocate the only register for it;
282 * - most modern CPUs have two ALUs, but usually only one has
283 * circuitry for shifts:-( this minor tweak inspires compiler
284 * to schedule shift instructions in a better way...
285 *
286 * <appro@fy.chalmers.se>
287 */
288#endif
289#endif
290
291#ifndef ROTATE
292#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
293#endif
294
295/*
296 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
297 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
298 * and host are of the same "endianess". It's possible to mask
299 * this with blank #define HASH_BLOCK_DATA_ORDER though...
300 *
301 * <appro@fy.chalmers.se>
302 */
303#if defined(B_ENDIAN)
304# if defined(DATA_ORDER_IS_BIG_ENDIAN)
305# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
306# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
307# endif
308# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
309# ifndef HOST_FETCH32
310# ifdef LE_FETCH32
311# define HOST_FETCH32(p,l) LE_FETCH32(p)
312# elif defined(REVERSE_FETCH32)
313# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
314# endif
315# endif
316# endif
317#elif defined(L_ENDIAN)
318# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
319# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
320# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
321# endif
322# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
323# ifndef HOST_FETCH32
324# ifdef BE_FETCH32
325# define HOST_FETCH32(p,l) BE_FETCH32(p)
326# elif defined(REVERSE_FETCH32)
327# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
328# endif
329# endif
330# endif
331#endif
332
333#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
334#ifndef HASH_BLOCK_DATA_ORDER
335#error "HASH_BLOCK_DATA_ORDER must be defined!"
336#endif
337#endif
338
339#if defined(DATA_ORDER_IS_BIG_ENDIAN)
340
341#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
342 l|=(((unsigned long)(*((c)++)))<<16), \
343 l|=(((unsigned long)(*((c)++)))<< 8), \
344 l|=(((unsigned long)(*((c)++))) ), \
345 l)
346#define HOST_p_c2l(c,l,n) { \
347 switch (n) { \
348 case 0: l =((unsigned long)(*((c)++)))<<24; \
349 case 1: l|=((unsigned long)(*((c)++)))<<16; \
350 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
351 case 3: l|=((unsigned long)(*((c)++))); \
352 } }
353#define HOST_p_c2l_p(c,l,sc,len) { \
354 switch (sc) { \
355 case 0: l =((unsigned long)(*((c)++)))<<24; \
356 if (--len == 0) break; \
357 case 1: l|=((unsigned long)(*((c)++)))<<16; \
358 if (--len == 0) break; \
359 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
360 } }
361/* NOTE the pointer is not incremented at the end of this */
362#define HOST_c2l_p(c,l,n) { \
363 l=0; (c)+=n; \
364 switch (n) { \
365 case 3: l =((unsigned long)(*(--(c))))<< 8; \
366 case 2: l|=((unsigned long)(*(--(c))))<<16; \
367 case 1: l|=((unsigned long)(*(--(c))))<<24; \
368 } }
369#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
370 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
371 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
372 *((c)++)=(unsigned char)(((l) )&0xff), \
373 l)
374
375#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
376
377#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
378 l|=(((unsigned long)(*((c)++)))<< 8), \
379 l|=(((unsigned long)(*((c)++)))<<16), \
380 l|=(((unsigned long)(*((c)++)))<<24), \
381 l)
382#define HOST_p_c2l(c,l,n) { \
383 switch (n) { \
384 case 0: l =((unsigned long)(*((c)++))); \
385 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
386 case 2: l|=((unsigned long)(*((c)++)))<<16; \
387 case 3: l|=((unsigned long)(*((c)++)))<<24; \
388 } }
389#define HOST_p_c2l_p(c,l,sc,len) { \
390 switch (sc) { \
391 case 0: l =((unsigned long)(*((c)++))); \
392 if (--len == 0) break; \
393 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
394 if (--len == 0) break; \
395 case 2: l|=((unsigned long)(*((c)++)))<<16; \
396 } }
397/* NOTE the pointer is not incremented at the end of this */
398#define HOST_c2l_p(c,l,n) { \
399 l=0; (c)+=n; \
400 switch (n) { \
401 case 3: l =((unsigned long)(*(--(c))))<<16; \
402 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
403 case 1: l|=((unsigned long)(*(--(c)))); \
404 } }
405#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
406 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
407 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
408 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
409 l)
410
411#endif
412
413/*
414 * Time for some action:-)
415 */
416
417int HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
418 {
419 const unsigned char *data=data_;
420 register HASH_LONG * p;
421 register unsigned long l;
422 int sw,sc,ew,ec;
423
424 if (len==0) return 1;
425
426 l=(c->Nl+(len<<3))&0xffffffffL;
427 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
428 * Wei Dai <weidai@eskimo.com> for pointing it out. */
429 if (l < c->Nl) /* overflow */
430 c->Nh++;
431 c->Nh+=(len>>29);
432 c->Nl=l;
433
434 if (c->num != 0)
435 {
436 p=c->data;
437 sw=c->num>>2;
438 sc=c->num&0x03;
439
440 if ((c->num+len) >= HASH_CBLOCK)
441 {
442 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
443 for (; sw<HASH_LBLOCK; sw++)
444 {
445 HOST_c2l(data,l); p[sw]=l;
446 }
447 HASH_BLOCK_HOST_ORDER (c,p,1);
448 len-=(HASH_CBLOCK-c->num);
449 c->num=0;
450 /* drop through and do the rest */
451 }
452 else
453 {
454 c->num+=len;
455 if ((sc+len) < 4) /* ugly, add char's to a word */
456 {
457 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
458 }
459 else
460 {
461 ew=(c->num>>2);
462 ec=(c->num&0x03);
463 if (sc)
464 l=p[sw];
465 HOST_p_c2l(data,l,sc);
466 p[sw++]=l;
467 for (; sw < ew; sw++)
468 {
469 HOST_c2l(data,l); p[sw]=l;
470 }
471 if (ec)
472 {
473 HOST_c2l_p(data,l,ec); p[sw]=l;
474 }
475 }
476 return 1;
477 }
478 }
479
480 sw=len/HASH_CBLOCK;
481 if (sw > 0)
482 {
483#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
484 /*
485 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
486 * only if sizeof(HASH_LONG)==4.
487 */
488 if ((((unsigned long)data)%4) == 0)
489 {
490 /* data is properly aligned so that we can cast it: */
491 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
492 sw*=HASH_CBLOCK;
493 data+=sw;
494 len-=sw;
495 }
496 else
497#if !defined(HASH_BLOCK_DATA_ORDER)
498 while (sw--)
499 {
500 memcpy (p=c->data,data,HASH_CBLOCK);
501 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
502 data+=HASH_CBLOCK;
503 len-=HASH_CBLOCK;
504 }
505#endif
506#endif
507#if defined(HASH_BLOCK_DATA_ORDER)
508 {
509 HASH_BLOCK_DATA_ORDER(c,data,sw);
510 sw*=HASH_CBLOCK;
511 data+=sw;
512 len-=sw;
513 }
514#endif
515 }
516
517 if (len!=0)
518 {
519 p = c->data;
520 c->num = len;
521 ew=len>>2; /* words to copy */
522 ec=len&0x03;
523 for (; ew; ew--,p++)
524 {
525 HOST_c2l(data,l); *p=l;
526 }
527 HOST_c2l_p(data,l,ec);
528 *p=l;
529 }
530 return 1;
531 }
532
533
534void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
535 {
536#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
537 if ((((unsigned long)data)%4) == 0)
538 /* data is properly aligned so that we can cast it: */
539 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
540 else
541#if !defined(HASH_BLOCK_DATA_ORDER)
542 {
543 memcpy (c->data,data,HASH_CBLOCK);
544 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
545 }
546#endif
547#endif
548#if defined(HASH_BLOCK_DATA_ORDER)
549 HASH_BLOCK_DATA_ORDER (c,data,1);
550#endif
551 }
552
553
554int HASH_FINAL (unsigned char *md, HASH_CTX *c)
555 {
556 register HASH_LONG *p;
557 register unsigned long l;
558 register int i,j;
559 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
560 const unsigned char *cp=end;
561
562#if 0
563 if(FIPS_mode() && !FIPS_md5_allowed())
564 {
565 FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD);
566 return 0;
567 }
568#endif
569
570 /* c->num should definitly have room for at least one more byte. */
571 p=c->data;
572 i=c->num>>2;
573 j=c->num&0x03;
574
575#if 0
576 /* purify often complains about the following line as an
577 * Uninitialized Memory Read. While this can be true, the
578 * following p_c2l macro will reset l when that case is true.
579 * This is because j&0x03 contains the number of 'valid' bytes
580 * already in p[i]. If and only if j&0x03 == 0, the UMR will
581 * occur but this is also the only time p_c2l will do
582 * l= *(cp++) instead of l|= *(cp++)
583 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
584 * 'potential bug' */
585#ifdef PURIFY
586 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
587#endif
588 l=p[i];
589#else
590 l = (j==0) ? 0 : p[i];
591#endif
592 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
593
594 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
595 {
596 if (i<HASH_LBLOCK) p[i]=0;
597 HASH_BLOCK_HOST_ORDER (c,p,1);
598 i=0;
599 }
600 for (; i<(HASH_LBLOCK-2); i++)
601 p[i]=0;
602
603#if defined(DATA_ORDER_IS_BIG_ENDIAN)
604 p[HASH_LBLOCK-2]=c->Nh;
605 p[HASH_LBLOCK-1]=c->Nl;
606#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
607 p[HASH_LBLOCK-2]=c->Nl;
608 p[HASH_LBLOCK-1]=c->Nh;
609#endif
610 HASH_BLOCK_HOST_ORDER (c,p,1);
611
612#ifndef HASH_MAKE_STRING
613#error "HASH_MAKE_STRING must be defined!"
614#else
615 HASH_MAKE_STRING(c,md);
616#endif
617
618 c->num=0;
619 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
620 * but I'm not worried :-)
621 OPENSSL_cleanse((void *)c,sizeof(HASH_CTX));
622 */
623 return 1;
624 }
625
626#ifndef MD32_REG_T
627#define MD32_REG_T long
628/*
629 * This comment was originaly written for MD5, which is why it
630 * discusses A-D. But it basically applies to all 32-bit digests,
631 * which is why it was moved to common header file.
632 *
633 * In case you wonder why A-D are declared as long and not
634 * as MD5_LONG. Doing so results in slight performance
635 * boost on LP64 architectures. The catch is we don't
636 * really care if 32 MSBs of a 64-bit register get polluted
637 * with eventual overflows as we *save* only 32 LSBs in
638 * *either* case. Now declaring 'em long excuses the compiler
639 * from keeping 32 MSBs zeroed resulting in 13% performance
640 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
641 * Well, to be honest it should say that this *prevents*
642 * performance degradation.
643 * <appro@fy.chalmers.se>
644 * Apparently there're LP64 compilers that generate better
645 * code if A-D are declared int. Most notably GCC-x86_64
646 * generates better code.
647 * <appro@fy.chalmers.se>
648 */
649#endif
diff --git a/src/lib/libcrypto/md4/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.h b/src/lib/libcrypto/md4/md4.h
new file mode 100644
index 0000000000..7e761efb62
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4.h
@@ -0,0 +1,119 @@
1/* crypto/md4/md4.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD4_H
60#define HEADER_MD4_H
61
62#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_MD4
69#error MD4 is disabled.
70#endif
71
72/*
73 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
74 * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then !
75 * ! MD4_LONG_LOG2 has to be defined along. !
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 */
78
79#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
80#define MD4_LONG unsigned long
81#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
82#define MD4_LONG unsigned long
83#define MD4_LONG_LOG2 3
84/*
85 * _CRAY note. I could declare short, but I have no idea what impact
86 * does it have on performance on none-T3E machines. I could declare
87 * int, but at least on C90 sizeof(int) can be chosen at compile time.
88 * So I've chosen long...
89 * <appro@fy.chalmers.se>
90 */
91#else
92#define MD4_LONG unsigned int
93#endif
94
95#define MD4_CBLOCK 64
96#define MD4_LBLOCK (MD4_CBLOCK/4)
97#define MD4_DIGEST_LENGTH 16
98
99typedef struct MD4state_st
100 {
101 MD4_LONG A,B,C,D;
102 MD4_LONG Nl,Nh;
103 MD4_LONG data[MD4_LBLOCK];
104 int num;
105 } MD4_CTX;
106
107#ifdef OPENSSL_FIPS
108int private_MD4_Init(MD4_CTX *c);
109#endif
110int MD4_Init(MD4_CTX *c);
111int MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
112int MD4_Final(unsigned char *md, MD4_CTX *c);
113unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);
114void MD4_Transform(MD4_CTX *c, const unsigned char *b);
115#ifdef __cplusplus
116}
117#endif
118
119#endif
diff --git a/src/lib/libcrypto/md4/md4_dgst.c b/src/lib/libcrypto/md4/md4_dgst.c
new file mode 100644
index 0000000000..ee7cc72262
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4_dgst.c
@@ -0,0 +1,258 @@
1/* crypto/md4/md4_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "md4_locl.h"
61#include <openssl/opensslv.h>
62
63const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
64
65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm
66 */
67
68#define INIT_DATA_A (unsigned long)0x67452301L
69#define INIT_DATA_B (unsigned long)0xefcdab89L
70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L
72
73FIPS_NON_FIPS_MD_Init(MD4)
74 {
75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B;
77 c->C=INIT_DATA_C;
78 c->D=INIT_DATA_D;
79 c->Nl=0;
80 c->Nh=0;
81 c->num=0;
82 return 1;
83 }
84
85#ifndef md4_block_host_order
86void md4_block_host_order (MD4_CTX *c, const void *data, int num)
87 {
88 const MD4_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 3,0);
100 R0(D,A,B,C,X[ 1], 7,0);
101 R0(C,D,A,B,X[ 2],11,0);
102 R0(B,C,D,A,X[ 3],19,0);
103 R0(A,B,C,D,X[ 4], 3,0);
104 R0(D,A,B,C,X[ 5], 7,0);
105 R0(C,D,A,B,X[ 6],11,0);
106 R0(B,C,D,A,X[ 7],19,0);
107 R0(A,B,C,D,X[ 8], 3,0);
108 R0(D,A,B,C,X[ 9], 7,0);
109 R0(C,D,A,B,X[10],11,0);
110 R0(B,C,D,A,X[11],19,0);
111 R0(A,B,C,D,X[12], 3,0);
112 R0(D,A,B,C,X[13], 7,0);
113 R0(C,D,A,B,X[14],11,0);
114 R0(B,C,D,A,X[15],19,0);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 0], 3,0x5A827999L);
117 R1(D,A,B,C,X[ 4], 5,0x5A827999L);
118 R1(C,D,A,B,X[ 8], 9,0x5A827999L);
119 R1(B,C,D,A,X[12],13,0x5A827999L);
120 R1(A,B,C,D,X[ 1], 3,0x5A827999L);
121 R1(D,A,B,C,X[ 5], 5,0x5A827999L);
122 R1(C,D,A,B,X[ 9], 9,0x5A827999L);
123 R1(B,C,D,A,X[13],13,0x5A827999L);
124 R1(A,B,C,D,X[ 2], 3,0x5A827999L);
125 R1(D,A,B,C,X[ 6], 5,0x5A827999L);
126 R1(C,D,A,B,X[10], 9,0x5A827999L);
127 R1(B,C,D,A,X[14],13,0x5A827999L);
128 R1(A,B,C,D,X[ 3], 3,0x5A827999L);
129 R1(D,A,B,C,X[ 7], 5,0x5A827999L);
130 R1(C,D,A,B,X[11], 9,0x5A827999L);
131 R1(B,C,D,A,X[15],13,0x5A827999L);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 0], 3,0x6ED9EBA1);
134 R2(D,A,B,C,X[ 8], 9,0x6ED9EBA1);
135 R2(C,D,A,B,X[ 4],11,0x6ED9EBA1);
136 R2(B,C,D,A,X[12],15,0x6ED9EBA1);
137 R2(A,B,C,D,X[ 2], 3,0x6ED9EBA1);
138 R2(D,A,B,C,X[10], 9,0x6ED9EBA1);
139 R2(C,D,A,B,X[ 6],11,0x6ED9EBA1);
140 R2(B,C,D,A,X[14],15,0x6ED9EBA1);
141 R2(A,B,C,D,X[ 1], 3,0x6ED9EBA1);
142 R2(D,A,B,C,X[ 9], 9,0x6ED9EBA1);
143 R2(C,D,A,B,X[ 5],11,0x6ED9EBA1);
144 R2(B,C,D,A,X[13],15,0x6ED9EBA1);
145 R2(A,B,C,D,X[ 3], 3,0x6ED9EBA1);
146 R2(D,A,B,C,X[11], 9,0x6ED9EBA1);
147 R2(C,D,A,B,X[ 7],11,0x6ED9EBA1);
148 R2(B,C,D,A,X[15],15,0x6ED9EBA1);
149
150 A = c->A += A;
151 B = c->B += B;
152 C = c->C += C;
153 D = c->D += D;
154 }
155 }
156#endif
157
158#ifndef md4_block_data_order
159#ifdef X
160#undef X
161#endif
162void md4_block_data_order (MD4_CTX *c, const void *data_, int num)
163 {
164 const unsigned char *data=data_;
165 register unsigned MD32_REG_T A,B,C,D,l;
166#ifndef MD32_XARRAY
167 /* See comment in crypto/sha/sha_locl.h for details. */
168 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
169 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
170# define X(i) XX##i
171#else
172 MD4_LONG XX[MD4_LBLOCK];
173# define X(i) XX[i]
174#endif
175
176 A=c->A;
177 B=c->B;
178 C=c->C;
179 D=c->D;
180
181 for (;num--;)
182 {
183 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
184 /* Round 0 */
185 R0(A,B,C,D,X( 0), 3,0); HOST_c2l(data,l); X( 2)=l;
186 R0(D,A,B,C,X( 1), 7,0); HOST_c2l(data,l); X( 3)=l;
187 R0(C,D,A,B,X( 2),11,0); HOST_c2l(data,l); X( 4)=l;
188 R0(B,C,D,A,X( 3),19,0); HOST_c2l(data,l); X( 5)=l;
189 R0(A,B,C,D,X( 4), 3,0); HOST_c2l(data,l); X( 6)=l;
190 R0(D,A,B,C,X( 5), 7,0); HOST_c2l(data,l); X( 7)=l;
191 R0(C,D,A,B,X( 6),11,0); HOST_c2l(data,l); X( 8)=l;
192 R0(B,C,D,A,X( 7),19,0); HOST_c2l(data,l); X( 9)=l;
193 R0(A,B,C,D,X( 8), 3,0); HOST_c2l(data,l); X(10)=l;
194 R0(D,A,B,C,X( 9), 7,0); HOST_c2l(data,l); X(11)=l;
195 R0(C,D,A,B,X(10),11,0); HOST_c2l(data,l); X(12)=l;
196 R0(B,C,D,A,X(11),19,0); HOST_c2l(data,l); X(13)=l;
197 R0(A,B,C,D,X(12), 3,0); HOST_c2l(data,l); X(14)=l;
198 R0(D,A,B,C,X(13), 7,0); HOST_c2l(data,l); X(15)=l;
199 R0(C,D,A,B,X(14),11,0);
200 R0(B,C,D,A,X(15),19,0);
201 /* Round 1 */
202 R1(A,B,C,D,X( 0), 3,0x5A827999L);
203 R1(D,A,B,C,X( 4), 5,0x5A827999L);
204 R1(C,D,A,B,X( 8), 9,0x5A827999L);
205 R1(B,C,D,A,X(12),13,0x5A827999L);
206 R1(A,B,C,D,X( 1), 3,0x5A827999L);
207 R1(D,A,B,C,X( 5), 5,0x5A827999L);
208 R1(C,D,A,B,X( 9), 9,0x5A827999L);
209 R1(B,C,D,A,X(13),13,0x5A827999L);
210 R1(A,B,C,D,X( 2), 3,0x5A827999L);
211 R1(D,A,B,C,X( 6), 5,0x5A827999L);
212 R1(C,D,A,B,X(10), 9,0x5A827999L);
213 R1(B,C,D,A,X(14),13,0x5A827999L);
214 R1(A,B,C,D,X( 3), 3,0x5A827999L);
215 R1(D,A,B,C,X( 7), 5,0x5A827999L);
216 R1(C,D,A,B,X(11), 9,0x5A827999L);
217 R1(B,C,D,A,X(15),13,0x5A827999L);
218 /* Round 2 */
219 R2(A,B,C,D,X( 0), 3,0x6ED9EBA1L);
220 R2(D,A,B,C,X( 8), 9,0x6ED9EBA1L);
221 R2(C,D,A,B,X( 4),11,0x6ED9EBA1L);
222 R2(B,C,D,A,X(12),15,0x6ED9EBA1L);
223 R2(A,B,C,D,X( 2), 3,0x6ED9EBA1L);
224 R2(D,A,B,C,X(10), 9,0x6ED9EBA1L);
225 R2(C,D,A,B,X( 6),11,0x6ED9EBA1L);
226 R2(B,C,D,A,X(14),15,0x6ED9EBA1L);
227 R2(A,B,C,D,X( 1), 3,0x6ED9EBA1L);
228 R2(D,A,B,C,X( 9), 9,0x6ED9EBA1L);
229 R2(C,D,A,B,X( 5),11,0x6ED9EBA1L);
230 R2(B,C,D,A,X(13),15,0x6ED9EBA1L);
231 R2(A,B,C,D,X( 3), 3,0x6ED9EBA1L);
232 R2(D,A,B,C,X(11), 9,0x6ED9EBA1L);
233 R2(C,D,A,B,X( 7),11,0x6ED9EBA1L);
234 R2(B,C,D,A,X(15),15,0x6ED9EBA1L);
235
236 A = c->A += A;
237 B = c->B += B;
238 C = c->C += C;
239 D = c->D += D;
240 }
241 }
242#endif
243
244#ifdef undef
245int printit(unsigned long *l)
246 {
247 int i,ii;
248
249 for (i=0; i<2; i++)
250 {
251 for (ii=0; ii<8; ii++)
252 {
253 fprintf(stderr,"%08lx ",l[i*8+ii]);
254 }
255 fprintf(stderr,"\n");
256 }
257 }
258#endif
diff --git a/src/lib/libcrypto/md4/md4_locl.h b/src/lib/libcrypto/md4/md4_locl.h
new file mode 100644
index 0000000000..a8d31d7a73
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4_locl.h
@@ -0,0 +1,154 @@
1/* crypto/md4/md4_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61#include <openssl/opensslconf.h>
62#include <openssl/md4.h>
63
64#ifndef MD4_LONG_LOG2
65#define MD4_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68void md4_block_host_order (MD4_CTX *c, const void *p,int num);
69void md4_block_data_order (MD4_CTX *c, const void *p,int num);
70
71#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
72/*
73 * *_block_host_order is expected to handle aligned data while
74 * *_block_data_order - unaligned. As algorithm and host (x86)
75 * are in this case of the same "endianness" these two are
76 * otherwise indistinguishable. But normally you don't want to
77 * call the same function because unaligned access in places
78 * where alignment is expected is usually a "Bad Thing". Indeed,
79 * on RISCs you get punished with BUS ERROR signal or *severe*
80 * performance degradation. Intel CPUs are in turn perfectly
81 * capable of loading unaligned data without such drastic side
82 * effect. Yes, they say it's slower than aligned load, but no
83 * exception is generated and therefore performance degradation
84 * is *incomparable* with RISCs. What we should weight here is
85 * costs of unaligned access against costs of aligning data.
86 * According to my measurements allowing unaligned access results
87 * in ~9% performance improvement on Pentium II operating at
88 * 266MHz. I won't be surprised if the difference will be higher
89 * on faster systems:-)
90 *
91 * <appro@fy.chalmers.se>
92 */
93#define md4_block_data_order md4_block_host_order
94#endif
95
96#define DATA_ORDER_IS_LITTLE_ENDIAN
97
98#define HASH_LONG MD4_LONG
99#define HASH_LONG_LOG2 MD4_LONG_LOG2
100#define HASH_CTX MD4_CTX
101#define HASH_CBLOCK MD4_CBLOCK
102#define HASH_LBLOCK MD4_LBLOCK
103#define HASH_UPDATE MD4_Update
104#define HASH_TRANSFORM MD4_Transform
105#define HASH_FINAL MD4_Final
106#define HASH_MAKE_STRING(c,s) do { \
107 unsigned long ll; \
108 ll=(c)->A; HOST_l2c(ll,(s)); \
109 ll=(c)->B; HOST_l2c(ll,(s)); \
110 ll=(c)->C; HOST_l2c(ll,(s)); \
111 ll=(c)->D; HOST_l2c(ll,(s)); \
112 } while (0)
113#define HASH_BLOCK_HOST_ORDER md4_block_host_order
114#if !defined(L_ENDIAN) || defined(md4_block_data_order)
115#define HASH_BLOCK_DATA_ORDER md4_block_data_order
116/*
117 * Little-endians (Intel and Alpha) feel better without this.
118 * It looks like memcpy does better job than generic
119 * md4_block_data_order on copying-n-aligning input data.
120 * But frankly speaking I didn't expect such result on Alpha.
121 * On the other hand I've got this with egcs-1.0.2 and if
122 * program is compiled with another (better?) compiler it
123 * might turn out other way around.
124 *
125 * <appro@fy.chalmers.se>
126 */
127#endif
128
129#include "md32_common.h"
130
131/*
132#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
133#define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z))))
134*/
135
136/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
137 * simplified to the code below. Wei attributes these optimizations
138 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
139 */
140#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
141#define G(b,c,d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
142#define H(b,c,d) ((b) ^ (c) ^ (d))
143
144#define R0(a,b,c,d,k,s,t) { \
145 a+=((k)+(t)+F((b),(c),(d))); \
146 a=ROTATE(a,s); };
147
148#define R1(a,b,c,d,k,s,t) { \
149 a+=((k)+(t)+G((b),(c),(d))); \
150 a=ROTATE(a,s); };\
151
152#define R2(a,b,c,d,k,s,t) { \
153 a+=((k)+(t)+H((b),(c),(d))); \
154 a=ROTATE(a,s); };
diff --git a/src/lib/libcrypto/md4/md4_one.c b/src/lib/libcrypto/md4/md4_one.c
new file mode 100644
index 0000000000..00565507e4
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4_one.c
@@ -0,0 +1,96 @@
1/* crypto/md4/md4_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/md4.h>
62#include <openssl/crypto.h>
63
64#ifdef CHARSET_EBCDIC
65#include <openssl/ebcdic.h>
66#endif
67
68unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md)
69 {
70 MD4_CTX c;
71 static unsigned char m[MD4_DIGEST_LENGTH];
72
73 if (md == NULL) md=m;
74 MD4_Init(&c);
75#ifndef CHARSET_EBCDIC
76 MD4_Update(&c,d,n);
77#else
78 {
79 char temp[1024];
80 unsigned long chunk;
81
82 while (n > 0)
83 {
84 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
85 ebcdic2ascii(temp, d, chunk);
86 MD4_Update(&c,temp,chunk);
87 n -= chunk;
88 d += chunk;
89 }
90 }
91#endif
92 MD4_Final(md,&c);
93 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
94 return(md);
95 }
96
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
new file mode 100644
index 0000000000..fa3fa3bed5
--- /dev/null
+++ b/src/lib/libcrypto/md5/asm/md5-586.pl
@@ -0,0 +1,306 @@
1#!/usr/local/bin/perl
2
3# Normal is the
4# md5_block_x86(MD5_CTX *c, ULONG *X);
5# version, non-normal is the
6# md5_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7
8$normal=0;
9
10push(@INC,"perlasm","../../perlasm");
11require "x86asm.pl";
12
13&asm_init($ARGV[0],$0);
14
15$A="eax";
16$B="ebx";
17$C="ecx";
18$D="edx";
19$tmp1="edi";
20$tmp2="ebp";
21$X="esi";
22
23# What we need to load into $tmp for the next round
24%Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D));
25@xo=(
26 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0
27 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1
28 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2
29 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
30 );
31
32&md5_block("md5_block_asm_host_order");
33&asm_finish();
34
35sub Np
36 {
37 local($p)=@_;
38 local(%n)=($A,$D,$B,$A,$C,$B,$D,$C);
39 return($n{$p});
40 }
41
42sub R0
43 {
44 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
45
46 &mov($tmp1,$C) if $pos < 0;
47 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one
48
49 # body proper
50
51 &comment("R0 $ki");
52 &xor($tmp1,$d); # F function - part 2
53
54 &and($tmp1,$b); # F function - part 3
55 &lea($a,&DWP($t,$a,$tmp2,1));
56
57 &xor($tmp1,$d); # F function - part 4
58
59 &add($a,$tmp1);
60 &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0
61 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1
62
63 &rotl($a,$s);
64
65 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
66
67 &add($a,$b);
68 }
69
70sub R1
71 {
72 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
73
74 &comment("R1 $ki");
75
76 &lea($a,&DWP($t,$a,$tmp2,1));
77
78 &xor($tmp1,$b); # G function - part 2
79 &and($tmp1,$d); # G function - part 3
80
81 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
82 &xor($tmp1,$c); # G function - part 4
83
84 &add($a,$tmp1);
85 &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1
86 &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1
87
88 &rotl($a,$s);
89
90 &add($a,$b);
91 }
92
93sub R2
94 {
95 local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
96 # This one is different, only 3 logical operations
97
98if (($n & 1) == 0)
99 {
100 &comment("R2 $ki");
101 # make sure to do 'D' first, not 'B', else we clash with
102 # the last add from the previous round.
103
104 &xor($tmp1,$d); # H function - part 2
105
106 &xor($tmp1,$b); # H function - part 3
107 &lea($a,&DWP($t,$a,$tmp2,1));
108
109 &add($a,$tmp1);
110
111 &rotl($a,$s);
112
113 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
114 &mov($tmp1,&Np($c));
115 }
116else
117 {
118 &comment("R2 $ki");
119 # make sure to do 'D' first, not 'B', else we clash with
120 # the last add from the previous round.
121
122 &lea($a,&DWP($t,$a,$tmp2,1));
123
124 &add($b,$c); # MOVED FORWARD
125 &xor($tmp1,$d); # H function - part 2
126
127 &xor($tmp1,$b); # H function - part 3
128 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
129
130 &add($a,$tmp1);
131 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
132 &mov($tmp1,-1) if $pos == 1; # I function - part 1
133
134 &rotl($a,$s);
135
136 &add($a,$b);
137 }
138 }
139
140sub R3
141 {
142 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
143
144 &comment("R3 $ki");
145
146 # &not($tmp1)
147 &xor($tmp1,$d) if $pos < 0; # I function - part 2
148
149 &or($tmp1,$b); # I function - part 3
150 &lea($a,&DWP($t,$a,$tmp2,1));
151
152 &xor($tmp1,$c); # I function - part 4
153 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
154 &mov($tmp2,&wparam(0)) if $pos == 2;
155
156 &add($a,$tmp1);
157 &mov($tmp1,-1) if $pos < 1; # H function - part 1
158 &add($K,64) if $pos >=1 && !$normal;
159
160 &rotl($a,$s);
161
162 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
163 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
164 &add($a,$b);
165 }
166
167
168sub md5_block
169 {
170 local($name)=@_;
171
172 &function_begin_B($name,"",3);
173
174 # parameter 1 is the MD5_CTX structure.
175 # A 0
176 # B 4
177 # C 8
178 # D 12
179
180 &push("esi");
181 &push("edi");
182 &mov($tmp1, &wparam(0)); # edi
183 &mov($X, &wparam(1)); # esi
184 &mov($C, &wparam(2));
185 &push("ebp");
186 &shl($C, 6);
187 &push("ebx");
188 &add($C, $X); # offset we end at
189 &sub($C, 64);
190 &mov($A, &DWP( 0,$tmp1,"",0));
191 &push($C); # Put on the TOS
192 &mov($B, &DWP( 4,$tmp1,"",0));
193 &mov($C, &DWP( 8,$tmp1,"",0));
194 &mov($D, &DWP(12,$tmp1,"",0));
195
196 &set_label("start") unless $normal;
197 &comment("");
198 &comment("R0 section");
199
200 &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
201 &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
202 &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
203 &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
204 &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
205 &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
206 &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
207 &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
208 &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
209 &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
210 &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
211 &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
212 &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
213 &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
214 &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
215 &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);
216
217 &comment("");
218 &comment("R1 section");
219 &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
220 &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
221 &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
222 &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
223 &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
224 &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
225 &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
226 &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
227 &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
228 &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
229 &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
230 &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
231 &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
232 &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
233 &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
234 &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);
235
236 &comment("");
237 &comment("R2 section");
238 &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
239 &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
240 &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
241 &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
242 &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
243 &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
244 &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
245 &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
246 &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
247 &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
248 &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
249 &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
250 &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
251 &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
252 &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
253 &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);
254
255 &comment("");
256 &comment("R3 section");
257 &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
258 &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
259 &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
260 &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
261 &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
262 &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
263 &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
264 &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
265 &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
266 &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
267 &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
268 &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
269 &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
270 &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
271 &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
272 &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);
273
274 # &mov($tmp2,&wparam(0)); # done in the last R3
275 # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3
276
277 &add($A,$tmp1);
278 &mov($tmp1, &DWP( 4,$tmp2,"",0));
279
280 &add($B,$tmp1);
281 &mov($tmp1, &DWP( 8,$tmp2,"",0));
282
283 &add($C,$tmp1);
284 &mov($tmp1, &DWP(12,$tmp2,"",0));
285
286 &add($D,$tmp1);
287 &mov(&DWP( 0,$tmp2,"",0),$A);
288
289 &mov(&DWP( 4,$tmp2,"",0),$B);
290 &mov($tmp1,&swtmp(0)) unless $normal;
291
292 &mov(&DWP( 8,$tmp2,"",0),$C);
293 &mov(&DWP(12,$tmp2,"",0),$D);
294
295 &cmp($tmp1,$X) unless $normal; # check count
296 &jae(&label("start")) unless $normal;
297
298 &pop("eax"); # pop the temp variable off the stack
299 &pop("ebx");
300 &pop("ebp");
301 &pop("edi");
302 &pop("esi");
303 &ret();
304 &function_end_B($name);
305 }
306
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
new file mode 100644
index 0000000000..c663dd1816
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5.h
@@ -0,0 +1,119 @@
1/* crypto/md5/md5.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD5_H
60#define HEADER_MD5_H
61
62#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_MD5
69#error MD5 is disabled.
70#endif
71
72/*
73 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
74 * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
75 * ! MD5_LONG_LOG2 has to be defined along. !
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 */
78
79#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
80#define MD5_LONG unsigned long
81#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
82#define MD5_LONG unsigned long
83#define MD5_LONG_LOG2 3
84/*
85 * _CRAY note. I could declare short, but I have no idea what impact
86 * does it have on performance on none-T3E machines. I could declare
87 * int, but at least on C90 sizeof(int) can be chosen at compile time.
88 * So I've chosen long...
89 * <appro@fy.chalmers.se>
90 */
91#else
92#define MD5_LONG unsigned int
93#endif
94
95#define MD5_CBLOCK 64
96#define MD5_LBLOCK (MD5_CBLOCK/4)
97#define MD5_DIGEST_LENGTH 16
98
99typedef struct MD5state_st
100 {
101 MD5_LONG A,B,C,D;
102 MD5_LONG Nl,Nh;
103 MD5_LONG data[MD5_LBLOCK];
104 int num;
105 } MD5_CTX;
106
107#ifdef OPENSSL_FIPS
108int private_MD5_Init(MD5_CTX *c);
109#endif
110int MD5_Init(MD5_CTX *c);
111int MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
112int MD5_Final(unsigned char *md, MD5_CTX *c);
113unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);
114void MD5_Transform(MD5_CTX *c, const unsigned char *b);
115#ifdef __cplusplus
116}
117#endif
118
119#endif
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
new file mode 100644
index 0000000000..54b33c6509
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5_dgst.c
@@ -0,0 +1,292 @@
1/* crypto/md5/md5_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "md5_locl.h"
61#include <openssl/opensslv.h>
62
63const char *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
64
65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
66 */
67
68#define INIT_DATA_A (unsigned long)0x67452301L
69#define INIT_DATA_B (unsigned long)0xefcdab89L
70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L
72
73FIPS_NON_FIPS_MD_Init(MD5)
74 {
75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B;
77 c->C=INIT_DATA_C;
78 c->D=INIT_DATA_D;
79 c->Nl=0;
80 c->Nh=0;
81 c->num=0;
82 return 1;
83 }
84
85#ifndef md5_block_host_order
86void md5_block_host_order (MD5_CTX *c, const void *data, int num)
87 {
88 const MD5_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
100 R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
101 R0(C,D,A,B,X[ 2],17,0x242070dbL);
102 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
103 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
104 R0(D,A,B,C,X[ 5],12,0x4787c62aL);
105 R0(C,D,A,B,X[ 6],17,0xa8304613L);
106 R0(B,C,D,A,X[ 7],22,0xfd469501L);
107 R0(A,B,C,D,X[ 8], 7,0x698098d8L);
108 R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
109 R0(C,D,A,B,X[10],17,0xffff5bb1L);
110 R0(B,C,D,A,X[11],22,0x895cd7beL);
111 R0(A,B,C,D,X[12], 7,0x6b901122L);
112 R0(D,A,B,C,X[13],12,0xfd987193L);
113 R0(C,D,A,B,X[14],17,0xa679438eL);
114 R0(B,C,D,A,X[15],22,0x49b40821L);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
117 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
118 R1(C,D,A,B,X[11],14,0x265e5a51L);
119 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
120 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
121 R1(D,A,B,C,X[10], 9,0x02441453L);
122 R1(C,D,A,B,X[15],14,0xd8a1e681L);
123 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
124 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
125 R1(D,A,B,C,X[14], 9,0xc33707d6L);
126 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
127 R1(B,C,D,A,X[ 8],20,0x455a14edL);
128 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
129 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
130 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
131 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
134 R2(D,A,B,C,X[ 8],11,0x8771f681L);
135 R2(C,D,A,B,X[11],16,0x6d9d6122L);
136 R2(B,C,D,A,X[14],23,0xfde5380cL);
137 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
138 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
139 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
140 R2(B,C,D,A,X[10],23,0xbebfbc70L);
141 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
142 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
143 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
144 R2(B,C,D,A,X[ 6],23,0x04881d05L);
145 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
146 R2(D,A,B,C,X[12],11,0xe6db99e5L);
147 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
148 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
149 /* Round 3 */
150 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
151 R3(D,A,B,C,X[ 7],10,0x432aff97L);
152 R3(C,D,A,B,X[14],15,0xab9423a7L);
153 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
154 R3(A,B,C,D,X[12], 6,0x655b59c3L);
155 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
156 R3(C,D,A,B,X[10],15,0xffeff47dL);
157 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
158 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
159 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
160 R3(C,D,A,B,X[ 6],15,0xa3014314L);
161 R3(B,C,D,A,X[13],21,0x4e0811a1L);
162 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
163 R3(D,A,B,C,X[11],10,0xbd3af235L);
164 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
165 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
166
167 A = c->A += A;
168 B = c->B += B;
169 C = c->C += C;
170 D = c->D += D;
171 }
172 }
173#endif
174
175#ifndef md5_block_data_order
176#ifdef X
177#undef X
178#endif
179void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
180 {
181 const unsigned char *data=data_;
182 register unsigned MD32_REG_T A,B,C,D,l;
183#ifndef MD32_XARRAY
184 /* See comment in crypto/sha/sha_locl.h for details. */
185 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
186 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
187# define X(i) XX##i
188#else
189 MD5_LONG XX[MD5_LBLOCK];
190# define X(i) XX[i]
191#endif
192
193 A=c->A;
194 B=c->B;
195 C=c->C;
196 D=c->D;
197
198 for (;num--;)
199 {
200 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
201 /* Round 0 */
202 R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l;
203 R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l;
204 R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l;
205 R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l;
206 R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l;
207 R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l;
208 R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l;
209 R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l;
210 R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l;
211 R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l;
212 R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l;
213 R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l;
214 R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l;
215 R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l;
216 R0(C,D,A,B,X(14),17,0xa679438eL);
217 R0(B,C,D,A,X(15),22,0x49b40821L);
218 /* Round 1 */
219 R1(A,B,C,D,X( 1), 5,0xf61e2562L);
220 R1(D,A,B,C,X( 6), 9,0xc040b340L);
221 R1(C,D,A,B,X(11),14,0x265e5a51L);
222 R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
223 R1(A,B,C,D,X( 5), 5,0xd62f105dL);
224 R1(D,A,B,C,X(10), 9,0x02441453L);
225 R1(C,D,A,B,X(15),14,0xd8a1e681L);
226 R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
227 R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
228 R1(D,A,B,C,X(14), 9,0xc33707d6L);
229 R1(C,D,A,B,X( 3),14,0xf4d50d87L);
230 R1(B,C,D,A,X( 8),20,0x455a14edL);
231 R1(A,B,C,D,X(13), 5,0xa9e3e905L);
232 R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
233 R1(C,D,A,B,X( 7),14,0x676f02d9L);
234 R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
235 /* Round 2 */
236 R2(A,B,C,D,X( 5), 4,0xfffa3942L);
237 R2(D,A,B,C,X( 8),11,0x8771f681L);
238 R2(C,D,A,B,X(11),16,0x6d9d6122L);
239 R2(B,C,D,A,X(14),23,0xfde5380cL);
240 R2(A,B,C,D,X( 1), 4,0xa4beea44L);
241 R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
242 R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
243 R2(B,C,D,A,X(10),23,0xbebfbc70L);
244 R2(A,B,C,D,X(13), 4,0x289b7ec6L);
245 R2(D,A,B,C,X( 0),11,0xeaa127faL);
246 R2(C,D,A,B,X( 3),16,0xd4ef3085L);
247 R2(B,C,D,A,X( 6),23,0x04881d05L);
248 R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
249 R2(D,A,B,C,X(12),11,0xe6db99e5L);
250 R2(C,D,A,B,X(15),16,0x1fa27cf8L);
251 R2(B,C,D,A,X( 2),23,0xc4ac5665L);
252 /* Round 3 */
253 R3(A,B,C,D,X( 0), 6,0xf4292244L);
254 R3(D,A,B,C,X( 7),10,0x432aff97L);
255 R3(C,D,A,B,X(14),15,0xab9423a7L);
256 R3(B,C,D,A,X( 5),21,0xfc93a039L);
257 R3(A,B,C,D,X(12), 6,0x655b59c3L);
258 R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
259 R3(C,D,A,B,X(10),15,0xffeff47dL);
260 R3(B,C,D,A,X( 1),21,0x85845dd1L);
261 R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
262 R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
263 R3(C,D,A,B,X( 6),15,0xa3014314L);
264 R3(B,C,D,A,X(13),21,0x4e0811a1L);
265 R3(A,B,C,D,X( 4), 6,0xf7537e82L);
266 R3(D,A,B,C,X(11),10,0xbd3af235L);
267 R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
268 R3(B,C,D,A,X( 9),21,0xeb86d391L);
269
270 A = c->A += A;
271 B = c->B += B;
272 C = c->C += C;
273 D = c->D += D;
274 }
275 }
276#endif
277
278#ifdef undef
279int printit(unsigned long *l)
280 {
281 int i,ii;
282
283 for (i=0; i<2; i++)
284 {
285 for (ii=0; ii<8; ii++)
286 {
287 fprintf(stderr,"%08lx ",l[i*8+ii]);
288 }
289 fprintf(stderr,"\n");
290 }
291 }
292#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
new file mode 100644
index 0000000000..9e360da732
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5_locl.h
@@ -0,0 +1,172 @@
1/* crypto/md5/md5_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61#include <openssl/e_os2.h>
62#include <openssl/md5.h>
63
64#ifndef MD5_LONG_LOG2
65#define MD5_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68#ifdef MD5_ASM
69# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
70# define md5_block_host_order md5_block_asm_host_order
71# elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC)
72 void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num);
73# define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned
74# endif
75#endif
76
77void md5_block_host_order (MD5_CTX *c, const void *p,int num);
78void md5_block_data_order (MD5_CTX *c, const void *p,int num);
79
80#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
81/*
82 * *_block_host_order is expected to handle aligned data while
83 * *_block_data_order - unaligned. As algorithm and host (x86)
84 * are in this case of the same "endianness" these two are
85 * otherwise indistinguishable. But normally you don't want to
86 * call the same function because unaligned access in places
87 * where alignment is expected is usually a "Bad Thing". Indeed,
88 * on RISCs you get punished with BUS ERROR signal or *severe*
89 * performance degradation. Intel CPUs are in turn perfectly
90 * capable of loading unaligned data without such drastic side
91 * effect. Yes, they say it's slower than aligned load, but no
92 * exception is generated and therefore performance degradation
93 * is *incomparable* with RISCs. What we should weight here is
94 * costs of unaligned access against costs of aligning data.
95 * According to my measurements allowing unaligned access results
96 * in ~9% performance improvement on Pentium II operating at
97 * 266MHz. I won't be surprised if the difference will be higher
98 * on faster systems:-)
99 *
100 * <appro@fy.chalmers.se>
101 */
102#define md5_block_data_order md5_block_host_order
103#endif
104
105#define DATA_ORDER_IS_LITTLE_ENDIAN
106
107#define HASH_LONG MD5_LONG
108#define HASH_LONG_LOG2 MD5_LONG_LOG2
109#define HASH_CTX MD5_CTX
110#define HASH_CBLOCK MD5_CBLOCK
111#define HASH_LBLOCK MD5_LBLOCK
112#define HASH_UPDATE MD5_Update
113#define HASH_TRANSFORM MD5_Transform
114#define HASH_FINAL MD5_Final
115#define HASH_MAKE_STRING(c,s) do { \
116 unsigned long ll; \
117 ll=(c)->A; HOST_l2c(ll,(s)); \
118 ll=(c)->B; HOST_l2c(ll,(s)); \
119 ll=(c)->C; HOST_l2c(ll,(s)); \
120 ll=(c)->D; HOST_l2c(ll,(s)); \
121 } while (0)
122#define HASH_BLOCK_HOST_ORDER md5_block_host_order
123#if !defined(L_ENDIAN) || defined(md5_block_data_order)
124#define HASH_BLOCK_DATA_ORDER md5_block_data_order
125/*
126 * Little-endians (Intel and Alpha) feel better without this.
127 * It looks like memcpy does better job than generic
128 * md5_block_data_order on copying-n-aligning input data.
129 * But frankly speaking I didn't expect such result on Alpha.
130 * On the other hand I've got this with egcs-1.0.2 and if
131 * program is compiled with another (better?) compiler it
132 * might turn out other way around.
133 *
134 * <appro@fy.chalmers.se>
135 */
136#endif
137
138#include "md32_common.h"
139
140/*
141#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
142#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
143*/
144
145/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
146 * simplified to the code below. Wei attributes these optimizations
147 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
148 */
149#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
150#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
151#define H(b,c,d) ((b) ^ (c) ^ (d))
152#define I(b,c,d) (((~(d)) | (b)) ^ (c))
153
154#define R0(a,b,c,d,k,s,t) { \
155 a+=((k)+(t)+F((b),(c),(d))); \
156 a=ROTATE(a,s); \
157 a+=b; };\
158
159#define R1(a,b,c,d,k,s,t) { \
160 a+=((k)+(t)+G((b),(c),(d))); \
161 a=ROTATE(a,s); \
162 a+=b; };
163
164#define R2(a,b,c,d,k,s,t) { \
165 a+=((k)+(t)+H((b),(c),(d))); \
166 a=ROTATE(a,s); \
167 a+=b; };
168
169#define R3(a,b,c,d,k,s,t) { \
170 a+=((k)+(t)+I((b),(c),(d))); \
171 a=ROTATE(a,s); \
172 a+=b; };
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
new file mode 100644
index 0000000000..c5dd2d81db
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5_one.c
@@ -0,0 +1,96 @@
1/* crypto/md5/md5_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/md5.h>
62#include <openssl/crypto.h>
63
64#ifdef CHARSET_EBCDIC
65#include <openssl/ebcdic.h>
66#endif
67
68unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md)
69 {
70 MD5_CTX c;
71 static unsigned char m[MD5_DIGEST_LENGTH];
72
73 if (md == NULL) md=m;
74 MD5_Init(&c);
75#ifndef CHARSET_EBCDIC
76 MD5_Update(&c,d,n);
77#else
78 {
79 char temp[1024];
80 unsigned long chunk;
81
82 while (n > 0)
83 {
84 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
85 ebcdic2ascii(temp, d, chunk);
86 MD5_Update(&c,temp,chunk);
87 n -= chunk;
88 d += chunk;
89 }
90 }
91#endif
92 MD5_Final(md,&c);
93 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
94 return(md);
95 }
96
diff --git a/src/lib/libcrypto/mdc2/Makefile b/src/lib/libcrypto/mdc2/Makefile
index b8e9a9a4fa..38c785bf95 100644
--- a/src/lib/libcrypto/mdc2/Makefile
+++ b/src/lib/libcrypto/mdc2/Makefile
@@ -1,5 +1,5 @@
1# 1#
2# OpenSSL/crypto/mdc2/Makefile 2# SSLeay/crypto/mdc2/Makefile
3# 3#
4 4
5DIR= mdc2 5DIR= mdc2
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/mem_clr.c b/src/lib/libcrypto/mem_clr.c
new file mode 100644
index 0000000000..e4b7f540b0
--- /dev/null
+++ b/src/lib/libcrypto/mem_clr.c
@@ -0,0 +1,75 @@
1/* crypto/mem_clr.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2002.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/crypto.h>
61
62unsigned char cleanse_ctr = 0;
63
64void OPENSSL_cleanse(void *ptr, size_t len)
65 {
66 unsigned char *p = ptr;
67 size_t loop = len;
68 while(loop--)
69 {
70 *(p++) = cleanse_ctr;
71 cleanse_ctr += (17 + (unsigned char)((int)p & 0xF));
72 }
73 if(memchr(ptr, cleanse_ctr, len))
74 cleanse_ctr += 63;
75 }
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c
new file mode 100644
index 0000000000..e212de27e4
--- /dev/null
+++ b/src/lib/libcrypto/mem_dbg.c
@@ -0,0 +1,787 @@
1/* crypto/mem_dbg.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <time.h>
62#include <openssl/crypto.h>
63#include <openssl/buffer.h>
64#include <openssl/bio.h>
65#include <openssl/lhash.h>
66#include "cryptlib.h"
67
68static int mh_mode=CRYPTO_MEM_CHECK_OFF;
69/* The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE
70 * when the application asks for it (usually after library initialisation
71 * for which no book-keeping is desired).
72 *
73 * State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
74 * thinks that certain allocations should not be checked (e.g. the data
75 * structures used for memory checking). It is not suitable as an initial
76 * state: the library will unexpectedly enable memory checking when it
77 * executes one of those sections that want to disable checking
78 * temporarily.
79 *
80 * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
81 */
82
83static unsigned long order = 0; /* number of memory requests */
84static LHASH *mh=NULL; /* hash-table of memory requests (address as key);
85 * access requires MALLOC2 lock */
86
87
88typedef struct app_mem_info_st
89/* For application-defined information (static C-string `info')
90 * to be displayed in memory leak list.
91 * Each thread has its own stack. For applications, there is
92 * CRYPTO_push_info("...") to push an entry,
93 * CRYPTO_pop_info() to pop an entry,
94 * CRYPTO_remove_all_info() to pop all entries.
95 */
96 {
97 unsigned long thread;
98 const char *file;
99 int line;
100 const char *info;
101 struct app_mem_info_st *next; /* tail of thread's stack */
102 int references;
103 } APP_INFO;
104
105static void app_info_free(APP_INFO *);
106
107static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
108 * that are at the top of their thread's stack
109 * (with `thread' as key);
110 * access requires MALLOC2 lock */
111
112typedef struct mem_st
113/* memory-block description */
114 {
115 void *addr;
116 int num;
117 const char *file;
118 int line;
119 unsigned long thread;
120 unsigned long order;
121 time_t time;
122 APP_INFO *app_info;
123 } MEM;
124
125static long options = /* extra information to be recorded */
126#if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
127 V_CRYPTO_MDEBUG_TIME |
128#endif
129#if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
130 V_CRYPTO_MDEBUG_THREAD |
131#endif
132 0;
133
134
135static unsigned int num_disable = 0; /* num_disable > 0
136 * iff
137 * mh_mode == CRYPTO_MEM_CHECK_ON (w/o ..._ENABLE)
138 */
139static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0.
140 * CRYPTO_LOCK_MALLOC2 is locked
141 * exactly in this case (by the
142 * thread named in disabling_thread).
143 */
144
145static void app_info_free(APP_INFO *inf)
146 {
147 if (--(inf->references) <= 0)
148 {
149 if (inf->next != NULL)
150 {
151 app_info_free(inf->next);
152 }
153 OPENSSL_free(inf);
154 }
155 }
156
157int CRYPTO_mem_ctrl(int mode)
158 {
159 int ret=mh_mode;
160
161 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
162 switch (mode)
163 {
164 /* for applications (not to be called while multiple threads
165 * use the library): */
166 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
167 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
168 num_disable = 0;
169 break;
170 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
171 mh_mode = 0;
172 num_disable = 0; /* should be true *before* MemCheck_stop is used,
173 or there'll be a lot of confusion */
174 break;
175
176 /* switch off temporarily (for library-internal use): */
177 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
178 if (mh_mode & CRYPTO_MEM_CHECK_ON)
179 {
180 if (!num_disable || (disabling_thread != CRYPTO_thread_id())) /* otherwise we already have the MALLOC2 lock */
181 {
182 /* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
183 * we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
184 * somebody else holds CRYPTO_LOCK_MALLOC2 (and cannot release
185 * it because we block entry to this function).
186 * Give them a chance, first, and then claim the locks in
187 * appropriate order (long-time lock first).
188 */
189 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
190 /* Note that after we have waited for CRYPTO_LOCK_MALLOC2
191 * and CRYPTO_LOCK_MALLOC, we'll still be in the right
192 * "case" and "if" branch because MemCheck_start and
193 * MemCheck_stop may never be used while there are multiple
194 * OpenSSL threads. */
195 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
196 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
197 mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;
198 disabling_thread=CRYPTO_thread_id();
199 }
200 num_disable++;
201 }
202 break;
203 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
204 if (mh_mode & CRYPTO_MEM_CHECK_ON)
205 {
206 if (num_disable) /* always true, or something is going wrong */
207 {
208 num_disable--;
209 if (num_disable == 0)
210 {
211 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
212 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
213 }
214 }
215 }
216 break;
217
218 default:
219 break;
220 }
221 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
222 return(ret);
223 }
224
225int CRYPTO_is_mem_check_on(void)
226 {
227 int ret = 0;
228
229 if (mh_mode & CRYPTO_MEM_CHECK_ON)
230 {
231 CRYPTO_r_lock(CRYPTO_LOCK_MALLOC);
232
233 ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
234 || (disabling_thread != CRYPTO_thread_id());
235
236 CRYPTO_r_unlock(CRYPTO_LOCK_MALLOC);
237 }
238 return(ret);
239 }
240
241
242void CRYPTO_dbg_set_options(long bits)
243 {
244 options = bits;
245 }
246
247long CRYPTO_dbg_get_options(void)
248 {
249 return options;
250 }
251
252/* static int mem_cmp(MEM *a, MEM *b) */
253static int mem_cmp(const void *a_void, const void *b_void)
254 {
255 return((const char *)((const MEM *)a_void)->addr
256 - (const char *)((const MEM *)b_void)->addr);
257 }
258
259/* static unsigned long mem_hash(MEM *a) */
260static unsigned long mem_hash(const void *a_void)
261 {
262 unsigned long ret;
263
264 ret=(unsigned long)((const MEM *)a_void)->addr;
265
266 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
267 return(ret);
268 }
269
270/* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */
271static int app_info_cmp(const void *a_void, const void *b_void)
272 {
273 return(((const APP_INFO *)a_void)->thread
274 != ((const APP_INFO *)b_void)->thread);
275 }
276
277/* static unsigned long app_info_hash(APP_INFO *a) */
278static unsigned long app_info_hash(const void *a_void)
279 {
280 unsigned long ret;
281
282 ret=(unsigned long)((const APP_INFO *)a_void)->thread;
283
284 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
285 return(ret);
286 }
287
288static APP_INFO *pop_info(void)
289 {
290 APP_INFO tmp;
291 APP_INFO *ret = NULL;
292
293 if (amih != NULL)
294 {
295 tmp.thread=CRYPTO_thread_id();
296 if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
297 {
298 APP_INFO *next=ret->next;
299
300 if (next != NULL)
301 {
302 next->references++;
303 lh_insert(amih,(char *)next);
304 }
305#ifdef LEVITTE_DEBUG_MEM
306 if (ret->thread != tmp.thread)
307 {
308 fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
309 ret->thread, tmp.thread);
310 abort();
311 }
312#endif
313 if (--(ret->references) <= 0)
314 {
315 ret->next = NULL;
316 if (next != NULL)
317 next->references--;
318 OPENSSL_free(ret);
319 }
320 }
321 }
322 return(ret);
323 }
324
325int CRYPTO_push_info_(const char *info, const char *file, int line)
326 {
327 APP_INFO *ami, *amim;
328 int ret=0;
329
330 if (is_MemCheck_on())
331 {
332 MemCheck_off(); /* obtain MALLOC2 lock */
333
334 if ((ami = (APP_INFO *)OPENSSL_malloc(sizeof(APP_INFO))) == NULL)
335 {
336 ret=0;
337 goto err;
338 }
339 if (amih == NULL)
340 {
341 if ((amih=lh_new(app_info_hash, app_info_cmp)) == NULL)
342 {
343 OPENSSL_free(ami);
344 ret=0;
345 goto err;
346 }
347 }
348
349 ami->thread=CRYPTO_thread_id();
350 ami->file=file;
351 ami->line=line;
352 ami->info=info;
353 ami->references=1;
354 ami->next=NULL;
355
356 if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
357 {
358#ifdef LEVITTE_DEBUG_MEM
359 if (ami->thread != amim->thread)
360 {
361 fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
362 amim->thread, ami->thread);
363 abort();
364 }
365#endif
366 ami->next=amim;
367 }
368 err:
369 MemCheck_on(); /* release MALLOC2 lock */
370 }
371
372 return(ret);
373 }
374
375int CRYPTO_pop_info(void)
376 {
377 int ret=0;
378
379 if (is_MemCheck_on()) /* _must_ be true, or something went severely wrong */
380 {
381 MemCheck_off(); /* obtain MALLOC2 lock */
382
383 ret=(pop_info() != NULL);
384
385 MemCheck_on(); /* release MALLOC2 lock */
386 }
387 return(ret);
388 }
389
390int CRYPTO_remove_all_info(void)
391 {
392 int ret=0;
393
394 if (is_MemCheck_on()) /* _must_ be true */
395 {
396 MemCheck_off(); /* obtain MALLOC2 lock */
397
398 while(pop_info() != NULL)
399 ret++;
400
401 MemCheck_on(); /* release MALLOC2 lock */
402 }
403 return(ret);
404 }
405
406
407static unsigned long break_order_num=0;
408void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
409 int before_p)
410 {
411 MEM *m,*mm;
412 APP_INFO tmp,*amim;
413
414 switch(before_p & 127)
415 {
416 case 0:
417 break;
418 case 1:
419 if (addr == NULL)
420 break;
421
422 if (is_MemCheck_on())
423 {
424 MemCheck_off(); /* make sure we hold MALLOC2 lock */
425 if ((m=(MEM *)OPENSSL_malloc(sizeof(MEM))) == NULL)
426 {
427 OPENSSL_free(addr);
428 MemCheck_on(); /* release MALLOC2 lock
429 * if num_disabled drops to 0 */
430 return;
431 }
432 if (mh == NULL)
433 {
434 if ((mh=lh_new(mem_hash, mem_cmp)) == NULL)
435 {
436 OPENSSL_free(addr);
437 OPENSSL_free(m);
438 addr=NULL;
439 goto err;
440 }
441 }
442
443 m->addr=addr;
444 m->file=file;
445 m->line=line;
446 m->num=num;
447 if (options & V_CRYPTO_MDEBUG_THREAD)
448 m->thread=CRYPTO_thread_id();
449 else
450 m->thread=0;
451
452 if (order == break_order_num)
453 {
454 /* BREAK HERE */
455 m->order=order;
456 }
457 m->order=order++;
458#ifdef LEVITTE_DEBUG_MEM
459 fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] %c 0x%p (%d)\n",
460 m->order,
461 (before_p & 128) ? '*' : '+',
462 m->addr, m->num);
463#endif
464 if (options & V_CRYPTO_MDEBUG_TIME)
465 m->time=time(NULL);
466 else
467 m->time=0;
468
469 tmp.thread=CRYPTO_thread_id();
470 m->app_info=NULL;
471 if (amih != NULL
472 && (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
473 {
474 m->app_info = amim;
475 amim->references++;
476 }
477
478 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
479 {
480 /* Not good, but don't sweat it */
481 if (mm->app_info != NULL)
482 {
483 mm->app_info->references--;
484 }
485 OPENSSL_free(mm);
486 }
487 err:
488 MemCheck_on(); /* release MALLOC2 lock
489 * if num_disabled drops to 0 */
490 }
491 break;
492 }
493 return;
494 }
495
496void CRYPTO_dbg_free(void *addr, int before_p)
497 {
498 MEM m,*mp;
499
500 switch(before_p)
501 {
502 case 0:
503 if (addr == NULL)
504 break;
505
506 if (is_MemCheck_on() && (mh != NULL))
507 {
508 MemCheck_off(); /* make sure we hold MALLOC2 lock */
509
510 m.addr=addr;
511 mp=(MEM *)lh_delete(mh,(char *)&m);
512 if (mp != NULL)
513 {
514#ifdef LEVITTE_DEBUG_MEM
515 fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] - 0x%p (%d)\n",
516 mp->order, mp->addr, mp->num);
517#endif
518 if (mp->app_info != NULL)
519 app_info_free(mp->app_info);
520 OPENSSL_free(mp);
521 }
522
523 MemCheck_on(); /* release MALLOC2 lock
524 * if num_disabled drops to 0 */
525 }
526 break;
527 case 1:
528 break;
529 }
530 }
531
532void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,
533 const char *file, int line, int before_p)
534 {
535 MEM m,*mp;
536
537#ifdef LEVITTE_DEBUG_MEM
538 fprintf(stderr, "LEVITTE_DEBUG_MEM: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n",
539 addr1, addr2, num, file, line, before_p);
540#endif
541
542 switch(before_p)
543 {
544 case 0:
545 break;
546 case 1:
547 if (addr2 == NULL)
548 break;
549
550 if (addr1 == NULL)
551 {
552 CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);
553 break;
554 }
555
556 if (is_MemCheck_on())
557 {
558 MemCheck_off(); /* make sure we hold MALLOC2 lock */
559
560 m.addr=addr1;
561 mp=(MEM *)lh_delete(mh,(char *)&m);
562 if (mp != NULL)
563 {
564#ifdef LEVITTE_DEBUG_MEM
565 fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
566 mp->order,
567 mp->addr, mp->num,
568 addr2, num);
569#endif
570 mp->addr=addr2;
571 mp->num=num;
572 lh_insert(mh,(char *)mp);
573 }
574
575 MemCheck_on(); /* release MALLOC2 lock
576 * if num_disabled drops to 0 */
577 }
578 break;
579 }
580 return;
581 }
582
583
584typedef struct mem_leak_st
585 {
586 BIO *bio;
587 int chunks;
588 long bytes;
589 } MEM_LEAK;
590
591static void print_leak(const MEM *m, MEM_LEAK *l)
592 {
593 char buf[1024];
594 char *bufp = buf;
595 APP_INFO *amip;
596 int ami_cnt;
597 struct tm *lcl = NULL;
598 unsigned long ti;
599
600#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
601
602 if(m->addr == (char *)l->bio)
603 return;
604
605 if (options & V_CRYPTO_MDEBUG_TIME)
606 {
607 lcl = localtime(&m->time);
608
609 BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",
610 lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
611 bufp += strlen(bufp);
612 }
613
614 BIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ",
615 m->order,m->file,m->line);
616 bufp += strlen(bufp);
617
618 if (options & V_CRYPTO_MDEBUG_THREAD)
619 {
620 BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ", m->thread);
621 bufp += strlen(bufp);
622 }
623
624 BIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\n",
625 m->num,(unsigned long)m->addr);
626 bufp += strlen(bufp);
627
628 BIO_puts(l->bio,buf);
629
630 l->chunks++;
631 l->bytes+=m->num;
632
633 amip=m->app_info;
634 ami_cnt=0;
635 if (!amip)
636 return;
637 ti=amip->thread;
638
639 do
640 {
641 int buf_len;
642 int info_len;
643
644 ami_cnt++;
645 memset(buf,'>',ami_cnt);
646 BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,
647 " thread=%lu, file=%s, line=%d, info=\"",
648 amip->thread, amip->file, amip->line);
649 buf_len=strlen(buf);
650 info_len=strlen(amip->info);
651 if (128 - buf_len - 3 < info_len)
652 {
653 memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
654 buf_len = 128 - 3;
655 }
656 else
657 {
658 BUF_strlcpy(buf + buf_len, amip->info,
659 sizeof buf - buf_len);
660 buf_len = strlen(buf);
661 }
662 BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n");
663
664 BIO_puts(l->bio,buf);
665
666 amip = amip->next;
667 }
668 while(amip && amip->thread == ti);
669
670#ifdef LEVITTE_DEBUG_MEM
671 if (amip)
672 {
673 fprintf(stderr, "Thread switch detected in backtrace!!!!\n");
674 abort();
675 }
676#endif
677 }
678
679static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM *, MEM_LEAK *)
680
681void CRYPTO_mem_leaks(BIO *b)
682 {
683 MEM_LEAK ml;
684
685 if (mh == NULL && amih == NULL)
686 return;
687
688 MemCheck_off(); /* obtain MALLOC2 lock */
689
690 ml.bio=b;
691 ml.bytes=0;
692 ml.chunks=0;
693 if (mh != NULL)
694 lh_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak),
695 (char *)&ml);
696 if (ml.chunks != 0)
697 {
698 BIO_printf(b,"%ld bytes leaked in %d chunks\n",
699 ml.bytes,ml.chunks);
700 }
701 else
702 {
703 /* Make sure that, if we found no leaks, memory-leak debugging itself
704 * does not introduce memory leaks (which might irritate
705 * external debugging tools).
706 * (When someone enables leak checking, but does not call
707 * this function, we declare it to be their fault.)
708 *
709 * XXX This should be in CRYPTO_mem_leaks_cb,
710 * and CRYPTO_mem_leaks should be implemented by
711 * using CRYPTO_mem_leaks_cb.
712 * (Also their should be a variant of lh_doall_arg
713 * that takes a function pointer instead of a void *;
714 * this would obviate the ugly and illegal
715 * void_fn_to_char kludge in CRYPTO_mem_leaks_cb.
716 * Otherwise the code police will come and get us.)
717 */
718 int old_mh_mode;
719
720 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
721
722 /* avoid deadlock when lh_free() uses CRYPTO_dbg_free(),
723 * which uses CRYPTO_is_mem_check_on */
724 old_mh_mode = mh_mode;
725 mh_mode = CRYPTO_MEM_CHECK_OFF;
726
727 if (mh != NULL)
728 {
729 lh_free(mh);
730 mh = NULL;
731 }
732 if (amih != NULL)
733 {
734 if (lh_num_items(amih) == 0)
735 {
736 lh_free(amih);
737 amih = NULL;
738 }
739 }
740
741 mh_mode = old_mh_mode;
742 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
743 }
744 MemCheck_on(); /* release MALLOC2 lock */
745 }
746
747#ifndef OPENSSL_NO_FP_API
748void CRYPTO_mem_leaks_fp(FILE *fp)
749 {
750 BIO *b;
751
752 if (mh == NULL) return;
753 /* Need to turn off memory checking when allocated BIOs ... especially
754 * as we're creating them at a time when we're trying to check we've not
755 * left anything un-free()'d!! */
756 MemCheck_off();
757 b = BIO_new(BIO_s_file());
758 MemCheck_on();
759 if(!b) return;
760 BIO_set_fp(b,fp,BIO_NOCLOSE);
761 CRYPTO_mem_leaks(b);
762 BIO_free(b);
763 }
764#endif
765
766
767
768/* FIXME: We really don't allow much to the callback. For example, it has
769 no chance of reaching the info stack for the item it processes. Should
770 it really be this way? -- Richard Levitte */
771/* NB: The prototypes have been typedef'd to CRYPTO_MEM_LEAK_CB inside crypto.h
772 * If this code is restructured, remove the callback type if it is no longer
773 * needed. -- Geoff Thorpe */
774static void cb_leak(const MEM *m, CRYPTO_MEM_LEAK_CB **cb)
775 {
776 (**cb)(m->order,m->file,m->line,m->num,m->addr);
777 }
778
779static IMPLEMENT_LHASH_DOALL_ARG_FN(cb_leak, const MEM *, CRYPTO_MEM_LEAK_CB **)
780
781void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb)
782 {
783 if (mh == NULL) return;
784 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
785 lh_doall_arg(mh, LHASH_DOALL_ARG_FN(cb_leak), &cb);
786 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
787 }
diff --git a/src/lib/libcrypto/o_str.c b/src/lib/libcrypto/o_str.c
new file mode 100644
index 0000000000..da8860491d
--- /dev/null
+++ b/src/lib/libcrypto/o_str.c
@@ -0,0 +1,96 @@
1/* crypto/o_str.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <ctype.h>
60#include <e_os.h>
61#include "o_str.h"
62
63int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n)
64 {
65#if defined(OPENSSL_IMPLEMENTS_strncasecmp)
66 while (*str1 && *str2 && n)
67 {
68 int res = toupper(*str1) - toupper(*str2);
69 if (res) return res < 0 ? -1 : 1;
70 str1++;
71 str2++;
72 n--;
73 }
74 if (n == 0)
75 return 0;
76 if (*str1)
77 return 1;
78 if (*str2)
79 return -1;
80 return 0;
81#else
82 /* Recursion hazard warning! Whenever strncasecmp is #defined as
83 * OPENSSL_strncasecmp, OPENSSL_IMPLEMENTS_strncasecmp must be
84 * defined as well. */
85 return strncasecmp(str1, str2, n);
86#endif
87 }
88int OPENSSL_strcasecmp(const char *str1, const char *str2)
89 {
90#if defined(OPENSSL_IMPLEMENTS_strncasecmp)
91 return OPENSSL_strncasecmp(str1, str2, (size_t)-1);
92#else
93 return strcasecmp(str1, str2);
94#endif
95 }
96
diff --git a/src/lib/libcrypto/o_time.c b/src/lib/libcrypto/o_time.c
new file mode 100644
index 0000000000..e29091d650
--- /dev/null
+++ b/src/lib/libcrypto/o_time.c
@@ -0,0 +1,217 @@
1/* crypto/o_time.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/e_os2.h>
60#include <string.h>
61#include "o_time.h"
62
63#ifdef OPENSSL_SYS_VMS
64# include <libdtdef.h>
65# include <lib$routines.h>
66# include <lnmdef.h>
67# include <starlet.h>
68# include <descrip.h>
69# include <stdlib.h>
70#endif
71
72struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
73 {
74 struct tm *ts = NULL;
75
76#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && !defined(__CYGWIN32__) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
77 /* should return &data, but doesn't on some systems,
78 so we don't even look at the return value */
79 gmtime_r(timer,result);
80 ts = result;
81#elif !defined(OPENSSL_SYS_VMS)
82 ts = gmtime(timer);
83 if (ts == NULL)
84 return NULL;
85
86 memcpy(result, ts, sizeof(struct tm));
87 ts = result;
88#endif
89#ifdef OPENSSL_SYS_VMS
90 if (ts == NULL)
91 {
92 static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
93 static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL");
94 char logvalue[256];
95 unsigned int reslen = 0;
96 struct {
97 short buflen;
98 short code;
99 void *bufaddr;
100 unsigned int *reslen;
101 } itemlist[] = {
102 { 0, LNM$_STRING, 0, 0 },
103 { 0, 0, 0, 0 },
104 };
105 int status;
106 time_t t;
107
108 /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
109 itemlist[0].buflen = sizeof(logvalue);
110 itemlist[0].bufaddr = logvalue;
111 itemlist[0].reslen = &reslen;
112 status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
113 if (!(status & 1))
114 return NULL;
115 logvalue[reslen] = '\0';
116
117 t = *timer;
118
119/* The following is extracted from the DEC C header time.h */
120/*
121** Beginning in OpenVMS Version 7.0 mktime, time, ctime, strftime
122** have two implementations. One implementation is provided
123** for compatibility and deals with time in terms of local time,
124** the other __utc_* deals with time in terms of UTC.
125*/
126/* We use the same conditions as in said time.h to check if we should
127 assume that t contains local time (and should therefore be adjusted)
128 or UTC (and should therefore be left untouched). */
129#if __CRTL_VER < 70000000 || defined _VMS_V6_SOURCE
130 /* Get the numerical value of the equivalence string */
131 status = atoi(logvalue);
132
133 /* and use it to move time to GMT */
134 t -= status;
135#endif
136
137 /* then convert the result to the time structure */
138
139 /* Since there was no gmtime_r() to do this stuff for us,
140 we have to do it the hard way. */
141 {
142 /* The VMS epoch is the astronomical Smithsonian date,
143 if I remember correctly, which is November 17, 1858.
144 Furthermore, time is measure in thenths of microseconds
145 and stored in quadwords (64 bit integers). unix_epoch
146 below is January 1st 1970 expressed as a VMS time. The
147 following code was used to get this number:
148
149 #include <stdio.h>
150 #include <stdlib.h>
151 #include <lib$routines.h>
152 #include <starlet.h>
153
154 main()
155 {
156 unsigned long systime[2];
157 unsigned short epoch_values[7] =
158 { 1970, 1, 1, 0, 0, 0, 0 };
159
160 lib$cvt_vectim(epoch_values, systime);
161
162 printf("%u %u", systime[0], systime[1]);
163 }
164 */
165 unsigned long unix_epoch[2] = { 1273708544, 8164711 };
166 unsigned long deltatime[2];
167 unsigned long systime[2];
168 struct vms_vectime
169 {
170 short year, month, day, hour, minute, second,
171 centi_second;
172 } time_values;
173 long operation;
174
175 /* Turn the number of seconds since January 1st 1970 to
176 an internal delta time.
177 Note that lib$cvt_to_internal_time() will assume
178 that t is signed, and will therefore break on 32-bit
179 systems some time in 2038.
180 */
181 operation = LIB$K_DELTA_SECONDS;
182 status = lib$cvt_to_internal_time(&operation,
183 &t, deltatime);
184
185 /* Add the delta time with the Unix epoch and we have
186 the current UTC time in internal format */
187 status = lib$add_times(unix_epoch, deltatime, systime);
188
189 /* Turn the internal time into a time vector */
190 status = sys$numtim(&time_values, systime);
191
192 /* Fill in the struct tm with the result */
193 result->tm_sec = time_values.second;
194 result->tm_min = time_values.minute;
195 result->tm_hour = time_values.hour;
196 result->tm_mday = time_values.day;
197 result->tm_mon = time_values.month - 1;
198 result->tm_year = time_values.year - 1900;
199
200 operation = LIB$K_DAY_OF_WEEK;
201 status = lib$cvt_from_internal_time(&operation,
202 &result->tm_wday, systime);
203 result->tm_wday %= 7;
204
205 operation = LIB$K_DAY_OF_YEAR;
206 status = lib$cvt_from_internal_time(&operation,
207 &result->tm_yday, systime);
208 result->tm_yday--;
209
210 result->tm_isdst = 0; /* There's no way to know... */
211
212 ts = result;
213 }
214 }
215#endif
216 return ts;
217 }
diff --git a/src/lib/libcrypto/o_time.h b/src/lib/libcrypto/o_time.h
new file mode 100644
index 0000000000..e66044626d
--- /dev/null
+++ b/src/lib/libcrypto/o_time.h
@@ -0,0 +1,66 @@
1/* crypto/o_time.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_O_TIME_H
60#define HEADER_O_TIME_H
61
62#include <time.h>
63
64struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
65
66#endif
diff --git a/src/lib/libcrypto/objects/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
new file mode 100644
index 0000000000..28c9370ca3
--- /dev/null
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -0,0 +1,369 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <openssl/err.h>
6#include <openssl/lhash.h>
7#include <openssl/objects.h>
8#include <openssl/safestack.h>
9#include <openssl/e_os2.h>
10
11/* Later versions of DEC C has started to add lnkage information to certain
12 * functions, which makes it tricky to use them as values to regular function
13 * pointers. One way is to define a macro that takes care of casting them
14 * correctly.
15 */
16#ifdef OPENSSL_SYS_VMS_DECC
17# define OPENSSL_strcmp (int (*)(const char *,const char *))strcmp
18#else
19# define OPENSSL_strcmp strcmp
20#endif
21
22/* I use the ex_data stuff to manage the identifiers for the obj_name_types
23 * that applications may define. I only really use the free function field.
24 */
25static LHASH *names_lh=NULL;
26static int names_type_num=OBJ_NAME_TYPE_NUM;
27
28typedef struct name_funcs_st
29 {
30 unsigned long (*hash_func)(const char *name);
31 int (*cmp_func)(const char *a,const char *b);
32 void (*free_func)(const char *, int, const char *);
33 } NAME_FUNCS;
34
35DECLARE_STACK_OF(NAME_FUNCS)
36IMPLEMENT_STACK_OF(NAME_FUNCS)
37
38static STACK_OF(NAME_FUNCS) *name_funcs_stack;
39
40/* The LHASH callbacks now use the raw "void *" prototypes and do per-variable
41 * casting in the functions. This prevents function pointer casting without the
42 * need for macro-generated wrapper functions. */
43
44/* static unsigned long obj_name_hash(OBJ_NAME *a); */
45static unsigned long obj_name_hash(const void *a_void);
46/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
47static int obj_name_cmp(const void *a_void,const void *b_void);
48
49int OBJ_NAME_init(void)
50 {
51 if (names_lh != NULL) return(1);
52 MemCheck_off();
53 names_lh=lh_new(obj_name_hash, obj_name_cmp);
54 MemCheck_on();
55 return(names_lh != NULL);
56 }
57
58int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
59 int (*cmp_func)(const char *, const char *),
60 void (*free_func)(const char *, int, const char *))
61 {
62 int ret;
63 int i;
64 NAME_FUNCS *name_funcs;
65
66 if (name_funcs_stack == NULL)
67 {
68 MemCheck_off();
69 name_funcs_stack=sk_NAME_FUNCS_new_null();
70 MemCheck_on();
71 }
72 if ((name_funcs_stack == NULL))
73 {
74 /* ERROR */
75 return(0);
76 }
77 ret=names_type_num;
78 names_type_num++;
79 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++)
80 {
81 MemCheck_off();
82 name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS));
83 MemCheck_on();
84 if (!name_funcs)
85 {
86 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX,ERR_R_MALLOC_FAILURE);
87 return(0);
88 }
89 name_funcs->hash_func = lh_strhash;
90 name_funcs->cmp_func = OPENSSL_strcmp;
91 name_funcs->free_func = 0; /* NULL is often declared to
92 * ((void *)0), which according
93 * to Compaq C is not really
94 * compatible with a function
95 * pointer. -- Richard Levitte*/
96 MemCheck_off();
97 sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
98 MemCheck_on();
99 }
100 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
101 if (hash_func != NULL)
102 name_funcs->hash_func = hash_func;
103 if (cmp_func != NULL)
104 name_funcs->cmp_func = cmp_func;
105 if (free_func != NULL)
106 name_funcs->free_func = free_func;
107 return(ret);
108 }
109
110/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */
111static int obj_name_cmp(const void *a_void, const void *b_void)
112 {
113 int ret;
114 OBJ_NAME *a = (OBJ_NAME *)a_void;
115 OBJ_NAME *b = (OBJ_NAME *)b_void;
116
117 ret=a->type-b->type;
118 if (ret == 0)
119 {
120 if ((name_funcs_stack != NULL)
121 && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
122 {
123 ret=sk_NAME_FUNCS_value(name_funcs_stack,
124 a->type)->cmp_func(a->name,b->name);
125 }
126 else
127 ret=strcmp(a->name,b->name);
128 }
129 return(ret);
130 }
131
132/* static unsigned long obj_name_hash(OBJ_NAME *a) */
133static unsigned long obj_name_hash(const void *a_void)
134 {
135 unsigned long ret;
136 OBJ_NAME *a = (OBJ_NAME *)a_void;
137
138 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
139 {
140 ret=sk_NAME_FUNCS_value(name_funcs_stack,
141 a->type)->hash_func(a->name);
142 }
143 else
144 {
145 ret=lh_strhash(a->name);
146 }
147 ret^=a->type;
148 return(ret);
149 }
150
151const char *OBJ_NAME_get(const char *name, int type)
152 {
153 OBJ_NAME on,*ret;
154 int num=0,alias;
155
156 if (name == NULL) return(NULL);
157 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL);
158
159 alias=type&OBJ_NAME_ALIAS;
160 type&= ~OBJ_NAME_ALIAS;
161
162 on.name=name;
163 on.type=type;
164
165 for (;;)
166 {
167 ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
168 if (ret == NULL) return(NULL);
169 if ((ret->alias) && !alias)
170 {
171 if (++num > 10) return(NULL);
172 on.name=ret->data;
173 }
174 else
175 {
176 return(ret->data);
177 }
178 }
179 }
180
181int OBJ_NAME_add(const char *name, int type, const char *data)
182 {
183 OBJ_NAME *onp,*ret;
184 int alias;
185
186 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);
187
188 alias=type&OBJ_NAME_ALIAS;
189 type&= ~OBJ_NAME_ALIAS;
190
191 onp=(OBJ_NAME *)OPENSSL_malloc(sizeof(OBJ_NAME));
192 if (onp == NULL)
193 {
194 /* ERROR */
195 return(0);
196 }
197
198 onp->name=name;
199 onp->alias=alias;
200 onp->type=type;
201 onp->data=data;
202
203 ret=(OBJ_NAME *)lh_insert(names_lh,onp);
204 if (ret != NULL)
205 {
206 /* free things */
207 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
208 {
209 /* XXX: I'm not sure I understand why the free
210 * function should get three arguments...
211 * -- Richard Levitte
212 */
213 sk_NAME_FUNCS_value(name_funcs_stack,
214 ret->type)->free_func(ret->name,ret->type,ret->data);
215 }
216 OPENSSL_free(ret);
217 }
218 else
219 {
220 if (lh_error(names_lh))
221 {
222 /* ERROR */
223 return(0);
224 }
225 }
226 return(1);
227 }
228
229int OBJ_NAME_remove(const char *name, int type)
230 {
231 OBJ_NAME on,*ret;
232
233 if (names_lh == NULL) return(0);
234
235 type&= ~OBJ_NAME_ALIAS;
236 on.name=name;
237 on.type=type;
238 ret=(OBJ_NAME *)lh_delete(names_lh,&on);
239 if (ret != NULL)
240 {
241 /* free things */
242 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
243 {
244 /* XXX: I'm not sure I understand why the free
245 * function should get three arguments...
246 * -- Richard Levitte
247 */
248 sk_NAME_FUNCS_value(name_funcs_stack,
249 ret->type)->free_func(ret->name,ret->type,ret->data);
250 }
251 OPENSSL_free(ret);
252 return(1);
253 }
254 else
255 return(0);
256 }
257
258struct doall
259 {
260 int type;
261 void (*fn)(const OBJ_NAME *,void *arg);
262 void *arg;
263 };
264
265static void do_all_fn(const OBJ_NAME *name,struct doall *d)
266 {
267 if(name->type == d->type)
268 d->fn(name,d->arg);
269 }
270
271static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME *, struct doall *)
272
273void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
274 {
275 struct doall d;
276
277 d.type=type;
278 d.fn=fn;
279 d.arg=arg;
280
281 lh_doall_arg(names_lh,LHASH_DOALL_ARG_FN(do_all_fn),&d);
282 }
283
284struct doall_sorted
285 {
286 int type;
287 int n;
288 const OBJ_NAME **names;
289 };
290
291static void do_all_sorted_fn(const OBJ_NAME *name,void *d_)
292 {
293 struct doall_sorted *d=d_;
294
295 if(name->type != d->type)
296 return;
297
298 d->names[d->n++]=name;
299 }
300
301static int do_all_sorted_cmp(const void *n1_,const void *n2_)
302 {
303 const OBJ_NAME * const *n1=n1_;
304 const OBJ_NAME * const *n2=n2_;
305
306 return strcmp((*n1)->name,(*n2)->name);
307 }
308
309void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
310 void *arg)
311 {
312 struct doall_sorted d;
313 int n;
314
315 d.type=type;
316 d.names=OPENSSL_malloc(lh_num_items(names_lh)*sizeof *d.names);
317 d.n=0;
318 OBJ_NAME_do_all(type,do_all_sorted_fn,&d);
319
320 qsort((void *)d.names,d.n,sizeof *d.names,do_all_sorted_cmp);
321
322 for(n=0 ; n < d.n ; ++n)
323 fn(d.names[n],arg);
324
325 OPENSSL_free((void *)d.names);
326 }
327
328static int free_type;
329
330static void names_lh_free(OBJ_NAME *onp)
331{
332 if(onp == NULL)
333 return;
334
335 if ((free_type < 0) || (free_type == onp->type))
336 {
337 OBJ_NAME_remove(onp->name,onp->type);
338 }
339 }
340
341static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME *)
342
343static void name_funcs_free(NAME_FUNCS *ptr)
344 {
345 OPENSSL_free(ptr);
346 }
347
348void OBJ_NAME_cleanup(int type)
349 {
350 unsigned long down_load;
351
352 if (names_lh == NULL) return;
353
354 free_type=type;
355 down_load=names_lh->down_load;
356 names_lh->down_load=0;
357
358 lh_doall(names_lh,LHASH_DOALL_FN(names_lh_free));
359 if (type < 0)
360 {
361 lh_free(names_lh);
362 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free);
363 names_lh=NULL;
364 name_funcs_stack = NULL;
365 }
366 else
367 names_lh->down_load=down_load;
368 }
369
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
new file mode 100644
index 0000000000..f549d078ef
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -0,0 +1,668 @@
1/* crypto/objects/obj_dat.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/lhash.h>
63#include <openssl/asn1.h>
64#include <openssl/objects.h>
65
66/* obj_dat.h is generated from objects.h by obj_dat.pl */
67#ifndef OPENSSL_NO_OBJECT
68#include "obj_dat.h"
69#else
70/* You will have to load all the objects needed manually in the application */
71#define NUM_NID 0
72#define NUM_SN 0
73#define NUM_LN 0
74#define NUM_OBJ 0
75static unsigned char lvalues[1];
76static ASN1_OBJECT nid_objs[1];
77static ASN1_OBJECT *sn_objs[1];
78static ASN1_OBJECT *ln_objs[1];
79static ASN1_OBJECT *obj_objs[1];
80#endif
81
82static int sn_cmp(const void *a, const void *b);
83static int ln_cmp(const void *a, const void *b);
84static int obj_cmp(const void *a, const void *b);
85#define ADDED_DATA 0
86#define ADDED_SNAME 1
87#define ADDED_LNAME 2
88#define ADDED_NID 3
89
90typedef struct added_obj_st
91 {
92 int type;
93 ASN1_OBJECT *obj;
94 } ADDED_OBJ;
95
96static int new_nid=NUM_NID;
97static LHASH *added=NULL;
98
99static int sn_cmp(const void *a, const void *b)
100 {
101 const ASN1_OBJECT * const *ap = a, * const *bp = b;
102 return(strcmp((*ap)->sn,(*bp)->sn));
103 }
104
105static int ln_cmp(const void *a, const void *b)
106 {
107 const ASN1_OBJECT * const *ap = a, * const *bp = b;
108 return(strcmp((*ap)->ln,(*bp)->ln));
109 }
110
111/* static unsigned long add_hash(ADDED_OBJ *ca) */
112static unsigned long add_hash(const void *ca_void)
113 {
114 const ASN1_OBJECT *a;
115 int i;
116 unsigned long ret=0;
117 unsigned char *p;
118 ADDED_OBJ *ca = (ADDED_OBJ *)ca_void;
119
120 a=ca->obj;
121 switch (ca->type)
122 {
123 case ADDED_DATA:
124 ret=a->length<<20L;
125 p=(unsigned char *)a->data;
126 for (i=0; i<a->length; i++)
127 ret^=p[i]<<((i*3)%24);
128 break;
129 case ADDED_SNAME:
130 ret=lh_strhash(a->sn);
131 break;
132 case ADDED_LNAME:
133 ret=lh_strhash(a->ln);
134 break;
135 case ADDED_NID:
136 ret=a->nid;
137 break;
138 default:
139 /* abort(); */
140 return 0;
141 }
142 ret&=0x3fffffffL;
143 ret|=ca->type<<30L;
144 return(ret);
145 }
146
147/* static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) */
148static int add_cmp(const void *ca_void, const void *cb_void)
149 {
150 ASN1_OBJECT *a,*b;
151 int i;
152 ADDED_OBJ *ca = (ADDED_OBJ *)ca_void;
153 ADDED_OBJ *cb = (ADDED_OBJ *)cb_void;
154
155 i=ca->type-cb->type;
156 if (i) return(i);
157 a=ca->obj;
158 b=cb->obj;
159 switch (ca->type)
160 {
161 case ADDED_DATA:
162 i=(a->length - b->length);
163 if (i) return(i);
164 return(memcmp(a->data,b->data,a->length));
165 case ADDED_SNAME:
166 if (a->sn == NULL) return(-1);
167 else if (b->sn == NULL) return(1);
168 else return(strcmp(a->sn,b->sn));
169 case ADDED_LNAME:
170 if (a->ln == NULL) return(-1);
171 else if (b->ln == NULL) return(1);
172 else return(strcmp(a->ln,b->ln));
173 case ADDED_NID:
174 return(a->nid-b->nid);
175 default:
176 /* abort(); */
177 return 0;
178 }
179 }
180
181static int init_added(void)
182 {
183 if (added != NULL) return(1);
184 added=lh_new(add_hash,add_cmp);
185 return(added != NULL);
186 }
187
188static void cleanup1(ADDED_OBJ *a)
189 {
190 a->obj->nid=0;
191 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
192 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
193 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
194 }
195
196static void cleanup2(ADDED_OBJ *a)
197 { a->obj->nid++; }
198
199static void cleanup3(ADDED_OBJ *a)
200 {
201 if (--a->obj->nid == 0)
202 ASN1_OBJECT_free(a->obj);
203 OPENSSL_free(a);
204 }
205
206static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *)
207static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *)
208static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *)
209
210void OBJ_cleanup(void)
211 {
212 if (added == NULL) return;
213 added->down_load=0;
214 lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */
215 lh_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */
216 lh_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */
217 lh_free(added);
218 added=NULL;
219 }
220
221int OBJ_new_nid(int num)
222 {
223 int i;
224
225 i=new_nid;
226 new_nid+=num;
227 return(i);
228 }
229
230int OBJ_add_object(const ASN1_OBJECT *obj)
231 {
232 ASN1_OBJECT *o;
233 ADDED_OBJ *ao[4]={NULL,NULL,NULL,NULL},*aop;
234 int i;
235
236 if (added == NULL)
237 if (!init_added()) return(0);
238 if ((o=OBJ_dup(obj)) == NULL) goto err;
239 if (!(ao[ADDED_NID]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
240 if ((o->length != 0) && (obj->data != NULL))
241 if (!(ao[ADDED_DATA]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
242 if (o->sn != NULL)
243 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
244 if (o->ln != NULL)
245 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
246
247 for (i=ADDED_DATA; i<=ADDED_NID; i++)
248 {
249 if (ao[i] != NULL)
250 {
251 ao[i]->type=i;
252 ao[i]->obj=o;
253 aop=(ADDED_OBJ *)lh_insert(added,ao[i]);
254 /* memory leak, buit should not normally matter */
255 if (aop != NULL)
256 OPENSSL_free(aop);
257 }
258 }
259 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
260 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
261
262 return(o->nid);
263err2:
264 OBJerr(OBJ_F_OBJ_ADD_OBJECT,ERR_R_MALLOC_FAILURE);
265err:
266 for (i=ADDED_DATA; i<=ADDED_NID; i++)
267 if (ao[i] != NULL) OPENSSL_free(ao[i]);
268 if (o != NULL) OPENSSL_free(o);
269 return(NID_undef);
270 }
271
272ASN1_OBJECT *OBJ_nid2obj(int n)
273 {
274 ADDED_OBJ ad,*adp;
275 ASN1_OBJECT ob;
276
277 if ((n >= 0) && (n < NUM_NID))
278 {
279 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
280 {
281 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
282 return(NULL);
283 }
284 return((ASN1_OBJECT *)&(nid_objs[n]));
285 }
286 else if (added == NULL)
287 return(NULL);
288 else
289 {
290 ad.type=ADDED_NID;
291 ad.obj= &ob;
292 ob.nid=n;
293 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
294 if (adp != NULL)
295 return(adp->obj);
296 else
297 {
298 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
299 return(NULL);
300 }
301 }
302 }
303
304const char *OBJ_nid2sn(int n)
305 {
306 ADDED_OBJ ad,*adp;
307 ASN1_OBJECT ob;
308
309 if ((n >= 0) && (n < NUM_NID))
310 {
311 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
312 {
313 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
314 return(NULL);
315 }
316 return(nid_objs[n].sn);
317 }
318 else if (added == NULL)
319 return(NULL);
320 else
321 {
322 ad.type=ADDED_NID;
323 ad.obj= &ob;
324 ob.nid=n;
325 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
326 if (adp != NULL)
327 return(adp->obj->sn);
328 else
329 {
330 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
331 return(NULL);
332 }
333 }
334 }
335
336const char *OBJ_nid2ln(int n)
337 {
338 ADDED_OBJ ad,*adp;
339 ASN1_OBJECT ob;
340
341 if ((n >= 0) && (n < NUM_NID))
342 {
343 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
344 {
345 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
346 return(NULL);
347 }
348 return(nid_objs[n].ln);
349 }
350 else if (added == NULL)
351 return(NULL);
352 else
353 {
354 ad.type=ADDED_NID;
355 ad.obj= &ob;
356 ob.nid=n;
357 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
358 if (adp != NULL)
359 return(adp->obj->ln);
360 else
361 {
362 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
363 return(NULL);
364 }
365 }
366 }
367
368int OBJ_obj2nid(const ASN1_OBJECT *a)
369 {
370 ASN1_OBJECT **op;
371 ADDED_OBJ ad,*adp;
372
373 if (a == NULL)
374 return(NID_undef);
375 if (a->nid != 0)
376 return(a->nid);
377
378 if (added != NULL)
379 {
380 ad.type=ADDED_DATA;
381 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
382 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
383 if (adp != NULL) return (adp->obj->nid);
384 }
385 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
386 sizeof(ASN1_OBJECT *),obj_cmp);
387 if (op == NULL)
388 return(NID_undef);
389 return((*op)->nid);
390 }
391
392/* Convert an object name into an ASN1_OBJECT
393 * if "noname" is not set then search for short and long names first.
394 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
395 * it can be used with any objects, not just registered ones.
396 */
397
398ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
399 {
400 int nid = NID_undef;
401 ASN1_OBJECT *op=NULL;
402 unsigned char *buf,*p;
403 int i, j;
404
405 if(!no_name) {
406 if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
407 ((nid = OBJ_ln2nid(s)) != NID_undef) )
408 return OBJ_nid2obj(nid);
409 }
410
411 /* Work out size of content octets */
412 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
413 if (i <= 0) {
414 /* Clear the error */
415 ERR_get_error();
416 return NULL;
417 }
418 /* Work out total size */
419 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
420
421 if((buf=(unsigned char *)OPENSSL_malloc(j)) == NULL) return NULL;
422
423 p = buf;
424 /* Write out tag+length */
425 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
426 /* Write out contents */
427 a2d_ASN1_OBJECT(p,i,s,-1);
428
429 p=buf;
430 op=d2i_ASN1_OBJECT(NULL,&p,j);
431 OPENSSL_free(buf);
432 return op;
433 }
434
435int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
436{
437 int i,idx=0,n=0,len,nid;
438 unsigned long l;
439 unsigned char *p;
440 const char *s;
441 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
442
443 if (buf_len <= 0) return(0);
444
445 if ((a == NULL) || (a->data == NULL)) {
446 buf[0]='\0';
447 return(0);
448 }
449
450 if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {
451 len=a->length;
452 p=a->data;
453
454 idx=0;
455 l=0;
456 while (idx < a->length) {
457 l|=(p[idx]&0x7f);
458 if (!(p[idx] & 0x80)) break;
459 l<<=7L;
460 idx++;
461 }
462 idx++;
463 i=(int)(l/40);
464 if (i > 2) i=2;
465 l-=(long)(i*40);
466
467 BIO_snprintf(tbuf,sizeof tbuf,"%d.%lu",i,l);
468 i=strlen(tbuf);
469 BUF_strlcpy(buf,tbuf,buf_len);
470 buf_len-=i;
471 buf+=i;
472 n+=i;
473
474 l=0;
475 for (; idx<len; idx++) {
476 l|=p[idx]&0x7f;
477 if (!(p[idx] & 0x80)) {
478 BIO_snprintf(tbuf,sizeof tbuf,".%lu",l);
479 i=strlen(tbuf);
480 if (buf_len > 0)
481 BUF_strlcpy(buf,tbuf,buf_len);
482 buf_len-=i;
483 buf+=i;
484 n+=i;
485 l=0;
486 }
487 l<<=7L;
488 }
489 } else {
490 s=OBJ_nid2ln(nid);
491 if (s == NULL)
492 s=OBJ_nid2sn(nid);
493 BUF_strlcpy(buf,s,buf_len);
494 n=strlen(s);
495 }
496 return(n);
497}
498
499int OBJ_txt2nid(const char *s)
500{
501 ASN1_OBJECT *obj;
502 int nid;
503 obj = OBJ_txt2obj(s, 0);
504 nid = OBJ_obj2nid(obj);
505 ASN1_OBJECT_free(obj);
506 return nid;
507}
508
509int OBJ_ln2nid(const char *s)
510 {
511 ASN1_OBJECT o,*oo= &o,**op;
512 ADDED_OBJ ad,*adp;
513
514 o.ln=s;
515 if (added != NULL)
516 {
517 ad.type=ADDED_LNAME;
518 ad.obj= &o;
519 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
520 if (adp != NULL) return (adp->obj->nid);
521 }
522 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
523 sizeof(ASN1_OBJECT *),ln_cmp);
524 if (op == NULL) return(NID_undef);
525 return((*op)->nid);
526 }
527
528int OBJ_sn2nid(const char *s)
529 {
530 ASN1_OBJECT o,*oo= &o,**op;
531 ADDED_OBJ ad,*adp;
532
533 o.sn=s;
534 if (added != NULL)
535 {
536 ad.type=ADDED_SNAME;
537 ad.obj= &o;
538 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
539 if (adp != NULL) return (adp->obj->nid);
540 }
541 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
542 sizeof(ASN1_OBJECT *),sn_cmp);
543 if (op == NULL) return(NID_undef);
544 return((*op)->nid);
545 }
546
547static int obj_cmp(const void *ap, const void *bp)
548 {
549 int j;
550 ASN1_OBJECT *a= *(ASN1_OBJECT **)ap;
551 ASN1_OBJECT *b= *(ASN1_OBJECT **)bp;
552
553 j=(a->length - b->length);
554 if (j) return(j);
555 return(memcmp(a->data,b->data,a->length));
556 }
557
558const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
559 int (*cmp)(const void *, const void *))
560 {
561 int l,h,i,c;
562 const char *p;
563
564 if (num == 0) return(NULL);
565 l=0;
566 h=num;
567 while (l < h)
568 {
569 i=(l+h)/2;
570 p= &(base[i*size]);
571 c=(*cmp)(key,p);
572 if (c < 0)
573 h=i;
574 else if (c > 0)
575 l=i+1;
576 else
577 return(p);
578 }
579#ifdef CHARSET_EBCDIC
580/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
581 * I don't have perl (yet), we revert to a *LINEAR* search
582 * when the object wasn't found in the binary search.
583 */
584 for (i=0; i<num; ++i) {
585 p= &(base[i*size]);
586 if ((*cmp)(key,p) == 0)
587 return p;
588 }
589#endif
590 return(NULL);
591 }
592
593int OBJ_create_objects(BIO *in)
594 {
595 MS_STATIC char buf[512];
596 int i,num=0;
597 char *o,*s,*l=NULL;
598
599 for (;;)
600 {
601 s=o=NULL;
602 i=BIO_gets(in,buf,512);
603 if (i <= 0) return(num);
604 buf[i-1]='\0';
605 if (!isalnum((unsigned char)buf[0])) return(num);
606 o=s=buf;
607 while (isdigit((unsigned char)*s) || (*s == '.'))
608 s++;
609 if (*s != '\0')
610 {
611 *(s++)='\0';
612 while (isspace((unsigned char)*s))
613 s++;
614 if (*s == '\0')
615 s=NULL;
616 else
617 {
618 l=s;
619 while ((*l != '\0') && !isspace((unsigned char)*l))
620 l++;
621 if (*l != '\0')
622 {
623 *(l++)='\0';
624 while (isspace((unsigned char)*l))
625 l++;
626 if (*l == '\0') l=NULL;
627 }
628 else
629 l=NULL;
630 }
631 }
632 else
633 s=NULL;
634 if ((o == NULL) || (*o == '\0')) return(num);
635 if (!OBJ_create(o,s,l)) return(num);
636 num++;
637 }
638 /* return(num); */
639 }
640
641int OBJ_create(const char *oid, const char *sn, const char *ln)
642 {
643 int ok=0;
644 ASN1_OBJECT *op=NULL;
645 unsigned char *buf;
646 int i;
647
648 i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
649 if (i <= 0) return(0);
650
651 if ((buf=(unsigned char *)OPENSSL_malloc(i)) == NULL)
652 {
653 OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE);
654 return(0);
655 }
656 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
657 if (i == 0)
658 goto err;
659 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
660 if (op == NULL)
661 goto err;
662 ok=OBJ_add_object(op);
663err:
664 ASN1_OBJECT_free(op);
665 OPENSSL_free(buf);
666 return(ok);
667 }
668
diff --git a/src/lib/libcrypto/objects/obj_dat.h b/src/lib/libcrypto/objects/obj_dat.h
deleted file mode 100644
index cc22152682..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.h
+++ /dev/null
@@ -1,3762 +0,0 @@
1/* crypto/objects/obj_dat.h */
2
3/* THIS FILE IS GENERATED FROM objects.h by obj_dat.pl via the
4 * following command:
5 * perl obj_dat.pl obj_mac.h obj_dat.h
6 */
7
8/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
9 * All rights reserved.
10 *
11 * This package is an SSL implementation written
12 * by Eric Young (eay@cryptsoft.com).
13 * The implementation was written so as to conform with Netscapes SSL.
14 *
15 * This library is free for commercial and non-commercial use as long as
16 * the following conditions are aheared to. The following conditions
17 * apply to all code found in this distribution, be it the RC4, RSA,
18 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
19 * included with this distribution is covered by the same copyright terms
20 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
21 *
22 * Copyright remains Eric Young's, and as such any Copyright notices in
23 * the code are not to be removed.
24 * If this package is used in a product, Eric Young should be given attribution
25 * as the author of the parts of the library used.
26 * This can be in the form of a textual message at program startup or
27 * in documentation (online or textual) provided with the package.
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 * 1. Redistributions of source code must retain the copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * "This product includes cryptographic software written by
40 * Eric Young (eay@cryptsoft.com)"
41 * The word 'cryptographic' can be left out if the rouines from the library
42 * being used are not cryptographic related :-).
43 * 4. If you include any Windows specific code (or a derivative thereof) from
44 * the apps directory (application code) you must include an acknowledgement:
45 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
46 *
47 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 * The licence and distribution terms for any publically available version or
60 * derivative of this code cannot be changed. i.e. this code cannot simply be
61 * copied and put under another distribution licence
62 * [including the GNU Public Licence.]
63 */
64
65#define NUM_NID 676
66#define NUM_SN 669
67#define NUM_LN 669
68#define NUM_OBJ 633
69
70static unsigned char lvalues[4575]={
710x00, /* [ 0] OBJ_undef */
720x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 1] OBJ_rsadsi */
730x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 7] OBJ_pkcs */
740x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 14] OBJ_md2 */
750x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 22] OBJ_md5 */
760x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 30] OBJ_rc4 */
770x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 38] OBJ_rsaEncryption */
780x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 47] OBJ_md2WithRSAEncryption */
790x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 56] OBJ_md5WithRSAEncryption */
800x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 65] OBJ_pbeWithMD2AndDES_CBC */
810x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 74] OBJ_pbeWithMD5AndDES_CBC */
820x55, /* [ 83] OBJ_X500 */
830x55,0x04, /* [ 84] OBJ_X509 */
840x55,0x04,0x03, /* [ 86] OBJ_commonName */
850x55,0x04,0x06, /* [ 89] OBJ_countryName */
860x55,0x04,0x07, /* [ 92] OBJ_localityName */
870x55,0x04,0x08, /* [ 95] OBJ_stateOrProvinceName */
880x55,0x04,0x0A, /* [ 98] OBJ_organizationName */
890x55,0x04,0x0B, /* [101] OBJ_organizationalUnitName */
900x55,0x08,0x01,0x01, /* [104] OBJ_rsa */
910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [108] OBJ_pkcs7 */
920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [116] OBJ_pkcs7_data */
930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [125] OBJ_pkcs7_signed */
940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [134] OBJ_pkcs7_enveloped */
950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [143] OBJ_pkcs7_signedAndEnveloped */
960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [152] OBJ_pkcs7_digest */
970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [161] OBJ_pkcs7_encrypted */
980x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [170] OBJ_pkcs3 */
990x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [178] OBJ_dhKeyAgreement */
1000x2B,0x0E,0x03,0x02,0x06, /* [187] OBJ_des_ecb */
1010x2B,0x0E,0x03,0x02,0x09, /* [192] OBJ_des_cfb64 */
1020x2B,0x0E,0x03,0x02,0x07, /* [197] OBJ_des_cbc */
1030x2B,0x0E,0x03,0x02,0x11, /* [202] OBJ_des_ede_ecb */
1040x2B,0x06,0x01,0x04,0x01,0x81,0x3C,0x07,0x01,0x01,0x02,/* [207] OBJ_idea_cbc */
1050x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [218] OBJ_rc2_cbc */
1060x2B,0x0E,0x03,0x02,0x12, /* [226] OBJ_sha */
1070x2B,0x0E,0x03,0x02,0x0F, /* [231] OBJ_shaWithRSAEncryption */
1080x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [236] OBJ_des_ede3_cbc */
1090x2B,0x0E,0x03,0x02,0x08, /* [244] OBJ_des_ofb64 */
1100x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [249] OBJ_pkcs9 */
1110x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [257] OBJ_pkcs9_emailAddress */
1120x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [266] OBJ_pkcs9_unstructuredName */
1130x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [275] OBJ_pkcs9_contentType */
1140x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [284] OBJ_pkcs9_messageDigest */
1150x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [293] OBJ_pkcs9_signingTime */
1160x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [302] OBJ_pkcs9_countersignature */
1170x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [311] OBJ_pkcs9_challengePassword */
1180x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [320] OBJ_pkcs9_unstructuredAddress */
1190x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [329] OBJ_pkcs9_extCertAttributes */
1200x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [338] OBJ_netscape */
1210x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [345] OBJ_netscape_cert_extension */
1220x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [353] OBJ_netscape_data_type */
1230x2B,0x0E,0x03,0x02,0x1A, /* [361] OBJ_sha1 */
1240x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [366] OBJ_sha1WithRSAEncryption */
1250x2B,0x0E,0x03,0x02,0x0D, /* [375] OBJ_dsaWithSHA */
1260x2B,0x0E,0x03,0x02,0x0C, /* [380] OBJ_dsa_2 */
1270x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [385] OBJ_pbeWithSHA1AndRC2_CBC */
1280x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [394] OBJ_id_pbkdf2 */
1290x2B,0x0E,0x03,0x02,0x1B, /* [403] OBJ_dsaWithSHA1_2 */
1300x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [408] OBJ_netscape_cert_type */
1310x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [417] OBJ_netscape_base_url */
1320x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [426] OBJ_netscape_revocation_url */
1330x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [435] OBJ_netscape_ca_revocation_url */
1340x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [444] OBJ_netscape_renewal_url */
1350x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [453] OBJ_netscape_ca_policy_url */
1360x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [462] OBJ_netscape_ssl_server_name */
1370x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [471] OBJ_netscape_comment */
1380x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [480] OBJ_netscape_cert_sequence */
1390x55,0x1D, /* [489] OBJ_id_ce */
1400x55,0x1D,0x0E, /* [491] OBJ_subject_key_identifier */
1410x55,0x1D,0x0F, /* [494] OBJ_key_usage */
1420x55,0x1D,0x10, /* [497] OBJ_private_key_usage_period */
1430x55,0x1D,0x11, /* [500] OBJ_subject_alt_name */
1440x55,0x1D,0x12, /* [503] OBJ_issuer_alt_name */
1450x55,0x1D,0x13, /* [506] OBJ_basic_constraints */
1460x55,0x1D,0x14, /* [509] OBJ_crl_number */
1470x55,0x1D,0x20, /* [512] OBJ_certificate_policies */
1480x55,0x1D,0x23, /* [515] OBJ_authority_key_identifier */
1490x2B,0x06,0x01,0x04,0x01,0x97,0x55,0x01,0x02,/* [518] OBJ_bf_cbc */
1500x55,0x08,0x03,0x65, /* [527] OBJ_mdc2 */
1510x55,0x08,0x03,0x64, /* [531] OBJ_mdc2WithRSA */
1520x55,0x04,0x2A, /* [535] OBJ_givenName */
1530x55,0x04,0x04, /* [538] OBJ_surname */
1540x55,0x04,0x2B, /* [541] OBJ_initials */
1550x55,0x1D,0x1F, /* [544] OBJ_crl_distribution_points */
1560x2B,0x0E,0x03,0x02,0x03, /* [547] OBJ_md5WithRSA */
1570x55,0x04,0x05, /* [552] OBJ_serialNumber */
1580x55,0x04,0x0C, /* [555] OBJ_title */
1590x55,0x04,0x0D, /* [558] OBJ_description */
1600x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [561] OBJ_cast5_cbc */
1610x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [570] OBJ_pbeWithMD5AndCast5_CBC */
1620x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [579] OBJ_dsaWithSHA1 */
1630x2B,0x0E,0x03,0x02,0x1D, /* [586] OBJ_sha1WithRSA */
1640x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [591] OBJ_dsa */
1650x2B,0x24,0x03,0x02,0x01, /* [598] OBJ_ripemd160 */
1660x2B,0x24,0x03,0x03,0x01,0x02, /* [603] OBJ_ripemd160WithRSA */
1670x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [609] OBJ_rc5_cbc */
1680x29,0x01,0x01,0x85,0x1A,0x01, /* [617] OBJ_rle_compression */
1690x29,0x01,0x01,0x85,0x1A,0x02, /* [623] OBJ_zlib_compression */
1700x55,0x1D,0x25, /* [629] OBJ_ext_key_usage */
1710x2B,0x06,0x01,0x05,0x05,0x07, /* [632] OBJ_id_pkix */
1720x2B,0x06,0x01,0x05,0x05,0x07,0x03, /* [638] OBJ_id_kp */
1730x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x01, /* [645] OBJ_server_auth */
1740x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x02, /* [653] OBJ_client_auth */
1750x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x03, /* [661] OBJ_code_sign */
1760x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x04, /* [669] OBJ_email_protect */
1770x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x08, /* [677] OBJ_time_stamp */
1780x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x15,/* [685] OBJ_ms_code_ind */
1790x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x16,/* [695] OBJ_ms_code_com */
1800x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x0A,0x03,0x01,/* [705] OBJ_ms_ctl_sign */
1810x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x0A,0x03,0x03,/* [715] OBJ_ms_sgc */
1820x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x0A,0x03,0x04,/* [725] OBJ_ms_efs */
1830x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x04,0x01,/* [735] OBJ_ns_sgc */
1840x55,0x1D,0x1B, /* [744] OBJ_delta_crl */
1850x55,0x1D,0x15, /* [747] OBJ_crl_reason */
1860x55,0x1D,0x18, /* [750] OBJ_invalidity_date */
1870x2B,0x65,0x01,0x04,0x01, /* [753] OBJ_sxnet */
1880x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x01,0x01,/* [758] OBJ_pbe_WithSHA1And128BitRC4 */
1890x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x01,0x02,/* [768] OBJ_pbe_WithSHA1And40BitRC4 */
1900x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x01,0x03,/* [778] OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC */
1910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x01,0x04,/* [788] OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC */
1920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x01,0x05,/* [798] OBJ_pbe_WithSHA1And128BitRC2_CBC */
1930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x01,0x06,/* [808] OBJ_pbe_WithSHA1And40BitRC2_CBC */
1940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x0A,0x01,0x01,/* [818] OBJ_keyBag */
1950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x0A,0x01,0x02,/* [829] OBJ_pkcs8ShroudedKeyBag */
1960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x0A,0x01,0x03,/* [840] OBJ_certBag */
1970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x0A,0x01,0x04,/* [851] OBJ_crlBag */
1980x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x0A,0x01,0x05,/* [862] OBJ_secretBag */
1990x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x0C,0x0A,0x01,0x06,/* [873] OBJ_safeContentsBag */
2000x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x14,/* [884] OBJ_friendlyName */
2010x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x15,/* [893] OBJ_localKeyID */
2020x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x16,0x01,/* [902] OBJ_x509Certificate */
2030x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x16,0x02,/* [912] OBJ_sdsiCertificate */
2040x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x17,0x01,/* [922] OBJ_x509Crl */
2050x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0D,/* [932] OBJ_pbes2 */
2060x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0E,/* [941] OBJ_pbmac1 */
2070x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x07, /* [950] OBJ_hmacWithSHA1 */
2080x2B,0x06,0x01,0x05,0x05,0x07,0x02,0x01, /* [958] OBJ_id_qt_cps */
2090x2B,0x06,0x01,0x05,0x05,0x07,0x02,0x02, /* [966] OBJ_id_qt_unotice */
2100x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x0F,/* [974] OBJ_SMIMECapabilities */
2110x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x04,/* [983] OBJ_pbeWithMD2AndRC2_CBC */
2120x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x06,/* [992] OBJ_pbeWithMD5AndRC2_CBC */
2130x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0A,/* [1001] OBJ_pbeWithSHA1AndDES_CBC */
2140x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0E,/* [1010] OBJ_ms_ext_req */
2150x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x0E,/* [1020] OBJ_ext_req */
2160x55,0x04,0x29, /* [1029] OBJ_name */
2170x55,0x04,0x2E, /* [1032] OBJ_dnQualifier */
2180x2B,0x06,0x01,0x05,0x05,0x07,0x01, /* [1035] OBJ_id_pe */
2190x2B,0x06,0x01,0x05,0x05,0x07,0x30, /* [1042] OBJ_id_ad */
2200x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x01, /* [1049] OBJ_info_access */
2210x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01, /* [1057] OBJ_ad_OCSP */
2220x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x02, /* [1065] OBJ_ad_ca_issuers */
2230x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x09, /* [1073] OBJ_OCSP_sign */
2240x28, /* [1081] OBJ_iso */
2250x2A, /* [1082] OBJ_member_body */
2260x2A,0x86,0x48, /* [1083] OBJ_ISO_US */
2270x2A,0x86,0x48,0xCE,0x38, /* [1086] OBJ_X9_57 */
2280x2A,0x86,0x48,0xCE,0x38,0x04, /* [1091] OBJ_X9cm */
2290x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01, /* [1097] OBJ_pkcs1 */
2300x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05, /* [1105] OBJ_pkcs5 */
2310x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,/* [1113] OBJ_SMIME */
2320x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,/* [1122] OBJ_id_smime_mod */
2330x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,/* [1132] OBJ_id_smime_ct */
2340x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,/* [1142] OBJ_id_smime_aa */
2350x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,/* [1152] OBJ_id_smime_alg */
2360x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x04,/* [1162] OBJ_id_smime_cd */
2370x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x05,/* [1172] OBJ_id_smime_spq */
2380x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,/* [1182] OBJ_id_smime_cti */
2390x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x01,/* [1192] OBJ_id_smime_mod_cms */
2400x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x02,/* [1203] OBJ_id_smime_mod_ess */
2410x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x03,/* [1214] OBJ_id_smime_mod_oid */
2420x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x04,/* [1225] OBJ_id_smime_mod_msg_v3 */
2430x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x05,/* [1236] OBJ_id_smime_mod_ets_eSignature_88 */
2440x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x06,/* [1247] OBJ_id_smime_mod_ets_eSignature_97 */
2450x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x07,/* [1258] OBJ_id_smime_mod_ets_eSigPolicy_88 */
2460x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x00,0x08,/* [1269] OBJ_id_smime_mod_ets_eSigPolicy_97 */
2470x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x01,/* [1280] OBJ_id_smime_ct_receipt */
2480x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x02,/* [1291] OBJ_id_smime_ct_authData */
2490x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x03,/* [1302] OBJ_id_smime_ct_publishCert */
2500x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x04,/* [1313] OBJ_id_smime_ct_TSTInfo */
2510x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x05,/* [1324] OBJ_id_smime_ct_TDTInfo */
2520x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x06,/* [1335] OBJ_id_smime_ct_contentInfo */
2530x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x07,/* [1346] OBJ_id_smime_ct_DVCSRequestData */
2540x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x01,0x08,/* [1357] OBJ_id_smime_ct_DVCSResponseData */
2550x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x01,/* [1368] OBJ_id_smime_aa_receiptRequest */
2560x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x02,/* [1379] OBJ_id_smime_aa_securityLabel */
2570x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x03,/* [1390] OBJ_id_smime_aa_mlExpandHistory */
2580x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x04,/* [1401] OBJ_id_smime_aa_contentHint */
2590x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x05,/* [1412] OBJ_id_smime_aa_msgSigDigest */
2600x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x06,/* [1423] OBJ_id_smime_aa_encapContentType */
2610x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x07,/* [1434] OBJ_id_smime_aa_contentIdentifier */
2620x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x08,/* [1445] OBJ_id_smime_aa_macValue */
2630x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x09,/* [1456] OBJ_id_smime_aa_equivalentLabels */
2640x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x0A,/* [1467] OBJ_id_smime_aa_contentReference */
2650x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x0B,/* [1478] OBJ_id_smime_aa_encrypKeyPref */
2660x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x0C,/* [1489] OBJ_id_smime_aa_signingCertificate */
2670x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x0D,/* [1500] OBJ_id_smime_aa_smimeEncryptCerts */
2680x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x0E,/* [1511] OBJ_id_smime_aa_timeStampToken */
2690x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x0F,/* [1522] OBJ_id_smime_aa_ets_sigPolicyId */
2700x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x10,/* [1533] OBJ_id_smime_aa_ets_commitmentType */
2710x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x11,/* [1544] OBJ_id_smime_aa_ets_signerLocation */
2720x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x12,/* [1555] OBJ_id_smime_aa_ets_signerAttr */
2730x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x13,/* [1566] OBJ_id_smime_aa_ets_otherSigCert */
2740x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x14,/* [1577] OBJ_id_smime_aa_ets_contentTimestamp */
2750x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x15,/* [1588] OBJ_id_smime_aa_ets_CertificateRefs */
2760x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x16,/* [1599] OBJ_id_smime_aa_ets_RevocationRefs */
2770x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x17,/* [1610] OBJ_id_smime_aa_ets_certValues */
2780x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x18,/* [1621] OBJ_id_smime_aa_ets_revocationValues */
2790x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x19,/* [1632] OBJ_id_smime_aa_ets_escTimeStamp */
2800x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x1A,/* [1643] OBJ_id_smime_aa_ets_certCRLTimestamp */
2810x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x1B,/* [1654] OBJ_id_smime_aa_ets_archiveTimeStamp */
2820x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x1C,/* [1665] OBJ_id_smime_aa_signatureType */
2830x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x02,0x1D,/* [1676] OBJ_id_smime_aa_dvcs_dvc */
2840x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x01,/* [1687] OBJ_id_smime_alg_ESDHwith3DES */
2850x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x02,/* [1698] OBJ_id_smime_alg_ESDHwithRC2 */
2860x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x03,/* [1709] OBJ_id_smime_alg_3DESwrap */
2870x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x04,/* [1720] OBJ_id_smime_alg_RC2wrap */
2880x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x05,/* [1731] OBJ_id_smime_alg_ESDH */
2890x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x06,/* [1742] OBJ_id_smime_alg_CMS3DESwrap */
2900x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x03,0x07,/* [1753] OBJ_id_smime_alg_CMSRC2wrap */
2910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x04,0x01,/* [1764] OBJ_id_smime_cd_ldap */
2920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x05,0x01,/* [1775] OBJ_id_smime_spq_ets_sqt_uri */
2930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x05,0x02,/* [1786] OBJ_id_smime_spq_ets_sqt_unotice */
2940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,0x01,/* [1797] OBJ_id_smime_cti_ets_proofOfOrigin */
2950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,0x02,/* [1808] OBJ_id_smime_cti_ets_proofOfReceipt */
2960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,0x03,/* [1819] OBJ_id_smime_cti_ets_proofOfDelivery */
2970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,0x04,/* [1830] OBJ_id_smime_cti_ets_proofOfSender */
2980x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,0x05,/* [1841] OBJ_id_smime_cti_ets_proofOfApproval */
2990x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x10,0x06,0x06,/* [1852] OBJ_id_smime_cti_ets_proofOfCreation */
3000x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x04, /* [1863] OBJ_md4 */
3010x2B,0x06,0x01,0x05,0x05,0x07,0x00, /* [1871] OBJ_id_pkix_mod */
3020x2B,0x06,0x01,0x05,0x05,0x07,0x02, /* [1878] OBJ_id_qt */
3030x2B,0x06,0x01,0x05,0x05,0x07,0x04, /* [1885] OBJ_id_it */
3040x2B,0x06,0x01,0x05,0x05,0x07,0x05, /* [1892] OBJ_id_pkip */
3050x2B,0x06,0x01,0x05,0x05,0x07,0x06, /* [1899] OBJ_id_alg */
3060x2B,0x06,0x01,0x05,0x05,0x07,0x07, /* [1906] OBJ_id_cmc */
3070x2B,0x06,0x01,0x05,0x05,0x07,0x08, /* [1913] OBJ_id_on */
3080x2B,0x06,0x01,0x05,0x05,0x07,0x09, /* [1920] OBJ_id_pda */
3090x2B,0x06,0x01,0x05,0x05,0x07,0x0A, /* [1927] OBJ_id_aca */
3100x2B,0x06,0x01,0x05,0x05,0x07,0x0B, /* [1934] OBJ_id_qcs */
3110x2B,0x06,0x01,0x05,0x05,0x07,0x0C, /* [1941] OBJ_id_cct */
3120x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x01, /* [1948] OBJ_id_pkix1_explicit_88 */
3130x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x02, /* [1956] OBJ_id_pkix1_implicit_88 */
3140x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x03, /* [1964] OBJ_id_pkix1_explicit_93 */
3150x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x04, /* [1972] OBJ_id_pkix1_implicit_93 */
3160x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x05, /* [1980] OBJ_id_mod_crmf */
3170x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x06, /* [1988] OBJ_id_mod_cmc */
3180x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x07, /* [1996] OBJ_id_mod_kea_profile_88 */
3190x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x08, /* [2004] OBJ_id_mod_kea_profile_93 */
3200x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x09, /* [2012] OBJ_id_mod_cmp */
3210x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x0A, /* [2020] OBJ_id_mod_qualified_cert_88 */
3220x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x0B, /* [2028] OBJ_id_mod_qualified_cert_93 */
3230x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x0C, /* [2036] OBJ_id_mod_attribute_cert */
3240x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x0D, /* [2044] OBJ_id_mod_timestamp_protocol */
3250x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x0E, /* [2052] OBJ_id_mod_ocsp */
3260x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x0F, /* [2060] OBJ_id_mod_dvcs */
3270x2B,0x06,0x01,0x05,0x05,0x07,0x00,0x10, /* [2068] OBJ_id_mod_cmp2000 */
3280x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x02, /* [2076] OBJ_biometricInfo */
3290x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x03, /* [2084] OBJ_qcStatements */
3300x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x04, /* [2092] OBJ_ac_auditEntity */
3310x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x05, /* [2100] OBJ_ac_targeting */
3320x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x06, /* [2108] OBJ_aaControls */
3330x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x07, /* [2116] OBJ_sbgp_ipAddrBlock */
3340x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x08, /* [2124] OBJ_sbgp_autonomousSysNum */
3350x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x09, /* [2132] OBJ_sbgp_routerIdentifier */
3360x2B,0x06,0x01,0x05,0x05,0x07,0x02,0x03, /* [2140] OBJ_textNotice */
3370x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x05, /* [2148] OBJ_ipsecEndSystem */
3380x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x06, /* [2156] OBJ_ipsecTunnel */
3390x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x07, /* [2164] OBJ_ipsecUser */
3400x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x0A, /* [2172] OBJ_dvcs */
3410x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x01, /* [2180] OBJ_id_it_caProtEncCert */
3420x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x02, /* [2188] OBJ_id_it_signKeyPairTypes */
3430x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x03, /* [2196] OBJ_id_it_encKeyPairTypes */
3440x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x04, /* [2204] OBJ_id_it_preferredSymmAlg */
3450x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x05, /* [2212] OBJ_id_it_caKeyUpdateInfo */
3460x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x06, /* [2220] OBJ_id_it_currentCRL */
3470x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x07, /* [2228] OBJ_id_it_unsupportedOIDs */
3480x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x08, /* [2236] OBJ_id_it_subscriptionRequest */
3490x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x09, /* [2244] OBJ_id_it_subscriptionResponse */
3500x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x0A, /* [2252] OBJ_id_it_keyPairParamReq */
3510x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x0B, /* [2260] OBJ_id_it_keyPairParamRep */
3520x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x0C, /* [2268] OBJ_id_it_revPassphrase */
3530x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x0D, /* [2276] OBJ_id_it_implicitConfirm */
3540x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x0E, /* [2284] OBJ_id_it_confirmWaitTime */
3550x2B,0x06,0x01,0x05,0x05,0x07,0x04,0x0F, /* [2292] OBJ_id_it_origPKIMessage */
3560x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01, /* [2300] OBJ_id_regCtrl */
3570x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x02, /* [2308] OBJ_id_regInfo */
3580x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01,0x01,/* [2316] OBJ_id_regCtrl_regToken */
3590x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01,0x02,/* [2325] OBJ_id_regCtrl_authenticator */
3600x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01,0x03,/* [2334] OBJ_id_regCtrl_pkiPublicationInfo */
3610x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01,0x04,/* [2343] OBJ_id_regCtrl_pkiArchiveOptions */
3620x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01,0x05,/* [2352] OBJ_id_regCtrl_oldCertID */
3630x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x01,0x06,/* [2361] OBJ_id_regCtrl_protocolEncrKey */
3640x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x02,0x01,/* [2370] OBJ_id_regInfo_utf8Pairs */
3650x2B,0x06,0x01,0x05,0x05,0x07,0x05,0x02,0x02,/* [2379] OBJ_id_regInfo_certReq */
3660x2B,0x06,0x01,0x05,0x05,0x07,0x06,0x01, /* [2388] OBJ_id_alg_des40 */
3670x2B,0x06,0x01,0x05,0x05,0x07,0x06,0x02, /* [2396] OBJ_id_alg_noSignature */
3680x2B,0x06,0x01,0x05,0x05,0x07,0x06,0x03, /* [2404] OBJ_id_alg_dh_sig_hmac_sha1 */
3690x2B,0x06,0x01,0x05,0x05,0x07,0x06,0x04, /* [2412] OBJ_id_alg_dh_pop */
3700x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x01, /* [2420] OBJ_id_cmc_statusInfo */
3710x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x02, /* [2428] OBJ_id_cmc_identification */
3720x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x03, /* [2436] OBJ_id_cmc_identityProof */
3730x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x04, /* [2444] OBJ_id_cmc_dataReturn */
3740x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x05, /* [2452] OBJ_id_cmc_transactionId */
3750x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x06, /* [2460] OBJ_id_cmc_senderNonce */
3760x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x07, /* [2468] OBJ_id_cmc_recipientNonce */
3770x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x08, /* [2476] OBJ_id_cmc_addExtensions */
3780x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x09, /* [2484] OBJ_id_cmc_encryptedPOP */
3790x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x0A, /* [2492] OBJ_id_cmc_decryptedPOP */
3800x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x0B, /* [2500] OBJ_id_cmc_lraPOPWitness */
3810x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x0F, /* [2508] OBJ_id_cmc_getCert */
3820x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x10, /* [2516] OBJ_id_cmc_getCRL */
3830x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x11, /* [2524] OBJ_id_cmc_revokeRequest */
3840x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x12, /* [2532] OBJ_id_cmc_regInfo */
3850x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x13, /* [2540] OBJ_id_cmc_responseInfo */
3860x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x15, /* [2548] OBJ_id_cmc_queryPending */
3870x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x16, /* [2556] OBJ_id_cmc_popLinkRandom */
3880x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x17, /* [2564] OBJ_id_cmc_popLinkWitness */
3890x2B,0x06,0x01,0x05,0x05,0x07,0x07,0x18, /* [2572] OBJ_id_cmc_confirmCertAcceptance */
3900x2B,0x06,0x01,0x05,0x05,0x07,0x08,0x01, /* [2580] OBJ_id_on_personalData */
3910x2B,0x06,0x01,0x05,0x05,0x07,0x09,0x01, /* [2588] OBJ_id_pda_dateOfBirth */
3920x2B,0x06,0x01,0x05,0x05,0x07,0x09,0x02, /* [2596] OBJ_id_pda_placeOfBirth */
3930x2B,0x06,0x01,0x05,0x05,0x07,0x09,0x03, /* [2604] OBJ_id_pda_gender */
3940x2B,0x06,0x01,0x05,0x05,0x07,0x09,0x04, /* [2612] OBJ_id_pda_countryOfCitizenship */
3950x2B,0x06,0x01,0x05,0x05,0x07,0x09,0x05, /* [2620] OBJ_id_pda_countryOfResidence */
3960x2B,0x06,0x01,0x05,0x05,0x07,0x0A,0x01, /* [2628] OBJ_id_aca_authenticationInfo */
3970x2B,0x06,0x01,0x05,0x05,0x07,0x0A,0x02, /* [2636] OBJ_id_aca_accessIdentity */
3980x2B,0x06,0x01,0x05,0x05,0x07,0x0A,0x03, /* [2644] OBJ_id_aca_chargingIdentity */
3990x2B,0x06,0x01,0x05,0x05,0x07,0x0A,0x04, /* [2652] OBJ_id_aca_group */
4000x2B,0x06,0x01,0x05,0x05,0x07,0x0A,0x05, /* [2660] OBJ_id_aca_role */
4010x2B,0x06,0x01,0x05,0x05,0x07,0x0B,0x01, /* [2668] OBJ_id_qcs_pkixQCSyntax_v1 */
4020x2B,0x06,0x01,0x05,0x05,0x07,0x0C,0x01, /* [2676] OBJ_id_cct_crs */
4030x2B,0x06,0x01,0x05,0x05,0x07,0x0C,0x02, /* [2684] OBJ_id_cct_PKIData */
4040x2B,0x06,0x01,0x05,0x05,0x07,0x0C,0x03, /* [2692] OBJ_id_cct_PKIResponse */
4050x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x03, /* [2700] OBJ_ad_timeStamping */
4060x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x04, /* [2708] OBJ_ad_dvcs */
4070x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x01,/* [2716] OBJ_id_pkix_OCSP_basic */
4080x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x02,/* [2725] OBJ_id_pkix_OCSP_Nonce */
4090x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x03,/* [2734] OBJ_id_pkix_OCSP_CrlID */
4100x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x04,/* [2743] OBJ_id_pkix_OCSP_acceptableResponses */
4110x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x05,/* [2752] OBJ_id_pkix_OCSP_noCheck */
4120x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x06,/* [2761] OBJ_id_pkix_OCSP_archiveCutoff */
4130x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x07,/* [2770] OBJ_id_pkix_OCSP_serviceLocator */
4140x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x08,/* [2779] OBJ_id_pkix_OCSP_extendedStatus */
4150x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x09,/* [2788] OBJ_id_pkix_OCSP_valid */
4160x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x0A,/* [2797] OBJ_id_pkix_OCSP_path */
4170x2B,0x06,0x01,0x05,0x05,0x07,0x30,0x01,0x0B,/* [2806] OBJ_id_pkix_OCSP_trustRoot */
4180x2B,0x0E,0x03,0x02, /* [2815] OBJ_algorithm */
4190x2B,0x0E,0x03,0x02,0x0B, /* [2819] OBJ_rsaSignature */
4200x55,0x08, /* [2824] OBJ_X500algorithms */
4210x2B, /* [2826] OBJ_org */
4220x2B,0x06, /* [2827] OBJ_dod */
4230x2B,0x06,0x01, /* [2829] OBJ_iana */
4240x2B,0x06,0x01,0x01, /* [2832] OBJ_Directory */
4250x2B,0x06,0x01,0x02, /* [2836] OBJ_Management */
4260x2B,0x06,0x01,0x03, /* [2840] OBJ_Experimental */
4270x2B,0x06,0x01,0x04, /* [2844] OBJ_Private */
4280x2B,0x06,0x01,0x05, /* [2848] OBJ_Security */
4290x2B,0x06,0x01,0x06, /* [2852] OBJ_SNMPv2 */
4300x2B,0x06,0x01,0x07, /* [2856] OBJ_Mail */
4310x2B,0x06,0x01,0x04,0x01, /* [2860] OBJ_Enterprises */
4320x2B,0x06,0x01,0x04,0x01,0x8B,0x3A,0x82,0x58,/* [2865] OBJ_dcObject */
4330x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x19,/* [2874] OBJ_domainComponent */
4340x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x0D,/* [2884] OBJ_Domain */
4350x50, /* [2894] OBJ_joint_iso_ccitt */
4360x55,0x01,0x05, /* [2895] OBJ_selected_attribute_types */
4370x55,0x01,0x05,0x37, /* [2898] OBJ_clearance */
4380x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x03,/* [2902] OBJ_md4WithRSAEncryption */
4390x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x0A, /* [2911] OBJ_ac_proxying */
4400x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x0B, /* [2919] OBJ_sinfo_access */
4410x2B,0x06,0x01,0x05,0x05,0x07,0x0A,0x06, /* [2927] OBJ_id_aca_encAttrs */
4420x55,0x04,0x48, /* [2935] OBJ_role */
4430x55,0x1D,0x24, /* [2938] OBJ_policy_constraints */
4440x55,0x1D,0x37, /* [2941] OBJ_target_information */
4450x55,0x1D,0x38, /* [2944] OBJ_no_rev_avail */
4460x00, /* [2947] OBJ_ccitt */
4470x2A,0x86,0x48,0xCE,0x3D, /* [2948] OBJ_ansi_X9_62 */
4480x2A,0x86,0x48,0xCE,0x3D,0x01,0x01, /* [2953] OBJ_X9_62_prime_field */
4490x2A,0x86,0x48,0xCE,0x3D,0x01,0x02, /* [2960] OBJ_X9_62_characteristic_two_field */
4500x2A,0x86,0x48,0xCE,0x3D,0x02,0x01, /* [2967] OBJ_X9_62_id_ecPublicKey */
4510x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x01, /* [2974] OBJ_X9_62_prime192v1 */
4520x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x02, /* [2982] OBJ_X9_62_prime192v2 */
4530x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x03, /* [2990] OBJ_X9_62_prime192v3 */
4540x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x04, /* [2998] OBJ_X9_62_prime239v1 */
4550x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x05, /* [3006] OBJ_X9_62_prime239v2 */
4560x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x06, /* [3014] OBJ_X9_62_prime239v3 */
4570x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07, /* [3022] OBJ_X9_62_prime256v1 */
4580x2A,0x86,0x48,0xCE,0x3D,0x04,0x01, /* [3030] OBJ_ecdsa_with_SHA1 */
4590x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x11,0x01,/* [3037] OBJ_ms_csp_name */
4600x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x01,/* [3046] OBJ_aes_128_ecb */
4610x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x02,/* [3055] OBJ_aes_128_cbc */
4620x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x03,/* [3064] OBJ_aes_128_ofb128 */
4630x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x04,/* [3073] OBJ_aes_128_cfb128 */
4640x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x15,/* [3082] OBJ_aes_192_ecb */
4650x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x16,/* [3091] OBJ_aes_192_cbc */
4660x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x17,/* [3100] OBJ_aes_192_ofb128 */
4670x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x18,/* [3109] OBJ_aes_192_cfb128 */
4680x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x29,/* [3118] OBJ_aes_256_ecb */
4690x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x2A,/* [3127] OBJ_aes_256_cbc */
4700x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x2B,/* [3136] OBJ_aes_256_ofb128 */
4710x60,0x86,0x48,0x01,0x65,0x03,0x04,0x01,0x2C,/* [3145] OBJ_aes_256_cfb128 */
4720x55,0x1D,0x17, /* [3154] OBJ_hold_instruction_code */
4730x2A,0x86,0x48,0xCE,0x38,0x02,0x01, /* [3157] OBJ_hold_instruction_none */
4740x2A,0x86,0x48,0xCE,0x38,0x02,0x02, /* [3164] OBJ_hold_instruction_call_issuer */
4750x2A,0x86,0x48,0xCE,0x38,0x02,0x03, /* [3171] OBJ_hold_instruction_reject */
4760x09, /* [3178] OBJ_data */
4770x09,0x92,0x26, /* [3179] OBJ_pss */
4780x09,0x92,0x26,0x89,0x93,0xF2,0x2C, /* [3182] OBJ_ucl */
4790x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64, /* [3189] OBJ_pilot */
4800x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,/* [3197] OBJ_pilotAttributeType */
4810x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x03,/* [3206] OBJ_pilotAttributeSyntax */
4820x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,/* [3215] OBJ_pilotObjectClass */
4830x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x0A,/* [3224] OBJ_pilotGroups */
4840x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x03,0x04,/* [3233] OBJ_iA5StringSyntax */
4850x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x03,0x05,/* [3243] OBJ_caseIgnoreIA5StringSyntax */
4860x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x03,/* [3253] OBJ_pilotObject */
4870x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x04,/* [3263] OBJ_pilotPerson */
4880x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x05,/* [3273] OBJ_account */
4890x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x06,/* [3283] OBJ_document */
4900x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x07,/* [3293] OBJ_room */
4910x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x09,/* [3303] OBJ_documentSeries */
4920x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x0E,/* [3313] OBJ_rFC822localPart */
4930x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x0F,/* [3323] OBJ_dNSDomain */
4940x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x11,/* [3333] OBJ_domainRelatedObject */
4950x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x12,/* [3343] OBJ_friendlyCountry */
4960x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x13,/* [3353] OBJ_simpleSecurityObject */
4970x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x14,/* [3363] OBJ_pilotOrganization */
4980x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x15,/* [3373] OBJ_pilotDSA */
4990x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x04,0x16,/* [3383] OBJ_qualityLabelledData */
5000x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x01,/* [3393] OBJ_userId */
5010x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x02,/* [3403] OBJ_textEncodedORAddress */
5020x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x03,/* [3413] OBJ_rfc822Mailbox */
5030x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x04,/* [3423] OBJ_info */
5040x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x05,/* [3433] OBJ_favouriteDrink */
5050x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x06,/* [3443] OBJ_roomNumber */
5060x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x07,/* [3453] OBJ_photo */
5070x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x08,/* [3463] OBJ_userClass */
5080x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x09,/* [3473] OBJ_host */
5090x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x0A,/* [3483] OBJ_manager */
5100x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x0B,/* [3493] OBJ_documentIdentifier */
5110x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x0C,/* [3503] OBJ_documentTitle */
5120x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x0D,/* [3513] OBJ_documentVersion */
5130x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x0E,/* [3523] OBJ_documentAuthor */
5140x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x0F,/* [3533] OBJ_documentLocation */
5150x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x14,/* [3543] OBJ_homeTelephoneNumber */
5160x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x15,/* [3553] OBJ_secretary */
5170x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x16,/* [3563] OBJ_otherMailbox */
5180x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x17,/* [3573] OBJ_lastModifiedTime */
5190x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x18,/* [3583] OBJ_lastModifiedBy */
5200x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x1A,/* [3593] OBJ_aRecord */
5210x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x1B,/* [3603] OBJ_pilotAttributeType27 */
5220x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x1C,/* [3613] OBJ_mXRecord */
5230x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x1D,/* [3623] OBJ_nSRecord */
5240x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x1E,/* [3633] OBJ_sOARecord */
5250x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x1F,/* [3643] OBJ_cNAMERecord */
5260x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x25,/* [3653] OBJ_associatedDomain */
5270x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x26,/* [3663] OBJ_associatedName */
5280x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x27,/* [3673] OBJ_homePostalAddress */
5290x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x28,/* [3683] OBJ_personalTitle */
5300x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x29,/* [3693] OBJ_mobileTelephoneNumber */
5310x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x2A,/* [3703] OBJ_pagerTelephoneNumber */
5320x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x2B,/* [3713] OBJ_friendlyCountryName */
5330x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x2D,/* [3723] OBJ_organizationalStatus */
5340x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x2E,/* [3733] OBJ_janetMailbox */
5350x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x2F,/* [3743] OBJ_mailPreferenceOption */
5360x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x30,/* [3753] OBJ_buildingName */
5370x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x31,/* [3763] OBJ_dSAQuality */
5380x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x32,/* [3773] OBJ_singleLevelQuality */
5390x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x33,/* [3783] OBJ_subtreeMinimumQuality */
5400x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x34,/* [3793] OBJ_subtreeMaximumQuality */
5410x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x35,/* [3803] OBJ_personalSignature */
5420x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x36,/* [3813] OBJ_dITRedirect */
5430x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x37,/* [3823] OBJ_audio */
5440x09,0x92,0x26,0x89,0x93,0xF2,0x2C,0x64,0x01,0x38,/* [3833] OBJ_documentPublisher */
5450x55,0x04,0x2D, /* [3843] OBJ_x500UniqueIdentifier */
5460x2B,0x06,0x01,0x07,0x01, /* [3846] OBJ_mime_mhs */
5470x2B,0x06,0x01,0x07,0x01,0x01, /* [3851] OBJ_mime_mhs_headings */
5480x2B,0x06,0x01,0x07,0x01,0x02, /* [3857] OBJ_mime_mhs_bodies */
5490x2B,0x06,0x01,0x07,0x01,0x01,0x01, /* [3863] OBJ_id_hex_partial_message */
5500x2B,0x06,0x01,0x07,0x01,0x01,0x02, /* [3870] OBJ_id_hex_multipart_message */
5510x55,0x04,0x2C, /* [3877] OBJ_generationQualifier */
5520x55,0x04,0x41, /* [3880] OBJ_pseudonym */
5530x67,0x2A, /* [3883] OBJ_id_set */
5540x67,0x2A,0x00, /* [3885] OBJ_set_ctype */
5550x67,0x2A,0x01, /* [3888] OBJ_set_msgExt */
5560x67,0x2A,0x03, /* [3891] OBJ_set_attr */
5570x67,0x2A,0x05, /* [3894] OBJ_set_policy */
5580x67,0x2A,0x07, /* [3897] OBJ_set_certExt */
5590x67,0x2A,0x08, /* [3900] OBJ_set_brand */
5600x67,0x2A,0x00,0x00, /* [3903] OBJ_setct_PANData */
5610x67,0x2A,0x00,0x01, /* [3907] OBJ_setct_PANToken */
5620x67,0x2A,0x00,0x02, /* [3911] OBJ_setct_PANOnly */
5630x67,0x2A,0x00,0x03, /* [3915] OBJ_setct_OIData */
5640x67,0x2A,0x00,0x04, /* [3919] OBJ_setct_PI */
5650x67,0x2A,0x00,0x05, /* [3923] OBJ_setct_PIData */
5660x67,0x2A,0x00,0x06, /* [3927] OBJ_setct_PIDataUnsigned */
5670x67,0x2A,0x00,0x07, /* [3931] OBJ_setct_HODInput */
5680x67,0x2A,0x00,0x08, /* [3935] OBJ_setct_AuthResBaggage */
5690x67,0x2A,0x00,0x09, /* [3939] OBJ_setct_AuthRevReqBaggage */
5700x67,0x2A,0x00,0x0A, /* [3943] OBJ_setct_AuthRevResBaggage */
5710x67,0x2A,0x00,0x0B, /* [3947] OBJ_setct_CapTokenSeq */
5720x67,0x2A,0x00,0x0C, /* [3951] OBJ_setct_PInitResData */
5730x67,0x2A,0x00,0x0D, /* [3955] OBJ_setct_PI_TBS */
5740x67,0x2A,0x00,0x0E, /* [3959] OBJ_setct_PResData */
5750x67,0x2A,0x00,0x10, /* [3963] OBJ_setct_AuthReqTBS */
5760x67,0x2A,0x00,0x11, /* [3967] OBJ_setct_AuthResTBS */
5770x67,0x2A,0x00,0x12, /* [3971] OBJ_setct_AuthResTBSX */
5780x67,0x2A,0x00,0x13, /* [3975] OBJ_setct_AuthTokenTBS */
5790x67,0x2A,0x00,0x14, /* [3979] OBJ_setct_CapTokenData */
5800x67,0x2A,0x00,0x15, /* [3983] OBJ_setct_CapTokenTBS */
5810x67,0x2A,0x00,0x16, /* [3987] OBJ_setct_AcqCardCodeMsg */
5820x67,0x2A,0x00,0x17, /* [3991] OBJ_setct_AuthRevReqTBS */
5830x67,0x2A,0x00,0x18, /* [3995] OBJ_setct_AuthRevResData */
5840x67,0x2A,0x00,0x19, /* [3999] OBJ_setct_AuthRevResTBS */
5850x67,0x2A,0x00,0x1A, /* [4003] OBJ_setct_CapReqTBS */
5860x67,0x2A,0x00,0x1B, /* [4007] OBJ_setct_CapReqTBSX */
5870x67,0x2A,0x00,0x1C, /* [4011] OBJ_setct_CapResData */
5880x67,0x2A,0x00,0x1D, /* [4015] OBJ_setct_CapRevReqTBS */
5890x67,0x2A,0x00,0x1E, /* [4019] OBJ_setct_CapRevReqTBSX */
5900x67,0x2A,0x00,0x1F, /* [4023] OBJ_setct_CapRevResData */
5910x67,0x2A,0x00,0x20, /* [4027] OBJ_setct_CredReqTBS */
5920x67,0x2A,0x00,0x21, /* [4031] OBJ_setct_CredReqTBSX */
5930x67,0x2A,0x00,0x22, /* [4035] OBJ_setct_CredResData */
5940x67,0x2A,0x00,0x23, /* [4039] OBJ_setct_CredRevReqTBS */
5950x67,0x2A,0x00,0x24, /* [4043] OBJ_setct_CredRevReqTBSX */
5960x67,0x2A,0x00,0x25, /* [4047] OBJ_setct_CredRevResData */
5970x67,0x2A,0x00,0x26, /* [4051] OBJ_setct_PCertReqData */
5980x67,0x2A,0x00,0x27, /* [4055] OBJ_setct_PCertResTBS */
5990x67,0x2A,0x00,0x28, /* [4059] OBJ_setct_BatchAdminReqData */
6000x67,0x2A,0x00,0x29, /* [4063] OBJ_setct_BatchAdminResData */
6010x67,0x2A,0x00,0x2A, /* [4067] OBJ_setct_CardCInitResTBS */
6020x67,0x2A,0x00,0x2B, /* [4071] OBJ_setct_MeAqCInitResTBS */
6030x67,0x2A,0x00,0x2C, /* [4075] OBJ_setct_RegFormResTBS */
6040x67,0x2A,0x00,0x2D, /* [4079] OBJ_setct_CertReqData */
6050x67,0x2A,0x00,0x2E, /* [4083] OBJ_setct_CertReqTBS */
6060x67,0x2A,0x00,0x2F, /* [4087] OBJ_setct_CertResData */
6070x67,0x2A,0x00,0x30, /* [4091] OBJ_setct_CertInqReqTBS */
6080x67,0x2A,0x00,0x31, /* [4095] OBJ_setct_ErrorTBS */
6090x67,0x2A,0x00,0x32, /* [4099] OBJ_setct_PIDualSignedTBE */
6100x67,0x2A,0x00,0x33, /* [4103] OBJ_setct_PIUnsignedTBE */
6110x67,0x2A,0x00,0x34, /* [4107] OBJ_setct_AuthReqTBE */
6120x67,0x2A,0x00,0x35, /* [4111] OBJ_setct_AuthResTBE */
6130x67,0x2A,0x00,0x36, /* [4115] OBJ_setct_AuthResTBEX */
6140x67,0x2A,0x00,0x37, /* [4119] OBJ_setct_AuthTokenTBE */
6150x67,0x2A,0x00,0x38, /* [4123] OBJ_setct_CapTokenTBE */
6160x67,0x2A,0x00,0x39, /* [4127] OBJ_setct_CapTokenTBEX */
6170x67,0x2A,0x00,0x3A, /* [4131] OBJ_setct_AcqCardCodeMsgTBE */
6180x67,0x2A,0x00,0x3B, /* [4135] OBJ_setct_AuthRevReqTBE */
6190x67,0x2A,0x00,0x3C, /* [4139] OBJ_setct_AuthRevResTBE */
6200x67,0x2A,0x00,0x3D, /* [4143] OBJ_setct_AuthRevResTBEB */
6210x67,0x2A,0x00,0x3E, /* [4147] OBJ_setct_CapReqTBE */
6220x67,0x2A,0x00,0x3F, /* [4151] OBJ_setct_CapReqTBEX */
6230x67,0x2A,0x00,0x40, /* [4155] OBJ_setct_CapResTBE */
6240x67,0x2A,0x00,0x41, /* [4159] OBJ_setct_CapRevReqTBE */
6250x67,0x2A,0x00,0x42, /* [4163] OBJ_setct_CapRevReqTBEX */
6260x67,0x2A,0x00,0x43, /* [4167] OBJ_setct_CapRevResTBE */
6270x67,0x2A,0x00,0x44, /* [4171] OBJ_setct_CredReqTBE */
6280x67,0x2A,0x00,0x45, /* [4175] OBJ_setct_CredReqTBEX */
6290x67,0x2A,0x00,0x46, /* [4179] OBJ_setct_CredResTBE */
6300x67,0x2A,0x00,0x47, /* [4183] OBJ_setct_CredRevReqTBE */
6310x67,0x2A,0x00,0x48, /* [4187] OBJ_setct_CredRevReqTBEX */
6320x67,0x2A,0x00,0x49, /* [4191] OBJ_setct_CredRevResTBE */
6330x67,0x2A,0x00,0x4A, /* [4195] OBJ_setct_BatchAdminReqTBE */
6340x67,0x2A,0x00,0x4B, /* [4199] OBJ_setct_BatchAdminResTBE */
6350x67,0x2A,0x00,0x4C, /* [4203] OBJ_setct_RegFormReqTBE */
6360x67,0x2A,0x00,0x4D, /* [4207] OBJ_setct_CertReqTBE */
6370x67,0x2A,0x00,0x4E, /* [4211] OBJ_setct_CertReqTBEX */
6380x67,0x2A,0x00,0x4F, /* [4215] OBJ_setct_CertResTBE */
6390x67,0x2A,0x00,0x50, /* [4219] OBJ_setct_CRLNotificationTBS */
6400x67,0x2A,0x00,0x51, /* [4223] OBJ_setct_CRLNotificationResTBS */
6410x67,0x2A,0x00,0x52, /* [4227] OBJ_setct_BCIDistributionTBS */
6420x67,0x2A,0x01,0x01, /* [4231] OBJ_setext_genCrypt */
6430x67,0x2A,0x01,0x03, /* [4235] OBJ_setext_miAuth */
6440x67,0x2A,0x01,0x04, /* [4239] OBJ_setext_pinSecure */
6450x67,0x2A,0x01,0x05, /* [4243] OBJ_setext_pinAny */
6460x67,0x2A,0x01,0x07, /* [4247] OBJ_setext_track2 */
6470x67,0x2A,0x01,0x08, /* [4251] OBJ_setext_cv */
6480x67,0x2A,0x05,0x00, /* [4255] OBJ_set_policy_root */
6490x67,0x2A,0x07,0x00, /* [4259] OBJ_setCext_hashedRoot */
6500x67,0x2A,0x07,0x01, /* [4263] OBJ_setCext_certType */
6510x67,0x2A,0x07,0x02, /* [4267] OBJ_setCext_merchData */
6520x67,0x2A,0x07,0x03, /* [4271] OBJ_setCext_cCertRequired */
6530x67,0x2A,0x07,0x04, /* [4275] OBJ_setCext_tunneling */
6540x67,0x2A,0x07,0x05, /* [4279] OBJ_setCext_setExt */
6550x67,0x2A,0x07,0x06, /* [4283] OBJ_setCext_setQualf */
6560x67,0x2A,0x07,0x07, /* [4287] OBJ_setCext_PGWYcapabilities */
6570x67,0x2A,0x07,0x08, /* [4291] OBJ_setCext_TokenIdentifier */
6580x67,0x2A,0x07,0x09, /* [4295] OBJ_setCext_Track2Data */
6590x67,0x2A,0x07,0x0A, /* [4299] OBJ_setCext_TokenType */
6600x67,0x2A,0x07,0x0B, /* [4303] OBJ_setCext_IssuerCapabilities */
6610x67,0x2A,0x03,0x00, /* [4307] OBJ_setAttr_Cert */
6620x67,0x2A,0x03,0x01, /* [4311] OBJ_setAttr_PGWYcap */
6630x67,0x2A,0x03,0x02, /* [4315] OBJ_setAttr_TokenType */
6640x67,0x2A,0x03,0x03, /* [4319] OBJ_setAttr_IssCap */
6650x67,0x2A,0x03,0x00,0x00, /* [4323] OBJ_set_rootKeyThumb */
6660x67,0x2A,0x03,0x00,0x01, /* [4328] OBJ_set_addPolicy */
6670x67,0x2A,0x03,0x02,0x01, /* [4333] OBJ_setAttr_Token_EMV */
6680x67,0x2A,0x03,0x02,0x02, /* [4338] OBJ_setAttr_Token_B0Prime */
6690x67,0x2A,0x03,0x03,0x03, /* [4343] OBJ_setAttr_IssCap_CVM */
6700x67,0x2A,0x03,0x03,0x04, /* [4348] OBJ_setAttr_IssCap_T2 */
6710x67,0x2A,0x03,0x03,0x05, /* [4353] OBJ_setAttr_IssCap_Sig */
6720x67,0x2A,0x03,0x03,0x03,0x01, /* [4358] OBJ_setAttr_GenCryptgrm */
6730x67,0x2A,0x03,0x03,0x04,0x01, /* [4364] OBJ_setAttr_T2Enc */
6740x67,0x2A,0x03,0x03,0x04,0x02, /* [4370] OBJ_setAttr_T2cleartxt */
6750x67,0x2A,0x03,0x03,0x05,0x01, /* [4376] OBJ_setAttr_TokICCsig */
6760x67,0x2A,0x03,0x03,0x05,0x02, /* [4382] OBJ_setAttr_SecDevSig */
6770x67,0x2A,0x08,0x01, /* [4388] OBJ_set_brand_IATA_ATA */
6780x67,0x2A,0x08,0x1E, /* [4392] OBJ_set_brand_Diners */
6790x67,0x2A,0x08,0x22, /* [4396] OBJ_set_brand_AmericanExpress */
6800x67,0x2A,0x08,0x23, /* [4400] OBJ_set_brand_JCB */
6810x67,0x2A,0x08,0x04, /* [4404] OBJ_set_brand_Visa */
6820x67,0x2A,0x08,0x05, /* [4408] OBJ_set_brand_MasterCard */
6830x67,0x2A,0x08,0xAE,0x7B, /* [4412] OBJ_set_brand_Novus */
6840x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x0A, /* [4417] OBJ_des_cdmf */
6850x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x06,/* [4425] OBJ_rsaOAEPEncryptionSET */
6860x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x14,0x02,0x02,/* [4434] OBJ_ms_smartcard_login */
6870x2B,0x06,0x01,0x04,0x01,0x82,0x37,0x14,0x02,0x03,/* [4444] OBJ_ms_upn */
6880x55,0x04,0x09, /* [4454] OBJ_streetAddress */
6890x55,0x04,0x11, /* [4457] OBJ_postalCode */
6900x2B,0x06,0x01,0x05,0x05,0x07,0x15, /* [4460] OBJ_id_ppl */
6910x2B,0x06,0x01,0x05,0x05,0x07,0x01,0x0E, /* [4467] OBJ_proxyCertInfo */
6920x2B,0x06,0x01,0x05,0x05,0x07,0x15,0x00, /* [4475] OBJ_id_ppl_anyLanguage */
6930x2B,0x06,0x01,0x05,0x05,0x07,0x15,0x01, /* [4483] OBJ_id_ppl_inheritAll */
6940x55,0x1D,0x1E, /* [4491] OBJ_name_constraints */
6950x2B,0x06,0x01,0x05,0x05,0x07,0x15,0x02, /* [4494] OBJ_Independent */
6960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x0B,/* [4502] OBJ_sha256WithRSAEncryption */
6970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x0C,/* [4511] OBJ_sha384WithRSAEncryption */
6980x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x0D,/* [4520] OBJ_sha512WithRSAEncryption */
6990x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x0E,/* [4529] OBJ_sha224WithRSAEncryption */
7000x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,/* [4538] OBJ_sha256 */
7010x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,/* [4547] OBJ_sha384 */
7020x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,/* [4556] OBJ_sha512 */
7030x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,/* [4565] OBJ_sha224 */
704};
705
706static ASN1_OBJECT nid_objs[NUM_NID]={
707{"UNDEF","undefined",NID_undef,1,&(lvalues[0]),0},
708{"rsadsi","RSA Data Security, Inc.",NID_rsadsi,6,&(lvalues[1]),0},
709{"pkcs","RSA Data Security, Inc. PKCS",NID_pkcs,7,&(lvalues[7]),0},
710{"MD2","md2",NID_md2,8,&(lvalues[14]),0},
711{"MD5","md5",NID_md5,8,&(lvalues[22]),0},
712{"RC4","rc4",NID_rc4,8,&(lvalues[30]),0},
713{"rsaEncryption","rsaEncryption",NID_rsaEncryption,9,&(lvalues[38]),0},
714{"RSA-MD2","md2WithRSAEncryption",NID_md2WithRSAEncryption,9,
715 &(lvalues[47]),0},
716{"RSA-MD5","md5WithRSAEncryption",NID_md5WithRSAEncryption,9,
717 &(lvalues[56]),0},
718{"PBE-MD2-DES","pbeWithMD2AndDES-CBC",NID_pbeWithMD2AndDES_CBC,9,
719 &(lvalues[65]),0},
720{"PBE-MD5-DES","pbeWithMD5AndDES-CBC",NID_pbeWithMD5AndDES_CBC,9,
721 &(lvalues[74]),0},
722{"X500","directory services (X.500)",NID_X500,1,&(lvalues[83]),0},
723{"X509","X509",NID_X509,2,&(lvalues[84]),0},
724{"CN","commonName",NID_commonName,3,&(lvalues[86]),0},
725{"C","countryName",NID_countryName,3,&(lvalues[89]),0},
726{"L","localityName",NID_localityName,3,&(lvalues[92]),0},
727{"ST","stateOrProvinceName",NID_stateOrProvinceName,3,&(lvalues[95]),0},
728{"O","organizationName",NID_organizationName,3,&(lvalues[98]),0},
729{"OU","organizationalUnitName",NID_organizationalUnitName,3,
730 &(lvalues[101]),0},
731{"RSA","rsa",NID_rsa,4,&(lvalues[104]),0},
732{"pkcs7","pkcs7",NID_pkcs7,8,&(lvalues[108]),0},
733{"pkcs7-data","pkcs7-data",NID_pkcs7_data,9,&(lvalues[116]),0},
734{"pkcs7-signedData","pkcs7-signedData",NID_pkcs7_signed,9,
735 &(lvalues[125]),0},
736{"pkcs7-envelopedData","pkcs7-envelopedData",NID_pkcs7_enveloped,9,
737 &(lvalues[134]),0},
738{"pkcs7-signedAndEnvelopedData","pkcs7-signedAndEnvelopedData",
739 NID_pkcs7_signedAndEnveloped,9,&(lvalues[143]),0},
740{"pkcs7-digestData","pkcs7-digestData",NID_pkcs7_digest,9,
741 &(lvalues[152]),0},
742{"pkcs7-encryptedData","pkcs7-encryptedData",NID_pkcs7_encrypted,9,
743 &(lvalues[161]),0},
744{"pkcs3","pkcs3",NID_pkcs3,8,&(lvalues[170]),0},
745{"dhKeyAgreement","dhKeyAgreement",NID_dhKeyAgreement,9,
746 &(lvalues[178]),0},
747{"DES-ECB","des-ecb",NID_des_ecb,5,&(lvalues[187]),0},
748{"DES-CFB","des-cfb",NID_des_cfb64,5,&(lvalues[192]),0},
749{"DES-CBC","des-cbc",NID_des_cbc,5,&(lvalues[197]),0},
750{"DES-EDE","des-ede",NID_des_ede_ecb,5,&(lvalues[202]),0},
751{"DES-EDE3","des-ede3",NID_des_ede3_ecb,0,NULL},
752{"IDEA-CBC","idea-cbc",NID_idea_cbc,11,&(lvalues[207]),0},
753{"IDEA-CFB","idea-cfb",NID_idea_cfb64,0,NULL},
754{"IDEA-ECB","idea-ecb",NID_idea_ecb,0,NULL},
755{"RC2-CBC","rc2-cbc",NID_rc2_cbc,8,&(lvalues[218]),0},
756{"RC2-ECB","rc2-ecb",NID_rc2_ecb,0,NULL},
757{"RC2-CFB","rc2-cfb",NID_rc2_cfb64,0,NULL},
758{"RC2-OFB","rc2-ofb",NID_rc2_ofb64,0,NULL},
759{"SHA","sha",NID_sha,5,&(lvalues[226]),0},
760{"RSA-SHA","shaWithRSAEncryption",NID_shaWithRSAEncryption,5,
761 &(lvalues[231]),0},
762{"DES-EDE-CBC","des-ede-cbc",NID_des_ede_cbc,0,NULL},
763{"DES-EDE3-CBC","des-ede3-cbc",NID_des_ede3_cbc,8,&(lvalues[236]),0},
764{"DES-OFB","des-ofb",NID_des_ofb64,5,&(lvalues[244]),0},
765{"IDEA-OFB","idea-ofb",NID_idea_ofb64,0,NULL},
766{"pkcs9","pkcs9",NID_pkcs9,8,&(lvalues[249]),0},
767{"emailAddress","emailAddress",NID_pkcs9_emailAddress,9,
768 &(lvalues[257]),0},
769{"unstructuredName","unstructuredName",NID_pkcs9_unstructuredName,9,
770 &(lvalues[266]),0},
771{"contentType","contentType",NID_pkcs9_contentType,9,&(lvalues[275]),0},
772{"messageDigest","messageDigest",NID_pkcs9_messageDigest,9,
773 &(lvalues[284]),0},
774{"signingTime","signingTime",NID_pkcs9_signingTime,9,&(lvalues[293]),0},
775{"countersignature","countersignature",NID_pkcs9_countersignature,9,
776 &(lvalues[302]),0},
777{"challengePassword","challengePassword",NID_pkcs9_challengePassword,
778 9,&(lvalues[311]),0},
779{"unstructuredAddress","unstructuredAddress",
780 NID_pkcs9_unstructuredAddress,9,&(lvalues[320]),0},
781{"extendedCertificateAttributes","extendedCertificateAttributes",
782 NID_pkcs9_extCertAttributes,9,&(lvalues[329]),0},
783{"Netscape","Netscape Communications Corp.",NID_netscape,7,
784 &(lvalues[338]),0},
785{"nsCertExt","Netscape Certificate Extension",
786 NID_netscape_cert_extension,8,&(lvalues[345]),0},
787{"nsDataType","Netscape Data Type",NID_netscape_data_type,8,
788 &(lvalues[353]),0},
789{"DES-EDE-CFB","des-ede-cfb",NID_des_ede_cfb64,0,NULL},
790{"DES-EDE3-CFB","des-ede3-cfb",NID_des_ede3_cfb64,0,NULL},
791{"DES-EDE-OFB","des-ede-ofb",NID_des_ede_ofb64,0,NULL},
792{"DES-EDE3-OFB","des-ede3-ofb",NID_des_ede3_ofb64,0,NULL},
793{"SHA1","sha1",NID_sha1,5,&(lvalues[361]),0},
794{"RSA-SHA1","sha1WithRSAEncryption",NID_sha1WithRSAEncryption,9,
795 &(lvalues[366]),0},
796{"DSA-SHA","dsaWithSHA",NID_dsaWithSHA,5,&(lvalues[375]),0},
797{"DSA-old","dsaEncryption-old",NID_dsa_2,5,&(lvalues[380]),0},
798{"PBE-SHA1-RC2-64","pbeWithSHA1AndRC2-CBC",NID_pbeWithSHA1AndRC2_CBC,
799 9,&(lvalues[385]),0},
800{"PBKDF2","PBKDF2",NID_id_pbkdf2,9,&(lvalues[394]),0},
801{"DSA-SHA1-old","dsaWithSHA1-old",NID_dsaWithSHA1_2,5,&(lvalues[403]),0},
802{"nsCertType","Netscape Cert Type",NID_netscape_cert_type,9,
803 &(lvalues[408]),0},
804{"nsBaseUrl","Netscape Base Url",NID_netscape_base_url,9,
805 &(lvalues[417]),0},
806{"nsRevocationUrl","Netscape Revocation Url",
807 NID_netscape_revocation_url,9,&(lvalues[426]),0},
808{"nsCaRevocationUrl","Netscape CA Revocation Url",
809 NID_netscape_ca_revocation_url,9,&(lvalues[435]),0},
810{"nsRenewalUrl","Netscape Renewal Url",NID_netscape_renewal_url,9,
811 &(lvalues[444]),0},
812{"nsCaPolicyUrl","Netscape CA Policy Url",NID_netscape_ca_policy_url,
813 9,&(lvalues[453]),0},
814{"nsSslServerName","Netscape SSL Server Name",
815 NID_netscape_ssl_server_name,9,&(lvalues[462]),0},
816{"nsComment","Netscape Comment",NID_netscape_comment,9,&(lvalues[471]),0},
817{"nsCertSequence","Netscape Certificate Sequence",
818 NID_netscape_cert_sequence,9,&(lvalues[480]),0},
819{"DESX-CBC","desx-cbc",NID_desx_cbc,0,NULL},
820{"id-ce","id-ce",NID_id_ce,2,&(lvalues[489]),0},
821{"subjectKeyIdentifier","X509v3 Subject Key Identifier",
822 NID_subject_key_identifier,3,&(lvalues[491]),0},
823{"keyUsage","X509v3 Key Usage",NID_key_usage,3,&(lvalues[494]),0},
824{"privateKeyUsagePeriod","X509v3 Private Key Usage Period",
825 NID_private_key_usage_period,3,&(lvalues[497]),0},
826{"subjectAltName","X509v3 Subject Alternative Name",
827 NID_subject_alt_name,3,&(lvalues[500]),0},
828{"issuerAltName","X509v3 Issuer Alternative Name",NID_issuer_alt_name,
829 3,&(lvalues[503]),0},
830{"basicConstraints","X509v3 Basic Constraints",NID_basic_constraints,
831 3,&(lvalues[506]),0},
832{"crlNumber","X509v3 CRL Number",NID_crl_number,3,&(lvalues[509]),0},
833{"certificatePolicies","X509v3 Certificate Policies",
834 NID_certificate_policies,3,&(lvalues[512]),0},
835{"authorityKeyIdentifier","X509v3 Authority Key Identifier",
836 NID_authority_key_identifier,3,&(lvalues[515]),0},
837{"BF-CBC","bf-cbc",NID_bf_cbc,9,&(lvalues[518]),0},
838{"BF-ECB","bf-ecb",NID_bf_ecb,0,NULL},
839{"BF-CFB","bf-cfb",NID_bf_cfb64,0,NULL},
840{"BF-OFB","bf-ofb",NID_bf_ofb64,0,NULL},
841{"MDC2","mdc2",NID_mdc2,4,&(lvalues[527]),0},
842{"RSA-MDC2","mdc2WithRSA",NID_mdc2WithRSA,4,&(lvalues[531]),0},
843{"RC4-40","rc4-40",NID_rc4_40,0,NULL},
844{"RC2-40-CBC","rc2-40-cbc",NID_rc2_40_cbc,0,NULL},
845{"GN","givenName",NID_givenName,3,&(lvalues[535]),0},
846{"SN","surname",NID_surname,3,&(lvalues[538]),0},
847{"initials","initials",NID_initials,3,&(lvalues[541]),0},
848{NULL,NULL,NID_undef,0,NULL},
849{"crlDistributionPoints","X509v3 CRL Distribution Points",
850 NID_crl_distribution_points,3,&(lvalues[544]),0},
851{"RSA-NP-MD5","md5WithRSA",NID_md5WithRSA,5,&(lvalues[547]),0},
852{"serialNumber","serialNumber",NID_serialNumber,3,&(lvalues[552]),0},
853{"title","title",NID_title,3,&(lvalues[555]),0},
854{"description","description",NID_description,3,&(lvalues[558]),0},
855{"CAST5-CBC","cast5-cbc",NID_cast5_cbc,9,&(lvalues[561]),0},
856{"CAST5-ECB","cast5-ecb",NID_cast5_ecb,0,NULL},
857{"CAST5-CFB","cast5-cfb",NID_cast5_cfb64,0,NULL},
858{"CAST5-OFB","cast5-ofb",NID_cast5_ofb64,0,NULL},
859{"pbeWithMD5AndCast5CBC","pbeWithMD5AndCast5CBC",
860 NID_pbeWithMD5AndCast5_CBC,9,&(lvalues[570]),0},
861{"DSA-SHA1","dsaWithSHA1",NID_dsaWithSHA1,7,&(lvalues[579]),0},
862{"MD5-SHA1","md5-sha1",NID_md5_sha1,0,NULL},
863{"RSA-SHA1-2","sha1WithRSA",NID_sha1WithRSA,5,&(lvalues[586]),0},
864{"DSA","dsaEncryption",NID_dsa,7,&(lvalues[591]),0},
865{"RIPEMD160","ripemd160",NID_ripemd160,5,&(lvalues[598]),0},
866{NULL,NULL,NID_undef,0,NULL},
867{"RSA-RIPEMD160","ripemd160WithRSA",NID_ripemd160WithRSA,6,
868 &(lvalues[603]),0},
869{"RC5-CBC","rc5-cbc",NID_rc5_cbc,8,&(lvalues[609]),0},
870{"RC5-ECB","rc5-ecb",NID_rc5_ecb,0,NULL},
871{"RC5-CFB","rc5-cfb",NID_rc5_cfb64,0,NULL},
872{"RC5-OFB","rc5-ofb",NID_rc5_ofb64,0,NULL},
873{"RLE","run length compression",NID_rle_compression,6,&(lvalues[617]),0},
874{"ZLIB","zlib compression",NID_zlib_compression,6,&(lvalues[623]),0},
875{"extendedKeyUsage","X509v3 Extended Key Usage",NID_ext_key_usage,3,
876 &(lvalues[629]),0},
877{"PKIX","PKIX",NID_id_pkix,6,&(lvalues[632]),0},
878{"id-kp","id-kp",NID_id_kp,7,&(lvalues[638]),0},
879{"serverAuth","TLS Web Server Authentication",NID_server_auth,8,
880 &(lvalues[645]),0},
881{"clientAuth","TLS Web Client Authentication",NID_client_auth,8,
882 &(lvalues[653]),0},
883{"codeSigning","Code Signing",NID_code_sign,8,&(lvalues[661]),0},
884{"emailProtection","E-mail Protection",NID_email_protect,8,
885 &(lvalues[669]),0},
886{"timeStamping","Time Stamping",NID_time_stamp,8,&(lvalues[677]),0},
887{"msCodeInd","Microsoft Individual Code Signing",NID_ms_code_ind,10,
888 &(lvalues[685]),0},
889{"msCodeCom","Microsoft Commercial Code Signing",NID_ms_code_com,10,
890 &(lvalues[695]),0},
891{"msCTLSign","Microsoft Trust List Signing",NID_ms_ctl_sign,10,
892 &(lvalues[705]),0},
893{"msSGC","Microsoft Server Gated Crypto",NID_ms_sgc,10,&(lvalues[715]),0},
894{"msEFS","Microsoft Encrypted File System",NID_ms_efs,10,
895 &(lvalues[725]),0},
896{"nsSGC","Netscape Server Gated Crypto",NID_ns_sgc,9,&(lvalues[735]),0},
897{"deltaCRL","X509v3 Delta CRL Indicator",NID_delta_crl,3,
898 &(lvalues[744]),0},
899{"CRLReason","X509v3 CRL Reason Code",NID_crl_reason,3,&(lvalues[747]),0},
900{"invalidityDate","Invalidity Date",NID_invalidity_date,3,
901 &(lvalues[750]),0},
902{"SXNetID","Strong Extranet ID",NID_sxnet,5,&(lvalues[753]),0},
903{"PBE-SHA1-RC4-128","pbeWithSHA1And128BitRC4",
904 NID_pbe_WithSHA1And128BitRC4,10,&(lvalues[758]),0},
905{"PBE-SHA1-RC4-40","pbeWithSHA1And40BitRC4",
906 NID_pbe_WithSHA1And40BitRC4,10,&(lvalues[768]),0},
907{"PBE-SHA1-3DES","pbeWithSHA1And3-KeyTripleDES-CBC",
908 NID_pbe_WithSHA1And3_Key_TripleDES_CBC,10,&(lvalues[778]),0},
909{"PBE-SHA1-2DES","pbeWithSHA1And2-KeyTripleDES-CBC",
910 NID_pbe_WithSHA1And2_Key_TripleDES_CBC,10,&(lvalues[788]),0},
911{"PBE-SHA1-RC2-128","pbeWithSHA1And128BitRC2-CBC",
912 NID_pbe_WithSHA1And128BitRC2_CBC,10,&(lvalues[798]),0},
913{"PBE-SHA1-RC2-40","pbeWithSHA1And40BitRC2-CBC",
914 NID_pbe_WithSHA1And40BitRC2_CBC,10,&(lvalues[808]),0},
915{"keyBag","keyBag",NID_keyBag,11,&(lvalues[818]),0},
916{"pkcs8ShroudedKeyBag","pkcs8ShroudedKeyBag",NID_pkcs8ShroudedKeyBag,
917 11,&(lvalues[829]),0},
918{"certBag","certBag",NID_certBag,11,&(lvalues[840]),0},
919{"crlBag","crlBag",NID_crlBag,11,&(lvalues[851]),0},
920{"secretBag","secretBag",NID_secretBag,11,&(lvalues[862]),0},
921{"safeContentsBag","safeContentsBag",NID_safeContentsBag,11,
922 &(lvalues[873]),0},
923{"friendlyName","friendlyName",NID_friendlyName,9,&(lvalues[884]),0},
924{"localKeyID","localKeyID",NID_localKeyID,9,&(lvalues[893]),0},
925{"x509Certificate","x509Certificate",NID_x509Certificate,10,
926 &(lvalues[902]),0},
927{"sdsiCertificate","sdsiCertificate",NID_sdsiCertificate,10,
928 &(lvalues[912]),0},
929{"x509Crl","x509Crl",NID_x509Crl,10,&(lvalues[922]),0},
930{"PBES2","PBES2",NID_pbes2,9,&(lvalues[932]),0},
931{"PBMAC1","PBMAC1",NID_pbmac1,9,&(lvalues[941]),0},
932{"hmacWithSHA1","hmacWithSHA1",NID_hmacWithSHA1,8,&(lvalues[950]),0},
933{"id-qt-cps","Policy Qualifier CPS",NID_id_qt_cps,8,&(lvalues[958]),0},
934{"id-qt-unotice","Policy Qualifier User Notice",NID_id_qt_unotice,8,
935 &(lvalues[966]),0},
936{"RC2-64-CBC","rc2-64-cbc",NID_rc2_64_cbc,0,NULL},
937{"SMIME-CAPS","S/MIME Capabilities",NID_SMIMECapabilities,9,
938 &(lvalues[974]),0},
939{"PBE-MD2-RC2-64","pbeWithMD2AndRC2-CBC",NID_pbeWithMD2AndRC2_CBC,9,
940 &(lvalues[983]),0},
941{"PBE-MD5-RC2-64","pbeWithMD5AndRC2-CBC",NID_pbeWithMD5AndRC2_CBC,9,
942 &(lvalues[992]),0},
943{"PBE-SHA1-DES","pbeWithSHA1AndDES-CBC",NID_pbeWithSHA1AndDES_CBC,9,
944 &(lvalues[1001]),0},
945{"msExtReq","Microsoft Extension Request",NID_ms_ext_req,10,
946 &(lvalues[1010]),0},
947{"extReq","Extension Request",NID_ext_req,9,&(lvalues[1020]),0},
948{"name","name",NID_name,3,&(lvalues[1029]),0},
949{"dnQualifier","dnQualifier",NID_dnQualifier,3,&(lvalues[1032]),0},
950{"id-pe","id-pe",NID_id_pe,7,&(lvalues[1035]),0},
951{"id-ad","id-ad",NID_id_ad,7,&(lvalues[1042]),0},
952{"authorityInfoAccess","Authority Information Access",NID_info_access,
953 8,&(lvalues[1049]),0},
954{"OCSP","OCSP",NID_ad_OCSP,8,&(lvalues[1057]),0},
955{"caIssuers","CA Issuers",NID_ad_ca_issuers,8,&(lvalues[1065]),0},
956{"OCSPSigning","OCSP Signing",NID_OCSP_sign,8,&(lvalues[1073]),0},
957{"ISO","iso",NID_iso,1,&(lvalues[1081]),0},
958{"member-body","ISO Member Body",NID_member_body,1,&(lvalues[1082]),0},
959{"ISO-US","ISO US Member Body",NID_ISO_US,3,&(lvalues[1083]),0},
960{"X9-57","X9.57",NID_X9_57,5,&(lvalues[1086]),0},
961{"X9cm","X9.57 CM ?",NID_X9cm,6,&(lvalues[1091]),0},
962{"pkcs1","pkcs1",NID_pkcs1,8,&(lvalues[1097]),0},
963{"pkcs5","pkcs5",NID_pkcs5,8,&(lvalues[1105]),0},
964{"SMIME","S/MIME",NID_SMIME,9,&(lvalues[1113]),0},
965{"id-smime-mod","id-smime-mod",NID_id_smime_mod,10,&(lvalues[1122]),0},
966{"id-smime-ct","id-smime-ct",NID_id_smime_ct,10,&(lvalues[1132]),0},
967{"id-smime-aa","id-smime-aa",NID_id_smime_aa,10,&(lvalues[1142]),0},
968{"id-smime-alg","id-smime-alg",NID_id_smime_alg,10,&(lvalues[1152]),0},
969{"id-smime-cd","id-smime-cd",NID_id_smime_cd,10,&(lvalues[1162]),0},
970{"id-smime-spq","id-smime-spq",NID_id_smime_spq,10,&(lvalues[1172]),0},
971{"id-smime-cti","id-smime-cti",NID_id_smime_cti,10,&(lvalues[1182]),0},
972{"id-smime-mod-cms","id-smime-mod-cms",NID_id_smime_mod_cms,11,
973 &(lvalues[1192]),0},
974{"id-smime-mod-ess","id-smime-mod-ess",NID_id_smime_mod_ess,11,
975 &(lvalues[1203]),0},
976{"id-smime-mod-oid","id-smime-mod-oid",NID_id_smime_mod_oid,11,
977 &(lvalues[1214]),0},
978{"id-smime-mod-msg-v3","id-smime-mod-msg-v3",NID_id_smime_mod_msg_v3,
979 11,&(lvalues[1225]),0},
980{"id-smime-mod-ets-eSignature-88","id-smime-mod-ets-eSignature-88",
981 NID_id_smime_mod_ets_eSignature_88,11,&(lvalues[1236]),0},
982{"id-smime-mod-ets-eSignature-97","id-smime-mod-ets-eSignature-97",
983 NID_id_smime_mod_ets_eSignature_97,11,&(lvalues[1247]),0},
984{"id-smime-mod-ets-eSigPolicy-88","id-smime-mod-ets-eSigPolicy-88",
985 NID_id_smime_mod_ets_eSigPolicy_88,11,&(lvalues[1258]),0},
986{"id-smime-mod-ets-eSigPolicy-97","id-smime-mod-ets-eSigPolicy-97",
987 NID_id_smime_mod_ets_eSigPolicy_97,11,&(lvalues[1269]),0},
988{"id-smime-ct-receipt","id-smime-ct-receipt",NID_id_smime_ct_receipt,
989 11,&(lvalues[1280]),0},
990{"id-smime-ct-authData","id-smime-ct-authData",
991 NID_id_smime_ct_authData,11,&(lvalues[1291]),0},
992{"id-smime-ct-publishCert","id-smime-ct-publishCert",
993 NID_id_smime_ct_publishCert,11,&(lvalues[1302]),0},
994{"id-smime-ct-TSTInfo","id-smime-ct-TSTInfo",NID_id_smime_ct_TSTInfo,
995 11,&(lvalues[1313]),0},
996{"id-smime-ct-TDTInfo","id-smime-ct-TDTInfo",NID_id_smime_ct_TDTInfo,
997 11,&(lvalues[1324]),0},
998{"id-smime-ct-contentInfo","id-smime-ct-contentInfo",
999 NID_id_smime_ct_contentInfo,11,&(lvalues[1335]),0},
1000{"id-smime-ct-DVCSRequestData","id-smime-ct-DVCSRequestData",
1001 NID_id_smime_ct_DVCSRequestData,11,&(lvalues[1346]),0},
1002{"id-smime-ct-DVCSResponseData","id-smime-ct-DVCSResponseData",
1003 NID_id_smime_ct_DVCSResponseData,11,&(lvalues[1357]),0},
1004{"id-smime-aa-receiptRequest","id-smime-aa-receiptRequest",
1005 NID_id_smime_aa_receiptRequest,11,&(lvalues[1368]),0},
1006{"id-smime-aa-securityLabel","id-smime-aa-securityLabel",
1007 NID_id_smime_aa_securityLabel,11,&(lvalues[1379]),0},
1008{"id-smime-aa-mlExpandHistory","id-smime-aa-mlExpandHistory",
1009 NID_id_smime_aa_mlExpandHistory,11,&(lvalues[1390]),0},
1010{"id-smime-aa-contentHint","id-smime-aa-contentHint",
1011 NID_id_smime_aa_contentHint,11,&(lvalues[1401]),0},
1012{"id-smime-aa-msgSigDigest","id-smime-aa-msgSigDigest",
1013 NID_id_smime_aa_msgSigDigest,11,&(lvalues[1412]),0},
1014{"id-smime-aa-encapContentType","id-smime-aa-encapContentType",
1015 NID_id_smime_aa_encapContentType,11,&(lvalues[1423]),0},
1016{"id-smime-aa-contentIdentifier","id-smime-aa-contentIdentifier",
1017 NID_id_smime_aa_contentIdentifier,11,&(lvalues[1434]),0},
1018{"id-smime-aa-macValue","id-smime-aa-macValue",
1019 NID_id_smime_aa_macValue,11,&(lvalues[1445]),0},
1020{"id-smime-aa-equivalentLabels","id-smime-aa-equivalentLabels",
1021 NID_id_smime_aa_equivalentLabels,11,&(lvalues[1456]),0},
1022{"id-smime-aa-contentReference","id-smime-aa-contentReference",
1023 NID_id_smime_aa_contentReference,11,&(lvalues[1467]),0},
1024{"id-smime-aa-encrypKeyPref","id-smime-aa-encrypKeyPref",
1025 NID_id_smime_aa_encrypKeyPref,11,&(lvalues[1478]),0},
1026{"id-smime-aa-signingCertificate","id-smime-aa-signingCertificate",
1027 NID_id_smime_aa_signingCertificate,11,&(lvalues[1489]),0},
1028{"id-smime-aa-smimeEncryptCerts","id-smime-aa-smimeEncryptCerts",
1029 NID_id_smime_aa_smimeEncryptCerts,11,&(lvalues[1500]),0},
1030{"id-smime-aa-timeStampToken","id-smime-aa-timeStampToken",
1031 NID_id_smime_aa_timeStampToken,11,&(lvalues[1511]),0},
1032{"id-smime-aa-ets-sigPolicyId","id-smime-aa-ets-sigPolicyId",
1033 NID_id_smime_aa_ets_sigPolicyId,11,&(lvalues[1522]),0},
1034{"id-smime-aa-ets-commitmentType","id-smime-aa-ets-commitmentType",
1035 NID_id_smime_aa_ets_commitmentType,11,&(lvalues[1533]),0},
1036{"id-smime-aa-ets-signerLocation","id-smime-aa-ets-signerLocation",
1037 NID_id_smime_aa_ets_signerLocation,11,&(lvalues[1544]),0},
1038{"id-smime-aa-ets-signerAttr","id-smime-aa-ets-signerAttr",
1039 NID_id_smime_aa_ets_signerAttr,11,&(lvalues[1555]),0},
1040{"id-smime-aa-ets-otherSigCert","id-smime-aa-ets-otherSigCert",
1041 NID_id_smime_aa_ets_otherSigCert,11,&(lvalues[1566]),0},
1042{"id-smime-aa-ets-contentTimestamp",
1043 "id-smime-aa-ets-contentTimestamp",
1044 NID_id_smime_aa_ets_contentTimestamp,11,&(lvalues[1577]),0},
1045{"id-smime-aa-ets-CertificateRefs","id-smime-aa-ets-CertificateRefs",
1046 NID_id_smime_aa_ets_CertificateRefs,11,&(lvalues[1588]),0},
1047{"id-smime-aa-ets-RevocationRefs","id-smime-aa-ets-RevocationRefs",
1048 NID_id_smime_aa_ets_RevocationRefs,11,&(lvalues[1599]),0},
1049{"id-smime-aa-ets-certValues","id-smime-aa-ets-certValues",
1050 NID_id_smime_aa_ets_certValues,11,&(lvalues[1610]),0},
1051{"id-smime-aa-ets-revocationValues",
1052 "id-smime-aa-ets-revocationValues",
1053 NID_id_smime_aa_ets_revocationValues,11,&(lvalues[1621]),0},
1054{"id-smime-aa-ets-escTimeStamp","id-smime-aa-ets-escTimeStamp",
1055 NID_id_smime_aa_ets_escTimeStamp,11,&(lvalues[1632]),0},
1056{"id-smime-aa-ets-certCRLTimestamp",
1057 "id-smime-aa-ets-certCRLTimestamp",
1058 NID_id_smime_aa_ets_certCRLTimestamp,11,&(lvalues[1643]),0},
1059{"id-smime-aa-ets-archiveTimeStamp",
1060 "id-smime-aa-ets-archiveTimeStamp",
1061 NID_id_smime_aa_ets_archiveTimeStamp,11,&(lvalues[1654]),0},
1062{"id-smime-aa-signatureType","id-smime-aa-signatureType",
1063 NID_id_smime_aa_signatureType,11,&(lvalues[1665]),0},
1064{"id-smime-aa-dvcs-dvc","id-smime-aa-dvcs-dvc",
1065 NID_id_smime_aa_dvcs_dvc,11,&(lvalues[1676]),0},
1066{"id-smime-alg-ESDHwith3DES","id-smime-alg-ESDHwith3DES",
1067 NID_id_smime_alg_ESDHwith3DES,11,&(lvalues[1687]),0},
1068{"id-smime-alg-ESDHwithRC2","id-smime-alg-ESDHwithRC2",
1069 NID_id_smime_alg_ESDHwithRC2,11,&(lvalues[1698]),0},
1070{"id-smime-alg-3DESwrap","id-smime-alg-3DESwrap",
1071 NID_id_smime_alg_3DESwrap,11,&(lvalues[1709]),0},
1072{"id-smime-alg-RC2wrap","id-smime-alg-RC2wrap",
1073 NID_id_smime_alg_RC2wrap,11,&(lvalues[1720]),0},
1074{"id-smime-alg-ESDH","id-smime-alg-ESDH",NID_id_smime_alg_ESDH,11,
1075 &(lvalues[1731]),0},
1076{"id-smime-alg-CMS3DESwrap","id-smime-alg-CMS3DESwrap",
1077 NID_id_smime_alg_CMS3DESwrap,11,&(lvalues[1742]),0},
1078{"id-smime-alg-CMSRC2wrap","id-smime-alg-CMSRC2wrap",
1079 NID_id_smime_alg_CMSRC2wrap,11,&(lvalues[1753]),0},
1080{"id-smime-cd-ldap","id-smime-cd-ldap",NID_id_smime_cd_ldap,11,
1081 &(lvalues[1764]),0},
1082{"id-smime-spq-ets-sqt-uri","id-smime-spq-ets-sqt-uri",
1083 NID_id_smime_spq_ets_sqt_uri,11,&(lvalues[1775]),0},
1084{"id-smime-spq-ets-sqt-unotice","id-smime-spq-ets-sqt-unotice",
1085 NID_id_smime_spq_ets_sqt_unotice,11,&(lvalues[1786]),0},
1086{"id-smime-cti-ets-proofOfOrigin","id-smime-cti-ets-proofOfOrigin",
1087 NID_id_smime_cti_ets_proofOfOrigin,11,&(lvalues[1797]),0},
1088{"id-smime-cti-ets-proofOfReceipt","id-smime-cti-ets-proofOfReceipt",
1089 NID_id_smime_cti_ets_proofOfReceipt,11,&(lvalues[1808]),0},
1090{"id-smime-cti-ets-proofOfDelivery",
1091 "id-smime-cti-ets-proofOfDelivery",
1092 NID_id_smime_cti_ets_proofOfDelivery,11,&(lvalues[1819]),0},
1093{"id-smime-cti-ets-proofOfSender","id-smime-cti-ets-proofOfSender",
1094 NID_id_smime_cti_ets_proofOfSender,11,&(lvalues[1830]),0},
1095{"id-smime-cti-ets-proofOfApproval",
1096 "id-smime-cti-ets-proofOfApproval",
1097 NID_id_smime_cti_ets_proofOfApproval,11,&(lvalues[1841]),0},
1098{"id-smime-cti-ets-proofOfCreation",
1099 "id-smime-cti-ets-proofOfCreation",
1100 NID_id_smime_cti_ets_proofOfCreation,11,&(lvalues[1852]),0},
1101{"MD4","md4",NID_md4,8,&(lvalues[1863]),0},
1102{"id-pkix-mod","id-pkix-mod",NID_id_pkix_mod,7,&(lvalues[1871]),0},
1103{"id-qt","id-qt",NID_id_qt,7,&(lvalues[1878]),0},
1104{"id-it","id-it",NID_id_it,7,&(lvalues[1885]),0},
1105{"id-pkip","id-pkip",NID_id_pkip,7,&(lvalues[1892]),0},
1106{"id-alg","id-alg",NID_id_alg,7,&(lvalues[1899]),0},
1107{"id-cmc","id-cmc",NID_id_cmc,7,&(lvalues[1906]),0},
1108{"id-on","id-on",NID_id_on,7,&(lvalues[1913]),0},
1109{"id-pda","id-pda",NID_id_pda,7,&(lvalues[1920]),0},
1110{"id-aca","id-aca",NID_id_aca,7,&(lvalues[1927]),0},
1111{"id-qcs","id-qcs",NID_id_qcs,7,&(lvalues[1934]),0},
1112{"id-cct","id-cct",NID_id_cct,7,&(lvalues[1941]),0},
1113{"id-pkix1-explicit-88","id-pkix1-explicit-88",
1114 NID_id_pkix1_explicit_88,8,&(lvalues[1948]),0},
1115{"id-pkix1-implicit-88","id-pkix1-implicit-88",
1116 NID_id_pkix1_implicit_88,8,&(lvalues[1956]),0},
1117{"id-pkix1-explicit-93","id-pkix1-explicit-93",
1118 NID_id_pkix1_explicit_93,8,&(lvalues[1964]),0},
1119{"id-pkix1-implicit-93","id-pkix1-implicit-93",
1120 NID_id_pkix1_implicit_93,8,&(lvalues[1972]),0},
1121{"id-mod-crmf","id-mod-crmf",NID_id_mod_crmf,8,&(lvalues[1980]),0},
1122{"id-mod-cmc","id-mod-cmc",NID_id_mod_cmc,8,&(lvalues[1988]),0},
1123{"id-mod-kea-profile-88","id-mod-kea-profile-88",
1124 NID_id_mod_kea_profile_88,8,&(lvalues[1996]),0},
1125{"id-mod-kea-profile-93","id-mod-kea-profile-93",
1126 NID_id_mod_kea_profile_93,8,&(lvalues[2004]),0},
1127{"id-mod-cmp","id-mod-cmp",NID_id_mod_cmp,8,&(lvalues[2012]),0},
1128{"id-mod-qualified-cert-88","id-mod-qualified-cert-88",
1129 NID_id_mod_qualified_cert_88,8,&(lvalues[2020]),0},
1130{"id-mod-qualified-cert-93","id-mod-qualified-cert-93",
1131 NID_id_mod_qualified_cert_93,8,&(lvalues[2028]),0},
1132{"id-mod-attribute-cert","id-mod-attribute-cert",
1133 NID_id_mod_attribute_cert,8,&(lvalues[2036]),0},
1134{"id-mod-timestamp-protocol","id-mod-timestamp-protocol",
1135 NID_id_mod_timestamp_protocol,8,&(lvalues[2044]),0},
1136{"id-mod-ocsp","id-mod-ocsp",NID_id_mod_ocsp,8,&(lvalues[2052]),0},
1137{"id-mod-dvcs","id-mod-dvcs",NID_id_mod_dvcs,8,&(lvalues[2060]),0},
1138{"id-mod-cmp2000","id-mod-cmp2000",NID_id_mod_cmp2000,8,
1139 &(lvalues[2068]),0},
1140{"biometricInfo","Biometric Info",NID_biometricInfo,8,&(lvalues[2076]),0},
1141{"qcStatements","qcStatements",NID_qcStatements,8,&(lvalues[2084]),0},
1142{"ac-auditEntity","ac-auditEntity",NID_ac_auditEntity,8,
1143 &(lvalues[2092]),0},
1144{"ac-targeting","ac-targeting",NID_ac_targeting,8,&(lvalues[2100]),0},
1145{"aaControls","aaControls",NID_aaControls,8,&(lvalues[2108]),0},
1146{"sbgp-ipAddrBlock","sbgp-ipAddrBlock",NID_sbgp_ipAddrBlock,8,
1147 &(lvalues[2116]),0},
1148{"sbgp-autonomousSysNum","sbgp-autonomousSysNum",
1149 NID_sbgp_autonomousSysNum,8,&(lvalues[2124]),0},
1150{"sbgp-routerIdentifier","sbgp-routerIdentifier",
1151 NID_sbgp_routerIdentifier,8,&(lvalues[2132]),0},
1152{"textNotice","textNotice",NID_textNotice,8,&(lvalues[2140]),0},
1153{"ipsecEndSystem","IPSec End System",NID_ipsecEndSystem,8,
1154 &(lvalues[2148]),0},
1155{"ipsecTunnel","IPSec Tunnel",NID_ipsecTunnel,8,&(lvalues[2156]),0},
1156{"ipsecUser","IPSec User",NID_ipsecUser,8,&(lvalues[2164]),0},
1157{"DVCS","dvcs",NID_dvcs,8,&(lvalues[2172]),0},
1158{"id-it-caProtEncCert","id-it-caProtEncCert",NID_id_it_caProtEncCert,
1159 8,&(lvalues[2180]),0},
1160{"id-it-signKeyPairTypes","id-it-signKeyPairTypes",
1161 NID_id_it_signKeyPairTypes,8,&(lvalues[2188]),0},
1162{"id-it-encKeyPairTypes","id-it-encKeyPairTypes",
1163 NID_id_it_encKeyPairTypes,8,&(lvalues[2196]),0},
1164{"id-it-preferredSymmAlg","id-it-preferredSymmAlg",
1165 NID_id_it_preferredSymmAlg,8,&(lvalues[2204]),0},
1166{"id-it-caKeyUpdateInfo","id-it-caKeyUpdateInfo",
1167 NID_id_it_caKeyUpdateInfo,8,&(lvalues[2212]),0},
1168{"id-it-currentCRL","id-it-currentCRL",NID_id_it_currentCRL,8,
1169 &(lvalues[2220]),0},
1170{"id-it-unsupportedOIDs","id-it-unsupportedOIDs",
1171 NID_id_it_unsupportedOIDs,8,&(lvalues[2228]),0},
1172{"id-it-subscriptionRequest","id-it-subscriptionRequest",
1173 NID_id_it_subscriptionRequest,8,&(lvalues[2236]),0},
1174{"id-it-subscriptionResponse","id-it-subscriptionResponse",
1175 NID_id_it_subscriptionResponse,8,&(lvalues[2244]),0},
1176{"id-it-keyPairParamReq","id-it-keyPairParamReq",
1177 NID_id_it_keyPairParamReq,8,&(lvalues[2252]),0},
1178{"id-it-keyPairParamRep","id-it-keyPairParamRep",
1179 NID_id_it_keyPairParamRep,8,&(lvalues[2260]),0},
1180{"id-it-revPassphrase","id-it-revPassphrase",NID_id_it_revPassphrase,
1181 8,&(lvalues[2268]),0},
1182{"id-it-implicitConfirm","id-it-implicitConfirm",
1183 NID_id_it_implicitConfirm,8,&(lvalues[2276]),0},
1184{"id-it-confirmWaitTime","id-it-confirmWaitTime",
1185 NID_id_it_confirmWaitTime,8,&(lvalues[2284]),0},
1186{"id-it-origPKIMessage","id-it-origPKIMessage",
1187 NID_id_it_origPKIMessage,8,&(lvalues[2292]),0},
1188{"id-regCtrl","id-regCtrl",NID_id_regCtrl,8,&(lvalues[2300]),0},
1189{"id-regInfo","id-regInfo",NID_id_regInfo,8,&(lvalues[2308]),0},
1190{"id-regCtrl-regToken","id-regCtrl-regToken",NID_id_regCtrl_regToken,
1191 9,&(lvalues[2316]),0},
1192{"id-regCtrl-authenticator","id-regCtrl-authenticator",
1193 NID_id_regCtrl_authenticator,9,&(lvalues[2325]),0},
1194{"id-regCtrl-pkiPublicationInfo","id-regCtrl-pkiPublicationInfo",
1195 NID_id_regCtrl_pkiPublicationInfo,9,&(lvalues[2334]),0},
1196{"id-regCtrl-pkiArchiveOptions","id-regCtrl-pkiArchiveOptions",
1197 NID_id_regCtrl_pkiArchiveOptions,9,&(lvalues[2343]),0},
1198{"id-regCtrl-oldCertID","id-regCtrl-oldCertID",
1199 NID_id_regCtrl_oldCertID,9,&(lvalues[2352]),0},
1200{"id-regCtrl-protocolEncrKey","id-regCtrl-protocolEncrKey",
1201 NID_id_regCtrl_protocolEncrKey,9,&(lvalues[2361]),0},
1202{"id-regInfo-utf8Pairs","id-regInfo-utf8Pairs",
1203 NID_id_regInfo_utf8Pairs,9,&(lvalues[2370]),0},
1204{"id-regInfo-certReq","id-regInfo-certReq",NID_id_regInfo_certReq,9,
1205 &(lvalues[2379]),0},
1206{"id-alg-des40","id-alg-des40",NID_id_alg_des40,8,&(lvalues[2388]),0},
1207{"id-alg-noSignature","id-alg-noSignature",NID_id_alg_noSignature,8,
1208 &(lvalues[2396]),0},
1209{"id-alg-dh-sig-hmac-sha1","id-alg-dh-sig-hmac-sha1",
1210 NID_id_alg_dh_sig_hmac_sha1,8,&(lvalues[2404]),0},
1211{"id-alg-dh-pop","id-alg-dh-pop",NID_id_alg_dh_pop,8,&(lvalues[2412]),0},
1212{"id-cmc-statusInfo","id-cmc-statusInfo",NID_id_cmc_statusInfo,8,
1213 &(lvalues[2420]),0},
1214{"id-cmc-identification","id-cmc-identification",
1215 NID_id_cmc_identification,8,&(lvalues[2428]),0},
1216{"id-cmc-identityProof","id-cmc-identityProof",
1217 NID_id_cmc_identityProof,8,&(lvalues[2436]),0},
1218{"id-cmc-dataReturn","id-cmc-dataReturn",NID_id_cmc_dataReturn,8,
1219 &(lvalues[2444]),0},
1220{"id-cmc-transactionId","id-cmc-transactionId",
1221 NID_id_cmc_transactionId,8,&(lvalues[2452]),0},
1222{"id-cmc-senderNonce","id-cmc-senderNonce",NID_id_cmc_senderNonce,8,
1223 &(lvalues[2460]),0},
1224{"id-cmc-recipientNonce","id-cmc-recipientNonce",
1225 NID_id_cmc_recipientNonce,8,&(lvalues[2468]),0},
1226{"id-cmc-addExtensions","id-cmc-addExtensions",
1227 NID_id_cmc_addExtensions,8,&(lvalues[2476]),0},
1228{"id-cmc-encryptedPOP","id-cmc-encryptedPOP",NID_id_cmc_encryptedPOP,
1229 8,&(lvalues[2484]),0},
1230{"id-cmc-decryptedPOP","id-cmc-decryptedPOP",NID_id_cmc_decryptedPOP,
1231 8,&(lvalues[2492]),0},
1232{"id-cmc-lraPOPWitness","id-cmc-lraPOPWitness",
1233 NID_id_cmc_lraPOPWitness,8,&(lvalues[2500]),0},
1234{"id-cmc-getCert","id-cmc-getCert",NID_id_cmc_getCert,8,
1235 &(lvalues[2508]),0},
1236{"id-cmc-getCRL","id-cmc-getCRL",NID_id_cmc_getCRL,8,&(lvalues[2516]),0},
1237{"id-cmc-revokeRequest","id-cmc-revokeRequest",
1238 NID_id_cmc_revokeRequest,8,&(lvalues[2524]),0},
1239{"id-cmc-regInfo","id-cmc-regInfo",NID_id_cmc_regInfo,8,
1240 &(lvalues[2532]),0},
1241{"id-cmc-responseInfo","id-cmc-responseInfo",NID_id_cmc_responseInfo,
1242 8,&(lvalues[2540]),0},
1243{"id-cmc-queryPending","id-cmc-queryPending",NID_id_cmc_queryPending,
1244 8,&(lvalues[2548]),0},
1245{"id-cmc-popLinkRandom","id-cmc-popLinkRandom",
1246 NID_id_cmc_popLinkRandom,8,&(lvalues[2556]),0},
1247{"id-cmc-popLinkWitness","id-cmc-popLinkWitness",
1248 NID_id_cmc_popLinkWitness,8,&(lvalues[2564]),0},
1249{"id-cmc-confirmCertAcceptance","id-cmc-confirmCertAcceptance",
1250 NID_id_cmc_confirmCertAcceptance,8,&(lvalues[2572]),0},
1251{"id-on-personalData","id-on-personalData",NID_id_on_personalData,8,
1252 &(lvalues[2580]),0},
1253{"id-pda-dateOfBirth","id-pda-dateOfBirth",NID_id_pda_dateOfBirth,8,
1254 &(lvalues[2588]),0},
1255{"id-pda-placeOfBirth","id-pda-placeOfBirth",NID_id_pda_placeOfBirth,
1256 8,&(lvalues[2596]),0},
1257{NULL,NULL,NID_undef,0,NULL},
1258{"id-pda-gender","id-pda-gender",NID_id_pda_gender,8,&(lvalues[2604]),0},
1259{"id-pda-countryOfCitizenship","id-pda-countryOfCitizenship",
1260 NID_id_pda_countryOfCitizenship,8,&(lvalues[2612]),0},
1261{"id-pda-countryOfResidence","id-pda-countryOfResidence",
1262 NID_id_pda_countryOfResidence,8,&(lvalues[2620]),0},
1263{"id-aca-authenticationInfo","id-aca-authenticationInfo",
1264 NID_id_aca_authenticationInfo,8,&(lvalues[2628]),0},
1265{"id-aca-accessIdentity","id-aca-accessIdentity",
1266 NID_id_aca_accessIdentity,8,&(lvalues[2636]),0},
1267{"id-aca-chargingIdentity","id-aca-chargingIdentity",
1268 NID_id_aca_chargingIdentity,8,&(lvalues[2644]),0},
1269{"id-aca-group","id-aca-group",NID_id_aca_group,8,&(lvalues[2652]),0},
1270{"id-aca-role","id-aca-role",NID_id_aca_role,8,&(lvalues[2660]),0},
1271{"id-qcs-pkixQCSyntax-v1","id-qcs-pkixQCSyntax-v1",
1272 NID_id_qcs_pkixQCSyntax_v1,8,&(lvalues[2668]),0},
1273{"id-cct-crs","id-cct-crs",NID_id_cct_crs,8,&(lvalues[2676]),0},
1274{"id-cct-PKIData","id-cct-PKIData",NID_id_cct_PKIData,8,
1275 &(lvalues[2684]),0},
1276{"id-cct-PKIResponse","id-cct-PKIResponse",NID_id_cct_PKIResponse,8,
1277 &(lvalues[2692]),0},
1278{"ad_timestamping","AD Time Stamping",NID_ad_timeStamping,8,
1279 &(lvalues[2700]),0},
1280{"AD_DVCS","ad dvcs",NID_ad_dvcs,8,&(lvalues[2708]),0},
1281{"basicOCSPResponse","Basic OCSP Response",NID_id_pkix_OCSP_basic,9,
1282 &(lvalues[2716]),0},
1283{"Nonce","OCSP Nonce",NID_id_pkix_OCSP_Nonce,9,&(lvalues[2725]),0},
1284{"CrlID","OCSP CRL ID",NID_id_pkix_OCSP_CrlID,9,&(lvalues[2734]),0},
1285{"acceptableResponses","Acceptable OCSP Responses",
1286 NID_id_pkix_OCSP_acceptableResponses,9,&(lvalues[2743]),0},
1287{"noCheck","OCSP No Check",NID_id_pkix_OCSP_noCheck,9,&(lvalues[2752]),0},
1288{"archiveCutoff","OCSP Archive Cutoff",NID_id_pkix_OCSP_archiveCutoff,
1289 9,&(lvalues[2761]),0},
1290{"serviceLocator","OCSP Service Locator",
1291 NID_id_pkix_OCSP_serviceLocator,9,&(lvalues[2770]),0},
1292{"extendedStatus","Extended OCSP Status",
1293 NID_id_pkix_OCSP_extendedStatus,9,&(lvalues[2779]),0},
1294{"valid","valid",NID_id_pkix_OCSP_valid,9,&(lvalues[2788]),0},
1295{"path","path",NID_id_pkix_OCSP_path,9,&(lvalues[2797]),0},
1296{"trustRoot","Trust Root",NID_id_pkix_OCSP_trustRoot,9,
1297 &(lvalues[2806]),0},
1298{"algorithm","algorithm",NID_algorithm,4,&(lvalues[2815]),0},
1299{"rsaSignature","rsaSignature",NID_rsaSignature,5,&(lvalues[2819]),0},
1300{"X500algorithms","directory services - algorithms",
1301 NID_X500algorithms,2,&(lvalues[2824]),0},
1302{"ORG","org",NID_org,1,&(lvalues[2826]),0},
1303{"DOD","dod",NID_dod,2,&(lvalues[2827]),0},
1304{"IANA","iana",NID_iana,3,&(lvalues[2829]),0},
1305{"directory","Directory",NID_Directory,4,&(lvalues[2832]),0},
1306{"mgmt","Management",NID_Management,4,&(lvalues[2836]),0},
1307{"experimental","Experimental",NID_Experimental,4,&(lvalues[2840]),0},
1308{"private","Private",NID_Private,4,&(lvalues[2844]),0},
1309{"security","Security",NID_Security,4,&(lvalues[2848]),0},
1310{"snmpv2","SNMPv2",NID_SNMPv2,4,&(lvalues[2852]),0},
1311{"Mail","Mail",NID_Mail,4,&(lvalues[2856]),0},
1312{"enterprises","Enterprises",NID_Enterprises,5,&(lvalues[2860]),0},
1313{"dcobject","dcObject",NID_dcObject,9,&(lvalues[2865]),0},
1314{"DC","domainComponent",NID_domainComponent,10,&(lvalues[2874]),0},
1315{"domain","Domain",NID_Domain,10,&(lvalues[2884]),0},
1316{"JOINT-ISO-CCITT","joint-iso-ccitt",NID_joint_iso_ccitt,1,
1317 &(lvalues[2894]),0},
1318{"selected-attribute-types","Selected Attribute Types",
1319 NID_selected_attribute_types,3,&(lvalues[2895]),0},
1320{"clearance","clearance",NID_clearance,4,&(lvalues[2898]),0},
1321{"RSA-MD4","md4WithRSAEncryption",NID_md4WithRSAEncryption,9,
1322 &(lvalues[2902]),0},
1323{"ac-proxying","ac-proxying",NID_ac_proxying,8,&(lvalues[2911]),0},
1324{"subjectInfoAccess","Subject Information Access",NID_sinfo_access,8,
1325 &(lvalues[2919]),0},
1326{"id-aca-encAttrs","id-aca-encAttrs",NID_id_aca_encAttrs,8,
1327 &(lvalues[2927]),0},
1328{"role","role",NID_role,3,&(lvalues[2935]),0},
1329{"policyConstraints","X509v3 Policy Constraints",
1330 NID_policy_constraints,3,&(lvalues[2938]),0},
1331{"targetInformation","X509v3 AC Targeting",NID_target_information,3,
1332 &(lvalues[2941]),0},
1333{"noRevAvail","X509v3 No Revocation Available",NID_no_rev_avail,3,
1334 &(lvalues[2944]),0},
1335{"CCITT","ccitt",NID_ccitt,1,&(lvalues[2947]),0},
1336{"ansi-X9-62","ANSI X9.62",NID_ansi_X9_62,5,&(lvalues[2948]),0},
1337{"prime-field","prime-field",NID_X9_62_prime_field,7,&(lvalues[2953]),0},
1338{"characteristic-two-field","characteristic-two-field",
1339 NID_X9_62_characteristic_two_field,7,&(lvalues[2960]),0},
1340{"id-ecPublicKey","id-ecPublicKey",NID_X9_62_id_ecPublicKey,7,
1341 &(lvalues[2967]),0},
1342{"prime192v1","prime192v1",NID_X9_62_prime192v1,8,&(lvalues[2974]),0},
1343{"prime192v2","prime192v2",NID_X9_62_prime192v2,8,&(lvalues[2982]),0},
1344{"prime192v3","prime192v3",NID_X9_62_prime192v3,8,&(lvalues[2990]),0},
1345{"prime239v1","prime239v1",NID_X9_62_prime239v1,8,&(lvalues[2998]),0},
1346{"prime239v2","prime239v2",NID_X9_62_prime239v2,8,&(lvalues[3006]),0},
1347{"prime239v3","prime239v3",NID_X9_62_prime239v3,8,&(lvalues[3014]),0},
1348{"prime256v1","prime256v1",NID_X9_62_prime256v1,8,&(lvalues[3022]),0},
1349{"ecdsa-with-SHA1","ecdsa-with-SHA1",NID_ecdsa_with_SHA1,7,
1350 &(lvalues[3030]),0},
1351{"CSPName","Microsoft CSP Name",NID_ms_csp_name,9,&(lvalues[3037]),0},
1352{"AES-128-ECB","aes-128-ecb",NID_aes_128_ecb,9,&(lvalues[3046]),0},
1353{"AES-128-CBC","aes-128-cbc",NID_aes_128_cbc,9,&(lvalues[3055]),0},
1354{"AES-128-OFB","aes-128-ofb",NID_aes_128_ofb128,9,&(lvalues[3064]),0},
1355{"AES-128-CFB","aes-128-cfb",NID_aes_128_cfb128,9,&(lvalues[3073]),0},
1356{"AES-192-ECB","aes-192-ecb",NID_aes_192_ecb,9,&(lvalues[3082]),0},
1357{"AES-192-CBC","aes-192-cbc",NID_aes_192_cbc,9,&(lvalues[3091]),0},
1358{"AES-192-OFB","aes-192-ofb",NID_aes_192_ofb128,9,&(lvalues[3100]),0},
1359{"AES-192-CFB","aes-192-cfb",NID_aes_192_cfb128,9,&(lvalues[3109]),0},
1360{"AES-256-ECB","aes-256-ecb",NID_aes_256_ecb,9,&(lvalues[3118]),0},
1361{"AES-256-CBC","aes-256-cbc",NID_aes_256_cbc,9,&(lvalues[3127]),0},
1362{"AES-256-OFB","aes-256-ofb",NID_aes_256_ofb128,9,&(lvalues[3136]),0},
1363{"AES-256-CFB","aes-256-cfb",NID_aes_256_cfb128,9,&(lvalues[3145]),0},
1364{"holdInstructionCode","Hold Instruction Code",
1365 NID_hold_instruction_code,3,&(lvalues[3154]),0},
1366{"holdInstructionNone","Hold Instruction None",
1367 NID_hold_instruction_none,7,&(lvalues[3157]),0},
1368{"holdInstructionCallIssuer","Hold Instruction Call Issuer",
1369 NID_hold_instruction_call_issuer,7,&(lvalues[3164]),0},
1370{"holdInstructionReject","Hold Instruction Reject",
1371 NID_hold_instruction_reject,7,&(lvalues[3171]),0},
1372{"data","data",NID_data,1,&(lvalues[3178]),0},
1373{"pss","pss",NID_pss,3,&(lvalues[3179]),0},
1374{"ucl","ucl",NID_ucl,7,&(lvalues[3182]),0},
1375{"pilot","pilot",NID_pilot,8,&(lvalues[3189]),0},
1376{"pilotAttributeType","pilotAttributeType",NID_pilotAttributeType,9,
1377 &(lvalues[3197]),0},
1378{"pilotAttributeSyntax","pilotAttributeSyntax",
1379 NID_pilotAttributeSyntax,9,&(lvalues[3206]),0},
1380{"pilotObjectClass","pilotObjectClass",NID_pilotObjectClass,9,
1381 &(lvalues[3215]),0},
1382{"pilotGroups","pilotGroups",NID_pilotGroups,9,&(lvalues[3224]),0},
1383{"iA5StringSyntax","iA5StringSyntax",NID_iA5StringSyntax,10,
1384 &(lvalues[3233]),0},
1385{"caseIgnoreIA5StringSyntax","caseIgnoreIA5StringSyntax",
1386 NID_caseIgnoreIA5StringSyntax,10,&(lvalues[3243]),0},
1387{"pilotObject","pilotObject",NID_pilotObject,10,&(lvalues[3253]),0},
1388{"pilotPerson","pilotPerson",NID_pilotPerson,10,&(lvalues[3263]),0},
1389{"account","account",NID_account,10,&(lvalues[3273]),0},
1390{"document","document",NID_document,10,&(lvalues[3283]),0},
1391{"room","room",NID_room,10,&(lvalues[3293]),0},
1392{"documentSeries","documentSeries",NID_documentSeries,10,
1393 &(lvalues[3303]),0},
1394{"rFC822localPart","rFC822localPart",NID_rFC822localPart,10,
1395 &(lvalues[3313]),0},
1396{"dNSDomain","dNSDomain",NID_dNSDomain,10,&(lvalues[3323]),0},
1397{"domainRelatedObject","domainRelatedObject",NID_domainRelatedObject,
1398 10,&(lvalues[3333]),0},
1399{"friendlyCountry","friendlyCountry",NID_friendlyCountry,10,
1400 &(lvalues[3343]),0},
1401{"simpleSecurityObject","simpleSecurityObject",
1402 NID_simpleSecurityObject,10,&(lvalues[3353]),0},
1403{"pilotOrganization","pilotOrganization",NID_pilotOrganization,10,
1404 &(lvalues[3363]),0},
1405{"pilotDSA","pilotDSA",NID_pilotDSA,10,&(lvalues[3373]),0},
1406{"qualityLabelledData","qualityLabelledData",NID_qualityLabelledData,
1407 10,&(lvalues[3383]),0},
1408{"UID","userId",NID_userId,10,&(lvalues[3393]),0},
1409{"textEncodedORAddress","textEncodedORAddress",
1410 NID_textEncodedORAddress,10,&(lvalues[3403]),0},
1411{"mail","rfc822Mailbox",NID_rfc822Mailbox,10,&(lvalues[3413]),0},
1412{"info","info",NID_info,10,&(lvalues[3423]),0},
1413{"favouriteDrink","favouriteDrink",NID_favouriteDrink,10,
1414 &(lvalues[3433]),0},
1415{"roomNumber","roomNumber",NID_roomNumber,10,&(lvalues[3443]),0},
1416{"photo","photo",NID_photo,10,&(lvalues[3453]),0},
1417{"userClass","userClass",NID_userClass,10,&(lvalues[3463]),0},
1418{"host","host",NID_host,10,&(lvalues[3473]),0},
1419{"manager","manager",NID_manager,10,&(lvalues[3483]),0},
1420{"documentIdentifier","documentIdentifier",NID_documentIdentifier,10,
1421 &(lvalues[3493]),0},
1422{"documentTitle","documentTitle",NID_documentTitle,10,&(lvalues[3503]),0},
1423{"documentVersion","documentVersion",NID_documentVersion,10,
1424 &(lvalues[3513]),0},
1425{"documentAuthor","documentAuthor",NID_documentAuthor,10,
1426 &(lvalues[3523]),0},
1427{"documentLocation","documentLocation",NID_documentLocation,10,
1428 &(lvalues[3533]),0},
1429{"homeTelephoneNumber","homeTelephoneNumber",NID_homeTelephoneNumber,
1430 10,&(lvalues[3543]),0},
1431{"secretary","secretary",NID_secretary,10,&(lvalues[3553]),0},
1432{"otherMailbox","otherMailbox",NID_otherMailbox,10,&(lvalues[3563]),0},
1433{"lastModifiedTime","lastModifiedTime",NID_lastModifiedTime,10,
1434 &(lvalues[3573]),0},
1435{"lastModifiedBy","lastModifiedBy",NID_lastModifiedBy,10,
1436 &(lvalues[3583]),0},
1437{"aRecord","aRecord",NID_aRecord,10,&(lvalues[3593]),0},
1438{"pilotAttributeType27","pilotAttributeType27",
1439 NID_pilotAttributeType27,10,&(lvalues[3603]),0},
1440{"mXRecord","mXRecord",NID_mXRecord,10,&(lvalues[3613]),0},
1441{"nSRecord","nSRecord",NID_nSRecord,10,&(lvalues[3623]),0},
1442{"sOARecord","sOARecord",NID_sOARecord,10,&(lvalues[3633]),0},
1443{"cNAMERecord","cNAMERecord",NID_cNAMERecord,10,&(lvalues[3643]),0},
1444{"associatedDomain","associatedDomain",NID_associatedDomain,10,
1445 &(lvalues[3653]),0},
1446{"associatedName","associatedName",NID_associatedName,10,
1447 &(lvalues[3663]),0},
1448{"homePostalAddress","homePostalAddress",NID_homePostalAddress,10,
1449 &(lvalues[3673]),0},
1450{"personalTitle","personalTitle",NID_personalTitle,10,&(lvalues[3683]),0},
1451{"mobileTelephoneNumber","mobileTelephoneNumber",
1452 NID_mobileTelephoneNumber,10,&(lvalues[3693]),0},
1453{"pagerTelephoneNumber","pagerTelephoneNumber",
1454 NID_pagerTelephoneNumber,10,&(lvalues[3703]),0},
1455{"friendlyCountryName","friendlyCountryName",NID_friendlyCountryName,
1456 10,&(lvalues[3713]),0},
1457{"organizationalStatus","organizationalStatus",
1458 NID_organizationalStatus,10,&(lvalues[3723]),0},
1459{"janetMailbox","janetMailbox",NID_janetMailbox,10,&(lvalues[3733]),0},
1460{"mailPreferenceOption","mailPreferenceOption",
1461 NID_mailPreferenceOption,10,&(lvalues[3743]),0},
1462{"buildingName","buildingName",NID_buildingName,10,&(lvalues[3753]),0},
1463{"dSAQuality","dSAQuality",NID_dSAQuality,10,&(lvalues[3763]),0},
1464{"singleLevelQuality","singleLevelQuality",NID_singleLevelQuality,10,
1465 &(lvalues[3773]),0},
1466{"subtreeMinimumQuality","subtreeMinimumQuality",
1467 NID_subtreeMinimumQuality,10,&(lvalues[3783]),0},
1468{"subtreeMaximumQuality","subtreeMaximumQuality",
1469 NID_subtreeMaximumQuality,10,&(lvalues[3793]),0},
1470{"personalSignature","personalSignature",NID_personalSignature,10,
1471 &(lvalues[3803]),0},
1472{"dITRedirect","dITRedirect",NID_dITRedirect,10,&(lvalues[3813]),0},
1473{"audio","audio",NID_audio,10,&(lvalues[3823]),0},
1474{"documentPublisher","documentPublisher",NID_documentPublisher,10,
1475 &(lvalues[3833]),0},
1476{"x500UniqueIdentifier","x500UniqueIdentifier",
1477 NID_x500UniqueIdentifier,3,&(lvalues[3843]),0},
1478{"mime-mhs","MIME MHS",NID_mime_mhs,5,&(lvalues[3846]),0},
1479{"mime-mhs-headings","mime-mhs-headings",NID_mime_mhs_headings,6,
1480 &(lvalues[3851]),0},
1481{"mime-mhs-bodies","mime-mhs-bodies",NID_mime_mhs_bodies,6,
1482 &(lvalues[3857]),0},
1483{"id-hex-partial-message","id-hex-partial-message",
1484 NID_id_hex_partial_message,7,&(lvalues[3863]),0},
1485{"id-hex-multipart-message","id-hex-multipart-message",
1486 NID_id_hex_multipart_message,7,&(lvalues[3870]),0},
1487{"generationQualifier","generationQualifier",NID_generationQualifier,
1488 3,&(lvalues[3877]),0},
1489{"pseudonym","pseudonym",NID_pseudonym,3,&(lvalues[3880]),0},
1490{NULL,NULL,NID_undef,0,NULL},
1491{"id-set","Secure Electronic Transactions",NID_id_set,2,
1492 &(lvalues[3883]),0},
1493{"set-ctype","content types",NID_set_ctype,3,&(lvalues[3885]),0},
1494{"set-msgExt","message extensions",NID_set_msgExt,3,&(lvalues[3888]),0},
1495{"set-attr","set-attr",NID_set_attr,3,&(lvalues[3891]),0},
1496{"set-policy","set-policy",NID_set_policy,3,&(lvalues[3894]),0},
1497{"set-certExt","certificate extensions",NID_set_certExt,3,
1498 &(lvalues[3897]),0},
1499{"set-brand","set-brand",NID_set_brand,3,&(lvalues[3900]),0},
1500{"setct-PANData","setct-PANData",NID_setct_PANData,4,&(lvalues[3903]),0},
1501{"setct-PANToken","setct-PANToken",NID_setct_PANToken,4,
1502 &(lvalues[3907]),0},
1503{"setct-PANOnly","setct-PANOnly",NID_setct_PANOnly,4,&(lvalues[3911]),0},
1504{"setct-OIData","setct-OIData",NID_setct_OIData,4,&(lvalues[3915]),0},
1505{"setct-PI","setct-PI",NID_setct_PI,4,&(lvalues[3919]),0},
1506{"setct-PIData","setct-PIData",NID_setct_PIData,4,&(lvalues[3923]),0},
1507{"setct-PIDataUnsigned","setct-PIDataUnsigned",
1508 NID_setct_PIDataUnsigned,4,&(lvalues[3927]),0},
1509{"setct-HODInput","setct-HODInput",NID_setct_HODInput,4,
1510 &(lvalues[3931]),0},
1511{"setct-AuthResBaggage","setct-AuthResBaggage",
1512 NID_setct_AuthResBaggage,4,&(lvalues[3935]),0},
1513{"setct-AuthRevReqBaggage","setct-AuthRevReqBaggage",
1514 NID_setct_AuthRevReqBaggage,4,&(lvalues[3939]),0},
1515{"setct-AuthRevResBaggage","setct-AuthRevResBaggage",
1516 NID_setct_AuthRevResBaggage,4,&(lvalues[3943]),0},
1517{"setct-CapTokenSeq","setct-CapTokenSeq",NID_setct_CapTokenSeq,4,
1518 &(lvalues[3947]),0},
1519{"setct-PInitResData","setct-PInitResData",NID_setct_PInitResData,4,
1520 &(lvalues[3951]),0},
1521{"setct-PI-TBS","setct-PI-TBS",NID_setct_PI_TBS,4,&(lvalues[3955]),0},
1522{"setct-PResData","setct-PResData",NID_setct_PResData,4,
1523 &(lvalues[3959]),0},
1524{"setct-AuthReqTBS","setct-AuthReqTBS",NID_setct_AuthReqTBS,4,
1525 &(lvalues[3963]),0},
1526{"setct-AuthResTBS","setct-AuthResTBS",NID_setct_AuthResTBS,4,
1527 &(lvalues[3967]),0},
1528{"setct-AuthResTBSX","setct-AuthResTBSX",NID_setct_AuthResTBSX,4,
1529 &(lvalues[3971]),0},
1530{"setct-AuthTokenTBS","setct-AuthTokenTBS",NID_setct_AuthTokenTBS,4,
1531 &(lvalues[3975]),0},
1532{"setct-CapTokenData","setct-CapTokenData",NID_setct_CapTokenData,4,
1533 &(lvalues[3979]),0},
1534{"setct-CapTokenTBS","setct-CapTokenTBS",NID_setct_CapTokenTBS,4,
1535 &(lvalues[3983]),0},
1536{"setct-AcqCardCodeMsg","setct-AcqCardCodeMsg",
1537 NID_setct_AcqCardCodeMsg,4,&(lvalues[3987]),0},
1538{"setct-AuthRevReqTBS","setct-AuthRevReqTBS",NID_setct_AuthRevReqTBS,
1539 4,&(lvalues[3991]),0},
1540{"setct-AuthRevResData","setct-AuthRevResData",
1541 NID_setct_AuthRevResData,4,&(lvalues[3995]),0},
1542{"setct-AuthRevResTBS","setct-AuthRevResTBS",NID_setct_AuthRevResTBS,
1543 4,&(lvalues[3999]),0},
1544{"setct-CapReqTBS","setct-CapReqTBS",NID_setct_CapReqTBS,4,
1545 &(lvalues[4003]),0},
1546{"setct-CapReqTBSX","setct-CapReqTBSX",NID_setct_CapReqTBSX,4,
1547 &(lvalues[4007]),0},
1548{"setct-CapResData","setct-CapResData",NID_setct_CapResData,4,
1549 &(lvalues[4011]),0},
1550{"setct-CapRevReqTBS","setct-CapRevReqTBS",NID_setct_CapRevReqTBS,4,
1551 &(lvalues[4015]),0},
1552{"setct-CapRevReqTBSX","setct-CapRevReqTBSX",NID_setct_CapRevReqTBSX,
1553 4,&(lvalues[4019]),0},
1554{"setct-CapRevResData","setct-CapRevResData",NID_setct_CapRevResData,
1555 4,&(lvalues[4023]),0},
1556{"setct-CredReqTBS","setct-CredReqTBS",NID_setct_CredReqTBS,4,
1557 &(lvalues[4027]),0},
1558{"setct-CredReqTBSX","setct-CredReqTBSX",NID_setct_CredReqTBSX,4,
1559 &(lvalues[4031]),0},
1560{"setct-CredResData","setct-CredResData",NID_setct_CredResData,4,
1561 &(lvalues[4035]),0},
1562{"setct-CredRevReqTBS","setct-CredRevReqTBS",NID_setct_CredRevReqTBS,
1563 4,&(lvalues[4039]),0},
1564{"setct-CredRevReqTBSX","setct-CredRevReqTBSX",
1565 NID_setct_CredRevReqTBSX,4,&(lvalues[4043]),0},
1566{"setct-CredRevResData","setct-CredRevResData",
1567 NID_setct_CredRevResData,4,&(lvalues[4047]),0},
1568{"setct-PCertReqData","setct-PCertReqData",NID_setct_PCertReqData,4,
1569 &(lvalues[4051]),0},
1570{"setct-PCertResTBS","setct-PCertResTBS",NID_setct_PCertResTBS,4,
1571 &(lvalues[4055]),0},
1572{"setct-BatchAdminReqData","setct-BatchAdminReqData",
1573 NID_setct_BatchAdminReqData,4,&(lvalues[4059]),0},
1574{"setct-BatchAdminResData","setct-BatchAdminResData",
1575 NID_setct_BatchAdminResData,4,&(lvalues[4063]),0},
1576{"setct-CardCInitResTBS","setct-CardCInitResTBS",
1577 NID_setct_CardCInitResTBS,4,&(lvalues[4067]),0},
1578{"setct-MeAqCInitResTBS","setct-MeAqCInitResTBS",
1579 NID_setct_MeAqCInitResTBS,4,&(lvalues[4071]),0},
1580{"setct-RegFormResTBS","setct-RegFormResTBS",NID_setct_RegFormResTBS,
1581 4,&(lvalues[4075]),0},
1582{"setct-CertReqData","setct-CertReqData",NID_setct_CertReqData,4,
1583 &(lvalues[4079]),0},
1584{"setct-CertReqTBS","setct-CertReqTBS",NID_setct_CertReqTBS,4,
1585 &(lvalues[4083]),0},
1586{"setct-CertResData","setct-CertResData",NID_setct_CertResData,4,
1587 &(lvalues[4087]),0},
1588{"setct-CertInqReqTBS","setct-CertInqReqTBS",NID_setct_CertInqReqTBS,
1589 4,&(lvalues[4091]),0},
1590{"setct-ErrorTBS","setct-ErrorTBS",NID_setct_ErrorTBS,4,
1591 &(lvalues[4095]),0},
1592{"setct-PIDualSignedTBE","setct-PIDualSignedTBE",
1593 NID_setct_PIDualSignedTBE,4,&(lvalues[4099]),0},
1594{"setct-PIUnsignedTBE","setct-PIUnsignedTBE",NID_setct_PIUnsignedTBE,
1595 4,&(lvalues[4103]),0},
1596{"setct-AuthReqTBE","setct-AuthReqTBE",NID_setct_AuthReqTBE,4,
1597 &(lvalues[4107]),0},
1598{"setct-AuthResTBE","setct-AuthResTBE",NID_setct_AuthResTBE,4,
1599 &(lvalues[4111]),0},
1600{"setct-AuthResTBEX","setct-AuthResTBEX",NID_setct_AuthResTBEX,4,
1601 &(lvalues[4115]),0},
1602{"setct-AuthTokenTBE","setct-AuthTokenTBE",NID_setct_AuthTokenTBE,4,
1603 &(lvalues[4119]),0},
1604{"setct-CapTokenTBE","setct-CapTokenTBE",NID_setct_CapTokenTBE,4,
1605 &(lvalues[4123]),0},
1606{"setct-CapTokenTBEX","setct-CapTokenTBEX",NID_setct_CapTokenTBEX,4,
1607 &(lvalues[4127]),0},
1608{"setct-AcqCardCodeMsgTBE","setct-AcqCardCodeMsgTBE",
1609 NID_setct_AcqCardCodeMsgTBE,4,&(lvalues[4131]),0},
1610{"setct-AuthRevReqTBE","setct-AuthRevReqTBE",NID_setct_AuthRevReqTBE,
1611 4,&(lvalues[4135]),0},
1612{"setct-AuthRevResTBE","setct-AuthRevResTBE",NID_setct_AuthRevResTBE,
1613 4,&(lvalues[4139]),0},
1614{"setct-AuthRevResTBEB","setct-AuthRevResTBEB",
1615 NID_setct_AuthRevResTBEB,4,&(lvalues[4143]),0},
1616{"setct-CapReqTBE","setct-CapReqTBE",NID_setct_CapReqTBE,4,
1617 &(lvalues[4147]),0},
1618{"setct-CapReqTBEX","setct-CapReqTBEX",NID_setct_CapReqTBEX,4,
1619 &(lvalues[4151]),0},
1620{"setct-CapResTBE","setct-CapResTBE",NID_setct_CapResTBE,4,
1621 &(lvalues[4155]),0},
1622{"setct-CapRevReqTBE","setct-CapRevReqTBE",NID_setct_CapRevReqTBE,4,
1623 &(lvalues[4159]),0},
1624{"setct-CapRevReqTBEX","setct-CapRevReqTBEX",NID_setct_CapRevReqTBEX,
1625 4,&(lvalues[4163]),0},
1626{"setct-CapRevResTBE","setct-CapRevResTBE",NID_setct_CapRevResTBE,4,
1627 &(lvalues[4167]),0},
1628{"setct-CredReqTBE","setct-CredReqTBE",NID_setct_CredReqTBE,4,
1629 &(lvalues[4171]),0},
1630{"setct-CredReqTBEX","setct-CredReqTBEX",NID_setct_CredReqTBEX,4,
1631 &(lvalues[4175]),0},
1632{"setct-CredResTBE","setct-CredResTBE",NID_setct_CredResTBE,4,
1633 &(lvalues[4179]),0},
1634{"setct-CredRevReqTBE","setct-CredRevReqTBE",NID_setct_CredRevReqTBE,
1635 4,&(lvalues[4183]),0},
1636{"setct-CredRevReqTBEX","setct-CredRevReqTBEX",
1637 NID_setct_CredRevReqTBEX,4,&(lvalues[4187]),0},
1638{"setct-CredRevResTBE","setct-CredRevResTBE",NID_setct_CredRevResTBE,
1639 4,&(lvalues[4191]),0},
1640{"setct-BatchAdminReqTBE","setct-BatchAdminReqTBE",
1641 NID_setct_BatchAdminReqTBE,4,&(lvalues[4195]),0},
1642{"setct-BatchAdminResTBE","setct-BatchAdminResTBE",
1643 NID_setct_BatchAdminResTBE,4,&(lvalues[4199]),0},
1644{"setct-RegFormReqTBE","setct-RegFormReqTBE",NID_setct_RegFormReqTBE,
1645 4,&(lvalues[4203]),0},
1646{"setct-CertReqTBE","setct-CertReqTBE",NID_setct_CertReqTBE,4,
1647 &(lvalues[4207]),0},
1648{"setct-CertReqTBEX","setct-CertReqTBEX",NID_setct_CertReqTBEX,4,
1649 &(lvalues[4211]),0},
1650{"setct-CertResTBE","setct-CertResTBE",NID_setct_CertResTBE,4,
1651 &(lvalues[4215]),0},
1652{"setct-CRLNotificationTBS","setct-CRLNotificationTBS",
1653 NID_setct_CRLNotificationTBS,4,&(lvalues[4219]),0},
1654{"setct-CRLNotificationResTBS","setct-CRLNotificationResTBS",
1655 NID_setct_CRLNotificationResTBS,4,&(lvalues[4223]),0},
1656{"setct-BCIDistributionTBS","setct-BCIDistributionTBS",
1657 NID_setct_BCIDistributionTBS,4,&(lvalues[4227]),0},
1658{"setext-genCrypt","generic cryptogram",NID_setext_genCrypt,4,
1659 &(lvalues[4231]),0},
1660{"setext-miAuth","merchant initiated auth",NID_setext_miAuth,4,
1661 &(lvalues[4235]),0},
1662{"setext-pinSecure","setext-pinSecure",NID_setext_pinSecure,4,
1663 &(lvalues[4239]),0},
1664{"setext-pinAny","setext-pinAny",NID_setext_pinAny,4,&(lvalues[4243]),0},
1665{"setext-track2","setext-track2",NID_setext_track2,4,&(lvalues[4247]),0},
1666{"setext-cv","additional verification",NID_setext_cv,4,
1667 &(lvalues[4251]),0},
1668{"set-policy-root","set-policy-root",NID_set_policy_root,4,
1669 &(lvalues[4255]),0},
1670{"setCext-hashedRoot","setCext-hashedRoot",NID_setCext_hashedRoot,4,
1671 &(lvalues[4259]),0},
1672{"setCext-certType","setCext-certType",NID_setCext_certType,4,
1673 &(lvalues[4263]),0},
1674{"setCext-merchData","setCext-merchData",NID_setCext_merchData,4,
1675 &(lvalues[4267]),0},
1676{"setCext-cCertRequired","setCext-cCertRequired",
1677 NID_setCext_cCertRequired,4,&(lvalues[4271]),0},
1678{"setCext-tunneling","setCext-tunneling",NID_setCext_tunneling,4,
1679 &(lvalues[4275]),0},
1680{"setCext-setExt","setCext-setExt",NID_setCext_setExt,4,
1681 &(lvalues[4279]),0},
1682{"setCext-setQualf","setCext-setQualf",NID_setCext_setQualf,4,
1683 &(lvalues[4283]),0},
1684{"setCext-PGWYcapabilities","setCext-PGWYcapabilities",
1685 NID_setCext_PGWYcapabilities,4,&(lvalues[4287]),0},
1686{"setCext-TokenIdentifier","setCext-TokenIdentifier",
1687 NID_setCext_TokenIdentifier,4,&(lvalues[4291]),0},
1688{"setCext-Track2Data","setCext-Track2Data",NID_setCext_Track2Data,4,
1689 &(lvalues[4295]),0},
1690{"setCext-TokenType","setCext-TokenType",NID_setCext_TokenType,4,
1691 &(lvalues[4299]),0},
1692{"setCext-IssuerCapabilities","setCext-IssuerCapabilities",
1693 NID_setCext_IssuerCapabilities,4,&(lvalues[4303]),0},
1694{"setAttr-Cert","setAttr-Cert",NID_setAttr_Cert,4,&(lvalues[4307]),0},
1695{"setAttr-PGWYcap","payment gateway capabilities",NID_setAttr_PGWYcap,
1696 4,&(lvalues[4311]),0},
1697{"setAttr-TokenType","setAttr-TokenType",NID_setAttr_TokenType,4,
1698 &(lvalues[4315]),0},
1699{"setAttr-IssCap","issuer capabilities",NID_setAttr_IssCap,4,
1700 &(lvalues[4319]),0},
1701{"set-rootKeyThumb","set-rootKeyThumb",NID_set_rootKeyThumb,5,
1702 &(lvalues[4323]),0},
1703{"set-addPolicy","set-addPolicy",NID_set_addPolicy,5,&(lvalues[4328]),0},
1704{"setAttr-Token-EMV","setAttr-Token-EMV",NID_setAttr_Token_EMV,5,
1705 &(lvalues[4333]),0},
1706{"setAttr-Token-B0Prime","setAttr-Token-B0Prime",
1707 NID_setAttr_Token_B0Prime,5,&(lvalues[4338]),0},
1708{"setAttr-IssCap-CVM","setAttr-IssCap-CVM",NID_setAttr_IssCap_CVM,5,
1709 &(lvalues[4343]),0},
1710{"setAttr-IssCap-T2","setAttr-IssCap-T2",NID_setAttr_IssCap_T2,5,
1711 &(lvalues[4348]),0},
1712{"setAttr-IssCap-Sig","setAttr-IssCap-Sig",NID_setAttr_IssCap_Sig,5,
1713 &(lvalues[4353]),0},
1714{"setAttr-GenCryptgrm","generate cryptogram",NID_setAttr_GenCryptgrm,
1715 6,&(lvalues[4358]),0},
1716{"setAttr-T2Enc","encrypted track 2",NID_setAttr_T2Enc,6,
1717 &(lvalues[4364]),0},
1718{"setAttr-T2cleartxt","cleartext track 2",NID_setAttr_T2cleartxt,6,
1719 &(lvalues[4370]),0},
1720{"setAttr-TokICCsig","ICC or token signature",NID_setAttr_TokICCsig,6,
1721 &(lvalues[4376]),0},
1722{"setAttr-SecDevSig","secure device signature",NID_setAttr_SecDevSig,
1723 6,&(lvalues[4382]),0},
1724{"set-brand-IATA-ATA","set-brand-IATA-ATA",NID_set_brand_IATA_ATA,4,
1725 &(lvalues[4388]),0},
1726{"set-brand-Diners","set-brand-Diners",NID_set_brand_Diners,4,
1727 &(lvalues[4392]),0},
1728{"set-brand-AmericanExpress","set-brand-AmericanExpress",
1729 NID_set_brand_AmericanExpress,4,&(lvalues[4396]),0},
1730{"set-brand-JCB","set-brand-JCB",NID_set_brand_JCB,4,&(lvalues[4400]),0},
1731{"set-brand-Visa","set-brand-Visa",NID_set_brand_Visa,4,
1732 &(lvalues[4404]),0},
1733{"set-brand-MasterCard","set-brand-MasterCard",
1734 NID_set_brand_MasterCard,4,&(lvalues[4408]),0},
1735{"set-brand-Novus","set-brand-Novus",NID_set_brand_Novus,5,
1736 &(lvalues[4412]),0},
1737{"DES-CDMF","des-cdmf",NID_des_cdmf,8,&(lvalues[4417]),0},
1738{"rsaOAEPEncryptionSET","rsaOAEPEncryptionSET",
1739 NID_rsaOAEPEncryptionSET,9,&(lvalues[4425]),0},
1740{NULL,NULL,NID_undef,0,NULL},
1741{NULL,NULL,NID_undef,0,NULL},
1742{NULL,NULL,NID_undef,0,NULL},
1743{"msSmartcardLogin","Microsoft Smartcardlogin",NID_ms_smartcard_login,
1744 10,&(lvalues[4434]),0},
1745{"msUPN","Microsoft Universal Principal Name",NID_ms_upn,10,
1746 &(lvalues[4444]),0},
1747{"AES-128-CFB1","aes-128-cfb1",NID_aes_128_cfb1,0,NULL},
1748{"AES-192-CFB1","aes-192-cfb1",NID_aes_192_cfb1,0,NULL},
1749{"AES-256-CFB1","aes-256-cfb1",NID_aes_256_cfb1,0,NULL},
1750{"AES-128-CFB8","aes-128-cfb8",NID_aes_128_cfb8,0,NULL},
1751{"AES-192-CFB8","aes-192-cfb8",NID_aes_192_cfb8,0,NULL},
1752{"AES-256-CFB8","aes-256-cfb8",NID_aes_256_cfb8,0,NULL},
1753{"DES-CFB1","des-cfb1",NID_des_cfb1,0,NULL},
1754{"DES-CFB8","des-cfb8",NID_des_cfb8,0,NULL},
1755{"DES-EDE3-CFB1","des-ede3-cfb1",NID_des_ede3_cfb1,0,NULL},
1756{"DES-EDE3-CFB8","des-ede3-cfb8",NID_des_ede3_cfb8,0,NULL},
1757{"streetAddress","streetAddress",NID_streetAddress,3,&(lvalues[4454]),0},
1758{"postalCode","postalCode",NID_postalCode,3,&(lvalues[4457]),0},
1759{"id-ppl","id-ppl",NID_id_ppl,7,&(lvalues[4460]),0},
1760{"proxyCertInfo","Proxy Certificate Information",NID_proxyCertInfo,8,
1761 &(lvalues[4467]),0},
1762{"id-ppl-anyLanguage","Any language",NID_id_ppl_anyLanguage,8,
1763 &(lvalues[4475]),0},
1764{"id-ppl-inheritAll","Inherit all",NID_id_ppl_inheritAll,8,
1765 &(lvalues[4483]),0},
1766{"nameConstraints","X509v3 Name Constraints",NID_name_constraints,3,
1767 &(lvalues[4491]),0},
1768{"id-ppl-independent","Independent",NID_Independent,8,&(lvalues[4494]),0},
1769{"RSA-SHA256","sha256WithRSAEncryption",NID_sha256WithRSAEncryption,9,
1770 &(lvalues[4502]),0},
1771{"RSA-SHA384","sha384WithRSAEncryption",NID_sha384WithRSAEncryption,9,
1772 &(lvalues[4511]),0},
1773{"RSA-SHA512","sha512WithRSAEncryption",NID_sha512WithRSAEncryption,9,
1774 &(lvalues[4520]),0},
1775{"RSA-SHA224","sha224WithRSAEncryption",NID_sha224WithRSAEncryption,9,
1776 &(lvalues[4529]),0},
1777{"SHA256","sha256",NID_sha256,9,&(lvalues[4538]),0},
1778{"SHA384","sha384",NID_sha384,9,&(lvalues[4547]),0},
1779{"SHA512","sha512",NID_sha512,9,&(lvalues[4556]),0},
1780{"SHA224","sha224",NID_sha224,9,&(lvalues[4565]),0},
1781};
1782
1783static ASN1_OBJECT *sn_objs[NUM_SN]={
1784&(nid_objs[364]),/* "AD_DVCS" */
1785&(nid_objs[419]),/* "AES-128-CBC" */
1786&(nid_objs[421]),/* "AES-128-CFB" */
1787&(nid_objs[650]),/* "AES-128-CFB1" */
1788&(nid_objs[653]),/* "AES-128-CFB8" */
1789&(nid_objs[418]),/* "AES-128-ECB" */
1790&(nid_objs[420]),/* "AES-128-OFB" */
1791&(nid_objs[423]),/* "AES-192-CBC" */
1792&(nid_objs[425]),/* "AES-192-CFB" */
1793&(nid_objs[651]),/* "AES-192-CFB1" */
1794&(nid_objs[654]),/* "AES-192-CFB8" */
1795&(nid_objs[422]),/* "AES-192-ECB" */
1796&(nid_objs[424]),/* "AES-192-OFB" */
1797&(nid_objs[427]),/* "AES-256-CBC" */
1798&(nid_objs[429]),/* "AES-256-CFB" */
1799&(nid_objs[652]),/* "AES-256-CFB1" */
1800&(nid_objs[655]),/* "AES-256-CFB8" */
1801&(nid_objs[426]),/* "AES-256-ECB" */
1802&(nid_objs[428]),/* "AES-256-OFB" */
1803&(nid_objs[91]),/* "BF-CBC" */
1804&(nid_objs[93]),/* "BF-CFB" */
1805&(nid_objs[92]),/* "BF-ECB" */
1806&(nid_objs[94]),/* "BF-OFB" */
1807&(nid_objs[14]),/* "C" */
1808&(nid_objs[108]),/* "CAST5-CBC" */
1809&(nid_objs[110]),/* "CAST5-CFB" */
1810&(nid_objs[109]),/* "CAST5-ECB" */
1811&(nid_objs[111]),/* "CAST5-OFB" */
1812&(nid_objs[404]),/* "CCITT" */
1813&(nid_objs[13]),/* "CN" */
1814&(nid_objs[141]),/* "CRLReason" */
1815&(nid_objs[417]),/* "CSPName" */
1816&(nid_objs[367]),/* "CrlID" */
1817&(nid_objs[391]),/* "DC" */
1818&(nid_objs[31]),/* "DES-CBC" */
1819&(nid_objs[643]),/* "DES-CDMF" */
1820&(nid_objs[30]),/* "DES-CFB" */
1821&(nid_objs[656]),/* "DES-CFB1" */
1822&(nid_objs[657]),/* "DES-CFB8" */
1823&(nid_objs[29]),/* "DES-ECB" */
1824&(nid_objs[32]),/* "DES-EDE" */
1825&(nid_objs[43]),/* "DES-EDE-CBC" */
1826&(nid_objs[60]),/* "DES-EDE-CFB" */
1827&(nid_objs[62]),/* "DES-EDE-OFB" */
1828&(nid_objs[33]),/* "DES-EDE3" */
1829&(nid_objs[44]),/* "DES-EDE3-CBC" */
1830&(nid_objs[61]),/* "DES-EDE3-CFB" */
1831&(nid_objs[658]),/* "DES-EDE3-CFB1" */
1832&(nid_objs[659]),/* "DES-EDE3-CFB8" */
1833&(nid_objs[63]),/* "DES-EDE3-OFB" */
1834&(nid_objs[45]),/* "DES-OFB" */
1835&(nid_objs[80]),/* "DESX-CBC" */
1836&(nid_objs[380]),/* "DOD" */
1837&(nid_objs[116]),/* "DSA" */
1838&(nid_objs[66]),/* "DSA-SHA" */
1839&(nid_objs[113]),/* "DSA-SHA1" */
1840&(nid_objs[70]),/* "DSA-SHA1-old" */
1841&(nid_objs[67]),/* "DSA-old" */
1842&(nid_objs[297]),/* "DVCS" */
1843&(nid_objs[99]),/* "GN" */
1844&(nid_objs[381]),/* "IANA" */
1845&(nid_objs[34]),/* "IDEA-CBC" */
1846&(nid_objs[35]),/* "IDEA-CFB" */
1847&(nid_objs[36]),/* "IDEA-ECB" */
1848&(nid_objs[46]),/* "IDEA-OFB" */
1849&(nid_objs[181]),/* "ISO" */
1850&(nid_objs[183]),/* "ISO-US" */
1851&(nid_objs[393]),/* "JOINT-ISO-CCITT" */
1852&(nid_objs[15]),/* "L" */
1853&(nid_objs[ 3]),/* "MD2" */
1854&(nid_objs[257]),/* "MD4" */
1855&(nid_objs[ 4]),/* "MD5" */
1856&(nid_objs[114]),/* "MD5-SHA1" */
1857&(nid_objs[95]),/* "MDC2" */
1858&(nid_objs[388]),/* "Mail" */
1859&(nid_objs[57]),/* "Netscape" */
1860&(nid_objs[366]),/* "Nonce" */
1861&(nid_objs[17]),/* "O" */
1862&(nid_objs[178]),/* "OCSP" */
1863&(nid_objs[180]),/* "OCSPSigning" */
1864&(nid_objs[379]),/* "ORG" */
1865&(nid_objs[18]),/* "OU" */
1866&(nid_objs[ 9]),/* "PBE-MD2-DES" */
1867&(nid_objs[168]),/* "PBE-MD2-RC2-64" */
1868&(nid_objs[10]),/* "PBE-MD5-DES" */
1869&(nid_objs[169]),/* "PBE-MD5-RC2-64" */
1870&(nid_objs[147]),/* "PBE-SHA1-2DES" */
1871&(nid_objs[146]),/* "PBE-SHA1-3DES" */
1872&(nid_objs[170]),/* "PBE-SHA1-DES" */
1873&(nid_objs[148]),/* "PBE-SHA1-RC2-128" */
1874&(nid_objs[149]),/* "PBE-SHA1-RC2-40" */
1875&(nid_objs[68]),/* "PBE-SHA1-RC2-64" */
1876&(nid_objs[144]),/* "PBE-SHA1-RC4-128" */
1877&(nid_objs[145]),/* "PBE-SHA1-RC4-40" */
1878&(nid_objs[161]),/* "PBES2" */
1879&(nid_objs[69]),/* "PBKDF2" */
1880&(nid_objs[162]),/* "PBMAC1" */
1881&(nid_objs[127]),/* "PKIX" */
1882&(nid_objs[98]),/* "RC2-40-CBC" */
1883&(nid_objs[166]),/* "RC2-64-CBC" */
1884&(nid_objs[37]),/* "RC2-CBC" */
1885&(nid_objs[39]),/* "RC2-CFB" */
1886&(nid_objs[38]),/* "RC2-ECB" */
1887&(nid_objs[40]),/* "RC2-OFB" */
1888&(nid_objs[ 5]),/* "RC4" */
1889&(nid_objs[97]),/* "RC4-40" */
1890&(nid_objs[120]),/* "RC5-CBC" */
1891&(nid_objs[122]),/* "RC5-CFB" */
1892&(nid_objs[121]),/* "RC5-ECB" */
1893&(nid_objs[123]),/* "RC5-OFB" */
1894&(nid_objs[117]),/* "RIPEMD160" */
1895&(nid_objs[124]),/* "RLE" */
1896&(nid_objs[19]),/* "RSA" */
1897&(nid_objs[ 7]),/* "RSA-MD2" */
1898&(nid_objs[396]),/* "RSA-MD4" */
1899&(nid_objs[ 8]),/* "RSA-MD5" */
1900&(nid_objs[96]),/* "RSA-MDC2" */
1901&(nid_objs[104]),/* "RSA-NP-MD5" */
1902&(nid_objs[119]),/* "RSA-RIPEMD160" */
1903&(nid_objs[42]),/* "RSA-SHA" */
1904&(nid_objs[65]),/* "RSA-SHA1" */
1905&(nid_objs[115]),/* "RSA-SHA1-2" */
1906&(nid_objs[671]),/* "RSA-SHA224" */
1907&(nid_objs[668]),/* "RSA-SHA256" */
1908&(nid_objs[669]),/* "RSA-SHA384" */
1909&(nid_objs[670]),/* "RSA-SHA512" */
1910&(nid_objs[41]),/* "SHA" */
1911&(nid_objs[64]),/* "SHA1" */
1912&(nid_objs[675]),/* "SHA224" */
1913&(nid_objs[672]),/* "SHA256" */
1914&(nid_objs[673]),/* "SHA384" */
1915&(nid_objs[674]),/* "SHA512" */
1916&(nid_objs[188]),/* "SMIME" */
1917&(nid_objs[167]),/* "SMIME-CAPS" */
1918&(nid_objs[100]),/* "SN" */
1919&(nid_objs[16]),/* "ST" */
1920&(nid_objs[143]),/* "SXNetID" */
1921&(nid_objs[458]),/* "UID" */
1922&(nid_objs[ 0]),/* "UNDEF" */
1923&(nid_objs[11]),/* "X500" */
1924&(nid_objs[378]),/* "X500algorithms" */
1925&(nid_objs[12]),/* "X509" */
1926&(nid_objs[184]),/* "X9-57" */
1927&(nid_objs[185]),/* "X9cm" */
1928&(nid_objs[125]),/* "ZLIB" */
1929&(nid_objs[478]),/* "aRecord" */
1930&(nid_objs[289]),/* "aaControls" */
1931&(nid_objs[287]),/* "ac-auditEntity" */
1932&(nid_objs[397]),/* "ac-proxying" */
1933&(nid_objs[288]),/* "ac-targeting" */
1934&(nid_objs[368]),/* "acceptableResponses" */
1935&(nid_objs[446]),/* "account" */
1936&(nid_objs[363]),/* "ad_timestamping" */
1937&(nid_objs[376]),/* "algorithm" */
1938&(nid_objs[405]),/* "ansi-X9-62" */
1939&(nid_objs[370]),/* "archiveCutoff" */
1940&(nid_objs[484]),/* "associatedDomain" */
1941&(nid_objs[485]),/* "associatedName" */
1942&(nid_objs[501]),/* "audio" */
1943&(nid_objs[177]),/* "authorityInfoAccess" */
1944&(nid_objs[90]),/* "authorityKeyIdentifier" */
1945&(nid_objs[87]),/* "basicConstraints" */
1946&(nid_objs[365]),/* "basicOCSPResponse" */
1947&(nid_objs[285]),/* "biometricInfo" */
1948&(nid_objs[494]),/* "buildingName" */
1949&(nid_objs[483]),/* "cNAMERecord" */
1950&(nid_objs[179]),/* "caIssuers" */
1951&(nid_objs[443]),/* "caseIgnoreIA5StringSyntax" */
1952&(nid_objs[152]),/* "certBag" */
1953&(nid_objs[89]),/* "certificatePolicies" */
1954&(nid_objs[54]),/* "challengePassword" */
1955&(nid_objs[407]),/* "characteristic-two-field" */
1956&(nid_objs[395]),/* "clearance" */
1957&(nid_objs[130]),/* "clientAuth" */
1958&(nid_objs[131]),/* "codeSigning" */
1959&(nid_objs[50]),/* "contentType" */
1960&(nid_objs[53]),/* "countersignature" */
1961&(nid_objs[153]),/* "crlBag" */
1962&(nid_objs[103]),/* "crlDistributionPoints" */
1963&(nid_objs[88]),/* "crlNumber" */
1964&(nid_objs[500]),/* "dITRedirect" */
1965&(nid_objs[451]),/* "dNSDomain" */
1966&(nid_objs[495]),/* "dSAQuality" */
1967&(nid_objs[434]),/* "data" */
1968&(nid_objs[390]),/* "dcobject" */
1969&(nid_objs[140]),/* "deltaCRL" */
1970&(nid_objs[107]),/* "description" */
1971&(nid_objs[28]),/* "dhKeyAgreement" */
1972&(nid_objs[382]),/* "directory" */
1973&(nid_objs[174]),/* "dnQualifier" */
1974&(nid_objs[447]),/* "document" */
1975&(nid_objs[471]),/* "documentAuthor" */
1976&(nid_objs[468]),/* "documentIdentifier" */
1977&(nid_objs[472]),/* "documentLocation" */
1978&(nid_objs[502]),/* "documentPublisher" */
1979&(nid_objs[449]),/* "documentSeries" */
1980&(nid_objs[469]),/* "documentTitle" */
1981&(nid_objs[470]),/* "documentVersion" */
1982&(nid_objs[392]),/* "domain" */
1983&(nid_objs[452]),/* "domainRelatedObject" */
1984&(nid_objs[416]),/* "ecdsa-with-SHA1" */
1985&(nid_objs[48]),/* "emailAddress" */
1986&(nid_objs[132]),/* "emailProtection" */
1987&(nid_objs[389]),/* "enterprises" */
1988&(nid_objs[384]),/* "experimental" */
1989&(nid_objs[172]),/* "extReq" */
1990&(nid_objs[56]),/* "extendedCertificateAttributes" */
1991&(nid_objs[126]),/* "extendedKeyUsage" */
1992&(nid_objs[372]),/* "extendedStatus" */
1993&(nid_objs[462]),/* "favouriteDrink" */
1994&(nid_objs[453]),/* "friendlyCountry" */
1995&(nid_objs[490]),/* "friendlyCountryName" */
1996&(nid_objs[156]),/* "friendlyName" */
1997&(nid_objs[509]),/* "generationQualifier" */
1998&(nid_objs[163]),/* "hmacWithSHA1" */
1999&(nid_objs[432]),/* "holdInstructionCallIssuer" */
2000&(nid_objs[430]),/* "holdInstructionCode" */
2001&(nid_objs[431]),/* "holdInstructionNone" */
2002&(nid_objs[433]),/* "holdInstructionReject" */
2003&(nid_objs[486]),/* "homePostalAddress" */
2004&(nid_objs[473]),/* "homeTelephoneNumber" */
2005&(nid_objs[466]),/* "host" */
2006&(nid_objs[442]),/* "iA5StringSyntax" */
2007&(nid_objs[266]),/* "id-aca" */
2008&(nid_objs[355]),/* "id-aca-accessIdentity" */
2009&(nid_objs[354]),/* "id-aca-authenticationInfo" */
2010&(nid_objs[356]),/* "id-aca-chargingIdentity" */
2011&(nid_objs[399]),/* "id-aca-encAttrs" */
2012&(nid_objs[357]),/* "id-aca-group" */
2013&(nid_objs[358]),/* "id-aca-role" */
2014&(nid_objs[176]),/* "id-ad" */
2015&(nid_objs[262]),/* "id-alg" */
2016&(nid_objs[323]),/* "id-alg-des40" */
2017&(nid_objs[326]),/* "id-alg-dh-pop" */
2018&(nid_objs[325]),/* "id-alg-dh-sig-hmac-sha1" */
2019&(nid_objs[324]),/* "id-alg-noSignature" */
2020&(nid_objs[268]),/* "id-cct" */
2021&(nid_objs[361]),/* "id-cct-PKIData" */
2022&(nid_objs[362]),/* "id-cct-PKIResponse" */
2023&(nid_objs[360]),/* "id-cct-crs" */
2024&(nid_objs[81]),/* "id-ce" */
2025&(nid_objs[263]),/* "id-cmc" */
2026&(nid_objs[334]),/* "id-cmc-addExtensions" */
2027&(nid_objs[346]),/* "id-cmc-confirmCertAcceptance" */
2028&(nid_objs[330]),/* "id-cmc-dataReturn" */
2029&(nid_objs[336]),/* "id-cmc-decryptedPOP" */
2030&(nid_objs[335]),/* "id-cmc-encryptedPOP" */
2031&(nid_objs[339]),/* "id-cmc-getCRL" */
2032&(nid_objs[338]),/* "id-cmc-getCert" */
2033&(nid_objs[328]),/* "id-cmc-identification" */
2034&(nid_objs[329]),/* "id-cmc-identityProof" */
2035&(nid_objs[337]),/* "id-cmc-lraPOPWitness" */
2036&(nid_objs[344]),/* "id-cmc-popLinkRandom" */
2037&(nid_objs[345]),/* "id-cmc-popLinkWitness" */
2038&(nid_objs[343]),/* "id-cmc-queryPending" */
2039&(nid_objs[333]),/* "id-cmc-recipientNonce" */
2040&(nid_objs[341]),/* "id-cmc-regInfo" */
2041&(nid_objs[342]),/* "id-cmc-responseInfo" */
2042&(nid_objs[340]),/* "id-cmc-revokeRequest" */
2043&(nid_objs[332]),/* "id-cmc-senderNonce" */
2044&(nid_objs[327]),/* "id-cmc-statusInfo" */
2045&(nid_objs[331]),/* "id-cmc-transactionId" */
2046&(nid_objs[408]),/* "id-ecPublicKey" */
2047&(nid_objs[508]),/* "id-hex-multipart-message" */
2048&(nid_objs[507]),/* "id-hex-partial-message" */
2049&(nid_objs[260]),/* "id-it" */
2050&(nid_objs[302]),/* "id-it-caKeyUpdateInfo" */
2051&(nid_objs[298]),/* "id-it-caProtEncCert" */
2052&(nid_objs[311]),/* "id-it-confirmWaitTime" */
2053&(nid_objs[303]),/* "id-it-currentCRL" */
2054&(nid_objs[300]),/* "id-it-encKeyPairTypes" */
2055&(nid_objs[310]),/* "id-it-implicitConfirm" */
2056&(nid_objs[308]),/* "id-it-keyPairParamRep" */
2057&(nid_objs[307]),/* "id-it-keyPairParamReq" */
2058&(nid_objs[312]),/* "id-it-origPKIMessage" */
2059&(nid_objs[301]),/* "id-it-preferredSymmAlg" */
2060&(nid_objs[309]),/* "id-it-revPassphrase" */
2061&(nid_objs[299]),/* "id-it-signKeyPairTypes" */
2062&(nid_objs[305]),/* "id-it-subscriptionRequest" */
2063&(nid_objs[306]),/* "id-it-subscriptionResponse" */
2064&(nid_objs[304]),/* "id-it-unsupportedOIDs" */
2065&(nid_objs[128]),/* "id-kp" */
2066&(nid_objs[280]),/* "id-mod-attribute-cert" */
2067&(nid_objs[274]),/* "id-mod-cmc" */
2068&(nid_objs[277]),/* "id-mod-cmp" */
2069&(nid_objs[284]),/* "id-mod-cmp2000" */
2070&(nid_objs[273]),/* "id-mod-crmf" */
2071&(nid_objs[283]),/* "id-mod-dvcs" */
2072&(nid_objs[275]),/* "id-mod-kea-profile-88" */
2073&(nid_objs[276]),/* "id-mod-kea-profile-93" */
2074&(nid_objs[282]),/* "id-mod-ocsp" */
2075&(nid_objs[278]),/* "id-mod-qualified-cert-88" */
2076&(nid_objs[279]),/* "id-mod-qualified-cert-93" */
2077&(nid_objs[281]),/* "id-mod-timestamp-protocol" */
2078&(nid_objs[264]),/* "id-on" */
2079&(nid_objs[347]),/* "id-on-personalData" */
2080&(nid_objs[265]),/* "id-pda" */
2081&(nid_objs[352]),/* "id-pda-countryOfCitizenship" */
2082&(nid_objs[353]),/* "id-pda-countryOfResidence" */
2083&(nid_objs[348]),/* "id-pda-dateOfBirth" */
2084&(nid_objs[351]),/* "id-pda-gender" */
2085&(nid_objs[349]),/* "id-pda-placeOfBirth" */
2086&(nid_objs[175]),/* "id-pe" */
2087&(nid_objs[261]),/* "id-pkip" */
2088&(nid_objs[258]),/* "id-pkix-mod" */
2089&(nid_objs[269]),/* "id-pkix1-explicit-88" */
2090&(nid_objs[271]),/* "id-pkix1-explicit-93" */
2091&(nid_objs[270]),/* "id-pkix1-implicit-88" */
2092&(nid_objs[272]),/* "id-pkix1-implicit-93" */
2093&(nid_objs[662]),/* "id-ppl" */
2094&(nid_objs[664]),/* "id-ppl-anyLanguage" */
2095&(nid_objs[667]),/* "id-ppl-independent" */
2096&(nid_objs[665]),/* "id-ppl-inheritAll" */
2097&(nid_objs[267]),/* "id-qcs" */
2098&(nid_objs[359]),/* "id-qcs-pkixQCSyntax-v1" */
2099&(nid_objs[259]),/* "id-qt" */
2100&(nid_objs[164]),/* "id-qt-cps" */
2101&(nid_objs[165]),/* "id-qt-unotice" */
2102&(nid_objs[313]),/* "id-regCtrl" */
2103&(nid_objs[316]),/* "id-regCtrl-authenticator" */
2104&(nid_objs[319]),/* "id-regCtrl-oldCertID" */
2105&(nid_objs[318]),/* "id-regCtrl-pkiArchiveOptions" */
2106&(nid_objs[317]),/* "id-regCtrl-pkiPublicationInfo" */
2107&(nid_objs[320]),/* "id-regCtrl-protocolEncrKey" */
2108&(nid_objs[315]),/* "id-regCtrl-regToken" */
2109&(nid_objs[314]),/* "id-regInfo" */
2110&(nid_objs[322]),/* "id-regInfo-certReq" */
2111&(nid_objs[321]),/* "id-regInfo-utf8Pairs" */
2112&(nid_objs[512]),/* "id-set" */
2113&(nid_objs[191]),/* "id-smime-aa" */
2114&(nid_objs[215]),/* "id-smime-aa-contentHint" */
2115&(nid_objs[218]),/* "id-smime-aa-contentIdentifier" */
2116&(nid_objs[221]),/* "id-smime-aa-contentReference" */
2117&(nid_objs[240]),/* "id-smime-aa-dvcs-dvc" */
2118&(nid_objs[217]),/* "id-smime-aa-encapContentType" */
2119&(nid_objs[222]),/* "id-smime-aa-encrypKeyPref" */
2120&(nid_objs[220]),/* "id-smime-aa-equivalentLabels" */
2121&(nid_objs[232]),/* "id-smime-aa-ets-CertificateRefs" */
2122&(nid_objs[233]),/* "id-smime-aa-ets-RevocationRefs" */
2123&(nid_objs[238]),/* "id-smime-aa-ets-archiveTimeStamp" */
2124&(nid_objs[237]),/* "id-smime-aa-ets-certCRLTimestamp" */
2125&(nid_objs[234]),/* "id-smime-aa-ets-certValues" */
2126&(nid_objs[227]),/* "id-smime-aa-ets-commitmentType" */
2127&(nid_objs[231]),/* "id-smime-aa-ets-contentTimestamp" */
2128&(nid_objs[236]),/* "id-smime-aa-ets-escTimeStamp" */
2129&(nid_objs[230]),/* "id-smime-aa-ets-otherSigCert" */
2130&(nid_objs[235]),/* "id-smime-aa-ets-revocationValues" */
2131&(nid_objs[226]),/* "id-smime-aa-ets-sigPolicyId" */
2132&(nid_objs[229]),/* "id-smime-aa-ets-signerAttr" */
2133&(nid_objs[228]),/* "id-smime-aa-ets-signerLocation" */
2134&(nid_objs[219]),/* "id-smime-aa-macValue" */
2135&(nid_objs[214]),/* "id-smime-aa-mlExpandHistory" */
2136&(nid_objs[216]),/* "id-smime-aa-msgSigDigest" */
2137&(nid_objs[212]),/* "id-smime-aa-receiptRequest" */
2138&(nid_objs[213]),/* "id-smime-aa-securityLabel" */
2139&(nid_objs[239]),/* "id-smime-aa-signatureType" */
2140&(nid_objs[223]),/* "id-smime-aa-signingCertificate" */
2141&(nid_objs[224]),/* "id-smime-aa-smimeEncryptCerts" */
2142&(nid_objs[225]),/* "id-smime-aa-timeStampToken" */
2143&(nid_objs[192]),/* "id-smime-alg" */
2144&(nid_objs[243]),/* "id-smime-alg-3DESwrap" */
2145&(nid_objs[246]),/* "id-smime-alg-CMS3DESwrap" */
2146&(nid_objs[247]),/* "id-smime-alg-CMSRC2wrap" */
2147&(nid_objs[245]),/* "id-smime-alg-ESDH" */
2148&(nid_objs[241]),/* "id-smime-alg-ESDHwith3DES" */
2149&(nid_objs[242]),/* "id-smime-alg-ESDHwithRC2" */
2150&(nid_objs[244]),/* "id-smime-alg-RC2wrap" */
2151&(nid_objs[193]),/* "id-smime-cd" */
2152&(nid_objs[248]),/* "id-smime-cd-ldap" */
2153&(nid_objs[190]),/* "id-smime-ct" */
2154&(nid_objs[210]),/* "id-smime-ct-DVCSRequestData" */
2155&(nid_objs[211]),/* "id-smime-ct-DVCSResponseData" */
2156&(nid_objs[208]),/* "id-smime-ct-TDTInfo" */
2157&(nid_objs[207]),/* "id-smime-ct-TSTInfo" */
2158&(nid_objs[205]),/* "id-smime-ct-authData" */
2159&(nid_objs[209]),/* "id-smime-ct-contentInfo" */
2160&(nid_objs[206]),/* "id-smime-ct-publishCert" */
2161&(nid_objs[204]),/* "id-smime-ct-receipt" */
2162&(nid_objs[195]),/* "id-smime-cti" */
2163&(nid_objs[255]),/* "id-smime-cti-ets-proofOfApproval" */
2164&(nid_objs[256]),/* "id-smime-cti-ets-proofOfCreation" */
2165&(nid_objs[253]),/* "id-smime-cti-ets-proofOfDelivery" */
2166&(nid_objs[251]),/* "id-smime-cti-ets-proofOfOrigin" */
2167&(nid_objs[252]),/* "id-smime-cti-ets-proofOfReceipt" */
2168&(nid_objs[254]),/* "id-smime-cti-ets-proofOfSender" */
2169&(nid_objs[189]),/* "id-smime-mod" */
2170&(nid_objs[196]),/* "id-smime-mod-cms" */
2171&(nid_objs[197]),/* "id-smime-mod-ess" */
2172&(nid_objs[202]),/* "id-smime-mod-ets-eSigPolicy-88" */
2173&(nid_objs[203]),/* "id-smime-mod-ets-eSigPolicy-97" */
2174&(nid_objs[200]),/* "id-smime-mod-ets-eSignature-88" */
2175&(nid_objs[201]),/* "id-smime-mod-ets-eSignature-97" */
2176&(nid_objs[199]),/* "id-smime-mod-msg-v3" */
2177&(nid_objs[198]),/* "id-smime-mod-oid" */
2178&(nid_objs[194]),/* "id-smime-spq" */
2179&(nid_objs[250]),/* "id-smime-spq-ets-sqt-unotice" */
2180&(nid_objs[249]),/* "id-smime-spq-ets-sqt-uri" */
2181&(nid_objs[461]),/* "info" */
2182&(nid_objs[101]),/* "initials" */
2183&(nid_objs[142]),/* "invalidityDate" */
2184&(nid_objs[294]),/* "ipsecEndSystem" */
2185&(nid_objs[295]),/* "ipsecTunnel" */
2186&(nid_objs[296]),/* "ipsecUser" */
2187&(nid_objs[86]),/* "issuerAltName" */
2188&(nid_objs[492]),/* "janetMailbox" */
2189&(nid_objs[150]),/* "keyBag" */
2190&(nid_objs[83]),/* "keyUsage" */
2191&(nid_objs[477]),/* "lastModifiedBy" */
2192&(nid_objs[476]),/* "lastModifiedTime" */
2193&(nid_objs[157]),/* "localKeyID" */
2194&(nid_objs[480]),/* "mXRecord" */
2195&(nid_objs[460]),/* "mail" */
2196&(nid_objs[493]),/* "mailPreferenceOption" */
2197&(nid_objs[467]),/* "manager" */
2198&(nid_objs[182]),/* "member-body" */
2199&(nid_objs[51]),/* "messageDigest" */
2200&(nid_objs[383]),/* "mgmt" */
2201&(nid_objs[504]),/* "mime-mhs" */
2202&(nid_objs[506]),/* "mime-mhs-bodies" */
2203&(nid_objs[505]),/* "mime-mhs-headings" */
2204&(nid_objs[488]),/* "mobileTelephoneNumber" */
2205&(nid_objs[136]),/* "msCTLSign" */
2206&(nid_objs[135]),/* "msCodeCom" */
2207&(nid_objs[134]),/* "msCodeInd" */
2208&(nid_objs[138]),/* "msEFS" */
2209&(nid_objs[171]),/* "msExtReq" */
2210&(nid_objs[137]),/* "msSGC" */
2211&(nid_objs[648]),/* "msSmartcardLogin" */
2212&(nid_objs[649]),/* "msUPN" */
2213&(nid_objs[481]),/* "nSRecord" */
2214&(nid_objs[173]),/* "name" */
2215&(nid_objs[666]),/* "nameConstraints" */
2216&(nid_objs[369]),/* "noCheck" */
2217&(nid_objs[403]),/* "noRevAvail" */
2218&(nid_objs[72]),/* "nsBaseUrl" */
2219&(nid_objs[76]),/* "nsCaPolicyUrl" */
2220&(nid_objs[74]),/* "nsCaRevocationUrl" */
2221&(nid_objs[58]),/* "nsCertExt" */
2222&(nid_objs[79]),/* "nsCertSequence" */
2223&(nid_objs[71]),/* "nsCertType" */
2224&(nid_objs[78]),/* "nsComment" */
2225&(nid_objs[59]),/* "nsDataType" */
2226&(nid_objs[75]),/* "nsRenewalUrl" */
2227&(nid_objs[73]),/* "nsRevocationUrl" */
2228&(nid_objs[139]),/* "nsSGC" */
2229&(nid_objs[77]),/* "nsSslServerName" */
2230&(nid_objs[491]),/* "organizationalStatus" */
2231&(nid_objs[475]),/* "otherMailbox" */
2232&(nid_objs[489]),/* "pagerTelephoneNumber" */
2233&(nid_objs[374]),/* "path" */
2234&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
2235&(nid_objs[499]),/* "personalSignature" */
2236&(nid_objs[487]),/* "personalTitle" */
2237&(nid_objs[464]),/* "photo" */
2238&(nid_objs[437]),/* "pilot" */
2239&(nid_objs[439]),/* "pilotAttributeSyntax" */
2240&(nid_objs[438]),/* "pilotAttributeType" */
2241&(nid_objs[479]),/* "pilotAttributeType27" */
2242&(nid_objs[456]),/* "pilotDSA" */
2243&(nid_objs[441]),/* "pilotGroups" */
2244&(nid_objs[444]),/* "pilotObject" */
2245&(nid_objs[440]),/* "pilotObjectClass" */
2246&(nid_objs[455]),/* "pilotOrganization" */
2247&(nid_objs[445]),/* "pilotPerson" */
2248&(nid_objs[ 2]),/* "pkcs" */
2249&(nid_objs[186]),/* "pkcs1" */
2250&(nid_objs[27]),/* "pkcs3" */
2251&(nid_objs[187]),/* "pkcs5" */
2252&(nid_objs[20]),/* "pkcs7" */
2253&(nid_objs[21]),/* "pkcs7-data" */
2254&(nid_objs[25]),/* "pkcs7-digestData" */
2255&(nid_objs[26]),/* "pkcs7-encryptedData" */
2256&(nid_objs[23]),/* "pkcs7-envelopedData" */
2257&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
2258&(nid_objs[22]),/* "pkcs7-signedData" */
2259&(nid_objs[151]),/* "pkcs8ShroudedKeyBag" */
2260&(nid_objs[47]),/* "pkcs9" */
2261&(nid_objs[401]),/* "policyConstraints" */
2262&(nid_objs[661]),/* "postalCode" */
2263&(nid_objs[406]),/* "prime-field" */
2264&(nid_objs[409]),/* "prime192v1" */
2265&(nid_objs[410]),/* "prime192v2" */
2266&(nid_objs[411]),/* "prime192v3" */
2267&(nid_objs[412]),/* "prime239v1" */
2268&(nid_objs[413]),/* "prime239v2" */
2269&(nid_objs[414]),/* "prime239v3" */
2270&(nid_objs[415]),/* "prime256v1" */
2271&(nid_objs[385]),/* "private" */
2272&(nid_objs[84]),/* "privateKeyUsagePeriod" */
2273&(nid_objs[663]),/* "proxyCertInfo" */
2274&(nid_objs[510]),/* "pseudonym" */
2275&(nid_objs[435]),/* "pss" */
2276&(nid_objs[286]),/* "qcStatements" */
2277&(nid_objs[457]),/* "qualityLabelledData" */
2278&(nid_objs[450]),/* "rFC822localPart" */
2279&(nid_objs[400]),/* "role" */
2280&(nid_objs[448]),/* "room" */
2281&(nid_objs[463]),/* "roomNumber" */
2282&(nid_objs[ 6]),/* "rsaEncryption" */
2283&(nid_objs[644]),/* "rsaOAEPEncryptionSET" */
2284&(nid_objs[377]),/* "rsaSignature" */
2285&(nid_objs[ 1]),/* "rsadsi" */
2286&(nid_objs[482]),/* "sOARecord" */
2287&(nid_objs[155]),/* "safeContentsBag" */
2288&(nid_objs[291]),/* "sbgp-autonomousSysNum" */
2289&(nid_objs[290]),/* "sbgp-ipAddrBlock" */
2290&(nid_objs[292]),/* "sbgp-routerIdentifier" */
2291&(nid_objs[159]),/* "sdsiCertificate" */
2292&(nid_objs[154]),/* "secretBag" */
2293&(nid_objs[474]),/* "secretary" */
2294&(nid_objs[386]),/* "security" */
2295&(nid_objs[394]),/* "selected-attribute-types" */
2296&(nid_objs[105]),/* "serialNumber" */
2297&(nid_objs[129]),/* "serverAuth" */
2298&(nid_objs[371]),/* "serviceLocator" */
2299&(nid_objs[625]),/* "set-addPolicy" */
2300&(nid_objs[515]),/* "set-attr" */
2301&(nid_objs[518]),/* "set-brand" */
2302&(nid_objs[638]),/* "set-brand-AmericanExpress" */
2303&(nid_objs[637]),/* "set-brand-Diners" */
2304&(nid_objs[636]),/* "set-brand-IATA-ATA" */
2305&(nid_objs[639]),/* "set-brand-JCB" */
2306&(nid_objs[641]),/* "set-brand-MasterCard" */
2307&(nid_objs[642]),/* "set-brand-Novus" */
2308&(nid_objs[640]),/* "set-brand-Visa" */
2309&(nid_objs[517]),/* "set-certExt" */
2310&(nid_objs[513]),/* "set-ctype" */
2311&(nid_objs[514]),/* "set-msgExt" */
2312&(nid_objs[516]),/* "set-policy" */
2313&(nid_objs[607]),/* "set-policy-root" */
2314&(nid_objs[624]),/* "set-rootKeyThumb" */
2315&(nid_objs[620]),/* "setAttr-Cert" */
2316&(nid_objs[631]),/* "setAttr-GenCryptgrm" */
2317&(nid_objs[623]),/* "setAttr-IssCap" */
2318&(nid_objs[628]),/* "setAttr-IssCap-CVM" */
2319&(nid_objs[630]),/* "setAttr-IssCap-Sig" */
2320&(nid_objs[629]),/* "setAttr-IssCap-T2" */
2321&(nid_objs[621]),/* "setAttr-PGWYcap" */
2322&(nid_objs[635]),/* "setAttr-SecDevSig" */
2323&(nid_objs[632]),/* "setAttr-T2Enc" */
2324&(nid_objs[633]),/* "setAttr-T2cleartxt" */
2325&(nid_objs[634]),/* "setAttr-TokICCsig" */
2326&(nid_objs[627]),/* "setAttr-Token-B0Prime" */
2327&(nid_objs[626]),/* "setAttr-Token-EMV" */
2328&(nid_objs[622]),/* "setAttr-TokenType" */
2329&(nid_objs[619]),/* "setCext-IssuerCapabilities" */
2330&(nid_objs[615]),/* "setCext-PGWYcapabilities" */
2331&(nid_objs[616]),/* "setCext-TokenIdentifier" */
2332&(nid_objs[618]),/* "setCext-TokenType" */
2333&(nid_objs[617]),/* "setCext-Track2Data" */
2334&(nid_objs[611]),/* "setCext-cCertRequired" */
2335&(nid_objs[609]),/* "setCext-certType" */
2336&(nid_objs[608]),/* "setCext-hashedRoot" */
2337&(nid_objs[610]),/* "setCext-merchData" */
2338&(nid_objs[613]),/* "setCext-setExt" */
2339&(nid_objs[614]),/* "setCext-setQualf" */
2340&(nid_objs[612]),/* "setCext-tunneling" */
2341&(nid_objs[540]),/* "setct-AcqCardCodeMsg" */
2342&(nid_objs[576]),/* "setct-AcqCardCodeMsgTBE" */
2343&(nid_objs[570]),/* "setct-AuthReqTBE" */
2344&(nid_objs[534]),/* "setct-AuthReqTBS" */
2345&(nid_objs[527]),/* "setct-AuthResBaggage" */
2346&(nid_objs[571]),/* "setct-AuthResTBE" */
2347&(nid_objs[572]),/* "setct-AuthResTBEX" */
2348&(nid_objs[535]),/* "setct-AuthResTBS" */
2349&(nid_objs[536]),/* "setct-AuthResTBSX" */
2350&(nid_objs[528]),/* "setct-AuthRevReqBaggage" */
2351&(nid_objs[577]),/* "setct-AuthRevReqTBE" */
2352&(nid_objs[541]),/* "setct-AuthRevReqTBS" */
2353&(nid_objs[529]),/* "setct-AuthRevResBaggage" */
2354&(nid_objs[542]),/* "setct-AuthRevResData" */
2355&(nid_objs[578]),/* "setct-AuthRevResTBE" */
2356&(nid_objs[579]),/* "setct-AuthRevResTBEB" */
2357&(nid_objs[543]),/* "setct-AuthRevResTBS" */
2358&(nid_objs[573]),/* "setct-AuthTokenTBE" */
2359&(nid_objs[537]),/* "setct-AuthTokenTBS" */
2360&(nid_objs[600]),/* "setct-BCIDistributionTBS" */
2361&(nid_objs[558]),/* "setct-BatchAdminReqData" */
2362&(nid_objs[592]),/* "setct-BatchAdminReqTBE" */
2363&(nid_objs[559]),/* "setct-BatchAdminResData" */
2364&(nid_objs[593]),/* "setct-BatchAdminResTBE" */
2365&(nid_objs[599]),/* "setct-CRLNotificationResTBS" */
2366&(nid_objs[598]),/* "setct-CRLNotificationTBS" */
2367&(nid_objs[580]),/* "setct-CapReqTBE" */
2368&(nid_objs[581]),/* "setct-CapReqTBEX" */
2369&(nid_objs[544]),/* "setct-CapReqTBS" */
2370&(nid_objs[545]),/* "setct-CapReqTBSX" */
2371&(nid_objs[546]),/* "setct-CapResData" */
2372&(nid_objs[582]),/* "setct-CapResTBE" */
2373&(nid_objs[583]),/* "setct-CapRevReqTBE" */
2374&(nid_objs[584]),/* "setct-CapRevReqTBEX" */
2375&(nid_objs[547]),/* "setct-CapRevReqTBS" */
2376&(nid_objs[548]),/* "setct-CapRevReqTBSX" */
2377&(nid_objs[549]),/* "setct-CapRevResData" */
2378&(nid_objs[585]),/* "setct-CapRevResTBE" */
2379&(nid_objs[538]),/* "setct-CapTokenData" */
2380&(nid_objs[530]),/* "setct-CapTokenSeq" */
2381&(nid_objs[574]),/* "setct-CapTokenTBE" */
2382&(nid_objs[575]),/* "setct-CapTokenTBEX" */
2383&(nid_objs[539]),/* "setct-CapTokenTBS" */
2384&(nid_objs[560]),/* "setct-CardCInitResTBS" */
2385&(nid_objs[566]),/* "setct-CertInqReqTBS" */
2386&(nid_objs[563]),/* "setct-CertReqData" */
2387&(nid_objs[595]),/* "setct-CertReqTBE" */
2388&(nid_objs[596]),/* "setct-CertReqTBEX" */
2389&(nid_objs[564]),/* "setct-CertReqTBS" */
2390&(nid_objs[565]),/* "setct-CertResData" */
2391&(nid_objs[597]),/* "setct-CertResTBE" */
2392&(nid_objs[586]),/* "setct-CredReqTBE" */
2393&(nid_objs[587]),/* "setct-CredReqTBEX" */
2394&(nid_objs[550]),/* "setct-CredReqTBS" */
2395&(nid_objs[551]),/* "setct-CredReqTBSX" */
2396&(nid_objs[552]),/* "setct-CredResData" */
2397&(nid_objs[588]),/* "setct-CredResTBE" */
2398&(nid_objs[589]),/* "setct-CredRevReqTBE" */
2399&(nid_objs[590]),/* "setct-CredRevReqTBEX" */
2400&(nid_objs[553]),/* "setct-CredRevReqTBS" */
2401&(nid_objs[554]),/* "setct-CredRevReqTBSX" */
2402&(nid_objs[555]),/* "setct-CredRevResData" */
2403&(nid_objs[591]),/* "setct-CredRevResTBE" */
2404&(nid_objs[567]),/* "setct-ErrorTBS" */
2405&(nid_objs[526]),/* "setct-HODInput" */
2406&(nid_objs[561]),/* "setct-MeAqCInitResTBS" */
2407&(nid_objs[522]),/* "setct-OIData" */
2408&(nid_objs[519]),/* "setct-PANData" */
2409&(nid_objs[521]),/* "setct-PANOnly" */
2410&(nid_objs[520]),/* "setct-PANToken" */
2411&(nid_objs[556]),/* "setct-PCertReqData" */
2412&(nid_objs[557]),/* "setct-PCertResTBS" */
2413&(nid_objs[523]),/* "setct-PI" */
2414&(nid_objs[532]),/* "setct-PI-TBS" */
2415&(nid_objs[524]),/* "setct-PIData" */
2416&(nid_objs[525]),/* "setct-PIDataUnsigned" */
2417&(nid_objs[568]),/* "setct-PIDualSignedTBE" */
2418&(nid_objs[569]),/* "setct-PIUnsignedTBE" */
2419&(nid_objs[531]),/* "setct-PInitResData" */
2420&(nid_objs[533]),/* "setct-PResData" */
2421&(nid_objs[594]),/* "setct-RegFormReqTBE" */
2422&(nid_objs[562]),/* "setct-RegFormResTBS" */
2423&(nid_objs[606]),/* "setext-cv" */
2424&(nid_objs[601]),/* "setext-genCrypt" */
2425&(nid_objs[602]),/* "setext-miAuth" */
2426&(nid_objs[604]),/* "setext-pinAny" */
2427&(nid_objs[603]),/* "setext-pinSecure" */
2428&(nid_objs[605]),/* "setext-track2" */
2429&(nid_objs[52]),/* "signingTime" */
2430&(nid_objs[454]),/* "simpleSecurityObject" */
2431&(nid_objs[496]),/* "singleLevelQuality" */
2432&(nid_objs[387]),/* "snmpv2" */
2433&(nid_objs[660]),/* "streetAddress" */
2434&(nid_objs[85]),/* "subjectAltName" */
2435&(nid_objs[398]),/* "subjectInfoAccess" */
2436&(nid_objs[82]),/* "subjectKeyIdentifier" */
2437&(nid_objs[498]),/* "subtreeMaximumQuality" */
2438&(nid_objs[497]),/* "subtreeMinimumQuality" */
2439&(nid_objs[402]),/* "targetInformation" */
2440&(nid_objs[459]),/* "textEncodedORAddress" */
2441&(nid_objs[293]),/* "textNotice" */
2442&(nid_objs[133]),/* "timeStamping" */
2443&(nid_objs[106]),/* "title" */
2444&(nid_objs[375]),/* "trustRoot" */
2445&(nid_objs[436]),/* "ucl" */
2446&(nid_objs[55]),/* "unstructuredAddress" */
2447&(nid_objs[49]),/* "unstructuredName" */
2448&(nid_objs[465]),/* "userClass" */
2449&(nid_objs[373]),/* "valid" */
2450&(nid_objs[503]),/* "x500UniqueIdentifier" */
2451&(nid_objs[158]),/* "x509Certificate" */
2452&(nid_objs[160]),/* "x509Crl" */
2453};
2454
2455static ASN1_OBJECT *ln_objs[NUM_LN]={
2456&(nid_objs[363]),/* "AD Time Stamping" */
2457&(nid_objs[405]),/* "ANSI X9.62" */
2458&(nid_objs[368]),/* "Acceptable OCSP Responses" */
2459&(nid_objs[664]),/* "Any language" */
2460&(nid_objs[177]),/* "Authority Information Access" */
2461&(nid_objs[365]),/* "Basic OCSP Response" */
2462&(nid_objs[285]),/* "Biometric Info" */
2463&(nid_objs[179]),/* "CA Issuers" */
2464&(nid_objs[131]),/* "Code Signing" */
2465&(nid_objs[382]),/* "Directory" */
2466&(nid_objs[392]),/* "Domain" */
2467&(nid_objs[132]),/* "E-mail Protection" */
2468&(nid_objs[389]),/* "Enterprises" */
2469&(nid_objs[384]),/* "Experimental" */
2470&(nid_objs[372]),/* "Extended OCSP Status" */
2471&(nid_objs[172]),/* "Extension Request" */
2472&(nid_objs[432]),/* "Hold Instruction Call Issuer" */
2473&(nid_objs[430]),/* "Hold Instruction Code" */
2474&(nid_objs[431]),/* "Hold Instruction None" */
2475&(nid_objs[433]),/* "Hold Instruction Reject" */
2476&(nid_objs[634]),/* "ICC or token signature" */
2477&(nid_objs[294]),/* "IPSec End System" */
2478&(nid_objs[295]),/* "IPSec Tunnel" */
2479&(nid_objs[296]),/* "IPSec User" */
2480&(nid_objs[182]),/* "ISO Member Body" */
2481&(nid_objs[183]),/* "ISO US Member Body" */
2482&(nid_objs[667]),/* "Independent" */
2483&(nid_objs[665]),/* "Inherit all" */
2484&(nid_objs[142]),/* "Invalidity Date" */
2485&(nid_objs[504]),/* "MIME MHS" */
2486&(nid_objs[388]),/* "Mail" */
2487&(nid_objs[383]),/* "Management" */
2488&(nid_objs[417]),/* "Microsoft CSP Name" */
2489&(nid_objs[135]),/* "Microsoft Commercial Code Signing" */
2490&(nid_objs[138]),/* "Microsoft Encrypted File System" */
2491&(nid_objs[171]),/* "Microsoft Extension Request" */
2492&(nid_objs[134]),/* "Microsoft Individual Code Signing" */
2493&(nid_objs[137]),/* "Microsoft Server Gated Crypto" */
2494&(nid_objs[648]),/* "Microsoft Smartcardlogin" */
2495&(nid_objs[136]),/* "Microsoft Trust List Signing" */
2496&(nid_objs[649]),/* "Microsoft Universal Principal Name" */
2497&(nid_objs[72]),/* "Netscape Base Url" */
2498&(nid_objs[76]),/* "Netscape CA Policy Url" */
2499&(nid_objs[74]),/* "Netscape CA Revocation Url" */
2500&(nid_objs[71]),/* "Netscape Cert Type" */
2501&(nid_objs[58]),/* "Netscape Certificate Extension" */
2502&(nid_objs[79]),/* "Netscape Certificate Sequence" */
2503&(nid_objs[78]),/* "Netscape Comment" */
2504&(nid_objs[57]),/* "Netscape Communications Corp." */
2505&(nid_objs[59]),/* "Netscape Data Type" */
2506&(nid_objs[75]),/* "Netscape Renewal Url" */
2507&(nid_objs[73]),/* "Netscape Revocation Url" */
2508&(nid_objs[77]),/* "Netscape SSL Server Name" */
2509&(nid_objs[139]),/* "Netscape Server Gated Crypto" */
2510&(nid_objs[178]),/* "OCSP" */
2511&(nid_objs[370]),/* "OCSP Archive Cutoff" */
2512&(nid_objs[367]),/* "OCSP CRL ID" */
2513&(nid_objs[369]),/* "OCSP No Check" */
2514&(nid_objs[366]),/* "OCSP Nonce" */
2515&(nid_objs[371]),/* "OCSP Service Locator" */
2516&(nid_objs[180]),/* "OCSP Signing" */
2517&(nid_objs[161]),/* "PBES2" */
2518&(nid_objs[69]),/* "PBKDF2" */
2519&(nid_objs[162]),/* "PBMAC1" */
2520&(nid_objs[127]),/* "PKIX" */
2521&(nid_objs[164]),/* "Policy Qualifier CPS" */
2522&(nid_objs[165]),/* "Policy Qualifier User Notice" */
2523&(nid_objs[385]),/* "Private" */
2524&(nid_objs[663]),/* "Proxy Certificate Information" */
2525&(nid_objs[ 1]),/* "RSA Data Security, Inc." */
2526&(nid_objs[ 2]),/* "RSA Data Security, Inc. PKCS" */
2527&(nid_objs[188]),/* "S/MIME" */
2528&(nid_objs[167]),/* "S/MIME Capabilities" */
2529&(nid_objs[387]),/* "SNMPv2" */
2530&(nid_objs[512]),/* "Secure Electronic Transactions" */
2531&(nid_objs[386]),/* "Security" */
2532&(nid_objs[394]),/* "Selected Attribute Types" */
2533&(nid_objs[143]),/* "Strong Extranet ID" */
2534&(nid_objs[398]),/* "Subject Information Access" */
2535&(nid_objs[130]),/* "TLS Web Client Authentication" */
2536&(nid_objs[129]),/* "TLS Web Server Authentication" */
2537&(nid_objs[133]),/* "Time Stamping" */
2538&(nid_objs[375]),/* "Trust Root" */
2539&(nid_objs[12]),/* "X509" */
2540&(nid_objs[402]),/* "X509v3 AC Targeting" */
2541&(nid_objs[90]),/* "X509v3 Authority Key Identifier" */
2542&(nid_objs[87]),/* "X509v3 Basic Constraints" */
2543&(nid_objs[103]),/* "X509v3 CRL Distribution Points" */
2544&(nid_objs[88]),/* "X509v3 CRL Number" */
2545&(nid_objs[141]),/* "X509v3 CRL Reason Code" */
2546&(nid_objs[89]),/* "X509v3 Certificate Policies" */
2547&(nid_objs[140]),/* "X509v3 Delta CRL Indicator" */
2548&(nid_objs[126]),/* "X509v3 Extended Key Usage" */
2549&(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */
2550&(nid_objs[83]),/* "X509v3 Key Usage" */
2551&(nid_objs[666]),/* "X509v3 Name Constraints" */
2552&(nid_objs[403]),/* "X509v3 No Revocation Available" */
2553&(nid_objs[401]),/* "X509v3 Policy Constraints" */
2554&(nid_objs[84]),/* "X509v3 Private Key Usage Period" */
2555&(nid_objs[85]),/* "X509v3 Subject Alternative Name" */
2556&(nid_objs[82]),/* "X509v3 Subject Key Identifier" */
2557&(nid_objs[184]),/* "X9.57" */
2558&(nid_objs[185]),/* "X9.57 CM ?" */
2559&(nid_objs[478]),/* "aRecord" */
2560&(nid_objs[289]),/* "aaControls" */
2561&(nid_objs[287]),/* "ac-auditEntity" */
2562&(nid_objs[397]),/* "ac-proxying" */
2563&(nid_objs[288]),/* "ac-targeting" */
2564&(nid_objs[446]),/* "account" */
2565&(nid_objs[364]),/* "ad dvcs" */
2566&(nid_objs[606]),/* "additional verification" */
2567&(nid_objs[419]),/* "aes-128-cbc" */
2568&(nid_objs[421]),/* "aes-128-cfb" */
2569&(nid_objs[650]),/* "aes-128-cfb1" */
2570&(nid_objs[653]),/* "aes-128-cfb8" */
2571&(nid_objs[418]),/* "aes-128-ecb" */
2572&(nid_objs[420]),/* "aes-128-ofb" */
2573&(nid_objs[423]),/* "aes-192-cbc" */
2574&(nid_objs[425]),/* "aes-192-cfb" */
2575&(nid_objs[651]),/* "aes-192-cfb1" */
2576&(nid_objs[654]),/* "aes-192-cfb8" */
2577&(nid_objs[422]),/* "aes-192-ecb" */
2578&(nid_objs[424]),/* "aes-192-ofb" */
2579&(nid_objs[427]),/* "aes-256-cbc" */
2580&(nid_objs[429]),/* "aes-256-cfb" */
2581&(nid_objs[652]),/* "aes-256-cfb1" */
2582&(nid_objs[655]),/* "aes-256-cfb8" */
2583&(nid_objs[426]),/* "aes-256-ecb" */
2584&(nid_objs[428]),/* "aes-256-ofb" */
2585&(nid_objs[376]),/* "algorithm" */
2586&(nid_objs[484]),/* "associatedDomain" */
2587&(nid_objs[485]),/* "associatedName" */
2588&(nid_objs[501]),/* "audio" */
2589&(nid_objs[91]),/* "bf-cbc" */
2590&(nid_objs[93]),/* "bf-cfb" */
2591&(nid_objs[92]),/* "bf-ecb" */
2592&(nid_objs[94]),/* "bf-ofb" */
2593&(nid_objs[494]),/* "buildingName" */
2594&(nid_objs[483]),/* "cNAMERecord" */
2595&(nid_objs[443]),/* "caseIgnoreIA5StringSyntax" */
2596&(nid_objs[108]),/* "cast5-cbc" */
2597&(nid_objs[110]),/* "cast5-cfb" */
2598&(nid_objs[109]),/* "cast5-ecb" */
2599&(nid_objs[111]),/* "cast5-ofb" */
2600&(nid_objs[404]),/* "ccitt" */
2601&(nid_objs[152]),/* "certBag" */
2602&(nid_objs[517]),/* "certificate extensions" */
2603&(nid_objs[54]),/* "challengePassword" */
2604&(nid_objs[407]),/* "characteristic-two-field" */
2605&(nid_objs[395]),/* "clearance" */
2606&(nid_objs[633]),/* "cleartext track 2" */
2607&(nid_objs[13]),/* "commonName" */
2608&(nid_objs[513]),/* "content types" */
2609&(nid_objs[50]),/* "contentType" */
2610&(nid_objs[53]),/* "countersignature" */
2611&(nid_objs[14]),/* "countryName" */
2612&(nid_objs[153]),/* "crlBag" */
2613&(nid_objs[500]),/* "dITRedirect" */
2614&(nid_objs[451]),/* "dNSDomain" */
2615&(nid_objs[495]),/* "dSAQuality" */
2616&(nid_objs[434]),/* "data" */
2617&(nid_objs[390]),/* "dcObject" */
2618&(nid_objs[31]),/* "des-cbc" */
2619&(nid_objs[643]),/* "des-cdmf" */
2620&(nid_objs[30]),/* "des-cfb" */
2621&(nid_objs[656]),/* "des-cfb1" */
2622&(nid_objs[657]),/* "des-cfb8" */
2623&(nid_objs[29]),/* "des-ecb" */
2624&(nid_objs[32]),/* "des-ede" */
2625&(nid_objs[43]),/* "des-ede-cbc" */
2626&(nid_objs[60]),/* "des-ede-cfb" */
2627&(nid_objs[62]),/* "des-ede-ofb" */
2628&(nid_objs[33]),/* "des-ede3" */
2629&(nid_objs[44]),/* "des-ede3-cbc" */
2630&(nid_objs[61]),/* "des-ede3-cfb" */
2631&(nid_objs[658]),/* "des-ede3-cfb1" */
2632&(nid_objs[659]),/* "des-ede3-cfb8" */
2633&(nid_objs[63]),/* "des-ede3-ofb" */
2634&(nid_objs[45]),/* "des-ofb" */
2635&(nid_objs[107]),/* "description" */
2636&(nid_objs[80]),/* "desx-cbc" */
2637&(nid_objs[28]),/* "dhKeyAgreement" */
2638&(nid_objs[11]),/* "directory services (X.500)" */
2639&(nid_objs[378]),/* "directory services - algorithms" */
2640&(nid_objs[174]),/* "dnQualifier" */
2641&(nid_objs[447]),/* "document" */
2642&(nid_objs[471]),/* "documentAuthor" */
2643&(nid_objs[468]),/* "documentIdentifier" */
2644&(nid_objs[472]),/* "documentLocation" */
2645&(nid_objs[502]),/* "documentPublisher" */
2646&(nid_objs[449]),/* "documentSeries" */
2647&(nid_objs[469]),/* "documentTitle" */
2648&(nid_objs[470]),/* "documentVersion" */
2649&(nid_objs[380]),/* "dod" */
2650&(nid_objs[391]),/* "domainComponent" */
2651&(nid_objs[452]),/* "domainRelatedObject" */
2652&(nid_objs[116]),/* "dsaEncryption" */
2653&(nid_objs[67]),/* "dsaEncryption-old" */
2654&(nid_objs[66]),/* "dsaWithSHA" */
2655&(nid_objs[113]),/* "dsaWithSHA1" */
2656&(nid_objs[70]),/* "dsaWithSHA1-old" */
2657&(nid_objs[297]),/* "dvcs" */
2658&(nid_objs[416]),/* "ecdsa-with-SHA1" */
2659&(nid_objs[48]),/* "emailAddress" */
2660&(nid_objs[632]),/* "encrypted track 2" */
2661&(nid_objs[56]),/* "extendedCertificateAttributes" */
2662&(nid_objs[462]),/* "favouriteDrink" */
2663&(nid_objs[453]),/* "friendlyCountry" */
2664&(nid_objs[490]),/* "friendlyCountryName" */
2665&(nid_objs[156]),/* "friendlyName" */
2666&(nid_objs[631]),/* "generate cryptogram" */
2667&(nid_objs[509]),/* "generationQualifier" */
2668&(nid_objs[601]),/* "generic cryptogram" */
2669&(nid_objs[99]),/* "givenName" */
2670&(nid_objs[163]),/* "hmacWithSHA1" */
2671&(nid_objs[486]),/* "homePostalAddress" */
2672&(nid_objs[473]),/* "homeTelephoneNumber" */
2673&(nid_objs[466]),/* "host" */
2674&(nid_objs[442]),/* "iA5StringSyntax" */
2675&(nid_objs[381]),/* "iana" */
2676&(nid_objs[266]),/* "id-aca" */
2677&(nid_objs[355]),/* "id-aca-accessIdentity" */
2678&(nid_objs[354]),/* "id-aca-authenticationInfo" */
2679&(nid_objs[356]),/* "id-aca-chargingIdentity" */
2680&(nid_objs[399]),/* "id-aca-encAttrs" */
2681&(nid_objs[357]),/* "id-aca-group" */
2682&(nid_objs[358]),/* "id-aca-role" */
2683&(nid_objs[176]),/* "id-ad" */
2684&(nid_objs[262]),/* "id-alg" */
2685&(nid_objs[323]),/* "id-alg-des40" */
2686&(nid_objs[326]),/* "id-alg-dh-pop" */
2687&(nid_objs[325]),/* "id-alg-dh-sig-hmac-sha1" */
2688&(nid_objs[324]),/* "id-alg-noSignature" */
2689&(nid_objs[268]),/* "id-cct" */
2690&(nid_objs[361]),/* "id-cct-PKIData" */
2691&(nid_objs[362]),/* "id-cct-PKIResponse" */
2692&(nid_objs[360]),/* "id-cct-crs" */
2693&(nid_objs[81]),/* "id-ce" */
2694&(nid_objs[263]),/* "id-cmc" */
2695&(nid_objs[334]),/* "id-cmc-addExtensions" */
2696&(nid_objs[346]),/* "id-cmc-confirmCertAcceptance" */
2697&(nid_objs[330]),/* "id-cmc-dataReturn" */
2698&(nid_objs[336]),/* "id-cmc-decryptedPOP" */
2699&(nid_objs[335]),/* "id-cmc-encryptedPOP" */
2700&(nid_objs[339]),/* "id-cmc-getCRL" */
2701&(nid_objs[338]),/* "id-cmc-getCert" */
2702&(nid_objs[328]),/* "id-cmc-identification" */
2703&(nid_objs[329]),/* "id-cmc-identityProof" */
2704&(nid_objs[337]),/* "id-cmc-lraPOPWitness" */
2705&(nid_objs[344]),/* "id-cmc-popLinkRandom" */
2706&(nid_objs[345]),/* "id-cmc-popLinkWitness" */
2707&(nid_objs[343]),/* "id-cmc-queryPending" */
2708&(nid_objs[333]),/* "id-cmc-recipientNonce" */
2709&(nid_objs[341]),/* "id-cmc-regInfo" */
2710&(nid_objs[342]),/* "id-cmc-responseInfo" */
2711&(nid_objs[340]),/* "id-cmc-revokeRequest" */
2712&(nid_objs[332]),/* "id-cmc-senderNonce" */
2713&(nid_objs[327]),/* "id-cmc-statusInfo" */
2714&(nid_objs[331]),/* "id-cmc-transactionId" */
2715&(nid_objs[408]),/* "id-ecPublicKey" */
2716&(nid_objs[508]),/* "id-hex-multipart-message" */
2717&(nid_objs[507]),/* "id-hex-partial-message" */
2718&(nid_objs[260]),/* "id-it" */
2719&(nid_objs[302]),/* "id-it-caKeyUpdateInfo" */
2720&(nid_objs[298]),/* "id-it-caProtEncCert" */
2721&(nid_objs[311]),/* "id-it-confirmWaitTime" */
2722&(nid_objs[303]),/* "id-it-currentCRL" */
2723&(nid_objs[300]),/* "id-it-encKeyPairTypes" */
2724&(nid_objs[310]),/* "id-it-implicitConfirm" */
2725&(nid_objs[308]),/* "id-it-keyPairParamRep" */
2726&(nid_objs[307]),/* "id-it-keyPairParamReq" */
2727&(nid_objs[312]),/* "id-it-origPKIMessage" */
2728&(nid_objs[301]),/* "id-it-preferredSymmAlg" */
2729&(nid_objs[309]),/* "id-it-revPassphrase" */
2730&(nid_objs[299]),/* "id-it-signKeyPairTypes" */
2731&(nid_objs[305]),/* "id-it-subscriptionRequest" */
2732&(nid_objs[306]),/* "id-it-subscriptionResponse" */
2733&(nid_objs[304]),/* "id-it-unsupportedOIDs" */
2734&(nid_objs[128]),/* "id-kp" */
2735&(nid_objs[280]),/* "id-mod-attribute-cert" */
2736&(nid_objs[274]),/* "id-mod-cmc" */
2737&(nid_objs[277]),/* "id-mod-cmp" */
2738&(nid_objs[284]),/* "id-mod-cmp2000" */
2739&(nid_objs[273]),/* "id-mod-crmf" */
2740&(nid_objs[283]),/* "id-mod-dvcs" */
2741&(nid_objs[275]),/* "id-mod-kea-profile-88" */
2742&(nid_objs[276]),/* "id-mod-kea-profile-93" */
2743&(nid_objs[282]),/* "id-mod-ocsp" */
2744&(nid_objs[278]),/* "id-mod-qualified-cert-88" */
2745&(nid_objs[279]),/* "id-mod-qualified-cert-93" */
2746&(nid_objs[281]),/* "id-mod-timestamp-protocol" */
2747&(nid_objs[264]),/* "id-on" */
2748&(nid_objs[347]),/* "id-on-personalData" */
2749&(nid_objs[265]),/* "id-pda" */
2750&(nid_objs[352]),/* "id-pda-countryOfCitizenship" */
2751&(nid_objs[353]),/* "id-pda-countryOfResidence" */
2752&(nid_objs[348]),/* "id-pda-dateOfBirth" */
2753&(nid_objs[351]),/* "id-pda-gender" */
2754&(nid_objs[349]),/* "id-pda-placeOfBirth" */
2755&(nid_objs[175]),/* "id-pe" */
2756&(nid_objs[261]),/* "id-pkip" */
2757&(nid_objs[258]),/* "id-pkix-mod" */
2758&(nid_objs[269]),/* "id-pkix1-explicit-88" */
2759&(nid_objs[271]),/* "id-pkix1-explicit-93" */
2760&(nid_objs[270]),/* "id-pkix1-implicit-88" */
2761&(nid_objs[272]),/* "id-pkix1-implicit-93" */
2762&(nid_objs[662]),/* "id-ppl" */
2763&(nid_objs[267]),/* "id-qcs" */
2764&(nid_objs[359]),/* "id-qcs-pkixQCSyntax-v1" */
2765&(nid_objs[259]),/* "id-qt" */
2766&(nid_objs[313]),/* "id-regCtrl" */
2767&(nid_objs[316]),/* "id-regCtrl-authenticator" */
2768&(nid_objs[319]),/* "id-regCtrl-oldCertID" */
2769&(nid_objs[318]),/* "id-regCtrl-pkiArchiveOptions" */
2770&(nid_objs[317]),/* "id-regCtrl-pkiPublicationInfo" */
2771&(nid_objs[320]),/* "id-regCtrl-protocolEncrKey" */
2772&(nid_objs[315]),/* "id-regCtrl-regToken" */
2773&(nid_objs[314]),/* "id-regInfo" */
2774&(nid_objs[322]),/* "id-regInfo-certReq" */
2775&(nid_objs[321]),/* "id-regInfo-utf8Pairs" */
2776&(nid_objs[191]),/* "id-smime-aa" */
2777&(nid_objs[215]),/* "id-smime-aa-contentHint" */
2778&(nid_objs[218]),/* "id-smime-aa-contentIdentifier" */
2779&(nid_objs[221]),/* "id-smime-aa-contentReference" */
2780&(nid_objs[240]),/* "id-smime-aa-dvcs-dvc" */
2781&(nid_objs[217]),/* "id-smime-aa-encapContentType" */
2782&(nid_objs[222]),/* "id-smime-aa-encrypKeyPref" */
2783&(nid_objs[220]),/* "id-smime-aa-equivalentLabels" */
2784&(nid_objs[232]),/* "id-smime-aa-ets-CertificateRefs" */
2785&(nid_objs[233]),/* "id-smime-aa-ets-RevocationRefs" */
2786&(nid_objs[238]),/* "id-smime-aa-ets-archiveTimeStamp" */
2787&(nid_objs[237]),/* "id-smime-aa-ets-certCRLTimestamp" */
2788&(nid_objs[234]),/* "id-smime-aa-ets-certValues" */
2789&(nid_objs[227]),/* "id-smime-aa-ets-commitmentType" */
2790&(nid_objs[231]),/* "id-smime-aa-ets-contentTimestamp" */
2791&(nid_objs[236]),/* "id-smime-aa-ets-escTimeStamp" */
2792&(nid_objs[230]),/* "id-smime-aa-ets-otherSigCert" */
2793&(nid_objs[235]),/* "id-smime-aa-ets-revocationValues" */
2794&(nid_objs[226]),/* "id-smime-aa-ets-sigPolicyId" */
2795&(nid_objs[229]),/* "id-smime-aa-ets-signerAttr" */
2796&(nid_objs[228]),/* "id-smime-aa-ets-signerLocation" */
2797&(nid_objs[219]),/* "id-smime-aa-macValue" */
2798&(nid_objs[214]),/* "id-smime-aa-mlExpandHistory" */
2799&(nid_objs[216]),/* "id-smime-aa-msgSigDigest" */
2800&(nid_objs[212]),/* "id-smime-aa-receiptRequest" */
2801&(nid_objs[213]),/* "id-smime-aa-securityLabel" */
2802&(nid_objs[239]),/* "id-smime-aa-signatureType" */
2803&(nid_objs[223]),/* "id-smime-aa-signingCertificate" */
2804&(nid_objs[224]),/* "id-smime-aa-smimeEncryptCerts" */
2805&(nid_objs[225]),/* "id-smime-aa-timeStampToken" */
2806&(nid_objs[192]),/* "id-smime-alg" */
2807&(nid_objs[243]),/* "id-smime-alg-3DESwrap" */
2808&(nid_objs[246]),/* "id-smime-alg-CMS3DESwrap" */
2809&(nid_objs[247]),/* "id-smime-alg-CMSRC2wrap" */
2810&(nid_objs[245]),/* "id-smime-alg-ESDH" */
2811&(nid_objs[241]),/* "id-smime-alg-ESDHwith3DES" */
2812&(nid_objs[242]),/* "id-smime-alg-ESDHwithRC2" */
2813&(nid_objs[244]),/* "id-smime-alg-RC2wrap" */
2814&(nid_objs[193]),/* "id-smime-cd" */
2815&(nid_objs[248]),/* "id-smime-cd-ldap" */
2816&(nid_objs[190]),/* "id-smime-ct" */
2817&(nid_objs[210]),/* "id-smime-ct-DVCSRequestData" */
2818&(nid_objs[211]),/* "id-smime-ct-DVCSResponseData" */
2819&(nid_objs[208]),/* "id-smime-ct-TDTInfo" */
2820&(nid_objs[207]),/* "id-smime-ct-TSTInfo" */
2821&(nid_objs[205]),/* "id-smime-ct-authData" */
2822&(nid_objs[209]),/* "id-smime-ct-contentInfo" */
2823&(nid_objs[206]),/* "id-smime-ct-publishCert" */
2824&(nid_objs[204]),/* "id-smime-ct-receipt" */
2825&(nid_objs[195]),/* "id-smime-cti" */
2826&(nid_objs[255]),/* "id-smime-cti-ets-proofOfApproval" */
2827&(nid_objs[256]),/* "id-smime-cti-ets-proofOfCreation" */
2828&(nid_objs[253]),/* "id-smime-cti-ets-proofOfDelivery" */
2829&(nid_objs[251]),/* "id-smime-cti-ets-proofOfOrigin" */
2830&(nid_objs[252]),/* "id-smime-cti-ets-proofOfReceipt" */
2831&(nid_objs[254]),/* "id-smime-cti-ets-proofOfSender" */
2832&(nid_objs[189]),/* "id-smime-mod" */
2833&(nid_objs[196]),/* "id-smime-mod-cms" */
2834&(nid_objs[197]),/* "id-smime-mod-ess" */
2835&(nid_objs[202]),/* "id-smime-mod-ets-eSigPolicy-88" */
2836&(nid_objs[203]),/* "id-smime-mod-ets-eSigPolicy-97" */
2837&(nid_objs[200]),/* "id-smime-mod-ets-eSignature-88" */
2838&(nid_objs[201]),/* "id-smime-mod-ets-eSignature-97" */
2839&(nid_objs[199]),/* "id-smime-mod-msg-v3" */
2840&(nid_objs[198]),/* "id-smime-mod-oid" */
2841&(nid_objs[194]),/* "id-smime-spq" */
2842&(nid_objs[250]),/* "id-smime-spq-ets-sqt-unotice" */
2843&(nid_objs[249]),/* "id-smime-spq-ets-sqt-uri" */
2844&(nid_objs[34]),/* "idea-cbc" */
2845&(nid_objs[35]),/* "idea-cfb" */
2846&(nid_objs[36]),/* "idea-ecb" */
2847&(nid_objs[46]),/* "idea-ofb" */
2848&(nid_objs[461]),/* "info" */
2849&(nid_objs[101]),/* "initials" */
2850&(nid_objs[181]),/* "iso" */
2851&(nid_objs[623]),/* "issuer capabilities" */
2852&(nid_objs[492]),/* "janetMailbox" */
2853&(nid_objs[393]),/* "joint-iso-ccitt" */
2854&(nid_objs[150]),/* "keyBag" */
2855&(nid_objs[477]),/* "lastModifiedBy" */
2856&(nid_objs[476]),/* "lastModifiedTime" */
2857&(nid_objs[157]),/* "localKeyID" */
2858&(nid_objs[15]),/* "localityName" */
2859&(nid_objs[480]),/* "mXRecord" */
2860&(nid_objs[493]),/* "mailPreferenceOption" */
2861&(nid_objs[467]),/* "manager" */
2862&(nid_objs[ 3]),/* "md2" */
2863&(nid_objs[ 7]),/* "md2WithRSAEncryption" */
2864&(nid_objs[257]),/* "md4" */
2865&(nid_objs[396]),/* "md4WithRSAEncryption" */
2866&(nid_objs[ 4]),/* "md5" */
2867&(nid_objs[114]),/* "md5-sha1" */
2868&(nid_objs[104]),/* "md5WithRSA" */
2869&(nid_objs[ 8]),/* "md5WithRSAEncryption" */
2870&(nid_objs[95]),/* "mdc2" */
2871&(nid_objs[96]),/* "mdc2WithRSA" */
2872&(nid_objs[602]),/* "merchant initiated auth" */
2873&(nid_objs[514]),/* "message extensions" */
2874&(nid_objs[51]),/* "messageDigest" */
2875&(nid_objs[506]),/* "mime-mhs-bodies" */
2876&(nid_objs[505]),/* "mime-mhs-headings" */
2877&(nid_objs[488]),/* "mobileTelephoneNumber" */
2878&(nid_objs[481]),/* "nSRecord" */
2879&(nid_objs[173]),/* "name" */
2880&(nid_objs[379]),/* "org" */
2881&(nid_objs[17]),/* "organizationName" */
2882&(nid_objs[491]),/* "organizationalStatus" */
2883&(nid_objs[18]),/* "organizationalUnitName" */
2884&(nid_objs[475]),/* "otherMailbox" */
2885&(nid_objs[489]),/* "pagerTelephoneNumber" */
2886&(nid_objs[374]),/* "path" */
2887&(nid_objs[621]),/* "payment gateway capabilities" */
2888&(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */
2889&(nid_objs[168]),/* "pbeWithMD2AndRC2-CBC" */
2890&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
2891&(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */
2892&(nid_objs[169]),/* "pbeWithMD5AndRC2-CBC" */
2893&(nid_objs[148]),/* "pbeWithSHA1And128BitRC2-CBC" */
2894&(nid_objs[144]),/* "pbeWithSHA1And128BitRC4" */
2895&(nid_objs[147]),/* "pbeWithSHA1And2-KeyTripleDES-CBC" */
2896&(nid_objs[146]),/* "pbeWithSHA1And3-KeyTripleDES-CBC" */
2897&(nid_objs[149]),/* "pbeWithSHA1And40BitRC2-CBC" */
2898&(nid_objs[145]),/* "pbeWithSHA1And40BitRC4" */
2899&(nid_objs[170]),/* "pbeWithSHA1AndDES-CBC" */
2900&(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */
2901&(nid_objs[499]),/* "personalSignature" */
2902&(nid_objs[487]),/* "personalTitle" */
2903&(nid_objs[464]),/* "photo" */
2904&(nid_objs[437]),/* "pilot" */
2905&(nid_objs[439]),/* "pilotAttributeSyntax" */
2906&(nid_objs[438]),/* "pilotAttributeType" */
2907&(nid_objs[479]),/* "pilotAttributeType27" */
2908&(nid_objs[456]),/* "pilotDSA" */
2909&(nid_objs[441]),/* "pilotGroups" */
2910&(nid_objs[444]),/* "pilotObject" */
2911&(nid_objs[440]),/* "pilotObjectClass" */
2912&(nid_objs[455]),/* "pilotOrganization" */
2913&(nid_objs[445]),/* "pilotPerson" */
2914&(nid_objs[186]),/* "pkcs1" */
2915&(nid_objs[27]),/* "pkcs3" */
2916&(nid_objs[187]),/* "pkcs5" */
2917&(nid_objs[20]),/* "pkcs7" */
2918&(nid_objs[21]),/* "pkcs7-data" */
2919&(nid_objs[25]),/* "pkcs7-digestData" */
2920&(nid_objs[26]),/* "pkcs7-encryptedData" */
2921&(nid_objs[23]),/* "pkcs7-envelopedData" */
2922&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
2923&(nid_objs[22]),/* "pkcs7-signedData" */
2924&(nid_objs[151]),/* "pkcs8ShroudedKeyBag" */
2925&(nid_objs[47]),/* "pkcs9" */
2926&(nid_objs[661]),/* "postalCode" */
2927&(nid_objs[406]),/* "prime-field" */
2928&(nid_objs[409]),/* "prime192v1" */
2929&(nid_objs[410]),/* "prime192v2" */
2930&(nid_objs[411]),/* "prime192v3" */
2931&(nid_objs[412]),/* "prime239v1" */
2932&(nid_objs[413]),/* "prime239v2" */
2933&(nid_objs[414]),/* "prime239v3" */
2934&(nid_objs[415]),/* "prime256v1" */
2935&(nid_objs[510]),/* "pseudonym" */
2936&(nid_objs[435]),/* "pss" */
2937&(nid_objs[286]),/* "qcStatements" */
2938&(nid_objs[457]),/* "qualityLabelledData" */
2939&(nid_objs[450]),/* "rFC822localPart" */
2940&(nid_objs[98]),/* "rc2-40-cbc" */
2941&(nid_objs[166]),/* "rc2-64-cbc" */
2942&(nid_objs[37]),/* "rc2-cbc" */
2943&(nid_objs[39]),/* "rc2-cfb" */
2944&(nid_objs[38]),/* "rc2-ecb" */
2945&(nid_objs[40]),/* "rc2-ofb" */
2946&(nid_objs[ 5]),/* "rc4" */
2947&(nid_objs[97]),/* "rc4-40" */
2948&(nid_objs[120]),/* "rc5-cbc" */
2949&(nid_objs[122]),/* "rc5-cfb" */
2950&(nid_objs[121]),/* "rc5-ecb" */
2951&(nid_objs[123]),/* "rc5-ofb" */
2952&(nid_objs[460]),/* "rfc822Mailbox" */
2953&(nid_objs[117]),/* "ripemd160" */
2954&(nid_objs[119]),/* "ripemd160WithRSA" */
2955&(nid_objs[400]),/* "role" */
2956&(nid_objs[448]),/* "room" */
2957&(nid_objs[463]),/* "roomNumber" */
2958&(nid_objs[19]),/* "rsa" */
2959&(nid_objs[ 6]),/* "rsaEncryption" */
2960&(nid_objs[644]),/* "rsaOAEPEncryptionSET" */
2961&(nid_objs[377]),/* "rsaSignature" */
2962&(nid_objs[124]),/* "run length compression" */
2963&(nid_objs[482]),/* "sOARecord" */
2964&(nid_objs[155]),/* "safeContentsBag" */
2965&(nid_objs[291]),/* "sbgp-autonomousSysNum" */
2966&(nid_objs[290]),/* "sbgp-ipAddrBlock" */
2967&(nid_objs[292]),/* "sbgp-routerIdentifier" */
2968&(nid_objs[159]),/* "sdsiCertificate" */
2969&(nid_objs[154]),/* "secretBag" */
2970&(nid_objs[474]),/* "secretary" */
2971&(nid_objs[635]),/* "secure device signature" */
2972&(nid_objs[105]),/* "serialNumber" */
2973&(nid_objs[625]),/* "set-addPolicy" */
2974&(nid_objs[515]),/* "set-attr" */
2975&(nid_objs[518]),/* "set-brand" */
2976&(nid_objs[638]),/* "set-brand-AmericanExpress" */
2977&(nid_objs[637]),/* "set-brand-Diners" */
2978&(nid_objs[636]),/* "set-brand-IATA-ATA" */
2979&(nid_objs[639]),/* "set-brand-JCB" */
2980&(nid_objs[641]),/* "set-brand-MasterCard" */
2981&(nid_objs[642]),/* "set-brand-Novus" */
2982&(nid_objs[640]),/* "set-brand-Visa" */
2983&(nid_objs[516]),/* "set-policy" */
2984&(nid_objs[607]),/* "set-policy-root" */
2985&(nid_objs[624]),/* "set-rootKeyThumb" */
2986&(nid_objs[620]),/* "setAttr-Cert" */
2987&(nid_objs[628]),/* "setAttr-IssCap-CVM" */
2988&(nid_objs[630]),/* "setAttr-IssCap-Sig" */
2989&(nid_objs[629]),/* "setAttr-IssCap-T2" */
2990&(nid_objs[627]),/* "setAttr-Token-B0Prime" */
2991&(nid_objs[626]),/* "setAttr-Token-EMV" */
2992&(nid_objs[622]),/* "setAttr-TokenType" */
2993&(nid_objs[619]),/* "setCext-IssuerCapabilities" */
2994&(nid_objs[615]),/* "setCext-PGWYcapabilities" */
2995&(nid_objs[616]),/* "setCext-TokenIdentifier" */
2996&(nid_objs[618]),/* "setCext-TokenType" */
2997&(nid_objs[617]),/* "setCext-Track2Data" */
2998&(nid_objs[611]),/* "setCext-cCertRequired" */
2999&(nid_objs[609]),/* "setCext-certType" */
3000&(nid_objs[608]),/* "setCext-hashedRoot" */
3001&(nid_objs[610]),/* "setCext-merchData" */
3002&(nid_objs[613]),/* "setCext-setExt" */
3003&(nid_objs[614]),/* "setCext-setQualf" */
3004&(nid_objs[612]),/* "setCext-tunneling" */
3005&(nid_objs[540]),/* "setct-AcqCardCodeMsg" */
3006&(nid_objs[576]),/* "setct-AcqCardCodeMsgTBE" */
3007&(nid_objs[570]),/* "setct-AuthReqTBE" */
3008&(nid_objs[534]),/* "setct-AuthReqTBS" */
3009&(nid_objs[527]),/* "setct-AuthResBaggage" */
3010&(nid_objs[571]),/* "setct-AuthResTBE" */
3011&(nid_objs[572]),/* "setct-AuthResTBEX" */
3012&(nid_objs[535]),/* "setct-AuthResTBS" */
3013&(nid_objs[536]),/* "setct-AuthResTBSX" */
3014&(nid_objs[528]),/* "setct-AuthRevReqBaggage" */
3015&(nid_objs[577]),/* "setct-AuthRevReqTBE" */
3016&(nid_objs[541]),/* "setct-AuthRevReqTBS" */
3017&(nid_objs[529]),/* "setct-AuthRevResBaggage" */
3018&(nid_objs[542]),/* "setct-AuthRevResData" */
3019&(nid_objs[578]),/* "setct-AuthRevResTBE" */
3020&(nid_objs[579]),/* "setct-AuthRevResTBEB" */
3021&(nid_objs[543]),/* "setct-AuthRevResTBS" */
3022&(nid_objs[573]),/* "setct-AuthTokenTBE" */
3023&(nid_objs[537]),/* "setct-AuthTokenTBS" */
3024&(nid_objs[600]),/* "setct-BCIDistributionTBS" */
3025&(nid_objs[558]),/* "setct-BatchAdminReqData" */
3026&(nid_objs[592]),/* "setct-BatchAdminReqTBE" */
3027&(nid_objs[559]),/* "setct-BatchAdminResData" */
3028&(nid_objs[593]),/* "setct-BatchAdminResTBE" */
3029&(nid_objs[599]),/* "setct-CRLNotificationResTBS" */
3030&(nid_objs[598]),/* "setct-CRLNotificationTBS" */
3031&(nid_objs[580]),/* "setct-CapReqTBE" */
3032&(nid_objs[581]),/* "setct-CapReqTBEX" */
3033&(nid_objs[544]),/* "setct-CapReqTBS" */
3034&(nid_objs[545]),/* "setct-CapReqTBSX" */
3035&(nid_objs[546]),/* "setct-CapResData" */
3036&(nid_objs[582]),/* "setct-CapResTBE" */
3037&(nid_objs[583]),/* "setct-CapRevReqTBE" */
3038&(nid_objs[584]),/* "setct-CapRevReqTBEX" */
3039&(nid_objs[547]),/* "setct-CapRevReqTBS" */
3040&(nid_objs[548]),/* "setct-CapRevReqTBSX" */
3041&(nid_objs[549]),/* "setct-CapRevResData" */
3042&(nid_objs[585]),/* "setct-CapRevResTBE" */
3043&(nid_objs[538]),/* "setct-CapTokenData" */
3044&(nid_objs[530]),/* "setct-CapTokenSeq" */
3045&(nid_objs[574]),/* "setct-CapTokenTBE" */
3046&(nid_objs[575]),/* "setct-CapTokenTBEX" */
3047&(nid_objs[539]),/* "setct-CapTokenTBS" */
3048&(nid_objs[560]),/* "setct-CardCInitResTBS" */
3049&(nid_objs[566]),/* "setct-CertInqReqTBS" */
3050&(nid_objs[563]),/* "setct-CertReqData" */
3051&(nid_objs[595]),/* "setct-CertReqTBE" */
3052&(nid_objs[596]),/* "setct-CertReqTBEX" */
3053&(nid_objs[564]),/* "setct-CertReqTBS" */
3054&(nid_objs[565]),/* "setct-CertResData" */
3055&(nid_objs[597]),/* "setct-CertResTBE" */
3056&(nid_objs[586]),/* "setct-CredReqTBE" */
3057&(nid_objs[587]),/* "setct-CredReqTBEX" */
3058&(nid_objs[550]),/* "setct-CredReqTBS" */
3059&(nid_objs[551]),/* "setct-CredReqTBSX" */
3060&(nid_objs[552]),/* "setct-CredResData" */
3061&(nid_objs[588]),/* "setct-CredResTBE" */
3062&(nid_objs[589]),/* "setct-CredRevReqTBE" */
3063&(nid_objs[590]),/* "setct-CredRevReqTBEX" */
3064&(nid_objs[553]),/* "setct-CredRevReqTBS" */
3065&(nid_objs[554]),/* "setct-CredRevReqTBSX" */
3066&(nid_objs[555]),/* "setct-CredRevResData" */
3067&(nid_objs[591]),/* "setct-CredRevResTBE" */
3068&(nid_objs[567]),/* "setct-ErrorTBS" */
3069&(nid_objs[526]),/* "setct-HODInput" */
3070&(nid_objs[561]),/* "setct-MeAqCInitResTBS" */
3071&(nid_objs[522]),/* "setct-OIData" */
3072&(nid_objs[519]),/* "setct-PANData" */
3073&(nid_objs[521]),/* "setct-PANOnly" */
3074&(nid_objs[520]),/* "setct-PANToken" */
3075&(nid_objs[556]),/* "setct-PCertReqData" */
3076&(nid_objs[557]),/* "setct-PCertResTBS" */
3077&(nid_objs[523]),/* "setct-PI" */
3078&(nid_objs[532]),/* "setct-PI-TBS" */
3079&(nid_objs[524]),/* "setct-PIData" */
3080&(nid_objs[525]),/* "setct-PIDataUnsigned" */
3081&(nid_objs[568]),/* "setct-PIDualSignedTBE" */
3082&(nid_objs[569]),/* "setct-PIUnsignedTBE" */
3083&(nid_objs[531]),/* "setct-PInitResData" */
3084&(nid_objs[533]),/* "setct-PResData" */
3085&(nid_objs[594]),/* "setct-RegFormReqTBE" */
3086&(nid_objs[562]),/* "setct-RegFormResTBS" */
3087&(nid_objs[604]),/* "setext-pinAny" */
3088&(nid_objs[603]),/* "setext-pinSecure" */
3089&(nid_objs[605]),/* "setext-track2" */
3090&(nid_objs[41]),/* "sha" */
3091&(nid_objs[64]),/* "sha1" */
3092&(nid_objs[115]),/* "sha1WithRSA" */
3093&(nid_objs[65]),/* "sha1WithRSAEncryption" */
3094&(nid_objs[675]),/* "sha224" */
3095&(nid_objs[671]),/* "sha224WithRSAEncryption" */
3096&(nid_objs[672]),/* "sha256" */
3097&(nid_objs[668]),/* "sha256WithRSAEncryption" */
3098&(nid_objs[673]),/* "sha384" */
3099&(nid_objs[669]),/* "sha384WithRSAEncryption" */
3100&(nid_objs[674]),/* "sha512" */
3101&(nid_objs[670]),/* "sha512WithRSAEncryption" */
3102&(nid_objs[42]),/* "shaWithRSAEncryption" */
3103&(nid_objs[52]),/* "signingTime" */
3104&(nid_objs[454]),/* "simpleSecurityObject" */
3105&(nid_objs[496]),/* "singleLevelQuality" */
3106&(nid_objs[16]),/* "stateOrProvinceName" */
3107&(nid_objs[660]),/* "streetAddress" */
3108&(nid_objs[498]),/* "subtreeMaximumQuality" */
3109&(nid_objs[497]),/* "subtreeMinimumQuality" */
3110&(nid_objs[100]),/* "surname" */
3111&(nid_objs[459]),/* "textEncodedORAddress" */
3112&(nid_objs[293]),/* "textNotice" */
3113&(nid_objs[106]),/* "title" */
3114&(nid_objs[436]),/* "ucl" */
3115&(nid_objs[ 0]),/* "undefined" */
3116&(nid_objs[55]),/* "unstructuredAddress" */
3117&(nid_objs[49]),/* "unstructuredName" */
3118&(nid_objs[465]),/* "userClass" */
3119&(nid_objs[458]),/* "userId" */
3120&(nid_objs[373]),/* "valid" */
3121&(nid_objs[503]),/* "x500UniqueIdentifier" */
3122&(nid_objs[158]),/* "x509Certificate" */
3123&(nid_objs[160]),/* "x509Crl" */
3124&(nid_objs[125]),/* "zlib compression" */
3125};
3126
3127static ASN1_OBJECT *obj_objs[NUM_OBJ]={
3128&(nid_objs[ 0]),/* OBJ_undef 0 */
3129&(nid_objs[404]),/* OBJ_ccitt 0 */
3130&(nid_objs[434]),/* OBJ_data 0 9 */
3131&(nid_objs[181]),/* OBJ_iso 1 */
3132&(nid_objs[182]),/* OBJ_member_body 1 2 */
3133&(nid_objs[379]),/* OBJ_org 1 3 */
3134&(nid_objs[393]),/* OBJ_joint_iso_ccitt 2 */
3135&(nid_objs[11]),/* OBJ_X500 2 5 */
3136&(nid_objs[380]),/* OBJ_dod 1 3 6 */
3137&(nid_objs[12]),/* OBJ_X509 2 5 4 */
3138&(nid_objs[378]),/* OBJ_X500algorithms 2 5 8 */
3139&(nid_objs[81]),/* OBJ_id_ce 2 5 29 */
3140&(nid_objs[512]),/* OBJ_id_set 2 23 42 */
3141&(nid_objs[435]),/* OBJ_pss 0 9 2342 */
3142&(nid_objs[183]),/* OBJ_ISO_US 1 2 840 */
3143&(nid_objs[381]),/* OBJ_iana 1 3 6 1 */
3144&(nid_objs[394]),/* OBJ_selected_attribute_types 2 5 1 5 */
3145&(nid_objs[13]),/* OBJ_commonName 2 5 4 3 */
3146&(nid_objs[100]),/* OBJ_surname 2 5 4 4 */
3147&(nid_objs[105]),/* OBJ_serialNumber 2 5 4 5 */
3148&(nid_objs[14]),/* OBJ_countryName 2 5 4 6 */
3149&(nid_objs[15]),/* OBJ_localityName 2 5 4 7 */
3150&(nid_objs[16]),/* OBJ_stateOrProvinceName 2 5 4 8 */
3151&(nid_objs[660]),/* OBJ_streetAddress 2 5 4 9 */
3152&(nid_objs[17]),/* OBJ_organizationName 2 5 4 10 */
3153&(nid_objs[18]),/* OBJ_organizationalUnitName 2 5 4 11 */
3154&(nid_objs[106]),/* OBJ_title 2 5 4 12 */
3155&(nid_objs[107]),/* OBJ_description 2 5 4 13 */
3156&(nid_objs[661]),/* OBJ_postalCode 2 5 4 17 */
3157&(nid_objs[173]),/* OBJ_name 2 5 4 41 */
3158&(nid_objs[99]),/* OBJ_givenName 2 5 4 42 */
3159&(nid_objs[101]),/* OBJ_initials 2 5 4 43 */
3160&(nid_objs[509]),/* OBJ_generationQualifier 2 5 4 44 */
3161&(nid_objs[503]),/* OBJ_x500UniqueIdentifier 2 5 4 45 */
3162&(nid_objs[174]),/* OBJ_dnQualifier 2 5 4 46 */
3163&(nid_objs[510]),/* OBJ_pseudonym 2 5 4 65 */
3164&(nid_objs[400]),/* OBJ_role 2 5 4 72 */
3165&(nid_objs[82]),/* OBJ_subject_key_identifier 2 5 29 14 */
3166&(nid_objs[83]),/* OBJ_key_usage 2 5 29 15 */
3167&(nid_objs[84]),/* OBJ_private_key_usage_period 2 5 29 16 */
3168&(nid_objs[85]),/* OBJ_subject_alt_name 2 5 29 17 */
3169&(nid_objs[86]),/* OBJ_issuer_alt_name 2 5 29 18 */
3170&(nid_objs[87]),/* OBJ_basic_constraints 2 5 29 19 */
3171&(nid_objs[88]),/* OBJ_crl_number 2 5 29 20 */
3172&(nid_objs[141]),/* OBJ_crl_reason 2 5 29 21 */
3173&(nid_objs[430]),/* OBJ_hold_instruction_code 2 5 29 23 */
3174&(nid_objs[142]),/* OBJ_invalidity_date 2 5 29 24 */
3175&(nid_objs[140]),/* OBJ_delta_crl 2 5 29 27 */
3176&(nid_objs[666]),/* OBJ_name_constraints 2 5 29 30 */
3177&(nid_objs[103]),/* OBJ_crl_distribution_points 2 5 29 31 */
3178&(nid_objs[89]),/* OBJ_certificate_policies 2 5 29 32 */
3179&(nid_objs[90]),/* OBJ_authority_key_identifier 2 5 29 35 */
3180&(nid_objs[401]),/* OBJ_policy_constraints 2 5 29 36 */
3181&(nid_objs[126]),/* OBJ_ext_key_usage 2 5 29 37 */
3182&(nid_objs[402]),/* OBJ_target_information 2 5 29 55 */
3183&(nid_objs[403]),/* OBJ_no_rev_avail 2 5 29 56 */
3184&(nid_objs[513]),/* OBJ_set_ctype 2 23 42 0 */
3185&(nid_objs[514]),/* OBJ_set_msgExt 2 23 42 1 */
3186&(nid_objs[515]),/* OBJ_set_attr 2 23 42 3 */
3187&(nid_objs[516]),/* OBJ_set_policy 2 23 42 5 */
3188&(nid_objs[517]),/* OBJ_set_certExt 2 23 42 7 */
3189&(nid_objs[518]),/* OBJ_set_brand 2 23 42 8 */
3190&(nid_objs[382]),/* OBJ_Directory 1 3 6 1 1 */
3191&(nid_objs[383]),/* OBJ_Management 1 3 6 1 2 */
3192&(nid_objs[384]),/* OBJ_Experimental 1 3 6 1 3 */
3193&(nid_objs[385]),/* OBJ_Private 1 3 6 1 4 */
3194&(nid_objs[386]),/* OBJ_Security 1 3 6 1 5 */
3195&(nid_objs[387]),/* OBJ_SNMPv2 1 3 6 1 6 */
3196&(nid_objs[388]),/* OBJ_Mail 1 3 6 1 7 */
3197&(nid_objs[376]),/* OBJ_algorithm 1 3 14 3 2 */
3198&(nid_objs[395]),/* OBJ_clearance 2 5 1 5 55 */
3199&(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */
3200&(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */
3201&(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */
3202&(nid_objs[519]),/* OBJ_setct_PANData 2 23 42 0 0 */
3203&(nid_objs[520]),/* OBJ_setct_PANToken 2 23 42 0 1 */
3204&(nid_objs[521]),/* OBJ_setct_PANOnly 2 23 42 0 2 */
3205&(nid_objs[522]),/* OBJ_setct_OIData 2 23 42 0 3 */
3206&(nid_objs[523]),/* OBJ_setct_PI 2 23 42 0 4 */
3207&(nid_objs[524]),/* OBJ_setct_PIData 2 23 42 0 5 */
3208&(nid_objs[525]),/* OBJ_setct_PIDataUnsigned 2 23 42 0 6 */
3209&(nid_objs[526]),/* OBJ_setct_HODInput 2 23 42 0 7 */
3210&(nid_objs[527]),/* OBJ_setct_AuthResBaggage 2 23 42 0 8 */
3211&(nid_objs[528]),/* OBJ_setct_AuthRevReqBaggage 2 23 42 0 9 */
3212&(nid_objs[529]),/* OBJ_setct_AuthRevResBaggage 2 23 42 0 10 */
3213&(nid_objs[530]),/* OBJ_setct_CapTokenSeq 2 23 42 0 11 */
3214&(nid_objs[531]),/* OBJ_setct_PInitResData 2 23 42 0 12 */
3215&(nid_objs[532]),/* OBJ_setct_PI_TBS 2 23 42 0 13 */
3216&(nid_objs[533]),/* OBJ_setct_PResData 2 23 42 0 14 */
3217&(nid_objs[534]),/* OBJ_setct_AuthReqTBS 2 23 42 0 16 */
3218&(nid_objs[535]),/* OBJ_setct_AuthResTBS 2 23 42 0 17 */
3219&(nid_objs[536]),/* OBJ_setct_AuthResTBSX 2 23 42 0 18 */
3220&(nid_objs[537]),/* OBJ_setct_AuthTokenTBS 2 23 42 0 19 */
3221&(nid_objs[538]),/* OBJ_setct_CapTokenData 2 23 42 0 20 */
3222&(nid_objs[539]),/* OBJ_setct_CapTokenTBS 2 23 42 0 21 */
3223&(nid_objs[540]),/* OBJ_setct_AcqCardCodeMsg 2 23 42 0 22 */
3224&(nid_objs[541]),/* OBJ_setct_AuthRevReqTBS 2 23 42 0 23 */
3225&(nid_objs[542]),/* OBJ_setct_AuthRevResData 2 23 42 0 24 */
3226&(nid_objs[543]),/* OBJ_setct_AuthRevResTBS 2 23 42 0 25 */
3227&(nid_objs[544]),/* OBJ_setct_CapReqTBS 2 23 42 0 26 */
3228&(nid_objs[545]),/* OBJ_setct_CapReqTBSX 2 23 42 0 27 */
3229&(nid_objs[546]),/* OBJ_setct_CapResData 2 23 42 0 28 */
3230&(nid_objs[547]),/* OBJ_setct_CapRevReqTBS 2 23 42 0 29 */
3231&(nid_objs[548]),/* OBJ_setct_CapRevReqTBSX 2 23 42 0 30 */
3232&(nid_objs[549]),/* OBJ_setct_CapRevResData 2 23 42 0 31 */
3233&(nid_objs[550]),/* OBJ_setct_CredReqTBS 2 23 42 0 32 */
3234&(nid_objs[551]),/* OBJ_setct_CredReqTBSX 2 23 42 0 33 */
3235&(nid_objs[552]),/* OBJ_setct_CredResData 2 23 42 0 34 */
3236&(nid_objs[553]),/* OBJ_setct_CredRevReqTBS 2 23 42 0 35 */
3237&(nid_objs[554]),/* OBJ_setct_CredRevReqTBSX 2 23 42 0 36 */
3238&(nid_objs[555]),/* OBJ_setct_CredRevResData 2 23 42 0 37 */
3239&(nid_objs[556]),/* OBJ_setct_PCertReqData 2 23 42 0 38 */
3240&(nid_objs[557]),/* OBJ_setct_PCertResTBS 2 23 42 0 39 */
3241&(nid_objs[558]),/* OBJ_setct_BatchAdminReqData 2 23 42 0 40 */
3242&(nid_objs[559]),/* OBJ_setct_BatchAdminResData 2 23 42 0 41 */
3243&(nid_objs[560]),/* OBJ_setct_CardCInitResTBS 2 23 42 0 42 */
3244&(nid_objs[561]),/* OBJ_setct_MeAqCInitResTBS 2 23 42 0 43 */
3245&(nid_objs[562]),/* OBJ_setct_RegFormResTBS 2 23 42 0 44 */
3246&(nid_objs[563]),/* OBJ_setct_CertReqData 2 23 42 0 45 */
3247&(nid_objs[564]),/* OBJ_setct_CertReqTBS 2 23 42 0 46 */
3248&(nid_objs[565]),/* OBJ_setct_CertResData 2 23 42 0 47 */
3249&(nid_objs[566]),/* OBJ_setct_CertInqReqTBS 2 23 42 0 48 */
3250&(nid_objs[567]),/* OBJ_setct_ErrorTBS 2 23 42 0 49 */
3251&(nid_objs[568]),/* OBJ_setct_PIDualSignedTBE 2 23 42 0 50 */
3252&(nid_objs[569]),/* OBJ_setct_PIUnsignedTBE 2 23 42 0 51 */
3253&(nid_objs[570]),/* OBJ_setct_AuthReqTBE 2 23 42 0 52 */
3254&(nid_objs[571]),/* OBJ_setct_AuthResTBE 2 23 42 0 53 */
3255&(nid_objs[572]),/* OBJ_setct_AuthResTBEX 2 23 42 0 54 */
3256&(nid_objs[573]),/* OBJ_setct_AuthTokenTBE 2 23 42 0 55 */
3257&(nid_objs[574]),/* OBJ_setct_CapTokenTBE 2 23 42 0 56 */
3258&(nid_objs[575]),/* OBJ_setct_CapTokenTBEX 2 23 42 0 57 */
3259&(nid_objs[576]),/* OBJ_setct_AcqCardCodeMsgTBE 2 23 42 0 58 */
3260&(nid_objs[577]),/* OBJ_setct_AuthRevReqTBE 2 23 42 0 59 */
3261&(nid_objs[578]),/* OBJ_setct_AuthRevResTBE 2 23 42 0 60 */
3262&(nid_objs[579]),/* OBJ_setct_AuthRevResTBEB 2 23 42 0 61 */
3263&(nid_objs[580]),/* OBJ_setct_CapReqTBE 2 23 42 0 62 */
3264&(nid_objs[581]),/* OBJ_setct_CapReqTBEX 2 23 42 0 63 */
3265&(nid_objs[582]),/* OBJ_setct_CapResTBE 2 23 42 0 64 */
3266&(nid_objs[583]),/* OBJ_setct_CapRevReqTBE 2 23 42 0 65 */
3267&(nid_objs[584]),/* OBJ_setct_CapRevReqTBEX 2 23 42 0 66 */
3268&(nid_objs[585]),/* OBJ_setct_CapRevResTBE 2 23 42 0 67 */
3269&(nid_objs[586]),/* OBJ_setct_CredReqTBE 2 23 42 0 68 */
3270&(nid_objs[587]),/* OBJ_setct_CredReqTBEX 2 23 42 0 69 */
3271&(nid_objs[588]),/* OBJ_setct_CredResTBE 2 23 42 0 70 */
3272&(nid_objs[589]),/* OBJ_setct_CredRevReqTBE 2 23 42 0 71 */
3273&(nid_objs[590]),/* OBJ_setct_CredRevReqTBEX 2 23 42 0 72 */
3274&(nid_objs[591]),/* OBJ_setct_CredRevResTBE 2 23 42 0 73 */
3275&(nid_objs[592]),/* OBJ_setct_BatchAdminReqTBE 2 23 42 0 74 */
3276&(nid_objs[593]),/* OBJ_setct_BatchAdminResTBE 2 23 42 0 75 */
3277&(nid_objs[594]),/* OBJ_setct_RegFormReqTBE 2 23 42 0 76 */
3278&(nid_objs[595]),/* OBJ_setct_CertReqTBE 2 23 42 0 77 */
3279&(nid_objs[596]),/* OBJ_setct_CertReqTBEX 2 23 42 0 78 */
3280&(nid_objs[597]),/* OBJ_setct_CertResTBE 2 23 42 0 79 */
3281&(nid_objs[598]),/* OBJ_setct_CRLNotificationTBS 2 23 42 0 80 */
3282&(nid_objs[599]),/* OBJ_setct_CRLNotificationResTBS 2 23 42 0 81 */
3283&(nid_objs[600]),/* OBJ_setct_BCIDistributionTBS 2 23 42 0 82 */
3284&(nid_objs[601]),/* OBJ_setext_genCrypt 2 23 42 1 1 */
3285&(nid_objs[602]),/* OBJ_setext_miAuth 2 23 42 1 3 */
3286&(nid_objs[603]),/* OBJ_setext_pinSecure 2 23 42 1 4 */
3287&(nid_objs[604]),/* OBJ_setext_pinAny 2 23 42 1 5 */
3288&(nid_objs[605]),/* OBJ_setext_track2 2 23 42 1 7 */
3289&(nid_objs[606]),/* OBJ_setext_cv 2 23 42 1 8 */
3290&(nid_objs[620]),/* OBJ_setAttr_Cert 2 23 42 3 0 */
3291&(nid_objs[621]),/* OBJ_setAttr_PGWYcap 2 23 42 3 1 */
3292&(nid_objs[622]),/* OBJ_setAttr_TokenType 2 23 42 3 2 */
3293&(nid_objs[623]),/* OBJ_setAttr_IssCap 2 23 42 3 3 */
3294&(nid_objs[607]),/* OBJ_set_policy_root 2 23 42 5 0 */
3295&(nid_objs[608]),/* OBJ_setCext_hashedRoot 2 23 42 7 0 */
3296&(nid_objs[609]),/* OBJ_setCext_certType 2 23 42 7 1 */
3297&(nid_objs[610]),/* OBJ_setCext_merchData 2 23 42 7 2 */
3298&(nid_objs[611]),/* OBJ_setCext_cCertRequired 2 23 42 7 3 */
3299&(nid_objs[612]),/* OBJ_setCext_tunneling 2 23 42 7 4 */
3300&(nid_objs[613]),/* OBJ_setCext_setExt 2 23 42 7 5 */
3301&(nid_objs[614]),/* OBJ_setCext_setQualf 2 23 42 7 6 */
3302&(nid_objs[615]),/* OBJ_setCext_PGWYcapabilities 2 23 42 7 7 */
3303&(nid_objs[616]),/* OBJ_setCext_TokenIdentifier 2 23 42 7 8 */
3304&(nid_objs[617]),/* OBJ_setCext_Track2Data 2 23 42 7 9 */
3305&(nid_objs[618]),/* OBJ_setCext_TokenType 2 23 42 7 10 */
3306&(nid_objs[619]),/* OBJ_setCext_IssuerCapabilities 2 23 42 7 11 */
3307&(nid_objs[636]),/* OBJ_set_brand_IATA_ATA 2 23 42 8 1 */
3308&(nid_objs[640]),/* OBJ_set_brand_Visa 2 23 42 8 4 */
3309&(nid_objs[641]),/* OBJ_set_brand_MasterCard 2 23 42 8 5 */
3310&(nid_objs[637]),/* OBJ_set_brand_Diners 2 23 42 8 30 */
3311&(nid_objs[638]),/* OBJ_set_brand_AmericanExpress 2 23 42 8 34 */
3312&(nid_objs[639]),/* OBJ_set_brand_JCB 2 23 42 8 35 */
3313&(nid_objs[184]),/* OBJ_X9_57 1 2 840 10040 */
3314&(nid_objs[405]),/* OBJ_ansi_X9_62 1 2 840 10045 */
3315&(nid_objs[389]),/* OBJ_Enterprises 1 3 6 1 4 1 */
3316&(nid_objs[504]),/* OBJ_mime_mhs 1 3 6 1 7 1 */
3317&(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */
3318&(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */
3319&(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */
3320&(nid_objs[45]),/* OBJ_des_ofb64 1 3 14 3 2 8 */
3321&(nid_objs[30]),/* OBJ_des_cfb64 1 3 14 3 2 9 */
3322&(nid_objs[377]),/* OBJ_rsaSignature 1 3 14 3 2 11 */
3323&(nid_objs[67]),/* OBJ_dsa_2 1 3 14 3 2 12 */
3324&(nid_objs[66]),/* OBJ_dsaWithSHA 1 3 14 3 2 13 */
3325&(nid_objs[42]),/* OBJ_shaWithRSAEncryption 1 3 14 3 2 15 */
3326&(nid_objs[32]),/* OBJ_des_ede_ecb 1 3 14 3 2 17 */
3327&(nid_objs[41]),/* OBJ_sha 1 3 14 3 2 18 */
3328&(nid_objs[64]),/* OBJ_sha1 1 3 14 3 2 26 */
3329&(nid_objs[70]),/* OBJ_dsaWithSHA1_2 1 3 14 3 2 27 */
3330&(nid_objs[115]),/* OBJ_sha1WithRSA 1 3 14 3 2 29 */
3331&(nid_objs[117]),/* OBJ_ripemd160 1 3 36 3 2 1 */
3332&(nid_objs[143]),/* OBJ_sxnet 1 3 101 1 4 1 */
3333&(nid_objs[624]),/* OBJ_set_rootKeyThumb 2 23 42 3 0 0 */
3334&(nid_objs[625]),/* OBJ_set_addPolicy 2 23 42 3 0 1 */
3335&(nid_objs[626]),/* OBJ_setAttr_Token_EMV 2 23 42 3 2 1 */
3336&(nid_objs[627]),/* OBJ_setAttr_Token_B0Prime 2 23 42 3 2 2 */
3337&(nid_objs[628]),/* OBJ_setAttr_IssCap_CVM 2 23 42 3 3 3 */
3338&(nid_objs[629]),/* OBJ_setAttr_IssCap_T2 2 23 42 3 3 4 */
3339&(nid_objs[630]),/* OBJ_setAttr_IssCap_Sig 2 23 42 3 3 5 */
3340&(nid_objs[642]),/* OBJ_set_brand_Novus 2 23 42 8 6011 */
3341&(nid_objs[124]),/* OBJ_rle_compression 1 1 1 1 666 1 */
3342&(nid_objs[125]),/* OBJ_zlib_compression 1 1 1 1 666 2 */
3343&(nid_objs[ 1]),/* OBJ_rsadsi 1 2 840 113549 */
3344&(nid_objs[185]),/* OBJ_X9cm 1 2 840 10040 4 */
3345&(nid_objs[127]),/* OBJ_id_pkix 1 3 6 1 5 5 7 */
3346&(nid_objs[505]),/* OBJ_mime_mhs_headings 1 3 6 1 7 1 1 */
3347&(nid_objs[506]),/* OBJ_mime_mhs_bodies 1 3 6 1 7 1 2 */
3348&(nid_objs[119]),/* OBJ_ripemd160WithRSA 1 3 36 3 3 1 2 */
3349&(nid_objs[631]),/* OBJ_setAttr_GenCryptgrm 2 23 42 3 3 3 1 */
3350&(nid_objs[632]),/* OBJ_setAttr_T2Enc 2 23 42 3 3 4 1 */
3351&(nid_objs[633]),/* OBJ_setAttr_T2cleartxt 2 23 42 3 3 4 2 */
3352&(nid_objs[634]),/* OBJ_setAttr_TokICCsig 2 23 42 3 3 5 1 */
3353&(nid_objs[635]),/* OBJ_setAttr_SecDevSig 2 23 42 3 3 5 2 */
3354&(nid_objs[436]),/* OBJ_ucl 0 9 2342 19200300 */
3355&(nid_objs[ 2]),/* OBJ_pkcs 1 2 840 113549 1 */
3356&(nid_objs[431]),/* OBJ_hold_instruction_none 1 2 840 10040 2 1 */
3357&(nid_objs[432]),/* OBJ_hold_instruction_call_issuer 1 2 840 10040 2 2 */
3358&(nid_objs[433]),/* OBJ_hold_instruction_reject 1 2 840 10040 2 3 */
3359&(nid_objs[116]),/* OBJ_dsa 1 2 840 10040 4 1 */
3360&(nid_objs[113]),/* OBJ_dsaWithSHA1 1 2 840 10040 4 3 */
3361&(nid_objs[406]),/* OBJ_X9_62_prime_field 1 2 840 10045 1 1 */
3362&(nid_objs[407]),/* OBJ_X9_62_characteristic_two_field 1 2 840 10045 1 2 */
3363&(nid_objs[408]),/* OBJ_X9_62_id_ecPublicKey 1 2 840 10045 2 1 */
3364&(nid_objs[416]),/* OBJ_ecdsa_with_SHA1 1 2 840 10045 4 1 */
3365&(nid_objs[258]),/* OBJ_id_pkix_mod 1 3 6 1 5 5 7 0 */
3366&(nid_objs[175]),/* OBJ_id_pe 1 3 6 1 5 5 7 1 */
3367&(nid_objs[259]),/* OBJ_id_qt 1 3 6 1 5 5 7 2 */
3368&(nid_objs[128]),/* OBJ_id_kp 1 3 6 1 5 5 7 3 */
3369&(nid_objs[260]),/* OBJ_id_it 1 3 6 1 5 5 7 4 */
3370&(nid_objs[261]),/* OBJ_id_pkip 1 3 6 1 5 5 7 5 */
3371&(nid_objs[262]),/* OBJ_id_alg 1 3 6 1 5 5 7 6 */
3372&(nid_objs[263]),/* OBJ_id_cmc 1 3 6 1 5 5 7 7 */
3373&(nid_objs[264]),/* OBJ_id_on 1 3 6 1 5 5 7 8 */
3374&(nid_objs[265]),/* OBJ_id_pda 1 3 6 1 5 5 7 9 */
3375&(nid_objs[266]),/* OBJ_id_aca 1 3 6 1 5 5 7 10 */
3376&(nid_objs[267]),/* OBJ_id_qcs 1 3 6 1 5 5 7 11 */
3377&(nid_objs[268]),/* OBJ_id_cct 1 3 6 1 5 5 7 12 */
3378&(nid_objs[662]),/* OBJ_id_ppl 1 3 6 1 5 5 7 21 */
3379&(nid_objs[176]),/* OBJ_id_ad 1 3 6 1 5 5 7 48 */
3380&(nid_objs[507]),/* OBJ_id_hex_partial_message 1 3 6 1 7 1 1 1 */
3381&(nid_objs[508]),/* OBJ_id_hex_multipart_message 1 3 6 1 7 1 1 2 */
3382&(nid_objs[57]),/* OBJ_netscape 2 16 840 1 113730 */
3383&(nid_objs[437]),/* OBJ_pilot 0 9 2342 19200300 100 */
3384&(nid_objs[186]),/* OBJ_pkcs1 1 2 840 113549 1 1 */
3385&(nid_objs[27]),/* OBJ_pkcs3 1 2 840 113549 1 3 */
3386&(nid_objs[187]),/* OBJ_pkcs5 1 2 840 113549 1 5 */
3387&(nid_objs[20]),/* OBJ_pkcs7 1 2 840 113549 1 7 */
3388&(nid_objs[47]),/* OBJ_pkcs9 1 2 840 113549 1 9 */
3389&(nid_objs[ 3]),/* OBJ_md2 1 2 840 113549 2 2 */
3390&(nid_objs[257]),/* OBJ_md4 1 2 840 113549 2 4 */
3391&(nid_objs[ 4]),/* OBJ_md5 1 2 840 113549 2 5 */
3392&(nid_objs[163]),/* OBJ_hmacWithSHA1 1 2 840 113549 2 7 */
3393&(nid_objs[37]),/* OBJ_rc2_cbc 1 2 840 113549 3 2 */
3394&(nid_objs[ 5]),/* OBJ_rc4 1 2 840 113549 3 4 */
3395&(nid_objs[44]),/* OBJ_des_ede3_cbc 1 2 840 113549 3 7 */
3396&(nid_objs[120]),/* OBJ_rc5_cbc 1 2 840 113549 3 8 */
3397&(nid_objs[643]),/* OBJ_des_cdmf 1 2 840 113549 3 10 */
3398&(nid_objs[409]),/* OBJ_X9_62_prime192v1 1 2 840 10045 3 1 1 */
3399&(nid_objs[410]),/* OBJ_X9_62_prime192v2 1 2 840 10045 3 1 2 */
3400&(nid_objs[411]),/* OBJ_X9_62_prime192v3 1 2 840 10045 3 1 3 */
3401&(nid_objs[412]),/* OBJ_X9_62_prime239v1 1 2 840 10045 3 1 4 */
3402&(nid_objs[413]),/* OBJ_X9_62_prime239v2 1 2 840 10045 3 1 5 */
3403&(nid_objs[414]),/* OBJ_X9_62_prime239v3 1 2 840 10045 3 1 6 */
3404&(nid_objs[415]),/* OBJ_X9_62_prime256v1 1 2 840 10045 3 1 7 */
3405&(nid_objs[269]),/* OBJ_id_pkix1_explicit_88 1 3 6 1 5 5 7 0 1 */
3406&(nid_objs[270]),/* OBJ_id_pkix1_implicit_88 1 3 6 1 5 5 7 0 2 */
3407&(nid_objs[271]),/* OBJ_id_pkix1_explicit_93 1 3 6 1 5 5 7 0 3 */
3408&(nid_objs[272]),/* OBJ_id_pkix1_implicit_93 1 3 6 1 5 5 7 0 4 */
3409&(nid_objs[273]),/* OBJ_id_mod_crmf 1 3 6 1 5 5 7 0 5 */
3410&(nid_objs[274]),/* OBJ_id_mod_cmc 1 3 6 1 5 5 7 0 6 */
3411&(nid_objs[275]),/* OBJ_id_mod_kea_profile_88 1 3 6 1 5 5 7 0 7 */
3412&(nid_objs[276]),/* OBJ_id_mod_kea_profile_93 1 3 6 1 5 5 7 0 8 */
3413&(nid_objs[277]),/* OBJ_id_mod_cmp 1 3 6 1 5 5 7 0 9 */
3414&(nid_objs[278]),/* OBJ_id_mod_qualified_cert_88 1 3 6 1 5 5 7 0 10 */
3415&(nid_objs[279]),/* OBJ_id_mod_qualified_cert_93 1 3 6 1 5 5 7 0 11 */
3416&(nid_objs[280]),/* OBJ_id_mod_attribute_cert 1 3 6 1 5 5 7 0 12 */
3417&(nid_objs[281]),/* OBJ_id_mod_timestamp_protocol 1 3 6 1 5 5 7 0 13 */
3418&(nid_objs[282]),/* OBJ_id_mod_ocsp 1 3 6 1 5 5 7 0 14 */
3419&(nid_objs[283]),/* OBJ_id_mod_dvcs 1 3 6 1 5 5 7 0 15 */
3420&(nid_objs[284]),/* OBJ_id_mod_cmp2000 1 3 6 1 5 5 7 0 16 */
3421&(nid_objs[177]),/* OBJ_info_access 1 3 6 1 5 5 7 1 1 */
3422&(nid_objs[285]),/* OBJ_biometricInfo 1 3 6 1 5 5 7 1 2 */
3423&(nid_objs[286]),/* OBJ_qcStatements 1 3 6 1 5 5 7 1 3 */
3424&(nid_objs[287]),/* OBJ_ac_auditEntity 1 3 6 1 5 5 7 1 4 */
3425&(nid_objs[288]),/* OBJ_ac_targeting 1 3 6 1 5 5 7 1 5 */
3426&(nid_objs[289]),/* OBJ_aaControls 1 3 6 1 5 5 7 1 6 */
3427&(nid_objs[290]),/* OBJ_sbgp_ipAddrBlock 1 3 6 1 5 5 7 1 7 */
3428&(nid_objs[291]),/* OBJ_sbgp_autonomousSysNum 1 3 6 1 5 5 7 1 8 */
3429&(nid_objs[292]),/* OBJ_sbgp_routerIdentifier 1 3 6 1 5 5 7 1 9 */
3430&(nid_objs[397]),/* OBJ_ac_proxying 1 3 6 1 5 5 7 1 10 */
3431&(nid_objs[398]),/* OBJ_sinfo_access 1 3 6 1 5 5 7 1 11 */
3432&(nid_objs[663]),/* OBJ_proxyCertInfo 1 3 6 1 5 5 7 1 14 */
3433&(nid_objs[164]),/* OBJ_id_qt_cps 1 3 6 1 5 5 7 2 1 */
3434&(nid_objs[165]),/* OBJ_id_qt_unotice 1 3 6 1 5 5 7 2 2 */
3435&(nid_objs[293]),/* OBJ_textNotice 1 3 6 1 5 5 7 2 3 */
3436&(nid_objs[129]),/* OBJ_server_auth 1 3 6 1 5 5 7 3 1 */
3437&(nid_objs[130]),/* OBJ_client_auth 1 3 6 1 5 5 7 3 2 */
3438&(nid_objs[131]),/* OBJ_code_sign 1 3 6 1 5 5 7 3 3 */
3439&(nid_objs[132]),/* OBJ_email_protect 1 3 6 1 5 5 7 3 4 */
3440&(nid_objs[294]),/* OBJ_ipsecEndSystem 1 3 6 1 5 5 7 3 5 */
3441&(nid_objs[295]),/* OBJ_ipsecTunnel 1 3 6 1 5 5 7 3 6 */
3442&(nid_objs[296]),/* OBJ_ipsecUser 1 3 6 1 5 5 7 3 7 */
3443&(nid_objs[133]),/* OBJ_time_stamp 1 3 6 1 5 5 7 3 8 */
3444&(nid_objs[180]),/* OBJ_OCSP_sign 1 3 6 1 5 5 7 3 9 */
3445&(nid_objs[297]),/* OBJ_dvcs 1 3 6 1 5 5 7 3 10 */
3446&(nid_objs[298]),/* OBJ_id_it_caProtEncCert 1 3 6 1 5 5 7 4 1 */
3447&(nid_objs[299]),/* OBJ_id_it_signKeyPairTypes 1 3 6 1 5 5 7 4 2 */
3448&(nid_objs[300]),/* OBJ_id_it_encKeyPairTypes 1 3 6 1 5 5 7 4 3 */
3449&(nid_objs[301]),/* OBJ_id_it_preferredSymmAlg 1 3 6 1 5 5 7 4 4 */
3450&(nid_objs[302]),/* OBJ_id_it_caKeyUpdateInfo 1 3 6 1 5 5 7 4 5 */
3451&(nid_objs[303]),/* OBJ_id_it_currentCRL 1 3 6 1 5 5 7 4 6 */
3452&(nid_objs[304]),/* OBJ_id_it_unsupportedOIDs 1 3 6 1 5 5 7 4 7 */
3453&(nid_objs[305]),/* OBJ_id_it_subscriptionRequest 1 3 6 1 5 5 7 4 8 */
3454&(nid_objs[306]),/* OBJ_id_it_subscriptionResponse 1 3 6 1 5 5 7 4 9 */
3455&(nid_objs[307]),/* OBJ_id_it_keyPairParamReq 1 3 6 1 5 5 7 4 10 */
3456&(nid_objs[308]),/* OBJ_id_it_keyPairParamRep 1 3 6 1 5 5 7 4 11 */
3457&(nid_objs[309]),/* OBJ_id_it_revPassphrase 1 3 6 1 5 5 7 4 12 */
3458&(nid_objs[310]),/* OBJ_id_it_implicitConfirm 1 3 6 1 5 5 7 4 13 */
3459&(nid_objs[311]),/* OBJ_id_it_confirmWaitTime 1 3 6 1 5 5 7 4 14 */
3460&(nid_objs[312]),/* OBJ_id_it_origPKIMessage 1 3 6 1 5 5 7 4 15 */
3461&(nid_objs[313]),/* OBJ_id_regCtrl 1 3 6 1 5 5 7 5 1 */
3462&(nid_objs[314]),/* OBJ_id_regInfo 1 3 6 1 5 5 7 5 2 */
3463&(nid_objs[323]),/* OBJ_id_alg_des40 1 3 6 1 5 5 7 6 1 */
3464&(nid_objs[324]),/* OBJ_id_alg_noSignature 1 3 6 1 5 5 7 6 2 */
3465&(nid_objs[325]),/* OBJ_id_alg_dh_sig_hmac_sha1 1 3 6 1 5 5 7 6 3 */
3466&(nid_objs[326]),/* OBJ_id_alg_dh_pop 1 3 6 1 5 5 7 6 4 */
3467&(nid_objs[327]),/* OBJ_id_cmc_statusInfo 1 3 6 1 5 5 7 7 1 */
3468&(nid_objs[328]),/* OBJ_id_cmc_identification 1 3 6 1 5 5 7 7 2 */
3469&(nid_objs[329]),/* OBJ_id_cmc_identityProof 1 3 6 1 5 5 7 7 3 */
3470&(nid_objs[330]),/* OBJ_id_cmc_dataReturn 1 3 6 1 5 5 7 7 4 */
3471&(nid_objs[331]),/* OBJ_id_cmc_transactionId 1 3 6 1 5 5 7 7 5 */
3472&(nid_objs[332]),/* OBJ_id_cmc_senderNonce 1 3 6 1 5 5 7 7 6 */
3473&(nid_objs[333]),/* OBJ_id_cmc_recipientNonce 1 3 6 1 5 5 7 7 7 */
3474&(nid_objs[334]),/* OBJ_id_cmc_addExtensions 1 3 6 1 5 5 7 7 8 */
3475&(nid_objs[335]),/* OBJ_id_cmc_encryptedPOP 1 3 6 1 5 5 7 7 9 */
3476&(nid_objs[336]),/* OBJ_id_cmc_decryptedPOP 1 3 6 1 5 5 7 7 10 */
3477&(nid_objs[337]),/* OBJ_id_cmc_lraPOPWitness 1 3 6 1 5 5 7 7 11 */
3478&(nid_objs[338]),/* OBJ_id_cmc_getCert 1 3 6 1 5 5 7 7 15 */
3479&(nid_objs[339]),/* OBJ_id_cmc_getCRL 1 3 6 1 5 5 7 7 16 */
3480&(nid_objs[340]),/* OBJ_id_cmc_revokeRequest 1 3 6 1 5 5 7 7 17 */
3481&(nid_objs[341]),/* OBJ_id_cmc_regInfo 1 3 6 1 5 5 7 7 18 */
3482&(nid_objs[342]),/* OBJ_id_cmc_responseInfo 1 3 6 1 5 5 7 7 19 */
3483&(nid_objs[343]),/* OBJ_id_cmc_queryPending 1 3 6 1 5 5 7 7 21 */
3484&(nid_objs[344]),/* OBJ_id_cmc_popLinkRandom 1 3 6 1 5 5 7 7 22 */
3485&(nid_objs[345]),/* OBJ_id_cmc_popLinkWitness 1 3 6 1 5 5 7 7 23 */
3486&(nid_objs[346]),/* OBJ_id_cmc_confirmCertAcceptance 1 3 6 1 5 5 7 7 24 */
3487&(nid_objs[347]),/* OBJ_id_on_personalData 1 3 6 1 5 5 7 8 1 */
3488&(nid_objs[348]),/* OBJ_id_pda_dateOfBirth 1 3 6 1 5 5 7 9 1 */
3489&(nid_objs[349]),/* OBJ_id_pda_placeOfBirth 1 3 6 1 5 5 7 9 2 */
3490&(nid_objs[351]),/* OBJ_id_pda_gender 1 3 6 1 5 5 7 9 3 */
3491&(nid_objs[352]),/* OBJ_id_pda_countryOfCitizenship 1 3 6 1 5 5 7 9 4 */
3492&(nid_objs[353]),/* OBJ_id_pda_countryOfResidence 1 3 6 1 5 5 7 9 5 */
3493&(nid_objs[354]),/* OBJ_id_aca_authenticationInfo 1 3 6 1 5 5 7 10 1 */
3494&(nid_objs[355]),/* OBJ_id_aca_accessIdentity 1 3 6 1 5 5 7 10 2 */
3495&(nid_objs[356]),/* OBJ_id_aca_chargingIdentity 1 3 6 1 5 5 7 10 3 */
3496&(nid_objs[357]),/* OBJ_id_aca_group 1 3 6 1 5 5 7 10 4 */
3497&(nid_objs[358]),/* OBJ_id_aca_role 1 3 6 1 5 5 7 10 5 */
3498&(nid_objs[399]),/* OBJ_id_aca_encAttrs 1 3 6 1 5 5 7 10 6 */
3499&(nid_objs[359]),/* OBJ_id_qcs_pkixQCSyntax_v1 1 3 6 1 5 5 7 11 1 */
3500&(nid_objs[360]),/* OBJ_id_cct_crs 1 3 6 1 5 5 7 12 1 */
3501&(nid_objs[361]),/* OBJ_id_cct_PKIData 1 3 6 1 5 5 7 12 2 */
3502&(nid_objs[362]),/* OBJ_id_cct_PKIResponse 1 3 6 1 5 5 7 12 3 */
3503&(nid_objs[664]),/* OBJ_id_ppl_anyLanguage 1 3 6 1 5 5 7 21 0 */
3504&(nid_objs[665]),/* OBJ_id_ppl_inheritAll 1 3 6 1 5 5 7 21 1 */
3505&(nid_objs[667]),/* OBJ_Independent 1 3 6 1 5 5 7 21 2 */
3506&(nid_objs[178]),/* OBJ_ad_OCSP 1 3 6 1 5 5 7 48 1 */
3507&(nid_objs[179]),/* OBJ_ad_ca_issuers 1 3 6 1 5 5 7 48 2 */
3508&(nid_objs[363]),/* OBJ_ad_timeStamping 1 3 6 1 5 5 7 48 3 */
3509&(nid_objs[364]),/* OBJ_ad_dvcs 1 3 6 1 5 5 7 48 4 */
3510&(nid_objs[58]),/* OBJ_netscape_cert_extension 2 16 840 1 113730 1 */
3511&(nid_objs[59]),/* OBJ_netscape_data_type 2 16 840 1 113730 2 */
3512&(nid_objs[438]),/* OBJ_pilotAttributeType 0 9 2342 19200300 100 1 */
3513&(nid_objs[439]),/* OBJ_pilotAttributeSyntax 0 9 2342 19200300 100 3 */
3514&(nid_objs[440]),/* OBJ_pilotObjectClass 0 9 2342 19200300 100 4 */
3515&(nid_objs[441]),/* OBJ_pilotGroups 0 9 2342 19200300 100 10 */
3516&(nid_objs[108]),/* OBJ_cast5_cbc 1 2 840 113533 7 66 10 */
3517&(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC 1 2 840 113533 7 66 12 */
3518&(nid_objs[ 6]),/* OBJ_rsaEncryption 1 2 840 113549 1 1 1 */
3519&(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption 1 2 840 113549 1 1 2 */
3520&(nid_objs[396]),/* OBJ_md4WithRSAEncryption 1 2 840 113549 1 1 3 */
3521&(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption 1 2 840 113549 1 1 4 */
3522&(nid_objs[65]),/* OBJ_sha1WithRSAEncryption 1 2 840 113549 1 1 5 */
3523&(nid_objs[644]),/* OBJ_rsaOAEPEncryptionSET 1 2 840 113549 1 1 6 */
3524&(nid_objs[668]),/* OBJ_sha256WithRSAEncryption 1 2 840 113549 1 1 11 */
3525&(nid_objs[669]),/* OBJ_sha384WithRSAEncryption 1 2 840 113549 1 1 12 */
3526&(nid_objs[670]),/* OBJ_sha512WithRSAEncryption 1 2 840 113549 1 1 13 */
3527&(nid_objs[671]),/* OBJ_sha224WithRSAEncryption 1 2 840 113549 1 1 14 */
3528&(nid_objs[28]),/* OBJ_dhKeyAgreement 1 2 840 113549 1 3 1 */
3529&(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC 1 2 840 113549 1 5 1 */
3530&(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC 1 2 840 113549 1 5 3 */
3531&(nid_objs[168]),/* OBJ_pbeWithMD2AndRC2_CBC 1 2 840 113549 1 5 4 */
3532&(nid_objs[169]),/* OBJ_pbeWithMD5AndRC2_CBC 1 2 840 113549 1 5 6 */
3533&(nid_objs[170]),/* OBJ_pbeWithSHA1AndDES_CBC 1 2 840 113549 1 5 10 */
3534&(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC 1 2 840 113549 1 5 11 */
3535&(nid_objs[69]),/* OBJ_id_pbkdf2 1 2 840 113549 1 5 12 */
3536&(nid_objs[161]),/* OBJ_pbes2 1 2 840 113549 1 5 13 */
3537&(nid_objs[162]),/* OBJ_pbmac1 1 2 840 113549 1 5 14 */
3538&(nid_objs[21]),/* OBJ_pkcs7_data 1 2 840 113549 1 7 1 */
3539&(nid_objs[22]),/* OBJ_pkcs7_signed 1 2 840 113549 1 7 2 */
3540&(nid_objs[23]),/* OBJ_pkcs7_enveloped 1 2 840 113549 1 7 3 */
3541&(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped 1 2 840 113549 1 7 4 */
3542&(nid_objs[25]),/* OBJ_pkcs7_digest 1 2 840 113549 1 7 5 */
3543&(nid_objs[26]),/* OBJ_pkcs7_encrypted 1 2 840 113549 1 7 6 */
3544&(nid_objs[48]),/* OBJ_pkcs9_emailAddress 1 2 840 113549 1 9 1 */
3545&(nid_objs[49]),/* OBJ_pkcs9_unstructuredName 1 2 840 113549 1 9 2 */
3546&(nid_objs[50]),/* OBJ_pkcs9_contentType 1 2 840 113549 1 9 3 */
3547&(nid_objs[51]),/* OBJ_pkcs9_messageDigest 1 2 840 113549 1 9 4 */
3548&(nid_objs[52]),/* OBJ_pkcs9_signingTime 1 2 840 113549 1 9 5 */
3549&(nid_objs[53]),/* OBJ_pkcs9_countersignature 1 2 840 113549 1 9 6 */
3550&(nid_objs[54]),/* OBJ_pkcs9_challengePassword 1 2 840 113549 1 9 7 */
3551&(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress 1 2 840 113549 1 9 8 */
3552&(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes 1 2 840 113549 1 9 9 */
3553&(nid_objs[172]),/* OBJ_ext_req 1 2 840 113549 1 9 14 */
3554&(nid_objs[167]),/* OBJ_SMIMECapabilities 1 2 840 113549 1 9 15 */
3555&(nid_objs[188]),/* OBJ_SMIME 1 2 840 113549 1 9 16 */
3556&(nid_objs[156]),/* OBJ_friendlyName 1 2 840 113549 1 9 20 */
3557&(nid_objs[157]),/* OBJ_localKeyID 1 2 840 113549 1 9 21 */
3558&(nid_objs[417]),/* OBJ_ms_csp_name 1 3 6 1 4 1 311 17 1 */
3559&(nid_objs[390]),/* OBJ_dcObject 1 3 6 1 4 1 1466 344 */
3560&(nid_objs[91]),/* OBJ_bf_cbc 1 3 6 1 4 1 3029 1 2 */
3561&(nid_objs[315]),/* OBJ_id_regCtrl_regToken 1 3 6 1 5 5 7 5 1 1 */
3562&(nid_objs[316]),/* OBJ_id_regCtrl_authenticator 1 3 6 1 5 5 7 5 1 2 */
3563&(nid_objs[317]),/* OBJ_id_regCtrl_pkiPublicationInfo 1 3 6 1 5 5 7 5 1 3 */
3564&(nid_objs[318]),/* OBJ_id_regCtrl_pkiArchiveOptions 1 3 6 1 5 5 7 5 1 4 */
3565&(nid_objs[319]),/* OBJ_id_regCtrl_oldCertID 1 3 6 1 5 5 7 5 1 5 */
3566&(nid_objs[320]),/* OBJ_id_regCtrl_protocolEncrKey 1 3 6 1 5 5 7 5 1 6 */
3567&(nid_objs[321]),/* OBJ_id_regInfo_utf8Pairs 1 3 6 1 5 5 7 5 2 1 */
3568&(nid_objs[322]),/* OBJ_id_regInfo_certReq 1 3 6 1 5 5 7 5 2 2 */
3569&(nid_objs[365]),/* OBJ_id_pkix_OCSP_basic 1 3 6 1 5 5 7 48 1 1 */
3570&(nid_objs[366]),/* OBJ_id_pkix_OCSP_Nonce 1 3 6 1 5 5 7 48 1 2 */
3571&(nid_objs[367]),/* OBJ_id_pkix_OCSP_CrlID 1 3 6 1 5 5 7 48 1 3 */
3572&(nid_objs[368]),/* OBJ_id_pkix_OCSP_acceptableResponses 1 3 6 1 5 5 7 48 1 4 */
3573&(nid_objs[369]),/* OBJ_id_pkix_OCSP_noCheck 1 3 6 1 5 5 7 48 1 5 */
3574&(nid_objs[370]),/* OBJ_id_pkix_OCSP_archiveCutoff 1 3 6 1 5 5 7 48 1 6 */
3575&(nid_objs[371]),/* OBJ_id_pkix_OCSP_serviceLocator 1 3 6 1 5 5 7 48 1 7 */
3576&(nid_objs[372]),/* OBJ_id_pkix_OCSP_extendedStatus 1 3 6 1 5 5 7 48 1 8 */
3577&(nid_objs[373]),/* OBJ_id_pkix_OCSP_valid 1 3 6 1 5 5 7 48 1 9 */
3578&(nid_objs[374]),/* OBJ_id_pkix_OCSP_path 1 3 6 1 5 5 7 48 1 10 */
3579&(nid_objs[375]),/* OBJ_id_pkix_OCSP_trustRoot 1 3 6 1 5 5 7 48 1 11 */
3580&(nid_objs[418]),/* OBJ_aes_128_ecb 2 16 840 1 101 3 4 1 1 */
3581&(nid_objs[419]),/* OBJ_aes_128_cbc 2 16 840 1 101 3 4 1 2 */
3582&(nid_objs[420]),/* OBJ_aes_128_ofb128 2 16 840 1 101 3 4 1 3 */
3583&(nid_objs[421]),/* OBJ_aes_128_cfb128 2 16 840 1 101 3 4 1 4 */
3584&(nid_objs[422]),/* OBJ_aes_192_ecb 2 16 840 1 101 3 4 1 21 */
3585&(nid_objs[423]),/* OBJ_aes_192_cbc 2 16 840 1 101 3 4 1 22 */
3586&(nid_objs[424]),/* OBJ_aes_192_ofb128 2 16 840 1 101 3 4 1 23 */
3587&(nid_objs[425]),/* OBJ_aes_192_cfb128 2 16 840 1 101 3 4 1 24 */
3588&(nid_objs[426]),/* OBJ_aes_256_ecb 2 16 840 1 101 3 4 1 41 */
3589&(nid_objs[427]),/* OBJ_aes_256_cbc 2 16 840 1 101 3 4 1 42 */
3590&(nid_objs[428]),/* OBJ_aes_256_ofb128 2 16 840 1 101 3 4 1 43 */
3591&(nid_objs[429]),/* OBJ_aes_256_cfb128 2 16 840 1 101 3 4 1 44 */
3592&(nid_objs[672]),/* OBJ_sha256 2 16 840 1 101 3 4 2 1 */
3593&(nid_objs[673]),/* OBJ_sha384 2 16 840 1 101 3 4 2 2 */
3594&(nid_objs[674]),/* OBJ_sha512 2 16 840 1 101 3 4 2 3 */
3595&(nid_objs[675]),/* OBJ_sha224 2 16 840 1 101 3 4 2 4 */
3596&(nid_objs[71]),/* OBJ_netscape_cert_type 2 16 840 1 113730 1 1 */
3597&(nid_objs[72]),/* OBJ_netscape_base_url 2 16 840 1 113730 1 2 */
3598&(nid_objs[73]),/* OBJ_netscape_revocation_url 2 16 840 1 113730 1 3 */
3599&(nid_objs[74]),/* OBJ_netscape_ca_revocation_url 2 16 840 1 113730 1 4 */
3600&(nid_objs[75]),/* OBJ_netscape_renewal_url 2 16 840 1 113730 1 7 */
3601&(nid_objs[76]),/* OBJ_netscape_ca_policy_url 2 16 840 1 113730 1 8 */
3602&(nid_objs[77]),/* OBJ_netscape_ssl_server_name 2 16 840 1 113730 1 12 */
3603&(nid_objs[78]),/* OBJ_netscape_comment 2 16 840 1 113730 1 13 */
3604&(nid_objs[79]),/* OBJ_netscape_cert_sequence 2 16 840 1 113730 2 5 */
3605&(nid_objs[139]),/* OBJ_ns_sgc 2 16 840 1 113730 4 1 */
3606&(nid_objs[458]),/* OBJ_userId 0 9 2342 19200300 100 1 1 */
3607&(nid_objs[459]),/* OBJ_textEncodedORAddress 0 9 2342 19200300 100 1 2 */
3608&(nid_objs[460]),/* OBJ_rfc822Mailbox 0 9 2342 19200300 100 1 3 */
3609&(nid_objs[461]),/* OBJ_info 0 9 2342 19200300 100 1 4 */
3610&(nid_objs[462]),/* OBJ_favouriteDrink 0 9 2342 19200300 100 1 5 */
3611&(nid_objs[463]),/* OBJ_roomNumber 0 9 2342 19200300 100 1 6 */
3612&(nid_objs[464]),/* OBJ_photo 0 9 2342 19200300 100 1 7 */
3613&(nid_objs[465]),/* OBJ_userClass 0 9 2342 19200300 100 1 8 */
3614&(nid_objs[466]),/* OBJ_host 0 9 2342 19200300 100 1 9 */
3615&(nid_objs[467]),/* OBJ_manager 0 9 2342 19200300 100 1 10 */
3616&(nid_objs[468]),/* OBJ_documentIdentifier 0 9 2342 19200300 100 1 11 */
3617&(nid_objs[469]),/* OBJ_documentTitle 0 9 2342 19200300 100 1 12 */
3618&(nid_objs[470]),/* OBJ_documentVersion 0 9 2342 19200300 100 1 13 */
3619&(nid_objs[471]),/* OBJ_documentAuthor 0 9 2342 19200300 100 1 14 */
3620&(nid_objs[472]),/* OBJ_documentLocation 0 9 2342 19200300 100 1 15 */
3621&(nid_objs[473]),/* OBJ_homeTelephoneNumber 0 9 2342 19200300 100 1 20 */
3622&(nid_objs[474]),/* OBJ_secretary 0 9 2342 19200300 100 1 21 */
3623&(nid_objs[475]),/* OBJ_otherMailbox 0 9 2342 19200300 100 1 22 */
3624&(nid_objs[476]),/* OBJ_lastModifiedTime 0 9 2342 19200300 100 1 23 */
3625&(nid_objs[477]),/* OBJ_lastModifiedBy 0 9 2342 19200300 100 1 24 */
3626&(nid_objs[391]),/* OBJ_domainComponent 0 9 2342 19200300 100 1 25 */
3627&(nid_objs[478]),/* OBJ_aRecord 0 9 2342 19200300 100 1 26 */
3628&(nid_objs[479]),/* OBJ_pilotAttributeType27 0 9 2342 19200300 100 1 27 */
3629&(nid_objs[480]),/* OBJ_mXRecord 0 9 2342 19200300 100 1 28 */
3630&(nid_objs[481]),/* OBJ_nSRecord 0 9 2342 19200300 100 1 29 */
3631&(nid_objs[482]),/* OBJ_sOARecord 0 9 2342 19200300 100 1 30 */
3632&(nid_objs[483]),/* OBJ_cNAMERecord 0 9 2342 19200300 100 1 31 */
3633&(nid_objs[484]),/* OBJ_associatedDomain 0 9 2342 19200300 100 1 37 */
3634&(nid_objs[485]),/* OBJ_associatedName 0 9 2342 19200300 100 1 38 */
3635&(nid_objs[486]),/* OBJ_homePostalAddress 0 9 2342 19200300 100 1 39 */
3636&(nid_objs[487]),/* OBJ_personalTitle 0 9 2342 19200300 100 1 40 */
3637&(nid_objs[488]),/* OBJ_mobileTelephoneNumber 0 9 2342 19200300 100 1 41 */
3638&(nid_objs[489]),/* OBJ_pagerTelephoneNumber 0 9 2342 19200300 100 1 42 */
3639&(nid_objs[490]),/* OBJ_friendlyCountryName 0 9 2342 19200300 100 1 43 */
3640&(nid_objs[491]),/* OBJ_organizationalStatus 0 9 2342 19200300 100 1 45 */
3641&(nid_objs[492]),/* OBJ_janetMailbox 0 9 2342 19200300 100 1 46 */
3642&(nid_objs[493]),/* OBJ_mailPreferenceOption 0 9 2342 19200300 100 1 47 */
3643&(nid_objs[494]),/* OBJ_buildingName 0 9 2342 19200300 100 1 48 */
3644&(nid_objs[495]),/* OBJ_dSAQuality 0 9 2342 19200300 100 1 49 */
3645&(nid_objs[496]),/* OBJ_singleLevelQuality 0 9 2342 19200300 100 1 50 */
3646&(nid_objs[497]),/* OBJ_subtreeMinimumQuality 0 9 2342 19200300 100 1 51 */
3647&(nid_objs[498]),/* OBJ_subtreeMaximumQuality 0 9 2342 19200300 100 1 52 */
3648&(nid_objs[499]),/* OBJ_personalSignature 0 9 2342 19200300 100 1 53 */
3649&(nid_objs[500]),/* OBJ_dITRedirect 0 9 2342 19200300 100 1 54 */
3650&(nid_objs[501]),/* OBJ_audio 0 9 2342 19200300 100 1 55 */
3651&(nid_objs[502]),/* OBJ_documentPublisher 0 9 2342 19200300 100 1 56 */
3652&(nid_objs[442]),/* OBJ_iA5StringSyntax 0 9 2342 19200300 100 3 4 */
3653&(nid_objs[443]),/* OBJ_caseIgnoreIA5StringSyntax 0 9 2342 19200300 100 3 5 */
3654&(nid_objs[444]),/* OBJ_pilotObject 0 9 2342 19200300 100 4 3 */
3655&(nid_objs[445]),/* OBJ_pilotPerson 0 9 2342 19200300 100 4 4 */
3656&(nid_objs[446]),/* OBJ_account 0 9 2342 19200300 100 4 5 */
3657&(nid_objs[447]),/* OBJ_document 0 9 2342 19200300 100 4 6 */
3658&(nid_objs[448]),/* OBJ_room 0 9 2342 19200300 100 4 7 */
3659&(nid_objs[449]),/* OBJ_documentSeries 0 9 2342 19200300 100 4 9 */
3660&(nid_objs[392]),/* OBJ_Domain 0 9 2342 19200300 100 4 13 */
3661&(nid_objs[450]),/* OBJ_rFC822localPart 0 9 2342 19200300 100 4 14 */
3662&(nid_objs[451]),/* OBJ_dNSDomain 0 9 2342 19200300 100 4 15 */
3663&(nid_objs[452]),/* OBJ_domainRelatedObject 0 9 2342 19200300 100 4 17 */
3664&(nid_objs[453]),/* OBJ_friendlyCountry 0 9 2342 19200300 100 4 18 */
3665&(nid_objs[454]),/* OBJ_simpleSecurityObject 0 9 2342 19200300 100 4 19 */
3666&(nid_objs[455]),/* OBJ_pilotOrganization 0 9 2342 19200300 100 4 20 */
3667&(nid_objs[456]),/* OBJ_pilotDSA 0 9 2342 19200300 100 4 21 */
3668&(nid_objs[457]),/* OBJ_qualityLabelledData 0 9 2342 19200300 100 4 22 */
3669&(nid_objs[189]),/* OBJ_id_smime_mod 1 2 840 113549 1 9 16 0 */
3670&(nid_objs[190]),/* OBJ_id_smime_ct 1 2 840 113549 1 9 16 1 */
3671&(nid_objs[191]),/* OBJ_id_smime_aa 1 2 840 113549 1 9 16 2 */
3672&(nid_objs[192]),/* OBJ_id_smime_alg 1 2 840 113549 1 9 16 3 */
3673&(nid_objs[193]),/* OBJ_id_smime_cd 1 2 840 113549 1 9 16 4 */
3674&(nid_objs[194]),/* OBJ_id_smime_spq 1 2 840 113549 1 9 16 5 */
3675&(nid_objs[195]),/* OBJ_id_smime_cti 1 2 840 113549 1 9 16 6 */
3676&(nid_objs[158]),/* OBJ_x509Certificate 1 2 840 113549 1 9 22 1 */
3677&(nid_objs[159]),/* OBJ_sdsiCertificate 1 2 840 113549 1 9 22 2 */
3678&(nid_objs[160]),/* OBJ_x509Crl 1 2 840 113549 1 9 23 1 */
3679&(nid_objs[144]),/* OBJ_pbe_WithSHA1And128BitRC4 1 2 840 113549 1 12 1 1 */
3680&(nid_objs[145]),/* OBJ_pbe_WithSHA1And40BitRC4 1 2 840 113549 1 12 1 2 */
3681&(nid_objs[146]),/* OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC 1 2 840 113549 1 12 1 3 */
3682&(nid_objs[147]),/* OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC 1 2 840 113549 1 12 1 4 */
3683&(nid_objs[148]),/* OBJ_pbe_WithSHA1And128BitRC2_CBC 1 2 840 113549 1 12 1 5 */
3684&(nid_objs[149]),/* OBJ_pbe_WithSHA1And40BitRC2_CBC 1 2 840 113549 1 12 1 6 */
3685&(nid_objs[171]),/* OBJ_ms_ext_req 1 3 6 1 4 1 311 2 1 14 */
3686&(nid_objs[134]),/* OBJ_ms_code_ind 1 3 6 1 4 1 311 2 1 21 */
3687&(nid_objs[135]),/* OBJ_ms_code_com 1 3 6 1 4 1 311 2 1 22 */
3688&(nid_objs[136]),/* OBJ_ms_ctl_sign 1 3 6 1 4 1 311 10 3 1 */
3689&(nid_objs[137]),/* OBJ_ms_sgc 1 3 6 1 4 1 311 10 3 3 */
3690&(nid_objs[138]),/* OBJ_ms_efs 1 3 6 1 4 1 311 10 3 4 */
3691&(nid_objs[648]),/* OBJ_ms_smartcard_login 1 3 6 1 4 1 311 20 2 2 */
3692&(nid_objs[649]),/* OBJ_ms_upn 1 3 6 1 4 1 311 20 2 3 */
3693&(nid_objs[196]),/* OBJ_id_smime_mod_cms 1 2 840 113549 1 9 16 0 1 */
3694&(nid_objs[197]),/* OBJ_id_smime_mod_ess 1 2 840 113549 1 9 16 0 2 */
3695&(nid_objs[198]),/* OBJ_id_smime_mod_oid 1 2 840 113549 1 9 16 0 3 */
3696&(nid_objs[199]),/* OBJ_id_smime_mod_msg_v3 1 2 840 113549 1 9 16 0 4 */
3697&(nid_objs[200]),/* OBJ_id_smime_mod_ets_eSignature_88 1 2 840 113549 1 9 16 0 5 */
3698&(nid_objs[201]),/* OBJ_id_smime_mod_ets_eSignature_97 1 2 840 113549 1 9 16 0 6 */
3699&(nid_objs[202]),/* OBJ_id_smime_mod_ets_eSigPolicy_88 1 2 840 113549 1 9 16 0 7 */
3700&(nid_objs[203]),/* OBJ_id_smime_mod_ets_eSigPolicy_97 1 2 840 113549 1 9 16 0 8 */
3701&(nid_objs[204]),/* OBJ_id_smime_ct_receipt 1 2 840 113549 1 9 16 1 1 */
3702&(nid_objs[205]),/* OBJ_id_smime_ct_authData 1 2 840 113549 1 9 16 1 2 */
3703&(nid_objs[206]),/* OBJ_id_smime_ct_publishCert 1 2 840 113549 1 9 16 1 3 */
3704&(nid_objs[207]),/* OBJ_id_smime_ct_TSTInfo 1 2 840 113549 1 9 16 1 4 */
3705&(nid_objs[208]),/* OBJ_id_smime_ct_TDTInfo 1 2 840 113549 1 9 16 1 5 */
3706&(nid_objs[209]),/* OBJ_id_smime_ct_contentInfo 1 2 840 113549 1 9 16 1 6 */
3707&(nid_objs[210]),/* OBJ_id_smime_ct_DVCSRequestData 1 2 840 113549 1 9 16 1 7 */
3708&(nid_objs[211]),/* OBJ_id_smime_ct_DVCSResponseData 1 2 840 113549 1 9 16 1 8 */
3709&(nid_objs[212]),/* OBJ_id_smime_aa_receiptRequest 1 2 840 113549 1 9 16 2 1 */
3710&(nid_objs[213]),/* OBJ_id_smime_aa_securityLabel 1 2 840 113549 1 9 16 2 2 */
3711&(nid_objs[214]),/* OBJ_id_smime_aa_mlExpandHistory 1 2 840 113549 1 9 16 2 3 */
3712&(nid_objs[215]),/* OBJ_id_smime_aa_contentHint 1 2 840 113549 1 9 16 2 4 */
3713&(nid_objs[216]),/* OBJ_id_smime_aa_msgSigDigest 1 2 840 113549 1 9 16 2 5 */
3714&(nid_objs[217]),/* OBJ_id_smime_aa_encapContentType 1 2 840 113549 1 9 16 2 6 */
3715&(nid_objs[218]),/* OBJ_id_smime_aa_contentIdentifier 1 2 840 113549 1 9 16 2 7 */
3716&(nid_objs[219]),/* OBJ_id_smime_aa_macValue 1 2 840 113549 1 9 16 2 8 */
3717&(nid_objs[220]),/* OBJ_id_smime_aa_equivalentLabels 1 2 840 113549 1 9 16 2 9 */
3718&(nid_objs[221]),/* OBJ_id_smime_aa_contentReference 1 2 840 113549 1 9 16 2 10 */
3719&(nid_objs[222]),/* OBJ_id_smime_aa_encrypKeyPref 1 2 840 113549 1 9 16 2 11 */
3720&(nid_objs[223]),/* OBJ_id_smime_aa_signingCertificate 1 2 840 113549 1 9 16 2 12 */
3721&(nid_objs[224]),/* OBJ_id_smime_aa_smimeEncryptCerts 1 2 840 113549 1 9 16 2 13 */
3722&(nid_objs[225]),/* OBJ_id_smime_aa_timeStampToken 1 2 840 113549 1 9 16 2 14 */
3723&(nid_objs[226]),/* OBJ_id_smime_aa_ets_sigPolicyId 1 2 840 113549 1 9 16 2 15 */
3724&(nid_objs[227]),/* OBJ_id_smime_aa_ets_commitmentType 1 2 840 113549 1 9 16 2 16 */
3725&(nid_objs[228]),/* OBJ_id_smime_aa_ets_signerLocation 1 2 840 113549 1 9 16 2 17 */
3726&(nid_objs[229]),/* OBJ_id_smime_aa_ets_signerAttr 1 2 840 113549 1 9 16 2 18 */
3727&(nid_objs[230]),/* OBJ_id_smime_aa_ets_otherSigCert 1 2 840 113549 1 9 16 2 19 */
3728&(nid_objs[231]),/* OBJ_id_smime_aa_ets_contentTimestamp 1 2 840 113549 1 9 16 2 20 */
3729&(nid_objs[232]),/* OBJ_id_smime_aa_ets_CertificateRefs 1 2 840 113549 1 9 16 2 21 */
3730&(nid_objs[233]),/* OBJ_id_smime_aa_ets_RevocationRefs 1 2 840 113549 1 9 16 2 22 */
3731&(nid_objs[234]),/* OBJ_id_smime_aa_ets_certValues 1 2 840 113549 1 9 16 2 23 */
3732&(nid_objs[235]),/* OBJ_id_smime_aa_ets_revocationValues 1 2 840 113549 1 9 16 2 24 */
3733&(nid_objs[236]),/* OBJ_id_smime_aa_ets_escTimeStamp 1 2 840 113549 1 9 16 2 25 */
3734&(nid_objs[237]),/* OBJ_id_smime_aa_ets_certCRLTimestamp 1 2 840 113549 1 9 16 2 26 */
3735&(nid_objs[238]),/* OBJ_id_smime_aa_ets_archiveTimeStamp 1 2 840 113549 1 9 16 2 27 */
3736&(nid_objs[239]),/* OBJ_id_smime_aa_signatureType 1 2 840 113549 1 9 16 2 28 */
3737&(nid_objs[240]),/* OBJ_id_smime_aa_dvcs_dvc 1 2 840 113549 1 9 16 2 29 */
3738&(nid_objs[241]),/* OBJ_id_smime_alg_ESDHwith3DES 1 2 840 113549 1 9 16 3 1 */
3739&(nid_objs[242]),/* OBJ_id_smime_alg_ESDHwithRC2 1 2 840 113549 1 9 16 3 2 */
3740&(nid_objs[243]),/* OBJ_id_smime_alg_3DESwrap 1 2 840 113549 1 9 16 3 3 */
3741&(nid_objs[244]),/* OBJ_id_smime_alg_RC2wrap 1 2 840 113549 1 9 16 3 4 */
3742&(nid_objs[245]),/* OBJ_id_smime_alg_ESDH 1 2 840 113549 1 9 16 3 5 */
3743&(nid_objs[246]),/* OBJ_id_smime_alg_CMS3DESwrap 1 2 840 113549 1 9 16 3 6 */
3744&(nid_objs[247]),/* OBJ_id_smime_alg_CMSRC2wrap 1 2 840 113549 1 9 16 3 7 */
3745&(nid_objs[248]),/* OBJ_id_smime_cd_ldap 1 2 840 113549 1 9 16 4 1 */
3746&(nid_objs[249]),/* OBJ_id_smime_spq_ets_sqt_uri 1 2 840 113549 1 9 16 5 1 */
3747&(nid_objs[250]),/* OBJ_id_smime_spq_ets_sqt_unotice 1 2 840 113549 1 9 16 5 2 */
3748&(nid_objs[251]),/* OBJ_id_smime_cti_ets_proofOfOrigin 1 2 840 113549 1 9 16 6 1 */
3749&(nid_objs[252]),/* OBJ_id_smime_cti_ets_proofOfReceipt 1 2 840 113549 1 9 16 6 2 */
3750&(nid_objs[253]),/* OBJ_id_smime_cti_ets_proofOfDelivery 1 2 840 113549 1 9 16 6 3 */
3751&(nid_objs[254]),/* OBJ_id_smime_cti_ets_proofOfSender 1 2 840 113549 1 9 16 6 4 */
3752&(nid_objs[255]),/* OBJ_id_smime_cti_ets_proofOfApproval 1 2 840 113549 1 9 16 6 5 */
3753&(nid_objs[256]),/* OBJ_id_smime_cti_ets_proofOfCreation 1 2 840 113549 1 9 16 6 6 */
3754&(nid_objs[150]),/* OBJ_keyBag 1 2 840 113549 1 12 10 1 1 */
3755&(nid_objs[151]),/* OBJ_pkcs8ShroudedKeyBag 1 2 840 113549 1 12 10 1 2 */
3756&(nid_objs[152]),/* OBJ_certBag 1 2 840 113549 1 12 10 1 3 */
3757&(nid_objs[153]),/* OBJ_crlBag 1 2 840 113549 1 12 10 1 4 */
3758&(nid_objs[154]),/* OBJ_secretBag 1 2 840 113549 1 12 10 1 5 */
3759&(nid_objs[155]),/* OBJ_safeContentsBag 1 2 840 113549 1 12 10 1 6 */
3760&(nid_objs[34]),/* OBJ_idea_cbc 1 3 6 1 4 1 188 7 1 1 2 */
3761};
3762
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
new file mode 100644
index 0000000000..d0371661f9
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_dat.pl
@@ -0,0 +1,307 @@
1#!/usr/local/bin/perl
2
3# fixes bug in floating point emulation on sparc64 when
4# this script produces off-by-one output on sparc64
5use integer;
6
7sub obj_cmp
8 {
9 local(@a,@b,$_,$r);
10
11 $A=$obj_len{$obj{$nid{$a}}};
12 $B=$obj_len{$obj{$nid{$b}}};
13
14 $r=($A-$B);
15 return($r) if $r != 0;
16
17 $A=$obj_der{$obj{$nid{$a}}};
18 $B=$obj_der{$obj{$nid{$b}}};
19
20 return($A cmp $B);
21 }
22
23sub expand_obj
24 {
25 local(*v)=@_;
26 local($k,$d);
27 local($i);
28
29 do {
30 $i=0;
31 foreach $k (keys %v)
32 {
33 if (($v{$k} =~ s/(OBJ_[^,]+),/$v{$1},/))
34 { $i++; }
35 }
36 } while($i);
37 foreach $k (keys %v)
38 {
39 @a=split(/,/,$v{$k});
40 $objn{$k}=$#a+1;
41 }
42 return(%objn);
43 }
44
45open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
46open (OUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
47
48while (<IN>)
49 {
50 next unless /^\#define\s+(\S+)\s+(.*)$/;
51 $v=$1;
52 $d=$2;
53 $d =~ s/^\"//;
54 $d =~ s/\"$//;
55 if ($v =~ /^SN_(.*)$/)
56 {
57 if(defined $snames{$d})
58 {
59 print "WARNING: Duplicate short name \"$d\"\n";
60 }
61 else
62 { $snames{$d} = "X"; }
63 $sn{$1}=$d;
64 }
65 elsif ($v =~ /^LN_(.*)$/)
66 {
67 if(defined $lnames{$d})
68 {
69 print "WARNING: Duplicate long name \"$d\"\n";
70 }
71 else
72 { $lnames{$d} = "X"; }
73 $ln{$1}=$d;
74 }
75 elsif ($v =~ /^NID_(.*)$/)
76 { $nid{$d}=$1; }
77 elsif ($v =~ /^OBJ_(.*)$/)
78 {
79 $obj{$1}=$v;
80 $objd{$v}=$d;
81 }
82 }
83close IN;
84
85%ob=&expand_obj(*objd);
86
87@a=sort { $a <=> $b } keys %nid;
88$n=$a[$#a]+1;
89
90@lvalues=();
91$lvalues=0;
92
93for ($i=0; $i<$n; $i++)
94 {
95 if (!defined($nid{$i}))
96 {
97 push(@out,"{NULL,NULL,NID_undef,0,NULL},\n");
98 }
99 else
100 {
101 $sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL";
102 $ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL";
103
104 if ($sn eq "NULL") {
105 $sn=$ln;
106 $sn{$nid{$i}} = $ln;
107 }
108
109 if ($ln eq "NULL") {
110 $ln=$sn;
111 $ln{$nid{$i}} = $sn;
112 }
113
114 $out ="{";
115 $out.="\"$sn\"";
116 $out.=","."\"$ln\"";
117 $out.=",NID_$nid{$i},";
118 if (defined($obj{$nid{$i}}))
119 {
120 $v=$objd{$obj{$nid{$i}}};
121 $v =~ s/L//g;
122 $v =~ s/,/ /g;
123 $r=&der_it($v);
124 $z="";
125 $length=0;
126 foreach (unpack("C*",$r))
127 {
128 $z.=sprintf("0x%02X,",$_);
129 $length++;
130 }
131 $obj_der{$obj{$nid{$i}}}=$z;
132 $obj_len{$obj{$nid{$i}}}=$length;
133
134 push(@lvalues,sprintf("%-45s/* [%3d] %s */\n",
135 $z,$lvalues,$obj{$nid{$i}}));
136 $out.="$length,&(lvalues[$lvalues]),0";
137 $lvalues+=$length;
138 }
139 else
140 {
141 $out.="0,NULL";
142 }
143 $out.="},\n";
144 push(@out,$out);
145 }
146 }
147
148@a=grep(defined($sn{$nid{$_}}),0 .. $n);
149foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
150 {
151 push(@sn,sprintf("&(nid_objs[%2d]),/* \"$sn{$nid{$_}}\" */\n",$_));
152 }
153
154@a=grep(defined($ln{$nid{$_}}),0 .. $n);
155foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
156 {
157 push(@ln,sprintf("&(nid_objs[%2d]),/* \"$ln{$nid{$_}}\" */\n",$_));
158 }
159
160@a=grep(defined($obj{$nid{$_}}),0 .. $n);
161foreach (sort obj_cmp @a)
162 {
163 $m=$obj{$nid{$_}};
164 $v=$objd{$m};
165 $v =~ s/L//g;
166 $v =~ s/,/ /g;
167 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
168 }
169
170print OUT <<'EOF';
171/* crypto/objects/obj_dat.h */
172
173/* THIS FILE IS GENERATED FROM objects.h by obj_dat.pl via the
174 * following command:
175 * perl obj_dat.pl obj_mac.h obj_dat.h
176 */
177
178/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
179 * All rights reserved.
180 *
181 * This package is an SSL implementation written
182 * by Eric Young (eay@cryptsoft.com).
183 * The implementation was written so as to conform with Netscapes SSL.
184 *
185 * This library is free for commercial and non-commercial use as long as
186 * the following conditions are aheared to. The following conditions
187 * apply to all code found in this distribution, be it the RC4, RSA,
188 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
189 * included with this distribution is covered by the same copyright terms
190 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
191 *
192 * Copyright remains Eric Young's, and as such any Copyright notices in
193 * the code are not to be removed.
194 * If this package is used in a product, Eric Young should be given attribution
195 * as the author of the parts of the library used.
196 * This can be in the form of a textual message at program startup or
197 * in documentation (online or textual) provided with the package.
198 *
199 * Redistribution and use in source and binary forms, with or without
200 * modification, are permitted provided that the following conditions
201 * are met:
202 * 1. Redistributions of source code must retain the copyright
203 * notice, this list of conditions and the following disclaimer.
204 * 2. Redistributions in binary form must reproduce the above copyright
205 * notice, this list of conditions and the following disclaimer in the
206 * documentation and/or other materials provided with the distribution.
207 * 3. All advertising materials mentioning features or use of this software
208 * must display the following acknowledgement:
209 * "This product includes cryptographic software written by
210 * Eric Young (eay@cryptsoft.com)"
211 * The word 'cryptographic' can be left out if the rouines from the library
212 * being used are not cryptographic related :-).
213 * 4. If you include any Windows specific code (or a derivative thereof) from
214 * the apps directory (application code) you must include an acknowledgement:
215 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
216 *
217 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
218 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
221 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
224 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
225 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
226 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
227 * SUCH DAMAGE.
228 *
229 * The licence and distribution terms for any publically available version or
230 * derivative of this code cannot be changed. i.e. this code cannot simply be
231 * copied and put under another distribution licence
232 * [including the GNU Public Licence.]
233 */
234
235EOF
236
237printf OUT "#define NUM_NID %d\n",$n;
238printf OUT "#define NUM_SN %d\n",$#sn+1;
239printf OUT "#define NUM_LN %d\n",$#ln+1;
240printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
241
242printf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
243print OUT @lvalues;
244print OUT "};\n\n";
245
246printf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
247foreach (@out)
248 {
249 if (length($_) > 75)
250 {
251 $out="";
252 foreach (split(/,/))
253 {
254 $t=$out.$_.",";
255 if (length($t) > 70)
256 {
257 print OUT "$out\n";
258 $t="\t$_,";
259 }
260 $out=$t;
261 }
262 chop $out;
263 print OUT "$out";
264 }
265 else
266 { print OUT $_; }
267 }
268print OUT "};\n\n";
269
270printf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
271print OUT @sn;
272print OUT "};\n\n";
273
274printf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
275print OUT @ln;
276print OUT "};\n\n";
277
278printf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
279print OUT @ob;
280print OUT "};\n\n";
281
282close OUT;
283
284sub der_it
285 {
286 local($v)=@_;
287 local(@a,$i,$ret,@r);
288
289 @a=split(/\s+/,$v);
290 $ret.=pack("C*",$a[0]*40+$a[1]);
291 shift @a;
292 shift @a;
293 foreach (@a)
294 {
295 @r=();
296 $t=0;
297 while ($_ >= 128)
298 {
299 $x=$_%128;
300 $_/=128;
301 push(@r,((($t++)?0x80:0)|$x));
302 }
303 push(@r,((($t++)?0x80:0)|$_));
304 $ret.=pack("C*",reverse(@r));
305 }
306 return($ret);
307 }
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
new file mode 100644
index 0000000000..2b5f43e3cc
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_err.c
@@ -0,0 +1,101 @@
1/* crypto/objects/obj_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/objects.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA OBJ_str_functs[]=
68 {
69{ERR_PACK(0,OBJ_F_OBJ_ADD_OBJECT,0), "OBJ_add_object"},
70{ERR_PACK(0,OBJ_F_OBJ_CREATE,0), "OBJ_create"},
71{ERR_PACK(0,OBJ_F_OBJ_DUP,0), "OBJ_dup"},
72{ERR_PACK(0,OBJ_F_OBJ_NAME_NEW_INDEX,0), "OBJ_NAME_new_index"},
73{ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"},
74{ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"},
75{ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"},
76{0,NULL}
77 };
78
79static ERR_STRING_DATA OBJ_str_reasons[]=
80 {
81{OBJ_R_MALLOC_FAILURE ,"malloc failure"},
82{OBJ_R_UNKNOWN_NID ,"unknown nid"},
83{0,NULL}
84 };
85
86#endif
87
88void ERR_load_OBJ_strings(void)
89 {
90 static int init=1;
91
92 if (init)
93 {
94 init=0;
95#ifndef OPENSSL_NO_ERR
96 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs);
97 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_reasons);
98#endif
99
100 }
101 }
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
new file mode 100644
index 0000000000..b0b0f2ff24
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -0,0 +1,127 @@
1/* crypto/objects/obj_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/lhash.h>
62#include <openssl/objects.h>
63#include <openssl/buffer.h>
64
65ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
66 {
67 ASN1_OBJECT *r;
68 int i;
69 char *ln=NULL;
70
71 if (o == NULL) return(NULL);
72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
73 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of
74 duplication is this??? */
75
76 r=ASN1_OBJECT_new();
77 if (r == NULL)
78 {
79 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
80 return(NULL);
81 }
82 r->data=OPENSSL_malloc(o->length);
83 if (r->data == NULL)
84 goto err;
85 memcpy(r->data,o->data,o->length);
86 r->length=o->length;
87 r->nid=o->nid;
88 r->ln=r->sn=NULL;
89 if (o->ln != NULL)
90 {
91 i=strlen(o->ln)+1;
92 r->ln=ln=OPENSSL_malloc(i);
93 if (r->ln == NULL) goto err;
94 memcpy(ln,o->ln,i);
95 }
96
97 if (o->sn != NULL)
98 {
99 char *s;
100
101 i=strlen(o->sn)+1;
102 r->sn=s=OPENSSL_malloc(i);
103 if (r->sn == NULL) goto err;
104 memcpy(s,o->sn,i);
105 }
106 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
107 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
108 return(r);
109err:
110 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
111 if (r != NULL)
112 {
113 if (ln != NULL) OPENSSL_free(ln);
114 if (r->data != NULL) OPENSSL_free(r->data);
115 OPENSSL_free(r);
116 }
117 return(NULL);
118 }
119
120int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
121 {
122 int ret;
123
124 ret=(a->length-b->length);
125 if (ret) return(ret);
126 return(memcmp(a->data,b->data,a->length));
127 }
diff --git a/src/lib/libcrypto/objects/obj_mac.h b/src/lib/libcrypto/objects/obj_mac.h
deleted file mode 100644
index 51bb50047f..0000000000
--- a/src/lib/libcrypto/objects/obj_mac.h
+++ /dev/null
@@ -1,2987 +0,0 @@
1/* crypto/objects/obj_mac.h */
2
3/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
4 * following command:
5 * perl objects.pl objects.txt obj_mac.num obj_mac.h
6 */
7
8/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
9 * All rights reserved.
10 *
11 * This package is an SSL implementation written
12 * by Eric Young (eay@cryptsoft.com).
13 * The implementation was written so as to conform with Netscapes SSL.
14 *
15 * This library is free for commercial and non-commercial use as long as
16 * the following conditions are aheared to. The following conditions
17 * apply to all code found in this distribution, be it the RC4, RSA,
18 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
19 * included with this distribution is covered by the same copyright terms
20 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
21 *
22 * Copyright remains Eric Young's, and as such any Copyright notices in
23 * the code are not to be removed.
24 * If this package is used in a product, Eric Young should be given attribution
25 * as the author of the parts of the library used.
26 * This can be in the form of a textual message at program startup or
27 * in documentation (online or textual) provided with the package.
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 * 1. Redistributions of source code must retain the copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * "This product includes cryptographic software written by
40 * Eric Young (eay@cryptsoft.com)"
41 * The word 'cryptographic' can be left out if the rouines from the library
42 * being used are not cryptographic related :-).
43 * 4. If you include any Windows specific code (or a derivative thereof) from
44 * the apps directory (application code) you must include an acknowledgement:
45 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
46 *
47 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 * The licence and distribution terms for any publically available version or
60 * derivative of this code cannot be changed. i.e. this code cannot simply be
61 * copied and put under another distribution licence
62 * [including the GNU Public Licence.]
63 */
64
65#define SN_undef "UNDEF"
66#define LN_undef "undefined"
67#define NID_undef 0
68#define OBJ_undef 0L
69
70#define SN_ccitt "CCITT"
71#define LN_ccitt "ccitt"
72#define NID_ccitt 404
73#define OBJ_ccitt 0L
74
75#define SN_iso "ISO"
76#define LN_iso "iso"
77#define NID_iso 181
78#define OBJ_iso 1L
79
80#define SN_joint_iso_ccitt "JOINT-ISO-CCITT"
81#define LN_joint_iso_ccitt "joint-iso-ccitt"
82#define NID_joint_iso_ccitt 393
83#define OBJ_joint_iso_ccitt 2L
84
85#define SN_member_body "member-body"
86#define LN_member_body "ISO Member Body"
87#define NID_member_body 182
88#define OBJ_member_body OBJ_iso,2L
89
90#define SN_selected_attribute_types "selected-attribute-types"
91#define LN_selected_attribute_types "Selected Attribute Types"
92#define NID_selected_attribute_types 394
93#define OBJ_selected_attribute_types OBJ_joint_iso_ccitt,5L,1L,5L
94
95#define SN_clearance "clearance"
96#define NID_clearance 395
97#define OBJ_clearance OBJ_selected_attribute_types,55L
98
99#define SN_ISO_US "ISO-US"
100#define LN_ISO_US "ISO US Member Body"
101#define NID_ISO_US 183
102#define OBJ_ISO_US OBJ_member_body,840L
103
104#define SN_X9_57 "X9-57"
105#define LN_X9_57 "X9.57"
106#define NID_X9_57 184
107#define OBJ_X9_57 OBJ_ISO_US,10040L
108
109#define SN_X9cm "X9cm"
110#define LN_X9cm "X9.57 CM ?"
111#define NID_X9cm 185
112#define OBJ_X9cm OBJ_X9_57,4L
113
114#define SN_dsa "DSA"
115#define LN_dsa "dsaEncryption"
116#define NID_dsa 116
117#define OBJ_dsa OBJ_X9cm,1L
118
119#define SN_dsaWithSHA1 "DSA-SHA1"
120#define LN_dsaWithSHA1 "dsaWithSHA1"
121#define NID_dsaWithSHA1 113
122#define OBJ_dsaWithSHA1 OBJ_X9cm,3L
123
124#define SN_ansi_X9_62 "ansi-X9-62"
125#define LN_ansi_X9_62 "ANSI X9.62"
126#define NID_ansi_X9_62 405
127#define OBJ_ansi_X9_62 OBJ_ISO_US,10045L
128
129#define OBJ_X9_62_id_fieldType OBJ_ansi_X9_62,1L
130
131#define SN_X9_62_prime_field "prime-field"
132#define NID_X9_62_prime_field 406
133#define OBJ_X9_62_prime_field OBJ_X9_62_id_fieldType,1L
134
135#define SN_X9_62_characteristic_two_field "characteristic-two-field"
136#define NID_X9_62_characteristic_two_field 407
137#define OBJ_X9_62_characteristic_two_field OBJ_X9_62_id_fieldType,2L
138
139#define OBJ_X9_62_id_publicKeyType OBJ_ansi_X9_62,2L
140
141#define SN_X9_62_id_ecPublicKey "id-ecPublicKey"
142#define NID_X9_62_id_ecPublicKey 408
143#define OBJ_X9_62_id_ecPublicKey OBJ_X9_62_id_publicKeyType,1L
144
145#define OBJ_X9_62_ellipticCurve OBJ_ansi_X9_62,3L
146
147#define OBJ_X9_62_c_TwoCurve OBJ_X9_62_ellipticCurve,0L
148
149#define OBJ_X9_62_primeCurve OBJ_X9_62_ellipticCurve,1L
150
151#define SN_X9_62_prime192v1 "prime192v1"
152#define NID_X9_62_prime192v1 409
153#define OBJ_X9_62_prime192v1 OBJ_X9_62_primeCurve,1L
154
155#define SN_X9_62_prime192v2 "prime192v2"
156#define NID_X9_62_prime192v2 410
157#define OBJ_X9_62_prime192v2 OBJ_X9_62_primeCurve,2L
158
159#define SN_X9_62_prime192v3 "prime192v3"
160#define NID_X9_62_prime192v3 411
161#define OBJ_X9_62_prime192v3 OBJ_X9_62_primeCurve,3L
162
163#define SN_X9_62_prime239v1 "prime239v1"
164#define NID_X9_62_prime239v1 412
165#define OBJ_X9_62_prime239v1 OBJ_X9_62_primeCurve,4L
166
167#define SN_X9_62_prime239v2 "prime239v2"
168#define NID_X9_62_prime239v2 413
169#define OBJ_X9_62_prime239v2 OBJ_X9_62_primeCurve,5L
170
171#define SN_X9_62_prime239v3 "prime239v3"
172#define NID_X9_62_prime239v3 414
173#define OBJ_X9_62_prime239v3 OBJ_X9_62_primeCurve,6L
174
175#define SN_X9_62_prime256v1 "prime256v1"
176#define NID_X9_62_prime256v1 415
177#define OBJ_X9_62_prime256v1 OBJ_X9_62_primeCurve,7L
178
179#define OBJ_X9_62_id_ecSigType OBJ_ansi_X9_62,4L
180
181#define SN_ecdsa_with_SHA1 "ecdsa-with-SHA1"
182#define NID_ecdsa_with_SHA1 416
183#define OBJ_ecdsa_with_SHA1 OBJ_X9_62_id_ecSigType,1L
184
185#define SN_cast5_cbc "CAST5-CBC"
186#define LN_cast5_cbc "cast5-cbc"
187#define NID_cast5_cbc 108
188#define OBJ_cast5_cbc OBJ_ISO_US,113533L,7L,66L,10L
189
190#define SN_cast5_ecb "CAST5-ECB"
191#define LN_cast5_ecb "cast5-ecb"
192#define NID_cast5_ecb 109
193
194#define SN_cast5_cfb64 "CAST5-CFB"
195#define LN_cast5_cfb64 "cast5-cfb"
196#define NID_cast5_cfb64 110
197
198#define SN_cast5_ofb64 "CAST5-OFB"
199#define LN_cast5_ofb64 "cast5-ofb"
200#define NID_cast5_ofb64 111
201
202#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
203#define NID_pbeWithMD5AndCast5_CBC 112
204#define OBJ_pbeWithMD5AndCast5_CBC OBJ_ISO_US,113533L,7L,66L,12L
205
206#define SN_rsadsi "rsadsi"
207#define LN_rsadsi "RSA Data Security, Inc."
208#define NID_rsadsi 1
209#define OBJ_rsadsi OBJ_ISO_US,113549L
210
211#define SN_pkcs "pkcs"
212#define LN_pkcs "RSA Data Security, Inc. PKCS"
213#define NID_pkcs 2
214#define OBJ_pkcs OBJ_rsadsi,1L
215
216#define SN_pkcs1 "pkcs1"
217#define NID_pkcs1 186
218#define OBJ_pkcs1 OBJ_pkcs,1L
219
220#define LN_rsaEncryption "rsaEncryption"
221#define NID_rsaEncryption 6
222#define OBJ_rsaEncryption OBJ_pkcs1,1L
223
224#define SN_md2WithRSAEncryption "RSA-MD2"
225#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
226#define NID_md2WithRSAEncryption 7
227#define OBJ_md2WithRSAEncryption OBJ_pkcs1,2L
228
229#define SN_md4WithRSAEncryption "RSA-MD4"
230#define LN_md4WithRSAEncryption "md4WithRSAEncryption"
231#define NID_md4WithRSAEncryption 396
232#define OBJ_md4WithRSAEncryption OBJ_pkcs1,3L
233
234#define SN_md5WithRSAEncryption "RSA-MD5"
235#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
236#define NID_md5WithRSAEncryption 8
237#define OBJ_md5WithRSAEncryption OBJ_pkcs1,4L
238
239#define SN_sha1WithRSAEncryption "RSA-SHA1"
240#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
241#define NID_sha1WithRSAEncryption 65
242#define OBJ_sha1WithRSAEncryption OBJ_pkcs1,5L
243
244#define SN_sha256WithRSAEncryption "RSA-SHA256"
245#define LN_sha256WithRSAEncryption "sha256WithRSAEncryption"
246#define NID_sha256WithRSAEncryption 668
247#define OBJ_sha256WithRSAEncryption OBJ_pkcs1,11L
248
249#define SN_sha384WithRSAEncryption "RSA-SHA384"
250#define LN_sha384WithRSAEncryption "sha384WithRSAEncryption"
251#define NID_sha384WithRSAEncryption 669
252#define OBJ_sha384WithRSAEncryption OBJ_pkcs1,12L
253
254#define SN_sha512WithRSAEncryption "RSA-SHA512"
255#define LN_sha512WithRSAEncryption "sha512WithRSAEncryption"
256#define NID_sha512WithRSAEncryption 670
257#define OBJ_sha512WithRSAEncryption OBJ_pkcs1,13L
258
259#define SN_sha224WithRSAEncryption "RSA-SHA224"
260#define LN_sha224WithRSAEncryption "sha224WithRSAEncryption"
261#define NID_sha224WithRSAEncryption 671
262#define OBJ_sha224WithRSAEncryption OBJ_pkcs1,14L
263
264#define SN_pkcs3 "pkcs3"
265#define NID_pkcs3 27
266#define OBJ_pkcs3 OBJ_pkcs,3L
267
268#define LN_dhKeyAgreement "dhKeyAgreement"
269#define NID_dhKeyAgreement 28
270#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
271
272#define SN_pkcs5 "pkcs5"
273#define NID_pkcs5 187
274#define OBJ_pkcs5 OBJ_pkcs,5L
275
276#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
277#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
278#define NID_pbeWithMD2AndDES_CBC 9
279#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs5,1L
280
281#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
282#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
283#define NID_pbeWithMD5AndDES_CBC 10
284#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs5,3L
285
286#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
287#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
288#define NID_pbeWithMD2AndRC2_CBC 168
289#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs5,4L
290
291#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
292#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
293#define NID_pbeWithMD5AndRC2_CBC 169
294#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs5,6L
295
296#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
297#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
298#define NID_pbeWithSHA1AndDES_CBC 170
299#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs5,10L
300
301#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
302#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
303#define NID_pbeWithSHA1AndRC2_CBC 68
304#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs5,11L
305
306#define LN_id_pbkdf2 "PBKDF2"
307#define NID_id_pbkdf2 69
308#define OBJ_id_pbkdf2 OBJ_pkcs5,12L
309
310#define LN_pbes2 "PBES2"
311#define NID_pbes2 161
312#define OBJ_pbes2 OBJ_pkcs5,13L
313
314#define LN_pbmac1 "PBMAC1"
315#define NID_pbmac1 162
316#define OBJ_pbmac1 OBJ_pkcs5,14L
317
318#define SN_pkcs7 "pkcs7"
319#define NID_pkcs7 20
320#define OBJ_pkcs7 OBJ_pkcs,7L
321
322#define LN_pkcs7_data "pkcs7-data"
323#define NID_pkcs7_data 21
324#define OBJ_pkcs7_data OBJ_pkcs7,1L
325
326#define LN_pkcs7_signed "pkcs7-signedData"
327#define NID_pkcs7_signed 22
328#define OBJ_pkcs7_signed OBJ_pkcs7,2L
329
330#define LN_pkcs7_enveloped "pkcs7-envelopedData"
331#define NID_pkcs7_enveloped 23
332#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
333
334#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
335#define NID_pkcs7_signedAndEnveloped 24
336#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
337
338#define LN_pkcs7_digest "pkcs7-digestData"
339#define NID_pkcs7_digest 25
340#define OBJ_pkcs7_digest OBJ_pkcs7,5L
341
342#define LN_pkcs7_encrypted "pkcs7-encryptedData"
343#define NID_pkcs7_encrypted 26
344#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
345
346#define SN_pkcs9 "pkcs9"
347#define NID_pkcs9 47
348#define OBJ_pkcs9 OBJ_pkcs,9L
349
350#define LN_pkcs9_emailAddress "emailAddress"
351#define NID_pkcs9_emailAddress 48
352#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
353
354#define LN_pkcs9_unstructuredName "unstructuredName"
355#define NID_pkcs9_unstructuredName 49
356#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
357
358#define LN_pkcs9_contentType "contentType"
359#define NID_pkcs9_contentType 50
360#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
361
362#define LN_pkcs9_messageDigest "messageDigest"
363#define NID_pkcs9_messageDigest 51
364#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
365
366#define LN_pkcs9_signingTime "signingTime"
367#define NID_pkcs9_signingTime 52
368#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
369
370#define LN_pkcs9_countersignature "countersignature"
371#define NID_pkcs9_countersignature 53
372#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
373
374#define LN_pkcs9_challengePassword "challengePassword"
375#define NID_pkcs9_challengePassword 54
376#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
377
378#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
379#define NID_pkcs9_unstructuredAddress 55
380#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
381
382#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
383#define NID_pkcs9_extCertAttributes 56
384#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
385
386#define SN_ext_req "extReq"
387#define LN_ext_req "Extension Request"
388#define NID_ext_req 172
389#define OBJ_ext_req OBJ_pkcs9,14L
390
391#define SN_SMIMECapabilities "SMIME-CAPS"
392#define LN_SMIMECapabilities "S/MIME Capabilities"
393#define NID_SMIMECapabilities 167
394#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
395
396#define SN_SMIME "SMIME"
397#define LN_SMIME "S/MIME"
398#define NID_SMIME 188
399#define OBJ_SMIME OBJ_pkcs9,16L
400
401#define SN_id_smime_mod "id-smime-mod"
402#define NID_id_smime_mod 189
403#define OBJ_id_smime_mod OBJ_SMIME,0L
404
405#define SN_id_smime_ct "id-smime-ct"
406#define NID_id_smime_ct 190
407#define OBJ_id_smime_ct OBJ_SMIME,1L
408
409#define SN_id_smime_aa "id-smime-aa"
410#define NID_id_smime_aa 191
411#define OBJ_id_smime_aa OBJ_SMIME,2L
412
413#define SN_id_smime_alg "id-smime-alg"
414#define NID_id_smime_alg 192
415#define OBJ_id_smime_alg OBJ_SMIME,3L
416
417#define SN_id_smime_cd "id-smime-cd"
418#define NID_id_smime_cd 193
419#define OBJ_id_smime_cd OBJ_SMIME,4L
420
421#define SN_id_smime_spq "id-smime-spq"
422#define NID_id_smime_spq 194
423#define OBJ_id_smime_spq OBJ_SMIME,5L
424
425#define SN_id_smime_cti "id-smime-cti"
426#define NID_id_smime_cti 195
427#define OBJ_id_smime_cti OBJ_SMIME,6L
428
429#define SN_id_smime_mod_cms "id-smime-mod-cms"
430#define NID_id_smime_mod_cms 196
431#define OBJ_id_smime_mod_cms OBJ_id_smime_mod,1L
432
433#define SN_id_smime_mod_ess "id-smime-mod-ess"
434#define NID_id_smime_mod_ess 197
435#define OBJ_id_smime_mod_ess OBJ_id_smime_mod,2L
436
437#define SN_id_smime_mod_oid "id-smime-mod-oid"
438#define NID_id_smime_mod_oid 198
439#define OBJ_id_smime_mod_oid OBJ_id_smime_mod,3L
440
441#define SN_id_smime_mod_msg_v3 "id-smime-mod-msg-v3"
442#define NID_id_smime_mod_msg_v3 199
443#define OBJ_id_smime_mod_msg_v3 OBJ_id_smime_mod,4L
444
445#define SN_id_smime_mod_ets_eSignature_88 "id-smime-mod-ets-eSignature-88"
446#define NID_id_smime_mod_ets_eSignature_88 200
447#define OBJ_id_smime_mod_ets_eSignature_88 OBJ_id_smime_mod,5L
448
449#define SN_id_smime_mod_ets_eSignature_97 "id-smime-mod-ets-eSignature-97"
450#define NID_id_smime_mod_ets_eSignature_97 201
451#define OBJ_id_smime_mod_ets_eSignature_97 OBJ_id_smime_mod,6L
452
453#define SN_id_smime_mod_ets_eSigPolicy_88 "id-smime-mod-ets-eSigPolicy-88"
454#define NID_id_smime_mod_ets_eSigPolicy_88 202
455#define OBJ_id_smime_mod_ets_eSigPolicy_88 OBJ_id_smime_mod,7L
456
457#define SN_id_smime_mod_ets_eSigPolicy_97 "id-smime-mod-ets-eSigPolicy-97"
458#define NID_id_smime_mod_ets_eSigPolicy_97 203
459#define OBJ_id_smime_mod_ets_eSigPolicy_97 OBJ_id_smime_mod,8L
460
461#define SN_id_smime_ct_receipt "id-smime-ct-receipt"
462#define NID_id_smime_ct_receipt 204
463#define OBJ_id_smime_ct_receipt OBJ_id_smime_ct,1L
464
465#define SN_id_smime_ct_authData "id-smime-ct-authData"
466#define NID_id_smime_ct_authData 205
467#define OBJ_id_smime_ct_authData OBJ_id_smime_ct,2L
468
469#define SN_id_smime_ct_publishCert "id-smime-ct-publishCert"
470#define NID_id_smime_ct_publishCert 206
471#define OBJ_id_smime_ct_publishCert OBJ_id_smime_ct,3L
472
473#define SN_id_smime_ct_TSTInfo "id-smime-ct-TSTInfo"
474#define NID_id_smime_ct_TSTInfo 207
475#define OBJ_id_smime_ct_TSTInfo OBJ_id_smime_ct,4L
476
477#define SN_id_smime_ct_TDTInfo "id-smime-ct-TDTInfo"
478#define NID_id_smime_ct_TDTInfo 208
479#define OBJ_id_smime_ct_TDTInfo OBJ_id_smime_ct,5L
480
481#define SN_id_smime_ct_contentInfo "id-smime-ct-contentInfo"
482#define NID_id_smime_ct_contentInfo 209
483#define OBJ_id_smime_ct_contentInfo OBJ_id_smime_ct,6L
484
485#define SN_id_smime_ct_DVCSRequestData "id-smime-ct-DVCSRequestData"
486#define NID_id_smime_ct_DVCSRequestData 210
487#define OBJ_id_smime_ct_DVCSRequestData OBJ_id_smime_ct,7L
488
489#define SN_id_smime_ct_DVCSResponseData "id-smime-ct-DVCSResponseData"
490#define NID_id_smime_ct_DVCSResponseData 211
491#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L
492
493#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest"
494#define NID_id_smime_aa_receiptRequest 212
495#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L
496
497#define SN_id_smime_aa_securityLabel "id-smime-aa-securityLabel"
498#define NID_id_smime_aa_securityLabel 213
499#define OBJ_id_smime_aa_securityLabel OBJ_id_smime_aa,2L
500
501#define SN_id_smime_aa_mlExpandHistory "id-smime-aa-mlExpandHistory"
502#define NID_id_smime_aa_mlExpandHistory 214
503#define OBJ_id_smime_aa_mlExpandHistory OBJ_id_smime_aa,3L
504
505#define SN_id_smime_aa_contentHint "id-smime-aa-contentHint"
506#define NID_id_smime_aa_contentHint 215
507#define OBJ_id_smime_aa_contentHint OBJ_id_smime_aa,4L
508
509#define SN_id_smime_aa_msgSigDigest "id-smime-aa-msgSigDigest"
510#define NID_id_smime_aa_msgSigDigest 216
511#define OBJ_id_smime_aa_msgSigDigest OBJ_id_smime_aa,5L
512
513#define SN_id_smime_aa_encapContentType "id-smime-aa-encapContentType"
514#define NID_id_smime_aa_encapContentType 217
515#define OBJ_id_smime_aa_encapContentType OBJ_id_smime_aa,6L
516
517#define SN_id_smime_aa_contentIdentifier "id-smime-aa-contentIdentifier"
518#define NID_id_smime_aa_contentIdentifier 218
519#define OBJ_id_smime_aa_contentIdentifier OBJ_id_smime_aa,7L
520
521#define SN_id_smime_aa_macValue "id-smime-aa-macValue"
522#define NID_id_smime_aa_macValue 219
523#define OBJ_id_smime_aa_macValue OBJ_id_smime_aa,8L
524
525#define SN_id_smime_aa_equivalentLabels "id-smime-aa-equivalentLabels"
526#define NID_id_smime_aa_equivalentLabels 220
527#define OBJ_id_smime_aa_equivalentLabels OBJ_id_smime_aa,9L
528
529#define SN_id_smime_aa_contentReference "id-smime-aa-contentReference"
530#define NID_id_smime_aa_contentReference 221
531#define OBJ_id_smime_aa_contentReference OBJ_id_smime_aa,10L
532
533#define SN_id_smime_aa_encrypKeyPref "id-smime-aa-encrypKeyPref"
534#define NID_id_smime_aa_encrypKeyPref 222
535#define OBJ_id_smime_aa_encrypKeyPref OBJ_id_smime_aa,11L
536
537#define SN_id_smime_aa_signingCertificate "id-smime-aa-signingCertificate"
538#define NID_id_smime_aa_signingCertificate 223
539#define OBJ_id_smime_aa_signingCertificate OBJ_id_smime_aa,12L
540
541#define SN_id_smime_aa_smimeEncryptCerts "id-smime-aa-smimeEncryptCerts"
542#define NID_id_smime_aa_smimeEncryptCerts 224
543#define OBJ_id_smime_aa_smimeEncryptCerts OBJ_id_smime_aa,13L
544
545#define SN_id_smime_aa_timeStampToken "id-smime-aa-timeStampToken"
546#define NID_id_smime_aa_timeStampToken 225
547#define OBJ_id_smime_aa_timeStampToken OBJ_id_smime_aa,14L
548
549#define SN_id_smime_aa_ets_sigPolicyId "id-smime-aa-ets-sigPolicyId"
550#define NID_id_smime_aa_ets_sigPolicyId 226
551#define OBJ_id_smime_aa_ets_sigPolicyId OBJ_id_smime_aa,15L
552
553#define SN_id_smime_aa_ets_commitmentType "id-smime-aa-ets-commitmentType"
554#define NID_id_smime_aa_ets_commitmentType 227
555#define OBJ_id_smime_aa_ets_commitmentType OBJ_id_smime_aa,16L
556
557#define SN_id_smime_aa_ets_signerLocation "id-smime-aa-ets-signerLocation"
558#define NID_id_smime_aa_ets_signerLocation 228
559#define OBJ_id_smime_aa_ets_signerLocation OBJ_id_smime_aa,17L
560
561#define SN_id_smime_aa_ets_signerAttr "id-smime-aa-ets-signerAttr"
562#define NID_id_smime_aa_ets_signerAttr 229
563#define OBJ_id_smime_aa_ets_signerAttr OBJ_id_smime_aa,18L
564
565#define SN_id_smime_aa_ets_otherSigCert "id-smime-aa-ets-otherSigCert"
566#define NID_id_smime_aa_ets_otherSigCert 230
567#define OBJ_id_smime_aa_ets_otherSigCert OBJ_id_smime_aa,19L
568
569#define SN_id_smime_aa_ets_contentTimestamp "id-smime-aa-ets-contentTimestamp"
570#define NID_id_smime_aa_ets_contentTimestamp 231
571#define OBJ_id_smime_aa_ets_contentTimestamp OBJ_id_smime_aa,20L
572
573#define SN_id_smime_aa_ets_CertificateRefs "id-smime-aa-ets-CertificateRefs"
574#define NID_id_smime_aa_ets_CertificateRefs 232
575#define OBJ_id_smime_aa_ets_CertificateRefs OBJ_id_smime_aa,21L
576
577#define SN_id_smime_aa_ets_RevocationRefs "id-smime-aa-ets-RevocationRefs"
578#define NID_id_smime_aa_ets_RevocationRefs 233
579#define OBJ_id_smime_aa_ets_RevocationRefs OBJ_id_smime_aa,22L
580
581#define SN_id_smime_aa_ets_certValues "id-smime-aa-ets-certValues"
582#define NID_id_smime_aa_ets_certValues 234
583#define OBJ_id_smime_aa_ets_certValues OBJ_id_smime_aa,23L
584
585#define SN_id_smime_aa_ets_revocationValues "id-smime-aa-ets-revocationValues"
586#define NID_id_smime_aa_ets_revocationValues 235
587#define OBJ_id_smime_aa_ets_revocationValues OBJ_id_smime_aa,24L
588
589#define SN_id_smime_aa_ets_escTimeStamp "id-smime-aa-ets-escTimeStamp"
590#define NID_id_smime_aa_ets_escTimeStamp 236
591#define OBJ_id_smime_aa_ets_escTimeStamp OBJ_id_smime_aa,25L
592
593#define SN_id_smime_aa_ets_certCRLTimestamp "id-smime-aa-ets-certCRLTimestamp"
594#define NID_id_smime_aa_ets_certCRLTimestamp 237
595#define OBJ_id_smime_aa_ets_certCRLTimestamp OBJ_id_smime_aa,26L
596
597#define SN_id_smime_aa_ets_archiveTimeStamp "id-smime-aa-ets-archiveTimeStamp"
598#define NID_id_smime_aa_ets_archiveTimeStamp 238
599#define OBJ_id_smime_aa_ets_archiveTimeStamp OBJ_id_smime_aa,27L
600
601#define SN_id_smime_aa_signatureType "id-smime-aa-signatureType"
602#define NID_id_smime_aa_signatureType 239
603#define OBJ_id_smime_aa_signatureType OBJ_id_smime_aa,28L
604
605#define SN_id_smime_aa_dvcs_dvc "id-smime-aa-dvcs-dvc"
606#define NID_id_smime_aa_dvcs_dvc 240
607#define OBJ_id_smime_aa_dvcs_dvc OBJ_id_smime_aa,29L
608
609#define SN_id_smime_alg_ESDHwith3DES "id-smime-alg-ESDHwith3DES"
610#define NID_id_smime_alg_ESDHwith3DES 241
611#define OBJ_id_smime_alg_ESDHwith3DES OBJ_id_smime_alg,1L
612
613#define SN_id_smime_alg_ESDHwithRC2 "id-smime-alg-ESDHwithRC2"
614#define NID_id_smime_alg_ESDHwithRC2 242
615#define OBJ_id_smime_alg_ESDHwithRC2 OBJ_id_smime_alg,2L
616
617#define SN_id_smime_alg_3DESwrap "id-smime-alg-3DESwrap"
618#define NID_id_smime_alg_3DESwrap 243
619#define OBJ_id_smime_alg_3DESwrap OBJ_id_smime_alg,3L
620
621#define SN_id_smime_alg_RC2wrap "id-smime-alg-RC2wrap"
622#define NID_id_smime_alg_RC2wrap 244
623#define OBJ_id_smime_alg_RC2wrap OBJ_id_smime_alg,4L
624
625#define SN_id_smime_alg_ESDH "id-smime-alg-ESDH"
626#define NID_id_smime_alg_ESDH 245
627#define OBJ_id_smime_alg_ESDH OBJ_id_smime_alg,5L
628
629#define SN_id_smime_alg_CMS3DESwrap "id-smime-alg-CMS3DESwrap"
630#define NID_id_smime_alg_CMS3DESwrap 246
631#define OBJ_id_smime_alg_CMS3DESwrap OBJ_id_smime_alg,6L
632
633#define SN_id_smime_alg_CMSRC2wrap "id-smime-alg-CMSRC2wrap"
634#define NID_id_smime_alg_CMSRC2wrap 247
635#define OBJ_id_smime_alg_CMSRC2wrap OBJ_id_smime_alg,7L
636
637#define SN_id_smime_cd_ldap "id-smime-cd-ldap"
638#define NID_id_smime_cd_ldap 248
639#define OBJ_id_smime_cd_ldap OBJ_id_smime_cd,1L
640
641#define SN_id_smime_spq_ets_sqt_uri "id-smime-spq-ets-sqt-uri"
642#define NID_id_smime_spq_ets_sqt_uri 249
643#define OBJ_id_smime_spq_ets_sqt_uri OBJ_id_smime_spq,1L
644
645#define SN_id_smime_spq_ets_sqt_unotice "id-smime-spq-ets-sqt-unotice"
646#define NID_id_smime_spq_ets_sqt_unotice 250
647#define OBJ_id_smime_spq_ets_sqt_unotice OBJ_id_smime_spq,2L
648
649#define SN_id_smime_cti_ets_proofOfOrigin "id-smime-cti-ets-proofOfOrigin"
650#define NID_id_smime_cti_ets_proofOfOrigin 251
651#define OBJ_id_smime_cti_ets_proofOfOrigin OBJ_id_smime_cti,1L
652
653#define SN_id_smime_cti_ets_proofOfReceipt "id-smime-cti-ets-proofOfReceipt"
654#define NID_id_smime_cti_ets_proofOfReceipt 252
655#define OBJ_id_smime_cti_ets_proofOfReceipt OBJ_id_smime_cti,2L
656
657#define SN_id_smime_cti_ets_proofOfDelivery "id-smime-cti-ets-proofOfDelivery"
658#define NID_id_smime_cti_ets_proofOfDelivery 253
659#define OBJ_id_smime_cti_ets_proofOfDelivery OBJ_id_smime_cti,3L
660
661#define SN_id_smime_cti_ets_proofOfSender "id-smime-cti-ets-proofOfSender"
662#define NID_id_smime_cti_ets_proofOfSender 254
663#define OBJ_id_smime_cti_ets_proofOfSender OBJ_id_smime_cti,4L
664
665#define SN_id_smime_cti_ets_proofOfApproval "id-smime-cti-ets-proofOfApproval"
666#define NID_id_smime_cti_ets_proofOfApproval 255
667#define OBJ_id_smime_cti_ets_proofOfApproval OBJ_id_smime_cti,5L
668
669#define SN_id_smime_cti_ets_proofOfCreation "id-smime-cti-ets-proofOfCreation"
670#define NID_id_smime_cti_ets_proofOfCreation 256
671#define OBJ_id_smime_cti_ets_proofOfCreation OBJ_id_smime_cti,6L
672
673#define LN_friendlyName "friendlyName"
674#define NID_friendlyName 156
675#define OBJ_friendlyName OBJ_pkcs9,20L
676
677#define LN_localKeyID "localKeyID"
678#define NID_localKeyID 157
679#define OBJ_localKeyID OBJ_pkcs9,21L
680
681#define SN_ms_csp_name "CSPName"
682#define LN_ms_csp_name "Microsoft CSP Name"
683#define NID_ms_csp_name 417
684#define OBJ_ms_csp_name 1L,3L,6L,1L,4L,1L,311L,17L,1L
685
686#define OBJ_certTypes OBJ_pkcs9,22L
687
688#define LN_x509Certificate "x509Certificate"
689#define NID_x509Certificate 158
690#define OBJ_x509Certificate OBJ_certTypes,1L
691
692#define LN_sdsiCertificate "sdsiCertificate"
693#define NID_sdsiCertificate 159
694#define OBJ_sdsiCertificate OBJ_certTypes,2L
695
696#define OBJ_crlTypes OBJ_pkcs9,23L
697
698#define LN_x509Crl "x509Crl"
699#define NID_x509Crl 160
700#define OBJ_x509Crl OBJ_crlTypes,1L
701
702#define OBJ_pkcs12 OBJ_pkcs,12L
703
704#define OBJ_pkcs12_pbeids OBJ_pkcs12,1L
705
706#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
707#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
708#define NID_pbe_WithSHA1And128BitRC4 144
709#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids,1L
710
711#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
712#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
713#define NID_pbe_WithSHA1And40BitRC4 145
714#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids,2L
715
716#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
717#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
718#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
719#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids,3L
720
721#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
722#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
723#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
724#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids,4L
725
726#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
727#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
728#define NID_pbe_WithSHA1And128BitRC2_CBC 148
729#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids,5L
730
731#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
732#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
733#define NID_pbe_WithSHA1And40BitRC2_CBC 149
734#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids,6L
735
736#define OBJ_pkcs12_Version1 OBJ_pkcs12,10L
737
738#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1,1L
739
740#define LN_keyBag "keyBag"
741#define NID_keyBag 150
742#define OBJ_keyBag OBJ_pkcs12_BagIds,1L
743
744#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
745#define NID_pkcs8ShroudedKeyBag 151
746#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds,2L
747
748#define LN_certBag "certBag"
749#define NID_certBag 152
750#define OBJ_certBag OBJ_pkcs12_BagIds,3L
751
752#define LN_crlBag "crlBag"
753#define NID_crlBag 153
754#define OBJ_crlBag OBJ_pkcs12_BagIds,4L
755
756#define LN_secretBag "secretBag"
757#define NID_secretBag 154
758#define OBJ_secretBag OBJ_pkcs12_BagIds,5L
759
760#define LN_safeContentsBag "safeContentsBag"
761#define NID_safeContentsBag 155
762#define OBJ_safeContentsBag OBJ_pkcs12_BagIds,6L
763
764#define SN_md2 "MD2"
765#define LN_md2 "md2"
766#define NID_md2 3
767#define OBJ_md2 OBJ_rsadsi,2L,2L
768
769#define SN_md4 "MD4"
770#define LN_md4 "md4"
771#define NID_md4 257
772#define OBJ_md4 OBJ_rsadsi,2L,4L
773
774#define SN_md5 "MD5"
775#define LN_md5 "md5"
776#define NID_md5 4
777#define OBJ_md5 OBJ_rsadsi,2L,5L
778
779#define SN_md5_sha1 "MD5-SHA1"
780#define LN_md5_sha1 "md5-sha1"
781#define NID_md5_sha1 114
782
783#define LN_hmacWithSHA1 "hmacWithSHA1"
784#define NID_hmacWithSHA1 163
785#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
786
787#define SN_rc2_cbc "RC2-CBC"
788#define LN_rc2_cbc "rc2-cbc"
789#define NID_rc2_cbc 37
790#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
791
792#define SN_rc2_ecb "RC2-ECB"
793#define LN_rc2_ecb "rc2-ecb"
794#define NID_rc2_ecb 38
795
796#define SN_rc2_cfb64 "RC2-CFB"
797#define LN_rc2_cfb64 "rc2-cfb"
798#define NID_rc2_cfb64 39
799
800#define SN_rc2_ofb64 "RC2-OFB"
801#define LN_rc2_ofb64 "rc2-ofb"
802#define NID_rc2_ofb64 40
803
804#define SN_rc2_40_cbc "RC2-40-CBC"
805#define LN_rc2_40_cbc "rc2-40-cbc"
806#define NID_rc2_40_cbc 98
807
808#define SN_rc2_64_cbc "RC2-64-CBC"
809#define LN_rc2_64_cbc "rc2-64-cbc"
810#define NID_rc2_64_cbc 166
811
812#define SN_rc4 "RC4"
813#define LN_rc4 "rc4"
814#define NID_rc4 5
815#define OBJ_rc4 OBJ_rsadsi,3L,4L
816
817#define SN_rc4_40 "RC4-40"
818#define LN_rc4_40 "rc4-40"
819#define NID_rc4_40 97
820
821#define SN_des_ede3_cbc "DES-EDE3-CBC"
822#define LN_des_ede3_cbc "des-ede3-cbc"
823#define NID_des_ede3_cbc 44
824#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
825
826#define SN_rc5_cbc "RC5-CBC"
827#define LN_rc5_cbc "rc5-cbc"
828#define NID_rc5_cbc 120
829#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
830
831#define SN_rc5_ecb "RC5-ECB"
832#define LN_rc5_ecb "rc5-ecb"
833#define NID_rc5_ecb 121
834
835#define SN_rc5_cfb64 "RC5-CFB"
836#define LN_rc5_cfb64 "rc5-cfb"
837#define NID_rc5_cfb64 122
838
839#define SN_rc5_ofb64 "RC5-OFB"
840#define LN_rc5_ofb64 "rc5-ofb"
841#define NID_rc5_ofb64 123
842
843#define SN_ms_ext_req "msExtReq"
844#define LN_ms_ext_req "Microsoft Extension Request"
845#define NID_ms_ext_req 171
846#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
847
848#define SN_ms_code_ind "msCodeInd"
849#define LN_ms_code_ind "Microsoft Individual Code Signing"
850#define NID_ms_code_ind 134
851#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
852
853#define SN_ms_code_com "msCodeCom"
854#define LN_ms_code_com "Microsoft Commercial Code Signing"
855#define NID_ms_code_com 135
856#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
857
858#define SN_ms_ctl_sign "msCTLSign"
859#define LN_ms_ctl_sign "Microsoft Trust List Signing"
860#define NID_ms_ctl_sign 136
861#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
862
863#define SN_ms_sgc "msSGC"
864#define LN_ms_sgc "Microsoft Server Gated Crypto"
865#define NID_ms_sgc 137
866#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
867
868#define SN_ms_efs "msEFS"
869#define LN_ms_efs "Microsoft Encrypted File System"
870#define NID_ms_efs 138
871#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
872
873#define SN_ms_smartcard_login "msSmartcardLogin"
874#define LN_ms_smartcard_login "Microsoft Smartcardlogin"
875#define NID_ms_smartcard_login 648
876#define OBJ_ms_smartcard_login 1L,3L,6L,1L,4L,1L,311L,20L,2L,2L
877
878#define SN_ms_upn "msUPN"
879#define LN_ms_upn "Microsoft Universal Principal Name"
880#define NID_ms_upn 649
881#define OBJ_ms_upn 1L,3L,6L,1L,4L,1L,311L,20L,2L,3L
882
883#define SN_idea_cbc "IDEA-CBC"
884#define LN_idea_cbc "idea-cbc"
885#define NID_idea_cbc 34
886#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
887
888#define SN_idea_ecb "IDEA-ECB"
889#define LN_idea_ecb "idea-ecb"
890#define NID_idea_ecb 36
891
892#define SN_idea_cfb64 "IDEA-CFB"
893#define LN_idea_cfb64 "idea-cfb"
894#define NID_idea_cfb64 35
895
896#define SN_idea_ofb64 "IDEA-OFB"
897#define LN_idea_ofb64 "idea-ofb"
898#define NID_idea_ofb64 46
899
900#define SN_bf_cbc "BF-CBC"
901#define LN_bf_cbc "bf-cbc"
902#define NID_bf_cbc 91
903#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
904
905#define SN_bf_ecb "BF-ECB"
906#define LN_bf_ecb "bf-ecb"
907#define NID_bf_ecb 92
908
909#define SN_bf_cfb64 "BF-CFB"
910#define LN_bf_cfb64 "bf-cfb"
911#define NID_bf_cfb64 93
912
913#define SN_bf_ofb64 "BF-OFB"
914#define LN_bf_ofb64 "bf-ofb"
915#define NID_bf_ofb64 94
916
917#define SN_id_pkix "PKIX"
918#define NID_id_pkix 127
919#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
920
921#define SN_id_pkix_mod "id-pkix-mod"
922#define NID_id_pkix_mod 258
923#define OBJ_id_pkix_mod OBJ_id_pkix,0L
924
925#define SN_id_pe "id-pe"
926#define NID_id_pe 175
927#define OBJ_id_pe OBJ_id_pkix,1L
928
929#define SN_id_qt "id-qt"
930#define NID_id_qt 259
931#define OBJ_id_qt OBJ_id_pkix,2L
932
933#define SN_id_kp "id-kp"
934#define NID_id_kp 128
935#define OBJ_id_kp OBJ_id_pkix,3L
936
937#define SN_id_it "id-it"
938#define NID_id_it 260
939#define OBJ_id_it OBJ_id_pkix,4L
940
941#define SN_id_pkip "id-pkip"
942#define NID_id_pkip 261
943#define OBJ_id_pkip OBJ_id_pkix,5L
944
945#define SN_id_alg "id-alg"
946#define NID_id_alg 262
947#define OBJ_id_alg OBJ_id_pkix,6L
948
949#define SN_id_cmc "id-cmc"
950#define NID_id_cmc 263
951#define OBJ_id_cmc OBJ_id_pkix,7L
952
953#define SN_id_on "id-on"
954#define NID_id_on 264
955#define OBJ_id_on OBJ_id_pkix,8L
956
957#define SN_id_pda "id-pda"
958#define NID_id_pda 265
959#define OBJ_id_pda OBJ_id_pkix,9L
960
961#define SN_id_aca "id-aca"
962#define NID_id_aca 266
963#define OBJ_id_aca OBJ_id_pkix,10L
964
965#define SN_id_qcs "id-qcs"
966#define NID_id_qcs 267
967#define OBJ_id_qcs OBJ_id_pkix,11L
968
969#define SN_id_cct "id-cct"
970#define NID_id_cct 268
971#define OBJ_id_cct OBJ_id_pkix,12L
972
973#define SN_id_ppl "id-ppl"
974#define NID_id_ppl 662
975#define OBJ_id_ppl OBJ_id_pkix,21L
976
977#define SN_id_ad "id-ad"
978#define NID_id_ad 176
979#define OBJ_id_ad OBJ_id_pkix,48L
980
981#define SN_id_pkix1_explicit_88 "id-pkix1-explicit-88"
982#define NID_id_pkix1_explicit_88 269
983#define OBJ_id_pkix1_explicit_88 OBJ_id_pkix_mod,1L
984
985#define SN_id_pkix1_implicit_88 "id-pkix1-implicit-88"
986#define NID_id_pkix1_implicit_88 270
987#define OBJ_id_pkix1_implicit_88 OBJ_id_pkix_mod,2L
988
989#define SN_id_pkix1_explicit_93 "id-pkix1-explicit-93"
990#define NID_id_pkix1_explicit_93 271
991#define OBJ_id_pkix1_explicit_93 OBJ_id_pkix_mod,3L
992
993#define SN_id_pkix1_implicit_93 "id-pkix1-implicit-93"
994#define NID_id_pkix1_implicit_93 272
995#define OBJ_id_pkix1_implicit_93 OBJ_id_pkix_mod,4L
996
997#define SN_id_mod_crmf "id-mod-crmf"
998#define NID_id_mod_crmf 273
999#define OBJ_id_mod_crmf OBJ_id_pkix_mod,5L
1000
1001#define SN_id_mod_cmc "id-mod-cmc"
1002#define NID_id_mod_cmc 274
1003#define OBJ_id_mod_cmc OBJ_id_pkix_mod,6L
1004
1005#define SN_id_mod_kea_profile_88 "id-mod-kea-profile-88"
1006#define NID_id_mod_kea_profile_88 275
1007#define OBJ_id_mod_kea_profile_88 OBJ_id_pkix_mod,7L
1008
1009#define SN_id_mod_kea_profile_93 "id-mod-kea-profile-93"
1010#define NID_id_mod_kea_profile_93 276
1011#define OBJ_id_mod_kea_profile_93 OBJ_id_pkix_mod,8L
1012
1013#define SN_id_mod_cmp "id-mod-cmp"
1014#define NID_id_mod_cmp 277
1015#define OBJ_id_mod_cmp OBJ_id_pkix_mod,9L
1016
1017#define SN_id_mod_qualified_cert_88 "id-mod-qualified-cert-88"
1018#define NID_id_mod_qualified_cert_88 278
1019#define OBJ_id_mod_qualified_cert_88 OBJ_id_pkix_mod,10L
1020
1021#define SN_id_mod_qualified_cert_93 "id-mod-qualified-cert-93"
1022#define NID_id_mod_qualified_cert_93 279
1023#define OBJ_id_mod_qualified_cert_93 OBJ_id_pkix_mod,11L
1024
1025#define SN_id_mod_attribute_cert "id-mod-attribute-cert"
1026#define NID_id_mod_attribute_cert 280
1027#define OBJ_id_mod_attribute_cert OBJ_id_pkix_mod,12L
1028
1029#define SN_id_mod_timestamp_protocol "id-mod-timestamp-protocol"
1030#define NID_id_mod_timestamp_protocol 281
1031#define OBJ_id_mod_timestamp_protocol OBJ_id_pkix_mod,13L
1032
1033#define SN_id_mod_ocsp "id-mod-ocsp"
1034#define NID_id_mod_ocsp 282
1035#define OBJ_id_mod_ocsp OBJ_id_pkix_mod,14L
1036
1037#define SN_id_mod_dvcs "id-mod-dvcs"
1038#define NID_id_mod_dvcs 283
1039#define OBJ_id_mod_dvcs OBJ_id_pkix_mod,15L
1040
1041#define SN_id_mod_cmp2000 "id-mod-cmp2000"
1042#define NID_id_mod_cmp2000 284
1043#define OBJ_id_mod_cmp2000 OBJ_id_pkix_mod,16L
1044
1045#define SN_info_access "authorityInfoAccess"
1046#define LN_info_access "Authority Information Access"
1047#define NID_info_access 177
1048#define OBJ_info_access OBJ_id_pe,1L
1049
1050#define SN_biometricInfo "biometricInfo"
1051#define LN_biometricInfo "Biometric Info"
1052#define NID_biometricInfo 285
1053#define OBJ_biometricInfo OBJ_id_pe,2L
1054
1055#define SN_qcStatements "qcStatements"
1056#define NID_qcStatements 286
1057#define OBJ_qcStatements OBJ_id_pe,3L
1058
1059#define SN_ac_auditEntity "ac-auditEntity"
1060#define NID_ac_auditEntity 287
1061#define OBJ_ac_auditEntity OBJ_id_pe,4L
1062
1063#define SN_ac_targeting "ac-targeting"
1064#define NID_ac_targeting 288
1065#define OBJ_ac_targeting OBJ_id_pe,5L
1066
1067#define SN_aaControls "aaControls"
1068#define NID_aaControls 289
1069#define OBJ_aaControls OBJ_id_pe,6L
1070
1071#define SN_sbgp_ipAddrBlock "sbgp-ipAddrBlock"
1072#define NID_sbgp_ipAddrBlock 290
1073#define OBJ_sbgp_ipAddrBlock OBJ_id_pe,7L
1074
1075#define SN_sbgp_autonomousSysNum "sbgp-autonomousSysNum"
1076#define NID_sbgp_autonomousSysNum 291
1077#define OBJ_sbgp_autonomousSysNum OBJ_id_pe,8L
1078
1079#define SN_sbgp_routerIdentifier "sbgp-routerIdentifier"
1080#define NID_sbgp_routerIdentifier 292
1081#define OBJ_sbgp_routerIdentifier OBJ_id_pe,9L
1082
1083#define SN_ac_proxying "ac-proxying"
1084#define NID_ac_proxying 397
1085#define OBJ_ac_proxying OBJ_id_pe,10L
1086
1087#define SN_sinfo_access "subjectInfoAccess"
1088#define LN_sinfo_access "Subject Information Access"
1089#define NID_sinfo_access 398
1090#define OBJ_sinfo_access OBJ_id_pe,11L
1091
1092#define SN_proxyCertInfo "proxyCertInfo"
1093#define LN_proxyCertInfo "Proxy Certificate Information"
1094#define NID_proxyCertInfo 663
1095#define OBJ_proxyCertInfo OBJ_id_pe,14L
1096
1097#define SN_id_qt_cps "id-qt-cps"
1098#define LN_id_qt_cps "Policy Qualifier CPS"
1099#define NID_id_qt_cps 164
1100#define OBJ_id_qt_cps OBJ_id_qt,1L
1101
1102#define SN_id_qt_unotice "id-qt-unotice"
1103#define LN_id_qt_unotice "Policy Qualifier User Notice"
1104#define NID_id_qt_unotice 165
1105#define OBJ_id_qt_unotice OBJ_id_qt,2L
1106
1107#define SN_textNotice "textNotice"
1108#define NID_textNotice 293
1109#define OBJ_textNotice OBJ_id_qt,3L
1110
1111#define SN_server_auth "serverAuth"
1112#define LN_server_auth "TLS Web Server Authentication"
1113#define NID_server_auth 129
1114#define OBJ_server_auth OBJ_id_kp,1L
1115
1116#define SN_client_auth "clientAuth"
1117#define LN_client_auth "TLS Web Client Authentication"
1118#define NID_client_auth 130
1119#define OBJ_client_auth OBJ_id_kp,2L
1120
1121#define SN_code_sign "codeSigning"
1122#define LN_code_sign "Code Signing"
1123#define NID_code_sign 131
1124#define OBJ_code_sign OBJ_id_kp,3L
1125
1126#define SN_email_protect "emailProtection"
1127#define LN_email_protect "E-mail Protection"
1128#define NID_email_protect 132
1129#define OBJ_email_protect OBJ_id_kp,4L
1130
1131#define SN_ipsecEndSystem "ipsecEndSystem"
1132#define LN_ipsecEndSystem "IPSec End System"
1133#define NID_ipsecEndSystem 294
1134#define OBJ_ipsecEndSystem OBJ_id_kp,5L
1135
1136#define SN_ipsecTunnel "ipsecTunnel"
1137#define LN_ipsecTunnel "IPSec Tunnel"
1138#define NID_ipsecTunnel 295
1139#define OBJ_ipsecTunnel OBJ_id_kp,6L
1140
1141#define SN_ipsecUser "ipsecUser"
1142#define LN_ipsecUser "IPSec User"
1143#define NID_ipsecUser 296
1144#define OBJ_ipsecUser OBJ_id_kp,7L
1145
1146#define SN_time_stamp "timeStamping"
1147#define LN_time_stamp "Time Stamping"
1148#define NID_time_stamp 133
1149#define OBJ_time_stamp OBJ_id_kp,8L
1150
1151#define SN_OCSP_sign "OCSPSigning"
1152#define LN_OCSP_sign "OCSP Signing"
1153#define NID_OCSP_sign 180
1154#define OBJ_OCSP_sign OBJ_id_kp,9L
1155
1156#define SN_dvcs "DVCS"
1157#define LN_dvcs "dvcs"
1158#define NID_dvcs 297
1159#define OBJ_dvcs OBJ_id_kp,10L
1160
1161#define SN_id_it_caProtEncCert "id-it-caProtEncCert"
1162#define NID_id_it_caProtEncCert 298
1163#define OBJ_id_it_caProtEncCert OBJ_id_it,1L
1164
1165#define SN_id_it_signKeyPairTypes "id-it-signKeyPairTypes"
1166#define NID_id_it_signKeyPairTypes 299
1167#define OBJ_id_it_signKeyPairTypes OBJ_id_it,2L
1168
1169#define SN_id_it_encKeyPairTypes "id-it-encKeyPairTypes"
1170#define NID_id_it_encKeyPairTypes 300
1171#define OBJ_id_it_encKeyPairTypes OBJ_id_it,3L
1172
1173#define SN_id_it_preferredSymmAlg "id-it-preferredSymmAlg"
1174#define NID_id_it_preferredSymmAlg 301
1175#define OBJ_id_it_preferredSymmAlg OBJ_id_it,4L
1176
1177#define SN_id_it_caKeyUpdateInfo "id-it-caKeyUpdateInfo"
1178#define NID_id_it_caKeyUpdateInfo 302
1179#define OBJ_id_it_caKeyUpdateInfo OBJ_id_it,5L
1180
1181#define SN_id_it_currentCRL "id-it-currentCRL"
1182#define NID_id_it_currentCRL 303
1183#define OBJ_id_it_currentCRL OBJ_id_it,6L
1184
1185#define SN_id_it_unsupportedOIDs "id-it-unsupportedOIDs"
1186#define NID_id_it_unsupportedOIDs 304
1187#define OBJ_id_it_unsupportedOIDs OBJ_id_it,7L
1188
1189#define SN_id_it_subscriptionRequest "id-it-subscriptionRequest"
1190#define NID_id_it_subscriptionRequest 305
1191#define OBJ_id_it_subscriptionRequest OBJ_id_it,8L
1192
1193#define SN_id_it_subscriptionResponse "id-it-subscriptionResponse"
1194#define NID_id_it_subscriptionResponse 306
1195#define OBJ_id_it_subscriptionResponse OBJ_id_it,9L
1196
1197#define SN_id_it_keyPairParamReq "id-it-keyPairParamReq"
1198#define NID_id_it_keyPairParamReq 307
1199#define OBJ_id_it_keyPairParamReq OBJ_id_it,10L
1200
1201#define SN_id_it_keyPairParamRep "id-it-keyPairParamRep"
1202#define NID_id_it_keyPairParamRep 308
1203#define OBJ_id_it_keyPairParamRep OBJ_id_it,11L
1204
1205#define SN_id_it_revPassphrase "id-it-revPassphrase"
1206#define NID_id_it_revPassphrase 309
1207#define OBJ_id_it_revPassphrase OBJ_id_it,12L
1208
1209#define SN_id_it_implicitConfirm "id-it-implicitConfirm"
1210#define NID_id_it_implicitConfirm 310
1211#define OBJ_id_it_implicitConfirm OBJ_id_it,13L
1212
1213#define SN_id_it_confirmWaitTime "id-it-confirmWaitTime"
1214#define NID_id_it_confirmWaitTime 311
1215#define OBJ_id_it_confirmWaitTime OBJ_id_it,14L
1216
1217#define SN_id_it_origPKIMessage "id-it-origPKIMessage"
1218#define NID_id_it_origPKIMessage 312
1219#define OBJ_id_it_origPKIMessage OBJ_id_it,15L
1220
1221#define SN_id_regCtrl "id-regCtrl"
1222#define NID_id_regCtrl 313
1223#define OBJ_id_regCtrl OBJ_id_pkip,1L
1224
1225#define SN_id_regInfo "id-regInfo"
1226#define NID_id_regInfo 314
1227#define OBJ_id_regInfo OBJ_id_pkip,2L
1228
1229#define SN_id_regCtrl_regToken "id-regCtrl-regToken"
1230#define NID_id_regCtrl_regToken 315
1231#define OBJ_id_regCtrl_regToken OBJ_id_regCtrl,1L
1232
1233#define SN_id_regCtrl_authenticator "id-regCtrl-authenticator"
1234#define NID_id_regCtrl_authenticator 316
1235#define OBJ_id_regCtrl_authenticator OBJ_id_regCtrl,2L
1236
1237#define SN_id_regCtrl_pkiPublicationInfo "id-regCtrl-pkiPublicationInfo"
1238#define NID_id_regCtrl_pkiPublicationInfo 317
1239#define OBJ_id_regCtrl_pkiPublicationInfo OBJ_id_regCtrl,3L
1240
1241#define SN_id_regCtrl_pkiArchiveOptions "id-regCtrl-pkiArchiveOptions"
1242#define NID_id_regCtrl_pkiArchiveOptions 318
1243#define OBJ_id_regCtrl_pkiArchiveOptions OBJ_id_regCtrl,4L
1244
1245#define SN_id_regCtrl_oldCertID "id-regCtrl-oldCertID"
1246#define NID_id_regCtrl_oldCertID 319
1247#define OBJ_id_regCtrl_oldCertID OBJ_id_regCtrl,5L
1248
1249#define SN_id_regCtrl_protocolEncrKey "id-regCtrl-protocolEncrKey"
1250#define NID_id_regCtrl_protocolEncrKey 320
1251#define OBJ_id_regCtrl_protocolEncrKey OBJ_id_regCtrl,6L
1252
1253#define SN_id_regInfo_utf8Pairs "id-regInfo-utf8Pairs"
1254#define NID_id_regInfo_utf8Pairs 321
1255#define OBJ_id_regInfo_utf8Pairs OBJ_id_regInfo,1L
1256
1257#define SN_id_regInfo_certReq "id-regInfo-certReq"
1258#define NID_id_regInfo_certReq 322
1259#define OBJ_id_regInfo_certReq OBJ_id_regInfo,2L
1260
1261#define SN_id_alg_des40 "id-alg-des40"
1262#define NID_id_alg_des40 323
1263#define OBJ_id_alg_des40 OBJ_id_alg,1L
1264
1265#define SN_id_alg_noSignature "id-alg-noSignature"
1266#define NID_id_alg_noSignature 324
1267#define OBJ_id_alg_noSignature OBJ_id_alg,2L
1268
1269#define SN_id_alg_dh_sig_hmac_sha1 "id-alg-dh-sig-hmac-sha1"
1270#define NID_id_alg_dh_sig_hmac_sha1 325
1271#define OBJ_id_alg_dh_sig_hmac_sha1 OBJ_id_alg,3L
1272
1273#define SN_id_alg_dh_pop "id-alg-dh-pop"
1274#define NID_id_alg_dh_pop 326
1275#define OBJ_id_alg_dh_pop OBJ_id_alg,4L
1276
1277#define SN_id_cmc_statusInfo "id-cmc-statusInfo"
1278#define NID_id_cmc_statusInfo 327
1279#define OBJ_id_cmc_statusInfo OBJ_id_cmc,1L
1280
1281#define SN_id_cmc_identification "id-cmc-identification"
1282#define NID_id_cmc_identification 328
1283#define OBJ_id_cmc_identification OBJ_id_cmc,2L
1284
1285#define SN_id_cmc_identityProof "id-cmc-identityProof"
1286#define NID_id_cmc_identityProof 329
1287#define OBJ_id_cmc_identityProof OBJ_id_cmc,3L
1288
1289#define SN_id_cmc_dataReturn "id-cmc-dataReturn"
1290#define NID_id_cmc_dataReturn 330
1291#define OBJ_id_cmc_dataReturn OBJ_id_cmc,4L
1292
1293#define SN_id_cmc_transactionId "id-cmc-transactionId"
1294#define NID_id_cmc_transactionId 331
1295#define OBJ_id_cmc_transactionId OBJ_id_cmc,5L
1296
1297#define SN_id_cmc_senderNonce "id-cmc-senderNonce"
1298#define NID_id_cmc_senderNonce 332
1299#define OBJ_id_cmc_senderNonce OBJ_id_cmc,6L
1300
1301#define SN_id_cmc_recipientNonce "id-cmc-recipientNonce"
1302#define NID_id_cmc_recipientNonce 333
1303#define OBJ_id_cmc_recipientNonce OBJ_id_cmc,7L
1304
1305#define SN_id_cmc_addExtensions "id-cmc-addExtensions"
1306#define NID_id_cmc_addExtensions 334
1307#define OBJ_id_cmc_addExtensions OBJ_id_cmc,8L
1308
1309#define SN_id_cmc_encryptedPOP "id-cmc-encryptedPOP"
1310#define NID_id_cmc_encryptedPOP 335
1311#define OBJ_id_cmc_encryptedPOP OBJ_id_cmc,9L
1312
1313#define SN_id_cmc_decryptedPOP "id-cmc-decryptedPOP"
1314#define NID_id_cmc_decryptedPOP 336
1315#define OBJ_id_cmc_decryptedPOP OBJ_id_cmc,10L
1316
1317#define SN_id_cmc_lraPOPWitness "id-cmc-lraPOPWitness"
1318#define NID_id_cmc_lraPOPWitness 337
1319#define OBJ_id_cmc_lraPOPWitness OBJ_id_cmc,11L
1320
1321#define SN_id_cmc_getCert "id-cmc-getCert"
1322#define NID_id_cmc_getCert 338
1323#define OBJ_id_cmc_getCert OBJ_id_cmc,15L
1324
1325#define SN_id_cmc_getCRL "id-cmc-getCRL"
1326#define NID_id_cmc_getCRL 339
1327#define OBJ_id_cmc_getCRL OBJ_id_cmc,16L
1328
1329#define SN_id_cmc_revokeRequest "id-cmc-revokeRequest"
1330#define NID_id_cmc_revokeRequest 340
1331#define OBJ_id_cmc_revokeRequest OBJ_id_cmc,17L
1332
1333#define SN_id_cmc_regInfo "id-cmc-regInfo"
1334#define NID_id_cmc_regInfo 341
1335#define OBJ_id_cmc_regInfo OBJ_id_cmc,18L
1336
1337#define SN_id_cmc_responseInfo "id-cmc-responseInfo"
1338#define NID_id_cmc_responseInfo 342
1339#define OBJ_id_cmc_responseInfo OBJ_id_cmc,19L
1340
1341#define SN_id_cmc_queryPending "id-cmc-queryPending"
1342#define NID_id_cmc_queryPending 343
1343#define OBJ_id_cmc_queryPending OBJ_id_cmc,21L
1344
1345#define SN_id_cmc_popLinkRandom "id-cmc-popLinkRandom"
1346#define NID_id_cmc_popLinkRandom 344
1347#define OBJ_id_cmc_popLinkRandom OBJ_id_cmc,22L
1348
1349#define SN_id_cmc_popLinkWitness "id-cmc-popLinkWitness"
1350#define NID_id_cmc_popLinkWitness 345
1351#define OBJ_id_cmc_popLinkWitness OBJ_id_cmc,23L
1352
1353#define SN_id_cmc_confirmCertAcceptance "id-cmc-confirmCertAcceptance"
1354#define NID_id_cmc_confirmCertAcceptance 346
1355#define OBJ_id_cmc_confirmCertAcceptance OBJ_id_cmc,24L
1356
1357#define SN_id_on_personalData "id-on-personalData"
1358#define NID_id_on_personalData 347
1359#define OBJ_id_on_personalData OBJ_id_on,1L
1360
1361#define SN_id_pda_dateOfBirth "id-pda-dateOfBirth"
1362#define NID_id_pda_dateOfBirth 348
1363#define OBJ_id_pda_dateOfBirth OBJ_id_pda,1L
1364
1365#define SN_id_pda_placeOfBirth "id-pda-placeOfBirth"
1366#define NID_id_pda_placeOfBirth 349
1367#define OBJ_id_pda_placeOfBirth OBJ_id_pda,2L
1368
1369#define SN_id_pda_gender "id-pda-gender"
1370#define NID_id_pda_gender 351
1371#define OBJ_id_pda_gender OBJ_id_pda,3L
1372
1373#define SN_id_pda_countryOfCitizenship "id-pda-countryOfCitizenship"
1374#define NID_id_pda_countryOfCitizenship 352
1375#define OBJ_id_pda_countryOfCitizenship OBJ_id_pda,4L
1376
1377#define SN_id_pda_countryOfResidence "id-pda-countryOfResidence"
1378#define NID_id_pda_countryOfResidence 353
1379#define OBJ_id_pda_countryOfResidence OBJ_id_pda,5L
1380
1381#define SN_id_aca_authenticationInfo "id-aca-authenticationInfo"
1382#define NID_id_aca_authenticationInfo 354
1383#define OBJ_id_aca_authenticationInfo OBJ_id_aca,1L
1384
1385#define SN_id_aca_accessIdentity "id-aca-accessIdentity"
1386#define NID_id_aca_accessIdentity 355
1387#define OBJ_id_aca_accessIdentity OBJ_id_aca,2L
1388
1389#define SN_id_aca_chargingIdentity "id-aca-chargingIdentity"
1390#define NID_id_aca_chargingIdentity 356
1391#define OBJ_id_aca_chargingIdentity OBJ_id_aca,3L
1392
1393#define SN_id_aca_group "id-aca-group"
1394#define NID_id_aca_group 357
1395#define OBJ_id_aca_group OBJ_id_aca,4L
1396
1397#define SN_id_aca_role "id-aca-role"
1398#define NID_id_aca_role 358
1399#define OBJ_id_aca_role OBJ_id_aca,5L
1400
1401#define SN_id_aca_encAttrs "id-aca-encAttrs"
1402#define NID_id_aca_encAttrs 399
1403#define OBJ_id_aca_encAttrs OBJ_id_aca,6L
1404
1405#define SN_id_qcs_pkixQCSyntax_v1 "id-qcs-pkixQCSyntax-v1"
1406#define NID_id_qcs_pkixQCSyntax_v1 359
1407#define OBJ_id_qcs_pkixQCSyntax_v1 OBJ_id_qcs,1L
1408
1409#define SN_id_cct_crs "id-cct-crs"
1410#define NID_id_cct_crs 360
1411#define OBJ_id_cct_crs OBJ_id_cct,1L
1412
1413#define SN_id_cct_PKIData "id-cct-PKIData"
1414#define NID_id_cct_PKIData 361
1415#define OBJ_id_cct_PKIData OBJ_id_cct,2L
1416
1417#define SN_id_cct_PKIResponse "id-cct-PKIResponse"
1418#define NID_id_cct_PKIResponse 362
1419#define OBJ_id_cct_PKIResponse OBJ_id_cct,3L
1420
1421#define SN_id_ppl_anyLanguage "id-ppl-anyLanguage"
1422#define LN_id_ppl_anyLanguage "Any language"
1423#define NID_id_ppl_anyLanguage 664
1424#define OBJ_id_ppl_anyLanguage OBJ_id_ppl,0L
1425
1426#define SN_id_ppl_inheritAll "id-ppl-inheritAll"
1427#define LN_id_ppl_inheritAll "Inherit all"
1428#define NID_id_ppl_inheritAll 665
1429#define OBJ_id_ppl_inheritAll OBJ_id_ppl,1L
1430
1431#define SN_Independent "id-ppl-independent"
1432#define LN_Independent "Independent"
1433#define NID_Independent 667
1434#define OBJ_Independent OBJ_id_ppl,2L
1435
1436#define SN_ad_OCSP "OCSP"
1437#define LN_ad_OCSP "OCSP"
1438#define NID_ad_OCSP 178
1439#define OBJ_ad_OCSP OBJ_id_ad,1L
1440
1441#define SN_ad_ca_issuers "caIssuers"
1442#define LN_ad_ca_issuers "CA Issuers"
1443#define NID_ad_ca_issuers 179
1444#define OBJ_ad_ca_issuers OBJ_id_ad,2L
1445
1446#define SN_ad_timeStamping "ad_timestamping"
1447#define LN_ad_timeStamping "AD Time Stamping"
1448#define NID_ad_timeStamping 363
1449#define OBJ_ad_timeStamping OBJ_id_ad,3L
1450
1451#define SN_ad_dvcs "AD_DVCS"
1452#define LN_ad_dvcs "ad dvcs"
1453#define NID_ad_dvcs 364
1454#define OBJ_ad_dvcs OBJ_id_ad,4L
1455
1456#define OBJ_id_pkix_OCSP OBJ_ad_OCSP
1457
1458#define SN_id_pkix_OCSP_basic "basicOCSPResponse"
1459#define LN_id_pkix_OCSP_basic "Basic OCSP Response"
1460#define NID_id_pkix_OCSP_basic 365
1461#define OBJ_id_pkix_OCSP_basic OBJ_id_pkix_OCSP,1L
1462
1463#define SN_id_pkix_OCSP_Nonce "Nonce"
1464#define LN_id_pkix_OCSP_Nonce "OCSP Nonce"
1465#define NID_id_pkix_OCSP_Nonce 366
1466#define OBJ_id_pkix_OCSP_Nonce OBJ_id_pkix_OCSP,2L
1467
1468#define SN_id_pkix_OCSP_CrlID "CrlID"
1469#define LN_id_pkix_OCSP_CrlID "OCSP CRL ID"
1470#define NID_id_pkix_OCSP_CrlID 367
1471#define OBJ_id_pkix_OCSP_CrlID OBJ_id_pkix_OCSP,3L
1472
1473#define SN_id_pkix_OCSP_acceptableResponses "acceptableResponses"
1474#define LN_id_pkix_OCSP_acceptableResponses "Acceptable OCSP Responses"
1475#define NID_id_pkix_OCSP_acceptableResponses 368
1476#define OBJ_id_pkix_OCSP_acceptableResponses OBJ_id_pkix_OCSP,4L
1477
1478#define SN_id_pkix_OCSP_noCheck "noCheck"
1479#define LN_id_pkix_OCSP_noCheck "OCSP No Check"
1480#define NID_id_pkix_OCSP_noCheck 369
1481#define OBJ_id_pkix_OCSP_noCheck OBJ_id_pkix_OCSP,5L
1482
1483#define SN_id_pkix_OCSP_archiveCutoff "archiveCutoff"
1484#define LN_id_pkix_OCSP_archiveCutoff "OCSP Archive Cutoff"
1485#define NID_id_pkix_OCSP_archiveCutoff 370
1486#define OBJ_id_pkix_OCSP_archiveCutoff OBJ_id_pkix_OCSP,6L
1487
1488#define SN_id_pkix_OCSP_serviceLocator "serviceLocator"
1489#define LN_id_pkix_OCSP_serviceLocator "OCSP Service Locator"
1490#define NID_id_pkix_OCSP_serviceLocator 371
1491#define OBJ_id_pkix_OCSP_serviceLocator OBJ_id_pkix_OCSP,7L
1492
1493#define SN_id_pkix_OCSP_extendedStatus "extendedStatus"
1494#define LN_id_pkix_OCSP_extendedStatus "Extended OCSP Status"
1495#define NID_id_pkix_OCSP_extendedStatus 372
1496#define OBJ_id_pkix_OCSP_extendedStatus OBJ_id_pkix_OCSP,8L
1497
1498#define SN_id_pkix_OCSP_valid "valid"
1499#define NID_id_pkix_OCSP_valid 373
1500#define OBJ_id_pkix_OCSP_valid OBJ_id_pkix_OCSP,9L
1501
1502#define SN_id_pkix_OCSP_path "path"
1503#define NID_id_pkix_OCSP_path 374
1504#define OBJ_id_pkix_OCSP_path OBJ_id_pkix_OCSP,10L
1505
1506#define SN_id_pkix_OCSP_trustRoot "trustRoot"
1507#define LN_id_pkix_OCSP_trustRoot "Trust Root"
1508#define NID_id_pkix_OCSP_trustRoot 375
1509#define OBJ_id_pkix_OCSP_trustRoot OBJ_id_pkix_OCSP,11L
1510
1511#define SN_algorithm "algorithm"
1512#define LN_algorithm "algorithm"
1513#define NID_algorithm 376
1514#define OBJ_algorithm 1L,3L,14L,3L,2L
1515
1516#define SN_md5WithRSA "RSA-NP-MD5"
1517#define LN_md5WithRSA "md5WithRSA"
1518#define NID_md5WithRSA 104
1519#define OBJ_md5WithRSA OBJ_algorithm,3L
1520
1521#define SN_des_ecb "DES-ECB"
1522#define LN_des_ecb "des-ecb"
1523#define NID_des_ecb 29
1524#define OBJ_des_ecb OBJ_algorithm,6L
1525
1526#define SN_des_cbc "DES-CBC"
1527#define LN_des_cbc "des-cbc"
1528#define NID_des_cbc 31
1529#define OBJ_des_cbc OBJ_algorithm,7L
1530
1531#define SN_des_ofb64 "DES-OFB"
1532#define LN_des_ofb64 "des-ofb"
1533#define NID_des_ofb64 45
1534#define OBJ_des_ofb64 OBJ_algorithm,8L
1535
1536#define SN_des_cfb64 "DES-CFB"
1537#define LN_des_cfb64 "des-cfb"
1538#define NID_des_cfb64 30
1539#define OBJ_des_cfb64 OBJ_algorithm,9L
1540
1541#define SN_rsaSignature "rsaSignature"
1542#define NID_rsaSignature 377
1543#define OBJ_rsaSignature OBJ_algorithm,11L
1544
1545#define SN_dsa_2 "DSA-old"
1546#define LN_dsa_2 "dsaEncryption-old"
1547#define NID_dsa_2 67
1548#define OBJ_dsa_2 OBJ_algorithm,12L
1549
1550#define SN_dsaWithSHA "DSA-SHA"
1551#define LN_dsaWithSHA "dsaWithSHA"
1552#define NID_dsaWithSHA 66
1553#define OBJ_dsaWithSHA OBJ_algorithm,13L
1554
1555#define SN_shaWithRSAEncryption "RSA-SHA"
1556#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
1557#define NID_shaWithRSAEncryption 42
1558#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
1559
1560#define SN_des_ede_ecb "DES-EDE"
1561#define LN_des_ede_ecb "des-ede"
1562#define NID_des_ede_ecb 32
1563#define OBJ_des_ede_ecb OBJ_algorithm,17L
1564
1565#define SN_des_ede3_ecb "DES-EDE3"
1566#define LN_des_ede3_ecb "des-ede3"
1567#define NID_des_ede3_ecb 33
1568
1569#define SN_des_ede_cbc "DES-EDE-CBC"
1570#define LN_des_ede_cbc "des-ede-cbc"
1571#define NID_des_ede_cbc 43
1572
1573#define SN_des_ede_cfb64 "DES-EDE-CFB"
1574#define LN_des_ede_cfb64 "des-ede-cfb"
1575#define NID_des_ede_cfb64 60
1576
1577#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
1578#define LN_des_ede3_cfb64 "des-ede3-cfb"
1579#define NID_des_ede3_cfb64 61
1580
1581#define SN_des_ede_ofb64 "DES-EDE-OFB"
1582#define LN_des_ede_ofb64 "des-ede-ofb"
1583#define NID_des_ede_ofb64 62
1584
1585#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
1586#define LN_des_ede3_ofb64 "des-ede3-ofb"
1587#define NID_des_ede3_ofb64 63
1588
1589#define SN_desx_cbc "DESX-CBC"
1590#define LN_desx_cbc "desx-cbc"
1591#define NID_desx_cbc 80
1592
1593#define SN_sha "SHA"
1594#define LN_sha "sha"
1595#define NID_sha 41
1596#define OBJ_sha OBJ_algorithm,18L
1597
1598#define SN_sha1 "SHA1"
1599#define LN_sha1 "sha1"
1600#define NID_sha1 64
1601#define OBJ_sha1 OBJ_algorithm,26L
1602
1603#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
1604#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
1605#define NID_dsaWithSHA1_2 70
1606#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
1607
1608#define SN_sha1WithRSA "RSA-SHA1-2"
1609#define LN_sha1WithRSA "sha1WithRSA"
1610#define NID_sha1WithRSA 115
1611#define OBJ_sha1WithRSA OBJ_algorithm,29L
1612
1613#define SN_ripemd160 "RIPEMD160"
1614#define LN_ripemd160 "ripemd160"
1615#define NID_ripemd160 117
1616#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
1617
1618#define SN_ripemd160WithRSA "RSA-RIPEMD160"
1619#define LN_ripemd160WithRSA "ripemd160WithRSA"
1620#define NID_ripemd160WithRSA 119
1621#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
1622
1623#define SN_sxnet "SXNetID"
1624#define LN_sxnet "Strong Extranet ID"
1625#define NID_sxnet 143
1626#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
1627
1628#define SN_X500 "X500"
1629#define LN_X500 "directory services (X.500)"
1630#define NID_X500 11
1631#define OBJ_X500 2L,5L
1632
1633#define SN_X509 "X509"
1634#define NID_X509 12
1635#define OBJ_X509 OBJ_X500,4L
1636
1637#define SN_commonName "CN"
1638#define LN_commonName "commonName"
1639#define NID_commonName 13
1640#define OBJ_commonName OBJ_X509,3L
1641
1642#define SN_surname "SN"
1643#define LN_surname "surname"
1644#define NID_surname 100
1645#define OBJ_surname OBJ_X509,4L
1646
1647#define LN_serialNumber "serialNumber"
1648#define NID_serialNumber 105
1649#define OBJ_serialNumber OBJ_X509,5L
1650
1651#define SN_countryName "C"
1652#define LN_countryName "countryName"
1653#define NID_countryName 14
1654#define OBJ_countryName OBJ_X509,6L
1655
1656#define SN_localityName "L"
1657#define LN_localityName "localityName"
1658#define NID_localityName 15
1659#define OBJ_localityName OBJ_X509,7L
1660
1661#define SN_stateOrProvinceName "ST"
1662#define LN_stateOrProvinceName "stateOrProvinceName"
1663#define NID_stateOrProvinceName 16
1664#define OBJ_stateOrProvinceName OBJ_X509,8L
1665
1666#define LN_streetAddress "streetAddress"
1667#define NID_streetAddress 660
1668#define OBJ_streetAddress OBJ_X509,9L
1669
1670#define SN_organizationName "O"
1671#define LN_organizationName "organizationName"
1672#define NID_organizationName 17
1673#define OBJ_organizationName OBJ_X509,10L
1674
1675#define SN_organizationalUnitName "OU"
1676#define LN_organizationalUnitName "organizationalUnitName"
1677#define NID_organizationalUnitName 18
1678#define OBJ_organizationalUnitName OBJ_X509,11L
1679
1680#define LN_title "title"
1681#define NID_title 106
1682#define OBJ_title OBJ_X509,12L
1683
1684#define LN_description "description"
1685#define NID_description 107
1686#define OBJ_description OBJ_X509,13L
1687
1688#define LN_postalCode "postalCode"
1689#define NID_postalCode 661
1690#define OBJ_postalCode OBJ_X509,17L
1691
1692#define SN_name "name"
1693#define LN_name "name"
1694#define NID_name 173
1695#define OBJ_name OBJ_X509,41L
1696
1697#define SN_givenName "GN"
1698#define LN_givenName "givenName"
1699#define NID_givenName 99
1700#define OBJ_givenName OBJ_X509,42L
1701
1702#define LN_initials "initials"
1703#define NID_initials 101
1704#define OBJ_initials OBJ_X509,43L
1705
1706#define LN_generationQualifier "generationQualifier"
1707#define NID_generationQualifier 509
1708#define OBJ_generationQualifier OBJ_X509,44L
1709
1710#define LN_x500UniqueIdentifier "x500UniqueIdentifier"
1711#define NID_x500UniqueIdentifier 503
1712#define OBJ_x500UniqueIdentifier OBJ_X509,45L
1713
1714#define SN_dnQualifier "dnQualifier"
1715#define LN_dnQualifier "dnQualifier"
1716#define NID_dnQualifier 174
1717#define OBJ_dnQualifier OBJ_X509,46L
1718
1719#define LN_pseudonym "pseudonym"
1720#define NID_pseudonym 510
1721#define OBJ_pseudonym OBJ_X509,65L
1722
1723#define SN_role "role"
1724#define LN_role "role"
1725#define NID_role 400
1726#define OBJ_role OBJ_X509,72L
1727
1728#define SN_X500algorithms "X500algorithms"
1729#define LN_X500algorithms "directory services - algorithms"
1730#define NID_X500algorithms 378
1731#define OBJ_X500algorithms OBJ_X500,8L
1732
1733#define SN_rsa "RSA"
1734#define LN_rsa "rsa"
1735#define NID_rsa 19
1736#define OBJ_rsa OBJ_X500algorithms,1L,1L
1737
1738#define SN_mdc2WithRSA "RSA-MDC2"
1739#define LN_mdc2WithRSA "mdc2WithRSA"
1740#define NID_mdc2WithRSA 96
1741#define OBJ_mdc2WithRSA OBJ_X500algorithms,3L,100L
1742
1743#define SN_mdc2 "MDC2"
1744#define LN_mdc2 "mdc2"
1745#define NID_mdc2 95
1746#define OBJ_mdc2 OBJ_X500algorithms,3L,101L
1747
1748#define SN_id_ce "id-ce"
1749#define NID_id_ce 81
1750#define OBJ_id_ce OBJ_X500,29L
1751
1752#define SN_subject_key_identifier "subjectKeyIdentifier"
1753#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
1754#define NID_subject_key_identifier 82
1755#define OBJ_subject_key_identifier OBJ_id_ce,14L
1756
1757#define SN_key_usage "keyUsage"
1758#define LN_key_usage "X509v3 Key Usage"
1759#define NID_key_usage 83
1760#define OBJ_key_usage OBJ_id_ce,15L
1761
1762#define SN_private_key_usage_period "privateKeyUsagePeriod"
1763#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
1764#define NID_private_key_usage_period 84
1765#define OBJ_private_key_usage_period OBJ_id_ce,16L
1766
1767#define SN_subject_alt_name "subjectAltName"
1768#define LN_subject_alt_name "X509v3 Subject Alternative Name"
1769#define NID_subject_alt_name 85
1770#define OBJ_subject_alt_name OBJ_id_ce,17L
1771
1772#define SN_issuer_alt_name "issuerAltName"
1773#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
1774#define NID_issuer_alt_name 86
1775#define OBJ_issuer_alt_name OBJ_id_ce,18L
1776
1777#define SN_basic_constraints "basicConstraints"
1778#define LN_basic_constraints "X509v3 Basic Constraints"
1779#define NID_basic_constraints 87
1780#define OBJ_basic_constraints OBJ_id_ce,19L
1781
1782#define SN_crl_number "crlNumber"
1783#define LN_crl_number "X509v3 CRL Number"
1784#define NID_crl_number 88
1785#define OBJ_crl_number OBJ_id_ce,20L
1786
1787#define SN_crl_reason "CRLReason"
1788#define LN_crl_reason "X509v3 CRL Reason Code"
1789#define NID_crl_reason 141
1790#define OBJ_crl_reason OBJ_id_ce,21L
1791
1792#define SN_invalidity_date "invalidityDate"
1793#define LN_invalidity_date "Invalidity Date"
1794#define NID_invalidity_date 142
1795#define OBJ_invalidity_date OBJ_id_ce,24L
1796
1797#define SN_delta_crl "deltaCRL"
1798#define LN_delta_crl "X509v3 Delta CRL Indicator"
1799#define NID_delta_crl 140
1800#define OBJ_delta_crl OBJ_id_ce,27L
1801
1802#define SN_name_constraints "nameConstraints"
1803#define LN_name_constraints "X509v3 Name Constraints"
1804#define NID_name_constraints 666
1805#define OBJ_name_constraints OBJ_id_ce,30L
1806
1807#define SN_crl_distribution_points "crlDistributionPoints"
1808#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
1809#define NID_crl_distribution_points 103
1810#define OBJ_crl_distribution_points OBJ_id_ce,31L
1811
1812#define SN_certificate_policies "certificatePolicies"
1813#define LN_certificate_policies "X509v3 Certificate Policies"
1814#define NID_certificate_policies 89
1815#define OBJ_certificate_policies OBJ_id_ce,32L
1816
1817#define SN_authority_key_identifier "authorityKeyIdentifier"
1818#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
1819#define NID_authority_key_identifier 90
1820#define OBJ_authority_key_identifier OBJ_id_ce,35L
1821
1822#define SN_policy_constraints "policyConstraints"
1823#define LN_policy_constraints "X509v3 Policy Constraints"
1824#define NID_policy_constraints 401
1825#define OBJ_policy_constraints OBJ_id_ce,36L
1826
1827#define SN_ext_key_usage "extendedKeyUsage"
1828#define LN_ext_key_usage "X509v3 Extended Key Usage"
1829#define NID_ext_key_usage 126
1830#define OBJ_ext_key_usage OBJ_id_ce,37L
1831
1832#define SN_target_information "targetInformation"
1833#define LN_target_information "X509v3 AC Targeting"
1834#define NID_target_information 402
1835#define OBJ_target_information OBJ_id_ce,55L
1836
1837#define SN_no_rev_avail "noRevAvail"
1838#define LN_no_rev_avail "X509v3 No Revocation Available"
1839#define NID_no_rev_avail 403
1840#define OBJ_no_rev_avail OBJ_id_ce,56L
1841
1842#define SN_netscape "Netscape"
1843#define LN_netscape "Netscape Communications Corp."
1844#define NID_netscape 57
1845#define OBJ_netscape 2L,16L,840L,1L,113730L
1846
1847#define SN_netscape_cert_extension "nsCertExt"
1848#define LN_netscape_cert_extension "Netscape Certificate Extension"
1849#define NID_netscape_cert_extension 58
1850#define OBJ_netscape_cert_extension OBJ_netscape,1L
1851
1852#define SN_netscape_data_type "nsDataType"
1853#define LN_netscape_data_type "Netscape Data Type"
1854#define NID_netscape_data_type 59
1855#define OBJ_netscape_data_type OBJ_netscape,2L
1856
1857#define SN_netscape_cert_type "nsCertType"
1858#define LN_netscape_cert_type "Netscape Cert Type"
1859#define NID_netscape_cert_type 71
1860#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
1861
1862#define SN_netscape_base_url "nsBaseUrl"
1863#define LN_netscape_base_url "Netscape Base Url"
1864#define NID_netscape_base_url 72
1865#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
1866
1867#define SN_netscape_revocation_url "nsRevocationUrl"
1868#define LN_netscape_revocation_url "Netscape Revocation Url"
1869#define NID_netscape_revocation_url 73
1870#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
1871
1872#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
1873#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
1874#define NID_netscape_ca_revocation_url 74
1875#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
1876
1877#define SN_netscape_renewal_url "nsRenewalUrl"
1878#define LN_netscape_renewal_url "Netscape Renewal Url"
1879#define NID_netscape_renewal_url 75
1880#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
1881
1882#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
1883#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
1884#define NID_netscape_ca_policy_url 76
1885#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
1886
1887#define SN_netscape_ssl_server_name "nsSslServerName"
1888#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
1889#define NID_netscape_ssl_server_name 77
1890#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
1891
1892#define SN_netscape_comment "nsComment"
1893#define LN_netscape_comment "Netscape Comment"
1894#define NID_netscape_comment 78
1895#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
1896
1897#define SN_netscape_cert_sequence "nsCertSequence"
1898#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
1899#define NID_netscape_cert_sequence 79
1900#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
1901
1902#define SN_ns_sgc "nsSGC"
1903#define LN_ns_sgc "Netscape Server Gated Crypto"
1904#define NID_ns_sgc 139
1905#define OBJ_ns_sgc OBJ_netscape,4L,1L
1906
1907#define SN_org "ORG"
1908#define LN_org "org"
1909#define NID_org 379
1910#define OBJ_org OBJ_iso,3L
1911
1912#define SN_dod "DOD"
1913#define LN_dod "dod"
1914#define NID_dod 380
1915#define OBJ_dod OBJ_org,6L
1916
1917#define SN_iana "IANA"
1918#define LN_iana "iana"
1919#define NID_iana 381
1920#define OBJ_iana OBJ_dod,1L
1921
1922#define OBJ_internet OBJ_iana
1923
1924#define SN_Directory "directory"
1925#define LN_Directory "Directory"
1926#define NID_Directory 382
1927#define OBJ_Directory OBJ_internet,1L
1928
1929#define SN_Management "mgmt"
1930#define LN_Management "Management"
1931#define NID_Management 383
1932#define OBJ_Management OBJ_internet,2L
1933
1934#define SN_Experimental "experimental"
1935#define LN_Experimental "Experimental"
1936#define NID_Experimental 384
1937#define OBJ_Experimental OBJ_internet,3L
1938
1939#define SN_Private "private"
1940#define LN_Private "Private"
1941#define NID_Private 385
1942#define OBJ_Private OBJ_internet,4L
1943
1944#define SN_Security "security"
1945#define LN_Security "Security"
1946#define NID_Security 386
1947#define OBJ_Security OBJ_internet,5L
1948
1949#define SN_SNMPv2 "snmpv2"
1950#define LN_SNMPv2 "SNMPv2"
1951#define NID_SNMPv2 387
1952#define OBJ_SNMPv2 OBJ_internet,6L
1953
1954#define LN_Mail "Mail"
1955#define NID_Mail 388
1956#define OBJ_Mail OBJ_internet,7L
1957
1958#define SN_Enterprises "enterprises"
1959#define LN_Enterprises "Enterprises"
1960#define NID_Enterprises 389
1961#define OBJ_Enterprises OBJ_Private,1L
1962
1963#define SN_dcObject "dcobject"
1964#define LN_dcObject "dcObject"
1965#define NID_dcObject 390
1966#define OBJ_dcObject OBJ_Enterprises,1466L,344L
1967
1968#define SN_mime_mhs "mime-mhs"
1969#define LN_mime_mhs "MIME MHS"
1970#define NID_mime_mhs 504
1971#define OBJ_mime_mhs OBJ_Mail,1L
1972
1973#define SN_mime_mhs_headings "mime-mhs-headings"
1974#define LN_mime_mhs_headings "mime-mhs-headings"
1975#define NID_mime_mhs_headings 505
1976#define OBJ_mime_mhs_headings OBJ_mime_mhs,1L
1977
1978#define SN_mime_mhs_bodies "mime-mhs-bodies"
1979#define LN_mime_mhs_bodies "mime-mhs-bodies"
1980#define NID_mime_mhs_bodies 506
1981#define OBJ_mime_mhs_bodies OBJ_mime_mhs,2L
1982
1983#define SN_id_hex_partial_message "id-hex-partial-message"
1984#define LN_id_hex_partial_message "id-hex-partial-message"
1985#define NID_id_hex_partial_message 507
1986#define OBJ_id_hex_partial_message OBJ_mime_mhs_headings,1L
1987
1988#define SN_id_hex_multipart_message "id-hex-multipart-message"
1989#define LN_id_hex_multipart_message "id-hex-multipart-message"
1990#define NID_id_hex_multipart_message 508
1991#define OBJ_id_hex_multipart_message OBJ_mime_mhs_headings,2L
1992
1993#define SN_rle_compression "RLE"
1994#define LN_rle_compression "run length compression"
1995#define NID_rle_compression 124
1996#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
1997
1998#define SN_zlib_compression "ZLIB"
1999#define LN_zlib_compression "zlib compression"
2000#define NID_zlib_compression 125
2001#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
2002
2003#define OBJ_csor 2L,16L,840L,1L,101L,3L
2004
2005#define OBJ_nistAlgorithms OBJ_csor,4L
2006
2007#define OBJ_aes OBJ_nistAlgorithms,1L
2008
2009#define SN_aes_128_ecb "AES-128-ECB"
2010#define LN_aes_128_ecb "aes-128-ecb"
2011#define NID_aes_128_ecb 418
2012#define OBJ_aes_128_ecb OBJ_aes,1L
2013
2014#define SN_aes_128_cbc "AES-128-CBC"
2015#define LN_aes_128_cbc "aes-128-cbc"
2016#define NID_aes_128_cbc 419
2017#define OBJ_aes_128_cbc OBJ_aes,2L
2018
2019#define SN_aes_128_ofb128 "AES-128-OFB"
2020#define LN_aes_128_ofb128 "aes-128-ofb"
2021#define NID_aes_128_ofb128 420
2022#define OBJ_aes_128_ofb128 OBJ_aes,3L
2023
2024#define SN_aes_128_cfb128 "AES-128-CFB"
2025#define LN_aes_128_cfb128 "aes-128-cfb"
2026#define NID_aes_128_cfb128 421
2027#define OBJ_aes_128_cfb128 OBJ_aes,4L
2028
2029#define SN_aes_192_ecb "AES-192-ECB"
2030#define LN_aes_192_ecb "aes-192-ecb"
2031#define NID_aes_192_ecb 422
2032#define OBJ_aes_192_ecb OBJ_aes,21L
2033
2034#define SN_aes_192_cbc "AES-192-CBC"
2035#define LN_aes_192_cbc "aes-192-cbc"
2036#define NID_aes_192_cbc 423
2037#define OBJ_aes_192_cbc OBJ_aes,22L
2038
2039#define SN_aes_192_ofb128 "AES-192-OFB"
2040#define LN_aes_192_ofb128 "aes-192-ofb"
2041#define NID_aes_192_ofb128 424
2042#define OBJ_aes_192_ofb128 OBJ_aes,23L
2043
2044#define SN_aes_192_cfb128 "AES-192-CFB"
2045#define LN_aes_192_cfb128 "aes-192-cfb"
2046#define NID_aes_192_cfb128 425
2047#define OBJ_aes_192_cfb128 OBJ_aes,24L
2048
2049#define SN_aes_256_ecb "AES-256-ECB"
2050#define LN_aes_256_ecb "aes-256-ecb"
2051#define NID_aes_256_ecb 426
2052#define OBJ_aes_256_ecb OBJ_aes,41L
2053
2054#define SN_aes_256_cbc "AES-256-CBC"
2055#define LN_aes_256_cbc "aes-256-cbc"
2056#define NID_aes_256_cbc 427
2057#define OBJ_aes_256_cbc OBJ_aes,42L
2058
2059#define SN_aes_256_ofb128 "AES-256-OFB"
2060#define LN_aes_256_ofb128 "aes-256-ofb"
2061#define NID_aes_256_ofb128 428
2062#define OBJ_aes_256_ofb128 OBJ_aes,43L
2063
2064#define SN_aes_256_cfb128 "AES-256-CFB"
2065#define LN_aes_256_cfb128 "aes-256-cfb"
2066#define NID_aes_256_cfb128 429
2067#define OBJ_aes_256_cfb128 OBJ_aes,44L
2068
2069#define SN_aes_128_cfb1 "AES-128-CFB1"
2070#define LN_aes_128_cfb1 "aes-128-cfb1"
2071#define NID_aes_128_cfb1 650
2072
2073#define SN_aes_192_cfb1 "AES-192-CFB1"
2074#define LN_aes_192_cfb1 "aes-192-cfb1"
2075#define NID_aes_192_cfb1 651
2076
2077#define SN_aes_256_cfb1 "AES-256-CFB1"
2078#define LN_aes_256_cfb1 "aes-256-cfb1"
2079#define NID_aes_256_cfb1 652
2080
2081#define SN_aes_128_cfb8 "AES-128-CFB8"
2082#define LN_aes_128_cfb8 "aes-128-cfb8"
2083#define NID_aes_128_cfb8 653
2084
2085#define SN_aes_192_cfb8 "AES-192-CFB8"
2086#define LN_aes_192_cfb8 "aes-192-cfb8"
2087#define NID_aes_192_cfb8 654
2088
2089#define SN_aes_256_cfb8 "AES-256-CFB8"
2090#define LN_aes_256_cfb8 "aes-256-cfb8"
2091#define NID_aes_256_cfb8 655
2092
2093#define SN_des_cfb1 "DES-CFB1"
2094#define LN_des_cfb1 "des-cfb1"
2095#define NID_des_cfb1 656
2096
2097#define SN_des_cfb8 "DES-CFB8"
2098#define LN_des_cfb8 "des-cfb8"
2099#define NID_des_cfb8 657
2100
2101#define SN_des_ede3_cfb1 "DES-EDE3-CFB1"
2102#define LN_des_ede3_cfb1 "des-ede3-cfb1"
2103#define NID_des_ede3_cfb1 658
2104
2105#define SN_des_ede3_cfb8 "DES-EDE3-CFB8"
2106#define LN_des_ede3_cfb8 "des-ede3-cfb8"
2107#define NID_des_ede3_cfb8 659
2108
2109#define OBJ_nist_hashalgs OBJ_nistAlgorithms,2L
2110
2111#define SN_sha256 "SHA256"
2112#define LN_sha256 "sha256"
2113#define NID_sha256 672
2114#define OBJ_sha256 OBJ_nist_hashalgs,1L
2115
2116#define SN_sha384 "SHA384"
2117#define LN_sha384 "sha384"
2118#define NID_sha384 673
2119#define OBJ_sha384 OBJ_nist_hashalgs,2L
2120
2121#define SN_sha512 "SHA512"
2122#define LN_sha512 "sha512"
2123#define NID_sha512 674
2124#define OBJ_sha512 OBJ_nist_hashalgs,3L
2125
2126#define SN_sha224 "SHA224"
2127#define LN_sha224 "sha224"
2128#define NID_sha224 675
2129#define OBJ_sha224 OBJ_nist_hashalgs,4L
2130
2131#define SN_hold_instruction_code "holdInstructionCode"
2132#define LN_hold_instruction_code "Hold Instruction Code"
2133#define NID_hold_instruction_code 430
2134#define OBJ_hold_instruction_code OBJ_id_ce,23L
2135
2136#define OBJ_holdInstruction OBJ_X9_57,2L
2137
2138#define SN_hold_instruction_none "holdInstructionNone"
2139#define LN_hold_instruction_none "Hold Instruction None"
2140#define NID_hold_instruction_none 431
2141#define OBJ_hold_instruction_none OBJ_holdInstruction,1L
2142
2143#define SN_hold_instruction_call_issuer "holdInstructionCallIssuer"
2144#define LN_hold_instruction_call_issuer "Hold Instruction Call Issuer"
2145#define NID_hold_instruction_call_issuer 432
2146#define OBJ_hold_instruction_call_issuer OBJ_holdInstruction,2L
2147
2148#define SN_hold_instruction_reject "holdInstructionReject"
2149#define LN_hold_instruction_reject "Hold Instruction Reject"
2150#define NID_hold_instruction_reject 433
2151#define OBJ_hold_instruction_reject OBJ_holdInstruction,3L
2152
2153#define SN_data "data"
2154#define NID_data 434
2155#define OBJ_data OBJ_ccitt,9L
2156
2157#define SN_pss "pss"
2158#define NID_pss 435
2159#define OBJ_pss OBJ_data,2342L
2160
2161#define SN_ucl "ucl"
2162#define NID_ucl 436
2163#define OBJ_ucl OBJ_pss,19200300L
2164
2165#define SN_pilot "pilot"
2166#define NID_pilot 437
2167#define OBJ_pilot OBJ_ucl,100L
2168
2169#define LN_pilotAttributeType "pilotAttributeType"
2170#define NID_pilotAttributeType 438
2171#define OBJ_pilotAttributeType OBJ_pilot,1L
2172
2173#define LN_pilotAttributeSyntax "pilotAttributeSyntax"
2174#define NID_pilotAttributeSyntax 439
2175#define OBJ_pilotAttributeSyntax OBJ_pilot,3L
2176
2177#define LN_pilotObjectClass "pilotObjectClass"
2178#define NID_pilotObjectClass 440
2179#define OBJ_pilotObjectClass OBJ_pilot,4L
2180
2181#define LN_pilotGroups "pilotGroups"
2182#define NID_pilotGroups 441
2183#define OBJ_pilotGroups OBJ_pilot,10L
2184
2185#define LN_iA5StringSyntax "iA5StringSyntax"
2186#define NID_iA5StringSyntax 442
2187#define OBJ_iA5StringSyntax OBJ_pilotAttributeSyntax,4L
2188
2189#define LN_caseIgnoreIA5StringSyntax "caseIgnoreIA5StringSyntax"
2190#define NID_caseIgnoreIA5StringSyntax 443
2191#define OBJ_caseIgnoreIA5StringSyntax OBJ_pilotAttributeSyntax,5L
2192
2193#define LN_pilotObject "pilotObject"
2194#define NID_pilotObject 444
2195#define OBJ_pilotObject OBJ_pilotObjectClass,3L
2196
2197#define LN_pilotPerson "pilotPerson"
2198#define NID_pilotPerson 445
2199#define OBJ_pilotPerson OBJ_pilotObjectClass,4L
2200
2201#define SN_account "account"
2202#define NID_account 446
2203#define OBJ_account OBJ_pilotObjectClass,5L
2204
2205#define SN_document "document"
2206#define NID_document 447
2207#define OBJ_document OBJ_pilotObjectClass,6L
2208
2209#define SN_room "room"
2210#define NID_room 448
2211#define OBJ_room OBJ_pilotObjectClass,7L
2212
2213#define LN_documentSeries "documentSeries"
2214#define NID_documentSeries 449
2215#define OBJ_documentSeries OBJ_pilotObjectClass,9L
2216
2217#define SN_Domain "domain"
2218#define LN_Domain "Domain"
2219#define NID_Domain 392
2220#define OBJ_Domain OBJ_pilotObjectClass,13L
2221
2222#define LN_rFC822localPart "rFC822localPart"
2223#define NID_rFC822localPart 450
2224#define OBJ_rFC822localPart OBJ_pilotObjectClass,14L
2225
2226#define LN_dNSDomain "dNSDomain"
2227#define NID_dNSDomain 451
2228#define OBJ_dNSDomain OBJ_pilotObjectClass,15L
2229
2230#define LN_domainRelatedObject "domainRelatedObject"
2231#define NID_domainRelatedObject 452
2232#define OBJ_domainRelatedObject OBJ_pilotObjectClass,17L
2233
2234#define LN_friendlyCountry "friendlyCountry"
2235#define NID_friendlyCountry 453
2236#define OBJ_friendlyCountry OBJ_pilotObjectClass,18L
2237
2238#define LN_simpleSecurityObject "simpleSecurityObject"
2239#define NID_simpleSecurityObject 454
2240#define OBJ_simpleSecurityObject OBJ_pilotObjectClass,19L
2241
2242#define LN_pilotOrganization "pilotOrganization"
2243#define NID_pilotOrganization 455
2244#define OBJ_pilotOrganization OBJ_pilotObjectClass,20L
2245
2246#define LN_pilotDSA "pilotDSA"
2247#define NID_pilotDSA 456
2248#define OBJ_pilotDSA OBJ_pilotObjectClass,21L
2249
2250#define LN_qualityLabelledData "qualityLabelledData"
2251#define NID_qualityLabelledData 457
2252#define OBJ_qualityLabelledData OBJ_pilotObjectClass,22L
2253
2254#define SN_userId "UID"
2255#define LN_userId "userId"
2256#define NID_userId 458
2257#define OBJ_userId OBJ_pilotAttributeType,1L
2258
2259#define LN_textEncodedORAddress "textEncodedORAddress"
2260#define NID_textEncodedORAddress 459
2261#define OBJ_textEncodedORAddress OBJ_pilotAttributeType,2L
2262
2263#define SN_rfc822Mailbox "mail"
2264#define LN_rfc822Mailbox "rfc822Mailbox"
2265#define NID_rfc822Mailbox 460
2266#define OBJ_rfc822Mailbox OBJ_pilotAttributeType,3L
2267
2268#define SN_info "info"
2269#define NID_info 461
2270#define OBJ_info OBJ_pilotAttributeType,4L
2271
2272#define LN_favouriteDrink "favouriteDrink"
2273#define NID_favouriteDrink 462
2274#define OBJ_favouriteDrink OBJ_pilotAttributeType,5L
2275
2276#define LN_roomNumber "roomNumber"
2277#define NID_roomNumber 463
2278#define OBJ_roomNumber OBJ_pilotAttributeType,6L
2279
2280#define SN_photo "photo"
2281#define NID_photo 464
2282#define OBJ_photo OBJ_pilotAttributeType,7L
2283
2284#define LN_userClass "userClass"
2285#define NID_userClass 465
2286#define OBJ_userClass OBJ_pilotAttributeType,8L
2287
2288#define SN_host "host"
2289#define NID_host 466
2290#define OBJ_host OBJ_pilotAttributeType,9L
2291
2292#define SN_manager "manager"
2293#define NID_manager 467
2294#define OBJ_manager OBJ_pilotAttributeType,10L
2295
2296#define LN_documentIdentifier "documentIdentifier"
2297#define NID_documentIdentifier 468
2298#define OBJ_documentIdentifier OBJ_pilotAttributeType,11L
2299
2300#define LN_documentTitle "documentTitle"
2301#define NID_documentTitle 469
2302#define OBJ_documentTitle OBJ_pilotAttributeType,12L
2303
2304#define LN_documentVersion "documentVersion"
2305#define NID_documentVersion 470
2306#define OBJ_documentVersion OBJ_pilotAttributeType,13L
2307
2308#define LN_documentAuthor "documentAuthor"
2309#define NID_documentAuthor 471
2310#define OBJ_documentAuthor OBJ_pilotAttributeType,14L
2311
2312#define LN_documentLocation "documentLocation"
2313#define NID_documentLocation 472
2314#define OBJ_documentLocation OBJ_pilotAttributeType,15L
2315
2316#define LN_homeTelephoneNumber "homeTelephoneNumber"
2317#define NID_homeTelephoneNumber 473
2318#define OBJ_homeTelephoneNumber OBJ_pilotAttributeType,20L
2319
2320#define SN_secretary "secretary"
2321#define NID_secretary 474
2322#define OBJ_secretary OBJ_pilotAttributeType,21L
2323
2324#define LN_otherMailbox "otherMailbox"
2325#define NID_otherMailbox 475
2326#define OBJ_otherMailbox OBJ_pilotAttributeType,22L
2327
2328#define LN_lastModifiedTime "lastModifiedTime"
2329#define NID_lastModifiedTime 476
2330#define OBJ_lastModifiedTime OBJ_pilotAttributeType,23L
2331
2332#define LN_lastModifiedBy "lastModifiedBy"
2333#define NID_lastModifiedBy 477
2334#define OBJ_lastModifiedBy OBJ_pilotAttributeType,24L
2335
2336#define SN_domainComponent "DC"
2337#define LN_domainComponent "domainComponent"
2338#define NID_domainComponent 391
2339#define OBJ_domainComponent OBJ_pilotAttributeType,25L
2340
2341#define LN_aRecord "aRecord"
2342#define NID_aRecord 478
2343#define OBJ_aRecord OBJ_pilotAttributeType,26L
2344
2345#define LN_pilotAttributeType27 "pilotAttributeType27"
2346#define NID_pilotAttributeType27 479
2347#define OBJ_pilotAttributeType27 OBJ_pilotAttributeType,27L
2348
2349#define LN_mXRecord "mXRecord"
2350#define NID_mXRecord 480
2351#define OBJ_mXRecord OBJ_pilotAttributeType,28L
2352
2353#define LN_nSRecord "nSRecord"
2354#define NID_nSRecord 481
2355#define OBJ_nSRecord OBJ_pilotAttributeType,29L
2356
2357#define LN_sOARecord "sOARecord"
2358#define NID_sOARecord 482
2359#define OBJ_sOARecord OBJ_pilotAttributeType,30L
2360
2361#define LN_cNAMERecord "cNAMERecord"
2362#define NID_cNAMERecord 483
2363#define OBJ_cNAMERecord OBJ_pilotAttributeType,31L
2364
2365#define LN_associatedDomain "associatedDomain"
2366#define NID_associatedDomain 484
2367#define OBJ_associatedDomain OBJ_pilotAttributeType,37L
2368
2369#define LN_associatedName "associatedName"
2370#define NID_associatedName 485
2371#define OBJ_associatedName OBJ_pilotAttributeType,38L
2372
2373#define LN_homePostalAddress "homePostalAddress"
2374#define NID_homePostalAddress 486
2375#define OBJ_homePostalAddress OBJ_pilotAttributeType,39L
2376
2377#define LN_personalTitle "personalTitle"
2378#define NID_personalTitle 487
2379#define OBJ_personalTitle OBJ_pilotAttributeType,40L
2380
2381#define LN_mobileTelephoneNumber "mobileTelephoneNumber"
2382#define NID_mobileTelephoneNumber 488
2383#define OBJ_mobileTelephoneNumber OBJ_pilotAttributeType,41L
2384
2385#define LN_pagerTelephoneNumber "pagerTelephoneNumber"
2386#define NID_pagerTelephoneNumber 489
2387#define OBJ_pagerTelephoneNumber OBJ_pilotAttributeType,42L
2388
2389#define LN_friendlyCountryName "friendlyCountryName"
2390#define NID_friendlyCountryName 490
2391#define OBJ_friendlyCountryName OBJ_pilotAttributeType,43L
2392
2393#define LN_organizationalStatus "organizationalStatus"
2394#define NID_organizationalStatus 491
2395#define OBJ_organizationalStatus OBJ_pilotAttributeType,45L
2396
2397#define LN_janetMailbox "janetMailbox"
2398#define NID_janetMailbox 492
2399#define OBJ_janetMailbox OBJ_pilotAttributeType,46L
2400
2401#define LN_mailPreferenceOption "mailPreferenceOption"
2402#define NID_mailPreferenceOption 493
2403#define OBJ_mailPreferenceOption OBJ_pilotAttributeType,47L
2404
2405#define LN_buildingName "buildingName"
2406#define NID_buildingName 494
2407#define OBJ_buildingName OBJ_pilotAttributeType,48L
2408
2409#define LN_dSAQuality "dSAQuality"
2410#define NID_dSAQuality 495
2411#define OBJ_dSAQuality OBJ_pilotAttributeType,49L
2412
2413#define LN_singleLevelQuality "singleLevelQuality"
2414#define NID_singleLevelQuality 496
2415#define OBJ_singleLevelQuality OBJ_pilotAttributeType,50L
2416
2417#define LN_subtreeMinimumQuality "subtreeMinimumQuality"
2418#define NID_subtreeMinimumQuality 497
2419#define OBJ_subtreeMinimumQuality OBJ_pilotAttributeType,51L
2420
2421#define LN_subtreeMaximumQuality "subtreeMaximumQuality"
2422#define NID_subtreeMaximumQuality 498
2423#define OBJ_subtreeMaximumQuality OBJ_pilotAttributeType,52L
2424
2425#define LN_personalSignature "personalSignature"
2426#define NID_personalSignature 499
2427#define OBJ_personalSignature OBJ_pilotAttributeType,53L
2428
2429#define LN_dITRedirect "dITRedirect"
2430#define NID_dITRedirect 500
2431#define OBJ_dITRedirect OBJ_pilotAttributeType,54L
2432
2433#define SN_audio "audio"
2434#define NID_audio 501
2435#define OBJ_audio OBJ_pilotAttributeType,55L
2436
2437#define LN_documentPublisher "documentPublisher"
2438#define NID_documentPublisher 502
2439#define OBJ_documentPublisher OBJ_pilotAttributeType,56L
2440
2441#define SN_id_set "id-set"
2442#define LN_id_set "Secure Electronic Transactions"
2443#define NID_id_set 512
2444#define OBJ_id_set 2L,23L,42L
2445
2446#define SN_set_ctype "set-ctype"
2447#define LN_set_ctype "content types"
2448#define NID_set_ctype 513
2449#define OBJ_set_ctype OBJ_id_set,0L
2450
2451#define SN_set_msgExt "set-msgExt"
2452#define LN_set_msgExt "message extensions"
2453#define NID_set_msgExt 514
2454#define OBJ_set_msgExt OBJ_id_set,1L
2455
2456#define SN_set_attr "set-attr"
2457#define NID_set_attr 515
2458#define OBJ_set_attr OBJ_id_set,3L
2459
2460#define SN_set_policy "set-policy"
2461#define NID_set_policy 516
2462#define OBJ_set_policy OBJ_id_set,5L
2463
2464#define SN_set_certExt "set-certExt"
2465#define LN_set_certExt "certificate extensions"
2466#define NID_set_certExt 517
2467#define OBJ_set_certExt OBJ_id_set,7L
2468
2469#define SN_set_brand "set-brand"
2470#define NID_set_brand 518
2471#define OBJ_set_brand OBJ_id_set,8L
2472
2473#define SN_setct_PANData "setct-PANData"
2474#define NID_setct_PANData 519
2475#define OBJ_setct_PANData OBJ_set_ctype,0L
2476
2477#define SN_setct_PANToken "setct-PANToken"
2478#define NID_setct_PANToken 520
2479#define OBJ_setct_PANToken OBJ_set_ctype,1L
2480
2481#define SN_setct_PANOnly "setct-PANOnly"
2482#define NID_setct_PANOnly 521
2483#define OBJ_setct_PANOnly OBJ_set_ctype,2L
2484
2485#define SN_setct_OIData "setct-OIData"
2486#define NID_setct_OIData 522
2487#define OBJ_setct_OIData OBJ_set_ctype,3L
2488
2489#define SN_setct_PI "setct-PI"
2490#define NID_setct_PI 523
2491#define OBJ_setct_PI OBJ_set_ctype,4L
2492
2493#define SN_setct_PIData "setct-PIData"
2494#define NID_setct_PIData 524
2495#define OBJ_setct_PIData OBJ_set_ctype,5L
2496
2497#define SN_setct_PIDataUnsigned "setct-PIDataUnsigned"
2498#define NID_setct_PIDataUnsigned 525
2499#define OBJ_setct_PIDataUnsigned OBJ_set_ctype,6L
2500
2501#define SN_setct_HODInput "setct-HODInput"
2502#define NID_setct_HODInput 526
2503#define OBJ_setct_HODInput OBJ_set_ctype,7L
2504
2505#define SN_setct_AuthResBaggage "setct-AuthResBaggage"
2506#define NID_setct_AuthResBaggage 527
2507#define OBJ_setct_AuthResBaggage OBJ_set_ctype,8L
2508
2509#define SN_setct_AuthRevReqBaggage "setct-AuthRevReqBaggage"
2510#define NID_setct_AuthRevReqBaggage 528
2511#define OBJ_setct_AuthRevReqBaggage OBJ_set_ctype,9L
2512
2513#define SN_setct_AuthRevResBaggage "setct-AuthRevResBaggage"
2514#define NID_setct_AuthRevResBaggage 529
2515#define OBJ_setct_AuthRevResBaggage OBJ_set_ctype,10L
2516
2517#define SN_setct_CapTokenSeq "setct-CapTokenSeq"
2518#define NID_setct_CapTokenSeq 530
2519#define OBJ_setct_CapTokenSeq OBJ_set_ctype,11L
2520
2521#define SN_setct_PInitResData "setct-PInitResData"
2522#define NID_setct_PInitResData 531
2523#define OBJ_setct_PInitResData OBJ_set_ctype,12L
2524
2525#define SN_setct_PI_TBS "setct-PI-TBS"
2526#define NID_setct_PI_TBS 532
2527#define OBJ_setct_PI_TBS OBJ_set_ctype,13L
2528
2529#define SN_setct_PResData "setct-PResData"
2530#define NID_setct_PResData 533
2531#define OBJ_setct_PResData OBJ_set_ctype,14L
2532
2533#define SN_setct_AuthReqTBS "setct-AuthReqTBS"
2534#define NID_setct_AuthReqTBS 534
2535#define OBJ_setct_AuthReqTBS OBJ_set_ctype,16L
2536
2537#define SN_setct_AuthResTBS "setct-AuthResTBS"
2538#define NID_setct_AuthResTBS 535
2539#define OBJ_setct_AuthResTBS OBJ_set_ctype,17L
2540
2541#define SN_setct_AuthResTBSX "setct-AuthResTBSX"
2542#define NID_setct_AuthResTBSX 536
2543#define OBJ_setct_AuthResTBSX OBJ_set_ctype,18L
2544
2545#define SN_setct_AuthTokenTBS "setct-AuthTokenTBS"
2546#define NID_setct_AuthTokenTBS 537
2547#define OBJ_setct_AuthTokenTBS OBJ_set_ctype,19L
2548
2549#define SN_setct_CapTokenData "setct-CapTokenData"
2550#define NID_setct_CapTokenData 538
2551#define OBJ_setct_CapTokenData OBJ_set_ctype,20L
2552
2553#define SN_setct_CapTokenTBS "setct-CapTokenTBS"
2554#define NID_setct_CapTokenTBS 539
2555#define OBJ_setct_CapTokenTBS OBJ_set_ctype,21L
2556
2557#define SN_setct_AcqCardCodeMsg "setct-AcqCardCodeMsg"
2558#define NID_setct_AcqCardCodeMsg 540
2559#define OBJ_setct_AcqCardCodeMsg OBJ_set_ctype,22L
2560
2561#define SN_setct_AuthRevReqTBS "setct-AuthRevReqTBS"
2562#define NID_setct_AuthRevReqTBS 541
2563#define OBJ_setct_AuthRevReqTBS OBJ_set_ctype,23L
2564
2565#define SN_setct_AuthRevResData "setct-AuthRevResData"
2566#define NID_setct_AuthRevResData 542
2567#define OBJ_setct_AuthRevResData OBJ_set_ctype,24L
2568
2569#define SN_setct_AuthRevResTBS "setct-AuthRevResTBS"
2570#define NID_setct_AuthRevResTBS 543
2571#define OBJ_setct_AuthRevResTBS OBJ_set_ctype,25L
2572
2573#define SN_setct_CapReqTBS "setct-CapReqTBS"
2574#define NID_setct_CapReqTBS 544
2575#define OBJ_setct_CapReqTBS OBJ_set_ctype,26L
2576
2577#define SN_setct_CapReqTBSX "setct-CapReqTBSX"
2578#define NID_setct_CapReqTBSX 545
2579#define OBJ_setct_CapReqTBSX OBJ_set_ctype,27L
2580
2581#define SN_setct_CapResData "setct-CapResData"
2582#define NID_setct_CapResData 546
2583#define OBJ_setct_CapResData OBJ_set_ctype,28L
2584
2585#define SN_setct_CapRevReqTBS "setct-CapRevReqTBS"
2586#define NID_setct_CapRevReqTBS 547
2587#define OBJ_setct_CapRevReqTBS OBJ_set_ctype,29L
2588
2589#define SN_setct_CapRevReqTBSX "setct-CapRevReqTBSX"
2590#define NID_setct_CapRevReqTBSX 548
2591#define OBJ_setct_CapRevReqTBSX OBJ_set_ctype,30L
2592
2593#define SN_setct_CapRevResData "setct-CapRevResData"
2594#define NID_setct_CapRevResData 549
2595#define OBJ_setct_CapRevResData OBJ_set_ctype,31L
2596
2597#define SN_setct_CredReqTBS "setct-CredReqTBS"
2598#define NID_setct_CredReqTBS 550
2599#define OBJ_setct_CredReqTBS OBJ_set_ctype,32L
2600
2601#define SN_setct_CredReqTBSX "setct-CredReqTBSX"
2602#define NID_setct_CredReqTBSX 551
2603#define OBJ_setct_CredReqTBSX OBJ_set_ctype,33L
2604
2605#define SN_setct_CredResData "setct-CredResData"
2606#define NID_setct_CredResData 552
2607#define OBJ_setct_CredResData OBJ_set_ctype,34L
2608
2609#define SN_setct_CredRevReqTBS "setct-CredRevReqTBS"
2610#define NID_setct_CredRevReqTBS 553
2611#define OBJ_setct_CredRevReqTBS OBJ_set_ctype,35L
2612
2613#define SN_setct_CredRevReqTBSX "setct-CredRevReqTBSX"
2614#define NID_setct_CredRevReqTBSX 554
2615#define OBJ_setct_CredRevReqTBSX OBJ_set_ctype,36L
2616
2617#define SN_setct_CredRevResData "setct-CredRevResData"
2618#define NID_setct_CredRevResData 555
2619#define OBJ_setct_CredRevResData OBJ_set_ctype,37L
2620
2621#define SN_setct_PCertReqData "setct-PCertReqData"
2622#define NID_setct_PCertReqData 556
2623#define OBJ_setct_PCertReqData OBJ_set_ctype,38L
2624
2625#define SN_setct_PCertResTBS "setct-PCertResTBS"
2626#define NID_setct_PCertResTBS 557
2627#define OBJ_setct_PCertResTBS OBJ_set_ctype,39L
2628
2629#define SN_setct_BatchAdminReqData "setct-BatchAdminReqData"
2630#define NID_setct_BatchAdminReqData 558
2631#define OBJ_setct_BatchAdminReqData OBJ_set_ctype,40L
2632
2633#define SN_setct_BatchAdminResData "setct-BatchAdminResData"
2634#define NID_setct_BatchAdminResData 559
2635#define OBJ_setct_BatchAdminResData OBJ_set_ctype,41L
2636
2637#define SN_setct_CardCInitResTBS "setct-CardCInitResTBS"
2638#define NID_setct_CardCInitResTBS 560
2639#define OBJ_setct_CardCInitResTBS OBJ_set_ctype,42L
2640
2641#define SN_setct_MeAqCInitResTBS "setct-MeAqCInitResTBS"
2642#define NID_setct_MeAqCInitResTBS 561
2643#define OBJ_setct_MeAqCInitResTBS OBJ_set_ctype,43L
2644
2645#define SN_setct_RegFormResTBS "setct-RegFormResTBS"
2646#define NID_setct_RegFormResTBS 562
2647#define OBJ_setct_RegFormResTBS OBJ_set_ctype,44L
2648
2649#define SN_setct_CertReqData "setct-CertReqData"
2650#define NID_setct_CertReqData 563
2651#define OBJ_setct_CertReqData OBJ_set_ctype,45L
2652
2653#define SN_setct_CertReqTBS "setct-CertReqTBS"
2654#define NID_setct_CertReqTBS 564
2655#define OBJ_setct_CertReqTBS OBJ_set_ctype,46L
2656
2657#define SN_setct_CertResData "setct-CertResData"
2658#define NID_setct_CertResData 565
2659#define OBJ_setct_CertResData OBJ_set_ctype,47L
2660
2661#define SN_setct_CertInqReqTBS "setct-CertInqReqTBS"
2662#define NID_setct_CertInqReqTBS 566
2663#define OBJ_setct_CertInqReqTBS OBJ_set_ctype,48L
2664
2665#define SN_setct_ErrorTBS "setct-ErrorTBS"
2666#define NID_setct_ErrorTBS 567
2667#define OBJ_setct_ErrorTBS OBJ_set_ctype,49L
2668
2669#define SN_setct_PIDualSignedTBE "setct-PIDualSignedTBE"
2670#define NID_setct_PIDualSignedTBE 568
2671#define OBJ_setct_PIDualSignedTBE OBJ_set_ctype,50L
2672
2673#define SN_setct_PIUnsignedTBE "setct-PIUnsignedTBE"
2674#define NID_setct_PIUnsignedTBE 569
2675#define OBJ_setct_PIUnsignedTBE OBJ_set_ctype,51L
2676
2677#define SN_setct_AuthReqTBE "setct-AuthReqTBE"
2678#define NID_setct_AuthReqTBE 570
2679#define OBJ_setct_AuthReqTBE OBJ_set_ctype,52L
2680
2681#define SN_setct_AuthResTBE "setct-AuthResTBE"
2682#define NID_setct_AuthResTBE 571
2683#define OBJ_setct_AuthResTBE OBJ_set_ctype,53L
2684
2685#define SN_setct_AuthResTBEX "setct-AuthResTBEX"
2686#define NID_setct_AuthResTBEX 572
2687#define OBJ_setct_AuthResTBEX OBJ_set_ctype,54L
2688
2689#define SN_setct_AuthTokenTBE "setct-AuthTokenTBE"
2690#define NID_setct_AuthTokenTBE 573
2691#define OBJ_setct_AuthTokenTBE OBJ_set_ctype,55L
2692
2693#define SN_setct_CapTokenTBE "setct-CapTokenTBE"
2694#define NID_setct_CapTokenTBE 574
2695#define OBJ_setct_CapTokenTBE OBJ_set_ctype,56L
2696
2697#define SN_setct_CapTokenTBEX "setct-CapTokenTBEX"
2698#define NID_setct_CapTokenTBEX 575
2699#define OBJ_setct_CapTokenTBEX OBJ_set_ctype,57L
2700
2701#define SN_setct_AcqCardCodeMsgTBE "setct-AcqCardCodeMsgTBE"
2702#define NID_setct_AcqCardCodeMsgTBE 576
2703#define OBJ_setct_AcqCardCodeMsgTBE OBJ_set_ctype,58L
2704
2705#define SN_setct_AuthRevReqTBE "setct-AuthRevReqTBE"
2706#define NID_setct_AuthRevReqTBE 577
2707#define OBJ_setct_AuthRevReqTBE OBJ_set_ctype,59L
2708
2709#define SN_setct_AuthRevResTBE "setct-AuthRevResTBE"
2710#define NID_setct_AuthRevResTBE 578
2711#define OBJ_setct_AuthRevResTBE OBJ_set_ctype,60L
2712
2713#define SN_setct_AuthRevResTBEB "setct-AuthRevResTBEB"
2714#define NID_setct_AuthRevResTBEB 579
2715#define OBJ_setct_AuthRevResTBEB OBJ_set_ctype,61L
2716
2717#define SN_setct_CapReqTBE "setct-CapReqTBE"
2718#define NID_setct_CapReqTBE 580
2719#define OBJ_setct_CapReqTBE OBJ_set_ctype,62L
2720
2721#define SN_setct_CapReqTBEX "setct-CapReqTBEX"
2722#define NID_setct_CapReqTBEX 581
2723#define OBJ_setct_CapReqTBEX OBJ_set_ctype,63L
2724
2725#define SN_setct_CapResTBE "setct-CapResTBE"
2726#define NID_setct_CapResTBE 582
2727#define OBJ_setct_CapResTBE OBJ_set_ctype,64L
2728
2729#define SN_setct_CapRevReqTBE "setct-CapRevReqTBE"
2730#define NID_setct_CapRevReqTBE 583
2731#define OBJ_setct_CapRevReqTBE OBJ_set_ctype,65L
2732
2733#define SN_setct_CapRevReqTBEX "setct-CapRevReqTBEX"
2734#define NID_setct_CapRevReqTBEX 584
2735#define OBJ_setct_CapRevReqTBEX OBJ_set_ctype,66L
2736
2737#define SN_setct_CapRevResTBE "setct-CapRevResTBE"
2738#define NID_setct_CapRevResTBE 585
2739#define OBJ_setct_CapRevResTBE OBJ_set_ctype,67L
2740
2741#define SN_setct_CredReqTBE "setct-CredReqTBE"
2742#define NID_setct_CredReqTBE 586
2743#define OBJ_setct_CredReqTBE OBJ_set_ctype,68L
2744
2745#define SN_setct_CredReqTBEX "setct-CredReqTBEX"
2746#define NID_setct_CredReqTBEX 587
2747#define OBJ_setct_CredReqTBEX OBJ_set_ctype,69L
2748
2749#define SN_setct_CredResTBE "setct-CredResTBE"
2750#define NID_setct_CredResTBE 588
2751#define OBJ_setct_CredResTBE OBJ_set_ctype,70L
2752
2753#define SN_setct_CredRevReqTBE "setct-CredRevReqTBE"
2754#define NID_setct_CredRevReqTBE 589
2755#define OBJ_setct_CredRevReqTBE OBJ_set_ctype,71L
2756
2757#define SN_setct_CredRevReqTBEX "setct-CredRevReqTBEX"
2758#define NID_setct_CredRevReqTBEX 590
2759#define OBJ_setct_CredRevReqTBEX OBJ_set_ctype,72L
2760
2761#define SN_setct_CredRevResTBE "setct-CredRevResTBE"
2762#define NID_setct_CredRevResTBE 591
2763#define OBJ_setct_CredRevResTBE OBJ_set_ctype,73L
2764
2765#define SN_setct_BatchAdminReqTBE "setct-BatchAdminReqTBE"
2766#define NID_setct_BatchAdminReqTBE 592
2767#define OBJ_setct_BatchAdminReqTBE OBJ_set_ctype,74L
2768
2769#define SN_setct_BatchAdminResTBE "setct-BatchAdminResTBE"
2770#define NID_setct_BatchAdminResTBE 593
2771#define OBJ_setct_BatchAdminResTBE OBJ_set_ctype,75L
2772
2773#define SN_setct_RegFormReqTBE "setct-RegFormReqTBE"
2774#define NID_setct_RegFormReqTBE 594
2775#define OBJ_setct_RegFormReqTBE OBJ_set_ctype,76L
2776
2777#define SN_setct_CertReqTBE "setct-CertReqTBE"
2778#define NID_setct_CertReqTBE 595
2779#define OBJ_setct_CertReqTBE OBJ_set_ctype,77L
2780
2781#define SN_setct_CertReqTBEX "setct-CertReqTBEX"
2782#define NID_setct_CertReqTBEX 596
2783#define OBJ_setct_CertReqTBEX OBJ_set_ctype,78L
2784
2785#define SN_setct_CertResTBE "setct-CertResTBE"
2786#define NID_setct_CertResTBE 597
2787#define OBJ_setct_CertResTBE OBJ_set_ctype,79L
2788
2789#define SN_setct_CRLNotificationTBS "setct-CRLNotificationTBS"
2790#define NID_setct_CRLNotificationTBS 598
2791#define OBJ_setct_CRLNotificationTBS OBJ_set_ctype,80L
2792
2793#define SN_setct_CRLNotificationResTBS "setct-CRLNotificationResTBS"
2794#define NID_setct_CRLNotificationResTBS 599
2795#define OBJ_setct_CRLNotificationResTBS OBJ_set_ctype,81L
2796
2797#define SN_setct_BCIDistributionTBS "setct-BCIDistributionTBS"
2798#define NID_setct_BCIDistributionTBS 600
2799#define OBJ_setct_BCIDistributionTBS OBJ_set_ctype,82L
2800
2801#define SN_setext_genCrypt "setext-genCrypt"
2802#define LN_setext_genCrypt "generic cryptogram"
2803#define NID_setext_genCrypt 601
2804#define OBJ_setext_genCrypt OBJ_set_msgExt,1L
2805
2806#define SN_setext_miAuth "setext-miAuth"
2807#define LN_setext_miAuth "merchant initiated auth"
2808#define NID_setext_miAuth 602
2809#define OBJ_setext_miAuth OBJ_set_msgExt,3L
2810
2811#define SN_setext_pinSecure "setext-pinSecure"
2812#define NID_setext_pinSecure 603
2813#define OBJ_setext_pinSecure OBJ_set_msgExt,4L
2814
2815#define SN_setext_pinAny "setext-pinAny"
2816#define NID_setext_pinAny 604
2817#define OBJ_setext_pinAny OBJ_set_msgExt,5L
2818
2819#define SN_setext_track2 "setext-track2"
2820#define NID_setext_track2 605
2821#define OBJ_setext_track2 OBJ_set_msgExt,7L
2822
2823#define SN_setext_cv "setext-cv"
2824#define LN_setext_cv "additional verification"
2825#define NID_setext_cv 606
2826#define OBJ_setext_cv OBJ_set_msgExt,8L
2827
2828#define SN_set_policy_root "set-policy-root"
2829#define NID_set_policy_root 607
2830#define OBJ_set_policy_root OBJ_set_policy,0L
2831
2832#define SN_setCext_hashedRoot "setCext-hashedRoot"
2833#define NID_setCext_hashedRoot 608
2834#define OBJ_setCext_hashedRoot OBJ_set_certExt,0L
2835
2836#define SN_setCext_certType "setCext-certType"
2837#define NID_setCext_certType 609
2838#define OBJ_setCext_certType OBJ_set_certExt,1L
2839
2840#define SN_setCext_merchData "setCext-merchData"
2841#define NID_setCext_merchData 610
2842#define OBJ_setCext_merchData OBJ_set_certExt,2L
2843
2844#define SN_setCext_cCertRequired "setCext-cCertRequired"
2845#define NID_setCext_cCertRequired 611
2846#define OBJ_setCext_cCertRequired OBJ_set_certExt,3L
2847
2848#define SN_setCext_tunneling "setCext-tunneling"
2849#define NID_setCext_tunneling 612
2850#define OBJ_setCext_tunneling OBJ_set_certExt,4L
2851
2852#define SN_setCext_setExt "setCext-setExt"
2853#define NID_setCext_setExt 613
2854#define OBJ_setCext_setExt OBJ_set_certExt,5L
2855
2856#define SN_setCext_setQualf "setCext-setQualf"
2857#define NID_setCext_setQualf 614
2858#define OBJ_setCext_setQualf OBJ_set_certExt,6L
2859
2860#define SN_setCext_PGWYcapabilities "setCext-PGWYcapabilities"
2861#define NID_setCext_PGWYcapabilities 615
2862#define OBJ_setCext_PGWYcapabilities OBJ_set_certExt,7L
2863
2864#define SN_setCext_TokenIdentifier "setCext-TokenIdentifier"
2865#define NID_setCext_TokenIdentifier 616
2866#define OBJ_setCext_TokenIdentifier OBJ_set_certExt,8L
2867
2868#define SN_setCext_Track2Data "setCext-Track2Data"
2869#define NID_setCext_Track2Data 617
2870#define OBJ_setCext_Track2Data OBJ_set_certExt,9L
2871
2872#define SN_setCext_TokenType "setCext-TokenType"
2873#define NID_setCext_TokenType 618
2874#define OBJ_setCext_TokenType OBJ_set_certExt,10L
2875
2876#define SN_setCext_IssuerCapabilities "setCext-IssuerCapabilities"
2877#define NID_setCext_IssuerCapabilities 619
2878#define OBJ_setCext_IssuerCapabilities OBJ_set_certExt,11L
2879
2880#define SN_setAttr_Cert "setAttr-Cert"
2881#define NID_setAttr_Cert 620
2882#define OBJ_setAttr_Cert OBJ_set_attr,0L
2883
2884#define SN_setAttr_PGWYcap "setAttr-PGWYcap"
2885#define LN_setAttr_PGWYcap "payment gateway capabilities"
2886#define NID_setAttr_PGWYcap 621
2887#define OBJ_setAttr_PGWYcap OBJ_set_attr,1L
2888
2889#define SN_setAttr_TokenType "setAttr-TokenType"
2890#define NID_setAttr_TokenType 622
2891#define OBJ_setAttr_TokenType OBJ_set_attr,2L
2892
2893#define SN_setAttr_IssCap "setAttr-IssCap"
2894#define LN_setAttr_IssCap "issuer capabilities"
2895#define NID_setAttr_IssCap 623
2896#define OBJ_setAttr_IssCap OBJ_set_attr,3L
2897
2898#define SN_set_rootKeyThumb "set-rootKeyThumb"
2899#define NID_set_rootKeyThumb 624
2900#define OBJ_set_rootKeyThumb OBJ_setAttr_Cert,0L
2901
2902#define SN_set_addPolicy "set-addPolicy"
2903#define NID_set_addPolicy 625
2904#define OBJ_set_addPolicy OBJ_setAttr_Cert,1L
2905
2906#define SN_setAttr_Token_EMV "setAttr-Token-EMV"
2907#define NID_setAttr_Token_EMV 626
2908#define OBJ_setAttr_Token_EMV OBJ_setAttr_TokenType,1L
2909
2910#define SN_setAttr_Token_B0Prime "setAttr-Token-B0Prime"
2911#define NID_setAttr_Token_B0Prime 627
2912#define OBJ_setAttr_Token_B0Prime OBJ_setAttr_TokenType,2L
2913
2914#define SN_setAttr_IssCap_CVM "setAttr-IssCap-CVM"
2915#define NID_setAttr_IssCap_CVM 628
2916#define OBJ_setAttr_IssCap_CVM OBJ_setAttr_IssCap,3L
2917
2918#define SN_setAttr_IssCap_T2 "setAttr-IssCap-T2"
2919#define NID_setAttr_IssCap_T2 629
2920#define OBJ_setAttr_IssCap_T2 OBJ_setAttr_IssCap,4L
2921
2922#define SN_setAttr_IssCap_Sig "setAttr-IssCap-Sig"
2923#define NID_setAttr_IssCap_Sig 630
2924#define OBJ_setAttr_IssCap_Sig OBJ_setAttr_IssCap,5L
2925
2926#define SN_setAttr_GenCryptgrm "setAttr-GenCryptgrm"
2927#define LN_setAttr_GenCryptgrm "generate cryptogram"
2928#define NID_setAttr_GenCryptgrm 631
2929#define OBJ_setAttr_GenCryptgrm OBJ_setAttr_IssCap_CVM,1L
2930
2931#define SN_setAttr_T2Enc "setAttr-T2Enc"
2932#define LN_setAttr_T2Enc "encrypted track 2"
2933#define NID_setAttr_T2Enc 632
2934#define OBJ_setAttr_T2Enc OBJ_setAttr_IssCap_T2,1L
2935
2936#define SN_setAttr_T2cleartxt "setAttr-T2cleartxt"
2937#define LN_setAttr_T2cleartxt "cleartext track 2"
2938#define NID_setAttr_T2cleartxt 633
2939#define OBJ_setAttr_T2cleartxt OBJ_setAttr_IssCap_T2,2L
2940
2941#define SN_setAttr_TokICCsig "setAttr-TokICCsig"
2942#define LN_setAttr_TokICCsig "ICC or token signature"
2943#define NID_setAttr_TokICCsig 634
2944#define OBJ_setAttr_TokICCsig OBJ_setAttr_IssCap_Sig,1L
2945
2946#define SN_setAttr_SecDevSig "setAttr-SecDevSig"
2947#define LN_setAttr_SecDevSig "secure device signature"
2948#define NID_setAttr_SecDevSig 635
2949#define OBJ_setAttr_SecDevSig OBJ_setAttr_IssCap_Sig,2L
2950
2951#define SN_set_brand_IATA_ATA "set-brand-IATA-ATA"
2952#define NID_set_brand_IATA_ATA 636
2953#define OBJ_set_brand_IATA_ATA OBJ_set_brand,1L
2954
2955#define SN_set_brand_Diners "set-brand-Diners"
2956#define NID_set_brand_Diners 637
2957#define OBJ_set_brand_Diners OBJ_set_brand,30L
2958
2959#define SN_set_brand_AmericanExpress "set-brand-AmericanExpress"
2960#define NID_set_brand_AmericanExpress 638
2961#define OBJ_set_brand_AmericanExpress OBJ_set_brand,34L
2962
2963#define SN_set_brand_JCB "set-brand-JCB"
2964#define NID_set_brand_JCB 639
2965#define OBJ_set_brand_JCB OBJ_set_brand,35L
2966
2967#define SN_set_brand_Visa "set-brand-Visa"
2968#define NID_set_brand_Visa 640
2969#define OBJ_set_brand_Visa OBJ_set_brand,4L
2970
2971#define SN_set_brand_MasterCard "set-brand-MasterCard"
2972#define NID_set_brand_MasterCard 641
2973#define OBJ_set_brand_MasterCard OBJ_set_brand,5L
2974
2975#define SN_set_brand_Novus "set-brand-Novus"
2976#define NID_set_brand_Novus 642
2977#define OBJ_set_brand_Novus OBJ_set_brand,6011L
2978
2979#define SN_des_cdmf "DES-CDMF"
2980#define LN_des_cdmf "des-cdmf"
2981#define NID_des_cdmf 643
2982#define OBJ_des_cdmf OBJ_rsadsi,3L,10L
2983
2984#define SN_rsaOAEPEncryptionSET "rsaOAEPEncryptionSET"
2985#define NID_rsaOAEPEncryptionSET 644
2986#define OBJ_rsaOAEPEncryptionSET OBJ_rsadsi,1L,1L,6L
2987
diff --git a/src/lib/libcrypto/objects/obj_mac.num b/src/lib/libcrypto/objects/obj_mac.num
new file mode 100644
index 0000000000..0e64a929ba
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_mac.num
@@ -0,0 +1,667 @@
1undef 0
2rsadsi 1
3pkcs 2
4md2 3
5md5 4
6rc4 5
7rsaEncryption 6
8md2WithRSAEncryption 7
9md5WithRSAEncryption 8
10pbeWithMD2AndDES_CBC 9
11pbeWithMD5AndDES_CBC 10
12X500 11
13X509 12
14commonName 13
15countryName 14
16localityName 15
17stateOrProvinceName 16
18organizationName 17
19organizationalUnitName 18
20rsa 19
21pkcs7 20
22pkcs7_data 21
23pkcs7_signed 22
24pkcs7_enveloped 23
25pkcs7_signedAndEnveloped 24
26pkcs7_digest 25
27pkcs7_encrypted 26
28pkcs3 27
29dhKeyAgreement 28
30des_ecb 29
31des_cfb64 30
32des_cbc 31
33des_ede_ecb 32
34des_ede3_ecb 33
35idea_cbc 34
36idea_cfb64 35
37idea_ecb 36
38rc2_cbc 37
39rc2_ecb 38
40rc2_cfb64 39
41rc2_ofb64 40
42sha 41
43shaWithRSAEncryption 42
44des_ede_cbc 43
45des_ede3_cbc 44
46des_ofb64 45
47idea_ofb64 46
48pkcs9 47
49pkcs9_emailAddress 48
50pkcs9_unstructuredName 49
51pkcs9_contentType 50
52pkcs9_messageDigest 51
53pkcs9_signingTime 52
54pkcs9_countersignature 53
55pkcs9_challengePassword 54
56pkcs9_unstructuredAddress 55
57pkcs9_extCertAttributes 56
58netscape 57
59netscape_cert_extension 58
60netscape_data_type 59
61des_ede_cfb64 60
62des_ede3_cfb64 61
63des_ede_ofb64 62
64des_ede3_ofb64 63
65sha1 64
66sha1WithRSAEncryption 65
67dsaWithSHA 66
68dsa_2 67
69pbeWithSHA1AndRC2_CBC 68
70id_pbkdf2 69
71dsaWithSHA1_2 70
72netscape_cert_type 71
73netscape_base_url 72
74netscape_revocation_url 73
75netscape_ca_revocation_url 74
76netscape_renewal_url 75
77netscape_ca_policy_url 76
78netscape_ssl_server_name 77
79netscape_comment 78
80netscape_cert_sequence 79
81desx_cbc 80
82id_ce 81
83subject_key_identifier 82
84key_usage 83
85private_key_usage_period 84
86subject_alt_name 85
87issuer_alt_name 86
88basic_constraints 87
89crl_number 88
90certificate_policies 89
91authority_key_identifier 90
92bf_cbc 91
93bf_ecb 92
94bf_cfb64 93
95bf_ofb64 94
96mdc2 95
97mdc2WithRSA 96
98rc4_40 97
99rc2_40_cbc 98
100givenName 99
101surname 100
102initials 101
103uniqueIdentifier 102
104crl_distribution_points 103
105md5WithRSA 104
106serialNumber 105
107title 106
108description 107
109cast5_cbc 108
110cast5_ecb 109
111cast5_cfb64 110
112cast5_ofb64 111
113pbeWithMD5AndCast5_CBC 112
114dsaWithSHA1 113
115md5_sha1 114
116sha1WithRSA 115
117dsa 116
118ripemd160 117
119ripemd160WithRSA 119
120rc5_cbc 120
121rc5_ecb 121
122rc5_cfb64 122
123rc5_ofb64 123
124rle_compression 124
125zlib_compression 125
126ext_key_usage 126
127id_pkix 127
128id_kp 128
129server_auth 129
130client_auth 130
131code_sign 131
132email_protect 132
133time_stamp 133
134ms_code_ind 134
135ms_code_com 135
136ms_ctl_sign 136
137ms_sgc 137
138ms_efs 138
139ns_sgc 139
140delta_crl 140
141crl_reason 141
142invalidity_date 142
143sxnet 143
144pbe_WithSHA1And128BitRC4 144
145pbe_WithSHA1And40BitRC4 145
146pbe_WithSHA1And3_Key_TripleDES_CBC 146
147pbe_WithSHA1And2_Key_TripleDES_CBC 147
148pbe_WithSHA1And128BitRC2_CBC 148
149pbe_WithSHA1And40BitRC2_CBC 149
150keyBag 150
151pkcs8ShroudedKeyBag 151
152certBag 152
153crlBag 153
154secretBag 154
155safeContentsBag 155
156friendlyName 156
157localKeyID 157
158x509Certificate 158
159sdsiCertificate 159
160x509Crl 160
161pbes2 161
162pbmac1 162
163hmacWithSHA1 163
164id_qt_cps 164
165id_qt_unotice 165
166rc2_64_cbc 166
167SMIMECapabilities 167
168pbeWithMD2AndRC2_CBC 168
169pbeWithMD5AndRC2_CBC 169
170pbeWithSHA1AndDES_CBC 170
171ms_ext_req 171
172ext_req 172
173name 173
174dnQualifier 174
175id_pe 175
176id_ad 176
177info_access 177
178ad_OCSP 178
179ad_ca_issuers 179
180OCSP_sign 180
181iso 181
182member_body 182
183ISO_US 183
184X9_57 184
185X9cm 185
186pkcs1 186
187pkcs5 187
188SMIME 188
189id_smime_mod 189
190id_smime_ct 190
191id_smime_aa 191
192id_smime_alg 192
193id_smime_cd 193
194id_smime_spq 194
195id_smime_cti 195
196id_smime_mod_cms 196
197id_smime_mod_ess 197
198id_smime_mod_oid 198
199id_smime_mod_msg_v3 199
200id_smime_mod_ets_eSignature_88 200
201id_smime_mod_ets_eSignature_97 201
202id_smime_mod_ets_eSigPolicy_88 202
203id_smime_mod_ets_eSigPolicy_97 203
204id_smime_ct_receipt 204
205id_smime_ct_authData 205
206id_smime_ct_publishCert 206
207id_smime_ct_TSTInfo 207
208id_smime_ct_TDTInfo 208
209id_smime_ct_contentInfo 209
210id_smime_ct_DVCSRequestData 210
211id_smime_ct_DVCSResponseData 211
212id_smime_aa_receiptRequest 212
213id_smime_aa_securityLabel 213
214id_smime_aa_mlExpandHistory 214
215id_smime_aa_contentHint 215
216id_smime_aa_msgSigDigest 216
217id_smime_aa_encapContentType 217
218id_smime_aa_contentIdentifier 218
219id_smime_aa_macValue 219
220id_smime_aa_equivalentLabels 220
221id_smime_aa_contentReference 221
222id_smime_aa_encrypKeyPref 222
223id_smime_aa_signingCertificate 223
224id_smime_aa_smimeEncryptCerts 224
225id_smime_aa_timeStampToken 225
226id_smime_aa_ets_sigPolicyId 226
227id_smime_aa_ets_commitmentType 227
228id_smime_aa_ets_signerLocation 228
229id_smime_aa_ets_signerAttr 229
230id_smime_aa_ets_otherSigCert 230
231id_smime_aa_ets_contentTimestamp 231
232id_smime_aa_ets_CertificateRefs 232
233id_smime_aa_ets_RevocationRefs 233
234id_smime_aa_ets_certValues 234
235id_smime_aa_ets_revocationValues 235
236id_smime_aa_ets_escTimeStamp 236
237id_smime_aa_ets_certCRLTimestamp 237
238id_smime_aa_ets_archiveTimeStamp 238
239id_smime_aa_signatureType 239
240id_smime_aa_dvcs_dvc 240
241id_smime_alg_ESDHwith3DES 241
242id_smime_alg_ESDHwithRC2 242
243id_smime_alg_3DESwrap 243
244id_smime_alg_RC2wrap 244
245id_smime_alg_ESDH 245
246id_smime_alg_CMS3DESwrap 246
247id_smime_alg_CMSRC2wrap 247
248id_smime_cd_ldap 248
249id_smime_spq_ets_sqt_uri 249
250id_smime_spq_ets_sqt_unotice 250
251id_smime_cti_ets_proofOfOrigin 251
252id_smime_cti_ets_proofOfReceipt 252
253id_smime_cti_ets_proofOfDelivery 253
254id_smime_cti_ets_proofOfSender 254
255id_smime_cti_ets_proofOfApproval 255
256id_smime_cti_ets_proofOfCreation 256
257md4 257
258id_pkix_mod 258
259id_qt 259
260id_it 260
261id_pkip 261
262id_alg 262
263id_cmc 263
264id_on 264
265id_pda 265
266id_aca 266
267id_qcs 267
268id_cct 268
269id_pkix1_explicit_88 269
270id_pkix1_implicit_88 270
271id_pkix1_explicit_93 271
272id_pkix1_implicit_93 272
273id_mod_crmf 273
274id_mod_cmc 274
275id_mod_kea_profile_88 275
276id_mod_kea_profile_93 276
277id_mod_cmp 277
278id_mod_qualified_cert_88 278
279id_mod_qualified_cert_93 279
280id_mod_attribute_cert 280
281id_mod_timestamp_protocol 281
282id_mod_ocsp 282
283id_mod_dvcs 283
284id_mod_cmp2000 284
285biometricInfo 285
286qcStatements 286
287ac_auditEntity 287
288ac_targeting 288
289aaControls 289
290sbqp_ipAddrBlock 290
291sbqp_autonomousSysNum 291
292sbqp_routerIdentifier 292
293textNotice 293
294ipsecEndSystem 294
295ipsecTunnel 295
296ipsecUser 296
297dvcs 297
298id_it_caProtEncCert 298
299id_it_signKeyPairTypes 299
300id_it_encKeyPairTypes 300
301id_it_preferredSymmAlg 301
302id_it_caKeyUpdateInfo 302
303id_it_currentCRL 303
304id_it_unsupportedOIDs 304
305id_it_subscriptionRequest 305
306id_it_subscriptionResponse 306
307id_it_keyPairParamReq 307
308id_it_keyPairParamRep 308
309id_it_revPassphrase 309
310id_it_implicitConfirm 310
311id_it_confirmWaitTime 311
312id_it_origPKIMessage 312
313id_regCtrl 313
314id_regInfo 314
315id_regCtrl_regToken 315
316id_regCtrl_authenticator 316
317id_regCtrl_pkiPublicationInfo 317
318id_regCtrl_pkiArchiveOptions 318
319id_regCtrl_oldCertID 319
320id_regCtrl_protocolEncrKey 320
321id_regInfo_utf8Pairs 321
322id_regInfo_certReq 322
323id_alg_des40 323
324id_alg_noSignature 324
325id_alg_dh_sig_hmac_sha1 325
326id_alg_dh_pop 326
327id_cmc_statusInfo 327
328id_cmc_identification 328
329id_cmc_identityProof 329
330id_cmc_dataReturn 330
331id_cmc_transactionId 331
332id_cmc_senderNonce 332
333id_cmc_recipientNonce 333
334id_cmc_addExtensions 334
335id_cmc_encryptedPOP 335
336id_cmc_decryptedPOP 336
337id_cmc_lraPOPWitness 337
338id_cmc_getCert 338
339id_cmc_getCRL 339
340id_cmc_revokeRequest 340
341id_cmc_regInfo 341
342id_cmc_responseInfo 342
343id_cmc_queryPending 343
344id_cmc_popLinkRandom 344
345id_cmc_popLinkWitness 345
346id_cmc_confirmCertAcceptance 346
347id_on_personalData 347
348id_pda_dateOfBirth 348
349id_pda_placeOfBirth 349
350id_pda_pseudonym 350
351id_pda_gender 351
352id_pda_countryOfCitizenship 352
353id_pda_countryOfResidence 353
354id_aca_authenticationInfo 354
355id_aca_accessIdentity 355
356id_aca_chargingIdentity 356
357id_aca_group 357
358id_aca_role 358
359id_qcs_pkixQCSyntax_v1 359
360id_cct_crs 360
361id_cct_PKIData 361
362id_cct_PKIResponse 362
363ad_timeStamping 363
364ad_dvcs 364
365id_pkix_OCSP_basic 365
366id_pkix_OCSP_Nonce 366
367id_pkix_OCSP_CrlID 367
368id_pkix_OCSP_acceptableResponses 368
369id_pkix_OCSP_noCheck 369
370id_pkix_OCSP_archiveCutoff 370
371id_pkix_OCSP_serviceLocator 371
372id_pkix_OCSP_extendedStatus 372
373id_pkix_OCSP_valid 373
374id_pkix_OCSP_path 374
375id_pkix_OCSP_trustRoot 375
376algorithm 376
377rsaSignature 377
378X500algorithms 378
379org 379
380dod 380
381iana 381
382Directory 382
383Management 383
384Experimental 384
385Private 385
386Security 386
387SNMPv2 387
388Mail 388
389Enterprises 389
390dcObject 390
391domainComponent 391
392Domain 392
393joint_iso_ccitt 393
394selected_attribute_types 394
395clearance 395
396md4WithRSAEncryption 396
397ac_proxying 397
398sinfo_access 398
399id_aca_encAttrs 399
400role 400
401policy_constraints 401
402target_information 402
403no_rev_avail 403
404ccitt 404
405ansi_X9_62 405
406X9_62_prime_field 406
407X9_62_characteristic_two_field 407
408X9_62_id_ecPublicKey 408
409X9_62_prime192v1 409
410X9_62_prime192v2 410
411X9_62_prime192v3 411
412X9_62_prime239v1 412
413X9_62_prime239v2 413
414X9_62_prime239v3 414
415X9_62_prime256v1 415
416ecdsa_with_SHA1 416
417ms_csp_name 417
418aes_128_ecb 418
419aes_128_cbc 419
420aes_128_ofb128 420
421aes_128_cfb128 421
422aes_192_ecb 422
423aes_192_cbc 423
424aes_192_ofb128 424
425aes_192_cfb128 425
426aes_256_ecb 426
427aes_256_cbc 427
428aes_256_ofb128 428
429aes_256_cfb128 429
430hold_instruction_code 430
431hold_instruction_none 431
432hold_instruction_call_issuer 432
433hold_instruction_reject 433
434data 434
435pss 435
436ucl 436
437pilot 437
438pilotAttributeType 438
439pilotAttributeSyntax 439
440pilotObjectClass 440
441pilotGroups 441
442iA5StringSyntax 442
443caseIgnoreIA5StringSyntax 443
444pilotObject 444
445pilotPerson 445
446account 446
447document 447
448room 448
449documentSeries 449
450rFC822localPart 450
451dNSDomain 451
452domainRelatedObject 452
453friendlyCountry 453
454simpleSecurityObject 454
455pilotOrganization 455
456pilotDSA 456
457qualityLabelledData 457
458userId 458
459textEncodedORAddress 459
460rfc822Mailbox 460
461info 461
462favouriteDrink 462
463roomNumber 463
464photo 464
465userClass 465
466host 466
467manager 467
468documentIdentifier 468
469documentTitle 469
470documentVersion 470
471documentAuthor 471
472documentLocation 472
473homeTelephoneNumber 473
474secretary 474
475otherMailbox 475
476lastModifiedTime 476
477lastModifiedBy 477
478aRecord 478
479pilotAttributeType27 479
480mXRecord 480
481nSRecord 481
482sOARecord 482
483cNAMERecord 483
484associatedDomain 484
485associatedName 485
486homePostalAddress 486
487personalTitle 487
488mobileTelephoneNumber 488
489pagerTelephoneNumber 489
490friendlyCountryName 490
491organizationalStatus 491
492janetMailbox 492
493mailPreferenceOption 493
494buildingName 494
495dSAQuality 495
496singleLevelQuality 496
497subtreeMinimumQuality 497
498subtreeMaximumQuality 498
499personalSignature 499
500dITRedirect 500
501audio 501
502documentPublisher 502
503x500UniqueIdentifier 503
504mime_mhs 504
505mime_mhs_headings 505
506mime_mhs_bodies 506
507id_hex_partial_message 507
508id_hex_multipart_message 508
509generationQualifier 509
510pseudonym 510
511InternationalRA 511
512id_set 512
513set_ctype 513
514set_msgExt 514
515set_attr 515
516set_policy 516
517set_certExt 517
518set_brand 518
519setct_PANData 519
520setct_PANToken 520
521setct_PANOnly 521
522setct_OIData 522
523setct_PI 523
524setct_PIData 524
525setct_PIDataUnsigned 525
526setct_HODInput 526
527setct_AuthResBaggage 527
528setct_AuthRevReqBaggage 528
529setct_AuthRevResBaggage 529
530setct_CapTokenSeq 530
531setct_PInitResData 531
532setct_PI_TBS 532
533setct_PResData 533
534setct_AuthReqTBS 534
535setct_AuthResTBS 535
536setct_AuthResTBSX 536
537setct_AuthTokenTBS 537
538setct_CapTokenData 538
539setct_CapTokenTBS 539
540setct_AcqCardCodeMsg 540
541setct_AuthRevReqTBS 541
542setct_AuthRevResData 542
543setct_AuthRevResTBS 543
544setct_CapReqTBS 544
545setct_CapReqTBSX 545
546setct_CapResData 546
547setct_CapRevReqTBS 547
548setct_CapRevReqTBSX 548
549setct_CapRevResData 549
550setct_CredReqTBS 550
551setct_CredReqTBSX 551
552setct_CredResData 552
553setct_CredRevReqTBS 553
554setct_CredRevReqTBSX 554
555setct_CredRevResData 555
556setct_PCertReqData 556
557setct_PCertResTBS 557
558setct_BatchAdminReqData 558
559setct_BatchAdminResData 559
560setct_CardCInitResTBS 560
561setct_MeAqCInitResTBS 561
562setct_RegFormResTBS 562
563setct_CertReqData 563
564setct_CertReqTBS 564
565setct_CertResData 565
566setct_CertInqReqTBS 566
567setct_ErrorTBS 567
568setct_PIDualSignedTBE 568
569setct_PIUnsignedTBE 569
570setct_AuthReqTBE 570
571setct_AuthResTBE 571
572setct_AuthResTBEX 572
573setct_AuthTokenTBE 573
574setct_CapTokenTBE 574
575setct_CapTokenTBEX 575
576setct_AcqCardCodeMsgTBE 576
577setct_AuthRevReqTBE 577
578setct_AuthRevResTBE 578
579setct_AuthRevResTBEB 579
580setct_CapReqTBE 580
581setct_CapReqTBEX 581
582setct_CapResTBE 582
583setct_CapRevReqTBE 583
584setct_CapRevReqTBEX 584
585setct_CapRevResTBE 585
586setct_CredReqTBE 586
587setct_CredReqTBEX 587
588setct_CredResTBE 588
589setct_CredRevReqTBE 589
590setct_CredRevReqTBEX 590
591setct_CredRevResTBE 591
592setct_BatchAdminReqTBE 592
593setct_BatchAdminResTBE 593
594setct_RegFormReqTBE 594
595setct_CertReqTBE 595
596setct_CertReqTBEX 596
597setct_CertResTBE 597
598setct_CRLNotificationTBS 598
599setct_CRLNotificationResTBS 599
600setct_BCIDistributionTBS 600
601setext_genCrypt 601
602setext_miAuth 602
603setext_pinSecure 603
604setext_pinAny 604
605setext_track2 605
606setext_cv 606
607set_policy_root 607
608setCext_hashedRoot 608
609setCext_certType 609
610setCext_merchData 610
611setCext_cCertRequired 611
612setCext_tunneling 612
613setCext_setExt 613
614setCext_setQualf 614
615setCext_PGWYcapabilities 615
616setCext_TokenIdentifier 616
617setCext_Track2Data 617
618setCext_TokenType 618
619setCext_IssuerCapabilities 619
620setAttr_Cert 620
621setAttr_PGWYcap 621
622setAttr_TokenType 622
623setAttr_IssCap 623
624set_rootKeyThumb 624
625set_addPolicy 625
626setAttr_Token_EMV 626
627setAttr_Token_B0Prime 627
628setAttr_IssCap_CVM 628
629setAttr_IssCap_T2 629
630setAttr_IssCap_Sig 630
631setAttr_GenCryptgrm 631
632setAttr_T2Enc 632
633setAttr_T2cleartxt 633
634setAttr_TokICCsig 634
635setAttr_SecDevSig 635
636set_brand_IATA_ATA 636
637set_brand_Diners 637
638set_brand_AmericanExpress 638
639set_brand_JCB 639
640set_brand_Visa 640
641set_brand_MasterCard 641
642set_brand_Novus 642
643des_cdmf 643
644rsaOAEPEncryptionSET 644
645itu_t 645
646joint_iso_itu_t 646
647international_organizations 647
648ms_smartcard_login 648
649ms_upn 649
650aes_128_cfb1 650
651aes_192_cfb1 651
652aes_256_cfb1 652
653aes_128_cfb8 653
654aes_192_cfb8 654
655aes_256_cfb8 655
656des_cfb1 656
657des_cfb8 657
658des_ede3_cfb1 658
659des_ede3_cfb8 659
660streetAddress 660
661postalCode 661
662id_ppl 662
663proxyCertInfo 663
664id_ppl_anyLanguage 664
665id_ppl_inheritAll 665
666id_ppl_independent 666
667Independent 667
diff --git a/src/lib/libcrypto/objects/objects.README b/src/lib/libcrypto/objects/objects.README
new file mode 100644
index 0000000000..4d745508d8
--- /dev/null
+++ b/src/lib/libcrypto/objects/objects.README
@@ -0,0 +1,44 @@
1objects.txt syntax
2------------------
3
4To cover all the naming hacks that were previously in objects.h needed some
5kind of hacks in objects.txt.
6
7The basic syntax for adding an object is as follows:
8
9 1 2 3 4 : shortName : Long Name
10
11 If the long name doesn't contain spaces, or no short name
12 exists, the long name is used as basis for the base name
13 in C. Otherwise, the short name is used.
14
15 The base name (let's call it 'base') will then be used to
16 create the C macros SN_base, LN_base, NID_base and OBJ_base.
17
18 Note that if the base name contains spaces, dashes or periods,
19 those will be converte to underscore.
20
21Then there are some extra commands:
22
23 !Alias foo 1 2 3 4
24
25 This juts makes a name foo for an OID. The C macro
26 OBJ_foo will be created as a result.
27
28 !Cname foo
29
30 This makes sure that the name foo will be used as base name
31 in C.
32
33 !module foo
34 1 2 3 4 : shortName : Long Name
35 !global
36
37 The !module command was meant to define a kind of modularity.
38 What it does is to make sure the module name is prepended
39 to the base name. !global turns this off. This construction
40 is not recursive.
41
42Lines starting with # are treated as comments, as well as any line starting
43with ! and not matching the commands above.
44
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
new file mode 100644
index 0000000000..f859d859b8
--- /dev/null
+++ b/src/lib/libcrypto/objects/objects.h
@@ -0,0 +1,1044 @@
1/* crypto/objects/objects.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_OBJECTS_H
60#define HEADER_OBJECTS_H
61
62#define USE_OBJ_MAC
63
64#ifdef USE_OBJ_MAC
65#include <openssl/obj_mac.h>
66#else
67#define SN_undef "UNDEF"
68#define LN_undef "undefined"
69#define NID_undef 0
70#define OBJ_undef 0L
71
72#define SN_Algorithm "Algorithm"
73#define LN_algorithm "algorithm"
74#define NID_algorithm 38
75#define OBJ_algorithm 1L,3L,14L,3L,2L
76
77#define LN_rsadsi "rsadsi"
78#define NID_rsadsi 1
79#define OBJ_rsadsi 1L,2L,840L,113549L
80
81#define LN_pkcs "pkcs"
82#define NID_pkcs 2
83#define OBJ_pkcs OBJ_rsadsi,1L
84
85#define SN_md2 "MD2"
86#define LN_md2 "md2"
87#define NID_md2 3
88#define OBJ_md2 OBJ_rsadsi,2L,2L
89
90#define SN_md5 "MD5"
91#define LN_md5 "md5"
92#define NID_md5 4
93#define OBJ_md5 OBJ_rsadsi,2L,5L
94
95#define SN_rc4 "RC4"
96#define LN_rc4 "rc4"
97#define NID_rc4 5
98#define OBJ_rc4 OBJ_rsadsi,3L,4L
99
100#define LN_rsaEncryption "rsaEncryption"
101#define NID_rsaEncryption 6
102#define OBJ_rsaEncryption OBJ_pkcs,1L,1L
103
104#define SN_md2WithRSAEncryption "RSA-MD2"
105#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
106#define NID_md2WithRSAEncryption 7
107#define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L
108
109#define SN_md5WithRSAEncryption "RSA-MD5"
110#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
111#define NID_md5WithRSAEncryption 8
112#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L
113
114#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
115#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
116#define NID_pbeWithMD2AndDES_CBC 9
117#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L
118
119#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
120#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
121#define NID_pbeWithMD5AndDES_CBC 10
122#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L
123
124#define LN_X500 "X500"
125#define NID_X500 11
126#define OBJ_X500 2L,5L
127
128#define LN_X509 "X509"
129#define NID_X509 12
130#define OBJ_X509 OBJ_X500,4L
131
132#define SN_commonName "CN"
133#define LN_commonName "commonName"
134#define NID_commonName 13
135#define OBJ_commonName OBJ_X509,3L
136
137#define SN_countryName "C"
138#define LN_countryName "countryName"
139#define NID_countryName 14
140#define OBJ_countryName OBJ_X509,6L
141
142#define SN_localityName "L"
143#define LN_localityName "localityName"
144#define NID_localityName 15
145#define OBJ_localityName OBJ_X509,7L
146
147/* Postal Address? PA */
148
149/* should be "ST" (rfc1327) but MS uses 'S' */
150#define SN_stateOrProvinceName "ST"
151#define LN_stateOrProvinceName "stateOrProvinceName"
152#define NID_stateOrProvinceName 16
153#define OBJ_stateOrProvinceName OBJ_X509,8L
154
155#define SN_organizationName "O"
156#define LN_organizationName "organizationName"
157#define NID_organizationName 17
158#define OBJ_organizationName OBJ_X509,10L
159
160#define SN_organizationalUnitName "OU"
161#define LN_organizationalUnitName "organizationalUnitName"
162#define NID_organizationalUnitName 18
163#define OBJ_organizationalUnitName OBJ_X509,11L
164
165#define SN_rsa "RSA"
166#define LN_rsa "rsa"
167#define NID_rsa 19
168#define OBJ_rsa OBJ_X500,8L,1L,1L
169
170#define LN_pkcs7 "pkcs7"
171#define NID_pkcs7 20
172#define OBJ_pkcs7 OBJ_pkcs,7L
173
174#define LN_pkcs7_data "pkcs7-data"
175#define NID_pkcs7_data 21
176#define OBJ_pkcs7_data OBJ_pkcs7,1L
177
178#define LN_pkcs7_signed "pkcs7-signedData"
179#define NID_pkcs7_signed 22
180#define OBJ_pkcs7_signed OBJ_pkcs7,2L
181
182#define LN_pkcs7_enveloped "pkcs7-envelopedData"
183#define NID_pkcs7_enveloped 23
184#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
185
186#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
187#define NID_pkcs7_signedAndEnveloped 24
188#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
189
190#define LN_pkcs7_digest "pkcs7-digestData"
191#define NID_pkcs7_digest 25
192#define OBJ_pkcs7_digest OBJ_pkcs7,5L
193
194#define LN_pkcs7_encrypted "pkcs7-encryptedData"
195#define NID_pkcs7_encrypted 26
196#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
197
198#define LN_pkcs3 "pkcs3"
199#define NID_pkcs3 27
200#define OBJ_pkcs3 OBJ_pkcs,3L
201
202#define LN_dhKeyAgreement "dhKeyAgreement"
203#define NID_dhKeyAgreement 28
204#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
205
206#define SN_des_ecb "DES-ECB"
207#define LN_des_ecb "des-ecb"
208#define NID_des_ecb 29
209#define OBJ_des_ecb OBJ_algorithm,6L
210
211#define SN_des_cfb64 "DES-CFB"
212#define LN_des_cfb64 "des-cfb"
213#define NID_des_cfb64 30
214/* IV + num */
215#define OBJ_des_cfb64 OBJ_algorithm,9L
216
217#define SN_des_cbc "DES-CBC"
218#define LN_des_cbc "des-cbc"
219#define NID_des_cbc 31
220/* IV */
221#define OBJ_des_cbc OBJ_algorithm,7L
222
223#define SN_des_ede "DES-EDE"
224#define LN_des_ede "des-ede"
225#define NID_des_ede 32
226/* ?? */
227#define OBJ_des_ede OBJ_algorithm,17L
228
229#define SN_des_ede3 "DES-EDE3"
230#define LN_des_ede3 "des-ede3"
231#define NID_des_ede3 33
232
233#define SN_idea_cbc "IDEA-CBC"
234#define LN_idea_cbc "idea-cbc"
235#define NID_idea_cbc 34
236#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
237
238#define SN_idea_cfb64 "IDEA-CFB"
239#define LN_idea_cfb64 "idea-cfb"
240#define NID_idea_cfb64 35
241
242#define SN_idea_ecb "IDEA-ECB"
243#define LN_idea_ecb "idea-ecb"
244#define NID_idea_ecb 36
245
246#define SN_rc2_cbc "RC2-CBC"
247#define LN_rc2_cbc "rc2-cbc"
248#define NID_rc2_cbc 37
249#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
250
251#define SN_rc2_ecb "RC2-ECB"
252#define LN_rc2_ecb "rc2-ecb"
253#define NID_rc2_ecb 38
254
255#define SN_rc2_cfb64 "RC2-CFB"
256#define LN_rc2_cfb64 "rc2-cfb"
257#define NID_rc2_cfb64 39
258
259#define SN_rc2_ofb64 "RC2-OFB"
260#define LN_rc2_ofb64 "rc2-ofb"
261#define NID_rc2_ofb64 40
262
263#define SN_sha "SHA"
264#define LN_sha "sha"
265#define NID_sha 41
266#define OBJ_sha OBJ_algorithm,18L
267
268#define SN_shaWithRSAEncryption "RSA-SHA"
269#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
270#define NID_shaWithRSAEncryption 42
271#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
272
273#define SN_des_ede_cbc "DES-EDE-CBC"
274#define LN_des_ede_cbc "des-ede-cbc"
275#define NID_des_ede_cbc 43
276
277#define SN_des_ede3_cbc "DES-EDE3-CBC"
278#define LN_des_ede3_cbc "des-ede3-cbc"
279#define NID_des_ede3_cbc 44
280#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
281
282#define SN_des_ofb64 "DES-OFB"
283#define LN_des_ofb64 "des-ofb"
284#define NID_des_ofb64 45
285#define OBJ_des_ofb64 OBJ_algorithm,8L
286
287#define SN_idea_ofb64 "IDEA-OFB"
288#define LN_idea_ofb64 "idea-ofb"
289#define NID_idea_ofb64 46
290
291#define LN_pkcs9 "pkcs9"
292#define NID_pkcs9 47
293#define OBJ_pkcs9 OBJ_pkcs,9L
294
295#define SN_pkcs9_emailAddress "Email"
296#define LN_pkcs9_emailAddress "emailAddress"
297#define NID_pkcs9_emailAddress 48
298#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
299
300#define LN_pkcs9_unstructuredName "unstructuredName"
301#define NID_pkcs9_unstructuredName 49
302#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
303
304#define LN_pkcs9_contentType "contentType"
305#define NID_pkcs9_contentType 50
306#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
307
308#define LN_pkcs9_messageDigest "messageDigest"
309#define NID_pkcs9_messageDigest 51
310#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
311
312#define LN_pkcs9_signingTime "signingTime"
313#define NID_pkcs9_signingTime 52
314#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
315
316#define LN_pkcs9_countersignature "countersignature"
317#define NID_pkcs9_countersignature 53
318#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
319
320#define LN_pkcs9_challengePassword "challengePassword"
321#define NID_pkcs9_challengePassword 54
322#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
323
324#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
325#define NID_pkcs9_unstructuredAddress 55
326#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
327
328#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
329#define NID_pkcs9_extCertAttributes 56
330#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
331
332#define SN_netscape "Netscape"
333#define LN_netscape "Netscape Communications Corp."
334#define NID_netscape 57
335#define OBJ_netscape 2L,16L,840L,1L,113730L
336
337#define SN_netscape_cert_extension "nsCertExt"
338#define LN_netscape_cert_extension "Netscape Certificate Extension"
339#define NID_netscape_cert_extension 58
340#define OBJ_netscape_cert_extension OBJ_netscape,1L
341
342#define SN_netscape_data_type "nsDataType"
343#define LN_netscape_data_type "Netscape Data Type"
344#define NID_netscape_data_type 59
345#define OBJ_netscape_data_type OBJ_netscape,2L
346
347#define SN_des_ede_cfb64 "DES-EDE-CFB"
348#define LN_des_ede_cfb64 "des-ede-cfb"
349#define NID_des_ede_cfb64 60
350
351#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
352#define LN_des_ede3_cfb64 "des-ede3-cfb"
353#define NID_des_ede3_cfb64 61
354
355#define SN_des_ede_ofb64 "DES-EDE-OFB"
356#define LN_des_ede_ofb64 "des-ede-ofb"
357#define NID_des_ede_ofb64 62
358
359#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
360#define LN_des_ede3_ofb64 "des-ede3-ofb"
361#define NID_des_ede3_ofb64 63
362
363/* I'm not sure about the object ID */
364#define SN_sha1 "SHA1"
365#define LN_sha1 "sha1"
366#define NID_sha1 64
367#define OBJ_sha1 OBJ_algorithm,26L
368/* 28 Jun 1996 - eay */
369/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */
370
371#define SN_sha1WithRSAEncryption "RSA-SHA1"
372#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
373#define NID_sha1WithRSAEncryption 65
374#define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L
375
376#define SN_dsaWithSHA "DSA-SHA"
377#define LN_dsaWithSHA "dsaWithSHA"
378#define NID_dsaWithSHA 66
379#define OBJ_dsaWithSHA OBJ_algorithm,13L
380
381#define SN_dsa_2 "DSA-old"
382#define LN_dsa_2 "dsaEncryption-old"
383#define NID_dsa_2 67
384#define OBJ_dsa_2 OBJ_algorithm,12L
385
386/* proposed by microsoft to RSA */
387#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
388#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
389#define NID_pbeWithSHA1AndRC2_CBC 68
390#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
391
392/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
393 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
394 * completely different.
395 */
396#define LN_id_pbkdf2 "PBKDF2"
397#define NID_id_pbkdf2 69
398#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
399
400#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
401#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
402#define NID_dsaWithSHA1_2 70
403/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */
404#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
405
406#define SN_netscape_cert_type "nsCertType"
407#define LN_netscape_cert_type "Netscape Cert Type"
408#define NID_netscape_cert_type 71
409#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
410
411#define SN_netscape_base_url "nsBaseUrl"
412#define LN_netscape_base_url "Netscape Base Url"
413#define NID_netscape_base_url 72
414#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
415
416#define SN_netscape_revocation_url "nsRevocationUrl"
417#define LN_netscape_revocation_url "Netscape Revocation Url"
418#define NID_netscape_revocation_url 73
419#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
420
421#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
422#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
423#define NID_netscape_ca_revocation_url 74
424#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
425
426#define SN_netscape_renewal_url "nsRenewalUrl"
427#define LN_netscape_renewal_url "Netscape Renewal Url"
428#define NID_netscape_renewal_url 75
429#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
430
431#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
432#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
433#define NID_netscape_ca_policy_url 76
434#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
435
436#define SN_netscape_ssl_server_name "nsSslServerName"
437#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
438#define NID_netscape_ssl_server_name 77
439#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
440
441#define SN_netscape_comment "nsComment"
442#define LN_netscape_comment "Netscape Comment"
443#define NID_netscape_comment 78
444#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
445
446#define SN_netscape_cert_sequence "nsCertSequence"
447#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
448#define NID_netscape_cert_sequence 79
449#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
450
451#define SN_desx_cbc "DESX-CBC"
452#define LN_desx_cbc "desx-cbc"
453#define NID_desx_cbc 80
454
455#define SN_id_ce "id-ce"
456#define NID_id_ce 81
457#define OBJ_id_ce 2L,5L,29L
458
459#define SN_subject_key_identifier "subjectKeyIdentifier"
460#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
461#define NID_subject_key_identifier 82
462#define OBJ_subject_key_identifier OBJ_id_ce,14L
463
464#define SN_key_usage "keyUsage"
465#define LN_key_usage "X509v3 Key Usage"
466#define NID_key_usage 83
467#define OBJ_key_usage OBJ_id_ce,15L
468
469#define SN_private_key_usage_period "privateKeyUsagePeriod"
470#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
471#define NID_private_key_usage_period 84
472#define OBJ_private_key_usage_period OBJ_id_ce,16L
473
474#define SN_subject_alt_name "subjectAltName"
475#define LN_subject_alt_name "X509v3 Subject Alternative Name"
476#define NID_subject_alt_name 85
477#define OBJ_subject_alt_name OBJ_id_ce,17L
478
479#define SN_issuer_alt_name "issuerAltName"
480#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
481#define NID_issuer_alt_name 86
482#define OBJ_issuer_alt_name OBJ_id_ce,18L
483
484#define SN_basic_constraints "basicConstraints"
485#define LN_basic_constraints "X509v3 Basic Constraints"
486#define NID_basic_constraints 87
487#define OBJ_basic_constraints OBJ_id_ce,19L
488
489#define SN_crl_number "crlNumber"
490#define LN_crl_number "X509v3 CRL Number"
491#define NID_crl_number 88
492#define OBJ_crl_number OBJ_id_ce,20L
493
494#define SN_certificate_policies "certificatePolicies"
495#define LN_certificate_policies "X509v3 Certificate Policies"
496#define NID_certificate_policies 89
497#define OBJ_certificate_policies OBJ_id_ce,32L
498
499#define SN_authority_key_identifier "authorityKeyIdentifier"
500#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
501#define NID_authority_key_identifier 90
502#define OBJ_authority_key_identifier OBJ_id_ce,35L
503
504#define SN_bf_cbc "BF-CBC"
505#define LN_bf_cbc "bf-cbc"
506#define NID_bf_cbc 91
507#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
508
509#define SN_bf_ecb "BF-ECB"
510#define LN_bf_ecb "bf-ecb"
511#define NID_bf_ecb 92
512
513#define SN_bf_cfb64 "BF-CFB"
514#define LN_bf_cfb64 "bf-cfb"
515#define NID_bf_cfb64 93
516
517#define SN_bf_ofb64 "BF-OFB"
518#define LN_bf_ofb64 "bf-ofb"
519#define NID_bf_ofb64 94
520
521#define SN_mdc2 "MDC2"
522#define LN_mdc2 "mdc2"
523#define NID_mdc2 95
524#define OBJ_mdc2 2L,5L,8L,3L,101L
525/* An alternative? 1L,3L,14L,3L,2L,19L */
526
527#define SN_mdc2WithRSA "RSA-MDC2"
528#define LN_mdc2WithRSA "mdc2withRSA"
529#define NID_mdc2WithRSA 96
530#define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L
531
532#define SN_rc4_40 "RC4-40"
533#define LN_rc4_40 "rc4-40"
534#define NID_rc4_40 97
535
536#define SN_rc2_40_cbc "RC2-40-CBC"
537#define LN_rc2_40_cbc "rc2-40-cbc"
538#define NID_rc2_40_cbc 98
539
540#define SN_givenName "G"
541#define LN_givenName "givenName"
542#define NID_givenName 99
543#define OBJ_givenName OBJ_X509,42L
544
545#define SN_surname "S"
546#define LN_surname "surname"
547#define NID_surname 100
548#define OBJ_surname OBJ_X509,4L
549
550#define SN_initials "I"
551#define LN_initials "initials"
552#define NID_initials 101
553#define OBJ_initials OBJ_X509,43L
554
555#define SN_uniqueIdentifier "UID"
556#define LN_uniqueIdentifier "uniqueIdentifier"
557#define NID_uniqueIdentifier 102
558#define OBJ_uniqueIdentifier OBJ_X509,45L
559
560#define SN_crl_distribution_points "crlDistributionPoints"
561#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
562#define NID_crl_distribution_points 103
563#define OBJ_crl_distribution_points OBJ_id_ce,31L
564
565#define SN_md5WithRSA "RSA-NP-MD5"
566#define LN_md5WithRSA "md5WithRSA"
567#define NID_md5WithRSA 104
568#define OBJ_md5WithRSA OBJ_algorithm,3L
569
570#define SN_serialNumber "SN"
571#define LN_serialNumber "serialNumber"
572#define NID_serialNumber 105
573#define OBJ_serialNumber OBJ_X509,5L
574
575#define SN_title "T"
576#define LN_title "title"
577#define NID_title 106
578#define OBJ_title OBJ_X509,12L
579
580#define SN_description "D"
581#define LN_description "description"
582#define NID_description 107
583#define OBJ_description OBJ_X509,13L
584
585/* CAST5 is CAST-128, I'm just sticking with the documentation */
586#define SN_cast5_cbc "CAST5-CBC"
587#define LN_cast5_cbc "cast5-cbc"
588#define NID_cast5_cbc 108
589#define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L
590
591#define SN_cast5_ecb "CAST5-ECB"
592#define LN_cast5_ecb "cast5-ecb"
593#define NID_cast5_ecb 109
594
595#define SN_cast5_cfb64 "CAST5-CFB"
596#define LN_cast5_cfb64 "cast5-cfb"
597#define NID_cast5_cfb64 110
598
599#define SN_cast5_ofb64 "CAST5-OFB"
600#define LN_cast5_ofb64 "cast5-ofb"
601#define NID_cast5_ofb64 111
602
603#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
604#define NID_pbeWithMD5AndCast5_CBC 112
605#define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L
606
607/* This is one sun will soon be using :-(
608 * id-dsa-with-sha1 ID ::= {
609 * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 }
610 */
611#define SN_dsaWithSHA1 "DSA-SHA1"
612#define LN_dsaWithSHA1 "dsaWithSHA1"
613#define NID_dsaWithSHA1 113
614#define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L
615
616#define NID_md5_sha1 114
617#define SN_md5_sha1 "MD5-SHA1"
618#define LN_md5_sha1 "md5-sha1"
619
620#define SN_sha1WithRSA "RSA-SHA1-2"
621#define LN_sha1WithRSA "sha1WithRSA"
622#define NID_sha1WithRSA 115
623#define OBJ_sha1WithRSA OBJ_algorithm,29L
624
625#define SN_dsa "DSA"
626#define LN_dsa "dsaEncryption"
627#define NID_dsa 116
628#define OBJ_dsa 1L,2L,840L,10040L,4L,1L
629
630#define SN_ripemd160 "RIPEMD160"
631#define LN_ripemd160 "ripemd160"
632#define NID_ripemd160 117
633#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
634
635/* The name should actually be rsaSignatureWithripemd160, but I'm going
636 * to continue using the convention I'm using with the other ciphers */
637#define SN_ripemd160WithRSA "RSA-RIPEMD160"
638#define LN_ripemd160WithRSA "ripemd160WithRSA"
639#define NID_ripemd160WithRSA 119
640#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
641
642/* Taken from rfc2040
643 * RC5_CBC_Parameters ::= SEQUENCE {
644 * version INTEGER (v1_0(16)),
645 * rounds INTEGER (8..127),
646 * blockSizeInBits INTEGER (64, 128),
647 * iv OCTET STRING OPTIONAL
648 * }
649 */
650#define SN_rc5_cbc "RC5-CBC"
651#define LN_rc5_cbc "rc5-cbc"
652#define NID_rc5_cbc 120
653#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
654
655#define SN_rc5_ecb "RC5-ECB"
656#define LN_rc5_ecb "rc5-ecb"
657#define NID_rc5_ecb 121
658
659#define SN_rc5_cfb64 "RC5-CFB"
660#define LN_rc5_cfb64 "rc5-cfb"
661#define NID_rc5_cfb64 122
662
663#define SN_rc5_ofb64 "RC5-OFB"
664#define LN_rc5_ofb64 "rc5-ofb"
665#define NID_rc5_ofb64 123
666
667#define SN_rle_compression "RLE"
668#define LN_rle_compression "run length compression"
669#define NID_rle_compression 124
670#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
671
672#define SN_zlib_compression "ZLIB"
673#define LN_zlib_compression "zlib compression"
674#define NID_zlib_compression 125
675#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
676
677#define SN_ext_key_usage "extendedKeyUsage"
678#define LN_ext_key_usage "X509v3 Extended Key Usage"
679#define NID_ext_key_usage 126
680#define OBJ_ext_key_usage OBJ_id_ce,37
681
682#define SN_id_pkix "PKIX"
683#define NID_id_pkix 127
684#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
685
686#define SN_id_kp "id-kp"
687#define NID_id_kp 128
688#define OBJ_id_kp OBJ_id_pkix,3L
689
690/* PKIX extended key usage OIDs */
691
692#define SN_server_auth "serverAuth"
693#define LN_server_auth "TLS Web Server Authentication"
694#define NID_server_auth 129
695#define OBJ_server_auth OBJ_id_kp,1L
696
697#define SN_client_auth "clientAuth"
698#define LN_client_auth "TLS Web Client Authentication"
699#define NID_client_auth 130
700#define OBJ_client_auth OBJ_id_kp,2L
701
702#define SN_code_sign "codeSigning"
703#define LN_code_sign "Code Signing"
704#define NID_code_sign 131
705#define OBJ_code_sign OBJ_id_kp,3L
706
707#define SN_email_protect "emailProtection"
708#define LN_email_protect "E-mail Protection"
709#define NID_email_protect 132
710#define OBJ_email_protect OBJ_id_kp,4L
711
712#define SN_time_stamp "timeStamping"
713#define LN_time_stamp "Time Stamping"
714#define NID_time_stamp 133
715#define OBJ_time_stamp OBJ_id_kp,8L
716
717/* Additional extended key usage OIDs: Microsoft */
718
719#define SN_ms_code_ind "msCodeInd"
720#define LN_ms_code_ind "Microsoft Individual Code Signing"
721#define NID_ms_code_ind 134
722#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
723
724#define SN_ms_code_com "msCodeCom"
725#define LN_ms_code_com "Microsoft Commercial Code Signing"
726#define NID_ms_code_com 135
727#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
728
729#define SN_ms_ctl_sign "msCTLSign"
730#define LN_ms_ctl_sign "Microsoft Trust List Signing"
731#define NID_ms_ctl_sign 136
732#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
733
734#define SN_ms_sgc "msSGC"
735#define LN_ms_sgc "Microsoft Server Gated Crypto"
736#define NID_ms_sgc 137
737#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
738
739#define SN_ms_efs "msEFS"
740#define LN_ms_efs "Microsoft Encrypted File System"
741#define NID_ms_efs 138
742#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
743
744/* Additional usage: Netscape */
745
746#define SN_ns_sgc "nsSGC"
747#define LN_ns_sgc "Netscape Server Gated Crypto"
748#define NID_ns_sgc 139
749#define OBJ_ns_sgc OBJ_netscape,4L,1L
750
751#define SN_delta_crl "deltaCRL"
752#define LN_delta_crl "X509v3 Delta CRL Indicator"
753#define NID_delta_crl 140
754#define OBJ_delta_crl OBJ_id_ce,27L
755
756#define SN_crl_reason "CRLReason"
757#define LN_crl_reason "CRL Reason Code"
758#define NID_crl_reason 141
759#define OBJ_crl_reason OBJ_id_ce,21L
760
761#define SN_invalidity_date "invalidityDate"
762#define LN_invalidity_date "Invalidity Date"
763#define NID_invalidity_date 142
764#define OBJ_invalidity_date OBJ_id_ce,24L
765
766#define SN_sxnet "SXNetID"
767#define LN_sxnet "Strong Extranet ID"
768#define NID_sxnet 143
769#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
770
771/* PKCS12 and related OBJECT IDENTIFIERS */
772
773#define OBJ_pkcs12 OBJ_pkcs,12L
774#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1
775
776#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
777#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
778#define NID_pbe_WithSHA1And128BitRC4 144
779#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L
780
781#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
782#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
783#define NID_pbe_WithSHA1And40BitRC4 145
784#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L
785
786#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
787#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
788#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
789#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L
790
791#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
792#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
793#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
794#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L
795
796#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
797#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
798#define NID_pbe_WithSHA1And128BitRC2_CBC 148
799#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L
800
801#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
802#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
803#define NID_pbe_WithSHA1And40BitRC2_CBC 149
804#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L
805
806#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L
807
808#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L
809
810#define LN_keyBag "keyBag"
811#define NID_keyBag 150
812#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L
813
814#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
815#define NID_pkcs8ShroudedKeyBag 151
816#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L
817
818#define LN_certBag "certBag"
819#define NID_certBag 152
820#define OBJ_certBag OBJ_pkcs12_BagIds, 3L
821
822#define LN_crlBag "crlBag"
823#define NID_crlBag 153
824#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L
825
826#define LN_secretBag "secretBag"
827#define NID_secretBag 154
828#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L
829
830#define LN_safeContentsBag "safeContentsBag"
831#define NID_safeContentsBag 155
832#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L
833
834#define LN_friendlyName "friendlyName"
835#define NID_friendlyName 156
836#define OBJ_friendlyName OBJ_pkcs9, 20L
837
838#define LN_localKeyID "localKeyID"
839#define NID_localKeyID 157
840#define OBJ_localKeyID OBJ_pkcs9, 21L
841
842#define OBJ_certTypes OBJ_pkcs9, 22L
843
844#define LN_x509Certificate "x509Certificate"
845#define NID_x509Certificate 158
846#define OBJ_x509Certificate OBJ_certTypes, 1L
847
848#define LN_sdsiCertificate "sdsiCertificate"
849#define NID_sdsiCertificate 159
850#define OBJ_sdsiCertificate OBJ_certTypes, 2L
851
852#define OBJ_crlTypes OBJ_pkcs9, 23L
853
854#define LN_x509Crl "x509Crl"
855#define NID_x509Crl 160
856#define OBJ_x509Crl OBJ_crlTypes, 1L
857
858/* PKCS#5 v2 OIDs */
859
860#define LN_pbes2 "PBES2"
861#define NID_pbes2 161
862#define OBJ_pbes2 OBJ_pkcs,5L,13L
863
864#define LN_pbmac1 "PBMAC1"
865#define NID_pbmac1 162
866#define OBJ_pbmac1 OBJ_pkcs,5L,14L
867
868#define LN_hmacWithSHA1 "hmacWithSHA1"
869#define NID_hmacWithSHA1 163
870#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
871
872/* Policy Qualifier Ids */
873
874#define LN_id_qt_cps "Policy Qualifier CPS"
875#define SN_id_qt_cps "id-qt-cps"
876#define NID_id_qt_cps 164
877#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L
878
879#define LN_id_qt_unotice "Policy Qualifier User Notice"
880#define SN_id_qt_unotice "id-qt-unotice"
881#define NID_id_qt_unotice 165
882#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L
883
884#define SN_rc2_64_cbc "RC2-64-CBC"
885#define LN_rc2_64_cbc "rc2-64-cbc"
886#define NID_rc2_64_cbc 166
887
888#define SN_SMIMECapabilities "SMIME-CAPS"
889#define LN_SMIMECapabilities "S/MIME Capabilities"
890#define NID_SMIMECapabilities 167
891#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
892
893#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
894#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
895#define NID_pbeWithMD2AndRC2_CBC 168
896#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L
897
898#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
899#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
900#define NID_pbeWithMD5AndRC2_CBC 169
901#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L
902
903#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
904#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
905#define NID_pbeWithSHA1AndDES_CBC 170
906#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L
907
908/* Extension request OIDs */
909
910#define LN_ms_ext_req "Microsoft Extension Request"
911#define SN_ms_ext_req "msExtReq"
912#define NID_ms_ext_req 171
913#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
914
915#define LN_ext_req "Extension Request"
916#define SN_ext_req "extReq"
917#define NID_ext_req 172
918#define OBJ_ext_req OBJ_pkcs9,14L
919
920#define SN_name "name"
921#define LN_name "name"
922#define NID_name 173
923#define OBJ_name OBJ_X509,41L
924
925#define SN_dnQualifier "dnQualifier"
926#define LN_dnQualifier "dnQualifier"
927#define NID_dnQualifier 174
928#define OBJ_dnQualifier OBJ_X509,46L
929
930#define SN_id_pe "id-pe"
931#define NID_id_pe 175
932#define OBJ_id_pe OBJ_id_pkix,1L
933
934#define SN_id_ad "id-ad"
935#define NID_id_ad 176
936#define OBJ_id_ad OBJ_id_pkix,48L
937
938#define SN_info_access "authorityInfoAccess"
939#define LN_info_access "Authority Information Access"
940#define NID_info_access 177
941#define OBJ_info_access OBJ_id_pe,1L
942
943#define SN_ad_OCSP "OCSP"
944#define LN_ad_OCSP "OCSP"
945#define NID_ad_OCSP 178
946#define OBJ_ad_OCSP OBJ_id_ad,1L
947
948#define SN_ad_ca_issuers "caIssuers"
949#define LN_ad_ca_issuers "CA Issuers"
950#define NID_ad_ca_issuers 179
951#define OBJ_ad_ca_issuers OBJ_id_ad,2L
952
953#define SN_OCSP_sign "OCSPSigning"
954#define LN_OCSP_sign "OCSP Signing"
955#define NID_OCSP_sign 180
956#define OBJ_OCSP_sign OBJ_id_kp,9L
957#endif /* USE_OBJ_MAC */
958
959#include <openssl/bio.h>
960#include <openssl/asn1.h>
961
962#define OBJ_NAME_TYPE_UNDEF 0x00
963#define OBJ_NAME_TYPE_MD_METH 0x01
964#define OBJ_NAME_TYPE_CIPHER_METH 0x02
965#define OBJ_NAME_TYPE_PKEY_METH 0x03
966#define OBJ_NAME_TYPE_COMP_METH 0x04
967#define OBJ_NAME_TYPE_NUM 0x05
968
969#define OBJ_NAME_ALIAS 0x8000
970
971
972#ifdef __cplusplus
973extern "C" {
974#endif
975
976typedef struct obj_name_st
977 {
978 int type;
979 int alias;
980 const char *name;
981 const char *data;
982 } OBJ_NAME;
983
984#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
985
986
987int OBJ_NAME_init(void);
988int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
989 int (*cmp_func)(const char *, const char *),
990 void (*free_func)(const char *, int, const char *));
991const char *OBJ_NAME_get(const char *name,int type);
992int OBJ_NAME_add(const char *name,int type,const char *data);
993int OBJ_NAME_remove(const char *name,int type);
994void OBJ_NAME_cleanup(int type); /* -1 for everything */
995void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),
996 void *arg);
997void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
998 void *arg);
999
1000ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
1001ASN1_OBJECT * OBJ_nid2obj(int n);
1002const char * OBJ_nid2ln(int n);
1003const char * OBJ_nid2sn(int n);
1004int OBJ_obj2nid(const ASN1_OBJECT *o);
1005ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
1006int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
1007int OBJ_txt2nid(const char *s);
1008int OBJ_ln2nid(const char *s);
1009int OBJ_sn2nid(const char *s);
1010int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
1011const char * OBJ_bsearch(const char *key,const char *base,int num,int size,
1012 int (*cmp)(const void *, const void *));
1013
1014int OBJ_new_nid(int num);
1015int OBJ_add_object(const ASN1_OBJECT *obj);
1016int OBJ_create(const char *oid,const char *sn,const char *ln);
1017void OBJ_cleanup(void );
1018int OBJ_create_objects(BIO *in);
1019
1020/* BEGIN ERROR CODES */
1021/* The following lines are auto generated by the script mkerr.pl. Any changes
1022 * made after this point may be overwritten when the script is next run.
1023 */
1024void ERR_load_OBJ_strings(void);
1025
1026/* Error codes for the OBJ functions. */
1027
1028/* Function codes. */
1029#define OBJ_F_OBJ_ADD_OBJECT 105
1030#define OBJ_F_OBJ_CREATE 100
1031#define OBJ_F_OBJ_DUP 101
1032#define OBJ_F_OBJ_NAME_NEW_INDEX 106
1033#define OBJ_F_OBJ_NID2LN 102
1034#define OBJ_F_OBJ_NID2OBJ 103
1035#define OBJ_F_OBJ_NID2SN 104
1036
1037/* Reason codes. */
1038#define OBJ_R_MALLOC_FAILURE 100
1039#define OBJ_R_UNKNOWN_NID 101
1040
1041#ifdef __cplusplus
1042}
1043#endif
1044#endif
diff --git a/src/lib/libcrypto/objects/objects.pl b/src/lib/libcrypto/objects/objects.pl
new file mode 100644
index 0000000000..76bb8da677
--- /dev/null
+++ b/src/lib/libcrypto/objects/objects.pl
@@ -0,0 +1,230 @@
1#!/usr/local/bin/perl
2
3open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
4$max_nid=0;
5$o=0;
6while(<NUMIN>)
7 {
8 chop;
9 $o++;
10 s/#.*$//;
11 next if /^\s*$/;
12 $_ = 'X'.$_;
13 ($Cname,$mynum) = split;
14 $Cname =~ s/^X//;
15 if (defined($nidn{$mynum}))
16 { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
17 $nid{$Cname} = $mynum;
18 $nidn{$mynum} = $Cname;
19 $order{$mynum} = $o;
20 $max_nid = $mynum if $mynum > $max_nid;
21 }
22close NUMIN;
23
24open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
25$Cname="";
26$o=0;
27while (<IN>)
28 {
29 chop;
30 $o++;
31 if (/^!module\s+(.*)$/)
32 {
33 $module = $1."-";
34 $module =~ s/\./_/g;
35 $module =~ s/-/_/g;
36 }
37 if (/^!global$/)
38 { $module = ""; }
39 if (/^!Cname\s+(.*)$/)
40 { $Cname = $1; }
41 if (/^!Alias\s+(.+?)\s+(.*)$/)
42 {
43 $Cname = $module.$1;
44 $myoid = $2;
45 $myoid = &process_oid($myoid);
46 $Cname =~ s/-/_/g;
47 $ordern{$o} = $Cname;
48 $order{$Cname} = $o;
49 $obj{$Cname} = $myoid;
50 $_ = "";
51 $Cname = "";
52 }
53 s/!.*$//;
54 s/#.*$//;
55 next if /^\s*$/;
56 ($myoid,$mysn,$myln) = split ':';
57 $mysn =~ s/^\s*//;
58 $mysn =~ s/\s*$//;
59 $myln =~ s/^\s*//;
60 $myln =~ s/\s*$//;
61 $myoid =~ s/^\s*//;
62 $myoid =~ s/\s*$//;
63 if ($myoid ne "")
64 {
65 $myoid = &process_oid($myoid);
66 }
67
68 if ($Cname eq "" && !($myln =~ / /))
69 {
70 $Cname = $myln;
71 $Cname =~ s/\./_/g;
72 $Cname =~ s/-/_/g;
73 if ($Cname ne "" && defined($ln{$module.$Cname}))
74 { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
75 }
76 if ($Cname eq "")
77 {
78 $Cname = $mysn;
79 $Cname =~ s/-/_/g;
80 if ($Cname ne "" && defined($sn{$module.$Cname}))
81 { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
82 }
83 if ($Cname eq "")
84 {
85 $Cname = $myln;
86 $Cname =~ s/-/_/g;
87 $Cname =~ s/\./_/g;
88 $Cname =~ s/ /_/g;
89 if ($Cname ne "" && defined($ln{$module.$Cname}))
90 { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
91 }
92 $Cname =~ s/\./_/g;
93 $Cname =~ s/-/_/g;
94 $Cname = $module.$Cname;
95 $ordern{$o} = $Cname;
96 $order{$Cname} = $o;
97 $sn{$Cname} = $mysn;
98 $ln{$Cname} = $myln;
99 $obj{$Cname} = $myoid;
100 if (!defined($nid{$Cname}))
101 {
102 $max_nid++;
103 $nid{$Cname} = $max_nid;
104 $nidn{$max_nid} = $Cname;
105 }
106 $Cname="";
107 }
108close IN;
109
110#XXX don't modify input files
111#open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
112#foreach (sort { $a <=> $b } keys %nidn)
113# {
114# print NUMOUT $nidn{$_},"\t\t",$_,"\n";
115# }
116#close NUMOUT;
117
118open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
119print OUT <<'EOF';
120/* crypto/objects/obj_mac.h */
121
122/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
123 * following command:
124 * perl objects.pl objects.txt obj_mac.num obj_mac.h
125 */
126
127/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
128 * All rights reserved.
129 *
130 * This package is an SSL implementation written
131 * by Eric Young (eay@cryptsoft.com).
132 * The implementation was written so as to conform with Netscapes SSL.
133 *
134 * This library is free for commercial and non-commercial use as long as
135 * the following conditions are aheared to. The following conditions
136 * apply to all code found in this distribution, be it the RC4, RSA,
137 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
138 * included with this distribution is covered by the same copyright terms
139 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
140 *
141 * Copyright remains Eric Young's, and as such any Copyright notices in
142 * the code are not to be removed.
143 * If this package is used in a product, Eric Young should be given attribution
144 * as the author of the parts of the library used.
145 * This can be in the form of a textual message at program startup or
146 * in documentation (online or textual) provided with the package.
147 *
148 * Redistribution and use in source and binary forms, with or without
149 * modification, are permitted provided that the following conditions
150 * are met:
151 * 1. Redistributions of source code must retain the copyright
152 * notice, this list of conditions and the following disclaimer.
153 * 2. Redistributions in binary form must reproduce the above copyright
154 * notice, this list of conditions and the following disclaimer in the
155 * documentation and/or other materials provided with the distribution.
156 * 3. All advertising materials mentioning features or use of this software
157 * must display the following acknowledgement:
158 * "This product includes cryptographic software written by
159 * Eric Young (eay@cryptsoft.com)"
160 * The word 'cryptographic' can be left out if the rouines from the library
161 * being used are not cryptographic related :-).
162 * 4. If you include any Windows specific code (or a derivative thereof) from
163 * the apps directory (application code) you must include an acknowledgement:
164 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
165 *
166 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
167 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
168 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
169 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
170 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
171 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
172 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
173 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
174 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
175 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
176 * SUCH DAMAGE.
177 *
178 * The licence and distribution terms for any publically available version or
179 * derivative of this code cannot be changed. i.e. this code cannot simply be
180 * copied and put under another distribution licence
181 * [including the GNU Public Licence.]
182 */
183
184#define SN_undef "UNDEF"
185#define LN_undef "undefined"
186#define NID_undef 0
187#define OBJ_undef 0L
188
189EOF
190
191foreach (sort { $a <=> $b } keys %ordern)
192 {
193 $Cname=$ordern{$_};
194 print OUT "#define SN_",$Cname,"\t\t\"",$sn{$Cname},"\"\n" if $sn{$Cname} ne "";
195 print OUT "#define LN_",$Cname,"\t\t\"",$ln{$Cname},"\"\n" if $ln{$Cname} ne "";
196 print OUT "#define NID_",$Cname,"\t\t",$nid{$Cname},"\n" if $nid{$Cname} ne "";
197 print OUT "#define OBJ_",$Cname,"\t\t",$obj{$Cname},"\n" if $obj{$Cname} ne "";
198 print OUT "\n";
199 }
200
201close OUT;
202
203sub process_oid
204 {
205 local($oid)=@_;
206 local(@a,$oid_pref);
207
208 @a = split(/\s+/,$myoid);
209 $pref_oid = "";
210 $pref_sep = "";
211 if (!($a[0] =~ /^[0-9]+$/))
212 {
213 $a[0] =~ s/-/_/g;
214 if (!defined($obj{$a[0]}))
215 { die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; }
216 $pref_oid = "OBJ_" . $a[0];
217 $pref_sep = ",";
218 shift @a;
219 }
220 $oids = join('L,',@a) . "L";
221 if ($oids ne "L")
222 {
223 $oids = $pref_oid . $pref_sep . $oids;
224 }
225 else
226 {
227 $oids = $pref_oid;
228 }
229 return($oids);
230 }
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt
new file mode 100644
index 0000000000..50e9031e61
--- /dev/null
+++ b/src/lib/libcrypto/objects/objects.txt
@@ -0,0 +1,938 @@
10 : CCITT : ccitt
2
31 : ISO : iso
4
52 : JOINT-ISO-CCITT : joint-iso-ccitt
6
7iso 2 : member-body : ISO Member Body
8
9joint-iso-ccitt 5 1 5 : selected-attribute-types : Selected Attribute Types
10
11selected-attribute-types 55 : clearance
12
13member-body 840 : ISO-US : ISO US Member Body
14ISO-US 10040 : X9-57 : X9.57
15X9-57 4 : X9cm : X9.57 CM ?
16
17!Cname dsa
18X9cm 1 : DSA : dsaEncryption
19X9cm 3 : DSA-SHA1 : dsaWithSHA1
20
21
22ISO-US 10045 : ansi-X9-62 : ANSI X9.62
23!module X9-62
24!Alias id-fieldType ansi-X9-62 1
25X9-62_id-fieldType 1 : prime-field
26X9-62_id-fieldType 2 : characteristic-two-field
27# ... characteristic-two-field OID subtree
28!Alias id-publicKeyType ansi-X9-62 2
29X9-62_id-publicKeyType 1 : id-ecPublicKey
30!Alias ellipticCurve ansi-X9-62 3
31!Alias c-TwoCurve X9-62_ellipticCurve 0
32# ... characteristic 2 curve OIDs
33!Alias primeCurve X9-62_ellipticCurve 1
34X9-62_primeCurve 1 : prime192v1
35X9-62_primeCurve 2 : prime192v2
36X9-62_primeCurve 3 : prime192v3
37X9-62_primeCurve 4 : prime239v1
38X9-62_primeCurve 5 : prime239v2
39X9-62_primeCurve 6 : prime239v3
40X9-62_primeCurve 7 : prime256v1
41!Alias id-ecSigType ansi-X9-62 4
42!global
43X9-62_id-ecSigType 1 : ecdsa-with-SHA1
44
45
46
47ISO-US 113533 7 66 10 : CAST5-CBC : cast5-cbc
48 : CAST5-ECB : cast5-ecb
49!Cname cast5-cfb64
50 : CAST5-CFB : cast5-cfb
51!Cname cast5-ofb64
52 : CAST5-OFB : cast5-ofb
53!Cname pbeWithMD5AndCast5-CBC
54ISO-US 113533 7 66 12 : : pbeWithMD5AndCast5CBC
55
56ISO-US 113549 : rsadsi : RSA Data Security, Inc.
57
58rsadsi 1 : pkcs : RSA Data Security, Inc. PKCS
59
60pkcs 1 : pkcs1
61pkcs1 1 : : rsaEncryption
62pkcs1 2 : RSA-MD2 : md2WithRSAEncryption
63pkcs1 3 : RSA-MD4 : md4WithRSAEncryption
64pkcs1 4 : RSA-MD5 : md5WithRSAEncryption
65pkcs1 5 : RSA-SHA1 : sha1WithRSAEncryption
66
67pkcs 3 : pkcs3
68pkcs3 1 : : dhKeyAgreement
69
70pkcs 5 : pkcs5
71pkcs5 1 : PBE-MD2-DES : pbeWithMD2AndDES-CBC
72pkcs5 3 : PBE-MD5-DES : pbeWithMD5AndDES-CBC
73pkcs5 4 : PBE-MD2-RC2-64 : pbeWithMD2AndRC2-CBC
74pkcs5 6 : PBE-MD5-RC2-64 : pbeWithMD5AndRC2-CBC
75pkcs5 10 : PBE-SHA1-DES : pbeWithSHA1AndDES-CBC
76pkcs5 11 : PBE-SHA1-RC2-64 : pbeWithSHA1AndRC2-CBC
77!Cname id_pbkdf2
78pkcs5 12 : : PBKDF2
79!Cname pbes2
80pkcs5 13 : : PBES2
81!Cname pbmac1
82pkcs5 14 : : PBMAC1
83
84pkcs 7 : pkcs7
85pkcs7 1 : : pkcs7-data
86!Cname pkcs7-signed
87pkcs7 2 : : pkcs7-signedData
88!Cname pkcs7-enveloped
89pkcs7 3 : : pkcs7-envelopedData
90!Cname pkcs7-signedAndEnveloped
91pkcs7 4 : : pkcs7-signedAndEnvelopedData
92!Cname pkcs7-digest
93pkcs7 5 : : pkcs7-digestData
94!Cname pkcs7-encrypted
95pkcs7 6 : : pkcs7-encryptedData
96
97pkcs 9 : pkcs9
98!module pkcs9
99pkcs9 1 : : emailAddress
100pkcs9 2 : : unstructuredName
101pkcs9 3 : : contentType
102pkcs9 4 : : messageDigest
103pkcs9 5 : : signingTime
104pkcs9 6 : : countersignature
105pkcs9 7 : : challengePassword
106pkcs9 8 : : unstructuredAddress
107!Cname extCertAttributes
108pkcs9 9 : : extendedCertificateAttributes
109!global
110
111!Cname ext-req
112pkcs9 14 : extReq : Extension Request
113
114!Cname SMIMECapabilities
115pkcs9 15 : SMIME-CAPS : S/MIME Capabilities
116
117# S/MIME
118!Cname SMIME
119pkcs9 16 : SMIME : S/MIME
120SMIME 0 : id-smime-mod
121SMIME 1 : id-smime-ct
122SMIME 2 : id-smime-aa
123SMIME 3 : id-smime-alg
124SMIME 4 : id-smime-cd
125SMIME 5 : id-smime-spq
126SMIME 6 : id-smime-cti
127
128# S/MIME Modules
129id-smime-mod 1 : id-smime-mod-cms
130id-smime-mod 2 : id-smime-mod-ess
131id-smime-mod 3 : id-smime-mod-oid
132id-smime-mod 4 : id-smime-mod-msg-v3
133id-smime-mod 5 : id-smime-mod-ets-eSignature-88
134id-smime-mod 6 : id-smime-mod-ets-eSignature-97
135id-smime-mod 7 : id-smime-mod-ets-eSigPolicy-88
136id-smime-mod 8 : id-smime-mod-ets-eSigPolicy-97
137
138# S/MIME Content Types
139id-smime-ct 1 : id-smime-ct-receipt
140id-smime-ct 2 : id-smime-ct-authData
141id-smime-ct 3 : id-smime-ct-publishCert
142id-smime-ct 4 : id-smime-ct-TSTInfo
143id-smime-ct 5 : id-smime-ct-TDTInfo
144id-smime-ct 6 : id-smime-ct-contentInfo
145id-smime-ct 7 : id-smime-ct-DVCSRequestData
146id-smime-ct 8 : id-smime-ct-DVCSResponseData
147
148# S/MIME Attributes
149id-smime-aa 1 : id-smime-aa-receiptRequest
150id-smime-aa 2 : id-smime-aa-securityLabel
151id-smime-aa 3 : id-smime-aa-mlExpandHistory
152id-smime-aa 4 : id-smime-aa-contentHint
153id-smime-aa 5 : id-smime-aa-msgSigDigest
154# obsolete
155id-smime-aa 6 : id-smime-aa-encapContentType
156id-smime-aa 7 : id-smime-aa-contentIdentifier
157# obsolete
158id-smime-aa 8 : id-smime-aa-macValue
159id-smime-aa 9 : id-smime-aa-equivalentLabels
160id-smime-aa 10 : id-smime-aa-contentReference
161id-smime-aa 11 : id-smime-aa-encrypKeyPref
162id-smime-aa 12 : id-smime-aa-signingCertificate
163id-smime-aa 13 : id-smime-aa-smimeEncryptCerts
164id-smime-aa 14 : id-smime-aa-timeStampToken
165id-smime-aa 15 : id-smime-aa-ets-sigPolicyId
166id-smime-aa 16 : id-smime-aa-ets-commitmentType
167id-smime-aa 17 : id-smime-aa-ets-signerLocation
168id-smime-aa 18 : id-smime-aa-ets-signerAttr
169id-smime-aa 19 : id-smime-aa-ets-otherSigCert
170id-smime-aa 20 : id-smime-aa-ets-contentTimestamp
171id-smime-aa 21 : id-smime-aa-ets-CertificateRefs
172id-smime-aa 22 : id-smime-aa-ets-RevocationRefs
173id-smime-aa 23 : id-smime-aa-ets-certValues
174id-smime-aa 24 : id-smime-aa-ets-revocationValues
175id-smime-aa 25 : id-smime-aa-ets-escTimeStamp
176id-smime-aa 26 : id-smime-aa-ets-certCRLTimestamp
177id-smime-aa 27 : id-smime-aa-ets-archiveTimeStamp
178id-smime-aa 28 : id-smime-aa-signatureType
179id-smime-aa 29 : id-smime-aa-dvcs-dvc
180
181# S/MIME Algorithm Identifiers
182# obsolete
183id-smime-alg 1 : id-smime-alg-ESDHwith3DES
184# obsolete
185id-smime-alg 2 : id-smime-alg-ESDHwithRC2
186# obsolete
187id-smime-alg 3 : id-smime-alg-3DESwrap
188# obsolete
189id-smime-alg 4 : id-smime-alg-RC2wrap
190id-smime-alg 5 : id-smime-alg-ESDH
191id-smime-alg 6 : id-smime-alg-CMS3DESwrap
192id-smime-alg 7 : id-smime-alg-CMSRC2wrap
193
194# S/MIME Certificate Distribution
195id-smime-cd 1 : id-smime-cd-ldap
196
197# S/MIME Signature Policy Qualifier
198id-smime-spq 1 : id-smime-spq-ets-sqt-uri
199id-smime-spq 2 : id-smime-spq-ets-sqt-unotice
200
201# S/MIME Commitment Type Identifier
202id-smime-cti 1 : id-smime-cti-ets-proofOfOrigin
203id-smime-cti 2 : id-smime-cti-ets-proofOfReceipt
204id-smime-cti 3 : id-smime-cti-ets-proofOfDelivery
205id-smime-cti 4 : id-smime-cti-ets-proofOfSender
206id-smime-cti 5 : id-smime-cti-ets-proofOfApproval
207id-smime-cti 6 : id-smime-cti-ets-proofOfCreation
208
209pkcs9 20 : : friendlyName
210pkcs9 21 : : localKeyID
211!Cname ms-csp-name
2121 3 6 1 4 1 311 17 1 : CSPName : Microsoft CSP Name
213!Alias certTypes pkcs9 22
214certTypes 1 : : x509Certificate
215certTypes 2 : : sdsiCertificate
216!Alias crlTypes pkcs9 23
217crlTypes 1 : : x509Crl
218
219!Alias pkcs12 pkcs 12
220!Alias pkcs12-pbeids pkcs12 1
221
222!Cname pbe-WithSHA1And128BitRC4
223pkcs12-pbeids 1 : PBE-SHA1-RC4-128 : pbeWithSHA1And128BitRC4
224!Cname pbe-WithSHA1And40BitRC4
225pkcs12-pbeids 2 : PBE-SHA1-RC4-40 : pbeWithSHA1And40BitRC4
226!Cname pbe-WithSHA1And3_Key_TripleDES-CBC
227pkcs12-pbeids 3 : PBE-SHA1-3DES : pbeWithSHA1And3-KeyTripleDES-CBC
228!Cname pbe-WithSHA1And2_Key_TripleDES-CBC
229pkcs12-pbeids 4 : PBE-SHA1-2DES : pbeWithSHA1And2-KeyTripleDES-CBC
230!Cname pbe-WithSHA1And128BitRC2-CBC
231pkcs12-pbeids 5 : PBE-SHA1-RC2-128 : pbeWithSHA1And128BitRC2-CBC
232!Cname pbe-WithSHA1And40BitRC2-CBC
233pkcs12-pbeids 6 : PBE-SHA1-RC2-40 : pbeWithSHA1And40BitRC2-CBC
234
235!Alias pkcs12-Version1 pkcs12 10
236!Alias pkcs12-BagIds pkcs12-Version1 1
237pkcs12-BagIds 1 : : keyBag
238pkcs12-BagIds 2 : : pkcs8ShroudedKeyBag
239pkcs12-BagIds 3 : : certBag
240pkcs12-BagIds 4 : : crlBag
241pkcs12-BagIds 5 : : secretBag
242pkcs12-BagIds 6 : : safeContentsBag
243
244rsadsi 2 2 : MD2 : md2
245rsadsi 2 4 : MD4 : md4
246rsadsi 2 5 : MD5 : md5
247 : MD5-SHA1 : md5-sha1
248rsadsi 2 7 : : hmacWithSHA1
249rsadsi 3 2 : RC2-CBC : rc2-cbc
250 : RC2-ECB : rc2-ecb
251!Cname rc2-cfb64
252 : RC2-CFB : rc2-cfb
253!Cname rc2-ofb64
254 : RC2-OFB : rc2-ofb
255 : RC2-40-CBC : rc2-40-cbc
256 : RC2-64-CBC : rc2-64-cbc
257rsadsi 3 4 : RC4 : rc4
258 : RC4-40 : rc4-40
259rsadsi 3 7 : DES-EDE3-CBC : des-ede3-cbc
260rsadsi 3 8 : RC5-CBC : rc5-cbc
261 : RC5-ECB : rc5-ecb
262!Cname rc5-cfb64
263 : RC5-CFB : rc5-cfb
264!Cname rc5-ofb64
265 : RC5-OFB : rc5-ofb
266
267!Cname ms-ext-req
2681 3 6 1 4 1 311 2 1 14 : msExtReq : Microsoft Extension Request
269!Cname ms-code-ind
2701 3 6 1 4 1 311 2 1 21 : msCodeInd : Microsoft Individual Code Signing
271!Cname ms-code-com
2721 3 6 1 4 1 311 2 1 22 : msCodeCom : Microsoft Commercial Code Signing
273!Cname ms-ctl-sign
2741 3 6 1 4 1 311 10 3 1 : msCTLSign : Microsoft Trust List Signing
275!Cname ms-sgc
2761 3 6 1 4 1 311 10 3 3 : msSGC : Microsoft Server Gated Crypto
277!Cname ms-efs
2781 3 6 1 4 1 311 10 3 4 : msEFS : Microsoft Encrypted File System
279!Cname ms-smartcard-login
2801 3 6 1 4 1 311 20 2 2 : msSmartcardLogin : Microsoft Smartcardlogin
281!Cname ms-upn
2821 3 6 1 4 1 311 20 2 3 : msUPN : Microsoft Universal Principal Name
283
2841 3 6 1 4 1 188 7 1 1 2 : IDEA-CBC : idea-cbc
285 : IDEA-ECB : idea-ecb
286!Cname idea-cfb64
287 : IDEA-CFB : idea-cfb
288!Cname idea-ofb64
289 : IDEA-OFB : idea-ofb
290
2911 3 6 1 4 1 3029 1 2 : BF-CBC : bf-cbc
292 : BF-ECB : bf-ecb
293!Cname bf-cfb64
294 : BF-CFB : bf-cfb
295!Cname bf-ofb64
296 : BF-OFB : bf-ofb
297
298!Cname id-pkix
2991 3 6 1 5 5 7 : PKIX
300
301# PKIX Arcs
302id-pkix 0 : id-pkix-mod
303id-pkix 1 : id-pe
304id-pkix 2 : id-qt
305id-pkix 3 : id-kp
306id-pkix 4 : id-it
307id-pkix 5 : id-pkip
308id-pkix 6 : id-alg
309id-pkix 7 : id-cmc
310id-pkix 8 : id-on
311id-pkix 9 : id-pda
312id-pkix 10 : id-aca
313id-pkix 11 : id-qcs
314id-pkix 12 : id-cct
315id-pkix 21 : id-ppl
316id-pkix 48 : id-ad
317
318# PKIX Modules
319id-pkix-mod 1 : id-pkix1-explicit-88
320id-pkix-mod 2 : id-pkix1-implicit-88
321id-pkix-mod 3 : id-pkix1-explicit-93
322id-pkix-mod 4 : id-pkix1-implicit-93
323id-pkix-mod 5 : id-mod-crmf
324id-pkix-mod 6 : id-mod-cmc
325id-pkix-mod 7 : id-mod-kea-profile-88
326id-pkix-mod 8 : id-mod-kea-profile-93
327id-pkix-mod 9 : id-mod-cmp
328id-pkix-mod 10 : id-mod-qualified-cert-88
329id-pkix-mod 11 : id-mod-qualified-cert-93
330id-pkix-mod 12 : id-mod-attribute-cert
331id-pkix-mod 13 : id-mod-timestamp-protocol
332id-pkix-mod 14 : id-mod-ocsp
333id-pkix-mod 15 : id-mod-dvcs
334id-pkix-mod 16 : id-mod-cmp2000
335
336# PKIX Private Extensions
337!Cname info-access
338id-pe 1 : authorityInfoAccess : Authority Information Access
339id-pe 2 : biometricInfo : Biometric Info
340id-pe 3 : qcStatements
341id-pe 4 : ac-auditEntity
342id-pe 5 : ac-targeting
343id-pe 6 : aaControls
344id-pe 7 : sbqp-ipAddrBlock
345id-pe 8 : sbqp-autonomousSysNum
346id-pe 9 : sbqp-routerIdentifier
347id-pe 10 : ac-proxying
348!Cname sinfo-access
349id-pe 11 : subjectInfoAccess : Subject Information Access
350id-pe 14 : proxyCertInfo : Proxy Certificate Information
351
352# PKIX policyQualifiers for Internet policy qualifiers
353id-qt 1 : id-qt-cps : Policy Qualifier CPS
354id-qt 2 : id-qt-unotice : Policy Qualifier User Notice
355id-qt 3 : textNotice
356
357# PKIX key purpose identifiers
358!Cname server-auth
359id-kp 1 : serverAuth : TLS Web Server Authentication
360!Cname client-auth
361id-kp 2 : clientAuth : TLS Web Client Authentication
362!Cname code-sign
363id-kp 3 : codeSigning : Code Signing
364!Cname email-protect
365id-kp 4 : emailProtection : E-mail Protection
366id-kp 5 : ipsecEndSystem : IPSec End System
367id-kp 6 : ipsecTunnel : IPSec Tunnel
368id-kp 7 : ipsecUser : IPSec User
369!Cname time-stamp
370id-kp 8 : timeStamping : Time Stamping
371# From OCSP spec RFC2560
372!Cname OCSP-sign
373id-kp 9 : OCSPSigning : OCSP Signing
374id-kp 10 : DVCS : dvcs
375
376# CMP information types
377id-it 1 : id-it-caProtEncCert
378id-it 2 : id-it-signKeyPairTypes
379id-it 3 : id-it-encKeyPairTypes
380id-it 4 : id-it-preferredSymmAlg
381id-it 5 : id-it-caKeyUpdateInfo
382id-it 6 : id-it-currentCRL
383id-it 7 : id-it-unsupportedOIDs
384# obsolete
385id-it 8 : id-it-subscriptionRequest
386# obsolete
387id-it 9 : id-it-subscriptionResponse
388id-it 10 : id-it-keyPairParamReq
389id-it 11 : id-it-keyPairParamRep
390id-it 12 : id-it-revPassphrase
391id-it 13 : id-it-implicitConfirm
392id-it 14 : id-it-confirmWaitTime
393id-it 15 : id-it-origPKIMessage
394
395# CRMF registration
396id-pkip 1 : id-regCtrl
397id-pkip 2 : id-regInfo
398
399# CRMF registration controls
400id-regCtrl 1 : id-regCtrl-regToken
401id-regCtrl 2 : id-regCtrl-authenticator
402id-regCtrl 3 : id-regCtrl-pkiPublicationInfo
403id-regCtrl 4 : id-regCtrl-pkiArchiveOptions
404id-regCtrl 5 : id-regCtrl-oldCertID
405id-regCtrl 6 : id-regCtrl-protocolEncrKey
406
407# CRMF registration information
408id-regInfo 1 : id-regInfo-utf8Pairs
409id-regInfo 2 : id-regInfo-certReq
410
411# algorithms
412id-alg 1 : id-alg-des40
413id-alg 2 : id-alg-noSignature
414id-alg 3 : id-alg-dh-sig-hmac-sha1
415id-alg 4 : id-alg-dh-pop
416
417# CMC controls
418id-cmc 1 : id-cmc-statusInfo
419id-cmc 2 : id-cmc-identification
420id-cmc 3 : id-cmc-identityProof
421id-cmc 4 : id-cmc-dataReturn
422id-cmc 5 : id-cmc-transactionId
423id-cmc 6 : id-cmc-senderNonce
424id-cmc 7 : id-cmc-recipientNonce
425id-cmc 8 : id-cmc-addExtensions
426id-cmc 9 : id-cmc-encryptedPOP
427id-cmc 10 : id-cmc-decryptedPOP
428id-cmc 11 : id-cmc-lraPOPWitness
429id-cmc 15 : id-cmc-getCert
430id-cmc 16 : id-cmc-getCRL
431id-cmc 17 : id-cmc-revokeRequest
432id-cmc 18 : id-cmc-regInfo
433id-cmc 19 : id-cmc-responseInfo
434id-cmc 21 : id-cmc-queryPending
435id-cmc 22 : id-cmc-popLinkRandom
436id-cmc 23 : id-cmc-popLinkWitness
437id-cmc 24 : id-cmc-confirmCertAcceptance
438
439# other names
440id-on 1 : id-on-personalData
441
442# personal data attributes
443id-pda 1 : id-pda-dateOfBirth
444id-pda 2 : id-pda-placeOfBirth
445id-pda 3 : id-pda-gender
446id-pda 4 : id-pda-countryOfCitizenship
447id-pda 5 : id-pda-countryOfResidence
448
449# attribute certificate attributes
450id-aca 1 : id-aca-authenticationInfo
451id-aca 2 : id-aca-accessIdentity
452id-aca 3 : id-aca-chargingIdentity
453id-aca 4 : id-aca-group
454# attention : the following seems to be obsolete, replace by 'role'
455id-aca 5 : id-aca-role
456id-aca 6 : id-aca-encAttrs
457
458# qualified certificate statements
459id-qcs 1 : id-qcs-pkixQCSyntax-v1
460
461# CMC content types
462id-cct 1 : id-cct-crs
463id-cct 2 : id-cct-PKIData
464id-cct 3 : id-cct-PKIResponse
465
466# Predefined Proxy Certificate policy languages
467id-ppl 0 : id-ppl-anyLanguage : Any language
468id-ppl 1 : id-ppl-inheritAll : Inherit all
469id-ppl 2 : id-ppl-independent : Independent
470
471# access descriptors for authority info access extension
472!Cname ad-OCSP
473id-ad 1 : OCSP : OCSP
474!Cname ad-ca-issuers
475id-ad 2 : caIssuers : CA Issuers
476!Cname ad-timeStamping
477id-ad 3 : ad_timestamping : AD Time Stamping
478!Cname ad-dvcs
479id-ad 4 : AD_DVCS : ad dvcs
480
481
482!Alias id-pkix-OCSP ad-OCSP
483!module id-pkix-OCSP
484!Cname basic
485id-pkix-OCSP 1 : basicOCSPResponse : Basic OCSP Response
486id-pkix-OCSP 2 : Nonce : OCSP Nonce
487id-pkix-OCSP 3 : CrlID : OCSP CRL ID
488id-pkix-OCSP 4 : acceptableResponses : Acceptable OCSP Responses
489id-pkix-OCSP 5 : noCheck : OCSP No Check
490id-pkix-OCSP 6 : archiveCutoff : OCSP Archive Cutoff
491id-pkix-OCSP 7 : serviceLocator : OCSP Service Locator
492id-pkix-OCSP 8 : extendedStatus : Extended OCSP Status
493id-pkix-OCSP 9 : valid
494id-pkix-OCSP 10 : path
495id-pkix-OCSP 11 : trustRoot : Trust Root
496!global
497
4981 3 14 3 2 : algorithm : algorithm
499algorithm 3 : RSA-NP-MD5 : md5WithRSA
500algorithm 6 : DES-ECB : des-ecb
501algorithm 7 : DES-CBC : des-cbc
502!Cname des-ofb64
503algorithm 8 : DES-OFB : des-ofb
504!Cname des-cfb64
505algorithm 9 : DES-CFB : des-cfb
506algorithm 11 : rsaSignature
507!Cname dsa-2
508algorithm 12 : DSA-old : dsaEncryption-old
509algorithm 13 : DSA-SHA : dsaWithSHA
510algorithm 15 : RSA-SHA : shaWithRSAEncryption
511!Cname des-ede-ecb
512algorithm 17 : DES-EDE : des-ede
513!Cname des-ede3-ecb
514 : DES-EDE3 : des-ede3
515 : DES-EDE-CBC : des-ede-cbc
516!Cname des-ede-cfb64
517 : DES-EDE-CFB : des-ede-cfb
518!Cname des-ede3-cfb64
519 : DES-EDE3-CFB : des-ede3-cfb
520!Cname des-ede-ofb64
521 : DES-EDE-OFB : des-ede-ofb
522!Cname des-ede3-ofb64
523 : DES-EDE3-OFB : des-ede3-ofb
524 : DESX-CBC : desx-cbc
525algorithm 18 : SHA : sha
526algorithm 26 : SHA1 : sha1
527!Cname dsaWithSHA1-2
528algorithm 27 : DSA-SHA1-old : dsaWithSHA1-old
529algorithm 29 : RSA-SHA1-2 : sha1WithRSA
530
5311 3 36 3 2 1 : RIPEMD160 : ripemd160
5321 3 36 3 3 1 2 : RSA-RIPEMD160 : ripemd160WithRSA
533
534!Cname sxnet
5351 3 101 1 4 1 : SXNetID : Strong Extranet ID
536
5372 5 : X500 : directory services (X.500)
538
539X500 4 : X509
540X509 3 : CN : commonName
541X509 4 : SN : surname
542X509 5 : : serialNumber
543X509 6 : C : countryName
544X509 7 : L : localityName
545X509 8 : ST : stateOrProvinceName
546X509 9 : : streetAddress
547X509 10 : O : organizationName
548X509 11 : OU : organizationalUnitName
549X509 12 : : title
550X509 13 : : description
551X509 17 : : postalCode
552X509 41 : name : name
553X509 42 : GN : givenName
554X509 43 : : initials
555X509 44 : : generationQualifier
556X509 45 : : x500UniqueIdentifier
557X509 46 : dnQualifier : dnQualifier
558X509 65 : : pseudonym
559X509 72 : role : role
560
561X500 8 : X500algorithms : directory services - algorithms
562X500algorithms 1 1 : RSA : rsa
563X500algorithms 3 100 : RSA-MDC2 : mdc2WithRSA
564X500algorithms 3 101 : MDC2 : mdc2
565
566X500 29 : id-ce
567!Cname subject-key-identifier
568id-ce 14 : subjectKeyIdentifier : X509v3 Subject Key Identifier
569!Cname key-usage
570id-ce 15 : keyUsage : X509v3 Key Usage
571!Cname private-key-usage-period
572id-ce 16 : privateKeyUsagePeriod : X509v3 Private Key Usage Period
573!Cname subject-alt-name
574id-ce 17 : subjectAltName : X509v3 Subject Alternative Name
575!Cname issuer-alt-name
576id-ce 18 : issuerAltName : X509v3 Issuer Alternative Name
577!Cname basic-constraints
578id-ce 19 : basicConstraints : X509v3 Basic Constraints
579!Cname crl-number
580id-ce 20 : crlNumber : X509v3 CRL Number
581!Cname crl-reason
582id-ce 21 : CRLReason : X509v3 CRL Reason Code
583!Cname invalidity-date
584id-ce 24 : invalidityDate : Invalidity Date
585!Cname delta-crl
586id-ce 27 : deltaCRL : X509v3 Delta CRL Indicator
587!Cname crl-distribution-points
588id-ce 31 : crlDistributionPoints : X509v3 CRL Distribution Points
589!Cname certificate-policies
590id-ce 32 : certificatePolicies : X509v3 Certificate Policies
591!Cname authority-key-identifier
592id-ce 35 : authorityKeyIdentifier : X509v3 Authority Key Identifier
593!Cname policy-constraints
594id-ce 36 : policyConstraints : X509v3 Policy Constraints
595!Cname ext-key-usage
596id-ce 37 : extendedKeyUsage : X509v3 Extended Key Usage
597!Cname target-information
598id-ce 55 : targetInformation : X509v3 AC Targeting
599!Cname no-rev-avail
600id-ce 56 : noRevAvail : X509v3 No Revocation Available
601
602!Cname netscape
6032 16 840 1 113730 : Netscape : Netscape Communications Corp.
604!Cname netscape-cert-extension
605netscape 1 : nsCertExt : Netscape Certificate Extension
606!Cname netscape-data-type
607netscape 2 : nsDataType : Netscape Data Type
608!Cname netscape-cert-type
609netscape-cert-extension 1 : nsCertType : Netscape Cert Type
610!Cname netscape-base-url
611netscape-cert-extension 2 : nsBaseUrl : Netscape Base Url
612!Cname netscape-revocation-url
613netscape-cert-extension 3 : nsRevocationUrl : Netscape Revocation Url
614!Cname netscape-ca-revocation-url
615netscape-cert-extension 4 : nsCaRevocationUrl : Netscape CA Revocation Url
616!Cname netscape-renewal-url
617netscape-cert-extension 7 : nsRenewalUrl : Netscape Renewal Url
618!Cname netscape-ca-policy-url
619netscape-cert-extension 8 : nsCaPolicyUrl : Netscape CA Policy Url
620!Cname netscape-ssl-server-name
621netscape-cert-extension 12 : nsSslServerName : Netscape SSL Server Name
622!Cname netscape-comment
623netscape-cert-extension 13 : nsComment : Netscape Comment
624!Cname netscape-cert-sequence
625netscape-data-type 5 : nsCertSequence : Netscape Certificate Sequence
626!Cname ns-sgc
627netscape 4 1 : nsSGC : Netscape Server Gated Crypto
628
629# iso(1)
630iso 3 : ORG : org
631org 6 : DOD : dod
632dod 1 : IANA : iana
633!Alias internet iana
634
635internet 1 : directory : Directory
636internet 2 : mgmt : Management
637internet 3 : experimental : Experimental
638internet 4 : private : Private
639internet 5 : security : Security
640internet 6 : snmpv2 : SNMPv2
641# Documents refer to "internet 7" as "mail". This however leads to ambiguities
642# with RFC2798, Section 9.1.3, where "mail" is defined as the short name for
643# rfc822Mailbox. The short name is therefore here left out for a reason.
644# Subclasses of "mail", e.g. "MIME MHS" don't consitute a problem, as
645# references are realized via long name "Mail" (with capital M).
646internet 7 : : Mail
647
648Private 1 : enterprises : Enterprises
649
650# RFC 2247
651Enterprises 1466 344 : dcobject : dcObject
652
653# RFC 1495
654Mail 1 : mime-mhs : MIME MHS
655mime-mhs 1 : mime-mhs-headings : mime-mhs-headings
656mime-mhs 2 : mime-mhs-bodies : mime-mhs-bodies
657mime-mhs-headings 1 : id-hex-partial-message : id-hex-partial-message
658mime-mhs-headings 2 : id-hex-multipart-message : id-hex-multipart-message
659
660# What the hell are these OIDs, really?
661!Cname rle-compression
6621 1 1 1 666 1 : RLE : run length compression
663!Cname zlib-compression
6641 1 1 1 666 2 : ZLIB : zlib compression
665
666# AES aka Rijndael
667
668!Alias csor 2 16 840 1 101 3
669!Alias nistAlgorithms csor 4
670!Alias aes nistAlgorithms 1
671
672aes 1 : AES-128-ECB : aes-128-ecb
673aes 2 : AES-128-CBC : aes-128-cbc
674!Cname aes-128-ofb128
675aes 3 : AES-128-OFB : aes-128-ofb
676!Cname aes-128-cfb128
677aes 4 : AES-128-CFB : aes-128-cfb
678
679aes 21 : AES-192-ECB : aes-192-ecb
680aes 22 : AES-192-CBC : aes-192-cbc
681!Cname aes-192-ofb128
682aes 23 : AES-192-OFB : aes-192-ofb
683!Cname aes-192-cfb128
684aes 24 : AES-192-CFB : aes-192-cfb
685
686aes 41 : AES-256-ECB : aes-256-ecb
687aes 42 : AES-256-CBC : aes-256-cbc
688!Cname aes-256-ofb128
689aes 43 : AES-256-OFB : aes-256-ofb
690!Cname aes-256-cfb128
691aes 44 : AES-256-CFB : aes-256-cfb
692
693# There are no OIDs for these modes...
694
695 : AES-128-CFB1 : aes-128-cfb1
696 : AES-192-CFB1 : aes-192-cfb1
697 : AES-256-CFB1 : aes-256-cfb1
698 : AES-128-CFB8 : aes-128-cfb8
699 : AES-192-CFB8 : aes-192-cfb8
700 : AES-256-CFB8 : aes-256-cfb8
701 : DES-CFB1 : des-cfb1
702 : DES-CFB8 : des-cfb8
703 : DES-EDE3-CFB1 : des-ede3-cfb1
704 : DES-EDE3-CFB8 : des-ede3-cfb8
705
706# Hold instruction CRL entry extension
707!Cname hold-instruction-code
708id-ce 23 : holdInstructionCode : Hold Instruction Code
709!Alias holdInstruction X9-57 2
710!Cname hold-instruction-none
711holdInstruction 1 : holdInstructionNone : Hold Instruction None
712!Cname hold-instruction-call-issuer
713holdInstruction 2 : holdInstructionCallIssuer : Hold Instruction Call Issuer
714!Cname hold-instruction-reject
715holdInstruction 3 : holdInstructionReject : Hold Instruction Reject
716
717# OID's from CCITT. Most of this is defined in RFC 1274. A couple of
718# them are also mentioned in RFC 2247
719ccitt 9 : data
720data 2342 : pss
721pss 19200300 : ucl
722ucl 100 : pilot
723pilot 1 : : pilotAttributeType
724pilot 3 : : pilotAttributeSyntax
725pilot 4 : : pilotObjectClass
726pilot 10 : : pilotGroups
727pilotAttributeSyntax 4 : : iA5StringSyntax
728pilotAttributeSyntax 5 : : caseIgnoreIA5StringSyntax
729pilotObjectClass 3 : : pilotObject
730pilotObjectClass 4 : : pilotPerson
731pilotObjectClass 5 : account
732pilotObjectClass 6 : document
733pilotObjectClass 7 : room
734pilotObjectClass 9 : : documentSeries
735pilotObjectClass 13 : domain : Domain
736pilotObjectClass 14 : : rFC822localPart
737pilotObjectClass 15 : : dNSDomain
738pilotObjectClass 17 : : domainRelatedObject
739pilotObjectClass 18 : : friendlyCountry
740pilotObjectClass 19 : : simpleSecurityObject
741pilotObjectClass 20 : : pilotOrganization
742pilotObjectClass 21 : : pilotDSA
743pilotObjectClass 22 : : qualityLabelledData
744pilotAttributeType 1 : UID : userId
745pilotAttributeType 2 : : textEncodedORAddress
746pilotAttributeType 3 : mail : rfc822Mailbox
747pilotAttributeType 4 : info
748pilotAttributeType 5 : : favouriteDrink
749pilotAttributeType 6 : : roomNumber
750pilotAttributeType 7 : photo
751pilotAttributeType 8 : : userClass
752pilotAttributeType 9 : host
753pilotAttributeType 10 : manager
754pilotAttributeType 11 : : documentIdentifier
755pilotAttributeType 12 : : documentTitle
756pilotAttributeType 13 : : documentVersion
757pilotAttributeType 14 : : documentAuthor
758pilotAttributeType 15 : : documentLocation
759pilotAttributeType 20 : : homeTelephoneNumber
760pilotAttributeType 21 : secretary
761pilotAttributeType 22 : : otherMailbox
762pilotAttributeType 23 : : lastModifiedTime
763pilotAttributeType 24 : : lastModifiedBy
764pilotAttributeType 25 : DC : domainComponent
765pilotAttributeType 26 : : aRecord
766pilotAttributeType 27 : : pilotAttributeType27
767pilotAttributeType 28 : : mXRecord
768pilotAttributeType 29 : : nSRecord
769pilotAttributeType 30 : : sOARecord
770pilotAttributeType 31 : : cNAMERecord
771pilotAttributeType 37 : : associatedDomain
772pilotAttributeType 38 : : associatedName
773pilotAttributeType 39 : : homePostalAddress
774pilotAttributeType 40 : : personalTitle
775pilotAttributeType 41 : : mobileTelephoneNumber
776pilotAttributeType 42 : : pagerTelephoneNumber
777pilotAttributeType 43 : : friendlyCountryName
778# The following clashes with 2.5.4.45, so commented away
779#pilotAttributeType 44 : uid : uniqueIdentifier
780pilotAttributeType 45 : : organizationalStatus
781pilotAttributeType 46 : : janetMailbox
782pilotAttributeType 47 : : mailPreferenceOption
783pilotAttributeType 48 : : buildingName
784pilotAttributeType 49 : : dSAQuality
785pilotAttributeType 50 : : singleLevelQuality
786pilotAttributeType 51 : : subtreeMinimumQuality
787pilotAttributeType 52 : : subtreeMaximumQuality
788pilotAttributeType 53 : : personalSignature
789pilotAttributeType 54 : : dITRedirect
790pilotAttributeType 55 : audio
791pilotAttributeType 56 : : documentPublisher
792
7932 23 42 : id-set : Secure Electronic Transactions
794
795id-set 0 : set-ctype : content types
796id-set 1 : set-msgExt : message extensions
797id-set 3 : set-attr
798id-set 5 : set-policy
799id-set 7 : set-certExt : certificate extensions
800id-set 8 : set-brand
801
802set-ctype 0 : setct-PANData
803set-ctype 1 : setct-PANToken
804set-ctype 2 : setct-PANOnly
805set-ctype 3 : setct-OIData
806set-ctype 4 : setct-PI
807set-ctype 5 : setct-PIData
808set-ctype 6 : setct-PIDataUnsigned
809set-ctype 7 : setct-HODInput
810set-ctype 8 : setct-AuthResBaggage
811set-ctype 9 : setct-AuthRevReqBaggage
812set-ctype 10 : setct-AuthRevResBaggage
813set-ctype 11 : setct-CapTokenSeq
814set-ctype 12 : setct-PInitResData
815set-ctype 13 : setct-PI-TBS
816set-ctype 14 : setct-PResData
817set-ctype 16 : setct-AuthReqTBS
818set-ctype 17 : setct-AuthResTBS
819set-ctype 18 : setct-AuthResTBSX
820set-ctype 19 : setct-AuthTokenTBS
821set-ctype 20 : setct-CapTokenData
822set-ctype 21 : setct-CapTokenTBS
823set-ctype 22 : setct-AcqCardCodeMsg
824set-ctype 23 : setct-AuthRevReqTBS
825set-ctype 24 : setct-AuthRevResData
826set-ctype 25 : setct-AuthRevResTBS
827set-ctype 26 : setct-CapReqTBS
828set-ctype 27 : setct-CapReqTBSX
829set-ctype 28 : setct-CapResData
830set-ctype 29 : setct-CapRevReqTBS
831set-ctype 30 : setct-CapRevReqTBSX
832set-ctype 31 : setct-CapRevResData
833set-ctype 32 : setct-CredReqTBS
834set-ctype 33 : setct-CredReqTBSX
835set-ctype 34 : setct-CredResData
836set-ctype 35 : setct-CredRevReqTBS
837set-ctype 36 : setct-CredRevReqTBSX
838set-ctype 37 : setct-CredRevResData
839set-ctype 38 : setct-PCertReqData
840set-ctype 39 : setct-PCertResTBS
841set-ctype 40 : setct-BatchAdminReqData
842set-ctype 41 : setct-BatchAdminResData
843set-ctype 42 : setct-CardCInitResTBS
844set-ctype 43 : setct-MeAqCInitResTBS
845set-ctype 44 : setct-RegFormResTBS
846set-ctype 45 : setct-CertReqData
847set-ctype 46 : setct-CertReqTBS
848set-ctype 47 : setct-CertResData
849set-ctype 48 : setct-CertInqReqTBS
850set-ctype 49 : setct-ErrorTBS
851set-ctype 50 : setct-PIDualSignedTBE
852set-ctype 51 : setct-PIUnsignedTBE
853set-ctype 52 : setct-AuthReqTBE
854set-ctype 53 : setct-AuthResTBE
855set-ctype 54 : setct-AuthResTBEX
856set-ctype 55 : setct-AuthTokenTBE
857set-ctype 56 : setct-CapTokenTBE
858set-ctype 57 : setct-CapTokenTBEX
859set-ctype 58 : setct-AcqCardCodeMsgTBE
860set-ctype 59 : setct-AuthRevReqTBE
861set-ctype 60 : setct-AuthRevResTBE
862set-ctype 61 : setct-AuthRevResTBEB
863set-ctype 62 : setct-CapReqTBE
864set-ctype 63 : setct-CapReqTBEX
865set-ctype 64 : setct-CapResTBE
866set-ctype 65 : setct-CapRevReqTBE
867set-ctype 66 : setct-CapRevReqTBEX
868set-ctype 67 : setct-CapRevResTBE
869set-ctype 68 : setct-CredReqTBE
870set-ctype 69 : setct-CredReqTBEX
871set-ctype 70 : setct-CredResTBE
872set-ctype 71 : setct-CredRevReqTBE
873set-ctype 72 : setct-CredRevReqTBEX
874set-ctype 73 : setct-CredRevResTBE
875set-ctype 74 : setct-BatchAdminReqTBE
876set-ctype 75 : setct-BatchAdminResTBE
877set-ctype 76 : setct-RegFormReqTBE
878set-ctype 77 : setct-CertReqTBE
879set-ctype 78 : setct-CertReqTBEX
880set-ctype 79 : setct-CertResTBE
881set-ctype 80 : setct-CRLNotificationTBS
882set-ctype 81 : setct-CRLNotificationResTBS
883set-ctype 82 : setct-BCIDistributionTBS
884
885set-msgExt 1 : setext-genCrypt : generic cryptogram
886set-msgExt 3 : setext-miAuth : merchant initiated auth
887set-msgExt 4 : setext-pinSecure
888set-msgExt 5 : setext-pinAny
889set-msgExt 7 : setext-track2
890set-msgExt 8 : setext-cv : additional verification
891
892set-policy 0 : set-policy-root
893
894set-certExt 0 : setCext-hashedRoot
895set-certExt 1 : setCext-certType
896set-certExt 2 : setCext-merchData
897set-certExt 3 : setCext-cCertRequired
898set-certExt 4 : setCext-tunneling
899set-certExt 5 : setCext-setExt
900set-certExt 6 : setCext-setQualf
901set-certExt 7 : setCext-PGWYcapabilities
902set-certExt 8 : setCext-TokenIdentifier
903set-certExt 9 : setCext-Track2Data
904set-certExt 10 : setCext-TokenType
905set-certExt 11 : setCext-IssuerCapabilities
906
907set-attr 0 : setAttr-Cert
908set-attr 1 : setAttr-PGWYcap : payment gateway capabilities
909set-attr 2 : setAttr-TokenType
910set-attr 3 : setAttr-IssCap : issuer capabilities
911
912setAttr-Cert 0 : set-rootKeyThumb
913setAttr-Cert 1 : set-addPolicy
914
915setAttr-TokenType 1 : setAttr-Token-EMV
916setAttr-TokenType 2 : setAttr-Token-B0Prime
917
918setAttr-IssCap 3 : setAttr-IssCap-CVM
919setAttr-IssCap 4 : setAttr-IssCap-T2
920setAttr-IssCap 5 : setAttr-IssCap-Sig
921
922setAttr-IssCap-CVM 1 : setAttr-GenCryptgrm : generate cryptogram
923setAttr-IssCap-T2 1 : setAttr-T2Enc : encrypted track 2
924setAttr-IssCap-T2 2 : setAttr-T2cleartxt : cleartext track 2
925
926setAttr-IssCap-Sig 1 : setAttr-TokICCsig : ICC or token signature
927setAttr-IssCap-Sig 2 : setAttr-SecDevSig : secure device signature
928
929set-brand 1 : set-brand-IATA-ATA
930set-brand 30 : set-brand-Diners
931set-brand 34 : set-brand-AmericanExpress
932set-brand 35 : set-brand-JCB
933set-brand 4 : set-brand-Visa
934set-brand 5 : set-brand-MasterCard
935set-brand 6011 : set-brand-Novus
936
937rsadsi 3 10 : DES-CDMF : des-cdmf
938rsadsi 1 1 6 : rsaOAEPEncryptionSET
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
new file mode 100644
index 0000000000..fab3c03182
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp.h
@@ -0,0 +1,619 @@
1/* ocsp.h */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#ifndef HEADER_OCSP_H
65#define HEADER_OCSP_H
66
67#include <openssl/x509.h>
68#include <openssl/x509v3.h>
69#include <openssl/safestack.h>
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75/* Various flags and values */
76
77#define OCSP_DEFAULT_NONCE_LENGTH 16
78
79#define OCSP_NOCERTS 0x1
80#define OCSP_NOINTERN 0x2
81#define OCSP_NOSIGS 0x4
82#define OCSP_NOCHAIN 0x8
83#define OCSP_NOVERIFY 0x10
84#define OCSP_NOEXPLICIT 0x20
85#define OCSP_NOCASIGN 0x40
86#define OCSP_NODELEGATED 0x80
87#define OCSP_NOCHECKS 0x100
88#define OCSP_TRUSTOTHER 0x200
89#define OCSP_RESPID_KEY 0x400
90#define OCSP_NOTIME 0x800
91
92/* CertID ::= SEQUENCE {
93 * hashAlgorithm AlgorithmIdentifier,
94 * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
95 * issuerKeyHash OCTET STRING, -- Hash of Issuers public key (excluding the tag & length fields)
96 * serialNumber CertificateSerialNumber }
97 */
98typedef struct ocsp_cert_id_st
99 {
100 X509_ALGOR *hashAlgorithm;
101 ASN1_OCTET_STRING *issuerNameHash;
102 ASN1_OCTET_STRING *issuerKeyHash;
103 ASN1_INTEGER *serialNumber;
104 } OCSP_CERTID;
105
106DECLARE_STACK_OF(OCSP_CERTID)
107
108/* Request ::= SEQUENCE {
109 * reqCert CertID,
110 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL }
111 */
112typedef struct ocsp_one_request_st
113 {
114 OCSP_CERTID *reqCert;
115 STACK_OF(X509_EXTENSION) *singleRequestExtensions;
116 } OCSP_ONEREQ;
117
118DECLARE_STACK_OF(OCSP_ONEREQ)
119DECLARE_ASN1_SET_OF(OCSP_ONEREQ)
120
121
122/* TBSRequest ::= SEQUENCE {
123 * version [0] EXPLICIT Version DEFAULT v1,
124 * requestorName [1] EXPLICIT GeneralName OPTIONAL,
125 * requestList SEQUENCE OF Request,
126 * requestExtensions [2] EXPLICIT Extensions OPTIONAL }
127 */
128typedef struct ocsp_req_info_st
129 {
130 ASN1_INTEGER *version;
131 GENERAL_NAME *requestorName;
132 STACK_OF(OCSP_ONEREQ) *requestList;
133 STACK_OF(X509_EXTENSION) *requestExtensions;
134 } OCSP_REQINFO;
135
136/* Signature ::= SEQUENCE {
137 * signatureAlgorithm AlgorithmIdentifier,
138 * signature BIT STRING,
139 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
140 */
141typedef struct ocsp_signature_st
142 {
143 X509_ALGOR *signatureAlgorithm;
144 ASN1_BIT_STRING *signature;
145 STACK_OF(X509) *certs;
146 } OCSP_SIGNATURE;
147
148/* OCSPRequest ::= SEQUENCE {
149 * tbsRequest TBSRequest,
150 * optionalSignature [0] EXPLICIT Signature OPTIONAL }
151 */
152typedef struct ocsp_request_st
153 {
154 OCSP_REQINFO *tbsRequest;
155 OCSP_SIGNATURE *optionalSignature; /* OPTIONAL */
156 } OCSP_REQUEST;
157
158/* OCSPResponseStatus ::= ENUMERATED {
159 * successful (0), --Response has valid confirmations
160 * malformedRequest (1), --Illegal confirmation request
161 * internalError (2), --Internal error in issuer
162 * tryLater (3), --Try again later
163 * --(4) is not used
164 * sigRequired (5), --Must sign the request
165 * unauthorized (6) --Request unauthorized
166 * }
167 */
168#define OCSP_RESPONSE_STATUS_SUCCESSFUL 0
169#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1
170#define OCSP_RESPONSE_STATUS_INTERNALERROR 2
171#define OCSP_RESPONSE_STATUS_TRYLATER 3
172#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5
173#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6
174
175/* ResponseBytes ::= SEQUENCE {
176 * responseType OBJECT IDENTIFIER,
177 * response OCTET STRING }
178 */
179typedef struct ocsp_resp_bytes_st
180 {
181 ASN1_OBJECT *responseType;
182 ASN1_OCTET_STRING *response;
183 } OCSP_RESPBYTES;
184
185/* OCSPResponse ::= SEQUENCE {
186 * responseStatus OCSPResponseStatus,
187 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
188 */
189typedef struct ocsp_response_st
190 {
191 ASN1_ENUMERATED *responseStatus;
192 OCSP_RESPBYTES *responseBytes;
193 } OCSP_RESPONSE;
194
195/* ResponderID ::= CHOICE {
196 * byName [1] Name,
197 * byKey [2] KeyHash }
198 */
199#define V_OCSP_RESPID_NAME 0
200#define V_OCSP_RESPID_KEY 1
201typedef struct ocsp_responder_id_st
202 {
203 int type;
204 union {
205 X509_NAME* byName;
206 ASN1_OCTET_STRING *byKey;
207 } value;
208 } OCSP_RESPID;
209/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key
210 * --(excluding the tag and length fields)
211 */
212
213/* RevokedInfo ::= SEQUENCE {
214 * revocationTime GeneralizedTime,
215 * revocationReason [0] EXPLICIT CRLReason OPTIONAL }
216 */
217typedef struct ocsp_revoked_info_st
218 {
219 ASN1_GENERALIZEDTIME *revocationTime;
220 ASN1_ENUMERATED *revocationReason;
221 } OCSP_REVOKEDINFO;
222
223/* CertStatus ::= CHOICE {
224 * good [0] IMPLICIT NULL,
225 * revoked [1] IMPLICIT RevokedInfo,
226 * unknown [2] IMPLICIT UnknownInfo }
227 */
228#define V_OCSP_CERTSTATUS_GOOD 0
229#define V_OCSP_CERTSTATUS_REVOKED 1
230#define V_OCSP_CERTSTATUS_UNKNOWN 2
231typedef struct ocsp_cert_status_st
232 {
233 int type;
234 union {
235 ASN1_NULL *good;
236 OCSP_REVOKEDINFO *revoked;
237 ASN1_NULL *unknown;
238 } value;
239 } OCSP_CERTSTATUS;
240
241/* SingleResponse ::= SEQUENCE {
242 * certID CertID,
243 * certStatus CertStatus,
244 * thisUpdate GeneralizedTime,
245 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
246 * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
247 */
248typedef struct ocsp_single_response_st
249 {
250 OCSP_CERTID *certId;
251 OCSP_CERTSTATUS *certStatus;
252 ASN1_GENERALIZEDTIME *thisUpdate;
253 ASN1_GENERALIZEDTIME *nextUpdate;
254 STACK_OF(X509_EXTENSION) *singleExtensions;
255 } OCSP_SINGLERESP;
256
257DECLARE_STACK_OF(OCSP_SINGLERESP)
258DECLARE_ASN1_SET_OF(OCSP_SINGLERESP)
259
260/* ResponseData ::= SEQUENCE {
261 * version [0] EXPLICIT Version DEFAULT v1,
262 * responderID ResponderID,
263 * producedAt GeneralizedTime,
264 * responses SEQUENCE OF SingleResponse,
265 * responseExtensions [1] EXPLICIT Extensions OPTIONAL }
266 */
267typedef struct ocsp_response_data_st
268 {
269 ASN1_INTEGER *version;
270 OCSP_RESPID *responderId;
271 ASN1_GENERALIZEDTIME *producedAt;
272 STACK_OF(OCSP_SINGLERESP) *responses;
273 STACK_OF(X509_EXTENSION) *responseExtensions;
274 } OCSP_RESPDATA;
275
276/* BasicOCSPResponse ::= SEQUENCE {
277 * tbsResponseData ResponseData,
278 * signatureAlgorithm AlgorithmIdentifier,
279 * signature BIT STRING,
280 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
281 */
282 /* Note 1:
283 The value for "signature" is specified in the OCSP rfc2560 as follows:
284 "The value for the signature SHALL be computed on the hash of the DER
285 encoding ResponseData." This means that you must hash the DER-encoded
286 tbsResponseData, and then run it through a crypto-signing function, which
287 will (at least w/RSA) do a hash-'n'-private-encrypt operation. This seems
288 a bit odd, but that's the spec. Also note that the data structures do not
289 leave anywhere to independently specify the algorithm used for the initial
290 hash. So, we look at the signature-specification algorithm, and try to do
291 something intelligent. -- Kathy Weinhold, CertCo */
292 /* Note 2:
293 It seems that the mentioned passage from RFC 2560 (section 4.2.1) is open
294 for interpretation. I've done tests against another responder, and found
295 that it doesn't do the double hashing that the RFC seems to say one
296 should. Therefore, all relevant functions take a flag saying which
297 variant should be used. -- Richard Levitte, OpenSSL team and CeloCom */
298typedef struct ocsp_basic_response_st
299 {
300 OCSP_RESPDATA *tbsResponseData;
301 X509_ALGOR *signatureAlgorithm;
302 ASN1_BIT_STRING *signature;
303 STACK_OF(X509) *certs;
304 } OCSP_BASICRESP;
305
306/*
307 * CRLReason ::= ENUMERATED {
308 * unspecified (0),
309 * keyCompromise (1),
310 * cACompromise (2),
311 * affiliationChanged (3),
312 * superseded (4),
313 * cessationOfOperation (5),
314 * certificateHold (6),
315 * removeFromCRL (8) }
316 */
317#define OCSP_REVOKED_STATUS_NOSTATUS -1
318#define OCSP_REVOKED_STATUS_UNSPECIFIED 0
319#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1
320#define OCSP_REVOKED_STATUS_CACOMPROMISE 2
321#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3
322#define OCSP_REVOKED_STATUS_SUPERSEDED 4
323#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5
324#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6
325#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8
326
327/* CrlID ::= SEQUENCE {
328 * crlUrl [0] EXPLICIT IA5String OPTIONAL,
329 * crlNum [1] EXPLICIT INTEGER OPTIONAL,
330 * crlTime [2] EXPLICIT GeneralizedTime OPTIONAL }
331 */
332typedef struct ocsp_crl_id_st
333 {
334 ASN1_IA5STRING *crlUrl;
335 ASN1_INTEGER *crlNum;
336 ASN1_GENERALIZEDTIME *crlTime;
337 } OCSP_CRLID;
338
339/* ServiceLocator ::= SEQUENCE {
340 * issuer Name,
341 * locator AuthorityInfoAccessSyntax OPTIONAL }
342 */
343typedef struct ocsp_service_locator_st
344 {
345 X509_NAME* issuer;
346 STACK_OF(ACCESS_DESCRIPTION) *locator;
347 } OCSP_SERVICELOC;
348
349#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST"
350#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"
351
352#define d2i_OCSP_REQUEST_bio(bp,p) (OCSP_REQUEST*)ASN1_d2i_bio((char*(*)()) \
353 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_REQUEST, (bp),\
354 (unsigned char **)(p))
355
356#define d2i_OCSP_RESPONSE_bio(bp,p) (OCSP_RESPONSE*)ASN1_d2i_bio((char*(*)())\
357 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_RESPONSE, (bp),\
358 (unsigned char **)(p))
359
360#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \
361 (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL)
362
363#define PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\
364 (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL)
365
366#define PEM_write_bio_OCSP_REQUEST(bp,o) \
367 PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\
368 bp,(char *)o, NULL,NULL,0,NULL,NULL)
369
370#define PEM_write_bio_OCSP_RESPONSE(bp,o) \
371 PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\
372 bp,(char *)o, NULL,NULL,0,NULL,NULL)
373
374#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_RESPONSE,bp,\
375 (unsigned char *)o)
376
377#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_REQUEST,bp,\
378 (unsigned char *)o)
379
380#define OCSP_REQUEST_sign(o,pkey,md) \
381 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\
382 o->optionalSignature->signatureAlgorithm,NULL,\
383 o->optionalSignature->signature,o->tbsRequest,pkey,md)
384
385#define OCSP_BASICRESP_sign(o,pkey,md,d) \
386 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),o->signatureAlgorithm,NULL,\
387 o->signature,o->tbsResponseData,pkey,md)
388
389#define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\
390 a->optionalSignature->signatureAlgorithm,\
391 a->optionalSignature->signature,a->tbsRequest,r)
392
393#define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\
394 a->signatureAlgorithm,a->signature,a->tbsResponseData,r)
395
396#define ASN1_BIT_STRING_digest(data,type,md,len) \
397 ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
398
399#define OCSP_CERTID_dup(cid) (OCSP_CERTID*)ASN1_dup((int(*)())i2d_OCSP_CERTID,\
400 (char *(*)())d2i_OCSP_CERTID,(char *)(cid))
401
402#define OCSP_CERTSTATUS_dup(cs)\
403 (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\
404 (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))
405
406OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req);
407
408OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer);
409
410OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
411 X509_NAME *issuerName,
412 ASN1_BIT_STRING* issuerKey,
413 ASN1_INTEGER *serialNumber);
414
415OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid);
416
417int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len);
418int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len);
419int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs);
420int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req);
421
422int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm);
423int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert);
424
425int OCSP_request_sign(OCSP_REQUEST *req,
426 X509 *signer,
427 EVP_PKEY *key,
428 const EVP_MD *dgst,
429 STACK_OF(X509) *certs,
430 unsigned long flags);
431
432int OCSP_response_status(OCSP_RESPONSE *resp);
433OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp);
434
435int OCSP_resp_count(OCSP_BASICRESP *bs);
436OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
437int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
438int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
439 ASN1_GENERALIZEDTIME **revtime,
440 ASN1_GENERALIZEDTIME **thisupd,
441 ASN1_GENERALIZEDTIME **nextupd);
442int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
443 int *reason,
444 ASN1_GENERALIZEDTIME **revtime,
445 ASN1_GENERALIZEDTIME **thisupd,
446 ASN1_GENERALIZEDTIME **nextupd);
447int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
448 ASN1_GENERALIZEDTIME *nextupd,
449 long sec, long maxsec);
450
451int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags);
452
453int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl);
454
455int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
456int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
457
458int OCSP_request_onereq_count(OCSP_REQUEST *req);
459OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i);
460OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one);
461int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
462 ASN1_OCTET_STRING **pikeyHash,
463 ASN1_INTEGER **pserial, OCSP_CERTID *cid);
464int OCSP_request_is_signed(OCSP_REQUEST *req);
465OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);
466OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
467 OCSP_CERTID *cid,
468 int status, int reason,
469 ASN1_TIME *revtime,
470 ASN1_TIME *thisupd, ASN1_TIME *nextupd);
471int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);
472int OCSP_basic_sign(OCSP_BASICRESP *brsp,
473 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
474 STACK_OF(X509) *certs, unsigned long flags);
475
476ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
477 char *data, STACK_OF(ASN1_OBJECT) *sk);
478
479X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim);
480
481X509_EXTENSION *OCSP_accept_responses_new(char **oids);
482
483X509_EXTENSION *OCSP_archive_cutoff_new(char* tim);
484
485X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls);
486
487int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x);
488int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos);
489int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos);
490int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos);
491X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc);
492X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc);
493void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx);
494int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
495 unsigned long flags);
496int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc);
497
498int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x);
499int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos);
500int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos);
501int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos);
502X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc);
503X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc);
504void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx);
505int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
506 unsigned long flags);
507int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc);
508
509int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x);
510int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos);
511int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos);
512int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos);
513X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc);
514X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc);
515void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx);
516int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
517 unsigned long flags);
518int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc);
519
520int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x);
521int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos);
522int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos);
523int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos);
524X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc);
525X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc);
526void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx);
527int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
528 unsigned long flags);
529int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc);
530
531DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP)
532DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
533DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
534DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP)
535DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA)
536DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)
537DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE)
538DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES)
539DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ)
540DECLARE_ASN1_FUNCTIONS(OCSP_CERTID)
541DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST)
542DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE)
543DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)
544DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)
545DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)
546
547char *OCSP_response_status_str(long s);
548char *OCSP_cert_status_str(long s);
549char *OCSP_crl_reason_str(long s);
550
551int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a, unsigned long flags);
552int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags);
553
554int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
555 X509_STORE *st, unsigned long flags);
556
557/* BEGIN ERROR CODES */
558/* The following lines are auto generated by the script mkerr.pl. Any changes
559 * made after this point may be overwritten when the script is next run.
560 */
561void ERR_load_OCSP_strings(void);
562
563/* Error codes for the OCSP functions. */
564
565/* Function codes. */
566#define OCSP_F_ASN1_STRING_ENCODE 100
567#define OCSP_F_CERT_ID_NEW 101
568#define OCSP_F_D2I_OCSP_NONCE 102
569#define OCSP_F_OCSP_BASIC_ADD1_STATUS 103
570#define OCSP_F_OCSP_BASIC_SIGN 104
571#define OCSP_F_OCSP_BASIC_VERIFY 105
572#define OCSP_F_OCSP_CHECK_DELEGATED 106
573#define OCSP_F_OCSP_CHECK_IDS 107
574#define OCSP_F_OCSP_CHECK_ISSUER 108
575#define OCSP_F_OCSP_CHECK_VALIDITY 115
576#define OCSP_F_OCSP_MATCH_ISSUERID 109
577#define OCSP_F_OCSP_PARSE_URL 114
578#define OCSP_F_OCSP_REQUEST_SIGN 110
579#define OCSP_F_OCSP_REQUEST_VERIFY 116
580#define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111
581#define OCSP_F_OCSP_SENDREQ_BIO 112
582#define OCSP_F_REQUEST_VERIFY 113
583
584/* Reason codes. */
585#define OCSP_R_BAD_DATA 100
586#define OCSP_R_CERTIFICATE_VERIFY_ERROR 101
587#define OCSP_R_DIGEST_ERR 102
588#define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122
589#define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123
590#define OCSP_R_ERROR_PARSING_URL 121
591#define OCSP_R_MISSING_OCSPSIGNING_USAGE 103
592#define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124
593#define OCSP_R_NOT_BASIC_RESPONSE 104
594#define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105
595#define OCSP_R_NO_CONTENT 106
596#define OCSP_R_NO_PUBLIC_KEY 107
597#define OCSP_R_NO_RESPONSE_DATA 108
598#define OCSP_R_NO_REVOKED_TIME 109
599#define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110
600#define OCSP_R_REQUEST_NOT_SIGNED 128
601#define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111
602#define OCSP_R_ROOT_CA_NOT_TRUSTED 112
603#define OCSP_R_SERVER_READ_ERROR 113
604#define OCSP_R_SERVER_RESPONSE_ERROR 114
605#define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115
606#define OCSP_R_SERVER_WRITE_ERROR 116
607#define OCSP_R_SIGNATURE_FAILURE 117
608#define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118
609#define OCSP_R_STATUS_EXPIRED 125
610#define OCSP_R_STATUS_NOT_YET_VALID 126
611#define OCSP_R_STATUS_TOO_OLD 127
612#define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119
613#define OCSP_R_UNKNOWN_NID 120
614#define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129
615
616#ifdef __cplusplus
617}
618#endif
619#endif
diff --git a/src/lib/libcrypto/ocsp/ocsp_asn.c b/src/lib/libcrypto/ocsp/ocsp_asn.c
new file mode 100644
index 0000000000..6a3a360d54
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_asn.c
@@ -0,0 +1,182 @@
1/* ocsp_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/ocsp.h>
61
62ASN1_SEQUENCE(OCSP_SIGNATURE) = {
63 ASN1_SIMPLE(OCSP_SIGNATURE, signatureAlgorithm, X509_ALGOR),
64 ASN1_SIMPLE(OCSP_SIGNATURE, signature, ASN1_BIT_STRING),
65 ASN1_EXP_SEQUENCE_OF(OCSP_SIGNATURE, certs, X509, 0)
66} ASN1_SEQUENCE_END(OCSP_SIGNATURE)
67
68IMPLEMENT_ASN1_FUNCTIONS(OCSP_SIGNATURE)
69
70ASN1_SEQUENCE(OCSP_CERTID) = {
71 ASN1_SIMPLE(OCSP_CERTID, hashAlgorithm, X509_ALGOR),
72 ASN1_SIMPLE(OCSP_CERTID, issuerNameHash, ASN1_OCTET_STRING),
73 ASN1_SIMPLE(OCSP_CERTID, issuerKeyHash, ASN1_OCTET_STRING),
74 ASN1_SIMPLE(OCSP_CERTID, serialNumber, ASN1_INTEGER)
75} ASN1_SEQUENCE_END(OCSP_CERTID)
76
77IMPLEMENT_ASN1_FUNCTIONS(OCSP_CERTID)
78
79ASN1_SEQUENCE(OCSP_ONEREQ) = {
80 ASN1_SIMPLE(OCSP_ONEREQ, reqCert, OCSP_CERTID),
81 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_ONEREQ, singleRequestExtensions, X509_EXTENSION, 0)
82} ASN1_SEQUENCE_END(OCSP_ONEREQ)
83
84IMPLEMENT_ASN1_FUNCTIONS(OCSP_ONEREQ)
85
86ASN1_SEQUENCE(OCSP_REQINFO) = {
87 ASN1_EXP_OPT(OCSP_REQINFO, version, ASN1_INTEGER, 0),
88 ASN1_EXP_OPT(OCSP_REQINFO, requestorName, GENERAL_NAME, 1),
89 ASN1_SEQUENCE_OF(OCSP_REQINFO, requestList, OCSP_ONEREQ),
90 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_REQINFO, requestExtensions, X509_EXTENSION, 2)
91} ASN1_SEQUENCE_END(OCSP_REQINFO)
92
93IMPLEMENT_ASN1_FUNCTIONS(OCSP_REQINFO)
94
95ASN1_SEQUENCE(OCSP_REQUEST) = {
96 ASN1_SIMPLE(OCSP_REQUEST, tbsRequest, OCSP_REQINFO),
97 ASN1_EXP_OPT(OCSP_REQUEST, optionalSignature, OCSP_SIGNATURE, 0)
98} ASN1_SEQUENCE_END(OCSP_REQUEST)
99
100IMPLEMENT_ASN1_FUNCTIONS(OCSP_REQUEST)
101
102/* OCSP_RESPONSE templates */
103
104ASN1_SEQUENCE(OCSP_RESPBYTES) = {
105 ASN1_SIMPLE(OCSP_RESPBYTES, responseType, ASN1_OBJECT),
106 ASN1_SIMPLE(OCSP_RESPBYTES, response, ASN1_OCTET_STRING)
107} ASN1_SEQUENCE_END(OCSP_RESPBYTES)
108
109IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPBYTES)
110
111ASN1_SEQUENCE(OCSP_RESPONSE) = {
112 ASN1_SIMPLE(OCSP_RESPONSE, responseStatus, ASN1_ENUMERATED),
113 ASN1_EXP_OPT(OCSP_RESPONSE, responseBytes, OCSP_RESPBYTES, 0)
114} ASN1_SEQUENCE_END(OCSP_RESPONSE)
115
116IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPONSE)
117
118ASN1_CHOICE(OCSP_RESPID) = {
119 ASN1_EXP(OCSP_RESPID, value.byName, X509_NAME, 1),
120 ASN1_EXP(OCSP_RESPID, value.byKey, ASN1_OCTET_STRING, 2)
121} ASN1_CHOICE_END(OCSP_RESPID)
122
123IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPID)
124
125ASN1_SEQUENCE(OCSP_REVOKEDINFO) = {
126 ASN1_SIMPLE(OCSP_REVOKEDINFO, revocationTime, ASN1_GENERALIZEDTIME),
127 ASN1_EXP_OPT(OCSP_REVOKEDINFO, revocationReason, ASN1_ENUMERATED, 0)
128} ASN1_SEQUENCE_END(OCSP_REVOKEDINFO)
129
130IMPLEMENT_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
131
132ASN1_CHOICE(OCSP_CERTSTATUS) = {
133 ASN1_IMP(OCSP_CERTSTATUS, value.good, ASN1_NULL, 0),
134 ASN1_IMP(OCSP_CERTSTATUS, value.revoked, OCSP_REVOKEDINFO, 1),
135 ASN1_IMP(OCSP_CERTSTATUS, value.unknown, ASN1_NULL, 2)
136} ASN1_CHOICE_END(OCSP_CERTSTATUS)
137
138IMPLEMENT_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
139
140ASN1_SEQUENCE(OCSP_SINGLERESP) = {
141 ASN1_SIMPLE(OCSP_SINGLERESP, certId, OCSP_CERTID),
142 ASN1_SIMPLE(OCSP_SINGLERESP, certStatus, OCSP_CERTSTATUS),
143 ASN1_SIMPLE(OCSP_SINGLERESP, thisUpdate, ASN1_GENERALIZEDTIME),
144 ASN1_EXP_OPT(OCSP_SINGLERESP, nextUpdate, ASN1_GENERALIZEDTIME, 0),
145 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_SINGLERESP, singleExtensions, X509_EXTENSION, 1)
146} ASN1_SEQUENCE_END(OCSP_SINGLERESP)
147
148IMPLEMENT_ASN1_FUNCTIONS(OCSP_SINGLERESP)
149
150ASN1_SEQUENCE(OCSP_RESPDATA) = {
151 ASN1_EXP_OPT(OCSP_RESPDATA, version, ASN1_INTEGER, 0),
152 ASN1_SIMPLE(OCSP_RESPDATA, responderId, OCSP_RESPID),
153 ASN1_SIMPLE(OCSP_RESPDATA, producedAt, ASN1_GENERALIZEDTIME),
154 ASN1_SEQUENCE_OF(OCSP_RESPDATA, responses, OCSP_SINGLERESP),
155 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_RESPDATA, responseExtensions, X509_EXTENSION, 1)
156} ASN1_SEQUENCE_END(OCSP_RESPDATA)
157
158IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPDATA)
159
160ASN1_SEQUENCE(OCSP_BASICRESP) = {
161 ASN1_SIMPLE(OCSP_BASICRESP, tbsResponseData, OCSP_RESPDATA),
162 ASN1_SIMPLE(OCSP_BASICRESP, signatureAlgorithm, X509_ALGOR),
163 ASN1_SIMPLE(OCSP_BASICRESP, signature, ASN1_BIT_STRING),
164 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_BASICRESP, certs, X509, 0)
165} ASN1_SEQUENCE_END(OCSP_BASICRESP)
166
167IMPLEMENT_ASN1_FUNCTIONS(OCSP_BASICRESP)
168
169ASN1_SEQUENCE(OCSP_CRLID) = {
170 ASN1_EXP_OPT(OCSP_CRLID, crlUrl, ASN1_IA5STRING, 0),
171 ASN1_EXP_OPT(OCSP_CRLID, crlNum, ASN1_INTEGER, 1),
172 ASN1_EXP_OPT(OCSP_CRLID, crlTime, ASN1_GENERALIZEDTIME, 2)
173} ASN1_SEQUENCE_END(OCSP_CRLID)
174
175IMPLEMENT_ASN1_FUNCTIONS(OCSP_CRLID)
176
177ASN1_SEQUENCE(OCSP_SERVICELOC) = {
178 ASN1_SIMPLE(OCSP_SERVICELOC, issuer, X509_NAME),
179 ASN1_SEQUENCE_OF_OPT(OCSP_SERVICELOC, locator, ACCESS_DESCRIPTION)
180} ASN1_SEQUENCE_END(OCSP_SERVICELOC)
181
182IMPLEMENT_ASN1_FUNCTIONS(OCSP_SERVICELOC)
diff --git a/src/lib/libcrypto/ocsp/ocsp_cl.c b/src/lib/libcrypto/ocsp/ocsp_cl.c
new file mode 100644
index 0000000000..9b3e6dd8ca
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_cl.c
@@ -0,0 +1,370 @@
1/* ocsp_cl.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include <cryptlib.h>
67#include <openssl/objects.h>
68#include <openssl/rand.h>
69#include <openssl/x509.h>
70#include <openssl/pem.h>
71#include <openssl/x509v3.h>
72#include <openssl/ocsp.h>
73
74/* Utility functions related to sending OCSP requests and extracting
75 * relevant information from the response.
76 */
77
78/* Add an OCSP_CERTID to an OCSP request. Return new OCSP_ONEREQ
79 * pointer: useful if we want to add extensions.
80 */
81
82OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid)
83 {
84 OCSP_ONEREQ *one = NULL;
85
86 if (!(one = OCSP_ONEREQ_new())) goto err;
87 if (one->reqCert) OCSP_CERTID_free(one->reqCert);
88 one->reqCert = cid;
89 if (req &&
90 !sk_OCSP_ONEREQ_push(req->tbsRequest->requestList, one))
91 goto err;
92 return one;
93err:
94 OCSP_ONEREQ_free(one);
95 return NULL;
96 }
97
98/* Set requestorName from an X509_NAME structure */
99
100int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
101 {
102 GENERAL_NAME *gen;
103 gen = GENERAL_NAME_new();
104 if (!X509_NAME_set(&gen->d.directoryName, nm))
105 {
106 GENERAL_NAME_free(gen);
107 return 0;
108 }
109 gen->type = GEN_DIRNAME;
110 if (req->tbsRequest->requestorName)
111 GENERAL_NAME_free(req->tbsRequest->requestorName);
112 req->tbsRequest->requestorName = gen;
113 return 1;
114 }
115
116
117/* Add a certificate to an OCSP request */
118
119int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert)
120 {
121 OCSP_SIGNATURE *sig;
122 if (!req->optionalSignature)
123 req->optionalSignature = OCSP_SIGNATURE_new();
124 sig = req->optionalSignature;
125 if (!sig) return 0;
126 if (!cert) return 1;
127 if (!sig->certs && !(sig->certs = sk_X509_new_null()))
128 return 0;
129
130 if(!sk_X509_push(sig->certs, cert)) return 0;
131 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
132 return 1;
133 }
134
135/* Sign an OCSP request set the requestorName to the subjec
136 * name of an optional signers certificate and include one
137 * or more optional certificates in the request. Behaves
138 * like PKCS7_sign().
139 */
140
141int OCSP_request_sign(OCSP_REQUEST *req,
142 X509 *signer,
143 EVP_PKEY *key,
144 const EVP_MD *dgst,
145 STACK_OF(X509) *certs,
146 unsigned long flags)
147 {
148 int i;
149 OCSP_SIGNATURE *sig;
150 X509 *x;
151
152 if (!OCSP_request_set1_name(req, X509_get_subject_name(signer)))
153 goto err;
154
155 if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
156 if (!dgst) dgst = EVP_sha1();
157 if (key)
158 {
159 if (!X509_check_private_key(signer, key))
160 {
161 OCSPerr(OCSP_F_OCSP_REQUEST_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
162 goto err;
163 }
164 if (!OCSP_REQUEST_sign(req, key, dgst)) goto err;
165 }
166
167 if (!(flags & OCSP_NOCERTS))
168 {
169 if(!OCSP_request_add1_cert(req, signer)) goto err;
170 for (i = 0; i < sk_X509_num(certs); i++)
171 {
172 x = sk_X509_value(certs, i);
173 if (!OCSP_request_add1_cert(req, x)) goto err;
174 }
175 }
176
177 return 1;
178err:
179 OCSP_SIGNATURE_free(req->optionalSignature);
180 req->optionalSignature = NULL;
181 return 0;
182 }
183
184/* Get response status */
185
186int OCSP_response_status(OCSP_RESPONSE *resp)
187 {
188 return ASN1_ENUMERATED_get(resp->responseStatus);
189 }
190
191/* Extract basic response from OCSP_RESPONSE or NULL if
192 * no basic response present.
193 */
194
195
196OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp)
197 {
198 OCSP_RESPBYTES *rb;
199 rb = resp->responseBytes;
200 if (!rb)
201 {
202 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NO_RESPONSE_DATA);
203 return NULL;
204 }
205 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
206 {
207 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NOT_BASIC_RESPONSE);
208 return NULL;
209 }
210
211 return ASN1_item_unpack(rb->response, ASN1_ITEM_rptr(OCSP_BASICRESP));
212 }
213
214/* Return number of OCSP_SINGLERESP reponses present in
215 * a basic response.
216 */
217
218int OCSP_resp_count(OCSP_BASICRESP *bs)
219 {
220 if (!bs) return -1;
221 return sk_OCSP_SINGLERESP_num(bs->tbsResponseData->responses);
222 }
223
224/* Extract an OCSP_SINGLERESP response with a given index */
225
226OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx)
227 {
228 if (!bs) return NULL;
229 return sk_OCSP_SINGLERESP_value(bs->tbsResponseData->responses, idx);
230 }
231
232/* Look single response matching a given certificate ID */
233
234int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last)
235 {
236 int i;
237 STACK_OF(OCSP_SINGLERESP) *sresp;
238 OCSP_SINGLERESP *single;
239 if (!bs) return -1;
240 if (last < 0) last = 0;
241 else last++;
242 sresp = bs->tbsResponseData->responses;
243 for (i = last; i < sk_OCSP_SINGLERESP_num(sresp); i++)
244 {
245 single = sk_OCSP_SINGLERESP_value(sresp, i);
246 if (!OCSP_id_cmp(id, single->certId)) return i;
247 }
248 return -1;
249 }
250
251/* Extract status information from an OCSP_SINGLERESP structure.
252 * Note: the revtime and reason values are only set if the
253 * certificate status is revoked. Returns numerical value of
254 * status.
255 */
256
257int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
258 ASN1_GENERALIZEDTIME **revtime,
259 ASN1_GENERALIZEDTIME **thisupd,
260 ASN1_GENERALIZEDTIME **nextupd)
261 {
262 int ret;
263 OCSP_CERTSTATUS *cst;
264 if(!single) return -1;
265 cst = single->certStatus;
266 ret = cst->type;
267 if (ret == V_OCSP_CERTSTATUS_REVOKED)
268 {
269 OCSP_REVOKEDINFO *rev = cst->value.revoked;
270 if (revtime) *revtime = rev->revocationTime;
271 if (reason)
272 {
273 if(rev->revocationReason)
274 *reason = ASN1_ENUMERATED_get(rev->revocationReason);
275 else *reason = -1;
276 }
277 }
278 if(thisupd) *thisupd = single->thisUpdate;
279 if(nextupd) *nextupd = single->nextUpdate;
280 return ret;
281 }
282
283/* This function combines the previous ones: look up a certificate ID and
284 * if found extract status information. Return 0 is successful.
285 */
286
287int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
288 int *reason,
289 ASN1_GENERALIZEDTIME **revtime,
290 ASN1_GENERALIZEDTIME **thisupd,
291 ASN1_GENERALIZEDTIME **nextupd)
292 {
293 int i;
294 OCSP_SINGLERESP *single;
295 i = OCSP_resp_find(bs, id, -1);
296 /* Maybe check for multiple responses and give an error? */
297 if(i < 0) return 0;
298 single = OCSP_resp_get0(bs, i);
299 i = OCSP_single_get0_status(single, reason, revtime, thisupd, nextupd);
300 if(status) *status = i;
301 return 1;
302 }
303
304/* Check validity of thisUpdate and nextUpdate fields. It is possible that the request will
305 * take a few seconds to process and/or the time wont be totally accurate. Therefore to avoid
306 * rejecting otherwise valid time we allow the times to be within 'nsec' of the current time.
307 * Also to avoid accepting very old responses without a nextUpdate field an optional maxage
308 * parameter specifies the maximum age the thisUpdate field can be.
309 */
310
311int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec)
312 {
313 int ret = 1;
314 time_t t_now, t_tmp;
315 time(&t_now);
316 /* Check thisUpdate is valid and not more than nsec in the future */
317 if (!ASN1_GENERALIZEDTIME_check(thisupd))
318 {
319 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_THISUPDATE_FIELD);
320 ret = 0;
321 }
322 else
323 {
324 t_tmp = t_now + nsec;
325 if (X509_cmp_time(thisupd, &t_tmp) > 0)
326 {
327 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_NOT_YET_VALID);
328 ret = 0;
329 }
330
331 /* If maxsec specified check thisUpdate is not more than maxsec in the past */
332 if (maxsec >= 0)
333 {
334 t_tmp = t_now - maxsec;
335 if (X509_cmp_time(thisupd, &t_tmp) < 0)
336 {
337 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_TOO_OLD);
338 ret = 0;
339 }
340 }
341 }
342
343
344 if (!nextupd) return ret;
345
346 /* Check nextUpdate is valid and not more than nsec in the past */
347 if (!ASN1_GENERALIZEDTIME_check(nextupd))
348 {
349 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
350 ret = 0;
351 }
352 else
353 {
354 t_tmp = t_now - nsec;
355 if (X509_cmp_time(nextupd, &t_tmp) < 0)
356 {
357 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_EXPIRED);
358 ret = 0;
359 }
360 }
361
362 /* Also don't allow nextUpdate to precede thisUpdate */
363 if (ASN1_STRING_cmp(nextupd, thisupd) < 0)
364 {
365 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
366 ret = 0;
367 }
368
369 return ret;
370 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_err.c b/src/lib/libcrypto/ocsp/ocsp_err.c
new file mode 100644
index 0000000000..4c4d8306f8
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_err.c
@@ -0,0 +1,139 @@
1/* crypto/ocsp/ocsp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ocsp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA OCSP_str_functs[]=
68 {
69{ERR_PACK(0,OCSP_F_ASN1_STRING_ENCODE,0), "ASN1_STRING_encode"},
70{ERR_PACK(0,OCSP_F_CERT_ID_NEW,0), "CERT_ID_NEW"},
71{ERR_PACK(0,OCSP_F_D2I_OCSP_NONCE,0), "D2I_OCSP_NONCE"},
72{ERR_PACK(0,OCSP_F_OCSP_BASIC_ADD1_STATUS,0), "OCSP_basic_add1_status"},
73{ERR_PACK(0,OCSP_F_OCSP_BASIC_SIGN,0), "OCSP_basic_sign"},
74{ERR_PACK(0,OCSP_F_OCSP_BASIC_VERIFY,0), "OCSP_basic_verify"},
75{ERR_PACK(0,OCSP_F_OCSP_CHECK_DELEGATED,0), "OCSP_CHECK_DELEGATED"},
76{ERR_PACK(0,OCSP_F_OCSP_CHECK_IDS,0), "OCSP_CHECK_IDS"},
77{ERR_PACK(0,OCSP_F_OCSP_CHECK_ISSUER,0), "OCSP_CHECK_ISSUER"},
78{ERR_PACK(0,OCSP_F_OCSP_CHECK_VALIDITY,0), "OCSP_check_validity"},
79{ERR_PACK(0,OCSP_F_OCSP_MATCH_ISSUERID,0), "OCSP_MATCH_ISSUERID"},
80{ERR_PACK(0,OCSP_F_OCSP_PARSE_URL,0), "OCSP_parse_url"},
81{ERR_PACK(0,OCSP_F_OCSP_REQUEST_SIGN,0), "OCSP_request_sign"},
82{ERR_PACK(0,OCSP_F_OCSP_REQUEST_VERIFY,0), "OCSP_request_verify"},
83{ERR_PACK(0,OCSP_F_OCSP_RESPONSE_GET1_BASIC,0), "OCSP_response_get1_basic"},
84{ERR_PACK(0,OCSP_F_OCSP_SENDREQ_BIO,0), "OCSP_sendreq_bio"},
85{ERR_PACK(0,OCSP_F_REQUEST_VERIFY,0), "REQUEST_VERIFY"},
86{0,NULL}
87 };
88
89static ERR_STRING_DATA OCSP_str_reasons[]=
90 {
91{OCSP_R_BAD_DATA ,"bad data"},
92{OCSP_R_CERTIFICATE_VERIFY_ERROR ,"certificate verify error"},
93{OCSP_R_DIGEST_ERR ,"digest err"},
94{OCSP_R_ERROR_IN_NEXTUPDATE_FIELD ,"error in nextupdate field"},
95{OCSP_R_ERROR_IN_THISUPDATE_FIELD ,"error in thisupdate field"},
96{OCSP_R_ERROR_PARSING_URL ,"error parsing url"},
97{OCSP_R_MISSING_OCSPSIGNING_USAGE ,"missing ocspsigning usage"},
98{OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE ,"nextupdate before thisupdate"},
99{OCSP_R_NOT_BASIC_RESPONSE ,"not basic response"},
100{OCSP_R_NO_CERTIFICATES_IN_CHAIN ,"no certificates in chain"},
101{OCSP_R_NO_CONTENT ,"no content"},
102{OCSP_R_NO_PUBLIC_KEY ,"no public key"},
103{OCSP_R_NO_RESPONSE_DATA ,"no response data"},
104{OCSP_R_NO_REVOKED_TIME ,"no revoked time"},
105{OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE,"private key does not match certificate"},
106{OCSP_R_REQUEST_NOT_SIGNED ,"request not signed"},
107{OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA,"response contains no revocation data"},
108{OCSP_R_ROOT_CA_NOT_TRUSTED ,"root ca not trusted"},
109{OCSP_R_SERVER_READ_ERROR ,"server read error"},
110{OCSP_R_SERVER_RESPONSE_ERROR ,"server response error"},
111{OCSP_R_SERVER_RESPONSE_PARSE_ERROR ,"server response parse error"},
112{OCSP_R_SERVER_WRITE_ERROR ,"server write error"},
113{OCSP_R_SIGNATURE_FAILURE ,"signature failure"},
114{OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND ,"signer certificate not found"},
115{OCSP_R_STATUS_EXPIRED ,"status expired"},
116{OCSP_R_STATUS_NOT_YET_VALID ,"status not yet valid"},
117{OCSP_R_STATUS_TOO_OLD ,"status too old"},
118{OCSP_R_UNKNOWN_MESSAGE_DIGEST ,"unknown message digest"},
119{OCSP_R_UNKNOWN_NID ,"unknown nid"},
120{OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE ,"unsupported requestorname type"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_OCSP_strings(void)
127 {
128 static int init=1;
129
130 if (init)
131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
134 ERR_load_strings(ERR_LIB_OCSP,OCSP_str_functs);
135 ERR_load_strings(ERR_LIB_OCSP,OCSP_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c
new file mode 100644
index 0000000000..57399433fc
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_ext.c
@@ -0,0 +1,538 @@
1/* ocsp_ext.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <cryptlib.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/ocsp.h>
69#include <openssl/rand.h>
70#include <openssl/x509v3.h>
71
72/* Standard wrapper functions for extensions */
73
74/* OCSP request extensions */
75
76int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
77 {
78 return(X509v3_get_ext_count(x->tbsRequest->requestExtensions));
79 }
80
81int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos)
82 {
83 return(X509v3_get_ext_by_NID(x->tbsRequest->requestExtensions,nid,lastpos));
84 }
85
86int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos)
87 {
88 return(X509v3_get_ext_by_OBJ(x->tbsRequest->requestExtensions,obj,lastpos));
89 }
90
91int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos)
92 {
93 return(X509v3_get_ext_by_critical(x->tbsRequest->requestExtensions,crit,lastpos));
94 }
95
96X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc)
97 {
98 return(X509v3_get_ext(x->tbsRequest->requestExtensions,loc));
99 }
100
101X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc)
102 {
103 return(X509v3_delete_ext(x->tbsRequest->requestExtensions,loc));
104 }
105
106void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx)
107 {
108 return X509V3_get_d2i(x->tbsRequest->requestExtensions, nid, crit, idx);
109 }
110
111int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
112 unsigned long flags)
113 {
114 return X509V3_add1_i2d(&x->tbsRequest->requestExtensions, nid, value, crit, flags);
115 }
116
117int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc)
118 {
119 return(X509v3_add_ext(&(x->tbsRequest->requestExtensions),ex,loc) != NULL);
120 }
121
122/* Single extensions */
123
124int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
125 {
126 return(X509v3_get_ext_count(x->singleRequestExtensions));
127 }
128
129int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos)
130 {
131 return(X509v3_get_ext_by_NID(x->singleRequestExtensions,nid,lastpos));
132 }
133
134int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos)
135 {
136 return(X509v3_get_ext_by_OBJ(x->singleRequestExtensions,obj,lastpos));
137 }
138
139int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos)
140 {
141 return(X509v3_get_ext_by_critical(x->singleRequestExtensions,crit,lastpos));
142 }
143
144X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc)
145 {
146 return(X509v3_get_ext(x->singleRequestExtensions,loc));
147 }
148
149X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc)
150 {
151 return(X509v3_delete_ext(x->singleRequestExtensions,loc));
152 }
153
154void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx)
155 {
156 return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx);
157 }
158
159int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
160 unsigned long flags)
161 {
162 return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit, flags);
163 }
164
165int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc)
166 {
167 return(X509v3_add_ext(&(x->singleRequestExtensions),ex,loc) != NULL);
168 }
169
170/* OCSP Basic response */
171
172int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
173 {
174 return(X509v3_get_ext_count(x->tbsResponseData->responseExtensions));
175 }
176
177int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos)
178 {
179 return(X509v3_get_ext_by_NID(x->tbsResponseData->responseExtensions,nid,lastpos));
180 }
181
182int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos)
183 {
184 return(X509v3_get_ext_by_OBJ(x->tbsResponseData->responseExtensions,obj,lastpos));
185 }
186
187int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos)
188 {
189 return(X509v3_get_ext_by_critical(x->tbsResponseData->responseExtensions,crit,lastpos));
190 }
191
192X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc)
193 {
194 return(X509v3_get_ext(x->tbsResponseData->responseExtensions,loc));
195 }
196
197X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc)
198 {
199 return(X509v3_delete_ext(x->tbsResponseData->responseExtensions,loc));
200 }
201
202void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx)
203 {
204 return X509V3_get_d2i(x->tbsResponseData->responseExtensions, nid, crit, idx);
205 }
206
207int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
208 unsigned long flags)
209 {
210 return X509V3_add1_i2d(&x->tbsResponseData->responseExtensions, nid, value, crit, flags);
211 }
212
213int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc)
214 {
215 return(X509v3_add_ext(&(x->tbsResponseData->responseExtensions),ex,loc) != NULL);
216 }
217
218/* OCSP single response extensions */
219
220int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
221 {
222 return(X509v3_get_ext_count(x->singleExtensions));
223 }
224
225int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos)
226 {
227 return(X509v3_get_ext_by_NID(x->singleExtensions,nid,lastpos));
228 }
229
230int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos)
231 {
232 return(X509v3_get_ext_by_OBJ(x->singleExtensions,obj,lastpos));
233 }
234
235int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos)
236 {
237 return(X509v3_get_ext_by_critical(x->singleExtensions,crit,lastpos));
238 }
239
240X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc)
241 {
242 return(X509v3_get_ext(x->singleExtensions,loc));
243 }
244
245X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc)
246 {
247 return(X509v3_delete_ext(x->singleExtensions,loc));
248 }
249
250void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx)
251 {
252 return X509V3_get_d2i(x->singleExtensions, nid, crit, idx);
253 }
254
255int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
256 unsigned long flags)
257 {
258 return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags);
259 }
260
261int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
262 {
263 return(X509v3_add_ext(&(x->singleExtensions),ex,loc) != NULL);
264 }
265
266/* also CRL Entry Extensions */
267
268ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
269 char *data, STACK_OF(ASN1_OBJECT) *sk)
270 {
271 int i;
272 unsigned char *p, *b = NULL;
273
274 if (data)
275 {
276 if ((i=i2d(data,NULL)) <= 0) goto err;
277 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
278 goto err;
279 if (i2d(data, &p) <= 0) goto err;
280 }
281 else if (sk)
282 {
283 if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL,i2d,V_ASN1_SEQUENCE,
284 V_ASN1_UNIVERSAL,IS_SEQUENCE))<=0) goto err;
285 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
286 goto err;
287 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,i2d,V_ASN1_SEQUENCE,
288 V_ASN1_UNIVERSAL,IS_SEQUENCE)<=0) goto err;
289 }
290 else
291 {
292 OCSPerr(OCSP_F_ASN1_STRING_ENCODE,OCSP_R_BAD_DATA);
293 goto err;
294 }
295 if (!s && !(s = ASN1_STRING_new())) goto err;
296 if (!(ASN1_STRING_set(s, b, i))) goto err;
297 OPENSSL_free(b);
298 return s;
299err:
300 if (b) OPENSSL_free(b);
301 return NULL;
302 }
303
304/* Nonce handling functions */
305
306/* Add a nonce to an extension stack. A nonce can be specificed or if NULL
307 * a random nonce will be generated.
308 * Note: OpenSSL 0.9.7d and later create an OCTET STRING containing the
309 * nonce, previous versions used the raw nonce.
310 */
311
312static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len)
313 {
314 unsigned char *tmpval;
315 ASN1_OCTET_STRING os;
316 int ret = 0;
317 if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH;
318 /* Create the OCTET STRING manually by writing out the header and
319 * appending the content octets. This avoids an extra memory allocation
320 * operation in some cases. Applications should *NOT* do this because
321 * it relies on library internals.
322 */
323 os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
324 os.data = OPENSSL_malloc(os.length);
325 if (os.data == NULL)
326 goto err;
327 tmpval = os.data;
328 ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);
329 if (val)
330 memcpy(tmpval, val, len);
331 else
332 RAND_pseudo_bytes(tmpval, len);
333 if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,
334 &os, 0, X509V3_ADD_REPLACE))
335 goto err;
336 ret = 1;
337 err:
338 if (os.data)
339 OPENSSL_free(os.data);
340 return ret;
341 }
342
343
344/* Add nonce to an OCSP request */
345
346int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
347 {
348 return ocsp_add1_nonce(&req->tbsRequest->requestExtensions, val, len);
349 }
350
351/* Same as above but for a response */
352
353int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
354 {
355 return ocsp_add1_nonce(&resp->tbsResponseData->responseExtensions, val, len);
356 }
357
358/* Check nonce validity in a request and response.
359 * Return value reflects result:
360 * 1: nonces present and equal.
361 * 2: nonces both absent.
362 * 3: nonce present in response only.
363 * 0: nonces both present and not equal.
364 * -1: nonce in request only.
365 *
366 * For most responders clients can check return > 0.
367 * If responder doesn't handle nonces return != 0 may be
368 * necessary. return == 0 is always an error.
369 */
370
371int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
372 {
373 /*
374 * Since we are only interested in the presence or absence of
375 * the nonce and comparing its value there is no need to use
376 * the X509V3 routines: this way we can avoid them allocating an
377 * ASN1_OCTET_STRING structure for the value which would be
378 * freed immediately anyway.
379 */
380
381 int req_idx, resp_idx;
382 X509_EXTENSION *req_ext, *resp_ext;
383 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
384 resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
385 /* Check both absent */
386 if((req_idx < 0) && (resp_idx < 0))
387 return 2;
388 /* Check in request only */
389 if((req_idx >= 0) && (resp_idx < 0))
390 return -1;
391 /* Check in response but not request */
392 if((req_idx < 0) && (resp_idx >= 0))
393 return 3;
394 /* Otherwise nonce in request and response so retrieve the extensions */
395 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
396 resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
397 if(ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value))
398 return 0;
399 return 1;
400 }
401
402/* Copy the nonce value (if any) from an OCSP request to
403 * a response.
404 */
405
406int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req)
407 {
408 X509_EXTENSION *req_ext;
409 int req_idx;
410 /* Check for nonce in request */
411 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
412 /* If no nonce that's OK */
413 if (req_idx < 0) return 2;
414 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
415 return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
416 }
417
418X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
419 {
420 X509_EXTENSION *x = NULL;
421 OCSP_CRLID *cid = NULL;
422
423 if (!(cid = OCSP_CRLID_new())) goto err;
424 if (url)
425 {
426 if (!(cid->crlUrl = ASN1_IA5STRING_new())) goto err;
427 if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err;
428 }
429 if (n)
430 {
431 if (!(cid->crlNum = ASN1_INTEGER_new())) goto err;
432 if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err;
433 }
434 if (tim)
435 {
436 if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) goto err;
437 if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim)))
438 goto err;
439 }
440 if (!(x = X509_EXTENSION_new())) goto err;
441 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err;
442 if (!(ASN1_STRING_encode(x->value,i2d_OCSP_CRLID,(char*)cid,NULL)))
443 goto err;
444 OCSP_CRLID_free(cid);
445 return x;
446err:
447 if (x) X509_EXTENSION_free(x);
448 if (cid) OCSP_CRLID_free(cid);
449 return NULL;
450 }
451
452/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
453X509_EXTENSION *OCSP_accept_responses_new(char **oids)
454 {
455 int nid;
456 STACK_OF(ASN1_OBJECT) *sk = NULL;
457 ASN1_OBJECT *o = NULL;
458 X509_EXTENSION *x = NULL;
459
460 if (!(sk = sk_ASN1_OBJECT_new_null())) goto err;
461 while (oids && *oids)
462 {
463 if ((nid=OBJ_txt2nid(*oids))!=NID_undef&&(o=OBJ_nid2obj(nid)))
464 sk_ASN1_OBJECT_push(sk, o);
465 oids++;
466 }
467 if (!(x = X509_EXTENSION_new())) goto err;
468 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses)))
469 goto err;
470 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_OBJECT,NULL,sk)))
471 goto err;
472 sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
473 return x;
474err:
475 if (x) X509_EXTENSION_free(x);
476 if (sk) sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
477 return NULL;
478 }
479
480/* ArchiveCutoff ::= GeneralizedTime */
481X509_EXTENSION *OCSP_archive_cutoff_new(char* tim)
482 {
483 X509_EXTENSION *x=NULL;
484 ASN1_GENERALIZEDTIME *gt = NULL;
485
486 if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err;
487 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err;
488 if (!(x = X509_EXTENSION_new())) goto err;
489 if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err;
490 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_GENERALIZEDTIME,
491 (char*)gt,NULL))) goto err;
492 ASN1_GENERALIZEDTIME_free(gt);
493 return x;
494err:
495 if (gt) ASN1_GENERALIZEDTIME_free(gt);
496 if (x) X509_EXTENSION_free(x);
497 return NULL;
498 }
499
500/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
501 * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This
502 * method forces NID_ad_ocsp and uniformResourceLocator [6] IA5String.
503 */
504X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
505 {
506 X509_EXTENSION *x = NULL;
507 ASN1_IA5STRING *ia5 = NULL;
508 OCSP_SERVICELOC *sloc = NULL;
509 ACCESS_DESCRIPTION *ad = NULL;
510
511 if (!(sloc = OCSP_SERVICELOC_new())) goto err;
512 if (!(sloc->issuer = X509_NAME_dup(issuer))) goto err;
513 if (urls && *urls && !(sloc->locator = sk_ACCESS_DESCRIPTION_new_null())) goto err;
514 while (urls && *urls)
515 {
516 if (!(ad = ACCESS_DESCRIPTION_new())) goto err;
517 if (!(ad->method=OBJ_nid2obj(NID_ad_OCSP))) goto err;
518 if (!(ad->location = GENERAL_NAME_new())) goto err;
519 if (!(ia5 = ASN1_IA5STRING_new())) goto err;
520 if (!ASN1_STRING_set((ASN1_STRING*)ia5, *urls, -1)) goto err;
521 ad->location->type = GEN_URI;
522 ad->location->d.ia5 = ia5;
523 if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) goto err;
524 urls++;
525 }
526 if (!(x = X509_EXTENSION_new())) goto err;
527 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator)))
528 goto err;
529 if (!(ASN1_STRING_encode(x->value, i2d_OCSP_SERVICELOC,
530 (char*)sloc, NULL))) goto err;
531 OCSP_SERVICELOC_free(sloc);
532 return x;
533err:
534 if (x) X509_EXTENSION_free(x);
535 if (sloc) OCSP_SERVICELOC_free(sloc);
536 return NULL;
537 }
538
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c
new file mode 100644
index 0000000000..9213e58ae4
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_ht.c
@@ -0,0 +1,173 @@
1/* ocsp_ht.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/asn1.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <ctype.h>
63#include <string.h>
64#include <openssl/ocsp.h>
65#include <openssl/err.h>
66#include <openssl/buffer.h>
67#ifdef OPENSSL_SYS_SUNOS
68#define strtoul (unsigned long)strtol
69#endif /* OPENSSL_SYS_SUNOS */
70
71/* Quick and dirty HTTP OCSP request handler.
72 * Could make this a bit cleverer by adding
73 * support for non blocking BIOs and a few
74 * other refinements.
75 */
76
77OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req)
78{
79 BIO *mem = NULL;
80 char tmpbuf[1024];
81 OCSP_RESPONSE *resp = NULL;
82 char *p, *q, *r;
83 int len, retcode;
84 static char req_txt[] =
85"POST %s HTTP/1.0\r\n\
86Content-Type: application/ocsp-request\r\n\
87Content-Length: %d\r\n\r\n";
88
89 len = i2d_OCSP_REQUEST(req, NULL);
90 if(BIO_printf(b, req_txt, path, len) < 0) {
91 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
92 goto err;
93 }
94 if(i2d_OCSP_REQUEST_bio(b, req) <= 0) {
95 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
96 goto err;
97 }
98 if(!(mem = BIO_new(BIO_s_mem()))) goto err;
99 /* Copy response to a memory BIO: socket bios can't do gets! */
100 while ((len = BIO_read(b, tmpbuf, sizeof tmpbuf))) {
101 if(len < 0) {
102 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR);
103 goto err;
104 }
105 BIO_write(mem, tmpbuf, len);
106 }
107 if(BIO_gets(mem, tmpbuf, 512) <= 0) {
108 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
109 goto err;
110 }
111 /* Parse the HTTP response. This will look like this:
112 * "HTTP/1.0 200 OK". We need to obtain the numeric code and
113 * (optional) informational message.
114 */
115
116 /* Skip to first white space (passed protocol info) */
117 for(p = tmpbuf; *p && !isspace((unsigned char)*p); p++) continue;
118 if(!*p) {
119 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
120 goto err;
121 }
122 /* Skip past white space to start of response code */
123 while(*p && isspace((unsigned char)*p)) p++;
124 if(!*p) {
125 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
126 goto err;
127 }
128 /* Find end of response code: first whitespace after start of code */
129 for(q = p; *q && !isspace((unsigned char)*q); q++) continue;
130 if(!*q) {
131 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
132 goto err;
133 }
134 /* Set end of response code and start of message */
135 *q++ = 0;
136 /* Attempt to parse numeric code */
137 retcode = strtoul(p, &r, 10);
138 if(*r) goto err;
139 /* Skip over any leading white space in message */
140 while(*q && isspace((unsigned char)*q)) q++;
141 if(*q) {
142 /* Finally zap any trailing white space in message (include CRLF) */
143 /* We know q has a non white space character so this is OK */
144 for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0;
145 }
146 if(retcode != 200) {
147 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR);
148 if(!*q) {
149 ERR_add_error_data(2, "Code=", p);
150 }
151 else {
152 ERR_add_error_data(4, "Code=", p, ",Reason=", q);
153 }
154 goto err;
155 }
156 /* Find blank line marking beginning of content */
157 while(BIO_gets(mem, tmpbuf, 512) > 0)
158 {
159 for(p = tmpbuf; *p && isspace((unsigned char)*p); p++) continue;
160 if(!*p) break;
161 }
162 if(*p) {
163 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_NO_CONTENT);
164 goto err;
165 }
166 if(!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) {
167 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,ERR_R_NESTED_ASN1_ERROR);
168 goto err;
169 }
170 err:
171 BIO_free(mem);
172 return resp;
173}
diff --git a/src/lib/libcrypto/ocsp/ocsp_lib.c b/src/lib/libcrypto/ocsp/ocsp_lib.c
new file mode 100644
index 0000000000..9e87fc7895
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_lib.c
@@ -0,0 +1,262 @@
1/* ocsp_lib.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <cryptlib.h>
66#include <openssl/objects.h>
67#include <openssl/rand.h>
68#include <openssl/x509.h>
69#include <openssl/pem.h>
70#include <openssl/x509v3.h>
71#include <openssl/ocsp.h>
72
73/* Convert a certificate and its issuer to an OCSP_CERTID */
74
75OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer)
76{
77 X509_NAME *iname;
78 ASN1_INTEGER *serial;
79 ASN1_BIT_STRING *ikey;
80#ifndef OPENSSL_NO_SHA1
81 if(!dgst) dgst = EVP_sha1();
82#endif
83 if (subject)
84 {
85 iname = X509_get_issuer_name(subject);
86 serial = X509_get_serialNumber(subject);
87 }
88 else
89 {
90 iname = X509_get_subject_name(issuer);
91 serial = NULL;
92 }
93 ikey = X509_get0_pubkey_bitstr(issuer);
94 return OCSP_cert_id_new(dgst, iname, ikey, serial);
95}
96
97
98OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
99 X509_NAME *issuerName,
100 ASN1_BIT_STRING* issuerKey,
101 ASN1_INTEGER *serialNumber)
102 {
103 int nid;
104 unsigned int i;
105 X509_ALGOR *alg;
106 OCSP_CERTID *cid = NULL;
107 unsigned char md[EVP_MAX_MD_SIZE];
108
109 if (!(cid = OCSP_CERTID_new())) goto err;
110
111 alg = cid->hashAlgorithm;
112 if (alg->algorithm != NULL) ASN1_OBJECT_free(alg->algorithm);
113 if ((nid = EVP_MD_type(dgst)) == NID_undef)
114 {
115 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_UNKNOWN_NID);
116 goto err;
117 }
118 if (!(alg->algorithm=OBJ_nid2obj(nid))) goto err;
119 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
120 alg->parameter->type=V_ASN1_NULL;
121
122 if (!X509_NAME_digest(issuerName, dgst, md, &i)) goto digerr;
123 if (!(ASN1_OCTET_STRING_set(cid->issuerNameHash, md, i))) goto err;
124
125 /* Calculate the issuerKey hash, excluding tag and length */
126 EVP_Digest(issuerKey->data, issuerKey->length, md, &i, dgst, NULL);
127
128 if (!(ASN1_OCTET_STRING_set(cid->issuerKeyHash, md, i))) goto err;
129
130 if (serialNumber)
131 {
132 ASN1_INTEGER_free(cid->serialNumber);
133 if (!(cid->serialNumber = ASN1_INTEGER_dup(serialNumber))) goto err;
134 }
135 return cid;
136digerr:
137 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_DIGEST_ERR);
138err:
139 if (cid) OCSP_CERTID_free(cid);
140 return NULL;
141 }
142
143int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b)
144 {
145 int ret;
146 ret = OBJ_cmp(a->hashAlgorithm->algorithm, b->hashAlgorithm->algorithm);
147 if (ret) return ret;
148 ret = ASN1_OCTET_STRING_cmp(a->issuerNameHash, b->issuerNameHash);
149 if (ret) return ret;
150 return ASN1_OCTET_STRING_cmp(a->issuerKeyHash, b->issuerKeyHash);
151 }
152
153int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b)
154 {
155 int ret;
156 ret = OCSP_id_issuer_cmp(a, b);
157 if (ret) return ret;
158 return ASN1_INTEGER_cmp(a->serialNumber, b->serialNumber);
159 }
160
161
162/* Parse a URL and split it up into host, port and path components and whether
163 * it is SSL.
164 */
165
166int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl)
167 {
168 char *p, *buf;
169
170 char *host, *port;
171
172 /* dup the buffer since we are going to mess with it */
173 buf = BUF_strdup(url);
174 if (!buf) goto mem_err;
175
176 *phost = NULL;
177 *pport = NULL;
178 *ppath = NULL;
179
180 /* Check for initial colon */
181 p = strchr(buf, ':');
182
183 if (!p) goto parse_err;
184
185 *(p++) = '\0';
186
187 if (!strcmp(buf, "http"))
188 {
189 *pssl = 0;
190 port = "80";
191 }
192 else if (!strcmp(buf, "https"))
193 {
194 *pssl = 1;
195 port = "443";
196 }
197 else
198 goto parse_err;
199
200 /* Check for double slash */
201 if ((p[0] != '/') || (p[1] != '/'))
202 goto parse_err;
203
204 p += 2;
205
206 host = p;
207
208 /* Check for trailing part of path */
209
210 p = strchr(p, '/');
211
212 if (!p)
213 *ppath = BUF_strdup("/");
214 else
215 {
216 *ppath = BUF_strdup(p);
217 /* Set start of path to 0 so hostname is valid */
218 *p = '\0';
219 }
220
221 if (!*ppath) goto mem_err;
222
223 /* Look for optional ':' for port number */
224 if ((p = strchr(host, ':')))
225 {
226 *p = 0;
227 port = p + 1;
228 }
229 else
230 {
231 /* Not found: set default port */
232 if (*pssl) port = "443";
233 else port = "80";
234 }
235
236 *pport = BUF_strdup(port);
237 if (!*pport) goto mem_err;
238
239 *phost = BUF_strdup(host);
240
241 if (!*phost) goto mem_err;
242
243 OPENSSL_free(buf);
244
245 return 1;
246
247 mem_err:
248 OCSPerr(OCSP_F_OCSP_PARSE_URL, ERR_R_MALLOC_FAILURE);
249 goto err;
250
251 parse_err:
252 OCSPerr(OCSP_F_OCSP_PARSE_URL, OCSP_R_ERROR_PARSING_URL);
253
254
255 err:
256 if (buf) OPENSSL_free(buf);
257 if (*ppath) OPENSSL_free(*ppath);
258 if (*pport) OPENSSL_free(*pport);
259 if (*phost) OPENSSL_free(*phost);
260 return 0;
261
262 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_prn.c b/src/lib/libcrypto/ocsp/ocsp_prn.c
new file mode 100644
index 0000000000..4b7bc28769
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_prn.c
@@ -0,0 +1,291 @@
1/* ocsp_prn.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was originally part of ocsp.c and was transfered to Richard
7 Levitte from CertCo by Kathy Weinhold in mid-spring 2000 to be included
8 in OpenSSL or released as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <openssl/bio.h>
65#include <openssl/err.h>
66#include <openssl/ocsp.h>
67#include <openssl/pem.h>
68
69static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent)
70 {
71 BIO_printf(bp, "%*sCertificate ID:\n", indent, "");
72 indent += 2;
73 BIO_printf(bp, "%*sHash Algorithm: ", indent, "");
74 i2a_ASN1_OBJECT(bp, a->hashAlgorithm->algorithm);
75 BIO_printf(bp, "\n%*sIssuer Name Hash: ", indent, "");
76 i2a_ASN1_STRING(bp, a->issuerNameHash, V_ASN1_OCTET_STRING);
77 BIO_printf(bp, "\n%*sIssuer Key Hash: ", indent, "");
78 i2a_ASN1_STRING(bp, a->issuerKeyHash, V_ASN1_OCTET_STRING);
79 BIO_printf(bp, "\n%*sSerial Number: ", indent, "");
80 i2a_ASN1_INTEGER(bp, a->serialNumber);
81 BIO_printf(bp, "\n");
82 return 1;
83 }
84
85typedef struct
86 {
87 long t;
88 char *m;
89 } OCSP_TBLSTR;
90
91static char *table2string(long s, OCSP_TBLSTR *ts, int len)
92{
93 OCSP_TBLSTR *p;
94 for (p=ts; p < ts + len; p++)
95 if (p->t == s)
96 return p->m;
97 return "(UNKNOWN)";
98}
99
100char *OCSP_response_status_str(long s)
101 {
102 static OCSP_TBLSTR rstat_tbl[] = {
103 { OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful" },
104 { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" },
105 { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" },
106 { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" },
107 { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" },
108 { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } };
109 return table2string(s, rstat_tbl, 6);
110 }
111
112char *OCSP_cert_status_str(long s)
113 {
114 static OCSP_TBLSTR cstat_tbl[] = {
115 { V_OCSP_CERTSTATUS_GOOD, "good" },
116 { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
117 { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } };
118 return table2string(s, cstat_tbl, 3);
119 }
120
121char *OCSP_crl_reason_str(long s)
122 {
123 OCSP_TBLSTR reason_tbl[] = {
124 { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" },
125 { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
126 { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
127 { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" },
128 { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" },
129 { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" },
130 { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" },
131 { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } };
132 return table2string(s, reason_tbl, 8);
133 }
134
135int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
136 {
137 int i;
138 long l;
139 OCSP_CERTID* cid = NULL;
140 OCSP_ONEREQ *one = NULL;
141 OCSP_REQINFO *inf = o->tbsRequest;
142 OCSP_SIGNATURE *sig = o->optionalSignature;
143
144 if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err;
145 l=ASN1_INTEGER_get(inf->version);
146 if (BIO_printf(bp," Version: %lu (0x%lx)",l+1,l) <= 0) goto err;
147 if (inf->requestorName != NULL)
148 {
149 if (BIO_write(bp,"\n Requestor Name: ",21) <= 0)
150 goto err;
151 GENERAL_NAME_print(bp, inf->requestorName);
152 }
153 if (BIO_write(bp,"\n Requestor List:\n",21) <= 0) goto err;
154 for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
155 {
156 one = sk_OCSP_ONEREQ_value(inf->requestList, i);
157 cid = one->reqCert;
158 ocsp_certid_print(bp, cid, 8);
159 if (!X509V3_extensions_print(bp,
160 "Request Single Extensions",
161 one->singleRequestExtensions, flags, 8))
162 goto err;
163 }
164 if (!X509V3_extensions_print(bp, "Request Extensions",
165 inf->requestExtensions, flags, 4))
166 goto err;
167 if (sig)
168 {
169 X509_signature_print(bp, sig->signatureAlgorithm, sig->signature);
170 for (i=0; i<sk_X509_num(sig->certs); i++)
171 {
172 X509_print(bp, sk_X509_value(sig->certs,i));
173 PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i));
174 }
175 }
176 return 1;
177err:
178 return 0;
179 }
180
181int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
182 {
183 int i, ret = 0;
184 long l;
185 unsigned char *p;
186 OCSP_CERTID *cid = NULL;
187 OCSP_BASICRESP *br = NULL;
188 OCSP_RESPID *rid = NULL;
189 OCSP_RESPDATA *rd = NULL;
190 OCSP_CERTSTATUS *cst = NULL;
191 OCSP_REVOKEDINFO *rev = NULL;
192 OCSP_SINGLERESP *single = NULL;
193 OCSP_RESPBYTES *rb = o->responseBytes;
194
195 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err;
196 l=ASN1_ENUMERATED_get(o->responseStatus);
197 if (BIO_printf(bp," OCSP Response Status: %s (0x%x)\n",
198 OCSP_response_status_str(l), l) <= 0) goto err;
199 if (rb == NULL) return 1;
200 if (BIO_puts(bp," Response Type: ") <= 0)
201 goto err;
202 if(i2a_ASN1_OBJECT(bp, rb->responseType) <= 0)
203 goto err;
204 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
205 {
206 BIO_puts(bp," (unknown response type)\n");
207 return 1;
208 }
209
210 p = ASN1_STRING_data(rb->response);
211 i = ASN1_STRING_length(rb->response);
212 if (!(br = OCSP_response_get1_basic(o))) goto err;
213 rd = br->tbsResponseData;
214 l=ASN1_INTEGER_get(rd->version);
215 if (BIO_printf(bp,"\n Version: %lu (0x%lx)\n",
216 l+1,l) <= 0) goto err;
217 if (BIO_puts(bp," Responder Id: ") <= 0) goto err;
218
219 rid = rd->responderId;
220 switch (rid->type)
221 {
222 case V_OCSP_RESPID_NAME:
223 X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE);
224 break;
225 case V_OCSP_RESPID_KEY:
226 i2a_ASN1_STRING(bp, rid->value.byKey, V_ASN1_OCTET_STRING);
227 break;
228 }
229
230 if (BIO_printf(bp,"\n Produced At: ")<=0) goto err;
231 if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err;
232 if (BIO_printf(bp,"\n Responses:\n") <= 0) goto err;
233 for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++)
234 {
235 if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue;
236 single = sk_OCSP_SINGLERESP_value(rd->responses, i);
237 cid = single->certId;
238 if(ocsp_certid_print(bp, cid, 4) <= 0) goto err;
239 cst = single->certStatus;
240 if (BIO_printf(bp," Cert Status: %s",
241 OCSP_cert_status_str(cst->type)) <= 0)
242 goto err;
243 if (cst->type == V_OCSP_CERTSTATUS_REVOKED)
244 {
245 rev = cst->value.revoked;
246 if (BIO_printf(bp, "\n Revocation Time: ") <= 0)
247 goto err;
248 if (!ASN1_GENERALIZEDTIME_print(bp,
249 rev->revocationTime))
250 goto err;
251 if (rev->revocationReason)
252 {
253 l=ASN1_ENUMERATED_get(rev->revocationReason);
254 if (BIO_printf(bp,
255 "\n Revocation Reason: %s (0x%x)",
256 OCSP_crl_reason_str(l), l) <= 0)
257 goto err;
258 }
259 }
260 if (BIO_printf(bp,"\n This Update: ") <= 0) goto err;
261 if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate))
262 goto err;
263 if (single->nextUpdate)
264 {
265 if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err;
266 if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate))
267 goto err;
268 }
269 if (!BIO_write(bp,"\n",1)) goto err;
270 if (!X509V3_extensions_print(bp,
271 "Response Single Extensions",
272 single->singleExtensions, flags, 8))
273 goto err;
274 if (!BIO_write(bp,"\n",1)) goto err;
275 }
276 if (!X509V3_extensions_print(bp, "Response Extensions",
277 rd->responseExtensions, flags, 4))
278 if(X509_signature_print(bp, br->signatureAlgorithm, br->signature) <= 0)
279 goto err;
280
281 for (i=0; i<sk_X509_num(br->certs); i++)
282 {
283 X509_print(bp, sk_X509_value(br->certs,i));
284 PEM_write_bio_X509(bp,sk_X509_value(br->certs,i));
285 }
286
287 ret = 1;
288err:
289 OCSP_BASICRESP_free(br);
290 return ret;
291 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_srv.c b/src/lib/libcrypto/ocsp/ocsp_srv.c
new file mode 100644
index 0000000000..fffa134e75
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_srv.c
@@ -0,0 +1,264 @@
1/* ocsp_srv.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <cryptlib.h>
61#include <openssl/objects.h>
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64#include <openssl/pem.h>
65#include <openssl/x509v3.h>
66#include <openssl/ocsp.h>
67
68/* Utility functions related to sending OCSP responses and extracting
69 * relevant information from the request.
70 */
71
72int OCSP_request_onereq_count(OCSP_REQUEST *req)
73 {
74 return sk_OCSP_ONEREQ_num(req->tbsRequest->requestList);
75 }
76
77OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i)
78 {
79 return sk_OCSP_ONEREQ_value(req->tbsRequest->requestList, i);
80 }
81
82OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one)
83 {
84 return one->reqCert;
85 }
86
87int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
88 ASN1_OCTET_STRING **pikeyHash,
89 ASN1_INTEGER **pserial, OCSP_CERTID *cid)
90 {
91 if (!cid) return 0;
92 if (pmd) *pmd = cid->hashAlgorithm->algorithm;
93 if(piNameHash) *piNameHash = cid->issuerNameHash;
94 if (pikeyHash) *pikeyHash = cid->issuerKeyHash;
95 if (pserial) *pserial = cid->serialNumber;
96 return 1;
97 }
98
99int OCSP_request_is_signed(OCSP_REQUEST *req)
100 {
101 if(req->optionalSignature) return 1;
102 return 0;
103 }
104
105/* Create an OCSP response and encode an optional basic response */
106OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs)
107 {
108 OCSP_RESPONSE *rsp = NULL;
109
110 if (!(rsp = OCSP_RESPONSE_new())) goto err;
111 if (!(ASN1_ENUMERATED_set(rsp->responseStatus, status))) goto err;
112 if (!bs) return rsp;
113 if (!(rsp->responseBytes = OCSP_RESPBYTES_new())) goto err;
114 rsp->responseBytes->responseType = OBJ_nid2obj(NID_id_pkix_OCSP_basic);
115 if (!ASN1_item_pack(bs, ASN1_ITEM_rptr(OCSP_BASICRESP), &rsp->responseBytes->response))
116 goto err;
117 return rsp;
118err:
119 if (rsp) OCSP_RESPONSE_free(rsp);
120 return NULL;
121 }
122
123
124OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
125 OCSP_CERTID *cid,
126 int status, int reason,
127 ASN1_TIME *revtime,
128 ASN1_TIME *thisupd, ASN1_TIME *nextupd)
129 {
130 OCSP_SINGLERESP *single = NULL;
131 OCSP_CERTSTATUS *cs;
132 OCSP_REVOKEDINFO *ri;
133
134 if(!rsp->tbsResponseData->responses &&
135 !(rsp->tbsResponseData->responses = sk_OCSP_SINGLERESP_new_null()))
136 goto err;
137
138 if (!(single = OCSP_SINGLERESP_new()))
139 goto err;
140
141
142
143 if (!ASN1_TIME_to_generalizedtime(thisupd, &single->thisUpdate))
144 goto err;
145 if (nextupd &&
146 !ASN1_TIME_to_generalizedtime(nextupd, &single->nextUpdate))
147 goto err;
148
149 OCSP_CERTID_free(single->certId);
150
151 if(!(single->certId = OCSP_CERTID_dup(cid)))
152 goto err;
153
154 cs = single->certStatus;
155 switch(cs->type = status)
156 {
157 case V_OCSP_CERTSTATUS_REVOKED:
158 if (!revtime)
159 {
160 OCSPerr(OCSP_F_OCSP_BASIC_ADD1_STATUS,OCSP_R_NO_REVOKED_TIME);
161 goto err;
162 }
163 if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) goto err;
164 if (!ASN1_TIME_to_generalizedtime(revtime, &ri->revocationTime))
165 goto err;
166 if (reason != OCSP_REVOKED_STATUS_NOSTATUS)
167 {
168 if (!(ri->revocationReason = ASN1_ENUMERATED_new()))
169 goto err;
170 if (!(ASN1_ENUMERATED_set(ri->revocationReason,
171 reason)))
172 goto err;
173 }
174 break;
175
176 case V_OCSP_CERTSTATUS_GOOD:
177 cs->value.good = ASN1_NULL_new();
178 break;
179
180 case V_OCSP_CERTSTATUS_UNKNOWN:
181 cs->value.unknown = ASN1_NULL_new();
182 break;
183
184 default:
185 goto err;
186
187 }
188 if (!(sk_OCSP_SINGLERESP_push(rsp->tbsResponseData->responses, single)))
189 goto err;
190 return single;
191err:
192 OCSP_SINGLERESP_free(single);
193 return NULL;
194 }
195
196/* Add a certificate to an OCSP request */
197
198int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert)
199 {
200 if (!resp->certs && !(resp->certs = sk_X509_new_null()))
201 return 0;
202
203 if(!sk_X509_push(resp->certs, cert)) return 0;
204 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
205 return 1;
206 }
207
208int OCSP_basic_sign(OCSP_BASICRESP *brsp,
209 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
210 STACK_OF(X509) *certs, unsigned long flags)
211 {
212 int i;
213 OCSP_RESPID *rid;
214
215 if (!X509_check_private_key(signer, key))
216 {
217 OCSPerr(OCSP_F_OCSP_BASIC_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
218 goto err;
219 }
220
221 if(!(flags & OCSP_NOCERTS))
222 {
223 if(!OCSP_basic_add1_cert(brsp, signer))
224 goto err;
225 for (i = 0; i < sk_X509_num(certs); i++)
226 {
227 X509 *tmpcert = sk_X509_value(certs, i);
228 if(!OCSP_basic_add1_cert(brsp, tmpcert))
229 goto err;
230 }
231 }
232
233 rid = brsp->tbsResponseData->responderId;
234 if (flags & OCSP_RESPID_KEY)
235 {
236 unsigned char md[SHA_DIGEST_LENGTH];
237 X509_pubkey_digest(signer, EVP_sha1(), md, NULL);
238 if (!(rid->value.byKey = ASN1_OCTET_STRING_new()))
239 goto err;
240 if (!(ASN1_OCTET_STRING_set(rid->value.byKey, md, SHA_DIGEST_LENGTH)))
241 goto err;
242 rid->type = V_OCSP_RESPID_KEY;
243 }
244 else
245 {
246 if (!X509_NAME_set(&rid->value.byName,
247 X509_get_subject_name(signer)))
248 goto err;
249 rid->type = V_OCSP_RESPID_NAME;
250 }
251
252 if (!(flags & OCSP_NOTIME) &&
253 !X509_gmtime_adj(brsp->tbsResponseData->producedAt, 0))
254 goto err;
255
256 /* Right now, I think that not doing double hashing is the right
257 thing. -- Richard Levitte */
258
259 if (!OCSP_BASICRESP_sign(brsp, key, dgst, 0)) goto err;
260
261 return 1;
262err:
263 return 0;
264 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_vfy.c b/src/lib/libcrypto/ocsp/ocsp_vfy.c
new file mode 100644
index 0000000000..3d58dfb06c
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/ocsp_vfy.c
@@ -0,0 +1,444 @@
1/* ocsp_vfy.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/ocsp.h>
60#include <openssl/err.h>
61#include <string.h>
62
63static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
64 X509_STORE *st, unsigned long flags);
65static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id);
66static int ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain, unsigned long flags);
67static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret);
68static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid, STACK_OF(OCSP_SINGLERESP) *sresp);
69static int ocsp_check_delegated(X509 *x, int flags);
70static int ocsp_req_find_signer(X509 **psigner, OCSP_REQUEST *req, X509_NAME *nm, STACK_OF(X509) *certs,
71 X509_STORE *st, unsigned long flags);
72
73/* Verify a basic response message */
74
75int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
76 X509_STORE *st, unsigned long flags)
77 {
78 X509 *signer, *x;
79 STACK_OF(X509) *chain = NULL;
80 X509_STORE_CTX ctx;
81 int i, ret = 0;
82 ret = ocsp_find_signer(&signer, bs, certs, st, flags);
83 if (!ret)
84 {
85 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
86 goto end;
87 }
88 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
89 flags |= OCSP_NOVERIFY;
90 if (!(flags & OCSP_NOSIGS))
91 {
92 EVP_PKEY *skey;
93 skey = X509_get_pubkey(signer);
94 ret = OCSP_BASICRESP_verify(bs, skey, 0);
95 EVP_PKEY_free(skey);
96 if(ret <= 0)
97 {
98 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNATURE_FAILURE);
99 goto end;
100 }
101 }
102 if (!(flags & OCSP_NOVERIFY))
103 {
104 int init_res;
105 if(flags & OCSP_NOCHAIN)
106 init_res = X509_STORE_CTX_init(&ctx, st, signer, NULL);
107 else
108 init_res = X509_STORE_CTX_init(&ctx, st, signer, bs->certs);
109 if(!init_res)
110 {
111 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,ERR_R_X509_LIB);
112 goto end;
113 }
114
115 X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
116 ret = X509_verify_cert(&ctx);
117 chain = X509_STORE_CTX_get1_chain(&ctx);
118 X509_STORE_CTX_cleanup(&ctx);
119 if (ret <= 0)
120 {
121 i = X509_STORE_CTX_get_error(&ctx);
122 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
123 ERR_add_error_data(2, "Verify error:",
124 X509_verify_cert_error_string(i));
125 goto end;
126 }
127 if(flags & OCSP_NOCHECKS)
128 {
129 ret = 1;
130 goto end;
131 }
132 /* At this point we have a valid certificate chain
133 * need to verify it against the OCSP issuer criteria.
134 */
135 ret = ocsp_check_issuer(bs, chain, flags);
136
137 /* If fatal error or valid match then finish */
138 if (ret != 0) goto end;
139
140 /* Easy case: explicitly trusted. Get root CA and
141 * check for explicit trust
142 */
143 if(flags & OCSP_NOEXPLICIT) goto end;
144
145 x = sk_X509_value(chain, sk_X509_num(chain) - 1);
146 if(X509_check_trust(x, NID_OCSP_sign, 0) != X509_TRUST_TRUSTED)
147 {
148 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_ROOT_CA_NOT_TRUSTED);
149 goto end;
150 }
151 ret = 1;
152 }
153
154
155
156 end:
157 if(chain) sk_X509_pop_free(chain, X509_free);
158 return ret;
159 }
160
161
162static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
163 X509_STORE *st, unsigned long flags)
164 {
165 X509 *signer;
166 OCSP_RESPID *rid = bs->tbsResponseData->responderId;
167 if ((signer = ocsp_find_signer_sk(certs, rid)))
168 {
169 *psigner = signer;
170 return 2;
171 }
172 if(!(flags & OCSP_NOINTERN) &&
173 (signer = ocsp_find_signer_sk(bs->certs, rid)))
174 {
175 *psigner = signer;
176 return 1;
177 }
178 /* Maybe lookup from store if by subject name */
179
180 *psigner = NULL;
181 return 0;
182 }
183
184
185static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id)
186 {
187 int i;
188 unsigned char tmphash[SHA_DIGEST_LENGTH], *keyhash;
189 X509 *x;
190
191 /* Easy if lookup by name */
192 if (id->type == V_OCSP_RESPID_NAME)
193 return X509_find_by_subject(certs, id->value.byName);
194
195 /* Lookup by key hash */
196
197 /* If key hash isn't SHA1 length then forget it */
198 if (id->value.byKey->length != SHA_DIGEST_LENGTH) return NULL;
199 keyhash = id->value.byKey->data;
200 /* Calculate hash of each key and compare */
201 for (i = 0; i < sk_X509_num(certs); i++)
202 {
203 x = sk_X509_value(certs, i);
204 X509_pubkey_digest(x, EVP_sha1(), tmphash, NULL);
205 if(!memcmp(keyhash, tmphash, SHA_DIGEST_LENGTH))
206 return x;
207 }
208 return NULL;
209 }
210
211
212static int ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain, unsigned long flags)
213 {
214 STACK_OF(OCSP_SINGLERESP) *sresp;
215 X509 *signer, *sca;
216 OCSP_CERTID *caid = NULL;
217 int i;
218 sresp = bs->tbsResponseData->responses;
219
220 if (sk_X509_num(chain) <= 0)
221 {
222 OCSPerr(OCSP_F_OCSP_CHECK_ISSUER, OCSP_R_NO_CERTIFICATES_IN_CHAIN);
223 return -1;
224 }
225
226 /* See if the issuer IDs match. */
227 i = ocsp_check_ids(sresp, &caid);
228
229 /* If ID mismatch or other error then return */
230 if (i <= 0) return i;
231
232 signer = sk_X509_value(chain, 0);
233 /* Check to see if OCSP responder CA matches request CA */
234 if (sk_X509_num(chain) > 1)
235 {
236 sca = sk_X509_value(chain, 1);
237 i = ocsp_match_issuerid(sca, caid, sresp);
238 if (i < 0) return i;
239 if (i)
240 {
241 /* We have a match, if extensions OK then success */
242 if (ocsp_check_delegated(signer, flags)) return 1;
243 return 0;
244 }
245 }
246
247 /* Otherwise check if OCSP request signed directly by request CA */
248 return ocsp_match_issuerid(signer, caid, sresp);
249 }
250
251
252/* Check the issuer certificate IDs for equality. If there is a mismatch with the same
253 * algorithm then there's no point trying to match any certificates against the issuer.
254 * If the issuer IDs all match then we just need to check equality against one of them.
255 */
256
257static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret)
258 {
259 OCSP_CERTID *tmpid, *cid;
260 int i, idcount;
261
262 idcount = sk_OCSP_SINGLERESP_num(sresp);
263 if (idcount <= 0)
264 {
265 OCSPerr(OCSP_F_OCSP_CHECK_IDS, OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA);
266 return -1;
267 }
268
269 cid = sk_OCSP_SINGLERESP_value(sresp, 0)->certId;
270
271 *ret = NULL;
272
273 for (i = 1; i < idcount; i++)
274 {
275 tmpid = sk_OCSP_SINGLERESP_value(sresp, i)->certId;
276 /* Check to see if IDs match */
277 if (OCSP_id_issuer_cmp(cid, tmpid))
278 {
279 /* If algoritm mismatch let caller deal with it */
280 if (OBJ_cmp(tmpid->hashAlgorithm->algorithm,
281 cid->hashAlgorithm->algorithm))
282 return 2;
283 /* Else mismatch */
284 return 0;
285 }
286 }
287
288 /* All IDs match: only need to check one ID */
289 *ret = cid;
290 return 1;
291 }
292
293
294static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid,
295 STACK_OF(OCSP_SINGLERESP) *sresp)
296 {
297 /* If only one ID to match then do it */
298 if(cid)
299 {
300 const EVP_MD *dgst;
301 X509_NAME *iname;
302 int mdlen;
303 unsigned char md[EVP_MAX_MD_SIZE];
304 if (!(dgst = EVP_get_digestbyobj(cid->hashAlgorithm->algorithm)))
305 {
306 OCSPerr(OCSP_F_OCSP_MATCH_ISSUERID, OCSP_R_UNKNOWN_MESSAGE_DIGEST);
307 return -1;
308 }
309
310 mdlen = EVP_MD_size(dgst);
311 if ((cid->issuerNameHash->length != mdlen) ||
312 (cid->issuerKeyHash->length != mdlen))
313 return 0;
314 iname = X509_get_subject_name(cert);
315 if (!X509_NAME_digest(iname, dgst, md, NULL))
316 return -1;
317 if (memcmp(md, cid->issuerNameHash->data, mdlen))
318 return 0;
319 X509_pubkey_digest(cert, EVP_sha1(), md, NULL);
320 if (memcmp(md, cid->issuerKeyHash->data, mdlen))
321 return 0;
322
323 return 1;
324
325 }
326 else
327 {
328 /* We have to match the whole lot */
329 int i, ret;
330 OCSP_CERTID *tmpid;
331 for (i = 0; i < sk_OCSP_SINGLERESP_num(sresp); i++)
332 {
333 tmpid = sk_OCSP_SINGLERESP_value(sresp, i)->certId;
334 ret = ocsp_match_issuerid(cert, tmpid, NULL);
335 if (ret <= 0) return ret;
336 }
337 return 1;
338 }
339
340 }
341
342static int ocsp_check_delegated(X509 *x, int flags)
343 {
344 X509_check_purpose(x, -1, 0);
345 if ((x->ex_flags & EXFLAG_XKUSAGE) &&
346 (x->ex_xkusage & XKU_OCSP_SIGN))
347 return 1;
348 OCSPerr(OCSP_F_OCSP_CHECK_DELEGATED, OCSP_R_MISSING_OCSPSIGNING_USAGE);
349 return 0;
350 }
351
352/* Verify an OCSP request. This is fortunately much easier than OCSP
353 * response verify. Just find the signers certificate and verify it
354 * against a given trust value.
355 */
356
357int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags)
358 {
359 X509 *signer;
360 X509_NAME *nm;
361 GENERAL_NAME *gen;
362 int ret;
363 X509_STORE_CTX ctx;
364 if (!req->optionalSignature)
365 {
366 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_REQUEST_NOT_SIGNED);
367 return 0;
368 }
369 gen = req->tbsRequest->requestorName;
370 if (gen->type != GEN_DIRNAME)
371 {
372 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
373 return 0;
374 }
375 nm = gen->d.directoryName;
376 ret = ocsp_req_find_signer(&signer, req, nm, certs, store, flags);
377 if (ret <= 0)
378 {
379 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
380 return 0;
381 }
382 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
383 flags |= OCSP_NOVERIFY;
384 if (!(flags & OCSP_NOSIGS))
385 {
386 EVP_PKEY *skey;
387 skey = X509_get_pubkey(signer);
388 ret = OCSP_REQUEST_verify(req, skey);
389 EVP_PKEY_free(skey);
390 if(ret <= 0)
391 {
392 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNATURE_FAILURE);
393 return 0;
394 }
395 }
396 if (!(flags & OCSP_NOVERIFY))
397 {
398 int init_res;
399 if(flags & OCSP_NOCHAIN)
400 init_res = X509_STORE_CTX_init(&ctx, store, signer, NULL);
401 else
402 init_res = X509_STORE_CTX_init(&ctx, store, signer,
403 req->optionalSignature->certs);
404 if(!init_res)
405 {
406 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,ERR_R_X509_LIB);
407 return 0;
408 }
409
410 X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
411 X509_STORE_CTX_set_trust(&ctx, X509_TRUST_OCSP_REQUEST);
412 ret = X509_verify_cert(&ctx);
413 X509_STORE_CTX_cleanup(&ctx);
414 if (ret <= 0)
415 {
416 ret = X509_STORE_CTX_get_error(&ctx);
417 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
418 ERR_add_error_data(2, "Verify error:",
419 X509_verify_cert_error_string(ret));
420 return 0;
421 }
422 }
423 return 1;
424 }
425
426static int ocsp_req_find_signer(X509 **psigner, OCSP_REQUEST *req, X509_NAME *nm, STACK_OF(X509) *certs,
427 X509_STORE *st, unsigned long flags)
428 {
429 X509 *signer;
430 if(!(flags & OCSP_NOINTERN))
431 {
432 signer = X509_find_by_subject(req->optionalSignature->certs, nm);
433 *psigner = signer;
434 return 1;
435 }
436
437 signer = X509_find_by_subject(certs, nm);
438 if (signer)
439 {
440 *psigner = signer;
441 return 2;
442 }
443 return 0;
444 }
diff --git a/src/lib/libcrypto/opensslconf.h b/src/lib/libcrypto/opensslconf.h
deleted file mode 100644
index 492041bc7c..0000000000
--- a/src/lib/libcrypto/opensslconf.h
+++ /dev/null
@@ -1,180 +0,0 @@
1/* opensslconf.h */
2/* WARNING: Generated automatically from opensslconf.h.in by Configure. */
3
4/* OpenSSL was configured with the following options: */
5#ifndef OPENSSL_DOING_MAKEDEPEND
6
7#ifndef OPENSSL_NO_KRB5
8# define OPENSSL_NO_KRB5
9#endif
10
11#endif /* OPENSSL_DOING_MAKEDEPEND */
12
13/* The OPENSSL_NO_* macros are also defined as NO_* if the application
14 asks for it. This is a transient feature that is provided for those
15 who haven't had the time to do the appropriate changes in their
16 applications. */
17#ifdef OPENSSL_ALGORITHM_DEFINES
18# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)
19# define NO_KRB5
20# endif
21#endif
22
23/* crypto/opensslconf.h.in */
24
25/* Generate 80386 code? */
26#undef I386_ONLY
27
28#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
29#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
30#define OPENSSLDIR "/usr/local/ssl"
31#endif
32#endif
33
34#undef OPENSSL_UNISTD
35#define OPENSSL_UNISTD <unistd.h>
36
37#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
38
39#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
40#define IDEA_INT unsigned int
41#endif
42
43#if defined(HEADER_MD2_H) && !defined(MD2_INT)
44#define MD2_INT unsigned int
45#endif
46
47#if defined(HEADER_RC2_H) && !defined(RC2_INT)
48/* I need to put in a mod for the alpha - eay */
49#define RC2_INT unsigned int
50#endif
51
52#if defined(HEADER_RC4_H)
53#if !defined(RC4_INT)
54/* using int types make the structure larger but make the code faster
55 * on most boxes I have tested - up to %20 faster. */
56/*
57 * I don't know what does "most" mean, but declaring "int" is a must on:
58 * - Intel P6 because partial register stalls are very expensive;
59 * - elder Alpha because it lacks byte load/store instructions;
60 */
61#define RC4_INT unsigned int
62#endif
63#if !defined(RC4_CHUNK)
64/*
65 * This enables code handling data aligned at natural CPU word
66 * boundary. See crypto/rc4/rc4_enc.c for further details.
67 */
68#undef RC4_CHUNK
69#endif
70#endif
71
72#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
73/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
74 * %20 speed up (longs are 8 bytes, int's are 4). */
75#ifndef DES_LONG
76#define DES_LONG unsigned long
77#endif
78#endif
79
80#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
81#define CONFIG_HEADER_BN_H
82#undef BN_LLONG
83
84/* Should we define BN_DIV2W here? */
85
86/* Only one for the following should be defined */
87/* The prime number generation stuff may not work when
88 * EIGHT_BIT but I don't care since I've only used this mode
89 * for debuging the bignum libraries */
90#undef SIXTY_FOUR_BIT_LONG
91#undef SIXTY_FOUR_BIT
92#define THIRTY_TWO_BIT
93#undef SIXTEEN_BIT
94#undef EIGHT_BIT
95#endif
96
97#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
98#define CONFIG_HEADER_RC4_LOCL_H
99/* if this is defined data[i] is used instead of *data, this is a %20
100 * speedup on x86 */
101#undef RC4_INDEX
102#endif
103
104#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
105#define CONFIG_HEADER_BF_LOCL_H
106#undef BF_PTR
107#endif /* HEADER_BF_LOCL_H */
108
109#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
110#define CONFIG_HEADER_DES_LOCL_H
111#ifndef DES_DEFAULT_OPTIONS
112/* the following is tweaked from a config script, that is why it is a
113 * protected undef/define */
114#ifndef DES_PTR
115#undef DES_PTR
116#endif
117
118/* This helps C compiler generate the correct code for multiple functional
119 * units. It reduces register dependancies at the expense of 2 more
120 * registers */
121#ifndef DES_RISC1
122#undef DES_RISC1
123#endif
124
125#ifndef DES_RISC2
126#undef DES_RISC2
127#endif
128
129#if defined(DES_RISC1) && defined(DES_RISC2)
130YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
131#endif
132
133/* Unroll the inner loop, this sometimes helps, sometimes hinders.
134 * Very mucy CPU dependant */
135#ifndef DES_UNROLL
136#undef DES_UNROLL
137#endif
138
139/* These default values were supplied by
140 * Peter Gutman <pgut001@cs.auckland.ac.nz>
141 * They are only used if nothing else has been defined */
142#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
143/* Special defines which change the way the code is built depending on the
144 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
145 even newer MIPS CPU's, but at the moment one size fits all for
146 optimization options. Older Sparc's work better with only UNROLL, but
147 there's no way to tell at compile time what it is you're running on */
148
149#if defined( sun ) /* Newer Sparc's */
150# define DES_PTR
151# define DES_RISC1
152# define DES_UNROLL
153#elif defined( __ultrix ) /* Older MIPS */
154# define DES_PTR
155# define DES_RISC2
156# define DES_UNROLL
157#elif defined( __osf1__ ) /* Alpha */
158# define DES_PTR
159# define DES_RISC2
160#elif defined ( _AIX ) /* RS6000 */
161 /* Unknown */
162#elif defined( __hpux ) /* HP-PA */
163 /* Unknown */
164#elif defined( __aux ) /* 68K */
165 /* Unknown */
166#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
167# define DES_UNROLL
168#elif defined( __sgi ) /* Newer MIPS */
169# define DES_PTR
170# define DES_RISC2
171# define DES_UNROLL
172#elif defined(i386) || defined(__i386__) /* x86 boxes, should be gcc */
173# define DES_PTR
174# define DES_RISC1
175# define DES_UNROLL
176#endif /* Systems-specific speed defines */
177#endif
178
179#endif /* DES_DEFAULT_OPTIONS */
180#endif /* HEADER_DES_LOCL_H */
diff --git a/src/lib/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h
new file mode 100644
index 0000000000..5d5f688edd
--- /dev/null
+++ b/src/lib/libcrypto/opensslv.h
@@ -0,0 +1,89 @@
1#ifndef HEADER_OPENSSLV_H
2#define HEADER_OPENSSLV_H
3
4/* Numeric release version identifier:
5 * MNNFFPPS: major minor fix patch status
6 * The status nibble has one of the values 0 for development, 1 to e for betas
7 * 1 to 14, and f for release. The patch level is exactly that.
8 * For example:
9 * 0.9.3-dev 0x00903000
10 * 0.9.3-beta1 0x00903001
11 * 0.9.3-beta2-dev 0x00903002
12 * 0.9.3-beta2 0x00903002 (same as ...beta2-dev)
13 * 0.9.3 0x0090300f
14 * 0.9.3a 0x0090301f
15 * 0.9.4 0x0090400f
16 * 1.2.3z 0x102031af
17 *
18 * For continuity reasons (because 0.9.5 is already out, and is coded
19 * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level
20 * part is slightly different, by setting the highest bit. This means
21 * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start
22 * with 0x0090600S...
23 *
24 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
25 * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
26 * major minor fix final patch/beta)
27 */
28#define OPENSSL_VERSION_NUMBER 0x0090707fL
29#ifdef OPENSSL_FIPS
30#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7g-fips 11 Apr 2005"
31#else
32#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7g 11 Apr 2005"
33#endif
34#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
35
36
37/* The macros below are to be used for shared library (.so, .dll, ...)
38 * versioning. That kind of versioning works a bit differently between
39 * operating systems. The most usual scheme is to set a major and a minor
40 * number, and have the runtime loader check that the major number is equal
41 * to what it was at application link time, while the minor number has to
42 * be greater or equal to what it was at application link time. With this
43 * scheme, the version number is usually part of the file name, like this:
44 *
45 * libcrypto.so.0.9
46 *
47 * Some unixen also make a softlink with the major verson number only:
48 *
49 * libcrypto.so.0
50 *
51 * On Tru64 and IRIX 6.x it works a little bit differently. There, the
52 * shared library version is stored in the file, and is actually a series
53 * of versions, separated by colons. The rightmost version present in the
54 * library when linking an application is stored in the application to be
55 * matched at run time. When the application is run, a check is done to
56 * see if the library version stored in the application matches any of the
57 * versions in the version string of the library itself.
58 * This version string can be constructed in any way, depending on what
59 * kind of matching is desired. However, to implement the same scheme as
60 * the one used in the other unixen, all compatible versions, from lowest
61 * to highest, should be part of the string. Consecutive builds would
62 * give the following versions strings:
63 *
64 * 3.0
65 * 3.0:3.1
66 * 3.0:3.1:3.2
67 * 4.0
68 * 4.0:4.1
69 *
70 * Notice how version 4 is completely incompatible with version, and
71 * therefore give the breach you can see.
72 *
73 * There may be other schemes as well that I haven't yet discovered.
74 *
75 * So, here's the way it works here: first of all, the library version
76 * number doesn't need at all to match the overall OpenSSL version.
77 * However, it's nice and more understandable if it actually does.
78 * The current library version is stored in the macro SHLIB_VERSION_NUMBER,
79 * which is just a piece of text in the format "M.m.e" (Major, minor, edit).
80 * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways,
81 * we need to keep a history of version numbers, which is done in the
82 * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and
83 * should only keep the versions that are binary compatible with the current.
84 */
85#define SHLIB_VERSION_HISTORY ""
86#define SHLIB_VERSION_NUMBER "0.9.7"
87
88
89#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libcrypto/ossl_typ.h b/src/lib/libcrypto/ossl_typ.h
new file mode 100644
index 0000000000..285fd0b1d9
--- /dev/null
+++ b/src/lib/libcrypto/ossl_typ.h
@@ -0,0 +1,122 @@
1/* ====================================================================
2 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_OPENSSL_TYPES_H
56#define HEADER_OPENSSL_TYPES_H
57
58#include <openssl/e_os2.h>
59
60#ifdef NO_ASN1_TYPEDEFS
61#define ASN1_INTEGER ASN1_STRING
62#define ASN1_ENUMERATED ASN1_STRING
63#define ASN1_BIT_STRING ASN1_STRING
64#define ASN1_OCTET_STRING ASN1_STRING
65#define ASN1_PRINTABLESTRING ASN1_STRING
66#define ASN1_T61STRING ASN1_STRING
67#define ASN1_IA5STRING ASN1_STRING
68#define ASN1_UTCTIME ASN1_STRING
69#define ASN1_GENERALIZEDTIME ASN1_STRING
70#define ASN1_TIME ASN1_STRING
71#define ASN1_GENERALSTRING ASN1_STRING
72#define ASN1_UNIVERSALSTRING ASN1_STRING
73#define ASN1_BMPSTRING ASN1_STRING
74#define ASN1_VISIBLESTRING ASN1_STRING
75#define ASN1_UTF8STRING ASN1_STRING
76#define ASN1_BOOLEAN int
77#define ASN1_NULL int
78#else
79typedef struct asn1_string_st ASN1_INTEGER;
80typedef struct asn1_string_st ASN1_ENUMERATED;
81typedef struct asn1_string_st ASN1_BIT_STRING;
82typedef struct asn1_string_st ASN1_OCTET_STRING;
83typedef struct asn1_string_st ASN1_PRINTABLESTRING;
84typedef struct asn1_string_st ASN1_T61STRING;
85typedef struct asn1_string_st ASN1_IA5STRING;
86typedef struct asn1_string_st ASN1_GENERALSTRING;
87typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
88typedef struct asn1_string_st ASN1_BMPSTRING;
89typedef struct asn1_string_st ASN1_UTCTIME;
90typedef struct asn1_string_st ASN1_TIME;
91typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
92typedef struct asn1_string_st ASN1_VISIBLESTRING;
93typedef struct asn1_string_st ASN1_UTF8STRING;
94typedef int ASN1_BOOLEAN;
95typedef int ASN1_NULL;
96#endif
97
98#ifdef OPENSSL_SYS_WIN32
99#undef X509_NAME
100#undef PKCS7_ISSUER_AND_SERIAL
101#endif
102
103typedef struct evp_cipher_st EVP_CIPHER;
104typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
105typedef struct env_md_st EVP_MD;
106typedef struct env_md_ctx_st EVP_MD_CTX;
107typedef struct evp_pkey_st EVP_PKEY;
108
109typedef struct x509_st X509;
110typedef struct X509_algor_st X509_ALGOR;
111typedef struct X509_crl_st X509_CRL;
112typedef struct X509_name_st X509_NAME;
113typedef struct x509_store_st X509_STORE;
114typedef struct x509_store_ctx_st X509_STORE_CTX;
115
116typedef struct engine_st ENGINE;
117
118 /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
119#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */
120#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */
121
122#endif /* def HEADER_OPENSSL_TYPES_H */
diff --git a/src/lib/libcrypto/pem/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/message b/src/lib/libcrypto/pem/message
new file mode 100644
index 0000000000..e8bf9d7592
--- /dev/null
+++ b/src/lib/libcrypto/pem/message
@@ -0,0 +1,16 @@
1-----BEGIN PRIVACY-ENHANCED MESSAGE-----
2Proc-Type: 4,ENCRYPTED
3Proc-Type: 4,MIC-ONLY
4Proc-Type: 4,MIC-CLEAR
5Content-Domain: RFC822
6DEK-Info: DES-CBC,0123456789abcdef
7Originator-Certificate
8 xxxx
9Issuer-Certificate
10 xxxx
11MIC-Info: RSA-MD5,RSA,
12 xxxx
13
14
15-----END PRIVACY-ENHANCED MESSAGE-----
16
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
new file mode 100644
index 0000000000..d330cbf9a3
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem.h
@@ -0,0 +1,672 @@
1/* crypto/pem/pem.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_PEM_H
60#define HEADER_PEM_H
61
62#ifndef OPENSSL_NO_BIO
63#include <openssl/bio.h>
64#endif
65#ifndef OPENSSL_NO_STACK
66#include <openssl/stack.h>
67#endif
68#include <openssl/evp.h>
69#include <openssl/x509.h>
70#include <openssl/pem2.h>
71#include <openssl/e_os2.h>
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77#define PEM_BUFSIZE 1024
78
79#define PEM_OBJ_UNDEF 0
80#define PEM_OBJ_X509 1
81#define PEM_OBJ_X509_REQ 2
82#define PEM_OBJ_CRL 3
83#define PEM_OBJ_SSL_SESSION 4
84#define PEM_OBJ_PRIV_KEY 10
85#define PEM_OBJ_PRIV_RSA 11
86#define PEM_OBJ_PRIV_DSA 12
87#define PEM_OBJ_PRIV_DH 13
88#define PEM_OBJ_PUB_RSA 14
89#define PEM_OBJ_PUB_DSA 15
90#define PEM_OBJ_PUB_DH 16
91#define PEM_OBJ_DHPARAMS 17
92#define PEM_OBJ_DSAPARAMS 18
93#define PEM_OBJ_PRIV_RSA_PUBLIC 19
94
95#define PEM_ERROR 30
96#define PEM_DEK_DES_CBC 40
97#define PEM_DEK_IDEA_CBC 45
98#define PEM_DEK_DES_EDE 50
99#define PEM_DEK_DES_ECB 60
100#define PEM_DEK_RSA 70
101#define PEM_DEK_RSA_MD2 80
102#define PEM_DEK_RSA_MD5 90
103
104#define PEM_MD_MD2 NID_md2
105#define PEM_MD_MD5 NID_md5
106#define PEM_MD_SHA NID_sha
107#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
108#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
109#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
110
111#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
112#define PEM_STRING_X509 "CERTIFICATE"
113#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
114#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
115#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
116#define PEM_STRING_X509_CRL "X509 CRL"
117#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
118#define PEM_STRING_PUBLIC "PUBLIC KEY"
119#define PEM_STRING_RSA "RSA PRIVATE KEY"
120#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
121#define PEM_STRING_DSA "DSA PRIVATE KEY"
122#define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
123#define PEM_STRING_PKCS7 "PKCS7"
124#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
125#define PEM_STRING_PKCS8INF "PRIVATE KEY"
126#define PEM_STRING_DHPARAMS "DH PARAMETERS"
127#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
128#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
129
130 /* Note that this structure is initialised by PEM_SealInit and cleaned up
131 by PEM_SealFinal (at least for now) */
132typedef struct PEM_Encode_Seal_st
133 {
134 EVP_ENCODE_CTX encode;
135 EVP_MD_CTX md;
136 EVP_CIPHER_CTX cipher;
137 } PEM_ENCODE_SEAL_CTX;
138
139/* enc_type is one off */
140#define PEM_TYPE_ENCRYPTED 10
141#define PEM_TYPE_MIC_ONLY 20
142#define PEM_TYPE_MIC_CLEAR 30
143#define PEM_TYPE_CLEAR 40
144
145typedef struct pem_recip_st
146 {
147 char *name;
148 X509_NAME *dn;
149
150 int cipher;
151 int key_enc;
152 /* char iv[8]; unused and wrong size */
153 } PEM_USER;
154
155typedef struct pem_ctx_st
156 {
157 int type; /* what type of object */
158
159 struct {
160 int version;
161 int mode;
162 } proc_type;
163
164 char *domain;
165
166 struct {
167 int cipher;
168 /* unused, and wrong size
169 unsigned char iv[8]; */
170 } DEK_info;
171
172 PEM_USER *originator;
173
174 int num_recipient;
175 PEM_USER **recipient;
176
177#ifndef OPENSSL_NO_STACK
178 STACK *x509_chain; /* certificate chain */
179#else
180 char *x509_chain; /* certificate chain */
181#endif
182 EVP_MD *md; /* signature type */
183
184 int md_enc; /* is the md encrypted or not? */
185 int md_len; /* length of md_data */
186 char *md_data; /* message digest, could be pkey encrypted */
187
188 EVP_CIPHER *dec; /* date encryption cipher */
189 int key_len; /* key length */
190 unsigned char *key; /* key */
191 /* unused, and wrong size
192 unsigned char iv[8]; */
193
194
195 int data_enc; /* is the data encrypted */
196 int data_len;
197 unsigned char *data;
198 } PEM_CTX;
199
200/* These macros make the PEM_read/PEM_write functions easier to maintain and
201 * write. Now they are all implemented with either:
202 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
203 */
204
205#ifdef OPENSSL_NO_FP_API
206
207#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
208#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
209#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
210
211#else
212
213#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
214type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
215{ \
216return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
217 cb,u)); \
218} \
219
220#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
221int PEM_write_##name(FILE *fp, type *x) \
222{ \
223return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
224 NULL,NULL,0,NULL,NULL)); \
225}
226
227#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
228int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
229 unsigned char *kstr, int klen, pem_password_cb *cb, \
230 void *u) \
231 { \
232 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
233 (char *)x,enc,kstr,klen,cb,u)); \
234 }
235
236#endif
237
238#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
239type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
240{ \
241return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
242 (char **)x,cb,u)); \
243}
244
245#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
246int PEM_write_bio_##name(BIO *bp, type *x) \
247{ \
248return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
249 NULL,NULL,0,NULL,NULL)); \
250}
251
252#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
253int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
254 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
255 { \
256 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
257 (char *)x,enc,kstr,klen,cb,u)); \
258 }
259
260#define IMPLEMENT_PEM_write(name, type, str, asn1) \
261 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
262 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
263
264#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
265 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
266 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
267
268#define IMPLEMENT_PEM_read(name, type, str, asn1) \
269 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
270 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
271
272#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
273 IMPLEMENT_PEM_read(name, type, str, asn1) \
274 IMPLEMENT_PEM_write(name, type, str, asn1)
275
276#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
277 IMPLEMENT_PEM_read(name, type, str, asn1) \
278 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
279
280/* These are the same except they are for the declarations */
281
282#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
283
284#define DECLARE_PEM_read_fp(name, type) /**/
285#define DECLARE_PEM_write_fp(name, type) /**/
286#define DECLARE_PEM_write_cb_fp(name, type) /**/
287
288#else
289
290#define DECLARE_PEM_read_fp(name, type) \
291 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
292
293#define DECLARE_PEM_write_fp(name, type) \
294 int PEM_write_##name(FILE *fp, type *x);
295
296#define DECLARE_PEM_write_cb_fp(name, type) \
297 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
299
300#endif
301
302#ifndef OPENSSL_NO_BIO
303#define DECLARE_PEM_read_bio(name, type) \
304 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
305
306#define DECLARE_PEM_write_bio(name, type) \
307 int PEM_write_bio_##name(BIO *bp, type *x);
308
309#define DECLARE_PEM_write_cb_bio(name, type) \
310 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
311 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
312
313#else
314
315#define DECLARE_PEM_read_bio(name, type) /**/
316#define DECLARE_PEM_write_bio(name, type) /**/
317#define DECLARE_PEM_write_cb_bio(name, type) /**/
318
319#endif
320
321#define DECLARE_PEM_write(name, type) \
322 DECLARE_PEM_write_bio(name, type) \
323 DECLARE_PEM_write_fp(name, type)
324
325#define DECLARE_PEM_write_cb(name, type) \
326 DECLARE_PEM_write_cb_bio(name, type) \
327 DECLARE_PEM_write_cb_fp(name, type)
328
329#define DECLARE_PEM_read(name, type) \
330 DECLARE_PEM_read_bio(name, type) \
331 DECLARE_PEM_read_fp(name, type)
332
333#define DECLARE_PEM_rw(name, type) \
334 DECLARE_PEM_read(name, type) \
335 DECLARE_PEM_write(name, type)
336
337#define DECLARE_PEM_rw_cb(name, type) \
338 DECLARE_PEM_read(name, type) \
339 DECLARE_PEM_write_cb(name, type)
340
341#ifdef SSLEAY_MACROS
342
343#define PEM_write_SSL_SESSION(fp,x) \
344 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
345 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
346#define PEM_write_X509(fp,x) \
347 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
348 (char *)x, NULL,NULL,0,NULL,NULL)
349#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
350 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
351 NULL,NULL,0,NULL,NULL)
352#define PEM_write_X509_CRL(fp,x) \
353 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
354 fp,(char *)x, NULL,NULL,0,NULL,NULL)
355#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
356 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
357 (char *)x,enc,kstr,klen,cb,u)
358#define PEM_write_RSAPublicKey(fp,x) \
359 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
360 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
361#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
362 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
363 (char *)x,enc,kstr,klen,cb,u)
364#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
365 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
366 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
367 bp,(char *)x,enc,kstr,klen,cb,u)
368#define PEM_write_PKCS7(fp,x) \
369 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
370 (char *)x, NULL,NULL,0,NULL,NULL)
371#define PEM_write_DHparams(fp,x) \
372 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
373 (char *)x,NULL,NULL,0,NULL,NULL)
374
375#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
376 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
377 PEM_STRING_X509,fp, \
378 (char *)x, NULL,NULL,0,NULL,NULL)
379
380#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
381 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
382#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
383 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
384#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
385 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
386#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
387 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
388#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
389 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
390#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
391 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
392#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
393 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
394#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
395 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
396#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
397 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
398#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
399 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
400
401#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
402 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
403 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
404 (char **)x,cb,u)
405
406#define PEM_write_bio_SSL_SESSION(bp,x) \
407 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
408 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
409#define PEM_write_bio_X509(bp,x) \
410 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
411 (char *)x, NULL,NULL,0,NULL,NULL)
412#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
413 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
414 NULL,NULL,0,NULL,NULL)
415#define PEM_write_bio_X509_CRL(bp,x) \
416 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
417 bp,(char *)x, NULL,NULL,0,NULL,NULL)
418#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
419 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
420 bp,(char *)x,enc,kstr,klen,cb,u)
421#define PEM_write_bio_RSAPublicKey(bp,x) \
422 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
423 PEM_STRING_RSA_PUBLIC,\
424 bp,(char *)x,NULL,NULL,0,NULL,NULL)
425#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
426 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
427 bp,(char *)x,enc,kstr,klen,cb,u)
428#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
429 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
430 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
431 bp,(char *)x,enc,kstr,klen,cb,u)
432#define PEM_write_bio_PKCS7(bp,x) \
433 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
434 (char *)x, NULL,NULL,0,NULL,NULL)
435#define PEM_write_bio_DHparams(bp,x) \
436 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
437 bp,(char *)x,NULL,NULL,0,NULL,NULL)
438#define PEM_write_bio_DSAparams(bp,x) \
439 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
440 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
441
442#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
443 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
444 PEM_STRING_X509,bp, \
445 (char *)x, NULL,NULL,0,NULL,NULL)
446
447#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
448 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
449#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
450 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
451#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
453#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
455#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
457#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
458 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
459#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
461#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
462 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
463
464#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
465 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
466#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
467 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
468#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
469 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
470
471#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
472 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
473 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
474 (char **)x,cb,u)
475
476#endif
477
478#if 1
479/* "userdata": new with OpenSSL 0.9.4 */
480typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
481#else
482/* OpenSSL 0.9.3, 0.9.3a */
483typedef int pem_password_cb(char *buf, int size, int rwflag);
484#endif
485
486int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
487int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
488 pem_password_cb *callback,void *u);
489
490#ifndef OPENSSL_NO_BIO
491int PEM_read_bio(BIO *bp, char **name, char **header,
492 unsigned char **data,long *len);
493int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
494 long len);
495int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
496 pem_password_cb *cb, void *u);
497char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
498 pem_password_cb *cb, void *u);
499int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
500 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
501 pem_password_cb *cb, void *u);
502STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
503int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
504 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
505#endif
506
507#ifndef OPENSSL_SYS_WIN16
508int PEM_read(FILE *fp, char **name, char **header,
509 unsigned char **data,long *len);
510int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
511char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
512 pem_password_cb *cb, void *u);
513int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
514 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
515 pem_password_cb *callback, void *u);
516STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
517 pem_password_cb *cb, void *u);
518#endif
519
520int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
521 EVP_MD *md_type, unsigned char **ek, int *ekl,
522 unsigned char *iv, EVP_PKEY **pubk, int npubk);
523void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
524 unsigned char *in, int inl);
525int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
526 unsigned char *out, int *outl, EVP_PKEY *priv);
527
528void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
529void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
530int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
531 unsigned int *siglen, EVP_PKEY *pkey);
532
533int PEM_def_callback(char *buf, int num, int w, void *key);
534void PEM_proc_type(char *buf, int type);
535void PEM_dek_info(char *buf, const char *type, int len, char *str);
536
537#ifndef SSLEAY_MACROS
538
539#include <openssl/symhacks.h>
540
541DECLARE_PEM_rw(X509, X509)
542
543DECLARE_PEM_rw(X509_AUX, X509)
544
545DECLARE_PEM_rw(X509_REQ, X509_REQ)
546DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
547
548DECLARE_PEM_rw(X509_CRL, X509_CRL)
549
550DECLARE_PEM_rw(PKCS7, PKCS7)
551
552DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
553
554DECLARE_PEM_rw(PKCS8, X509_SIG)
555
556DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
557
558#ifndef OPENSSL_NO_RSA
559
560DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
561
562DECLARE_PEM_rw(RSAPublicKey, RSA)
563DECLARE_PEM_rw(RSA_PUBKEY, RSA)
564
565#endif
566
567#ifndef OPENSSL_NO_DSA
568
569DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
570
571DECLARE_PEM_rw(DSA_PUBKEY, DSA)
572
573DECLARE_PEM_rw(DSAparams, DSA)
574
575#endif
576
577#ifndef OPENSSL_NO_DH
578
579DECLARE_PEM_rw(DHparams, DH)
580
581#endif
582
583DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
584
585DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
586
587int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
588 char *kstr, int klen,
589 pem_password_cb *cb, void *u);
590int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
591 char *, int, pem_password_cb *, void *);
592int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
593 char *kstr, int klen,
594 pem_password_cb *cb, void *u);
595int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
596 char *kstr, int klen,
597 pem_password_cb *cb, void *u);
598EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
599
600int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
601 char *kstr, int klen,
602 pem_password_cb *cb, void *u);
603int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
604 char *kstr, int klen,
605 pem_password_cb *cb, void *u);
606int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
607 char *kstr, int klen,
608 pem_password_cb *cb, void *u);
609
610EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
611
612int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
613 char *kstr,int klen, pem_password_cb *cd, void *u);
614
615#endif /* SSLEAY_MACROS */
616
617
618/* BEGIN ERROR CODES */
619/* The following lines are auto generated by the script mkerr.pl. Any changes
620 * made after this point may be overwritten when the script is next run.
621 */
622void ERR_load_PEM_strings(void);
623
624/* Error codes for the PEM functions. */
625
626/* Function codes. */
627#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
628#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
629#define PEM_F_DEF_CALLBACK 100
630#define PEM_F_LOAD_IV 101
631#define PEM_F_PEM_ASN1_READ 102
632#define PEM_F_PEM_ASN1_READ_BIO 103
633#define PEM_F_PEM_ASN1_WRITE 104
634#define PEM_F_PEM_ASN1_WRITE_BIO 105
635#define PEM_F_PEM_DO_HEADER 106
636#define PEM_F_PEM_F_DO_PK8KEY_FP 122
637#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
638#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
639#define PEM_F_PEM_READ 108
640#define PEM_F_PEM_READ_BIO 109
641#define PEM_F_PEM_SEALFINAL 110
642#define PEM_F_PEM_SEALINIT 111
643#define PEM_F_PEM_SIGNFINAL 112
644#define PEM_F_PEM_WRITE 113
645#define PEM_F_PEM_WRITE_BIO 114
646#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
647#define PEM_F_PEM_X509_INFO_READ 115
648#define PEM_F_PEM_X509_INFO_READ_BIO 116
649#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
650
651/* Reason codes. */
652#define PEM_R_BAD_BASE64_DECODE 100
653#define PEM_R_BAD_DECRYPT 101
654#define PEM_R_BAD_END_LINE 102
655#define PEM_R_BAD_IV_CHARS 103
656#define PEM_R_BAD_PASSWORD_READ 104
657#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
658#define PEM_R_NOT_DEK_INFO 105
659#define PEM_R_NOT_ENCRYPTED 106
660#define PEM_R_NOT_PROC_TYPE 107
661#define PEM_R_NO_START_LINE 108
662#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
663#define PEM_R_PUBLIC_KEY_NO_RSA 110
664#define PEM_R_READ_KEY 111
665#define PEM_R_SHORT_HEADER 112
666#define PEM_R_UNSUPPORTED_CIPHER 113
667#define PEM_R_UNSUPPORTED_ENCRYPTION 114
668
669#ifdef __cplusplus
670}
671#endif
672#endif
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h
new file mode 100644
index 0000000000..f31790d69c
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem2.h
@@ -0,0 +1,70 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * This header only exists to break a circular dependency between pem and err
57 * Ben 30 Jan 1999.
58 */
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64#ifndef HEADER_PEM_H
65void ERR_load_PEM_strings(void);
66#endif
67
68#ifdef __cplusplus
69}
70#endif
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
new file mode 100644
index 0000000000..07963314c9
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_all.c
@@ -0,0 +1,315 @@
1/* crypto/pem/pem_all.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67#include <openssl/fips.h>
68
69#ifndef OPENSSL_NO_RSA
70static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
71#endif
72#ifndef OPENSSL_NO_DSA
73static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
74#endif
75
76IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
77
78IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
79
80IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
81
82IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
83
84IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
85 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
86
87
88#ifndef OPENSSL_NO_RSA
89
90/* We treat RSA or DSA private keys as a special case.
91 *
92 * For private keys we read in an EVP_PKEY structure with
93 * PEM_read_bio_PrivateKey() and extract the relevant private
94 * key: this means can handle "traditional" and PKCS#8 formats
95 * transparently.
96 */
97
98static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa)
99{
100 RSA *rtmp;
101 if(!key) return NULL;
102 rtmp = EVP_PKEY_get1_RSA(key);
103 EVP_PKEY_free(key);
104 if(!rtmp) return NULL;
105 if(rsa) {
106 RSA_free(*rsa);
107 *rsa = rtmp;
108 }
109 return rtmp;
110}
111
112RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
113 void *u)
114{
115 EVP_PKEY *pktmp;
116 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
117 return pkey_get_rsa(pktmp, rsa);
118}
119
120#ifndef OPENSSL_NO_FP_API
121
122RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
123 void *u)
124{
125 EVP_PKEY *pktmp;
126 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
127 return pkey_get_rsa(pktmp, rsa);
128}
129
130#endif
131
132#ifdef OPENSSL_FIPS
133
134int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
135 unsigned char *kstr, int klen,
136 pem_password_cb *cb, void *u)
137{
138 EVP_PKEY *k;
139 int ret;
140 k = EVP_PKEY_new();
141 if (!k)
142 return 0;
143 EVP_PKEY_set1_RSA(k, x);
144
145 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
146 EVP_PKEY_free(k);
147 return ret;
148}
149
150#ifndef OPENSSL_NO_FP_API
151int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
152 unsigned char *kstr, int klen,
153 pem_password_cb *cb, void *u)
154{
155 EVP_PKEY *k;
156 int ret;
157 k = EVP_PKEY_new();
158 if (!k)
159 return 0;
160
161 EVP_PKEY_set1_RSA(k, x);
162
163 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
164 EVP_PKEY_free(k);
165 return ret;
166}
167#endif
168
169#else
170
171IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
172
173#endif
174
175IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
176IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
177
178#endif
179
180#ifndef OPENSSL_NO_DSA
181
182static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa)
183{
184 DSA *dtmp;
185 if(!key) return NULL;
186 dtmp = EVP_PKEY_get1_DSA(key);
187 EVP_PKEY_free(key);
188 if(!dtmp) return NULL;
189 if(dsa) {
190 DSA_free(*dsa);
191 *dsa = dtmp;
192 }
193 return dtmp;
194}
195
196DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
197 void *u)
198{
199 EVP_PKEY *pktmp;
200 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
201 return pkey_get_dsa(pktmp, dsa);
202}
203
204
205#ifdef OPENSSL_FIPS
206
207int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
208 unsigned char *kstr, int klen,
209 pem_password_cb *cb, void *u)
210{
211 EVP_PKEY *k;
212 int ret;
213 k = EVP_PKEY_new();
214 if (!k)
215 return 0;
216 EVP_PKEY_set1_DSA(k, x);
217
218 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
219 EVP_PKEY_free(k);
220 return ret;
221}
222
223#ifndef OPENSSL_NO_FP_API
224int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
225 unsigned char *kstr, int klen,
226 pem_password_cb *cb, void *u)
227{
228 EVP_PKEY *k;
229 int ret;
230 k = EVP_PKEY_new();
231 if (!k)
232 return 0;
233 EVP_PKEY_set1_DSA(k, x);
234 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
235 EVP_PKEY_free(k);
236 return ret;
237}
238#endif
239
240#else
241
242IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
243
244#endif
245
246IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
247
248#ifndef OPENSSL_NO_FP_API
249
250DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
251 void *u)
252{
253 EVP_PKEY *pktmp;
254 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
255 return pkey_get_dsa(pktmp, dsa);
256}
257
258#endif
259
260IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
261
262#endif
263
264#ifndef OPENSSL_NO_DH
265
266IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
267
268#endif
269
270
271/* The PrivateKey case is not that straightforward.
272 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
273 * does not work, RSA and DSA keys have specific strings.
274 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
275 * appropriate.)
276 */
277
278#ifdef OPENSSL_FIPS
279
280int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
281 unsigned char *kstr, int klen,
282 pem_password_cb *cb, void *u)
283 {
284 if (FIPS_mode())
285 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
286 (char *)kstr, klen, cb, u);
287 else
288 return PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
289 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
290 bp,(char *)x,enc,kstr,klen,cb,u);
291 }
292
293#ifndef OPENSSL_NO_FP_API
294int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
295 unsigned char *kstr, int klen,
296 pem_password_cb *cb, void *u)
297 {
298 if (FIPS_mode())
299 return PEM_write_PKCS8PrivateKey(fp, x, enc,
300 (char *)kstr, klen, cb, u);
301 else
302 return PEM_ASN1_write((int (*)())i2d_PrivateKey,
303 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
304 fp,(char *)x,enc,kstr,klen,cb,u);
305 }
306#endif
307
308#else
309
310IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
311
312#endif
313
314IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
315
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
new file mode 100644
index 0000000000..3b39b84d66
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -0,0 +1,131 @@
1/* crypto/pem/pem_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pem.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA PEM_str_functs[]=
68 {
69{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_BIO,0), "d2i_PKCS8PrivateKey_bio"},
70{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_FP,0), "d2i_PKCS8PrivateKey_fp"},
71{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"},
72{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"},
73{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"},
74{ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"},
75{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
76{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
77{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
78{ERR_PACK(0,PEM_F_PEM_F_DO_PK8KEY_FP,0), "PEM_F_DO_PK8KEY_FP"},
79{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
80{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
81{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
82{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
83{ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"},
84{ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"},
85{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
86{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
87{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
88{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"},
89{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
90{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
91{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
92{0,NULL}
93 };
94
95static ERR_STRING_DATA PEM_str_reasons[]=
96 {
97{PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"},
98{PEM_R_BAD_DECRYPT ,"bad decrypt"},
99{PEM_R_BAD_END_LINE ,"bad end line"},
100{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
101{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
102{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"},
103{PEM_R_NOT_DEK_INFO ,"not dek info"},
104{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
105{PEM_R_NOT_PROC_TYPE ,"not proc type"},
106{PEM_R_NO_START_LINE ,"no start line"},
107{PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"},
108{PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"},
109{PEM_R_READ_KEY ,"read key"},
110{PEM_R_SHORT_HEADER ,"short header"},
111{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
112{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
113{0,NULL}
114 };
115
116#endif
117
118void ERR_load_PEM_strings(void)
119 {
120 static int init=1;
121
122 if (init)
123 {
124 init=0;
125#ifndef OPENSSL_NO_ERR
126 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs);
127 ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons);
128#endif
129
130 }
131 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
new file mode 100644
index 0000000000..9e4af29c95
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -0,0 +1,365 @@
1/* crypto/pem/pem_info.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
67#ifndef OPENSSL_NO_FP_API
68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
69 {
70 BIO *b;
71 STACK_OF(X509_INFO) *ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
86 {
87 X509_INFO *xi=NULL;
88 char *name=NULL,*header=NULL,**pp;
89 unsigned char *data=NULL,*p;
90 long len,error=0;
91 int ok=0;
92 STACK_OF(X509_INFO) *ret=NULL;
93 unsigned int i,raw;
94 char *(*d2i)();
95
96 if (sk == NULL)
97 {
98 if ((ret=sk_X509_INFO_new_null()) == NULL)
99 {
100 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
101 goto err;
102 }
103 }
104 else
105 ret=sk;
106
107 if ((xi=X509_INFO_new()) == NULL) goto err;
108 for (;;)
109 {
110 raw=0;
111 i=PEM_read_bio(bp,&name,&header,&data,&len);
112 if (i == 0)
113 {
114 error=ERR_GET_REASON(ERR_peek_last_error());
115 if (error == PEM_R_NO_START_LINE)
116 {
117 ERR_clear_error();
118 break;
119 }
120 goto err;
121 }
122start:
123 if ( (strcmp(name,PEM_STRING_X509) == 0) ||
124 (strcmp(name,PEM_STRING_X509_OLD) == 0))
125 {
126 d2i=(char *(*)())d2i_X509;
127 if (xi->x509 != NULL)
128 {
129 if (!sk_X509_INFO_push(ret,xi)) goto err;
130 if ((xi=X509_INFO_new()) == NULL) goto err;
131 goto start;
132 }
133 pp=(char **)&(xi->x509);
134 }
135 else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0))
136 {
137 d2i=(char *(*)())d2i_X509_AUX;
138 if (xi->x509 != NULL)
139 {
140 if (!sk_X509_INFO_push(ret,xi)) goto err;
141 if ((xi=X509_INFO_new()) == NULL) goto err;
142 goto start;
143 }
144 pp=(char **)&(xi->x509);
145 }
146 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
147 {
148 d2i=(char *(*)())d2i_X509_CRL;
149 if (xi->crl != NULL)
150 {
151 if (!sk_X509_INFO_push(ret,xi)) goto err;
152 if ((xi=X509_INFO_new()) == NULL) goto err;
153 goto start;
154 }
155 pp=(char **)&(xi->crl);
156 }
157 else
158#ifndef OPENSSL_NO_RSA
159 if (strcmp(name,PEM_STRING_RSA) == 0)
160 {
161 d2i=(char *(*)())d2i_RSAPrivateKey;
162 if (xi->x_pkey != NULL)
163 {
164 if (!sk_X509_INFO_push(ret,xi)) goto err;
165 if ((xi=X509_INFO_new()) == NULL) goto err;
166 goto start;
167 }
168
169 xi->enc_data=NULL;
170 xi->enc_len=0;
171
172 xi->x_pkey=X509_PKEY_new();
173 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
174 goto err;
175 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
176 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa);
177 if ((int)strlen(header) > 10) /* assume encrypted */
178 raw=1;
179 }
180 else
181#endif
182#ifndef OPENSSL_NO_DSA
183 if (strcmp(name,PEM_STRING_DSA) == 0)
184 {
185 d2i=(char *(*)())d2i_DSAPrivateKey;
186 if (xi->x_pkey != NULL)
187 {
188 if (!sk_X509_INFO_push(ret,xi)) goto err;
189 if ((xi=X509_INFO_new()) == NULL) goto err;
190 goto start;
191 }
192
193 xi->enc_data=NULL;
194 xi->enc_len=0;
195
196 xi->x_pkey=X509_PKEY_new();
197 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
198 goto err;
199 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
200 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa);
201 if ((int)strlen(header) > 10) /* assume encrypted */
202 raw=1;
203 }
204 else
205#endif
206 {
207 d2i=NULL;
208 pp=NULL;
209 }
210
211 if (d2i != NULL)
212 {
213 if (!raw)
214 {
215 EVP_CIPHER_INFO cipher;
216
217 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
218 goto err;
219 if (!PEM_do_header(&cipher,data,&len,cb,u))
220 goto err;
221 p=data;
222 if (d2i(pp,&p,len) == NULL)
223 {
224 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
225 goto err;
226 }
227 }
228 else
229 { /* encrypted RSA data */
230 if (!PEM_get_EVP_CIPHER_INFO(header,
231 &xi->enc_cipher)) goto err;
232 xi->enc_data=(char *)data;
233 xi->enc_len=(int)len;
234 data=NULL;
235 }
236 }
237 else {
238 /* unknown */
239 }
240 if (name != NULL) OPENSSL_free(name);
241 if (header != NULL) OPENSSL_free(header);
242 if (data != NULL) OPENSSL_free(data);
243 name=NULL;
244 header=NULL;
245 data=NULL;
246 }
247
248 /* if the last one hasn't been pushed yet and there is anything
249 * in it then add it to the stack ...
250 */
251 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
252 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
253 {
254 if (!sk_X509_INFO_push(ret,xi)) goto err;
255 xi=NULL;
256 }
257 ok=1;
258err:
259 if (xi != NULL) X509_INFO_free(xi);
260 if (!ok)
261 {
262 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
263 {
264 xi=sk_X509_INFO_value(ret,i);
265 X509_INFO_free(xi);
266 }
267 if (ret != sk) sk_X509_INFO_free(ret);
268 ret=NULL;
269 }
270
271 if (name != NULL) OPENSSL_free(name);
272 if (header != NULL) OPENSSL_free(header);
273 if (data != NULL) OPENSSL_free(data);
274 return(ret);
275 }
276
277
278/* A TJH addition */
279int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
280 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
281 {
282 EVP_CIPHER_CTX ctx;
283 int i,ret=0;
284 unsigned char *data=NULL;
285 const char *objstr=NULL;
286 char buf[PEM_BUFSIZE];
287 unsigned char *iv=NULL;
288
289 if (enc != NULL)
290 {
291 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
292 if (objstr == NULL)
293 {
294 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
295 goto err;
296 }
297 }
298
299 /* now for the fun part ... if we have a private key then
300 * we have to be able to handle a not-yet-decrypted key
301 * being written out correctly ... if it is decrypted or
302 * it is non-encrypted then we use the base code
303 */
304 if (xi->x_pkey!=NULL)
305 {
306 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
307 {
308 /* copy from weirdo names into more normal things */
309 iv=xi->enc_cipher.iv;
310 data=(unsigned char *)xi->enc_data;
311 i=xi->enc_len;
312
313 /* we take the encryption data from the
314 * internal stuff rather than what the
315 * user has passed us ... as we have to
316 * match exactly for some strange reason
317 */
318 objstr=OBJ_nid2sn(
319 EVP_CIPHER_nid(xi->enc_cipher.cipher));
320 if (objstr == NULL)
321 {
322 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
323 goto err;
324 }
325
326 /* create the right magic header stuff */
327 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
328 buf[0]='\0';
329 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
330 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
331
332 /* use the normal code to write things out */
333 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
334 if (i <= 0) goto err;
335 }
336 else
337 {
338 /* Add DSA/DH */
339#ifndef OPENSSL_NO_RSA
340 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb,u)<=0)
344 goto err;
345#endif
346 }
347 }
348
349 /* if we have a certificate then write it out now */
350 if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0))
351 goto err;
352
353 /* we are ignoring anything else that is loaded into the X509_INFO
354 * structure for the moment ... as I don't need it so I'm not
355 * coding it here and Eric can do it when this makes it into the
356 * base library --tjh
357 */
358
359 ret=1;
360
361err:
362 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
363 OPENSSL_cleanse(buf,PEM_BUFSIZE);
364 return(ret);
365 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
new file mode 100644
index 0000000000..82815067b3
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -0,0 +1,776 @@
1/* crypto/pem/pem_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67#include <openssl/pkcs12.h>
68#ifndef OPENSSL_NO_DES
69#include <openssl/des.h>
70#endif
71
72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
73
74#define MIN_LENGTH 4
75
76static int load_iv(char **fromp,unsigned char *to, int num);
77static int check_pem(const char *nm, const char *name);
78
79int PEM_def_callback(char *buf, int num, int w, void *key)
80 {
81#ifdef OPENSSL_NO_FP_API
82 /* We should not ever call the default callback routine from
83 * windows. */
84 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85 return(-1);
86#else
87 int i,j;
88 const char *prompt;
89 if(key) {
90 i=strlen(key);
91 i=(i > num)?num:i;
92 memcpy(buf,key,i);
93 return(i);
94 }
95
96 prompt=EVP_get_pw_prompt();
97 if (prompt == NULL)
98 prompt="Enter PEM pass phrase:";
99
100 for (;;)
101 {
102 i=EVP_read_pw_string(buf,num,prompt,w);
103 if (i != 0)
104 {
105 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
106 memset(buf,0,(unsigned int)num);
107 return(-1);
108 }
109 j=strlen(buf);
110 if (j < MIN_LENGTH)
111 {
112 fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH);
113 }
114 else
115 break;
116 }
117 return(j);
118#endif
119 }
120
121void PEM_proc_type(char *buf, int type)
122 {
123 const char *str;
124
125 if (type == PEM_TYPE_ENCRYPTED)
126 str="ENCRYPTED";
127 else if (type == PEM_TYPE_MIC_CLEAR)
128 str="MIC-CLEAR";
129 else if (type == PEM_TYPE_MIC_ONLY)
130 str="MIC-ONLY";
131 else
132 str="BAD-TYPE";
133
134 BUF_strlcat(buf,"Proc-Type: 4,",PEM_BUFSIZE);
135 BUF_strlcat(buf,str,PEM_BUFSIZE);
136 BUF_strlcat(buf,"\n",PEM_BUFSIZE);
137 }
138
139void PEM_dek_info(char *buf, const char *type, int len, char *str)
140 {
141 static const unsigned char map[17]="0123456789ABCDEF";
142 long i;
143 int j;
144
145 BUF_strlcat(buf,"DEK-Info: ",PEM_BUFSIZE);
146 BUF_strlcat(buf,type,PEM_BUFSIZE);
147 BUF_strlcat(buf,",",PEM_BUFSIZE);
148 j=strlen(buf);
149 if (j + (len * 2) + 1 > PEM_BUFSIZE)
150 return;
151 for (i=0; i<len; i++)
152 {
153 buf[j+i*2] =map[(str[i]>>4)&0x0f];
154 buf[j+i*2+1]=map[(str[i] )&0x0f];
155 }
156 buf[j+i*2]='\n';
157 buf[j+i*2+1]='\0';
158 }
159
160#ifndef OPENSSL_NO_FP_API
161char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
162 pem_password_cb *cb, void *u)
163 {
164 BIO *b;
165 char *ret;
166
167 if ((b=BIO_new(BIO_s_file())) == NULL)
168 {
169 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
170 return(0);
171 }
172 BIO_set_fp(b,fp,BIO_NOCLOSE);
173 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
174 BIO_free(b);
175 return(ret);
176 }
177#endif
178
179static int check_pem(const char *nm, const char *name)
180{
181 /* Normal matching nm and name */
182 if (!strcmp(nm,name)) return 1;
183
184 /* Make PEM_STRING_EVP_PKEY match any private key */
185
186 if(!strcmp(nm,PEM_STRING_PKCS8) &&
187 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
188
189 if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
190 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
191
192 if(!strcmp(nm,PEM_STRING_RSA) &&
193 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
194
195 if(!strcmp(nm,PEM_STRING_DSA) &&
196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
197
198 /* Permit older strings */
199
200 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
201 !strcmp(name,PEM_STRING_X509)) return 1;
202
203 if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) &&
204 !strcmp(name,PEM_STRING_X509_REQ)) return 1;
205
206 /* Allow normal certs to be read as trusted certs */
207 if(!strcmp(nm,PEM_STRING_X509) &&
208 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
209
210 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
211 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
212
213 /* Some CAs use PKCS#7 with CERTIFICATE headers */
214 if(!strcmp(nm, PEM_STRING_X509) &&
215 !strcmp(name, PEM_STRING_PKCS7)) return 1;
216
217 return 0;
218}
219
220int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
221 pem_password_cb *cb, void *u)
222 {
223 EVP_CIPHER_INFO cipher;
224 char *nm=NULL,*header=NULL;
225 unsigned char *data=NULL;
226 long len;
227 int ret = 0;
228
229 for (;;)
230 {
231 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) {
232 if(ERR_GET_REASON(ERR_peek_error()) ==
233 PEM_R_NO_START_LINE)
234 ERR_add_error_data(2, "Expecting: ", name);
235 return 0;
236 }
237 if(check_pem(nm, name)) break;
238 OPENSSL_free(nm);
239 OPENSSL_free(header);
240 OPENSSL_free(data);
241 }
242 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
243 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
244
245 *pdata = data;
246 *plen = len;
247
248 if (pnm)
249 *pnm = nm;
250
251 ret = 1;
252
253err:
254 if (!ret || !pnm) OPENSSL_free(nm);
255 OPENSSL_free(header);
256 if (!ret) OPENSSL_free(data);
257 return ret;
258 }
259
260#ifndef OPENSSL_NO_FP_API
261int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
262 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
263 pem_password_cb *callback, void *u)
264 {
265 BIO *b;
266 int ret;
267
268 if ((b=BIO_new(BIO_s_file())) == NULL)
269 {
270 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
271 return(0);
272 }
273 BIO_set_fp(b,fp,BIO_NOCLOSE);
274 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
275 BIO_free(b);
276 return(ret);
277 }
278#endif
279
280int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
281 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
282 pem_password_cb *callback, void *u)
283 {
284 EVP_CIPHER_CTX ctx;
285 int dsize=0,i,j,ret=0;
286 unsigned char *p,*data=NULL;
287 const char *objstr=NULL;
288 char buf[PEM_BUFSIZE];
289 unsigned char key[EVP_MAX_KEY_LENGTH];
290 unsigned char iv[EVP_MAX_IV_LENGTH];
291
292 if (enc != NULL)
293 {
294 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
295 if (objstr == NULL)
296 {
297 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
298 goto err;
299 }
300 }
301
302 if ((dsize=i2d(x,NULL)) < 0)
303 {
304 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_ASN1_LIB);
305 dsize=0;
306 goto err;
307 }
308 /* dzise + 8 bytes are needed */
309 /* actually it needs the cipher block size extra... */
310 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20);
311 if (data == NULL)
312 {
313 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
314 goto err;
315 }
316 p=data;
317 i=i2d(x,&p);
318
319 if (enc != NULL)
320 {
321 if (kstr == NULL)
322 {
323 if (callback == NULL)
324 klen=PEM_def_callback(buf,PEM_BUFSIZE,1,u);
325 else
326 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
327 if (klen <= 0)
328 {
329 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
330 goto err;
331 }
332#ifdef CHARSET_EBCDIC
333 /* Convert the pass phrase from EBCDIC */
334 ebcdic2ascii(buf, buf, klen);
335#endif
336 kstr=(unsigned char *)buf;
337 }
338 RAND_add(data,i,0);/* put in the RSA key. */
339 OPENSSL_assert(enc->iv_len <= sizeof iv);
340 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
341 goto err;
342 /* The 'iv' is used as the iv and as a salt. It is
343 * NOT taken from the BytesToKey function */
344 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
345
346 if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE);
347
348 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
349
350 buf[0]='\0';
351 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
352 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
353 /* k=strlen(buf); */
354
355 EVP_CIPHER_CTX_init(&ctx);
356 EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv);
357 EVP_EncryptUpdate(&ctx,data,&j,data,i);
358 EVP_EncryptFinal_ex(&ctx,&(data[j]),&i);
359 EVP_CIPHER_CTX_cleanup(&ctx);
360 i+=j;
361 ret=1;
362 }
363 else
364 {
365 ret=1;
366 buf[0]='\0';
367 }
368 i=PEM_write_bio(bp,name,buf,data,i);
369 if (i <= 0) ret=0;
370err:
371 OPENSSL_cleanse(key,sizeof(key));
372 OPENSSL_cleanse(iv,sizeof(iv));
373 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
374 OPENSSL_cleanse(buf,PEM_BUFSIZE);
375 if (data != NULL)
376 {
377 OPENSSL_cleanse(data,(unsigned int)dsize);
378 OPENSSL_free(data);
379 }
380 return(ret);
381 }
382
383int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
384 pem_password_cb *callback,void *u)
385 {
386 int i,j,o,klen;
387 long len;
388 EVP_CIPHER_CTX ctx;
389 unsigned char key[EVP_MAX_KEY_LENGTH];
390 char buf[PEM_BUFSIZE];
391
392 len= *plen;
393
394 if (cipher->cipher == NULL) return(1);
395 if (callback == NULL)
396 klen=PEM_def_callback(buf,PEM_BUFSIZE,0,u);
397 else
398 klen=callback(buf,PEM_BUFSIZE,0,u);
399 if (klen <= 0)
400 {
401 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
402 return(0);
403 }
404#ifdef CHARSET_EBCDIC
405 /* Convert the pass phrase from EBCDIC */
406 ebcdic2ascii(buf, buf, klen);
407#endif
408
409 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
410 (unsigned char *)buf,klen,1,key,NULL);
411
412 j=(int)len;
413 EVP_CIPHER_CTX_init(&ctx);
414 EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0]));
415 EVP_DecryptUpdate(&ctx,data,&i,data,j);
416 o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j);
417 EVP_CIPHER_CTX_cleanup(&ctx);
418 OPENSSL_cleanse((char *)buf,sizeof(buf));
419 OPENSSL_cleanse((char *)key,sizeof(key));
420 j+=i;
421 if (!o)
422 {
423 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
424 return(0);
425 }
426 *plen=j;
427 return(1);
428 }
429
430int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
431 {
432 int o;
433 const EVP_CIPHER *enc=NULL;
434 char *p,c;
435 char **header_pp = &header;
436
437 cipher->cipher=NULL;
438 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
439 return(1);
440 if (strncmp(header,"Proc-Type: ",11) != 0)
441 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
442 header+=11;
443 if (*header != '4') return(0); header++;
444 if (*header != ',') return(0); header++;
445 if (strncmp(header,"ENCRYPTED",9) != 0)
446 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
447 for (; (*header != '\n') && (*header != '\0'); header++)
448 ;
449 if (*header == '\0')
450 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
451 header++;
452 if (strncmp(header,"DEK-Info: ",10) != 0)
453 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
454 header+=10;
455
456 p=header;
457 for (;;)
458 {
459 c= *header;
460#ifndef CHARSET_EBCDIC
461 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
462 ((c >= '0') && (c <= '9'))))
463 break;
464#else
465 if (!( isupper(c) || (c == '-') ||
466 isdigit(c)))
467 break;
468#endif
469 header++;
470 }
471 *header='\0';
472 o=OBJ_sn2nid(p);
473 cipher->cipher=enc=EVP_get_cipherbyname(p);
474 *header=c;
475 header++;
476
477 if (enc == NULL)
478 {
479 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
480 return(0);
481 }
482 if (!load_iv(header_pp,&(cipher->iv[0]),enc->iv_len))
483 return(0);
484
485 return(1);
486 }
487
488static int load_iv(char **fromp, unsigned char *to, int num)
489 {
490 int v,i;
491 char *from;
492
493 from= *fromp;
494 for (i=0; i<num; i++) to[i]=0;
495 num*=2;
496 for (i=0; i<num; i++)
497 {
498 if ((*from >= '0') && (*from <= '9'))
499 v= *from-'0';
500 else if ((*from >= 'A') && (*from <= 'F'))
501 v= *from-'A'+10;
502 else if ((*from >= 'a') && (*from <= 'f'))
503 v= *from-'a'+10;
504 else
505 {
506 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
507 return(0);
508 }
509 from++;
510 to[i/2]|=v<<(long)((!(i&1))*4);
511 }
512
513 *fromp=from;
514 return(1);
515 }
516
517#ifndef OPENSSL_NO_FP_API
518int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
519 long len)
520 {
521 BIO *b;
522 int ret;
523
524 if ((b=BIO_new(BIO_s_file())) == NULL)
525 {
526 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
527 return(0);
528 }
529 BIO_set_fp(b,fp,BIO_NOCLOSE);
530 ret=PEM_write_bio(b, name, header, data,len);
531 BIO_free(b);
532 return(ret);
533 }
534#endif
535
536int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
537 long len)
538 {
539 int nlen,n,i,j,outl;
540 unsigned char *buf = NULL;
541 EVP_ENCODE_CTX ctx;
542 int reason=ERR_R_BUF_LIB;
543
544 EVP_EncodeInit(&ctx);
545 nlen=strlen(name);
546
547 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
548 (BIO_write(bp,name,nlen) != nlen) ||
549 (BIO_write(bp,"-----\n",6) != 6))
550 goto err;
551
552 i=strlen(header);
553 if (i > 0)
554 {
555 if ( (BIO_write(bp,header,i) != i) ||
556 (BIO_write(bp,"\n",1) != 1))
557 goto err;
558 }
559
560 buf = OPENSSL_malloc(PEM_BUFSIZE*8);
561 if (buf == NULL)
562 {
563 reason=ERR_R_MALLOC_FAILURE;
564 goto err;
565 }
566
567 i=j=0;
568 while (len > 0)
569 {
570 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
571 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
572 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
573 goto err;
574 i+=outl;
575 len-=n;
576 j+=n;
577 }
578 EVP_EncodeFinal(&ctx,buf,&outl);
579 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
580 OPENSSL_free(buf);
581 buf = NULL;
582 if ( (BIO_write(bp,"-----END ",9) != 9) ||
583 (BIO_write(bp,name,nlen) != nlen) ||
584 (BIO_write(bp,"-----\n",6) != 6))
585 goto err;
586 return(i+outl);
587err:
588 if (buf)
589 OPENSSL_free(buf);
590 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
591 return(0);
592 }
593
594#ifndef OPENSSL_NO_FP_API
595int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
596 long *len)
597 {
598 BIO *b;
599 int ret;
600
601 if ((b=BIO_new(BIO_s_file())) == NULL)
602 {
603 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
604 return(0);
605 }
606 BIO_set_fp(b,fp,BIO_NOCLOSE);
607 ret=PEM_read_bio(b, name, header, data,len);
608 BIO_free(b);
609 return(ret);
610 }
611#endif
612
613int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
614 long *len)
615 {
616 EVP_ENCODE_CTX ctx;
617 int end=0,i,k,bl=0,hl=0,nohead=0;
618 char buf[256];
619 BUF_MEM *nameB;
620 BUF_MEM *headerB;
621 BUF_MEM *dataB,*tmpB;
622
623 nameB=BUF_MEM_new();
624 headerB=BUF_MEM_new();
625 dataB=BUF_MEM_new();
626 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
627 {
628 BUF_MEM_free(nameB);
629 BUF_MEM_free(headerB);
630 BUF_MEM_free(dataB);
631 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
632 return(0);
633 }
634
635 buf[254]='\0';
636 for (;;)
637 {
638 i=BIO_gets(bp,buf,254);
639
640 if (i <= 0)
641 {
642 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
643 goto err;
644 }
645
646 while ((i >= 0) && (buf[i] <= ' ')) i--;
647 buf[++i]='\n'; buf[++i]='\0';
648
649 if (strncmp(buf,"-----BEGIN ",11) == 0)
650 {
651 i=strlen(&(buf[11]));
652
653 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
654 continue;
655 if (!BUF_MEM_grow(nameB,i+9))
656 {
657 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
658 goto err;
659 }
660 memcpy(nameB->data,&(buf[11]),i-6);
661 nameB->data[i-6]='\0';
662 break;
663 }
664 }
665 hl=0;
666 if (!BUF_MEM_grow(headerB,256))
667 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
668 headerB->data[0]='\0';
669 for (;;)
670 {
671 i=BIO_gets(bp,buf,254);
672 if (i <= 0) break;
673
674 while ((i >= 0) && (buf[i] <= ' ')) i--;
675 buf[++i]='\n'; buf[++i]='\0';
676
677 if (buf[0] == '\n') break;
678 if (!BUF_MEM_grow(headerB,hl+i+9))
679 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
680 if (strncmp(buf,"-----END ",9) == 0)
681 {
682 nohead=1;
683 break;
684 }
685 memcpy(&(headerB->data[hl]),buf,i);
686 headerB->data[hl+i]='\0';
687 hl+=i;
688 }
689
690 bl=0;
691 if (!BUF_MEM_grow(dataB,1024))
692 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
693 dataB->data[0]='\0';
694 if (!nohead)
695 {
696 for (;;)
697 {
698 i=BIO_gets(bp,buf,254);
699 if (i <= 0) break;
700
701 while ((i >= 0) && (buf[i] <= ' ')) i--;
702 buf[++i]='\n'; buf[++i]='\0';
703
704 if (i != 65) end=1;
705 if (strncmp(buf,"-----END ",9) == 0)
706 break;
707 if (i > 65) break;
708 if (!BUF_MEM_grow_clean(dataB,i+bl+9))
709 {
710 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
711 goto err;
712 }
713 memcpy(&(dataB->data[bl]),buf,i);
714 dataB->data[bl+i]='\0';
715 bl+=i;
716 if (end)
717 {
718 buf[0]='\0';
719 i=BIO_gets(bp,buf,254);
720 if (i <= 0) break;
721
722 while ((i >= 0) && (buf[i] <= ' ')) i--;
723 buf[++i]='\n'; buf[++i]='\0';
724
725 break;
726 }
727 }
728 }
729 else
730 {
731 tmpB=headerB;
732 headerB=dataB;
733 dataB=tmpB;
734 bl=hl;
735 }
736 i=strlen(nameB->data);
737 if ( (strncmp(buf,"-----END ",9) != 0) ||
738 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
739 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
740 {
741 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
742 goto err;
743 }
744
745 EVP_DecodeInit(&ctx);
746 i=EVP_DecodeUpdate(&ctx,
747 (unsigned char *)dataB->data,&bl,
748 (unsigned char *)dataB->data,bl);
749 if (i < 0)
750 {
751 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
752 goto err;
753 }
754 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
755 if (i < 0)
756 {
757 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
758 goto err;
759 }
760 bl+=k;
761
762 if (bl == 0) goto err;
763 *name=nameB->data;
764 *header=headerB->data;
765 *data=(unsigned char *)dataB->data;
766 *len=bl;
767 OPENSSL_free(nameB);
768 OPENSSL_free(headerB);
769 OPENSSL_free(dataB);
770 return(1);
771err:
772 BUF_MEM_free(nameB);
773 BUF_MEM_free(headerB);
774 BUF_MEM_free(dataB);
775 return(0);
776 }
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c
new file mode 100644
index 0000000000..8d9064ea7c
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_oth.c
@@ -0,0 +1,85 @@
1/* crypto/pem/pem_oth.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68/* Handle 'other' PEMs: not private keys */
69
70char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
71 pem_password_cb *cb, void *u)
72 {
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 char *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
78 return NULL;
79 p = data;
80 ret=d2i(x,&p,len);
81 if (ret == NULL)
82 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
83 OPENSSL_free(data);
84 return(ret);
85 }
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
new file mode 100644
index 0000000000..db38a2a79d
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_pk8.c
@@ -0,0 +1,243 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
70 int nid, const EVP_CIPHER *enc,
71 char *kstr, int klen,
72 pem_password_cb *cb, void *u);
73static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
74 int nid, const EVP_CIPHER *enc,
75 char *kstr, int klen,
76 pem_password_cb *cb, void *u);
77
78/* These functions write a private key in PKCS#8 format: it is a "drop in"
79 * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
80 * is NULL then it uses the unencrypted private key form. The 'nid' versions
81 * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
82 */
83
84int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
85 char *kstr, int klen,
86 pem_password_cb *cb, void *u)
87{
88 return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
89}
90
91int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
92 char *kstr, int klen,
93 pem_password_cb *cb, void *u)
94{
95 return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
96}
97
98int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
99 char *kstr, int klen,
100 pem_password_cb *cb, void *u)
101{
102 return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
103}
104
105int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
106 char *kstr, int klen,
107 pem_password_cb *cb, void *u)
108{
109 return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
110}
111
112static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
113 char *kstr, int klen,
114 pem_password_cb *cb, void *u)
115{
116 X509_SIG *p8;
117 PKCS8_PRIV_KEY_INFO *p8inf;
118 char buf[PEM_BUFSIZE];
119 int ret;
120 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
121 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
122 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
123 return 0;
124 }
125 if(enc || (nid != -1)) {
126 if(!kstr) {
127 if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
128 else klen = cb(buf, PEM_BUFSIZE, 1, u);
129 if(klen <= 0) {
130 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
131 PEM_R_READ_KEY);
132 PKCS8_PRIV_KEY_INFO_free(p8inf);
133 return 0;
134 }
135
136 kstr = buf;
137 }
138 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
139 if(kstr == buf) OPENSSL_cleanse(buf, klen);
140 PKCS8_PRIV_KEY_INFO_free(p8inf);
141 if(isder) ret = i2d_PKCS8_bio(bp, p8);
142 else ret = PEM_write_bio_PKCS8(bp, p8);
143 X509_SIG_free(p8);
144 return ret;
145 } else {
146 if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
147 else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
148 PKCS8_PRIV_KEY_INFO_free(p8inf);
149 return ret;
150 }
151}
152
153EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
154{
155 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
156 X509_SIG *p8 = NULL;
157 int klen;
158 EVP_PKEY *ret;
159 char psbuf[PEM_BUFSIZE];
160 p8 = d2i_PKCS8_bio(bp, NULL);
161 if(!p8) return NULL;
162 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
163 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
164 if (klen <= 0) {
165 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
166 X509_SIG_free(p8);
167 return NULL;
168 }
169 p8inf = PKCS8_decrypt(p8, psbuf, klen);
170 X509_SIG_free(p8);
171 if(!p8inf) return NULL;
172 ret = EVP_PKCS82PKEY(p8inf);
173 PKCS8_PRIV_KEY_INFO_free(p8inf);
174 if(!ret) return NULL;
175 if(x) {
176 if(*x) EVP_PKEY_free(*x);
177 *x = ret;
178 }
179 return ret;
180}
181
182#ifndef OPENSSL_NO_FP_API
183
184int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
185 char *kstr, int klen,
186 pem_password_cb *cb, void *u)
187{
188 return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
189}
190
191int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
192 char *kstr, int klen,
193 pem_password_cb *cb, void *u)
194{
195 return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
196}
197
198int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
199 char *kstr, int klen,
200 pem_password_cb *cb, void *u)
201{
202 return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
203}
204
205int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
206 char *kstr, int klen, pem_password_cb *cb, void *u)
207{
208 return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
209}
210
211static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
212 char *kstr, int klen,
213 pem_password_cb *cb, void *u)
214{
215 BIO *bp;
216 int ret;
217 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
218 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
219 return(0);
220 }
221 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
222 BIO_free(bp);
223 return ret;
224}
225
226EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
227{
228 BIO *bp;
229 EVP_PKEY *ret;
230 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
231 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
232 return NULL;
233 }
234 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
235 BIO_free(bp);
236 return ret;
237}
238
239#endif
240
241IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
242IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
243 PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
new file mode 100644
index 0000000000..9ecdbd5419
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -0,0 +1,145 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69
70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
71 {
72 char *nm=NULL;
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 EVP_PKEY *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
78 return NULL;
79 p = data;
80
81 if (strcmp(nm,PEM_STRING_RSA) == 0)
82 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
83 else if (strcmp(nm,PEM_STRING_DSA) == 0)
84 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
85 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
86 PKCS8_PRIV_KEY_INFO *p8inf;
87 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
88 if(!p8inf) goto p8err;
89 ret = EVP_PKCS82PKEY(p8inf);
90 if(x) {
91 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
92 *x = ret;
93 }
94 PKCS8_PRIV_KEY_INFO_free(p8inf);
95 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
96 PKCS8_PRIV_KEY_INFO *p8inf;
97 X509_SIG *p8;
98 int klen;
99 char psbuf[PEM_BUFSIZE];
100 p8 = d2i_X509_SIG(NULL, &p, len);
101 if(!p8) goto p8err;
102 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
103 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
104 if (klen <= 0) {
105 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
106 PEM_R_BAD_PASSWORD_READ);
107 X509_SIG_free(p8);
108 goto err;
109 }
110 p8inf = PKCS8_decrypt(p8, psbuf, klen);
111 X509_SIG_free(p8);
112 if(!p8inf) goto p8err;
113 ret = EVP_PKCS82PKEY(p8inf);
114 if(x) {
115 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
116 *x = ret;
117 }
118 PKCS8_PRIV_KEY_INFO_free(p8inf);
119 }
120p8err:
121 if (ret == NULL)
122 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
123err:
124 OPENSSL_free(nm);
125 OPENSSL_free(data);
126 return(ret);
127 }
128
129#ifndef OPENSSL_NO_FP_API
130EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
131 {
132 BIO *b;
133 EVP_PKEY *ret;
134
135 if ((b=BIO_new(BIO_s_file())) == NULL)
136 {
137 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
138 return(0);
139 }
140 BIO_set_fp(b,fp,BIO_NOCLOSE);
141 ret=PEM_read_bio_PrivateKey(b,x,cb,u);
142 BIO_free(b);
143 return(ret);
144 }
145#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
new file mode 100644
index 0000000000..56e08abd70
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -0,0 +1,187 @@
1/* crypto/pem/pem_seal.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/rand.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
69 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
70 int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int ret= -1;
74 int i,j,max=0;
75 char *s=NULL;
76
77 for (i=0; i<npubk; i++)
78 {
79 if (pubk[i]->type != EVP_PKEY_RSA)
80 {
81 PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA);
82 goto err;
83 }
84 j=RSA_size(pubk[i]->pkey.rsa);
85 if (j > max) max=j;
86 }
87 s=(char *)OPENSSL_malloc(max*2);
88 if (s == NULL)
89 {
90 PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93
94 EVP_EncodeInit(&ctx->encode);
95
96 EVP_MD_CTX_init(&ctx->md);
97 EVP_SignInit(&ctx->md,md_type);
98
99 EVP_CIPHER_CTX_init(&ctx->cipher);
100 ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk);
101 if (!ret) goto err;
102
103 /* base64 encode the keys */
104 for (i=0; i<npubk; i++)
105 {
106 j=EVP_EncodeBlock((unsigned char *)s,ek[i],
107 RSA_size(pubk[i]->pkey.rsa));
108 ekl[i]=j;
109 memcpy(ek[i],s,j+1);
110 }
111
112 ret=npubk;
113err:
114 if (s != NULL) OPENSSL_free(s);
115 OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH);
116 return(ret);
117 }
118
119void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
120 unsigned char *in, int inl)
121 {
122 unsigned char buffer[1600];
123 int i,j;
124
125 *outl=0;
126 EVP_SignUpdate(&ctx->md,in,inl);
127 for (;;)
128 {
129 if (inl <= 0) break;
130 if (inl > 1200)
131 i=1200;
132 else
133 i=inl;
134 EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i);
135 EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j);
136 *outl+=j;
137 out+=j;
138 in+=i;
139 inl-=i;
140 }
141 }
142
143int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
144 unsigned char *out, int *outl, EVP_PKEY *priv)
145 {
146 unsigned char *s=NULL;
147 int ret=0,j;
148 unsigned int i;
149
150 if (priv->type != EVP_PKEY_RSA)
151 {
152 PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA);
153 goto err;
154 }
155 i=RSA_size(priv->pkey.rsa);
156 if (i < 100) i=100;
157 s=(unsigned char *)OPENSSL_malloc(i*2);
158 if (s == NULL)
159 {
160 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
161 goto err;
162 }
163
164 EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i);
165 EVP_EncodeUpdate(&ctx->encode,out,&j,s,i);
166 *outl=j;
167 out+=j;
168 EVP_EncodeFinal(&ctx->encode,out,&j);
169 *outl+=j;
170
171 if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err;
172 *sigl=EVP_EncodeBlock(sig,s,i);
173
174 ret=1;
175err:
176 EVP_MD_CTX_cleanup(&ctx->md);
177 EVP_CIPHER_CTX_cleanup(&ctx->cipher);
178 if (s != NULL) OPENSSL_free(s);
179 return(ret);
180 }
181#else /* !OPENSSL_NO_RSA */
182
183# if PEDANTIC
184static void *dummy=&dummy;
185# endif
186
187#endif
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
new file mode 100644
index 0000000000..c3b9808cb2
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_sign.c
@@ -0,0 +1,102 @@
1/* crypto/pem/pem_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
67void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
68 {
69 EVP_DigestInit_ex(ctx, type, NULL);
70 }
71
72void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
73 unsigned int count)
74 {
75 EVP_DigestUpdate(ctx,data,count);
76 }
77
78int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char *m;
82 int i,ret=0;
83 unsigned int m_len;
84
85 m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2);
86 if (m == NULL)
87 {
88 PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
89 goto err;
90 }
91
92 if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err;
93
94 i=EVP_EncodeBlock(sigret,m,m_len);
95 *siglen=i;
96 ret=1;
97err:
98 /* ctx has been zeroed by EVP_SignFinal() */
99 if (m != NULL) OPENSSL_free(m);
100 return(ret);
101 }
102
diff --git a/src/lib/libcrypto/pem/pem_x509.c b/src/lib/libcrypto/pem/pem_x509.c
new file mode 100644
index 0000000000..19f88d8d3a
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_x509.c
@@ -0,0 +1,69 @@
1/* pem_x509.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69
diff --git a/src/lib/libcrypto/pem/pem_xaux.c b/src/lib/libcrypto/pem/pem_xaux.c
new file mode 100644
index 0000000000..2f579b5421
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem_xaux.c
@@ -0,0 +1,68 @@
1/* pem_xaux.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
diff --git a/src/lib/libcrypto/pem/pkcs7.lis b/src/lib/libcrypto/pem/pkcs7.lis
new file mode 100644
index 0000000000..be90c5d87f
--- /dev/null
+++ b/src/lib/libcrypto/pem/pkcs7.lis
@@ -0,0 +1,22 @@
121 0:d=0 hl=2 l= 0 cons: univ: SEQUENCE
2 00 2:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-signedData
3 21 13:d=0 hl=2 l= 0 cons: cont: 00 # explicit tag
4 21 15:d=0 hl=2 l= 0 cons: univ: SEQUENCE
5 00 17:d=0 hl=2 l= 1 prim: univ: INTEGER # version
6 20 20:d=0 hl=2 l= 0 cons: univ: SET
7 21 22:d=0 hl=2 l= 0 cons: univ: SEQUENCE
8 00 24:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-data
9 00 35:d=0 hl=2 l= 0 prim: univ: EOC
10 21 37:d=0 hl=2 l= 0 cons: cont: 00 # cert tag
11 20 39:d=0 hl=4 l=545 cons: univ: SEQUENCE
12 20 588:d=0 hl=4 l=524 cons: univ: SEQUENCE
13 00 1116:d=0 hl=2 l= 0 prim: univ: EOC
14 21 1118:d=0 hl=2 l= 0 cons: cont: 01 # crl tag
15 20 1120:d=0 hl=4 l=653 cons: univ: SEQUENCE
16 20 1777:d=0 hl=4 l=285 cons: univ: SEQUENCE
17 00 2066:d=0 hl=2 l= 0 prim: univ: EOC
18 21 2068:d=0 hl=2 l= 0 cons: univ: SET # signers
19 00 2070:d=0 hl=2 l= 0 prim: univ: EOC
20 00 2072:d=0 hl=2 l= 0 prim: univ: EOC
21 00 2074:d=0 hl=2 l= 0 prim: univ: EOC
2200 2076:d=0 hl=2 l= 0 prim: univ: EOC
diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl
new file mode 100644
index 0000000000..22149c680e
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/cbc.pl
@@ -0,0 +1,349 @@
1#!/usr/local/bin/perl
2
3# void des_ncbc_encrypt(input, output, length, schedule, ivec, enc)
4# des_cblock (*input);
5# des_cblock (*output);
6# long length;
7# des_key_schedule schedule;
8# des_cblock (*ivec);
9# int enc;
10#
11# calls
12# des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
13#
14
15#&cbc("des_ncbc_encrypt","des_encrypt",0);
16#&cbc("BF_cbc_encrypt","BF_encrypt","BF_encrypt",
17# 1,4,5,3,5,-1);
18#&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",
19# 0,4,5,3,5,-1);
20#&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",
21# 0,6,7,3,4,5);
22#
23# When doing a cipher that needs bigendian order,
24# for encrypt, the iv is kept in bigendian form,
25# while for decrypt, it is kept in little endian.
26sub cbc
27 {
28 local($name,$enc_func,$dec_func,$swap,$iv_off,$enc_off,$p1,$p2,$p3)=@_;
29 # name is the function name
30 # enc_func and dec_func and the functions to call for encrypt/decrypt
31 # swap is true if byte order needs to be reversed
32 # iv_off is parameter number for the iv
33 # enc_off is parameter number for the encrypt/decrypt flag
34 # p1,p2,p3 are the offsets for parameters to be passed to the
35 # underlying calls.
36
37 &function_begin_B($name,"");
38 &comment("");
39
40 $in="esi";
41 $out="edi";
42 $count="ebp";
43
44 &push("ebp");
45 &push("ebx");
46 &push("esi");
47 &push("edi");
48
49 $data_off=4;
50 $data_off+=4 if ($p1 > 0);
51 $data_off+=4 if ($p2 > 0);
52 $data_off+=4 if ($p3 > 0);
53
54 &mov($count, &wparam(2)); # length
55
56 &comment("getting iv ptr from parameter $iv_off");
57 &mov("ebx", &wparam($iv_off)); # Get iv ptr
58
59 &mov($in, &DWP(0,"ebx","",0));# iv[0]
60 &mov($out, &DWP(4,"ebx","",0));# iv[1]
61
62 &push($out);
63 &push($in);
64 &push($out); # used in decrypt for iv[1]
65 &push($in); # used in decrypt for iv[0]
66
67 &mov("ebx", "esp"); # This is the address of tin[2]
68
69 &mov($in, &wparam(0)); # in
70 &mov($out, &wparam(1)); # out
71
72 # We have loaded them all, how lets push things
73 &comment("getting encrypt flag from parameter $enc_off");
74 &mov("ecx", &wparam($enc_off)); # Get enc flag
75 if ($p3 > 0)
76 {
77 &comment("get and push parameter $p3");
78 if ($enc_off != $p3)
79 { &mov("eax", &wparam($p3)); &push("eax"); }
80 else { &push("ecx"); }
81 }
82 if ($p2 > 0)
83 {
84 &comment("get and push parameter $p2");
85 if ($enc_off != $p2)
86 { &mov("eax", &wparam($p2)); &push("eax"); }
87 else { &push("ecx"); }
88 }
89 if ($p1 > 0)
90 {
91 &comment("get and push parameter $p1");
92 if ($enc_off != $p1)
93 { &mov("eax", &wparam($p1)); &push("eax"); }
94 else { &push("ecx"); }
95 }
96 &push("ebx"); # push data/iv
97
98 &cmp("ecx",0);
99 &jz(&label("decrypt"));
100
101 &and($count,0xfffffff8);
102 &mov("eax", &DWP($data_off,"esp","",0)); # load iv[0]
103 &mov("ebx", &DWP($data_off+4,"esp","",0)); # load iv[1]
104
105 &jz(&label("encrypt_finish"));
106
107 #############################################################
108
109 &set_label("encrypt_loop");
110 # encrypt start
111 # "eax" and "ebx" hold iv (or the last cipher text)
112
113 &mov("ecx", &DWP(0,$in,"",0)); # load first 4 bytes
114 &mov("edx", &DWP(4,$in,"",0)); # second 4 bytes
115
116 &xor("eax", "ecx");
117 &xor("ebx", "edx");
118
119 &bswap("eax") if $swap;
120 &bswap("ebx") if $swap;
121
122 &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call
123 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
124
125 &call($enc_func);
126
127 &mov("eax", &DWP($data_off,"esp","",0));
128 &mov("ebx", &DWP($data_off+4,"esp","",0));
129
130 &bswap("eax") if $swap;
131 &bswap("ebx") if $swap;
132
133 &mov(&DWP(0,$out,"",0),"eax");
134 &mov(&DWP(4,$out,"",0),"ebx");
135
136 # eax and ebx are the next iv.
137
138 &add($in, 8);
139 &add($out, 8);
140
141 &sub($count, 8);
142 &jnz(&label("encrypt_loop"));
143
144###################################################################3
145 &set_label("encrypt_finish");
146 &mov($count, &wparam(2)); # length
147 &and($count, 7);
148 &jz(&label("finish"));
149 &call(&label("PIC_point"));
150&set_label("PIC_point");
151 &blindpop("edx");
152 &lea("ecx",&DWP(&label("cbc_enc_jmp_table")."-".&label("PIC_point"),"edx"));
153 &mov($count,&DWP(0,"ecx",$count,4))
154 &add($count,"edx");
155 &xor("ecx","ecx");
156 &xor("edx","edx");
157 #&mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4));
158 &jmp_ptr($count);
159
160&set_label("ej7");
161 &xor("edx", "edx") if $ppro; # ppro friendly
162 &movb(&HB("edx"), &BP(6,$in,"",0));
163 &shl("edx",8);
164&set_label("ej6");
165 &movb(&HB("edx"), &BP(5,$in,"",0));
166&set_label("ej5");
167 &movb(&LB("edx"), &BP(4,$in,"",0));
168&set_label("ej4");
169 &mov("ecx", &DWP(0,$in,"",0));
170 &jmp(&label("ejend"));
171&set_label("ej3");
172 &movb(&HB("ecx"), &BP(2,$in,"",0));
173 &xor("ecx", "ecx") if $ppro; # ppro friendly
174 &shl("ecx",8);
175&set_label("ej2");
176 &movb(&HB("ecx"), &BP(1,$in,"",0));
177&set_label("ej1");
178 &movb(&LB("ecx"), &BP(0,$in,"",0));
179&set_label("ejend");
180
181 &xor("eax", "ecx");
182 &xor("ebx", "edx");
183
184 &bswap("eax") if $swap;
185 &bswap("ebx") if $swap;
186
187 &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call
188 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
189
190 &call($enc_func);
191
192 &mov("eax", &DWP($data_off,"esp","",0));
193 &mov("ebx", &DWP($data_off+4,"esp","",0));
194
195 &bswap("eax") if $swap;
196 &bswap("ebx") if $swap;
197
198 &mov(&DWP(0,$out,"",0),"eax");
199 &mov(&DWP(4,$out,"",0),"ebx");
200
201 &jmp(&label("finish"));
202
203 #############################################################
204 #############################################################
205 &set_label("decrypt",1);
206 # decrypt start
207 &and($count,0xfffffff8);
208 # The next 2 instructions are only for if the jz is taken
209 &mov("eax", &DWP($data_off+8,"esp","",0)); # get iv[0]
210 &mov("ebx", &DWP($data_off+12,"esp","",0)); # get iv[1]
211 &jz(&label("decrypt_finish"));
212
213 &set_label("decrypt_loop");
214 &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes
215 &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes
216
217 &bswap("eax") if $swap;
218 &bswap("ebx") if $swap;
219
220 &mov(&DWP($data_off,"esp","",0), "eax"); # put back
221 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
222
223 &call($dec_func);
224
225 &mov("eax", &DWP($data_off,"esp","",0)); # get return
226 &mov("ebx", &DWP($data_off+4,"esp","",0)); #
227
228 &bswap("eax") if $swap;
229 &bswap("ebx") if $swap;
230
231 &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0]
232 &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1]
233
234 &xor("ecx", "eax");
235 &xor("edx", "ebx");
236
237 &mov("eax", &DWP(0,$in,"",0)); # get old cipher text,
238 &mov("ebx", &DWP(4,$in,"",0)); # next iv actually
239
240 &mov(&DWP(0,$out,"",0),"ecx");
241 &mov(&DWP(4,$out,"",0),"edx");
242
243 &mov(&DWP($data_off+8,"esp","",0), "eax"); # save iv
244 &mov(&DWP($data_off+12,"esp","",0), "ebx"); #
245
246 &add($in, 8);
247 &add($out, 8);
248
249 &sub($count, 8);
250 &jnz(&label("decrypt_loop"));
251############################ ENDIT #######################3
252 &set_label("decrypt_finish");
253 &mov($count, &wparam(2)); # length
254 &and($count, 7);
255 &jz(&label("finish"));
256
257 &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes
258 &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes
259
260 &bswap("eax") if $swap;
261 &bswap("ebx") if $swap;
262
263 &mov(&DWP($data_off,"esp","",0), "eax"); # put back
264 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
265
266 &call($dec_func);
267
268 &mov("eax", &DWP($data_off,"esp","",0)); # get return
269 &mov("ebx", &DWP($data_off+4,"esp","",0)); #
270
271 &bswap("eax") if $swap;
272 &bswap("ebx") if $swap;
273
274 &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0]
275 &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1]
276
277 &xor("ecx", "eax");
278 &xor("edx", "ebx");
279
280 # this is for when we exit
281 &mov("eax", &DWP(0,$in,"",0)); # get old cipher text,
282 &mov("ebx", &DWP(4,$in,"",0)); # next iv actually
283
284&set_label("dj7");
285 &rotr("edx", 16);
286 &movb(&BP(6,$out,"",0), &LB("edx"));
287 &shr("edx",16);
288&set_label("dj6");
289 &movb(&BP(5,$out,"",0), &HB("edx"));
290&set_label("dj5");
291 &movb(&BP(4,$out,"",0), &LB("edx"));
292&set_label("dj4");
293 &mov(&DWP(0,$out,"",0), "ecx");
294 &jmp(&label("djend"));
295&set_label("dj3");
296 &rotr("ecx", 16);
297 &movb(&BP(2,$out,"",0), &LB("ecx"));
298 &shl("ecx",16);
299&set_label("dj2");
300 &movb(&BP(1,$in,"",0), &HB("ecx"));
301&set_label("dj1");
302 &movb(&BP(0,$in,"",0), &LB("ecx"));
303&set_label("djend");
304
305 # final iv is still in eax:ebx
306 &jmp(&label("finish"));
307
308
309############################ FINISH #######################3
310 &set_label("finish",1);
311 &mov("ecx", &wparam($iv_off)); # Get iv ptr
312
313 #################################################
314 $total=16+4;
315 $total+=4 if ($p1 > 0);
316 $total+=4 if ($p2 > 0);
317 $total+=4 if ($p3 > 0);
318 &add("esp",$total);
319
320 &mov(&DWP(0,"ecx","",0), "eax"); # save iv
321 &mov(&DWP(4,"ecx","",0), "ebx"); # save iv
322
323 &function_end_A($name);
324
325 &set_label("cbc_enc_jmp_table",1);
326 &data_word("0");
327 &data_word(&label("ej1")."-".&label("PIC_point"));
328 &data_word(&label("ej2")."-".&label("PIC_point"));
329 &data_word(&label("ej3")."-".&label("PIC_point"));
330 &data_word(&label("ej4")."-".&label("PIC_point"));
331 &data_word(&label("ej5")."-".&label("PIC_point"));
332 &data_word(&label("ej6")."-".&label("PIC_point"));
333 &data_word(&label("ej7")."-".&label("PIC_point"));
334 # not used
335 #&set_label("cbc_dec_jmp_table",1);
336 #&data_word("0");
337 #&data_word(&label("dj1")."-".&label("PIC_point"));
338 #&data_word(&label("dj2")."-".&label("PIC_point"));
339 #&data_word(&label("dj3")."-".&label("PIC_point"));
340 #&data_word(&label("dj4")."-".&label("PIC_point"));
341 #&data_word(&label("dj5")."-".&label("PIC_point"));
342 #&data_word(&label("dj6")."-".&label("PIC_point"));
343 #&data_word(&label("dj7")."-".&label("PIC_point"));
344
345 &function_end_B($name);
346
347 }
348
3491;
diff --git a/src/lib/libcrypto/perlasm/readme b/src/lib/libcrypto/perlasm/readme
new file mode 100644
index 0000000000..f02bbee75a
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/readme
@@ -0,0 +1,124 @@
1The perl scripts in this directory are my 'hack' to generate
2multiple different assembler formats via the one origional script.
3
4The way to use this library is to start with adding the path to this directory
5and then include it.
6
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9
10The first thing we do is setup the file and type of assember
11
12&asm_init($ARGV[0],$0);
13
14The first argument is the 'type'. Currently
15'cpp', 'sol', 'a.out', 'elf' or 'win32'.
16Argument 2 is the file name.
17
18The reciprocal function is
19&asm_finish() which should be called at the end.
20
21There are 2 main 'packages'. x86ms.pl, which is the microsoft assembler,
22and x86unix.pl which is the unix (gas) version.
23
24Functions of interest are:
25&external_label("des_SPtrans"); declare and external variable
26&LB(reg); Low byte for a register
27&HB(reg); High byte for a register
28&BP(off,base,index,scale) Byte pointer addressing
29&DWP(off,base,index,scale) Word pointer addressing
30&stack_push(num) Basically a 'sub esp, num*4' with extra
31&stack_pop(num) inverse of stack_push
32&function_begin(name,extra) Start a function with pushing of
33 edi, esi, ebx and ebp. extra is extra win32
34 external info that may be required.
35&function_begin_B(name,extra) Same as norma function_begin but no pushing.
36&function_end(name) Call at end of function.
37&function_end_A(name) Standard pop and ret, for use inside functions
38&function_end_B(name) Call at end but with poping or 'ret'.
39&swtmp(num) Address on stack temp word.
40&wparam(num) Parameter number num, that was push
41 in C convention. This all works over pushes
42 and pops.
43&comment("hello there") Put in a comment.
44&label("loop") Refer to a label, normally a jmp target.
45&set_label("loop") Set a label at this point.
46&data_word(word) Put in a word of data.
47
48So how does this all hold together? Given
49
50int calc(int len, int *data)
51 {
52 int i,j=0;
53
54 for (i=0; i<len; i++)
55 {
56 j+=other(data[i]);
57 }
58 }
59
60So a very simple version of this function could be coded as
61
62 push(@INC,"perlasm","../../perlasm");
63 require "x86asm.pl";
64
65 &asm_init($ARGV[0],"cacl.pl");
66
67 &external_label("other");
68
69 $tmp1= "eax";
70 $j= "edi";
71 $data= "esi";
72 $i= "ebp";
73
74 &comment("a simple function");
75 &function_begin("calc");
76 &mov( $data, &wparam(1)); # data
77 &xor( $j, $j);
78 &xor( $i, $i);
79
80 &set_label("loop");
81 &cmp( $i, &wparam(0));
82 &jge( &label("end"));
83
84 &mov( $tmp1, &DWP(0,$data,$i,4));
85 &push( $tmp1);
86 &call( "other");
87 &add( $j, "eax");
88 &pop( $tmp1);
89 &inc( $i);
90 &jmp( &label("loop"));
91
92 &set_label("end");
93 &mov( "eax", $j);
94
95 &function_end("calc");
96
97 &asm_finish();
98
99The above example is very very unoptimised but gives an idea of how
100things work.
101
102There is also a cbc mode function generator in cbc.pl
103
104&cbc( $name,
105 $encrypt_function_name,
106 $decrypt_function_name,
107 $true_if_byte_swap_needed,
108 $parameter_number_for_iv,
109 $parameter_number_for_encrypt_flag,
110 $first_parameter_to_pass,
111 $second_parameter_to_pass,
112 $third_parameter_to_pass);
113
114So for example, given
115void BF_encrypt(BF_LONG *data,BF_KEY *key);
116void BF_decrypt(BF_LONG *data,BF_KEY *key);
117void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
118 BF_KEY *ks, unsigned char *iv, int enc);
119
120&cbc("BF_cbc_encrypt","BF_encrypt","BF_encrypt",1,4,5,3,-1,-1);
121
122&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1);
123&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5);
124
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl
new file mode 100644
index 0000000000..60233f80e8
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86asm.pl
@@ -0,0 +1,135 @@
1#!/usr/local/bin/perl
2
3# require 'x86asm.pl';
4# &asm_init("cpp","des-586.pl");
5# XXX
6# XXX
7# main'asm_finish
8
9sub main'asm_finish
10 {
11 &file_end();
12 &asm_finish_cpp() if $cpp;
13 print &asm_get_output();
14 }
15
16sub main'asm_init
17 {
18 ($type,$fn,$i386)=@_;
19 $filename=$fn;
20
21 $elf=$cpp=$sol=$aout=$win32=$gaswin=$openbsd=0;
22 if ( ($type eq "elf"))
23 { $elf=1; require "x86unix.pl"; }
24 elsif ( ($type eq "openbsd-elf"))
25 { $openbsd=$elf=1; require "x86unix.pl"; }
26 elsif ( ($type eq "openbsd-a.out"))
27 { $openbsd=1; require "x86unix.pl"; }
28 elsif ( ($type eq "a.out"))
29 { $aout=1; require "x86unix.pl"; }
30 elsif ( ($type eq "gaswin"))
31 { $gaswin=1; $aout=1; require "x86unix.pl"; }
32 elsif ( ($type eq "sol"))
33 { $sol=1; require "x86unix.pl"; }
34 elsif ( ($type eq "cpp"))
35 { $cpp=1; require "x86unix.pl"; }
36 elsif ( ($type eq "win32"))
37 { $win32=1; require "x86ms.pl"; }
38 elsif ( ($type eq "win32n"))
39 { $win32=1; require "x86nasm.pl"; }
40 else
41 {
42 print STDERR <<"EOF";
43Pick one target type from
44 elf - linux, FreeBSD etc
45 a.out - old linux
46 sol - x86 solaris
47 cpp - format so x86unix.cpp can be used
48 win32 - Windows 95/Windows NT
49 win32n - Windows 95/Windows NT NASM format
50 openbsd-elf - OpenBSD elf
51 openbsd-a.out - OpenBSD a.out
52EOF
53 exit(1);
54 }
55
56 $pic=0;
57 for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
58
59 &asm_init_output();
60
61&comment("Don't even think of reading this code");
62&comment("It was automatically generated by $filename");
63&comment("Which is a perl program used to generate the x86 assember for");
64&comment("any of elf, a.out, BSDI, Win32, gaswin (for GNU as on Win32) or Solaris");
65&comment("eric <eay\@cryptsoft.com>");
66&comment("");
67
68 $filename =~ s/\.pl$//;
69 &file($filename);
70 }
71
72sub asm_finish_cpp
73 {
74 return unless $cpp;
75
76 local($tmp,$i);
77 foreach $i (&get_labels())
78 {
79 $tmp.="#define $i _$i\n";
80 }
81 print <<"EOF";
82/* Run the C pre-processor over this file with one of the following defined
83 * ELF - elf object files,
84 * OUT - a.out object files,
85 * BSDI - BSDI style a.out object files
86 * SOL - Solaris style elf
87 */
88
89#define TYPE(a,b) .type a,b
90#define SIZE(a,b) .size a,b
91
92#if defined(OUT) || (defined(BSDI) && !defined(ELF))
93$tmp
94#endif
95
96#ifdef OUT
97#define OK 1
98#define ALIGN 4
99#if defined(__CYGWIN__) || defined(__DJGPP__)
100#undef SIZE
101#undef TYPE
102#define SIZE(a,b)
103#define TYPE(a,b) .def a; .scl 2; .type 32; .endef
104#endif /* __CYGWIN || __DJGPP */
105#endif
106
107#if defined(BSDI) && !defined(ELF)
108#define OK 1
109#define ALIGN 4
110#undef SIZE
111#undef TYPE
112#define SIZE(a,b)
113#define TYPE(a,b)
114#endif
115
116#if defined(ELF) || defined(SOL)
117#define OK 1
118#define ALIGN 16
119#endif
120
121#ifndef OK
122You need to define one of
123ELF - elf systems - linux-elf, NetBSD and DG-UX
124OUT - a.out systems - linux-a.out and FreeBSD
125SOL - solaris systems, which are elf with strange comment lines
126BSDI - a.out with a very primative version of as.
127#endif
128
129/* Let the Assembler begin :-) */
130EOF
131 }
132
133sub main'align() {} # swallow align statements in 0.9.7 context
134
1351;
diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl
index 4bdb3fe180..5009acb4b3 100644
--- a/src/lib/libcrypto/perlasm/x86nasm.pl
+++ b/src/lib/libcrypto/perlasm/x86nasm.pl
@@ -221,15 +221,7 @@ sub using486
221 221
222sub main'file 222sub main'file
223 { 223 {
224 local $tmp; 224 push(@out, "segment .text use32\n");
225 $tmp=<<___;
226%ifdef __omf__
227section code use32 class=code
228%else
229section .text
230%endif
231___
232 push(@out,$tmp);
233 } 225 }
234 226
235sub main'function_begin 227sub main'function_begin
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
index a31a25c12b..b61425e951 100644
--- a/src/lib/libcrypto/perlasm/x86unix.pl
+++ b/src/lib/libcrypto/perlasm/x86unix.pl
@@ -15,6 +15,12 @@ sub main'asm_get_output { return(@out); }
15sub main'get_labels { return(@labels); } 15sub main'get_labels { return(@labels); }
16sub main'external_label { push(@labels,@_); } 16sub main'external_label { push(@labels,@_); }
17 17
18if ($main'openbsd)
19 {
20 $com_start='/*';
21 $com_end='*/';
22 }
23
18if ($main'cpp) 24if ($main'cpp)
19 { 25 {
20 $align="ALIGN"; 26 $align="ALIGN";
@@ -173,7 +179,9 @@ sub main'not { &out1("notl",@_); }
173sub main'call { &out1("call",($_[0]=~/^\.L/?'':$under).$_[0]); } 179sub main'call { &out1("call",($_[0]=~/^\.L/?'':$under).$_[0]); }
174sub main'ret { &out0("ret"); } 180sub main'ret { &out0("ret"); }
175sub main'nop { &out0("nop"); } 181sub main'nop { &out0("nop"); }
182sub main'test { &out2("testl",@_); }
176sub main'movz { &out2("movzbl",@_); } 183sub main'movz { &out2("movzbl",@_); }
184sub main'neg { &out1("negl",@_); }
177 185
178# The bswapl instruction is new for the 486. Emulate if i386. 186# The bswapl instruction is new for the 486. Emulate if i386.
179sub main'bswap 187sub main'bswap
@@ -277,6 +285,9 @@ sub main'file
277 { 285 {
278 local($file)=@_; 286 local($file)=@_;
279 287
288 if ($main'openbsd)
289 { push(@out,"#include <machine/asm.h>\n"); return; }
290
280 local($tmp)=<<"EOF"; 291 local($tmp)=<<"EOF";
281 .file "$file.s" 292 .file "$file.s"
282 .version "01.01" 293 .version "01.01"
@@ -292,6 +303,9 @@ sub main'function_begin
292 &main'external_label($func); 303 &main'external_label($func);
293 $func=$under.$func; 304 $func=$under.$func;
294 305
306 if ($main'openbsd)
307 { push (@out, "\nENTRY($func)\n"); goto skip; }
308
295 local($tmp)=<<"EOF"; 309 local($tmp)=<<"EOF";
296.text 310.text
297 .align $align 311 .align $align
@@ -304,6 +318,7 @@ EOF
304 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } 318 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
305 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); } 319 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
306 push(@out,"$func:\n"); 320 push(@out,"$func:\n");
321skip:
307 $tmp=<<"EOF"; 322 $tmp=<<"EOF";
308 pushl %ebp 323 pushl %ebp
309 pushl %ebx 324 pushl %ebx
@@ -322,6 +337,9 @@ sub main'function_begin_B
322 &main'external_label($func); 337 &main'external_label($func);
323 $func=$under.$func; 338 $func=$under.$func;
324 339
340 if ($main'openbsd)
341 { push(@out, "\nENTRY($func)\n"); goto skip; }
342
325 local($tmp)=<<"EOF"; 343 local($tmp)=<<"EOF";
326.text 344.text
327 .align $align 345 .align $align
@@ -334,6 +352,7 @@ EOF
334 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } 352 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
335 else { push(@out,"\t.type $func,\@function\n"); } 353 else { push(@out,"\t.type $func,\@function\n"); }
336 push(@out,"$func:\n"); 354 push(@out,"$func:\n");
355skip:
337 $stack=4; 356 $stack=4;
338 } 357 }
339 358
@@ -430,7 +449,8 @@ sub main'swtmp
430 449
431sub main'comment 450sub main'comment
432 { 451 {
433 if ($main'elf) # GNU and SVR4 as'es use different comment delimiters, 452 if (!$main'openbsd && $main'elf)
453 # GNU and SVR4 as'es use different comment delimiters,
434 { # so we just skip comments... 454 { # so we just skip comments...
435 push(@out,"\n"); 455 push(@out,"\n");
436 return; 456 return;
@@ -444,6 +464,12 @@ sub main'comment
444 } 464 }
445 } 465 }
446 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
447sub main'label 473sub main'label
448 { 474 {
449 if (!defined($label{$_[0]})) 475 if (!defined($label{$_[0]}))
@@ -461,7 +487,10 @@ sub main'set_label
461 $label{$_[0]}=".${label}${_[0]}"; 487 $label{$_[0]}=".${label}${_[0]}";
462 $label++; 488 $label++;
463 } 489 }
464 push(@out,".align $align\n") if ($_[1] != 0); 490 if ($main'openbsd)
491 { push(@out,"_ALIGN_TEXT\n") if ($_[1] != 0); }
492 else
493 { push(@out,".align $align\n") if ($_[1] != 0); }
465 push(@out,"$label{$_[0]}:\n"); 494 push(@out,"$label{$_[0]}:\n");
466 } 495 }
467 496
@@ -477,7 +506,7 @@ sub main'file_end
477 506
478sub main'data_word 507sub main'data_word
479 { 508 {
480 push(@out,"\t.long $_[0]\n"); 509 push(@out,"\t.long\t".join(',',@_)."\n");
481 } 510 }
482 511
483# debug output functions: puts, putx, printf 512# debug output functions: puts, putx, printf
@@ -570,6 +599,16 @@ sub main'picmeup
570___ 599___
571 push(@out,$tmp); 600 push(@out,$tmp);
572 } 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 }
573 elsif ($main'pic && ($main'elf || $main'aout)) 612 elsif ($main'pic && ($main'elf || $main'aout))
574 { 613 {
575 push(@out,"\t.align\t8\n"); 614 push(@out,"\t.align\t8\n");
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
new file mode 100644
index 0000000000..1909f28506
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_add.c
@@ -0,0 +1,215 @@
1/* p12_add.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Pack an object into an OCTET STRING and turn into a safebag */
64
65PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1,
66 int nid2)
67{
68 PKCS12_BAGS *bag;
69 PKCS12_SAFEBAG *safebag;
70 if (!(bag = PKCS12_BAGS_new())) {
71 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
72 return NULL;
73 }
74 bag->type = OBJ_nid2obj(nid1);
75 if (!ASN1_item_pack(obj, it, &bag->value.octet)) {
76 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
77 return NULL;
78 }
79 if (!(safebag = PKCS12_SAFEBAG_new())) {
80 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
81 return NULL;
82 }
83 safebag->value.bag = bag;
84 safebag->type = OBJ_nid2obj(nid2);
85 return safebag;
86}
87
88/* Turn PKCS8 object into a keybag */
89
90PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
91{
92 PKCS12_SAFEBAG *bag;
93 if (!(bag = PKCS12_SAFEBAG_new())) {
94 PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 bag->type = OBJ_nid2obj(NID_keyBag);
98 bag->value.keybag = p8;
99 return bag;
100}
101
102/* Turn PKCS8 object into a shrouded keybag */
103
104PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
105 int passlen, unsigned char *salt, int saltlen, int iter,
106 PKCS8_PRIV_KEY_INFO *p8)
107{
108 PKCS12_SAFEBAG *bag;
109
110 /* Set up the safe bag */
111 if (!(bag = PKCS12_SAFEBAG_new())) {
112 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115
116 bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag);
117 if (!(bag->value.shkeybag =
118 PKCS8_encrypt(pbe_nid, NULL, pass, passlen, salt, saltlen, iter,
119 p8))) {
120 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123
124 return bag;
125}
126
127/* Turn a stack of SAFEBAGS into a PKCS#7 data Contentinfo */
128PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk)
129{
130 PKCS7 *p7;
131 if (!(p7 = PKCS7_new())) {
132 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
133 return NULL;
134 }
135 p7->type = OBJ_nid2obj(NID_pkcs7_data);
136 if (!(p7->d.data = M_ASN1_OCTET_STRING_new())) {
137 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
138 return NULL;
139 }
140
141 if (!ASN1_item_pack(sk, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), &p7->d.data)) {
142 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, PKCS12_R_CANT_PACK_STRUCTURE);
143 return NULL;
144 }
145 return p7;
146}
147
148/* Unpack SAFEBAGS from PKCS#7 data ContentInfo */
149STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7)
150{
151 if(!PKCS7_type_is_data(p7)) return NULL;
152 return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS));
153}
154
155/* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */
156
157PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
158 unsigned char *salt, int saltlen, int iter,
159 STACK_OF(PKCS12_SAFEBAG) *bags)
160{
161 PKCS7 *p7;
162 X509_ALGOR *pbe;
163 if (!(p7 = PKCS7_new())) {
164 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
165 return NULL;
166 }
167 if(!PKCS7_set_type(p7, NID_pkcs7_encrypted)) {
168 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA,
169 PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
170 return NULL;
171 }
172 if (!(pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen))) {
173 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
174 return NULL;
175 }
176 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
177 p7->d.encrypted->enc_data->algorithm = pbe;
178 M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
179 if (!(p7->d.encrypted->enc_data->enc_data =
180 PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), pass, passlen,
181 bags, 1))) {
182 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR);
183 return NULL;
184 }
185
186 return p7;
187}
188
189STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen)
190{
191 if(!PKCS7_type_is_encrypted(p7)) return NULL;
192 return PKCS12_item_decrypt_d2i(p7->d.encrypted->enc_data->algorithm,
193 ASN1_ITEM_rptr(PKCS12_SAFEBAGS),
194 pass, passlen,
195 p7->d.encrypted->enc_data->enc_data, 1);
196}
197
198PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass,
199 int passlen)
200{
201 return PKCS8_decrypt(bag->value.shkeybag, pass, passlen);
202}
203
204int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes)
205{
206 if(ASN1_item_pack(safes, ASN1_ITEM_rptr(PKCS12_AUTHSAFES),
207 &p12->authsafes->d.data))
208 return 1;
209 return 0;
210}
211
212STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12)
213{
214 return ASN1_item_unpack(p12->authsafes->d.data, ASN1_ITEM_rptr(PKCS12_AUTHSAFES));
215}
diff --git a/src/lib/libcrypto/pkcs12/p12_asn.c b/src/lib/libcrypto/pkcs12/p12_asn.c
new file mode 100644
index 0000000000..a3739fee1a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_asn.c
@@ -0,0 +1,125 @@
1/* p12_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs12.h>
63
64/* PKCS#12 ASN1 module */
65
66ASN1_SEQUENCE(PKCS12) = {
67 ASN1_SIMPLE(PKCS12, version, ASN1_INTEGER),
68 ASN1_SIMPLE(PKCS12, authsafes, PKCS7),
69 ASN1_OPT(PKCS12, mac, PKCS12_MAC_DATA)
70} ASN1_SEQUENCE_END(PKCS12)
71
72IMPLEMENT_ASN1_FUNCTIONS(PKCS12)
73
74ASN1_SEQUENCE(PKCS12_MAC_DATA) = {
75 ASN1_SIMPLE(PKCS12_MAC_DATA, dinfo, X509_SIG),
76 ASN1_SIMPLE(PKCS12_MAC_DATA, salt, ASN1_OCTET_STRING),
77 ASN1_OPT(PKCS12_MAC_DATA, iter, ASN1_INTEGER)
78} ASN1_SEQUENCE_END(PKCS12_MAC_DATA)
79
80IMPLEMENT_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
81
82ASN1_ADB_TEMPLATE(bag_default) = ASN1_EXP(PKCS12_BAGS, value.other, ASN1_ANY, 0);
83
84ASN1_ADB(PKCS12_BAGS) = {
85 ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509cert, ASN1_OCTET_STRING, 0)),
86 ADB_ENTRY(NID_x509Crl, ASN1_EXP(PKCS12_BAGS, value.x509crl, ASN1_OCTET_STRING, 0)),
87 ADB_ENTRY(NID_sdsiCertificate, ASN1_EXP(PKCS12_BAGS, value.sdsicert, ASN1_IA5STRING, 0)),
88} ASN1_ADB_END(PKCS12_BAGS, 0, type, 0, &bag_default_tt, NULL);
89
90ASN1_SEQUENCE(PKCS12_BAGS) = {
91 ASN1_SIMPLE(PKCS12_BAGS, type, ASN1_OBJECT),
92 ASN1_ADB_OBJECT(PKCS12_BAGS),
93} ASN1_SEQUENCE_END(PKCS12_BAGS)
94
95IMPLEMENT_ASN1_FUNCTIONS(PKCS12_BAGS)
96
97ASN1_ADB_TEMPLATE(safebag_default) = ASN1_EXP(PKCS12_SAFEBAG, value.other, ASN1_ANY, 0);
98
99ASN1_ADB(PKCS12_SAFEBAG) = {
100 ADB_ENTRY(NID_keyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, PKCS8_PRIV_KEY_INFO, 0)),
101 ADB_ENTRY(NID_pkcs8ShroudedKeyBag, ASN1_EXP(PKCS12_SAFEBAG, value.shkeybag, X509_SIG, 0)),
102 ADB_ENTRY(NID_safeContentsBag, ASN1_EXP_SET_OF(PKCS12_SAFEBAG, value.safes, PKCS12_SAFEBAG, 0)),
103 ADB_ENTRY(NID_certBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)),
104 ADB_ENTRY(NID_crlBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)),
105 ADB_ENTRY(NID_secretBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0))
106} ASN1_ADB_END(PKCS12_SAFEBAG, 0, type, 0, &safebag_default_tt, NULL);
107
108ASN1_SEQUENCE(PKCS12_SAFEBAG) = {
109 ASN1_SIMPLE(PKCS12_SAFEBAG, type, ASN1_OBJECT),
110 ASN1_ADB_OBJECT(PKCS12_SAFEBAG),
111 ASN1_SET_OF_OPT(PKCS12_SAFEBAG, attrib, X509_ATTRIBUTE)
112} ASN1_SEQUENCE_END(PKCS12_SAFEBAG)
113
114IMPLEMENT_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
115
116/* SEQUENCE OF SafeBag */
117ASN1_ITEM_TEMPLATE(PKCS12_SAFEBAGS) =
118 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_SAFEBAGS, PKCS12_SAFEBAG)
119ASN1_ITEM_TEMPLATE_END(PKCS12_SAFEBAGS)
120
121/* Authsafes: SEQUENCE OF PKCS7 */
122ASN1_ITEM_TEMPLATE(PKCS12_AUTHSAFES) =
123 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_AUTHSAFES, PKCS7)
124ASN1_ITEM_TEMPLATE_END(PKCS12_AUTHSAFES)
125
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
new file mode 100644
index 0000000000..026cf3826a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_attr.c
@@ -0,0 +1,145 @@
1/* p12_attr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Add a local keyid to a safebag */
64
65int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
66 int namelen)
67{
68 if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID,
69 V_ASN1_OCTET_STRING, name, namelen))
70 return 1;
71 else
72 return 0;
73}
74
75/* Add key usage to PKCS#8 structure */
76
77int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
78{
79 unsigned char us_val;
80 us_val = (unsigned char) usage;
81 if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage,
82 V_ASN1_BIT_STRING, &us_val, 1))
83 return 1;
84 else
85 return 0;
86}
87
88/* Add a friendlyname to a safebag */
89
90int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
91 int namelen)
92{
93 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
94 MBSTRING_ASC, (unsigned char *)name, namelen))
95 return 1;
96 else
97 return 0;
98}
99
100
101int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
102 const unsigned char *name, int namelen)
103{
104 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
105 MBSTRING_BMP, name, namelen))
106 return 1;
107 else
108 return 0;
109}
110
111int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
112 int namelen)
113{
114 if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name,
115 MBSTRING_ASC, (unsigned char *)name, namelen))
116 return 1;
117 else
118 return 0;
119}
120
121ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid)
122{
123 X509_ATTRIBUTE *attrib;
124 int i;
125 if (!attrs) return NULL;
126 for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) {
127 attrib = sk_X509_ATTRIBUTE_value (attrs, i);
128 if (OBJ_obj2nid (attrib->object) == attr_nid) {
129 if (sk_ASN1_TYPE_num (attrib->value.set))
130 return sk_ASN1_TYPE_value(attrib->value.set, 0);
131 else return NULL;
132 }
133 }
134 return NULL;
135}
136
137char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
138{
139 ASN1_TYPE *atype;
140 if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL;
141 if (atype->type != V_ASN1_BMPSTRING) return NULL;
142 return uni2asc(atype->value.bmpstring->data,
143 atype->value.bmpstring->length);
144}
145
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
new file mode 100644
index 0000000000..003ec7a33e
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_crpt.c
@@ -0,0 +1,124 @@
1/* p12_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* PKCS#12 specific PBE functions */
64
65void PKCS12_PBE_add(void)
66{
67#ifndef OPENSSL_NO_RC4
68EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(),
69 PKCS12_PBE_keyivgen);
70EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(),
71 PKCS12_PBE_keyivgen);
72#endif
73#ifndef OPENSSL_NO_DES
74EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
75 EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
76EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
77 EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
78#endif
79#ifndef OPENSSL_NO_RC2
80EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
81 EVP_sha1(), PKCS12_PBE_keyivgen);
82EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
83 EVP_sha1(), PKCS12_PBE_keyivgen);
84#endif
85}
86
87int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
88 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de)
89{
90 PBEPARAM *pbe;
91 int saltlen, iter, ret;
92 unsigned char *salt, *pbuf;
93 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
94
95 /* Extract useful info from parameter */
96 pbuf = param->value.sequence->data;
97 if (!param || (param->type != V_ASN1_SEQUENCE) ||
98 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
99 EVPerr(PKCS12_F_PKCS12_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
100 return 0;
101 }
102
103 if (!pbe->iter) iter = 1;
104 else iter = ASN1_INTEGER_get (pbe->iter);
105 salt = pbe->salt->data;
106 saltlen = pbe->salt->length;
107 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID,
108 iter, EVP_CIPHER_key_length(cipher), key, md)) {
109 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_KEY_GEN_ERROR);
110 PBEPARAM_free(pbe);
111 return 0;
112 }
113 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID,
114 iter, EVP_CIPHER_iv_length(cipher), iv, md)) {
115 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_IV_GEN_ERROR);
116 PBEPARAM_free(pbe);
117 return 0;
118 }
119 PBEPARAM_free(pbe);
120 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de);
121 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
122 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
123 return ret;
124}
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
new file mode 100644
index 0000000000..4c36c643ce
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_crt.c
@@ -0,0 +1,164 @@
1/* p12_crt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
64 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, int mac_iter,
65 int keytype)
66{
67 PKCS12 *p12;
68 STACK_OF(PKCS12_SAFEBAG) *bags;
69 STACK_OF(PKCS7) *safes;
70 PKCS12_SAFEBAG *bag;
71 PKCS8_PRIV_KEY_INFO *p8;
72 PKCS7 *authsafe;
73 X509 *tcert;
74 int i;
75 unsigned char keyid[EVP_MAX_MD_SIZE];
76 unsigned int keyidlen;
77
78 /* Set defaults */
79 if(!nid_cert) nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
80 if(!nid_key) nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
81 if(!iter) iter = PKCS12_DEFAULT_ITER;
82 if(!mac_iter) mac_iter = 1;
83
84 if(!pkey || !cert) {
85 PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT);
86 return NULL;
87 }
88
89 if(!X509_check_private_key(cert, pkey)) return NULL;
90
91 if(!(bags = sk_PKCS12_SAFEBAG_new_null ())) {
92 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
93 return NULL;
94 }
95
96 /* Add user certificate */
97 if(!(bag = PKCS12_x5092certbag(cert))) return NULL;
98 if(name && !PKCS12_add_friendlyname(bag, name, -1)) return NULL;
99 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
100 if(!PKCS12_add_localkeyid(bag, keyid, keyidlen)) return NULL;
101
102 if(!sk_PKCS12_SAFEBAG_push(bags, bag)) {
103 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
104 return NULL;
105 }
106
107 /* Add all other certificates */
108 if(ca) {
109 for(i = 0; i < sk_X509_num(ca); i++) {
110 tcert = sk_X509_value(ca, i);
111 if(!(bag = PKCS12_x5092certbag(tcert))) return NULL;
112 if(!sk_PKCS12_SAFEBAG_push(bags, bag)) {
113 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116 }
117 }
118
119 /* Turn certbags into encrypted authsafe */
120 authsafe = PKCS12_pack_p7encdata (nid_cert, pass, -1, NULL, 0,
121 iter, bags);
122 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
123
124 if (!authsafe) return NULL;
125
126 if(!(safes = sk_PKCS7_new_null ())
127 || !sk_PKCS7_push(safes, authsafe)) {
128 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
129 return NULL;
130 }
131
132 /* Make a shrouded key bag */
133 if(!(p8 = EVP_PKEY2PKCS8 (pkey))) return NULL;
134 if(keytype && !PKCS8_add_keyusage(p8, keytype)) return NULL;
135 bag = PKCS12_MAKE_SHKEYBAG (nid_key, pass, -1, NULL, 0, iter, p8);
136 if(!bag) return NULL;
137 PKCS8_PRIV_KEY_INFO_free(p8);
138 if (name && !PKCS12_add_friendlyname (bag, name, -1)) return NULL;
139 if(!PKCS12_add_localkeyid (bag, keyid, keyidlen)) return NULL;
140 if(!(bags = sk_PKCS12_SAFEBAG_new_null())
141 || !sk_PKCS12_SAFEBAG_push (bags, bag)) {
142 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
143 return NULL;
144 }
145 /* Turn it into unencrypted safe bag */
146 if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL;
147 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
148 if(!sk_PKCS7_push(safes, authsafe)) {
149 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
150 return NULL;
151 }
152
153 if(!(p12 = PKCS12_init (NID_pkcs7_data))) return NULL;
154
155 if(!PKCS12_pack_authsafes (p12, safes)) return NULL;
156
157 sk_PKCS7_pop_free(safes, PKCS7_free);
158
159 if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL))
160 return NULL;
161
162 return p12;
163
164}
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
new file mode 100644
index 0000000000..b5684a83ba
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_decr.c
@@ -0,0 +1,176 @@
1/* p12_decr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Define this to dump decrypted output to files called DERnnn */
64/*#define DEBUG_DECRYPT*/
65
66
67/* Encrypt/Decrypt a buffer based on password and algor, result in a
68 * OPENSSL_malloc'ed buffer
69 */
70
71unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
72 int passlen, unsigned char *in, int inlen, unsigned char **data,
73 int *datalen, int en_de)
74{
75 unsigned char *out;
76 int outlen, i;
77 EVP_CIPHER_CTX ctx;
78
79 EVP_CIPHER_CTX_init(&ctx);
80 /* Decrypt data */
81 if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen,
82 algor->parameter, &ctx, en_de)) {
83 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);
84 return NULL;
85 }
86
87 if(!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {
88 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);
89 goto err;
90 }
91
92 EVP_CipherUpdate(&ctx, out, &i, in, inlen);
93 outlen = i;
94 if(!EVP_CipherFinal_ex(&ctx, out + i, &i)) {
95 OPENSSL_free(out);
96 out = NULL;
97 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
98 goto err;
99 }
100 outlen += i;
101 if (datalen) *datalen = outlen;
102 if (data) *data = out;
103 err:
104 EVP_CIPHER_CTX_cleanup(&ctx);
105 return out;
106
107}
108
109/* Decrypt an OCTET STRING and decode ASN1 structure
110 * if zbuf set zero buffer after use.
111 */
112
113void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
114 const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf)
115{
116 unsigned char *out, *p;
117 void *ret;
118 int outlen;
119
120 if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length,
121 &out, &outlen, 0)) {
122 PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
123 return NULL;
124 }
125 p = out;
126#ifdef DEBUG_DECRYPT
127 {
128 FILE *op;
129
130 char fname[30];
131 static int fnm = 1;
132 sprintf(fname, "DER%d", fnm++);
133 op = fopen(fname, "wb");
134 fwrite (p, 1, outlen, op);
135 fclose(op);
136 }
137#endif
138 ret = ASN1_item_d2i(NULL, &p, outlen, it);
139 if (zbuf) OPENSSL_cleanse(out, outlen);
140 if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);
141 OPENSSL_free(out);
142 return ret;
143}
144
145/* Encode ASN1 structure and encrypt, return OCTET STRING
146 * if zbuf set zero encoding.
147 */
148
149ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
150 const char *pass, int passlen,
151 void *obj, int zbuf)
152{
153 ASN1_OCTET_STRING *oct;
154 unsigned char *in = NULL;
155 int inlen;
156 if (!(oct = M_ASN1_OCTET_STRING_new ())) {
157 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
158 return NULL;
159 }
160 inlen = ASN1_item_i2d(obj, &in, it);
161 if (!in) {
162 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR);
163 return NULL;
164 }
165 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data,
166 &oct->length, 1)) {
167 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR);
168 OPENSSL_free(in);
169 return NULL;
170 }
171 if (zbuf) OPENSSL_cleanse(in, inlen);
172 OPENSSL_free(in);
173 return oct;
174}
175
176IMPLEMENT_PKCS12_STACK_OF(PKCS7)
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c
new file mode 100644
index 0000000000..5276b12669
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_init.c
@@ -0,0 +1,92 @@
1/* p12_init.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Initialise a PKCS12 structure to take data */
64
65PKCS12 *PKCS12_init (int mode)
66{
67 PKCS12 *pkcs12;
68 if (!(pkcs12 = PKCS12_new())) {
69 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
70 return NULL;
71 }
72 ASN1_INTEGER_set(pkcs12->version, 3);
73 pkcs12->authsafes->type = OBJ_nid2obj(mode);
74 switch (mode) {
75 case NID_pkcs7_data:
76 if (!(pkcs12->authsafes->d.data =
77 M_ASN1_OCTET_STRING_new())) {
78 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
79 goto err;
80 }
81 break;
82 default:
83 PKCS12err(PKCS12_F_PKCS12_INIT,
84 PKCS12_R_UNSUPPORTED_PKCS12_MODE);
85 goto err;
86 }
87
88 return pkcs12;
89err:
90 if (pkcs12 != NULL) PKCS12_free(pkcs12);
91 return NULL;
92}
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
new file mode 100644
index 0000000000..9196a34b4a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -0,0 +1,206 @@
1/* p12_key.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63
64/* Uncomment out this line to get debugging info about key generation */
65/*#define DEBUG_KEYGEN*/
66#ifdef DEBUG_KEYGEN
67#include <openssl/bio.h>
68extern BIO *bio_err;
69void h__dump (unsigned char *p, int len);
70#endif
71
72/* PKCS12 compatible key/IV generation */
73#ifndef min
74#define min(a,b) ((a) < (b) ? (a) : (b))
75#endif
76
77int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
78 int saltlen, int id, int iter, int n, unsigned char *out,
79 const EVP_MD *md_type)
80{
81 int ret;
82 unsigned char *unipass;
83 int uniplen;
84 if(!pass) {
85 unipass = NULL;
86 uniplen = 0;
87 } else if (!asc2uni(pass, passlen, &unipass, &uniplen)) {
88 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE);
89 return 0;
90 }
91 ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen,
92 id, iter, n, out, md_type);
93 if(unipass) {
94 OPENSSL_cleanse(unipass, uniplen); /* Clear password from memory */
95 OPENSSL_free(unipass);
96 }
97 return ret;
98}
99
100int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
101 int saltlen, int id, int iter, int n, unsigned char *out,
102 const EVP_MD *md_type)
103{
104 unsigned char *B, *D, *I, *p, *Ai;
105 int Slen, Plen, Ilen, Ijlen;
106 int i, j, u, v;
107 BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */
108 EVP_MD_CTX ctx;
109#ifdef DEBUG_KEYGEN
110 unsigned char *tmpout = out;
111 int tmpn = n;
112#endif
113
114#if 0
115 if (!pass) {
116 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_PASSED_NULL_PARAMETER);
117 return 0;
118 }
119#endif
120
121 EVP_MD_CTX_init(&ctx);
122#ifdef DEBUG_KEYGEN
123 fprintf(stderr, "KEYGEN DEBUG\n");
124 fprintf(stderr, "ID %d, ITER %d\n", id, iter);
125 fprintf(stderr, "Password (length %d):\n", passlen);
126 h__dump(pass, passlen);
127 fprintf(stderr, "Salt (length %d):\n", saltlen);
128 h__dump(salt, saltlen);
129#endif
130 v = EVP_MD_block_size (md_type);
131 u = EVP_MD_size (md_type);
132 D = OPENSSL_malloc (v);
133 Ai = OPENSSL_malloc (u);
134 B = OPENSSL_malloc (v + 1);
135 Slen = v * ((saltlen+v-1)/v);
136 if(passlen) Plen = v * ((passlen+v-1)/v);
137 else Plen = 0;
138 Ilen = Slen + Plen;
139 I = OPENSSL_malloc (Ilen);
140 Ij = BN_new();
141 Bpl1 = BN_new();
142 if (!D || !Ai || !B || !I || !Ij || !Bpl1) {
143 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE);
144 return 0;
145 }
146 for (i = 0; i < v; i++) D[i] = id;
147 p = I;
148 for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen];
149 for (i = 0; i < Plen; i++) *p++ = pass[i % passlen];
150 for (;;) {
151 EVP_DigestInit_ex(&ctx, md_type, NULL);
152 EVP_DigestUpdate(&ctx, D, v);
153 EVP_DigestUpdate(&ctx, I, Ilen);
154 EVP_DigestFinal_ex(&ctx, Ai, NULL);
155 for (j = 1; j < iter; j++) {
156 EVP_DigestInit_ex(&ctx, md_type, NULL);
157 EVP_DigestUpdate(&ctx, Ai, u);
158 EVP_DigestFinal_ex(&ctx, Ai, NULL);
159 }
160 memcpy (out, Ai, min (n, u));
161 if (u >= n) {
162 OPENSSL_free (Ai);
163 OPENSSL_free (B);
164 OPENSSL_free (D);
165 OPENSSL_free (I);
166 BN_free (Ij);
167 BN_free (Bpl1);
168 EVP_MD_CTX_cleanup(&ctx);
169#ifdef DEBUG_KEYGEN
170 fprintf(stderr, "Output KEY (length %d)\n", tmpn);
171 h__dump(tmpout, tmpn);
172#endif
173 return 1;
174 }
175 n -= u;
176 out += u;
177 for (j = 0; j < v; j++) B[j] = Ai[j % u];
178 /* Work out B + 1 first then can use B as tmp space */
179 BN_bin2bn (B, v, Bpl1);
180 BN_add_word (Bpl1, 1);
181 for (j = 0; j < Ilen ; j+=v) {
182 BN_bin2bn (I + j, v, Ij);
183 BN_add (Ij, Ij, Bpl1);
184 BN_bn2bin (Ij, B);
185 Ijlen = BN_num_bytes (Ij);
186 /* If more than 2^(v*8) - 1 cut off MSB */
187 if (Ijlen > v) {
188 BN_bn2bin (Ij, B);
189 memcpy (I + j, B + 1, v);
190#ifndef PKCS12_BROKEN_KEYGEN
191 /* If less than v bytes pad with zeroes */
192 } else if (Ijlen < v) {
193 memset(I + j, 0, v - Ijlen);
194 BN_bn2bin(Ij, I + j + v - Ijlen);
195#endif
196 } else BN_bn2bin (Ij, I + j);
197 }
198 }
199}
200#ifdef DEBUG_KEYGEN
201void h__dump (unsigned char *p, int len)
202{
203 for (; len --; p++) fprintf(stderr, "%02X", *p);
204 fprintf(stderr, "\n");
205}
206#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
new file mode 100644
index 0000000000..2b31999e11
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_kiss.c
@@ -0,0 +1,297 @@
1/* p12_kiss.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Simplified PKCS#12 routines */
64
65static int parse_pk12( PKCS12 *p12, const char *pass, int passlen,
66 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);
67
68static int parse_bags( STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
69 int passlen, EVP_PKEY **pkey, X509 **cert,
70 STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
71 char *keymatch);
72
73static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen,
74 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
75 ASN1_OCTET_STRING **keyid, char *keymatch);
76
77/* Parse and decrypt a PKCS#12 structure returning user key, user cert
78 * and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
79 * or it should point to a valid STACK structure. pkey and cert can be
80 * passed unitialised.
81 */
82
83int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
84 STACK_OF(X509) **ca)
85{
86
87 /* Check for NULL PKCS12 structure */
88
89 if(!p12) {
90 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
91 return 0;
92 }
93
94 /* Allocate stack for ca certificates if needed */
95 if ((ca != NULL) && (*ca == NULL)) {
96 if (!(*ca = sk_X509_new_null())) {
97 PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
98 return 0;
99 }
100 }
101
102 if(pkey) *pkey = NULL;
103 if(cert) *cert = NULL;
104
105 /* Check the mac */
106
107 /* If password is zero length or NULL then try verifying both cases
108 * to determine which password is correct. The reason for this is that
109 * under PKCS#12 password based encryption no password and a zero length
110 * password are two different things...
111 */
112
113 if(!pass || !*pass) {
114 if(PKCS12_verify_mac(p12, NULL, 0)) pass = NULL;
115 else if(PKCS12_verify_mac(p12, "", 0)) pass = "";
116 else {
117 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
118 goto err;
119 }
120 } else if (!PKCS12_verify_mac(p12, pass, -1)) {
121 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
122 goto err;
123 }
124
125 if (!parse_pk12 (p12, pass, -1, pkey, cert, ca))
126 {
127 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
128 goto err;
129 }
130
131 return 1;
132
133 err:
134
135 if (pkey && *pkey) EVP_PKEY_free(*pkey);
136 if (cert && *cert) X509_free(*cert);
137 if (ca) sk_X509_pop_free(*ca, X509_free);
138 return 0;
139
140}
141
142/* Parse the outer PKCS#12 structure */
143
144static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
145 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
146{
147 STACK_OF(PKCS7) *asafes;
148 STACK_OF(PKCS12_SAFEBAG) *bags;
149 int i, bagnid;
150 PKCS7 *p7;
151 ASN1_OCTET_STRING *keyid = NULL;
152
153 char keymatch = 0;
154 if (!(asafes = PKCS12_unpack_authsafes (p12))) return 0;
155 for (i = 0; i < sk_PKCS7_num (asafes); i++) {
156 p7 = sk_PKCS7_value (asafes, i);
157 bagnid = OBJ_obj2nid (p7->type);
158 if (bagnid == NID_pkcs7_data) {
159 bags = PKCS12_unpack_p7data(p7);
160 } else if (bagnid == NID_pkcs7_encrypted) {
161 bags = PKCS12_unpack_p7encdata(p7, pass, passlen);
162 } else continue;
163 if (!bags) {
164 sk_PKCS7_pop_free(asafes, PKCS7_free);
165 return 0;
166 }
167 if (!parse_bags(bags, pass, passlen, pkey, cert, ca,
168 &keyid, &keymatch)) {
169 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
170 sk_PKCS7_pop_free(asafes, PKCS7_free);
171 return 0;
172 }
173 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
174 }
175 sk_PKCS7_pop_free(asafes, PKCS7_free);
176 if (keyid) M_ASN1_OCTET_STRING_free(keyid);
177 return 1;
178}
179
180
181static int parse_bags (STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
182 int passlen, EVP_PKEY **pkey, X509 **cert,
183 STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
184 char *keymatch)
185{
186 int i;
187 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
188 if (!parse_bag(sk_PKCS12_SAFEBAG_value (bags, i),
189 pass, passlen, pkey, cert, ca, keyid,
190 keymatch)) return 0;
191 }
192 return 1;
193}
194
195#define MATCH_KEY 0x1
196#define MATCH_CERT 0x2
197#define MATCH_ALL 0x3
198
199static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
200 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
201 ASN1_OCTET_STRING **keyid,
202 char *keymatch)
203{
204 PKCS8_PRIV_KEY_INFO *p8;
205 X509 *x509;
206 ASN1_OCTET_STRING *lkey = NULL, *ckid = NULL;
207 ASN1_TYPE *attrib;
208 ASN1_BMPSTRING *fname = NULL;
209
210 if ((attrib = PKCS12_get_attr (bag, NID_friendlyName)))
211 fname = attrib->value.bmpstring;
212
213 if ((attrib = PKCS12_get_attr (bag, NID_localKeyID))) {
214 lkey = attrib->value.octet_string;
215 ckid = lkey;
216 }
217
218 /* Check for any local key id matching (if needed) */
219 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
220 if (*keyid) {
221 if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL;
222 } else {
223 if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) {
224 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
225 return 0;
226 }
227 }
228 }
229
230 switch (M_PKCS12_bag_type(bag))
231 {
232 case NID_keyBag:
233 if (!lkey || !pkey) return 1;
234 if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) return 0;
235 *keymatch |= MATCH_KEY;
236 break;
237
238 case NID_pkcs8ShroudedKeyBag:
239 if (!lkey || !pkey) return 1;
240 if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen)))
241 return 0;
242 *pkey = EVP_PKCS82PKEY(p8);
243 PKCS8_PRIV_KEY_INFO_free(p8);
244 if (!(*pkey)) return 0;
245 *keymatch |= MATCH_KEY;
246 break;
247
248 case NID_certBag:
249 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
250 return 1;
251 if (!(x509 = PKCS12_certbag2x509(bag))) return 0;
252 if(ckid)
253 {
254 if (!X509_keyid_set1(x509, ckid->data, ckid->length))
255 {
256 X509_free(x509);
257 return 0;
258 }
259 }
260 if(fname) {
261 int len, r;
262 unsigned char *data;
263 len = ASN1_STRING_to_UTF8(&data, fname);
264 if(len > 0) {
265 r = X509_alias_set1(x509, data, len);
266 OPENSSL_free(data);
267 if (!r)
268 {
269 X509_free(x509);
270 return 0;
271 }
272 }
273 }
274
275
276 if (lkey) {
277 *keymatch |= MATCH_CERT;
278 if (cert) *cert = x509;
279 else X509_free(x509);
280 } else {
281 if(ca) sk_X509_push (*ca, x509);
282 else X509_free(x509);
283 }
284 break;
285
286 case NID_safeContentsBag:
287 return parse_bags(bag->value.safes, pass, passlen,
288 pkey, cert, ca, keyid, keymatch);
289 break;
290
291 default:
292 return 1;
293 break;
294 }
295 return 1;
296}
297
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
new file mode 100644
index 0000000000..4886b9b289
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_mutl.c
@@ -0,0 +1,176 @@
1/* p12_mutl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef OPENSSL_NO_HMAC
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/hmac.h>
63#include <openssl/rand.h>
64#include <openssl/pkcs12.h>
65
66/* Generate a MAC */
67int PKCS12_gen_mac (PKCS12 *p12, const char *pass, int passlen,
68 unsigned char *mac, unsigned int *maclen)
69{
70 const EVP_MD *md_type;
71 HMAC_CTX hmac;
72 unsigned char key[PKCS12_MAC_KEY_LENGTH], *salt;
73 int saltlen, iter;
74
75 salt = p12->mac->salt->data;
76 saltlen = p12->mac->salt->length;
77 if (!p12->mac->iter) iter = 1;
78 else iter = ASN1_INTEGER_get (p12->mac->iter);
79 if(!(md_type =
80 EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) {
81 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
82 return 0;
83 }
84 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
85 PKCS12_MAC_KEY_LENGTH, key, md_type)) {
86 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
87 return 0;
88 }
89 HMAC_CTX_init(&hmac);
90 HMAC_Init_ex(&hmac, key, PKCS12_MAC_KEY_LENGTH, md_type, NULL);
91 HMAC_Update(&hmac, p12->authsafes->d.data->data,
92 p12->authsafes->d.data->length);
93 HMAC_Final(&hmac, mac, maclen);
94 HMAC_CTX_cleanup(&hmac);
95 return 1;
96}
97
98/* Verify the mac */
99int PKCS12_verify_mac (PKCS12 *p12, const char *pass, int passlen)
100{
101 unsigned char mac[EVP_MAX_MD_SIZE];
102 unsigned int maclen;
103 if(p12->mac == NULL) {
104 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_ABSENT);
105 return 0;
106 }
107 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
108 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR);
109 return 0;
110 }
111 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length)
112 || memcmp (mac, p12->mac->dinfo->digest->data, maclen)) return 0;
113 return 1;
114}
115
116/* Set a mac */
117
118int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
119 unsigned char *salt, int saltlen, int iter, const EVP_MD *md_type)
120{
121 unsigned char mac[EVP_MAX_MD_SIZE];
122 unsigned int maclen;
123
124 if (!md_type) md_type = EVP_sha1();
125 if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) ==
126 PKCS12_ERROR) {
127 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR);
128 return 0;
129 }
130 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
131 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
132 return 0;
133 }
134 if (!(M_ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
135 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
136 return 0;
137 }
138 return 1;
139}
140
141/* Set up a mac structure */
142int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
143 const EVP_MD *md_type)
144{
145 if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR;
146 if (iter > 1) {
147 if(!(p12->mac->iter = M_ASN1_INTEGER_new())) {
148 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
149 return 0;
150 }
151 if (!ASN1_INTEGER_set(p12->mac->iter, iter)) {
152 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
153 return 0;
154 }
155 }
156 if (!saltlen) saltlen = PKCS12_SALT_LEN;
157 p12->mac->salt->length = saltlen;
158 if (!(p12->mac->salt->data = OPENSSL_malloc (saltlen))) {
159 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
160 return 0;
161 }
162 if (!salt) {
163 if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0)
164 return 0;
165 }
166 else memcpy (p12->mac->salt->data, salt, saltlen);
167 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
168 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
169 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
170 return 0;
171 }
172 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
173
174 return 1;
175}
176#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
new file mode 100644
index 0000000000..af708a2743
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_npas.c
@@ -0,0 +1,217 @@
1/* p12_npas.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/pkcs12.h>
65
66/* PKCS#12 password change routine */
67
68static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass);
69static int newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass,
70 char *newpass);
71static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass);
72static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
73
74/*
75 * Change the password on a PKCS#12 structure.
76 */
77
78int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
79{
80
81/* Check for NULL PKCS12 structure */
82
83if(!p12) {
84 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
85 return 0;
86}
87
88/* Check the mac */
89
90if (!PKCS12_verify_mac(p12, oldpass, -1)) {
91 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
92 return 0;
93}
94
95if (!newpass_p12(p12, oldpass, newpass)) {
96 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
97 return 0;
98}
99
100return 1;
101
102}
103
104/* Parse the outer PKCS#12 structure */
105
106static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)
107{
108 STACK_OF(PKCS7) *asafes, *newsafes;
109 STACK_OF(PKCS12_SAFEBAG) *bags;
110 int i, bagnid, pbe_nid = 0, pbe_iter = 0, pbe_saltlen = 0;
111 PKCS7 *p7, *p7new;
112 ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;
113 unsigned char mac[EVP_MAX_MD_SIZE];
114 unsigned int maclen;
115
116 if (!(asafes = PKCS12_unpack_authsafes(p12))) return 0;
117 if(!(newsafes = sk_PKCS7_new_null())) return 0;
118 for (i = 0; i < sk_PKCS7_num (asafes); i++) {
119 p7 = sk_PKCS7_value(asafes, i);
120 bagnid = OBJ_obj2nid(p7->type);
121 if (bagnid == NID_pkcs7_data) {
122 bags = PKCS12_unpack_p7data(p7);
123 } else if (bagnid == NID_pkcs7_encrypted) {
124 bags = PKCS12_unpack_p7encdata(p7, oldpass, -1);
125 alg_get(p7->d.encrypted->enc_data->algorithm,
126 &pbe_nid, &pbe_iter, &pbe_saltlen);
127 } else continue;
128 if (!bags) {
129 sk_PKCS7_pop_free(asafes, PKCS7_free);
130 return 0;
131 }
132 if (!newpass_bags(bags, oldpass, newpass)) {
133 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
134 sk_PKCS7_pop_free(asafes, PKCS7_free);
135 return 0;
136 }
137 /* Repack bag in same form with new password */
138 if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);
139 else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,
140 pbe_saltlen, pbe_iter, bags);
141 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
142 if(!p7new) {
143 sk_PKCS7_pop_free(asafes, PKCS7_free);
144 return 0;
145 }
146 sk_PKCS7_push(newsafes, p7new);
147 }
148 sk_PKCS7_pop_free(asafes, PKCS7_free);
149
150 /* Repack safe: save old safe in case of error */
151
152 p12_data_tmp = p12->authsafes->d.data;
153 if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;
154 if(!PKCS12_pack_authsafes(p12, newsafes)) goto saferr;
155
156 if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;
157 if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;
158 if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;
159 ASN1_OCTET_STRING_free(p12->mac->dinfo->digest);
160 p12->mac->dinfo->digest = macnew;
161 ASN1_OCTET_STRING_free(p12_data_tmp);
162
163 return 1;
164
165 saferr:
166 /* Restore old safe */
167 ASN1_OCTET_STRING_free(p12->authsafes->d.data);
168 ASN1_OCTET_STRING_free(macnew);
169 p12->authsafes->d.data = p12_data_tmp;
170 return 0;
171
172}
173
174
175static int newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass,
176 char *newpass)
177{
178 int i;
179 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
180 if (!newpass_bag(sk_PKCS12_SAFEBAG_value(bags, i),
181 oldpass, newpass))
182 return 0;
183 }
184 return 1;
185}
186
187/* Change password of safebag: only needs handle shrouded keybags */
188
189static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
190{
191 PKCS8_PRIV_KEY_INFO *p8;
192 X509_SIG *p8new;
193 int p8_nid, p8_saltlen, p8_iter;
194
195 if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1;
196
197 if (!(p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1))) return 0;
198 alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen);
199 if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
200 p8_iter, p8))) return 0;
201 X509_SIG_free(bag->value.shkeybag);
202 bag->value.shkeybag = p8new;
203 return 1;
204}
205
206static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
207{
208 PBEPARAM *pbe;
209 unsigned char *p;
210 p = alg->parameter->value.sequence->data;
211 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
212 *pnid = OBJ_obj2nid(alg->algorithm);
213 *piter = ASN1_INTEGER_get(pbe->iter);
214 *psaltlen = pbe->salt->length;
215 PBEPARAM_free(pbe);
216 return 0;
217}
diff --git a/src/lib/libcrypto/pkcs12/p12_p8d.c b/src/lib/libcrypto/pkcs12/p12_p8d.c
new file mode 100644
index 0000000000..3c6f377933
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_p8d.c
@@ -0,0 +1,68 @@
1/* p12_p8d.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen)
64{
65 return PKCS12_item_decrypt_d2i(p8->algor, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass,
66 passlen, p8->digest, 1);
67}
68
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c
new file mode 100644
index 0000000000..3d47956652
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_p8e.c
@@ -0,0 +1,97 @@
1/* p12_p8e.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
64 const char *pass, int passlen,
65 unsigned char *salt, int saltlen, int iter,
66 PKCS8_PRIV_KEY_INFO *p8inf)
67{
68 X509_SIG *p8 = NULL;
69 X509_ALGOR *pbe;
70
71 if (!(p8 = X509_SIG_new())) {
72 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
73 goto err;
74 }
75
76 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
77 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
78 if(!pbe) {
79 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB);
80 goto err;
81 }
82 X509_ALGOR_free(p8->algor);
83 p8->algor = pbe;
84 M_ASN1_OCTET_STRING_free(p8->digest);
85 p8->digest = PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO),
86 pass, passlen, p8inf, 1);
87 if(!p8->digest) {
88 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
89 goto err;
90 }
91
92 return p8;
93
94 err:
95 X509_SIG_free(p8);
96 return NULL;
97}
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c
new file mode 100644
index 0000000000..243ec76be9
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_utl.c
@@ -0,0 +1,146 @@
1/* p12_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Cheap and nasty Unicode stuff */
64
65unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen)
66{
67 int ulen, i;
68 unsigned char *unitmp;
69 if (asclen == -1) asclen = strlen(asc);
70 ulen = asclen*2 + 2;
71 if (!(unitmp = OPENSSL_malloc(ulen))) return NULL;
72 for (i = 0; i < ulen - 2; i+=2) {
73 unitmp[i] = 0;
74 unitmp[i + 1] = asc[i>>1];
75 }
76 /* Make result double null terminated */
77 unitmp[ulen - 2] = 0;
78 unitmp[ulen - 1] = 0;
79 if (unilen) *unilen = ulen;
80 if (uni) *uni = unitmp;
81 return unitmp;
82}
83
84char *uni2asc(unsigned char *uni, int unilen)
85{
86 int asclen, i;
87 char *asctmp;
88 asclen = unilen / 2;
89 /* If no terminating zero allow for one */
90 if (!unilen || uni[unilen - 1]) asclen++;
91 uni++;
92 if (!(asctmp = OPENSSL_malloc(asclen))) return NULL;
93 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
94 asctmp[asclen - 1] = 0;
95 return asctmp;
96}
97
98int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12)
99{
100 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS12), bp, p12);
101}
102
103#ifndef OPENSSL_NO_FP_API
104int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12)
105{
106 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS12), fp, p12);
107}
108#endif
109
110PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12)
111{
112 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS12), bp, p12);
113}
114#ifndef OPENSSL_NO_FP_API
115PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12)
116{
117 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS12), fp, p12);
118}
119#endif
120
121PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509)
122{
123 return PKCS12_item_pack_safebag(x509, ASN1_ITEM_rptr(X509),
124 NID_x509Certificate, NID_certBag);
125}
126
127PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl)
128{
129 return PKCS12_item_pack_safebag(crl, ASN1_ITEM_rptr(X509_CRL),
130 NID_x509Crl, NID_crlBag);
131}
132
133X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag)
134{
135 if(M_PKCS12_bag_type(bag) != NID_certBag) return NULL;
136 if(M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) return NULL;
137 return ASN1_item_unpack(bag->value.bag->value.octet, ASN1_ITEM_rptr(X509));
138}
139
140X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag)
141{
142 if(M_PKCS12_bag_type(bag) != NID_crlBag) return NULL;
143 if(M_PKCS12_cert_bag_type(bag) != NID_x509Crl) return NULL;
144 return ASN1_item_unpack(bag->value.bag->value.octet,
145 ASN1_ITEM_rptr(X509_CRL));
146}
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c
new file mode 100644
index 0000000000..10ab80502c
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/pk12err.c
@@ -0,0 +1,139 @@
1/* crypto/pkcs12/pk12err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pkcs12.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA PKCS12_str_functs[]=
68 {
69{ERR_PACK(0,PKCS12_F_PARSE_BAGS,0), "PARSE_BAGS"},
70{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME,0), "PKCS12_ADD_FRIENDLYNAME"},
71{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,0), "PKCS12_add_friendlyname_asc"},
72{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,0), "PKCS12_add_friendlyname_uni"},
73{ERR_PACK(0,PKCS12_F_PKCS12_ADD_LOCALKEYID,0), "PKCS12_add_localkeyid"},
74{ERR_PACK(0,PKCS12_F_PKCS12_CREATE,0), "PKCS12_create"},
75{ERR_PACK(0,PKCS12_F_PKCS12_DECRYPT_D2I,0), "PKCS12_decrypt_d2i"},
76{ERR_PACK(0,PKCS12_F_PKCS12_GEN_MAC,0), "PKCS12_gen_mac"},
77{ERR_PACK(0,PKCS12_F_PKCS12_I2D_ENCRYPT,0), "PKCS12_i2d_encrypt"},
78{ERR_PACK(0,PKCS12_F_PKCS12_INIT,0), "PKCS12_init"},
79{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_ASC,0), "PKCS12_key_gen_asc"},
80{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_UNI,0), "PKCS12_key_gen_uni"},
81{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_KEYBAG,0), "PKCS12_MAKE_KEYBAG"},
82{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_SHKEYBAG,0), "PKCS12_MAKE_SHKEYBAG"},
83{ERR_PACK(0,PKCS12_F_PKCS12_NEWPASS,0), "PKCS12_newpass"},
84{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7DATA,0), "PKCS12_pack_p7data"},
85{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7ENCDATA,0), "PKCS12_pack_p7encdata"},
86{ERR_PACK(0,PKCS12_F_PKCS12_PACK_SAFEBAG,0), "PKCS12_pack_safebag"},
87{ERR_PACK(0,PKCS12_F_PKCS12_PARSE,0), "PKCS12_parse"},
88{ERR_PACK(0,PKCS12_F_PKCS12_PBE_CRYPT,0), "PKCS12_pbe_crypt"},
89{ERR_PACK(0,PKCS12_F_PKCS12_PBE_KEYIVGEN,0), "PKCS12_PBE_keyivgen"},
90{ERR_PACK(0,PKCS12_F_PKCS12_SETUP_MAC,0), "PKCS12_setup_mac"},
91{ERR_PACK(0,PKCS12_F_PKCS12_SET_MAC,0), "PKCS12_set_mac"},
92{ERR_PACK(0,PKCS12_F_PKCS8_ADD_KEYUSAGE,0), "PKCS8_add_keyusage"},
93{ERR_PACK(0,PKCS12_F_PKCS8_ENCRYPT,0), "PKCS8_encrypt"},
94{ERR_PACK(0,PKCS12_F_VERIFY_MAC,0), "VERIFY_MAC"},
95{0,NULL}
96 };
97
98static ERR_STRING_DATA PKCS12_str_reasons[]=
99 {
100{PKCS12_R_CANT_PACK_STRUCTURE ,"cant pack structure"},
101{PKCS12_R_DECODE_ERROR ,"decode error"},
102{PKCS12_R_ENCODE_ERROR ,"encode error"},
103{PKCS12_R_ENCRYPT_ERROR ,"encrypt error"},
104{PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE,"error setting encrypted data type"},
105{PKCS12_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
106{PKCS12_R_INVALID_NULL_PKCS12_POINTER ,"invalid null pkcs12 pointer"},
107{PKCS12_R_IV_GEN_ERROR ,"iv gen error"},
108{PKCS12_R_KEY_GEN_ERROR ,"key gen error"},
109{PKCS12_R_MAC_ABSENT ,"mac absent"},
110{PKCS12_R_MAC_GENERATION_ERROR ,"mac generation error"},
111{PKCS12_R_MAC_SETUP_ERROR ,"mac setup error"},
112{PKCS12_R_MAC_STRING_SET_ERROR ,"mac string set error"},
113{PKCS12_R_MAC_VERIFY_ERROR ,"mac verify error"},
114{PKCS12_R_MAC_VERIFY_FAILURE ,"mac verify failure"},
115{PKCS12_R_PARSE_ERROR ,"parse error"},
116{PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR ,"pkcs12 algor cipherinit error"},
117{PKCS12_R_PKCS12_CIPHERFINAL_ERROR ,"pkcs12 cipherfinal error"},
118{PKCS12_R_PKCS12_PBE_CRYPT_ERROR ,"pkcs12 pbe crypt error"},
119{PKCS12_R_UNKNOWN_DIGEST_ALGORITHM ,"unknown digest algorithm"},
120{PKCS12_R_UNSUPPORTED_PKCS12_MODE ,"unsupported pkcs12 mode"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_PKCS12_strings(void)
127 {
128 static int init=1;
129
130 if (init)
131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
134 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_functs);
135 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h
new file mode 100644
index 0000000000..dd338f266c
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/pkcs12.h
@@ -0,0 +1,320 @@
1/* pkcs12.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_PKCS12_H
60#define HEADER_PKCS12_H
61
62#include <openssl/bio.h>
63#include <openssl/x509.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69#define PKCS12_KEY_ID 1
70#define PKCS12_IV_ID 2
71#define PKCS12_MAC_ID 3
72
73/* Default iteration count */
74#ifndef PKCS12_DEFAULT_ITER
75#define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
76#endif
77
78#define PKCS12_MAC_KEY_LENGTH 20
79
80#define PKCS12_SALT_LEN 8
81
82/* Uncomment out next line for unicode password and names, otherwise ASCII */
83
84/*#define PBE_UNICODE*/
85
86#ifdef PBE_UNICODE
87#define PKCS12_key_gen PKCS12_key_gen_uni
88#define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni
89#else
90#define PKCS12_key_gen PKCS12_key_gen_asc
91#define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc
92#endif
93
94/* MS key usage constants */
95
96#define KEY_EX 0x10
97#define KEY_SIG 0x80
98
99typedef struct {
100X509_SIG *dinfo;
101ASN1_OCTET_STRING *salt;
102ASN1_INTEGER *iter; /* defaults to 1 */
103} PKCS12_MAC_DATA;
104
105typedef struct {
106ASN1_INTEGER *version;
107PKCS12_MAC_DATA *mac;
108PKCS7 *authsafes;
109} PKCS12;
110
111PREDECLARE_STACK_OF(PKCS12_SAFEBAG)
112
113typedef struct {
114ASN1_OBJECT *type;
115union {
116 struct pkcs12_bag_st *bag; /* secret, crl and certbag */
117 struct pkcs8_priv_key_info_st *keybag; /* keybag */
118 X509_SIG *shkeybag; /* shrouded key bag */
119 STACK_OF(PKCS12_SAFEBAG) *safes;
120 ASN1_TYPE *other;
121}value;
122STACK_OF(X509_ATTRIBUTE) *attrib;
123} PKCS12_SAFEBAG;
124
125DECLARE_STACK_OF(PKCS12_SAFEBAG)
126DECLARE_ASN1_SET_OF(PKCS12_SAFEBAG)
127DECLARE_PKCS12_STACK_OF(PKCS12_SAFEBAG)
128
129typedef struct pkcs12_bag_st {
130ASN1_OBJECT *type;
131union {
132 ASN1_OCTET_STRING *x509cert;
133 ASN1_OCTET_STRING *x509crl;
134 ASN1_OCTET_STRING *octet;
135 ASN1_IA5STRING *sdsicert;
136 ASN1_TYPE *other; /* Secret or other bag */
137}value;
138} PKCS12_BAGS;
139
140#define PKCS12_ERROR 0
141#define PKCS12_OK 1
142
143/* Compatibility macros */
144
145#define M_PKCS12_x5092certbag PKCS12_x5092certbag
146#define M_PKCS12_x509crl2certbag PKCS12_x509crl2certbag
147
148#define M_PKCS12_certbag2x509 PKCS12_certbag2x509
149#define M_PKCS12_certbag2x509crl PKCS12_certbag2x509crl
150
151#define M_PKCS12_unpack_p7data PKCS12_unpack_p7data
152#define M_PKCS12_pack_authsafes PKCS12_pack_authsafes
153#define M_PKCS12_unpack_authsafes PKCS12_unpack_authsafes
154#define M_PKCS12_unpack_p7encdata PKCS12_unpack_p7encdata
155
156#define M_PKCS12_decrypt_skey PKCS12_decrypt_skey
157#define M_PKCS8_decrypt PKCS8_decrypt
158
159#define M_PKCS12_bag_type(bg) OBJ_obj2nid((bg)->type)
160#define M_PKCS12_cert_bag_type(bg) OBJ_obj2nid((bg)->value.bag->type)
161#define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type
162
163#define PKCS12_get_attr(bag, attr_nid) \
164 PKCS12_get_attr_gen(bag->attrib, attr_nid)
165
166#define PKCS8_get_attr(p8, attr_nid) \
167 PKCS12_get_attr_gen(p8->attributes, attr_nid)
168
169#define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0)
170
171
172PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509);
173PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl);
174X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag);
175X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag);
176
177PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1,
178 int nid2);
179PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8);
180PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen);
181PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass,
182 int passlen);
183X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
184 const char *pass, int passlen,
185 unsigned char *salt, int saltlen, int iter,
186 PKCS8_PRIV_KEY_INFO *p8);
187PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
188 int passlen, unsigned char *salt,
189 int saltlen, int iter,
190 PKCS8_PRIV_KEY_INFO *p8);
191PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
192STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
193PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
194 unsigned char *salt, int saltlen, int iter,
195 STACK_OF(PKCS12_SAFEBAG) *bags);
196STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen);
197
198int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
199STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12);
200
201int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen);
202int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
203 int namelen);
204int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
205 int namelen);
206int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name,
207 int namelen);
208int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
209ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid);
210char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
211unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
212 int passlen, unsigned char *in, int inlen,
213 unsigned char **data, int *datalen, int en_de);
214void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
215 const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf);
216ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
217 const char *pass, int passlen,
218 void *obj, int zbuf);
219PKCS12 *PKCS12_init(int mode);
220int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
221 int saltlen, int id, int iter, int n,
222 unsigned char *out, const EVP_MD *md_type);
223int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type);
224int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
225 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md_type,
226 int en_de);
227int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
228 unsigned char *mac, unsigned int *maclen);
229int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
230int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
231 unsigned char *salt, int saltlen, int iter,
232 const EVP_MD *md_type);
233int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
234 int saltlen, const EVP_MD *md_type);
235unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen);
236char *uni2asc(unsigned char *uni, int unilen);
237
238DECLARE_ASN1_FUNCTIONS(PKCS12)
239DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
240DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
241DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
242
243DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
244DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
245
246void PKCS12_PBE_add(void);
247int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
248 STACK_OF(X509) **ca);
249PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
250 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter,
251 int mac_iter, int keytype);
252int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
253int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
254PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
255PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
256int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
257
258/* BEGIN ERROR CODES */
259/* The following lines are auto generated by the script mkerr.pl. Any changes
260 * made after this point may be overwritten when the script is next run.
261 */
262void ERR_load_PKCS12_strings(void);
263
264/* Error codes for the PKCS12 functions. */
265
266/* Function codes. */
267#define PKCS12_F_PARSE_BAGS 103
268#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100
269#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127
270#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102
271#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104
272#define PKCS12_F_PKCS12_CREATE 105
273#define PKCS12_F_PKCS12_DECRYPT_D2I 106
274#define PKCS12_F_PKCS12_GEN_MAC 107
275#define PKCS12_F_PKCS12_I2D_ENCRYPT 108
276#define PKCS12_F_PKCS12_INIT 109
277#define PKCS12_F_PKCS12_KEY_GEN_ASC 110
278#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
279#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
280#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113
281#define PKCS12_F_PKCS12_NEWPASS 128
282#define PKCS12_F_PKCS12_PACK_P7DATA 114
283#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
284#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
285#define PKCS12_F_PKCS12_PARSE 118
286#define PKCS12_F_PKCS12_PBE_CRYPT 119
287#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
288#define PKCS12_F_PKCS12_SETUP_MAC 122
289#define PKCS12_F_PKCS12_SET_MAC 123
290#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124
291#define PKCS12_F_PKCS8_ENCRYPT 125
292#define PKCS12_F_VERIFY_MAC 126
293
294/* Reason codes. */
295#define PKCS12_R_CANT_PACK_STRUCTURE 100
296#define PKCS12_R_DECODE_ERROR 101
297#define PKCS12_R_ENCODE_ERROR 102
298#define PKCS12_R_ENCRYPT_ERROR 103
299#define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120
300#define PKCS12_R_INVALID_NULL_ARGUMENT 104
301#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
302#define PKCS12_R_IV_GEN_ERROR 106
303#define PKCS12_R_KEY_GEN_ERROR 107
304#define PKCS12_R_MAC_ABSENT 108
305#define PKCS12_R_MAC_GENERATION_ERROR 109
306#define PKCS12_R_MAC_SETUP_ERROR 110
307#define PKCS12_R_MAC_STRING_SET_ERROR 111
308#define PKCS12_R_MAC_VERIFY_ERROR 112
309#define PKCS12_R_MAC_VERIFY_FAILURE 113
310#define PKCS12_R_PARSE_ERROR 114
311#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115
312#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116
313#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117
314#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118
315#define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119
316
317#ifdef __cplusplus
318}
319#endif
320#endif
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/pk7_asn1.c b/src/lib/libcrypto/pkcs7/pk7_asn1.c
new file mode 100644
index 0000000000..46f0fc9375
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_asn1.c
@@ -0,0 +1,213 @@
1/* pk7_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs7.h>
63#include <openssl/x509.h>
64
65/* PKCS#7 ASN1 module */
66
67/* This is the ANY DEFINED BY table for the top level PKCS#7 structure */
68
69ASN1_ADB_TEMPLATE(p7default) = ASN1_EXP_OPT(PKCS7, d.other, ASN1_ANY, 0);
70
71ASN1_ADB(PKCS7) = {
72 ADB_ENTRY(NID_pkcs7_data, ASN1_EXP_OPT(PKCS7, d.data, ASN1_OCTET_STRING, 0)),
73 ADB_ENTRY(NID_pkcs7_signed, ASN1_EXP_OPT(PKCS7, d.sign, PKCS7_SIGNED, 0)),
74 ADB_ENTRY(NID_pkcs7_enveloped, ASN1_EXP_OPT(PKCS7, d.enveloped, PKCS7_ENVELOPE, 0)),
75 ADB_ENTRY(NID_pkcs7_signedAndEnveloped, ASN1_EXP_OPT(PKCS7, d.signed_and_enveloped, PKCS7_SIGN_ENVELOPE, 0)),
76 ADB_ENTRY(NID_pkcs7_digest, ASN1_EXP_OPT(PKCS7, d.digest, PKCS7_DIGEST, 0)),
77 ADB_ENTRY(NID_pkcs7_encrypted, ASN1_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0))
78} ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL);
79
80ASN1_SEQUENCE(PKCS7) = {
81 ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT),
82 ASN1_ADB_OBJECT(PKCS7)
83}ASN1_SEQUENCE_END(PKCS7)
84
85IMPLEMENT_ASN1_FUNCTIONS(PKCS7)
86IMPLEMENT_ASN1_DUP_FUNCTION(PKCS7)
87
88ASN1_SEQUENCE(PKCS7_SIGNED) = {
89 ASN1_SIMPLE(PKCS7_SIGNED, version, ASN1_INTEGER),
90 ASN1_SET_OF(PKCS7_SIGNED, md_algs, X509_ALGOR),
91 ASN1_SIMPLE(PKCS7_SIGNED, contents, PKCS7),
92 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNED, cert, X509, 0),
93 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNED, crl, X509_CRL, 1),
94 ASN1_SET_OF(PKCS7_SIGNED, signer_info, PKCS7_SIGNER_INFO)
95} ASN1_SEQUENCE_END(PKCS7_SIGNED)
96
97IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED)
98
99/* Minor tweak to operation: free up EVP_PKEY */
100static int si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
101{
102 if(operation == ASN1_OP_FREE_POST) {
103 PKCS7_SIGNER_INFO *si = (PKCS7_SIGNER_INFO *)*pval;
104 EVP_PKEY_free(si->pkey);
105 }
106 return 1;
107}
108
109ASN1_SEQUENCE_cb(PKCS7_SIGNER_INFO, si_cb) = {
110 ASN1_SIMPLE(PKCS7_SIGNER_INFO, version, ASN1_INTEGER),
111 ASN1_SIMPLE(PKCS7_SIGNER_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
112 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_alg, X509_ALGOR),
113 /* NB this should be a SET OF but we use a SEQUENCE OF so the
114 * original order * is retained when the structure is reencoded.
115 * Since the attributes are implicitly tagged this will not affect
116 * the encoding.
117 */
118 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNER_INFO, auth_attr, X509_ATTRIBUTE, 0),
119 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_enc_alg, X509_ALGOR),
120 ASN1_SIMPLE(PKCS7_SIGNER_INFO, enc_digest, ASN1_OCTET_STRING),
121 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNER_INFO, unauth_attr, X509_ATTRIBUTE, 1)
122} ASN1_SEQUENCE_END_cb(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO)
123
124IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
125
126ASN1_SEQUENCE(PKCS7_ISSUER_AND_SERIAL) = {
127 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, issuer, X509_NAME),
128 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, serial, ASN1_INTEGER)
129} ASN1_SEQUENCE_END(PKCS7_ISSUER_AND_SERIAL)
130
131IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
132
133ASN1_SEQUENCE(PKCS7_ENVELOPE) = {
134 ASN1_SIMPLE(PKCS7_ENVELOPE, version, ASN1_INTEGER),
135 ASN1_SET_OF(PKCS7_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
136 ASN1_SIMPLE(PKCS7_ENVELOPE, enc_data, PKCS7_ENC_CONTENT)
137} ASN1_SEQUENCE_END(PKCS7_ENVELOPE)
138
139IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
140
141/* Minor tweak to operation: free up X509 */
142static int ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
143{
144 if(operation == ASN1_OP_FREE_POST) {
145 PKCS7_RECIP_INFO *ri = (PKCS7_RECIP_INFO *)*pval;
146 X509_free(ri->cert);
147 }
148 return 1;
149}
150
151ASN1_SEQUENCE_cb(PKCS7_RECIP_INFO, ri_cb) = {
152 ASN1_SIMPLE(PKCS7_RECIP_INFO, version, ASN1_INTEGER),
153 ASN1_SIMPLE(PKCS7_RECIP_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
154 ASN1_SIMPLE(PKCS7_RECIP_INFO, key_enc_algor, X509_ALGOR),
155 ASN1_SIMPLE(PKCS7_RECIP_INFO, enc_key, ASN1_OCTET_STRING)
156} ASN1_SEQUENCE_END_cb(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO)
157
158IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
159
160ASN1_SEQUENCE(PKCS7_ENC_CONTENT) = {
161 ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT),
162 ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR),
163 ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING, 0)
164} ASN1_SEQUENCE_END(PKCS7_ENC_CONTENT)
165
166IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
167
168ASN1_SEQUENCE(PKCS7_SIGN_ENVELOPE) = {
169 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, version, ASN1_INTEGER),
170 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
171 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, md_algs, X509_ALGOR),
172 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, enc_data, PKCS7_ENC_CONTENT),
173 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, cert, X509, 0),
174 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, crl, X509_CRL, 1),
175 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, signer_info, PKCS7_SIGNER_INFO)
176} ASN1_SEQUENCE_END(PKCS7_SIGN_ENVELOPE)
177
178IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
179
180ASN1_SEQUENCE(PKCS7_ENCRYPT) = {
181 ASN1_SIMPLE(PKCS7_ENCRYPT, version, ASN1_INTEGER),
182 ASN1_SIMPLE(PKCS7_ENCRYPT, enc_data, PKCS7_ENC_CONTENT)
183} ASN1_SEQUENCE_END(PKCS7_ENCRYPT)
184
185IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
186
187ASN1_SEQUENCE(PKCS7_DIGEST) = {
188 ASN1_SIMPLE(PKCS7_DIGEST, version, ASN1_INTEGER),
189 ASN1_SIMPLE(PKCS7_DIGEST, md, X509_ALGOR),
190 ASN1_SIMPLE(PKCS7_DIGEST, contents, PKCS7),
191 ASN1_SIMPLE(PKCS7_DIGEST, digest, ASN1_OCTET_STRING)
192} ASN1_SEQUENCE_END(PKCS7_DIGEST)
193
194IMPLEMENT_ASN1_FUNCTIONS(PKCS7_DIGEST)
195
196/* Specials for authenticated attributes */
197
198/* When signing attributes we want to reorder them to match the sorted
199 * encoding.
200 */
201
202ASN1_ITEM_TEMPLATE(PKCS7_ATTR_SIGN) =
203 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_ORDER, 0, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
204ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_SIGN)
205
206/* When verifying attributes we need to use the received order. So
207 * we use SEQUENCE OF and tag it to SET OF
208 */
209
210ASN1_ITEM_TEMPLATE(PKCS7_ATTR_VERIFY) =
211 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
212 V_ASN1_SET, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
213ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_VERIFY)
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
new file mode 100644
index 0000000000..039141027a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_attr.c
@@ -0,0 +1,140 @@
1/* pk7_attr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/bio.h>
62#include <openssl/asn1.h>
63#include <openssl/pem.h>
64#include <openssl/pkcs7.h>
65#include <openssl/x509.h>
66#include <openssl/err.h>
67
68int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
69{
70 ASN1_STRING *seq;
71 unsigned char *p, *pp;
72 int len;
73 len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR,
74 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL,
75 IS_SEQUENCE);
76 if(!(pp=(unsigned char *)OPENSSL_malloc(len))) {
77 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 p=pp;
81 i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
82 V_ASN1_UNIVERSAL, IS_SEQUENCE);
83 if(!(seq = ASN1_STRING_new())) {
84 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
85 return 0;
86 }
87 if(!ASN1_STRING_set (seq, pp, len)) {
88 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
89 return 0;
90 }
91 OPENSSL_free (pp);
92 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
93 V_ASN1_SEQUENCE, seq);
94}
95
96STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
97 {
98 ASN1_TYPE *cap;
99 unsigned char *p;
100 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
101 if (!cap || (cap->type != V_ASN1_SEQUENCE))
102 return NULL;
103 p = cap->value.sequence->data;
104 return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p,
105 cap->value.sequence->length,
106 d2i_X509_ALGOR, X509_ALGOR_free,
107 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
108 }
109
110/* Basic smime-capabilities OID and optional integer arg */
111int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
112{
113 X509_ALGOR *alg;
114
115 if(!(alg = X509_ALGOR_new())) {
116 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
117 return 0;
118 }
119 ASN1_OBJECT_free(alg->algorithm);
120 alg->algorithm = OBJ_nid2obj (nid);
121 if (arg > 0) {
122 ASN1_INTEGER *nbit;
123 if(!(alg->parameter = ASN1_TYPE_new())) {
124 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
125 return 0;
126 }
127 if(!(nbit = ASN1_INTEGER_new())) {
128 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
129 return 0;
130 }
131 if(!ASN1_INTEGER_set (nbit, arg)) {
132 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
133 return 0;
134 }
135 alg->parameter->value.integer = nbit;
136 alg->parameter->type = V_ASN1_INTEGER;
137 }
138 sk_X509_ALGOR_push (sk, alg);
139 return 1;
140}
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
new file mode 100644
index 0000000000..4ac29ae14d
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -0,0 +1,1013 @@
1/* crypto/pkcs7/pk7_doit.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
67 void *value);
68static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
69
70static int PKCS7_type_is_other(PKCS7* p7)
71 {
72 int isOther=1;
73
74 int nid=OBJ_obj2nid(p7->type);
75
76 switch( nid )
77 {
78 case NID_pkcs7_data:
79 case NID_pkcs7_signed:
80 case NID_pkcs7_enveloped:
81 case NID_pkcs7_signedAndEnveloped:
82 case NID_pkcs7_digest:
83 case NID_pkcs7_encrypted:
84 isOther=0;
85 break;
86 default:
87 isOther=1;
88 }
89
90 return isOther;
91
92 }
93
94static ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7)
95 {
96 if ( PKCS7_type_is_data(p7))
97 return p7->d.data;
98 if ( PKCS7_type_is_other(p7) && p7->d.other
99 && (p7->d.other->type == V_ASN1_OCTET_STRING))
100 return p7->d.other->value.octet_string;
101 return NULL;
102 }
103
104BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
105 {
106 int i;
107 BIO *out=NULL,*btmp=NULL;
108 X509_ALGOR *xa;
109 const EVP_MD *evp_md;
110 const EVP_CIPHER *evp_cipher=NULL;
111 STACK_OF(X509_ALGOR) *md_sk=NULL;
112 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
113 X509_ALGOR *xalg=NULL;
114 PKCS7_RECIP_INFO *ri=NULL;
115 EVP_PKEY *pkey;
116
117 i=OBJ_obj2nid(p7->type);
118 p7->state=PKCS7_S_HEADER;
119
120 switch (i)
121 {
122 case NID_pkcs7_signed:
123 md_sk=p7->d.sign->md_algs;
124 break;
125 case NID_pkcs7_signedAndEnveloped:
126 rsk=p7->d.signed_and_enveloped->recipientinfo;
127 md_sk=p7->d.signed_and_enveloped->md_algs;
128 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
129 evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher;
130 if (evp_cipher == NULL)
131 {
132 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
133 PKCS7_R_CIPHER_NOT_INITIALIZED);
134 goto err;
135 }
136 break;
137 case NID_pkcs7_enveloped:
138 rsk=p7->d.enveloped->recipientinfo;
139 xalg=p7->d.enveloped->enc_data->algorithm;
140 evp_cipher=p7->d.enveloped->enc_data->cipher;
141 if (evp_cipher == NULL)
142 {
143 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
144 PKCS7_R_CIPHER_NOT_INITIALIZED);
145 goto err;
146 }
147 break;
148 default:
149 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
150 goto err;
151 }
152
153 if (md_sk != NULL)
154 {
155 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
156 {
157 xa=sk_X509_ALGOR_value(md_sk,i);
158 if ((btmp=BIO_new(BIO_f_md())) == NULL)
159 {
160 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
161 goto err;
162 }
163
164 evp_md=EVP_get_digestbyobj(xa->algorithm);
165 if (evp_md == NULL)
166 {
167 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE);
168 goto err;
169 }
170
171 BIO_set_md(btmp,evp_md);
172 if (out == NULL)
173 out=btmp;
174 else
175 BIO_push(out,btmp);
176 btmp=NULL;
177 }
178 }
179
180 if (evp_cipher != NULL)
181 {
182 unsigned char key[EVP_MAX_KEY_LENGTH];
183 unsigned char iv[EVP_MAX_IV_LENGTH];
184 int keylen,ivlen;
185 int jj,max;
186 unsigned char *tmp;
187 EVP_CIPHER_CTX *ctx;
188
189 if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
190 {
191 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
192 goto err;
193 }
194 BIO_get_cipher_ctx(btmp, &ctx);
195 keylen=EVP_CIPHER_key_length(evp_cipher);
196 ivlen=EVP_CIPHER_iv_length(evp_cipher);
197 if (RAND_bytes(key,keylen) <= 0)
198 goto err;
199 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
200 if (ivlen > 0) RAND_pseudo_bytes(iv,ivlen);
201 EVP_CipherInit_ex(ctx, evp_cipher, NULL, key, iv, 1);
202
203 if (ivlen > 0) {
204 if (xalg->parameter == NULL)
205 xalg->parameter=ASN1_TYPE_new();
206 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
207 goto err;
208 }
209
210 /* Lets do the pub key stuff :-) */
211 max=0;
212 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
213 {
214 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
215 if (ri->cert == NULL)
216 {
217 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
218 goto err;
219 }
220 pkey=X509_get_pubkey(ri->cert);
221 jj=EVP_PKEY_size(pkey);
222 EVP_PKEY_free(pkey);
223 if (max < jj) max=jj;
224 }
225 if ((tmp=(unsigned char *)OPENSSL_malloc(max)) == NULL)
226 {
227 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE);
228 goto err;
229 }
230 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
231 {
232 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
233 pkey=X509_get_pubkey(ri->cert);
234 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
235 EVP_PKEY_free(pkey);
236 if (jj <= 0)
237 {
238 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
239 OPENSSL_free(tmp);
240 goto err;
241 }
242 if (!M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj))
243 {
244 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
245 ERR_R_MALLOC_FAILURE);
246 OPENSSL_free(tmp);
247 goto err;
248 }
249 }
250 OPENSSL_free(tmp);
251 OPENSSL_cleanse(key, keylen);
252
253 if (out == NULL)
254 out=btmp;
255 else
256 BIO_push(out,btmp);
257 btmp=NULL;
258 }
259
260 if (bio == NULL)
261 {
262 if (PKCS7_is_detached(p7))
263 bio=BIO_new(BIO_s_null());
264 else
265 {
266 if (PKCS7_type_is_signed(p7))
267 {
268 ASN1_OCTET_STRING *os;
269 os = PKCS7_get_octet_string(
270 p7->d.sign->contents);
271 if (os && os->length > 0)
272 bio = BIO_new_mem_buf(os->data,
273 os->length);
274 }
275 if(bio == NULL)
276 {
277 bio=BIO_new(BIO_s_mem());
278 BIO_set_mem_eof_return(bio,0);
279 }
280 }
281 }
282 BIO_push(out,bio);
283 bio=NULL;
284 if (0)
285 {
286err:
287 if (out != NULL)
288 BIO_free_all(out);
289 if (btmp != NULL)
290 BIO_free_all(btmp);
291 out=NULL;
292 }
293 return(out);
294 }
295
296/* int */
297BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
298 {
299 int i,j;
300 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
301 unsigned char *tmp=NULL;
302 X509_ALGOR *xa;
303 ASN1_OCTET_STRING *data_body=NULL;
304 const EVP_MD *evp_md;
305 const EVP_CIPHER *evp_cipher=NULL;
306 EVP_CIPHER_CTX *evp_ctx=NULL;
307 X509_ALGOR *enc_alg=NULL;
308 STACK_OF(X509_ALGOR) *md_sk=NULL;
309 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
310 X509_ALGOR *xalg=NULL;
311 PKCS7_RECIP_INFO *ri=NULL;
312
313 i=OBJ_obj2nid(p7->type);
314 p7->state=PKCS7_S_HEADER;
315
316 switch (i)
317 {
318 case NID_pkcs7_signed:
319 data_body=PKCS7_get_octet_string(p7->d.sign->contents);
320 md_sk=p7->d.sign->md_algs;
321 break;
322 case NID_pkcs7_signedAndEnveloped:
323 rsk=p7->d.signed_and_enveloped->recipientinfo;
324 md_sk=p7->d.signed_and_enveloped->md_algs;
325 data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
326 enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
327 evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
328 if (evp_cipher == NULL)
329 {
330 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
331 goto err;
332 }
333 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
334 break;
335 case NID_pkcs7_enveloped:
336 rsk=p7->d.enveloped->recipientinfo;
337 enc_alg=p7->d.enveloped->enc_data->algorithm;
338 data_body=p7->d.enveloped->enc_data->enc_data;
339 evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
340 if (evp_cipher == NULL)
341 {
342 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
343 goto err;
344 }
345 xalg=p7->d.enveloped->enc_data->algorithm;
346 break;
347 default:
348 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
349 goto err;
350 }
351
352 /* We will be checking the signature */
353 if (md_sk != NULL)
354 {
355 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
356 {
357 xa=sk_X509_ALGOR_value(md_sk,i);
358 if ((btmp=BIO_new(BIO_f_md())) == NULL)
359 {
360 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
361 goto err;
362 }
363
364 j=OBJ_obj2nid(xa->algorithm);
365 evp_md=EVP_get_digestbynid(j);
366 if (evp_md == NULL)
367 {
368 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
369 goto err;
370 }
371
372 BIO_set_md(btmp,evp_md);
373 if (out == NULL)
374 out=btmp;
375 else
376 BIO_push(out,btmp);
377 btmp=NULL;
378 }
379 }
380
381 if (evp_cipher != NULL)
382 {
383#if 0
384 unsigned char key[EVP_MAX_KEY_LENGTH];
385 unsigned char iv[EVP_MAX_IV_LENGTH];
386 unsigned char *p;
387 int keylen,ivlen;
388 int max;
389 X509_OBJECT ret;
390#endif
391 int jj;
392
393 if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
394 {
395 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
396 goto err;
397 }
398
399 /* It was encrypted, we need to decrypt the secret key
400 * with the private key */
401
402 /* Find the recipientInfo which matches the passed certificate
403 * (if any)
404 */
405
406 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
407 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
408 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
409 pcert->cert_info->issuer) &&
410 !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
411 ri->issuer_and_serial->serial)) break;
412 ri=NULL;
413 }
414 if (ri == NULL) {
415 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
416 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
417 goto err;
418 }
419
420 jj=EVP_PKEY_size(pkey);
421 tmp=(unsigned char *)OPENSSL_malloc(jj+10);
422 if (tmp == NULL)
423 {
424 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
425 goto err;
426 }
427
428 jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),
429 M_ASN1_STRING_length(ri->enc_key), pkey);
430 if (jj <= 0)
431 {
432 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
433 goto err;
434 }
435
436 evp_ctx=NULL;
437 BIO_get_cipher_ctx(etmp,&evp_ctx);
438 EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0);
439 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
440 goto err;
441
442 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {
443 /* Some S/MIME clients don't use the same key
444 * and effective key length. The key length is
445 * determined by the size of the decrypted RSA key.
446 */
447 if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, jj))
448 {
449 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
450 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
451 goto err;
452 }
453 }
454 EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0);
455
456 OPENSSL_cleanse(tmp,jj);
457
458 if (out == NULL)
459 out=etmp;
460 else
461 BIO_push(out,etmp);
462 etmp=NULL;
463 }
464
465#if 1
466 if (PKCS7_is_detached(p7) || (in_bio != NULL))
467 {
468 bio=in_bio;
469 }
470 else
471 {
472#if 0
473 bio=BIO_new(BIO_s_mem());
474 /* We need to set this so that when we have read all
475 * the data, the encrypt BIO, if present, will read
476 * EOF and encode the last few bytes */
477 BIO_set_mem_eof_return(bio,0);
478
479 if (data_body->length > 0)
480 BIO_write(bio,(char *)data_body->data,data_body->length);
481#else
482 if (data_body->length > 0)
483 bio = BIO_new_mem_buf(data_body->data,data_body->length);
484 else {
485 bio=BIO_new(BIO_s_mem());
486 BIO_set_mem_eof_return(bio,0);
487 }
488#endif
489 }
490 BIO_push(out,bio);
491 bio=NULL;
492#endif
493 if (0)
494 {
495err:
496 if (out != NULL) BIO_free_all(out);
497 if (btmp != NULL) BIO_free_all(btmp);
498 if (etmp != NULL) BIO_free_all(etmp);
499 if (bio != NULL) BIO_free_all(bio);
500 out=NULL;
501 }
502 if (tmp != NULL)
503 OPENSSL_free(tmp);
504 return(out);
505 }
506
507int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
508 {
509 int ret=0;
510 int i,j;
511 BIO *btmp;
512 BUF_MEM *buf_mem=NULL;
513 BUF_MEM *buf=NULL;
514 PKCS7_SIGNER_INFO *si;
515 EVP_MD_CTX *mdc,ctx_tmp;
516 STACK_OF(X509_ATTRIBUTE) *sk;
517 STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
518 ASN1_OCTET_STRING *os=NULL;
519
520 EVP_MD_CTX_init(&ctx_tmp);
521 i=OBJ_obj2nid(p7->type);
522 p7->state=PKCS7_S_HEADER;
523
524 switch (i)
525 {
526 case NID_pkcs7_signedAndEnveloped:
527 /* XXXXXXXXXXXXXXXX */
528 si_sk=p7->d.signed_and_enveloped->signer_info;
529 if (!(os=M_ASN1_OCTET_STRING_new()))
530 {
531 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_MALLOC_FAILURE);
532 goto err;
533 }
534 p7->d.signed_and_enveloped->enc_data->enc_data=os;
535 break;
536 case NID_pkcs7_enveloped:
537 /* XXXXXXXXXXXXXXXX */
538 if (!(os=M_ASN1_OCTET_STRING_new()))
539 {
540 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_MALLOC_FAILURE);
541 goto err;
542 }
543 p7->d.enveloped->enc_data->enc_data=os;
544 break;
545 case NID_pkcs7_signed:
546 si_sk=p7->d.sign->signer_info;
547 os=PKCS7_get_octet_string(p7->d.sign->contents);
548 /* If detached data then the content is excluded */
549 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
550 M_ASN1_OCTET_STRING_free(os);
551 p7->d.sign->contents->d.data = NULL;
552 }
553 break;
554 }
555
556 if (si_sk != NULL)
557 {
558 if ((buf=BUF_MEM_new()) == NULL)
559 {
560 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
561 goto err;
562 }
563 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
564 {
565 si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
566 if (si->pkey == NULL) continue;
567
568 j=OBJ_obj2nid(si->digest_alg->algorithm);
569
570 btmp=bio;
571 for (;;)
572 {
573 if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD))
574 == NULL)
575 {
576 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
577 goto err;
578 }
579 BIO_get_md_ctx(btmp,&mdc);
580 if (mdc == NULL)
581 {
582 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_INTERNAL_ERROR);
583 goto err;
584 }
585 if (EVP_MD_CTX_type(mdc) == j)
586 break;
587 else
588 btmp=BIO_next(btmp);
589 }
590
591 /* We now have the EVP_MD_CTX, lets do the
592 * signing. */
593 EVP_MD_CTX_copy_ex(&ctx_tmp,mdc);
594 if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey)))
595 {
596 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
597 goto err;
598 }
599
600 sk=si->auth_attr;
601
602 /* If there are attributes, we add the digest
603 * attribute and only sign the attributes */
604 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
605 {
606 unsigned char md_data[EVP_MAX_MD_SIZE], *abuf=NULL;
607 unsigned int md_len, alen;
608 ASN1_OCTET_STRING *digest;
609 ASN1_UTCTIME *sign_time;
610 const EVP_MD *md_tmp;
611
612 /* Add signing time if not already present */
613 if (!PKCS7_get_signed_attribute(si,
614 NID_pkcs9_signingTime))
615 {
616 if (!(sign_time=X509_gmtime_adj(NULL,0)))
617 {
618 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
619 ERR_R_MALLOC_FAILURE);
620 goto err;
621 }
622 PKCS7_add_signed_attribute(si,
623 NID_pkcs9_signingTime,
624 V_ASN1_UTCTIME,sign_time);
625 }
626
627 /* Add digest */
628 md_tmp=EVP_MD_CTX_md(&ctx_tmp);
629 EVP_DigestFinal_ex(&ctx_tmp,md_data,&md_len);
630 if (!(digest=M_ASN1_OCTET_STRING_new()))
631 {
632 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
633 ERR_R_MALLOC_FAILURE);
634 goto err;
635 }
636 if (!M_ASN1_OCTET_STRING_set(digest,md_data,
637 md_len))
638 {
639 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
640 ERR_R_MALLOC_FAILURE);
641 goto err;
642 }
643 PKCS7_add_signed_attribute(si,
644 NID_pkcs9_messageDigest,
645 V_ASN1_OCTET_STRING,digest);
646
647 /* Now sign the attributes */
648 EVP_SignInit_ex(&ctx_tmp,md_tmp,NULL);
649 alen = ASN1_item_i2d((ASN1_VALUE *)sk,&abuf,
650 ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
651 if(!abuf) goto err;
652 EVP_SignUpdate(&ctx_tmp,abuf,alen);
653 OPENSSL_free(abuf);
654 }
655
656#ifndef OPENSSL_NO_DSA
657 if (si->pkey->type == EVP_PKEY_DSA)
658 ctx_tmp.digest=EVP_dss1();
659#endif
660
661 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
662 (unsigned int *)&buf->length,si->pkey))
663 {
664 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB);
665 goto err;
666 }
667 if (!ASN1_STRING_set(si->enc_digest,
668 (unsigned char *)buf->data,buf->length))
669 {
670 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB);
671 goto err;
672 }
673 }
674 }
675
676 if (!PKCS7_is_detached(p7))
677 {
678 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
679 if (btmp == NULL)
680 {
681 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
682 goto err;
683 }
684 BIO_get_mem_ptr(btmp,&buf_mem);
685 /* Mark the BIO read only then we can use its copy of the data
686 * instead of making an extra copy.
687 */
688 BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
689 BIO_set_mem_eof_return(btmp, 0);
690 os->data = (unsigned char *)buf_mem->data;
691 os->length = buf_mem->length;
692#if 0
693 M_ASN1_OCTET_STRING_set(os,
694 (unsigned char *)buf_mem->data,buf_mem->length);
695#endif
696 }
697 ret=1;
698err:
699 EVP_MD_CTX_cleanup(&ctx_tmp);
700 if (buf != NULL) BUF_MEM_free(buf);
701 return(ret);
702 }
703
704int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
705 PKCS7 *p7, PKCS7_SIGNER_INFO *si)
706 {
707 PKCS7_ISSUER_AND_SERIAL *ias;
708 int ret=0,i;
709 STACK_OF(X509) *cert;
710 X509 *x509;
711
712 if (PKCS7_type_is_signed(p7))
713 {
714 cert=p7->d.sign->cert;
715 }
716 else if (PKCS7_type_is_signedAndEnveloped(p7))
717 {
718 cert=p7->d.signed_and_enveloped->cert;
719 }
720 else
721 {
722 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);
723 goto err;
724 }
725 /* XXXXXXXXXXXXXXXXXXXXXXX */
726 ias=si->issuer_and_serial;
727
728 x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);
729
730 /* were we able to find the cert in passed to us */
731 if (x509 == NULL)
732 {
733 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
734 goto err;
735 }
736
737 /* Lets verify */
738 if(!X509_STORE_CTX_init(ctx,cert_store,x509,cert))
739 {
740 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
741 goto err;
742 }
743 X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN);
744 i=X509_verify_cert(ctx);
745 if (i <= 0)
746 {
747 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
748 X509_STORE_CTX_cleanup(ctx);
749 goto err;
750 }
751 X509_STORE_CTX_cleanup(ctx);
752
753 return PKCS7_signatureVerify(bio, p7, si, x509);
754 err:
755 return ret;
756 }
757
758int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
759 X509 *x509)
760 {
761 ASN1_OCTET_STRING *os;
762 EVP_MD_CTX mdc_tmp,*mdc;
763 int ret=0,i;
764 int md_type;
765 STACK_OF(X509_ATTRIBUTE) *sk;
766 BIO *btmp;
767 EVP_PKEY *pkey;
768
769 EVP_MD_CTX_init(&mdc_tmp);
770
771 if (!PKCS7_type_is_signed(p7) &&
772 !PKCS7_type_is_signedAndEnveloped(p7)) {
773 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
774 PKCS7_R_WRONG_PKCS7_TYPE);
775 goto err;
776 }
777
778 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
779
780 btmp=bio;
781 for (;;)
782 {
783 if ((btmp == NULL) ||
784 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
785 {
786 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
787 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
788 goto err;
789 }
790 BIO_get_md_ctx(btmp,&mdc);
791 if (mdc == NULL)
792 {
793 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
794 ERR_R_INTERNAL_ERROR);
795 goto err;
796 }
797 if (EVP_MD_CTX_type(mdc) == md_type)
798 break;
799 /* Workaround for some broken clients that put the signature
800 * OID instead of the digest OID in digest_alg->algorithm
801 */
802 if (EVP_MD_pkey_type(EVP_MD_CTX_md(mdc)) == md_type)
803 break;
804 btmp=BIO_next(btmp);
805 }
806
807 /* mdc is the digest ctx that we want, unless there are attributes,
808 * in which case the digest is the signed attributes */
809 EVP_MD_CTX_copy_ex(&mdc_tmp,mdc);
810
811 sk=si->auth_attr;
812 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
813 {
814 unsigned char md_dat[EVP_MAX_MD_SIZE], *abuf = NULL;
815 unsigned int md_len, alen;
816 ASN1_OCTET_STRING *message_digest;
817
818 EVP_DigestFinal_ex(&mdc_tmp,md_dat,&md_len);
819 message_digest=PKCS7_digest_from_attributes(sk);
820 if (!message_digest)
821 {
822 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
823 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
824 goto err;
825 }
826 if ((message_digest->length != (int)md_len) ||
827 (memcmp(message_digest->data,md_dat,md_len)))
828 {
829#if 0
830{
831int ii;
832for (ii=0; ii<message_digest->length; ii++)
833 printf("%02X",message_digest->data[ii]); printf(" sent\n");
834for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
835}
836#endif
837 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
838 PKCS7_R_DIGEST_FAILURE);
839 ret= -1;
840 goto err;
841 }
842
843 EVP_VerifyInit_ex(&mdc_tmp,EVP_get_digestbynid(md_type), NULL);
844
845 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
846 ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
847 EVP_VerifyUpdate(&mdc_tmp, abuf, alen);
848
849 OPENSSL_free(abuf);
850 }
851
852 os=si->enc_digest;
853 pkey = X509_get_pubkey(x509);
854 if (!pkey)
855 {
856 ret = -1;
857 goto err;
858 }
859#ifndef OPENSSL_NO_DSA
860 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
861#endif
862
863 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
864 EVP_PKEY_free(pkey);
865 if (i <= 0)
866 {
867 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
868 PKCS7_R_SIGNATURE_FAILURE);
869 ret= -1;
870 goto err;
871 }
872 else
873 ret=1;
874err:
875 EVP_MD_CTX_cleanup(&mdc_tmp);
876 return(ret);
877 }
878
879PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
880 {
881 STACK_OF(PKCS7_RECIP_INFO) *rsk;
882 PKCS7_RECIP_INFO *ri;
883 int i;
884
885 i=OBJ_obj2nid(p7->type);
886 if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
887 rsk=p7->d.signed_and_enveloped->recipientinfo;
888 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
889 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
890 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
891 return(ri->issuer_and_serial);
892 }
893
894ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid)
895 {
896 return(get_attribute(si->auth_attr,nid));
897 }
898
899ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
900 {
901 return(get_attribute(si->unauth_attr,nid));
902 }
903
904static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
905 {
906 int i;
907 X509_ATTRIBUTE *xa;
908 ASN1_OBJECT *o;
909
910 o=OBJ_nid2obj(nid);
911 if (!o || !sk) return(NULL);
912 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
913 {
914 xa=sk_X509_ATTRIBUTE_value(sk,i);
915 if (OBJ_cmp(xa->object,o) == 0)
916 {
917 if (!xa->single && sk_ASN1_TYPE_num(xa->value.set))
918 return(sk_ASN1_TYPE_value(xa->value.set,0));
919 else
920 return(NULL);
921 }
922 }
923 return(NULL);
924 }
925
926ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
927{
928 ASN1_TYPE *astype;
929 if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
930 return astype->value.octet_string;
931}
932
933int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
934 STACK_OF(X509_ATTRIBUTE) *sk)
935 {
936 int i;
937
938 if (p7si->auth_attr != NULL)
939 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
940 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
941 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
942 {
943 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
944 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
945 == NULL)
946 return(0);
947 }
948 return(1);
949 }
950
951int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
952 {
953 int i;
954
955 if (p7si->unauth_attr != NULL)
956 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
957 X509_ATTRIBUTE_free);
958 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
959 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
960 {
961 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
962 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
963 == NULL)
964 return(0);
965 }
966 return(1);
967 }
968
969int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
970 void *value)
971 {
972 return(add_attribute(&(p7si->auth_attr),nid,atrtype,value));
973 }
974
975int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
976 void *value)
977 {
978 return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
979 }
980
981static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
982 void *value)
983 {
984 X509_ATTRIBUTE *attr=NULL;
985
986 if (*sk == NULL)
987 {
988 *sk = sk_X509_ATTRIBUTE_new_null();
989new_attrib:
990 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
991 sk_X509_ATTRIBUTE_push(*sk,attr);
992 }
993 else
994 {
995 int i;
996
997 for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
998 {
999 attr=sk_X509_ATTRIBUTE_value(*sk,i);
1000 if (OBJ_obj2nid(attr->object) == nid)
1001 {
1002 X509_ATTRIBUTE_free(attr);
1003 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
1004 sk_X509_ATTRIBUTE_set(*sk,i,attr);
1005 goto end;
1006 }
1007 }
1008 goto new_attrib;
1009 }
1010end:
1011 return(1);
1012 }
1013
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
new file mode 100644
index 0000000000..ee1817c7af
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -0,0 +1,500 @@
1/* crypto/pkcs7/pk7_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/x509.h>
63
64long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
65 {
66 int nid;
67 long ret;
68
69 nid=OBJ_obj2nid(p7->type);
70
71 switch (cmd)
72 {
73 case PKCS7_OP_SET_DETACHED_SIGNATURE:
74 if (nid == NID_pkcs7_signed)
75 {
76 ret=p7->detached=(int)larg;
77 if (ret && PKCS7_type_is_data(p7->d.sign->contents))
78 {
79 ASN1_OCTET_STRING *os;
80 os=p7->d.sign->contents->d.data;
81 ASN1_OCTET_STRING_free(os);
82 p7->d.sign->contents->d.data = NULL;
83 }
84 }
85 else
86 {
87 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
88 ret=0;
89 }
90 break;
91 case PKCS7_OP_GET_DETACHED_SIGNATURE:
92 if (nid == NID_pkcs7_signed)
93 {
94 if(!p7->d.sign || !p7->d.sign->contents->d.ptr)
95 ret = 1;
96 else ret = 0;
97
98 p7->detached = ret;
99 }
100 else
101 {
102 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
103 ret=0;
104 }
105
106 break;
107 default:
108 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION);
109 ret=0;
110 }
111 return(ret);
112 }
113
114int PKCS7_content_new(PKCS7 *p7, int type)
115 {
116 PKCS7 *ret=NULL;
117
118 if ((ret=PKCS7_new()) == NULL) goto err;
119 if (!PKCS7_set_type(ret,type)) goto err;
120 if (!PKCS7_set_content(p7,ret)) goto err;
121
122 return(1);
123err:
124 if (ret != NULL) PKCS7_free(ret);
125 return(0);
126 }
127
128int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
129 {
130 int i;
131
132 i=OBJ_obj2nid(p7->type);
133 switch (i)
134 {
135 case NID_pkcs7_signed:
136 if (p7->d.sign->contents != NULL)
137 PKCS7_free(p7->d.sign->contents);
138 p7->d.sign->contents=p7_data;
139 break;
140 case NID_pkcs7_digest:
141 case NID_pkcs7_data:
142 case NID_pkcs7_enveloped:
143 case NID_pkcs7_signedAndEnveloped:
144 case NID_pkcs7_encrypted:
145 default:
146 PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
147 goto err;
148 }
149 return(1);
150err:
151 return(0);
152 }
153
154int PKCS7_set_type(PKCS7 *p7, int type)
155 {
156 ASN1_OBJECT *obj;
157
158 /*PKCS7_content_free(p7);*/
159 obj=OBJ_nid2obj(type); /* will not fail */
160
161 switch (type)
162 {
163 case NID_pkcs7_signed:
164 p7->type=obj;
165 if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL)
166 goto err;
167 if (!ASN1_INTEGER_set(p7->d.sign->version,1))
168 {
169 PKCS7_SIGNED_free(p7->d.sign);
170 p7->d.sign=NULL;
171 goto err;
172 }
173 break;
174 case NID_pkcs7_data:
175 p7->type=obj;
176 if ((p7->d.data=M_ASN1_OCTET_STRING_new()) == NULL)
177 goto err;
178 break;
179 case NID_pkcs7_signedAndEnveloped:
180 p7->type=obj;
181 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
182 == NULL) goto err;
183 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1);
184 if (!ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1))
185 goto err;
186 p7->d.signed_and_enveloped->enc_data->content_type
187 = OBJ_nid2obj(NID_pkcs7_data);
188 break;
189 case NID_pkcs7_enveloped:
190 p7->type=obj;
191 if ((p7->d.enveloped=PKCS7_ENVELOPE_new())
192 == NULL) goto err;
193 if (!ASN1_INTEGER_set(p7->d.enveloped->version,0))
194 goto err;
195 p7->d.enveloped->enc_data->content_type
196 = OBJ_nid2obj(NID_pkcs7_data);
197 break;
198 case NID_pkcs7_encrypted:
199 p7->type=obj;
200 if ((p7->d.encrypted=PKCS7_ENCRYPT_new())
201 == NULL) goto err;
202 if (!ASN1_INTEGER_set(p7->d.encrypted->version,0))
203 goto err;
204 p7->d.encrypted->enc_data->content_type
205 = OBJ_nid2obj(NID_pkcs7_data);
206 break;
207
208 case NID_pkcs7_digest:
209 default:
210 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
211 goto err;
212 }
213 return(1);
214err:
215 return(0);
216 }
217
218int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
219 {
220 int i,j,nid;
221 X509_ALGOR *alg;
222 STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
223 STACK_OF(X509_ALGOR) *md_sk;
224
225 i=OBJ_obj2nid(p7->type);
226 switch (i)
227 {
228 case NID_pkcs7_signed:
229 signer_sk= p7->d.sign->signer_info;
230 md_sk= p7->d.sign->md_algs;
231 break;
232 case NID_pkcs7_signedAndEnveloped:
233 signer_sk= p7->d.signed_and_enveloped->signer_info;
234 md_sk= p7->d.signed_and_enveloped->md_algs;
235 break;
236 default:
237 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE);
238 return(0);
239 }
240
241 nid=OBJ_obj2nid(psi->digest_alg->algorithm);
242
243 /* If the digest is not currently listed, add it */
244 j=0;
245 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
246 {
247 alg=sk_X509_ALGOR_value(md_sk,i);
248 if (OBJ_obj2nid(alg->algorithm) == nid)
249 {
250 j=1;
251 break;
252 }
253 }
254 if (!j) /* we need to add another algorithm */
255 {
256 if(!(alg=X509_ALGOR_new())
257 || !(alg->parameter = ASN1_TYPE_new())) {
258 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE);
259 return(0);
260 }
261 alg->algorithm=OBJ_nid2obj(nid);
262 alg->parameter->type = V_ASN1_NULL;
263 sk_X509_ALGOR_push(md_sk,alg);
264 }
265
266 sk_PKCS7_SIGNER_INFO_push(signer_sk,psi);
267 return(1);
268 }
269
270int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
271 {
272 int i;
273 STACK_OF(X509) **sk;
274
275 i=OBJ_obj2nid(p7->type);
276 switch (i)
277 {
278 case NID_pkcs7_signed:
279 sk= &(p7->d.sign->cert);
280 break;
281 case NID_pkcs7_signedAndEnveloped:
282 sk= &(p7->d.signed_and_enveloped->cert);
283 break;
284 default:
285 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE);
286 return(0);
287 }
288
289 if (*sk == NULL)
290 *sk=sk_X509_new_null();
291 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
292 sk_X509_push(*sk,x509);
293 return(1);
294 }
295
296int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
297 {
298 int i;
299 STACK_OF(X509_CRL) **sk;
300
301 i=OBJ_obj2nid(p7->type);
302 switch (i)
303 {
304 case NID_pkcs7_signed:
305 sk= &(p7->d.sign->crl);
306 break;
307 case NID_pkcs7_signedAndEnveloped:
308 sk= &(p7->d.signed_and_enveloped->crl);
309 break;
310 default:
311 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE);
312 return(0);
313 }
314
315 if (*sk == NULL)
316 *sk=sk_X509_CRL_new_null();
317
318 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
319 sk_X509_CRL_push(*sk,crl);
320 return(1);
321 }
322
323int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
324 const EVP_MD *dgst)
325 {
326 char is_dsa;
327 if (pkey->type == EVP_PKEY_DSA) is_dsa = 1;
328 else is_dsa = 0;
329 /* We now need to add another PKCS7_SIGNER_INFO entry */
330 if (!ASN1_INTEGER_set(p7i->version,1))
331 goto err;
332 if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
333 X509_get_issuer_name(x509)))
334 goto err;
335
336 /* because ASN1_INTEGER_set is used to set a 'long' we will do
337 * things the ugly way. */
338 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
339 if (!(p7i->issuer_and_serial->serial=
340 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
341 goto err;
342
343 /* lets keep the pkey around for a while */
344 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
345 p7i->pkey=pkey;
346
347 /* Set the algorithms */
348 if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
349 else
350 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
351
352 if (p7i->digest_alg->parameter != NULL)
353 ASN1_TYPE_free(p7i->digest_alg->parameter);
354 if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL)
355 goto err;
356 p7i->digest_alg->parameter->type=V_ASN1_NULL;
357
358 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type));
359
360 if (p7i->digest_enc_alg->parameter != NULL)
361 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
362 if(is_dsa) p7i->digest_enc_alg->parameter = NULL;
363 else {
364 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
365 goto err;
366 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
367 }
368
369 return(1);
370err:
371 return(0);
372 }
373
374PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
375 const EVP_MD *dgst)
376 {
377 PKCS7_SIGNER_INFO *si;
378
379 if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
380 if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
381 if (!PKCS7_add_signer(p7,si)) goto err;
382 return(si);
383err:
384 return(NULL);
385 }
386
387STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
388 {
389 if (PKCS7_type_is_signed(p7))
390 {
391 return(p7->d.sign->signer_info);
392 }
393 else if (PKCS7_type_is_signedAndEnveloped(p7))
394 {
395 return(p7->d.signed_and_enveloped->signer_info);
396 }
397 else
398 return(NULL);
399 }
400
401PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
402 {
403 PKCS7_RECIP_INFO *ri;
404
405 if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
406 if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
407 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
408 return(ri);
409err:
410 return(NULL);
411 }
412
413int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
414 {
415 int i;
416 STACK_OF(PKCS7_RECIP_INFO) *sk;
417
418 i=OBJ_obj2nid(p7->type);
419 switch (i)
420 {
421 case NID_pkcs7_signedAndEnveloped:
422 sk= p7->d.signed_and_enveloped->recipientinfo;
423 break;
424 case NID_pkcs7_enveloped:
425 sk= p7->d.enveloped->recipientinfo;
426 break;
427 default:
428 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
429 return(0);
430 }
431
432 sk_PKCS7_RECIP_INFO_push(sk,ri);
433 return(1);
434 }
435
436int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
437 {
438 if (!ASN1_INTEGER_set(p7i->version,0))
439 return 0;
440 if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
441 X509_get_issuer_name(x509)))
442 return 0;
443
444 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
445 if (!(p7i->issuer_and_serial->serial=
446 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
447 return 0;
448
449 X509_ALGOR_free(p7i->key_enc_algor);
450 if (!(p7i->key_enc_algor= X509_ALGOR_dup(x509->cert_info->key->algor)))
451 return 0;
452
453 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
454 p7i->cert=x509;
455
456 return(1);
457 }
458
459X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
460 {
461 if (PKCS7_type_is_signed(p7))
462 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
463 si->issuer_and_serial->issuer,
464 si->issuer_and_serial->serial));
465 else
466 return(NULL);
467 }
468
469int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
470 {
471 int i;
472 ASN1_OBJECT *objtmp;
473 PKCS7_ENC_CONTENT *ec;
474
475 i=OBJ_obj2nid(p7->type);
476 switch (i)
477 {
478 case NID_pkcs7_signedAndEnveloped:
479 ec=p7->d.signed_and_enveloped->enc_data;
480 break;
481 case NID_pkcs7_enveloped:
482 ec=p7->d.enveloped->enc_data;
483 break;
484 default:
485 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
486 return(0);
487 }
488
489 /* Check cipher OID exists and has data in it*/
490 i = EVP_CIPHER_type(cipher);
491 if(i == NID_undef) {
492 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
493 return(0);
494 }
495 objtmp = OBJ_nid2obj(i);
496
497 ec->cipher = cipher;
498 return 1;
499 }
500
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c
new file mode 100644
index 0000000000..5d2a97839d
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_mime.c
@@ -0,0 +1,714 @@
1/* pk7_mime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-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#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64
65/* MIME and related routines */
66
67/* MIME format structures
68 * Note that all are translated to lower case apart from
69 * parameter values. Quotes are stripped off
70 */
71
72typedef struct {
73char *param_name; /* Param name e.g. "micalg" */
74char *param_value; /* Param value e.g. "sha1" */
75} MIME_PARAM;
76
77DECLARE_STACK_OF(MIME_PARAM)
78IMPLEMENT_STACK_OF(MIME_PARAM)
79
80typedef struct {
81char *name; /* Name of line e.g. "content-type" */
82char *value; /* Value of line e.g. "text/plain" */
83STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */
84} MIME_HEADER;
85
86DECLARE_STACK_OF(MIME_HEADER)
87IMPLEMENT_STACK_OF(MIME_HEADER)
88
89static int B64_write_PKCS7(BIO *bio, PKCS7 *p7);
90static PKCS7 *B64_read_PKCS7(BIO *bio);
91static char * strip_ends(char *name);
92static char * strip_start(char *name);
93static char * strip_end(char *name);
94static MIME_HEADER *mime_hdr_new(char *name, char *value);
95static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
96static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio);
97static int mime_hdr_cmp(const MIME_HEADER * const *a,
98 const MIME_HEADER * const *b);
99static int mime_param_cmp(const MIME_PARAM * const *a,
100 const MIME_PARAM * const *b);
101static void mime_param_free(MIME_PARAM *param);
102static int mime_bound_check(char *line, int linelen, char *bound, int blen);
103static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret);
104static int strip_eol(char *linebuf, int *plen);
105static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name);
106static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name);
107static void mime_hdr_free(MIME_HEADER *hdr);
108
109#define MAX_SMLEN 1024
110#define mime_debug(x) /* x */
111
112
113typedef void (*stkfree)();
114
115/* Base 64 read and write of PKCS#7 structure */
116
117static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
118{
119 BIO *b64;
120 if(!(b64 = BIO_new(BIO_f_base64()))) {
121 PKCS7err(PKCS7_F_B64_WRITE_PKCS7,ERR_R_MALLOC_FAILURE);
122 return 0;
123 }
124 bio = BIO_push(b64, bio);
125 i2d_PKCS7_bio(bio, p7);
126 BIO_flush(bio);
127 bio = BIO_pop(bio);
128 BIO_free(b64);
129 return 1;
130}
131
132static PKCS7 *B64_read_PKCS7(BIO *bio)
133{
134 BIO *b64;
135 PKCS7 *p7;
136 if(!(b64 = BIO_new(BIO_f_base64()))) {
137 PKCS7err(PKCS7_F_B64_READ_PKCS7,ERR_R_MALLOC_FAILURE);
138 return 0;
139 }
140 bio = BIO_push(b64, bio);
141 if(!(p7 = d2i_PKCS7_bio(bio, NULL)))
142 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR);
143 BIO_flush(bio);
144 bio = BIO_pop(bio);
145 BIO_free(b64);
146 return p7;
147}
148
149/* SMIME sender */
150
151int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
152{
153 char bound[33], c;
154 int i;
155 char *mime_prefix, *mime_eol;
156 if (flags & PKCS7_NOOLDMIMETYPE)
157 mime_prefix = "application/pkcs7-";
158 else
159 mime_prefix = "application/x-pkcs7-";
160 if (flags & PKCS7_CRLFEOL)
161 mime_eol = "\r\n";
162 else
163 mime_eol = "\n";
164 if((flags & PKCS7_DETACHED) && data) {
165 /* We want multipart/signed */
166 /* Generate a random boundary */
167 RAND_pseudo_bytes((unsigned char *)bound, 32);
168 for(i = 0; i < 32; i++) {
169 c = bound[i] & 0xf;
170 if(c < 10) c += '0';
171 else c += 'A' - 10;
172 bound[i] = c;
173 }
174 bound[32] = 0;
175 BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
176 BIO_printf(bio, "Content-Type: multipart/signed;");
177 BIO_printf(bio, " protocol=\"%ssignature\";", mime_prefix);
178 BIO_printf(bio, " micalg=sha1; boundary=\"----%s\"%s%s",
179 bound, mime_eol, mime_eol);
180 BIO_printf(bio, "This is an S/MIME signed message%s%s",
181 mime_eol, mime_eol);
182 /* Now write out the first part */
183 BIO_printf(bio, "------%s%s", bound, mime_eol);
184 SMIME_crlf_copy(data, bio, flags);
185 BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol);
186
187 /* Headers for signature */
188
189 BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix);
190 BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol);
191 BIO_printf(bio, "Content-Transfer-Encoding: base64%s",
192 mime_eol);
193 BIO_printf(bio, "Content-Disposition: attachment;");
194 BIO_printf(bio, " filename=\"smime.p7s\"%s%s",
195 mime_eol, mime_eol);
196 B64_write_PKCS7(bio, p7);
197 BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound,
198 mime_eol, mime_eol);
199 return 1;
200 }
201 /* MIME headers */
202 BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
203 BIO_printf(bio, "Content-Disposition: attachment;");
204 BIO_printf(bio, " filename=\"smime.p7m\"%s", mime_eol);
205 BIO_printf(bio, "Content-Type: %smime;", mime_prefix);
206 BIO_printf(bio, " name=\"smime.p7m\"%s", mime_eol);
207 BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s",
208 mime_eol, mime_eol);
209 B64_write_PKCS7(bio, p7);
210 BIO_printf(bio, "%s", mime_eol);
211 return 1;
212}
213
214/* SMIME reader: handle multipart/signed and opaque signing.
215 * in multipart case the content is placed in a memory BIO
216 * pointed to by "bcont". In opaque this is set to NULL
217 */
218
219PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
220{
221 BIO *p7in;
222 STACK_OF(MIME_HEADER) *headers = NULL;
223 STACK_OF(BIO) *parts = NULL;
224 MIME_HEADER *hdr;
225 MIME_PARAM *prm;
226 PKCS7 *p7;
227 int ret;
228
229 if(bcont) *bcont = NULL;
230
231 if (!(headers = mime_parse_hdr(bio))) {
232 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_PARSE_ERROR);
233 return NULL;
234 }
235
236 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
237 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
238 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE);
239 return NULL;
240 }
241
242 /* Handle multipart/signed */
243
244 if(!strcmp(hdr->value, "multipart/signed")) {
245 /* Split into two parts */
246 prm = mime_param_find(hdr, "boundary");
247 if(!prm || !prm->param_value) {
248 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
249 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BOUNDARY);
250 return NULL;
251 }
252 ret = multi_split(bio, prm->param_value, &parts);
253 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
254 if(!ret || (sk_BIO_num(parts) != 2) ) {
255 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BODY_FAILURE);
256 sk_BIO_pop_free(parts, BIO_vfree);
257 return NULL;
258 }
259
260 /* Parse the signature piece */
261 p7in = sk_BIO_value(parts, 1);
262
263 if (!(headers = mime_parse_hdr(p7in))) {
264 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR);
265 sk_BIO_pop_free(parts, BIO_vfree);
266 return NULL;
267 }
268
269 /* Get content type */
270
271 if(!(hdr = mime_hdr_find(headers, "content-type")) ||
272 !hdr->value) {
273 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
274 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE);
275 return NULL;
276 }
277
278 if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
279 strcmp(hdr->value, "application/pkcs7-signature")) {
280 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
281 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE);
282 ERR_add_error_data(2, "type: ", hdr->value);
283 sk_BIO_pop_free(parts, BIO_vfree);
284 return NULL;
285 }
286 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
287 /* Read in PKCS#7 */
288 if(!(p7 = B64_read_PKCS7(p7in))) {
289 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR);
290 sk_BIO_pop_free(parts, BIO_vfree);
291 return NULL;
292 }
293
294 if(bcont) {
295 *bcont = sk_BIO_value(parts, 0);
296 BIO_free(p7in);
297 sk_BIO_free(parts);
298 } else sk_BIO_pop_free(parts, BIO_vfree);
299 return p7;
300 }
301
302 /* OK, if not multipart/signed try opaque signature */
303
304 if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
305 strcmp (hdr->value, "application/pkcs7-mime")) {
306 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE);
307 ERR_add_error_data(2, "type: ", hdr->value);
308 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
309 return NULL;
310 }
311
312 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
313
314 if(!(p7 = B64_read_PKCS7(bio))) {
315 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR);
316 return NULL;
317 }
318 return p7;
319
320}
321
322/* Copy text from one BIO to another making the output CRLF at EOL */
323int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
324{
325 char eol;
326 int len;
327 char linebuf[MAX_SMLEN];
328 if(flags & PKCS7_BINARY) {
329 while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
330 BIO_write(out, linebuf, len);
331 return 1;
332 }
333 if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
334 while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
335 eol = strip_eol(linebuf, &len);
336 if (len)
337 BIO_write(out, linebuf, len);
338 if(eol) BIO_write(out, "\r\n", 2);
339 }
340 return 1;
341}
342
343/* Strip off headers if they are text/plain */
344int SMIME_text(BIO *in, BIO *out)
345{
346 char iobuf[4096];
347 int len;
348 STACK_OF(MIME_HEADER) *headers;
349 MIME_HEADER *hdr;
350
351 if (!(headers = mime_parse_hdr(in))) {
352 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
353 return 0;
354 }
355 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
356 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
357 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
358 return 0;
359 }
360 if (strcmp (hdr->value, "text/plain")) {
361 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
362 ERR_add_error_data(2, "type: ", hdr->value);
363 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
364 return 0;
365 }
366 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
367 while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
368 BIO_write(out, iobuf, len);
369 return 1;
370}
371
372/* Split a multipart/XXX message body into component parts: result is
373 * canonical parts in a STACK of bios
374 */
375
376static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
377{
378 char linebuf[MAX_SMLEN];
379 int len, blen;
380 int eol = 0, next_eol = 0;
381 BIO *bpart = NULL;
382 STACK_OF(BIO) *parts;
383 char state, part, first;
384
385 blen = strlen(bound);
386 part = 0;
387 state = 0;
388 first = 1;
389 parts = sk_BIO_new_null();
390 *ret = parts;
391 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
392 state = mime_bound_check(linebuf, len, bound, blen);
393 if(state == 1) {
394 first = 1;
395 part++;
396 } else if(state == 2) {
397 sk_BIO_push(parts, bpart);
398 return 1;
399 } else if(part) {
400 /* Strip CR+LF from linebuf */
401 next_eol = strip_eol(linebuf, &len);
402 if(first) {
403 first = 0;
404 if(bpart) sk_BIO_push(parts, bpart);
405 bpart = BIO_new(BIO_s_mem());
406 BIO_set_mem_eof_return(bpart, 0);
407 } else if (eol)
408 BIO_write(bpart, "\r\n", 2);
409 eol = next_eol;
410 if (len)
411 BIO_write(bpart, linebuf, len);
412 }
413 }
414 return 0;
415}
416
417/* This is the big one: parse MIME header lines up to message body */
418
419#define MIME_INVALID 0
420#define MIME_START 1
421#define MIME_TYPE 2
422#define MIME_NAME 3
423#define MIME_VALUE 4
424#define MIME_QUOTE 5
425#define MIME_COMMENT 6
426
427
428static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
429{
430 char *p, *q, c;
431 char *ntmp;
432 char linebuf[MAX_SMLEN];
433 MIME_HEADER *mhdr = NULL;
434 STACK_OF(MIME_HEADER) *headers;
435 int len, state, save_state = 0;
436
437 headers = sk_MIME_HEADER_new(mime_hdr_cmp);
438 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
439 /* If whitespace at line start then continuation line */
440 if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
441 else state = MIME_START;
442 ntmp = NULL;
443 /* Go through all characters */
444 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
445
446 /* State machine to handle MIME headers
447 * if this looks horrible that's because it *is*
448 */
449
450 switch(state) {
451 case MIME_START:
452 if(c == ':') {
453 state = MIME_TYPE;
454 *p = 0;
455 ntmp = strip_ends(q);
456 q = p + 1;
457 }
458 break;
459
460 case MIME_TYPE:
461 if(c == ';') {
462 mime_debug("Found End Value\n");
463 *p = 0;
464 mhdr = mime_hdr_new(ntmp, strip_ends(q));
465 sk_MIME_HEADER_push(headers, mhdr);
466 ntmp = NULL;
467 q = p + 1;
468 state = MIME_NAME;
469 } else if(c == '(') {
470 save_state = state;
471 state = MIME_COMMENT;
472 }
473 break;
474
475 case MIME_COMMENT:
476 if(c == ')') {
477 state = save_state;
478 }
479 break;
480
481 case MIME_NAME:
482 if(c == '=') {
483 state = MIME_VALUE;
484 *p = 0;
485 ntmp = strip_ends(q);
486 q = p + 1;
487 }
488 break ;
489
490 case MIME_VALUE:
491 if(c == ';') {
492 state = MIME_NAME;
493 *p = 0;
494 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
495 ntmp = NULL;
496 q = p + 1;
497 } else if (c == '"') {
498 mime_debug("Found Quote\n");
499 state = MIME_QUOTE;
500 } else if(c == '(') {
501 save_state = state;
502 state = MIME_COMMENT;
503 }
504 break;
505
506 case MIME_QUOTE:
507 if(c == '"') {
508 mime_debug("Found Match Quote\n");
509 state = MIME_VALUE;
510 }
511 break;
512 }
513 }
514
515 if(state == MIME_TYPE) {
516 mhdr = mime_hdr_new(ntmp, strip_ends(q));
517 sk_MIME_HEADER_push(headers, mhdr);
518 } else if(state == MIME_VALUE)
519 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
520 if(p == linebuf) break; /* Blank line means end of headers */
521}
522
523return headers;
524
525}
526
527static char *strip_ends(char *name)
528{
529 return strip_end(strip_start(name));
530}
531
532/* Strip a parameter of whitespace from start of param */
533static char *strip_start(char *name)
534{
535 char *p, c;
536 /* Look for first non white space or quote */
537 for(p = name; (c = *p) ;p++) {
538 if(c == '"') {
539 /* Next char is start of string if non null */
540 if(p[1]) return p + 1;
541 /* Else null string */
542 return NULL;
543 }
544 if(!isspace((unsigned char)c)) return p;
545 }
546 return NULL;
547}
548
549/* As above but strip from end of string : maybe should handle brackets? */
550static char *strip_end(char *name)
551{
552 char *p, c;
553 if(!name) return NULL;
554 /* Look for first non white space or quote */
555 for(p = name + strlen(name) - 1; p >= name ;p--) {
556 c = *p;
557 if(c == '"') {
558 if(p - 1 == name) return NULL;
559 *p = 0;
560 return name;
561 }
562 if(isspace((unsigned char)c)) *p = 0;
563 else return name;
564 }
565 return NULL;
566}
567
568static MIME_HEADER *mime_hdr_new(char *name, char *value)
569{
570 MIME_HEADER *mhdr;
571 char *tmpname, *tmpval, *p;
572 int c;
573 if(name) {
574 if(!(tmpname = BUF_strdup(name))) return NULL;
575 for(p = tmpname ; *p; p++) {
576 c = *p;
577 if(isupper(c)) {
578 c = tolower(c);
579 *p = c;
580 }
581 }
582 } else tmpname = NULL;
583 if(value) {
584 if(!(tmpval = BUF_strdup(value))) return NULL;
585 for(p = tmpval ; *p; p++) {
586 c = *p;
587 if(isupper(c)) {
588 c = tolower(c);
589 *p = c;
590 }
591 }
592 } else tmpval = NULL;
593 mhdr = (MIME_HEADER *) OPENSSL_malloc(sizeof(MIME_HEADER));
594 if(!mhdr) return NULL;
595 mhdr->name = tmpname;
596 mhdr->value = tmpval;
597 if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL;
598 return mhdr;
599}
600
601static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
602{
603 char *tmpname, *tmpval, *p;
604 int c;
605 MIME_PARAM *mparam;
606 if(name) {
607 tmpname = BUF_strdup(name);
608 if(!tmpname) return 0;
609 for(p = tmpname ; *p; p++) {
610 c = *p;
611 if(isupper(c)) {
612 c = tolower(c);
613 *p = c;
614 }
615 }
616 } else tmpname = NULL;
617 if(value) {
618 tmpval = BUF_strdup(value);
619 if(!tmpval) return 0;
620 } else tmpval = NULL;
621 /* Parameter values are case sensitive so leave as is */
622 mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM));
623 if(!mparam) return 0;
624 mparam->param_name = tmpname;
625 mparam->param_value = tmpval;
626 sk_MIME_PARAM_push(mhdr->params, mparam);
627 return 1;
628}
629
630static int mime_hdr_cmp(const MIME_HEADER * const *a,
631 const MIME_HEADER * const *b)
632{
633 return(strcmp((*a)->name, (*b)->name));
634}
635
636static int mime_param_cmp(const MIME_PARAM * const *a,
637 const MIME_PARAM * const *b)
638{
639 return(strcmp((*a)->param_name, (*b)->param_name));
640}
641
642/* Find a header with a given name (if possible) */
643
644static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
645{
646 MIME_HEADER htmp;
647 int idx;
648 htmp.name = name;
649 idx = sk_MIME_HEADER_find(hdrs, &htmp);
650 if(idx < 0) return NULL;
651 return sk_MIME_HEADER_value(hdrs, idx);
652}
653
654static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
655{
656 MIME_PARAM param;
657 int idx;
658 param.param_name = name;
659 idx = sk_MIME_PARAM_find(hdr->params, &param);
660 if(idx < 0) return NULL;
661 return sk_MIME_PARAM_value(hdr->params, idx);
662}
663
664static void mime_hdr_free(MIME_HEADER *hdr)
665{
666 if(hdr->name) OPENSSL_free(hdr->name);
667 if(hdr->value) OPENSSL_free(hdr->value);
668 if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
669 OPENSSL_free(hdr);
670}
671
672static void mime_param_free(MIME_PARAM *param)
673{
674 if(param->param_name) OPENSSL_free(param->param_name);
675 if(param->param_value) OPENSSL_free(param->param_value);
676 OPENSSL_free(param);
677}
678
679/* Check for a multipart boundary. Returns:
680 * 0 : no boundary
681 * 1 : part boundary
682 * 2 : final boundary
683 */
684static int mime_bound_check(char *line, int linelen, char *bound, int blen)
685{
686 if(linelen == -1) linelen = strlen(line);
687 if(blen == -1) blen = strlen(bound);
688 /* Quickly eliminate if line length too short */
689 if(blen + 2 > linelen) return 0;
690 /* Check for part boundary */
691 if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
692 if(!strncmp(line + blen + 2, "--", 2)) return 2;
693 else return 1;
694 }
695 return 0;
696}
697
698static int strip_eol(char *linebuf, int *plen)
699 {
700 int len = *plen;
701 char *p, c;
702 int is_eol = 0;
703 p = linebuf + len - 1;
704 for (p = linebuf + len - 1; len > 0; len--, p--)
705 {
706 c = *p;
707 if (c == '\n')
708 is_eol = 1;
709 else if (c != '\r')
710 break;
711 }
712 *plen = len;
713 return is_eol;
714 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
new file mode 100644
index 0000000000..a852b49235
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_smime.c
@@ -0,0 +1,471 @@
1/* pk7_smime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple PKCS#7 processing functions */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
67 BIO *data, int flags)
68{
69 PKCS7 *p7;
70 PKCS7_SIGNER_INFO *si;
71 BIO *p7bio;
72 STACK_OF(X509_ALGOR) *smcap;
73 int i;
74
75 if(!X509_check_private_key(signcert, pkey)) {
76 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
77 return NULL;
78 }
79
80 if(!(p7 = PKCS7_new())) {
81 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
82 return NULL;
83 }
84
85 PKCS7_set_type(p7, NID_pkcs7_signed);
86
87 PKCS7_content_new(p7, NID_pkcs7_data);
88
89 if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) {
90 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
91 return NULL;
92 }
93
94 if(!(flags & PKCS7_NOCERTS)) {
95 PKCS7_add_certificate(p7, signcert);
96 if(certs) for(i = 0; i < sk_X509_num(certs); i++)
97 PKCS7_add_certificate(p7, sk_X509_value(certs, i));
98 }
99
100 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
101 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104
105
106 SMIME_crlf_copy(data, p7bio, flags);
107
108 if(!(flags & PKCS7_NOATTR)) {
109 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
110 V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data));
111 /* Add SMIMECapabilities */
112 if(!(flags & PKCS7_NOSMIMECAP))
113 {
114 if(!(smcap = sk_X509_ALGOR_new_null())) {
115 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
116 return NULL;
117 }
118#ifndef OPENSSL_NO_DES
119 PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1);
120#endif
121#ifndef OPENSSL_NO_RC2
122 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128);
123 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64);
124#endif
125#ifndef OPENSSL_NO_DES
126 PKCS7_simple_smimecap (smcap, NID_des_cbc, -1);
127#endif
128#ifndef OPENSSL_NO_RC2
129 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40);
130#endif
131 PKCS7_add_attrib_smimecap (si, smcap);
132 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
133 }
134 }
135
136 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
137
138 if (!PKCS7_dataFinal(p7,p7bio)) {
139 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
140 return NULL;
141 }
142
143 BIO_free_all(p7bio);
144 return p7;
145}
146
147int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
148 BIO *indata, BIO *out, int flags)
149{
150 STACK_OF(X509) *signers;
151 X509 *signer;
152 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
153 PKCS7_SIGNER_INFO *si;
154 X509_STORE_CTX cert_ctx;
155 char buf[4096];
156 int i, j=0, k, ret = 0;
157 BIO *p7bio;
158 BIO *tmpin, *tmpout;
159
160 if(!p7) {
161 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER);
162 return 0;
163 }
164
165 if(!PKCS7_type_is_signed(p7)) {
166 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE);
167 return 0;
168 }
169
170 /* Check for no data and no content: no data to verify signature */
171 if(PKCS7_get_detached(p7) && !indata) {
172 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT);
173 return 0;
174 }
175#if 0
176 /* NB: this test commented out because some versions of Netscape
177 * illegally include zero length content when signing data.
178 */
179
180 /* Check for data and content: two sets of data */
181 if(!PKCS7_get_detached(p7) && indata) {
182 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT);
183 return 0;
184 }
185#endif
186
187 sinfos = PKCS7_get_signer_info(p7);
188
189 if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
190 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA);
191 return 0;
192 }
193
194
195 signers = PKCS7_get0_signers(p7, certs, flags);
196
197 if(!signers) return 0;
198
199 /* Now verify the certificates */
200
201 if (!(flags & PKCS7_NOVERIFY)) for (k = 0; k < sk_X509_num(signers); k++) {
202 signer = sk_X509_value (signers, k);
203 if (!(flags & PKCS7_NOCHAIN)) {
204 if(!X509_STORE_CTX_init(&cert_ctx, store, signer,
205 p7->d.sign->cert))
206 {
207 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_X509_LIB);
208 sk_X509_free(signers);
209 return 0;
210 }
211 X509_STORE_CTX_set_purpose(&cert_ctx,
212 X509_PURPOSE_SMIME_SIGN);
213 } else if(!X509_STORE_CTX_init (&cert_ctx, store, signer, NULL)) {
214 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_X509_LIB);
215 sk_X509_free(signers);
216 return 0;
217 }
218 i = X509_verify_cert(&cert_ctx);
219 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
220 X509_STORE_CTX_cleanup(&cert_ctx);
221 if (i <= 0) {
222 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR);
223 ERR_add_error_data(2, "Verify error:",
224 X509_verify_cert_error_string(j));
225 sk_X509_free(signers);
226 return 0;
227 }
228 /* Check for revocation status here */
229 }
230
231 /* Performance optimization: if the content is a memory BIO then
232 * store its contents in a temporary read only memory BIO. This
233 * avoids potentially large numbers of slow copies of data which will
234 * occur when reading from a read write memory BIO when signatures
235 * are calculated.
236 */
237
238 if (indata && (BIO_method_type(indata) == BIO_TYPE_MEM))
239 {
240 char *ptr;
241 long len;
242 len = BIO_get_mem_data(indata, &ptr);
243 tmpin = BIO_new_mem_buf(ptr, len);
244 if (tmpin == NULL)
245 {
246 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
247 return 0;
248 }
249 }
250 else
251 tmpin = indata;
252
253
254 p7bio=PKCS7_dataInit(p7,tmpin);
255
256 if(flags & PKCS7_TEXT) {
257 if(!(tmpout = BIO_new(BIO_s_mem()))) {
258 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
259 goto err;
260 }
261 } else tmpout = out;
262
263 /* We now have to 'read' from p7bio to calculate digests etc. */
264 for (;;)
265 {
266 i=BIO_read(p7bio,buf,sizeof(buf));
267 if (i <= 0) break;
268 if (tmpout) BIO_write(tmpout, buf, i);
269 }
270
271 if(flags & PKCS7_TEXT) {
272 if(!SMIME_text(tmpout, out)) {
273 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR);
274 BIO_free(tmpout);
275 goto err;
276 }
277 BIO_free(tmpout);
278 }
279
280 /* Now Verify All Signatures */
281 if (!(flags & PKCS7_NOSIGS))
282 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
283 {
284 si=sk_PKCS7_SIGNER_INFO_value(sinfos,i);
285 signer = sk_X509_value (signers, i);
286 j=PKCS7_signatureVerify(p7bio,p7,si, signer);
287 if (j <= 0) {
288 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE);
289 goto err;
290 }
291 }
292
293 ret = 1;
294
295 err:
296
297 if (tmpin == indata)
298 {
299 if(indata) BIO_pop(p7bio);
300 BIO_free_all(p7bio);
301 }
302 else
303 BIO_free_all(tmpin);
304
305 sk_X509_free(signers);
306
307 return ret;
308}
309
310STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
311{
312 STACK_OF(X509) *signers;
313 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
314 PKCS7_SIGNER_INFO *si;
315 PKCS7_ISSUER_AND_SERIAL *ias;
316 X509 *signer;
317 int i;
318
319 if(!p7) {
320 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
321 return NULL;
322 }
323
324 if(!PKCS7_type_is_signed(p7)) {
325 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
326 return NULL;
327 }
328
329 /* Collect all the signers together */
330
331 sinfos = PKCS7_get_signer_info(p7);
332
333 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
334 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
335 return 0;
336 }
337
338 if(!(signers = sk_X509_new_null())) {
339 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
340 return NULL;
341 }
342
343 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
344 {
345 si = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
346 ias = si->issuer_and_serial;
347 signer = NULL;
348 /* If any certificates passed they take priority */
349 if (certs) signer = X509_find_by_issuer_and_serial (certs,
350 ias->issuer, ias->serial);
351 if (!signer && !(flags & PKCS7_NOINTERN)
352 && p7->d.sign->cert) signer =
353 X509_find_by_issuer_and_serial (p7->d.sign->cert,
354 ias->issuer, ias->serial);
355 if (!signer) {
356 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
357 sk_X509_free(signers);
358 return 0;
359 }
360
361 sk_X509_push(signers, signer);
362 }
363 return signers;
364}
365
366
367/* Build a complete PKCS#7 enveloped data */
368
369PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
370 int flags)
371{
372 PKCS7 *p7;
373 BIO *p7bio = NULL;
374 int i;
375 X509 *x509;
376 if(!(p7 = PKCS7_new())) {
377 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
378 return NULL;
379 }
380
381 PKCS7_set_type(p7, NID_pkcs7_enveloped);
382 if(!PKCS7_set_cipher(p7, cipher)) {
383 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
384 goto err;
385 }
386
387 for(i = 0; i < sk_X509_num(certs); i++) {
388 x509 = sk_X509_value(certs, i);
389 if(!PKCS7_add_recipient(p7, x509)) {
390 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,
391 PKCS7_R_ERROR_ADDING_RECIPIENT);
392 goto err;
393 }
394 }
395
396 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
397 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
398 goto err;
399 }
400
401 SMIME_crlf_copy(in, p7bio, flags);
402
403 BIO_flush(p7bio);
404
405 if (!PKCS7_dataFinal(p7,p7bio)) {
406 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
407 goto err;
408 }
409 BIO_free_all(p7bio);
410
411 return p7;
412
413 err:
414
415 BIO_free(p7bio);
416 PKCS7_free(p7);
417 return NULL;
418
419}
420
421int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
422{
423 BIO *tmpmem;
424 int ret, i;
425 char buf[4096];
426
427 if(!p7) {
428 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER);
429 return 0;
430 }
431
432 if(!PKCS7_type_is_enveloped(p7)) {
433 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE);
434 return 0;
435 }
436
437 if(!X509_check_private_key(cert, pkey)) {
438 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
439 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
440 return 0;
441 }
442
443 if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
444 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR);
445 return 0;
446 }
447
448 if (flags & PKCS7_TEXT) {
449 BIO *tmpbuf, *bread;
450 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
451 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
452 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
453 return 0;
454 }
455 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
456 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
457 return 0;
458 }
459 ret = SMIME_text(bread, data);
460 BIO_free_all(bread);
461 return ret;
462 } else {
463 for(;;) {
464 i = BIO_read(tmpmem, buf, sizeof(buf));
465 if(i <= 0) break;
466 BIO_write(data, buf, i);
467 }
468 BIO_free_all(tmpmem);
469 return 1;
470 }
471}
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
new file mode 100644
index 0000000000..15372e18f8
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pkcs7.h
@@ -0,0 +1,451 @@
1/* crypto/pkcs7/pkcs7.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_PKCS7_H
60#define HEADER_PKCS7_H
61
62#include <openssl/asn1.h>
63#include <openssl/bio.h>
64#include <openssl/e_os2.h>
65
66#include <openssl/symhacks.h>
67#include <openssl/ossl_typ.h>
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#ifdef OPENSSL_SYS_WIN32
74/* Under Win32 thes are defined in wincrypt.h */
75#undef PKCS7_ISSUER_AND_SERIAL
76#undef PKCS7_SIGNER_INFO
77#endif
78
79/*
80Encryption_ID DES-CBC
81Digest_ID MD5
82Digest_Encryption_ID rsaEncryption
83Key_Encryption_ID rsaEncryption
84*/
85
86typedef struct pkcs7_issuer_and_serial_st
87 {
88 X509_NAME *issuer;
89 ASN1_INTEGER *serial;
90 } PKCS7_ISSUER_AND_SERIAL;
91
92typedef struct pkcs7_signer_info_st
93 {
94 ASN1_INTEGER *version; /* version 1 */
95 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
96 X509_ALGOR *digest_alg;
97 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
98 X509_ALGOR *digest_enc_alg;
99 ASN1_OCTET_STRING *enc_digest;
100 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
101
102 /* The private key to sign with */
103 EVP_PKEY *pkey;
104 } PKCS7_SIGNER_INFO;
105
106DECLARE_STACK_OF(PKCS7_SIGNER_INFO)
107DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)
108
109typedef struct pkcs7_recip_info_st
110 {
111 ASN1_INTEGER *version; /* version 0 */
112 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
113 X509_ALGOR *key_enc_algor;
114 ASN1_OCTET_STRING *enc_key;
115 X509 *cert; /* get the pub-key from this */
116 } PKCS7_RECIP_INFO;
117
118DECLARE_STACK_OF(PKCS7_RECIP_INFO)
119DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)
120
121typedef struct pkcs7_signed_st
122 {
123 ASN1_INTEGER *version; /* version 1 */
124 STACK_OF(X509_ALGOR) *md_algs; /* md used */
125 STACK_OF(X509) *cert; /* [ 0 ] */
126 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
127 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
128
129 struct pkcs7_st *contents;
130 } PKCS7_SIGNED;
131/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.
132 * How about merging the two */
133
134typedef struct pkcs7_enc_content_st
135 {
136 ASN1_OBJECT *content_type;
137 X509_ALGOR *algorithm;
138 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
139 const EVP_CIPHER *cipher;
140 } PKCS7_ENC_CONTENT;
141
142typedef struct pkcs7_enveloped_st
143 {
144 ASN1_INTEGER *version; /* version 0 */
145 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
146 PKCS7_ENC_CONTENT *enc_data;
147 } PKCS7_ENVELOPE;
148
149typedef struct pkcs7_signedandenveloped_st
150 {
151 ASN1_INTEGER *version; /* version 1 */
152 STACK_OF(X509_ALGOR) *md_algs; /* md used */
153 STACK_OF(X509) *cert; /* [ 0 ] */
154 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
155 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
156
157 PKCS7_ENC_CONTENT *enc_data;
158 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
159 } PKCS7_SIGN_ENVELOPE;
160
161typedef struct pkcs7_digest_st
162 {
163 ASN1_INTEGER *version; /* version 0 */
164 X509_ALGOR *md; /* md used */
165 struct pkcs7_st *contents;
166 ASN1_OCTET_STRING *digest;
167 } PKCS7_DIGEST;
168
169typedef struct pkcs7_encrypted_st
170 {
171 ASN1_INTEGER *version; /* version 0 */
172 PKCS7_ENC_CONTENT *enc_data;
173 } PKCS7_ENCRYPT;
174
175typedef struct pkcs7_st
176 {
177 /* The following is non NULL if it contains ASN1 encoding of
178 * this structure */
179 unsigned char *asn1;
180 long length;
181
182#define PKCS7_S_HEADER 0
183#define PKCS7_S_BODY 1
184#define PKCS7_S_TAIL 2
185 int state; /* used during processing */
186
187 int detached;
188
189 ASN1_OBJECT *type;
190 /* content as defined by the type */
191 /* all encryption/message digests are applied to the 'contents',
192 * leaving out the 'type' field. */
193 union {
194 char *ptr;
195
196 /* NID_pkcs7_data */
197 ASN1_OCTET_STRING *data;
198
199 /* NID_pkcs7_signed */
200 PKCS7_SIGNED *sign;
201
202 /* NID_pkcs7_enveloped */
203 PKCS7_ENVELOPE *enveloped;
204
205 /* NID_pkcs7_signedAndEnveloped */
206 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
207
208 /* NID_pkcs7_digest */
209 PKCS7_DIGEST *digest;
210
211 /* NID_pkcs7_encrypted */
212 PKCS7_ENCRYPT *encrypted;
213
214 /* Anything else */
215 ASN1_TYPE *other;
216 } d;
217 } PKCS7;
218
219DECLARE_STACK_OF(PKCS7)
220DECLARE_ASN1_SET_OF(PKCS7)
221DECLARE_PKCS12_STACK_OF(PKCS7)
222
223#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
224#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
225
226#define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
227#define PKCS7_get_attributes(si) ((si)->unauth_attr)
228
229#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
230#define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
231#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
232#define PKCS7_type_is_signedAndEnveloped(a) \
233 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
234#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
235
236#define PKCS7_set_detached(p,v) \
237 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
238#define PKCS7_get_detached(p) \
239 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
240
241#define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
242
243#ifdef SSLEAY_MACROS
244#ifndef PKCS7_ISSUER_AND_SERIAL_digest
245#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
246 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
247 (char *)data,md,len)
248#endif
249#endif
250
251/* S/MIME related flags */
252
253#define PKCS7_TEXT 0x1
254#define PKCS7_NOCERTS 0x2
255#define PKCS7_NOSIGS 0x4
256#define PKCS7_NOCHAIN 0x8
257#define PKCS7_NOINTERN 0x10
258#define PKCS7_NOVERIFY 0x20
259#define PKCS7_DETACHED 0x40
260#define PKCS7_BINARY 0x80
261#define PKCS7_NOATTR 0x100
262#define PKCS7_NOSMIMECAP 0x200
263#define PKCS7_NOOLDMIMETYPE 0x400
264#define PKCS7_CRLFEOL 0x800
265
266/* Flags: for compatibility with older code */
267
268#define SMIME_TEXT PKCS7_TEXT
269#define SMIME_NOCERTS PKCS7_NOCERTS
270#define SMIME_NOSIGS PKCS7_NOSIGS
271#define SMIME_NOCHAIN PKCS7_NOCHAIN
272#define SMIME_NOINTERN PKCS7_NOINTERN
273#define SMIME_NOVERIFY PKCS7_NOVERIFY
274#define SMIME_DETACHED PKCS7_DETACHED
275#define SMIME_BINARY PKCS7_BINARY
276#define SMIME_NOATTR PKCS7_NOATTR
277
278DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
279
280#ifndef SSLEAY_MACROS
281int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
282 unsigned char *md,unsigned int *len);
283#ifndef OPENSSL_NO_FP_API
284PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
285int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
286#endif
287PKCS7 *PKCS7_dup(PKCS7 *p7);
288PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
289int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
290#endif
291
292DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
293DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
294DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
295DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
296DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
297DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
298DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
299DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
300DECLARE_ASN1_FUNCTIONS(PKCS7)
301
302DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
303DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
304
305
306long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
307
308int PKCS7_set_type(PKCS7 *p7, int type);
309int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
310int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
311 const EVP_MD *dgst);
312int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
313int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
314int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
315int PKCS7_content_new(PKCS7 *p7, int nid);
316int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
317 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
318int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
319 X509 *x509);
320
321BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
322int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
323BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
324
325
326PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
327 EVP_PKEY *pkey, const EVP_MD *dgst);
328X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
329STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
330
331PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
332int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
333int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
334int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
335
336PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
337ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
338int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
339 void *data);
340int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
341 void *value);
342ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
343ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
344int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
345 STACK_OF(X509_ATTRIBUTE) *sk);
346int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
347
348
349PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
350 BIO *data, int flags);
351int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
352 BIO *indata, BIO *out, int flags);
353STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
354PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
355 int flags);
356int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
357
358int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
359 STACK_OF(X509_ALGOR) *cap);
360STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
361int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
362
363int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
364PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
365int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
366int SMIME_text(BIO *in, BIO *out);
367
368/* BEGIN ERROR CODES */
369/* The following lines are auto generated by the script mkerr.pl. Any changes
370 * made after this point may be overwritten when the script is next run.
371 */
372void ERR_load_PKCS7_strings(void);
373
374/* Error codes for the PKCS7 functions. */
375
376/* Function codes. */
377#define PKCS7_F_B64_READ_PKCS7 120
378#define PKCS7_F_B64_WRITE_PKCS7 121
379#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118
380#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
381#define PKCS7_F_PKCS7_ADD_CRL 101
382#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
383#define PKCS7_F_PKCS7_ADD_SIGNER 103
384#define PKCS7_F_PKCS7_CTRL 104
385#define PKCS7_F_PKCS7_DATADECODE 112
386#define PKCS7_F_PKCS7_DATAINIT 105
387#define PKCS7_F_PKCS7_DATASIGN 106
388#define PKCS7_F_PKCS7_DATAVERIFY 107
389#define PKCS7_F_PKCS7_DECRYPT 114
390#define PKCS7_F_PKCS7_ENCRYPT 115
391#define PKCS7_F_PKCS7_GET0_SIGNERS 124
392#define PKCS7_F_PKCS7_SET_CIPHER 108
393#define PKCS7_F_PKCS7_SET_CONTENT 109
394#define PKCS7_F_PKCS7_SET_TYPE 110
395#define PKCS7_F_PKCS7_SIGN 116
396#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
397#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119
398#define PKCS7_F_PKCS7_VERIFY 117
399#define PKCS7_F_SMIME_READ_PKCS7 122
400#define PKCS7_F_SMIME_TEXT 123
401
402/* Reason codes. */
403#define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117
404#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144
405#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
406#define PKCS7_R_CONTENT_AND_DATA_PRESENT 118
407#define PKCS7_R_DECODE_ERROR 130
408#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
409#define PKCS7_R_DECRYPT_ERROR 119
410#define PKCS7_R_DIGEST_FAILURE 101
411#define PKCS7_R_ERROR_ADDING_RECIPIENT 120
412#define PKCS7_R_ERROR_SETTING_CIPHER 121
413#define PKCS7_R_INVALID_MIME_TYPE 131
414#define PKCS7_R_INVALID_NULL_POINTER 143
415#define PKCS7_R_MIME_NO_CONTENT_TYPE 132
416#define PKCS7_R_MIME_PARSE_ERROR 133
417#define PKCS7_R_MIME_SIG_PARSE_ERROR 134
418#define PKCS7_R_MISSING_CERIPEND_INFO 103
419#define PKCS7_R_NO_CONTENT 122
420#define PKCS7_R_NO_CONTENT_TYPE 135
421#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
422#define PKCS7_R_NO_MULTIPART_BOUNDARY 137
423#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
424#define PKCS7_R_NO_SIGNATURES_ON_DATA 123
425#define PKCS7_R_NO_SIGNERS 142
426#define PKCS7_R_NO_SIG_CONTENT_TYPE 138
427#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
428#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
429#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
430#define PKCS7_R_PKCS7_DATASIGN 126
431#define PKCS7_R_PKCS7_PARSE_ERROR 139
432#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
433#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
434#define PKCS7_R_SIGNATURE_FAILURE 105
435#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128
436#define PKCS7_R_SIG_INVALID_MIME_TYPE 141
437#define PKCS7_R_SMIME_TEXT_ERROR 129
438#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
439#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
440#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
441#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
442#define PKCS7_R_UNKNOWN_OPERATION 110
443#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
444#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
445#define PKCS7_R_WRONG_CONTENT_TYPE 113
446#define PKCS7_R_WRONG_PKCS7_TYPE 114
447
448#ifdef __cplusplus
449}
450#endif
451#endif
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
new file mode 100644
index 0000000000..5e51527a40
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pkcs7err.c
@@ -0,0 +1,160 @@
1/* crypto/pkcs7/pkcs7err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pkcs7.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA PKCS7_str_functs[]=
68 {
69{ERR_PACK(0,PKCS7_F_B64_READ_PKCS7,0), "B64_READ_PKCS7"},
70{ERR_PACK(0,PKCS7_F_B64_WRITE_PKCS7,0), "B64_WRITE_PKCS7"},
71{ERR_PACK(0,PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,0), "PKCS7_add_attrib_smimecap"},
72{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"},
73{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"},
74{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"},
75{ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"},
76{ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"},
77{ERR_PACK(0,PKCS7_F_PKCS7_DATADECODE,0), "PKCS7_dataDecode"},
78{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"},
79{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"},
80{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"},
81{ERR_PACK(0,PKCS7_F_PKCS7_DECRYPT,0), "PKCS7_decrypt"},
82{ERR_PACK(0,PKCS7_F_PKCS7_ENCRYPT,0), "PKCS7_encrypt"},
83{ERR_PACK(0,PKCS7_F_PKCS7_GET0_SIGNERS,0), "PKCS7_get0_signers"},
84{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"},
85{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"},
86{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"},
87{ERR_PACK(0,PKCS7_F_PKCS7_SIGN,0), "PKCS7_sign"},
88{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"},
89{ERR_PACK(0,PKCS7_F_PKCS7_SIMPLE_SMIMECAP,0), "PKCS7_simple_smimecap"},
90{ERR_PACK(0,PKCS7_F_PKCS7_VERIFY,0), "PKCS7_verify"},
91{ERR_PACK(0,PKCS7_F_SMIME_READ_PKCS7,0), "SMIME_read_PKCS7"},
92{ERR_PACK(0,PKCS7_F_SMIME_TEXT,0), "SMIME_text"},
93{0,NULL}
94 };
95
96static ERR_STRING_DATA PKCS7_str_reasons[]=
97 {
98{PKCS7_R_CERTIFICATE_VERIFY_ERROR ,"certificate verify error"},
99{PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
100{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"},
101{PKCS7_R_CONTENT_AND_DATA_PRESENT ,"content and data present"},
102{PKCS7_R_DECODE_ERROR ,"decode error"},
103{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"},
104{PKCS7_R_DECRYPT_ERROR ,"decrypt error"},
105{PKCS7_R_DIGEST_FAILURE ,"digest failure"},
106{PKCS7_R_ERROR_ADDING_RECIPIENT ,"error adding recipient"},
107{PKCS7_R_ERROR_SETTING_CIPHER ,"error setting cipher"},
108{PKCS7_R_INVALID_MIME_TYPE ,"invalid mime type"},
109{PKCS7_R_INVALID_NULL_POINTER ,"invalid null pointer"},
110{PKCS7_R_MIME_NO_CONTENT_TYPE ,"mime no content type"},
111{PKCS7_R_MIME_PARSE_ERROR ,"mime parse error"},
112{PKCS7_R_MIME_SIG_PARSE_ERROR ,"mime sig parse error"},
113{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"},
114{PKCS7_R_NO_CONTENT ,"no content"},
115{PKCS7_R_NO_CONTENT_TYPE ,"no content type"},
116{PKCS7_R_NO_MULTIPART_BODY_FAILURE ,"no multipart body failure"},
117{PKCS7_R_NO_MULTIPART_BOUNDARY ,"no multipart boundary"},
118{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"},
119{PKCS7_R_NO_SIGNATURES_ON_DATA ,"no signatures on data"},
120{PKCS7_R_NO_SIGNERS ,"no signers"},
121{PKCS7_R_NO_SIG_CONTENT_TYPE ,"no sig content type"},
122{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"},
123{PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR ,"pkcs7 add signature error"},
124{PKCS7_R_PKCS7_DATAFINAL_ERROR ,"pkcs7 datafinal error"},
125{PKCS7_R_PKCS7_DATASIGN ,"pkcs7 datasign"},
126{PKCS7_R_PKCS7_PARSE_ERROR ,"pkcs7 parse error"},
127{PKCS7_R_PKCS7_SIG_PARSE_ERROR ,"pkcs7 sig parse error"},
128{PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE,"private key does not match certificate"},
129{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"},
130{PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND ,"signer certificate not found"},
131{PKCS7_R_SIG_INVALID_MIME_TYPE ,"sig invalid mime type"},
132{PKCS7_R_SMIME_TEXT_ERROR ,"smime text error"},
133{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"},
134{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"},
135{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"},
136{PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"},
137{PKCS7_R_UNKNOWN_OPERATION ,"unknown operation"},
138{PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"},
139{PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"},
140{PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"},
141{PKCS7_R_WRONG_PKCS7_TYPE ,"wrong pkcs7 type"},
142{0,NULL}
143 };
144
145#endif
146
147void ERR_load_PKCS7_strings(void)
148 {
149 static int init=1;
150
151 if (init)
152 {
153 init=0;
154#ifndef OPENSSL_NO_ERR
155 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs);
156 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_reasons);
157#endif
158
159 }
160 }
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/rand.h b/src/lib/libcrypto/rand/rand.h
new file mode 100644
index 0000000000..604df9be6c
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand.h
@@ -0,0 +1,143 @@
1/* crypto/rand/rand.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RAND_H
60#define HEADER_RAND_H
61
62#include <stdlib.h>
63#include <openssl/ossl_typ.h>
64#include <openssl/e_os2.h>
65
66#if defined(OPENSSL_SYS_WINDOWS)
67#include <windows.h>
68#endif
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#if defined(OPENSSL_FIPS)
75#define FIPS_RAND_SIZE_T int
76#endif
77
78typedef struct rand_meth_st
79 {
80 void (*seed)(const void *buf, int num);
81 int (*bytes)(unsigned char *buf, int num);
82 void (*cleanup)(void);
83 void (*add)(const void *buf, int num, double entropy);
84 int (*pseudorand)(unsigned char *buf, int num);
85 int (*status)(void);
86 } RAND_METHOD;
87
88#ifdef BN_DEBUG
89extern int rand_predictable;
90#endif
91
92int RAND_set_rand_method(const RAND_METHOD *meth);
93const RAND_METHOD *RAND_get_rand_method(void);
94#ifndef OPENSSL_NO_ENGINE
95int RAND_set_rand_engine(ENGINE *engine);
96#endif
97RAND_METHOD *RAND_SSLeay(void);
98void RAND_cleanup(void );
99int RAND_bytes(unsigned char *buf,int num);
100int RAND_pseudo_bytes(unsigned char *buf,int num);
101void RAND_seed(const void *buf,int num);
102void RAND_add(const void *buf,int num,double entropy);
103int RAND_load_file(const char *file,long max_bytes);
104int RAND_write_file(const char *file);
105const char *RAND_file_name(char *file,size_t num);
106int RAND_status(void);
107int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
108int RAND_egd(const char *path);
109int RAND_egd_bytes(const char *path,int bytes);
110int RAND_poll(void);
111
112#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
113
114void RAND_screen(void);
115int RAND_event(UINT, WPARAM, LPARAM);
116
117#endif
118
119/* BEGIN ERROR CODES */
120/* The following lines are auto generated by the script mkerr.pl. Any changes
121 * made after this point may be overwritten when the script is next run.
122 */
123void ERR_load_RAND_strings(void);
124
125/* Error codes for the RAND functions. */
126
127/* Function codes. */
128#define RAND_F_FIPS_RAND_BYTES 102
129#define RAND_F_RAND_GET_RAND_METHOD 101
130#define RAND_F_SSLEAY_RAND_BYTES 100
131
132/* Reason codes. */
133#define RAND_R_NON_FIPS_METHOD 101
134#define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 105
135#define RAND_R_PRNG_NOT_REKEYED 103
136#define RAND_R_PRNG_NOT_RESEEDED 104
137#define RAND_R_PRNG_NOT_SEEDED 100
138#define RAND_R_PRNG_STUCK 102
139
140#ifdef __cplusplus
141}
142#endif
143#endif
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
new file mode 100644
index 0000000000..95574659ac
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_err.c
@@ -0,0 +1,101 @@
1/* crypto/rand/rand_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/rand.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA RAND_str_functs[]=
68 {
69{ERR_PACK(0,RAND_F_FIPS_RAND_BYTES,0), "FIPS_RAND_BYTES"},
70{ERR_PACK(0,RAND_F_RAND_GET_RAND_METHOD,0), "RAND_get_rand_method"},
71{ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"},
72{0,NULL}
73 };
74
75static ERR_STRING_DATA RAND_str_reasons[]=
76 {
77{RAND_R_NON_FIPS_METHOD ,"non fips method"},
78{RAND_R_PRNG_ASKING_FOR_TOO_MUCH ,"prng asking for too much"},
79{RAND_R_PRNG_NOT_REKEYED ,"prng not rekeyed"},
80{RAND_R_PRNG_NOT_RESEEDED ,"prng not reseeded"},
81{RAND_R_PRNG_NOT_SEEDED ,"PRNG not seeded"},
82{RAND_R_PRNG_STUCK ,"prng stuck"},
83{0,NULL}
84 };
85
86#endif
87
88void ERR_load_RAND_strings(void)
89 {
90 static int init=1;
91
92 if (init)
93 {
94 init=0;
95#ifndef OPENSSL_NO_ERR
96 ERR_load_strings(ERR_LIB_RAND,RAND_str_functs);
97 ERR_load_strings(ERR_LIB_RAND,RAND_str_reasons);
98#endif
99
100 }
101 }
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
new file mode 100644
index 0000000000..88f1b56d91
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_lib.c
@@ -0,0 +1,188 @@
1/* crypto/rand/rand_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h>
65#endif
66#include <openssl/fips.h>
67#include <openssl/fips_rand.h>
68
69#ifndef OPENSSL_NO_ENGINE
70/* non-NULL if default_RAND_meth is ENGINE-provided */
71static ENGINE *funct_ref =NULL;
72#endif
73static const RAND_METHOD *default_RAND_meth = NULL;
74
75int RAND_set_rand_method(const RAND_METHOD *meth)
76 {
77#ifndef OPENSSL_NO_ENGINE
78 if(funct_ref)
79 {
80 ENGINE_finish(funct_ref);
81 funct_ref = NULL;
82 }
83#endif
84 default_RAND_meth = meth;
85 return 1;
86 }
87
88const RAND_METHOD *RAND_get_rand_method(void)
89 {
90#ifdef OPENSSL_FIPS
91 if(FIPS_mode()
92 && default_RAND_meth != FIPS_rand_check())
93 {
94 RANDerr(RAND_F_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD);
95 return 0;
96 }
97#endif
98
99
100 if (!default_RAND_meth)
101 {
102#ifndef OPENSSL_NO_ENGINE
103 ENGINE *e = ENGINE_get_default_RAND();
104 if(e)
105 {
106 default_RAND_meth = ENGINE_get_RAND(e);
107 if(!default_RAND_meth)
108 {
109 ENGINE_finish(e);
110 e = NULL;
111 }
112 }
113 if(e)
114 funct_ref = e;
115 else
116#endif
117 default_RAND_meth = RAND_SSLeay();
118 }
119 return default_RAND_meth;
120 }
121
122#ifndef OPENSSL_NO_ENGINE
123int RAND_set_rand_engine(ENGINE *engine)
124 {
125 const RAND_METHOD *tmp_meth = NULL;
126 if(engine)
127 {
128 if(!ENGINE_init(engine))
129 return 0;
130 tmp_meth = ENGINE_get_RAND(engine);
131 if(!tmp_meth)
132 {
133 ENGINE_finish(engine);
134 return 0;
135 }
136 }
137 /* This function releases any prior ENGINE so call it first */
138 RAND_set_rand_method(tmp_meth);
139 funct_ref = engine;
140 return 1;
141 }
142#endif
143
144void RAND_cleanup(void)
145 {
146 const RAND_METHOD *meth = RAND_get_rand_method();
147 if (meth && meth->cleanup)
148 meth->cleanup();
149 RAND_set_rand_method(NULL);
150 }
151
152void RAND_seed(const void *buf, int num)
153 {
154 const RAND_METHOD *meth = RAND_get_rand_method();
155 if (meth && meth->seed)
156 meth->seed(buf,num);
157 }
158
159void RAND_add(const void *buf, int num, double entropy)
160 {
161 const RAND_METHOD *meth = RAND_get_rand_method();
162 if (meth && meth->add)
163 meth->add(buf,num,entropy);
164 }
165
166int RAND_bytes(unsigned char *buf, int num)
167 {
168 const RAND_METHOD *meth = RAND_get_rand_method();
169 if (meth && meth->bytes)
170 return meth->bytes(buf,num);
171 return(-1);
172 }
173
174int RAND_pseudo_bytes(unsigned char *buf, int num)
175 {
176 const RAND_METHOD *meth = RAND_get_rand_method();
177 if (meth && meth->pseudorand)
178 return meth->pseudorand(buf,num);
179 return(-1);
180 }
181
182int RAND_status(void)
183 {
184 const RAND_METHOD *meth = RAND_get_rand_method();
185 if (meth && meth->status)
186 return meth->status();
187 return 0;
188 }
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
new file mode 100644
index 0000000000..9bd89ba495
--- /dev/null
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -0,0 +1,285 @@
1/* crypto/rand/randfile.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* We need to define this to get macros like S_IFBLK and S_IFCHR */
60#define _XOPEN_SOURCE 1
61
62#include <errno.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66
67#include "e_os.h"
68#include <openssl/crypto.h>
69#include <openssl/rand.h>
70#include <openssl/buffer.h>
71
72#ifdef OPENSSL_SYS_VMS
73#include <unixio.h>
74#endif
75#ifndef NO_SYS_TYPES_H
76# include <sys/types.h>
77#endif
78#ifdef MAC_OS_pre_X
79# include <stat.h>
80#else
81# include <sys/stat.h>
82#endif
83
84#undef BUFSIZE
85#define BUFSIZE 1024
86#define RAND_DATA 1024
87
88/* #define RFILE ".rnd" - defined in ../../e_os.h */
89
90/* Note that these functions are intended for seed files only.
91 * Entropy devices and EGD sockets are handled in rand_unix.c */
92
93int RAND_load_file(const char *file, long bytes)
94 {
95 /* If bytes >= 0, read up to 'bytes' bytes.
96 * if bytes == -1, read complete file. */
97
98 MS_STATIC unsigned char buf[BUFSIZE];
99 struct stat sb;
100 int i,ret=0,n;
101 FILE *in;
102
103 if (file == NULL) return(0);
104
105 i=stat(file,&sb);
106 /* If the state fails, put some crap in anyway */
107 RAND_add(&sb,sizeof(sb),0);
108 if (i < 0) return(0);
109 if (bytes == 0) return(ret);
110
111 in=fopen(file,"rb");
112 if (in == NULL) goto err;
113#if defined(S_IFBLK) && defined(S_IFCHR)
114 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
115 /* this file is a device. we don't want read an infinite number
116 * of bytes from a random device, nor do we want to use buffered
117 * I/O because we will waste system entropy.
118 */
119 bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
120 setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */
121 }
122#endif
123 for (;;)
124 {
125 if (bytes > 0)
126 n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE;
127 else
128 n = BUFSIZE;
129 i=fread(buf,1,n,in);
130 if (i <= 0) break;
131 /* even if n != i, use the full array */
132 RAND_add(buf,n,i);
133 ret+=i;
134 if (bytes > 0)
135 {
136 bytes-=n;
137 if (bytes <= 0) break;
138 }
139 }
140 fclose(in);
141 OPENSSL_cleanse(buf,BUFSIZE);
142err:
143 return(ret);
144 }
145
146int RAND_write_file(const char *file)
147 {
148 unsigned char buf[BUFSIZE];
149 int i,ret=0,rand_err=0;
150 FILE *out = NULL;
151 int n;
152 struct stat sb;
153
154 i=stat(file,&sb);
155 if (i != -1) {
156#if defined(S_IFBLK) && defined(S_IFCHR)
157 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
158 /* this file is a device. we don't write back to it.
159 * we "succeed" on the assumption this is some sort
160 * of random device. Otherwise attempting to write to
161 * and chmod the device causes problems.
162 */
163 return(1);
164 }
165#endif
166 }
167
168#if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32)
169 {
170 /* For some reason Win32 can't write to files created this way */
171
172 /* chmod(..., 0600) is too late to protect the file,
173 * permissions should be restrictive from the start */
174 int fd = open(file, O_CREAT, 0600);
175 if (fd != -1)
176 out = fdopen(fd, "wb");
177 }
178#endif
179 if (out == NULL)
180 out = fopen(file,"wb");
181 if (out == NULL) goto err;
182
183#ifndef NO_CHMOD
184 chmod(file,0600);
185#endif
186 n=RAND_DATA;
187 for (;;)
188 {
189 i=(n > BUFSIZE)?BUFSIZE:n;
190 n-=BUFSIZE;
191 if (RAND_bytes(buf,i) <= 0)
192 rand_err=1;
193 i=fwrite(buf,1,i,out);
194 if (i <= 0)
195 {
196 ret=0;
197 break;
198 }
199 ret+=i;
200 if (n <= 0) break;
201 }
202#ifdef OPENSSL_SYS_VMS
203 /* Try to delete older versions of the file, until there aren't
204 any */
205 {
206 char *tmpf;
207
208 tmpf = OPENSSL_malloc(strlen(file) + 4); /* to add ";-1" and a nul */
209 if (tmpf)
210 {
211 strcpy(tmpf, file);
212 strcat(tmpf, ";-1");
213 while(delete(tmpf) == 0)
214 ;
215 rename(file,";1"); /* Make sure it's version 1, or we
216 will reach the limit (32767) at
217 some point... */
218 }
219 }
220#endif /* OPENSSL_SYS_VMS */
221
222 fclose(out);
223 OPENSSL_cleanse(buf,BUFSIZE);
224err:
225 return (rand_err ? -1 : ret);
226 }
227
228const char *RAND_file_name(char *buf, size_t size)
229 {
230 char *s=NULL;
231 int ok = 0;
232#ifdef __OpenBSD__
233 struct stat sb;
234#endif
235
236 if (issetugid() == 0)
237 s=getenv("RANDFILE");
238 if (s != NULL && *s && strlen(s) + 1 < size)
239 {
240 if (BUF_strlcpy(buf,s,size) >= size)
241 return NULL;
242 }
243 else
244 {
245 if (issetugid() == 0)
246 s=getenv("HOME");
247#ifdef DEFAULT_HOME
248 if (s == NULL)
249 {
250 s = DEFAULT_HOME;
251 }
252#endif
253 if (s && *s && strlen(s)+strlen(RFILE)+2 < size)
254 {
255 BUF_strlcpy(buf,s,size);
256#ifndef OPENSSL_SYS_VMS
257 BUF_strlcat(buf,"/",size);
258#endif
259 BUF_strlcat(buf,RFILE,size);
260 ok = 1;
261 }
262 else
263 buf[0] = '\0'; /* no file name */
264 }
265
266#ifdef __OpenBSD__
267 /* given that all random loads just fail if the file can't be
268 * seen on a stat, we stat the file we're returning, if it
269 * fails, use /dev/arandom instead. this allows the user to
270 * use their own source for good random data, but defaults
271 * to something hopefully decent if that isn't available.
272 */
273
274 if (!ok)
275 if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
276 return(NULL);
277 }
278 if (stat(buf,&sb) == -1)
279 if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
280 return(NULL);
281 }
282
283#endif
284 return(buf);
285 }
diff --git a/src/lib/libcrypto/rc2/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
new file mode 100644
index 0000000000..71788158d8
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2.h
@@ -0,0 +1,104 @@
1/* crypto/rc2/rc2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC2_H
60#define HEADER_RC2_H
61
62#ifdef OPENSSL_NO_RC2
63#error RC2 is disabled.
64#endif
65
66#define RC2_ENCRYPT 1
67#define RC2_DECRYPT 0
68
69#include <openssl/opensslconf.h> /* RC2_INT */
70#define RC2_BLOCK 8
71#define RC2_KEY_LENGTH 16
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77typedef struct rc2_key_st
78 {
79 RC2_INT data[64];
80 } RC2_KEY;
81
82#ifdef OPENSSL_FIPS
83void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
84 int bits);
85#endif
86void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);
87void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key,
88 int enc);
89void RC2_encrypt(unsigned long *data,RC2_KEY *key);
90void RC2_decrypt(unsigned long *data,RC2_KEY *key);
91void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
92 RC2_KEY *ks, unsigned char *iv, int enc);
93void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
94 long length, RC2_KEY *schedule, unsigned char *ivec,
95 int *num, int enc);
96void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
97 long length, RC2_KEY *schedule, unsigned char *ivec,
98 int *num);
99
100#ifdef __cplusplus
101}
102#endif
103
104#endif
diff --git a/src/lib/libcrypto/rc2/rc2_cbc.c b/src/lib/libcrypto/rc2/rc2_cbc.c
new file mode 100644
index 0000000000..74f48d3d87
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2_cbc.c
@@ -0,0 +1,226 @@
1/* crypto/rc2/rc2_cbc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc2.h>
60#include "rc2_locl.h"
61
62void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63 RC2_KEY *ks, unsigned char *iv, int encrypt)
64 {
65 register unsigned long tin0,tin1;
66 register unsigned long tout0,tout1,xor0,xor1;
67 register long l=length;
68 unsigned long tin[2];
69
70 if (encrypt)
71 {
72 c2l(iv,tout0);
73 c2l(iv,tout1);
74 iv-=8;
75 for (l-=8; l>=0; l-=8)
76 {
77 c2l(in,tin0);
78 c2l(in,tin1);
79 tin0^=tout0;
80 tin1^=tout1;
81 tin[0]=tin0;
82 tin[1]=tin1;
83 RC2_encrypt(tin,ks);
84 tout0=tin[0]; l2c(tout0,out);
85 tout1=tin[1]; l2c(tout1,out);
86 }
87 if (l != -8)
88 {
89 c2ln(in,tin0,tin1,l+8);
90 tin0^=tout0;
91 tin1^=tout1;
92 tin[0]=tin0;
93 tin[1]=tin1;
94 RC2_encrypt(tin,ks);
95 tout0=tin[0]; l2c(tout0,out);
96 tout1=tin[1]; l2c(tout1,out);
97 }
98 l2c(tout0,iv);
99 l2c(tout1,iv);
100 }
101 else
102 {
103 c2l(iv,xor0);
104 c2l(iv,xor1);
105 iv-=8;
106 for (l-=8; l>=0; l-=8)
107 {
108 c2l(in,tin0); tin[0]=tin0;
109 c2l(in,tin1); tin[1]=tin1;
110 RC2_decrypt(tin,ks);
111 tout0=tin[0]^xor0;
112 tout1=tin[1]^xor1;
113 l2c(tout0,out);
114 l2c(tout1,out);
115 xor0=tin0;
116 xor1=tin1;
117 }
118 if (l != -8)
119 {
120 c2l(in,tin0); tin[0]=tin0;
121 c2l(in,tin1); tin[1]=tin1;
122 RC2_decrypt(tin,ks);
123 tout0=tin[0]^xor0;
124 tout1=tin[1]^xor1;
125 l2cn(tout0,tout1,out,l+8);
126 xor0=tin0;
127 xor1=tin1;
128 }
129 l2c(xor0,iv);
130 l2c(xor1,iv);
131 }
132 tin0=tin1=tout0=tout1=xor0=xor1=0;
133 tin[0]=tin[1]=0;
134 }
135
136void RC2_encrypt(unsigned long *d, RC2_KEY *key)
137 {
138 int i,n;
139 register RC2_INT *p0,*p1;
140 register RC2_INT x0,x1,x2,x3,t;
141 unsigned long l;
142
143 l=d[0];
144 x0=(RC2_INT)l&0xffff;
145 x1=(RC2_INT)(l>>16L);
146 l=d[1];
147 x2=(RC2_INT)l&0xffff;
148 x3=(RC2_INT)(l>>16L);
149
150 n=3;
151 i=5;
152
153 p0=p1= &(key->data[0]);
154 for (;;)
155 {
156 t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff;
157 x0=(t<<1)|(t>>15);
158 t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff;
159 x1=(t<<2)|(t>>14);
160 t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff;
161 x2=(t<<3)|(t>>13);
162 t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff;
163 x3=(t<<5)|(t>>11);
164
165 if (--i == 0)
166 {
167 if (--n == 0) break;
168 i=(n == 2)?6:5;
169
170 x0+=p1[x3&0x3f];
171 x1+=p1[x0&0x3f];
172 x2+=p1[x1&0x3f];
173 x3+=p1[x2&0x3f];
174 }
175 }
176
177 d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
178 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
179 }
180
181void RC2_decrypt(unsigned long *d, RC2_KEY *key)
182 {
183 int i,n;
184 register RC2_INT *p0,*p1;
185 register RC2_INT x0,x1,x2,x3,t;
186 unsigned long l;
187
188 l=d[0];
189 x0=(RC2_INT)l&0xffff;
190 x1=(RC2_INT)(l>>16L);
191 l=d[1];
192 x2=(RC2_INT)l&0xffff;
193 x3=(RC2_INT)(l>>16L);
194
195 n=3;
196 i=5;
197
198 p0= &(key->data[63]);
199 p1= &(key->data[0]);
200 for (;;)
201 {
202 t=((x3<<11)|(x3>>5))&0xffff;
203 x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff;
204 t=((x2<<13)|(x2>>3))&0xffff;
205 x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff;
206 t=((x1<<14)|(x1>>2))&0xffff;
207 x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff;
208 t=((x0<<15)|(x0>>1))&0xffff;
209 x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff;
210
211 if (--i == 0)
212 {
213 if (--n == 0) break;
214 i=(n == 2)?6:5;
215
216 x3=(x3-p1[x2&0x3f])&0xffff;
217 x2=(x2-p1[x1&0x3f])&0xffff;
218 x1=(x1-p1[x0&0x3f])&0xffff;
219 x0=(x0-p1[x3&0x3f])&0xffff;
220 }
221 }
222
223 d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
224 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
225 }
226
diff --git a/src/lib/libcrypto/rc2/rc2_ecb.c b/src/lib/libcrypto/rc2/rc2_ecb.c
new file mode 100644
index 0000000000..d3e8c2718a
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2_ecb.c
@@ -0,0 +1,88 @@
1/* crypto/rc2/rc2_ecb.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc2.h>
60#include "rc2_locl.h"
61#include <openssl/opensslv.h>
62
63const char *RC2_version="RC2" OPENSSL_VERSION_PTEXT;
64
65/* RC2 as implemented frm a posting from
66 * Newsgroups: sci.crypt
67 * Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann)
68 * Subject: Specification for Ron Rivests Cipher No.2
69 * Message-ID: <4fk39f$f70@net.auckland.ac.nz>
70 * Date: 11 Feb 1996 06:45:03 GMT
71 */
72
73void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, RC2_KEY *ks,
74 int encrypt)
75 {
76 unsigned long l,d[2];
77
78 c2l(in,l); d[0]=l;
79 c2l(in,l); d[1]=l;
80 if (encrypt)
81 RC2_encrypt(d,ks);
82 else
83 RC2_decrypt(d,ks);
84 l=d[0]; l2c(l,out);
85 l=d[1]; l2c(l,out);
86 l=d[0]=d[1]=0;
87 }
88
diff --git a/src/lib/libcrypto/rc2/rc2_locl.h b/src/lib/libcrypto/rc2/rc2_locl.h
new file mode 100644
index 0000000000..565cd17619
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2_locl.h
@@ -0,0 +1,156 @@
1/* crypto/rc2/rc2_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#undef c2l
60#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
61 l|=((unsigned long)(*((c)++)))<< 8L, \
62 l|=((unsigned long)(*((c)++)))<<16L, \
63 l|=((unsigned long)(*((c)++)))<<24L)
64
65/* NOTE - c is not incremented as per c2l */
66#undef c2ln
67#define c2ln(c,l1,l2,n) { \
68 c+=n; \
69 l1=l2=0; \
70 switch (n) { \
71 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
72 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
73 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
74 case 5: l2|=((unsigned long)(*(--(c)))); \
75 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
76 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
77 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
78 case 1: l1|=((unsigned long)(*(--(c)))); \
79 } \
80 }
81
82#undef l2c
83#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
84 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
85 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
86 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
87
88/* NOTE - c is not incremented as per l2c */
89#undef l2cn
90#define l2cn(l1,l2,c,n) { \
91 c+=n; \
92 switch (n) { \
93 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
94 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
95 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
96 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
97 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
98 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
99 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
100 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
101 } \
102 }
103
104/* NOTE - c is not incremented as per n2l */
105#define n2ln(c,l1,l2,n) { \
106 c+=n; \
107 l1=l2=0; \
108 switch (n) { \
109 case 8: l2 =((unsigned long)(*(--(c)))) ; \
110 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
111 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
112 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
113 case 4: l1 =((unsigned long)(*(--(c)))) ; \
114 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
115 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
116 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
117 } \
118 }
119
120/* NOTE - c is not incremented as per l2n */
121#define l2nn(l1,l2,c,n) { \
122 c+=n; \
123 switch (n) { \
124 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
125 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
126 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
127 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
128 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
129 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
130 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
131 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
132 } \
133 }
134
135#undef n2l
136#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
137 l|=((unsigned long)(*((c)++)))<<16L, \
138 l|=((unsigned long)(*((c)++)))<< 8L, \
139 l|=((unsigned long)(*((c)++))))
140
141#undef l2n
142#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
143 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
144 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
145 *((c)++)=(unsigned char)(((l) )&0xff))
146
147#define C_RC2(n) \
148 t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
149 x0=(t<<1)|(t>>15); \
150 t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
151 x1=(t<<2)|(t>>14); \
152 t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
153 x2=(t<<3)|(t>>13); \
154 t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
155 x3=(t<<5)|(t>>11);
156
diff --git a/src/lib/libcrypto/rc2/rc2_skey.c b/src/lib/libcrypto/rc2/rc2_skey.c
new file mode 100644
index 0000000000..22f372f85c
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2_skey.c
@@ -0,0 +1,151 @@
1/* crypto/rc2/rc2_skey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc2.h>
60#include <openssl/crypto.h>
61#include "rc2_locl.h"
62
63static unsigned char key_table[256]={
64 0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79,
65 0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e,
66 0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5,
67 0x87,0xb3,0x4f,0x13,0x61,0x45,0x6d,0x8d,0x09,0x81,0x7d,0x32,
68 0xbd,0x8f,0x40,0xeb,0x86,0xb7,0x7b,0x0b,0xf0,0x95,0x21,0x22,
69 0x5c,0x6b,0x4e,0x82,0x54,0xd6,0x65,0x93,0xce,0x60,0xb2,0x1c,
70 0x73,0x56,0xc0,0x14,0xa7,0x8c,0xf1,0xdc,0x12,0x75,0xca,0x1f,
71 0x3b,0xbe,0xe4,0xd1,0x42,0x3d,0xd4,0x30,0xa3,0x3c,0xb6,0x26,
72 0x6f,0xbf,0x0e,0xda,0x46,0x69,0x07,0x57,0x27,0xf2,0x1d,0x9b,
73 0xbc,0x94,0x43,0x03,0xf8,0x11,0xc7,0xf6,0x90,0xef,0x3e,0xe7,
74 0x06,0xc3,0xd5,0x2f,0xc8,0x66,0x1e,0xd7,0x08,0xe8,0xea,0xde,
75 0x80,0x52,0xee,0xf7,0x84,0xaa,0x72,0xac,0x35,0x4d,0x6a,0x2a,
76 0x96,0x1a,0xd2,0x71,0x5a,0x15,0x49,0x74,0x4b,0x9f,0xd0,0x5e,
77 0x04,0x18,0xa4,0xec,0xc2,0xe0,0x41,0x6e,0x0f,0x51,0xcb,0xcc,
78 0x24,0x91,0xaf,0x50,0xa1,0xf4,0x70,0x39,0x99,0x7c,0x3a,0x85,
79 0x23,0xb8,0xb4,0x7a,0xfc,0x02,0x36,0x5b,0x25,0x55,0x97,0x31,
80 0x2d,0x5d,0xfa,0x98,0xe3,0x8a,0x92,0xae,0x05,0xdf,0x29,0x10,
81 0x67,0x6c,0xba,0xc9,0xd3,0x00,0xe6,0xcf,0xe1,0x9e,0xa8,0x2c,
82 0x63,0x16,0x01,0x3f,0x58,0xe2,0x89,0xa9,0x0d,0x38,0x34,0x1b,
83 0xab,0x33,0xff,0xb0,0xbb,0x48,0x0c,0x5f,0xb9,0xb1,0xcd,0x2e,
84 0xc5,0xf3,0xdb,0x47,0xe5,0xa5,0x9c,0x77,0x0a,0xa6,0x20,0x68,
85 0xfe,0x7f,0xc1,0xad,
86 };
87
88/* It has come to my attention that there are 2 versions of the RC2
89 * key schedule. One which is normal, and anther which has a hook to
90 * use a reduced key length.
91 * BSAFE uses the 'retarded' version. What I previously shipped is
92 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses
93 * a version where the bits parameter is the same as len*8 */
94
95#ifdef OPENSSL_FIPS
96void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
97 {
98 if (FIPS_mode())
99 FIPS_BAD_ABORT(RC2)
100 private_RC2_set_key(key, len, data, bits);
101 }
102void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
103 int bits)
104#else
105void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
106#endif
107 {
108 int i,j;
109 unsigned char *k;
110 RC2_INT *ki;
111 unsigned int c,d;
112
113 k= (unsigned char *)&(key->data[0]);
114 *k=0; /* for if there is a zero length key */
115
116 if (len > 128) len=128;
117 if (bits <= 0) bits=1024;
118 if (bits > 1024) bits=1024;
119
120 for (i=0; i<len; i++)
121 k[i]=data[i];
122
123 /* expand table */
124 d=k[len-1];
125 j=0;
126 for (i=len; i < 128; i++,j++)
127 {
128 d=key_table[(k[j]+d)&0xff];
129 k[i]=d;
130 }
131
132 /* hmm.... key reduction to 'bits' bits */
133
134 j=(bits+7)>>3;
135 i=128-j;
136 c= (0xff>>(-bits & 0x07));
137
138 d=key_table[k[i]&c];
139 k[i]=d;
140 while (i--)
141 {
142 d=key_table[k[i+j]^d];
143 k[i]=d;
144 }
145
146 /* copy from bytes into RC2_INT's */
147 ki= &(key->data[63]);
148 for (i=127; i>=0; i-=2)
149 *(ki--)=((k[i]<<8)|k[i-1])&0xffff;
150 }
151
diff --git a/src/lib/libcrypto/rc2/rc2cfb64.c b/src/lib/libcrypto/rc2/rc2cfb64.c
new file mode 100644
index 0000000000..b3a0158a6e
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2cfb64.c
@@ -0,0 +1,122 @@
1/* crypto/rc2/rc2cfb64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc2.h>
60#include "rc2_locl.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 long length, RC2_KEY *schedule, unsigned char *ivec,
69 int *num, int encrypt)
70 {
71 register unsigned long v0,v1,t;
72 register int n= *num;
73 register long l=length;
74 unsigned long ti[2];
75 unsigned char *iv,c,cc;
76
77 iv=(unsigned char *)ivec;
78 if (encrypt)
79 {
80 while (l--)
81 {
82 if (n == 0)
83 {
84 c2l(iv,v0); ti[0]=v0;
85 c2l(iv,v1); ti[1]=v1;
86 RC2_encrypt((unsigned long *)ti,schedule);
87 iv=(unsigned char *)ivec;
88 t=ti[0]; l2c(t,iv);
89 t=ti[1]; l2c(t,iv);
90 iv=(unsigned char *)ivec;
91 }
92 c= *(in++)^iv[n];
93 *(out++)=c;
94 iv[n]=c;
95 n=(n+1)&0x07;
96 }
97 }
98 else
99 {
100 while (l--)
101 {
102 if (n == 0)
103 {
104 c2l(iv,v0); ti[0]=v0;
105 c2l(iv,v1); ti[1]=v1;
106 RC2_encrypt((unsigned long *)ti,schedule);
107 iv=(unsigned char *)ivec;
108 t=ti[0]; l2c(t,iv);
109 t=ti[1]; l2c(t,iv);
110 iv=(unsigned char *)ivec;
111 }
112 cc= *(in++);
113 c=iv[n];
114 iv[n]=cc;
115 *(out++)=c^cc;
116 n=(n+1)&0x07;
117 }
118 }
119 v0=v1=ti[0]=ti[1]=t=c=cc=0;
120 *num=n;
121 }
122
diff --git a/src/lib/libcrypto/rc2/rc2ofb64.c b/src/lib/libcrypto/rc2/rc2ofb64.c
new file mode 100644
index 0000000000..9e297867ed
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2ofb64.c
@@ -0,0 +1,111 @@
1/* crypto/rc2/rc2ofb64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc2.h>
60#include "rc2_locl.h"
61
62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
67 long length, RC2_KEY *schedule, unsigned char *ivec,
68 int *num)
69 {
70 register unsigned long v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 unsigned char d[8];
74 register char *dp;
75 unsigned long ti[2];
76 unsigned char *iv;
77 int save=0;
78
79 iv=(unsigned char *)ivec;
80 c2l(iv,v0);
81 c2l(iv,v1);
82 ti[0]=v0;
83 ti[1]=v1;
84 dp=(char *)d;
85 l2c(v0,dp);
86 l2c(v1,dp);
87 while (l--)
88 {
89 if (n == 0)
90 {
91 RC2_encrypt((unsigned long *)ti,schedule);
92 dp=(char *)d;
93 t=ti[0]; l2c(t,dp);
94 t=ti[1]; l2c(t,dp);
95 save++;
96 }
97 *(out++)= *(in++)^d[n];
98 n=(n+1)&0x07;
99 }
100 if (save)
101 {
102 v0=ti[0];
103 v1=ti[1];
104 iv=(unsigned char *)ivec;
105 l2c(v0,iv);
106 l2c(v1,iv);
107 }
108 t=v0=v1=ti[0]=ti[1]=0;
109 *num=n;
110 }
111
diff --git a/src/lib/libcrypto/rc2/rc2speed.c b/src/lib/libcrypto/rc2/rc2speed.c
index 4d0e1242ea..47d34b444e 100644
--- a/src/lib/libcrypto/rc2/rc2speed.c
+++ b/src/lib/libcrypto/rc2/rc2speed.c
@@ -102,10 +102,10 @@ OPENSSL_DECLARE_EXIT
102#ifndef HZ 102#ifndef HZ
103#ifndef CLK_TCK 103#ifndef CLK_TCK
104#define HZ 100.0 104#define HZ 100.0
105#else /* CLK_TCK */ 105#endif
106#else /* CLK_TCK */
106#define HZ ((double)CLK_TCK) 107#define HZ ((double)CLK_TCK)
107#endif /* CLK_TCK */ 108#endif
108#endif /* HZ */
109 109
110#define BUFSIZE ((long)1024) 110#define BUFSIZE ((long)1024)
111long run=0; 111long run=0;
diff --git a/src/lib/libcrypto/rc2/rrc2.doc b/src/lib/libcrypto/rc2/rrc2.doc
new file mode 100644
index 0000000000..f93ee003d2
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rrc2.doc
@@ -0,0 +1,219 @@
1>From cygnus.mincom.oz.au!minbne.mincom.oz.au!bunyip.cc.uq.oz.au!munnari.OZ.AU!comp.vuw.ac.nz!waikato!auckland.ac.nz!news Mon Feb 12 18:48:17 EST 1996
2Article 23601 of sci.crypt:
3Path: cygnus.mincom.oz.au!minbne.mincom.oz.au!bunyip.cc.uq.oz.au!munnari.OZ.AU!comp.vuw.ac.nz!waikato!auckland.ac.nz!news
4>From: pgut01@cs.auckland.ac.nz (Peter Gutmann)
5Newsgroups: sci.crypt
6Subject: Specification for Ron Rivests Cipher No.2
7Date: 11 Feb 1996 06:45:03 GMT
8Organization: University of Auckland
9Lines: 203
10Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann)
11Message-ID: <4fk39f$f70@net.auckland.ac.nz>
12NNTP-Posting-Host: cs26.cs.auckland.ac.nz
13X-Newsreader: NN version 6.5.0 #3 (NOV)
14
15
16
17
18 Ron Rivest's Cipher No.2
19 ------------------------
20
21Ron Rivest's Cipher No.2 (hereafter referred to as RRC.2, other people may
22refer to it by other names) is word oriented, operating on a block of 64 bits
23divided into four 16-bit words, with a key table of 64 words. All data units
24are little-endian. This functional description of the algorithm is based in
25the paper "The RC5 Encryption Algorithm" (RC5 is a trademark of RSADSI), using
26the same general layout, terminology, and pseudocode style.
27
28
29Notation and RRC.2 Primitive Operations
30
31RRC.2 uses the following primitive operations:
32
331. Two's-complement addition of words, denoted by "+". The inverse operation,
34 subtraction, is denoted by "-".
352. Bitwise exclusive OR, denoted by "^".
363. Bitwise AND, denoted by "&".
374. Bitwise NOT, denoted by "~".
385. A left-rotation of words; the rotation of word x left by y is denoted
39 x <<< y. The inverse operation, right-rotation, is denoted x >>> y.
40
41These operations are directly and efficiently supported by most processors.
42
43
44The RRC.2 Algorithm
45
46RRC.2 consists of three components, a *key expansion* algorithm, an
47*encryption* algorithm, and a *decryption* algorithm.
48
49
50Key Expansion
51
52The purpose of the key-expansion routine is to expand the user's key K to fill
53the expanded key array S, so S resembles an array of random binary words
54determined by the user's secret key K.
55
56Initialising the S-box
57
58RRC.2 uses a single 256-byte S-box derived from the ciphertext contents of
59Beale Cipher No.1 XOR'd with a one-time pad. The Beale Ciphers predate modern
60cryptography by enough time that there should be no concerns about trapdoors
61hidden in the data. They have been published widely, and the S-box can be
62easily recreated from the one-time pad values and the Beale Cipher data taken
63from a standard source. To initialise the S-box:
64
65 for i = 0 to 255 do
66 sBox[ i ] = ( beale[ i ] mod 256 ) ^ pad[ i ]
67
68The contents of Beale Cipher No.1 and the necessary one-time pad are given as
69an appendix at the end of this document. For efficiency, implementors may wish
70to skip the Beale Cipher expansion and store the sBox table directly.
71
72Expanding the Secret Key to 128 Bytes
73
74The secret key is first expanded to fill 128 bytes (64 words). The expansion
75consists of taking the sum of the first and last bytes in the user key, looking
76up the sum (modulo 256) in the S-box, and appending the result to the key. The
77operation is repeated with the second byte and new last byte of the key until
78all 128 bytes have been generated. Note that the following pseudocode treats
79the S array as an array of 128 bytes rather than 64 words.
80
81 for j = 0 to length-1 do
82 S[ j ] = K[ j ]
83 for j = length to 127 do
84 s[ j ] = sBox[ ( S[ j-length ] + S[ j-1 ] ) mod 256 ];
85
86At this point it is possible to perform a truncation of the effective key
87length to ease the creation of espionage-enabled software products. However
88since the author cannot conceive why anyone would want to do this, it will not
89be considered further.
90
91The final phase of the key expansion involves replacing the first byte of S
92with the entry selected from the S-box:
93
94 S[ 0 ] = sBox[ S[ 0 ] ]
95
96
97Encryption
98
99The cipher has 16 full rounds, each divided into 4 subrounds. Two of the full
100rounds perform an additional transformation on the data. Note that the
101following pseudocode treats the S array as an array of 64 words rather than 128
102bytes.
103
104 for i = 0 to 15 do
105 j = i * 4;
106 word0 = ( word0 + ( word1 & ~word3 ) + ( word2 & word3 ) + S[ j+0 ] ) <<< 1
107 word1 = ( word1 + ( word2 & ~word0 ) + ( word3 & word0 ) + S[ j+1 ] ) <<< 2
108 word2 = ( word2 + ( word3 & ~word1 ) + ( word0 & word1 ) + S[ j+2 ] ) <<< 3
109 word3 = ( word3 + ( word0 & ~word2 ) + ( word1 & word2 ) + S[ j+3 ] ) <<< 5
110
111In addition the fifth and eleventh rounds add the contents of the S-box indexed
112by one of the data words to another of the data words following the four
113subrounds as follows:
114
115 word0 = word0 + S[ word3 & 63 ];
116 word1 = word1 + S[ word0 & 63 ];
117 word2 = word2 + S[ word1 & 63 ];
118 word3 = word3 + S[ word2 & 63 ];
119
120
121Decryption
122
123The decryption operation is simply the inverse of the encryption operation.
124Note that the following pseudocode treats the S array as an array of 64 words
125rather than 128 bytes.
126
127 for i = 15 downto 0 do
128 j = i * 4;
129 word3 = ( word3 >>> 5 ) - ( word0 & ~word2 ) - ( word1 & word2 ) - S[ j+3 ]
130 word2 = ( word2 >>> 3 ) - ( word3 & ~word1 ) - ( word0 & word1 ) - S[ j+2 ]
131 word1 = ( word1 >>> 2 ) - ( word2 & ~word0 ) - ( word3 & word0 ) - S[ j+1 ]
132 word0 = ( word0 >>> 1 ) - ( word1 & ~word3 ) - ( word2 & word3 ) - S[ j+0 ]
133
134In addition the fifth and eleventh rounds subtract the contents of the S-box
135indexed by one of the data words from another one of the data words following
136the four subrounds as follows:
137
138 word3 = word3 - S[ word2 & 63 ]
139 word2 = word2 - S[ word1 & 63 ]
140 word1 = word1 - S[ word0 & 63 ]
141 word0 = word0 - S[ word3 & 63 ]
142
143
144Test Vectors
145
146The following test vectors may be used to test the correctness of an RRC.2
147implementation:
148
149 Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
151 Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
152 Cipher: 0x1C, 0x19, 0x8A, 0x83, 0x8D, 0xF0, 0x28, 0xB7
153
154 Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
156 Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
157 Cipher: 0x21, 0x82, 0x9C, 0x78, 0xA9, 0xF9, 0xC0, 0x74
158
159 Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
161 Plain: 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
162 Cipher: 0x13, 0xDB, 0x35, 0x17, 0xD3, 0x21, 0x86, 0x9E
163
164 Key: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
165 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
166 Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
167 Cipher: 0x50, 0xDC, 0x01, 0x62, 0xBD, 0x75, 0x7F, 0x31
168
169
170Appendix: Beale Cipher No.1, "The Locality of the Vault", and One-time Pad for
171 Creating the S-Box
172
173Beale Cipher No.1.
174
175 71, 194, 38,1701, 89, 76, 11, 83,1629, 48, 94, 63, 132, 16, 111, 95,
176 84, 341, 975, 14, 40, 64, 27, 81, 139, 213, 63, 90,1120, 8, 15, 3,
177 126,2018, 40, 74, 758, 485, 604, 230, 436, 664, 582, 150, 251, 284, 308, 231,
178 124, 211, 486, 225, 401, 370, 11, 101, 305, 139, 189, 17, 33, 88, 208, 193,
179 145, 1, 94, 73, 416, 918, 263, 28, 500, 538, 356, 117, 136, 219, 27, 176,
180 130, 10, 460, 25, 485, 18, 436, 65, 84, 200, 283, 118, 320, 138, 36, 416,
181 280, 15, 71, 224, 961, 44, 16, 401, 39, 88, 61, 304, 12, 21, 24, 283,
182 134, 92, 63, 246, 486, 682, 7, 219, 184, 360, 780, 18, 64, 463, 474, 131,
183 160, 79, 73, 440, 95, 18, 64, 581, 34, 69, 128, 367, 460, 17, 81, 12,
184 103, 820, 62, 110, 97, 103, 862, 70, 60,1317, 471, 540, 208, 121, 890, 346,
185 36, 150, 59, 568, 614, 13, 120, 63, 219, 812,2160,1780, 99, 35, 18, 21,
186 136, 872, 15, 28, 170, 88, 4, 30, 44, 112, 18, 147, 436, 195, 320, 37,
187 122, 113, 6, 140, 8, 120, 305, 42, 58, 461, 44, 106, 301, 13, 408, 680,
188 93, 86, 116, 530, 82, 568, 9, 102, 38, 416, 89, 71, 216, 728, 965, 818,
189 2, 38, 121, 195, 14, 326, 148, 234, 18, 55, 131, 234, 361, 824, 5, 81,
190 623, 48, 961, 19, 26, 33, 10,1101, 365, 92, 88, 181, 275, 346, 201, 206
191
192One-time Pad.
193
194 158, 186, 223, 97, 64, 145, 190, 190, 117, 217, 163, 70, 206, 176, 183, 194,
195 146, 43, 248, 141, 3, 54, 72, 223, 233, 153, 91, 210, 36, 131, 244, 161,
196 105, 120, 113, 191, 113, 86, 19, 245, 213, 221, 43, 27, 242, 157, 73, 213,
197 193, 92, 166, 10, 23, 197, 112, 110, 193, 30, 156, 51, 125, 51, 158, 67,
198 197, 215, 59, 218, 110, 246, 181, 0, 135, 76, 164, 97, 47, 87, 234, 108,
199 144, 127, 6, 6, 222, 172, 80, 144, 22, 245, 207, 70, 227, 182, 146, 134,
200 119, 176, 73, 58, 135, 69, 23, 198, 0, 170, 32, 171, 176, 129, 91, 24,
201 126, 77, 248, 0, 118, 69, 57, 60, 190, 171, 217, 61, 136, 169, 196, 84,
202 168, 167, 163, 102, 223, 64, 174, 178, 166, 239, 242, 195, 249, 92, 59, 38,
203 241, 46, 236, 31, 59, 114, 23, 50, 119, 186, 7, 66, 212, 97, 222, 182,
204 230, 118, 122, 86, 105, 92, 179, 243, 255, 189, 223, 164, 194, 215, 98, 44,
205 17, 20, 53, 153, 137, 224, 176, 100, 208, 114, 36, 200, 145, 150, 215, 20,
206 87, 44, 252, 20, 235, 242, 163, 132, 63, 18, 5, 122, 74, 97, 34, 97,
207 142, 86, 146, 221, 179, 166, 161, 74, 69, 182, 88, 120, 128, 58, 76, 155,
208 15, 30, 77, 216, 165, 117, 107, 90, 169, 127, 143, 181, 208, 137, 200, 127,
209 170, 195, 26, 84, 255, 132, 150, 58, 103, 250, 120, 221, 237, 37, 8, 99
210
211
212Implementation
213
214A non-US based programmer who has never seen any encryption code before will
215shortly be implementing RRC.2 based solely on this specification and not on
216knowledge of any other encryption algorithms. Stand by.
217
218
219
diff --git a/src/lib/libcrypto/rc2/version b/src/lib/libcrypto/rc2/version
new file mode 100644
index 0000000000..6f89d595f1
--- /dev/null
+++ b/src/lib/libcrypto/rc2/version
@@ -0,0 +1,22 @@
11.1 23/08/96 - eay
2 Changed RC2_set_key() so it now takes another argument. Many
3 thanks to Peter Gutmann <pgut01@cs.auckland.ac.nz> for the
4 clarification and origional specification of RC2. BSAFE uses
5 this last parameter, 'bits'. It the key is 128 bits, BSAFE
6 also sets this parameter to 128. The old behaviour can be
7 duplicated by setting this parameter to 1024.
8
91.0 08/04/96 - eay
10 First version of SSLeay with rc2. This has been written from the spec
11 posted sci.crypt. It is in this directory under rrc2.doc
12 I have no test values for any mode other than ecb, my wrappers for the
13 other modes should be ok since they are basically the same as
14 the ones taken from idea and des :-). I have implemented them as
15 little-endian operators.
16 While rc2 is included because it is used with SSL, I don't know how
17 far I trust it. It is about the same speed as IDEA and DES.
18 So if you are paranoid, used Tripple DES, else IDEA. If RC2
19 does get used more, perhaps more people will look for weaknesses in
20 it.
21
22
diff --git a/src/lib/libcrypto/rc4/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
new file mode 100644
index 0000000000..d6e98f0811
--- /dev/null
+++ b/src/lib/libcrypto/rc4/asm/rc4-586.pl
@@ -0,0 +1,229 @@
1#!/usr/local/bin/perl
2
3# At some point it became apparent that the original SSLeay RC4
4# assembler implementation performs suboptimaly on latest IA-32
5# microarchitectures. After re-tuning performance has changed as
6# following:
7#
8# Pentium +0%
9# Pentium III +17%
10# AMD +52%(*)
11# P4 +180%(**)
12#
13# (*) This number is actually a trade-off:-) It's possible to
14# achieve +72%, but at the cost of -48% off PIII performance.
15# In other words code performing further 13% faster on AMD
16# would perform almost 2 times slower on Intel PIII...
17# For reference! This code delivers ~80% of rc4-amd64.pl
18# performance on the same Opteron machine.
19# (**) This number requires compressed key schedule set up by
20# RC4_set_key and therefore doesn't apply to 0.9.7 [option for
21# compressed key schedule is implemented in 0.9.8 and later,
22# see commentary section in rc4_skey.c for further details].
23#
24# <appro@fy.chalmers.se>
25
26push(@INC,"perlasm","../../perlasm");
27require "x86asm.pl";
28
29&asm_init($ARGV[0],"rc4-586.pl");
30
31$x="eax";
32$y="ebx";
33$tx="ecx";
34$ty="edx";
35$in="esi";
36$out="edi";
37$d="ebp";
38
39&RC4("RC4");
40
41&asm_finish();
42
43sub RC4_loop
44 {
45 local($n,$p,$char)=@_;
46
47 &comment("Round $n");
48
49 if ($char)
50 {
51 if ($p >= 0)
52 {
53 &mov($ty, &swtmp(2));
54 &cmp($ty, $in);
55 &jbe(&label("finished"));
56 &inc($in);
57 }
58 else
59 {
60 &add($ty, 8);
61 &inc($in);
62 &cmp($ty, $in);
63 &jb(&label("finished"));
64 &mov(&swtmp(2), $ty);
65 }
66 }
67 # Moved out
68 # &mov( $tx, &DWP(0,$d,$x,4)) if $p < 0;
69
70 &add( &LB($y), &LB($tx));
71 &mov( $ty, &DWP(0,$d,$y,4));
72 # XXX
73 &mov( &DWP(0,$d,$x,4),$ty);
74 &add( $ty, $tx);
75 &mov( &DWP(0,$d,$y,4),$tx);
76 &and( $ty, 0xff);
77 &inc( &LB($x)); # NEXT ROUND
78 &mov( $tx, &DWP(0,$d,$x,4)) if $p < 1; # NEXT ROUND
79 &mov( $ty, &DWP(0,$d,$ty,4));
80
81 if (!$char)
82 {
83 #moved up into last round
84 if ($p >= 1)
85 {
86 &add( $out, 8)
87 }
88 &movb( &BP($n,"esp","",0), &LB($ty));
89 }
90 else
91 {
92 # Note in+=8 has occured
93 &movb( &HB($ty), &BP(-1,$in,"",0));
94 # XXX
95 &xorb(&LB($ty), &HB($ty));
96 # XXX
97 &movb(&BP($n,$out,"",0),&LB($ty));
98 }
99 }
100
101
102sub RC4
103 {
104 local($name)=@_;
105
106 &function_begin_B($name,"");
107
108 &mov($ty,&wparam(1)); # len
109 &cmp($ty,0);
110 &jne(&label("proceed"));
111 &ret();
112 &set_label("proceed");
113
114 &comment("");
115
116 &push("ebp");
117 &push("ebx");
118 &push("esi");
119 &xor( $x, $x); # avoid partial register stalls
120 &push("edi");
121 &xor( $y, $y); # avoid partial register stalls
122 &mov( $d, &wparam(0)); # key
123 &mov( $in, &wparam(2));
124
125 &movb( &LB($x), &BP(0,$d,"",1));
126 &movb( &LB($y), &BP(4,$d,"",1));
127
128 &mov( $out, &wparam(3));
129 &inc( &LB($x));
130
131 &stack_push(3); # 3 temp variables
132 &add( $d, 8);
133
134 # detect compressed schedule, see commentary section in rc4_skey.c...
135 # in 0.9.7 context ~50 bytes below RC4_CHAR label remain redundant,
136 # as compressed key schedule is set up in 0.9.8 and later.
137 &cmp(&DWP(256,$d),-1);
138 &je(&label("RC4_CHAR"));
139
140 &lea( $ty, &DWP(-8,$ty,$in));
141
142 # check for 0 length input
143
144 &mov( &swtmp(2), $ty); # this is now address to exit at
145 &mov( $tx, &DWP(0,$d,$x,4));
146
147 &cmp( $ty, $in);
148 &jb( &label("end")); # less than 8 bytes
149
150 &set_label("start");
151
152 # filling DELAY SLOT
153 &add( $in, 8);
154
155 &RC4_loop(0,-1,0);
156 &RC4_loop(1,0,0);
157 &RC4_loop(2,0,0);
158 &RC4_loop(3,0,0);
159 &RC4_loop(4,0,0);
160 &RC4_loop(5,0,0);
161 &RC4_loop(6,0,0);
162 &RC4_loop(7,1,0);
163
164 &comment("apply the cipher text");
165 # xor the cipher data with input
166
167 #&add( $out, 8); #moved up into last round
168
169 &mov( $tx, &swtmp(0));
170 &mov( $ty, &DWP(-8,$in,"",0));
171 &xor( $tx, $ty);
172 &mov( $ty, &DWP(-4,$in,"",0));
173 &mov( &DWP(-8,$out,"",0), $tx);
174 &mov( $tx, &swtmp(1));
175 &xor( $tx, $ty);
176 &mov( $ty, &swtmp(2)); # load end ptr;
177 &mov( &DWP(-4,$out,"",0), $tx);
178 &mov( $tx, &DWP(0,$d,$x,4));
179 &cmp($in, $ty);
180 &jbe(&label("start"));
181
182 &set_label("end");
183
184 # There is quite a bit of extra crap in RC4_loop() for this
185 # first round
186 &RC4_loop(0,-1,1);
187 &RC4_loop(1,0,1);
188 &RC4_loop(2,0,1);
189 &RC4_loop(3,0,1);
190 &RC4_loop(4,0,1);
191 &RC4_loop(5,0,1);
192 &RC4_loop(6,1,1);
193
194 &jmp(&label("finished"));
195
196 &align(16);
197 # this is essentially Intel P4 specific codepath, see rc4_skey.c,
198 # and is engaged in 0.9.8 and later context...
199 &set_label("RC4_CHAR");
200
201 &lea ($ty,&DWP(0,$in,$ty));
202 &mov (&swtmp(2),$ty);
203
204 # strangely enough unrolled loop performs over 20% slower...
205 &set_label("RC4_CHAR_loop");
206 &movz ($tx,&BP(0,$d,$x));
207 &add (&LB($y),&LB($tx));
208 &movz ($ty,&BP(0,$d,$y));
209 &movb (&BP(0,$d,$y),&LB($tx));
210 &movb (&BP(0,$d,$x),&LB($ty));
211 &add (&LB($ty),&LB($tx));
212 &movz ($ty,&BP(0,$d,$ty));
213 &xorb (&LB($ty),&BP(0,$in));
214 &movb (&BP(0,$out),&LB($ty));
215 &inc (&LB($x));
216 &inc ($in);
217 &inc ($out);
218 &cmp ($in,&swtmp(2));
219 &jb (&label("RC4_CHAR_loop"));
220
221 &set_label("finished");
222 &dec( $x);
223 &stack_pop(3);
224 &movb( &BP(-4,$d,"",0),&LB($y));
225 &movb( &BP(-8,$d,"",0),&LB($x));
226
227 &function_end($name);
228 }
229
diff --git a/src/lib/libcrypto/rc4/asm/rc4-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/rc4.h b/src/lib/libcrypto/rc4/rc4.h
new file mode 100644
index 0000000000..dd90d9fde0
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4.h
@@ -0,0 +1,95 @@
1/* crypto/rc4/rc4.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC4_H
60#define HEADER_RC4_H
61
62#ifdef OPENSSL_NO_RC4
63#error RC4 is disabled.
64#endif
65
66#include <openssl/opensslconf.h> /* RC4_INT */
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72typedef struct rc4_key_st
73 {
74 RC4_INT x,y;
75 RC4_INT data[256];
76#if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
77 /* see crypto/rc4/asm/rc4-ia64.S for further details... */
78 RC4_INT pad[512-256-2];
79#endif
80 } RC4_KEY;
81
82
83const char *RC4_options(void);
84#ifdef OPENSSL_FIPS
85void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
86#endif
87void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
88void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
89 unsigned char *outdata);
90
91#ifdef __cplusplus
92}
93#endif
94
95#endif
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c
new file mode 100644
index 0000000000..81a97ea3b7
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4_enc.c
@@ -0,0 +1,319 @@
1/* crypto/rc4/rc4_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc4.h>
60#include "rc4_locl.h"
61
62/* RC4 as implemented from a posting from
63 * Newsgroups: sci.crypt
64 * From: sterndark@netcom.com (David Sterndark)
65 * Subject: RC4 Algorithm revealed.
66 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
67 * Date: Wed, 14 Sep 1994 06:35:31 GMT
68 */
69
70void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
71 unsigned char *outdata)
72 {
73 register RC4_INT *d;
74 register RC4_INT x,y,tx,ty;
75 int i;
76
77 x=key->x;
78 y=key->y;
79 d=key->data;
80#if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
81 /* see crypto/rc4/asm/rc4-ia64.S for further details... */
82 d=(RC4_INT *)(((size_t)(d+255))&~(sizeof(key->data)-1));
83#endif
84
85#if defined(RC4_CHUNK)
86 /*
87 * The original reason for implementing this(*) was the fact that
88 * pre-21164a Alpha CPUs don't have byte load/store instructions
89 * and e.g. a byte store has to be done with 64-bit load, shift,
90 * and, or and finally 64-bit store. Peaking data and operating
91 * at natural word size made it possible to reduce amount of
92 * instructions as well as to perform early read-ahead without
93 * suffering from RAW (read-after-write) hazard. This resulted
94 * in ~40%(**) performance improvement on 21064 box with gcc.
95 * But it's not only Alpha users who win here:-) Thanks to the
96 * early-n-wide read-ahead this implementation also exhibits
97 * >40% speed-up on SPARC and 20-30% on 64-bit MIPS (depending
98 * on sizeof(RC4_INT)).
99 *
100 * (*) "this" means code which recognizes the case when input
101 * and output pointers appear to be aligned at natural CPU
102 * word boundary
103 * (**) i.e. according to 'apps/openssl speed rc4' benchmark,
104 * crypto/rc4/rc4speed.c exhibits almost 70% speed-up...
105 *
106 * Cavets.
107 *
108 * - RC4_CHUNK="unsigned long long" should be a #1 choice for
109 * UltraSPARC. Unfortunately gcc generates very slow code
110 * (2.5-3 times slower than one generated by Sun's WorkShop
111 * C) and therefore gcc (at least 2.95 and earlier) should
112 * always be told that RC4_CHUNK="unsigned long".
113 *
114 * <appro@fy.chalmers.se>
115 */
116
117# define RC4_STEP ( \
118 x=(x+1) &0xff, \
119 tx=d[x], \
120 y=(tx+y)&0xff, \
121 ty=d[y], \
122 d[y]=tx, \
123 d[x]=ty, \
124 (RC4_CHUNK)d[(tx+ty)&0xff]\
125 )
126
127 if ( ( ((unsigned long)indata & (sizeof(RC4_CHUNK)-1)) |
128 ((unsigned long)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
129 {
130 RC4_CHUNK ichunk,otp;
131 const union { long one; char little; } is_endian = {1};
132
133 /*
134 * I reckon we can afford to implement both endian
135 * cases and to decide which way to take at run-time
136 * because the machine code appears to be very compact
137 * and redundant 1-2KB is perfectly tolerable (i.e.
138 * in case the compiler fails to eliminate it:-). By
139 * suggestion from Terrel Larson <terr@terralogic.net>
140 * who also stands for the is_endian union:-)
141 *
142 * Special notes.
143 *
144 * - is_endian is declared automatic as doing otherwise
145 * (declaring static) prevents gcc from eliminating
146 * the redundant code;
147 * - compilers (those I've tried) don't seem to have
148 * problems eliminating either the operators guarded
149 * by "if (sizeof(RC4_CHUNK)==8)" or the condition
150 * expressions themselves so I've got 'em to replace
151 * corresponding #ifdefs from the previous version;
152 * - I chose to let the redundant switch cases when
153 * sizeof(RC4_CHUNK)!=8 be (were also #ifdefed
154 * before);
155 * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in
156 * [LB]ESHFT guards against "shift is out of range"
157 * warnings when sizeof(RC4_CHUNK)!=8
158 *
159 * <appro@fy.chalmers.se>
160 */
161 if (!is_endian.little)
162 { /* BIG-ENDIAN CASE */
163# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
164 for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
165 {
166 ichunk = *(RC4_CHUNK *)indata;
167 otp = RC4_STEP<<BESHFT(0);
168 otp |= RC4_STEP<<BESHFT(1);
169 otp |= RC4_STEP<<BESHFT(2);
170 otp |= RC4_STEP<<BESHFT(3);
171 if (sizeof(RC4_CHUNK)==8)
172 {
173 otp |= RC4_STEP<<BESHFT(4);
174 otp |= RC4_STEP<<BESHFT(5);
175 otp |= RC4_STEP<<BESHFT(6);
176 otp |= RC4_STEP<<BESHFT(7);
177 }
178 *(RC4_CHUNK *)outdata = otp^ichunk;
179 indata += sizeof(RC4_CHUNK);
180 outdata += sizeof(RC4_CHUNK);
181 }
182 if (len)
183 {
184 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
185
186 ichunk = *(RC4_CHUNK *)indata;
187 ochunk = *(RC4_CHUNK *)outdata;
188 otp = 0;
189 i = BESHFT(0);
190 mask <<= (sizeof(RC4_CHUNK)-len)<<3;
191 switch (len&(sizeof(RC4_CHUNK)-1))
192 {
193 case 7: otp = RC4_STEP<<i, i-=8;
194 case 6: otp |= RC4_STEP<<i, i-=8;
195 case 5: otp |= RC4_STEP<<i, i-=8;
196 case 4: otp |= RC4_STEP<<i, i-=8;
197 case 3: otp |= RC4_STEP<<i, i-=8;
198 case 2: otp |= RC4_STEP<<i, i-=8;
199 case 1: otp |= RC4_STEP<<i, i-=8;
200 case 0: ; /*
201 * it's never the case,
202 * but it has to be here
203 * for ultrix?
204 */
205 }
206 ochunk &= ~mask;
207 ochunk |= (otp^ichunk) & mask;
208 *(RC4_CHUNK *)outdata = ochunk;
209 }
210 key->x=x;
211 key->y=y;
212 return;
213 }
214 else
215 { /* LITTLE-ENDIAN CASE */
216# define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
217 for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
218 {
219 ichunk = *(RC4_CHUNK *)indata;
220 otp = RC4_STEP;
221 otp |= RC4_STEP<<8;
222 otp |= RC4_STEP<<16;
223 otp |= RC4_STEP<<24;
224 if (sizeof(RC4_CHUNK)==8)
225 {
226 otp |= RC4_STEP<<LESHFT(4);
227 otp |= RC4_STEP<<LESHFT(5);
228 otp |= RC4_STEP<<LESHFT(6);
229 otp |= RC4_STEP<<LESHFT(7);
230 }
231 *(RC4_CHUNK *)outdata = otp^ichunk;
232 indata += sizeof(RC4_CHUNK);
233 outdata += sizeof(RC4_CHUNK);
234 }
235 if (len)
236 {
237 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
238
239 ichunk = *(RC4_CHUNK *)indata;
240 ochunk = *(RC4_CHUNK *)outdata;
241 otp = 0;
242 i = 0;
243 mask >>= (sizeof(RC4_CHUNK)-len)<<3;
244 switch (len&(sizeof(RC4_CHUNK)-1))
245 {
246 case 7: otp = RC4_STEP, i+=8;
247 case 6: otp |= RC4_STEP<<i, i+=8;
248 case 5: otp |= RC4_STEP<<i, i+=8;
249 case 4: otp |= RC4_STEP<<i, i+=8;
250 case 3: otp |= RC4_STEP<<i, i+=8;
251 case 2: otp |= RC4_STEP<<i, i+=8;
252 case 1: otp |= RC4_STEP<<i, i+=8;
253 case 0: ; /*
254 * it's never the case,
255 * but it has to be here
256 * for ultrix?
257 */
258 }
259 ochunk &= ~mask;
260 ochunk |= (otp^ichunk) & mask;
261 *(RC4_CHUNK *)outdata = ochunk;
262 }
263 key->x=x;
264 key->y=y;
265 return;
266 }
267 }
268#endif
269#define LOOP(in,out) \
270 x=((x+1)&0xff); \
271 tx=d[x]; \
272 y=(tx+y)&0xff; \
273 d[x]=ty=d[y]; \
274 d[y]=tx; \
275 (out) = d[(tx+ty)&0xff]^ (in);
276
277#ifndef RC4_INDEX
278#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
279#else
280#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
281#endif
282
283 i=(int)(len>>3L);
284 if (i)
285 {
286 for (;;)
287 {
288 RC4_LOOP(indata,outdata,0);
289 RC4_LOOP(indata,outdata,1);
290 RC4_LOOP(indata,outdata,2);
291 RC4_LOOP(indata,outdata,3);
292 RC4_LOOP(indata,outdata,4);
293 RC4_LOOP(indata,outdata,5);
294 RC4_LOOP(indata,outdata,6);
295 RC4_LOOP(indata,outdata,7);
296#ifdef RC4_INDEX
297 indata+=8;
298 outdata+=8;
299#endif
300 if (--i == 0) break;
301 }
302 }
303 i=(int)len&0x07;
304 if (i)
305 {
306 for (;;)
307 {
308 RC4_LOOP(indata,outdata,0); if (--i == 0) break;
309 RC4_LOOP(indata,outdata,1); if (--i == 0) break;
310 RC4_LOOP(indata,outdata,2); if (--i == 0) break;
311 RC4_LOOP(indata,outdata,3); if (--i == 0) break;
312 RC4_LOOP(indata,outdata,4); if (--i == 0) break;
313 RC4_LOOP(indata,outdata,5); if (--i == 0) break;
314 RC4_LOOP(indata,outdata,6); if (--i == 0) break;
315 }
316 }
317 key->x=x;
318 key->y=y;
319 }
diff --git a/src/lib/libcrypto/rc4/rc4_locl.h b/src/lib/libcrypto/rc4/rc4_locl.h
new file mode 100644
index 0000000000..c712e1632e
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4_locl.h
@@ -0,0 +1,5 @@
1#ifndef HEADER_RC4_LOCL_H
2#define HEADER_RC4_LOCL_H
3#include <openssl/opensslconf.h>
4#include <cryptlib.h>
5#endif
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
new file mode 100644
index 0000000000..07234f061a
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4_skey.c
@@ -0,0 +1,123 @@
1/* crypto/rc4/rc4_skey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/rc4.h>
60#include <openssl/crypto.h>
61#include "rc4_locl.h"
62#include <openssl/opensslv.h>
63
64const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT;
65
66const char *RC4_options(void)
67 {
68#ifdef RC4_INDEX
69 if (sizeof(RC4_INT) == 1)
70 return("rc4(idx,char)");
71 else
72 return("rc4(idx,int)");
73#else
74 if (sizeof(RC4_INT) == 1)
75 return("rc4(ptr,char)");
76 else
77 return("rc4(ptr,int)");
78#endif
79 }
80
81/* RC4 as implemented from a posting from
82 * Newsgroups: sci.crypt
83 * From: sterndark@netcom.com (David Sterndark)
84 * Subject: RC4 Algorithm revealed.
85 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
86 * Date: Wed, 14 Sep 1994 06:35:31 GMT
87 */
88
89FIPS_NON_FIPS_VCIPHER_Init(RC4)
90 {
91 register RC4_INT tmp;
92 register int id1,id2;
93 register RC4_INT *d;
94 unsigned int i;
95
96 d= &(key->data[0]);
97#if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
98 /* see crypto/rc4/asm/rc4-ia64.S for further details... */
99 d=(RC4_INT *)(((size_t)(d+255))&~(sizeof(key->data)-1));
100#endif
101
102 for (i=0; i<256; i++)
103 d[i]=i;
104 key->x = 0;
105 key->y = 0;
106 id1=id2=0;
107
108#define SK_LOOP(n) { \
109 tmp=d[(n)]; \
110 id2 = (data[id1] + tmp + id2) & 0xff; \
111 if (++id1 == len) id1=0; \
112 d[(n)]=d[id2]; \
113 d[id2]=tmp; }
114
115 for (i=0; i < 256; i+=4)
116 {
117 SK_LOOP(i+0);
118 SK_LOOP(i+1);
119 SK_LOOP(i+2);
120 SK_LOOP(i+3);
121 }
122 }
123
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/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
new file mode 100644
index 0000000000..f1ffc8b134
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/README
@@ -0,0 +1,15 @@
1RIPEMD-160
2http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
3
4This is my implementation of RIPEMD-160. The pentium assember is a little
5off the pace since I only get 1050 cycles, while the best is 1013.
6I have a few ideas for how to get another 20 or so cycles, but at
7this point I will not bother right now. I believe the trick will be
8to remove my 'copy X array onto stack' until inside the RIP1() finctions the
9first time round. To do this I need another register and will only have one
10temporary one. A bit tricky.... I can also cleanup the saving of the 5 words
11after the first half of the calculation. I should read the origional
12value, add then write. Currently I just save the new and read the origioal.
13I then read both at the end. Bad.
14
15eric (20-Jan-1998)
diff --git a/src/lib/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
new file mode 100644
index 0000000000..0ab6f76bff
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
@@ -0,0 +1,590 @@
1#!/usr/local/bin/perl
2
3# Normal is the
4# ripemd160_block_asm_host_order(RIPEMD160_CTX *c, ULONG *X,int blocks);
5
6$normal=0;
7
8push(@INC,"perlasm","../../perlasm");
9require "x86asm.pl";
10
11&asm_init($ARGV[0],$0);
12
13$A="ecx";
14$B="esi";
15$C="edi";
16$D="ebx";
17$E="ebp";
18$tmp1="eax";
19$tmp2="edx";
20
21$KL1=0x5A827999;
22$KL2=0x6ED9EBA1;
23$KL3=0x8F1BBCDC;
24$KL4=0xA953FD4E;
25$KR0=0x50A28BE6;
26$KR1=0x5C4DD124;
27$KR2=0x6D703EF3;
28$KR3=0x7A6D76E9;
29
30
31@wl=( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
32 7, 4,13, 1,10, 6,15, 3,12, 0, 9, 5, 2,14,11, 8,
33 3,10,14, 4, 9,15, 8, 1, 2, 7, 0, 6,13,11, 5,12,
34 1, 9,11,10, 0, 8,12, 4,13, 3, 7,15,14, 5, 6, 2,
35 4, 0, 5, 9, 7,12, 2,10,14, 1, 3, 8,11, 6,15,13,
36 );
37
38@wr=( 5,14, 7, 0, 9, 2,11, 4,13, 6,15, 8, 1,10, 3,12,
39 6,11, 3, 7, 0,13, 5,10,14,15, 8,12, 4, 9, 1, 2,
40 15, 5, 1, 3, 7,14, 6, 9,11, 8,12, 2,10, 0, 4,13,
41 8, 6, 4, 1, 3,11,15, 0, 5,12, 2,13, 9, 7,10,14,
42 12,15,10, 4, 1, 5, 8, 7, 6, 2,13,14, 0, 3, 9,11,
43 );
44
45@sl=( 11,14,15,12, 5, 8, 7, 9,11,13,14,15, 6, 7, 9, 8,
46 7, 6, 8,13,11, 9, 7,15, 7,12,15, 9,11, 7,13,12,
47 11,13, 6, 7,14, 9,13,15,14, 8,13, 6, 5,12, 7, 5,
48 11,12,14,15,14,15, 9, 8, 9,14, 5, 6, 8, 6, 5,12,
49 9,15, 5,11, 6, 8,13,12, 5,12,13,14,11, 8, 5, 6,
50 );
51
52@sr=( 8, 9, 9,11,13,15,15, 5, 7, 7, 8,11,14,14,12, 6,
53 9,13,15, 7,12, 8, 9,11, 7, 7,12, 7, 6,15,13,11,
54 9, 7,15,11, 8, 6, 6,14,12,13, 5,14,13,13, 7, 5,
55 15, 5, 8,11,14,14, 6,14, 6, 9,12, 9,12, 5,15, 8,
56 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11,
57 );
58
59&ripemd160_block("ripemd160_block_asm_host_order");
60&asm_finish();
61
62sub Xv
63 {
64 local($n)=@_;
65 return(&swtmp($n));
66 # tmp on stack
67 }
68
69sub Np
70 {
71 local($p)=@_;
72 local(%n)=($A,$E,$B,$A,$C,$B,$D,$C,$E,$D);
73 return($n{$p});
74 }
75
76sub RIP1
77 {
78 local($a,$b,$c,$d,$e,$pos,$s,$o,$pos2)=@_;
79
80 &comment($p++);
81 if ($p & 1)
82 {
83 #&mov($tmp1, $c) if $o == -1;
84 &xor($tmp1, $d) if $o == -1;
85 &mov($tmp2, &Xv($pos));
86 &xor($tmp1, $b);
87 &add($a, $tmp2);
88 &rotl($c, 10);
89 &add($a, $tmp1);
90 &mov($tmp1, &Np($c)); # NEXT
91 # XXX
92 &rotl($a, $s);
93 &add($a, $e);
94 }
95 else
96 {
97 &xor($tmp1, $d);
98 &mov($tmp2, &Xv($pos));
99 &xor($tmp1, $b);
100 &add($a, $tmp1);
101 &mov($tmp1, &Np($c)) if $o <= 0;
102 &mov($tmp1, -1) if $o == 1;
103 # XXX if $o == 2;
104 &rotl($c, 10);
105 &add($a, $tmp2);
106 &xor($tmp1, &Np($d)) if $o <= 0;
107 &mov($tmp2, &Xv($pos2)) if $o == 1;
108 &mov($tmp2, &wparam(0)) if $o == 2;
109 &rotl($a, $s);
110 &add($a, $e);
111 }
112 }
113
114sub RIP2
115 {
116 local($a,$b,$c,$d,$e,$pos,$pos2,$s,$K,$o)=@_;
117
118# XXXXXX
119 &comment($p++);
120 if ($p & 1)
121 {
122# &mov($tmp2, &Xv($pos)) if $o < -1;
123# &mov($tmp1, -1) if $o < -1;
124
125 &add($a, $tmp2);
126 &mov($tmp2, $c);
127 &sub($tmp1, $b);
128 &and($tmp2, $b);
129 &and($tmp1, $d);
130 &or($tmp2, $tmp1);
131 &mov($tmp1, &Xv($pos2)) if $o <= 0; # XXXXXXXXXXXXXX
132 # XXX
133 &rotl($c, 10);
134 &lea($a, &DWP($K,$a,$tmp2,1));
135 &mov($tmp2, -1) if $o <= 0;
136 # XXX
137 &rotl($a, $s);
138 &add($a, $e);
139 }
140 else
141 {
142 # XXX
143 &add($a, $tmp1);
144 &mov($tmp1, $c);
145 &sub($tmp2, $b);
146 &and($tmp1, $b);
147 &and($tmp2, $d);
148 if ($o != 2)
149 {
150 &or($tmp1, $tmp2);
151 &mov($tmp2, &Xv($pos2)) if $o <= 0;
152 &mov($tmp2, -1) if $o == 1;
153 &rotl($c, 10);
154 &lea($a, &DWP($K,$a,$tmp1,1));
155 &mov($tmp1, -1) if $o <= 0;
156 &sub($tmp2, &Np($c)) if $o == 1;
157 } else {
158 &or($tmp2, $tmp1);
159 &mov($tmp1, &Np($c));
160 &rotl($c, 10);
161 &lea($a, &DWP($K,$a,$tmp2,1));
162 &xor($tmp1, &Np($d));
163 }
164 &rotl($a, $s);
165 &add($a, $e);
166 }
167 }
168
169sub RIP3
170 {
171 local($a,$b,$c,$d,$e,$pos,$s,$K,$o,$pos2)=@_;
172
173 &comment($p++);
174 if ($p & 1)
175 {
176# &mov($tmp2, -1) if $o < -1;
177# &sub($tmp2, $c) if $o < -1;
178 &mov($tmp1, &Xv($pos));
179 &or($tmp2, $b);
180 &add($a, $tmp1);
181 &xor($tmp2, $d);
182 &mov($tmp1, -1) if $o <= 0; # NEXT
183 # XXX
184 &rotl($c, 10);
185 &lea($a, &DWP($K,$a,$tmp2,1));
186 &sub($tmp1, &Np($c)) if $o <= 0; # NEXT
187 # XXX
188 &rotl($a, $s);
189 &add($a, $e);
190 }
191 else
192 {
193 &mov($tmp2, &Xv($pos));
194 &or($tmp1, $b);
195 &add($a, $tmp2);
196 &xor($tmp1, $d);
197 &mov($tmp2, -1) if $o <= 0; # NEXT
198 &mov($tmp2, -1) if $o == 1;
199 &mov($tmp2, &Xv($pos2)) if $o == 2;
200 &rotl($c, 10);
201 &lea($a, &DWP($K,$a,$tmp1,1));
202 &sub($tmp2, &Np($c)) if $o <= 0; # NEXT
203 &mov($tmp1, &Np($d)) if $o == 1;
204 &mov($tmp1, -1) if $o == 2;
205 &rotl($a, $s);
206 &add($a, $e);
207 }
208 }
209
210sub RIP4
211 {
212 local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_;
213
214 &comment($p++);
215 if ($p & 1)
216 {
217# &mov($tmp2, -1) if $o == -2;
218# &mov($tmp1, $d) if $o == -2;
219 &sub($tmp2, $d);
220 &and($tmp1, $b);
221 &and($tmp2, $c);
222 &or($tmp2, $tmp1);
223 &mov($tmp1, &Xv($pos));
224 &rotl($c, 10);
225 &lea($a, &DWP($K,$a,$tmp2));
226 &mov($tmp2, -1) unless $o > 0; # NEXT
227 # XXX
228 &add($a, $tmp1);
229 &mov($tmp1, &Np($d)) unless $o > 0; # NEXT
230 # XXX
231 &rotl($a, $s);
232 &add($a, $e);
233 }
234 else
235 {
236 &sub($tmp2, $d);
237 &and($tmp1, $b);
238 &and($tmp2, $c);
239 &or($tmp2, $tmp1);
240 &mov($tmp1, &Xv($pos));
241 &rotl($c, 10);
242 &lea($a, &DWP($K,$a,$tmp2));
243 &mov($tmp2, -1) if $o == 0; # NEXT
244 &mov($tmp2, -1) if $o == 1;
245 &mov($tmp2, -1) if $o == 2;
246 # XXX
247 &add($a, $tmp1);
248 &mov($tmp1, &Np($d)) if $o == 0; # NEXT
249 &sub($tmp2, &Np($d)) if $o == 1;
250 &sub($tmp2, &Np($c)) if $o == 2;
251 # XXX
252 &rotl($a, $s);
253 &add($a, $e);
254 }
255 }
256
257sub RIP5
258 {
259 local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_;
260
261 &comment($p++);
262 if ($p & 1)
263 {
264 &mov($tmp2, -1) if $o == -2;
265 &sub($tmp2, $d) if $o == -2;
266 &mov($tmp1, &Xv($pos));
267 &or($tmp2, $c);
268 &add($a, $tmp1);
269 &xor($tmp2, $b);
270 &mov($tmp1, -1) if $o <= 0;
271 # XXX
272 &rotl($c, 10);
273 &lea($a, &DWP($K,$a,$tmp2,1));
274 &sub($tmp1, &Np($d)) if $o <= 0;
275 # XXX
276 &rotl($a, $s);
277 &add($a, $e);
278 }
279 else
280 {
281 &mov($tmp2, &Xv($pos));
282 &or($tmp1, $c);
283 &add($a, $tmp2);
284 &xor($tmp1, $b);
285 &mov($tmp2, -1) if $o <= 0;
286 &mov($tmp2, &wparam(0)) if $o == 1; # Middle code
287 &mov($tmp2, -1) if $o == 2;
288 &rotl($c, 10);
289 &lea($a, &DWP($K,$a,$tmp1,1));
290 &sub($tmp2, &Np($d)) if $o <= 0;
291 &mov(&swtmp(16), $A) if $o == 1;
292 &mov($tmp1, &Np($d)) if $o == 2;
293 &rotl($a, $s);
294 &add($a, $e);
295 }
296 }
297
298sub ripemd160_block
299 {
300 local($name)=@_;
301
302 &function_begin_B($name,"",3);
303
304 # parameter 1 is the RIPEMD160_CTX structure.
305 # A 0
306 # B 4
307 # C 8
308 # D 12
309 # E 16
310
311 &mov($tmp2, &wparam(0));
312 &mov($tmp1, &wparam(1));
313 &push("esi");
314 &mov($A, &DWP( 0,$tmp2,"",0));
315 &push("edi");
316 &mov($B, &DWP( 4,$tmp2,"",0));
317 &push("ebp");
318 &mov($C, &DWP( 8,$tmp2,"",0));
319 &push("ebx");
320 &stack_push(16+5+6);
321 # Special comment about the figure of 6.
322 # Idea is to pad the current frame so
323 # that the top of the stack gets fairly
324 # aligned. Well, as you realize it would
325 # always depend on how the frame below is
326 # aligned. The good news are that gcc-2.95
327 # and later does keep first argument at
328 # least double-wise aligned.
329 # <appro@fy.chalmers.se>
330
331 &set_label("start") unless $normal;
332 &comment("");
333
334 # &mov($tmp1, &wparam(1)); # Done at end of loop
335 # &mov($tmp2, &wparam(0)); # Done at end of loop
336
337 for ($z=0; $z<16; $z+=2)
338 {
339 &mov($D, &DWP( $z*4,$tmp1,"",0));
340 &mov($E, &DWP( ($z+1)*4,$tmp1,"",0));
341 &mov(&swtmp($z), $D);
342 &mov(&swtmp($z+1), $E);
343 }
344 &mov($tmp1, $C);
345 &mov($D, &DWP(12,$tmp2,"",0));
346 &mov($E, &DWP(16,$tmp2,"",0));
347
348 &RIP1($A,$B,$C,$D,$E,$wl[ 0],$sl[ 0],-1);
349 &RIP1($E,$A,$B,$C,$D,$wl[ 1],$sl[ 1],0);
350 &RIP1($D,$E,$A,$B,$C,$wl[ 2],$sl[ 2],0);
351 &RIP1($C,$D,$E,$A,$B,$wl[ 3],$sl[ 3],0);
352 &RIP1($B,$C,$D,$E,$A,$wl[ 4],$sl[ 4],0);
353 &RIP1($A,$B,$C,$D,$E,$wl[ 5],$sl[ 5],0);
354 &RIP1($E,$A,$B,$C,$D,$wl[ 6],$sl[ 6],0);
355 &RIP1($D,$E,$A,$B,$C,$wl[ 7],$sl[ 7],0);
356 &RIP1($C,$D,$E,$A,$B,$wl[ 8],$sl[ 8],0);
357 &RIP1($B,$C,$D,$E,$A,$wl[ 9],$sl[ 9],0);
358 &RIP1($A,$B,$C,$D,$E,$wl[10],$sl[10],0);
359 &RIP1($E,$A,$B,$C,$D,$wl[11],$sl[11],0);
360 &RIP1($D,$E,$A,$B,$C,$wl[12],$sl[12],0);
361 &RIP1($C,$D,$E,$A,$B,$wl[13],$sl[13],0);
362 &RIP1($B,$C,$D,$E,$A,$wl[14],$sl[14],0);
363 &RIP1($A,$B,$C,$D,$E,$wl[15],$sl[15],1,$wl[16]);
364
365 &RIP2($E,$A,$B,$C,$D,$wl[16],$wl[17],$sl[16],$KL1,-1);
366 &RIP2($D,$E,$A,$B,$C,$wl[17],$wl[18],$sl[17],$KL1,0);
367 &RIP2($C,$D,$E,$A,$B,$wl[18],$wl[19],$sl[18],$KL1,0);
368 &RIP2($B,$C,$D,$E,$A,$wl[19],$wl[20],$sl[19],$KL1,0);
369 &RIP2($A,$B,$C,$D,$E,$wl[20],$wl[21],$sl[20],$KL1,0);
370 &RIP2($E,$A,$B,$C,$D,$wl[21],$wl[22],$sl[21],$KL1,0);
371 &RIP2($D,$E,$A,$B,$C,$wl[22],$wl[23],$sl[22],$KL1,0);
372 &RIP2($C,$D,$E,$A,$B,$wl[23],$wl[24],$sl[23],$KL1,0);
373 &RIP2($B,$C,$D,$E,$A,$wl[24],$wl[25],$sl[24],$KL1,0);
374 &RIP2($A,$B,$C,$D,$E,$wl[25],$wl[26],$sl[25],$KL1,0);
375 &RIP2($E,$A,$B,$C,$D,$wl[26],$wl[27],$sl[26],$KL1,0);
376 &RIP2($D,$E,$A,$B,$C,$wl[27],$wl[28],$sl[27],$KL1,0);
377 &RIP2($C,$D,$E,$A,$B,$wl[28],$wl[29],$sl[28],$KL1,0);
378 &RIP2($B,$C,$D,$E,$A,$wl[29],$wl[30],$sl[29],$KL1,0);
379 &RIP2($A,$B,$C,$D,$E,$wl[30],$wl[31],$sl[30],$KL1,0);
380 &RIP2($E,$A,$B,$C,$D,$wl[31],$wl[32],$sl[31],$KL1,1);
381
382 &RIP3($D,$E,$A,$B,$C,$wl[32],$sl[32],$KL2,-1);
383 &RIP3($C,$D,$E,$A,$B,$wl[33],$sl[33],$KL2,0);
384 &RIP3($B,$C,$D,$E,$A,$wl[34],$sl[34],$KL2,0);
385 &RIP3($A,$B,$C,$D,$E,$wl[35],$sl[35],$KL2,0);
386 &RIP3($E,$A,$B,$C,$D,$wl[36],$sl[36],$KL2,0);
387 &RIP3($D,$E,$A,$B,$C,$wl[37],$sl[37],$KL2,0);
388 &RIP3($C,$D,$E,$A,$B,$wl[38],$sl[38],$KL2,0);
389 &RIP3($B,$C,$D,$E,$A,$wl[39],$sl[39],$KL2,0);
390 &RIP3($A,$B,$C,$D,$E,$wl[40],$sl[40],$KL2,0);
391 &RIP3($E,$A,$B,$C,$D,$wl[41],$sl[41],$KL2,0);
392 &RIP3($D,$E,$A,$B,$C,$wl[42],$sl[42],$KL2,0);
393 &RIP3($C,$D,$E,$A,$B,$wl[43],$sl[43],$KL2,0);
394 &RIP3($B,$C,$D,$E,$A,$wl[44],$sl[44],$KL2,0);
395 &RIP3($A,$B,$C,$D,$E,$wl[45],$sl[45],$KL2,0);
396 &RIP3($E,$A,$B,$C,$D,$wl[46],$sl[46],$KL2,0);
397 &RIP3($D,$E,$A,$B,$C,$wl[47],$sl[47],$KL2,1);
398
399 &RIP4($C,$D,$E,$A,$B,$wl[48],$sl[48],$KL3,-1);
400 &RIP4($B,$C,$D,$E,$A,$wl[49],$sl[49],$KL3,0);
401 &RIP4($A,$B,$C,$D,$E,$wl[50],$sl[50],$KL3,0);
402 &RIP4($E,$A,$B,$C,$D,$wl[51],$sl[51],$KL3,0);
403 &RIP4($D,$E,$A,$B,$C,$wl[52],$sl[52],$KL3,0);
404 &RIP4($C,$D,$E,$A,$B,$wl[53],$sl[53],$KL3,0);
405 &RIP4($B,$C,$D,$E,$A,$wl[54],$sl[54],$KL3,0);
406 &RIP4($A,$B,$C,$D,$E,$wl[55],$sl[55],$KL3,0);
407 &RIP4($E,$A,$B,$C,$D,$wl[56],$sl[56],$KL3,0);
408 &RIP4($D,$E,$A,$B,$C,$wl[57],$sl[57],$KL3,0);
409 &RIP4($C,$D,$E,$A,$B,$wl[58],$sl[58],$KL3,0);
410 &RIP4($B,$C,$D,$E,$A,$wl[59],$sl[59],$KL3,0);
411 &RIP4($A,$B,$C,$D,$E,$wl[60],$sl[60],$KL3,0);
412 &RIP4($E,$A,$B,$C,$D,$wl[61],$sl[61],$KL3,0);
413 &RIP4($D,$E,$A,$B,$C,$wl[62],$sl[62],$KL3,0);
414 &RIP4($C,$D,$E,$A,$B,$wl[63],$sl[63],$KL3,1);
415
416 &RIP5($B,$C,$D,$E,$A,$wl[64],$sl[64],$KL4,-1);
417 &RIP5($A,$B,$C,$D,$E,$wl[65],$sl[65],$KL4,0);
418 &RIP5($E,$A,$B,$C,$D,$wl[66],$sl[66],$KL4,0);
419 &RIP5($D,$E,$A,$B,$C,$wl[67],$sl[67],$KL4,0);
420 &RIP5($C,$D,$E,$A,$B,$wl[68],$sl[68],$KL4,0);
421 &RIP5($B,$C,$D,$E,$A,$wl[69],$sl[69],$KL4,0);
422 &RIP5($A,$B,$C,$D,$E,$wl[70],$sl[70],$KL4,0);
423 &RIP5($E,$A,$B,$C,$D,$wl[71],$sl[71],$KL4,0);
424 &RIP5($D,$E,$A,$B,$C,$wl[72],$sl[72],$KL4,0);
425 &RIP5($C,$D,$E,$A,$B,$wl[73],$sl[73],$KL4,0);
426 &RIP5($B,$C,$D,$E,$A,$wl[74],$sl[74],$KL4,0);
427 &RIP5($A,$B,$C,$D,$E,$wl[75],$sl[75],$KL4,0);
428 &RIP5($E,$A,$B,$C,$D,$wl[76],$sl[76],$KL4,0);
429 &RIP5($D,$E,$A,$B,$C,$wl[77],$sl[77],$KL4,0);
430 &RIP5($C,$D,$E,$A,$B,$wl[78],$sl[78],$KL4,0);
431 &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1);
432
433 # &mov($tmp2, &wparam(0)); # moved into last RIP5
434 # &mov(&swtmp(16), $A);
435 &mov($A, &DWP( 0,$tmp2,"",0));
436 &mov(&swtmp(16+1), $B);
437 &mov(&swtmp(16+2), $C);
438 &mov($B, &DWP( 4,$tmp2,"",0));
439 &mov(&swtmp(16+3), $D);
440 &mov($C, &DWP( 8,$tmp2,"",0));
441 &mov(&swtmp(16+4), $E);
442 &mov($D, &DWP(12,$tmp2,"",0));
443 &mov($E, &DWP(16,$tmp2,"",0));
444
445 &RIP5($A,$B,$C,$D,$E,$wr[ 0],$sr[ 0],$KR0,-2);
446 &RIP5($E,$A,$B,$C,$D,$wr[ 1],$sr[ 1],$KR0,0);
447 &RIP5($D,$E,$A,$B,$C,$wr[ 2],$sr[ 2],$KR0,0);
448 &RIP5($C,$D,$E,$A,$B,$wr[ 3],$sr[ 3],$KR0,0);
449 &RIP5($B,$C,$D,$E,$A,$wr[ 4],$sr[ 4],$KR0,0);
450 &RIP5($A,$B,$C,$D,$E,$wr[ 5],$sr[ 5],$KR0,0);
451 &RIP5($E,$A,$B,$C,$D,$wr[ 6],$sr[ 6],$KR0,0);
452 &RIP5($D,$E,$A,$B,$C,$wr[ 7],$sr[ 7],$KR0,0);
453 &RIP5($C,$D,$E,$A,$B,$wr[ 8],$sr[ 8],$KR0,0);
454 &RIP5($B,$C,$D,$E,$A,$wr[ 9],$sr[ 9],$KR0,0);
455 &RIP5($A,$B,$C,$D,$E,$wr[10],$sr[10],$KR0,0);
456 &RIP5($E,$A,$B,$C,$D,$wr[11],$sr[11],$KR0,0);
457 &RIP5($D,$E,$A,$B,$C,$wr[12],$sr[12],$KR0,0);
458 &RIP5($C,$D,$E,$A,$B,$wr[13],$sr[13],$KR0,0);
459 &RIP5($B,$C,$D,$E,$A,$wr[14],$sr[14],$KR0,0);
460 &RIP5($A,$B,$C,$D,$E,$wr[15],$sr[15],$KR0,2);
461
462 &RIP4($E,$A,$B,$C,$D,$wr[16],$sr[16],$KR1,-2);
463 &RIP4($D,$E,$A,$B,$C,$wr[17],$sr[17],$KR1,0);
464 &RIP4($C,$D,$E,$A,$B,$wr[18],$sr[18],$KR1,0);
465 &RIP4($B,$C,$D,$E,$A,$wr[19],$sr[19],$KR1,0);
466 &RIP4($A,$B,$C,$D,$E,$wr[20],$sr[20],$KR1,0);
467 &RIP4($E,$A,$B,$C,$D,$wr[21],$sr[21],$KR1,0);
468 &RIP4($D,$E,$A,$B,$C,$wr[22],$sr[22],$KR1,0);
469 &RIP4($C,$D,$E,$A,$B,$wr[23],$sr[23],$KR1,0);
470 &RIP4($B,$C,$D,$E,$A,$wr[24],$sr[24],$KR1,0);
471 &RIP4($A,$B,$C,$D,$E,$wr[25],$sr[25],$KR1,0);
472 &RIP4($E,$A,$B,$C,$D,$wr[26],$sr[26],$KR1,0);
473 &RIP4($D,$E,$A,$B,$C,$wr[27],$sr[27],$KR1,0);
474 &RIP4($C,$D,$E,$A,$B,$wr[28],$sr[28],$KR1,0);
475 &RIP4($B,$C,$D,$E,$A,$wr[29],$sr[29],$KR1,0);
476 &RIP4($A,$B,$C,$D,$E,$wr[30],$sr[30],$KR1,0);
477 &RIP4($E,$A,$B,$C,$D,$wr[31],$sr[31],$KR1,2);
478
479 &RIP3($D,$E,$A,$B,$C,$wr[32],$sr[32],$KR2,-2);
480 &RIP3($C,$D,$E,$A,$B,$wr[33],$sr[33],$KR2,0);
481 &RIP3($B,$C,$D,$E,$A,$wr[34],$sr[34],$KR2,0);
482 &RIP3($A,$B,$C,$D,$E,$wr[35],$sr[35],$KR2,0);
483 &RIP3($E,$A,$B,$C,$D,$wr[36],$sr[36],$KR2,0);
484 &RIP3($D,$E,$A,$B,$C,$wr[37],$sr[37],$KR2,0);
485 &RIP3($C,$D,$E,$A,$B,$wr[38],$sr[38],$KR2,0);
486 &RIP3($B,$C,$D,$E,$A,$wr[39],$sr[39],$KR2,0);
487 &RIP3($A,$B,$C,$D,$E,$wr[40],$sr[40],$KR2,0);
488 &RIP3($E,$A,$B,$C,$D,$wr[41],$sr[41],$KR2,0);
489 &RIP3($D,$E,$A,$B,$C,$wr[42],$sr[42],$KR2,0);
490 &RIP3($C,$D,$E,$A,$B,$wr[43],$sr[43],$KR2,0);
491 &RIP3($B,$C,$D,$E,$A,$wr[44],$sr[44],$KR2,0);
492 &RIP3($A,$B,$C,$D,$E,$wr[45],$sr[45],$KR2,0);
493 &RIP3($E,$A,$B,$C,$D,$wr[46],$sr[46],$KR2,0);
494 &RIP3($D,$E,$A,$B,$C,$wr[47],$sr[47],$KR2,2,$wr[48]);
495
496 &RIP2($C,$D,$E,$A,$B,$wr[48],$wr[49],$sr[48],$KR3,-2);
497 &RIP2($B,$C,$D,$E,$A,$wr[49],$wr[50],$sr[49],$KR3,0);
498 &RIP2($A,$B,$C,$D,$E,$wr[50],$wr[51],$sr[50],$KR3,0);
499 &RIP2($E,$A,$B,$C,$D,$wr[51],$wr[52],$sr[51],$KR3,0);
500 &RIP2($D,$E,$A,$B,$C,$wr[52],$wr[53],$sr[52],$KR3,0);
501 &RIP2($C,$D,$E,$A,$B,$wr[53],$wr[54],$sr[53],$KR3,0);
502 &RIP2($B,$C,$D,$E,$A,$wr[54],$wr[55],$sr[54],$KR3,0);
503 &RIP2($A,$B,$C,$D,$E,$wr[55],$wr[56],$sr[55],$KR3,0);
504 &RIP2($E,$A,$B,$C,$D,$wr[56],$wr[57],$sr[56],$KR3,0);
505 &RIP2($D,$E,$A,$B,$C,$wr[57],$wr[58],$sr[57],$KR3,0);
506 &RIP2($C,$D,$E,$A,$B,$wr[58],$wr[59],$sr[58],$KR3,0);
507 &RIP2($B,$C,$D,$E,$A,$wr[59],$wr[60],$sr[59],$KR3,0);
508 &RIP2($A,$B,$C,$D,$E,$wr[60],$wr[61],$sr[60],$KR3,0);
509 &RIP2($E,$A,$B,$C,$D,$wr[61],$wr[62],$sr[61],$KR3,0);
510 &RIP2($D,$E,$A,$B,$C,$wr[62],$wr[63],$sr[62],$KR3,0);
511 &RIP2($C,$D,$E,$A,$B,$wr[63],$wr[64],$sr[63],$KR3,2);
512
513 &RIP1($B,$C,$D,$E,$A,$wr[64],$sr[64],-2);
514 &RIP1($A,$B,$C,$D,$E,$wr[65],$sr[65],0);
515 &RIP1($E,$A,$B,$C,$D,$wr[66],$sr[66],0);
516 &RIP1($D,$E,$A,$B,$C,$wr[67],$sr[67],0);
517 &RIP1($C,$D,$E,$A,$B,$wr[68],$sr[68],0);
518 &RIP1($B,$C,$D,$E,$A,$wr[69],$sr[69],0);
519 &RIP1($A,$B,$C,$D,$E,$wr[70],$sr[70],0);
520 &RIP1($E,$A,$B,$C,$D,$wr[71],$sr[71],0);
521 &RIP1($D,$E,$A,$B,$C,$wr[72],$sr[72],0);
522 &RIP1($C,$D,$E,$A,$B,$wr[73],$sr[73],0);
523 &RIP1($B,$C,$D,$E,$A,$wr[74],$sr[74],0);
524 &RIP1($A,$B,$C,$D,$E,$wr[75],$sr[75],0);
525 &RIP1($E,$A,$B,$C,$D,$wr[76],$sr[76],0);
526 &RIP1($D,$E,$A,$B,$C,$wr[77],$sr[77],0);
527 &RIP1($C,$D,$E,$A,$B,$wr[78],$sr[78],0);
528 &RIP1($B,$C,$D,$E,$A,$wr[79],$sr[79],2);
529
530 # &mov($tmp2, &wparam(0)); # Moved into last round
531
532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B
533 &add($D, $tmp1);
534 &mov($tmp1, &swtmp(16+2)); # $c
535 &add($D, $tmp1);
536
537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C
538 &add($E, $tmp1);
539 &mov($tmp1, &swtmp(16+3)); # $d
540 &add($E, $tmp1);
541
542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D
543 &add($A, $tmp1);
544 &mov($tmp1, &swtmp(16+4)); # $e
545 &add($A, $tmp1);
546
547
548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E
549 &add($B, $tmp1);
550 &mov($tmp1, &swtmp(16+0)); # $a
551 &add($B, $tmp1);
552
553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A
554 &add($C, $tmp1);
555 &mov($tmp1, &swtmp(16+1)); # $b
556 &add($C, $tmp1);
557
558 &mov($tmp1, &wparam(2));
559
560 &mov(&DWP( 0,$tmp2,"",0), $D);
561 &mov(&DWP( 4,$tmp2,"",0), $E);
562 &mov(&DWP( 8,$tmp2,"",0), $A);
563 &sub($tmp1,1);
564 &mov(&DWP(12,$tmp2,"",0), $B);
565 &mov(&DWP(16,$tmp2,"",0), $C);
566
567 &jle(&label("get_out"));
568
569 &mov(&wparam(2),$tmp1);
570 &mov($C, $A);
571 &mov($tmp1, &wparam(1));
572 &mov($A, $D);
573 &add($tmp1, 64);
574 &mov($B, $E);
575 &mov(&wparam(1),$tmp1);
576
577 &jmp(&label("start"));
578
579 &set_label("get_out");
580
581 &stack_pop(16+5+6);
582
583 &pop("ebx");
584 &pop("ebp");
585 &pop("edi");
586 &pop("esi");
587 &ret();
588 &function_end_B($name);
589 }
590
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
new file mode 100644
index 0000000000..7d0d998189
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/ripemd.h
@@ -0,0 +1,106 @@
1/* crypto/ripemd/ripemd.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RIPEMD_H
60#define HEADER_RIPEMD_H
61
62#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_RIPEMD
69#error RIPEMD is disabled.
70#endif
71
72#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
73#define RIPEMD160_LONG unsigned long
74#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
75#define RIPEMD160_LONG unsigned long
76#define RIPEMD160_LONG_LOG2 3
77#else
78#define RIPEMD160_LONG unsigned int
79#endif
80
81#define RIPEMD160_CBLOCK 64
82#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4)
83#define RIPEMD160_DIGEST_LENGTH 20
84
85typedef struct RIPEMD160state_st
86 {
87 RIPEMD160_LONG A,B,C,D,E;
88 RIPEMD160_LONG Nl,Nh;
89 RIPEMD160_LONG data[RIPEMD160_LBLOCK];
90 int num;
91 } RIPEMD160_CTX;
92
93#ifdef OPENSSL_FIPS
94int private_RIPEMD160_Init(RIPEMD160_CTX *c);
95#endif
96int RIPEMD160_Init(RIPEMD160_CTX *c);
97int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
98int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
99unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
100 unsigned char *md);
101void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
102#ifdef __cplusplus
103}
104#endif
105
106#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
new file mode 100644
index 0000000000..58ff010d11
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmd_dgst.c
@@ -0,0 +1,495 @@
1/* crypto/ripemd/rmd_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "rmd_locl.h"
61#include <openssl/fips.h>
62#include <openssl/opensslv.h>
63
64const char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
65
66# ifdef RMD160_ASM
67 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
68# define ripemd160_block ripemd160_block_x86
69# else
70 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
71# endif
72
73FIPS_NON_FIPS_MD_Init(RIPEMD160)
74 {
75 c->A=RIPEMD160_A;
76 c->B=RIPEMD160_B;
77 c->C=RIPEMD160_C;
78 c->D=RIPEMD160_D;
79 c->E=RIPEMD160_E;
80 c->Nl=0;
81 c->Nh=0;
82 c->num=0;
83 return 1;
84 }
85
86#ifndef ripemd160_block_host_order
87#ifdef X
88#undef X
89#endif
90#define X(i) XX[i]
91void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num)
92 {
93 const RIPEMD160_LONG *XX=p;
94 register volatile unsigned MD32_REG_T A,B,C,D,E;
95 register unsigned MD32_REG_T a,b,c,d,e;
96
97 for (;num--;XX+=HASH_LBLOCK)
98 {
99
100 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
101
102 RIP1(A,B,C,D,E,WL00,SL00);
103 RIP1(E,A,B,C,D,WL01,SL01);
104 RIP1(D,E,A,B,C,WL02,SL02);
105 RIP1(C,D,E,A,B,WL03,SL03);
106 RIP1(B,C,D,E,A,WL04,SL04);
107 RIP1(A,B,C,D,E,WL05,SL05);
108 RIP1(E,A,B,C,D,WL06,SL06);
109 RIP1(D,E,A,B,C,WL07,SL07);
110 RIP1(C,D,E,A,B,WL08,SL08);
111 RIP1(B,C,D,E,A,WL09,SL09);
112 RIP1(A,B,C,D,E,WL10,SL10);
113 RIP1(E,A,B,C,D,WL11,SL11);
114 RIP1(D,E,A,B,C,WL12,SL12);
115 RIP1(C,D,E,A,B,WL13,SL13);
116 RIP1(B,C,D,E,A,WL14,SL14);
117 RIP1(A,B,C,D,E,WL15,SL15);
118
119 RIP2(E,A,B,C,D,WL16,SL16,KL1);
120 RIP2(D,E,A,B,C,WL17,SL17,KL1);
121 RIP2(C,D,E,A,B,WL18,SL18,KL1);
122 RIP2(B,C,D,E,A,WL19,SL19,KL1);
123 RIP2(A,B,C,D,E,WL20,SL20,KL1);
124 RIP2(E,A,B,C,D,WL21,SL21,KL1);
125 RIP2(D,E,A,B,C,WL22,SL22,KL1);
126 RIP2(C,D,E,A,B,WL23,SL23,KL1);
127 RIP2(B,C,D,E,A,WL24,SL24,KL1);
128 RIP2(A,B,C,D,E,WL25,SL25,KL1);
129 RIP2(E,A,B,C,D,WL26,SL26,KL1);
130 RIP2(D,E,A,B,C,WL27,SL27,KL1);
131 RIP2(C,D,E,A,B,WL28,SL28,KL1);
132 RIP2(B,C,D,E,A,WL29,SL29,KL1);
133 RIP2(A,B,C,D,E,WL30,SL30,KL1);
134 RIP2(E,A,B,C,D,WL31,SL31,KL1);
135
136 RIP3(D,E,A,B,C,WL32,SL32,KL2);
137 RIP3(C,D,E,A,B,WL33,SL33,KL2);
138 RIP3(B,C,D,E,A,WL34,SL34,KL2);
139 RIP3(A,B,C,D,E,WL35,SL35,KL2);
140 RIP3(E,A,B,C,D,WL36,SL36,KL2);
141 RIP3(D,E,A,B,C,WL37,SL37,KL2);
142 RIP3(C,D,E,A,B,WL38,SL38,KL2);
143 RIP3(B,C,D,E,A,WL39,SL39,KL2);
144 RIP3(A,B,C,D,E,WL40,SL40,KL2);
145 RIP3(E,A,B,C,D,WL41,SL41,KL2);
146 RIP3(D,E,A,B,C,WL42,SL42,KL2);
147 RIP3(C,D,E,A,B,WL43,SL43,KL2);
148 RIP3(B,C,D,E,A,WL44,SL44,KL2);
149 RIP3(A,B,C,D,E,WL45,SL45,KL2);
150 RIP3(E,A,B,C,D,WL46,SL46,KL2);
151 RIP3(D,E,A,B,C,WL47,SL47,KL2);
152
153 RIP4(C,D,E,A,B,WL48,SL48,KL3);
154 RIP4(B,C,D,E,A,WL49,SL49,KL3);
155 RIP4(A,B,C,D,E,WL50,SL50,KL3);
156 RIP4(E,A,B,C,D,WL51,SL51,KL3);
157 RIP4(D,E,A,B,C,WL52,SL52,KL3);
158 RIP4(C,D,E,A,B,WL53,SL53,KL3);
159 RIP4(B,C,D,E,A,WL54,SL54,KL3);
160 RIP4(A,B,C,D,E,WL55,SL55,KL3);
161 RIP4(E,A,B,C,D,WL56,SL56,KL3);
162 RIP4(D,E,A,B,C,WL57,SL57,KL3);
163 RIP4(C,D,E,A,B,WL58,SL58,KL3);
164 RIP4(B,C,D,E,A,WL59,SL59,KL3);
165 RIP4(A,B,C,D,E,WL60,SL60,KL3);
166 RIP4(E,A,B,C,D,WL61,SL61,KL3);
167 RIP4(D,E,A,B,C,WL62,SL62,KL3);
168 RIP4(C,D,E,A,B,WL63,SL63,KL3);
169
170 RIP5(B,C,D,E,A,WL64,SL64,KL4);
171 RIP5(A,B,C,D,E,WL65,SL65,KL4);
172 RIP5(E,A,B,C,D,WL66,SL66,KL4);
173 RIP5(D,E,A,B,C,WL67,SL67,KL4);
174 RIP5(C,D,E,A,B,WL68,SL68,KL4);
175 RIP5(B,C,D,E,A,WL69,SL69,KL4);
176 RIP5(A,B,C,D,E,WL70,SL70,KL4);
177 RIP5(E,A,B,C,D,WL71,SL71,KL4);
178 RIP5(D,E,A,B,C,WL72,SL72,KL4);
179 RIP5(C,D,E,A,B,WL73,SL73,KL4);
180 RIP5(B,C,D,E,A,WL74,SL74,KL4);
181 RIP5(A,B,C,D,E,WL75,SL75,KL4);
182 RIP5(E,A,B,C,D,WL76,SL76,KL4);
183 RIP5(D,E,A,B,C,WL77,SL77,KL4);
184 RIP5(C,D,E,A,B,WL78,SL78,KL4);
185 RIP5(B,C,D,E,A,WL79,SL79,KL4);
186
187 a=A; b=B; c=C; d=D; e=E;
188 /* Do other half */
189 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
190
191 RIP5(A,B,C,D,E,WR00,SR00,KR0);
192 RIP5(E,A,B,C,D,WR01,SR01,KR0);
193 RIP5(D,E,A,B,C,WR02,SR02,KR0);
194 RIP5(C,D,E,A,B,WR03,SR03,KR0);
195 RIP5(B,C,D,E,A,WR04,SR04,KR0);
196 RIP5(A,B,C,D,E,WR05,SR05,KR0);
197 RIP5(E,A,B,C,D,WR06,SR06,KR0);
198 RIP5(D,E,A,B,C,WR07,SR07,KR0);
199 RIP5(C,D,E,A,B,WR08,SR08,KR0);
200 RIP5(B,C,D,E,A,WR09,SR09,KR0);
201 RIP5(A,B,C,D,E,WR10,SR10,KR0);
202 RIP5(E,A,B,C,D,WR11,SR11,KR0);
203 RIP5(D,E,A,B,C,WR12,SR12,KR0);
204 RIP5(C,D,E,A,B,WR13,SR13,KR0);
205 RIP5(B,C,D,E,A,WR14,SR14,KR0);
206 RIP5(A,B,C,D,E,WR15,SR15,KR0);
207
208 RIP4(E,A,B,C,D,WR16,SR16,KR1);
209 RIP4(D,E,A,B,C,WR17,SR17,KR1);
210 RIP4(C,D,E,A,B,WR18,SR18,KR1);
211 RIP4(B,C,D,E,A,WR19,SR19,KR1);
212 RIP4(A,B,C,D,E,WR20,SR20,KR1);
213 RIP4(E,A,B,C,D,WR21,SR21,KR1);
214 RIP4(D,E,A,B,C,WR22,SR22,KR1);
215 RIP4(C,D,E,A,B,WR23,SR23,KR1);
216 RIP4(B,C,D,E,A,WR24,SR24,KR1);
217 RIP4(A,B,C,D,E,WR25,SR25,KR1);
218 RIP4(E,A,B,C,D,WR26,SR26,KR1);
219 RIP4(D,E,A,B,C,WR27,SR27,KR1);
220 RIP4(C,D,E,A,B,WR28,SR28,KR1);
221 RIP4(B,C,D,E,A,WR29,SR29,KR1);
222 RIP4(A,B,C,D,E,WR30,SR30,KR1);
223 RIP4(E,A,B,C,D,WR31,SR31,KR1);
224
225 RIP3(D,E,A,B,C,WR32,SR32,KR2);
226 RIP3(C,D,E,A,B,WR33,SR33,KR2);
227 RIP3(B,C,D,E,A,WR34,SR34,KR2);
228 RIP3(A,B,C,D,E,WR35,SR35,KR2);
229 RIP3(E,A,B,C,D,WR36,SR36,KR2);
230 RIP3(D,E,A,B,C,WR37,SR37,KR2);
231 RIP3(C,D,E,A,B,WR38,SR38,KR2);
232 RIP3(B,C,D,E,A,WR39,SR39,KR2);
233 RIP3(A,B,C,D,E,WR40,SR40,KR2);
234 RIP3(E,A,B,C,D,WR41,SR41,KR2);
235 RIP3(D,E,A,B,C,WR42,SR42,KR2);
236 RIP3(C,D,E,A,B,WR43,SR43,KR2);
237 RIP3(B,C,D,E,A,WR44,SR44,KR2);
238 RIP3(A,B,C,D,E,WR45,SR45,KR2);
239 RIP3(E,A,B,C,D,WR46,SR46,KR2);
240 RIP3(D,E,A,B,C,WR47,SR47,KR2);
241
242 RIP2(C,D,E,A,B,WR48,SR48,KR3);
243 RIP2(B,C,D,E,A,WR49,SR49,KR3);
244 RIP2(A,B,C,D,E,WR50,SR50,KR3);
245 RIP2(E,A,B,C,D,WR51,SR51,KR3);
246 RIP2(D,E,A,B,C,WR52,SR52,KR3);
247 RIP2(C,D,E,A,B,WR53,SR53,KR3);
248 RIP2(B,C,D,E,A,WR54,SR54,KR3);
249 RIP2(A,B,C,D,E,WR55,SR55,KR3);
250 RIP2(E,A,B,C,D,WR56,SR56,KR3);
251 RIP2(D,E,A,B,C,WR57,SR57,KR3);
252 RIP2(C,D,E,A,B,WR58,SR58,KR3);
253 RIP2(B,C,D,E,A,WR59,SR59,KR3);
254 RIP2(A,B,C,D,E,WR60,SR60,KR3);
255 RIP2(E,A,B,C,D,WR61,SR61,KR3);
256 RIP2(D,E,A,B,C,WR62,SR62,KR3);
257 RIP2(C,D,E,A,B,WR63,SR63,KR3);
258
259 RIP1(B,C,D,E,A,WR64,SR64);
260 RIP1(A,B,C,D,E,WR65,SR65);
261 RIP1(E,A,B,C,D,WR66,SR66);
262 RIP1(D,E,A,B,C,WR67,SR67);
263 RIP1(C,D,E,A,B,WR68,SR68);
264 RIP1(B,C,D,E,A,WR69,SR69);
265 RIP1(A,B,C,D,E,WR70,SR70);
266 RIP1(E,A,B,C,D,WR71,SR71);
267 RIP1(D,E,A,B,C,WR72,SR72);
268 RIP1(C,D,E,A,B,WR73,SR73);
269 RIP1(B,C,D,E,A,WR74,SR74);
270 RIP1(A,B,C,D,E,WR75,SR75);
271 RIP1(E,A,B,C,D,WR76,SR76);
272 RIP1(D,E,A,B,C,WR77,SR77);
273 RIP1(C,D,E,A,B,WR78,SR78);
274 RIP1(B,C,D,E,A,WR79,SR79);
275
276 D =ctx->B+c+D;
277 ctx->B=ctx->C+d+E;
278 ctx->C=ctx->D+e+A;
279 ctx->D=ctx->E+a+B;
280 ctx->E=ctx->A+b+C;
281 ctx->A=D;
282
283 }
284 }
285#endif
286
287#ifndef ripemd160_block_data_order
288#ifdef X
289#undef X
290#endif
291void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num)
292 {
293 const unsigned char *data=p;
294 register volatile unsigned MD32_REG_T A,B,C,D,E;
295 unsigned MD32_REG_T a,b,c,d,e,l;
296#ifndef MD32_XARRAY
297 /* See comment in crypto/sha/sha_locl.h for details. */
298 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
299 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
300# define X(i) XX##i
301#else
302 RIPEMD160_LONG XX[16];
303# define X(i) XX[i]
304#endif
305
306 for (;num--;)
307 {
308
309 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
310
311 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
312 RIP1(A,B,C,D,E,WL00,SL00); HOST_c2l(data,l); X( 2)=l;
313 RIP1(E,A,B,C,D,WL01,SL01); HOST_c2l(data,l); X( 3)=l;
314 RIP1(D,E,A,B,C,WL02,SL02); HOST_c2l(data,l); X( 4)=l;
315 RIP1(C,D,E,A,B,WL03,SL03); HOST_c2l(data,l); X( 5)=l;
316 RIP1(B,C,D,E,A,WL04,SL04); HOST_c2l(data,l); X( 6)=l;
317 RIP1(A,B,C,D,E,WL05,SL05); HOST_c2l(data,l); X( 7)=l;
318 RIP1(E,A,B,C,D,WL06,SL06); HOST_c2l(data,l); X( 8)=l;
319 RIP1(D,E,A,B,C,WL07,SL07); HOST_c2l(data,l); X( 9)=l;
320 RIP1(C,D,E,A,B,WL08,SL08); HOST_c2l(data,l); X(10)=l;
321 RIP1(B,C,D,E,A,WL09,SL09); HOST_c2l(data,l); X(11)=l;
322 RIP1(A,B,C,D,E,WL10,SL10); HOST_c2l(data,l); X(12)=l;
323 RIP1(E,A,B,C,D,WL11,SL11); HOST_c2l(data,l); X(13)=l;
324 RIP1(D,E,A,B,C,WL12,SL12); HOST_c2l(data,l); X(14)=l;
325 RIP1(C,D,E,A,B,WL13,SL13); HOST_c2l(data,l); X(15)=l;
326 RIP1(B,C,D,E,A,WL14,SL14);
327 RIP1(A,B,C,D,E,WL15,SL15);
328
329 RIP2(E,A,B,C,D,WL16,SL16,KL1);
330 RIP2(D,E,A,B,C,WL17,SL17,KL1);
331 RIP2(C,D,E,A,B,WL18,SL18,KL1);
332 RIP2(B,C,D,E,A,WL19,SL19,KL1);
333 RIP2(A,B,C,D,E,WL20,SL20,KL1);
334 RIP2(E,A,B,C,D,WL21,SL21,KL1);
335 RIP2(D,E,A,B,C,WL22,SL22,KL1);
336 RIP2(C,D,E,A,B,WL23,SL23,KL1);
337 RIP2(B,C,D,E,A,WL24,SL24,KL1);
338 RIP2(A,B,C,D,E,WL25,SL25,KL1);
339 RIP2(E,A,B,C,D,WL26,SL26,KL1);
340 RIP2(D,E,A,B,C,WL27,SL27,KL1);
341 RIP2(C,D,E,A,B,WL28,SL28,KL1);
342 RIP2(B,C,D,E,A,WL29,SL29,KL1);
343 RIP2(A,B,C,D,E,WL30,SL30,KL1);
344 RIP2(E,A,B,C,D,WL31,SL31,KL1);
345
346 RIP3(D,E,A,B,C,WL32,SL32,KL2);
347 RIP3(C,D,E,A,B,WL33,SL33,KL2);
348 RIP3(B,C,D,E,A,WL34,SL34,KL2);
349 RIP3(A,B,C,D,E,WL35,SL35,KL2);
350 RIP3(E,A,B,C,D,WL36,SL36,KL2);
351 RIP3(D,E,A,B,C,WL37,SL37,KL2);
352 RIP3(C,D,E,A,B,WL38,SL38,KL2);
353 RIP3(B,C,D,E,A,WL39,SL39,KL2);
354 RIP3(A,B,C,D,E,WL40,SL40,KL2);
355 RIP3(E,A,B,C,D,WL41,SL41,KL2);
356 RIP3(D,E,A,B,C,WL42,SL42,KL2);
357 RIP3(C,D,E,A,B,WL43,SL43,KL2);
358 RIP3(B,C,D,E,A,WL44,SL44,KL2);
359 RIP3(A,B,C,D,E,WL45,SL45,KL2);
360 RIP3(E,A,B,C,D,WL46,SL46,KL2);
361 RIP3(D,E,A,B,C,WL47,SL47,KL2);
362
363 RIP4(C,D,E,A,B,WL48,SL48,KL3);
364 RIP4(B,C,D,E,A,WL49,SL49,KL3);
365 RIP4(A,B,C,D,E,WL50,SL50,KL3);
366 RIP4(E,A,B,C,D,WL51,SL51,KL3);
367 RIP4(D,E,A,B,C,WL52,SL52,KL3);
368 RIP4(C,D,E,A,B,WL53,SL53,KL3);
369 RIP4(B,C,D,E,A,WL54,SL54,KL3);
370 RIP4(A,B,C,D,E,WL55,SL55,KL3);
371 RIP4(E,A,B,C,D,WL56,SL56,KL3);
372 RIP4(D,E,A,B,C,WL57,SL57,KL3);
373 RIP4(C,D,E,A,B,WL58,SL58,KL3);
374 RIP4(B,C,D,E,A,WL59,SL59,KL3);
375 RIP4(A,B,C,D,E,WL60,SL60,KL3);
376 RIP4(E,A,B,C,D,WL61,SL61,KL3);
377 RIP4(D,E,A,B,C,WL62,SL62,KL3);
378 RIP4(C,D,E,A,B,WL63,SL63,KL3);
379
380 RIP5(B,C,D,E,A,WL64,SL64,KL4);
381 RIP5(A,B,C,D,E,WL65,SL65,KL4);
382 RIP5(E,A,B,C,D,WL66,SL66,KL4);
383 RIP5(D,E,A,B,C,WL67,SL67,KL4);
384 RIP5(C,D,E,A,B,WL68,SL68,KL4);
385 RIP5(B,C,D,E,A,WL69,SL69,KL4);
386 RIP5(A,B,C,D,E,WL70,SL70,KL4);
387 RIP5(E,A,B,C,D,WL71,SL71,KL4);
388 RIP5(D,E,A,B,C,WL72,SL72,KL4);
389 RIP5(C,D,E,A,B,WL73,SL73,KL4);
390 RIP5(B,C,D,E,A,WL74,SL74,KL4);
391 RIP5(A,B,C,D,E,WL75,SL75,KL4);
392 RIP5(E,A,B,C,D,WL76,SL76,KL4);
393 RIP5(D,E,A,B,C,WL77,SL77,KL4);
394 RIP5(C,D,E,A,B,WL78,SL78,KL4);
395 RIP5(B,C,D,E,A,WL79,SL79,KL4);
396
397 a=A; b=B; c=C; d=D; e=E;
398 /* Do other half */
399 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
400
401 RIP5(A,B,C,D,E,WR00,SR00,KR0);
402 RIP5(E,A,B,C,D,WR01,SR01,KR0);
403 RIP5(D,E,A,B,C,WR02,SR02,KR0);
404 RIP5(C,D,E,A,B,WR03,SR03,KR0);
405 RIP5(B,C,D,E,A,WR04,SR04,KR0);
406 RIP5(A,B,C,D,E,WR05,SR05,KR0);
407 RIP5(E,A,B,C,D,WR06,SR06,KR0);
408 RIP5(D,E,A,B,C,WR07,SR07,KR0);
409 RIP5(C,D,E,A,B,WR08,SR08,KR0);
410 RIP5(B,C,D,E,A,WR09,SR09,KR0);
411 RIP5(A,B,C,D,E,WR10,SR10,KR0);
412 RIP5(E,A,B,C,D,WR11,SR11,KR0);
413 RIP5(D,E,A,B,C,WR12,SR12,KR0);
414 RIP5(C,D,E,A,B,WR13,SR13,KR0);
415 RIP5(B,C,D,E,A,WR14,SR14,KR0);
416 RIP5(A,B,C,D,E,WR15,SR15,KR0);
417
418 RIP4(E,A,B,C,D,WR16,SR16,KR1);
419 RIP4(D,E,A,B,C,WR17,SR17,KR1);
420 RIP4(C,D,E,A,B,WR18,SR18,KR1);
421 RIP4(B,C,D,E,A,WR19,SR19,KR1);
422 RIP4(A,B,C,D,E,WR20,SR20,KR1);
423 RIP4(E,A,B,C,D,WR21,SR21,KR1);
424 RIP4(D,E,A,B,C,WR22,SR22,KR1);
425 RIP4(C,D,E,A,B,WR23,SR23,KR1);
426 RIP4(B,C,D,E,A,WR24,SR24,KR1);
427 RIP4(A,B,C,D,E,WR25,SR25,KR1);
428 RIP4(E,A,B,C,D,WR26,SR26,KR1);
429 RIP4(D,E,A,B,C,WR27,SR27,KR1);
430 RIP4(C,D,E,A,B,WR28,SR28,KR1);
431 RIP4(B,C,D,E,A,WR29,SR29,KR1);
432 RIP4(A,B,C,D,E,WR30,SR30,KR1);
433 RIP4(E,A,B,C,D,WR31,SR31,KR1);
434
435 RIP3(D,E,A,B,C,WR32,SR32,KR2);
436 RIP3(C,D,E,A,B,WR33,SR33,KR2);
437 RIP3(B,C,D,E,A,WR34,SR34,KR2);
438 RIP3(A,B,C,D,E,WR35,SR35,KR2);
439 RIP3(E,A,B,C,D,WR36,SR36,KR2);
440 RIP3(D,E,A,B,C,WR37,SR37,KR2);
441 RIP3(C,D,E,A,B,WR38,SR38,KR2);
442 RIP3(B,C,D,E,A,WR39,SR39,KR2);
443 RIP3(A,B,C,D,E,WR40,SR40,KR2);
444 RIP3(E,A,B,C,D,WR41,SR41,KR2);
445 RIP3(D,E,A,B,C,WR42,SR42,KR2);
446 RIP3(C,D,E,A,B,WR43,SR43,KR2);
447 RIP3(B,C,D,E,A,WR44,SR44,KR2);
448 RIP3(A,B,C,D,E,WR45,SR45,KR2);
449 RIP3(E,A,B,C,D,WR46,SR46,KR2);
450 RIP3(D,E,A,B,C,WR47,SR47,KR2);
451
452 RIP2(C,D,E,A,B,WR48,SR48,KR3);
453 RIP2(B,C,D,E,A,WR49,SR49,KR3);
454 RIP2(A,B,C,D,E,WR50,SR50,KR3);
455 RIP2(E,A,B,C,D,WR51,SR51,KR3);
456 RIP2(D,E,A,B,C,WR52,SR52,KR3);
457 RIP2(C,D,E,A,B,WR53,SR53,KR3);
458 RIP2(B,C,D,E,A,WR54,SR54,KR3);
459 RIP2(A,B,C,D,E,WR55,SR55,KR3);
460 RIP2(E,A,B,C,D,WR56,SR56,KR3);
461 RIP2(D,E,A,B,C,WR57,SR57,KR3);
462 RIP2(C,D,E,A,B,WR58,SR58,KR3);
463 RIP2(B,C,D,E,A,WR59,SR59,KR3);
464 RIP2(A,B,C,D,E,WR60,SR60,KR3);
465 RIP2(E,A,B,C,D,WR61,SR61,KR3);
466 RIP2(D,E,A,B,C,WR62,SR62,KR3);
467 RIP2(C,D,E,A,B,WR63,SR63,KR3);
468
469 RIP1(B,C,D,E,A,WR64,SR64);
470 RIP1(A,B,C,D,E,WR65,SR65);
471 RIP1(E,A,B,C,D,WR66,SR66);
472 RIP1(D,E,A,B,C,WR67,SR67);
473 RIP1(C,D,E,A,B,WR68,SR68);
474 RIP1(B,C,D,E,A,WR69,SR69);
475 RIP1(A,B,C,D,E,WR70,SR70);
476 RIP1(E,A,B,C,D,WR71,SR71);
477 RIP1(D,E,A,B,C,WR72,SR72);
478 RIP1(C,D,E,A,B,WR73,SR73);
479 RIP1(B,C,D,E,A,WR74,SR74);
480 RIP1(A,B,C,D,E,WR75,SR75);
481 RIP1(E,A,B,C,D,WR76,SR76);
482 RIP1(D,E,A,B,C,WR77,SR77);
483 RIP1(C,D,E,A,B,WR78,SR78);
484 RIP1(B,C,D,E,A,WR79,SR79);
485
486 D =ctx->B+c+D;
487 ctx->B=ctx->C+d+E;
488 ctx->C=ctx->D+e+A;
489 ctx->D=ctx->E+a+B;
490 ctx->E=ctx->A+b+C;
491 ctx->A=D;
492
493 }
494 }
495#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
new file mode 100644
index 0000000000..7b835dfbd4
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmd_locl.h
@@ -0,0 +1,160 @@
1/* crypto/ripemd/rmd_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61#include <openssl/opensslconf.h>
62#include <openssl/ripemd.h>
63
64#ifndef RIPEMD160_LONG_LOG2
65#define RIPEMD160_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68/*
69 * DO EXAMINE COMMENTS IN crypto/md5/md5_locl.h & crypto/md5/md5_dgst.c
70 * FOR EXPLANATIONS ON FOLLOWING "CODE."
71 * <appro@fy.chalmers.se>
72 */
73#ifdef RMD160_ASM
74# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
75# define ripemd160_block_host_order ripemd160_block_asm_host_order
76# endif
77#endif
78
79void ripemd160_block_host_order (RIPEMD160_CTX *c, const void *p,int num);
80void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,int num);
81
82#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
83#define ripemd160_block_data_order ripemd160_block_host_order
84#endif
85
86#define DATA_ORDER_IS_LITTLE_ENDIAN
87
88#define HASH_LONG RIPEMD160_LONG
89#define HASH_LONG_LOG2 RIPEMD160_LONG_LOG2
90#define HASH_CTX RIPEMD160_CTX
91#define HASH_CBLOCK RIPEMD160_CBLOCK
92#define HASH_LBLOCK RIPEMD160_LBLOCK
93#define HASH_UPDATE RIPEMD160_Update
94#define HASH_TRANSFORM RIPEMD160_Transform
95#define HASH_FINAL RIPEMD160_Final
96#define HASH_BLOCK_HOST_ORDER ripemd160_block_host_order
97#define HASH_MAKE_STRING(c,s) do { \
98 unsigned long ll; \
99 ll=(c)->A; HOST_l2c(ll,(s)); \
100 ll=(c)->B; HOST_l2c(ll,(s)); \
101 ll=(c)->C; HOST_l2c(ll,(s)); \
102 ll=(c)->D; HOST_l2c(ll,(s)); \
103 ll=(c)->E; HOST_l2c(ll,(s)); \
104 } while (0)
105#if !defined(L_ENDIAN) || defined(ripemd160_block_data_order)
106#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
107#endif
108
109#include "md32_common.h"
110
111#if 0
112#define F1(x,y,z) ((x)^(y)^(z))
113#define F2(x,y,z) (((x)&(y))|((~x)&z))
114#define F3(x,y,z) (((x)|(~y))^(z))
115#define F4(x,y,z) (((x)&(z))|((y)&(~(z))))
116#define F5(x,y,z) ((x)^((y)|(~(z))))
117#else
118/*
119 * Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com>
120 */
121#define F1(x,y,z) ((x) ^ (y) ^ (z))
122#define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
123#define F3(x,y,z) (((~(y)) | (x)) ^ (z))
124#define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
125#define F5(x,y,z) (((~(z)) | (y)) ^ (x))
126#endif
127
128#define RIPEMD160_A 0x67452301L
129#define RIPEMD160_B 0xEFCDAB89L
130#define RIPEMD160_C 0x98BADCFEL
131#define RIPEMD160_D 0x10325476L
132#define RIPEMD160_E 0xC3D2E1F0L
133
134#include "rmdconst.h"
135
136#define RIP1(a,b,c,d,e,w,s) { \
137 a+=F1(b,c,d)+X(w); \
138 a=ROTATE(a,s)+e; \
139 c=ROTATE(c,10); }
140
141#define RIP2(a,b,c,d,e,w,s,K) { \
142 a+=F2(b,c,d)+X(w)+K; \
143 a=ROTATE(a,s)+e; \
144 c=ROTATE(c,10); }
145
146#define RIP3(a,b,c,d,e,w,s,K) { \
147 a+=F3(b,c,d)+X(w)+K; \
148 a=ROTATE(a,s)+e; \
149 c=ROTATE(c,10); }
150
151#define RIP4(a,b,c,d,e,w,s,K) { \
152 a+=F4(b,c,d)+X(w)+K; \
153 a=ROTATE(a,s)+e; \
154 c=ROTATE(c,10); }
155
156#define RIP5(a,b,c,d,e,w,s,K) { \
157 a+=F5(b,c,d)+X(w)+K; \
158 a=ROTATE(a,s)+e; \
159 c=ROTATE(c,10); }
160
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
new file mode 100644
index 0000000000..f8b580c33a
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmd_one.c
@@ -0,0 +1,77 @@
1/* crypto/ripemd/rmd_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/ripemd.h>
62#include <openssl/crypto.h>
63
64unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
65 unsigned char *md)
66 {
67 RIPEMD160_CTX c;
68 static unsigned char m[RIPEMD160_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 RIPEMD160_Init(&c);
72 RIPEMD160_Update(&c,d,n);
73 RIPEMD160_Final(md,&c);
74 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
75 return(md);
76 }
77
diff --git a/src/lib/libcrypto/ripemd/rmdconst.h b/src/lib/libcrypto/ripemd/rmdconst.h
new file mode 100644
index 0000000000..59c48dead1
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmdconst.h
@@ -0,0 +1,399 @@
1/* crypto/ripemd/rmdconst.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#define KL0 0x00000000L
59#define KL1 0x5A827999L
60#define KL2 0x6ED9EBA1L
61#define KL3 0x8F1BBCDCL
62#define KL4 0xA953FD4EL
63
64#define KR0 0x50A28BE6L
65#define KR1 0x5C4DD124L
66#define KR2 0x6D703EF3L
67#define KR3 0x7A6D76E9L
68#define KR4 0x00000000L
69
70#define WL00 0
71#define SL00 11
72#define WL01 1
73#define SL01 14
74#define WL02 2
75#define SL02 15
76#define WL03 3
77#define SL03 12
78#define WL04 4
79#define SL04 5
80#define WL05 5
81#define SL05 8
82#define WL06 6
83#define SL06 7
84#define WL07 7
85#define SL07 9
86#define WL08 8
87#define SL08 11
88#define WL09 9
89#define SL09 13
90#define WL10 10
91#define SL10 14
92#define WL11 11
93#define SL11 15
94#define WL12 12
95#define SL12 6
96#define WL13 13
97#define SL13 7
98#define WL14 14
99#define SL14 9
100#define WL15 15
101#define SL15 8
102
103#define WL16 7
104#define SL16 7
105#define WL17 4
106#define SL17 6
107#define WL18 13
108#define SL18 8
109#define WL19 1
110#define SL19 13
111#define WL20 10
112#define SL20 11
113#define WL21 6
114#define SL21 9
115#define WL22 15
116#define SL22 7
117#define WL23 3
118#define SL23 15
119#define WL24 12
120#define SL24 7
121#define WL25 0
122#define SL25 12
123#define WL26 9
124#define SL26 15
125#define WL27 5
126#define SL27 9
127#define WL28 2
128#define SL28 11
129#define WL29 14
130#define SL29 7
131#define WL30 11
132#define SL30 13
133#define WL31 8
134#define SL31 12
135
136#define WL32 3
137#define SL32 11
138#define WL33 10
139#define SL33 13
140#define WL34 14
141#define SL34 6
142#define WL35 4
143#define SL35 7
144#define WL36 9
145#define SL36 14
146#define WL37 15
147#define SL37 9
148#define WL38 8
149#define SL38 13
150#define WL39 1
151#define SL39 15
152#define WL40 2
153#define SL40 14
154#define WL41 7
155#define SL41 8
156#define WL42 0
157#define SL42 13
158#define WL43 6
159#define SL43 6
160#define WL44 13
161#define SL44 5
162#define WL45 11
163#define SL45 12
164#define WL46 5
165#define SL46 7
166#define WL47 12
167#define SL47 5
168
169#define WL48 1
170#define SL48 11
171#define WL49 9
172#define SL49 12
173#define WL50 11
174#define SL50 14
175#define WL51 10
176#define SL51 15
177#define WL52 0
178#define SL52 14
179#define WL53 8
180#define SL53 15
181#define WL54 12
182#define SL54 9
183#define WL55 4
184#define SL55 8
185#define WL56 13
186#define SL56 9
187#define WL57 3
188#define SL57 14
189#define WL58 7
190#define SL58 5
191#define WL59 15
192#define SL59 6
193#define WL60 14
194#define SL60 8
195#define WL61 5
196#define SL61 6
197#define WL62 6
198#define SL62 5
199#define WL63 2
200#define SL63 12
201
202#define WL64 4
203#define SL64 9
204#define WL65 0
205#define SL65 15
206#define WL66 5
207#define SL66 5
208#define WL67 9
209#define SL67 11
210#define WL68 7
211#define SL68 6
212#define WL69 12
213#define SL69 8
214#define WL70 2
215#define SL70 13
216#define WL71 10
217#define SL71 12
218#define WL72 14
219#define SL72 5
220#define WL73 1
221#define SL73 12
222#define WL74 3
223#define SL74 13
224#define WL75 8
225#define SL75 14
226#define WL76 11
227#define SL76 11
228#define WL77 6
229#define SL77 8
230#define WL78 15
231#define SL78 5
232#define WL79 13
233#define SL79 6
234
235#define WR00 5
236#define SR00 8
237#define WR01 14
238#define SR01 9
239#define WR02 7
240#define SR02 9
241#define WR03 0
242#define SR03 11
243#define WR04 9
244#define SR04 13
245#define WR05 2
246#define SR05 15
247#define WR06 11
248#define SR06 15
249#define WR07 4
250#define SR07 5
251#define WR08 13
252#define SR08 7
253#define WR09 6
254#define SR09 7
255#define WR10 15
256#define SR10 8
257#define WR11 8
258#define SR11 11
259#define WR12 1
260#define SR12 14
261#define WR13 10
262#define SR13 14
263#define WR14 3
264#define SR14 12
265#define WR15 12
266#define SR15 6
267
268#define WR16 6
269#define SR16 9
270#define WR17 11
271#define SR17 13
272#define WR18 3
273#define SR18 15
274#define WR19 7
275#define SR19 7
276#define WR20 0
277#define SR20 12
278#define WR21 13
279#define SR21 8
280#define WR22 5
281#define SR22 9
282#define WR23 10
283#define SR23 11
284#define WR24 14
285#define SR24 7
286#define WR25 15
287#define SR25 7
288#define WR26 8
289#define SR26 12
290#define WR27 12
291#define SR27 7
292#define WR28 4
293#define SR28 6
294#define WR29 9
295#define SR29 15
296#define WR30 1
297#define SR30 13
298#define WR31 2
299#define SR31 11
300
301#define WR32 15
302#define SR32 9
303#define WR33 5
304#define SR33 7
305#define WR34 1
306#define SR34 15
307#define WR35 3
308#define SR35 11
309#define WR36 7
310#define SR36 8
311#define WR37 14
312#define SR37 6
313#define WR38 6
314#define SR38 6
315#define WR39 9
316#define SR39 14
317#define WR40 11
318#define SR40 12
319#define WR41 8
320#define SR41 13
321#define WR42 12
322#define SR42 5
323#define WR43 2
324#define SR43 14
325#define WR44 10
326#define SR44 13
327#define WR45 0
328#define SR45 13
329#define WR46 4
330#define SR46 7
331#define WR47 13
332#define SR47 5
333
334#define WR48 8
335#define SR48 15
336#define WR49 6
337#define SR49 5
338#define WR50 4
339#define SR50 8
340#define WR51 1
341#define SR51 11
342#define WR52 3
343#define SR52 14
344#define WR53 11
345#define SR53 14
346#define WR54 15
347#define SR54 6
348#define WR55 0
349#define SR55 14
350#define WR56 5
351#define SR56 6
352#define WR57 12
353#define SR57 9
354#define WR58 2
355#define SR58 12
356#define WR59 13
357#define SR59 9
358#define WR60 9
359#define SR60 12
360#define WR61 7
361#define SR61 5
362#define WR62 10
363#define SR62 15
364#define WR63 14
365#define SR63 8
366
367#define WR64 12
368#define SR64 8
369#define WR65 15
370#define SR65 5
371#define WR66 10
372#define SR66 12
373#define WR67 4
374#define SR67 9
375#define WR68 1
376#define SR68 12
377#define WR69 5
378#define SR69 5
379#define WR70 8
380#define SR70 14
381#define WR71 7
382#define SR71 6
383#define WR72 6
384#define SR72 8
385#define WR73 2
386#define SR73 13
387#define WR74 13
388#define SR74 6
389#define WR75 14
390#define SR75 5
391#define WR76 0
392#define SR76 15
393#define WR77 3
394#define SR77 13
395#define WR78 9
396#define SR78 11
397#define WR79 11
398#define SR79 11
399
diff --git a/src/lib/libcrypto/rsa/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
new file mode 100644
index 0000000000..fc3bb5f86d
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -0,0 +1,366 @@
1/* crypto/rsa/rsa.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RSA_H
60#define HEADER_RSA_H
61
62#include <openssl/asn1.h>
63
64#ifndef OPENSSL_NO_BIO
65#include <openssl/bio.h>
66#endif
67#include <openssl/bn.h>
68#include <openssl/crypto.h>
69#include <openssl/ossl_typ.h>
70
71#ifdef OPENSSL_NO_RSA
72#error RSA is disabled.
73#endif
74
75#if defined(OPENSSL_FIPS)
76#define FIPS_RSA_SIZE_T int
77#endif
78
79#ifdef __cplusplus
80extern "C" {
81#endif
82
83typedef struct rsa_st RSA;
84
85typedef struct rsa_meth_st
86 {
87 const char *name;
88 int (*rsa_pub_enc)(int flen,const unsigned char *from,
89 unsigned char *to,
90 RSA *rsa,int padding);
91 int (*rsa_pub_dec)(int flen,const unsigned char *from,
92 unsigned char *to,
93 RSA *rsa,int padding);
94 int (*rsa_priv_enc)(int flen,const unsigned char *from,
95 unsigned char *to,
96 RSA *rsa,int padding);
97 int (*rsa_priv_dec)(int flen,const unsigned char *from,
98 unsigned char *to,
99 RSA *rsa,int padding);
100 int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa); /* Can be null */
101 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
102 const BIGNUM *m, BN_CTX *ctx,
103 BN_MONT_CTX *m_ctx); /* Can be null */
104 int (*init)(RSA *rsa); /* called at new */
105 int (*finish)(RSA *rsa); /* called at free */
106 int flags; /* RSA_METHOD_FLAG_* things */
107 char *app_data; /* may be needed! */
108/* New sign and verify functions: some libraries don't allow arbitrary data
109 * to be signed/verified: this allows them to be used. Note: for this to work
110 * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
111 * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
112 * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
113 * option is set in 'flags'.
114 */
115 int (*rsa_sign)(int type,
116 const unsigned char *m, unsigned int m_length,
117 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
118 int (*rsa_verify)(int dtype,
119 const unsigned char *m, unsigned int m_length,
120 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
121
122 } RSA_METHOD;
123
124struct rsa_st
125 {
126 /* The first parameter is used to pickup errors where
127 * this is passed instead of aEVP_PKEY, it is set to 0 */
128 int pad;
129 long version;
130 const RSA_METHOD *meth;
131 /* functional reference if 'meth' is ENGINE-provided */
132 ENGINE *engine;
133 BIGNUM *n;
134 BIGNUM *e;
135 BIGNUM *d;
136 BIGNUM *p;
137 BIGNUM *q;
138 BIGNUM *dmp1;
139 BIGNUM *dmq1;
140 BIGNUM *iqmp;
141 /* be careful using this if the RSA structure is shared */
142 CRYPTO_EX_DATA ex_data;
143 int references;
144 int flags;
145
146 /* Used to cache montgomery values */
147 BN_MONT_CTX *_method_mod_n;
148 BN_MONT_CTX *_method_mod_p;
149 BN_MONT_CTX *_method_mod_q;
150
151 /* all BIGNUM values are actually in the following data, if it is not
152 * NULL */
153 char *bignum_data;
154 BN_BLINDING *blinding;
155 };
156
157#define RSA_3 0x3L
158#define RSA_F4 0x10001L
159
160#define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */
161
162#define RSA_FLAG_CACHE_PUBLIC 0x02
163#define RSA_FLAG_CACHE_PRIVATE 0x04
164#define RSA_FLAG_BLINDING 0x08
165#define RSA_FLAG_THREAD_SAFE 0x10
166/* This flag means the private key operations will be handled by rsa_mod_exp
167 * and that they do not depend on the private key components being present:
168 * for example a key stored in external hardware. Without this flag bn_mod_exp
169 * gets called when private key components are absent.
170 */
171#define RSA_FLAG_EXT_PKEY 0x20
172
173/* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions.
174 */
175#define RSA_FLAG_SIGN_VER 0x40
176
177#define RSA_FLAG_NO_BLINDING 0x80 /* new with 0.9.6j and 0.9.7b; the built-in
178 * RSA implementation now uses blinding by
179 * default (ignoring RSA_FLAG_BLINDING),
180 * but other engines might not need it
181 */
182
183#define RSA_PKCS1_PADDING 1
184#define RSA_SSLV23_PADDING 2
185#define RSA_NO_PADDING 3
186#define RSA_PKCS1_OAEP_PADDING 4
187
188#define RSA_PKCS1_PADDING_SIZE 11
189
190#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
191#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
192
193RSA * RSA_new(void);
194RSA * RSA_new_method(ENGINE *engine);
195int RSA_size(const RSA *);
196RSA * RSA_generate_key(int bits, unsigned long e,void
197 (*callback)(int,int,void *),void *cb_arg);
198int RSA_check_key(const RSA *);
199 /* next 4 return -1 on error */
200int RSA_public_encrypt(int flen, const unsigned char *from,
201 unsigned char *to, RSA *rsa,int padding);
202int RSA_private_encrypt(int flen, const unsigned char *from,
203 unsigned char *to, RSA *rsa,int padding);
204int RSA_public_decrypt(int flen, const unsigned char *from,
205 unsigned char *to, RSA *rsa,int padding);
206int RSA_private_decrypt(int flen, const unsigned char *from,
207 unsigned char *to, RSA *rsa,int padding);
208void RSA_free (RSA *r);
209/* "up" the RSA object's reference count */
210int RSA_up_ref(RSA *r);
211
212int RSA_flags(const RSA *r);
213
214void RSA_set_default_method(const RSA_METHOD *meth);
215const RSA_METHOD *RSA_get_default_method(void);
216const RSA_METHOD *RSA_get_method(const RSA *rsa);
217int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
218
219/* This function needs the memory locking malloc callbacks to be installed */
220int RSA_memory_lock(RSA *r);
221
222/* these are the actual SSLeay RSA functions */
223const RSA_METHOD *RSA_PKCS1_SSLeay(void);
224
225const RSA_METHOD *RSA_null_method(void);
226
227DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
228DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
229
230#ifndef OPENSSL_NO_FP_API
231int RSA_print_fp(FILE *fp, const RSA *r,int offset);
232#endif
233
234#ifndef OPENSSL_NO_BIO
235int RSA_print(BIO *bp, const RSA *r,int offset);
236#endif
237
238int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey);
239RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey);
240
241int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)());
242RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)());
243
244/* The following 2 functions sign and verify a X509_SIG ASN1 object
245 * inside PKCS#1 padded RSA encryption */
246int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
247 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
248int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
249 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
250
251/* The following 2 function sign and verify a ASN1_OCTET_STRING
252 * object inside PKCS#1 padded RSA encryption */
253int RSA_sign_ASN1_OCTET_STRING(int type,
254 const unsigned char *m, unsigned int m_length,
255 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
256int RSA_verify_ASN1_OCTET_STRING(int type,
257 const unsigned char *m, unsigned int m_length,
258 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
259
260int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
261void RSA_blinding_off(RSA *rsa);
262
263int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
264 const unsigned char *f,int fl);
265int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
266 const unsigned char *f,int fl,int rsa_len);
267int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
268 const unsigned char *f,int fl);
269int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
270 const unsigned char *f,int fl,int rsa_len);
271int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,
272 const unsigned char *f,int fl,
273 const unsigned char *p,int pl);
274int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,
275 const unsigned char *f,int fl,int rsa_len,
276 const unsigned char *p,int pl);
277int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
278 const unsigned char *f,int fl);
279int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
280 const unsigned char *f,int fl,int rsa_len);
281int RSA_padding_add_none(unsigned char *to,int tlen,
282 const unsigned char *f,int fl);
283int RSA_padding_check_none(unsigned char *to,int tlen,
284 const unsigned char *f,int fl,int rsa_len);
285
286int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
287 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
288int RSA_set_ex_data(RSA *r,int idx,void *arg);
289void *RSA_get_ex_data(const RSA *r, int idx);
290
291RSA *RSAPublicKey_dup(RSA *rsa);
292RSA *RSAPrivateKey_dup(RSA *rsa);
293
294/* BEGIN ERROR CODES */
295/* The following lines are auto generated by the script mkerr.pl. Any changes
296 * made after this point may be overwritten when the script is next run.
297 */
298void ERR_load_RSA_strings(void);
299
300/* Error codes for the RSA functions. */
301
302/* Function codes. */
303#define RSA_F_MEMORY_LOCK 100
304#define RSA_F_RSA_CHECK_KEY 123
305#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
306#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
307#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
308#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
309#define RSA_F_RSA_GENERATE_KEY 105
310#define RSA_F_RSA_NEW_METHOD 106
311#define RSA_F_RSA_NULL 124
312#define RSA_F_RSA_PADDING_ADD_NONE 107
313#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
314#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
315#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
316#define RSA_F_RSA_PADDING_ADD_SSLV23 110
317#define RSA_F_RSA_PADDING_CHECK_NONE 111
318#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
319#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
320#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
321#define RSA_F_RSA_PADDING_CHECK_SSLV23 114
322#define RSA_F_RSA_PRINT 115
323#define RSA_F_RSA_PRINT_FP 116
324#define RSA_F_RSA_SIGN 117
325#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
326#define RSA_F_RSA_VERIFY 119
327#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
328
329/* Reason codes. */
330#define RSA_R_ALGORITHM_MISMATCH 100
331#define RSA_R_BAD_E_VALUE 101
332#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
333#define RSA_R_BAD_PAD_BYTE_COUNT 103
334#define RSA_R_BAD_SIGNATURE 104
335#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
336#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
337#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
338#define RSA_R_DATA_TOO_LARGE 109
339#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
340#define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132
341#define RSA_R_DATA_TOO_SMALL 111
342#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
343#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
344#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
345#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
346#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
347#define RSA_R_INVALID_MESSAGE_LENGTH 131
348#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
349#define RSA_R_KEY_SIZE_TOO_SMALL 120
350#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
351#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
352#define RSA_R_OAEP_DECODING_ERROR 121
353#define RSA_R_PADDING_CHECK_FAILED 114
354#define RSA_R_P_NOT_PRIME 128
355#define RSA_R_Q_NOT_PRIME 129
356#define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
357#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
358#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
359#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
360#define RSA_R_UNKNOWN_PADDING_TYPE 118
361#define RSA_R_WRONG_SIGNATURE_LENGTH 119
362
363#ifdef __cplusplus
364}
365#endif
366#endif
diff --git a/src/lib/libcrypto/rsa/rsa_asn1.c b/src/lib/libcrypto/rsa/rsa_asn1.c
new file mode 100644
index 0000000000..1455a7e0e4
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_asn1.c
@@ -0,0 +1,121 @@
1/* rsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/asn1t.h>
64
65static ASN1_METHOD method={
66 (int (*)()) i2d_RSAPrivateKey,
67 (char *(*)())d2i_RSAPrivateKey,
68 (char *(*)())RSA_new,
69 (void (*)()) RSA_free};
70
71ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
72 {
73 return(&method);
74 }
75
76/* Override the default free and new methods */
77static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
78{
79 if(operation == ASN1_OP_NEW_PRE) {
80 *pval = (ASN1_VALUE *)RSA_new();
81 if(*pval) return 2;
82 return 0;
83 } else if(operation == ASN1_OP_FREE_PRE) {
84 RSA_free((RSA *)*pval);
85 *pval = NULL;
86 return 2;
87 }
88 return 1;
89}
90
91ASN1_SEQUENCE_cb(RSAPrivateKey, rsa_cb) = {
92 ASN1_SIMPLE(RSA, version, LONG),
93 ASN1_SIMPLE(RSA, n, BIGNUM),
94 ASN1_SIMPLE(RSA, e, BIGNUM),
95 ASN1_SIMPLE(RSA, d, BIGNUM),
96 ASN1_SIMPLE(RSA, p, BIGNUM),
97 ASN1_SIMPLE(RSA, q, BIGNUM),
98 ASN1_SIMPLE(RSA, dmp1, BIGNUM),
99 ASN1_SIMPLE(RSA, dmq1, BIGNUM),
100 ASN1_SIMPLE(RSA, iqmp, BIGNUM)
101} ASN1_SEQUENCE_END_cb(RSA, RSAPrivateKey)
102
103
104ASN1_SEQUENCE_cb(RSAPublicKey, rsa_cb) = {
105 ASN1_SIMPLE(RSA, n, BIGNUM),
106 ASN1_SIMPLE(RSA, e, BIGNUM),
107} ASN1_SEQUENCE_END_cb(RSA, RSAPublicKey)
108
109IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPrivateKey, RSAPrivateKey)
110
111IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPublicKey, RSAPublicKey)
112
113RSA *RSAPublicKey_dup(RSA *rsa)
114 {
115 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPublicKey), rsa);
116 }
117
118RSA *RSAPrivateKey_dup(RSA *rsa)
119 {
120 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPrivateKey), rsa);
121 }
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c
new file mode 100644
index 0000000000..002f2cb487
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_chk.c
@@ -0,0 +1,184 @@
1/* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 */
50
51#include <openssl/bn.h>
52#include <openssl/err.h>
53#include <openssl/rsa.h>
54
55
56int RSA_check_key(const RSA *key)
57 {
58 BIGNUM *i, *j, *k, *l, *m;
59 BN_CTX *ctx;
60 int r;
61 int ret=1;
62
63 i = BN_new();
64 j = BN_new();
65 k = BN_new();
66 l = BN_new();
67 m = BN_new();
68 ctx = BN_CTX_new();
69 if (i == NULL || j == NULL || k == NULL || l == NULL ||
70 m == NULL || ctx == NULL)
71 {
72 ret = -1;
73 RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE);
74 goto err;
75 }
76
77 /* p prime? */
78 r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL);
79 if (r != 1)
80 {
81 ret = r;
82 if (r != 0)
83 goto err;
84 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME);
85 }
86
87 /* q prime? */
88 r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL);
89 if (r != 1)
90 {
91 ret = r;
92 if (r != 0)
93 goto err;
94 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME);
95 }
96
97 /* n = p*q? */
98 r = BN_mul(i, key->p, key->q, ctx);
99 if (!r) { ret = -1; goto err; }
100
101 if (BN_cmp(i, key->n) != 0)
102 {
103 ret = 0;
104 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q);
105 }
106
107 /* d*e = 1 mod lcm(p-1,q-1)? */
108
109 r = BN_sub(i, key->p, BN_value_one());
110 if (!r) { ret = -1; goto err; }
111 r = BN_sub(j, key->q, BN_value_one());
112 if (!r) { ret = -1; goto err; }
113
114 /* now compute k = lcm(i,j) */
115 r = BN_mul(l, i, j, ctx);
116 if (!r) { ret = -1; goto err; }
117 r = BN_gcd(m, i, j, ctx);
118 if (!r) { ret = -1; goto err; }
119 r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */
120 if (!r) { ret = -1; goto err; }
121
122 r = BN_mod_mul(i, key->d, key->e, k, ctx);
123 if (!r) { ret = -1; goto err; }
124
125 if (!BN_is_one(i))
126 {
127 ret = 0;
128 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1);
129 }
130
131 if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL)
132 {
133 /* dmp1 = d mod (p-1)? */
134 r = BN_sub(i, key->p, BN_value_one());
135 if (!r) { ret = -1; goto err; }
136
137 r = BN_mod(j, key->d, i, ctx);
138 if (!r) { ret = -1; goto err; }
139
140 if (BN_cmp(j, key->dmp1) != 0)
141 {
142 ret = 0;
143 RSAerr(RSA_F_RSA_CHECK_KEY,
144 RSA_R_DMP1_NOT_CONGRUENT_TO_D);
145 }
146
147 /* dmq1 = d mod (q-1)? */
148 r = BN_sub(i, key->q, BN_value_one());
149 if (!r) { ret = -1; goto err; }
150
151 r = BN_mod(j, key->d, i, ctx);
152 if (!r) { ret = -1; goto err; }
153
154 if (BN_cmp(j, key->dmq1) != 0)
155 {
156 ret = 0;
157 RSAerr(RSA_F_RSA_CHECK_KEY,
158 RSA_R_DMQ1_NOT_CONGRUENT_TO_D);
159 }
160
161 /* iqmp = q^-1 mod p? */
162 if(!BN_mod_inverse(i, key->q, key->p, ctx))
163 {
164 ret = -1;
165 goto err;
166 }
167
168 if (BN_cmp(i, key->iqmp) != 0)
169 {
170 ret = 0;
171 RSAerr(RSA_F_RSA_CHECK_KEY,
172 RSA_R_IQMP_NOT_INVERSE_OF_Q);
173 }
174 }
175
176 err:
177 if (i != NULL) BN_free(i);
178 if (j != NULL) BN_free(j);
179 if (k != NULL) BN_free(k);
180 if (l != NULL) BN_free(l);
181 if (m != NULL) BN_free(m);
182 if (ctx != NULL) BN_CTX_free(ctx);
183 return (ret);
184 }
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
new file mode 100644
index 0000000000..d4caab3f95
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -0,0 +1,727 @@
1/* crypto/rsa/rsa_eay.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65#if !defined(RSA_NULL) && !defined(OPENSSL_FIPS)
66
67static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
68 unsigned char *to, RSA *rsa,int padding);
69static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
70 unsigned char *to, RSA *rsa,int padding);
71static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
72 unsigned char *to, RSA *rsa,int padding);
73static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
74 unsigned char *to, RSA *rsa,int padding);
75static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa);
76static int RSA_eay_init(RSA *rsa);
77static int RSA_eay_finish(RSA *rsa);
78static RSA_METHOD rsa_pkcs1_eay_meth={
79 "Eric Young's PKCS#1 RSA",
80 RSA_eay_public_encrypt,
81 RSA_eay_public_decrypt, /* signature verification */
82 RSA_eay_private_encrypt, /* signing */
83 RSA_eay_private_decrypt,
84 RSA_eay_mod_exp,
85 BN_mod_exp_mont, /* XXX probably we should not use Montgomery if e == 3 */
86 RSA_eay_init,
87 RSA_eay_finish,
88 0, /* flags */
89 NULL,
90 0, /* rsa_sign */
91 0 /* rsa_verify */
92 };
93
94const RSA_METHOD *RSA_PKCS1_SSLeay(void)
95 {
96 return(&rsa_pkcs1_eay_meth);
97 }
98
99static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
100 unsigned char *to, RSA *rsa, int padding)
101 {
102 BIGNUM f,ret;
103 int i,j,k,num=0,r= -1;
104 unsigned char *buf=NULL;
105 BN_CTX *ctx=NULL;
106
107 BN_init(&f);
108 BN_init(&ret);
109 if ((ctx=BN_CTX_new()) == NULL) goto err;
110 num=BN_num_bytes(rsa->n);
111 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
112 {
113 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
114 goto err;
115 }
116
117 switch (padding)
118 {
119 case RSA_PKCS1_PADDING:
120 i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
121 break;
122#ifndef OPENSSL_NO_SHA
123 case RSA_PKCS1_OAEP_PADDING:
124 i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
125 break;
126#endif
127 case RSA_SSLV23_PADDING:
128 i=RSA_padding_add_SSLv23(buf,num,from,flen);
129 break;
130 case RSA_NO_PADDING:
131 i=RSA_padding_add_none(buf,num,from,flen);
132 break;
133 default:
134 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
135 goto err;
136 }
137 if (i <= 0) goto err;
138
139 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
140
141 if (BN_ucmp(&f, rsa->n) >= 0)
142 {
143 /* usually the padding functions would catch this */
144 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
145 goto err;
146 }
147
148 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
149 {
150 BN_MONT_CTX* bn_mont_ctx;
151 if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL)
152 goto err;
153 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx))
154 {
155 BN_MONT_CTX_free(bn_mont_ctx);
156 goto err;
157 }
158 if (rsa->_method_mod_n == NULL) /* other thread may have finished first */
159 {
160 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
161 if (rsa->_method_mod_n == NULL)
162 {
163 rsa->_method_mod_n = bn_mont_ctx;
164 bn_mont_ctx = NULL;
165 }
166 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
167 }
168 if (bn_mont_ctx)
169 BN_MONT_CTX_free(bn_mont_ctx);
170 }
171
172 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
173 rsa->_method_mod_n)) goto err;
174
175 /* put in leading 0 bytes if the number is less than the
176 * length of the modulus */
177 j=BN_num_bytes(&ret);
178 i=BN_bn2bin(&ret,&(to[num-j]));
179 for (k=0; k<(num-i); k++)
180 to[k]=0;
181
182 r=num;
183err:
184 if (ctx != NULL) BN_CTX_free(ctx);
185 BN_clear_free(&f);
186 BN_clear_free(&ret);
187 if (buf != NULL)
188 {
189 OPENSSL_cleanse(buf,num);
190 OPENSSL_free(buf);
191 }
192 return(r);
193 }
194
195static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
196 {
197 int ret = 1;
198 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
199 /* Check again inside the lock - the macro's check is racey */
200 if(rsa->blinding == NULL)
201 ret = RSA_blinding_on(rsa, ctx);
202 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
203 return ret;
204 }
205
206#define BLINDING_HELPER(rsa, ctx, err_instr) \
207 do { \
208 if((!((rsa)->flags & RSA_FLAG_NO_BLINDING)) && \
209 ((rsa)->blinding == NULL) && \
210 !rsa_eay_blinding(rsa, ctx)) \
211 err_instr \
212 } while(0)
213
214static BN_BLINDING *setup_blinding(RSA *rsa, BN_CTX *ctx)
215 {
216 BIGNUM *A, *Ai;
217 BN_BLINDING *ret = NULL;
218
219 /* added in OpenSSL 0.9.6j and 0.9.7b */
220
221 /* NB: similar code appears in RSA_blinding_on (rsa_lib.c);
222 * this should be placed in a new function of its own, but for reasons
223 * of binary compatibility can't */
224
225 BN_CTX_start(ctx);
226 A = BN_CTX_get(ctx);
227 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
228 {
229 /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */
230 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
231 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
232 }
233 else
234 {
235 if (!BN_rand_range(A,rsa->n)) goto err;
236 }
237 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
238
239 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
240 goto err;
241 ret = BN_BLINDING_new(A,Ai,rsa->n);
242 BN_free(Ai);
243err:
244 BN_CTX_end(ctx);
245 return ret;
246 }
247
248/* signing */
249static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
250 unsigned char *to, RSA *rsa, int padding)
251 {
252 BIGNUM f,ret;
253 int i,j,k,num=0,r= -1;
254 unsigned char *buf=NULL;
255 BN_CTX *ctx=NULL;
256 int local_blinding = 0;
257 BN_BLINDING *blinding = NULL;
258
259 BN_init(&f);
260 BN_init(&ret);
261
262 if ((ctx=BN_CTX_new()) == NULL) goto err;
263 num=BN_num_bytes(rsa->n);
264 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
265 {
266 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
267 goto err;
268 }
269
270 switch (padding)
271 {
272 case RSA_PKCS1_PADDING:
273 i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);
274 break;
275 case RSA_NO_PADDING:
276 i=RSA_padding_add_none(buf,num,from,flen);
277 break;
278 case RSA_SSLV23_PADDING:
279 default:
280 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
281 goto err;
282 }
283 if (i <= 0) goto err;
284
285 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
286
287 if (BN_ucmp(&f, rsa->n) >= 0)
288 {
289 /* usually the padding functions would catch this */
290 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
291 goto err;
292 }
293
294 BLINDING_HELPER(rsa, ctx, goto err;);
295 blinding = rsa->blinding;
296
297 /* Now unless blinding is disabled, 'blinding' is non-NULL.
298 * But the BN_BLINDING object may be owned by some other thread
299 * (we don't want to keep it constant and we don't want to use
300 * lots of locking to avoid race conditions, so only a single
301 * thread can use it; other threads have to use local blinding
302 * factors) */
303 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
304 {
305 if (blinding == NULL)
306 {
307 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);
308 goto err;
309 }
310 }
311
312 if (blinding != NULL)
313 {
314 if (blinding->thread_id != CRYPTO_thread_id())
315 {
316 /* we need a local one-time blinding factor */
317
318 blinding = setup_blinding(rsa, ctx);
319 if (blinding == NULL)
320 goto err;
321 local_blinding = 1;
322 }
323 }
324
325 if (blinding)
326 if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err;
327
328 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
329 ((rsa->p != NULL) &&
330 (rsa->q != NULL) &&
331 (rsa->dmp1 != NULL) &&
332 (rsa->dmq1 != NULL) &&
333 (rsa->iqmp != NULL)) )
334 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
335 else
336 {
337 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err;
338 }
339
340 if (blinding)
341 if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err;
342
343 /* put in leading 0 bytes if the number is less than the
344 * length of the modulus */
345 j=BN_num_bytes(&ret);
346 i=BN_bn2bin(&ret,&(to[num-j]));
347 for (k=0; k<(num-i); k++)
348 to[k]=0;
349
350 r=num;
351err:
352 if (ctx != NULL) BN_CTX_free(ctx);
353 BN_clear_free(&ret);
354 BN_clear_free(&f);
355 if (local_blinding)
356 BN_BLINDING_free(blinding);
357 if (buf != NULL)
358 {
359 OPENSSL_cleanse(buf,num);
360 OPENSSL_free(buf);
361 }
362 return(r);
363 }
364
365static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
366 unsigned char *to, RSA *rsa, int padding)
367 {
368 BIGNUM f,ret;
369 int j,num=0,r= -1;
370 unsigned char *p;
371 unsigned char *buf=NULL;
372 BN_CTX *ctx=NULL;
373 int local_blinding = 0;
374 BN_BLINDING *blinding = NULL;
375
376 BN_init(&f);
377 BN_init(&ret);
378 ctx=BN_CTX_new();
379 if (ctx == NULL) goto err;
380
381 num=BN_num_bytes(rsa->n);
382
383 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
384 {
385 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
386 goto err;
387 }
388
389 /* This check was for equality but PGP does evil things
390 * and chops off the top '0' bytes */
391 if (flen > num)
392 {
393 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
394 goto err;
395 }
396
397 /* make data into a big number */
398 if (BN_bin2bn(from,(int)flen,&f) == NULL) goto err;
399
400 if (BN_ucmp(&f, rsa->n) >= 0)
401 {
402 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
403 goto err;
404 }
405
406 BLINDING_HELPER(rsa, ctx, goto err;);
407 blinding = rsa->blinding;
408
409 /* Now unless blinding is disabled, 'blinding' is non-NULL.
410 * But the BN_BLINDING object may be owned by some other thread
411 * (we don't want to keep it constant and we don't want to use
412 * lots of locking to avoid race conditions, so only a single
413 * thread can use it; other threads have to use local blinding
414 * factors) */
415 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
416 {
417 if (blinding == NULL)
418 {
419 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);
420 goto err;
421 }
422 }
423
424 if (blinding != NULL)
425 {
426 if (blinding->thread_id != CRYPTO_thread_id())
427 {
428 /* we need a local one-time blinding factor */
429
430 blinding = setup_blinding(rsa, ctx);
431 if (blinding == NULL)
432 goto err;
433 local_blinding = 1;
434 }
435 }
436
437 if (blinding)
438 if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err;
439
440 /* do the decrypt */
441 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
442 ((rsa->p != NULL) &&
443 (rsa->q != NULL) &&
444 (rsa->dmp1 != NULL) &&
445 (rsa->dmq1 != NULL) &&
446 (rsa->iqmp != NULL)) )
447 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
448 else
449 {
450 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL))
451 goto err;
452 }
453
454 if (blinding)
455 if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err;
456
457 p=buf;
458 j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */
459
460 switch (padding)
461 {
462 case RSA_PKCS1_PADDING:
463 r=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);
464 break;
465#ifndef OPENSSL_NO_SHA
466 case RSA_PKCS1_OAEP_PADDING:
467 r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);
468 break;
469#endif
470 case RSA_SSLV23_PADDING:
471 r=RSA_padding_check_SSLv23(to,num,buf,j,num);
472 break;
473 case RSA_NO_PADDING:
474 r=RSA_padding_check_none(to,num,buf,j,num);
475 break;
476 default:
477 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
478 goto err;
479 }
480 if (r < 0)
481 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
482
483err:
484 if (ctx != NULL) BN_CTX_free(ctx);
485 BN_clear_free(&f);
486 BN_clear_free(&ret);
487 if (local_blinding)
488 BN_BLINDING_free(blinding);
489 if (buf != NULL)
490 {
491 OPENSSL_cleanse(buf,num);
492 OPENSSL_free(buf);
493 }
494 return(r);
495 }
496
497/* signature verification */
498static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
499 unsigned char *to, RSA *rsa, int padding)
500 {
501 BIGNUM f,ret;
502 int i,num=0,r= -1;
503 unsigned char *p;
504 unsigned char *buf=NULL;
505 BN_CTX *ctx=NULL;
506
507 BN_init(&f);
508 BN_init(&ret);
509 ctx=BN_CTX_new();
510 if (ctx == NULL) goto err;
511
512 num=BN_num_bytes(rsa->n);
513 buf=(unsigned char *)OPENSSL_malloc(num);
514 if (buf == NULL)
515 {
516 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
517 goto err;
518 }
519
520 /* This check was for equality but PGP does evil things
521 * and chops off the top '0' bytes */
522 if (flen > num)
523 {
524 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
525 goto err;
526 }
527
528 if (BN_bin2bn(from,flen,&f) == NULL) goto err;
529
530 if (BN_ucmp(&f, rsa->n) >= 0)
531 {
532 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
533 goto err;
534 }
535
536 /* do the decrypt */
537 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
538 {
539 BN_MONT_CTX* bn_mont_ctx;
540 if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL)
541 goto err;
542 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx))
543 {
544 BN_MONT_CTX_free(bn_mont_ctx);
545 goto err;
546 }
547 if (rsa->_method_mod_n == NULL) /* other thread may have finished first */
548 {
549 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
550 if (rsa->_method_mod_n == NULL)
551 {
552 rsa->_method_mod_n = bn_mont_ctx;
553 bn_mont_ctx = NULL;
554 }
555 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
556 }
557 if (bn_mont_ctx)
558 BN_MONT_CTX_free(bn_mont_ctx);
559 }
560
561 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
562 rsa->_method_mod_n)) goto err;
563
564 p=buf;
565 i=BN_bn2bin(&ret,p);
566
567 switch (padding)
568 {
569 case RSA_PKCS1_PADDING:
570 r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
571 break;
572 case RSA_NO_PADDING:
573 r=RSA_padding_check_none(to,num,buf,i,num);
574 break;
575 default:
576 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
577 goto err;
578 }
579 if (r < 0)
580 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
581
582err:
583 if (ctx != NULL) BN_CTX_free(ctx);
584 BN_clear_free(&f);
585 BN_clear_free(&ret);
586 if (buf != NULL)
587 {
588 OPENSSL_cleanse(buf,num);
589 OPENSSL_free(buf);
590 }
591 return(r);
592 }
593
594static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
595 {
596 BIGNUM r1,m1,vrfy;
597 int ret=0;
598 BN_CTX *ctx;
599
600 BN_init(&m1);
601 BN_init(&r1);
602 BN_init(&vrfy);
603 if ((ctx=BN_CTX_new()) == NULL) goto err;
604
605 if (rsa->flags & RSA_FLAG_CACHE_PRIVATE)
606 {
607 if (rsa->_method_mod_p == NULL)
608 {
609 BN_MONT_CTX* bn_mont_ctx;
610 if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL)
611 goto err;
612 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->p,ctx))
613 {
614 BN_MONT_CTX_free(bn_mont_ctx);
615 goto err;
616 }
617 if (rsa->_method_mod_p == NULL) /* other thread may have finished first */
618 {
619 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
620 if (rsa->_method_mod_p == NULL)
621 {
622 rsa->_method_mod_p = bn_mont_ctx;
623 bn_mont_ctx = NULL;
624 }
625 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
626 }
627 if (bn_mont_ctx)
628 BN_MONT_CTX_free(bn_mont_ctx);
629 }
630
631 if (rsa->_method_mod_q == NULL)
632 {
633 BN_MONT_CTX* bn_mont_ctx;
634 if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL)
635 goto err;
636 if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->q,ctx))
637 {
638 BN_MONT_CTX_free(bn_mont_ctx);
639 goto err;
640 }
641 if (rsa->_method_mod_q == NULL) /* other thread may have finished first */
642 {
643 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
644 if (rsa->_method_mod_q == NULL)
645 {
646 rsa->_method_mod_q = bn_mont_ctx;
647 bn_mont_ctx = NULL;
648 }
649 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
650 }
651 if (bn_mont_ctx)
652 BN_MONT_CTX_free(bn_mont_ctx);
653 }
654 }
655
656 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
657 if (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,
658 rsa->_method_mod_q)) goto err;
659
660 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
661 if (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,
662 rsa->_method_mod_p)) goto err;
663
664 if (!BN_sub(r0,r0,&m1)) goto err;
665 /* This will help stop the size of r0 increasing, which does
666 * affect the multiply if it optimised for a power of 2 size */
667 if (r0->neg)
668 if (!BN_add(r0,r0,rsa->p)) goto err;
669
670 if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
671 if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
672 /* If p < q it is occasionally possible for the correction of
673 * adding 'p' if r0 is negative above to leave the result still
674 * negative. This can break the private key operations: the following
675 * second correction should *always* correct this rare occurrence.
676 * This will *never* happen with OpenSSL generated keys because
677 * they ensure p > q [steve]
678 */
679 if (r0->neg)
680 if (!BN_add(r0,r0,rsa->p)) goto err;
681 if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
682 if (!BN_add(r0,&r1,&m1)) goto err;
683
684 if (rsa->e && rsa->n)
685 {
686 if (!rsa->meth->bn_mod_exp(&vrfy,r0,rsa->e,rsa->n,ctx,NULL)) goto err;
687 /* If 'I' was greater than (or equal to) rsa->n, the operation
688 * will be equivalent to using 'I mod n'. However, the result of
689 * the verify will *always* be less than 'n' so we don't check
690 * for absolute equality, just congruency. */
691 if (!BN_sub(&vrfy, &vrfy, I)) goto err;
692 if (!BN_mod(&vrfy, &vrfy, rsa->n, ctx)) goto err;
693 if (vrfy.neg)
694 if (!BN_add(&vrfy, &vrfy, rsa->n)) goto err;
695 if (!BN_is_zero(&vrfy))
696 /* 'I' and 'vrfy' aren't congruent mod n. Don't leak
697 * miscalculated CRT output, just do a raw (slower)
698 * mod_exp and return that instead. */
699 if (!rsa->meth->bn_mod_exp(r0,I,rsa->d,rsa->n,ctx,NULL)) goto err;
700 }
701 ret=1;
702err:
703 BN_clear_free(&m1);
704 BN_clear_free(&r1);
705 BN_clear_free(&vrfy);
706 BN_CTX_free(ctx);
707 return(ret);
708 }
709
710static int RSA_eay_init(RSA *rsa)
711 {
712 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
713 return(1);
714 }
715
716static int RSA_eay_finish(RSA *rsa)
717 {
718 if (rsa->_method_mod_n != NULL)
719 BN_MONT_CTX_free(rsa->_method_mod_n);
720 if (rsa->_method_mod_p != NULL)
721 BN_MONT_CTX_free(rsa->_method_mod_p);
722 if (rsa->_method_mod_q != NULL)
723 BN_MONT_CTX_free(rsa->_method_mod_q);
724 return(1);
725 }
726
727#endif
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
new file mode 100644
index 0000000000..a7766c3b76
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_err.c
@@ -0,0 +1,149 @@
1/* crypto/rsa/rsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/rsa.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA RSA_str_functs[]=
68 {
69{ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"},
70{ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"},
71{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"},
72{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"},
73{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"},
74{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"},
75{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"},
76{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"},
77{ERR_PACK(0,RSA_F_RSA_NULL,0), "RSA_NULL"},
78{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"},
79{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"},
80{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"},
81{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"},
82{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"},
83{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"},
84{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"},
85{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"},
86{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"},
87{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"},
88{ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"},
89{ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"},
90{ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"},
91{ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"},
92{ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"},
93{ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"},
94{0,NULL}
95 };
96
97static ERR_STRING_DATA RSA_str_reasons[]=
98 {
99{RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"},
100{RSA_R_BAD_E_VALUE ,"bad e value"},
101{RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"},
102{RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"},
103{RSA_R_BAD_SIGNATURE ,"bad signature"},
104{RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"},
105{RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"},
106{RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"},
107{RSA_R_DATA_TOO_LARGE ,"data too large"},
108{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
109{RSA_R_DATA_TOO_LARGE_FOR_MODULUS ,"data too large for modulus"},
110{RSA_R_DATA_TOO_SMALL ,"data too small"},
111{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"},
112{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"},
113{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"},
114{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"},
115{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"},
116{RSA_R_INVALID_MESSAGE_LENGTH ,"invalid message length"},
117{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"},
118{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"},
119{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"},
120{RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"},
121{RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"},
122{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"},
123{RSA_R_P_NOT_PRIME ,"p not prime"},
124{RSA_R_Q_NOT_PRIME ,"q not prime"},
125{RSA_R_RSA_OPERATIONS_NOT_SUPPORTED ,"rsa operations not supported"},
126{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"},
127{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
128{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
129{RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"},
130{RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
131{0,NULL}
132 };
133
134#endif
135
136void ERR_load_RSA_strings(void)
137 {
138 static int init=1;
139
140 if (init)
141 {
142 init=0;
143#ifndef OPENSSL_NO_ERR
144 ERR_load_strings(ERR_LIB_RSA,RSA_str_functs);
145 ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons);
146#endif
147
148 }
149 }
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
new file mode 100644
index 0000000000..adb5e34da5
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -0,0 +1,200 @@
1/* crypto/rsa/rsa_gen.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include "cryptlib.h"
62#include <openssl/bn.h>
63#include <openssl/rsa.h>
64
65#ifndef OPENSSL_FIPS
66
67RSA *RSA_generate_key(int bits, unsigned long e_value,
68 void (*callback)(int,int,void *), void *cb_arg)
69 {
70 RSA *rsa=NULL;
71 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
72 int bitsp,bitsq,ok= -1,n=0,i;
73 BN_CTX *ctx=NULL,*ctx2=NULL;
74
75 ctx=BN_CTX_new();
76 if (ctx == NULL) goto err;
77 ctx2=BN_CTX_new();
78 if (ctx2 == NULL) goto err;
79 BN_CTX_start(ctx);
80 r0 = BN_CTX_get(ctx);
81 r1 = BN_CTX_get(ctx);
82 r2 = BN_CTX_get(ctx);
83 r3 = BN_CTX_get(ctx);
84 if (r3 == NULL) goto err;
85
86 bitsp=(bits+1)/2;
87 bitsq=bits-bitsp;
88 rsa=RSA_new();
89 if (rsa == NULL) goto err;
90
91 /* set e */
92 rsa->e=BN_new();
93 if (rsa->e == NULL) goto err;
94
95#if 1
96 /* The problem is when building with 8, 16, or 32 BN_ULONG,
97 * unsigned long can be larger */
98 for (i=0; i<sizeof(unsigned long)*8; i++)
99 {
100 if (e_value & (1UL<<i))
101 BN_set_bit(rsa->e,i);
102 }
103#else
104 if (!BN_set_word(rsa->e,e_value)) goto err;
105#endif
106
107 /* generate p and q */
108 for (;;)
109 {
110 rsa->p=BN_generate_prime(NULL,bitsp,0,NULL,NULL,callback,cb_arg);
111 if (rsa->p == NULL) goto err;
112 if (!BN_sub(r2,rsa->p,BN_value_one())) goto err;
113 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
114 if (BN_is_one(r1)) break;
115 if (callback != NULL) callback(2,n++,cb_arg);
116 BN_free(rsa->p);
117 }
118 if (callback != NULL) callback(3,0,cb_arg);
119 for (;;)
120 {
121 rsa->q=BN_generate_prime(NULL,bitsq,0,NULL,NULL,callback,cb_arg);
122 if (rsa->q == NULL) goto err;
123 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err;
124 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
125 if (BN_is_one(r1) && (BN_cmp(rsa->p,rsa->q) != 0))
126 break;
127 if (callback != NULL) callback(2,n++,cb_arg);
128 BN_free(rsa->q);
129 }
130 if (callback != NULL) callback(3,1,cb_arg);
131 if (BN_cmp(rsa->p,rsa->q) < 0)
132 {
133 tmp=rsa->p;
134 rsa->p=rsa->q;
135 rsa->q=tmp;
136 }
137
138 /* calculate n */
139 rsa->n=BN_new();
140 if (rsa->n == NULL) goto err;
141 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;
142
143 /* calculate d */
144 if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */
145 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */
146 if (!BN_mul(r0,r1,r2,ctx)) goto err; /* (p-1)(q-1) */
147
148/* should not be needed, since gcd(p-1,e) == 1 and gcd(q-1,e) == 1 */
149/* for (;;)
150 {
151 if (!BN_gcd(r3,r0,rsa->e,ctx)) goto err;
152 if (BN_is_one(r3)) break;
153
154 if (1)
155 {
156 if (!BN_add_word(rsa->e,2L)) goto err;
157 continue;
158 }
159 RSAerr(RSA_F_RSA_GENERATE_KEY,RSA_R_BAD_E_VALUE);
160 goto err;
161 }
162*/
163 rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */
164 if (rsa->d == NULL) goto err;
165
166 /* calculate d mod (p-1) */
167 rsa->dmp1=BN_new();
168 if (rsa->dmp1 == NULL) goto err;
169 if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err;
170
171 /* calculate d mod (q-1) */
172 rsa->dmq1=BN_new();
173 if (rsa->dmq1 == NULL) goto err;
174 if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err;
175
176 /* calculate inverse of q mod p */
177 rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
178 if (rsa->iqmp == NULL) goto err;
179
180 ok=1;
181err:
182 if (ok == -1)
183 {
184 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
185 ok=0;
186 }
187 BN_CTX_end(ctx);
188 BN_CTX_free(ctx);
189 BN_CTX_free(ctx2);
190
191 if (!ok)
192 {
193 if (rsa != NULL) RSA_free(rsa);
194 return(NULL);
195 }
196 else
197 return(rsa);
198 }
199
200#endif
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
new file mode 100644
index 0000000000..e4d622851e
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -0,0 +1,414 @@
1/* crypto/rsa/rsa_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/lhash.h>
63#include <openssl/bn.h>
64#include <openssl/rsa.h>
65#include <openssl/rand.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
71
72static const RSA_METHOD *default_RSA_meth=NULL;
73
74RSA *RSA_new(void)
75 {
76 RSA *r=RSA_new_method(NULL);
77
78 return r;
79 }
80
81void RSA_set_default_method(const RSA_METHOD *meth)
82 {
83 default_RSA_meth = meth;
84 }
85
86const RSA_METHOD *RSA_get_default_method(void)
87 {
88 if (default_RSA_meth == NULL)
89 {
90#ifdef RSA_NULL
91 default_RSA_meth=RSA_null_method();
92#else
93#if 0 /* was: #ifdef RSAref */
94 default_RSA_meth=RSA_PKCS1_RSAref();
95#else
96 default_RSA_meth=RSA_PKCS1_SSLeay();
97#endif
98#endif
99 }
100
101 return default_RSA_meth;
102 }
103
104const RSA_METHOD *RSA_get_method(const RSA *rsa)
105 {
106 return rsa->meth;
107 }
108
109int RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
110 {
111 /* NB: The caller is specifically setting a method, so it's not up to us
112 * to deal with which ENGINE it comes from. */
113 const RSA_METHOD *mtmp;
114 mtmp = rsa->meth;
115 if (mtmp->finish) mtmp->finish(rsa);
116#ifndef OPENSSL_NO_ENGINE
117 if (rsa->engine)
118 {
119 ENGINE_finish(rsa->engine);
120 rsa->engine = NULL;
121 }
122#endif
123 rsa->meth = meth;
124 if (meth->init) meth->init(rsa);
125 return 1;
126 }
127
128RSA *RSA_new_method(ENGINE *engine)
129 {
130 RSA *ret;
131
132 ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
133 if (ret == NULL)
134 {
135 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
136 return NULL;
137 }
138
139 ret->meth = RSA_get_default_method();
140#ifndef OPENSSL_NO_ENGINE
141 if (engine)
142 {
143 if (!ENGINE_init(engine))
144 {
145 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
146 OPENSSL_free(ret);
147 return NULL;
148 }
149 ret->engine = engine;
150 }
151 else
152 ret->engine = ENGINE_get_default_RSA();
153 if(ret->engine)
154 {
155 ret->meth = ENGINE_get_RSA(ret->engine);
156 if(!ret->meth)
157 {
158 RSAerr(RSA_F_RSA_NEW_METHOD,
159 ERR_R_ENGINE_LIB);
160 ENGINE_finish(ret->engine);
161 OPENSSL_free(ret);
162 return NULL;
163 }
164 }
165#endif
166
167 ret->pad=0;
168 ret->version=0;
169 ret->n=NULL;
170 ret->e=NULL;
171 ret->d=NULL;
172 ret->p=NULL;
173 ret->q=NULL;
174 ret->dmp1=NULL;
175 ret->dmq1=NULL;
176 ret->iqmp=NULL;
177 ret->references=1;
178 ret->_method_mod_n=NULL;
179 ret->_method_mod_p=NULL;
180 ret->_method_mod_q=NULL;
181 ret->blinding=NULL;
182 ret->bignum_data=NULL;
183 ret->flags=ret->meth->flags;
184 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
185 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
186 {
187#ifndef OPENSSL_NO_ENGINE
188 if (ret->engine)
189 ENGINE_finish(ret->engine);
190#endif
191 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
192 OPENSSL_free(ret);
193 ret=NULL;
194 }
195 return(ret);
196 }
197
198void RSA_free(RSA *r)
199 {
200 int i;
201
202 if (r == NULL) return;
203
204 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
205#ifdef REF_PRINT
206 REF_PRINT("RSA",r);
207#endif
208 if (i > 0) return;
209#ifdef REF_CHECK
210 if (i < 0)
211 {
212 fprintf(stderr,"RSA_free, bad reference count\n");
213 abort();
214 }
215#endif
216
217 if (r->meth->finish)
218 r->meth->finish(r);
219#ifndef OPENSSL_NO_ENGINE
220 if (r->engine)
221 ENGINE_finish(r->engine);
222#endif
223
224 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
225
226 if (r->n != NULL) BN_clear_free(r->n);
227 if (r->e != NULL) BN_clear_free(r->e);
228 if (r->d != NULL) BN_clear_free(r->d);
229 if (r->p != NULL) BN_clear_free(r->p);
230 if (r->q != NULL) BN_clear_free(r->q);
231 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
232 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
233 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
234 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
235 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
236 OPENSSL_free(r);
237 }
238
239int RSA_up_ref(RSA *r)
240 {
241 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
242#ifdef REF_PRINT
243 REF_PRINT("RSA",r);
244#endif
245#ifdef REF_CHECK
246 if (i < 2)
247 {
248 fprintf(stderr, "RSA_up_ref, bad reference count\n");
249 abort();
250 }
251#endif
252 return ((i > 1) ? 1 : 0);
253 }
254
255int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
256 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
257 {
258 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp,
259 new_func, dup_func, free_func);
260 }
261
262int RSA_set_ex_data(RSA *r, int idx, void *arg)
263 {
264 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
265 }
266
267void *RSA_get_ex_data(const RSA *r, int idx)
268 {
269 return(CRYPTO_get_ex_data(&r->ex_data,idx));
270 }
271
272int RSA_size(const RSA *r)
273 {
274 return(BN_num_bytes(r->n));
275 }
276
277int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
278 RSA *rsa, int padding)
279 {
280 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding));
281 }
282
283int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
284 RSA *rsa, int padding)
285 {
286 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
287 }
288
289int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
290 RSA *rsa, int padding)
291 {
292 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding));
293 }
294
295int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
296 RSA *rsa, int padding)
297 {
298 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
299 }
300
301int RSA_flags(const RSA *r)
302 {
303 return((r == NULL)?0:r->meth->flags);
304 }
305
306void RSA_blinding_off(RSA *rsa)
307 {
308 if (rsa->blinding != NULL)
309 {
310 BN_BLINDING_free(rsa->blinding);
311 rsa->blinding=NULL;
312 }
313 rsa->flags &= ~RSA_FLAG_BLINDING;
314 rsa->flags |= RSA_FLAG_NO_BLINDING;
315 }
316
317int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
318 {
319 BIGNUM *A,*Ai = NULL;
320 BN_CTX *ctx;
321 int ret=0;
322
323 if (p_ctx == NULL)
324 {
325 if ((ctx=BN_CTX_new()) == NULL) goto err;
326 }
327 else
328 ctx=p_ctx;
329
330 /* XXXXX: Shouldn't this be RSA_blinding_off(rsa)? */
331 if (rsa->blinding != NULL)
332 {
333 BN_BLINDING_free(rsa->blinding);
334 rsa->blinding = NULL;
335 }
336
337 /* NB: similar code appears in setup_blinding (rsa_eay.c);
338 * this should be placed in a new function of its own, but for reasons
339 * of binary compatibility can't */
340
341 BN_CTX_start(ctx);
342 A = BN_CTX_get(ctx);
343 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
344 {
345 /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */
346 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
347 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
348 }
349 else
350 {
351 if (!BN_rand_range(A,rsa->n)) goto err;
352 }
353 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
354
355 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
356 goto err;
357 if ((rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n)) == NULL) goto err;
358 /* to make things thread-safe without excessive locking,
359 * rsa->blinding will be used just by the current thread: */
360 rsa->blinding->thread_id = CRYPTO_thread_id();
361 rsa->flags |= RSA_FLAG_BLINDING;
362 rsa->flags &= ~RSA_FLAG_NO_BLINDING;
363 ret=1;
364err:
365 if (Ai != NULL) BN_free(Ai);
366 BN_CTX_end(ctx);
367 if (ctx != p_ctx) BN_CTX_free(ctx);
368 return(ret);
369 }
370
371int RSA_memory_lock(RSA *r)
372 {
373 int i,j,k,off;
374 char *p;
375 BIGNUM *bn,**t[6],*b;
376 BN_ULONG *ul;
377
378 if (r->d == NULL) return(1);
379 t[0]= &r->d;
380 t[1]= &r->p;
381 t[2]= &r->q;
382 t[3]= &r->dmp1;
383 t[4]= &r->dmq1;
384 t[5]= &r->iqmp;
385 k=sizeof(BIGNUM)*6;
386 off=k/sizeof(BN_ULONG)+1;
387 j=1;
388 for (i=0; i<6; i++)
389 j+= (*t[i])->top;
390 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
391 {
392 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
393 return(0);
394 }
395 bn=(BIGNUM *)p;
396 ul=(BN_ULONG *)&(p[off]);
397 for (i=0; i<6; i++)
398 {
399 b= *(t[i]);
400 *(t[i])= &(bn[i]);
401 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
402 bn[i].flags=BN_FLG_STATIC_DATA;
403 bn[i].d=ul;
404 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
405 ul+=b->top;
406 BN_clear_free(b);
407 }
408
409 /* I should fix this so it can still be done */
410 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
411
412 r->bignum_data=p;
413 return(1);
414 }
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c
new file mode 100644
index 0000000000..e6f3e627ca
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_none.c
@@ -0,0 +1,98 @@
1/* crypto/rsa/rsa_none.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65int RSA_padding_add_none(unsigned char *to, int tlen,
66 const unsigned char *from, int flen)
67 {
68 if (flen > tlen)
69 {
70 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
71 return(0);
72 }
73
74 if (flen < tlen)
75 {
76 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
77 return(0);
78 }
79
80 memcpy(to,from,(unsigned int)flen);
81 return(1);
82 }
83
84int RSA_padding_check_none(unsigned char *to, int tlen,
85 const unsigned char *from, int flen, int num)
86 {
87
88 if (flen > tlen)
89 {
90 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE);
91 return(-1);
92 }
93
94 memset(to,0,tlen-flen);
95 memcpy(to+tlen-flen,from,flen);
96 return(tlen);
97 }
98
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
new file mode 100644
index 0000000000..e3f7c608ec
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -0,0 +1,206 @@
1/* crypto/rsa/rsa_oaep.c */
2/* Written by Ulf Moeller. This software is distributed on an "AS IS"
3 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */
4
5/* EME-OAEP as defined in RFC 2437 (PKCS #1 v2.0) */
6
7/* See Victor Shoup, "OAEP reconsidered," Nov. 2000,
8 * <URL: http://www.shoup.net/papers/oaep.ps.Z>
9 * for problems with the security proof for the
10 * original OAEP scheme, which EME-OAEP is based on.
11 *
12 * A new proof can be found in E. Fujisaki, T. Okamoto,
13 * D. Pointcheval, J. Stern, "RSA-OEAP is Still Alive!",
14 * Dec. 2000, <URL: http://eprint.iacr.org/2000/061/>.
15 * The new proof has stronger requirements for the
16 * underlying permutation: "partial-one-wayness" instead
17 * of one-wayness. For the RSA function, this is
18 * an equivalent notion.
19 */
20
21
22#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
23#include <stdio.h>
24#include "cryptlib.h"
25#include <openssl/bn.h>
26#include <openssl/rsa.h>
27#include <openssl/evp.h>
28#include <openssl/rand.h>
29#include <openssl/sha.h>
30
31int 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,
35 const unsigned char *from, int flen,
36 const unsigned char *param, int plen)
37 {
38 int i, emlen = tlen - 1;
39 unsigned char *db, *seed;
40 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];
41
42 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1)
43 {
44 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,
45 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
46 return 0;
47 }
48
49 if (emlen < 2 * SHA_DIGEST_LENGTH + 1)
50 {
51 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL);
52 return 0;
53 }
54
55 dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH);
56 if (dbmask == NULL)
57 {
58 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
59 return 0;
60 }
61
62 to[0] = 0;
63 seed = to + 1;
64 db = to + SHA_DIGEST_LENGTH + 1;
65
66 EVP_Digest((void *)param, plen, db, NULL, EVP_sha1(), NULL);
67 memset(db + SHA_DIGEST_LENGTH, 0,
68 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
69 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
70 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);
71 if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0)
72 return 0;
73#ifdef PKCS_TESTVECT
74 memcpy(seed,
75 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
76 20);
77#endif
78
79 MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);
80 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
81 db[i] ^= dbmask[i];
82
83 MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);
84 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
85 seed[i] ^= seedmask[i];
86
87 OPENSSL_free(dbmask);
88 return 1;
89 }
90
91int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
92 const unsigned char *from, int flen, int num,
93 const unsigned char *param, int plen)
94 {
95 int i, dblen, mlen = -1;
96 const unsigned char *maskeddb;
97 int lzero;
98 unsigned char *db = NULL, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
99 int bad = 0;
100
101 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
102 /* 'num' is the length of the modulus, i.e. does not depend on the
103 * particular ciphertext. */
104 goto decoding_err;
105
106 lzero = num - flen;
107 if (lzero < 0)
108 {
109 /* lzero == -1 */
110
111 /* signalling this error immediately after detection might allow
112 * for side-channel attacks (e.g. timing if 'plen' is huge
113 * -- cf. James H. Manger, "A Chosen Ciphertext Attack on RSA Optimal
114 * Asymmetric Encryption Padding (OAEP) [...]", CRYPTO 2001),
115 * so we use a 'bad' flag */
116 bad = 1;
117 lzero = 0;
118 }
119 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
120
121 dblen = num - SHA_DIGEST_LENGTH;
122 db = OPENSSL_malloc(dblen);
123 if (db == NULL)
124 {
125 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
126 return -1;
127 }
128
129 MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
130 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
131 seed[i] ^= from[i - lzero];
132
133 MGF1(db, dblen, seed, SHA_DIGEST_LENGTH);
134 for (i = 0; i < dblen; i++)
135 db[i] ^= maskeddb[i];
136
137 EVP_Digest((void *)param, plen, phash, NULL, EVP_sha1(), NULL);
138
139 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0 || bad)
140 goto decoding_err;
141 else
142 {
143 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
144 if (db[i] != 0x00)
145 break;
146 if (db[i] != 0x01 || i++ >= dblen)
147 goto decoding_err;
148 else
149 {
150 /* everything looks OK */
151
152 mlen = dblen - i;
153 if (tlen < mlen)
154 {
155 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
156 mlen = -1;
157 }
158 else
159 memcpy(to, db + i, mlen);
160 }
161 }
162 OPENSSL_free(db);
163 return mlen;
164
165decoding_err:
166 /* to avoid chosen ciphertext attacks, the error message should not reveal
167 * which kind of decoding error happened */
168 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
169 if (db != NULL) OPENSSL_free(db);
170 return -1;
171 }
172
173int MGF1(unsigned char *mask, long len,
174 const unsigned char *seed, long seedlen)
175 {
176 long i, outlen = 0;
177 unsigned char cnt[4];
178 EVP_MD_CTX c;
179 unsigned char md[SHA_DIGEST_LENGTH];
180
181 EVP_MD_CTX_init(&c);
182 for (i = 0; outlen < len; i++)
183 {
184 cnt[0] = (unsigned char)((i >> 24) & 255);
185 cnt[1] = (unsigned char)((i >> 16) & 255);
186 cnt[2] = (unsigned char)((i >> 8)) & 255;
187 cnt[3] = (unsigned char)(i & 255);
188 EVP_DigestInit_ex(&c,EVP_sha1(), NULL);
189 EVP_DigestUpdate(&c, seed, seedlen);
190 EVP_DigestUpdate(&c, cnt, 4);
191 if (outlen + SHA_DIGEST_LENGTH <= len)
192 {
193 EVP_DigestFinal_ex(&c, mask + outlen, NULL);
194 outlen += SHA_DIGEST_LENGTH;
195 }
196 else
197 {
198 EVP_DigestFinal_ex(&c, md, NULL);
199 memcpy(mask + outlen, md, len - outlen);
200 outlen = len;
201 }
202 }
203 EVP_MD_CTX_cleanup(&c);
204 return 0;
205 }
206#endif
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
new file mode 100644
index 0000000000..8560755f1d
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_pk1.c
@@ -0,0 +1,224 @@
1/* crypto/rsa/rsa_pk1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
66 const unsigned char *from, int flen)
67 {
68 int j;
69 unsigned char *p;
70
71 if (flen > (tlen-RSA_PKCS1_PADDING_SIZE))
72 {
73 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
74 return(0);
75 }
76
77 p=(unsigned char *)to;
78
79 *(p++)=0;
80 *(p++)=1; /* Private Key BT (Block Type) */
81
82 /* pad out with 0xff data */
83 j=tlen-3-flen;
84 memset(p,0xff,j);
85 p+=j;
86 *(p++)='\0';
87 memcpy(p,from,(unsigned int)flen);
88 return(1);
89 }
90
91int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
92 const unsigned char *from, int flen, int num)
93 {
94 int i,j;
95 const unsigned char *p;
96
97 p=from;
98 if ((num != (flen+1)) || (*(p++) != 01))
99 {
100 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01);
101 return(-1);
102 }
103
104 /* scan over padding data */
105 j=flen-1; /* one for type. */
106 for (i=0; i<j; i++)
107 {
108 if (*p != 0xff) /* should decrypt to 0xff */
109 {
110 if (*p == 0)
111 { p++; break; }
112 else {
113 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_FIXED_HEADER_DECRYPT);
114 return(-1);
115 }
116 }
117 p++;
118 }
119
120 if (i == j)
121 {
122 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_NULL_BEFORE_BLOCK_MISSING);
123 return(-1);
124 }
125
126 if (i < 8)
127 {
128 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_PAD_BYTE_COUNT);
129 return(-1);
130 }
131 i++; /* Skip over the '\0' */
132 j-=i;
133 if (j > tlen)
134 {
135 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE);
136 return(-1);
137 }
138 memcpy(to,p,(unsigned int)j);
139
140 return(j);
141 }
142
143int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
144 const unsigned char *from, int flen)
145 {
146 int i,j;
147 unsigned char *p;
148
149 if (flen > (tlen-11))
150 {
151 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
152 return(0);
153 }
154
155 p=(unsigned char *)to;
156
157 *(p++)=0;
158 *(p++)=2; /* Public Key BT (Block Type) */
159
160 /* pad out with non-zero random data */
161 j=tlen-3-flen;
162
163 if (RAND_bytes(p,j) <= 0)
164 return(0);
165 for (i=0; i<j; i++)
166 {
167 if (*p == '\0')
168 do {
169 if (RAND_bytes(p,1) <= 0)
170 return(0);
171 } while (*p == '\0');
172 p++;
173 }
174
175 *(p++)='\0';
176
177 memcpy(p,from,(unsigned int)flen);
178 return(1);
179 }
180
181int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
182 const unsigned char *from, int flen, int num)
183 {
184 int i,j;
185 const unsigned char *p;
186
187 p=from;
188 if ((num != (flen+1)) || (*(p++) != 02))
189 {
190 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02);
191 return(-1);
192 }
193#ifdef PKCS1_CHECK
194 return(num-11);
195#endif
196
197 /* scan over padding data */
198 j=flen-1; /* one for type. */
199 for (i=0; i<j; i++)
200 if (*(p++) == 0) break;
201
202 if (i == j)
203 {
204 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING);
205 return(-1);
206 }
207
208 if (i < 8)
209 {
210 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT);
211 return(-1);
212 }
213 i++; /* Skip over the '\0' */
214 j-=i;
215 if (j > tlen)
216 {
217 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE);
218 return(-1);
219 }
220 memcpy(to,p,(unsigned int)j);
221
222 return(j);
223 }
224
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
new file mode 100644
index 0000000000..24fc94835e
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -0,0 +1,149 @@
1/* crypto/rsa/rsa_saos.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int RSA_sign_ASN1_OCTET_STRING(int type,
67 const unsigned char *m, unsigned int m_len,
68 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
69 {
70 ASN1_OCTET_STRING sig;
71 int i,j,ret=1;
72 unsigned char *p,*s;
73
74 sig.type=V_ASN1_OCTET_STRING;
75 sig.length=m_len;
76 sig.data=(unsigned char *)m;
77
78 i=i2d_ASN1_OCTET_STRING(&sig,NULL);
79 j=RSA_size(rsa);
80 if (i > (j-RSA_PKCS1_PADDING_SIZE))
81 {
82 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
83 return(0);
84 }
85 s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1);
86 if (s == NULL)
87 {
88 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
89 return(0);
90 }
91 p=s;
92 i2d_ASN1_OCTET_STRING(&sig,&p);
93 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
94 if (i <= 0)
95 ret=0;
96 else
97 *siglen=i;
98
99 OPENSSL_cleanse(s,(unsigned int)j+1);
100 OPENSSL_free(s);
101 return(ret);
102 }
103
104int RSA_verify_ASN1_OCTET_STRING(int dtype,
105 const unsigned char *m,
106 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
107 RSA *rsa)
108 {
109 int i,ret=0;
110 unsigned char *p,*s;
111 ASN1_OCTET_STRING *sig=NULL;
112
113 if (siglen != (unsigned int)RSA_size(rsa))
114 {
115 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH);
116 return(0);
117 }
118
119 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
120 if (s == NULL)
121 {
122 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
123 goto err;
124 }
125 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
126
127 if (i <= 0) goto err;
128
129 p=s;
130 sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i);
131 if (sig == NULL) goto err;
132
133 if ( ((unsigned int)sig->length != m_len) ||
134 (memcmp(m,sig->data,m_len) != 0))
135 {
136 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE);
137 }
138 else
139 ret=1;
140err:
141 if (sig != NULL) M_ASN1_OCTET_STRING_free(sig);
142 if (s != NULL)
143 {
144 OPENSSL_cleanse(s,(unsigned int)siglen);
145 OPENSSL_free(s);
146 }
147 return(ret);
148 }
149
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
new file mode 100644
index 0000000000..cee09eccb1
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -0,0 +1,232 @@
1/* crypto/rsa/rsa_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66/* Size of an SSL signature: MD5+SHA1 */
67#define SSL_SIG_LENGTH 36
68
69int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
70 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
71 {
72 X509_SIG sig;
73 ASN1_TYPE parameter;
74 int i,j,ret=1;
75 unsigned char *p, *tmps = NULL;
76 const unsigned char *s = NULL;
77 X509_ALGOR algor;
78 ASN1_OCTET_STRING digest;
79 if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_sign)
80 {
81 return rsa->meth->rsa_sign(type, m, m_len,
82 sigret, siglen, rsa);
83 }
84 /* Special case: SSL signature, just check the length */
85 if(type == NID_md5_sha1) {
86 if(m_len != SSL_SIG_LENGTH) {
87 RSAerr(RSA_F_RSA_SIGN,RSA_R_INVALID_MESSAGE_LENGTH);
88 return(0);
89 }
90 i = SSL_SIG_LENGTH;
91 s = m;
92 } else {
93 sig.algor= &algor;
94 sig.algor->algorithm=OBJ_nid2obj(type);
95 if (sig.algor->algorithm == NULL)
96 {
97 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
98 return(0);
99 }
100 if (sig.algor->algorithm->length == 0)
101 {
102 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
103 return(0);
104 }
105 parameter.type=V_ASN1_NULL;
106 parameter.value.ptr=NULL;
107 sig.algor->parameter= &parameter;
108
109 sig.digest= &digest;
110 sig.digest->data=(unsigned char *)m; /* TMP UGLY CAST */
111 sig.digest->length=m_len;
112
113 i=i2d_X509_SIG(&sig,NULL);
114 }
115 j=RSA_size(rsa);
116 if (i > (j-RSA_PKCS1_PADDING_SIZE))
117 {
118 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
119 return(0);
120 }
121 if(type != NID_md5_sha1) {
122 tmps=(unsigned char *)OPENSSL_malloc((unsigned int)j+1);
123 if (tmps == NULL)
124 {
125 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
126 return(0);
127 }
128 p=tmps;
129 i2d_X509_SIG(&sig,&p);
130 s=tmps;
131 }
132 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
133 if (i <= 0)
134 ret=0;
135 else
136 *siglen=i;
137
138 if(type != NID_md5_sha1) {
139 OPENSSL_cleanse(tmps,(unsigned int)j+1);
140 OPENSSL_free(tmps);
141 }
142 return(ret);
143 }
144
145int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
146 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
147 {
148 int i,ret=0,sigtype;
149 unsigned char *p,*s;
150 X509_SIG *sig=NULL;
151
152 if (siglen != (unsigned int)RSA_size(rsa))
153 {
154 RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
155 return(0);
156 }
157
158 if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)
159 {
160 return rsa->meth->rsa_verify(dtype, m, m_len,
161 sigbuf, siglen, rsa);
162 }
163
164 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
165 if (s == NULL)
166 {
167 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
168 goto err;
169 }
170 if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
171 RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
172 goto err;
173 }
174 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
175
176 if (i <= 0) goto err;
177
178 /* Special case: SSL signature */
179 if(dtype == NID_md5_sha1) {
180 if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
181 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
182 else ret = 1;
183 } else {
184 p=s;
185 sig=d2i_X509_SIG(NULL,&p,(long)i);
186
187 if (sig == NULL) goto err;
188 sigtype=OBJ_obj2nid(sig->algor->algorithm);
189
190
191 #ifdef RSA_DEBUG
192 /* put a backward compatibility flag in EAY */
193 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
194 OBJ_nid2ln(dtype));
195 #endif
196 if (sigtype != dtype)
197 {
198 if (((dtype == NID_md5) &&
199 (sigtype == NID_md5WithRSAEncryption)) ||
200 ((dtype == NID_md2) &&
201 (sigtype == NID_md2WithRSAEncryption)))
202 {
203 /* ok, we will let it through */
204#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
205 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
206#endif
207 }
208 else
209 {
210 RSAerr(RSA_F_RSA_VERIFY,
211 RSA_R_ALGORITHM_MISMATCH);
212 goto err;
213 }
214 }
215 if ( ((unsigned int)sig->digest->length != m_len) ||
216 (memcmp(m,sig->digest->data,m_len) != 0))
217 {
218 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
219 }
220 else
221 ret=1;
222 }
223err:
224 if (sig != NULL) X509_SIG_free(sig);
225 if (s != NULL)
226 {
227 OPENSSL_cleanse(s,(unsigned int)siglen);
228 OPENSSL_free(s);
229 }
230 return(ret);
231 }
232
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
new file mode 100644
index 0000000000..ea72629494
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_ssl.c
@@ -0,0 +1,154 @@
1/* crypto/rsa/rsa_ssl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
66 const unsigned char *from, int flen)
67 {
68 int i,j;
69 unsigned char *p;
70
71 if (flen > (tlen-11))
72 {
73 RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
74 return(0);
75 }
76
77 p=(unsigned char *)to;
78
79 *(p++)=0;
80 *(p++)=2; /* Public Key BT (Block Type) */
81
82 /* pad out with non-zero random data */
83 j=tlen-3-8-flen;
84
85 if (RAND_bytes(p,j) <= 0)
86 return(0);
87 for (i=0; i<j; i++)
88 {
89 if (*p == '\0')
90 do {
91 if (RAND_bytes(p,1) <= 0)
92 return(0);
93 } while (*p == '\0');
94 p++;
95 }
96
97 memset(p,3,8);
98 p+=8;
99 *(p++)='\0';
100
101 memcpy(p,from,(unsigned int)flen);
102 return(1);
103 }
104
105int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
106 const unsigned char *from, int flen, int num)
107 {
108 int i,j,k;
109 const unsigned char *p;
110
111 p=from;
112 if (flen < 10)
113 {
114 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL);
115 return(-1);
116 }
117 if ((num != (flen+1)) || (*(p++) != 02))
118 {
119 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02);
120 return(-1);
121 }
122
123 /* scan over padding data */
124 j=flen-1; /* one for type */
125 for (i=0; i<j; i++)
126 if (*(p++) == 0) break;
127
128 if ((i == j) || (i < 8))
129 {
130 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING);
131 return(-1);
132 }
133 for (k= -8; k<0; k++)
134 {
135 if (p[k] != 0x03) break;
136 }
137 if (k == -1)
138 {
139 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK);
140 return(-1);
141 }
142
143 i++; /* Skip over the '\0' */
144 j-=i;
145 if (j > tlen)
146 {
147 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_LARGE);
148 return(-1);
149 }
150 memcpy(to,p,(unsigned int)j);
151
152 return(j);
153 }
154
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c
index 218bb2a39b..924e9ad1f6 100644
--- a/src/lib/libcrypto/rsa/rsa_test.c
+++ b/src/lib/libcrypto/rsa/rsa_test.c
@@ -227,10 +227,10 @@ int main(int argc, char *argv[])
227 227
228 plen = sizeof(ptext_ex) - 1; 228 plen = sizeof(ptext_ex) - 1;
229 229
230 for (v = 0; v < 6; v++) 230 for (v = 0; v < 3; v++)
231 { 231 {
232 key = RSA_new(); 232 key = RSA_new();
233 switch (v%3) { 233 switch (v) {
234 case 0: 234 case 0:
235 clen = key1(key, ctext_ex); 235 clen = key1(key, ctext_ex);
236 break; 236 break;
@@ -241,7 +241,6 @@ int main(int argc, char *argv[])
241 clen = key3(key, ctext_ex); 241 clen = key3(key, ctext_ex);
242 break; 242 break;
243 } 243 }
244 if (v/3 > 1) key->flags |= RSA_FLAG_NO_EXP_CONSTTIME;
245 244
246 num = RSA_public_encrypt(plen, ptext_ex, ctext, key, 245 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
247 RSA_PKCS1_PADDING); 246 RSA_PKCS1_PADDING);
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/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl
new file mode 100644
index 0000000000..041acc0348
--- /dev/null
+++ b/src/lib/libcrypto/sha/asm/sha1-586.pl
@@ -0,0 +1,425 @@
1#!/usr/local/bin/perl
2
3# It was noted that Intel IA-32 C compiler generates code which
4# performs ~30% *faster* on P4 CPU than original *hand-coded*
5# SHA1 assembler implementation. To address this problem (and
6# prove that humans are still better than machines:-), the
7# original code was overhauled, which resulted in following
8# performance changes:
9#
10# compared with original compared with Intel cc
11# assembler impl. generated code
12# Pentium -25% +37%
13# PIII/AMD +8% +16%
14# P4 +85%(!) +45%
15#
16# As you can see Pentium came out as looser:-( Yet I reckoned that
17# improvement on P4 outweights the loss and incorporate this
18# re-tuned code to 0.9.7 and later.
19# ----------------------------------------------------------------
20# Those who for any particular reason absolutely must score on
21# Pentium can replace this module with one from 0.9.6 distribution.
22# This "offer" shall be revoked the moment programming interface to
23# this module is changed, in which case this paragraph should be
24# removed.
25# ----------------------------------------------------------------
26# <appro@fy.chalmers.se>
27
28$normal=0;
29
30push(@INC,"perlasm","../../perlasm");
31require "x86asm.pl";
32
33&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
34
35$A="eax";
36$B="ecx";
37$C="ebx";
38$D="edx";
39$E="edi";
40$T="esi";
41$tmp1="ebp";
42
43$off=9*4;
44
45@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6);
46
47&sha1_block_data("sha1_block_asm_data_order");
48
49&asm_finish();
50
51sub Nn
52 {
53 local($p)=@_;
54 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
55 return($n{$p});
56 }
57
58sub Np
59 {
60 local($p)=@_;
61 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
62 local(%n)=($A,$B,$B,$C,$C,$D,$D,$E,$E,$T,$T,$A);
63 return($n{$p});
64 }
65
66sub Na
67 {
68 local($n)=@_;
69 return( (($n )&0x0f),
70 (($n+ 2)&0x0f),
71 (($n+ 8)&0x0f),
72 (($n+13)&0x0f),
73 (($n+ 1)&0x0f));
74 }
75
76sub X_expand
77 {
78 local($in)=@_;
79
80 &comment("First, load the words onto the stack in network byte order");
81 for ($i=0; $i<16; $i+=2)
82 {
83 &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0;
84 &mov($B,&DWP(($i+1)*4,$in,"",0));
85 &bswap($A);
86 &bswap($B);
87 &mov(&swtmp($i+0),$A);
88 &mov(&swtmp($i+1),$B);
89 }
90
91 &comment("We now have the X array on the stack");
92 &comment("starting at sp-4");
93 }
94
95# Rules of engagement
96# F is always trashable at the start, the running total.
97# E becomes the next F so it can be trashed after it has been 'accumulated'
98# F becomes A in the next round. We don't need to access it much.
99# During the X update part, the result ends up in $X[$n0].
100
101sub BODY_00_15
102 {
103 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
104
105 &comment("00_15 $n");
106
107 &mov($tmp1,$a);
108 &mov($f,$c); # f to hold F_00_19(b,c,d)
109 &rotl($tmp1,5); # tmp1=ROTATE(a,5)
110 &xor($f,$d);
111 &and($f,$b);
112 &rotr($b,2); # b=ROTATE(b,30)
113 &add($tmp1,$e); # tmp1+=e;
114 &mov($e,&swtmp($n)); # e becomes volatile and
115 # is loaded with xi
116 &xor($f,$d); # f holds F_00_19(b,c,d)
117 &lea($tmp1,&DWP($K,$tmp1,$e,1));# tmp1+=K_00_19+xi
118
119 &add($f,$tmp1); # f+=tmp1
120 }
121
122sub BODY_16_19
123 {
124 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
125 local($n0,$n1,$n2,$n3,$np)=&Na($n);
126
127 &comment("16_19 $n");
128
129 &mov($f,&swtmp($n1)); # f to hold Xupdate(xi,xa,xb,xc,xd)
130 &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d)
131 &xor($f,&swtmp($n0));
132 &xor($tmp1,$d);
133 &xor($f,&swtmp($n2));
134 &and($tmp1,$b); # tmp1 holds F_00_19(b,c,d)
135 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
136 &rotr($b,2); # b=ROTATE(b,30)
137 &xor($tmp1,$d); # tmp1=F_00_19(b,c,d)
138 &rotl($f,1); # f=ROATE(f,1)
139 &mov(&swtmp($n0),$f); # xi=f
140 &lea($f,&DWP($K,$f,$e,1)); # f+=K_00_19+e
141 &mov($e,$a); # e becomes volatile
142 &add($f,$tmp1); # f+=F_00_19(b,c,d)
143 &rotl($e,5); # e=ROTATE(a,5)
144 &add($f,$e); # f+=ROTATE(a,5)
145 }
146
147sub BODY_20_39
148 {
149 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
150
151 &comment("20_39 $n");
152 local($n0,$n1,$n2,$n3,$np)=&Na($n);
153
154 &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd)
155 &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d)
156 &xor($f,&swtmp($n1));
157 &rotr($b,2); # b=ROTATE(b,30)
158 &xor($f,&swtmp($n2));
159 &xor($tmp1,$c);
160 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
161 &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d)
162 &rotl($f,1); # f=ROTATE(f,1)
163 &mov(&swtmp($n0),$f); # xi=f
164 &lea($f,&DWP($K,$f,$e,1)); # f+=K_20_39+e
165 &mov($e,$a); # e becomes volatile
166 &rotl($e,5); # e=ROTATE(a,5)
167 &add($f,$tmp1); # f+=F_20_39(b,c,d)
168 &add($f,$e); # f+=ROTATE(a,5)
169 }
170
171sub BODY_40_59
172 {
173 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
174
175 &comment("40_59 $n");
176 local($n0,$n1,$n2,$n3,$np)=&Na($n);
177
178 &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd)
179 &mov($tmp1,$b); # tmp1 to hold F_40_59(b,c,d)
180 &xor($f,&swtmp($n1));
181 &or($tmp1,$c);
182 &xor($f,&swtmp($n2));
183 &and($tmp1,$d);
184 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
185 &rotl($f,1); # f=ROTATE(f,1)
186 &mov(&swtmp($n0),$f); # xi=f
187 &lea($f,&DWP($K,$f,$e,1)); # f+=K_40_59+e
188 &mov($e,$b); # e becomes volatile and is used
189 # to calculate F_40_59(b,c,d)
190 &rotr($b,2); # b=ROTATE(b,30)
191 &and($e,$c);
192 &or($tmp1,$e); # tmp1 holds F_40_59(b,c,d)
193 &mov($e,$a);
194 &rotl($e,5); # e=ROTATE(a,5)
195 &add($tmp1,$e); # tmp1+=ROTATE(a,5)
196 &add($f,$tmp1); # f+=tmp1;
197 }
198
199sub BODY_60_79
200 {
201 &BODY_20_39(@_);
202 }
203
204sub sha1_block_host
205 {
206 local($name, $sclabel)=@_;
207
208 &function_begin_B($name,"");
209
210 # parameter 1 is the MD5_CTX structure.
211 # A 0
212 # B 4
213 # C 8
214 # D 12
215 # E 16
216
217 &mov("ecx", &wparam(2));
218 &push("esi");
219 &shl("ecx",6);
220 &mov("esi", &wparam(1));
221 &push("ebp");
222 &add("ecx","esi"); # offset to leave on
223 &push("ebx");
224 &mov("ebp", &wparam(0));
225 &push("edi");
226 &mov($D, &DWP(12,"ebp","",0));
227 &stack_push(18+9);
228 &mov($E, &DWP(16,"ebp","",0));
229 &mov($C, &DWP( 8,"ebp","",0));
230 &mov(&swtmp(17),"ecx");
231
232 &comment("First we need to setup the X array");
233
234 for ($i=0; $i<16; $i+=2)
235 {
236 &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0;
237 &mov($B,&DWP(($i+1)*4,"esi","",0));
238 &mov(&swtmp($i+0),$A);
239 &mov(&swtmp($i+1),$B);
240 }
241 &jmp($sclabel);
242 &function_end_B($name);
243 }
244
245
246sub sha1_block_data
247 {
248 local($name)=@_;
249
250 &function_begin_B($name,"");
251
252 # parameter 1 is the MD5_CTX structure.
253 # A 0
254 # B 4
255 # C 8
256 # D 12
257 # E 16
258
259 &mov("ecx", &wparam(2));
260 &push("esi");
261 &shl("ecx",6);
262 &mov("esi", &wparam(1));
263 &push("ebp");
264 &add("ecx","esi"); # offset to leave on
265 &push("ebx");
266 &mov("ebp", &wparam(0));
267 &push("edi");
268 &mov($D, &DWP(12,"ebp","",0));
269 &stack_push(18+9);
270 &mov($E, &DWP(16,"ebp","",0));
271 &mov($C, &DWP( 8,"ebp","",0));
272 &mov(&swtmp(17),"ecx");
273
274 &comment("First we need to setup the X array");
275
276 &set_label("start") unless $normal;
277
278 &X_expand("esi");
279 &mov(&wparam(1),"esi");
280
281 &set_label("shortcut", 0, 1);
282 &comment("");
283 &comment("Start processing");
284
285 # odd start
286 &mov($A, &DWP( 0,"ebp","",0));
287 &mov($B, &DWP( 4,"ebp","",0));
288 $X="esp";
289 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
290 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
291 &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D);
292 &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C);
293 &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B);
294 &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A);
295 &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T);
296 &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E);
297 &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D);
298 &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C);
299 &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B);
300 &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A);
301 &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T);
302 &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E);
303 &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D);
304 &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C);
305 &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B);
306 &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A);
307 &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T);
308 &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E);
309
310 &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D);
311 &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C);
312 &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B);
313 &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A);
314 &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T);
315 &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E);
316 &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D);
317 &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C);
318 &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B);
319 &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A);
320 &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T);
321 &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E);
322 &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D);
323 &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C);
324 &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B);
325 &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A);
326 &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T);
327 &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E);
328 &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D);
329 &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C);
330
331 &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B);
332 &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A);
333 &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
334 &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
335 &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D);
336 &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C);
337 &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B);
338 &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A);
339 &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T);
340 &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E);
341 &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D);
342 &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C);
343 &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B);
344 &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A);
345 &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T);
346 &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E);
347 &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D);
348 &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C);
349 &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B);
350 &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A);
351
352 &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T);
353 &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E);
354 &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D);
355 &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C);
356 &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B);
357 &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A);
358 &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T);
359 &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E);
360 &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D);
361 &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C);
362 &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B);
363 &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A);
364 &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T);
365 &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E);
366 &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D);
367 &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C);
368 &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B);
369 &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A);
370 &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T);
371 &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E);
372
373 &comment("End processing");
374 &comment("");
375 # D is the tmp value
376
377 # E -> A
378 # T -> B
379 # A -> C
380 # B -> D
381 # C -> E
382 # D -> T
383
384 &mov($tmp1,&wparam(0));
385
386 &mov($D, &DWP(12,$tmp1,"",0));
387 &add($D,$B);
388 &mov($B, &DWP( 4,$tmp1,"",0));
389 &add($B,$T);
390 &mov($T, $A);
391 &mov($A, &DWP( 0,$tmp1,"",0));
392 &mov(&DWP(12,$tmp1,"",0),$D);
393
394 &add($A,$E);
395 &mov($E, &DWP(16,$tmp1,"",0));
396 &add($E,$C);
397 &mov($C, &DWP( 8,$tmp1,"",0));
398 &add($C,$T);
399
400 &mov(&DWP( 0,$tmp1,"",0),$A);
401 &mov("esi",&wparam(1));
402 &mov(&DWP( 8,$tmp1,"",0),$C);
403 &add("esi",64);
404 &mov("eax",&swtmp(17));
405 &mov(&DWP(16,$tmp1,"",0),$E);
406 &cmp("esi","eax");
407 &mov(&DWP( 4,$tmp1,"",0),$B);
408 &jb(&label("start"));
409
410 &stack_pop(18+9);
411 &pop("edi");
412 &pop("ebx");
413 &pop("ebp");
414 &pop("esi");
415 &ret();
416
417 # keep a note of shortcut label so it can be used outside
418 # block.
419 my $sclabel = &label("shortcut");
420
421 &function_end_B($name);
422 # Putting this here avoids problems with MASM in debugging mode
423 &sha1_block_host("sha1_block_asm_host_order", $sclabel);
424 }
425
diff --git a/src/lib/libcrypto/sha/asm/sha1-ia64.pl b/src/lib/libcrypto/sha/asm/sha1-ia64.pl
new file mode 100644
index 0000000000..cb9dfad124
--- /dev/null
+++ b/src/lib/libcrypto/sha/asm/sha1-ia64.pl
@@ -0,0 +1,549 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# Eternal question is what's wrong with compiler generated code? The
10# trick is that it's possible to reduce the number of shifts required
11# to perform rotations by maintaining copy of 32-bit value in upper
12# bits of 64-bit register. Just follow mux2 and shrp instructions...
13# Performance under big-endian OS such as HP-UX is 179MBps*1GHz, which
14# is >50% better than HP C and >2x better than gcc. As of this moment
15# performance under little-endian OS such as Linux and Windows will be
16# a bit lower, because data has to be picked in reverse byte-order.
17# It's possible to resolve this issue by implementing third function,
18# sha1_block_asm_data_order_aligned, which would temporarily flip
19# BE field in User Mask register...
20
21$code=<<___;
22.ident \"sha1-ia64.s, version 1.0\"
23.ident \"IA-64 ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>\"
24.explicit
25
26___
27
28
29if ($^O eq "hpux") {
30 $ADDP="addp4";
31 for (@ARGV) { $ADDP="add" if (/[\+DD|\-mlp]64/); }
32} else { $ADDP="add"; }
33for (@ARGV) { $big_endian=1 if (/\-DB_ENDIAN/);
34 $big_endian=0 if (/\-DL_ENDIAN/); }
35if (!defined($big_endian))
36 { $big_endian=(unpack('L',pack('N',1))==1); }
37
38#$human=1;
39if ($human) { # useful for visual code auditing...
40 ($A,$B,$C,$D,$E,$T) = ("A","B","C","D","E","T");
41 ($h0,$h1,$h2,$h3,$h4) = ("h0","h1","h2","h3","h4");
42 ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
43 ( "K_00_19","K_20_39","K_40_59","K_60_79" );
44 @X= ( "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7",
45 "X8", "X9","X10","X11","X12","X13","X14","X15" );
46}
47else {
48 ($A,$B,$C,$D,$E,$T) = ("loc0","loc1","loc2","loc3","loc4","loc5");
49 ($h0,$h1,$h2,$h3,$h4) = ("loc6","loc7","loc8","loc9","loc10");
50 ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
51 ( "r14", "r15", "loc11", "loc12" );
52 @X= ( "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
53 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" );
54}
55
56sub BODY_00_15 {
57local *code=shift;
58local ($i,$a,$b,$c,$d,$e,$f,$unaligned)=@_;
59
60if ($unaligned) {
61 $code.=<<___;
62{ .mmi; ld1 tmp0=[inp],2 // MSB
63 ld1 tmp1=[tmp3],2 };;
64{ .mmi; ld1 tmp2=[inp],2
65 ld1 $X[$i&0xf]=[tmp3],2 // LSB
66 dep tmp1=tmp0,tmp1,8,8 };;
67{ .mii; cmp.ne p16,p0=r0,r0 // no misaligned prefetch
68 dep $X[$i&0xf]=tmp2,$X[$i&0xf],8,8;;
69 dep $X[$i&0xf]=tmp1,$X[$i&0xf],16,16 };;
70{ .mmi; nop.m 0
71___
72 }
73elsif ($i<15) {
74 $code.=<<___;
75{ .mmi; ld4 $X[($i+1)&0xf]=[inp],4 // prefetch
76___
77 }
78else {
79 $code.=<<___;
80{ .mmi; nop.m 0
81___
82 }
83if ($i<15) {
84 $code.=<<___;
85 and tmp0=$c,$b
86 dep.z tmp5=$a,5,27 } // a<<5
87{ .mmi; andcm tmp1=$d,$b
88 add tmp4=$e,$K_00_19 };;
89{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
90 add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
91 extr.u tmp1=$a,27,5 };; // a>>27
92{ .mib; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
93 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
94{ .mib; or tmp1=tmp1,tmp5 // ROTATE(a,5)
95 mux2 tmp6=$a,0x44 };; // see b in next iteration
96{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
97 mux2 $X[$i&0xf]=$X[$i&0xf],0x44
98 nop.i 0 };;
99
100___
101 }
102else {
103 $code.=<<___;
104 and tmp0=$c,$b
105 dep.z tmp5=$a,5,27 } // a<<5 ;;?
106{ .mmi; andcm tmp1=$d,$b
107 add tmp4=$e,$K_00_19 };;
108{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
109 add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
110 extr.u tmp1=$a,27,5 } // a>>27
111{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
112 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
113 nop.i 0 };;
114{ .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
115 xor tmp2=tmp2,tmp3 // +1
116 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
117{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
118 mux2 tmp6=$a,0x44 };; // see b in next iteration
119{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
120 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
121 mux2 $X[$i&0xf]=$X[$i&0xf],0x44 };;
122
123___
124 }
125}
126
127sub BODY_16_19 {
128local *code=shift;
129local ($i,$a,$b,$c,$d,$e,$f)=@_;
130
131$code.=<<___;
132{ .mmi; mov $X[$i&0xf]=$f // Xupdate
133 and tmp0=$c,$b
134 dep.z tmp5=$a,5,27 } // a<<5
135{ .mmi; andcm tmp1=$d,$b
136 add tmp4=$e,$K_00_19 };;
137{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
138 add $f=$f,tmp4 // f+=e+K_00_19
139 extr.u tmp1=$a,27,5 } // a>>27
140{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
141 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
142 nop.i 0 };;
143{ .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
144 xor tmp2=tmp2,tmp3 // +1
145 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
146{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
147 mux2 tmp6=$a,0x44 };; // see b in next iteration
148{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
149 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
150 nop.i 0 };;
151
152___
153}
154
155sub BODY_20_39 {
156local *code=shift;
157local ($i,$a,$b,$c,$d,$e,$f,$Konst)=@_;
158 $Konst = $K_20_39 if (!defined($Konst));
159
160if ($i<79) {
161$code.=<<___;
162{ .mib; mov $X[$i&0xf]=$f // Xupdate
163 dep.z tmp5=$a,5,27 } // a<<5
164{ .mib; xor tmp0=$c,$b
165 add tmp4=$e,$Konst };;
166{ .mmi; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
167 add $f=$f,tmp4 // f+=e+K_20_39
168 extr.u tmp1=$a,27,5 } // a>>27
169{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
170 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
171 nop.i 0 };;
172{ .mmi; add $f=$f,tmp0 // f+=F_20_39(b,c,d)
173 xor tmp2=tmp2,tmp3 // +1
174 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
175{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
176 mux2 tmp6=$a,0x44 };; // see b in next iteration
177{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
178 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
179 nop.i 0 };;
180
181___
182}
183else {
184$code.=<<___;
185{ .mib; mov $X[$i&0xf]=$f // Xupdate
186 dep.z tmp5=$a,5,27 } // a<<5
187{ .mib; xor tmp0=$c,$b
188 add tmp4=$e,$Konst };;
189{ .mib; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
190 extr.u tmp1=$a,27,5 } // a>>27
191{ .mib; add $f=$f,tmp4 // f+=e+K_20_39
192 add $h1=$h1,$a };; // wrap up
193{ .mmi;
194(p16) ld4.s $X[0]=[inp],4 // non-faulting prefetch
195 add $f=$f,tmp0 // f+=F_20_39(b,c,d)
196 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) ;;?
197{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
198 add $h3=$h3,$c };; // wrap up
199{ .mib; add tmp3=1,inp // used in unaligned codepath
200 add $f=$f,tmp1 } // f+=ROTATE(a,5)
201{ .mib; add $h2=$h2,$b // wrap up
202 add $h4=$h4,$d };; // wrap up
203
204___
205}
206}
207
208sub BODY_40_59 {
209local *code=shift;
210local ($i,$a,$b,$c,$d,$e,$f)=@_;
211
212$code.=<<___;
213{ .mmi; mov $X[$i&0xf]=$f // Xupdate
214 and tmp0=$c,$b
215 dep.z tmp5=$a,5,27 } // a<<5
216{ .mmi; and tmp1=$d,$b
217 add tmp4=$e,$K_40_59 };;
218{ .mmi; or tmp0=tmp0,tmp1 // (b&c)|(b&d)
219 add $f=$f,tmp4 // f+=e+K_40_59
220 extr.u tmp1=$a,27,5 } // a>>27
221{ .mmi; and tmp4=$c,$d
222 xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
223 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
224 };;
225{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
226 xor tmp2=tmp2,tmp3 // +1
227 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
228{ .mmi; or tmp0=tmp0,tmp4 // F_40_59(b,c,d)=(b&c)|(b&d)|(c&d)
229 mux2 tmp6=$a,0x44 };; // see b in next iteration
230{ .mii; add $f=$f,tmp0 // f+=F_40_59(b,c,d)
231 shrp $e=tmp2,tmp2,31;; // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
232 add $f=$f,tmp1 };; // f+=ROTATE(a,5)
233
234___
235}
236sub BODY_60_79 { &BODY_20_39(@_,$K_60_79); }
237
238$code.=<<___;
239.text
240
241tmp0=r8;
242tmp1=r9;
243tmp2=r10;
244tmp3=r11;
245ctx=r32; // in0
246inp=r33; // in1
247
248// void sha1_block_asm_host_order(SHA_CTX *c,const void *p,size_t num);
249.global sha1_block_asm_host_order#
250.proc sha1_block_asm_host_order#
251.align 32
252sha1_block_asm_host_order:
253 .prologue
254 .fframe 0
255 .save ar.pfs,r0
256 .save ar.lc,r3
257{ .mmi; alloc tmp1=ar.pfs,3,15,0,0
258 $ADDP tmp0=4,ctx
259 mov r3=ar.lc }
260{ .mmi; $ADDP ctx=0,ctx
261 $ADDP inp=0,inp
262 mov r2=pr };;
263tmp4=in2;
264tmp5=loc13;
265tmp6=loc14;
266 .body
267{ .mlx; ld4 $h0=[ctx],8
268 movl $K_00_19=0x5a827999 }
269{ .mlx; ld4 $h1=[tmp0],8
270 movl $K_20_39=0x6ed9eba1 };;
271{ .mlx; ld4 $h2=[ctx],8
272 movl $K_40_59=0x8f1bbcdc }
273{ .mlx; ld4 $h3=[tmp0]
274 movl $K_60_79=0xca62c1d6 };;
275{ .mmi; ld4 $h4=[ctx],-16
276 add in2=-1,in2 // adjust num for ar.lc
277 mov ar.ec=1 };;
278{ .mmi; ld4 $X[0]=[inp],4 // prefetch
279 cmp.ne p16,p0=r0,in2 // prefecth at loop end
280 mov ar.lc=in2 };; // brp.loop.imp: too far
281
282.Lhtop:
283{ .mmi; mov $A=$h0
284 mov $B=$h1
285 mux2 tmp6=$h1,0x44 }
286{ .mmi; mov $C=$h2
287 mov $D=$h3
288 mov $E=$h4 };;
289
290___
291
292 &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T);
293 &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E);
294 &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D);
295 &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C);
296 &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B);
297 &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A);
298 &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T);
299 &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E);
300 &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D);
301 &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C);
302 &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B);
303 &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A);
304 &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T);
305 &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E);
306 &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D);
307 &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C);
308
309 &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
310 &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
311 &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
312 &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
313
314 &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
315 &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
316 &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
317 &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
318 &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
319 &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
320 &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
321 &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
322 &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
323 &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
324 &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
325 &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
326 &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
327 &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
328 &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
329 &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
330 &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
331 &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
332 &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
333 &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
334
335 &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
336 &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
337 &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
338 &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
339 &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
340 &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
341 &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
342 &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
343 &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
344 &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
345 &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
346 &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
347 &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
348 &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
349 &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
350 &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
351 &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
352 &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
353 &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
354 &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
355
356 &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
357 &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
358 &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
359 &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
360 &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
361 &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
362 &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
363 &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
364 &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
365 &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
366 &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
367 &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
368 &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
369 &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
370 &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
371 &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
372 &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
373 &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
374 &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
375 &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
376
377$code.=<<___;
378{ .mmb; add $h0=$h0,$E
379 nop.m 0
380 br.ctop.dptk.many .Lhtop };;
381.Lhend:
382{ .mmi; add tmp0=4,ctx
383 mov ar.lc=r3 };;
384{ .mmi; st4 [ctx]=$h0,8
385 st4 [tmp0]=$h1,8 };;
386{ .mmi; st4 [ctx]=$h2,8
387 st4 [tmp0]=$h3 };;
388{ .mib; st4 [ctx]=$h4,-16
389 mov pr=r2,0x1ffff
390 br.ret.sptk.many b0 };;
391.endp sha1_block_asm_host_order#
392___
393
394
395$code.=<<___;
396// void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num);
397.global sha1_block_asm_data_order#
398.proc sha1_block_asm_data_order#
399.align 32
400sha1_block_asm_data_order:
401___
402$code.=<<___ if ($big_endian);
403{ .mmi; and r2=3,inp };;
404{ .mib; cmp.eq p6,p0=r0,r2
405(p6) br.dptk.many sha1_block_asm_host_order };;
406___
407$code.=<<___;
408 .prologue
409 .fframe 0
410 .save ar.pfs,r0
411 .save ar.lc,r3
412{ .mmi; alloc tmp1=ar.pfs,3,15,0,0
413 $ADDP tmp0=4,ctx
414 mov r3=ar.lc }
415{ .mmi; $ADDP ctx=0,ctx
416 $ADDP inp=0,inp
417 mov r2=pr };;
418tmp4=in2;
419tmp5=loc13;
420tmp6=loc14;
421 .body
422{ .mlx; ld4 $h0=[ctx],8
423 movl $K_00_19=0x5a827999 }
424{ .mlx; ld4 $h1=[tmp0],8
425 movl $K_20_39=0x6ed9eba1 };;
426{ .mlx; ld4 $h2=[ctx],8
427 movl $K_40_59=0x8f1bbcdc }
428{ .mlx; ld4 $h3=[tmp0]
429 movl $K_60_79=0xca62c1d6 };;
430{ .mmi; ld4 $h4=[ctx],-16
431 add in2=-1,in2 // adjust num for ar.lc
432 mov ar.ec=1 };;
433{ .mmi; nop.m 0
434 add tmp3=1,inp
435 mov ar.lc=in2 };; // brp.loop.imp: too far
436
437.Ldtop:
438{ .mmi; mov $A=$h0
439 mov $B=$h1
440 mux2 tmp6=$h1,0x44 }
441{ .mmi; mov $C=$h2
442 mov $D=$h3
443 mov $E=$h4 };;
444
445___
446
447 &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T,1);
448 &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E,1);
449 &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D,1);
450 &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C,1);
451 &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B,1);
452 &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A,1);
453 &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T,1);
454 &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E,1);
455 &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D,1);
456 &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C,1);
457 &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B,1);
458 &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A,1);
459 &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T,1);
460 &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E,1);
461 &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D,1);
462 &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C,1);
463
464 &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
465 &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
466 &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
467 &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
468
469 &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
470 &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
471 &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
472 &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
473 &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
474 &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
475 &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
476 &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
477 &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
478 &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
479 &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
480 &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
481 &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
482 &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
483 &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
484 &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
485 &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
486 &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
487 &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
488 &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
489
490 &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
491 &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
492 &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
493 &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
494 &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
495 &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
496 &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
497 &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
498 &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
499 &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
500 &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
501 &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
502 &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
503 &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
504 &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
505 &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
506 &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
507 &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
508 &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
509 &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
510
511 &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
512 &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
513 &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
514 &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
515 &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
516 &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
517 &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
518 &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
519 &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
520 &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
521 &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
522 &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
523 &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
524 &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
525 &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
526 &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
527 &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
528 &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
529 &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
530 &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
531
532$code.=<<___;
533{ .mmb; add $h0=$h0,$E
534 nop.m 0
535 br.ctop.dptk.many .Ldtop };;
536.Ldend:
537{ .mmi; add tmp0=4,ctx
538 mov ar.lc=r3 };;
539{ .mmi; st4 [ctx]=$h0,8
540 st4 [tmp0]=$h1,8 };;
541{ .mmi; st4 [ctx]=$h2,8
542 st4 [tmp0]=$h3 };;
543{ .mib; st4 [ctx]=$h4,-16
544 mov pr=r2,0x1ffff
545 br.ret.sptk.many b0 };;
546.endp sha1_block_asm_data_order#
547___
548
549print $code;
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
new file mode 100644
index 0000000000..79c07b0fd1
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha.h
@@ -0,0 +1,128 @@
1/* crypto/sha/sha.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_SHA_H
60#define HEADER_SHA_H
61
62#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
69#error SHA is disabled.
70#endif
71
72#if defined(OPENSSL_FIPS)
73#define FIPS_SHA_SIZE_T unsigned long
74#endif
75
76/*
77 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
79 * ! SHA_LONG_LOG2 has to be defined along. !
80 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
81 */
82
83#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
84#define SHA_LONG unsigned long
85#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
86#define SHA_LONG unsigned long
87#define SHA_LONG_LOG2 3
88#else
89#define SHA_LONG unsigned int
90#endif
91
92#define SHA_LBLOCK 16
93#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
94 * contiguous array of 32 bit
95 * wide big-endian values. */
96#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
97#define SHA_DIGEST_LENGTH 20
98
99typedef struct SHAstate_st
100 {
101 SHA_LONG h0,h1,h2,h3,h4;
102 SHA_LONG Nl,Nh;
103 SHA_LONG data[SHA_LBLOCK];
104 int num;
105 } SHA_CTX;
106
107#ifndef OPENSSL_NO_SHA0
108#ifdef OPENSSL_FIPS
109int private_SHA_Init(SHA_CTX *c);
110#endif
111int SHA_Init(SHA_CTX *c);
112int SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
113int SHA_Final(unsigned char *md, SHA_CTX *c);
114unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
115void SHA_Transform(SHA_CTX *c, const unsigned char *data);
116#endif
117#ifndef OPENSSL_NO_SHA1
118int SHA1_Init(SHA_CTX *c);
119int SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
120int SHA1_Final(unsigned char *md, SHA_CTX *c);
121unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
122void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
123#endif
124#ifdef __cplusplus
125}
126#endif
127
128#endif
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c
new file mode 100644
index 0000000000..20e660c71d
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1_one.c
@@ -0,0 +1,77 @@
1/* crypto/sha/sha1_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/sha.h>
62#include <openssl/crypto.h>
63
64#ifndef OPENSSL_NO_SHA1
65unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)
66 {
67 SHA_CTX c;
68 static unsigned char m[SHA_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 SHA1_Init(&c);
72 SHA1_Update(&c,d,n);
73 SHA1_Final(md,&c);
74 OPENSSL_cleanse(&c,sizeof(c));
75 return(md);
76 }
77#endif
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c
new file mode 100644
index 0000000000..1e2009b760
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1dgst.c
@@ -0,0 +1,81 @@
1/* crypto/sha/sha1dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA)
60
61#undef SHA_0
62#define SHA_1
63
64#include <openssl/opensslv.h>
65#include <openssl/opensslconf.h>
66
67#ifndef OPENSSL_FIPS
68const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
69
70/* The implementation is in ../md32_common.h */
71
72#include "sha_locl.h"
73
74#else /* ndef OPENSSL_FIPS */
75
76static void *dummy=&dummy;
77
78#endif /* ndef OPENSSL_FIPS */
79
80#endif
81
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
new file mode 100644
index 0000000000..a3623f72da
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha_locl.h
@@ -0,0 +1,481 @@
1/* crypto/sha/sha_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61
62#include <openssl/opensslconf.h>
63#include <openssl/sha.h>
64
65#ifndef SHA_LONG_LOG2
66#define SHA_LONG_LOG2 2 /* default to 32 bits */
67#endif
68
69#define DATA_ORDER_IS_BIG_ENDIAN
70
71#define HASH_LONG SHA_LONG
72#define HASH_LONG_LOG2 SHA_LONG_LOG2
73#define HASH_CTX SHA_CTX
74#define HASH_CBLOCK SHA_CBLOCK
75#define HASH_LBLOCK SHA_LBLOCK
76#define HASH_MAKE_STRING(c,s) do { \
77 unsigned long ll; \
78 ll=(c)->h0; HOST_l2c(ll,(s)); \
79 ll=(c)->h1; HOST_l2c(ll,(s)); \
80 ll=(c)->h2; HOST_l2c(ll,(s)); \
81 ll=(c)->h3; HOST_l2c(ll,(s)); \
82 ll=(c)->h4; HOST_l2c(ll,(s)); \
83 } while (0)
84
85#if defined(SHA_0)
86
87# define HASH_UPDATE SHA_Update
88# define HASH_TRANSFORM SHA_Transform
89# define HASH_FINAL SHA_Final
90# define HASH_INIT SHA_Init
91# define HASH_BLOCK_HOST_ORDER sha_block_host_order
92# define HASH_BLOCK_DATA_ORDER sha_block_data_order
93# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id))
94
95 void sha_block_host_order (SHA_CTX *c, const void *p,int num);
96 void sha_block_data_order (SHA_CTX *c, const void *p,int num);
97
98#elif defined(SHA_1)
99
100# define HASH_UPDATE SHA1_Update
101# define HASH_TRANSFORM SHA1_Transform
102# define HASH_FINAL SHA1_Final
103# define HASH_INIT SHA1_Init
104# define HASH_BLOCK_HOST_ORDER sha1_block_host_order
105# define HASH_BLOCK_DATA_ORDER sha1_block_data_order
106# if defined(__MWERKS__) && defined(__MC68K__)
107 /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
108# define Xupdate(a,ix,ia,ib,ic,id) do { (a)=(ia^ib^ic^id); \
109 ix=(a)=ROTATE((a),1); \
110 } while (0)
111# else
112# define Xupdate(a,ix,ia,ib,ic,id) ( (a)=(ia^ib^ic^id), \
113 ix=(a)=ROTATE((a),1) \
114 )
115# endif
116
117# ifdef SHA1_ASM
118# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
119# define sha1_block_host_order sha1_block_asm_host_order
120# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
121# define sha1_block_data_order sha1_block_asm_data_order
122# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
123# define HASH_BLOCK_DATA_ORDER_ALIGNED sha1_block_asm_data_order
124# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
125# define sha1_block_host_order sha1_block_asm_host_order
126# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
127# define sha1_block_data_order sha1_block_asm_data_order
128# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
129# endif
130# endif
131 void sha1_block_host_order (SHA_CTX *c, const void *p,int num);
132 void sha1_block_data_order (SHA_CTX *c, const void *p,int num);
133
134#else
135# error "Either SHA_0 or SHA_1 must be defined."
136#endif
137
138#include "md32_common.h"
139
140#define INIT_DATA_h0 0x67452301UL
141#define INIT_DATA_h1 0xefcdab89UL
142#define INIT_DATA_h2 0x98badcfeUL
143#define INIT_DATA_h3 0x10325476UL
144#define INIT_DATA_h4 0xc3d2e1f0UL
145
146#if defined(SHA_0) && defined(OPENSSL_FIPS)
147FIPS_NON_FIPS_MD_Init(SHA)
148#else
149int HASH_INIT (SHA_CTX *c)
150#endif
151 {
152 c->h0=INIT_DATA_h0;
153 c->h1=INIT_DATA_h1;
154 c->h2=INIT_DATA_h2;
155 c->h3=INIT_DATA_h3;
156 c->h4=INIT_DATA_h4;
157 c->Nl=0;
158 c->Nh=0;
159 c->num=0;
160 return 1;
161 }
162
163#define K_00_19 0x5a827999UL
164#define K_20_39 0x6ed9eba1UL
165#define K_40_59 0x8f1bbcdcUL
166#define K_60_79 0xca62c1d6UL
167
168/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
169 * simplified to the code in F_00_19. Wei attributes these optimisations
170 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
171 * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
172 * I've just become aware of another tweak to be made, again from Wei Dai,
173 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
174 */
175#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
176#define F_20_39(b,c,d) ((b) ^ (c) ^ (d))
177#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
178#define F_60_79(b,c,d) F_20_39(b,c,d)
179
180#define BODY_00_15(i,a,b,c,d,e,f,xi) \
181 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
182 (b)=ROTATE((b),30);
183
184#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
185 Xupdate(f,xi,xa,xb,xc,xd); \
186 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
187 (b)=ROTATE((b),30);
188
189#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
190 Xupdate(f,xi,xa,xb,xc,xd); \
191 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
192 (b)=ROTATE((b),30);
193
194#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \
195 Xupdate(f,xa,xa,xb,xc,xd); \
196 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
197 (b)=ROTATE((b),30);
198
199#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \
200 Xupdate(f,xa,xa,xb,xc,xd); \
201 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
202 (b)=ROTATE((b),30);
203
204#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \
205 Xupdate(f,xa,xa,xb,xc,xd); \
206 (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
207 (b)=ROTATE((b),30);
208
209#ifdef X
210#undef X
211#endif
212#ifndef MD32_XARRAY
213 /*
214 * Originally X was an array. As it's automatic it's natural
215 * to expect RISC compiler to accomodate at least part of it in
216 * the register bank, isn't it? Unfortunately not all compilers
217 * "find" this expectation reasonable:-( On order to make such
218 * compilers generate better code I replace X[] with a bunch of
219 * X0, X1, etc. See the function body below...
220 * <appro@fy.chalmers.se>
221 */
222# define X(i) XX##i
223#else
224 /*
225 * However! Some compilers (most notably HP C) get overwhelmed by
226 * that many local variables so that we have to have the way to
227 * fall down to the original behavior.
228 */
229# define X(i) XX[i]
230#endif
231
232#ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
233void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
234 {
235 const SHA_LONG *W=d;
236 register unsigned MD32_REG_T A,B,C,D,E,T;
237#ifndef MD32_XARRAY
238 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
239 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
240#else
241 SHA_LONG XX[16];
242#endif
243
244 A=c->h0;
245 B=c->h1;
246 C=c->h2;
247 D=c->h3;
248 E=c->h4;
249
250 for (;;)
251 {
252 BODY_00_15( 0,A,B,C,D,E,T,W[ 0]);
253 BODY_00_15( 1,T,A,B,C,D,E,W[ 1]);
254 BODY_00_15( 2,E,T,A,B,C,D,W[ 2]);
255 BODY_00_15( 3,D,E,T,A,B,C,W[ 3]);
256 BODY_00_15( 4,C,D,E,T,A,B,W[ 4]);
257 BODY_00_15( 5,B,C,D,E,T,A,W[ 5]);
258 BODY_00_15( 6,A,B,C,D,E,T,W[ 6]);
259 BODY_00_15( 7,T,A,B,C,D,E,W[ 7]);
260 BODY_00_15( 8,E,T,A,B,C,D,W[ 8]);
261 BODY_00_15( 9,D,E,T,A,B,C,W[ 9]);
262 BODY_00_15(10,C,D,E,T,A,B,W[10]);
263 BODY_00_15(11,B,C,D,E,T,A,W[11]);
264 BODY_00_15(12,A,B,C,D,E,T,W[12]);
265 BODY_00_15(13,T,A,B,C,D,E,W[13]);
266 BODY_00_15(14,E,T,A,B,C,D,W[14]);
267 BODY_00_15(15,D,E,T,A,B,C,W[15]);
268
269 BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]);
270 BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]);
271 BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]);
272 BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0));
273
274 BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1));
275 BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2));
276 BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3));
277 BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4));
278 BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5));
279 BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6));
280 BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7));
281 BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8));
282 BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9));
283 BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10));
284 BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11));
285 BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12));
286
287 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
288 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
289 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
290 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
291 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
292 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
293 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
294 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
295
296 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
297 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
298 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
299 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
300 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
301 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
302 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
303 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
304 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
305 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
306 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
307 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
308 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
309 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
310 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
311 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
312 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
313 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
314 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
315 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
316
317 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
318 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
319 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
320 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
321 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
322 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
323 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
324 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
325 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
326 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
327 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
328 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
329 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
330 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
331 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
332 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
333 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
334 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
335 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
336 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
337
338 c->h0=(c->h0+E)&0xffffffffL;
339 c->h1=(c->h1+T)&0xffffffffL;
340 c->h2=(c->h2+A)&0xffffffffL;
341 c->h3=(c->h3+B)&0xffffffffL;
342 c->h4=(c->h4+C)&0xffffffffL;
343
344 if (--num <= 0) break;
345
346 A=c->h0;
347 B=c->h1;
348 C=c->h2;
349 D=c->h3;
350 E=c->h4;
351
352 W+=SHA_LBLOCK;
353 }
354 }
355#endif
356
357#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER
358void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
359 {
360 const unsigned char *data=p;
361 register unsigned MD32_REG_T A,B,C,D,E,T,l;
362#ifndef MD32_XARRAY
363 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
364 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
365#else
366 SHA_LONG XX[16];
367#endif
368
369 A=c->h0;
370 B=c->h1;
371 C=c->h2;
372 D=c->h3;
373 E=c->h4;
374
375 for (;;)
376 {
377
378 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
379 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l;
380 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l;
381 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l;
382 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l;
383 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l;
384 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l;
385 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l;
386 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l;
387 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l;
388 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l;
389 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l;
390 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l;
391 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l;
392 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l;
393 BODY_00_15(14,E,T,A,B,C,D,X(14));
394 BODY_00_15(15,D,E,T,A,B,C,X(15));
395
396 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
397 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
398 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
399 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
400
401 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
402 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
403 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
404 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
405 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
406 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
407 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
408 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
409 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
410 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
411 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
412 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
413
414 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
415 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
416 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
417 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
418 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
419 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
420 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
421 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
422
423 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
424 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
425 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
426 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
427 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
428 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
429 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
430 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
431 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
432 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
433 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
434 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
435 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
436 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
437 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
438 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
439 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
440 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
441 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
442 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
443
444 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
445 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
446 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
447 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
448 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
449 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
450 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
451 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
452 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
453 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
454 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
455 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
456 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
457 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
458 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
459 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
460 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
461 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
462 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
463 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
464
465 c->h0=(c->h0+E)&0xffffffffL;
466 c->h1=(c->h1+T)&0xffffffffL;
467 c->h2=(c->h2+A)&0xffffffffL;
468 c->h3=(c->h3+B)&0xffffffffL;
469 c->h4=(c->h4+C)&0xffffffffL;
470
471 if (--num <= 0) break;
472
473 A=c->h0;
474 B=c->h1;
475 C=c->h2;
476 D=c->h3;
477 E=c->h4;
478
479 }
480 }
481#endif
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c
index d4f4d344df..e61c63f3e9 100644
--- a/src/lib/libcrypto/sha/sha_one.c
+++ b/src/lib/libcrypto/sha/sha_one.c
@@ -68,8 +68,7 @@ unsigned char *SHA(const unsigned char *d, unsigned long n, unsigned char *md)
68 static unsigned char m[SHA_DIGEST_LENGTH]; 68 static unsigned char m[SHA_DIGEST_LENGTH];
69 69
70 if (md == NULL) md=m; 70 if (md == NULL) md=m;
71 if (!SHA_Init(&c)) 71 SHA_Init(&c);
72 return NULL;
73 SHA_Update(&c,d,n); 72 SHA_Update(&c,d,n);
74 SHA_Final(md,&c); 73 SHA_Final(md,&c);
75 OPENSSL_cleanse(&c,sizeof(c)); 74 OPENSSL_cleanse(&c,sizeof(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
new file mode 100644
index 0000000000..bd1121c279
--- /dev/null
+++ b/src/lib/libcrypto/stack/safestack.h
@@ -0,0 +1,1571 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SAFESTACK_H
56#define HEADER_SAFESTACK_H
57
58#include <openssl/stack.h>
59
60#ifdef DEBUG_SAFESTACK
61
62#define STACK_OF(type) struct stack_st_##type
63#define PREDECLARE_STACK_OF(type) STACK_OF(type);
64
65#define DECLARE_STACK_OF(type) \
66STACK_OF(type) \
67 { \
68 STACK stack; \
69 };
70
71#define IMPLEMENT_STACK_OF(type) /* nada (obsolete in new safestack approach)*/
72
73/* SKM_sk_... stack macros are internal to safestack.h:
74 * never use them directly, use sk_<type>_... instead */
75#define SKM_sk_new(type, cmp) \
76 ((STACK_OF(type) * (*)(int (*)(const type * const *, const type * const *)))sk_new)(cmp)
77#define SKM_sk_new_null(type) \
78 ((STACK_OF(type) * (*)(void))sk_new_null)()
79#define SKM_sk_free(type, st) \
80 ((void (*)(STACK_OF(type) *))sk_free)(st)
81#define SKM_sk_num(type, st) \
82 ((int (*)(const STACK_OF(type) *))sk_num)(st)
83#define SKM_sk_value(type, st,i) \
84 ((type * (*)(const STACK_OF(type) *, int))sk_value)(st, i)
85#define SKM_sk_set(type, st,i,val) \
86 ((type * (*)(STACK_OF(type) *, int, type *))sk_set)(st, i, val)
87#define SKM_sk_zero(type, st) \
88 ((void (*)(STACK_OF(type) *))sk_zero)(st)
89#define SKM_sk_push(type, st,val) \
90 ((int (*)(STACK_OF(type) *, type *))sk_push)(st, val)
91#define SKM_sk_unshift(type, st,val) \
92 ((int (*)(STACK_OF(type) *, type *))sk_unshift)(st, val)
93#define SKM_sk_find(type, st,val) \
94 ((int (*)(STACK_OF(type) *, type *))sk_find)(st, val)
95#define SKM_sk_delete(type, st,i) \
96 ((type * (*)(STACK_OF(type) *, int))sk_delete)(st, i)
97#define SKM_sk_delete_ptr(type, st,ptr) \
98 ((type * (*)(STACK_OF(type) *, type *))sk_delete_ptr)(st, ptr)
99#define SKM_sk_insert(type, st,val,i) \
100 ((int (*)(STACK_OF(type) *, type *, int))sk_insert)(st, val, i)
101#define SKM_sk_set_cmp_func(type, st,cmp) \
102 ((int (*(*)(STACK_OF(type) *, int (*)(const type * const *, const type * const *))) \
103 (const type * const *, const type * const *))sk_set_cmp_func)\
104 (st, cmp)
105#define SKM_sk_dup(type, st) \
106 ((STACK_OF(type) *(*)(STACK_OF(type) *))sk_dup)(st)
107#define SKM_sk_pop_free(type, st,free_func) \
108 ((void (*)(STACK_OF(type) *, void (*)(type *)))sk_pop_free)\
109 (st, free_func)
110#define SKM_sk_shift(type, st) \
111 ((type * (*)(STACK_OF(type) *))sk_shift)(st)
112#define SKM_sk_pop(type, st) \
113 ((type * (*)(STACK_OF(type) *))sk_pop)(st)
114#define SKM_sk_sort(type, st) \
115 ((void (*)(STACK_OF(type) *))sk_sort)(st)
116#define SKM_sk_is_sorted(type, st) \
117 ((int (*)(const STACK_OF(type) *))sk_is_sorted)(st)
118
119#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
120 ((STACK_OF(type) * (*) (STACK_OF(type) **,unsigned char **, long , \
121 type *(*)(type **, unsigned char **,long), \
122 void (*)(type *), int ,int )) d2i_ASN1_SET) \
123 (st,pp,length, d2i_func, free_func, ex_tag,ex_class)
124#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
125 ((int (*)(STACK_OF(type) *,unsigned char **, \
126 int (*)(type *,unsigned char **), int , int , int)) i2d_ASN1_SET) \
127 (st,pp,i2d_func,ex_tag,ex_class,is_set)
128
129#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
130 ((unsigned char *(*)(STACK_OF(type) *, \
131 int (*)(type *,unsigned char **), unsigned char **,int *)) ASN1_seq_pack) \
132 (st, i2d_func, buf, len)
133#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
134 ((STACK_OF(type) * (*)(unsigned char *,int, \
135 type *(*)(type **,unsigned char **, long), \
136 void (*)(type *)))ASN1_seq_unpack) \
137 (buf,len,d2i_func, free_func)
138
139#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
140 ((STACK_OF(type) * (*)(X509_ALGOR *, \
141 type *(*)(type **, unsigned char **, long), void (*)(type *), \
142 const char *, int, \
143 ASN1_STRING *, int))PKCS12_decrypt_d2i) \
144 (algor,d2i_func,free_func,pass,passlen,oct,seq)
145
146#else
147
148#define STACK_OF(type) STACK
149#define PREDECLARE_STACK_OF(type) /* nada */
150#define DECLARE_STACK_OF(type) /* nada */
151#define IMPLEMENT_STACK_OF(type) /* nada */
152
153#define SKM_sk_new(type, cmp) \
154 sk_new((int (*)(const char * const *, const char * const *))(cmp))
155#define SKM_sk_new_null(type) \
156 sk_new_null()
157#define SKM_sk_free(type, st) \
158 sk_free(st)
159#define SKM_sk_num(type, st) \
160 sk_num(st)
161#define SKM_sk_value(type, st,i) \
162 ((type *)sk_value(st, i))
163#define SKM_sk_set(type, st,i,val) \
164 ((type *)sk_set(st, i,(char *)val))
165#define SKM_sk_zero(type, st) \
166 sk_zero(st)
167#define SKM_sk_push(type, st,val) \
168 sk_push(st, (char *)val)
169#define SKM_sk_unshift(type, st,val) \
170 sk_unshift(st, val)
171#define SKM_sk_find(type, st,val) \
172 sk_find(st, (char *)val)
173#define SKM_sk_delete(type, st,i) \
174 ((type *)sk_delete(st, i))
175#define SKM_sk_delete_ptr(type, st,ptr) \
176 ((type *)sk_delete_ptr(st,(char *)ptr))
177#define SKM_sk_insert(type, st,val,i) \
178 sk_insert(st, (char *)val, i)
179#define SKM_sk_set_cmp_func(type, st,cmp) \
180 ((int (*)(const type * const *,const type * const *)) \
181 sk_set_cmp_func(st, (int (*)(const char * const *, const char * const *))(cmp)))
182#define SKM_sk_dup(type, st) \
183 sk_dup(st)
184#define SKM_sk_pop_free(type, st,free_func) \
185 sk_pop_free(st, (void (*)(void *))free_func)
186#define SKM_sk_shift(type, st) \
187 ((type *)sk_shift(st))
188#define SKM_sk_pop(type, st) \
189 ((type *)sk_pop(st))
190#define SKM_sk_sort(type, st) \
191 sk_sort(st)
192#define SKM_sk_is_sorted(type, st) \
193 sk_is_sorted(st)
194
195#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
196 d2i_ASN1_SET(st,pp,length, (char *(*)())d2i_func, (void (*)(void *))free_func, ex_tag,ex_class)
197#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
198 i2d_ASN1_SET(st,pp,i2d_func,ex_tag,ex_class,is_set)
199
200#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
201 ASN1_seq_pack(st, i2d_func, buf, len)
202#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
203 ASN1_seq_unpack(buf,len,(char *(*)())d2i_func, (void(*)(void *))free_func)
204
205#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
206 ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq))
207
208#endif
209
210/* This block of defines is updated by util/mkstack.pl, please do not touch! */
211#define sk_ACCESS_DESCRIPTION_new(st) SKM_sk_new(ACCESS_DESCRIPTION, (st))
212#define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION)
213#define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st))
214#define sk_ACCESS_DESCRIPTION_num(st) SKM_sk_num(ACCESS_DESCRIPTION, (st))
215#define sk_ACCESS_DESCRIPTION_value(st, i) SKM_sk_value(ACCESS_DESCRIPTION, (st), (i))
216#define sk_ACCESS_DESCRIPTION_set(st, i, val) SKM_sk_set(ACCESS_DESCRIPTION, (st), (i), (val))
217#define sk_ACCESS_DESCRIPTION_zero(st) SKM_sk_zero(ACCESS_DESCRIPTION, (st))
218#define sk_ACCESS_DESCRIPTION_push(st, val) SKM_sk_push(ACCESS_DESCRIPTION, (st), (val))
219#define sk_ACCESS_DESCRIPTION_unshift(st, val) SKM_sk_unshift(ACCESS_DESCRIPTION, (st), (val))
220#define sk_ACCESS_DESCRIPTION_find(st, val) SKM_sk_find(ACCESS_DESCRIPTION, (st), (val))
221#define sk_ACCESS_DESCRIPTION_delete(st, i) SKM_sk_delete(ACCESS_DESCRIPTION, (st), (i))
222#define sk_ACCESS_DESCRIPTION_delete_ptr(st, ptr) SKM_sk_delete_ptr(ACCESS_DESCRIPTION, (st), (ptr))
223#define sk_ACCESS_DESCRIPTION_insert(st, val, i) SKM_sk_insert(ACCESS_DESCRIPTION, (st), (val), (i))
224#define sk_ACCESS_DESCRIPTION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ACCESS_DESCRIPTION, (st), (cmp))
225#define sk_ACCESS_DESCRIPTION_dup(st) SKM_sk_dup(ACCESS_DESCRIPTION, st)
226#define sk_ACCESS_DESCRIPTION_pop_free(st, free_func) SKM_sk_pop_free(ACCESS_DESCRIPTION, (st), (free_func))
227#define sk_ACCESS_DESCRIPTION_shift(st) SKM_sk_shift(ACCESS_DESCRIPTION, (st))
228#define sk_ACCESS_DESCRIPTION_pop(st) SKM_sk_pop(ACCESS_DESCRIPTION, (st))
229#define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st))
230#define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st))
231
232#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st))
233#define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING)
234#define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st))
235#define sk_ASN1_GENERALSTRING_num(st) SKM_sk_num(ASN1_GENERALSTRING, (st))
236#define sk_ASN1_GENERALSTRING_value(st, i) SKM_sk_value(ASN1_GENERALSTRING, (st), (i))
237#define sk_ASN1_GENERALSTRING_set(st, i, val) SKM_sk_set(ASN1_GENERALSTRING, (st), (i), (val))
238#define sk_ASN1_GENERALSTRING_zero(st) SKM_sk_zero(ASN1_GENERALSTRING, (st))
239#define sk_ASN1_GENERALSTRING_push(st, val) SKM_sk_push(ASN1_GENERALSTRING, (st), (val))
240#define sk_ASN1_GENERALSTRING_unshift(st, val) SKM_sk_unshift(ASN1_GENERALSTRING, (st), (val))
241#define sk_ASN1_GENERALSTRING_find(st, val) SKM_sk_find(ASN1_GENERALSTRING, (st), (val))
242#define sk_ASN1_GENERALSTRING_delete(st, i) SKM_sk_delete(ASN1_GENERALSTRING, (st), (i))
243#define sk_ASN1_GENERALSTRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_GENERALSTRING, (st), (ptr))
244#define sk_ASN1_GENERALSTRING_insert(st, val, i) SKM_sk_insert(ASN1_GENERALSTRING, (st), (val), (i))
245#define sk_ASN1_GENERALSTRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_GENERALSTRING, (st), (cmp))
246#define sk_ASN1_GENERALSTRING_dup(st) SKM_sk_dup(ASN1_GENERALSTRING, st)
247#define sk_ASN1_GENERALSTRING_pop_free(st, free_func) SKM_sk_pop_free(ASN1_GENERALSTRING, (st), (free_func))
248#define sk_ASN1_GENERALSTRING_shift(st) SKM_sk_shift(ASN1_GENERALSTRING, (st))
249#define sk_ASN1_GENERALSTRING_pop(st) SKM_sk_pop(ASN1_GENERALSTRING, (st))
250#define sk_ASN1_GENERALSTRING_sort(st) SKM_sk_sort(ASN1_GENERALSTRING, (st))
251#define sk_ASN1_GENERALSTRING_is_sorted(st) SKM_sk_is_sorted(ASN1_GENERALSTRING, (st))
252
253#define sk_ASN1_INTEGER_new(st) SKM_sk_new(ASN1_INTEGER, (st))
254#define sk_ASN1_INTEGER_new_null() SKM_sk_new_null(ASN1_INTEGER)
255#define sk_ASN1_INTEGER_free(st) SKM_sk_free(ASN1_INTEGER, (st))
256#define sk_ASN1_INTEGER_num(st) SKM_sk_num(ASN1_INTEGER, (st))
257#define sk_ASN1_INTEGER_value(st, i) SKM_sk_value(ASN1_INTEGER, (st), (i))
258#define sk_ASN1_INTEGER_set(st, i, val) SKM_sk_set(ASN1_INTEGER, (st), (i), (val))
259#define sk_ASN1_INTEGER_zero(st) SKM_sk_zero(ASN1_INTEGER, (st))
260#define sk_ASN1_INTEGER_push(st, val) SKM_sk_push(ASN1_INTEGER, (st), (val))
261#define sk_ASN1_INTEGER_unshift(st, val) SKM_sk_unshift(ASN1_INTEGER, (st), (val))
262#define sk_ASN1_INTEGER_find(st, val) SKM_sk_find(ASN1_INTEGER, (st), (val))
263#define sk_ASN1_INTEGER_delete(st, i) SKM_sk_delete(ASN1_INTEGER, (st), (i))
264#define sk_ASN1_INTEGER_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_INTEGER, (st), (ptr))
265#define sk_ASN1_INTEGER_insert(st, val, i) SKM_sk_insert(ASN1_INTEGER, (st), (val), (i))
266#define sk_ASN1_INTEGER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_INTEGER, (st), (cmp))
267#define sk_ASN1_INTEGER_dup(st) SKM_sk_dup(ASN1_INTEGER, st)
268#define sk_ASN1_INTEGER_pop_free(st, free_func) SKM_sk_pop_free(ASN1_INTEGER, (st), (free_func))
269#define sk_ASN1_INTEGER_shift(st) SKM_sk_shift(ASN1_INTEGER, (st))
270#define sk_ASN1_INTEGER_pop(st) SKM_sk_pop(ASN1_INTEGER, (st))
271#define sk_ASN1_INTEGER_sort(st) SKM_sk_sort(ASN1_INTEGER, (st))
272#define sk_ASN1_INTEGER_is_sorted(st) SKM_sk_is_sorted(ASN1_INTEGER, (st))
273
274#define sk_ASN1_OBJECT_new(st) SKM_sk_new(ASN1_OBJECT, (st))
275#define sk_ASN1_OBJECT_new_null() SKM_sk_new_null(ASN1_OBJECT)
276#define sk_ASN1_OBJECT_free(st) SKM_sk_free(ASN1_OBJECT, (st))
277#define sk_ASN1_OBJECT_num(st) SKM_sk_num(ASN1_OBJECT, (st))
278#define sk_ASN1_OBJECT_value(st, i) SKM_sk_value(ASN1_OBJECT, (st), (i))
279#define sk_ASN1_OBJECT_set(st, i, val) SKM_sk_set(ASN1_OBJECT, (st), (i), (val))
280#define sk_ASN1_OBJECT_zero(st) SKM_sk_zero(ASN1_OBJECT, (st))
281#define sk_ASN1_OBJECT_push(st, val) SKM_sk_push(ASN1_OBJECT, (st), (val))
282#define sk_ASN1_OBJECT_unshift(st, val) SKM_sk_unshift(ASN1_OBJECT, (st), (val))
283#define sk_ASN1_OBJECT_find(st, val) SKM_sk_find(ASN1_OBJECT, (st), (val))
284#define sk_ASN1_OBJECT_delete(st, i) SKM_sk_delete(ASN1_OBJECT, (st), (i))
285#define sk_ASN1_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_OBJECT, (st), (ptr))
286#define sk_ASN1_OBJECT_insert(st, val, i) SKM_sk_insert(ASN1_OBJECT, (st), (val), (i))
287#define sk_ASN1_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_OBJECT, (st), (cmp))
288#define sk_ASN1_OBJECT_dup(st) SKM_sk_dup(ASN1_OBJECT, st)
289#define sk_ASN1_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(ASN1_OBJECT, (st), (free_func))
290#define sk_ASN1_OBJECT_shift(st) SKM_sk_shift(ASN1_OBJECT, (st))
291#define sk_ASN1_OBJECT_pop(st) SKM_sk_pop(ASN1_OBJECT, (st))
292#define sk_ASN1_OBJECT_sort(st) SKM_sk_sort(ASN1_OBJECT, (st))
293#define sk_ASN1_OBJECT_is_sorted(st) SKM_sk_is_sorted(ASN1_OBJECT, (st))
294
295#define sk_ASN1_STRING_TABLE_new(st) SKM_sk_new(ASN1_STRING_TABLE, (st))
296#define sk_ASN1_STRING_TABLE_new_null() SKM_sk_new_null(ASN1_STRING_TABLE)
297#define sk_ASN1_STRING_TABLE_free(st) SKM_sk_free(ASN1_STRING_TABLE, (st))
298#define sk_ASN1_STRING_TABLE_num(st) SKM_sk_num(ASN1_STRING_TABLE, (st))
299#define sk_ASN1_STRING_TABLE_value(st, i) SKM_sk_value(ASN1_STRING_TABLE, (st), (i))
300#define sk_ASN1_STRING_TABLE_set(st, i, val) SKM_sk_set(ASN1_STRING_TABLE, (st), (i), (val))
301#define sk_ASN1_STRING_TABLE_zero(st) SKM_sk_zero(ASN1_STRING_TABLE, (st))
302#define sk_ASN1_STRING_TABLE_push(st, val) SKM_sk_push(ASN1_STRING_TABLE, (st), (val))
303#define sk_ASN1_STRING_TABLE_unshift(st, val) SKM_sk_unshift(ASN1_STRING_TABLE, (st), (val))
304#define sk_ASN1_STRING_TABLE_find(st, val) SKM_sk_find(ASN1_STRING_TABLE, (st), (val))
305#define sk_ASN1_STRING_TABLE_delete(st, i) SKM_sk_delete(ASN1_STRING_TABLE, (st), (i))
306#define sk_ASN1_STRING_TABLE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_STRING_TABLE, (st), (ptr))
307#define sk_ASN1_STRING_TABLE_insert(st, val, i) SKM_sk_insert(ASN1_STRING_TABLE, (st), (val), (i))
308#define sk_ASN1_STRING_TABLE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_STRING_TABLE, (st), (cmp))
309#define sk_ASN1_STRING_TABLE_dup(st) SKM_sk_dup(ASN1_STRING_TABLE, st)
310#define sk_ASN1_STRING_TABLE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_STRING_TABLE, (st), (free_func))
311#define sk_ASN1_STRING_TABLE_shift(st) SKM_sk_shift(ASN1_STRING_TABLE, (st))
312#define sk_ASN1_STRING_TABLE_pop(st) SKM_sk_pop(ASN1_STRING_TABLE, (st))
313#define sk_ASN1_STRING_TABLE_sort(st) SKM_sk_sort(ASN1_STRING_TABLE, (st))
314#define sk_ASN1_STRING_TABLE_is_sorted(st) SKM_sk_is_sorted(ASN1_STRING_TABLE, (st))
315
316#define sk_ASN1_TYPE_new(st) SKM_sk_new(ASN1_TYPE, (st))
317#define sk_ASN1_TYPE_new_null() SKM_sk_new_null(ASN1_TYPE)
318#define sk_ASN1_TYPE_free(st) SKM_sk_free(ASN1_TYPE, (st))
319#define sk_ASN1_TYPE_num(st) SKM_sk_num(ASN1_TYPE, (st))
320#define sk_ASN1_TYPE_value(st, i) SKM_sk_value(ASN1_TYPE, (st), (i))
321#define sk_ASN1_TYPE_set(st, i, val) SKM_sk_set(ASN1_TYPE, (st), (i), (val))
322#define sk_ASN1_TYPE_zero(st) SKM_sk_zero(ASN1_TYPE, (st))
323#define sk_ASN1_TYPE_push(st, val) SKM_sk_push(ASN1_TYPE, (st), (val))
324#define sk_ASN1_TYPE_unshift(st, val) SKM_sk_unshift(ASN1_TYPE, (st), (val))
325#define sk_ASN1_TYPE_find(st, val) SKM_sk_find(ASN1_TYPE, (st), (val))
326#define sk_ASN1_TYPE_delete(st, i) SKM_sk_delete(ASN1_TYPE, (st), (i))
327#define sk_ASN1_TYPE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_TYPE, (st), (ptr))
328#define sk_ASN1_TYPE_insert(st, val, i) SKM_sk_insert(ASN1_TYPE, (st), (val), (i))
329#define sk_ASN1_TYPE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_TYPE, (st), (cmp))
330#define sk_ASN1_TYPE_dup(st) SKM_sk_dup(ASN1_TYPE, st)
331#define sk_ASN1_TYPE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_TYPE, (st), (free_func))
332#define sk_ASN1_TYPE_shift(st) SKM_sk_shift(ASN1_TYPE, (st))
333#define sk_ASN1_TYPE_pop(st) SKM_sk_pop(ASN1_TYPE, (st))
334#define sk_ASN1_TYPE_sort(st) SKM_sk_sort(ASN1_TYPE, (st))
335#define sk_ASN1_TYPE_is_sorted(st) SKM_sk_is_sorted(ASN1_TYPE, (st))
336
337#define sk_ASN1_VALUE_new(st) SKM_sk_new(ASN1_VALUE, (st))
338#define sk_ASN1_VALUE_new_null() SKM_sk_new_null(ASN1_VALUE)
339#define sk_ASN1_VALUE_free(st) SKM_sk_free(ASN1_VALUE, (st))
340#define sk_ASN1_VALUE_num(st) SKM_sk_num(ASN1_VALUE, (st))
341#define sk_ASN1_VALUE_value(st, i) SKM_sk_value(ASN1_VALUE, (st), (i))
342#define sk_ASN1_VALUE_set(st, i, val) SKM_sk_set(ASN1_VALUE, (st), (i), (val))
343#define sk_ASN1_VALUE_zero(st) SKM_sk_zero(ASN1_VALUE, (st))
344#define sk_ASN1_VALUE_push(st, val) SKM_sk_push(ASN1_VALUE, (st), (val))
345#define sk_ASN1_VALUE_unshift(st, val) SKM_sk_unshift(ASN1_VALUE, (st), (val))
346#define sk_ASN1_VALUE_find(st, val) SKM_sk_find(ASN1_VALUE, (st), (val))
347#define sk_ASN1_VALUE_delete(st, i) SKM_sk_delete(ASN1_VALUE, (st), (i))
348#define sk_ASN1_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_VALUE, (st), (ptr))
349#define sk_ASN1_VALUE_insert(st, val, i) SKM_sk_insert(ASN1_VALUE, (st), (val), (i))
350#define sk_ASN1_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_VALUE, (st), (cmp))
351#define sk_ASN1_VALUE_dup(st) SKM_sk_dup(ASN1_VALUE, st)
352#define sk_ASN1_VALUE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_VALUE, (st), (free_func))
353#define sk_ASN1_VALUE_shift(st) SKM_sk_shift(ASN1_VALUE, (st))
354#define sk_ASN1_VALUE_pop(st) SKM_sk_pop(ASN1_VALUE, (st))
355#define sk_ASN1_VALUE_sort(st) SKM_sk_sort(ASN1_VALUE, (st))
356#define sk_ASN1_VALUE_is_sorted(st) SKM_sk_is_sorted(ASN1_VALUE, (st))
357
358#define sk_BIO_new(st) SKM_sk_new(BIO, (st))
359#define sk_BIO_new_null() SKM_sk_new_null(BIO)
360#define sk_BIO_free(st) SKM_sk_free(BIO, (st))
361#define sk_BIO_num(st) SKM_sk_num(BIO, (st))
362#define sk_BIO_value(st, i) SKM_sk_value(BIO, (st), (i))
363#define sk_BIO_set(st, i, val) SKM_sk_set(BIO, (st), (i), (val))
364#define sk_BIO_zero(st) SKM_sk_zero(BIO, (st))
365#define sk_BIO_push(st, val) SKM_sk_push(BIO, (st), (val))
366#define sk_BIO_unshift(st, val) SKM_sk_unshift(BIO, (st), (val))
367#define sk_BIO_find(st, val) SKM_sk_find(BIO, (st), (val))
368#define sk_BIO_delete(st, i) SKM_sk_delete(BIO, (st), (i))
369#define sk_BIO_delete_ptr(st, ptr) SKM_sk_delete_ptr(BIO, (st), (ptr))
370#define sk_BIO_insert(st, val, i) SKM_sk_insert(BIO, (st), (val), (i))
371#define sk_BIO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(BIO, (st), (cmp))
372#define sk_BIO_dup(st) SKM_sk_dup(BIO, st)
373#define sk_BIO_pop_free(st, free_func) SKM_sk_pop_free(BIO, (st), (free_func))
374#define sk_BIO_shift(st) SKM_sk_shift(BIO, (st))
375#define sk_BIO_pop(st) SKM_sk_pop(BIO, (st))
376#define sk_BIO_sort(st) SKM_sk_sort(BIO, (st))
377#define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st))
378
379#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st))
380#define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE)
381#define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st))
382#define sk_CONF_IMODULE_num(st) SKM_sk_num(CONF_IMODULE, (st))
383#define sk_CONF_IMODULE_value(st, i) SKM_sk_value(CONF_IMODULE, (st), (i))
384#define sk_CONF_IMODULE_set(st, i, val) SKM_sk_set(CONF_IMODULE, (st), (i), (val))
385#define sk_CONF_IMODULE_zero(st) SKM_sk_zero(CONF_IMODULE, (st))
386#define sk_CONF_IMODULE_push(st, val) SKM_sk_push(CONF_IMODULE, (st), (val))
387#define sk_CONF_IMODULE_unshift(st, val) SKM_sk_unshift(CONF_IMODULE, (st), (val))
388#define sk_CONF_IMODULE_find(st, val) SKM_sk_find(CONF_IMODULE, (st), (val))
389#define sk_CONF_IMODULE_delete(st, i) SKM_sk_delete(CONF_IMODULE, (st), (i))
390#define sk_CONF_IMODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_IMODULE, (st), (ptr))
391#define sk_CONF_IMODULE_insert(st, val, i) SKM_sk_insert(CONF_IMODULE, (st), (val), (i))
392#define sk_CONF_IMODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_IMODULE, (st), (cmp))
393#define sk_CONF_IMODULE_dup(st) SKM_sk_dup(CONF_IMODULE, st)
394#define sk_CONF_IMODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_IMODULE, (st), (free_func))
395#define sk_CONF_IMODULE_shift(st) SKM_sk_shift(CONF_IMODULE, (st))
396#define sk_CONF_IMODULE_pop(st) SKM_sk_pop(CONF_IMODULE, (st))
397#define sk_CONF_IMODULE_sort(st) SKM_sk_sort(CONF_IMODULE, (st))
398#define sk_CONF_IMODULE_is_sorted(st) SKM_sk_is_sorted(CONF_IMODULE, (st))
399
400#define sk_CONF_MODULE_new(st) SKM_sk_new(CONF_MODULE, (st))
401#define sk_CONF_MODULE_new_null() SKM_sk_new_null(CONF_MODULE)
402#define sk_CONF_MODULE_free(st) SKM_sk_free(CONF_MODULE, (st))
403#define sk_CONF_MODULE_num(st) SKM_sk_num(CONF_MODULE, (st))
404#define sk_CONF_MODULE_value(st, i) SKM_sk_value(CONF_MODULE, (st), (i))
405#define sk_CONF_MODULE_set(st, i, val) SKM_sk_set(CONF_MODULE, (st), (i), (val))
406#define sk_CONF_MODULE_zero(st) SKM_sk_zero(CONF_MODULE, (st))
407#define sk_CONF_MODULE_push(st, val) SKM_sk_push(CONF_MODULE, (st), (val))
408#define sk_CONF_MODULE_unshift(st, val) SKM_sk_unshift(CONF_MODULE, (st), (val))
409#define sk_CONF_MODULE_find(st, val) SKM_sk_find(CONF_MODULE, (st), (val))
410#define sk_CONF_MODULE_delete(st, i) SKM_sk_delete(CONF_MODULE, (st), (i))
411#define sk_CONF_MODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_MODULE, (st), (ptr))
412#define sk_CONF_MODULE_insert(st, val, i) SKM_sk_insert(CONF_MODULE, (st), (val), (i))
413#define sk_CONF_MODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_MODULE, (st), (cmp))
414#define sk_CONF_MODULE_dup(st) SKM_sk_dup(CONF_MODULE, st)
415#define sk_CONF_MODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_MODULE, (st), (free_func))
416#define sk_CONF_MODULE_shift(st) SKM_sk_shift(CONF_MODULE, (st))
417#define sk_CONF_MODULE_pop(st) SKM_sk_pop(CONF_MODULE, (st))
418#define sk_CONF_MODULE_sort(st) SKM_sk_sort(CONF_MODULE, (st))
419#define sk_CONF_MODULE_is_sorted(st) SKM_sk_is_sorted(CONF_MODULE, (st))
420
421#define sk_CONF_VALUE_new(st) SKM_sk_new(CONF_VALUE, (st))
422#define sk_CONF_VALUE_new_null() SKM_sk_new_null(CONF_VALUE)
423#define sk_CONF_VALUE_free(st) SKM_sk_free(CONF_VALUE, (st))
424#define sk_CONF_VALUE_num(st) SKM_sk_num(CONF_VALUE, (st))
425#define sk_CONF_VALUE_value(st, i) SKM_sk_value(CONF_VALUE, (st), (i))
426#define sk_CONF_VALUE_set(st, i, val) SKM_sk_set(CONF_VALUE, (st), (i), (val))
427#define sk_CONF_VALUE_zero(st) SKM_sk_zero(CONF_VALUE, (st))
428#define sk_CONF_VALUE_push(st, val) SKM_sk_push(CONF_VALUE, (st), (val))
429#define sk_CONF_VALUE_unshift(st, val) SKM_sk_unshift(CONF_VALUE, (st), (val))
430#define sk_CONF_VALUE_find(st, val) SKM_sk_find(CONF_VALUE, (st), (val))
431#define sk_CONF_VALUE_delete(st, i) SKM_sk_delete(CONF_VALUE, (st), (i))
432#define sk_CONF_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_VALUE, (st), (ptr))
433#define sk_CONF_VALUE_insert(st, val, i) SKM_sk_insert(CONF_VALUE, (st), (val), (i))
434#define sk_CONF_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_VALUE, (st), (cmp))
435#define sk_CONF_VALUE_dup(st) SKM_sk_dup(CONF_VALUE, st)
436#define sk_CONF_VALUE_pop_free(st, free_func) SKM_sk_pop_free(CONF_VALUE, (st), (free_func))
437#define sk_CONF_VALUE_shift(st) SKM_sk_shift(CONF_VALUE, (st))
438#define sk_CONF_VALUE_pop(st) SKM_sk_pop(CONF_VALUE, (st))
439#define sk_CONF_VALUE_sort(st) SKM_sk_sort(CONF_VALUE, (st))
440#define sk_CONF_VALUE_is_sorted(st) SKM_sk_is_sorted(CONF_VALUE, (st))
441
442#define sk_CRYPTO_EX_DATA_FUNCS_new(st) SKM_sk_new(CRYPTO_EX_DATA_FUNCS, (st))
443#define sk_CRYPTO_EX_DATA_FUNCS_new_null() SKM_sk_new_null(CRYPTO_EX_DATA_FUNCS)
444#define sk_CRYPTO_EX_DATA_FUNCS_free(st) SKM_sk_free(CRYPTO_EX_DATA_FUNCS, (st))
445#define sk_CRYPTO_EX_DATA_FUNCS_num(st) SKM_sk_num(CRYPTO_EX_DATA_FUNCS, (st))
446#define sk_CRYPTO_EX_DATA_FUNCS_value(st, i) SKM_sk_value(CRYPTO_EX_DATA_FUNCS, (st), (i))
447#define sk_CRYPTO_EX_DATA_FUNCS_set(st, i, val) SKM_sk_set(CRYPTO_EX_DATA_FUNCS, (st), (i), (val))
448#define sk_CRYPTO_EX_DATA_FUNCS_zero(st) SKM_sk_zero(CRYPTO_EX_DATA_FUNCS, (st))
449#define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val))
450#define sk_CRYPTO_EX_DATA_FUNCS_unshift(st, val) SKM_sk_unshift(CRYPTO_EX_DATA_FUNCS, (st), (val))
451#define sk_CRYPTO_EX_DATA_FUNCS_find(st, val) SKM_sk_find(CRYPTO_EX_DATA_FUNCS, (st), (val))
452#define sk_CRYPTO_EX_DATA_FUNCS_delete(st, i) SKM_sk_delete(CRYPTO_EX_DATA_FUNCS, (st), (i))
453#define sk_CRYPTO_EX_DATA_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_EX_DATA_FUNCS, (st), (ptr))
454#define sk_CRYPTO_EX_DATA_FUNCS_insert(st, val, i) SKM_sk_insert(CRYPTO_EX_DATA_FUNCS, (st), (val), (i))
455#define sk_CRYPTO_EX_DATA_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_EX_DATA_FUNCS, (st), (cmp))
456#define sk_CRYPTO_EX_DATA_FUNCS_dup(st) SKM_sk_dup(CRYPTO_EX_DATA_FUNCS, st)
457#define sk_CRYPTO_EX_DATA_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_EX_DATA_FUNCS, (st), (free_func))
458#define sk_CRYPTO_EX_DATA_FUNCS_shift(st) SKM_sk_shift(CRYPTO_EX_DATA_FUNCS, (st))
459#define sk_CRYPTO_EX_DATA_FUNCS_pop(st) SKM_sk_pop(CRYPTO_EX_DATA_FUNCS, (st))
460#define sk_CRYPTO_EX_DATA_FUNCS_sort(st) SKM_sk_sort(CRYPTO_EX_DATA_FUNCS, (st))
461#define sk_CRYPTO_EX_DATA_FUNCS_is_sorted(st) SKM_sk_is_sorted(CRYPTO_EX_DATA_FUNCS, (st))
462
463#define sk_CRYPTO_dynlock_new(st) SKM_sk_new(CRYPTO_dynlock, (st))
464#define sk_CRYPTO_dynlock_new_null() SKM_sk_new_null(CRYPTO_dynlock)
465#define sk_CRYPTO_dynlock_free(st) SKM_sk_free(CRYPTO_dynlock, (st))
466#define sk_CRYPTO_dynlock_num(st) SKM_sk_num(CRYPTO_dynlock, (st))
467#define sk_CRYPTO_dynlock_value(st, i) SKM_sk_value(CRYPTO_dynlock, (st), (i))
468#define sk_CRYPTO_dynlock_set(st, i, val) SKM_sk_set(CRYPTO_dynlock, (st), (i), (val))
469#define sk_CRYPTO_dynlock_zero(st) SKM_sk_zero(CRYPTO_dynlock, (st))
470#define sk_CRYPTO_dynlock_push(st, val) SKM_sk_push(CRYPTO_dynlock, (st), (val))
471#define sk_CRYPTO_dynlock_unshift(st, val) SKM_sk_unshift(CRYPTO_dynlock, (st), (val))
472#define sk_CRYPTO_dynlock_find(st, val) SKM_sk_find(CRYPTO_dynlock, (st), (val))
473#define sk_CRYPTO_dynlock_delete(st, i) SKM_sk_delete(CRYPTO_dynlock, (st), (i))
474#define sk_CRYPTO_dynlock_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_dynlock, (st), (ptr))
475#define sk_CRYPTO_dynlock_insert(st, val, i) SKM_sk_insert(CRYPTO_dynlock, (st), (val), (i))
476#define sk_CRYPTO_dynlock_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_dynlock, (st), (cmp))
477#define sk_CRYPTO_dynlock_dup(st) SKM_sk_dup(CRYPTO_dynlock, st)
478#define sk_CRYPTO_dynlock_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_dynlock, (st), (free_func))
479#define sk_CRYPTO_dynlock_shift(st) SKM_sk_shift(CRYPTO_dynlock, (st))
480#define sk_CRYPTO_dynlock_pop(st) SKM_sk_pop(CRYPTO_dynlock, (st))
481#define sk_CRYPTO_dynlock_sort(st) SKM_sk_sort(CRYPTO_dynlock, (st))
482#define sk_CRYPTO_dynlock_is_sorted(st) SKM_sk_is_sorted(CRYPTO_dynlock, (st))
483
484#define sk_DIST_POINT_new(st) SKM_sk_new(DIST_POINT, (st))
485#define sk_DIST_POINT_new_null() SKM_sk_new_null(DIST_POINT)
486#define sk_DIST_POINT_free(st) SKM_sk_free(DIST_POINT, (st))
487#define sk_DIST_POINT_num(st) SKM_sk_num(DIST_POINT, (st))
488#define sk_DIST_POINT_value(st, i) SKM_sk_value(DIST_POINT, (st), (i))
489#define sk_DIST_POINT_set(st, i, val) SKM_sk_set(DIST_POINT, (st), (i), (val))
490#define sk_DIST_POINT_zero(st) SKM_sk_zero(DIST_POINT, (st))
491#define sk_DIST_POINT_push(st, val) SKM_sk_push(DIST_POINT, (st), (val))
492#define sk_DIST_POINT_unshift(st, val) SKM_sk_unshift(DIST_POINT, (st), (val))
493#define sk_DIST_POINT_find(st, val) SKM_sk_find(DIST_POINT, (st), (val))
494#define sk_DIST_POINT_delete(st, i) SKM_sk_delete(DIST_POINT, (st), (i))
495#define sk_DIST_POINT_delete_ptr(st, ptr) SKM_sk_delete_ptr(DIST_POINT, (st), (ptr))
496#define sk_DIST_POINT_insert(st, val, i) SKM_sk_insert(DIST_POINT, (st), (val), (i))
497#define sk_DIST_POINT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(DIST_POINT, (st), (cmp))
498#define sk_DIST_POINT_dup(st) SKM_sk_dup(DIST_POINT, st)
499#define sk_DIST_POINT_pop_free(st, free_func) SKM_sk_pop_free(DIST_POINT, (st), (free_func))
500#define sk_DIST_POINT_shift(st) SKM_sk_shift(DIST_POINT, (st))
501#define sk_DIST_POINT_pop(st) SKM_sk_pop(DIST_POINT, (st))
502#define sk_DIST_POINT_sort(st) SKM_sk_sort(DIST_POINT, (st))
503#define sk_DIST_POINT_is_sorted(st) SKM_sk_is_sorted(DIST_POINT, (st))
504
505#define sk_ENGINE_new(st) SKM_sk_new(ENGINE, (st))
506#define sk_ENGINE_new_null() SKM_sk_new_null(ENGINE)
507#define sk_ENGINE_free(st) SKM_sk_free(ENGINE, (st))
508#define sk_ENGINE_num(st) SKM_sk_num(ENGINE, (st))
509#define sk_ENGINE_value(st, i) SKM_sk_value(ENGINE, (st), (i))
510#define sk_ENGINE_set(st, i, val) SKM_sk_set(ENGINE, (st), (i), (val))
511#define sk_ENGINE_zero(st) SKM_sk_zero(ENGINE, (st))
512#define sk_ENGINE_push(st, val) SKM_sk_push(ENGINE, (st), (val))
513#define sk_ENGINE_unshift(st, val) SKM_sk_unshift(ENGINE, (st), (val))
514#define sk_ENGINE_find(st, val) SKM_sk_find(ENGINE, (st), (val))
515#define sk_ENGINE_delete(st, i) SKM_sk_delete(ENGINE, (st), (i))
516#define sk_ENGINE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE, (st), (ptr))
517#define sk_ENGINE_insert(st, val, i) SKM_sk_insert(ENGINE, (st), (val), (i))
518#define sk_ENGINE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE, (st), (cmp))
519#define sk_ENGINE_dup(st) SKM_sk_dup(ENGINE, st)
520#define sk_ENGINE_pop_free(st, free_func) SKM_sk_pop_free(ENGINE, (st), (free_func))
521#define sk_ENGINE_shift(st) SKM_sk_shift(ENGINE, (st))
522#define sk_ENGINE_pop(st) SKM_sk_pop(ENGINE, (st))
523#define sk_ENGINE_sort(st) SKM_sk_sort(ENGINE, (st))
524#define sk_ENGINE_is_sorted(st) SKM_sk_is_sorted(ENGINE, (st))
525
526#define sk_ENGINE_CLEANUP_ITEM_new(st) SKM_sk_new(ENGINE_CLEANUP_ITEM, (st))
527#define sk_ENGINE_CLEANUP_ITEM_new_null() SKM_sk_new_null(ENGINE_CLEANUP_ITEM)
528#define sk_ENGINE_CLEANUP_ITEM_free(st) SKM_sk_free(ENGINE_CLEANUP_ITEM, (st))
529#define sk_ENGINE_CLEANUP_ITEM_num(st) SKM_sk_num(ENGINE_CLEANUP_ITEM, (st))
530#define sk_ENGINE_CLEANUP_ITEM_value(st, i) SKM_sk_value(ENGINE_CLEANUP_ITEM, (st), (i))
531#define sk_ENGINE_CLEANUP_ITEM_set(st, i, val) SKM_sk_set(ENGINE_CLEANUP_ITEM, (st), (i), (val))
532#define sk_ENGINE_CLEANUP_ITEM_zero(st) SKM_sk_zero(ENGINE_CLEANUP_ITEM, (st))
533#define sk_ENGINE_CLEANUP_ITEM_push(st, val) SKM_sk_push(ENGINE_CLEANUP_ITEM, (st), (val))
534#define sk_ENGINE_CLEANUP_ITEM_unshift(st, val) SKM_sk_unshift(ENGINE_CLEANUP_ITEM, (st), (val))
535#define sk_ENGINE_CLEANUP_ITEM_find(st, val) SKM_sk_find(ENGINE_CLEANUP_ITEM, (st), (val))
536#define sk_ENGINE_CLEANUP_ITEM_delete(st, i) SKM_sk_delete(ENGINE_CLEANUP_ITEM, (st), (i))
537#define sk_ENGINE_CLEANUP_ITEM_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE_CLEANUP_ITEM, (st), (ptr))
538#define sk_ENGINE_CLEANUP_ITEM_insert(st, val, i) SKM_sk_insert(ENGINE_CLEANUP_ITEM, (st), (val), (i))
539#define sk_ENGINE_CLEANUP_ITEM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE_CLEANUP_ITEM, (st), (cmp))
540#define sk_ENGINE_CLEANUP_ITEM_dup(st) SKM_sk_dup(ENGINE_CLEANUP_ITEM, st)
541#define sk_ENGINE_CLEANUP_ITEM_pop_free(st, free_func) SKM_sk_pop_free(ENGINE_CLEANUP_ITEM, (st), (free_func))
542#define sk_ENGINE_CLEANUP_ITEM_shift(st) SKM_sk_shift(ENGINE_CLEANUP_ITEM, (st))
543#define sk_ENGINE_CLEANUP_ITEM_pop(st) SKM_sk_pop(ENGINE_CLEANUP_ITEM, (st))
544#define sk_ENGINE_CLEANUP_ITEM_sort(st) SKM_sk_sort(ENGINE_CLEANUP_ITEM, (st))
545#define sk_ENGINE_CLEANUP_ITEM_is_sorted(st) SKM_sk_is_sorted(ENGINE_CLEANUP_ITEM, (st))
546
547#define sk_GENERAL_NAME_new(st) SKM_sk_new(GENERAL_NAME, (st))
548#define sk_GENERAL_NAME_new_null() SKM_sk_new_null(GENERAL_NAME)
549#define sk_GENERAL_NAME_free(st) SKM_sk_free(GENERAL_NAME, (st))
550#define sk_GENERAL_NAME_num(st) SKM_sk_num(GENERAL_NAME, (st))
551#define sk_GENERAL_NAME_value(st, i) SKM_sk_value(GENERAL_NAME, (st), (i))
552#define sk_GENERAL_NAME_set(st, i, val) SKM_sk_set(GENERAL_NAME, (st), (i), (val))
553#define sk_GENERAL_NAME_zero(st) SKM_sk_zero(GENERAL_NAME, (st))
554#define sk_GENERAL_NAME_push(st, val) SKM_sk_push(GENERAL_NAME, (st), (val))
555#define sk_GENERAL_NAME_unshift(st, val) SKM_sk_unshift(GENERAL_NAME, (st), (val))
556#define sk_GENERAL_NAME_find(st, val) SKM_sk_find(GENERAL_NAME, (st), (val))
557#define sk_GENERAL_NAME_delete(st, i) SKM_sk_delete(GENERAL_NAME, (st), (i))
558#define sk_GENERAL_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAME, (st), (ptr))
559#define sk_GENERAL_NAME_insert(st, val, i) SKM_sk_insert(GENERAL_NAME, (st), (val), (i))
560#define sk_GENERAL_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_NAME, (st), (cmp))
561#define sk_GENERAL_NAME_dup(st) SKM_sk_dup(GENERAL_NAME, st)
562#define sk_GENERAL_NAME_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_NAME, (st), (free_func))
563#define sk_GENERAL_NAME_shift(st) SKM_sk_shift(GENERAL_NAME, (st))
564#define sk_GENERAL_NAME_pop(st) SKM_sk_pop(GENERAL_NAME, (st))
565#define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st))
566#define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st))
567
568#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st))
569#define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY)
570#define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st))
571#define sk_KRB5_APREQBODY_num(st) SKM_sk_num(KRB5_APREQBODY, (st))
572#define sk_KRB5_APREQBODY_value(st, i) SKM_sk_value(KRB5_APREQBODY, (st), (i))
573#define sk_KRB5_APREQBODY_set(st, i, val) SKM_sk_set(KRB5_APREQBODY, (st), (i), (val))
574#define sk_KRB5_APREQBODY_zero(st) SKM_sk_zero(KRB5_APREQBODY, (st))
575#define sk_KRB5_APREQBODY_push(st, val) SKM_sk_push(KRB5_APREQBODY, (st), (val))
576#define sk_KRB5_APREQBODY_unshift(st, val) SKM_sk_unshift(KRB5_APREQBODY, (st), (val))
577#define sk_KRB5_APREQBODY_find(st, val) SKM_sk_find(KRB5_APREQBODY, (st), (val))
578#define sk_KRB5_APREQBODY_delete(st, i) SKM_sk_delete(KRB5_APREQBODY, (st), (i))
579#define sk_KRB5_APREQBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_APREQBODY, (st), (ptr))
580#define sk_KRB5_APREQBODY_insert(st, val, i) SKM_sk_insert(KRB5_APREQBODY, (st), (val), (i))
581#define sk_KRB5_APREQBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_APREQBODY, (st), (cmp))
582#define sk_KRB5_APREQBODY_dup(st) SKM_sk_dup(KRB5_APREQBODY, st)
583#define sk_KRB5_APREQBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_APREQBODY, (st), (free_func))
584#define sk_KRB5_APREQBODY_shift(st) SKM_sk_shift(KRB5_APREQBODY, (st))
585#define sk_KRB5_APREQBODY_pop(st) SKM_sk_pop(KRB5_APREQBODY, (st))
586#define sk_KRB5_APREQBODY_sort(st) SKM_sk_sort(KRB5_APREQBODY, (st))
587#define sk_KRB5_APREQBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_APREQBODY, (st))
588
589#define sk_KRB5_AUTHDATA_new(st) SKM_sk_new(KRB5_AUTHDATA, (st))
590#define sk_KRB5_AUTHDATA_new_null() SKM_sk_new_null(KRB5_AUTHDATA)
591#define sk_KRB5_AUTHDATA_free(st) SKM_sk_free(KRB5_AUTHDATA, (st))
592#define sk_KRB5_AUTHDATA_num(st) SKM_sk_num(KRB5_AUTHDATA, (st))
593#define sk_KRB5_AUTHDATA_value(st, i) SKM_sk_value(KRB5_AUTHDATA, (st), (i))
594#define sk_KRB5_AUTHDATA_set(st, i, val) SKM_sk_set(KRB5_AUTHDATA, (st), (i), (val))
595#define sk_KRB5_AUTHDATA_zero(st) SKM_sk_zero(KRB5_AUTHDATA, (st))
596#define sk_KRB5_AUTHDATA_push(st, val) SKM_sk_push(KRB5_AUTHDATA, (st), (val))
597#define sk_KRB5_AUTHDATA_unshift(st, val) SKM_sk_unshift(KRB5_AUTHDATA, (st), (val))
598#define sk_KRB5_AUTHDATA_find(st, val) SKM_sk_find(KRB5_AUTHDATA, (st), (val))
599#define sk_KRB5_AUTHDATA_delete(st, i) SKM_sk_delete(KRB5_AUTHDATA, (st), (i))
600#define sk_KRB5_AUTHDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHDATA, (st), (ptr))
601#define sk_KRB5_AUTHDATA_insert(st, val, i) SKM_sk_insert(KRB5_AUTHDATA, (st), (val), (i))
602#define sk_KRB5_AUTHDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHDATA, (st), (cmp))
603#define sk_KRB5_AUTHDATA_dup(st) SKM_sk_dup(KRB5_AUTHDATA, st)
604#define sk_KRB5_AUTHDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHDATA, (st), (free_func))
605#define sk_KRB5_AUTHDATA_shift(st) SKM_sk_shift(KRB5_AUTHDATA, (st))
606#define sk_KRB5_AUTHDATA_pop(st) SKM_sk_pop(KRB5_AUTHDATA, (st))
607#define sk_KRB5_AUTHDATA_sort(st) SKM_sk_sort(KRB5_AUTHDATA, (st))
608#define sk_KRB5_AUTHDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHDATA, (st))
609
610#define sk_KRB5_AUTHENTBODY_new(st) SKM_sk_new(KRB5_AUTHENTBODY, (st))
611#define sk_KRB5_AUTHENTBODY_new_null() SKM_sk_new_null(KRB5_AUTHENTBODY)
612#define sk_KRB5_AUTHENTBODY_free(st) SKM_sk_free(KRB5_AUTHENTBODY, (st))
613#define sk_KRB5_AUTHENTBODY_num(st) SKM_sk_num(KRB5_AUTHENTBODY, (st))
614#define sk_KRB5_AUTHENTBODY_value(st, i) SKM_sk_value(KRB5_AUTHENTBODY, (st), (i))
615#define sk_KRB5_AUTHENTBODY_set(st, i, val) SKM_sk_set(KRB5_AUTHENTBODY, (st), (i), (val))
616#define sk_KRB5_AUTHENTBODY_zero(st) SKM_sk_zero(KRB5_AUTHENTBODY, (st))
617#define sk_KRB5_AUTHENTBODY_push(st, val) SKM_sk_push(KRB5_AUTHENTBODY, (st), (val))
618#define sk_KRB5_AUTHENTBODY_unshift(st, val) SKM_sk_unshift(KRB5_AUTHENTBODY, (st), (val))
619#define sk_KRB5_AUTHENTBODY_find(st, val) SKM_sk_find(KRB5_AUTHENTBODY, (st), (val))
620#define sk_KRB5_AUTHENTBODY_delete(st, i) SKM_sk_delete(KRB5_AUTHENTBODY, (st), (i))
621#define sk_KRB5_AUTHENTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHENTBODY, (st), (ptr))
622#define sk_KRB5_AUTHENTBODY_insert(st, val, i) SKM_sk_insert(KRB5_AUTHENTBODY, (st), (val), (i))
623#define sk_KRB5_AUTHENTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHENTBODY, (st), (cmp))
624#define sk_KRB5_AUTHENTBODY_dup(st) SKM_sk_dup(KRB5_AUTHENTBODY, st)
625#define sk_KRB5_AUTHENTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHENTBODY, (st), (free_func))
626#define sk_KRB5_AUTHENTBODY_shift(st) SKM_sk_shift(KRB5_AUTHENTBODY, (st))
627#define sk_KRB5_AUTHENTBODY_pop(st) SKM_sk_pop(KRB5_AUTHENTBODY, (st))
628#define sk_KRB5_AUTHENTBODY_sort(st) SKM_sk_sort(KRB5_AUTHENTBODY, (st))
629#define sk_KRB5_AUTHENTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHENTBODY, (st))
630
631#define sk_KRB5_CHECKSUM_new(st) SKM_sk_new(KRB5_CHECKSUM, (st))
632#define sk_KRB5_CHECKSUM_new_null() SKM_sk_new_null(KRB5_CHECKSUM)
633#define sk_KRB5_CHECKSUM_free(st) SKM_sk_free(KRB5_CHECKSUM, (st))
634#define sk_KRB5_CHECKSUM_num(st) SKM_sk_num(KRB5_CHECKSUM, (st))
635#define sk_KRB5_CHECKSUM_value(st, i) SKM_sk_value(KRB5_CHECKSUM, (st), (i))
636#define sk_KRB5_CHECKSUM_set(st, i, val) SKM_sk_set(KRB5_CHECKSUM, (st), (i), (val))
637#define sk_KRB5_CHECKSUM_zero(st) SKM_sk_zero(KRB5_CHECKSUM, (st))
638#define sk_KRB5_CHECKSUM_push(st, val) SKM_sk_push(KRB5_CHECKSUM, (st), (val))
639#define sk_KRB5_CHECKSUM_unshift(st, val) SKM_sk_unshift(KRB5_CHECKSUM, (st), (val))
640#define sk_KRB5_CHECKSUM_find(st, val) SKM_sk_find(KRB5_CHECKSUM, (st), (val))
641#define sk_KRB5_CHECKSUM_delete(st, i) SKM_sk_delete(KRB5_CHECKSUM, (st), (i))
642#define sk_KRB5_CHECKSUM_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_CHECKSUM, (st), (ptr))
643#define sk_KRB5_CHECKSUM_insert(st, val, i) SKM_sk_insert(KRB5_CHECKSUM, (st), (val), (i))
644#define sk_KRB5_CHECKSUM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_CHECKSUM, (st), (cmp))
645#define sk_KRB5_CHECKSUM_dup(st) SKM_sk_dup(KRB5_CHECKSUM, st)
646#define sk_KRB5_CHECKSUM_pop_free(st, free_func) SKM_sk_pop_free(KRB5_CHECKSUM, (st), (free_func))
647#define sk_KRB5_CHECKSUM_shift(st) SKM_sk_shift(KRB5_CHECKSUM, (st))
648#define sk_KRB5_CHECKSUM_pop(st) SKM_sk_pop(KRB5_CHECKSUM, (st))
649#define sk_KRB5_CHECKSUM_sort(st) SKM_sk_sort(KRB5_CHECKSUM, (st))
650#define sk_KRB5_CHECKSUM_is_sorted(st) SKM_sk_is_sorted(KRB5_CHECKSUM, (st))
651
652#define sk_KRB5_ENCDATA_new(st) SKM_sk_new(KRB5_ENCDATA, (st))
653#define sk_KRB5_ENCDATA_new_null() SKM_sk_new_null(KRB5_ENCDATA)
654#define sk_KRB5_ENCDATA_free(st) SKM_sk_free(KRB5_ENCDATA, (st))
655#define sk_KRB5_ENCDATA_num(st) SKM_sk_num(KRB5_ENCDATA, (st))
656#define sk_KRB5_ENCDATA_value(st, i) SKM_sk_value(KRB5_ENCDATA, (st), (i))
657#define sk_KRB5_ENCDATA_set(st, i, val) SKM_sk_set(KRB5_ENCDATA, (st), (i), (val))
658#define sk_KRB5_ENCDATA_zero(st) SKM_sk_zero(KRB5_ENCDATA, (st))
659#define sk_KRB5_ENCDATA_push(st, val) SKM_sk_push(KRB5_ENCDATA, (st), (val))
660#define sk_KRB5_ENCDATA_unshift(st, val) SKM_sk_unshift(KRB5_ENCDATA, (st), (val))
661#define sk_KRB5_ENCDATA_find(st, val) SKM_sk_find(KRB5_ENCDATA, (st), (val))
662#define sk_KRB5_ENCDATA_delete(st, i) SKM_sk_delete(KRB5_ENCDATA, (st), (i))
663#define sk_KRB5_ENCDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCDATA, (st), (ptr))
664#define sk_KRB5_ENCDATA_insert(st, val, i) SKM_sk_insert(KRB5_ENCDATA, (st), (val), (i))
665#define sk_KRB5_ENCDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCDATA, (st), (cmp))
666#define sk_KRB5_ENCDATA_dup(st) SKM_sk_dup(KRB5_ENCDATA, st)
667#define sk_KRB5_ENCDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCDATA, (st), (free_func))
668#define sk_KRB5_ENCDATA_shift(st) SKM_sk_shift(KRB5_ENCDATA, (st))
669#define sk_KRB5_ENCDATA_pop(st) SKM_sk_pop(KRB5_ENCDATA, (st))
670#define sk_KRB5_ENCDATA_sort(st) SKM_sk_sort(KRB5_ENCDATA, (st))
671#define sk_KRB5_ENCDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCDATA, (st))
672
673#define sk_KRB5_ENCKEY_new(st) SKM_sk_new(KRB5_ENCKEY, (st))
674#define sk_KRB5_ENCKEY_new_null() SKM_sk_new_null(KRB5_ENCKEY)
675#define sk_KRB5_ENCKEY_free(st) SKM_sk_free(KRB5_ENCKEY, (st))
676#define sk_KRB5_ENCKEY_num(st) SKM_sk_num(KRB5_ENCKEY, (st))
677#define sk_KRB5_ENCKEY_value(st, i) SKM_sk_value(KRB5_ENCKEY, (st), (i))
678#define sk_KRB5_ENCKEY_set(st, i, val) SKM_sk_set(KRB5_ENCKEY, (st), (i), (val))
679#define sk_KRB5_ENCKEY_zero(st) SKM_sk_zero(KRB5_ENCKEY, (st))
680#define sk_KRB5_ENCKEY_push(st, val) SKM_sk_push(KRB5_ENCKEY, (st), (val))
681#define sk_KRB5_ENCKEY_unshift(st, val) SKM_sk_unshift(KRB5_ENCKEY, (st), (val))
682#define sk_KRB5_ENCKEY_find(st, val) SKM_sk_find(KRB5_ENCKEY, (st), (val))
683#define sk_KRB5_ENCKEY_delete(st, i) SKM_sk_delete(KRB5_ENCKEY, (st), (i))
684#define sk_KRB5_ENCKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCKEY, (st), (ptr))
685#define sk_KRB5_ENCKEY_insert(st, val, i) SKM_sk_insert(KRB5_ENCKEY, (st), (val), (i))
686#define sk_KRB5_ENCKEY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCKEY, (st), (cmp))
687#define sk_KRB5_ENCKEY_dup(st) SKM_sk_dup(KRB5_ENCKEY, st)
688#define sk_KRB5_ENCKEY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCKEY, (st), (free_func))
689#define sk_KRB5_ENCKEY_shift(st) SKM_sk_shift(KRB5_ENCKEY, (st))
690#define sk_KRB5_ENCKEY_pop(st) SKM_sk_pop(KRB5_ENCKEY, (st))
691#define sk_KRB5_ENCKEY_sort(st) SKM_sk_sort(KRB5_ENCKEY, (st))
692#define sk_KRB5_ENCKEY_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCKEY, (st))
693
694#define sk_KRB5_PRINCNAME_new(st) SKM_sk_new(KRB5_PRINCNAME, (st))
695#define sk_KRB5_PRINCNAME_new_null() SKM_sk_new_null(KRB5_PRINCNAME)
696#define sk_KRB5_PRINCNAME_free(st) SKM_sk_free(KRB5_PRINCNAME, (st))
697#define sk_KRB5_PRINCNAME_num(st) SKM_sk_num(KRB5_PRINCNAME, (st))
698#define sk_KRB5_PRINCNAME_value(st, i) SKM_sk_value(KRB5_PRINCNAME, (st), (i))
699#define sk_KRB5_PRINCNAME_set(st, i, val) SKM_sk_set(KRB5_PRINCNAME, (st), (i), (val))
700#define sk_KRB5_PRINCNAME_zero(st) SKM_sk_zero(KRB5_PRINCNAME, (st))
701#define sk_KRB5_PRINCNAME_push(st, val) SKM_sk_push(KRB5_PRINCNAME, (st), (val))
702#define sk_KRB5_PRINCNAME_unshift(st, val) SKM_sk_unshift(KRB5_PRINCNAME, (st), (val))
703#define sk_KRB5_PRINCNAME_find(st, val) SKM_sk_find(KRB5_PRINCNAME, (st), (val))
704#define sk_KRB5_PRINCNAME_delete(st, i) SKM_sk_delete(KRB5_PRINCNAME, (st), (i))
705#define sk_KRB5_PRINCNAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_PRINCNAME, (st), (ptr))
706#define sk_KRB5_PRINCNAME_insert(st, val, i) SKM_sk_insert(KRB5_PRINCNAME, (st), (val), (i))
707#define sk_KRB5_PRINCNAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_PRINCNAME, (st), (cmp))
708#define sk_KRB5_PRINCNAME_dup(st) SKM_sk_dup(KRB5_PRINCNAME, st)
709#define sk_KRB5_PRINCNAME_pop_free(st, free_func) SKM_sk_pop_free(KRB5_PRINCNAME, (st), (free_func))
710#define sk_KRB5_PRINCNAME_shift(st) SKM_sk_shift(KRB5_PRINCNAME, (st))
711#define sk_KRB5_PRINCNAME_pop(st) SKM_sk_pop(KRB5_PRINCNAME, (st))
712#define sk_KRB5_PRINCNAME_sort(st) SKM_sk_sort(KRB5_PRINCNAME, (st))
713#define sk_KRB5_PRINCNAME_is_sorted(st) SKM_sk_is_sorted(KRB5_PRINCNAME, (st))
714
715#define sk_KRB5_TKTBODY_new(st) SKM_sk_new(KRB5_TKTBODY, (st))
716#define sk_KRB5_TKTBODY_new_null() SKM_sk_new_null(KRB5_TKTBODY)
717#define sk_KRB5_TKTBODY_free(st) SKM_sk_free(KRB5_TKTBODY, (st))
718#define sk_KRB5_TKTBODY_num(st) SKM_sk_num(KRB5_TKTBODY, (st))
719#define sk_KRB5_TKTBODY_value(st, i) SKM_sk_value(KRB5_TKTBODY, (st), (i))
720#define sk_KRB5_TKTBODY_set(st, i, val) SKM_sk_set(KRB5_TKTBODY, (st), (i), (val))
721#define sk_KRB5_TKTBODY_zero(st) SKM_sk_zero(KRB5_TKTBODY, (st))
722#define sk_KRB5_TKTBODY_push(st, val) SKM_sk_push(KRB5_TKTBODY, (st), (val))
723#define sk_KRB5_TKTBODY_unshift(st, val) SKM_sk_unshift(KRB5_TKTBODY, (st), (val))
724#define sk_KRB5_TKTBODY_find(st, val) SKM_sk_find(KRB5_TKTBODY, (st), (val))
725#define sk_KRB5_TKTBODY_delete(st, i) SKM_sk_delete(KRB5_TKTBODY, (st), (i))
726#define sk_KRB5_TKTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_TKTBODY, (st), (ptr))
727#define sk_KRB5_TKTBODY_insert(st, val, i) SKM_sk_insert(KRB5_TKTBODY, (st), (val), (i))
728#define sk_KRB5_TKTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_TKTBODY, (st), (cmp))
729#define sk_KRB5_TKTBODY_dup(st) SKM_sk_dup(KRB5_TKTBODY, st)
730#define sk_KRB5_TKTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_TKTBODY, (st), (free_func))
731#define sk_KRB5_TKTBODY_shift(st) SKM_sk_shift(KRB5_TKTBODY, (st))
732#define sk_KRB5_TKTBODY_pop(st) SKM_sk_pop(KRB5_TKTBODY, (st))
733#define sk_KRB5_TKTBODY_sort(st) SKM_sk_sort(KRB5_TKTBODY, (st))
734#define sk_KRB5_TKTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_TKTBODY, (st))
735
736#define sk_MIME_HEADER_new(st) SKM_sk_new(MIME_HEADER, (st))
737#define sk_MIME_HEADER_new_null() SKM_sk_new_null(MIME_HEADER)
738#define sk_MIME_HEADER_free(st) SKM_sk_free(MIME_HEADER, (st))
739#define sk_MIME_HEADER_num(st) SKM_sk_num(MIME_HEADER, (st))
740#define sk_MIME_HEADER_value(st, i) SKM_sk_value(MIME_HEADER, (st), (i))
741#define sk_MIME_HEADER_set(st, i, val) SKM_sk_set(MIME_HEADER, (st), (i), (val))
742#define sk_MIME_HEADER_zero(st) SKM_sk_zero(MIME_HEADER, (st))
743#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val))
744#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val))
745#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val))
746#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i))
747#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr))
748#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i))
749#define sk_MIME_HEADER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_HEADER, (st), (cmp))
750#define sk_MIME_HEADER_dup(st) SKM_sk_dup(MIME_HEADER, st)
751#define sk_MIME_HEADER_pop_free(st, free_func) SKM_sk_pop_free(MIME_HEADER, (st), (free_func))
752#define sk_MIME_HEADER_shift(st) SKM_sk_shift(MIME_HEADER, (st))
753#define sk_MIME_HEADER_pop(st) SKM_sk_pop(MIME_HEADER, (st))
754#define sk_MIME_HEADER_sort(st) SKM_sk_sort(MIME_HEADER, (st))
755#define sk_MIME_HEADER_is_sorted(st) SKM_sk_is_sorted(MIME_HEADER, (st))
756
757#define sk_MIME_PARAM_new(st) SKM_sk_new(MIME_PARAM, (st))
758#define sk_MIME_PARAM_new_null() SKM_sk_new_null(MIME_PARAM)
759#define sk_MIME_PARAM_free(st) SKM_sk_free(MIME_PARAM, (st))
760#define sk_MIME_PARAM_num(st) SKM_sk_num(MIME_PARAM, (st))
761#define sk_MIME_PARAM_value(st, i) SKM_sk_value(MIME_PARAM, (st), (i))
762#define sk_MIME_PARAM_set(st, i, val) SKM_sk_set(MIME_PARAM, (st), (i), (val))
763#define sk_MIME_PARAM_zero(st) SKM_sk_zero(MIME_PARAM, (st))
764#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val))
765#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val))
766#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val))
767#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i))
768#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr))
769#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i))
770#define sk_MIME_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_PARAM, (st), (cmp))
771#define sk_MIME_PARAM_dup(st) SKM_sk_dup(MIME_PARAM, st)
772#define sk_MIME_PARAM_pop_free(st, free_func) SKM_sk_pop_free(MIME_PARAM, (st), (free_func))
773#define sk_MIME_PARAM_shift(st) SKM_sk_shift(MIME_PARAM, (st))
774#define sk_MIME_PARAM_pop(st) SKM_sk_pop(MIME_PARAM, (st))
775#define sk_MIME_PARAM_sort(st) SKM_sk_sort(MIME_PARAM, (st))
776#define sk_MIME_PARAM_is_sorted(st) SKM_sk_is_sorted(MIME_PARAM, (st))
777
778#define sk_NAME_FUNCS_new(st) SKM_sk_new(NAME_FUNCS, (st))
779#define sk_NAME_FUNCS_new_null() SKM_sk_new_null(NAME_FUNCS)
780#define sk_NAME_FUNCS_free(st) SKM_sk_free(NAME_FUNCS, (st))
781#define sk_NAME_FUNCS_num(st) SKM_sk_num(NAME_FUNCS, (st))
782#define sk_NAME_FUNCS_value(st, i) SKM_sk_value(NAME_FUNCS, (st), (i))
783#define sk_NAME_FUNCS_set(st, i, val) SKM_sk_set(NAME_FUNCS, (st), (i), (val))
784#define sk_NAME_FUNCS_zero(st) SKM_sk_zero(NAME_FUNCS, (st))
785#define sk_NAME_FUNCS_push(st, val) SKM_sk_push(NAME_FUNCS, (st), (val))
786#define sk_NAME_FUNCS_unshift(st, val) SKM_sk_unshift(NAME_FUNCS, (st), (val))
787#define sk_NAME_FUNCS_find(st, val) SKM_sk_find(NAME_FUNCS, (st), (val))
788#define sk_NAME_FUNCS_delete(st, i) SKM_sk_delete(NAME_FUNCS, (st), (i))
789#define sk_NAME_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(NAME_FUNCS, (st), (ptr))
790#define sk_NAME_FUNCS_insert(st, val, i) SKM_sk_insert(NAME_FUNCS, (st), (val), (i))
791#define sk_NAME_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(NAME_FUNCS, (st), (cmp))
792#define sk_NAME_FUNCS_dup(st) SKM_sk_dup(NAME_FUNCS, st)
793#define sk_NAME_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(NAME_FUNCS, (st), (free_func))
794#define sk_NAME_FUNCS_shift(st) SKM_sk_shift(NAME_FUNCS, (st))
795#define sk_NAME_FUNCS_pop(st) SKM_sk_pop(NAME_FUNCS, (st))
796#define sk_NAME_FUNCS_sort(st) SKM_sk_sort(NAME_FUNCS, (st))
797#define sk_NAME_FUNCS_is_sorted(st) SKM_sk_is_sorted(NAME_FUNCS, (st))
798
799#define sk_OCSP_CERTID_new(st) SKM_sk_new(OCSP_CERTID, (st))
800#define sk_OCSP_CERTID_new_null() SKM_sk_new_null(OCSP_CERTID)
801#define sk_OCSP_CERTID_free(st) SKM_sk_free(OCSP_CERTID, (st))
802#define sk_OCSP_CERTID_num(st) SKM_sk_num(OCSP_CERTID, (st))
803#define sk_OCSP_CERTID_value(st, i) SKM_sk_value(OCSP_CERTID, (st), (i))
804#define sk_OCSP_CERTID_set(st, i, val) SKM_sk_set(OCSP_CERTID, (st), (i), (val))
805#define sk_OCSP_CERTID_zero(st) SKM_sk_zero(OCSP_CERTID, (st))
806#define sk_OCSP_CERTID_push(st, val) SKM_sk_push(OCSP_CERTID, (st), (val))
807#define sk_OCSP_CERTID_unshift(st, val) SKM_sk_unshift(OCSP_CERTID, (st), (val))
808#define sk_OCSP_CERTID_find(st, val) SKM_sk_find(OCSP_CERTID, (st), (val))
809#define sk_OCSP_CERTID_delete(st, i) SKM_sk_delete(OCSP_CERTID, (st), (i))
810#define sk_OCSP_CERTID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_CERTID, (st), (ptr))
811#define sk_OCSP_CERTID_insert(st, val, i) SKM_sk_insert(OCSP_CERTID, (st), (val), (i))
812#define sk_OCSP_CERTID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_CERTID, (st), (cmp))
813#define sk_OCSP_CERTID_dup(st) SKM_sk_dup(OCSP_CERTID, st)
814#define sk_OCSP_CERTID_pop_free(st, free_func) SKM_sk_pop_free(OCSP_CERTID, (st), (free_func))
815#define sk_OCSP_CERTID_shift(st) SKM_sk_shift(OCSP_CERTID, (st))
816#define sk_OCSP_CERTID_pop(st) SKM_sk_pop(OCSP_CERTID, (st))
817#define sk_OCSP_CERTID_sort(st) SKM_sk_sort(OCSP_CERTID, (st))
818#define sk_OCSP_CERTID_is_sorted(st) SKM_sk_is_sorted(OCSP_CERTID, (st))
819
820#define sk_OCSP_ONEREQ_new(st) SKM_sk_new(OCSP_ONEREQ, (st))
821#define sk_OCSP_ONEREQ_new_null() SKM_sk_new_null(OCSP_ONEREQ)
822#define sk_OCSP_ONEREQ_free(st) SKM_sk_free(OCSP_ONEREQ, (st))
823#define sk_OCSP_ONEREQ_num(st) SKM_sk_num(OCSP_ONEREQ, (st))
824#define sk_OCSP_ONEREQ_value(st, i) SKM_sk_value(OCSP_ONEREQ, (st), (i))
825#define sk_OCSP_ONEREQ_set(st, i, val) SKM_sk_set(OCSP_ONEREQ, (st), (i), (val))
826#define sk_OCSP_ONEREQ_zero(st) SKM_sk_zero(OCSP_ONEREQ, (st))
827#define sk_OCSP_ONEREQ_push(st, val) SKM_sk_push(OCSP_ONEREQ, (st), (val))
828#define sk_OCSP_ONEREQ_unshift(st, val) SKM_sk_unshift(OCSP_ONEREQ, (st), (val))
829#define sk_OCSP_ONEREQ_find(st, val) SKM_sk_find(OCSP_ONEREQ, (st), (val))
830#define sk_OCSP_ONEREQ_delete(st, i) SKM_sk_delete(OCSP_ONEREQ, (st), (i))
831#define sk_OCSP_ONEREQ_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_ONEREQ, (st), (ptr))
832#define sk_OCSP_ONEREQ_insert(st, val, i) SKM_sk_insert(OCSP_ONEREQ, (st), (val), (i))
833#define sk_OCSP_ONEREQ_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_ONEREQ, (st), (cmp))
834#define sk_OCSP_ONEREQ_dup(st) SKM_sk_dup(OCSP_ONEREQ, st)
835#define sk_OCSP_ONEREQ_pop_free(st, free_func) SKM_sk_pop_free(OCSP_ONEREQ, (st), (free_func))
836#define sk_OCSP_ONEREQ_shift(st) SKM_sk_shift(OCSP_ONEREQ, (st))
837#define sk_OCSP_ONEREQ_pop(st) SKM_sk_pop(OCSP_ONEREQ, (st))
838#define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st))
839#define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st))
840
841#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st))
842#define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP)
843#define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st))
844#define sk_OCSP_SINGLERESP_num(st) SKM_sk_num(OCSP_SINGLERESP, (st))
845#define sk_OCSP_SINGLERESP_value(st, i) SKM_sk_value(OCSP_SINGLERESP, (st), (i))
846#define sk_OCSP_SINGLERESP_set(st, i, val) SKM_sk_set(OCSP_SINGLERESP, (st), (i), (val))
847#define sk_OCSP_SINGLERESP_zero(st) SKM_sk_zero(OCSP_SINGLERESP, (st))
848#define sk_OCSP_SINGLERESP_push(st, val) SKM_sk_push(OCSP_SINGLERESP, (st), (val))
849#define sk_OCSP_SINGLERESP_unshift(st, val) SKM_sk_unshift(OCSP_SINGLERESP, (st), (val))
850#define sk_OCSP_SINGLERESP_find(st, val) SKM_sk_find(OCSP_SINGLERESP, (st), (val))
851#define sk_OCSP_SINGLERESP_delete(st, i) SKM_sk_delete(OCSP_SINGLERESP, (st), (i))
852#define sk_OCSP_SINGLERESP_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_SINGLERESP, (st), (ptr))
853#define sk_OCSP_SINGLERESP_insert(st, val, i) SKM_sk_insert(OCSP_SINGLERESP, (st), (val), (i))
854#define sk_OCSP_SINGLERESP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_SINGLERESP, (st), (cmp))
855#define sk_OCSP_SINGLERESP_dup(st) SKM_sk_dup(OCSP_SINGLERESP, st)
856#define sk_OCSP_SINGLERESP_pop_free(st, free_func) SKM_sk_pop_free(OCSP_SINGLERESP, (st), (free_func))
857#define sk_OCSP_SINGLERESP_shift(st) SKM_sk_shift(OCSP_SINGLERESP, (st))
858#define sk_OCSP_SINGLERESP_pop(st) SKM_sk_pop(OCSP_SINGLERESP, (st))
859#define sk_OCSP_SINGLERESP_sort(st) SKM_sk_sort(OCSP_SINGLERESP, (st))
860#define sk_OCSP_SINGLERESP_is_sorted(st) SKM_sk_is_sorted(OCSP_SINGLERESP, (st))
861
862#define sk_PKCS12_SAFEBAG_new(st) SKM_sk_new(PKCS12_SAFEBAG, (st))
863#define sk_PKCS12_SAFEBAG_new_null() SKM_sk_new_null(PKCS12_SAFEBAG)
864#define sk_PKCS12_SAFEBAG_free(st) SKM_sk_free(PKCS12_SAFEBAG, (st))
865#define sk_PKCS12_SAFEBAG_num(st) SKM_sk_num(PKCS12_SAFEBAG, (st))
866#define sk_PKCS12_SAFEBAG_value(st, i) SKM_sk_value(PKCS12_SAFEBAG, (st), (i))
867#define sk_PKCS12_SAFEBAG_set(st, i, val) SKM_sk_set(PKCS12_SAFEBAG, (st), (i), (val))
868#define sk_PKCS12_SAFEBAG_zero(st) SKM_sk_zero(PKCS12_SAFEBAG, (st))
869#define sk_PKCS12_SAFEBAG_push(st, val) SKM_sk_push(PKCS12_SAFEBAG, (st), (val))
870#define sk_PKCS12_SAFEBAG_unshift(st, val) SKM_sk_unshift(PKCS12_SAFEBAG, (st), (val))
871#define sk_PKCS12_SAFEBAG_find(st, val) SKM_sk_find(PKCS12_SAFEBAG, (st), (val))
872#define sk_PKCS12_SAFEBAG_delete(st, i) SKM_sk_delete(PKCS12_SAFEBAG, (st), (i))
873#define sk_PKCS12_SAFEBAG_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS12_SAFEBAG, (st), (ptr))
874#define sk_PKCS12_SAFEBAG_insert(st, val, i) SKM_sk_insert(PKCS12_SAFEBAG, (st), (val), (i))
875#define sk_PKCS12_SAFEBAG_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS12_SAFEBAG, (st), (cmp))
876#define sk_PKCS12_SAFEBAG_dup(st) SKM_sk_dup(PKCS12_SAFEBAG, st)
877#define sk_PKCS12_SAFEBAG_pop_free(st, free_func) SKM_sk_pop_free(PKCS12_SAFEBAG, (st), (free_func))
878#define sk_PKCS12_SAFEBAG_shift(st) SKM_sk_shift(PKCS12_SAFEBAG, (st))
879#define sk_PKCS12_SAFEBAG_pop(st) SKM_sk_pop(PKCS12_SAFEBAG, (st))
880#define sk_PKCS12_SAFEBAG_sort(st) SKM_sk_sort(PKCS12_SAFEBAG, (st))
881#define sk_PKCS12_SAFEBAG_is_sorted(st) SKM_sk_is_sorted(PKCS12_SAFEBAG, (st))
882
883#define sk_PKCS7_new(st) SKM_sk_new(PKCS7, (st))
884#define sk_PKCS7_new_null() SKM_sk_new_null(PKCS7)
885#define sk_PKCS7_free(st) SKM_sk_free(PKCS7, (st))
886#define sk_PKCS7_num(st) SKM_sk_num(PKCS7, (st))
887#define sk_PKCS7_value(st, i) SKM_sk_value(PKCS7, (st), (i))
888#define sk_PKCS7_set(st, i, val) SKM_sk_set(PKCS7, (st), (i), (val))
889#define sk_PKCS7_zero(st) SKM_sk_zero(PKCS7, (st))
890#define sk_PKCS7_push(st, val) SKM_sk_push(PKCS7, (st), (val))
891#define sk_PKCS7_unshift(st, val) SKM_sk_unshift(PKCS7, (st), (val))
892#define sk_PKCS7_find(st, val) SKM_sk_find(PKCS7, (st), (val))
893#define sk_PKCS7_delete(st, i) SKM_sk_delete(PKCS7, (st), (i))
894#define sk_PKCS7_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7, (st), (ptr))
895#define sk_PKCS7_insert(st, val, i) SKM_sk_insert(PKCS7, (st), (val), (i))
896#define sk_PKCS7_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7, (st), (cmp))
897#define sk_PKCS7_dup(st) SKM_sk_dup(PKCS7, st)
898#define sk_PKCS7_pop_free(st, free_func) SKM_sk_pop_free(PKCS7, (st), (free_func))
899#define sk_PKCS7_shift(st) SKM_sk_shift(PKCS7, (st))
900#define sk_PKCS7_pop(st) SKM_sk_pop(PKCS7, (st))
901#define sk_PKCS7_sort(st) SKM_sk_sort(PKCS7, (st))
902#define sk_PKCS7_is_sorted(st) SKM_sk_is_sorted(PKCS7, (st))
903
904#define sk_PKCS7_RECIP_INFO_new(st) SKM_sk_new(PKCS7_RECIP_INFO, (st))
905#define sk_PKCS7_RECIP_INFO_new_null() SKM_sk_new_null(PKCS7_RECIP_INFO)
906#define sk_PKCS7_RECIP_INFO_free(st) SKM_sk_free(PKCS7_RECIP_INFO, (st))
907#define sk_PKCS7_RECIP_INFO_num(st) SKM_sk_num(PKCS7_RECIP_INFO, (st))
908#define sk_PKCS7_RECIP_INFO_value(st, i) SKM_sk_value(PKCS7_RECIP_INFO, (st), (i))
909#define sk_PKCS7_RECIP_INFO_set(st, i, val) SKM_sk_set(PKCS7_RECIP_INFO, (st), (i), (val))
910#define sk_PKCS7_RECIP_INFO_zero(st) SKM_sk_zero(PKCS7_RECIP_INFO, (st))
911#define sk_PKCS7_RECIP_INFO_push(st, val) SKM_sk_push(PKCS7_RECIP_INFO, (st), (val))
912#define sk_PKCS7_RECIP_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_RECIP_INFO, (st), (val))
913#define sk_PKCS7_RECIP_INFO_find(st, val) SKM_sk_find(PKCS7_RECIP_INFO, (st), (val))
914#define sk_PKCS7_RECIP_INFO_delete(st, i) SKM_sk_delete(PKCS7_RECIP_INFO, (st), (i))
915#define sk_PKCS7_RECIP_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_RECIP_INFO, (st), (ptr))
916#define sk_PKCS7_RECIP_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_RECIP_INFO, (st), (val), (i))
917#define sk_PKCS7_RECIP_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_RECIP_INFO, (st), (cmp))
918#define sk_PKCS7_RECIP_INFO_dup(st) SKM_sk_dup(PKCS7_RECIP_INFO, st)
919#define sk_PKCS7_RECIP_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_RECIP_INFO, (st), (free_func))
920#define sk_PKCS7_RECIP_INFO_shift(st) SKM_sk_shift(PKCS7_RECIP_INFO, (st))
921#define sk_PKCS7_RECIP_INFO_pop(st) SKM_sk_pop(PKCS7_RECIP_INFO, (st))
922#define sk_PKCS7_RECIP_INFO_sort(st) SKM_sk_sort(PKCS7_RECIP_INFO, (st))
923#define sk_PKCS7_RECIP_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_RECIP_INFO, (st))
924
925#define sk_PKCS7_SIGNER_INFO_new(st) SKM_sk_new(PKCS7_SIGNER_INFO, (st))
926#define sk_PKCS7_SIGNER_INFO_new_null() SKM_sk_new_null(PKCS7_SIGNER_INFO)
927#define sk_PKCS7_SIGNER_INFO_free(st) SKM_sk_free(PKCS7_SIGNER_INFO, (st))
928#define sk_PKCS7_SIGNER_INFO_num(st) SKM_sk_num(PKCS7_SIGNER_INFO, (st))
929#define sk_PKCS7_SIGNER_INFO_value(st, i) SKM_sk_value(PKCS7_SIGNER_INFO, (st), (i))
930#define sk_PKCS7_SIGNER_INFO_set(st, i, val) SKM_sk_set(PKCS7_SIGNER_INFO, (st), (i), (val))
931#define sk_PKCS7_SIGNER_INFO_zero(st) SKM_sk_zero(PKCS7_SIGNER_INFO, (st))
932#define sk_PKCS7_SIGNER_INFO_push(st, val) SKM_sk_push(PKCS7_SIGNER_INFO, (st), (val))
933#define sk_PKCS7_SIGNER_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_SIGNER_INFO, (st), (val))
934#define sk_PKCS7_SIGNER_INFO_find(st, val) SKM_sk_find(PKCS7_SIGNER_INFO, (st), (val))
935#define sk_PKCS7_SIGNER_INFO_delete(st, i) SKM_sk_delete(PKCS7_SIGNER_INFO, (st), (i))
936#define sk_PKCS7_SIGNER_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_SIGNER_INFO, (st), (ptr))
937#define sk_PKCS7_SIGNER_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_SIGNER_INFO, (st), (val), (i))
938#define sk_PKCS7_SIGNER_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_SIGNER_INFO, (st), (cmp))
939#define sk_PKCS7_SIGNER_INFO_dup(st) SKM_sk_dup(PKCS7_SIGNER_INFO, st)
940#define sk_PKCS7_SIGNER_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_SIGNER_INFO, (st), (free_func))
941#define sk_PKCS7_SIGNER_INFO_shift(st) SKM_sk_shift(PKCS7_SIGNER_INFO, (st))
942#define sk_PKCS7_SIGNER_INFO_pop(st) SKM_sk_pop(PKCS7_SIGNER_INFO, (st))
943#define sk_PKCS7_SIGNER_INFO_sort(st) SKM_sk_sort(PKCS7_SIGNER_INFO, (st))
944#define sk_PKCS7_SIGNER_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_SIGNER_INFO, (st))
945
946#define sk_POLICYINFO_new(st) SKM_sk_new(POLICYINFO, (st))
947#define sk_POLICYINFO_new_null() SKM_sk_new_null(POLICYINFO)
948#define sk_POLICYINFO_free(st) SKM_sk_free(POLICYINFO, (st))
949#define sk_POLICYINFO_num(st) SKM_sk_num(POLICYINFO, (st))
950#define sk_POLICYINFO_value(st, i) SKM_sk_value(POLICYINFO, (st), (i))
951#define sk_POLICYINFO_set(st, i, val) SKM_sk_set(POLICYINFO, (st), (i), (val))
952#define sk_POLICYINFO_zero(st) SKM_sk_zero(POLICYINFO, (st))
953#define sk_POLICYINFO_push(st, val) SKM_sk_push(POLICYINFO, (st), (val))
954#define sk_POLICYINFO_unshift(st, val) SKM_sk_unshift(POLICYINFO, (st), (val))
955#define sk_POLICYINFO_find(st, val) SKM_sk_find(POLICYINFO, (st), (val))
956#define sk_POLICYINFO_delete(st, i) SKM_sk_delete(POLICYINFO, (st), (i))
957#define sk_POLICYINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYINFO, (st), (ptr))
958#define sk_POLICYINFO_insert(st, val, i) SKM_sk_insert(POLICYINFO, (st), (val), (i))
959#define sk_POLICYINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYINFO, (st), (cmp))
960#define sk_POLICYINFO_dup(st) SKM_sk_dup(POLICYINFO, st)
961#define sk_POLICYINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYINFO, (st), (free_func))
962#define sk_POLICYINFO_shift(st) SKM_sk_shift(POLICYINFO, (st))
963#define sk_POLICYINFO_pop(st) SKM_sk_pop(POLICYINFO, (st))
964#define sk_POLICYINFO_sort(st) SKM_sk_sort(POLICYINFO, (st))
965#define sk_POLICYINFO_is_sorted(st) SKM_sk_is_sorted(POLICYINFO, (st))
966
967#define sk_POLICYQUALINFO_new(st) SKM_sk_new(POLICYQUALINFO, (st))
968#define sk_POLICYQUALINFO_new_null() SKM_sk_new_null(POLICYQUALINFO)
969#define sk_POLICYQUALINFO_free(st) SKM_sk_free(POLICYQUALINFO, (st))
970#define sk_POLICYQUALINFO_num(st) SKM_sk_num(POLICYQUALINFO, (st))
971#define sk_POLICYQUALINFO_value(st, i) SKM_sk_value(POLICYQUALINFO, (st), (i))
972#define sk_POLICYQUALINFO_set(st, i, val) SKM_sk_set(POLICYQUALINFO, (st), (i), (val))
973#define sk_POLICYQUALINFO_zero(st) SKM_sk_zero(POLICYQUALINFO, (st))
974#define sk_POLICYQUALINFO_push(st, val) SKM_sk_push(POLICYQUALINFO, (st), (val))
975#define sk_POLICYQUALINFO_unshift(st, val) SKM_sk_unshift(POLICYQUALINFO, (st), (val))
976#define sk_POLICYQUALINFO_find(st, val) SKM_sk_find(POLICYQUALINFO, (st), (val))
977#define sk_POLICYQUALINFO_delete(st, i) SKM_sk_delete(POLICYQUALINFO, (st), (i))
978#define sk_POLICYQUALINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYQUALINFO, (st), (ptr))
979#define sk_POLICYQUALINFO_insert(st, val, i) SKM_sk_insert(POLICYQUALINFO, (st), (val), (i))
980#define sk_POLICYQUALINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYQUALINFO, (st), (cmp))
981#define sk_POLICYQUALINFO_dup(st) SKM_sk_dup(POLICYQUALINFO, st)
982#define sk_POLICYQUALINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYQUALINFO, (st), (free_func))
983#define sk_POLICYQUALINFO_shift(st) SKM_sk_shift(POLICYQUALINFO, (st))
984#define sk_POLICYQUALINFO_pop(st) SKM_sk_pop(POLICYQUALINFO, (st))
985#define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st))
986#define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st))
987
988#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st))
989#define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER)
990#define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st))
991#define sk_SSL_CIPHER_num(st) SKM_sk_num(SSL_CIPHER, (st))
992#define sk_SSL_CIPHER_value(st, i) SKM_sk_value(SSL_CIPHER, (st), (i))
993#define sk_SSL_CIPHER_set(st, i, val) SKM_sk_set(SSL_CIPHER, (st), (i), (val))
994#define sk_SSL_CIPHER_zero(st) SKM_sk_zero(SSL_CIPHER, (st))
995#define sk_SSL_CIPHER_push(st, val) SKM_sk_push(SSL_CIPHER, (st), (val))
996#define sk_SSL_CIPHER_unshift(st, val) SKM_sk_unshift(SSL_CIPHER, (st), (val))
997#define sk_SSL_CIPHER_find(st, val) SKM_sk_find(SSL_CIPHER, (st), (val))
998#define sk_SSL_CIPHER_delete(st, i) SKM_sk_delete(SSL_CIPHER, (st), (i))
999#define sk_SSL_CIPHER_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_CIPHER, (st), (ptr))
1000#define sk_SSL_CIPHER_insert(st, val, i) SKM_sk_insert(SSL_CIPHER, (st), (val), (i))
1001#define sk_SSL_CIPHER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_CIPHER, (st), (cmp))
1002#define sk_SSL_CIPHER_dup(st) SKM_sk_dup(SSL_CIPHER, st)
1003#define sk_SSL_CIPHER_pop_free(st, free_func) SKM_sk_pop_free(SSL_CIPHER, (st), (free_func))
1004#define sk_SSL_CIPHER_shift(st) SKM_sk_shift(SSL_CIPHER, (st))
1005#define sk_SSL_CIPHER_pop(st) SKM_sk_pop(SSL_CIPHER, (st))
1006#define sk_SSL_CIPHER_sort(st) SKM_sk_sort(SSL_CIPHER, (st))
1007#define sk_SSL_CIPHER_is_sorted(st) SKM_sk_is_sorted(SSL_CIPHER, (st))
1008
1009#define sk_SSL_COMP_new(st) SKM_sk_new(SSL_COMP, (st))
1010#define sk_SSL_COMP_new_null() SKM_sk_new_null(SSL_COMP)
1011#define sk_SSL_COMP_free(st) SKM_sk_free(SSL_COMP, (st))
1012#define sk_SSL_COMP_num(st) SKM_sk_num(SSL_COMP, (st))
1013#define sk_SSL_COMP_value(st, i) SKM_sk_value(SSL_COMP, (st), (i))
1014#define sk_SSL_COMP_set(st, i, val) SKM_sk_set(SSL_COMP, (st), (i), (val))
1015#define sk_SSL_COMP_zero(st) SKM_sk_zero(SSL_COMP, (st))
1016#define sk_SSL_COMP_push(st, val) SKM_sk_push(SSL_COMP, (st), (val))
1017#define sk_SSL_COMP_unshift(st, val) SKM_sk_unshift(SSL_COMP, (st), (val))
1018#define sk_SSL_COMP_find(st, val) SKM_sk_find(SSL_COMP, (st), (val))
1019#define sk_SSL_COMP_delete(st, i) SKM_sk_delete(SSL_COMP, (st), (i))
1020#define sk_SSL_COMP_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_COMP, (st), (ptr))
1021#define sk_SSL_COMP_insert(st, val, i) SKM_sk_insert(SSL_COMP, (st), (val), (i))
1022#define sk_SSL_COMP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_COMP, (st), (cmp))
1023#define sk_SSL_COMP_dup(st) SKM_sk_dup(SSL_COMP, st)
1024#define sk_SSL_COMP_pop_free(st, free_func) SKM_sk_pop_free(SSL_COMP, (st), (free_func))
1025#define sk_SSL_COMP_shift(st) SKM_sk_shift(SSL_COMP, (st))
1026#define sk_SSL_COMP_pop(st) SKM_sk_pop(SSL_COMP, (st))
1027#define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st))
1028#define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st))
1029
1030#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st))
1031#define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID)
1032#define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st))
1033#define sk_SXNETID_num(st) SKM_sk_num(SXNETID, (st))
1034#define sk_SXNETID_value(st, i) SKM_sk_value(SXNETID, (st), (i))
1035#define sk_SXNETID_set(st, i, val) SKM_sk_set(SXNETID, (st), (i), (val))
1036#define sk_SXNETID_zero(st) SKM_sk_zero(SXNETID, (st))
1037#define sk_SXNETID_push(st, val) SKM_sk_push(SXNETID, (st), (val))
1038#define sk_SXNETID_unshift(st, val) SKM_sk_unshift(SXNETID, (st), (val))
1039#define sk_SXNETID_find(st, val) SKM_sk_find(SXNETID, (st), (val))
1040#define sk_SXNETID_delete(st, i) SKM_sk_delete(SXNETID, (st), (i))
1041#define sk_SXNETID_delete_ptr(st, ptr) SKM_sk_delete_ptr(SXNETID, (st), (ptr))
1042#define sk_SXNETID_insert(st, val, i) SKM_sk_insert(SXNETID, (st), (val), (i))
1043#define sk_SXNETID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SXNETID, (st), (cmp))
1044#define sk_SXNETID_dup(st) SKM_sk_dup(SXNETID, st)
1045#define sk_SXNETID_pop_free(st, free_func) SKM_sk_pop_free(SXNETID, (st), (free_func))
1046#define sk_SXNETID_shift(st) SKM_sk_shift(SXNETID, (st))
1047#define sk_SXNETID_pop(st) SKM_sk_pop(SXNETID, (st))
1048#define sk_SXNETID_sort(st) SKM_sk_sort(SXNETID, (st))
1049#define sk_SXNETID_is_sorted(st) SKM_sk_is_sorted(SXNETID, (st))
1050
1051#define sk_UI_STRING_new(st) SKM_sk_new(UI_STRING, (st))
1052#define sk_UI_STRING_new_null() SKM_sk_new_null(UI_STRING)
1053#define sk_UI_STRING_free(st) SKM_sk_free(UI_STRING, (st))
1054#define sk_UI_STRING_num(st) SKM_sk_num(UI_STRING, (st))
1055#define sk_UI_STRING_value(st, i) SKM_sk_value(UI_STRING, (st), (i))
1056#define sk_UI_STRING_set(st, i, val) SKM_sk_set(UI_STRING, (st), (i), (val))
1057#define sk_UI_STRING_zero(st) SKM_sk_zero(UI_STRING, (st))
1058#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val))
1059#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val))
1060#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val))
1061#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i))
1062#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr))
1063#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i))
1064#define sk_UI_STRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(UI_STRING, (st), (cmp))
1065#define sk_UI_STRING_dup(st) SKM_sk_dup(UI_STRING, st)
1066#define sk_UI_STRING_pop_free(st, free_func) SKM_sk_pop_free(UI_STRING, (st), (free_func))
1067#define sk_UI_STRING_shift(st) SKM_sk_shift(UI_STRING, (st))
1068#define sk_UI_STRING_pop(st) SKM_sk_pop(UI_STRING, (st))
1069#define sk_UI_STRING_sort(st) SKM_sk_sort(UI_STRING, (st))
1070#define sk_UI_STRING_is_sorted(st) SKM_sk_is_sorted(UI_STRING, (st))
1071
1072#define sk_X509_new(st) SKM_sk_new(X509, (st))
1073#define sk_X509_new_null() SKM_sk_new_null(X509)
1074#define sk_X509_free(st) SKM_sk_free(X509, (st))
1075#define sk_X509_num(st) SKM_sk_num(X509, (st))
1076#define sk_X509_value(st, i) SKM_sk_value(X509, (st), (i))
1077#define sk_X509_set(st, i, val) SKM_sk_set(X509, (st), (i), (val))
1078#define sk_X509_zero(st) SKM_sk_zero(X509, (st))
1079#define sk_X509_push(st, val) SKM_sk_push(X509, (st), (val))
1080#define sk_X509_unshift(st, val) SKM_sk_unshift(X509, (st), (val))
1081#define sk_X509_find(st, val) SKM_sk_find(X509, (st), (val))
1082#define sk_X509_delete(st, i) SKM_sk_delete(X509, (st), (i))
1083#define sk_X509_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509, (st), (ptr))
1084#define sk_X509_insert(st, val, i) SKM_sk_insert(X509, (st), (val), (i))
1085#define sk_X509_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509, (st), (cmp))
1086#define sk_X509_dup(st) SKM_sk_dup(X509, st)
1087#define sk_X509_pop_free(st, free_func) SKM_sk_pop_free(X509, (st), (free_func))
1088#define sk_X509_shift(st) SKM_sk_shift(X509, (st))
1089#define sk_X509_pop(st) SKM_sk_pop(X509, (st))
1090#define sk_X509_sort(st) SKM_sk_sort(X509, (st))
1091#define sk_X509_is_sorted(st) SKM_sk_is_sorted(X509, (st))
1092
1093#define sk_X509V3_EXT_METHOD_new(st) SKM_sk_new(X509V3_EXT_METHOD, (st))
1094#define sk_X509V3_EXT_METHOD_new_null() SKM_sk_new_null(X509V3_EXT_METHOD)
1095#define sk_X509V3_EXT_METHOD_free(st) SKM_sk_free(X509V3_EXT_METHOD, (st))
1096#define sk_X509V3_EXT_METHOD_num(st) SKM_sk_num(X509V3_EXT_METHOD, (st))
1097#define sk_X509V3_EXT_METHOD_value(st, i) SKM_sk_value(X509V3_EXT_METHOD, (st), (i))
1098#define sk_X509V3_EXT_METHOD_set(st, i, val) SKM_sk_set(X509V3_EXT_METHOD, (st), (i), (val))
1099#define sk_X509V3_EXT_METHOD_zero(st) SKM_sk_zero(X509V3_EXT_METHOD, (st))
1100#define sk_X509V3_EXT_METHOD_push(st, val) SKM_sk_push(X509V3_EXT_METHOD, (st), (val))
1101#define sk_X509V3_EXT_METHOD_unshift(st, val) SKM_sk_unshift(X509V3_EXT_METHOD, (st), (val))
1102#define sk_X509V3_EXT_METHOD_find(st, val) SKM_sk_find(X509V3_EXT_METHOD, (st), (val))
1103#define sk_X509V3_EXT_METHOD_delete(st, i) SKM_sk_delete(X509V3_EXT_METHOD, (st), (i))
1104#define sk_X509V3_EXT_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509V3_EXT_METHOD, (st), (ptr))
1105#define sk_X509V3_EXT_METHOD_insert(st, val, i) SKM_sk_insert(X509V3_EXT_METHOD, (st), (val), (i))
1106#define sk_X509V3_EXT_METHOD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509V3_EXT_METHOD, (st), (cmp))
1107#define sk_X509V3_EXT_METHOD_dup(st) SKM_sk_dup(X509V3_EXT_METHOD, st)
1108#define sk_X509V3_EXT_METHOD_pop_free(st, free_func) SKM_sk_pop_free(X509V3_EXT_METHOD, (st), (free_func))
1109#define sk_X509V3_EXT_METHOD_shift(st) SKM_sk_shift(X509V3_EXT_METHOD, (st))
1110#define sk_X509V3_EXT_METHOD_pop(st) SKM_sk_pop(X509V3_EXT_METHOD, (st))
1111#define sk_X509V3_EXT_METHOD_sort(st) SKM_sk_sort(X509V3_EXT_METHOD, (st))
1112#define sk_X509V3_EXT_METHOD_is_sorted(st) SKM_sk_is_sorted(X509V3_EXT_METHOD, (st))
1113
1114#define sk_X509_ALGOR_new(st) SKM_sk_new(X509_ALGOR, (st))
1115#define sk_X509_ALGOR_new_null() SKM_sk_new_null(X509_ALGOR)
1116#define sk_X509_ALGOR_free(st) SKM_sk_free(X509_ALGOR, (st))
1117#define sk_X509_ALGOR_num(st) SKM_sk_num(X509_ALGOR, (st))
1118#define sk_X509_ALGOR_value(st, i) SKM_sk_value(X509_ALGOR, (st), (i))
1119#define sk_X509_ALGOR_set(st, i, val) SKM_sk_set(X509_ALGOR, (st), (i), (val))
1120#define sk_X509_ALGOR_zero(st) SKM_sk_zero(X509_ALGOR, (st))
1121#define sk_X509_ALGOR_push(st, val) SKM_sk_push(X509_ALGOR, (st), (val))
1122#define sk_X509_ALGOR_unshift(st, val) SKM_sk_unshift(X509_ALGOR, (st), (val))
1123#define sk_X509_ALGOR_find(st, val) SKM_sk_find(X509_ALGOR, (st), (val))
1124#define sk_X509_ALGOR_delete(st, i) SKM_sk_delete(X509_ALGOR, (st), (i))
1125#define sk_X509_ALGOR_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ALGOR, (st), (ptr))
1126#define sk_X509_ALGOR_insert(st, val, i) SKM_sk_insert(X509_ALGOR, (st), (val), (i))
1127#define sk_X509_ALGOR_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ALGOR, (st), (cmp))
1128#define sk_X509_ALGOR_dup(st) SKM_sk_dup(X509_ALGOR, st)
1129#define sk_X509_ALGOR_pop_free(st, free_func) SKM_sk_pop_free(X509_ALGOR, (st), (free_func))
1130#define sk_X509_ALGOR_shift(st) SKM_sk_shift(X509_ALGOR, (st))
1131#define sk_X509_ALGOR_pop(st) SKM_sk_pop(X509_ALGOR, (st))
1132#define sk_X509_ALGOR_sort(st) SKM_sk_sort(X509_ALGOR, (st))
1133#define sk_X509_ALGOR_is_sorted(st) SKM_sk_is_sorted(X509_ALGOR, (st))
1134
1135#define sk_X509_ATTRIBUTE_new(st) SKM_sk_new(X509_ATTRIBUTE, (st))
1136#define sk_X509_ATTRIBUTE_new_null() SKM_sk_new_null(X509_ATTRIBUTE)
1137#define sk_X509_ATTRIBUTE_free(st) SKM_sk_free(X509_ATTRIBUTE, (st))
1138#define sk_X509_ATTRIBUTE_num(st) SKM_sk_num(X509_ATTRIBUTE, (st))
1139#define sk_X509_ATTRIBUTE_value(st, i) SKM_sk_value(X509_ATTRIBUTE, (st), (i))
1140#define sk_X509_ATTRIBUTE_set(st, i, val) SKM_sk_set(X509_ATTRIBUTE, (st), (i), (val))
1141#define sk_X509_ATTRIBUTE_zero(st) SKM_sk_zero(X509_ATTRIBUTE, (st))
1142#define sk_X509_ATTRIBUTE_push(st, val) SKM_sk_push(X509_ATTRIBUTE, (st), (val))
1143#define sk_X509_ATTRIBUTE_unshift(st, val) SKM_sk_unshift(X509_ATTRIBUTE, (st), (val))
1144#define sk_X509_ATTRIBUTE_find(st, val) SKM_sk_find(X509_ATTRIBUTE, (st), (val))
1145#define sk_X509_ATTRIBUTE_delete(st, i) SKM_sk_delete(X509_ATTRIBUTE, (st), (i))
1146#define sk_X509_ATTRIBUTE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ATTRIBUTE, (st), (ptr))
1147#define sk_X509_ATTRIBUTE_insert(st, val, i) SKM_sk_insert(X509_ATTRIBUTE, (st), (val), (i))
1148#define sk_X509_ATTRIBUTE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ATTRIBUTE, (st), (cmp))
1149#define sk_X509_ATTRIBUTE_dup(st) SKM_sk_dup(X509_ATTRIBUTE, st)
1150#define sk_X509_ATTRIBUTE_pop_free(st, free_func) SKM_sk_pop_free(X509_ATTRIBUTE, (st), (free_func))
1151#define sk_X509_ATTRIBUTE_shift(st) SKM_sk_shift(X509_ATTRIBUTE, (st))
1152#define sk_X509_ATTRIBUTE_pop(st) SKM_sk_pop(X509_ATTRIBUTE, (st))
1153#define sk_X509_ATTRIBUTE_sort(st) SKM_sk_sort(X509_ATTRIBUTE, (st))
1154#define sk_X509_ATTRIBUTE_is_sorted(st) SKM_sk_is_sorted(X509_ATTRIBUTE, (st))
1155
1156#define sk_X509_CRL_new(st) SKM_sk_new(X509_CRL, (st))
1157#define sk_X509_CRL_new_null() SKM_sk_new_null(X509_CRL)
1158#define sk_X509_CRL_free(st) SKM_sk_free(X509_CRL, (st))
1159#define sk_X509_CRL_num(st) SKM_sk_num(X509_CRL, (st))
1160#define sk_X509_CRL_value(st, i) SKM_sk_value(X509_CRL, (st), (i))
1161#define sk_X509_CRL_set(st, i, val) SKM_sk_set(X509_CRL, (st), (i), (val))
1162#define sk_X509_CRL_zero(st) SKM_sk_zero(X509_CRL, (st))
1163#define sk_X509_CRL_push(st, val) SKM_sk_push(X509_CRL, (st), (val))
1164#define sk_X509_CRL_unshift(st, val) SKM_sk_unshift(X509_CRL, (st), (val))
1165#define sk_X509_CRL_find(st, val) SKM_sk_find(X509_CRL, (st), (val))
1166#define sk_X509_CRL_delete(st, i) SKM_sk_delete(X509_CRL, (st), (i))
1167#define sk_X509_CRL_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_CRL, (st), (ptr))
1168#define sk_X509_CRL_insert(st, val, i) SKM_sk_insert(X509_CRL, (st), (val), (i))
1169#define sk_X509_CRL_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_CRL, (st), (cmp))
1170#define sk_X509_CRL_dup(st) SKM_sk_dup(X509_CRL, st)
1171#define sk_X509_CRL_pop_free(st, free_func) SKM_sk_pop_free(X509_CRL, (st), (free_func))
1172#define sk_X509_CRL_shift(st) SKM_sk_shift(X509_CRL, (st))
1173#define sk_X509_CRL_pop(st) SKM_sk_pop(X509_CRL, (st))
1174#define sk_X509_CRL_sort(st) SKM_sk_sort(X509_CRL, (st))
1175#define sk_X509_CRL_is_sorted(st) SKM_sk_is_sorted(X509_CRL, (st))
1176
1177#define sk_X509_EXTENSION_new(st) SKM_sk_new(X509_EXTENSION, (st))
1178#define sk_X509_EXTENSION_new_null() SKM_sk_new_null(X509_EXTENSION)
1179#define sk_X509_EXTENSION_free(st) SKM_sk_free(X509_EXTENSION, (st))
1180#define sk_X509_EXTENSION_num(st) SKM_sk_num(X509_EXTENSION, (st))
1181#define sk_X509_EXTENSION_value(st, i) SKM_sk_value(X509_EXTENSION, (st), (i))
1182#define sk_X509_EXTENSION_set(st, i, val) SKM_sk_set(X509_EXTENSION, (st), (i), (val))
1183#define sk_X509_EXTENSION_zero(st) SKM_sk_zero(X509_EXTENSION, (st))
1184#define sk_X509_EXTENSION_push(st, val) SKM_sk_push(X509_EXTENSION, (st), (val))
1185#define sk_X509_EXTENSION_unshift(st, val) SKM_sk_unshift(X509_EXTENSION, (st), (val))
1186#define sk_X509_EXTENSION_find(st, val) SKM_sk_find(X509_EXTENSION, (st), (val))
1187#define sk_X509_EXTENSION_delete(st, i) SKM_sk_delete(X509_EXTENSION, (st), (i))
1188#define sk_X509_EXTENSION_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_EXTENSION, (st), (ptr))
1189#define sk_X509_EXTENSION_insert(st, val, i) SKM_sk_insert(X509_EXTENSION, (st), (val), (i))
1190#define sk_X509_EXTENSION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_EXTENSION, (st), (cmp))
1191#define sk_X509_EXTENSION_dup(st) SKM_sk_dup(X509_EXTENSION, st)
1192#define sk_X509_EXTENSION_pop_free(st, free_func) SKM_sk_pop_free(X509_EXTENSION, (st), (free_func))
1193#define sk_X509_EXTENSION_shift(st) SKM_sk_shift(X509_EXTENSION, (st))
1194#define sk_X509_EXTENSION_pop(st) SKM_sk_pop(X509_EXTENSION, (st))
1195#define sk_X509_EXTENSION_sort(st) SKM_sk_sort(X509_EXTENSION, (st))
1196#define sk_X509_EXTENSION_is_sorted(st) SKM_sk_is_sorted(X509_EXTENSION, (st))
1197
1198#define sk_X509_INFO_new(st) SKM_sk_new(X509_INFO, (st))
1199#define sk_X509_INFO_new_null() SKM_sk_new_null(X509_INFO)
1200#define sk_X509_INFO_free(st) SKM_sk_free(X509_INFO, (st))
1201#define sk_X509_INFO_num(st) SKM_sk_num(X509_INFO, (st))
1202#define sk_X509_INFO_value(st, i) SKM_sk_value(X509_INFO, (st), (i))
1203#define sk_X509_INFO_set(st, i, val) SKM_sk_set(X509_INFO, (st), (i), (val))
1204#define sk_X509_INFO_zero(st) SKM_sk_zero(X509_INFO, (st))
1205#define sk_X509_INFO_push(st, val) SKM_sk_push(X509_INFO, (st), (val))
1206#define sk_X509_INFO_unshift(st, val) SKM_sk_unshift(X509_INFO, (st), (val))
1207#define sk_X509_INFO_find(st, val) SKM_sk_find(X509_INFO, (st), (val))
1208#define sk_X509_INFO_delete(st, i) SKM_sk_delete(X509_INFO, (st), (i))
1209#define sk_X509_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_INFO, (st), (ptr))
1210#define sk_X509_INFO_insert(st, val, i) SKM_sk_insert(X509_INFO, (st), (val), (i))
1211#define sk_X509_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_INFO, (st), (cmp))
1212#define sk_X509_INFO_dup(st) SKM_sk_dup(X509_INFO, st)
1213#define sk_X509_INFO_pop_free(st, free_func) SKM_sk_pop_free(X509_INFO, (st), (free_func))
1214#define sk_X509_INFO_shift(st) SKM_sk_shift(X509_INFO, (st))
1215#define sk_X509_INFO_pop(st) SKM_sk_pop(X509_INFO, (st))
1216#define sk_X509_INFO_sort(st) SKM_sk_sort(X509_INFO, (st))
1217#define sk_X509_INFO_is_sorted(st) SKM_sk_is_sorted(X509_INFO, (st))
1218
1219#define sk_X509_LOOKUP_new(st) SKM_sk_new(X509_LOOKUP, (st))
1220#define sk_X509_LOOKUP_new_null() SKM_sk_new_null(X509_LOOKUP)
1221#define sk_X509_LOOKUP_free(st) SKM_sk_free(X509_LOOKUP, (st))
1222#define sk_X509_LOOKUP_num(st) SKM_sk_num(X509_LOOKUP, (st))
1223#define sk_X509_LOOKUP_value(st, i) SKM_sk_value(X509_LOOKUP, (st), (i))
1224#define sk_X509_LOOKUP_set(st, i, val) SKM_sk_set(X509_LOOKUP, (st), (i), (val))
1225#define sk_X509_LOOKUP_zero(st) SKM_sk_zero(X509_LOOKUP, (st))
1226#define sk_X509_LOOKUP_push(st, val) SKM_sk_push(X509_LOOKUP, (st), (val))
1227#define sk_X509_LOOKUP_unshift(st, val) SKM_sk_unshift(X509_LOOKUP, (st), (val))
1228#define sk_X509_LOOKUP_find(st, val) SKM_sk_find(X509_LOOKUP, (st), (val))
1229#define sk_X509_LOOKUP_delete(st, i) SKM_sk_delete(X509_LOOKUP, (st), (i))
1230#define sk_X509_LOOKUP_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_LOOKUP, (st), (ptr))
1231#define sk_X509_LOOKUP_insert(st, val, i) SKM_sk_insert(X509_LOOKUP, (st), (val), (i))
1232#define sk_X509_LOOKUP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_LOOKUP, (st), (cmp))
1233#define sk_X509_LOOKUP_dup(st) SKM_sk_dup(X509_LOOKUP, st)
1234#define sk_X509_LOOKUP_pop_free(st, free_func) SKM_sk_pop_free(X509_LOOKUP, (st), (free_func))
1235#define sk_X509_LOOKUP_shift(st) SKM_sk_shift(X509_LOOKUP, (st))
1236#define sk_X509_LOOKUP_pop(st) SKM_sk_pop(X509_LOOKUP, (st))
1237#define sk_X509_LOOKUP_sort(st) SKM_sk_sort(X509_LOOKUP, (st))
1238#define sk_X509_LOOKUP_is_sorted(st) SKM_sk_is_sorted(X509_LOOKUP, (st))
1239
1240#define sk_X509_NAME_new(st) SKM_sk_new(X509_NAME, (st))
1241#define sk_X509_NAME_new_null() SKM_sk_new_null(X509_NAME)
1242#define sk_X509_NAME_free(st) SKM_sk_free(X509_NAME, (st))
1243#define sk_X509_NAME_num(st) SKM_sk_num(X509_NAME, (st))
1244#define sk_X509_NAME_value(st, i) SKM_sk_value(X509_NAME, (st), (i))
1245#define sk_X509_NAME_set(st, i, val) SKM_sk_set(X509_NAME, (st), (i), (val))
1246#define sk_X509_NAME_zero(st) SKM_sk_zero(X509_NAME, (st))
1247#define sk_X509_NAME_push(st, val) SKM_sk_push(X509_NAME, (st), (val))
1248#define sk_X509_NAME_unshift(st, val) SKM_sk_unshift(X509_NAME, (st), (val))
1249#define sk_X509_NAME_find(st, val) SKM_sk_find(X509_NAME, (st), (val))
1250#define sk_X509_NAME_delete(st, i) SKM_sk_delete(X509_NAME, (st), (i))
1251#define sk_X509_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME, (st), (ptr))
1252#define sk_X509_NAME_insert(st, val, i) SKM_sk_insert(X509_NAME, (st), (val), (i))
1253#define sk_X509_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME, (st), (cmp))
1254#define sk_X509_NAME_dup(st) SKM_sk_dup(X509_NAME, st)
1255#define sk_X509_NAME_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME, (st), (free_func))
1256#define sk_X509_NAME_shift(st) SKM_sk_shift(X509_NAME, (st))
1257#define sk_X509_NAME_pop(st) SKM_sk_pop(X509_NAME, (st))
1258#define sk_X509_NAME_sort(st) SKM_sk_sort(X509_NAME, (st))
1259#define sk_X509_NAME_is_sorted(st) SKM_sk_is_sorted(X509_NAME, (st))
1260
1261#define sk_X509_NAME_ENTRY_new(st) SKM_sk_new(X509_NAME_ENTRY, (st))
1262#define sk_X509_NAME_ENTRY_new_null() SKM_sk_new_null(X509_NAME_ENTRY)
1263#define sk_X509_NAME_ENTRY_free(st) SKM_sk_free(X509_NAME_ENTRY, (st))
1264#define sk_X509_NAME_ENTRY_num(st) SKM_sk_num(X509_NAME_ENTRY, (st))
1265#define sk_X509_NAME_ENTRY_value(st, i) SKM_sk_value(X509_NAME_ENTRY, (st), (i))
1266#define sk_X509_NAME_ENTRY_set(st, i, val) SKM_sk_set(X509_NAME_ENTRY, (st), (i), (val))
1267#define sk_X509_NAME_ENTRY_zero(st) SKM_sk_zero(X509_NAME_ENTRY, (st))
1268#define sk_X509_NAME_ENTRY_push(st, val) SKM_sk_push(X509_NAME_ENTRY, (st), (val))
1269#define sk_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(X509_NAME_ENTRY, (st), (val))
1270#define sk_X509_NAME_ENTRY_find(st, val) SKM_sk_find(X509_NAME_ENTRY, (st), (val))
1271#define sk_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(X509_NAME_ENTRY, (st), (i))
1272#define sk_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME_ENTRY, (st), (ptr))
1273#define sk_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(X509_NAME_ENTRY, (st), (val), (i))
1274#define sk_X509_NAME_ENTRY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME_ENTRY, (st), (cmp))
1275#define sk_X509_NAME_ENTRY_dup(st) SKM_sk_dup(X509_NAME_ENTRY, st)
1276#define sk_X509_NAME_ENTRY_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME_ENTRY, (st), (free_func))
1277#define sk_X509_NAME_ENTRY_shift(st) SKM_sk_shift(X509_NAME_ENTRY, (st))
1278#define sk_X509_NAME_ENTRY_pop(st) SKM_sk_pop(X509_NAME_ENTRY, (st))
1279#define sk_X509_NAME_ENTRY_sort(st) SKM_sk_sort(X509_NAME_ENTRY, (st))
1280#define sk_X509_NAME_ENTRY_is_sorted(st) SKM_sk_is_sorted(X509_NAME_ENTRY, (st))
1281
1282#define sk_X509_OBJECT_new(st) SKM_sk_new(X509_OBJECT, (st))
1283#define sk_X509_OBJECT_new_null() SKM_sk_new_null(X509_OBJECT)
1284#define sk_X509_OBJECT_free(st) SKM_sk_free(X509_OBJECT, (st))
1285#define sk_X509_OBJECT_num(st) SKM_sk_num(X509_OBJECT, (st))
1286#define sk_X509_OBJECT_value(st, i) SKM_sk_value(X509_OBJECT, (st), (i))
1287#define sk_X509_OBJECT_set(st, i, val) SKM_sk_set(X509_OBJECT, (st), (i), (val))
1288#define sk_X509_OBJECT_zero(st) SKM_sk_zero(X509_OBJECT, (st))
1289#define sk_X509_OBJECT_push(st, val) SKM_sk_push(X509_OBJECT, (st), (val))
1290#define sk_X509_OBJECT_unshift(st, val) SKM_sk_unshift(X509_OBJECT, (st), (val))
1291#define sk_X509_OBJECT_find(st, val) SKM_sk_find(X509_OBJECT, (st), (val))
1292#define sk_X509_OBJECT_delete(st, i) SKM_sk_delete(X509_OBJECT, (st), (i))
1293#define sk_X509_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_OBJECT, (st), (ptr))
1294#define sk_X509_OBJECT_insert(st, val, i) SKM_sk_insert(X509_OBJECT, (st), (val), (i))
1295#define sk_X509_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_OBJECT, (st), (cmp))
1296#define sk_X509_OBJECT_dup(st) SKM_sk_dup(X509_OBJECT, st)
1297#define sk_X509_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(X509_OBJECT, (st), (free_func))
1298#define sk_X509_OBJECT_shift(st) SKM_sk_shift(X509_OBJECT, (st))
1299#define sk_X509_OBJECT_pop(st) SKM_sk_pop(X509_OBJECT, (st))
1300#define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st))
1301#define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st))
1302
1303#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st))
1304#define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE)
1305#define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st))
1306#define sk_X509_PURPOSE_num(st) SKM_sk_num(X509_PURPOSE, (st))
1307#define sk_X509_PURPOSE_value(st, i) SKM_sk_value(X509_PURPOSE, (st), (i))
1308#define sk_X509_PURPOSE_set(st, i, val) SKM_sk_set(X509_PURPOSE, (st), (i), (val))
1309#define sk_X509_PURPOSE_zero(st) SKM_sk_zero(X509_PURPOSE, (st))
1310#define sk_X509_PURPOSE_push(st, val) SKM_sk_push(X509_PURPOSE, (st), (val))
1311#define sk_X509_PURPOSE_unshift(st, val) SKM_sk_unshift(X509_PURPOSE, (st), (val))
1312#define sk_X509_PURPOSE_find(st, val) SKM_sk_find(X509_PURPOSE, (st), (val))
1313#define sk_X509_PURPOSE_delete(st, i) SKM_sk_delete(X509_PURPOSE, (st), (i))
1314#define sk_X509_PURPOSE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_PURPOSE, (st), (ptr))
1315#define sk_X509_PURPOSE_insert(st, val, i) SKM_sk_insert(X509_PURPOSE, (st), (val), (i))
1316#define sk_X509_PURPOSE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_PURPOSE, (st), (cmp))
1317#define sk_X509_PURPOSE_dup(st) SKM_sk_dup(X509_PURPOSE, st)
1318#define sk_X509_PURPOSE_pop_free(st, free_func) SKM_sk_pop_free(X509_PURPOSE, (st), (free_func))
1319#define sk_X509_PURPOSE_shift(st) SKM_sk_shift(X509_PURPOSE, (st))
1320#define sk_X509_PURPOSE_pop(st) SKM_sk_pop(X509_PURPOSE, (st))
1321#define sk_X509_PURPOSE_sort(st) SKM_sk_sort(X509_PURPOSE, (st))
1322#define sk_X509_PURPOSE_is_sorted(st) SKM_sk_is_sorted(X509_PURPOSE, (st))
1323
1324#define sk_X509_REVOKED_new(st) SKM_sk_new(X509_REVOKED, (st))
1325#define sk_X509_REVOKED_new_null() SKM_sk_new_null(X509_REVOKED)
1326#define sk_X509_REVOKED_free(st) SKM_sk_free(X509_REVOKED, (st))
1327#define sk_X509_REVOKED_num(st) SKM_sk_num(X509_REVOKED, (st))
1328#define sk_X509_REVOKED_value(st, i) SKM_sk_value(X509_REVOKED, (st), (i))
1329#define sk_X509_REVOKED_set(st, i, val) SKM_sk_set(X509_REVOKED, (st), (i), (val))
1330#define sk_X509_REVOKED_zero(st) SKM_sk_zero(X509_REVOKED, (st))
1331#define sk_X509_REVOKED_push(st, val) SKM_sk_push(X509_REVOKED, (st), (val))
1332#define sk_X509_REVOKED_unshift(st, val) SKM_sk_unshift(X509_REVOKED, (st), (val))
1333#define sk_X509_REVOKED_find(st, val) SKM_sk_find(X509_REVOKED, (st), (val))
1334#define sk_X509_REVOKED_delete(st, i) SKM_sk_delete(X509_REVOKED, (st), (i))
1335#define sk_X509_REVOKED_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_REVOKED, (st), (ptr))
1336#define sk_X509_REVOKED_insert(st, val, i) SKM_sk_insert(X509_REVOKED, (st), (val), (i))
1337#define sk_X509_REVOKED_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_REVOKED, (st), (cmp))
1338#define sk_X509_REVOKED_dup(st) SKM_sk_dup(X509_REVOKED, st)
1339#define sk_X509_REVOKED_pop_free(st, free_func) SKM_sk_pop_free(X509_REVOKED, (st), (free_func))
1340#define sk_X509_REVOKED_shift(st) SKM_sk_shift(X509_REVOKED, (st))
1341#define sk_X509_REVOKED_pop(st) SKM_sk_pop(X509_REVOKED, (st))
1342#define sk_X509_REVOKED_sort(st) SKM_sk_sort(X509_REVOKED, (st))
1343#define sk_X509_REVOKED_is_sorted(st) SKM_sk_is_sorted(X509_REVOKED, (st))
1344
1345#define sk_X509_TRUST_new(st) SKM_sk_new(X509_TRUST, (st))
1346#define sk_X509_TRUST_new_null() SKM_sk_new_null(X509_TRUST)
1347#define sk_X509_TRUST_free(st) SKM_sk_free(X509_TRUST, (st))
1348#define sk_X509_TRUST_num(st) SKM_sk_num(X509_TRUST, (st))
1349#define sk_X509_TRUST_value(st, i) SKM_sk_value(X509_TRUST, (st), (i))
1350#define sk_X509_TRUST_set(st, i, val) SKM_sk_set(X509_TRUST, (st), (i), (val))
1351#define sk_X509_TRUST_zero(st) SKM_sk_zero(X509_TRUST, (st))
1352#define sk_X509_TRUST_push(st, val) SKM_sk_push(X509_TRUST, (st), (val))
1353#define sk_X509_TRUST_unshift(st, val) SKM_sk_unshift(X509_TRUST, (st), (val))
1354#define sk_X509_TRUST_find(st, val) SKM_sk_find(X509_TRUST, (st), (val))
1355#define sk_X509_TRUST_delete(st, i) SKM_sk_delete(X509_TRUST, (st), (i))
1356#define sk_X509_TRUST_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_TRUST, (st), (ptr))
1357#define sk_X509_TRUST_insert(st, val, i) SKM_sk_insert(X509_TRUST, (st), (val), (i))
1358#define sk_X509_TRUST_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_TRUST, (st), (cmp))
1359#define sk_X509_TRUST_dup(st) SKM_sk_dup(X509_TRUST, st)
1360#define sk_X509_TRUST_pop_free(st, free_func) SKM_sk_pop_free(X509_TRUST, (st), (free_func))
1361#define sk_X509_TRUST_shift(st) SKM_sk_shift(X509_TRUST, (st))
1362#define sk_X509_TRUST_pop(st) SKM_sk_pop(X509_TRUST, (st))
1363#define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st))
1364#define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st))
1365
1366#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1367 SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1368#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1369 SKM_ASN1_SET_OF_i2d(ACCESS_DESCRIPTION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1370#define ASN1_seq_pack_ACCESS_DESCRIPTION(st, i2d_func, buf, len) \
1371 SKM_ASN1_seq_pack(ACCESS_DESCRIPTION, (st), (i2d_func), (buf), (len))
1372#define ASN1_seq_unpack_ACCESS_DESCRIPTION(buf, len, d2i_func, free_func) \
1373 SKM_ASN1_seq_unpack(ACCESS_DESCRIPTION, (buf), (len), (d2i_func), (free_func))
1374
1375#define d2i_ASN1_SET_OF_ASN1_INTEGER(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1376 SKM_ASN1_SET_OF_d2i(ASN1_INTEGER, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1377#define i2d_ASN1_SET_OF_ASN1_INTEGER(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1378 SKM_ASN1_SET_OF_i2d(ASN1_INTEGER, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1379#define ASN1_seq_pack_ASN1_INTEGER(st, i2d_func, buf, len) \
1380 SKM_ASN1_seq_pack(ASN1_INTEGER, (st), (i2d_func), (buf), (len))
1381#define ASN1_seq_unpack_ASN1_INTEGER(buf, len, d2i_func, free_func) \
1382 SKM_ASN1_seq_unpack(ASN1_INTEGER, (buf), (len), (d2i_func), (free_func))
1383
1384#define d2i_ASN1_SET_OF_ASN1_OBJECT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1385 SKM_ASN1_SET_OF_d2i(ASN1_OBJECT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1386#define i2d_ASN1_SET_OF_ASN1_OBJECT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1387 SKM_ASN1_SET_OF_i2d(ASN1_OBJECT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1388#define ASN1_seq_pack_ASN1_OBJECT(st, i2d_func, buf, len) \
1389 SKM_ASN1_seq_pack(ASN1_OBJECT, (st), (i2d_func), (buf), (len))
1390#define ASN1_seq_unpack_ASN1_OBJECT(buf, len, d2i_func, free_func) \
1391 SKM_ASN1_seq_unpack(ASN1_OBJECT, (buf), (len), (d2i_func), (free_func))
1392
1393#define d2i_ASN1_SET_OF_ASN1_TYPE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1394 SKM_ASN1_SET_OF_d2i(ASN1_TYPE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1395#define i2d_ASN1_SET_OF_ASN1_TYPE(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1396 SKM_ASN1_SET_OF_i2d(ASN1_TYPE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1397#define ASN1_seq_pack_ASN1_TYPE(st, i2d_func, buf, len) \
1398 SKM_ASN1_seq_pack(ASN1_TYPE, (st), (i2d_func), (buf), (len))
1399#define ASN1_seq_unpack_ASN1_TYPE(buf, len, d2i_func, free_func) \
1400 SKM_ASN1_seq_unpack(ASN1_TYPE, (buf), (len), (d2i_func), (free_func))
1401
1402#define d2i_ASN1_SET_OF_DIST_POINT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1403 SKM_ASN1_SET_OF_d2i(DIST_POINT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1404#define i2d_ASN1_SET_OF_DIST_POINT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1405 SKM_ASN1_SET_OF_i2d(DIST_POINT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1406#define ASN1_seq_pack_DIST_POINT(st, i2d_func, buf, len) \
1407 SKM_ASN1_seq_pack(DIST_POINT, (st), (i2d_func), (buf), (len))
1408#define ASN1_seq_unpack_DIST_POINT(buf, len, d2i_func, free_func) \
1409 SKM_ASN1_seq_unpack(DIST_POINT, (buf), (len), (d2i_func), (free_func))
1410
1411#define d2i_ASN1_SET_OF_GENERAL_NAME(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1412 SKM_ASN1_SET_OF_d2i(GENERAL_NAME, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1413#define i2d_ASN1_SET_OF_GENERAL_NAME(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1414 SKM_ASN1_SET_OF_i2d(GENERAL_NAME, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1415#define ASN1_seq_pack_GENERAL_NAME(st, i2d_func, buf, len) \
1416 SKM_ASN1_seq_pack(GENERAL_NAME, (st), (i2d_func), (buf), (len))
1417#define ASN1_seq_unpack_GENERAL_NAME(buf, len, d2i_func, free_func) \
1418 SKM_ASN1_seq_unpack(GENERAL_NAME, (buf), (len), (d2i_func), (free_func))
1419
1420#define d2i_ASN1_SET_OF_OCSP_ONEREQ(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1421 SKM_ASN1_SET_OF_d2i(OCSP_ONEREQ, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1422#define i2d_ASN1_SET_OF_OCSP_ONEREQ(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1423 SKM_ASN1_SET_OF_i2d(OCSP_ONEREQ, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1424#define ASN1_seq_pack_OCSP_ONEREQ(st, i2d_func, buf, len) \
1425 SKM_ASN1_seq_pack(OCSP_ONEREQ, (st), (i2d_func), (buf), (len))
1426#define ASN1_seq_unpack_OCSP_ONEREQ(buf, len, d2i_func, free_func) \
1427 SKM_ASN1_seq_unpack(OCSP_ONEREQ, (buf), (len), (d2i_func), (free_func))
1428
1429#define d2i_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1430 SKM_ASN1_SET_OF_d2i(OCSP_SINGLERESP, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1431#define i2d_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1432 SKM_ASN1_SET_OF_i2d(OCSP_SINGLERESP, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1433#define ASN1_seq_pack_OCSP_SINGLERESP(st, i2d_func, buf, len) \
1434 SKM_ASN1_seq_pack(OCSP_SINGLERESP, (st), (i2d_func), (buf), (len))
1435#define ASN1_seq_unpack_OCSP_SINGLERESP(buf, len, d2i_func, free_func) \
1436 SKM_ASN1_seq_unpack(OCSP_SINGLERESP, (buf), (len), (d2i_func), (free_func))
1437
1438#define d2i_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1439 SKM_ASN1_SET_OF_d2i(PKCS12_SAFEBAG, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1440#define i2d_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1441 SKM_ASN1_SET_OF_i2d(PKCS12_SAFEBAG, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1442#define ASN1_seq_pack_PKCS12_SAFEBAG(st, i2d_func, buf, len) \
1443 SKM_ASN1_seq_pack(PKCS12_SAFEBAG, (st), (i2d_func), (buf), (len))
1444#define ASN1_seq_unpack_PKCS12_SAFEBAG(buf, len, d2i_func, free_func) \
1445 SKM_ASN1_seq_unpack(PKCS12_SAFEBAG, (buf), (len), (d2i_func), (free_func))
1446
1447#define d2i_ASN1_SET_OF_PKCS7(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1448 SKM_ASN1_SET_OF_d2i(PKCS7, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1449#define i2d_ASN1_SET_OF_PKCS7(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1450 SKM_ASN1_SET_OF_i2d(PKCS7, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1451#define ASN1_seq_pack_PKCS7(st, i2d_func, buf, len) \
1452 SKM_ASN1_seq_pack(PKCS7, (st), (i2d_func), (buf), (len))
1453#define ASN1_seq_unpack_PKCS7(buf, len, d2i_func, free_func) \
1454 SKM_ASN1_seq_unpack(PKCS7, (buf), (len), (d2i_func), (free_func))
1455
1456#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1457 SKM_ASN1_SET_OF_d2i(PKCS7_RECIP_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1458#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1459 SKM_ASN1_SET_OF_i2d(PKCS7_RECIP_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1460#define ASN1_seq_pack_PKCS7_RECIP_INFO(st, i2d_func, buf, len) \
1461 SKM_ASN1_seq_pack(PKCS7_RECIP_INFO, (st), (i2d_func), (buf), (len))
1462#define ASN1_seq_unpack_PKCS7_RECIP_INFO(buf, len, d2i_func, free_func) \
1463 SKM_ASN1_seq_unpack(PKCS7_RECIP_INFO, (buf), (len), (d2i_func), (free_func))
1464
1465#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1466 SKM_ASN1_SET_OF_d2i(PKCS7_SIGNER_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1467#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1468 SKM_ASN1_SET_OF_i2d(PKCS7_SIGNER_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1469#define ASN1_seq_pack_PKCS7_SIGNER_INFO(st, i2d_func, buf, len) \
1470 SKM_ASN1_seq_pack(PKCS7_SIGNER_INFO, (st), (i2d_func), (buf), (len))
1471#define ASN1_seq_unpack_PKCS7_SIGNER_INFO(buf, len, d2i_func, free_func) \
1472 SKM_ASN1_seq_unpack(PKCS7_SIGNER_INFO, (buf), (len), (d2i_func), (free_func))
1473
1474#define d2i_ASN1_SET_OF_POLICYINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1475 SKM_ASN1_SET_OF_d2i(POLICYINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1476#define i2d_ASN1_SET_OF_POLICYINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1477 SKM_ASN1_SET_OF_i2d(POLICYINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1478#define ASN1_seq_pack_POLICYINFO(st, i2d_func, buf, len) \
1479 SKM_ASN1_seq_pack(POLICYINFO, (st), (i2d_func), (buf), (len))
1480#define ASN1_seq_unpack_POLICYINFO(buf, len, d2i_func, free_func) \
1481 SKM_ASN1_seq_unpack(POLICYINFO, (buf), (len), (d2i_func), (free_func))
1482
1483#define d2i_ASN1_SET_OF_POLICYQUALINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1484 SKM_ASN1_SET_OF_d2i(POLICYQUALINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1485#define i2d_ASN1_SET_OF_POLICYQUALINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1486 SKM_ASN1_SET_OF_i2d(POLICYQUALINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1487#define ASN1_seq_pack_POLICYQUALINFO(st, i2d_func, buf, len) \
1488 SKM_ASN1_seq_pack(POLICYQUALINFO, (st), (i2d_func), (buf), (len))
1489#define ASN1_seq_unpack_POLICYQUALINFO(buf, len, d2i_func, free_func) \
1490 SKM_ASN1_seq_unpack(POLICYQUALINFO, (buf), (len), (d2i_func), (free_func))
1491
1492#define d2i_ASN1_SET_OF_SXNETID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1493 SKM_ASN1_SET_OF_d2i(SXNETID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1494#define i2d_ASN1_SET_OF_SXNETID(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1495 SKM_ASN1_SET_OF_i2d(SXNETID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1496#define ASN1_seq_pack_SXNETID(st, i2d_func, buf, len) \
1497 SKM_ASN1_seq_pack(SXNETID, (st), (i2d_func), (buf), (len))
1498#define ASN1_seq_unpack_SXNETID(buf, len, d2i_func, free_func) \
1499 SKM_ASN1_seq_unpack(SXNETID, (buf), (len), (d2i_func), (free_func))
1500
1501#define d2i_ASN1_SET_OF_X509(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1502 SKM_ASN1_SET_OF_d2i(X509, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1503#define i2d_ASN1_SET_OF_X509(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1504 SKM_ASN1_SET_OF_i2d(X509, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1505#define ASN1_seq_pack_X509(st, i2d_func, buf, len) \
1506 SKM_ASN1_seq_pack(X509, (st), (i2d_func), (buf), (len))
1507#define ASN1_seq_unpack_X509(buf, len, d2i_func, free_func) \
1508 SKM_ASN1_seq_unpack(X509, (buf), (len), (d2i_func), (free_func))
1509
1510#define d2i_ASN1_SET_OF_X509_ALGOR(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1511 SKM_ASN1_SET_OF_d2i(X509_ALGOR, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1512#define i2d_ASN1_SET_OF_X509_ALGOR(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1513 SKM_ASN1_SET_OF_i2d(X509_ALGOR, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1514#define ASN1_seq_pack_X509_ALGOR(st, i2d_func, buf, len) \
1515 SKM_ASN1_seq_pack(X509_ALGOR, (st), (i2d_func), (buf), (len))
1516#define ASN1_seq_unpack_X509_ALGOR(buf, len, d2i_func, free_func) \
1517 SKM_ASN1_seq_unpack(X509_ALGOR, (buf), (len), (d2i_func), (free_func))
1518
1519#define d2i_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1520 SKM_ASN1_SET_OF_d2i(X509_ATTRIBUTE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1521#define i2d_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1522 SKM_ASN1_SET_OF_i2d(X509_ATTRIBUTE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1523#define ASN1_seq_pack_X509_ATTRIBUTE(st, i2d_func, buf, len) \
1524 SKM_ASN1_seq_pack(X509_ATTRIBUTE, (st), (i2d_func), (buf), (len))
1525#define ASN1_seq_unpack_X509_ATTRIBUTE(buf, len, d2i_func, free_func) \
1526 SKM_ASN1_seq_unpack(X509_ATTRIBUTE, (buf), (len), (d2i_func), (free_func))
1527
1528#define d2i_ASN1_SET_OF_X509_CRL(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1529 SKM_ASN1_SET_OF_d2i(X509_CRL, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1530#define i2d_ASN1_SET_OF_X509_CRL(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1531 SKM_ASN1_SET_OF_i2d(X509_CRL, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1532#define ASN1_seq_pack_X509_CRL(st, i2d_func, buf, len) \
1533 SKM_ASN1_seq_pack(X509_CRL, (st), (i2d_func), (buf), (len))
1534#define ASN1_seq_unpack_X509_CRL(buf, len, d2i_func, free_func) \
1535 SKM_ASN1_seq_unpack(X509_CRL, (buf), (len), (d2i_func), (free_func))
1536
1537#define d2i_ASN1_SET_OF_X509_EXTENSION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1538 SKM_ASN1_SET_OF_d2i(X509_EXTENSION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1539#define i2d_ASN1_SET_OF_X509_EXTENSION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1540 SKM_ASN1_SET_OF_i2d(X509_EXTENSION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1541#define ASN1_seq_pack_X509_EXTENSION(st, i2d_func, buf, len) \
1542 SKM_ASN1_seq_pack(X509_EXTENSION, (st), (i2d_func), (buf), (len))
1543#define ASN1_seq_unpack_X509_EXTENSION(buf, len, d2i_func, free_func) \
1544 SKM_ASN1_seq_unpack(X509_EXTENSION, (buf), (len), (d2i_func), (free_func))
1545
1546#define d2i_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1547 SKM_ASN1_SET_OF_d2i(X509_NAME_ENTRY, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1548#define i2d_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1549 SKM_ASN1_SET_OF_i2d(X509_NAME_ENTRY, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1550#define ASN1_seq_pack_X509_NAME_ENTRY(st, i2d_func, buf, len) \
1551 SKM_ASN1_seq_pack(X509_NAME_ENTRY, (st), (i2d_func), (buf), (len))
1552#define ASN1_seq_unpack_X509_NAME_ENTRY(buf, len, d2i_func, free_func) \
1553 SKM_ASN1_seq_unpack(X509_NAME_ENTRY, (buf), (len), (d2i_func), (free_func))
1554
1555#define d2i_ASN1_SET_OF_X509_REVOKED(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1556 SKM_ASN1_SET_OF_d2i(X509_REVOKED, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1557#define i2d_ASN1_SET_OF_X509_REVOKED(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1558 SKM_ASN1_SET_OF_i2d(X509_REVOKED, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1559#define ASN1_seq_pack_X509_REVOKED(st, i2d_func, buf, len) \
1560 SKM_ASN1_seq_pack(X509_REVOKED, (st), (i2d_func), (buf), (len))
1561#define ASN1_seq_unpack_X509_REVOKED(buf, len, d2i_func, free_func) \
1562 SKM_ASN1_seq_unpack(X509_REVOKED, (buf), (len), (d2i_func), (free_func))
1563
1564#define PKCS12_decrypt_d2i_PKCS12_SAFEBAG(algor, d2i_func, free_func, pass, passlen, oct, seq) \
1565 SKM_PKCS12_decrypt_d2i(PKCS12_SAFEBAG, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
1566
1567#define PKCS12_decrypt_d2i_PKCS7(algor, d2i_func, free_func, pass, passlen, oct, seq) \
1568 SKM_PKCS12_decrypt_d2i(PKCS7, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
1569/* End of util/mkstack.pl block, you may now edit :-) */
1570
1571#endif /* !defined HEADER_SAFESTACK_H */
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
new file mode 100644
index 0000000000..c7173eb6ab
--- /dev/null
+++ b/src/lib/libcrypto/stack/stack.c
@@ -0,0 +1,340 @@
1/* crypto/stack/stack.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Code for stacks
60 * Author - Eric Young v 1.0
61 * 1.2 eay 12-Mar-97 - Modified sk_find so that it _DOES_ return the
62 * lowest index for the searched item.
63 *
64 * 1.1 eay - Take from netdb and added to SSLeay
65 *
66 * 1.0 eay - First version 29/07/92
67 */
68#include <stdio.h>
69#include "cryptlib.h"
70#include <openssl/stack.h>
71
72#undef MIN_NODES
73#define MIN_NODES 4
74
75const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
76
77#include <errno.h>
78
79int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * const *)))
80 (const char * const *, const char * const *)
81 {
82 int (*old)(const char * const *,const char * const *)=sk->comp;
83
84 if (sk->comp != c)
85 sk->sorted=0;
86 sk->comp=c;
87
88 return old;
89 }
90
91STACK *sk_dup(STACK *sk)
92 {
93 STACK *ret;
94 char **s;
95
96 if ((ret=sk_new(sk->comp)) == NULL) goto err;
97 s=(char **)OPENSSL_realloc((char *)ret->data,
98 (unsigned int)sizeof(char *)*sk->num_alloc);
99 if (s == NULL) goto err;
100 ret->data=s;
101
102 ret->num=sk->num;
103 memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
104 ret->sorted=sk->sorted;
105 ret->num_alloc=sk->num_alloc;
106 ret->comp=sk->comp;
107 return(ret);
108err:
109 if(ret)
110 sk_free(ret);
111 return(NULL);
112 }
113
114STACK *sk_new_null(void)
115 {
116 return sk_new((int (*)(const char * const *, const char * const *))0);
117 }
118
119STACK *sk_new(int (*c)(const char * const *, const char * const *))
120 {
121 STACK *ret;
122 int i;
123
124 if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)
125 goto err;
126 if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
127 goto err;
128 for (i=0; i<MIN_NODES; i++)
129 ret->data[i]=NULL;
130 ret->comp=c;
131 ret->num_alloc=MIN_NODES;
132 ret->num=0;
133 ret->sorted=0;
134 return(ret);
135err:
136 if(ret)
137 OPENSSL_free(ret);
138 return(NULL);
139 }
140
141int sk_insert(STACK *st, char *data, int loc)
142 {
143 char **s;
144
145 if(st == NULL) return 0;
146 if (st->num_alloc <= st->num+1)
147 {
148 s=(char **)OPENSSL_realloc((char *)st->data,
149 (unsigned int)sizeof(char *)*st->num_alloc*2);
150 if (s == NULL)
151 return(0);
152 st->data=s;
153 st->num_alloc*=2;
154 }
155 if ((loc >= (int)st->num) || (loc < 0))
156 st->data[st->num]=data;
157 else
158 {
159 int i;
160 char **f,**t;
161
162 f=(char **)st->data;
163 t=(char **)&(st->data[1]);
164 for (i=st->num; i>=loc; i--)
165 t[i]=f[i];
166
167#ifdef undef /* no memmove on sunos :-( */
168 memmove( (char *)&(st->data[loc+1]),
169 (char *)&(st->data[loc]),
170 sizeof(char *)*(st->num-loc));
171#endif
172 st->data[loc]=data;
173 }
174 st->num++;
175 st->sorted=0;
176 return(st->num);
177 }
178
179char *sk_delete_ptr(STACK *st, char *p)
180 {
181 int i;
182
183 for (i=0; i<st->num; i++)
184 if (st->data[i] == p)
185 return(sk_delete(st,i));
186 return(NULL);
187 }
188
189char *sk_delete(STACK *st, int loc)
190 {
191 char *ret;
192 int i,j;
193
194 if(!st || (loc < 0) || (loc >= st->num)) return NULL;
195
196 ret=st->data[loc];
197 if (loc != st->num-1)
198 {
199 j=st->num-1;
200 for (i=loc; i<j; i++)
201 st->data[i]=st->data[i+1];
202 /* In theory memcpy is not safe for this
203 * memcpy( &(st->data[loc]),
204 * &(st->data[loc+1]),
205 * sizeof(char *)*(st->num-loc-1));
206 */
207 }
208 st->num--;
209 return(ret);
210 }
211
212int sk_find(STACK *st, char *data)
213 {
214 char **r;
215 int i;
216 int (*comp_func)(const void *,const void *);
217 if(st == NULL) return -1;
218
219 if (st->comp == NULL)
220 {
221 for (i=0; i<st->num; i++)
222 if (st->data[i] == data)
223 return(i);
224 return(-1);
225 }
226 sk_sort(st);
227 if (data == NULL) return(-1);
228 /* This (and the "qsort" below) are the two places in OpenSSL
229 * where we need to convert from our standard (type **,type **)
230 * compare callback type to the (void *,void *) type required by
231 * bsearch. However, the "data" it is being called(back) with are
232 * not (type *) pointers, but the *pointers* to (type *) pointers,
233 * so we get our extra level of pointer dereferencing that way. */
234 comp_func=(int (*)(const void *,const void *))(st->comp);
235 r=(char **)bsearch(&data,(char *)st->data,
236 st->num,sizeof(char *), comp_func);
237 if (r == NULL) return(-1);
238 i=(int)(r-st->data);
239 for ( ; i>0; i--)
240 /* This needs a cast because the type being pointed to from
241 * the "&" expressions are (char *) rather than (const char *).
242 * For an explanation, read:
243 * http://www.eskimo.com/~scs/C-faq/q11.10.html :-) */
244 if ((*st->comp)((const char * const *)&(st->data[i-1]),
245 (const char * const *)&data) < 0)
246 break;
247 return(i);
248 }
249
250int sk_push(STACK *st, char *data)
251 {
252 return(sk_insert(st,data,st->num));
253 }
254
255int sk_unshift(STACK *st, char *data)
256 {
257 return(sk_insert(st,data,0));
258 }
259
260char *sk_shift(STACK *st)
261 {
262 if (st == NULL) return(NULL);
263 if (st->num <= 0) return(NULL);
264 return(sk_delete(st,0));
265 }
266
267char *sk_pop(STACK *st)
268 {
269 if (st == NULL) return(NULL);
270 if (st->num <= 0) return(NULL);
271 return(sk_delete(st,st->num-1));
272 }
273
274void sk_zero(STACK *st)
275 {
276 if (st == NULL) return;
277 if (st->num <= 0) return;
278 memset((char *)st->data,0,sizeof(st->data)*st->num);
279 st->num=0;
280 }
281
282void sk_pop_free(STACK *st, void (*func)(void *))
283 {
284 int i;
285
286 if (st == NULL) return;
287 for (i=0; i<st->num; i++)
288 if (st->data[i] != NULL)
289 func(st->data[i]);
290 sk_free(st);
291 }
292
293void sk_free(STACK *st)
294 {
295 if (st == NULL) return;
296 if (st->data != NULL) OPENSSL_free(st->data);
297 OPENSSL_free(st);
298 }
299
300int sk_num(const STACK *st)
301{
302 if(st == NULL) return -1;
303 return st->num;
304}
305
306char *sk_value(const STACK *st, int i)
307{
308 if(!st || (i < 0) || (i >= st->num)) return NULL;
309 return st->data[i];
310}
311
312char *sk_set(STACK *st, int i, char *value)
313{
314 if(!st || (i < 0) || (i >= st->num)) return NULL;
315 return (st->data[i] = value);
316}
317
318void sk_sort(STACK *st)
319 {
320 if (st && !st->sorted)
321 {
322 int (*comp_func)(const void *,const void *);
323
324 /* same comment as in sk_find ... previously st->comp was declared
325 * as a (void*,void*) callback type, but this made the population
326 * of the callback pointer illogical - our callbacks compare
327 * type** with type**, so we leave the casting until absolutely
328 * necessary (ie. "now"). */
329 comp_func=(int (*)(const void *,const void *))(st->comp);
330 qsort(st->data,st->num,sizeof(char *), comp_func);
331 st->sorted=1;
332 }
333 }
334
335int sk_is_sorted(const STACK *st)
336 {
337 if (!st)
338 return 1;
339 return st->sorted;
340 }
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h
new file mode 100644
index 0000000000..7570b85fe8
--- /dev/null
+++ b/src/lib/libcrypto/stack/stack.h
@@ -0,0 +1,108 @@
1/* crypto/stack/stack.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_STACK_H
60#define HEADER_STACK_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66typedef struct stack_st
67 {
68 int num;
69 char **data;
70 int sorted;
71
72 int num_alloc;
73 int (*comp)(const char * const *, const char * const *);
74 } STACK;
75
76#define M_sk_num(sk) ((sk) ? (sk)->num:-1)
77#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
78
79int sk_num(const STACK *);
80char *sk_value(const STACK *, int);
81
82char *sk_set(STACK *, int, char *);
83
84STACK *sk_new(int (*cmp)(const char * const *, const char * const *));
85STACK *sk_new_null(void);
86void sk_free(STACK *);
87void sk_pop_free(STACK *st, void (*func)(void *));
88int sk_insert(STACK *sk,char *data,int where);
89char *sk_delete(STACK *st,int loc);
90char *sk_delete_ptr(STACK *st, char *p);
91int sk_find(STACK *st,char *data);
92int sk_push(STACK *st,char *data);
93int sk_unshift(STACK *st,char *data);
94char *sk_shift(STACK *st);
95char *sk_pop(STACK *st);
96void sk_zero(STACK *st);
97int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,
98 const char * const *)))
99 (const char * const *, const char * const *);
100STACK *sk_dup(STACK *st);
101void sk_sort(STACK *st);
102int sk_is_sorted(const STACK *st);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif
diff --git a/src/lib/libcrypto/txt_db/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
new file mode 100644
index 0000000000..58b300b00b
--- /dev/null
+++ b/src/lib/libcrypto/txt_db/txt_db.c
@@ -0,0 +1,383 @@
1/* crypto/txt_db/txt_db.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include "cryptlib.h"
63#include <openssl/buffer.h>
64#include <openssl/txt_db.h>
65
66#undef BUFSIZE
67#define BUFSIZE 512
68
69const char *TXT_DB_version="TXT_DB" OPENSSL_VERSION_PTEXT;
70
71TXT_DB *TXT_DB_read(BIO *in, int num)
72 {
73 TXT_DB *ret=NULL;
74 int er=1;
75 int esc=0;
76 long ln=0;
77 int i,add,n;
78 int size=BUFSIZE;
79 int offset=0;
80 char *p,**pp,*f;
81 BUF_MEM *buf=NULL;
82
83 if ((buf=BUF_MEM_new()) == NULL) goto err;
84 if (!BUF_MEM_grow(buf,size)) goto err;
85
86 if ((ret=(TXT_DB *)OPENSSL_malloc(sizeof(TXT_DB))) == NULL)
87 goto err;
88 ret->num_fields=num;
89 ret->index=NULL;
90 ret->qual=NULL;
91 if ((ret->data=sk_new_null()) == NULL)
92 goto err;
93 if ((ret->index=(LHASH **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL)
94 goto err;
95 if ((ret->qual=(int (**)())OPENSSL_malloc(sizeof(int (**)())*num)) == NULL)
96 goto err;
97 for (i=0; i<num; i++)
98 {
99 ret->index[i]=NULL;
100 ret->qual[i]=NULL;
101 }
102
103 add=(num+1)*sizeof(char *);
104 buf->data[size-1]='\0';
105 offset=0;
106 for (;;)
107 {
108 if (offset != 0)
109 {
110 size+=BUFSIZE;
111 if (!BUF_MEM_grow_clean(buf,size)) goto err;
112 }
113 buf->data[offset]='\0';
114 BIO_gets(in,&(buf->data[offset]),size-offset);
115 ln++;
116 if (buf->data[offset] == '\0') break;
117 if ((offset == 0) && (buf->data[0] == '#')) continue;
118 i=strlen(&(buf->data[offset]));
119 offset+=i;
120 if (buf->data[offset-1] != '\n')
121 continue;
122 else
123 {
124 buf->data[offset-1]='\0'; /* blat the '\n' */
125 if (!(p=(char *)OPENSSL_malloc(add+offset))) goto err;
126 offset=0;
127 }
128 pp=(char **)p;
129 p+=add;
130 n=0;
131 pp[n++]=p;
132 i=0;
133 f=buf->data;
134
135 esc=0;
136 for (;;)
137 {
138 if (*f == '\0') break;
139 if (*f == '\t')
140 {
141 if (esc)
142 p--;
143 else
144 {
145 *(p++)='\0';
146 f++;
147 if (n >= num) break;
148 pp[n++]=p;
149 continue;
150 }
151 }
152 esc=(*f == '\\');
153 *(p++)= *(f++);
154 }
155 *(p++)='\0';
156 if ((n != num) || (*f != '\0'))
157 {
158#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporaty fix :-( */
159 fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f);
160#endif
161 er=2;
162 goto err;
163 }
164 pp[n]=p;
165 if (!sk_push(ret->data,(char *)pp))
166 {
167#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) /* temporaty fix :-( */
168 fprintf(stderr,"failure in sk_push\n");
169#endif
170 er=2;
171 goto err;
172 }
173 }
174 er=0;
175err:
176 BUF_MEM_free(buf);
177 if (er)
178 {
179#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
180 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n");
181#endif
182 if (ret->data != NULL) sk_free(ret->data);
183 if (ret->index != NULL) OPENSSL_free(ret->index);
184 if (ret->qual != NULL) OPENSSL_free(ret->qual);
185 if (ret != NULL) OPENSSL_free(ret);
186 return(NULL);
187 }
188 else
189 return(ret);
190 }
191
192char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
193 {
194 char **ret;
195 LHASH *lh;
196
197 if (idx >= db->num_fields)
198 {
199 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
200 return(NULL);
201 }
202 lh=db->index[idx];
203 if (lh == NULL)
204 {
205 db->error=DB_ERROR_NO_INDEX;
206 return(NULL);
207 }
208 ret=(char **)lh_retrieve(lh,value);
209 db->error=DB_ERROR_OK;
210 return(ret);
211 }
212
213int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(),
214 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
215 {
216 LHASH *idx;
217 char *r;
218 int i,n;
219
220 if (field >= db->num_fields)
221 {
222 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
223 return(0);
224 }
225 if ((idx=lh_new(hash,cmp)) == NULL)
226 {
227 db->error=DB_ERROR_MALLOC;
228 return(0);
229 }
230 n=sk_num(db->data);
231 for (i=0; i<n; i++)
232 {
233 r=(char *)sk_value(db->data,i);
234 if ((qual != NULL) && (qual(r) == 0)) continue;
235 if ((r=lh_insert(idx,r)) != NULL)
236 {
237 db->error=DB_ERROR_INDEX_CLASH;
238 db->arg1=sk_find(db->data,r);
239 db->arg2=i;
240 lh_free(idx);
241 return(0);
242 }
243 }
244 if (db->index[field] != NULL) lh_free(db->index[field]);
245 db->index[field]=idx;
246 db->qual[field]=qual;
247 return(1);
248 }
249
250long TXT_DB_write(BIO *out, TXT_DB *db)
251 {
252 long i,j,n,nn,l,tot=0;
253 char *p,**pp,*f;
254 BUF_MEM *buf=NULL;
255 long ret= -1;
256
257 if ((buf=BUF_MEM_new()) == NULL)
258 goto err;
259 n=sk_num(db->data);
260 nn=db->num_fields;
261 for (i=0; i<n; i++)
262 {
263 pp=(char **)sk_value(db->data,i);
264
265 l=0;
266 for (j=0; j<nn; j++)
267 {
268 if (pp[j] != NULL)
269 l+=strlen(pp[j]);
270 }
271 if (!BUF_MEM_grow_clean(buf,(int)(l*2+nn))) goto err;
272
273 p=buf->data;
274 for (j=0; j<nn; j++)
275 {
276 f=pp[j];
277 if (f != NULL)
278 for (;;)
279 {
280 if (*f == '\0') break;
281 if (*f == '\t') *(p++)='\\';
282 *(p++)= *(f++);
283 }
284 *(p++)='\t';
285 }
286 p[-1]='\n';
287 j=p-buf->data;
288 if (BIO_write(out,buf->data,(int)j) != j)
289 goto err;
290 tot+=j;
291 }
292 ret=tot;
293err:
294 if (buf != NULL) BUF_MEM_free(buf);
295 return(ret);
296 }
297
298int TXT_DB_insert(TXT_DB *db, char **row)
299 {
300 int i;
301 char **r;
302
303 for (i=0; i<db->num_fields; i++)
304 {
305 if (db->index[i] != NULL)
306 {
307 if ((db->qual[i] != NULL) &&
308 (db->qual[i](row) == 0)) continue;
309 r=(char **)lh_retrieve(db->index[i],row);
310 if (r != NULL)
311 {
312 db->error=DB_ERROR_INDEX_CLASH;
313 db->arg1=i;
314 db->arg_row=r;
315 goto err;
316 }
317 }
318 }
319 /* We have passed the index checks, now just append and insert */
320 if (!sk_push(db->data,(char *)row))
321 {
322 db->error=DB_ERROR_MALLOC;
323 goto err;
324 }
325
326 for (i=0; i<db->num_fields; i++)
327 {
328 if (db->index[i] != NULL)
329 {
330 if ((db->qual[i] != NULL) &&
331 (db->qual[i](row) == 0)) continue;
332 lh_insert(db->index[i],row);
333 }
334 }
335 return(1);
336err:
337 return(0);
338 }
339
340void TXT_DB_free(TXT_DB *db)
341 {
342 int i,n;
343 char **p,*max;
344
345 if(db == NULL)
346 return;
347
348 if (db->index != NULL)
349 {
350 for (i=db->num_fields-1; i>=0; i--)
351 if (db->index[i] != NULL) lh_free(db->index[i]);
352 OPENSSL_free(db->index);
353 }
354 if (db->qual != NULL)
355 OPENSSL_free(db->qual);
356 if (db->data != NULL)
357 {
358 for (i=sk_num(db->data)-1; i>=0; i--)
359 {
360 /* check if any 'fields' have been allocated
361 * from outside of the initial block */
362 p=(char **)sk_value(db->data,i);
363 max=p[db->num_fields]; /* last address */
364 if (max == NULL) /* new row */
365 {
366 for (n=0; n<db->num_fields; n++)
367 if (p[n] != NULL) OPENSSL_free(p[n]);
368 }
369 else
370 {
371 for (n=0; n<db->num_fields; n++)
372 {
373 if (((p[n] < (char *)p) || (p[n] > max))
374 && (p[n] != NULL))
375 OPENSSL_free(p[n]);
376 }
377 }
378 OPENSSL_free(sk_value(db->data,i));
379 }
380 sk_free(db->data);
381 }
382 OPENSSL_free(db);
383 }
diff --git a/src/lib/libcrypto/txt_db/txt_db.h b/src/lib/libcrypto/txt_db/txt_db.h
new file mode 100644
index 0000000000..563392aeff
--- /dev/null
+++ b/src/lib/libcrypto/txt_db/txt_db.h
@@ -0,0 +1,108 @@
1/* crypto/txt_db/txt_db.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_TXT_DB_H
60#define HEADER_TXT_DB_H
61
62#ifndef OPENSSL_NO_BIO
63#include <openssl/bio.h>
64#endif
65#include <openssl/stack.h>
66#include <openssl/lhash.h>
67
68#define DB_ERROR_OK 0
69#define DB_ERROR_MALLOC 1
70#define DB_ERROR_INDEX_CLASH 2
71#define DB_ERROR_INDEX_OUT_OF_RANGE 3
72#define DB_ERROR_NO_INDEX 4
73#define DB_ERROR_INSERT_INDEX_CLASH 5
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79typedef struct txt_db_st
80 {
81 int num_fields;
82 STACK /* char ** */ *data;
83 LHASH **index;
84 int (**qual)();
85 long error;
86 long arg1;
87 long arg2;
88 char **arg_row;
89 } TXT_DB;
90
91#ifndef OPENSSL_NO_BIO
92TXT_DB *TXT_DB_read(BIO *in, int num);
93long TXT_DB_write(BIO *out, TXT_DB *db);
94#else
95TXT_DB *TXT_DB_read(char *in, int num);
96long TXT_DB_write(char *out, TXT_DB *db);
97#endif
98int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(),
99 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
100void TXT_DB_free(TXT_DB *db);
101char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
102int TXT_DB_insert(TXT_DB *db,char **value);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif
diff --git a/src/lib/libcrypto/ui/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
new file mode 100644
index 0000000000..735a2d988e
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui.h
@@ -0,0 +1,387 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_H
60#define HEADER_UI_H
61
62#include <openssl/crypto.h>
63#include <openssl/safestack.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The UI type is a holder for a specific user interface session. It can
70 contain an illimited number of informational or error strings as well
71 as things to prompt for, both passwords (noecho mode) and others (echo
72 mode), and verification of the same. All of these are called strings,
73 and are further described below. */
74typedef struct ui_st UI;
75
76/* All instances of UI have a reference to a method structure, which is a
77 ordered vector of functions that implement the lower level things to do.
78 There is an instruction on the implementation further down, in the section
79 for method implementors. */
80typedef struct ui_method_st UI_METHOD;
81
82
83/* All the following functions return -1 or NULL on error and in some cases
84 (UI_process()) -2 if interrupted or in some other way cancelled.
85 When everything is fine, they return 0, a positive value or a non-NULL
86 pointer, all depending on their purpose. */
87
88/* Creators and destructor. */
89UI *UI_new(void);
90UI *UI_new_method(const UI_METHOD *method);
91void UI_free(UI *ui);
92
93/* The following functions are used to add strings to be printed and prompt
94 strings to prompt for data. The names are UI_{add,dup}_<function>_string
95 and UI_{add,dup}_input_boolean.
96
97 UI_{add,dup}_<function>_string have the following meanings:
98 add add a text or prompt string. The pointers given to these
99 functions are used verbatim, no copying is done.
100 dup make a copy of the text or prompt string, then add the copy
101 to the collection of strings in the user interface.
102 <function>
103 The function is a name for the functionality that the given
104 string shall be used for. It can be one of:
105 input use the string as data prompt.
106 verify use the string as verification prompt. This
107 is used to verify a previous input.
108 info use the string for informational output.
109 error use the string for error output.
110 Honestly, there's currently no difference between info and error for the
111 moment.
112
113 UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
114 and are typically used when one wants to prompt for a yes/no response.
115
116
117 All of the functions in this group take a UI and a prompt string.
118 The string input and verify addition functions also take a flag argument,
119 a buffer for the result to end up with, a minimum input size and a maximum
120 input size (the result buffer MUST be large enough to be able to contain
121 the maximum number of characters). Additionally, the verify addition
122 functions takes another buffer to compare the result against.
123 The boolean input functions take an action description string (which should
124 be safe to ignore if the expected user action is obvious, for example with
125 a dialog box with an OK button and a Cancel button), a string of acceptable
126 characters to mean OK and to mean Cancel. The two last strings are checked
127 to make sure they don't have common characters. Additionally, the same
128 flag argument as for the string input is taken, as well as a result buffer.
129 The result buffer is required to be at least one byte long. Depending on
130 the answer, the first character from the OK or the Cancel character strings
131 will be stored in the first byte of the result buffer. No NUL will be
132 added, so the result is *not* a string.
133
134 On success, the all return an index of the added information. That index
135 is usefull when retrieving results with UI_get0_result(). */
136int UI_add_input_string(UI *ui, const char *prompt, int flags,
137 char *result_buf, int minsize, int maxsize);
138int UI_dup_input_string(UI *ui, const char *prompt, int flags,
139 char *result_buf, int minsize, int maxsize);
140int UI_add_verify_string(UI *ui, const char *prompt, int flags,
141 char *result_buf, int minsize, int maxsize, const char *test_buf);
142int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
143 char *result_buf, int minsize, int maxsize, const char *test_buf);
144int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
145 const char *ok_chars, const char *cancel_chars,
146 int flags, char *result_buf);
147int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
148 const char *ok_chars, const char *cancel_chars,
149 int flags, char *result_buf);
150int UI_add_info_string(UI *ui, const char *text);
151int UI_dup_info_string(UI *ui, const char *text);
152int UI_add_error_string(UI *ui, const char *text);
153int UI_dup_error_string(UI *ui, const char *text);
154
155/* These are the possible flags. They can be or'ed together. */
156/* Use to have echoing of input */
157#define UI_INPUT_FLAG_ECHO 0x01
158/* Use a default password. Where that password is found is completely
159 up to the application, it might for example be in the user data set
160 with UI_add_user_data(). It is not recommended to have more than
161 one input in each UI being marked with this flag, or the application
162 might get confused. */
163#define UI_INPUT_FLAG_DEFAULT_PWD 0x02
164
165/* The user of these routines may want to define flags of their own. The core
166 UI won't look at those, but will pass them on to the method routines. They
167 must use higher bits so they don't get confused with the UI bits above.
168 UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good
169 example of use is this:
170
171 #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE)
172
173*/
174#define UI_INPUT_FLAG_USER_BASE 16
175
176
177/* The following function helps construct a prompt. object_desc is a
178 textual short description of the object, for example "pass phrase",
179 and object_name is the name of the object (might be a card name or
180 a file name.
181 The returned string shall always be allocated on the heap with
182 OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
183
184 If the ui_method doesn't contain a pointer to a user-defined prompt
185 constructor, a default string is built, looking like this:
186
187 "Enter {object_desc} for {object_name}:"
188
189 So, if object_desc has the value "pass phrase" and object_name has
190 the value "foo.key", the resulting string is:
191
192 "Enter pass phrase for foo.key:"
193*/
194char *UI_construct_prompt(UI *ui_method,
195 const char *object_desc, const char *object_name);
196
197
198/* The following function is used to store a pointer to user-specific data.
199 Any previous such pointer will be returned and replaced.
200
201 For callback purposes, this function makes a lot more sense than using
202 ex_data, since the latter requires that different parts of OpenSSL or
203 applications share the same ex_data index.
204
205 Note that the UI_OpenSSL() method completely ignores the user data.
206 Other methods may not, however. */
207void *UI_add_user_data(UI *ui, void *user_data);
208/* We need a user data retrieving function as well. */
209void *UI_get0_user_data(UI *ui);
210
211/* Return the result associated with a prompt given with the index i. */
212const char *UI_get0_result(UI *ui, int i);
213
214/* When all strings have been added, process the whole thing. */
215int UI_process(UI *ui);
216
217/* Give a user interface parametrised control commands. This can be used to
218 send down an integer, a data pointer or a function pointer, as well as
219 be used to get information from a UI. */
220int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
221
222/* The commands */
223/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
224 OpenSSL error stack before printing any info or added error messages and
225 before any prompting. */
226#define UI_CTRL_PRINT_ERRORS 1
227/* Check if a UI_process() is possible to do again with the same instance of
228 a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0
229 if not. */
230#define UI_CTRL_IS_REDOABLE 2
231
232
233/* Some methods may use extra data */
234#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg)
235#define UI_get_app_data(s) UI_get_ex_data(s,0)
236int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
237 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
238int UI_set_ex_data(UI *r,int idx,void *arg);
239void *UI_get_ex_data(UI *r, int idx);
240
241/* Use specific methods instead of the built-in one */
242void UI_set_default_method(const UI_METHOD *meth);
243const UI_METHOD *UI_get_default_method(void);
244const UI_METHOD *UI_get_method(UI *ui);
245const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
246
247/* The method with all the built-in thingies */
248UI_METHOD *UI_OpenSSL(void);
249
250
251/* ---------- For method writers ---------- */
252/* A method contains a number of functions that implement the low level
253 of the User Interface. The functions are:
254
255 an opener This function starts a session, maybe by opening
256 a channel to a tty, or by opening a window.
257 a writer This function is called to write a given string,
258 maybe to the tty, maybe as a field label in a
259 window.
260 a flusher This function is called to flush everything that
261 has been output so far. It can be used to actually
262 display a dialog box after it has been built.
263 a reader This function is called to read a given prompt,
264 maybe from the tty, maybe from a field in a
265 window. Note that it's called wth all string
266 structures, not only the prompt ones, so it must
267 check such things itself.
268 a closer This function closes the session, maybe by closing
269 the channel to the tty, or closing the window.
270
271 All these functions are expected to return:
272
273 0 on error.
274 1 on success.
275 -1 on out-of-band events, for example if some prompting has
276 been canceled (by pressing Ctrl-C, for example). This is
277 only checked when returned by the flusher or the reader.
278
279 The way this is used, the opener is first called, then the writer for all
280 strings, then the flusher, then the reader for all strings and finally the
281 closer. Note that if you want to prompt from a terminal or other command
282 line interface, the best is to have the reader also write the prompts
283 instead of having the writer do it. If you want to prompt from a dialog
284 box, the writer can be used to build up the contents of the box, and the
285 flusher to actually display the box and run the event loop until all data
286 has been given, after which the reader only grabs the given data and puts
287 them back into the UI strings.
288
289 All method functions take a UI as argument. Additionally, the writer and
290 the reader take a UI_STRING.
291*/
292
293/* The UI_STRING type is the data structure that contains all the needed info
294 about a string or a prompt, including test data for a verification prompt.
295*/
296DECLARE_STACK_OF(UI_STRING)
297typedef struct ui_string_st UI_STRING;
298
299/* The different types of strings that are currently supported.
300 This is only needed by method authors. */
301enum UI_string_types
302 {
303 UIT_NONE=0,
304 UIT_PROMPT, /* Prompt for a string */
305 UIT_VERIFY, /* Prompt for a string and verify */
306 UIT_BOOLEAN, /* Prompt for a yes/no response */
307 UIT_INFO, /* Send info to the user */
308 UIT_ERROR /* Send an error message to the user */
309 };
310
311/* Create and manipulate methods */
312UI_METHOD *UI_create_method(char *name);
313void UI_destroy_method(UI_METHOD *ui_method);
314int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
315int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis));
316int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
317int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));
318int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
319int (*UI_method_get_opener(UI_METHOD *method))(UI*);
320int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
321int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
322int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
323int (*UI_method_get_closer(UI_METHOD *method))(UI*);
324
325/* The following functions are helpers for method writers to access relevant
326 data from a UI_STRING. */
327
328/* Return type of the UI_STRING */
329enum UI_string_types UI_get_string_type(UI_STRING *uis);
330/* Return input flags of the UI_STRING */
331int UI_get_input_flags(UI_STRING *uis);
332/* Return the actual string to output (the prompt, info or error) */
333const char *UI_get0_output_string(UI_STRING *uis);
334/* Return the optional action string to output (the boolean promtp instruction) */
335const char *UI_get0_action_string(UI_STRING *uis);
336/* Return the result of a prompt */
337const char *UI_get0_result_string(UI_STRING *uis);
338/* Return the string to test the result against. Only useful with verifies. */
339const char *UI_get0_test_string(UI_STRING *uis);
340/* Return the required minimum size of the result */
341int UI_get_result_minsize(UI_STRING *uis);
342/* Return the required maximum size of the result */
343int UI_get_result_maxsize(UI_STRING *uis);
344/* Set the result of a UI_STRING. */
345int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
346
347
348/* A couple of popular utility functions */
349int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);
350int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
351
352
353/* BEGIN ERROR CODES */
354/* The following lines are auto generated by the script mkerr.pl. Any changes
355 * made after this point may be overwritten when the script is next run.
356 */
357void ERR_load_UI_strings(void);
358
359/* Error codes for the UI functions. */
360
361/* Function codes. */
362#define UI_F_GENERAL_ALLOCATE_BOOLEAN 108
363#define UI_F_GENERAL_ALLOCATE_PROMPT 109
364#define UI_F_GENERAL_ALLOCATE_STRING 100
365#define UI_F_UI_CTRL 111
366#define UI_F_UI_DUP_ERROR_STRING 101
367#define UI_F_UI_DUP_INFO_STRING 102
368#define UI_F_UI_DUP_INPUT_BOOLEAN 110
369#define UI_F_UI_DUP_INPUT_STRING 103
370#define UI_F_UI_DUP_VERIFY_STRING 106
371#define UI_F_UI_GET0_RESULT 107
372#define UI_F_UI_NEW_METHOD 104
373#define UI_F_UI_SET_RESULT 105
374
375/* Reason codes. */
376#define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104
377#define UI_R_INDEX_TOO_LARGE 102
378#define UI_R_INDEX_TOO_SMALL 103
379#define UI_R_NO_RESULT_BUFFER 105
380#define UI_R_RESULT_TOO_LARGE 100
381#define UI_R_RESULT_TOO_SMALL 101
382#define UI_R_UNKNOWN_CONTROL_COMMAND 106
383
384#ifdef __cplusplus
385}
386#endif
387#endif
diff --git a/src/lib/libcrypto/ui/ui_compat.h b/src/lib/libcrypto/ui/ui_compat.h
new file mode 100644
index 0000000000..b35c9bb7fd
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_compat.h
@@ -0,0 +1,83 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_COMPAT_H
60#define HEADER_UI_COMPAT_H
61
62#include <openssl/opensslconf.h>
63#include <openssl/ui.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The following functions were previously part of the DES section,
70 and are provided here for backward compatibility reasons. */
71
72#define des_read_pw_string(b,l,p,v) \
73 _ossl_old_des_read_pw_string((b),(l),(p),(v))
74#define des_read_pw(b,bf,s,p,v) \
75 _ossl_old_des_read_pw((b),(bf),(s),(p),(v))
76
77int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);
78int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
79
80#ifdef __cplusplus
81}
82#endif
83#endif
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c
new file mode 100644
index 0000000000..39a62ae737
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_err.c
@@ -0,0 +1,111 @@
1/* crypto/ui/ui_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ui.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA UI_str_functs[]=
68 {
69{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_BOOLEAN,0), "GENERAL_ALLOCATE_BOOLEAN"},
70{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_PROMPT,0), "GENERAL_ALLOCATE_PROMPT"},
71{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_STRING,0), "GENERAL_ALLOCATE_STRING"},
72{ERR_PACK(0,UI_F_UI_CTRL,0), "UI_ctrl"},
73{ERR_PACK(0,UI_F_UI_DUP_ERROR_STRING,0), "UI_dup_error_string"},
74{ERR_PACK(0,UI_F_UI_DUP_INFO_STRING,0), "UI_dup_info_string"},
75{ERR_PACK(0,UI_F_UI_DUP_INPUT_BOOLEAN,0), "UI_dup_input_boolean"},
76{ERR_PACK(0,UI_F_UI_DUP_INPUT_STRING,0), "UI_dup_input_string"},
77{ERR_PACK(0,UI_F_UI_DUP_VERIFY_STRING,0), "UI_dup_verify_string"},
78{ERR_PACK(0,UI_F_UI_GET0_RESULT,0), "UI_get0_result"},
79{ERR_PACK(0,UI_F_UI_NEW_METHOD,0), "UI_new_method"},
80{ERR_PACK(0,UI_F_UI_SET_RESULT,0), "UI_set_result"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA UI_str_reasons[]=
85 {
86{UI_R_COMMON_OK_AND_CANCEL_CHARACTERS ,"common ok and cancel characters"},
87{UI_R_INDEX_TOO_LARGE ,"index too large"},
88{UI_R_INDEX_TOO_SMALL ,"index too small"},
89{UI_R_NO_RESULT_BUFFER ,"no result buffer"},
90{UI_R_RESULT_TOO_LARGE ,"result too large"},
91{UI_R_RESULT_TOO_SMALL ,"result too small"},
92{UI_R_UNKNOWN_CONTROL_COMMAND ,"unknown control command"},
93{0,NULL}
94 };
95
96#endif
97
98void ERR_load_UI_strings(void)
99 {
100 static int init=1;
101
102 if (init)
103 {
104 init=0;
105#ifndef OPENSSL_NO_ERR
106 ERR_load_strings(ERR_LIB_UI,UI_str_functs);
107 ERR_load_strings(ERR_LIB_UI,UI_str_reasons);
108#endif
109
110 }
111 }
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
new file mode 100644
index 0000000000..dbc9711a2d
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -0,0 +1,902 @@
1/* crypto/ui/ui_lib.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/e_os2.h>
61#include <openssl/buffer.h>
62#include <openssl/ui.h>
63#include <openssl/err.h>
64#include "ui_locl.h"
65#include "cryptlib.h"
66
67IMPLEMENT_STACK_OF(UI_STRING_ST)
68
69static const UI_METHOD *default_UI_meth=NULL;
70
71UI *UI_new(void)
72 {
73 return(UI_new_method(NULL));
74 }
75
76UI *UI_new_method(const UI_METHOD *method)
77 {
78 UI *ret;
79
80 ret=(UI *)OPENSSL_malloc(sizeof(UI));
81 if (ret == NULL)
82 {
83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
84 return NULL;
85 }
86 if (method == NULL)
87 ret->meth=UI_get_default_method();
88 else
89 ret->meth=method;
90
91 ret->strings=NULL;
92 ret->user_data=NULL;
93 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
94 return ret;
95 }
96
97static void free_string(UI_STRING *uis)
98 {
99 if (uis->flags & OUT_STRING_FREEABLE)
100 {
101 OPENSSL_free((char *)uis->out_string);
102 switch(uis->type)
103 {
104 case UIT_BOOLEAN:
105 OPENSSL_free((char *)uis->_.boolean_data.action_desc);
106 OPENSSL_free((char *)uis->_.boolean_data.ok_chars);
107 OPENSSL_free((char *)uis->_.boolean_data.cancel_chars);
108 break;
109 default:
110 break;
111 }
112 }
113 OPENSSL_free(uis);
114 }
115
116void UI_free(UI *ui)
117 {
118 if (ui == NULL)
119 return;
120 sk_UI_STRING_pop_free(ui->strings,free_string);
121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
122 OPENSSL_free(ui);
123 }
124
125static int allocate_string_stack(UI *ui)
126 {
127 if (ui->strings == NULL)
128 {
129 ui->strings=sk_UI_STRING_new_null();
130 if (ui->strings == NULL)
131 {
132 return -1;
133 }
134 }
135 return 0;
136 }
137
138static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt,
139 int prompt_freeable, enum UI_string_types type, int input_flags,
140 char *result_buf)
141 {
142 UI_STRING *ret = NULL;
143
144 if (prompt == NULL)
145 {
146 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER);
147 }
148 else if ((type == UIT_PROMPT || type == UIT_VERIFY
149 || type == UIT_BOOLEAN) && result_buf == NULL)
150 {
151 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER);
152 }
153 else if ((ret = (UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING))))
154 {
155 ret->out_string=prompt;
156 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
157 ret->input_flags=input_flags;
158 ret->type=type;
159 ret->result_buf=result_buf;
160 }
161 return ret;
162 }
163
164static int general_allocate_string(UI *ui, const char *prompt,
165 int prompt_freeable, enum UI_string_types type, int input_flags,
166 char *result_buf, int minsize, int maxsize, const char *test_buf)
167 {
168 int ret = -1;
169 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
170 type, input_flags, result_buf);
171
172 if (s)
173 {
174 if (allocate_string_stack(ui) >= 0)
175 {
176 s->_.string_data.result_minsize=minsize;
177 s->_.string_data.result_maxsize=maxsize;
178 s->_.string_data.test_buf=test_buf;
179 ret=sk_UI_STRING_push(ui->strings, s);
180 /* sk_push() returns 0 on error. Let's addapt that */
181 if (ret <= 0) ret--;
182 }
183 else
184 free_string(s);
185 }
186 return ret;
187 }
188
189static int general_allocate_boolean(UI *ui,
190 const char *prompt, const char *action_desc,
191 const char *ok_chars, const char *cancel_chars,
192 int prompt_freeable, enum UI_string_types type, int input_flags,
193 char *result_buf)
194 {
195 int ret = -1;
196 UI_STRING *s;
197 const char *p;
198
199 if (ok_chars == NULL)
200 {
201 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
202 }
203 else if (cancel_chars == NULL)
204 {
205 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
206 }
207 else
208 {
209 for(p = ok_chars; *p; p++)
210 {
211 if (strchr(cancel_chars, *p))
212 {
213 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
214 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
215 }
216 }
217
218 s = general_allocate_prompt(ui, prompt, prompt_freeable,
219 type, input_flags, result_buf);
220
221 if (s)
222 {
223 if (allocate_string_stack(ui) >= 0)
224 {
225 s->_.boolean_data.action_desc = action_desc;
226 s->_.boolean_data.ok_chars = ok_chars;
227 s->_.boolean_data.cancel_chars = cancel_chars;
228 ret=sk_UI_STRING_push(ui->strings, s);
229 /* sk_push() returns 0 on error.
230 Let's addapt that */
231 if (ret <= 0) ret--;
232 }
233 else
234 free_string(s);
235 }
236 }
237 return ret;
238 }
239
240/* Returns the index to the place in the stack or -1 for error. Uses a
241 direct reference to the prompt. */
242int UI_add_input_string(UI *ui, const char *prompt, int flags,
243 char *result_buf, int minsize, int maxsize)
244 {
245 return general_allocate_string(ui, prompt, 0,
246 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
247 }
248
249/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
250int UI_dup_input_string(UI *ui, const char *prompt, int flags,
251 char *result_buf, int minsize, int maxsize)
252 {
253 char *prompt_copy=NULL;
254
255 if (prompt)
256 {
257 prompt_copy=BUF_strdup(prompt);
258 if (prompt_copy == NULL)
259 {
260 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
261 return 0;
262 }
263 }
264
265 return general_allocate_string(ui, prompt_copy, 1,
266 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
267 }
268
269int UI_add_verify_string(UI *ui, const char *prompt, int flags,
270 char *result_buf, int minsize, int maxsize, const char *test_buf)
271 {
272 return general_allocate_string(ui, prompt, 0,
273 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
274 }
275
276int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
277 char *result_buf, int minsize, int maxsize, const char *test_buf)
278 {
279 char *prompt_copy=NULL;
280
281 if (prompt)
282 {
283 prompt_copy=BUF_strdup(prompt);
284 if (prompt_copy == NULL)
285 {
286 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
287 return -1;
288 }
289 }
290
291 return general_allocate_string(ui, prompt_copy, 1,
292 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
293 }
294
295int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
296 const char *ok_chars, const char *cancel_chars,
297 int flags, char *result_buf)
298 {
299 return general_allocate_boolean(ui, prompt, action_desc,
300 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
301 }
302
303int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
304 const char *ok_chars, const char *cancel_chars,
305 int flags, char *result_buf)
306 {
307 char *prompt_copy = NULL;
308 char *action_desc_copy = NULL;
309 char *ok_chars_copy = NULL;
310 char *cancel_chars_copy = NULL;
311
312 if (prompt)
313 {
314 prompt_copy=BUF_strdup(prompt);
315 if (prompt_copy == NULL)
316 {
317 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
318 goto err;
319 }
320 }
321
322 if (action_desc)
323 {
324 action_desc_copy=BUF_strdup(action_desc);
325 if (action_desc_copy == NULL)
326 {
327 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
328 goto err;
329 }
330 }
331
332 if (ok_chars)
333 {
334 ok_chars_copy=BUF_strdup(ok_chars);
335 if (ok_chars_copy == NULL)
336 {
337 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
338 goto err;
339 }
340 }
341
342 if (cancel_chars)
343 {
344 cancel_chars_copy=BUF_strdup(cancel_chars);
345 if (cancel_chars_copy == NULL)
346 {
347 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
348 goto err;
349 }
350 }
351
352 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
353 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
354 result_buf);
355 err:
356 if (prompt_copy) OPENSSL_free(prompt_copy);
357 if (action_desc_copy) OPENSSL_free(action_desc_copy);
358 if (ok_chars_copy) OPENSSL_free(ok_chars_copy);
359 if (cancel_chars_copy) OPENSSL_free(cancel_chars_copy);
360 return -1;
361 }
362
363int UI_add_info_string(UI *ui, const char *text)
364 {
365 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
366 NULL);
367 }
368
369int UI_dup_info_string(UI *ui, const char *text)
370 {
371 char *text_copy=NULL;
372
373 if (text)
374 {
375 text_copy=BUF_strdup(text);
376 if (text_copy == NULL)
377 {
378 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
379 return -1;
380 }
381 }
382
383 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
384 0, 0, NULL);
385 }
386
387int UI_add_error_string(UI *ui, const char *text)
388 {
389 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
390 NULL);
391 }
392
393int UI_dup_error_string(UI *ui, const char *text)
394 {
395 char *text_copy=NULL;
396
397 if (text)
398 {
399 text_copy=BUF_strdup(text);
400 if (text_copy == NULL)
401 {
402 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
403 return -1;
404 }
405 }
406 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
407 0, 0, NULL);
408 }
409
410char *UI_construct_prompt(UI *ui, const char *object_desc,
411 const char *object_name)
412 {
413 char *prompt = NULL;
414
415 if (ui->meth->ui_construct_prompt)
416 prompt = ui->meth->ui_construct_prompt(ui,
417 object_desc, object_name);
418 else
419 {
420 char prompt1[] = "Enter ";
421 char prompt2[] = " for ";
422 char prompt3[] = ":";
423 int len = 0;
424
425 if (object_desc == NULL)
426 return NULL;
427 len = sizeof(prompt1) - 1 + strlen(object_desc);
428 if (object_name)
429 len += sizeof(prompt2) - 1 + strlen(object_name);
430 len += sizeof(prompt3) - 1;
431
432 prompt = (char *)OPENSSL_malloc(len + 1);
433 BUF_strlcpy(prompt, prompt1, len + 1);
434 BUF_strlcat(prompt, object_desc, len + 1);
435 if (object_name)
436 {
437 BUF_strlcat(prompt, prompt2, len + 1);
438 BUF_strlcat(prompt, object_name, len + 1);
439 }
440 BUF_strlcat(prompt, prompt3, len + 1);
441 }
442 return prompt;
443 }
444
445void *UI_add_user_data(UI *ui, void *user_data)
446 {
447 void *old_data = ui->user_data;
448 ui->user_data = user_data;
449 return old_data;
450 }
451
452void *UI_get0_user_data(UI *ui)
453 {
454 return ui->user_data;
455 }
456
457const char *UI_get0_result(UI *ui, int i)
458 {
459 if (i < 0)
460 {
461 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL);
462 return NULL;
463 }
464 if (i >= sk_UI_STRING_num(ui->strings))
465 {
466 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
467 return NULL;
468 }
469 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
470 }
471
472static int print_error(const char *str, size_t len, UI *ui)
473 {
474 UI_STRING uis;
475
476 memset(&uis, 0, sizeof(uis));
477 uis.type = UIT_ERROR;
478 uis.out_string = str;
479
480 if (ui->meth->ui_write_string
481 && !ui->meth->ui_write_string(ui, &uis))
482 return -1;
483 return 0;
484 }
485
486int UI_process(UI *ui)
487 {
488 int i, ok=0;
489
490 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
491 return -1;
492
493 if (ui->flags & UI_FLAG_PRINT_ERRORS)
494 ERR_print_errors_cb(
495 (int (*)(const char *, size_t, void *))print_error,
496 (void *)ui);
497
498 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
499 {
500 if (ui->meth->ui_write_string
501 && !ui->meth->ui_write_string(ui,
502 sk_UI_STRING_value(ui->strings, i)))
503 {
504 ok=-1;
505 goto err;
506 }
507 }
508
509 if (ui->meth->ui_flush)
510 switch(ui->meth->ui_flush(ui))
511 {
512 case -1: /* Interrupt/Cancel/something... */
513 ok = -2;
514 goto err;
515 case 0: /* Errors */
516 ok = -1;
517 goto err;
518 default: /* Success */
519 ok = 0;
520 break;
521 }
522
523 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
524 {
525 if (ui->meth->ui_read_string)
526 {
527 switch(ui->meth->ui_read_string(ui,
528 sk_UI_STRING_value(ui->strings, i)))
529 {
530 case -1: /* Interrupt/Cancel/something... */
531 ok = -2;
532 goto err;
533 case 0: /* Errors */
534 ok = -1;
535 goto err;
536 default: /* Success */
537 ok = 0;
538 break;
539 }
540 }
541 }
542 err:
543 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
544 return -1;
545 return ok;
546 }
547
548int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
549 {
550 if (ui == NULL)
551 {
552 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER);
553 return -1;
554 }
555 switch(cmd)
556 {
557 case UI_CTRL_PRINT_ERRORS:
558 {
559 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
560 if (i)
561 ui->flags |= UI_FLAG_PRINT_ERRORS;
562 else
563 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
564 return save_flag;
565 }
566 case UI_CTRL_IS_REDOABLE:
567 return !!(ui->flags & UI_FLAG_REDOABLE);
568 default:
569 break;
570 }
571 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
572 return -1;
573 }
574
575int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
576 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
577 {
578 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
579 new_func, dup_func, free_func);
580 }
581
582int UI_set_ex_data(UI *r, int idx, void *arg)
583 {
584 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
585 }
586
587void *UI_get_ex_data(UI *r, int idx)
588 {
589 return(CRYPTO_get_ex_data(&r->ex_data,idx));
590 }
591
592void UI_set_default_method(const UI_METHOD *meth)
593 {
594 default_UI_meth=meth;
595 }
596
597const UI_METHOD *UI_get_default_method(void)
598 {
599 if (default_UI_meth == NULL)
600 {
601 default_UI_meth=UI_OpenSSL();
602 }
603 return default_UI_meth;
604 }
605
606const UI_METHOD *UI_get_method(UI *ui)
607 {
608 return ui->meth;
609 }
610
611const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth)
612 {
613 ui->meth=meth;
614 return ui->meth;
615 }
616
617
618UI_METHOD *UI_create_method(char *name)
619 {
620 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
621
622 if (ui_method)
623 memset(ui_method, 0, sizeof(*ui_method));
624 ui_method->name = BUF_strdup(name);
625 return ui_method;
626 }
627
628/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
629 (that is, it hasn't been allocated using UI_create_method(), you deserve
630 anything Murphy can throw at you and more! You have been warned. */
631void UI_destroy_method(UI_METHOD *ui_method)
632 {
633 OPENSSL_free(ui_method->name);
634 ui_method->name = NULL;
635 OPENSSL_free(ui_method);
636 }
637
638int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
639 {
640 if (method)
641 {
642 method->ui_open_session = opener;
643 return 0;
644 }
645 else
646 return -1;
647 }
648
649int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
650 {
651 if (method)
652 {
653 method->ui_write_string = writer;
654 return 0;
655 }
656 else
657 return -1;
658 }
659
660int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
661 {
662 if (method)
663 {
664 method->ui_flush = flusher;
665 return 0;
666 }
667 else
668 return -1;
669 }
670
671int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
672 {
673 if (method)
674 {
675 method->ui_read_string = reader;
676 return 0;
677 }
678 else
679 return -1;
680 }
681
682int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
683 {
684 if (method)
685 {
686 method->ui_close_session = closer;
687 return 0;
688 }
689 else
690 return -1;
691 }
692
693int (*UI_method_get_opener(UI_METHOD *method))(UI*)
694 {
695 if (method)
696 return method->ui_open_session;
697 else
698 return NULL;
699 }
700
701int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
702 {
703 if (method)
704 return method->ui_write_string;
705 else
706 return NULL;
707 }
708
709int (*UI_method_get_flusher(UI_METHOD *method))(UI*)
710 {
711 if (method)
712 return method->ui_flush;
713 else
714 return NULL;
715 }
716
717int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
718 {
719 if (method)
720 return method->ui_read_string;
721 else
722 return NULL;
723 }
724
725int (*UI_method_get_closer(UI_METHOD *method))(UI*)
726 {
727 if (method)
728 return method->ui_close_session;
729 else
730 return NULL;
731 }
732
733enum UI_string_types UI_get_string_type(UI_STRING *uis)
734 {
735 if (!uis)
736 return UIT_NONE;
737 return uis->type;
738 }
739
740int UI_get_input_flags(UI_STRING *uis)
741 {
742 if (!uis)
743 return 0;
744 return uis->input_flags;
745 }
746
747const char *UI_get0_output_string(UI_STRING *uis)
748 {
749 if (!uis)
750 return NULL;
751 return uis->out_string;
752 }
753
754const char *UI_get0_action_string(UI_STRING *uis)
755 {
756 if (!uis)
757 return NULL;
758 switch(uis->type)
759 {
760 case UIT_PROMPT:
761 case UIT_BOOLEAN:
762 return uis->_.boolean_data.action_desc;
763 default:
764 return NULL;
765 }
766 }
767
768const char *UI_get0_result_string(UI_STRING *uis)
769 {
770 if (!uis)
771 return NULL;
772 switch(uis->type)
773 {
774 case UIT_PROMPT:
775 case UIT_VERIFY:
776 return uis->result_buf;
777 default:
778 return NULL;
779 }
780 }
781
782const char *UI_get0_test_string(UI_STRING *uis)
783 {
784 if (!uis)
785 return NULL;
786 switch(uis->type)
787 {
788 case UIT_VERIFY:
789 return uis->_.string_data.test_buf;
790 default:
791 return NULL;
792 }
793 }
794
795int UI_get_result_minsize(UI_STRING *uis)
796 {
797 if (!uis)
798 return -1;
799 switch(uis->type)
800 {
801 case UIT_PROMPT:
802 case UIT_VERIFY:
803 return uis->_.string_data.result_minsize;
804 default:
805 return -1;
806 }
807 }
808
809int UI_get_result_maxsize(UI_STRING *uis)
810 {
811 if (!uis)
812 return -1;
813 switch(uis->type)
814 {
815 case UIT_PROMPT:
816 case UIT_VERIFY:
817 return uis->_.string_data.result_maxsize;
818 default:
819 return -1;
820 }
821 }
822
823int UI_set_result(UI *ui, UI_STRING *uis, const char *result)
824 {
825 int l = strlen(result);
826
827 ui->flags &= ~UI_FLAG_REDOABLE;
828
829 if (!uis)
830 return -1;
831 switch (uis->type)
832 {
833 case UIT_PROMPT:
834 case UIT_VERIFY:
835 {
836 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1];
837 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1];
838
839 BIO_snprintf(number1, sizeof(number1), "%d",
840 uis->_.string_data.result_minsize);
841 BIO_snprintf(number2, sizeof(number2), "%d",
842 uis->_.string_data.result_maxsize);
843
844 if (l < uis->_.string_data.result_minsize)
845 {
846 ui->flags |= UI_FLAG_REDOABLE;
847 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL);
848 ERR_add_error_data(5,"You must type in ",
849 number1," to ",number2," characters");
850 return -1;
851 }
852 if (l > uis->_.string_data.result_maxsize)
853 {
854 ui->flags |= UI_FLAG_REDOABLE;
855 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE);
856 ERR_add_error_data(5,"You must type in ",
857 number1," to ",number2," characters");
858 return -1;
859 }
860 }
861
862 if (!uis->result_buf)
863 {
864 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
865 return -1;
866 }
867
868 BUF_strlcpy(uis->result_buf, result,
869 uis->_.string_data.result_maxsize + 1);
870 break;
871 case UIT_BOOLEAN:
872 {
873 const char *p;
874
875 if (!uis->result_buf)
876 {
877 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
878 return -1;
879 }
880
881 uis->result_buf[0] = '\0';
882 for(p = result; *p; p++)
883 {
884 if (strchr(uis->_.boolean_data.ok_chars, *p))
885 {
886 uis->result_buf[0] =
887 uis->_.boolean_data.ok_chars[0];
888 break;
889 }
890 if (strchr(uis->_.boolean_data.cancel_chars, *p))
891 {
892 uis->result_buf[0] =
893 uis->_.boolean_data.cancel_chars[0];
894 break;
895 }
896 }
897 default:
898 break;
899 }
900 }
901 return 0;
902 }
diff --git a/src/lib/libcrypto/ui/ui_locl.h b/src/lib/libcrypto/ui/ui_locl.h
new file mode 100644
index 0000000000..7d3a75a619
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_locl.h
@@ -0,0 +1,148 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_LOCL_H
60#define HEADER_UI_LOCL_H
61
62#include <openssl/ui.h>
63
64struct ui_method_st
65 {
66 char *name;
67
68 /* All the functions return 1 or non-NULL for success and 0 or NULL
69 for failure */
70
71 /* Open whatever channel for this, be it the console, an X window
72 or whatever.
73 This function should use the ex_data structure to save
74 intermediate data. */
75 int (*ui_open_session)(UI *ui);
76
77 int (*ui_write_string)(UI *ui, UI_STRING *uis);
78
79 /* Flush the output. If a GUI dialog box is used, this function can
80 be used to actually display it. */
81 int (*ui_flush)(UI *ui);
82
83 int (*ui_read_string)(UI *ui, UI_STRING *uis);
84
85 int (*ui_close_session)(UI *ui);
86
87 /* Construct a prompt in a user-defined manner. object_desc is a
88 textual short description of the object, for example "pass phrase",
89 and object_name is the name of the object (might be a card name or
90 a file name.
91 The returned string shall always be allocated on the heap with
92 OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). */
93 char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
94 const char *object_name);
95 };
96
97struct ui_string_st
98 {
99 enum UI_string_types type; /* Input */
100 const char *out_string; /* Input */
101 int input_flags; /* Flags from the user */
102
103 /* The following parameters are completely irrelevant for UIT_INFO,
104 and can therefore be set to 0 or NULL */
105 char *result_buf; /* Input and Output: If not NULL, user-defined
106 with size in result_maxsize. Otherwise, it
107 may be allocated by the UI routine, meaning
108 result_minsize is going to be overwritten.*/
109 union
110 {
111 struct
112 {
113 int result_minsize; /* Input: minimum required
114 size of the result.
115 */
116 int result_maxsize; /* Input: maximum permitted
117 size of the result */
118
119 const char *test_buf; /* Input: test string to verify
120 against */
121 } string_data;
122 struct
123 {
124 const char *action_desc; /* Input */
125 const char *ok_chars; /* Input */
126 const char *cancel_chars; /* Input */
127 } boolean_data;
128 } _;
129
130#define OUT_STRING_FREEABLE 0x01
131 int flags; /* flags for internal use */
132 };
133
134struct ui_st
135 {
136 const UI_METHOD *meth;
137 STACK_OF(UI_STRING) *strings; /* We might want to prompt for more
138 than one thing at a time, and
139 with different echoing status. */
140 void *user_data;
141 CRYPTO_EX_DATA ex_data;
142
143#define UI_FLAG_REDOABLE 0x0001
144#define UI_FLAG_PRINT_ERRORS 0x0100
145 int flags;
146 };
147
148#endif
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
new file mode 100644
index 0000000000..75318d48a1
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_openssl.c
@@ -0,0 +1,673 @@
1/* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) and others
3 * for the OpenSSL project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* The lowest level part of this file was previously in crypto/des/read_pwd.c,
60 * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
61 * All rights reserved.
62 *
63 * This package is an SSL implementation written
64 * by Eric Young (eay@cryptsoft.com).
65 * The implementation was written so as to conform with Netscapes SSL.
66 *
67 * This library is free for commercial and non-commercial use as long as
68 * the following conditions are aheared to. The following conditions
69 * apply to all code found in this distribution, be it the RC4, RSA,
70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
71 * included with this distribution is covered by the same copyright terms
72 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 *
74 * Copyright remains Eric Young's, and as such any Copyright notices in
75 * the code are not to be removed.
76 * If this package is used in a product, Eric Young should be given attribution
77 * as the author of the parts of the library used.
78 * This can be in the form of a textual message at program startup or
79 * in documentation (online or textual) provided with the package.
80 *
81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions
83 * are met:
84 * 1. Redistributions of source code must retain the copyright
85 * notice, this list of conditions and the following disclaimer.
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in the
88 * documentation and/or other materials provided with the distribution.
89 * 3. All advertising materials mentioning features or use of this software
90 * must display the following acknowledgement:
91 * "This product includes cryptographic software written by
92 * Eric Young (eay@cryptsoft.com)"
93 * The word 'cryptographic' can be left out if the rouines from the library
94 * being used are not cryptographic related :-).
95 * 4. If you include any Windows specific code (or a derivative thereof) from
96 * the apps directory (application code) you must include an acknowledgement:
97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
103 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
104 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
105 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE.
110 *
111 * The licence and distribution terms for any publically available version or
112 * derivative of this code cannot be changed. i.e. this code cannot simply be
113 * copied and put under another distribution licence
114 * [including the GNU Public Licence.]
115 */
116
117
118#include <openssl/e_os2.h>
119
120#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
121# ifdef OPENSSL_UNISTD
122# include OPENSSL_UNISTD
123# else
124# include <unistd.h>
125# endif
126/* If unistd.h defines _POSIX_VERSION, we conclude that we
127 * are on a POSIX system and have sigaction and termios. */
128# if defined(_POSIX_VERSION)
129
130# define SIGACTION
131# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132# define TERMIOS
133# endif
134
135# endif
136#endif
137
138#ifdef WIN16TTY
139# undef OPENSSL_SYS_WIN16
140# undef WIN16
141# undef _WINDOWS
142# include <graph.h>
143#endif
144
145/* 06-Apr-92 Luke Brennan Support for VMS */
146#include "ui_locl.h"
147#include "cryptlib.h"
148#include <signal.h>
149#include <stdio.h>
150#include <string.h>
151#include <errno.h>
152
153#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
154# include <starlet.h>
155# ifdef __DECC
156# pragma message disable DOLLARID
157# endif
158#endif
159
160#ifdef WIN_CONSOLE_BUG
161# include <windows.h>
162#ifndef OPENSSL_SYS_WINCE
163# include <wincon.h>
164#endif
165#endif
166
167
168/* There are 5 types of terminal interface supported,
169 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
170 */
171
172#if defined(__sgi) && !defined(TERMIOS)
173# define TERMIOS
174# undef TERMIO
175# undef SGTTY
176#endif
177
178#if defined(linux) && !defined(TERMIO)
179# undef TERMIOS
180# define TERMIO
181# undef SGTTY
182#endif
183
184#ifdef _LIBC
185# undef TERMIOS
186# define TERMIO
187# undef SGTTY
188#endif
189
190#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
191# undef TERMIOS
192# undef TERMIO
193# define SGTTY
194#endif
195
196#if defined(OPENSSL_SYS_VXWORKS)
197#undef TERMIOS
198#undef TERMIO
199#undef SGTTY
200#endif
201
202#ifdef TERMIOS
203# include <termios.h>
204# define TTY_STRUCT struct termios
205# define TTY_FLAGS c_lflag
206# define TTY_get(tty,data) tcgetattr(tty,data)
207# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
208#endif
209
210#ifdef TERMIO
211# include <termio.h>
212# define TTY_STRUCT struct termio
213# define TTY_FLAGS c_lflag
214# define TTY_get(tty,data) ioctl(tty,TCGETA,data)
215# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
216#endif
217
218#ifdef SGTTY
219# include <sgtty.h>
220# define TTY_STRUCT struct sgttyb
221# define TTY_FLAGS sg_flags
222# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
223# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
224#endif
225
226#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
227# include <sys/ioctl.h>
228#endif
229
230#ifdef OPENSSL_SYS_MSDOS
231# include <conio.h>
232#endif
233
234#ifdef OPENSSL_SYS_VMS
235# include <ssdef.h>
236# include <iodef.h>
237# include <ttdef.h>
238# include <descrip.h>
239struct IOSB {
240 short iosb$w_value;
241 short iosb$w_count;
242 long iosb$l_info;
243 };
244#endif
245
246#ifdef OPENSSL_SYS_SUNOS
247 typedef int sig_atomic_t;
248#endif
249
250#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
251/*
252 * This one needs work. As a matter of fact the code is unoperational
253 * and this is only a trick to get it compiled.
254 * <appro@fy.chalmers.se>
255 */
256# define TTY_STRUCT int
257#endif
258
259#ifndef NX509_SIG
260# define NX509_SIG 32
261#endif
262
263
264/* Define globals. They are protected by a lock */
265#ifdef SIGACTION
266static struct sigaction savsig[NX509_SIG];
267#else
268static void (*savsig[NX509_SIG])(int );
269#endif
270
271#ifdef OPENSSL_SYS_VMS
272static struct IOSB iosb;
273static $DESCRIPTOR(terminal,"TT");
274static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
275static long status;
276static unsigned short channel = 0;
277#else
278#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
279static TTY_STRUCT tty_orig,tty_new;
280#endif
281#endif
282static FILE *tty_in, *tty_out;
283static int is_a_tty;
284
285/* Declare static functions */
286#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
287static void read_till_nl(FILE *);
288static void recsig(int);
289static void pushsig(void);
290static void popsig(void);
291#endif
292#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
293static int noecho_fgets(char *buf, int size, FILE *tty);
294#endif
295static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
296
297static int read_string(UI *ui, UI_STRING *uis);
298static int write_string(UI *ui, UI_STRING *uis);
299
300static int open_console(UI *ui);
301static int echo_console(UI *ui);
302static int noecho_console(UI *ui);
303static int close_console(UI *ui);
304
305static UI_METHOD ui_openssl =
306 {
307 "OpenSSL default user interface",
308 open_console,
309 write_string,
310 NULL, /* No flusher is needed for command lines */
311 read_string,
312 close_console,
313 NULL
314 };
315
316/* The method with all the built-in thingies */
317UI_METHOD *UI_OpenSSL(void)
318 {
319 return &ui_openssl;
320 }
321
322/* The following function makes sure that info and error strings are printed
323 before any prompt. */
324static int write_string(UI *ui, UI_STRING *uis)
325 {
326 switch (UI_get_string_type(uis))
327 {
328 case UIT_ERROR:
329 case UIT_INFO:
330 fputs(UI_get0_output_string(uis), tty_out);
331 fflush(tty_out);
332 break;
333 default:
334 break;
335 }
336 return 1;
337 }
338
339static int read_string(UI *ui, UI_STRING *uis)
340 {
341 int ok = 0;
342
343 switch (UI_get_string_type(uis))
344 {
345 case UIT_BOOLEAN:
346 fputs(UI_get0_output_string(uis), tty_out);
347 fputs(UI_get0_action_string(uis), tty_out);
348 fflush(tty_out);
349 return read_string_inner(ui, uis,
350 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
351 case UIT_PROMPT:
352 fputs(UI_get0_output_string(uis), tty_out);
353 fflush(tty_out);
354 return read_string_inner(ui, uis,
355 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
356 case UIT_VERIFY:
357 fprintf(tty_out,"Verifying - %s",
358 UI_get0_output_string(uis));
359 fflush(tty_out);
360 if ((ok = read_string_inner(ui, uis,
361 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
362 return ok;
363 if (strcmp(UI_get0_result_string(uis),
364 UI_get0_test_string(uis)) != 0)
365 {
366 fprintf(tty_out,"Verify failure\n");
367 fflush(tty_out);
368 return 0;
369 }
370 break;
371 default:
372 break;
373 }
374 return 1;
375 }
376
377
378#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
379/* Internal functions to read a string without echoing */
380static void read_till_nl(FILE *in)
381 {
382#define SIZE 4
383 char buf[SIZE+1];
384
385 do {
386 fgets(buf,SIZE,in);
387 } while (strchr(buf,'\n') == NULL);
388 }
389
390static volatile sig_atomic_t intr_signal;
391#endif
392
393static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
394 {
395 static int ps;
396 int ok;
397 char result[BUFSIZ];
398 int maxsize = BUFSIZ-1;
399#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
400 char *p;
401
402 intr_signal=0;
403 ok=0;
404 ps=0;
405
406 pushsig();
407 ps=1;
408
409 if (!echo && !noecho_console(ui))
410 goto error;
411 ps=2;
412
413 result[0]='\0';
414#ifdef OPENSSL_SYS_MSDOS
415 if (!echo)
416 {
417 noecho_fgets(result,maxsize,tty_in);
418 p=result; /* FIXME: noecho_fgets doesn't return errors */
419 }
420 else
421 p=fgets(result,maxsize,tty_in);
422#else
423 p=fgets(result,maxsize,tty_in);
424#endif
425 if(!p)
426 goto error;
427 if (feof(tty_in)) goto error;
428 if (ferror(tty_in)) goto error;
429 if ((p=(char *)strchr(result,'\n')) != NULL)
430 {
431 if (strip_nl)
432 *p='\0';
433 }
434 else
435 read_till_nl(tty_in);
436 if (UI_set_result(ui, uis, result) >= 0)
437 ok=1;
438
439error:
440 if (intr_signal == SIGINT)
441 ok=-1;
442 if (!echo) fprintf(tty_out,"\n");
443 if (ps >= 2 && !echo && !echo_console(ui))
444 ok=0;
445
446 if (ps >= 1)
447 popsig();
448#else
449 ok=1;
450#endif
451
452 OPENSSL_cleanse(result,BUFSIZ);
453 return ok;
454 }
455
456
457/* Internal functions to open, handle and close a channel to the console. */
458static int open_console(UI *ui)
459 {
460 CRYPTO_w_lock(CRYPTO_LOCK_UI);
461 is_a_tty = 1;
462
463#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS)
464 tty_in=stdin;
465 tty_out=stderr;
466#else
467# ifdef OPENSSL_SYS_MSDOS
468# define DEV_TTY "con"
469# else
470# define DEV_TTY "/dev/tty"
471# endif
472 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
473 tty_in=stdin;
474 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
475 tty_out=stderr;
476#endif
477
478#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
479 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
480 {
481#ifdef ENOTTY
482 if (errno == ENOTTY)
483 is_a_tty=0;
484 else
485#endif
486#ifdef EINVAL
487 /* Ariel Glenn ariel@columbia.edu reports that solaris
488 * can return EINVAL instead. This should be ok */
489 if (errno == EINVAL)
490 is_a_tty=0;
491 else
492#endif
493 return 0;
494 }
495#endif
496#ifdef OPENSSL_SYS_VMS
497 status = sys$assign(&terminal,&channel,0,0);
498 if (status != SS$_NORMAL)
499 return 0;
500 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
501 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
502 return 0;
503#endif
504 return 1;
505 }
506
507static int noecho_console(UI *ui)
508 {
509#ifdef TTY_FLAGS
510 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
511 tty_new.TTY_FLAGS &= ~ECHO;
512#endif
513
514#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
515 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
516 return 0;
517#endif
518#ifdef OPENSSL_SYS_VMS
519 tty_new[0] = tty_orig[0];
520 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
521 tty_new[2] = tty_orig[2];
522 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
523 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
524 return 0;
525#endif
526 return 1;
527 }
528
529static int echo_console(UI *ui)
530 {
531#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
532 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
533 tty_new.TTY_FLAGS |= ECHO;
534#endif
535
536#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
537 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
538 return 0;
539#endif
540#ifdef OPENSSL_SYS_VMS
541 tty_new[0] = tty_orig[0];
542 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
543 tty_new[2] = tty_orig[2];
544 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
545 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
546 return 0;
547#endif
548 return 1;
549 }
550
551static int close_console(UI *ui)
552 {
553 if (tty_in != stdin) fclose(tty_in);
554 if (tty_out != stderr) fclose(tty_out);
555#ifdef OPENSSL_SYS_VMS
556 status = sys$dassgn(channel);
557#endif
558 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
559
560 return 1;
561 }
562
563
564#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
565/* Internal functions to handle signals and act on them */
566static void pushsig(void)
567 {
568 int i;
569#ifdef SIGACTION
570 struct sigaction sa;
571
572 memset(&sa,0,sizeof sa);
573 sa.sa_handler=recsig;
574#endif
575
576 for (i=1; i<NX509_SIG; i++)
577 {
578#ifdef SIGUSR1
579 if (i == SIGUSR1)
580 continue;
581#endif
582#ifdef SIGUSR2
583 if (i == SIGUSR2)
584 continue;
585#endif
586#ifdef SIGKILL
587 if (i == SIGKILL) /* We can't make any action on that. */
588 continue;
589#endif
590#ifdef SIGACTION
591 sigaction(i,&sa,&savsig[i]);
592#else
593 savsig[i]=signal(i,recsig);
594#endif
595 }
596
597#ifdef SIGWINCH
598 signal(SIGWINCH,SIG_DFL);
599#endif
600 }
601
602static void popsig(void)
603 {
604 int i;
605
606 for (i=1; i<NX509_SIG; i++)
607 {
608#ifdef SIGUSR1
609 if (i == SIGUSR1)
610 continue;
611#endif
612#ifdef SIGUSR2
613 if (i == SIGUSR2)
614 continue;
615#endif
616#ifdef SIGACTION
617 sigaction(i,&savsig[i],NULL);
618#else
619 signal(i,savsig[i]);
620#endif
621 }
622 }
623
624static void recsig(int i)
625 {
626 intr_signal=i;
627 }
628#endif
629
630/* Internal functions specific for Windows */
631#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
632static int noecho_fgets(char *buf, int size, FILE *tty)
633 {
634 int i;
635 char *p;
636
637 p=buf;
638 for (;;)
639 {
640 if (size == 0)
641 {
642 *p='\0';
643 break;
644 }
645 size--;
646#ifdef WIN16TTY
647 i=_inchar();
648#else
649 i=getch();
650#endif
651 if (i == '\r') i='\n';
652 *(p++)=i;
653 if (i == '\n')
654 {
655 *p='\0';
656 break;
657 }
658 }
659#ifdef WIN_CONSOLE_BUG
660/* Win95 has several evil console bugs: one of these is that the
661 * last character read using getch() is passed to the next read: this is
662 * usually a CR so this can be trouble. No STDIO fix seems to work but
663 * flushing the console appears to do the trick.
664 */
665 {
666 HANDLE inh;
667 inh = GetStdHandle(STD_INPUT_HANDLE);
668 FlushConsoleInputBuffer(inh);
669 }
670#endif
671 return(strlen(buf));
672 }
673#endif
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
new file mode 100644
index 0000000000..46bc8c1a9a
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_util.c
@@ -0,0 +1,91 @@
1/* crypto/ui/ui_util.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui.h>
58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 char buff[BUFSIZ];
62 int ret;
63
64 ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
65 OPENSSL_cleanse(buff,BUFSIZ);
66 return(ret);
67 }
68
69int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
70 {
71 int ok = 0;
72 UI *ui;
73
74 if (size < 1)
75 return -1;
76
77 ui = UI_new();
78 if (ui)
79 {
80 ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
81 if (ok >= 0 && verify)
82 ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1,
83 buf);
84 if (ok >= 0)
85 ok=UI_process(ui);
86 UI_free(ui);
87 }
88 if (ok > 0)
89 ok = 0;
90 return(ok);
91 }
diff --git a/src/lib/libcrypto/util/libeay.num b/src/lib/libcrypto/util/libeay.num
index 4222bef6d6..56fb7446e0 100644
--- a/src/lib/libcrypto/util/libeay.num
+++ b/src/lib/libcrypto/util/libeay.num
@@ -2811,7 +2811,7 @@ EVP_aes_192_cfb8 3252 EXIST::FUNCTION:AES
2811FIPS_mode_set 3253 EXIST:OPENSSL_FIPS:FUNCTION: 2811FIPS_mode_set 3253 EXIST:OPENSSL_FIPS:FUNCTION:
2812FIPS_selftest_dsa 3254 EXIST:OPENSSL_FIPS:FUNCTION: 2812FIPS_selftest_dsa 3254 EXIST:OPENSSL_FIPS:FUNCTION:
2813EVP_aes_256_cfb8 3255 EXIST::FUNCTION:AES 2813EVP_aes_256_cfb8 3255 EXIST::FUNCTION:AES
2814FIPS_allow_md5 3256 NOEXIST::FUNCTION: 2814FIPS_allow_md5 3256 EXIST:OPENSSL_FIPS:FUNCTION:
2815DES_ede3_cfb_encrypt 3257 EXIST::FUNCTION:DES 2815DES_ede3_cfb_encrypt 3257 EXIST::FUNCTION:DES
2816EVP_des_ede3_cfb8 3258 EXIST::FUNCTION:DES 2816EVP_des_ede3_cfb8 3258 EXIST::FUNCTION:DES
2817FIPS_rand_seeded 3259 EXIST:OPENSSL_FIPS:FUNCTION: 2817FIPS_rand_seeded 3259 EXIST:OPENSSL_FIPS:FUNCTION:
@@ -2837,7 +2837,7 @@ FIPS_dsa_check 3278 EXIST:OPENSSL_FIPS:FUNCTION:
2837AES_cfb1_encrypt 3279 EXIST::FUNCTION:AES 2837AES_cfb1_encrypt 3279 EXIST::FUNCTION:AES
2838EVP_des_ede3_cfb1 3280 EXIST::FUNCTION:DES 2838EVP_des_ede3_cfb1 3280 EXIST::FUNCTION:DES
2839FIPS_rand_check 3281 EXIST:OPENSSL_FIPS:FUNCTION: 2839FIPS_rand_check 3281 EXIST:OPENSSL_FIPS:FUNCTION:
2840FIPS_md5_allowed 3282 NOEXIST::FUNCTION: 2840FIPS_md5_allowed 3282 EXIST:OPENSSL_FIPS:FUNCTION:
2841FIPS_mode 3283 EXIST:OPENSSL_FIPS:FUNCTION: 2841FIPS_mode 3283 EXIST:OPENSSL_FIPS:FUNCTION:
2842FIPS_selftest_failed 3284 EXIST:OPENSSL_FIPS:FUNCTION: 2842FIPS_selftest_failed 3284 EXIST:OPENSSL_FIPS:FUNCTION:
2843sk_is_sorted 3285 EXIST::FUNCTION: 2843sk_is_sorted 3285 EXIST::FUNCTION:
@@ -2867,41 +2867,3 @@ PROXY_CERT_INFO_EXTENSION_it 3307 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIA
2867PROXY_CERT_INFO_EXTENSION_it 3307 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION: 2867PROXY_CERT_INFO_EXTENSION_it 3307 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2868PROXY_POLICY_free 3308 EXIST::FUNCTION: 2868PROXY_POLICY_free 3308 EXIST::FUNCTION:
2869PROXY_POLICY_new 3309 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
index 05a6086164..957264c6b5 100644
--- a/src/lib/libcrypto/util/mk1mf.pl
+++ b/src/lib/libcrypto/util/mk1mf.pl
@@ -10,20 +10,6 @@ $OPTIONS="";
10$ssl_version=""; 10$ssl_version="";
11$banner="\t\@echo Building OpenSSL"; 11$banner="\t\@echo Building OpenSSL";
12 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"; 13open(IN,"<Makefile") || die "unable to open Makefile!\n";
28while(<IN>) { 14while(<IN>) {
29 $ssl_version=$1 if (/^VERSION=(.*)$/); 15 $ssl_version=$1 if (/^VERSION=(.*)$/);
@@ -38,7 +24,6 @@ $infile="MINFO";
38 24
39%ops=( 25%ops=(
40 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X", 26 "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", 27 "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
43 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY", 28 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
44 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286", 29 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
@@ -58,7 +43,6 @@ $infile="MINFO";
58 ); 43 );
59 44
60$platform=""; 45$platform="";
61my $xcflags="";
62foreach (@ARGV) 46foreach (@ARGV)
63 { 47 {
64 if (!&read_options && !defined($ops{$_})) 48 if (!&read_options && !defined($ops{$_}))
@@ -120,12 +104,8 @@ $inc_def="outinc";
120$tmp_def="tmp"; 104$tmp_def="tmp";
121 105
122$mkdir="-mkdir"; 106$mkdir="-mkdir";
123$mkcanister="ld -r -o";
124
125$ex_build_targets = "";
126 107
127($ssl,$crypto)=("ssl","crypto"); 108($ssl,$crypto)=("ssl","crypto");
128$cryptocompat = "";
129$ranlib="echo ranlib"; 109$ranlib="echo ranlib";
130 110
131$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc'; 111$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
@@ -160,10 +140,6 @@ elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
160 $NT = 1 if $platform eq "VC-NT"; 140 $NT = 1 if $platform eq "VC-NT";
161 require 'VC-32.pl'; 141 require 'VC-32.pl';
162 } 142 }
163elsif ($platform eq "VC-WIN32-GMAKE")
164 {
165 require 'VC-32-GMAKE.pl';
166 }
167elsif ($platform eq "VC-CE") 143elsif ($platform eq "VC-CE")
168 { 144 {
169 require 'VC-CE.pl'; 145 require 'VC-CE.pl';
@@ -234,8 +210,6 @@ $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
234 210
235$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq '')); 211$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
236 212
237$cflags= "$xcflags$cflags" if $xcflags ne "";
238
239$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea; 213$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
240$cflags.=" -DOPENSSL_NO_AES" if $no_aes; 214$cflags.=" -DOPENSSL_NO_AES" if $no_aes;
241$cflags.=" -DOPENSSL_NO_RC2" if $no_rc2; 215$cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
@@ -265,9 +239,6 @@ $cflags.=" -DOPENSSL_NO_HW" if $no_hw;
265$cflags.=" -DOPENSSL_FIPS" if $fips; 239$cflags.=" -DOPENSSL_FIPS" if $fips;
266#$cflags.=" -DRSAref" if $rsaref ne ""; 240#$cflags.=" -DRSAref" if $rsaref ne "";
267 241
268$cflags.= " -DZLIB" if $zlib_opt;
269$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
270
271## if ($unix) 242## if ($unix)
272## { $cflags="$c_flags" if ($c_flags ne ""); } 243## { $cflags="$c_flags" if ($c_flags ne ""); }
273##else 244##else
@@ -275,7 +246,6 @@ $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
275 246
276$ex_libs="$l_flags$ex_libs" if ($l_flags ne ""); 247$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
277 248
278
279%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL", 249%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
280 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO"); 250 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
281 251
@@ -292,135 +262,6 @@ $link="$bin_dir$link" if ($link !~ /^\$/);
292 262
293$INSTALLTOP =~ s|/|$o|g; 263$INSTALLTOP =~ s|/|$o|g;
294 264
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"; 265$defs= <<"EOF";
425# This makefile has been automatically generated from the OpenSSL distribution. 266# This makefile has been automatically generated from the OpenSSL distribution.
426# This single makefile will build the complete OpenSSL distribution and 267# This single makefile will build the complete OpenSSL distribution and
@@ -445,7 +286,6 @@ if ($platform eq "VC-CE")
445!INCLUDE <\$(WCECOMPAT)/wcedefs.mak> 286!INCLUDE <\$(WCECOMPAT)/wcedefs.mak>
446 287
447EOF 288EOF
448 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
449 } 289 }
450 290
451$defs.= <<"EOF"; 291$defs.= <<"EOF";
@@ -468,8 +308,6 @@ EX_LIBS=$ex_libs
468SRC_D=$src_dir 308SRC_D=$src_dir
469 309
470LINK=$link 310LINK=$link
471PERL=perl
472FIPSLINK=\$(PERL) util${o}fipslink.pl
473LFLAGS=$lflags 311LFLAGS=$lflags
474 312
475BN_ASM_OBJ=$bn_asm_obj 313BN_ASM_OBJ=$bn_asm_obj
@@ -501,9 +339,6 @@ TMP_D=$tmp_dir
501INC_D=$inc_dir 339INC_D=$inc_dir
502INCO_D=$inc_dir${o}openssl 340INCO_D=$inc_dir${o}openssl
503 341
504# Directory containing FIPS module
505
506
507CP=$cp 342CP=$cp
508RM=$rm 343RM=$rm
509RANLIB=$ranlib 344RANLIB=$ranlib
@@ -511,18 +346,6 @@ MKDIR=$mkdir
511MKLIB=$bin_dir$mklib 346MKLIB=$bin_dir$mklib
512MLFLAGS=$mlflags 347MLFLAGS=$mlflags
513ASM=$bin_dir$asm 348ASM=$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 349
527###################################################### 350######################################################
528# You should not need to touch anything below this point 351# You should not need to touch anything below this point
@@ -554,7 +377,7 @@ SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
554L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp 377L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
555L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp 378L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
556 379
557L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs 380L_LIBS= \$(L_SSL) \$(L_CRYPTO)
558 381
559###################################################### 382######################################################
560# Don't touch anything below this point 383# Don't touch anything below this point
@@ -564,13 +387,13 @@ INC=-I\$(INC_D) -I\$(INCL_D)
564APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG) 387APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
565LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) 388LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
566SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG) 389SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
567LIBS_DEP=\$(O_CRYPTO) \$(O_SSL) $ex_libs_dep 390LIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
568 391
569############################################# 392#############################################
570EOF 393EOF
571 394
572$rules=<<"EOF"; 395$rules=<<"EOF";
573all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers \$(FIPS_SHA1_EXE) lib exe $ex_build_targets 396all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
574 397
575banner: 398banner:
576$banner 399$banner
@@ -656,6 +479,57 @@ printf OUT " #define DATE \"%s\"\n", scalar gmtime();
656printf OUT "#endif\n"; 479printf OUT "#endif\n";
657close(OUT); 480close(OUT);
658 481
482#############################################
483# We parse in input file and 'store' info for later printing.
484open(IN,"<$infile") || die "unable to open $infile:$!\n";
485$_=<IN>;
486for (;;)
487 {
488 chop;
489
490 ($key,$val)=/^([^=]+)=(.*)/;
491 if ($key eq "RELATIVE_DIRECTORY")
492 {
493 if ($lib ne "")
494 {
495 $uc=$lib;
496 $uc =~ s/^lib(.*)\.a/$1/;
497 $uc =~ tr/a-z/A-Z/;
498 $lib_nam{$uc}=$uc;
499 $lib_obj{$uc}.=$libobj." ";
500 }
501 last if ($val eq "FINISHED");
502 $lib="";
503 $libobj="";
504 $dir=$val;
505 }
506
507 if ($key eq "TEST")
508 { $test.=&var_add($dir,$val); }
509
510 if (($key eq "PROGS") || ($key eq "E_OBJ"))
511 { $e_exe.=&var_add($dir,$val); }
512
513 if ($key eq "LIB")
514 {
515 $lib=$val;
516 $lib =~ s/^.*\/([^\/]+)$/$1/;
517 }
518
519 if ($key eq "EXHEADER")
520 { $exheader.=&var_add($dir,$val); }
521
522 if ($key eq "HEADER")
523 { $header.=&var_add($dir,$val); }
524
525 if ($key eq "LIBOBJ")
526 { $libobj=&var_add($dir,$val); }
527
528 if (!($_=<IN>))
529 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
530 }
531close(IN);
532
659# Strip of trailing ' ' 533# Strip of trailing ' '
660foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); } 534foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
661$test=&clean_up_ws($test); 535$test=&clean_up_ws($test);
@@ -680,29 +554,6 @@ $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
680$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj); 554$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
681$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)'); 555$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
682 556
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) 557foreach (values %lib_nam)
707 { 558 {
708 $lib_obj=$lib_obj{$_}; 559 $lib_obj=$lib_obj{$_};
@@ -779,42 +630,16 @@ foreach (split(/\s+/,$test))
779 } 630 }
780 631
781$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)"); 632$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
782 633$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
783 634
784if ($fips) 635if ($fips)
785 { 636 {
786 if ($shlib) 637 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)","\$(BIN_D)$o.sha1","\$(BIN_D)$o\$(E_EXE)$exep");
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 } 638 }
801 else 639else
802 {
803 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
804 "\$(SO_CRYPTO)");
805 }
806
807
808if ($fips)
809 { 640 {
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; 641 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
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 } 642 }
815
816 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)",0);
817
818print $defs; 643print $defs;
819 644
820if ($platform eq "linux-elf") { 645if ($platform eq "linux-elf") {
@@ -1110,24 +935,6 @@ sub read_options
1110 elsif (/^shlib$/) { $shlib=1; } 935 elsif (/^shlib$/) { $shlib=1; }
1111 elsif (/^dll$/) { $shlib=1; } 936 elsif (/^dll$/) { $shlib=1; }
1112 elsif (/^shared$/) { } # We just need to ignore it for now... 937 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; } 938 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1132 elsif (/^-[lL].*$/) { $l_flags.="$_ "; } 939 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1133 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/) 940 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
@@ -1135,31 +942,3 @@ sub read_options
1135 else { return(0); } 942 else { return(0); }
1136 return(1); 943 return(1);
1137 } 944 }
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/mkdef.pl b/src/lib/libcrypto/util/mkdef.pl
index 6c1e53bb14..9918c3d549 100644
--- a/src/lib/libcrypto/util/mkdef.pl
+++ b/src/lib/libcrypto/util/mkdef.pl
@@ -83,7 +83,7 @@ my @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT",
83my @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" ); 83my @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" );
84my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF", 84my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
85 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1", 85 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
86 "SHA256", "SHA512", "RIPEMD", 86 "RIPEMD",
87 "MDC2", "RSA", "DSA", "DH", "EC", "HMAC", "AES", 87 "MDC2", "RSA", "DSA", "DH", "EC", "HMAC", "AES",
88 # Envelope "algorithms" 88 # Envelope "algorithms"
89 "EVP", "X509", "ASN1_TYPEDEFS", 89 "EVP", "X509", "ASN1_TYPEDEFS",
@@ -267,7 +267,7 @@ $crypto.=" crypto/ocsp/ocsp.h";
267$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 267$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h";
268$crypto.=" crypto/krb5/krb5_asn.h"; 268$crypto.=" crypto/krb5/krb5_asn.h";
269$crypto.=" crypto/tmdiff.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"; 270$crypto.=" fips/fips.h fips/rand/fips_rand.h";
271 271
272my $symhacks="crypto/symhacks.h"; 272my $symhacks="crypto/symhacks.h";
273 273
@@ -864,9 +864,6 @@ sub do_defs
864 $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 864 $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
865 $a .= ",RSA" if($s =~ /RSAPrivateKey/); 865 $a .= ",RSA" if($s =~ /RSAPrivateKey/);
866 $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 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 867
871 $platform{$s} = 868 $platform{$s} =
872 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 869 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
@@ -1014,7 +1011,7 @@ sub is_valid
1014{ 1011{
1015 my ($keywords_txt,$platforms) = @_; 1012 my ($keywords_txt,$platforms) = @_;
1016 my (@keywords) = split /,/,$keywords_txt; 1013 my (@keywords) = split /,/,$keywords_txt;
1017 my ($falsesum, $truesum) = (0, 1); 1014 my ($falsesum, $truesum) = (0, !grep(/^[^!]/,@keywords));
1018 1015
1019 # Param: one keyword 1016 # Param: one keyword
1020 sub recognise 1017 sub recognise
@@ -1082,7 +1079,7 @@ sub is_valid
1082 if ($k =~ /^!(.*)$/) { 1079 if ($k =~ /^!(.*)$/) {
1083 $falsesum += &recognise($1,$platforms); 1080 $falsesum += &recognise($1,$platforms);
1084 } else { 1081 } else {
1085 $truesum *= &recognise($k,$platforms); 1082 $truesum += &recognise($k,$platforms);
1086 } 1083 }
1087 } 1084 }
1088 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1085 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
new file mode 100644
index 0000000000..60e534807e
--- /dev/null
+++ b/src/lib/libcrypto/util/mkerr.pl
@@ -0,0 +1,630 @@
1#!/usr/local/bin/perl -w
2
3my $config = "crypto/err/openssl.ec";
4my $debug = 0;
5my $rebuild = 0;
6my $static = 1;
7my $recurse = 0;
8my $reindex = 0;
9my $dowrite = 0;
10my $staticloader = "";
11
12while (@ARGV) {
13 my $arg = $ARGV[0];
14 if($arg eq "-conf") {
15 shift @ARGV;
16 $config = shift @ARGV;
17 } elsif($arg eq "-debug") {
18 $debug = 1;
19 shift @ARGV;
20 } elsif($arg eq "-rebuild") {
21 $rebuild = 1;
22 shift @ARGV;
23 } elsif($arg eq "-recurse") {
24 $recurse = 1;
25 shift @ARGV;
26 } elsif($arg eq "-reindex") {
27 $reindex = 1;
28 shift @ARGV;
29 } elsif($arg eq "-nostatic") {
30 $static = 0;
31 shift @ARGV;
32 } elsif($arg eq "-staticloader") {
33 $staticloader = "static ";
34 shift @ARGV;
35 } elsif($arg eq "-write") {
36 $dowrite = 1;
37 shift @ARGV;
38 } else {
39 last;
40 }
41}
42
43if($recurse) {
44 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <fips/*.c>,
45 <fips/*/*.c>);
46} else {
47 @source = @ARGV;
48}
49
50# Read in the config file
51
52open(IN, "<$config") || die "Can't open config file $config";
53
54# Parse config file
55
56while(<IN>)
57{
58 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
59 $hinc{$1} = $2;
60 $libinc{$2} = $1;
61 $cskip{$3} = $1;
62 if($3 ne "NONE") {
63 $csrc{$1} = $3;
64 $fmax{$1} = 99;
65 $rmax{$1} = 99;
66 $fnew{$1} = 0;
67 $rnew{$1} = 0;
68 }
69 } elsif (/^F\s+(\S+)/) {
70 # Add extra function with $1
71 } elsif (/^R\s+(\S+)\s+(\S+)/) {
72 $rextra{$1} = $2;
73 $rcodes{$1} = $2;
74 }
75}
76
77close IN;
78
79# Scan each header file in turn and make a list of error codes
80# and function names
81
82while (($hdr, $lib) = each %libinc)
83{
84 next if($hdr eq "NONE");
85 print STDERR "Scanning header file $hdr\n" if $debug;
86 my $line = "", $def= "", $linenr = 0, $gotfile = 0;
87 if (open(IN, "<$hdr")) {
88 $gotfile = 1;
89 while(<IN>) {
90 $linenr++;
91 print STDERR "line: $linenr\r" if $debug;
92
93 last if(/BEGIN\s+ERROR\s+CODES/);
94 if ($line ne '') {
95 $_ = $line . $_;
96 $line = '';
97 }
98
99 if (/\\$/) {
100 $line = $_;
101 next;
102 }
103
104 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
105 if ($cpp) {
106 $cpp = 0 if /^#.*endif/;
107 next;
108 }
109
110 next if (/^\#/); # skip preprocessor directives
111
112 s/\/\*.*?\*\///gs; # ignore comments
113 s/{[^{}]*}//gs; # ignore {} blocks
114
115 if (/\{|\/\*/) { # Add a } so editor works...
116 $line = $_;
117 } else {
118 $def .= $_;
119 }
120 }
121 }
122
123 print STDERR " \r" if $debug;
124 $defnr = 0;
125 foreach (split /;/, $def) {
126 $defnr++;
127 print STDERR "def: $defnr\r" if $debug;
128
129 s/^[\n\s]*//g;
130 s/[\n\s]*$//g;
131 next if(/typedef\W/);
132 if (/\(\*(\w*)\([^\)]+/) {
133 my $name = $1;
134 $name =~ tr/[a-z]/[A-Z]/;
135 $ftrans{$name} = $1;
136 } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){
137 # K&R C
138 next ;
139 } elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) {
140 while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) {
141 s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
142 s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
143 }
144 s/\(void\)//;
145 /(\w+(\{[0-9]+\})?)\W*\(\)/s;
146 my $name = $1;
147 $name =~ tr/[a-z]/[A-Z]/;
148 $ftrans{$name} = $1;
149 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
150 print STDERR "Header $hdr: cannot parse: $_;\n";
151 }
152 }
153
154 print STDERR " \r" if $debug;
155
156 next if $reindex;
157
158 # Scan function and reason codes and store them: keep a note of the
159 # maximum code used.
160
161 if ($gotfile) {
162 while(<IN>) {
163 if(/^\#define\s+(\S+)\s+(\S+)/) {
164 $name = $1;
165 $code = $2;
166 next if $name =~ /^${lib}err/;
167 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
168 print STDERR "Invalid error code $name\n";
169 next;
170 }
171 if($1 eq "R") {
172 $rcodes{$name} = $code;
173 if(!(exists $rextra{$name}) &&
174 ($code > $rmax{$lib}) ) {
175 $rmax{$lib} = $code;
176 }
177 } else {
178 if($code > $fmax{$lib}) {
179 $fmax{$lib} = $code;
180 }
181 $fcodes{$name} = $code;
182 }
183 }
184 }
185 }
186 close IN;
187}
188
189# Scan each C source file and look for function and reason codes
190# This is done by looking for strings that "look like" function or
191# reason codes: basically anything consisting of all upper case and
192# numerics which has _F_ or _R_ in it and which has the name of an
193# error library at the start. This seems to work fine except for the
194# oddly named structure BIO_F_CTX which needs to be ignored.
195# If a code doesn't exist in list compiled from headers then mark it
196# with the value "X" as a place holder to give it a value later.
197# Store all function and reason codes found in %ufcodes and %urcodes
198# so all those unreferenced can be printed out.
199
200
201print STDERR "Files loaded: " if $debug;
202foreach $file (@source) {
203 # Don't parse the error source file.
204 next if exists $cskip{$file};
205 print STDERR $file if $debug;
206 open(IN, "<$file") || die "Can't open source file $file\n";
207 while(<IN>) {
208 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
209 next unless exists $csrc{$2};
210 next if($1 eq "BIO_F_BUFFER_CTX");
211 $ufcodes{$1} = 1;
212 if(!exists $fcodes{$1}) {
213 $fcodes{$1} = "X";
214 $fnew{$2}++;
215 }
216 $notrans{$1} = 1 unless exists $ftrans{$3};
217 }
218 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
219 next unless exists $csrc{$2};
220 $urcodes{$1} = 1;
221 if(!exists $rcodes{$1}) {
222 $rcodes{$1} = "X";
223 $rnew{$2}++;
224 }
225 }
226 }
227 close IN;
228}
229print STDERR "\n" if $debug;
230
231# Now process each library in turn.
232
233foreach $lib (keys %csrc)
234{
235 my $hfile = $hinc{$lib};
236 my $cfile = $csrc{$lib};
237 if(!$fnew{$lib} && !$rnew{$lib}) {
238 print STDERR "$lib:\t\tNo new error codes\n";
239 next unless $rebuild;
240 } else {
241 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
242 print STDERR " $rnew{$lib} New Reasons.\n";
243 next unless $dowrite;
244 }
245
246 # If we get here then we have some new error codes so we
247 # need to rebuild the header file and C file.
248
249 # Make a sorted list of error and reason codes for later use.
250
251 my @function = sort grep(/^${lib}_/,keys %fcodes);
252 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
253
254 # Rewrite the header file
255
256 if (open(IN, "<$hfile")) {
257 # Copy across the old file
258 while(<IN>) {
259 push @out, $_;
260 last if (/BEGIN ERROR CODES/);
261 }
262 close IN;
263 } else {
264 push @out,
265"/* ====================================================================\n",
266" * Copyright (c) 2001-2005 The OpenSSL Project. All rights reserved.\n",
267" *\n",
268" * Redistribution and use in source and binary forms, with or without\n",
269" * modification, are permitted provided that the following conditions\n",
270" * are met:\n",
271" *\n",
272" * 1. Redistributions of source code must retain the above copyright\n",
273" * notice, this list of conditions and the following disclaimer. \n",
274" *\n",
275" * 2. Redistributions in binary form must reproduce the above copyright\n",
276" * notice, this list of conditions and the following disclaimer in\n",
277" * the documentation and/or other materials provided with the\n",
278" * distribution.\n",
279" *\n",
280" * 3. All advertising materials mentioning features or use of this\n",
281" * software must display the following acknowledgment:\n",
282" * \"This product includes software developed by the OpenSSL Project\n",
283" * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
284" *\n",
285" * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
286" * endorse or promote products derived from this software without\n",
287" * prior written permission. For written permission, please contact\n",
288" * openssl-core\@openssl.org.\n",
289" *\n",
290" * 5. Products derived from this software may not be called \"OpenSSL\"\n",
291" * nor may \"OpenSSL\" appear in their names without prior written\n",
292" * permission of the OpenSSL Project.\n",
293" *\n",
294" * 6. Redistributions of any form whatsoever must retain the following\n",
295" * acknowledgment:\n",
296" * \"This product includes software developed by the OpenSSL Project\n",
297" * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
298" *\n",
299" * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
300" * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
301" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
302" * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
303" * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
304" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
305" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
306" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
307" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
308" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
309" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
310" * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
311" * ====================================================================\n",
312" *\n",
313" * This product includes cryptographic software written by Eric Young\n",
314" * (eay\@cryptsoft.com). This product includes software written by Tim\n",
315" * Hudson (tjh\@cryptsoft.com).\n",
316" *\n",
317" */\n",
318"\n",
319"#ifndef HEADER_${lib}_ERR_H\n",
320"#define HEADER_${lib}_ERR_H\n",
321"\n",
322"/* BEGIN ERROR CODES */\n";
323 }
324 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
325
326 print OUT @out;
327 undef @out;
328 print OUT <<"EOF";
329/* The following lines are auto generated by the script mkerr.pl. Any changes
330 * made after this point may be overwritten when the script is next run.
331 */
332EOF
333 if($static) {
334 print OUT <<"EOF";
335${staticloader}void ERR_load_${lib}_strings(void);
336
337EOF
338 } else {
339 print OUT <<"EOF";
340${staticloader}void ERR_load_${lib}_strings(void);
341${staticloader}void ERR_unload_${lib}_strings(void);
342${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
343#define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
344
345EOF
346 }
347 print OUT <<"EOF";
348/* Error codes for the $lib functions. */
349
350/* Function codes. */
351EOF
352
353 foreach $i (@function) {
354 $z=6-int(length($i)/8);
355 if($fcodes{$i} eq "X") {
356 $fcodes{$i} = ++$fmax{$lib};
357 print STDERR "New Function code $i\n" if $debug;
358 }
359 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
360 }
361
362 print OUT "\n/* Reason codes. */\n";
363
364 foreach $i (@reasons) {
365 $z=6-int(length($i)/8);
366 if($rcodes{$i} eq "X") {
367 $rcodes{$i} = ++$rmax{$lib};
368 print STDERR "New Reason code $i\n" if $debug;
369 }
370 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
371 }
372 print OUT <<"EOF";
373
374#ifdef __cplusplus
375}
376#endif
377#endif
378EOF
379 close OUT;
380
381 # Rewrite the C source file containing the error details.
382
383 # First, read any existing reason string definitions:
384 my %err_reason_strings;
385 if (open(IN,"<$cfile")) {
386 while (<IN>) {
387 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
388 $err_reason_strings{$1} = $2;
389 }
390 }
391 close(IN);
392 }
393
394 my $hincf;
395 if($static) {
396 $hfile =~ /([^\/]+)$/;
397 $hincf = "<openssl/$1>";
398 } else {
399 $hincf = "\"$hfile\"";
400 }
401
402
403 open (OUT,">$cfile") || die "Can't open $cfile for writing";
404
405 print OUT <<"EOF";
406/* $cfile */
407/* ====================================================================
408 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
409 *
410 * Redistribution and use in source and binary forms, with or without
411 * modification, are permitted provided that the following conditions
412 * are met:
413 *
414 * 1. Redistributions of source code must retain the above copyright
415 * notice, this list of conditions and the following disclaimer.
416 *
417 * 2. Redistributions in binary form must reproduce the above copyright
418 * notice, this list of conditions and the following disclaimer in
419 * the documentation and/or other materials provided with the
420 * distribution.
421 *
422 * 3. All advertising materials mentioning features or use of this
423 * software must display the following acknowledgment:
424 * "This product includes software developed by the OpenSSL Project
425 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
426 *
427 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
428 * endorse or promote products derived from this software without
429 * prior written permission. For written permission, please contact
430 * openssl-core\@OpenSSL.org.
431 *
432 * 5. Products derived from this software may not be called "OpenSSL"
433 * nor may "OpenSSL" appear in their names without prior written
434 * permission of the OpenSSL Project.
435 *
436 * 6. Redistributions of any form whatsoever must retain the following
437 * acknowledgment:
438 * "This product includes software developed by the OpenSSL Project
439 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
440 *
441 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
442 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
443 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
444 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
445 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
446 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
447 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
448 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
449 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
450 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
451 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
452 * OF THE POSSIBILITY OF SUCH DAMAGE.
453 * ====================================================================
454 *
455 * This product includes cryptographic software written by Eric Young
456 * (eay\@cryptsoft.com). This product includes software written by Tim
457 * Hudson (tjh\@cryptsoft.com).
458 *
459 */
460
461/* NOTE: this file was auto generated by the mkerr.pl script: any changes
462 * made to it will be overwritten when the script next updates this file,
463 * only reason strings will be preserved.
464 */
465
466#include <stdio.h>
467#include <openssl/err.h>
468#include $hincf
469
470/* BEGIN ERROR CODES */
471#ifndef OPENSSL_NO_ERR
472static ERR_STRING_DATA ${lib}_str_functs[]=
473 {
474EOF
475 # Add each function code: if a function name is found then use it.
476 foreach $i (@function) {
477 my $fn;
478 $i =~ /^${lib}_F_(\S+)$/;
479 $fn = $1;
480 if(exists $ftrans{$fn}) {
481 $fn = $ftrans{$fn};
482 }
483 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
484 }
485 print OUT <<"EOF";
486{0,NULL}
487 };
488
489static ERR_STRING_DATA ${lib}_str_reasons[]=
490 {
491EOF
492 # Add each reason code.
493 foreach $i (@reasons) {
494 my $rn;
495 my $nspc = 0;
496 if (exists $err_reason_strings{$i}) {
497 $rn = $err_reason_strings{$i};
498 } else {
499 $i =~ /^${lib}_R_(\S+)$/;
500 $rn = $1;
501 $rn =~ tr/_[A-Z]/ [a-z]/;
502 }
503 $nspc = 40 - length($i) unless length($i) > 40;
504 $nspc = " " x $nspc;
505 print OUT "{${i}${nspc},\"$rn\"},\n";
506 }
507if($static) {
508 print OUT <<"EOF";
509{0,NULL}
510 };
511
512#endif
513
514${staticloader}void ERR_load_${lib}_strings(void)
515 {
516 static int init=1;
517
518 if (init)
519 {
520 init=0;
521#ifndef OPENSSL_NO_ERR
522 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
523 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
524#endif
525
526 }
527 }
528EOF
529} else {
530 print OUT <<"EOF";
531{0,NULL}
532 };
533
534#endif
535
536#ifdef ${lib}_LIB_NAME
537static ERR_STRING_DATA ${lib}_lib_name[]=
538 {
539{0 ,${lib}_LIB_NAME},
540{0,NULL}
541 };
542#endif
543
544
545static int ${lib}_lib_error_code=0;
546static int ${lib}_error_init=1;
547
548${staticloader}void ERR_load_${lib}_strings(void)
549 {
550 if (${lib}_lib_error_code == 0)
551 ${lib}_lib_error_code=ERR_get_next_error_library();
552
553 if (${lib}_error_init)
554 {
555 ${lib}_error_init=0;
556#ifndef OPENSSL_NO_ERR
557 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
558 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
559#endif
560
561#ifdef ${lib}_LIB_NAME
562 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
563 ERR_load_strings(0,${lib}_lib_name);
564#endif
565 }
566 }
567
568${staticloader}void ERR_unload_${lib}_strings(void)
569 {
570 if (${lib}_error_init == 0)
571 {
572#ifndef OPENSSL_NO_ERR
573 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
574 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
575#endif
576
577#ifdef ${lib}_LIB_NAME
578 ERR_unload_strings(0,${lib}_lib_name);
579#endif
580 ${lib}_error_init=1;
581 }
582 }
583
584${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
585 {
586 if (${lib}_lib_error_code == 0)
587 ${lib}_lib_error_code=ERR_get_next_error_library();
588 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
589 }
590EOF
591
592}
593
594 close OUT;
595 undef %err_reason_strings;
596}
597
598if($debug && defined(%notrans)) {
599 print STDERR "The following function codes were not translated:\n";
600 foreach(sort keys %notrans)
601 {
602 print STDERR "$_\n";
603 }
604}
605
606# Make a list of unreferenced function and reason codes
607
608foreach (keys %fcodes) {
609 push (@funref, $_) unless exists $ufcodes{$_};
610}
611
612foreach (keys %rcodes) {
613 push (@runref, $_) unless exists $urcodes{$_};
614}
615
616if($debug && defined(@funref) ) {
617 print STDERR "The following function codes were not referenced:\n";
618 foreach(sort @funref)
619 {
620 print STDERR "$_\n";
621 }
622}
623
624if($debug && defined(@runref) ) {
625 print STDERR "The following reason codes were not referenced:\n";
626 foreach(sort @runref)
627 {
628 print STDERR "$_\n";
629 }
630}
diff --git a/src/lib/libcrypto/util/mkfiles.pl b/src/lib/libcrypto/util/mkfiles.pl
index bc78510f56..928a274303 100644
--- a/src/lib/libcrypto/util/mkfiles.pl
+++ b/src/lib/libcrypto/util/mkfiles.pl
@@ -51,15 +51,14 @@ my @dirs = (
51"crypto/ocsp", 51"crypto/ocsp",
52"crypto/ui", 52"crypto/ui",
53"crypto/krb5", 53"crypto/krb5",
54"fips-1.0", 54"fips",
55"fips-1.0/aes", 55"fips/aes",
56"fips-1.0/des", 56"fips/des",
57"fips-1.0/dsa", 57"fips/dsa",
58"fips-1.0/dh", 58"fips/dh",
59"fips-1.0/hmac", 59"fips/rand",
60"fips-1.0/rand", 60"fips/rsa",
61"fips-1.0/rsa", 61"fips/sha1",
62"fips-1.0/sha",
63"ssl", 62"ssl",
64"apps", 63"apps",
65"test", 64"test",
diff --git a/src/lib/libcrypto/util/mklink.pl b/src/lib/libcrypto/util/mklink.pl
index 182732d959..c8653cecc3 100644
--- a/src/lib/libcrypto/util/mklink.pl
+++ b/src/lib/libcrypto/util/mklink.pl
@@ -14,16 +14,13 @@
14# not contain symbolic links and that the parent of / is never referenced. 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 15# Apart from this, this script should be able to handle even the most
16# pathological cases. 16# pathological cases.
17#
18
19use Cwd;
20 17
21my $from = shift; 18my $from = shift;
22my @files = @ARGV; 19my @files = @ARGV;
23 20
24my @from_path = split(/[\\\/]/, $from); 21my @from_path = split(/[\\\/]/, $from);
25my $pwd = getcwd(); 22my $pwd = `pwd`;
26chomp($pwd); 23chop($pwd);
27my @pwd_path = split(/[\\\/]/, $pwd); 24my @pwd_path = split(/[\\\/]/, $pwd);
28 25
29my @to_path = (); 26my @to_path = ();
diff --git a/src/lib/libcrypto/util/mkstack.pl b/src/lib/libcrypto/util/mkstack.pl
new file mode 100644
index 0000000000..0ca9eb6a76
--- /dev/null
+++ b/src/lib/libcrypto/util/mkstack.pl
@@ -0,0 +1,125 @@
1#!/usr/local/bin/perl -w
2
3# This is a utility that searches out "DECLARE_STACK_OF()"
4# declarations in .h and .c files, and updates/creates/replaces
5# the corresponding macro declarations in crypto/stack/safestack.h.
6# As it's not generally possible to have macros that generate macros,
7# we need to control this from the "outside", here in this script.
8#
9# Geoff Thorpe, June, 2000 (with massive Perl-hacking
10# help from Steve Robb)
11
12my $safestack = "crypto/stack/safestack";
13
14my $do_write;
15while (@ARGV) {
16 my $arg = $ARGV[0];
17 if($arg eq "-write") {
18 $do_write = 1;
19 }
20 shift @ARGV;
21}
22
23
24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>);
25foreach $file (@source) {
26 next if -l $file;
27
28 # Open the .c/.h file for reading
29 open(IN, "< $file") || die "Can't open $file for reading: $!";
30
31 while(<IN>) {
32 if (/^DECLARE_STACK_OF\(([^)]+)\)/) {
33 push @stacklst, $1;
34 } if (/^DECLARE_ASN1_SET_OF\(([^)]+)\)/) {
35 push @asn1setlst, $1;
36 } if (/^DECLARE_PKCS12_STACK_OF\(([^)]+)\)/) {
37 push @p12stklst, $1;
38 }
39 }
40 close(IN);
41}
42
43
44
45my $old_stackfile = "";
46my $new_stackfile = "";
47my $inside_block = 0;
48my $type_thing;
49
50open(IN, "< $safestack.h") || die "Can't open input file: $!";
51while(<IN>) {
52 $old_stackfile .= $_;
53
54 if (m|^/\* This block of defines is updated by util/mkstack.pl, please do not touch! \*/|) {
55 $inside_block = 1;
56 }
57 if (m|^/\* End of util/mkstack.pl block, you may now edit :-\) \*/|) {
58 $inside_block = 0;
59 } elsif ($inside_block == 0) {
60 $new_stackfile .= $_;
61 }
62 next if($inside_block != 1);
63 $new_stackfile .= "/* This block of defines is updated by util/mkstack.pl, please do not touch! */";
64
65 foreach $type_thing (sort @stacklst) {
66 $new_stackfile .= <<EOF;
67
68#define sk_${type_thing}_new(st) SKM_sk_new($type_thing, (st))
69#define sk_${type_thing}_new_null() SKM_sk_new_null($type_thing)
70#define sk_${type_thing}_free(st) SKM_sk_free($type_thing, (st))
71#define sk_${type_thing}_num(st) SKM_sk_num($type_thing, (st))
72#define sk_${type_thing}_value(st, i) SKM_sk_value($type_thing, (st), (i))
73#define sk_${type_thing}_set(st, i, val) SKM_sk_set($type_thing, (st), (i), (val))
74#define sk_${type_thing}_zero(st) SKM_sk_zero($type_thing, (st))
75#define sk_${type_thing}_push(st, val) SKM_sk_push($type_thing, (st), (val))
76#define sk_${type_thing}_unshift(st, val) SKM_sk_unshift($type_thing, (st), (val))
77#define sk_${type_thing}_find(st, val) SKM_sk_find($type_thing, (st), (val))
78#define sk_${type_thing}_delete(st, i) SKM_sk_delete($type_thing, (st), (i))
79#define sk_${type_thing}_delete_ptr(st, ptr) SKM_sk_delete_ptr($type_thing, (st), (ptr))
80#define sk_${type_thing}_insert(st, val, i) SKM_sk_insert($type_thing, (st), (val), (i))
81#define sk_${type_thing}_set_cmp_func(st, cmp) SKM_sk_set_cmp_func($type_thing, (st), (cmp))
82#define sk_${type_thing}_dup(st) SKM_sk_dup($type_thing, st)
83#define sk_${type_thing}_pop_free(st, free_func) SKM_sk_pop_free($type_thing, (st), (free_func))
84#define sk_${type_thing}_shift(st) SKM_sk_shift($type_thing, (st))
85#define sk_${type_thing}_pop(st) SKM_sk_pop($type_thing, (st))
86#define sk_${type_thing}_sort(st) SKM_sk_sort($type_thing, (st))
87#define sk_${type_thing}_is_sorted(st) SKM_sk_is_sorted($type_thing, (st))
88EOF
89 }
90 foreach $type_thing (sort @asn1setlst) {
91 $new_stackfile .= <<EOF;
92
93#define d2i_ASN1_SET_OF_${type_thing}(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\
94 SKM_ASN1_SET_OF_d2i($type_thing, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
95#define i2d_ASN1_SET_OF_${type_thing}(st, pp, i2d_func, ex_tag, ex_class, is_set) \\
96 SKM_ASN1_SET_OF_i2d($type_thing, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
97#define ASN1_seq_pack_${type_thing}(st, i2d_func, buf, len) \\
98 SKM_ASN1_seq_pack($type_thing, (st), (i2d_func), (buf), (len))
99#define ASN1_seq_unpack_${type_thing}(buf, len, d2i_func, free_func) \\
100 SKM_ASN1_seq_unpack($type_thing, (buf), (len), (d2i_func), (free_func))
101EOF
102 }
103 foreach $type_thing (sort @p12stklst) {
104 $new_stackfile .= <<EOF;
105
106#define PKCS12_decrypt_d2i_${type_thing}(algor, d2i_func, free_func, pass, passlen, oct, seq) \\
107 SKM_PKCS12_decrypt_d2i($type_thing, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
108EOF
109 }
110 $new_stackfile .= "/* End of util/mkstack.pl block, you may now edit :-) */\n";
111 $inside_block = 2;
112}
113
114
115if ($new_stackfile eq $old_stackfile) {
116 print "No changes to $safestack.h.\n";
117 exit 0; # avoid unnecessary rebuild
118}
119
120if ($do_write) {
121 print "Writing new $safestack.h.\n";
122 open OUT, ">$safestack.h" || die "Can't open output file";
123 print OUT $new_stackfile;
124 close OUT;
125}
diff --git a/src/lib/libcrypto/util/pl/BC-32.pl b/src/lib/libcrypto/util/pl/BC-32.pl
index 28869c868d..897ae9d824 100644
--- a/src/lib/libcrypto/util/pl/BC-32.pl
+++ b/src/lib/libcrypto/util/pl/BC-32.pl
@@ -18,7 +18,7 @@ $out_def="out32";
18$tmp_def="tmp32"; 18$tmp_def="tmp32";
19$inc_def="inc32"; 19$inc_def="inc32";
20#enable max error messages, disable most common warnings 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 "; 21$cflags="-DWIN32_LEAN_AND_MEAN -q -w-aus -w-par -w-inl -c -tWC -tWM -DOPENSSL_SYSNAME_WIN32 -DL_ENDIAN -DDSO_WIN32 -D_stricmp=stricmp ";
22if ($debug) 22if ($debug)
23{ 23{
24 $cflags.="-Od -y -v -vi- -D_DEBUG"; 24 $cflags.="-Od -y -v -vi- -D_DEBUG";
@@ -51,7 +51,7 @@ $lfile='';
51$shlib_ex_obj=""; 51$shlib_ex_obj="";
52$app_ex_obj="c0x32.obj"; 52$app_ex_obj="c0x32.obj";
53 53
54$asm='nasmw -f obj -d__omf__'; 54$asm='nasmw -f obj';
55$asm.=" /Zi" if $debug; 55$asm.=" /Zi" if $debug;
56$afile='-o'; 56$afile='-o';
57 57
@@ -106,13 +106,9 @@ sub do_lib_rule
106 $ret.="$target: $objs\n"; 106 $ret.="$target: $objs\n";
107 if (!$shlib) 107 if (!$shlib)
108 { 108 {
109 $ret.=<<___; 109 # $ret.="\t\$(RM) \$(O_$Name)\n";
110 -\$(RM) $lfile$target 110 $ret.="\techo LIB $<\n";
111 \$(MKLIB) $lfile$target \@&&! 111 $ret.="\t&\$(MKLIB) $lfile$target -+\$**\n";
112+\$(**: = &^
113+)
114!
115___
116 } 112 }
117 else 113 else
118 { 114 {
diff --git a/src/lib/libcrypto/util/pl/OS2-EMX.pl b/src/lib/libcrypto/util/pl/OS2-EMX.pl
index 8dbeaa7a08..75d72ebbcb 100644
--- a/src/lib/libcrypto/util/pl/OS2-EMX.pl
+++ b/src/lib/libcrypto/util/pl/OS2-EMX.pl
@@ -68,7 +68,6 @@ if (!$no_asm && !$fips)
68 $sha1_asm_src="crypto/sha/asm/s1-os2.asm"; 68 $sha1_asm_src="crypto/sha/asm/s1-os2.asm";
69 $rmd160_asm_obj="crypto/ripemd/asm/rm-os2$obj"; 69 $rmd160_asm_obj="crypto/ripemd/asm/rm-os2$obj";
70 $rmd160_asm_src="crypto/ripemd/asm/rm-os2.asm"; 70 $rmd160_asm_src="crypto/ripemd/asm/rm-os2.asm";
71 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS";
72 } 71 }
73 72
74if ($shlib) 73if ($shlib)
diff --git a/src/lib/libcrypto/util/pl/VC-32.pl b/src/lib/libcrypto/util/pl/VC-32.pl
index 4e97dfa9af..cf689b9feb 100644
--- a/src/lib/libcrypto/util/pl/VC-32.pl
+++ b/src/lib/libcrypto/util/pl/VC-32.pl
@@ -3,28 +3,15 @@
3# 3#
4 4
5$ssl= "ssleay32"; 5$ssl= "ssleay32";
6 6$crypto="libeay32";
7if ($fips && !$shlib)
8 {
9 $crypto="libeayfips32";
10 $crypto_compat = "libeaycompat32.lib";
11 }
12else
13 {
14 $crypto="libeay32";
15 }
16 7
17$o='\\'; 8$o='\\';
18$cp='copy nul+'; # Timestamps get stuffed otherwise 9$cp='copy nul+'; # Timestamps get stuffed otherwise
19$rm='del'; 10$rm='del';
20 11
21$zlib_lib="zlib1.lib";
22
23# C compiler stuff 12# C compiler stuff
24$cc='cl'; 13$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'; 14$cflags=' /MD /W3 /WX /G5 /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"; 15$lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
29$mlflags=''; 16$mlflags='';
30 17
@@ -113,56 +100,25 @@ $cflags.=" /Fd$out_def";
113 100
114sub do_lib_rule 101sub do_lib_rule
115 { 102 {
116 local($objs,$target,$name,$shlib,$ign,$base_addr) = @_; 103 local($objs,$target,$name,$shlib)=@_;
117 local($ret,$Name); 104 local($ret,$Name);
118 105
119 $taget =~ s/\//$o/g if $o ne '/'; 106 $taget =~ s/\//$o/g if $o ne '/';
120 ($Name=$name) =~ tr/a-z/A-Z/; 107 ($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 108
132# $target="\$(LIB_D)$o$target"; 109# $target="\$(LIB_D)$o$target";
110 $ret.="$target: $objs\n";
133 if (!$shlib) 111 if (!$shlib)
134 { 112 {
135# $ret.="\t\$(RM) \$(O_$Name)\n"; 113# $ret.="\t\$(RM) \$(O_$Name)\n";
136 $ret.="$target: $objs\n";
137 $ex =' advapi32.lib'; 114 $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"; 115 $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs $ex\n<<\n";
140 } 116 }
141 else 117 else
142 { 118 {
143 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; 119 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
144 $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib'; 120 $ex.=' wsock32.lib gdi32.lib advapi32.lib';
145 $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/; 121 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
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 } 122 }
167 $ret.="\n"; 123 $ret.="\n";
168 return($ret); 124 return($ret);
@@ -170,51 +126,20 @@ sub do_lib_rule
170 126
171sub do_link_rule 127sub do_link_rule
172 { 128 {
173 local($target,$files,$dep_libs,$libs,$standalone)=@_; 129 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
174 local($ret,$_); 130 local($ret,$_);
131
175 $file =~ s/\//$o/g if $o ne '/'; 132 $file =~ s/\//$o/g if $o ne '/';
176 $n=&bname($targer); 133 $n=&bname($targer);
177 $ret.="$target: $files $dep_libs\n"; 134 $ret.="$target: $files $dep_libs\n";
178 if ($standalone) 135 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n";
179 { 136 $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n";
180 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n\t"; 137 if (defined $sha1file)
181 $ret.="\$(FIPSLIB_D)${o}_chkstk.o " if ($files =~ /O_FIPSCANISTER/);
182 $ret.="$files $libs\n<<\n";
183 }
184 elsif ($fips && !$shlib)
185 { 138 {
186 $ret.="\tSET FIPS_LINK=\$(LINK)\n"; 139 $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
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 } 140 }
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"; 141 $ret.="\n";
216 return($ret); 142 return($ret);
217 } 143 }
218 144
219
2201; 1451;
diff --git a/src/lib/libcrypto/util/pod2man.pl b/src/lib/libcrypto/util/pod2man.pl
index 546d1ec186..657e4e264e 100644
--- a/src/lib/libcrypto/util/pod2man.pl
+++ b/src/lib/libcrypto/util/pod2man.pl
@@ -425,7 +425,6 @@ if ($name ne 'something') {
425 } 425 }
426 next if /^=cut\b/; # DB_File and Net::Ping have =cut before NAME 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 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; 428 die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
430 } 429 }
431 die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax; 430 die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
diff --git a/src/lib/libcrypto/util/selftest.pl b/src/lib/libcrypto/util/selftest.pl
index 4778c5ab01..e9d5aa8938 100644
--- a/src/lib/libcrypto/util/selftest.pl
+++ b/src/lib/libcrypto/util/selftest.pl
@@ -49,7 +49,7 @@ if (open(IN,"<Makefile")) {
49} 49}
50 50
51$cversion=`$cc -v 2>&1`; 51$cversion=`$cc -v 2>&1`;
52$cversion=`$cc -V 2>&1` if $cversion =~ "[Uu]sage"; 52$cversion=`$cc -V 2>&1` if $cversion =~ "usage";
53$cversion=`$cc -V |head -1` if $cversion =~ "Error"; 53$cversion=`$cc -V |head -1` if $cversion =~ "Error";
54$cversion=`$cc --version` if $cversion eq ""; 54$cversion=`$cc --version` if $cversion eq "";
55$cversion =~ s/Reading specs.*\n//; 55$cversion =~ s/Reading specs.*\n//;
@@ -130,21 +130,15 @@ if (system("make 2>&1 | tee make.log") > 255) {
130 goto err; 130 goto err;
131} 131}
132 132
133# Not sure why this is here. The tests themselves can detect if their 133$_=$options;
134# particular feature isn't included, and should therefore skip themselves. 134s/no-asm//;
135# To skip *all* tests just because one algorithm isn't included is like 135s/no-shared//;
136# shooting mosquito with an elephant gun... 136s/no-krb5//;
137# -- Richard Levitte, inspired by problem report 1089 137if (/no-/)
138# 138{
139#$_=$options; 139 print OUT "Test skipped.\n";
140#s/no-asm//; 140 goto err;
141#s/no-shared//; 141}
142#s/no-krb5//;
143#if (/no-/)
144#{
145# print OUT "Test skipped.\n";
146# goto err;
147#}
148 142
149print "Running make test...\n"; 143print "Running make test...\n";
150if (system("make test 2>&1 | tee maketest.log") > 255) 144if (system("make test 2>&1 | tee maketest.log") > 255)
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
new file mode 100644
index 0000000000..6207340472
--- /dev/null
+++ b/src/lib/libcrypto/x509/by_dir.c
@@ -0,0 +1,381 @@
1/* crypto/x509/by_dir.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include <errno.h>
62
63#include "cryptlib.h"
64
65#ifndef NO_SYS_TYPES_H
66# include <sys/types.h>
67#endif
68#ifdef MAC_OS_pre_X
69# include <stat.h>
70#else
71# include <sys/stat.h>
72#endif
73
74#include <openssl/lhash.h>
75#include <openssl/x509.h>
76
77typedef struct lookup_dir_st
78 {
79 BUF_MEM *buffer;
80 int num_dirs;
81 char **dirs;
82 int *dirs_type;
83 int num_dirs_alloced;
84 } BY_DIR;
85
86static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
87 char **ret);
88static int new_dir(X509_LOOKUP *lu);
89static void free_dir(X509_LOOKUP *lu);
90static int add_cert_dir(BY_DIR *ctx,const char *dir,int type);
91static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name,
92 X509_OBJECT *ret);
93X509_LOOKUP_METHOD x509_dir_lookup=
94 {
95 "Load certs from files in a directory",
96 new_dir, /* new */
97 free_dir, /* free */
98 NULL, /* init */
99 NULL, /* shutdown */
100 dir_ctrl, /* ctrl */
101 get_cert_by_subject, /* get_by_subject */
102 NULL, /* get_by_issuer_serial */
103 NULL, /* get_by_fingerprint */
104 NULL, /* get_by_alias */
105 };
106
107X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void)
108 {
109 return(&x509_dir_lookup);
110 }
111
112static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
113 char **retp)
114 {
115 int ret=0;
116 BY_DIR *ld;
117 char *dir;
118
119 ld=(BY_DIR *)ctx->method_data;
120
121 switch (cmd)
122 {
123 case X509_L_ADD_DIR:
124 if (argl == X509_FILETYPE_DEFAULT)
125 {
126 ret=add_cert_dir(ld,X509_get_default_cert_dir(),
127 X509_FILETYPE_PEM);
128 if (!ret)
129 {
130 X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR);
131 }
132 else
133 {
134 dir=(char *)Getenv(X509_get_default_cert_dir_env());
135 ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
136 }
137 }
138 else
139 ret=add_cert_dir(ld,argp,(int)argl);
140 break;
141 }
142 return(ret);
143 }
144
145static int new_dir(X509_LOOKUP *lu)
146 {
147 BY_DIR *a;
148
149 if ((a=(BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL)
150 return(0);
151 if ((a->buffer=BUF_MEM_new()) == NULL)
152 {
153 OPENSSL_free(a);
154 return(0);
155 }
156 a->num_dirs=0;
157 a->dirs=NULL;
158 a->dirs_type=NULL;
159 a->num_dirs_alloced=0;
160 lu->method_data=(char *)a;
161 return(1);
162 }
163
164static void free_dir(X509_LOOKUP *lu)
165 {
166 BY_DIR *a;
167 int i;
168
169 a=(BY_DIR *)lu->method_data;
170 for (i=0; i<a->num_dirs; i++)
171 if (a->dirs[i] != NULL) OPENSSL_free(a->dirs[i]);
172 if (a->dirs != NULL) OPENSSL_free(a->dirs);
173 if (a->dirs_type != NULL) OPENSSL_free(a->dirs_type);
174 if (a->buffer != NULL) BUF_MEM_free(a->buffer);
175 OPENSSL_free(a);
176 }
177
178static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
179 {
180 int j,len;
181 int *ip;
182 const char *s,*ss,*p;
183 char **pp;
184
185 if (dir == NULL || !*dir)
186 {
187 X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY);
188 return 0;
189 }
190
191 s=dir;
192 p=s;
193 for (;;)
194 {
195 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
196 {
197 ss=s;
198 s=p+1;
199 len=(int)(p-ss);
200 if (len == 0) continue;
201 for (j=0; j<ctx->num_dirs; j++)
202 if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
203 continue;
204 if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
205 {
206 ctx->num_dirs_alloced+=10;
207 pp=(char **)OPENSSL_malloc(ctx->num_dirs_alloced*
208 sizeof(char *));
209 ip=(int *)OPENSSL_malloc(ctx->num_dirs_alloced*
210 sizeof(int));
211 if ((pp == NULL) || (ip == NULL))
212 {
213 X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE);
214 return(0);
215 }
216 memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)*
217 sizeof(char *));
218 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
219 sizeof(int));
220 if (ctx->dirs != NULL)
221 OPENSSL_free(ctx->dirs);
222 if (ctx->dirs_type != NULL)
223 OPENSSL_free(ctx->dirs_type);
224 ctx->dirs=pp;
225 ctx->dirs_type=ip;
226 }
227 ctx->dirs_type[ctx->num_dirs]=type;
228 ctx->dirs[ctx->num_dirs]=(char *)OPENSSL_malloc((unsigned int)len+1);
229 if (ctx->dirs[ctx->num_dirs] == NULL) return(0);
230 strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len);
231 ctx->dirs[ctx->num_dirs][len]='\0';
232 ctx->num_dirs++;
233 }
234 if (*p == '\0') break;
235 p++;
236 }
237 return(1);
238 }
239
240static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
241 X509_OBJECT *ret)
242 {
243 BY_DIR *ctx;
244 union {
245 struct {
246 X509 st_x509;
247 X509_CINF st_x509_cinf;
248 } x509;
249 struct {
250 X509_CRL st_crl;
251 X509_CRL_INFO st_crl_info;
252 } crl;
253 } data;
254 int ok=0;
255 int i,j,k;
256 unsigned long h;
257 BUF_MEM *b=NULL;
258 struct stat st;
259 X509_OBJECT stmp,*tmp;
260 const char *postfix="";
261
262 if (name == NULL) return(0);
263
264 stmp.type=type;
265 if (type == X509_LU_X509)
266 {
267 data.x509.st_x509.cert_info= &data.x509.st_x509_cinf;
268 data.x509.st_x509_cinf.subject=name;
269 stmp.data.x509= &data.x509.st_x509;
270 postfix="";
271 }
272 else if (type == X509_LU_CRL)
273 {
274 data.crl.st_crl.crl= &data.crl.st_crl_info;
275 data.crl.st_crl_info.issuer=name;
276 stmp.data.crl= &data.crl.st_crl;
277 postfix="r";
278 }
279 else
280 {
281 X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE);
282 goto finish;
283 }
284
285 if ((b=BUF_MEM_new()) == NULL)
286 {
287 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB);
288 goto finish;
289 }
290
291 ctx=(BY_DIR *)xl->method_data;
292
293 h=X509_NAME_hash(name);
294 for (i=0; i<ctx->num_dirs; i++)
295 {
296 j=strlen(ctx->dirs[i])+1+8+6+1+1;
297 if (!BUF_MEM_grow(b,j))
298 {
299 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE);
300 goto finish;
301 }
302 k=0;
303 for (;;)
304 {
305 char c = '/';
306#ifdef OPENSSL_SYS_VMS
307 c = ctx->dirs[i][strlen(ctx->dirs[i])-1];
308 if (c != ':' && c != '>' && c != ']')
309 {
310 /* If no separator is present, we assume the
311 directory specifier is a logical name, and
312 add a colon. We really should use better
313 VMS routines for merging things like this,
314 but this will do for now...
315 -- Richard Levitte */
316 c = ':';
317 }
318 else
319 {
320 c = '\0';
321 }
322#endif
323 if (c == '\0')
324 {
325 /* This is special. When c == '\0', no
326 directory separator should be added. */
327 BIO_snprintf(b->data,b->max,
328 "%s%08lx.%s%d",ctx->dirs[i],h,
329 postfix,k);
330 }
331 else
332 {
333 BIO_snprintf(b->data,b->max,
334 "%s%c%08lx.%s%d",ctx->dirs[i],c,h,
335 postfix,k);
336 }
337 k++;
338 if (stat(b->data,&st) < 0)
339 break;
340 /* found one. */
341 if (type == X509_LU_X509)
342 {
343 if ((X509_load_cert_file(xl,b->data,
344 ctx->dirs_type[i])) == 0)
345 break;
346 }
347 else if (type == X509_LU_CRL)
348 {
349 if ((X509_load_crl_file(xl,b->data,
350 ctx->dirs_type[i])) == 0)
351 break;
352 }
353 /* else case will caught higher up */
354 }
355
356 /* we have added it to the cache so now pull
357 * it out again */
358 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
359 j = sk_X509_OBJECT_find(xl->store_ctx->objs,&stmp);
360 if(j != -1) tmp=sk_X509_OBJECT_value(xl->store_ctx->objs,j);
361 else tmp = NULL;
362 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
363
364 if (tmp != NULL)
365 {
366 ok=1;
367 ret->type=tmp->type;
368 memcpy(&ret->data,&tmp->data,sizeof(ret->data));
369 /* If we were going to up the reference count,
370 * we would need to do it on a perl 'type'
371 * basis */
372 /* CRYPTO_add(&tmp->data.x509->references,1,
373 CRYPTO_LOCK_X509);*/
374 goto finish;
375 }
376 }
377finish:
378 if (b != NULL) BUF_MEM_free(b);
379 return(ok);
380 }
381
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
new file mode 100644
index 0000000000..a5e0d4aefa
--- /dev/null
+++ b/src/lib/libcrypto/x509/by_file.c
@@ -0,0 +1,300 @@
1/* crypto/x509/by_file.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include <errno.h>
62
63#include "cryptlib.h"
64#include <openssl/lhash.h>
65#include <openssl/buffer.h>
66#include <openssl/x509.h>
67#include <openssl/pem.h>
68
69#ifndef OPENSSL_NO_STDIO
70
71static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
72 long argl, char **ret);
73X509_LOOKUP_METHOD x509_file_lookup=
74 {
75 "Load file into cache",
76 NULL, /* new */
77 NULL, /* free */
78 NULL, /* init */
79 NULL, /* shutdown */
80 by_file_ctrl, /* ctrl */
81 NULL, /* get_by_subject */
82 NULL, /* get_by_issuer_serial */
83 NULL, /* get_by_fingerprint */
84 NULL, /* get_by_alias */
85 };
86
87X509_LOOKUP_METHOD *X509_LOOKUP_file(void)
88 {
89 return(&x509_file_lookup);
90 }
91
92static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
93 char **ret)
94 {
95 int ok=0;
96 char *file;
97
98 switch (cmd)
99 {
100 case X509_L_FILE_LOAD:
101 if (argl == X509_FILETYPE_DEFAULT)
102 {
103 file = (char *)Getenv(X509_get_default_cert_file_env());
104 if (file)
105 ok = (X509_load_cert_crl_file(ctx,file,
106 X509_FILETYPE_PEM) != 0);
107
108 else
109 ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(),
110 X509_FILETYPE_PEM) != 0);
111
112 if (!ok)
113 {
114 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS);
115 }
116 }
117 else
118 {
119 if(argl == X509_FILETYPE_PEM)
120 ok = (X509_load_cert_crl_file(ctx,argp,
121 X509_FILETYPE_PEM) != 0);
122 else
123 ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0);
124 }
125 break;
126 }
127 return(ok);
128 }
129
130int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
131 {
132 int ret=0;
133 BIO *in=NULL;
134 int i,count=0;
135 X509 *x=NULL;
136
137 if (file == NULL) return(1);
138 in=BIO_new(BIO_s_file_internal());
139
140 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
141 {
142 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);
143 goto err;
144 }
145
146 if (type == X509_FILETYPE_PEM)
147 {
148 for (;;)
149 {
150 x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL);
151 if (x == NULL)
152 {
153 if ((ERR_GET_REASON(ERR_peek_last_error()) ==
154 PEM_R_NO_START_LINE) && (count > 0))
155 {
156 ERR_clear_error();
157 break;
158 }
159 else
160 {
161 X509err(X509_F_X509_LOAD_CERT_FILE,
162 ERR_R_PEM_LIB);
163 goto err;
164 }
165 }
166 i=X509_STORE_add_cert(ctx->store_ctx,x);
167 if (!i) goto err;
168 count++;
169 X509_free(x);
170 x=NULL;
171 }
172 ret=count;
173 }
174 else if (type == X509_FILETYPE_ASN1)
175 {
176 x=d2i_X509_bio(in,NULL);
177 if (x == NULL)
178 {
179 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);
180 goto err;
181 }
182 i=X509_STORE_add_cert(ctx->store_ctx,x);
183 if (!i) goto err;
184 ret=i;
185 }
186 else
187 {
188 X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);
189 goto err;
190 }
191err:
192 if (x != NULL) X509_free(x);
193 if (in != NULL) BIO_free(in);
194 return(ret);
195 }
196
197int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
198 {
199 int ret=0;
200 BIO *in=NULL;
201 int i,count=0;
202 X509_CRL *x=NULL;
203
204 if (file == NULL) return(1);
205 in=BIO_new(BIO_s_file_internal());
206
207 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
208 {
209 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB);
210 goto err;
211 }
212
213 if (type == X509_FILETYPE_PEM)
214 {
215 for (;;)
216 {
217 x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
218 if (x == NULL)
219 {
220 if ((ERR_GET_REASON(ERR_peek_last_error()) ==
221 PEM_R_NO_START_LINE) && (count > 0))
222 {
223 ERR_clear_error();
224 break;
225 }
226 else
227 {
228 X509err(X509_F_X509_LOAD_CRL_FILE,
229 ERR_R_PEM_LIB);
230 goto err;
231 }
232 }
233 i=X509_STORE_add_crl(ctx->store_ctx,x);
234 if (!i) goto err;
235 count++;
236 X509_CRL_free(x);
237 x=NULL;
238 }
239 ret=count;
240 }
241 else if (type == X509_FILETYPE_ASN1)
242 {
243 x=d2i_X509_CRL_bio(in,NULL);
244 if (x == NULL)
245 {
246 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB);
247 goto err;
248 }
249 i=X509_STORE_add_crl(ctx->store_ctx,x);
250 if (!i) goto err;
251 ret=i;
252 }
253 else
254 {
255 X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE);
256 goto err;
257 }
258err:
259 if (x != NULL) X509_CRL_free(x);
260 if (in != NULL) BIO_free(in);
261 return(ret);
262 }
263
264int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
265{
266 STACK_OF(X509_INFO) *inf;
267 X509_INFO *itmp;
268 BIO *in;
269 int i, count = 0;
270 if(type != X509_FILETYPE_PEM)
271 return X509_load_cert_file(ctx, file, type);
272 in = BIO_new_file(file, "r");
273 if(!in) {
274 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB);
275 return 0;
276 }
277 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
278 BIO_free(in);
279 if(!inf) {
280 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB);
281 return 0;
282 }
283 for(i = 0; i < sk_X509_INFO_num(inf); i++) {
284 itmp = sk_X509_INFO_value(inf, i);
285 if(itmp->x509) {
286 X509_STORE_add_cert(ctx->store_ctx, itmp->x509);
287 count++;
288 }
289 if(itmp->crl) {
290 X509_STORE_add_crl(ctx->store_ctx, itmp->crl);
291 count++;
292 }
293 }
294 sk_X509_INFO_pop_free(inf, X509_INFO_free);
295 return count;
296}
297
298
299#endif /* OPENSSL_NO_STDIO */
300
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
new file mode 100644
index 0000000000..e8c1a59cf2
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509.h
@@ -0,0 +1,1259 @@
1/* crypto/x509/x509.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_X509_H
60#define HEADER_X509_H
61
62#include <openssl/symhacks.h>
63#ifndef OPENSSL_NO_BUFFER
64#include <openssl/buffer.h>
65#endif
66#ifndef OPENSSL_NO_EVP
67#include <openssl/evp.h>
68#endif
69#ifndef OPENSSL_NO_BIO
70#include <openssl/bio.h>
71#endif
72#include <openssl/stack.h>
73#include <openssl/asn1.h>
74#include <openssl/safestack.h>
75
76#ifndef OPENSSL_NO_RSA
77#include <openssl/rsa.h>
78#endif
79
80#ifndef OPENSSL_NO_DSA
81#include <openssl/dsa.h>
82#endif
83
84#ifndef OPENSSL_NO_DH
85#include <openssl/dh.h>
86#endif
87#ifndef OPENSSL_NO_SHA
88#include <openssl/sha.h>
89#endif
90#include <openssl/e_os2.h>
91#include <openssl/ossl_typ.h>
92
93#ifdef __cplusplus
94extern "C" {
95#endif
96
97#ifdef OPENSSL_SYS_WIN32
98/* Under Win32 this is defined in wincrypt.h */
99#undef X509_NAME
100#endif
101
102#define X509_FILETYPE_PEM 1
103#define X509_FILETYPE_ASN1 2
104#define X509_FILETYPE_DEFAULT 3
105
106#define X509v3_KU_DIGITAL_SIGNATURE 0x0080
107#define X509v3_KU_NON_REPUDIATION 0x0040
108#define X509v3_KU_KEY_ENCIPHERMENT 0x0020
109#define X509v3_KU_DATA_ENCIPHERMENT 0x0010
110#define X509v3_KU_KEY_AGREEMENT 0x0008
111#define X509v3_KU_KEY_CERT_SIGN 0x0004
112#define X509v3_KU_CRL_SIGN 0x0002
113#define X509v3_KU_ENCIPHER_ONLY 0x0001
114#define X509v3_KU_DECIPHER_ONLY 0x8000
115#define X509v3_KU_UNDEF 0xffff
116
117typedef struct X509_objects_st
118 {
119 int nid;
120 int (*a2i)();
121 int (*i2a)();
122 } X509_OBJECTS;
123
124struct X509_algor_st
125 {
126 ASN1_OBJECT *algorithm;
127 ASN1_TYPE *parameter;
128 } /* X509_ALGOR */;
129
130DECLARE_STACK_OF(X509_ALGOR)
131DECLARE_ASN1_SET_OF(X509_ALGOR)
132
133typedef struct X509_val_st
134 {
135 ASN1_TIME *notBefore;
136 ASN1_TIME *notAfter;
137 } X509_VAL;
138
139typedef struct X509_pubkey_st
140 {
141 X509_ALGOR *algor;
142 ASN1_BIT_STRING *public_key;
143 EVP_PKEY *pkey;
144 } X509_PUBKEY;
145
146typedef struct X509_sig_st
147 {
148 X509_ALGOR *algor;
149 ASN1_OCTET_STRING *digest;
150 } X509_SIG;
151
152typedef struct X509_name_entry_st
153 {
154 ASN1_OBJECT *object;
155 ASN1_STRING *value;
156 int set;
157 int size; /* temp variable */
158 } X509_NAME_ENTRY;
159
160DECLARE_STACK_OF(X509_NAME_ENTRY)
161DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
162
163/* we always keep X509_NAMEs in 2 forms. */
164struct X509_name_st
165 {
166 STACK_OF(X509_NAME_ENTRY) *entries;
167 int modified; /* true if 'bytes' needs to be built */
168#ifndef OPENSSL_NO_BUFFER
169 BUF_MEM *bytes;
170#else
171 char *bytes;
172#endif
173 unsigned long hash; /* Keep the hash around for lookups */
174 } /* X509_NAME */;
175
176DECLARE_STACK_OF(X509_NAME)
177
178#define X509_EX_V_NETSCAPE_HACK 0x8000
179#define X509_EX_V_INIT 0x0001
180typedef struct X509_extension_st
181 {
182 ASN1_OBJECT *object;
183 ASN1_BOOLEAN critical;
184 ASN1_OCTET_STRING *value;
185 } X509_EXTENSION;
186
187DECLARE_STACK_OF(X509_EXTENSION)
188DECLARE_ASN1_SET_OF(X509_EXTENSION)
189
190/* a sequence of these are used */
191typedef struct x509_attributes_st
192 {
193 ASN1_OBJECT *object;
194 int single; /* 0 for a set, 1 for a single item (which is wrong) */
195 union {
196 char *ptr;
197/* 0 */ STACK_OF(ASN1_TYPE) *set;
198/* 1 */ ASN1_TYPE *single;
199 } value;
200 } X509_ATTRIBUTE;
201
202DECLARE_STACK_OF(X509_ATTRIBUTE)
203DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
204
205
206typedef struct X509_req_info_st
207 {
208 ASN1_ENCODING enc;
209 ASN1_INTEGER *version;
210 X509_NAME *subject;
211 X509_PUBKEY *pubkey;
212 /* d=2 hl=2 l= 0 cons: cont: 00 */
213 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
214 } X509_REQ_INFO;
215
216typedef struct X509_req_st
217 {
218 X509_REQ_INFO *req_info;
219 X509_ALGOR *sig_alg;
220 ASN1_BIT_STRING *signature;
221 int references;
222 } X509_REQ;
223
224typedef struct x509_cinf_st
225 {
226 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
227 ASN1_INTEGER *serialNumber;
228 X509_ALGOR *signature;
229 X509_NAME *issuer;
230 X509_VAL *validity;
231 X509_NAME *subject;
232 X509_PUBKEY *key;
233 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
234 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
235 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
236 } X509_CINF;
237
238/* This stuff is certificate "auxiliary info"
239 * it contains details which are useful in certificate
240 * stores and databases. When used this is tagged onto
241 * the end of the certificate itself
242 */
243
244typedef struct x509_cert_aux_st
245 {
246 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
247 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
248 ASN1_UTF8STRING *alias; /* "friendly name" */
249 ASN1_OCTET_STRING *keyid; /* key id of private key */
250 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
251 } X509_CERT_AUX;
252
253struct x509_st
254 {
255 X509_CINF *cert_info;
256 X509_ALGOR *sig_alg;
257 ASN1_BIT_STRING *signature;
258 int valid;
259 int references;
260 char *name;
261 CRYPTO_EX_DATA ex_data;
262 /* These contain copies of various extension values */
263 long ex_pathlen;
264 unsigned long ex_flags;
265 unsigned long ex_kusage;
266 unsigned long ex_xkusage;
267 unsigned long ex_nscert;
268 ASN1_OCTET_STRING *skid;
269 struct AUTHORITY_KEYID_st *akid;
270#ifndef OPENSSL_NO_SHA
271 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
272#endif
273 X509_CERT_AUX *aux;
274 } /* X509 */;
275
276DECLARE_STACK_OF(X509)
277DECLARE_ASN1_SET_OF(X509)
278
279/* This is used for a table of trust checking functions */
280
281typedef struct x509_trust_st {
282 int trust;
283 int flags;
284 int (*check_trust)(struct x509_trust_st *, X509 *, int);
285 char *name;
286 int arg1;
287 void *arg2;
288} X509_TRUST;
289
290DECLARE_STACK_OF(X509_TRUST)
291
292/* standard trust ids */
293
294#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */
295
296#define X509_TRUST_COMPAT 1
297#define X509_TRUST_SSL_CLIENT 2
298#define X509_TRUST_SSL_SERVER 3
299#define X509_TRUST_EMAIL 4
300#define X509_TRUST_OBJECT_SIGN 5
301#define X509_TRUST_OCSP_SIGN 6
302#define X509_TRUST_OCSP_REQUEST 7
303
304/* Keep these up to date! */
305#define X509_TRUST_MIN 1
306#define X509_TRUST_MAX 7
307
308
309/* trust_flags values */
310#define X509_TRUST_DYNAMIC 1
311#define X509_TRUST_DYNAMIC_NAME 2
312
313/* check_trust return codes */
314
315#define X509_TRUST_TRUSTED 1
316#define X509_TRUST_REJECTED 2
317#define X509_TRUST_UNTRUSTED 3
318
319/* Flags for X509_print_ex() */
320
321#define X509_FLAG_COMPAT 0
322#define X509_FLAG_NO_HEADER 1L
323#define X509_FLAG_NO_VERSION (1L << 1)
324#define X509_FLAG_NO_SERIAL (1L << 2)
325#define X509_FLAG_NO_SIGNAME (1L << 3)
326#define X509_FLAG_NO_ISSUER (1L << 4)
327#define X509_FLAG_NO_VALIDITY (1L << 5)
328#define X509_FLAG_NO_SUBJECT (1L << 6)
329#define X509_FLAG_NO_PUBKEY (1L << 7)
330#define X509_FLAG_NO_EXTENSIONS (1L << 8)
331#define X509_FLAG_NO_SIGDUMP (1L << 9)
332#define X509_FLAG_NO_AUX (1L << 10)
333#define X509_FLAG_NO_ATTRIBUTES (1L << 11)
334
335/* Flags specific to X509_NAME_print_ex() */
336
337/* The field separator information */
338
339#define XN_FLAG_SEP_MASK (0xf << 16)
340
341#define XN_FLAG_COMPAT 0 /* Traditional SSLeay: use old X509_NAME_print */
342#define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */
343#define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */
344#define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */
345#define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */
346
347#define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */
348
349/* How the field name is shown */
350
351#define XN_FLAG_FN_MASK (0x3 << 21)
352
353#define XN_FLAG_FN_SN 0 /* Object short name */
354#define XN_FLAG_FN_LN (1 << 21) /* Object long name */
355#define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */
356#define XN_FLAG_FN_NONE (3 << 21) /* No field names */
357
358#define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */
359
360/* This determines if we dump fields we don't recognise:
361 * RFC2253 requires this.
362 */
363
364#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24)
365
366#define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 characters */
367
368/* Complete set of RFC2253 flags */
369
370#define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \
371 XN_FLAG_SEP_COMMA_PLUS | \
372 XN_FLAG_DN_REV | \
373 XN_FLAG_FN_SN | \
374 XN_FLAG_DUMP_UNKNOWN_FIELDS)
375
376/* readable oneline form */
377
378#define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \
379 ASN1_STRFLGS_ESC_QUOTE | \
380 XN_FLAG_SEP_CPLUS_SPC | \
381 XN_FLAG_SPC_EQ | \
382 XN_FLAG_FN_SN)
383
384/* readable multiline form */
385
386#define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \
387 ASN1_STRFLGS_ESC_MSB | \
388 XN_FLAG_SEP_MULTILINE | \
389 XN_FLAG_SPC_EQ | \
390 XN_FLAG_FN_LN | \
391 XN_FLAG_FN_ALIGN)
392
393typedef struct X509_revoked_st
394 {
395 ASN1_INTEGER *serialNumber;
396 ASN1_TIME *revocationDate;
397 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
398 int sequence; /* load sequence */
399 } X509_REVOKED;
400
401DECLARE_STACK_OF(X509_REVOKED)
402DECLARE_ASN1_SET_OF(X509_REVOKED)
403
404typedef struct X509_crl_info_st
405 {
406 ASN1_INTEGER *version;
407 X509_ALGOR *sig_alg;
408 X509_NAME *issuer;
409 ASN1_TIME *lastUpdate;
410 ASN1_TIME *nextUpdate;
411 STACK_OF(X509_REVOKED) *revoked;
412 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
413 ASN1_ENCODING enc;
414 } X509_CRL_INFO;
415
416struct X509_crl_st
417 {
418 /* actual signature */
419 X509_CRL_INFO *crl;
420 X509_ALGOR *sig_alg;
421 ASN1_BIT_STRING *signature;
422 int references;
423 } /* X509_CRL */;
424
425DECLARE_STACK_OF(X509_CRL)
426DECLARE_ASN1_SET_OF(X509_CRL)
427
428typedef struct private_key_st
429 {
430 int version;
431 /* The PKCS#8 data types */
432 X509_ALGOR *enc_algor;
433 ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */
434
435 /* When decrypted, the following will not be NULL */
436 EVP_PKEY *dec_pkey;
437
438 /* used to encrypt and decrypt */
439 int key_length;
440 char *key_data;
441 int key_free; /* true if we should auto free key_data */
442
443 /* expanded version of 'enc_algor' */
444 EVP_CIPHER_INFO cipher;
445
446 int references;
447 } X509_PKEY;
448
449#ifndef OPENSSL_NO_EVP
450typedef struct X509_info_st
451 {
452 X509 *x509;
453 X509_CRL *crl;
454 X509_PKEY *x_pkey;
455
456 EVP_CIPHER_INFO enc_cipher;
457 int enc_len;
458 char *enc_data;
459
460 int references;
461 } X509_INFO;
462
463DECLARE_STACK_OF(X509_INFO)
464#endif
465
466/* The next 2 structures and their 8 routines were sent to me by
467 * Pat Richard <patr@x509.com> and are used to manipulate
468 * Netscapes spki structures - useful if you are writing a CA web page
469 */
470typedef struct Netscape_spkac_st
471 {
472 X509_PUBKEY *pubkey;
473 ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */
474 } NETSCAPE_SPKAC;
475
476typedef struct Netscape_spki_st
477 {
478 NETSCAPE_SPKAC *spkac; /* signed public key and challenge */
479 X509_ALGOR *sig_algor;
480 ASN1_BIT_STRING *signature;
481 } NETSCAPE_SPKI;
482
483/* Netscape certificate sequence structure */
484typedef struct Netscape_certificate_sequence
485 {
486 ASN1_OBJECT *type;
487 STACK_OF(X509) *certs;
488 } NETSCAPE_CERT_SEQUENCE;
489
490/* Unused (and iv length is wrong)
491typedef struct CBCParameter_st
492 {
493 unsigned char iv[8];
494 } CBC_PARAM;
495*/
496
497/* Password based encryption structure */
498
499typedef struct PBEPARAM_st {
500ASN1_OCTET_STRING *salt;
501ASN1_INTEGER *iter;
502} PBEPARAM;
503
504/* Password based encryption V2 structures */
505
506typedef struct PBE2PARAM_st {
507X509_ALGOR *keyfunc;
508X509_ALGOR *encryption;
509} PBE2PARAM;
510
511typedef struct PBKDF2PARAM_st {
512ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */
513ASN1_INTEGER *iter;
514ASN1_INTEGER *keylength;
515X509_ALGOR *prf;
516} PBKDF2PARAM;
517
518
519/* PKCS#8 private key info structure */
520
521typedef struct pkcs8_priv_key_info_st
522 {
523 int broken; /* Flag for various broken formats */
524#define PKCS8_OK 0
525#define PKCS8_NO_OCTET 1
526#define PKCS8_EMBEDDED_PARAM 2
527#define PKCS8_NS_DB 3
528 ASN1_INTEGER *version;
529 X509_ALGOR *pkeyalg;
530 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
531 STACK_OF(X509_ATTRIBUTE) *attributes;
532 } PKCS8_PRIV_KEY_INFO;
533
534#ifdef __cplusplus
535}
536#endif
537
538#include <openssl/x509_vfy.h>
539#include <openssl/pkcs7.h>
540
541#ifdef __cplusplus
542extern "C" {
543#endif
544
545#ifdef SSLEAY_MACROS
546#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
547 a->signature,(char *)a->cert_info,r)
548#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
549 a->sig_alg,a->signature,(char *)a->req_info,r)
550#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
551 a->sig_alg, a->signature,(char *)a->crl,r)
552
553#define X509_sign(x,pkey,md) \
554 ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
555 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
556#define X509_REQ_sign(x,pkey,md) \
557 ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
558 x->signature, (char *)x->req_info,pkey,md)
559#define X509_CRL_sign(x,pkey,md) \
560 ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
561 x->signature, (char *)x->crl,pkey,md)
562#define NETSCAPE_SPKI_sign(x,pkey,md) \
563 ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
564 x->signature, (char *)x->spkac,pkey,md)
565
566#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
567 (char *(*)())d2i_X509,(char *)x509)
568#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
569 (int (*)())i2d_X509_ATTRIBUTE, \
570 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
571#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
572 (int (*)())i2d_X509_EXTENSION, \
573 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
574#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
575 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
576#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
577#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
578 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
579#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
580
581#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
582 (char *(*)())d2i_X509_CRL,(char *)crl)
583#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
584 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
585 (unsigned char **)(crl))
586#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
587 (unsigned char *)crl)
588#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
589 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
590 (unsigned char **)(crl))
591#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
592 (unsigned char *)crl)
593
594#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
595 (char *(*)())d2i_PKCS7,(char *)p7)
596#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
597 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
598 (unsigned char **)(p7))
599#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
600 (unsigned char *)p7)
601#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
602 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
603 (unsigned char **)(p7))
604#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
605 (unsigned char *)p7)
606
607#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
608 (char *(*)())d2i_X509_REQ,(char *)req)
609#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
610 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
611 (unsigned char **)(req))
612#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
613 (unsigned char *)req)
614#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
615 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
616 (unsigned char **)(req))
617#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
618 (unsigned char *)req)
619
620#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
621 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
622#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
623 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
624
625#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
626 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
627 (unsigned char **)(rsa))
628#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
629 (unsigned char *)rsa)
630#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
631 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
632 (unsigned char **)(rsa))
633#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
634 (unsigned char *)rsa)
635
636#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
637 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
638 (unsigned char **)(rsa))
639#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
640 (unsigned char *)rsa)
641#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
642 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
643 (unsigned char **)(rsa))
644#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
645 (unsigned char *)rsa)
646
647#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
648 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
649 (unsigned char **)(dsa))
650#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
651 (unsigned char *)dsa)
652#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
653 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
654 (unsigned char **)(dsa))
655#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
656 (unsigned char *)dsa)
657
658#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
659 (char *(*)())d2i_X509_ALGOR,(char *)xn)
660
661#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
662 (char *(*)())d2i_X509_NAME,(char *)xn)
663#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
664 (int (*)())i2d_X509_NAME_ENTRY, \
665 (char *(*)())d2i_X509_NAME_ENTRY,\
666 (char *)ne)
667
668#define X509_digest(data,type,md,len) \
669 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
670#define X509_NAME_digest(data,type,md,len) \
671 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
672#ifndef PKCS7_ISSUER_AND_SERIAL_digest
673#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
674 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
675 (char *)data,md,len)
676#endif
677#endif
678
679#define X509_EXT_PACK_UNKNOWN 1
680#define X509_EXT_PACK_STRING 2
681
682#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
683/* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
684#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
685#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
686#define X509_extract_key(x) X509_get_pubkey(x) /*****/
687#define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
688#define X509_REQ_get_subject_name(x) ((x)->req_info->subject)
689#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
690#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
691#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
692
693#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
694#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
695#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
696#define X509_CRL_get_issuer(x) ((x)->crl->issuer)
697#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
698
699/* This one is only used so that a binary form can output, as in
700 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
701#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
702
703
704const char *X509_verify_cert_error_string(long n);
705
706#ifndef SSLEAY_MACROS
707#ifndef OPENSSL_NO_EVP
708int X509_verify(X509 *a, EVP_PKEY *r);
709
710int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
711int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
712int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
713
714NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
715char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
716EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
717int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
718
719int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
720
721int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig);
722
723int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
724int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
725int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
726int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
727
728int X509_pubkey_digest(const X509 *data,const EVP_MD *type,
729 unsigned char *md, unsigned int *len);
730int X509_digest(const X509 *data,const EVP_MD *type,
731 unsigned char *md, unsigned int *len);
732int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type,
733 unsigned char *md, unsigned int *len);
734int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type,
735 unsigned char *md, unsigned int *len);
736int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type,
737 unsigned char *md, unsigned int *len);
738#endif
739
740#ifndef OPENSSL_NO_FP_API
741X509 *d2i_X509_fp(FILE *fp, X509 **x509);
742int i2d_X509_fp(FILE *fp,X509 *x509);
743X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
744int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
745X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
746int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
747#ifndef OPENSSL_NO_RSA
748RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
749int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
750RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
751int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
752RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
753int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
754#endif
755#ifndef OPENSSL_NO_DSA
756DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
757int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
758DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
759int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
760#endif
761X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
762int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
763PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
764 PKCS8_PRIV_KEY_INFO **p8inf);
765int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
766int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
767int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
768EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
769int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey);
770EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a);
771#endif
772
773#ifndef OPENSSL_NO_BIO
774X509 *d2i_X509_bio(BIO *bp,X509 **x509);
775int i2d_X509_bio(BIO *bp,X509 *x509);
776X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
777int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
778X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
779int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
780#ifndef OPENSSL_NO_RSA
781RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
782int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
783RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
784int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
785RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
786int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
787#endif
788#ifndef OPENSSL_NO_DSA
789DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
790int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
791DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
792int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
793#endif
794X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
795int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
796PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
797 PKCS8_PRIV_KEY_INFO **p8inf);
798int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
799int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
800int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
801EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
802int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);
803EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);
804#endif
805
806X509 *X509_dup(X509 *x509);
807X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
808X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
809X509_CRL *X509_CRL_dup(X509_CRL *crl);
810X509_REQ *X509_REQ_dup(X509_REQ *req);
811X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
812X509_NAME *X509_NAME_dup(X509_NAME *xn);
813X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
814
815#endif /* !SSLEAY_MACROS */
816
817int X509_cmp_time(ASN1_TIME *s, time_t *t);
818int X509_cmp_current_time(ASN1_TIME *s);
819ASN1_TIME * X509_time_adj(ASN1_TIME *s, long adj, time_t *t);
820ASN1_TIME * X509_gmtime_adj(ASN1_TIME *s, long adj);
821
822const char * X509_get_default_cert_area(void );
823const char * X509_get_default_cert_dir(void );
824const char * X509_get_default_cert_file(void );
825const char * X509_get_default_cert_dir_env(void );
826const char * X509_get_default_cert_file_env(void );
827const char * X509_get_default_private_dir(void );
828
829X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
830X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
831
832DECLARE_ASN1_FUNCTIONS(X509_ALGOR)
833DECLARE_ASN1_FUNCTIONS(X509_VAL)
834
835DECLARE_ASN1_FUNCTIONS(X509_PUBKEY)
836
837int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
838EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
839int X509_get_pubkey_parameters(EVP_PKEY *pkey,
840 STACK_OF(X509) *chain);
841int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
842EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
843 long length);
844#ifndef OPENSSL_NO_RSA
845int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
846RSA * d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
847 long length);
848#endif
849#ifndef OPENSSL_NO_DSA
850int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
851DSA * d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
852 long length);
853#endif
854
855DECLARE_ASN1_FUNCTIONS(X509_SIG)
856DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO)
857DECLARE_ASN1_FUNCTIONS(X509_REQ)
858
859DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE)
860X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
861
862DECLARE_ASN1_FUNCTIONS(X509_EXTENSION)
863
864DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY)
865
866DECLARE_ASN1_FUNCTIONS(X509_NAME)
867
868int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
869
870DECLARE_ASN1_FUNCTIONS(X509_CINF)
871
872DECLARE_ASN1_FUNCTIONS(X509)
873DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)
874
875int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
876 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
877int X509_set_ex_data(X509 *r, int idx, void *arg);
878void *X509_get_ex_data(X509 *r, int idx);
879int i2d_X509_AUX(X509 *a,unsigned char **pp);
880X509 * d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
881
882int X509_alias_set1(X509 *x, unsigned char *name, int len);
883int X509_keyid_set1(X509 *x, unsigned char *id, int len);
884unsigned char * X509_alias_get0(X509 *x, int *len);
885int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
886int X509_TRUST_set(int *t, int trust);
887int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
888int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
889void X509_trust_clear(X509 *x);
890void X509_reject_clear(X509 *x);
891
892DECLARE_ASN1_FUNCTIONS(X509_REVOKED)
893DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO)
894DECLARE_ASN1_FUNCTIONS(X509_CRL)
895
896int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
897
898X509_PKEY * X509_PKEY_new(void );
899void X509_PKEY_free(X509_PKEY *a);
900int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
901X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
902
903DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)
904DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
905DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)
906
907#ifndef OPENSSL_NO_EVP
908X509_INFO * X509_INFO_new(void);
909void X509_INFO_free(X509_INFO *a);
910char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
911
912int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
913 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
914
915int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
916 unsigned char *md,unsigned int *len);
917
918int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
919 ASN1_BIT_STRING *signature,
920 char *data,EVP_PKEY *pkey, const EVP_MD *type);
921
922int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,
923 unsigned char *md,unsigned int *len);
924
925int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1,
926 ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey);
927
928int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
929 ASN1_BIT_STRING *signature,
930 void *data, EVP_PKEY *pkey, const EVP_MD *type);
931#endif
932
933int X509_set_version(X509 *x,long version);
934int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
935ASN1_INTEGER * X509_get_serialNumber(X509 *x);
936int X509_set_issuer_name(X509 *x, X509_NAME *name);
937X509_NAME * X509_get_issuer_name(X509 *a);
938int X509_set_subject_name(X509 *x, X509_NAME *name);
939X509_NAME * X509_get_subject_name(X509 *a);
940int X509_set_notBefore(X509 *x, ASN1_TIME *tm);
941int X509_set_notAfter(X509 *x, ASN1_TIME *tm);
942int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
943EVP_PKEY * X509_get_pubkey(X509 *x);
944ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x);
945int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
946
947int X509_REQ_set_version(X509_REQ *x,long version);
948int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
949int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
950EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
951int X509_REQ_extension_nid(int nid);
952int * X509_REQ_get_extension_nids(void);
953void X509_REQ_set_extension_nids(int *nids);
954STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
955int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
956 int nid);
957int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
958int X509_REQ_get_attr_count(const X509_REQ *req);
959int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
960 int lastpos);
961int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
962 int lastpos);
963X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
964X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
965int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
966int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
967 const ASN1_OBJECT *obj, int type,
968 const unsigned char *bytes, int len);
969int X509_REQ_add1_attr_by_NID(X509_REQ *req,
970 int nid, int type,
971 const unsigned char *bytes, int len);
972int X509_REQ_add1_attr_by_txt(X509_REQ *req,
973 const char *attrname, int type,
974 const unsigned char *bytes, int len);
975
976int X509_CRL_set_version(X509_CRL *x, long version);
977int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
978int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm);
979int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm);
980int X509_CRL_sort(X509_CRL *crl);
981
982int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
983int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);
984
985int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
986
987int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
988unsigned long X509_issuer_and_serial_hash(X509 *a);
989
990int X509_issuer_name_cmp(const X509 *a, const X509 *b);
991unsigned long X509_issuer_name_hash(X509 *a);
992
993int X509_subject_name_cmp(const X509 *a, const X509 *b);
994unsigned long X509_subject_name_hash(X509 *x);
995
996int X509_cmp(const X509 *a, const X509 *b);
997int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
998unsigned long X509_NAME_hash(X509_NAME *x);
999
1000int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
1001#ifndef OPENSSL_NO_FP_API
1002int X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
1003int X509_print_fp(FILE *bp,X509 *x);
1004int X509_CRL_print_fp(FILE *bp,X509_CRL *x);
1005int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
1006int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);
1007#endif
1008
1009#ifndef OPENSSL_NO_BIO
1010int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
1011int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);
1012int X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
1013int X509_print(BIO *bp,X509 *x);
1014int X509_ocspid_print(BIO *bp,X509 *x);
1015int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
1016int X509_CRL_print(BIO *bp,X509_CRL *x);
1017int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag);
1018int X509_REQ_print(BIO *bp,X509_REQ *req);
1019#endif
1020
1021int X509_NAME_entry_count(X509_NAME *name);
1022int X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
1023 char *buf,int len);
1024int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
1025 char *buf,int len);
1026
1027/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
1028 * lastpos, search after that position on. */
1029int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
1030int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
1031 int lastpos);
1032X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
1033X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
1034int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
1035 int loc, int set);
1036int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
1037 unsigned char *bytes, int len, int loc, int set);
1038int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
1039 unsigned char *bytes, int len, int loc, int set);
1040X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
1041 const char *field, int type, const unsigned char *bytes, int len);
1042X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
1043 int type,unsigned char *bytes, int len);
1044int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
1045 const unsigned char *bytes, int len, int loc, int set);
1046X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
1047 ASN1_OBJECT *obj, int type,const unsigned char *bytes,
1048 int len);
1049int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
1050 ASN1_OBJECT *obj);
1051int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
1052 const unsigned char *bytes, int len);
1053ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
1054ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
1055
1056int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
1057int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
1058 int nid, int lastpos);
1059int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
1060 ASN1_OBJECT *obj,int lastpos);
1061int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
1062 int crit, int lastpos);
1063X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
1064X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
1065STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
1066 X509_EXTENSION *ex, int loc);
1067
1068int X509_get_ext_count(X509 *x);
1069int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
1070int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
1071int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
1072X509_EXTENSION *X509_get_ext(X509 *x, int loc);
1073X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
1074int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
1075void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
1076int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
1077 unsigned long flags);
1078
1079int X509_CRL_get_ext_count(X509_CRL *x);
1080int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
1081int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
1082int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
1083X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
1084X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
1085int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
1086void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
1087int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,
1088 unsigned long flags);
1089
1090int X509_REVOKED_get_ext_count(X509_REVOKED *x);
1091int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
1092int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
1093int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
1094X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
1095X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
1096int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
1097void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
1098int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,
1099 unsigned long flags);
1100
1101X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
1102 int nid, int crit, ASN1_OCTET_STRING *data);
1103X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
1104 ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
1105int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
1106int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
1107int X509_EXTENSION_set_data(X509_EXTENSION *ex,
1108 ASN1_OCTET_STRING *data);
1109ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
1110ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
1111int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
1112
1113int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
1114int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
1115 int lastpos);
1116int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
1117 int lastpos);
1118X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
1119X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
1120STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
1121 X509_ATTRIBUTE *attr);
1122STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
1123 const ASN1_OBJECT *obj, int type,
1124 const unsigned char *bytes, int len);
1125STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
1126 int nid, int type,
1127 const unsigned char *bytes, int len);
1128STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
1129 const char *attrname, int type,
1130 const unsigned char *bytes, int len);
1131X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
1132 int atrtype, const void *data, int len);
1133X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
1134 const ASN1_OBJECT *obj, int atrtype, const void *data, int len);
1135X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
1136 const char *atrname, int type, const unsigned char *bytes, int len);
1137int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);
1138int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len);
1139void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
1140 int atrtype, void *data);
1141int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
1142ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
1143ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
1144
1145int X509_verify_cert(X509_STORE_CTX *ctx);
1146
1147/* lookup a cert from a X509 STACK */
1148X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
1149 ASN1_INTEGER *serial);
1150X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
1151
1152DECLARE_ASN1_FUNCTIONS(PBEPARAM)
1153DECLARE_ASN1_FUNCTIONS(PBE2PARAM)
1154DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM)
1155
1156X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
1157X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
1158 unsigned char *salt, int saltlen);
1159
1160/* PKCS#8 utilities */
1161
1162DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
1163
1164EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
1165PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
1166PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
1167PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
1168
1169int X509_check_trust(X509 *x, int id, int flags);
1170int X509_TRUST_get_count(void);
1171X509_TRUST * X509_TRUST_get0(int idx);
1172int X509_TRUST_get_by_id(int id);
1173int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
1174 char *name, int arg1, void *arg2);
1175void X509_TRUST_cleanup(void);
1176int X509_TRUST_get_flags(X509_TRUST *xp);
1177char *X509_TRUST_get0_name(X509_TRUST *xp);
1178int X509_TRUST_get_trust(X509_TRUST *xp);
1179
1180/* BEGIN ERROR CODES */
1181/* The following lines are auto generated by the script mkerr.pl. Any changes
1182 * made after this point may be overwritten when the script is next run.
1183 */
1184void ERR_load_X509_strings(void);
1185
1186/* Error codes for the X509 functions. */
1187
1188/* Function codes. */
1189#define X509_F_ADD_CERT_DIR 100
1190#define X509_F_BY_FILE_CTRL 101
1191#define X509_F_DIR_CTRL 102
1192#define X509_F_GET_CERT_BY_SUBJECT 103
1193#define X509_F_NETSCAPE_SPKI_B64_DECODE 129
1194#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130
1195#define X509_F_X509V3_ADD_EXT 104
1196#define X509_F_X509_ADD_ATTR 135
1197#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136
1198#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137
1199#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140
1200#define X509_F_X509_ATTRIBUTE_GET0_DATA 139
1201#define X509_F_X509_ATTRIBUTE_SET1_DATA 138
1202#define X509_F_X509_CHECK_PRIVATE_KEY 128
1203#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
1204#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
1205#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
1206#define X509_F_X509_LOAD_CERT_CRL_FILE 132
1207#define X509_F_X509_LOAD_CERT_FILE 111
1208#define X509_F_X509_LOAD_CRL_FILE 112
1209#define X509_F_X509_NAME_ADD_ENTRY 113
1210#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
1211#define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131
1212#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
1213#define X509_F_X509_NAME_ONELINE 116
1214#define X509_F_X509_NAME_PRINT 117
1215#define X509_F_X509_PRINT_FP 118
1216#define X509_F_X509_PUBKEY_GET 119
1217#define X509_F_X509_PUBKEY_SET 120
1218#define X509_F_X509_REQ_PRINT 121
1219#define X509_F_X509_REQ_PRINT_FP 122
1220#define X509_F_X509_REQ_TO_X509 123
1221#define X509_F_X509_STORE_ADD_CERT 124
1222#define X509_F_X509_STORE_ADD_CRL 125
1223#define X509_F_X509_STORE_CTX_INIT 143
1224#define X509_F_X509_STORE_CTX_NEW 142
1225#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134
1226#define X509_F_X509_TO_X509_REQ 126
1227#define X509_F_X509_TRUST_ADD 133
1228#define X509_F_X509_TRUST_SET 141
1229#define X509_F_X509_VERIFY_CERT 127
1230
1231/* Reason codes. */
1232#define X509_R_BAD_X509_FILETYPE 100
1233#define X509_R_BASE64_DECODE_ERROR 118
1234#define X509_R_CANT_CHECK_DH_KEY 114
1235#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
1236#define X509_R_ERR_ASN1_LIB 102
1237#define X509_R_INVALID_DIRECTORY 113
1238#define X509_R_INVALID_FIELD_NAME 119
1239#define X509_R_INVALID_TRUST 123
1240#define X509_R_KEY_TYPE_MISMATCH 115
1241#define X509_R_KEY_VALUES_MISMATCH 116
1242#define X509_R_LOADING_CERT_DIR 103
1243#define X509_R_LOADING_DEFAULTS 104
1244#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
1245#define X509_R_SHOULD_RETRY 106
1246#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
1247#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
1248#define X509_R_UNKNOWN_KEY_TYPE 117
1249#define X509_R_UNKNOWN_NID 109
1250#define X509_R_UNKNOWN_PURPOSE_ID 121
1251#define X509_R_UNKNOWN_TRUST_ID 120
1252#define X509_R_UNSUPPORTED_ALGORITHM 111
1253#define X509_R_WRONG_LOOKUP_TYPE 112
1254#define X509_R_WRONG_TYPE 122
1255
1256#ifdef __cplusplus
1257}
1258#endif
1259#endif
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
new file mode 100644
index 0000000000..0bae3d32a1
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_att.c
@@ -0,0 +1,326 @@
1/* crypto/x509/x509_att.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
69{
70 if (!x) return 0;
71 return(sk_X509_ATTRIBUTE_num(x));
72}
73
74int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
75 int lastpos)
76{
77 ASN1_OBJECT *obj;
78
79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2);
81 return(X509at_get_attr_by_OBJ(x,obj,lastpos));
82}
83
84int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
85 int lastpos)
86{
87 int n;
88 X509_ATTRIBUTE *ex;
89
90 if (sk == NULL) return(-1);
91 lastpos++;
92 if (lastpos < 0)
93 lastpos=0;
94 n=sk_X509_ATTRIBUTE_num(sk);
95 for ( ; lastpos < n; lastpos++)
96 {
97 ex=sk_X509_ATTRIBUTE_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos);
100 }
101 return(-1);
102}
103
104X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc)
105{
106 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
107 return NULL;
108 else
109 return sk_X509_ATTRIBUTE_value(x,loc);
110}
111
112X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc)
113{
114 X509_ATTRIBUTE *ret;
115
116 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
117 return(NULL);
118 ret=sk_X509_ATTRIBUTE_delete(x,loc);
119 return(ret);
120}
121
122STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
123 X509_ATTRIBUTE *attr)
124{
125 X509_ATTRIBUTE *new_attr=NULL;
126 STACK_OF(X509_ATTRIBUTE) *sk=NULL;
127
128 if ((x != NULL) && (*x == NULL))
129 {
130 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL)
131 goto err;
132 }
133 else
134 sk= *x;
135
136 if ((new_attr=X509_ATTRIBUTE_dup(attr)) == NULL)
137 goto err2;
138 if (!sk_X509_ATTRIBUTE_push(sk,new_attr))
139 goto err;
140 if ((x != NULL) && (*x == NULL))
141 *x=sk;
142 return(sk);
143err:
144 X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE);
145err2:
146 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr);
147 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk);
148 return(NULL);
149}
150
151STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
152 const ASN1_OBJECT *obj, int type,
153 const unsigned char *bytes, int len)
154{
155 X509_ATTRIBUTE *attr;
156 STACK_OF(X509_ATTRIBUTE) *ret;
157 attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, type, bytes, len);
158 if(!attr) return 0;
159 ret = X509at_add1_attr(x, attr);
160 X509_ATTRIBUTE_free(attr);
161 return ret;
162}
163
164STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
165 int nid, int type,
166 const unsigned char *bytes, int len)
167{
168 X509_ATTRIBUTE *attr;
169 STACK_OF(X509_ATTRIBUTE) *ret;
170 attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type, bytes, len);
171 if(!attr) return 0;
172 ret = X509at_add1_attr(x, attr);
173 X509_ATTRIBUTE_free(attr);
174 return ret;
175}
176
177STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
178 const char *attrname, int type,
179 const unsigned char *bytes, int len)
180{
181 X509_ATTRIBUTE *attr;
182 STACK_OF(X509_ATTRIBUTE) *ret;
183 attr = X509_ATTRIBUTE_create_by_txt(NULL, attrname, type, bytes, len);
184 if(!attr) return 0;
185 ret = X509at_add1_attr(x, attr);
186 X509_ATTRIBUTE_free(attr);
187 return ret;
188}
189
190X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
191 int atrtype, const void *data, int len)
192{
193 ASN1_OBJECT *obj;
194 X509_ATTRIBUTE *ret;
195
196 obj=OBJ_nid2obj(nid);
197 if (obj == NULL)
198 {
199 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_NID,X509_R_UNKNOWN_NID);
200 return(NULL);
201 }
202 ret=X509_ATTRIBUTE_create_by_OBJ(attr,obj,atrtype,data,len);
203 if (ret == NULL) ASN1_OBJECT_free(obj);
204 return(ret);
205}
206
207X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
208 const ASN1_OBJECT *obj, int atrtype, const void *data, int len)
209{
210 X509_ATTRIBUTE *ret;
211
212 if ((attr == NULL) || (*attr == NULL))
213 {
214 if ((ret=X509_ATTRIBUTE_new()) == NULL)
215 {
216 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
217 return(NULL);
218 }
219 }
220 else
221 ret= *attr;
222
223 if (!X509_ATTRIBUTE_set1_object(ret,obj))
224 goto err;
225 if (!X509_ATTRIBUTE_set1_data(ret,atrtype,data,len))
226 goto err;
227
228 if ((attr != NULL) && (*attr == NULL)) *attr=ret;
229 return(ret);
230err:
231 if ((attr == NULL) || (ret != *attr))
232 X509_ATTRIBUTE_free(ret);
233 return(NULL);
234}
235
236X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
237 const char *atrname, int type, const unsigned char *bytes, int len)
238 {
239 ASN1_OBJECT *obj;
240 X509_ATTRIBUTE *nattr;
241
242 obj=OBJ_txt2obj(atrname, 0);
243 if (obj == NULL)
244 {
245 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,
246 X509_R_INVALID_FIELD_NAME);
247 ERR_add_error_data(2, "name=", atrname);
248 return(NULL);
249 }
250 nattr = X509_ATTRIBUTE_create_by_OBJ(attr,obj,type,bytes,len);
251 ASN1_OBJECT_free(obj);
252 return nattr;
253 }
254
255int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj)
256{
257 if ((attr == NULL) || (obj == NULL))
258 return(0);
259 ASN1_OBJECT_free(attr->object);
260 attr->object=OBJ_dup(obj);
261 return(1);
262}
263
264int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len)
265{
266 ASN1_TYPE *ttmp;
267 ASN1_STRING *stmp;
268 int atype;
269 if (!attr) return 0;
270 if(attrtype & MBSTRING_FLAG) {
271 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
272 OBJ_obj2nid(attr->object));
273 if(!stmp) {
274 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_ASN1_LIB);
275 return 0;
276 }
277 atype = stmp->type;
278 } else {
279 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
280 if(!ASN1_STRING_set(stmp, data, len)) goto err;
281 atype = attrtype;
282 }
283 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
284 if(!(ttmp = ASN1_TYPE_new())) goto err;
285 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
286 attr->single = 0;
287 ASN1_TYPE_set(ttmp, atype, stmp);
288 return 1;
289 err:
290 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
291 return 0;
292}
293
294int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr)
295{
296 if(!attr->single) return sk_ASN1_TYPE_num(attr->value.set);
297 if(attr->value.single) return 1;
298 return 0;
299}
300
301ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr)
302{
303 if (attr == NULL) return(NULL);
304 return(attr->object);
305}
306
307void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
308 int atrtype, void *data)
309{
310 ASN1_TYPE *ttmp;
311 ttmp = X509_ATTRIBUTE_get0_type(attr, idx);
312 if(!ttmp) return NULL;
313 if(atrtype != ASN1_TYPE_get(ttmp)){
314 X509err(X509_F_X509_ATTRIBUTE_GET0_DATA, X509_R_WRONG_TYPE);
315 return NULL;
316 }
317 return ttmp->value.ptr;
318}
319
320ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx)
321{
322 if (attr == NULL) return(NULL);
323 if(idx >= X509_ATTRIBUTE_count(attr)) return NULL;
324 if(!attr->single) return sk_ASN1_TYPE_value(attr->value.set, idx);
325 else return attr->value.single;
326}
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
new file mode 100644
index 0000000000..030d0966fc
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_cmp.c
@@ -0,0 +1,440 @@
1/* crypto/x509/x509_cmp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
68 {
69 int i;
70 X509_CINF *ai,*bi;
71
72 ai=a->cert_info;
73 bi=b->cert_info;
74 i=M_ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber);
75 if (i) return(i);
76 return(X509_NAME_cmp(ai->issuer,bi->issuer));
77 }
78
79#ifndef OPENSSL_NO_MD5
80unsigned long X509_issuer_and_serial_hash(X509 *a)
81 {
82 unsigned long ret=0;
83 EVP_MD_CTX ctx;
84 unsigned char md[16];
85 char *f;
86
87 EVP_MD_CTX_init(&ctx);
88 f=X509_NAME_oneline(a->cert_info->issuer,NULL,0);
89 ret=strlen(f);
90 EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
91 EVP_DigestUpdate(&ctx,(unsigned char *)f,ret);
92 OPENSSL_free(f);
93 EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
94 (unsigned long)a->cert_info->serialNumber->length);
95 EVP_DigestFinal_ex(&ctx,&(md[0]),NULL);
96 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
97 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
98 )&0xffffffffL;
99 EVP_MD_CTX_cleanup(&ctx);
100 return(ret);
101 }
102#endif
103
104int X509_issuer_name_cmp(const X509 *a, const X509 *b)
105 {
106 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer));
107 }
108
109int X509_subject_name_cmp(const X509 *a, const X509 *b)
110 {
111 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject));
112 }
113
114int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b)
115 {
116 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
117 }
118
119X509_NAME *X509_get_issuer_name(X509 *a)
120 {
121 return(a->cert_info->issuer);
122 }
123
124unsigned long X509_issuer_name_hash(X509 *x)
125 {
126 return(X509_NAME_hash(x->cert_info->issuer));
127 }
128
129X509_NAME *X509_get_subject_name(X509 *a)
130 {
131 return(a->cert_info->subject);
132 }
133
134ASN1_INTEGER *X509_get_serialNumber(X509 *a)
135 {
136 return(a->cert_info->serialNumber);
137 }
138
139unsigned long X509_subject_name_hash(X509 *x)
140 {
141 return(X509_NAME_hash(x->cert_info->subject));
142 }
143
144#ifndef OPENSSL_NO_SHA
145/* Compare two certificates: they must be identical for
146 * this to work. NB: Although "cmp" operations are generally
147 * prototyped to take "const" arguments (eg. for use in
148 * STACKs), the way X509 handling is - these operations may
149 * involve ensuring the hashes are up-to-date and ensuring
150 * certain cert information is cached. So this is the point
151 * where the "depth-first" constification tree has to halt
152 * with an evil cast.
153 */
154int X509_cmp(const X509 *a, const X509 *b)
155{
156 /* ensure hash is valid */
157 X509_check_purpose((X509 *)a, -1, 0);
158 X509_check_purpose((X509 *)b, -1, 0);
159
160 return memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
161}
162#endif
163
164
165/* Case insensitive string comparision */
166static int nocase_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
167{
168 int i;
169
170 if (a->length != b->length)
171 return (a->length - b->length);
172
173 for (i=0; i<a->length; i++)
174 {
175 int ca, cb;
176
177 ca = tolower(a->data[i]);
178 cb = tolower(b->data[i]);
179
180 if (ca != cb)
181 return(ca-cb);
182 }
183 return 0;
184}
185
186/* Case insensitive string comparision with space normalization
187 * Space normalization - ignore leading, trailing spaces,
188 * multiple spaces between characters are replaced by single space
189 */
190static int nocase_spacenorm_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
191{
192 unsigned char *pa = NULL, *pb = NULL;
193 int la, lb;
194
195 la = a->length;
196 lb = b->length;
197 pa = a->data;
198 pb = b->data;
199
200 /* skip leading spaces */
201 while (la > 0 && isspace(*pa))
202 {
203 la--;
204 pa++;
205 }
206 while (lb > 0 && isspace(*pb))
207 {
208 lb--;
209 pb++;
210 }
211
212 /* skip trailing spaces */
213 while (la > 0 && isspace(pa[la-1]))
214 la--;
215 while (lb > 0 && isspace(pb[lb-1]))
216 lb--;
217
218 /* compare strings with space normalization */
219 while (la > 0 && lb > 0)
220 {
221 int ca, cb;
222
223 /* compare character */
224 ca = tolower(*pa);
225 cb = tolower(*pb);
226 if (ca != cb)
227 return (ca - cb);
228
229 pa++; pb++;
230 la--; lb--;
231
232 if (la <= 0 || lb <= 0)
233 break;
234
235 /* is white space next character ? */
236 if (isspace(*pa) && isspace(*pb))
237 {
238 /* skip remaining white spaces */
239 while (la > 0 && isspace(*pa))
240 {
241 la--;
242 pa++;
243 }
244 while (lb > 0 && isspace(*pb))
245 {
246 lb--;
247 pb++;
248 }
249 }
250 }
251 if (la > 0 || lb > 0)
252 return la - lb;
253
254 return 0;
255}
256
257static int asn1_string_memcmp(ASN1_STRING *a, ASN1_STRING *b)
258 {
259 int j;
260 j = a->length - b->length;
261 if (j)
262 return j;
263 return memcmp(a->data, b->data, a->length);
264 }
265
266#define STR_TYPE_CMP (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_UTF8STRING)
267
268int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
269 {
270 int i,j;
271 X509_NAME_ENTRY *na,*nb;
272
273 unsigned long nabit, nbbit;
274
275 j = sk_X509_NAME_ENTRY_num(a->entries)
276 - sk_X509_NAME_ENTRY_num(b->entries);
277 if (j)
278 return j;
279 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
280 {
281 na=sk_X509_NAME_ENTRY_value(a->entries,i);
282 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
283 j=na->value->type-nb->value->type;
284 if (j)
285 {
286 nabit = ASN1_tag2bit(na->value->type);
287 nbbit = ASN1_tag2bit(nb->value->type);
288 if (!(nabit & STR_TYPE_CMP) ||
289 !(nbbit & STR_TYPE_CMP))
290 return j;
291 j = asn1_string_memcmp(na->value, nb->value);
292 }
293 else if (na->value->type == V_ASN1_PRINTABLESTRING)
294 j=nocase_spacenorm_cmp(na->value, nb->value);
295 else if (na->value->type == V_ASN1_IA5STRING
296 && OBJ_obj2nid(na->object) == NID_pkcs9_emailAddress)
297 j=nocase_cmp(na->value, nb->value);
298 else
299 j = asn1_string_memcmp(na->value, nb->value);
300 if (j) return(j);
301 j=na->set-nb->set;
302 if (j) return(j);
303 }
304
305 /* We will check the object types after checking the values
306 * since the values will more often be different than the object
307 * types. */
308 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
309 {
310 na=sk_X509_NAME_ENTRY_value(a->entries,i);
311 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
312 j=OBJ_cmp(na->object,nb->object);
313 if (j) return(j);
314 }
315 return(0);
316 }
317
318#ifndef OPENSSL_NO_MD5
319/* I now DER encode the name and hash it. Since I cache the DER encoding,
320 * this is reasonably efficient. */
321unsigned long X509_NAME_hash(X509_NAME *x)
322 {
323 unsigned long ret=0;
324 unsigned char md[16];
325 EVP_MD_CTX md_ctx;
326
327 /* Make sure X509_NAME structure contains valid cached encoding */
328 i2d_X509_NAME(x,NULL);
329 EVP_MD_CTX_init(&md_ctx);
330 EVP_MD_CTX_set_flags(&md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
331 EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL);
332 EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length);
333 EVP_DigestFinal_ex(&md_ctx,md,NULL);
334 EVP_MD_CTX_cleanup(&md_ctx);
335
336 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
337 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
338 )&0xffffffffL;
339 return(ret);
340 }
341#endif
342
343/* Search a stack of X509 for a match */
344X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
345 ASN1_INTEGER *serial)
346 {
347 int i;
348 X509_CINF cinf;
349 X509 x,*x509=NULL;
350
351 if(!sk) return NULL;
352
353 x.cert_info= &cinf;
354 cinf.serialNumber=serial;
355 cinf.issuer=name;
356
357 for (i=0; i<sk_X509_num(sk); i++)
358 {
359 x509=sk_X509_value(sk,i);
360 if (X509_issuer_and_serial_cmp(x509,&x) == 0)
361 return(x509);
362 }
363 return(NULL);
364 }
365
366X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name)
367 {
368 X509 *x509;
369 int i;
370
371 for (i=0; i<sk_X509_num(sk); i++)
372 {
373 x509=sk_X509_value(sk,i);
374 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0)
375 return(x509);
376 }
377 return(NULL);
378 }
379
380EVP_PKEY *X509_get_pubkey(X509 *x)
381 {
382 if ((x == NULL) || (x->cert_info == NULL))
383 return(NULL);
384 return(X509_PUBKEY_get(x->cert_info->key));
385 }
386
387ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)
388 {
389 if(!x) return NULL;
390 return x->cert_info->key->public_key;
391 }
392
393int X509_check_private_key(X509 *x, EVP_PKEY *k)
394 {
395 EVP_PKEY *xk=NULL;
396 int ok=0;
397
398 xk=X509_get_pubkey(x);
399 if (xk->type != k->type)
400 {
401 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
402 goto err;
403 }
404 switch (k->type)
405 {
406#ifndef OPENSSL_NO_RSA
407 case EVP_PKEY_RSA:
408 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0
409 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)
410 {
411 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
412 goto err;
413 }
414 break;
415#endif
416#ifndef OPENSSL_NO_DSA
417 case EVP_PKEY_DSA:
418 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
419 {
420 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
421 goto err;
422 }
423 break;
424#endif
425#ifndef OPENSSL_NO_DH
426 case EVP_PKEY_DH:
427 /* No idea */
428 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
429 goto err;
430#endif
431 default:
432 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
433 goto err;
434 }
435
436 ok=1;
437err:
438 EVP_PKEY_free(xk);
439 return(ok);
440 }
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c
new file mode 100644
index 0000000000..51410cfd1a
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_d2.c
@@ -0,0 +1,107 @@
1/* crypto/x509/x509_d2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63
64#ifndef OPENSSL_NO_STDIO
65int X509_STORE_set_default_paths(X509_STORE *ctx)
66 {
67 X509_LOOKUP *lookup;
68
69 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
70 if (lookup == NULL) return(0);
71 X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
72
73 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
74 if (lookup == NULL) return(0);
75 X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
76
77 /* clear any errors */
78 ERR_clear_error();
79
80 return(1);
81 }
82
83int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
84 const char *path)
85 {
86 X509_LOOKUP *lookup;
87
88 if (file != NULL)
89 {
90 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
91 if (lookup == NULL) return(0);
92 if (X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM) != 1)
93 return(0);
94 }
95 if (path != NULL)
96 {
97 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
98 if (lookup == NULL) return(0);
99 if (X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM) != 1)
100 return(0);
101 }
102 if ((path == NULL) && (file == NULL))
103 return(0);
104 return(1);
105 }
106
107#endif
diff --git a/src/lib/libcrypto/x509/x509_def.c b/src/lib/libcrypto/x509/x509_def.c
new file mode 100644
index 0000000000..e0ac151a76
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_def.c
@@ -0,0 +1,81 @@
1/* crypto/x509/x509_def.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63
64const char *X509_get_default_private_dir(void)
65 { return(X509_PRIVATE_DIR); }
66
67const char *X509_get_default_cert_area(void)
68 { return(X509_CERT_AREA); }
69
70const char *X509_get_default_cert_dir(void)
71 { return(X509_CERT_DIR); }
72
73const char *X509_get_default_cert_file(void)
74 { return(X509_CERT_FILE); }
75
76const char *X509_get_default_cert_dir_env(void)
77 { return(X509_CERT_DIR_EVP); }
78
79const char *X509_get_default_cert_file_env(void)
80 { return(X509_CERT_FILE_EVP); }
81
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
new file mode 100644
index 0000000000..5bbf4acf76
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_err.c
@@ -0,0 +1,156 @@
1/* crypto/x509/x509_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/x509.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA X509_str_functs[]=
68 {
69{ERR_PACK(0,X509_F_ADD_CERT_DIR,0), "ADD_CERT_DIR"},
70{ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"},
71{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"},
72{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"},
73{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_DECODE,0), "NETSCAPE_SPKI_b64_decode"},
74{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_ENCODE,0), "NETSCAPE_SPKI_b64_encode"},
75{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"},
76{ERR_PACK(0,X509_F_X509_ADD_ATTR,0), "X509_ADD_ATTR"},
77{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_NID,0), "X509_ATTRIBUTE_create_by_NID"},
78{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,0), "X509_ATTRIBUTE_create_by_OBJ"},
79{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,0), "X509_ATTRIBUTE_create_by_txt"},
80{ERR_PACK(0,X509_F_X509_ATTRIBUTE_GET0_DATA,0), "X509_ATTRIBUTE_get0_data"},
81{ERR_PACK(0,X509_F_X509_ATTRIBUTE_SET1_DATA,0), "X509_ATTRIBUTE_set1_data"},
82{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"},
83{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"},
84{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"},
85{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"},
86{ERR_PACK(0,X509_F_X509_LOAD_CERT_CRL_FILE,0), "X509_load_cert_crl_file"},
87{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_load_cert_file"},
88{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_load_crl_file"},
89{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"},
90{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"},
91{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,0), "X509_NAME_ENTRY_create_by_txt"},
92{ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"},
93{ERR_PACK(0,X509_F_X509_NAME_ONELINE,0), "X509_NAME_oneline"},
94{ERR_PACK(0,X509_F_X509_NAME_PRINT,0), "X509_NAME_print"},
95{ERR_PACK(0,X509_F_X509_PRINT_FP,0), "X509_print_fp"},
96{ERR_PACK(0,X509_F_X509_PUBKEY_GET,0), "X509_PUBKEY_get"},
97{ERR_PACK(0,X509_F_X509_PUBKEY_SET,0), "X509_PUBKEY_set"},
98{ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"},
99{ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"},
100{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"},
101{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_add_cert"},
102{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_add_crl"},
103{ERR_PACK(0,X509_F_X509_STORE_CTX_INIT,0), "X509_STORE_CTX_init"},
104{ERR_PACK(0,X509_F_X509_STORE_CTX_NEW,0), "X509_STORE_CTX_new"},
105{ERR_PACK(0,X509_F_X509_STORE_CTX_PURPOSE_INHERIT,0), "X509_STORE_CTX_purpose_inherit"},
106{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"},
107{ERR_PACK(0,X509_F_X509_TRUST_ADD,0), "X509_TRUST_add"},
108{ERR_PACK(0,X509_F_X509_TRUST_SET,0), "X509_TRUST_set"},
109{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"},
110{0,NULL}
111 };
112
113static ERR_STRING_DATA X509_str_reasons[]=
114 {
115{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"},
116{X509_R_BASE64_DECODE_ERROR ,"base64 decode error"},
117{X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"},
118{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"},
119{X509_R_ERR_ASN1_LIB ,"err asn1 lib"},
120{X509_R_INVALID_DIRECTORY ,"invalid directory"},
121{X509_R_INVALID_FIELD_NAME ,"invalid field name"},
122{X509_R_INVALID_TRUST ,"invalid trust"},
123{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"},
124{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"},
125{X509_R_LOADING_CERT_DIR ,"loading cert dir"},
126{X509_R_LOADING_DEFAULTS ,"loading defaults"},
127{X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"},
128{X509_R_SHOULD_RETRY ,"should retry"},
129{X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"},
130{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"},
131{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"},
132{X509_R_UNKNOWN_NID ,"unknown nid"},
133{X509_R_UNKNOWN_PURPOSE_ID ,"unknown purpose id"},
134{X509_R_UNKNOWN_TRUST_ID ,"unknown trust id"},
135{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"},
136{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"},
137{X509_R_WRONG_TYPE ,"wrong type"},
138{0,NULL}
139 };
140
141#endif
142
143void ERR_load_X509_strings(void)
144 {
145 static int init=1;
146
147 if (init)
148 {
149 init=0;
150#ifndef OPENSSL_NO_ERR
151 ERR_load_strings(ERR_LIB_X509,X509_str_functs);
152 ERR_load_strings(ERR_LIB_X509,X509_str_reasons);
153#endif
154
155 }
156 }
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c
new file mode 100644
index 0000000000..e7fdacb5e4
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_ext.c
@@ -0,0 +1,210 @@
1/* crypto/x509/x509_ext.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68
69int X509_CRL_get_ext_count(X509_CRL *x)
70 {
71 return(X509v3_get_ext_count(x->crl->extensions));
72 }
73
74int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos)
75 {
76 return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos));
77 }
78
79int X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos)
80 {
81 return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos));
82 }
83
84int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos)
85 {
86 return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos));
87 }
88
89X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc)
90 {
91 return(X509v3_get_ext(x->crl->extensions,loc));
92 }
93
94X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
95 {
96 return(X509v3_delete_ext(x->crl->extensions,loc));
97 }
98
99void *X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx)
100{
101 return X509V3_get_d2i(x->crl->extensions, nid, crit, idx);
102}
103
104int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,
105 unsigned long flags)
106{
107 return X509V3_add1_i2d(&x->crl->extensions, nid, value, crit, flags);
108}
109
110int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
111 {
112 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
113 }
114
115int X509_get_ext_count(X509 *x)
116 {
117 return(X509v3_get_ext_count(x->cert_info->extensions));
118 }
119
120int X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
121 {
122 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos));
123 }
124
125int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
126 {
127 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos));
128 }
129
130int X509_get_ext_by_critical(X509 *x, int crit, int lastpos)
131 {
132 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos));
133 }
134
135X509_EXTENSION *X509_get_ext(X509 *x, int loc)
136 {
137 return(X509v3_get_ext(x->cert_info->extensions,loc));
138 }
139
140X509_EXTENSION *X509_delete_ext(X509 *x, int loc)
141 {
142 return(X509v3_delete_ext(x->cert_info->extensions,loc));
143 }
144
145int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
146 {
147 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
148 }
149
150void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
151{
152 return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx);
153}
154
155int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
156 unsigned long flags)
157{
158 return X509V3_add1_i2d(&x->cert_info->extensions, nid, value, crit,
159 flags);
160}
161
162int X509_REVOKED_get_ext_count(X509_REVOKED *x)
163 {
164 return(X509v3_get_ext_count(x->extensions));
165 }
166
167int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos)
168 {
169 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos));
170 }
171
172int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj,
173 int lastpos)
174 {
175 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos));
176 }
177
178int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos)
179 {
180 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos));
181 }
182
183X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc)
184 {
185 return(X509v3_get_ext(x->extensions,loc));
186 }
187
188X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc)
189 {
190 return(X509v3_delete_ext(x->extensions,loc));
191 }
192
193int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
194 {
195 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
196 }
197
198void *X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx)
199{
200 return X509V3_get_d2i(x->extensions, nid, crit, idx);
201}
202
203int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,
204 unsigned long flags)
205{
206 return X509V3_add1_i2d(&x->extensions, nid, value, crit, flags);
207}
208
209IMPLEMENT_STACK_OF(X509_EXTENSION)
210IMPLEMENT_ASN1_SET_OF(X509_EXTENSION)
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
new file mode 100644
index 0000000000..b780dae5e2
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -0,0 +1,557 @@
1/* crypto/x509/x509_lu.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/lhash.h>
62#include <openssl/x509.h>
63#include <openssl/x509v3.h>
64
65X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
66 {
67 X509_LOOKUP *ret;
68
69 ret=(X509_LOOKUP *)OPENSSL_malloc(sizeof(X509_LOOKUP));
70 if (ret == NULL) return NULL;
71
72 ret->init=0;
73 ret->skip=0;
74 ret->method=method;
75 ret->method_data=NULL;
76 ret->store_ctx=NULL;
77 if ((method->new_item != NULL) && !method->new_item(ret))
78 {
79 OPENSSL_free(ret);
80 return NULL;
81 }
82 return ret;
83 }
84
85void X509_LOOKUP_free(X509_LOOKUP *ctx)
86 {
87 if (ctx == NULL) return;
88 if ( (ctx->method != NULL) &&
89 (ctx->method->free != NULL))
90 ctx->method->free(ctx);
91 OPENSSL_free(ctx);
92 }
93
94int X509_LOOKUP_init(X509_LOOKUP *ctx)
95 {
96 if (ctx->method == NULL) return 0;
97 if (ctx->method->init != NULL)
98 return ctx->method->init(ctx);
99 else
100 return 1;
101 }
102
103int X509_LOOKUP_shutdown(X509_LOOKUP *ctx)
104 {
105 if (ctx->method == NULL) return 0;
106 if (ctx->method->shutdown != NULL)
107 return ctx->method->shutdown(ctx);
108 else
109 return 1;
110 }
111
112int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
113 char **ret)
114 {
115 if (ctx->method == NULL) return -1;
116 if (ctx->method->ctrl != NULL)
117 return ctx->method->ctrl(ctx,cmd,argc,argl,ret);
118 else
119 return 1;
120 }
121
122int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
123 X509_OBJECT *ret)
124 {
125 if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))
126 return X509_LU_FAIL;
127 if (ctx->skip) return 0;
128 return ctx->method->get_by_subject(ctx,type,name,ret);
129 }
130
131int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
132 ASN1_INTEGER *serial, X509_OBJECT *ret)
133 {
134 if ((ctx->method == NULL) ||
135 (ctx->method->get_by_issuer_serial == NULL))
136 return X509_LU_FAIL;
137 return ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret);
138 }
139
140int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
141 unsigned char *bytes, int len, X509_OBJECT *ret)
142 {
143 if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL))
144 return X509_LU_FAIL;
145 return ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret);
146 }
147
148int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len,
149 X509_OBJECT *ret)
150 {
151 if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL))
152 return X509_LU_FAIL;
153 return ctx->method->get_by_alias(ctx,type,str,len,ret);
154 }
155
156
157static int x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b)
158 {
159 int ret;
160
161 ret=((*a)->type - (*b)->type);
162 if (ret) return ret;
163 switch ((*a)->type)
164 {
165 case X509_LU_X509:
166 ret=X509_subject_name_cmp((*a)->data.x509,(*b)->data.x509);
167 break;
168 case X509_LU_CRL:
169 ret=X509_CRL_cmp((*a)->data.crl,(*b)->data.crl);
170 break;
171 default:
172 /* abort(); */
173 return 0;
174 }
175 return ret;
176 }
177
178X509_STORE *X509_STORE_new(void)
179 {
180 X509_STORE *ret;
181
182 if ((ret=(X509_STORE *)OPENSSL_malloc(sizeof(X509_STORE))) == NULL)
183 return NULL;
184 ret->objs = sk_X509_OBJECT_new(x509_object_cmp);
185 ret->cache=1;
186 ret->get_cert_methods=sk_X509_LOOKUP_new_null();
187 ret->verify=0;
188 ret->verify_cb=0;
189
190 ret->purpose = 0;
191 ret->trust = 0;
192
193 ret->flags = 0;
194
195 ret->get_issuer = 0;
196 ret->check_issued = 0;
197 ret->check_revocation = 0;
198 ret->get_crl = 0;
199 ret->check_crl = 0;
200 ret->cert_crl = 0;
201 ret->cleanup = 0;
202
203 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data);
204 ret->references=1;
205 ret->depth=0;
206 return ret;
207 }
208
209static void cleanup(X509_OBJECT *a)
210 {
211 if (a->type == X509_LU_X509)
212 {
213 X509_free(a->data.x509);
214 }
215 else if (a->type == X509_LU_CRL)
216 {
217 X509_CRL_free(a->data.crl);
218 }
219 else
220 {
221 /* abort(); */
222 }
223
224 OPENSSL_free(a);
225 }
226
227void X509_STORE_free(X509_STORE *vfy)
228 {
229 int i;
230 STACK_OF(X509_LOOKUP) *sk;
231 X509_LOOKUP *lu;
232
233 if (vfy == NULL)
234 return;
235
236 sk=vfy->get_cert_methods;
237 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
238 {
239 lu=sk_X509_LOOKUP_value(sk,i);
240 X509_LOOKUP_shutdown(lu);
241 X509_LOOKUP_free(lu);
242 }
243 sk_X509_LOOKUP_free(sk);
244 sk_X509_OBJECT_pop_free(vfy->objs, cleanup);
245
246 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data);
247 OPENSSL_free(vfy);
248 }
249
250X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
251 {
252 int i;
253 STACK_OF(X509_LOOKUP) *sk;
254 X509_LOOKUP *lu;
255
256 sk=v->get_cert_methods;
257 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
258 {
259 lu=sk_X509_LOOKUP_value(sk,i);
260 if (m == lu->method)
261 {
262 return lu;
263 }
264 }
265 /* a new one */
266 lu=X509_LOOKUP_new(m);
267 if (lu == NULL)
268 return NULL;
269 else
270 {
271 lu->store_ctx=v;
272 if (sk_X509_LOOKUP_push(v->get_cert_methods,lu))
273 return lu;
274 else
275 {
276 X509_LOOKUP_free(lu);
277 return NULL;
278 }
279 }
280 }
281
282int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
283 X509_OBJECT *ret)
284 {
285 X509_STORE *ctx=vs->ctx;
286 X509_LOOKUP *lu;
287 X509_OBJECT stmp,*tmp;
288 int i,j;
289
290 tmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name);
291
292 if (tmp == NULL)
293 {
294 for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)
295 {
296 lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);
297 j=X509_LOOKUP_by_subject(lu,type,name,&stmp);
298 if (j < 0)
299 {
300 vs->current_method=j;
301 return j;
302 }
303 else if (j)
304 {
305 tmp= &stmp;
306 break;
307 }
308 }
309 vs->current_method=0;
310 if (tmp == NULL)
311 return 0;
312 }
313
314/* if (ret->data.ptr != NULL)
315 X509_OBJECT_free_contents(ret); */
316
317 ret->type=tmp->type;
318 ret->data.ptr=tmp->data.ptr;
319
320 X509_OBJECT_up_ref_count(ret);
321
322 return 1;
323 }
324
325int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
326 {
327 X509_OBJECT *obj;
328 int ret=1;
329
330 if (x == NULL) return 0;
331 obj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
332 if (obj == NULL)
333 {
334 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);
335 return 0;
336 }
337 obj->type=X509_LU_X509;
338 obj->data.x509=x;
339
340 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
341
342 X509_OBJECT_up_ref_count(obj);
343
344
345 if (X509_OBJECT_retrieve_match(ctx->objs, obj))
346 {
347 X509_OBJECT_free_contents(obj);
348 OPENSSL_free(obj);
349 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
350 ret=0;
351 }
352 else sk_X509_OBJECT_push(ctx->objs, obj);
353
354 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
355
356 return ret;
357 }
358
359int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
360 {
361 X509_OBJECT *obj;
362 int ret=1;
363
364 if (x == NULL) return 0;
365 obj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
366 if (obj == NULL)
367 {
368 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE);
369 return 0;
370 }
371 obj->type=X509_LU_CRL;
372 obj->data.crl=x;
373
374 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
375
376 X509_OBJECT_up_ref_count(obj);
377
378 if (X509_OBJECT_retrieve_match(ctx->objs, obj))
379 {
380 X509_OBJECT_free_contents(obj);
381 OPENSSL_free(obj);
382 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
383 ret=0;
384 }
385 else sk_X509_OBJECT_push(ctx->objs, obj);
386
387 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
388
389 return ret;
390 }
391
392void X509_OBJECT_up_ref_count(X509_OBJECT *a)
393 {
394 switch (a->type)
395 {
396 case X509_LU_X509:
397 CRYPTO_add(&a->data.x509->references,1,CRYPTO_LOCK_X509);
398 break;
399 case X509_LU_CRL:
400 CRYPTO_add(&a->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
401 break;
402 }
403 }
404
405void X509_OBJECT_free_contents(X509_OBJECT *a)
406 {
407 switch (a->type)
408 {
409 case X509_LU_X509:
410 X509_free(a->data.x509);
411 break;
412 case X509_LU_CRL:
413 X509_CRL_free(a->data.crl);
414 break;
415 }
416 }
417
418int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
419 X509_NAME *name)
420 {
421 X509_OBJECT stmp;
422 X509 x509_s;
423 X509_CINF cinf_s;
424 X509_CRL crl_s;
425 X509_CRL_INFO crl_info_s;
426
427 stmp.type=type;
428 switch (type)
429 {
430 case X509_LU_X509:
431 stmp.data.x509= &x509_s;
432 x509_s.cert_info= &cinf_s;
433 cinf_s.subject=name;
434 break;
435 case X509_LU_CRL:
436 stmp.data.crl= &crl_s;
437 crl_s.crl= &crl_info_s;
438 crl_info_s.issuer=name;
439 break;
440 default:
441 /* abort(); */
442 return -1;
443 }
444
445 return sk_X509_OBJECT_find(h,&stmp);
446 }
447
448X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type,
449 X509_NAME *name)
450{
451 int idx;
452 idx = X509_OBJECT_idx_by_subject(h, type, name);
453 if (idx==-1) return NULL;
454 return sk_X509_OBJECT_value(h, idx);
455}
456
457X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x)
458{
459 int idx, i;
460 X509_OBJECT *obj;
461 idx = sk_X509_OBJECT_find(h, x);
462 if (idx == -1) return NULL;
463 if (x->type != X509_LU_X509) return sk_X509_OBJECT_value(h, idx);
464 for (i = idx; i < sk_X509_OBJECT_num(h); i++)
465 {
466 obj = sk_X509_OBJECT_value(h, i);
467 if (x509_object_cmp((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x))
468 return NULL;
469 if ((x->type != X509_LU_X509) || !X509_cmp(obj->data.x509, x->data.x509))
470 return obj;
471 }
472 return NULL;
473}
474
475
476/* Try to get issuer certificate from store. Due to limitations
477 * of the API this can only retrieve a single certificate matching
478 * a given subject name. However it will fill the cache with all
479 * matching certificates, so we can examine the cache for all
480 * matches.
481 *
482 * Return values are:
483 * 1 lookup successful.
484 * 0 certificate not found.
485 * -1 some other error.
486 */
487
488
489int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
490{
491 X509_NAME *xn;
492 X509_OBJECT obj, *pobj;
493 int i, ok, idx;
494 xn=X509_get_issuer_name(x);
495 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
496 if (ok != X509_LU_X509)
497 {
498 if (ok == X509_LU_RETRY)
499 {
500 X509_OBJECT_free_contents(&obj);
501 X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);
502 return -1;
503 }
504 else if (ok != X509_LU_FAIL)
505 {
506 X509_OBJECT_free_contents(&obj);
507 /* not good :-(, break anyway */
508 return -1;
509 }
510 return 0;
511 }
512 /* If certificate matches all OK */
513 if (ctx->check_issued(ctx, x, obj.data.x509))
514 {
515 *issuer = obj.data.x509;
516 return 1;
517 }
518 X509_OBJECT_free_contents(&obj);
519 /* Else find index of first matching cert */
520 idx = X509_OBJECT_idx_by_subject(ctx->ctx->objs, X509_LU_X509, xn);
521 /* This shouldn't normally happen since we already have one match */
522 if (idx == -1) return 0;
523
524 /* Look through all matching certificates for a suitable issuer */
525 for (i = idx; i < sk_X509_OBJECT_num(ctx->ctx->objs); i++)
526 {
527 pobj = sk_X509_OBJECT_value(ctx->ctx->objs, i);
528 /* See if we've ran out of matches */
529 if (pobj->type != X509_LU_X509) return 0;
530 if (X509_NAME_cmp(xn, X509_get_subject_name(pobj->data.x509))) return 0;
531 if (ctx->check_issued(ctx, x, pobj->data.x509))
532 {
533 *issuer = pobj->data.x509;
534 X509_OBJECT_up_ref_count(pobj);
535 return 1;
536 }
537 }
538 return 0;
539}
540
541void X509_STORE_set_flags(X509_STORE *ctx, long flags)
542 {
543 ctx->flags |= flags;
544 }
545
546int X509_STORE_set_purpose(X509_STORE *ctx, int purpose)
547 {
548 return X509_PURPOSE_set(&ctx->purpose, purpose);
549 }
550
551int X509_STORE_set_trust(X509_STORE *ctx, int trust)
552 {
553 return X509_TRUST_set(&ctx->trust, trust);
554 }
555
556IMPLEMENT_STACK_OF(X509_LOOKUP)
557IMPLEMENT_STACK_OF(X509_OBJECT)
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
new file mode 100644
index 0000000000..1e718f76eb
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_obj.c
@@ -0,0 +1,226 @@
1/* crypto/x509/x509_obj.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/lhash.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#include <openssl/buffer.h>
65
66char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
67 {
68 X509_NAME_ENTRY *ne;
69int i;
70 int n,lold,l,l1,l2,num,j,type;
71 const char *s;
72 char *p;
73 unsigned char *q;
74 BUF_MEM *b=NULL;
75 static char hex[17]="0123456789ABCDEF";
76 int gs_doit[4];
77 char tmp_buf[80];
78#ifdef CHARSET_EBCDIC
79 char ebcdic_buf[1024];
80#endif
81
82 if (buf == NULL)
83 {
84 if ((b=BUF_MEM_new()) == NULL) goto err;
85 if (!BUF_MEM_grow(b,200)) goto err;
86 b->data[0]='\0';
87 len=200;
88 }
89 if (a == NULL)
90 {
91 if(b)
92 {
93 buf=b->data;
94 OPENSSL_free(b);
95 }
96 strncpy(buf,"NO X509_NAME",len);
97 buf[len-1]='\0';
98 return buf;
99 }
100
101 len--; /* space for '\0' */
102 l=0;
103 for (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++)
104 {
105 ne=sk_X509_NAME_ENTRY_value(a->entries,i);
106 n=OBJ_obj2nid(ne->object);
107 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL))
108 {
109 i2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object);
110 s=tmp_buf;
111 }
112 l1=strlen(s);
113
114 type=ne->value->type;
115 num=ne->value->length;
116 q=ne->value->data;
117#ifdef CHARSET_EBCDIC
118 if (type == V_ASN1_GENERALSTRING ||
119 type == V_ASN1_VISIBLESTRING ||
120 type == V_ASN1_PRINTABLESTRING ||
121 type == V_ASN1_TELETEXSTRING ||
122 type == V_ASN1_VISIBLESTRING ||
123 type == V_ASN1_IA5STRING) {
124 ascii2ebcdic(ebcdic_buf, q,
125 (num > sizeof ebcdic_buf)
126 ? sizeof ebcdic_buf : num);
127 q=ebcdic_buf;
128 }
129#endif
130
131 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))
132 {
133 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0;
134 for (j=0; j<num; j++)
135 if (q[j] != 0) gs_doit[j&3]=1;
136
137 if (gs_doit[0]|gs_doit[1]|gs_doit[2])
138 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
139 else
140 {
141 gs_doit[0]=gs_doit[1]=gs_doit[2]=0;
142 gs_doit[3]=1;
143 }
144 }
145 else
146 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
147
148 for (l2=j=0; j<num; j++)
149 {
150 if (!gs_doit[j&3]) continue;
151 l2++;
152#ifndef CHARSET_EBCDIC
153 if ((q[j] < ' ') || (q[j] > '~')) l2+=3;
154#else
155 if ((os_toascii[q[j]] < os_toascii[' ']) ||
156 (os_toascii[q[j]] > os_toascii['~'])) l2+=3;
157#endif
158 }
159
160 lold=l;
161 l+=1+l1+1+l2;
162 if (b != NULL)
163 {
164 if (!BUF_MEM_grow(b,l+1)) goto err;
165 p= &(b->data[lold]);
166 }
167 else if (l > len)
168 {
169 break;
170 }
171 else
172 p= &(buf[lold]);
173 *(p++)='/';
174 memcpy(p,s,(unsigned int)l1); p+=l1;
175 *(p++)='=';
176
177#ifndef CHARSET_EBCDIC /* q was assigned above already. */
178 q=ne->value->data;
179#endif
180
181 for (j=0; j<num; j++)
182 {
183 if (!gs_doit[j&3]) continue;
184#ifndef CHARSET_EBCDIC
185 n=q[j];
186 if ((n < ' ') || (n > '~'))
187 {
188 *(p++)='\\';
189 *(p++)='x';
190 *(p++)=hex[(n>>4)&0x0f];
191 *(p++)=hex[n&0x0f];
192 }
193 else
194 *(p++)=n;
195#else
196 n=os_toascii[q[j]];
197 if ((n < os_toascii[' ']) ||
198 (n > os_toascii['~']))
199 {
200 *(p++)='\\';
201 *(p++)='x';
202 *(p++)=hex[(n>>4)&0x0f];
203 *(p++)=hex[n&0x0f];
204 }
205 else
206 *(p++)=q[j];
207#endif
208 }
209 *p='\0';
210 }
211 if (b != NULL)
212 {
213 p=b->data;
214 OPENSSL_free(b);
215 }
216 else
217 p=buf;
218 if (i == 0)
219 *p = '\0';
220 return(p);
221err:
222 X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE);
223 if (b != NULL) BUF_MEM_free(b);
224 return(NULL);
225 }
226
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
new file mode 100644
index 0000000000..fb8a78dabe
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_r2x.c
@@ -0,0 +1,112 @@
1/* crypto/x509/x509_r2x.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/asn1.h>
64#include <openssl/x509.h>
65#include <openssl/objects.h>
66#include <openssl/buffer.h>
67
68X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
69 {
70 X509 *ret=NULL;
71 X509_CINF *xi=NULL;
72 X509_NAME *xn;
73
74 if ((ret=X509_new()) == NULL)
75 {
76 X509err(X509_F_X509_REQ_TO_X509,ERR_R_MALLOC_FAILURE);
77 goto err;
78 }
79
80 /* duplicate the request */
81 xi=ret->cert_info;
82
83 if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0)
84 {
85 if ((xi->version=M_ASN1_INTEGER_new()) == NULL) goto err;
86 if (!ASN1_INTEGER_set(xi->version,2)) goto err;
87/* xi->extensions=ri->attributes; <- bad, should not ever be done
88 ri->attributes=NULL; */
89 }
90
91 xn=X509_REQ_get_subject_name(r);
92 X509_set_subject_name(ret,X509_NAME_dup(xn));
93 X509_set_issuer_name(ret,X509_NAME_dup(xn));
94
95 if (X509_gmtime_adj(xi->validity->notBefore,0) == NULL)
96 goto err;
97 if (X509_gmtime_adj(xi->validity->notAfter,(long)60*60*24*days) == NULL)
98 goto err;
99
100 X509_set_pubkey(ret,X509_REQ_get_pubkey(r));
101
102 if (!X509_sign(ret,pkey,EVP_md5()))
103 goto err;
104 if (0)
105 {
106err:
107 X509_free(ret);
108 ret=NULL;
109 }
110 return(ret);
111 }
112
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
new file mode 100644
index 0000000000..59fc6ca548
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -0,0 +1,279 @@
1/* crypto/x509/x509_req.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/asn1.h>
64#include <openssl/x509.h>
65#include <openssl/objects.h>
66#include <openssl/buffer.h>
67#include <openssl/pem.h>
68
69X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
70 {
71 X509_REQ *ret;
72 X509_REQ_INFO *ri;
73 int i;
74 EVP_PKEY *pktmp;
75
76 ret=X509_REQ_new();
77 if (ret == NULL)
78 {
79 X509err(X509_F_X509_TO_X509_REQ,ERR_R_MALLOC_FAILURE);
80 goto err;
81 }
82
83 ri=ret->req_info;
84
85 ri->version->length=1;
86 ri->version->data=(unsigned char *)OPENSSL_malloc(1);
87 if (ri->version->data == NULL) goto err;
88 ri->version->data[0]=0; /* version == 0 */
89
90 if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x)))
91 goto err;
92
93 pktmp = X509_get_pubkey(x);
94 i=X509_REQ_set_pubkey(ret,pktmp);
95 EVP_PKEY_free(pktmp);
96 if (!i) goto err;
97
98 if (pkey != NULL)
99 {
100 if (!X509_REQ_sign(ret,pkey,md))
101 goto err;
102 }
103 return(ret);
104err:
105 X509_REQ_free(ret);
106 return(NULL);
107 }
108
109EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)
110 {
111 if ((req == NULL) || (req->req_info == NULL))
112 return(NULL);
113 return(X509_PUBKEY_get(req->req_info->pubkey));
114 }
115
116/* It seems several organisations had the same idea of including a list of
117 * extensions in a certificate request. There are at least two OIDs that are
118 * used and there may be more: so the list is configurable.
119 */
120
121static int ext_nid_list[] = { NID_ext_req, NID_ms_ext_req, NID_undef};
122
123static int *ext_nids = ext_nid_list;
124
125int X509_REQ_extension_nid(int req_nid)
126{
127 int i, nid;
128 for(i = 0; ; i++) {
129 nid = ext_nids[i];
130 if(nid == NID_undef) return 0;
131 else if (req_nid == nid) return 1;
132 }
133}
134
135int *X509_REQ_get_extension_nids(void)
136{
137 return ext_nids;
138}
139
140void X509_REQ_set_extension_nids(int *nids)
141{
142 ext_nids = nids;
143}
144
145STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
146 {
147 X509_ATTRIBUTE *attr;
148 ASN1_TYPE *ext = NULL;
149 int idx, *pnid;
150 unsigned char *p;
151
152 if ((req == NULL) || (req->req_info == NULL) || !ext_nids)
153 return(NULL);
154 for (pnid = ext_nids; *pnid != NID_undef; pnid++)
155 {
156 idx = X509_REQ_get_attr_by_NID(req, *pnid, -1);
157 if (idx == -1)
158 continue;
159 attr = X509_REQ_get_attr(req, idx);
160 if(attr->single) ext = attr->value.single;
161 else if(sk_ASN1_TYPE_num(attr->value.set))
162 ext = sk_ASN1_TYPE_value(attr->value.set, 0);
163 break;
164 }
165 if(!ext || (ext->type != V_ASN1_SEQUENCE))
166 return NULL;
167 p = ext->value.sequence->data;
168 return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
169 ext->value.sequence->length,
170 d2i_X509_EXTENSION, X509_EXTENSION_free,
171 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
172 }
173
174/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs
175 * in case we want to create a non standard one.
176 */
177
178int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
179 int nid)
180{
181 unsigned char *p = NULL, *q;
182 long len;
183 ASN1_TYPE *at = NULL;
184 X509_ATTRIBUTE *attr = NULL;
185 if(!(at = ASN1_TYPE_new()) ||
186 !(at->value.sequence = ASN1_STRING_new())) goto err;
187
188 at->type = V_ASN1_SEQUENCE;
189 /* Generate encoding of extensions */
190 len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION,
191 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
192 if(!(p = OPENSSL_malloc(len))) goto err;
193 q = p;
194 i2d_ASN1_SET_OF_X509_EXTENSION(exts, &q, i2d_X509_EXTENSION,
195 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
196 at->value.sequence->data = p;
197 p = NULL;
198 at->value.sequence->length = len;
199 if(!(attr = X509_ATTRIBUTE_new())) goto err;
200 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
201 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err;
202 at = NULL;
203 attr->single = 0;
204 attr->object = OBJ_nid2obj(nid);
205 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
206 return 1;
207 err:
208 if(p) OPENSSL_free(p);
209 X509_ATTRIBUTE_free(attr);
210 ASN1_TYPE_free(at);
211 return 0;
212}
213/* This is the normal usage: use the "official" OID */
214int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts)
215{
216 return X509_REQ_add_extensions_nid(req, exts, NID_ext_req);
217}
218
219/* Request attribute functions */
220
221int X509_REQ_get_attr_count(const X509_REQ *req)
222{
223 return X509at_get_attr_count(req->req_info->attributes);
224}
225
226int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
227 int lastpos)
228{
229 return X509at_get_attr_by_NID(req->req_info->attributes, nid, lastpos);
230}
231
232int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
233 int lastpos)
234{
235 return X509at_get_attr_by_OBJ(req->req_info->attributes, obj, lastpos);
236}
237
238X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc)
239{
240 return X509at_get_attr(req->req_info->attributes, loc);
241}
242
243X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc)
244{
245 return X509at_delete_attr(req->req_info->attributes, loc);
246}
247
248int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr)
249{
250 if(X509at_add1_attr(&req->req_info->attributes, attr)) return 1;
251 return 0;
252}
253
254int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
255 const ASN1_OBJECT *obj, int type,
256 const unsigned char *bytes, int len)
257{
258 if(X509at_add1_attr_by_OBJ(&req->req_info->attributes, obj,
259 type, bytes, len)) return 1;
260 return 0;
261}
262
263int X509_REQ_add1_attr_by_NID(X509_REQ *req,
264 int nid, int type,
265 const unsigned char *bytes, int len)
266{
267 if(X509at_add1_attr_by_NID(&req->req_info->attributes, nid,
268 type, bytes, len)) return 1;
269 return 0;
270}
271
272int X509_REQ_add1_attr_by_txt(X509_REQ *req,
273 const char *attrname, int type,
274 const unsigned char *bytes, int len)
275{
276 if(X509at_add1_attr_by_txt(&req->req_info->attributes, attrname,
277 type, bytes, len)) return 1;
278 return 0;
279}
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c
new file mode 100644
index 0000000000..aaf61ca062
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_set.c
@@ -0,0 +1,150 @@
1/* crypto/x509/x509_set.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_set_version(X509 *x, long version)
67 {
68 if (x == NULL) return(0);
69 if (x->cert_info->version == NULL)
70 {
71 if ((x->cert_info->version=M_ASN1_INTEGER_new()) == NULL)
72 return(0);
73 }
74 return(ASN1_INTEGER_set(x->cert_info->version,version));
75 }
76
77int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
78 {
79 ASN1_INTEGER *in;
80
81 if (x == NULL) return(0);
82 in=x->cert_info->serialNumber;
83 if (in != serial)
84 {
85 in=M_ASN1_INTEGER_dup(serial);
86 if (in != NULL)
87 {
88 M_ASN1_INTEGER_free(x->cert_info->serialNumber);
89 x->cert_info->serialNumber=in;
90 }
91 }
92 return(in != NULL);
93 }
94
95int X509_set_issuer_name(X509 *x, X509_NAME *name)
96 {
97 if ((x == NULL) || (x->cert_info == NULL)) return(0);
98 return(X509_NAME_set(&x->cert_info->issuer,name));
99 }
100
101int X509_set_subject_name(X509 *x, X509_NAME *name)
102 {
103 if ((x == NULL) || (x->cert_info == NULL)) return(0);
104 return(X509_NAME_set(&x->cert_info->subject,name));
105 }
106
107int X509_set_notBefore(X509 *x, ASN1_TIME *tm)
108 {
109 ASN1_TIME *in;
110
111 if ((x == NULL) || (x->cert_info->validity == NULL)) return(0);
112 in=x->cert_info->validity->notBefore;
113 if (in != tm)
114 {
115 in=M_ASN1_TIME_dup(tm);
116 if (in != NULL)
117 {
118 M_ASN1_TIME_free(x->cert_info->validity->notBefore);
119 x->cert_info->validity->notBefore=in;
120 }
121 }
122 return(in != NULL);
123 }
124
125int X509_set_notAfter(X509 *x, ASN1_TIME *tm)
126 {
127 ASN1_TIME *in;
128
129 if ((x == NULL) || (x->cert_info->validity == NULL)) return(0);
130 in=x->cert_info->validity->notAfter;
131 if (in != tm)
132 {
133 in=M_ASN1_TIME_dup(tm);
134 if (in != NULL)
135 {
136 M_ASN1_TIME_free(x->cert_info->validity->notAfter);
137 x->cert_info->validity->notAfter=in;
138 }
139 }
140 return(in != NULL);
141 }
142
143int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
144 {
145 if ((x == NULL) || (x->cert_info == NULL)) return(0);
146 return(X509_PUBKEY_set(&(x->cert_info->key),pkey));
147 }
148
149
150
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
new file mode 100644
index 0000000000..881252608d
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -0,0 +1,287 @@
1/* x509_trs.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static int tr_cmp(const X509_TRUST * const *a,
65 const X509_TRUST * const *b);
66static void trtable_free(X509_TRUST *p);
67
68static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
69static int trust_1oid(X509_TRUST *trust, X509 *x, int flags);
70static int trust_compat(X509_TRUST *trust, X509 *x, int flags);
71
72static int obj_trust(int id, X509 *x, int flags);
73static int (*default_trust)(int id, X509 *x, int flags) = obj_trust;
74
75/* WARNING: the following table should be kept in order of trust
76 * and without any gaps so we can just subtract the minimum trust
77 * value to get an index into the table
78 */
79
80static X509_TRUST trstandard[] = {
81{X509_TRUST_COMPAT, 0, trust_compat, "compatible", 0, NULL},
82{X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL},
83{X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Server", NID_server_auth, NULL},
84{X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},
85{X509_TRUST_OBJECT_SIGN, 0, trust_1oidany, "Object Signer", NID_code_sign, NULL},
86{X509_TRUST_OCSP_SIGN, 0, trust_1oid, "OCSP responder", NID_OCSP_sign, NULL},
87{X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL}
88};
89
90#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST))
91
92IMPLEMENT_STACK_OF(X509_TRUST)
93
94static STACK_OF(X509_TRUST) *trtable = NULL;
95
96static int tr_cmp(const X509_TRUST * const *a,
97 const X509_TRUST * const *b)
98{
99 return (*a)->trust - (*b)->trust;
100}
101
102int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
103{
104 int (*oldtrust)(int , X509 *, int);
105 oldtrust = default_trust;
106 default_trust = trust;
107 return oldtrust;
108}
109
110
111int X509_check_trust(X509 *x, int id, int flags)
112{
113 X509_TRUST *pt;
114 int idx;
115 if(id == -1) return 1;
116 idx = X509_TRUST_get_by_id(id);
117 if(idx == -1) return default_trust(id, x, flags);
118 pt = X509_TRUST_get0(idx);
119 return pt->check_trust(pt, x, flags);
120}
121
122int X509_TRUST_get_count(void)
123{
124 if(!trtable) return X509_TRUST_COUNT;
125 return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT;
126}
127
128X509_TRUST * X509_TRUST_get0(int idx)
129{
130 if(idx < 0) return NULL;
131 if(idx < X509_TRUST_COUNT) return trstandard + idx;
132 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
133}
134
135int X509_TRUST_get_by_id(int id)
136{
137 X509_TRUST tmp;
138 int idx;
139 if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
140 return id - X509_TRUST_MIN;
141 tmp.trust = id;
142 if(!trtable) return -1;
143 idx = sk_X509_TRUST_find(trtable, &tmp);
144 if(idx == -1) return -1;
145 return idx + X509_TRUST_COUNT;
146}
147
148int X509_TRUST_set(int *t, int trust)
149{
150 if(X509_TRUST_get_by_id(trust) == -1) {
151 X509err(X509_F_X509_TRUST_SET, X509_R_INVALID_TRUST);
152 return 0;
153 }
154 *t = trust;
155 return 1;
156}
157
158int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
159 char *name, int arg1, void *arg2)
160{
161 int idx;
162 X509_TRUST *trtmp;
163 /* This is set according to what we change: application can't set it */
164 flags &= ~X509_TRUST_DYNAMIC;
165 /* This will always be set for application modified trust entries */
166 flags |= X509_TRUST_DYNAMIC_NAME;
167 /* Get existing entry if any */
168 idx = X509_TRUST_get_by_id(id);
169 /* Need a new entry */
170 if(idx == -1) {
171 if(!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) {
172 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
173 return 0;
174 }
175 trtmp->flags = X509_TRUST_DYNAMIC;
176 } else trtmp = X509_TRUST_get0(idx);
177
178 /* OPENSSL_free existing name if dynamic */
179 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name);
180 /* dup supplied name */
181 if(!(trtmp->name = BUF_strdup(name))) {
182 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 /* Keep the dynamic flag of existing entry */
186 trtmp->flags &= X509_TRUST_DYNAMIC;
187 /* Set all other flags */
188 trtmp->flags |= flags;
189
190 trtmp->trust = id;
191 trtmp->check_trust = ck;
192 trtmp->arg1 = arg1;
193 trtmp->arg2 = arg2;
194
195 /* If its a new entry manage the dynamic table */
196 if(idx == -1) {
197 if(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
198 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
199 return 0;
200 }
201 if (!sk_X509_TRUST_push(trtable, trtmp)) {
202 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
203 return 0;
204 }
205 }
206 return 1;
207}
208
209static void trtable_free(X509_TRUST *p)
210 {
211 if(!p) return;
212 if (p->flags & X509_TRUST_DYNAMIC)
213 {
214 if (p->flags & X509_TRUST_DYNAMIC_NAME)
215 OPENSSL_free(p->name);
216 OPENSSL_free(p);
217 }
218 }
219
220void X509_TRUST_cleanup(void)
221{
222 int i;
223 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i);
224 sk_X509_TRUST_pop_free(trtable, trtable_free);
225 trtable = NULL;
226}
227
228int X509_TRUST_get_flags(X509_TRUST *xp)
229{
230 return xp->flags;
231}
232
233char *X509_TRUST_get0_name(X509_TRUST *xp)
234{
235 return xp->name;
236}
237
238int X509_TRUST_get_trust(X509_TRUST *xp)
239{
240 return xp->trust;
241}
242
243static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags)
244{
245 if(x->aux && (x->aux->trust || x->aux->reject))
246 return obj_trust(trust->arg1, x, flags);
247 /* we don't have any trust settings: for compatibility
248 * we return trusted if it is self signed
249 */
250 return trust_compat(trust, x, flags);
251}
252
253static int trust_1oid(X509_TRUST *trust, X509 *x, int flags)
254{
255 if(x->aux) return obj_trust(trust->arg1, x, flags);
256 return X509_TRUST_UNTRUSTED;
257}
258
259static int trust_compat(X509_TRUST *trust, X509 *x, int flags)
260{
261 X509_check_purpose(x, -1, 0);
262 if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED;
263 else return X509_TRUST_UNTRUSTED;
264}
265
266static int obj_trust(int id, X509 *x, int flags)
267{
268 ASN1_OBJECT *obj;
269 int i;
270 X509_CERT_AUX *ax;
271 ax = x->aux;
272 if(!ax) return X509_TRUST_UNTRUSTED;
273 if(ax->reject) {
274 for(i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
275 obj = sk_ASN1_OBJECT_value(ax->reject, i);
276 if(OBJ_obj2nid(obj) == id) return X509_TRUST_REJECTED;
277 }
278 }
279 if(ax->trust) {
280 for(i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
281 obj = sk_ASN1_OBJECT_value(ax->trust, i);
282 if(OBJ_obj2nid(obj) == id) return X509_TRUST_TRUSTED;
283 }
284 }
285 return X509_TRUST_UNTRUSTED;
286}
287
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c
new file mode 100644
index 0000000000..f19e66a238
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_txt.c
@@ -0,0 +1,165 @@
1/* crypto/x509/x509_txt.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include <errno.h>
62
63#include "cryptlib.h"
64#include <openssl/lhash.h>
65#include <openssl/buffer.h>
66#include <openssl/evp.h>
67#include <openssl/asn1.h>
68#include <openssl/x509.h>
69#include <openssl/objects.h>
70
71const char *X509_verify_cert_error_string(long n)
72 {
73 static char buf[100];
74
75 switch ((int)n)
76 {
77 case X509_V_OK:
78 return("ok");
79 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
80 return("unable to get issuer certificate");
81 case X509_V_ERR_UNABLE_TO_GET_CRL:
82 return("unable to get certificate CRL");
83 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
84 return("unable to decrypt certificate's signature");
85 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
86 return("unable to decrypt CRL's signature");
87 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
88 return("unable to decode issuer public key");
89 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
90 return("certificate signature failure");
91 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
92 return("CRL signature failure");
93 case X509_V_ERR_CERT_NOT_YET_VALID:
94 return("certificate is not yet valid");
95 case X509_V_ERR_CRL_NOT_YET_VALID:
96 return("CRL is not yet valid");
97 case X509_V_ERR_CERT_HAS_EXPIRED:
98 return("certificate has expired");
99 case X509_V_ERR_CRL_HAS_EXPIRED:
100 return("CRL has expired");
101 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
102 return("format error in certificate's notBefore field");
103 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
104 return("format error in certificate's notAfter field");
105 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
106 return("format error in CRL's lastUpdate field");
107 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
108 return("format error in CRL's nextUpdate field");
109 case X509_V_ERR_OUT_OF_MEM:
110 return("out of memory");
111 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
112 return("self signed certificate");
113 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
114 return("self signed certificate in certificate chain");
115 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
116 return("unable to get local issuer certificate");
117 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
118 return("unable to verify the first certificate");
119 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
120 return("certificate chain too long");
121 case X509_V_ERR_CERT_REVOKED:
122 return("certificate revoked");
123 case X509_V_ERR_INVALID_CA:
124 return ("invalid CA certificate");
125 case X509_V_ERR_INVALID_NON_CA:
126 return ("invalid non-CA certificate (has CA markings)");
127 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
128 return ("path length constraint exceeded");
129 case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
130 return("proxy path length constraint exceeded");
131 case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
132 return("proxy cerificates not allowed, please set the appropriate flag");
133 case X509_V_ERR_INVALID_PURPOSE:
134 return ("unsupported certificate purpose");
135 case X509_V_ERR_CERT_UNTRUSTED:
136 return ("certificate not trusted");
137 case X509_V_ERR_CERT_REJECTED:
138 return ("certificate rejected");
139 case X509_V_ERR_APPLICATION_VERIFICATION:
140 return("application verification failure");
141 case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
142 return("subject issuer mismatch");
143 case X509_V_ERR_AKID_SKID_MISMATCH:
144 return("authority and subject key identifier mismatch");
145 case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
146 return("authority and issuer serial number mismatch");
147 case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
148 return("key usage does not include certificate signing");
149 case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
150 return("unable to get CRL issuer certificate");
151 case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
152 return("unhandled critical extension");
153 case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
154 return("key usage does not include CRL signing");
155 case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE:
156 return("key usage does not include digital signature");
157 case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
158 return("unhandled critical CRL extension");
159 default:
160 BIO_snprintf(buf,sizeof buf,"error number %ld",n);
161 return(buf);
162 }
163 }
164
165
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
new file mode 100644
index 0000000000..67b1796a92
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -0,0 +1,268 @@
1/* crypto/x509/x509_v3.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
69 {
70 if (x == NULL) return(0);
71 return(sk_X509_EXTENSION_num(x));
72 }
73
74int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid,
75 int lastpos)
76 {
77 ASN1_OBJECT *obj;
78
79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2);
81 return(X509v3_get_ext_by_OBJ(x,obj,lastpos));
82 }
83
84int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj,
85 int lastpos)
86 {
87 int n;
88 X509_EXTENSION *ex;
89
90 if (sk == NULL) return(-1);
91 lastpos++;
92 if (lastpos < 0)
93 lastpos=0;
94 n=sk_X509_EXTENSION_num(sk);
95 for ( ; lastpos < n; lastpos++)
96 {
97 ex=sk_X509_EXTENSION_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos);
100 }
101 return(-1);
102 }
103
104int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
105 int lastpos)
106 {
107 int n;
108 X509_EXTENSION *ex;
109
110 if (sk == NULL) return(-1);
111 lastpos++;
112 if (lastpos < 0)
113 lastpos=0;
114 n=sk_X509_EXTENSION_num(sk);
115 for ( ; lastpos < n; lastpos++)
116 {
117 ex=sk_X509_EXTENSION_value(sk,lastpos);
118 if ( ((ex->critical > 0) && crit) ||
119 ((ex->critical <= 0) && !crit))
120 return(lastpos);
121 }
122 return(-1);
123 }
124
125X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc)
126 {
127 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
128 return NULL;
129 else
130 return sk_X509_EXTENSION_value(x,loc);
131 }
132
133X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)
134 {
135 X509_EXTENSION *ret;
136
137 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
138 return(NULL);
139 ret=sk_X509_EXTENSION_delete(x,loc);
140 return(ret);
141 }
142
143STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
144 X509_EXTENSION *ex, int loc)
145 {
146 X509_EXTENSION *new_ex=NULL;
147 int n;
148 STACK_OF(X509_EXTENSION) *sk=NULL;
149
150 if ((x != NULL) && (*x == NULL))
151 {
152 if ((sk=sk_X509_EXTENSION_new_null()) == NULL)
153 goto err;
154 }
155 else
156 sk= *x;
157
158 n=sk_X509_EXTENSION_num(sk);
159 if (loc > n) loc=n;
160 else if (loc < 0) loc=n;
161
162 if ((new_ex=X509_EXTENSION_dup(ex)) == NULL)
163 goto err2;
164 if (!sk_X509_EXTENSION_insert(sk,new_ex,loc))
165 goto err;
166 if ((x != NULL) && (*x == NULL))
167 *x=sk;
168 return(sk);
169err:
170 X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE);
171err2:
172 if (new_ex != NULL) X509_EXTENSION_free(new_ex);
173 if (sk != NULL) sk_X509_EXTENSION_free(sk);
174 return(NULL);
175 }
176
177X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
178 int crit, ASN1_OCTET_STRING *data)
179 {
180 ASN1_OBJECT *obj;
181 X509_EXTENSION *ret;
182
183 obj=OBJ_nid2obj(nid);
184 if (obj == NULL)
185 {
186 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID);
187 return(NULL);
188 }
189 ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data);
190 if (ret == NULL) ASN1_OBJECT_free(obj);
191 return(ret);
192 }
193
194X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
195 ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data)
196 {
197 X509_EXTENSION *ret;
198
199 if ((ex == NULL) || (*ex == NULL))
200 {
201 if ((ret=X509_EXTENSION_new()) == NULL)
202 {
203 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
204 return(NULL);
205 }
206 }
207 else
208 ret= *ex;
209
210 if (!X509_EXTENSION_set_object(ret,obj))
211 goto err;
212 if (!X509_EXTENSION_set_critical(ret,crit))
213 goto err;
214 if (!X509_EXTENSION_set_data(ret,data))
215 goto err;
216
217 if ((ex != NULL) && (*ex == NULL)) *ex=ret;
218 return(ret);
219err:
220 if ((ex == NULL) || (ret != *ex))
221 X509_EXTENSION_free(ret);
222 return(NULL);
223 }
224
225int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj)
226 {
227 if ((ex == NULL) || (obj == NULL))
228 return(0);
229 ASN1_OBJECT_free(ex->object);
230 ex->object=OBJ_dup(obj);
231 return(1);
232 }
233
234int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)
235 {
236 if (ex == NULL) return(0);
237 ex->critical=(crit)?0xFF:-1;
238 return(1);
239 }
240
241int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
242 {
243 int i;
244
245 if (ex == NULL) return(0);
246 i=M_ASN1_OCTET_STRING_set(ex->value,data->data,data->length);
247 if (!i) return(0);
248 return(1);
249 }
250
251ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)
252 {
253 if (ex == NULL) return(NULL);
254 return(ex->object);
255 }
256
257ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)
258 {
259 if (ex == NULL) return(NULL);
260 return(ex->value);
261 }
262
263int X509_EXTENSION_get_critical(X509_EXTENSION *ex)
264 {
265 if (ex == NULL) return(0);
266 if(ex->critical > 0) return 1;
267 return 0;
268 }
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
new file mode 100644
index 0000000000..e43c861ee7
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_vfy.c
@@ -0,0 +1,1333 @@
1/* crypto/x509/x509_vfy.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include <errno.h>
62
63#include "cryptlib.h"
64#include <openssl/crypto.h>
65#include <openssl/lhash.h>
66#include <openssl/buffer.h>
67#include <openssl/evp.h>
68#include <openssl/asn1.h>
69#include <openssl/x509.h>
70#include <openssl/x509v3.h>
71#include <openssl/objects.h>
72
73static int null_callback(int ok,X509_STORE_CTX *e);
74static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
75static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x);
76static int check_chain_extensions(X509_STORE_CTX *ctx);
77static int check_trust(X509_STORE_CTX *ctx);
78static int check_revocation(X509_STORE_CTX *ctx);
79static int check_cert(X509_STORE_CTX *ctx);
80static int internal_verify(X509_STORE_CTX *ctx);
81const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
82
83
84static int null_callback(int ok, X509_STORE_CTX *e)
85 {
86 return ok;
87 }
88
89#if 0
90static int x509_subject_cmp(X509 **a, X509 **b)
91 {
92 return X509_subject_name_cmp(*a,*b);
93 }
94#endif
95
96int X509_verify_cert(X509_STORE_CTX *ctx)
97 {
98 X509 *x,*xtmp,*chain_ss=NULL;
99 X509_NAME *xn;
100 int depth,i,ok=0;
101 int num;
102 int (*cb)();
103 STACK_OF(X509) *sktmp=NULL;
104
105 if (ctx->cert == NULL)
106 {
107 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
108 return -1;
109 }
110
111 cb=ctx->verify_cb;
112
113 /* first we make sure the chain we are going to build is
114 * present and that the first entry is in place */
115 if (ctx->chain == NULL)
116 {
117 if ( ((ctx->chain=sk_X509_new_null()) == NULL) ||
118 (!sk_X509_push(ctx->chain,ctx->cert)))
119 {
120 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
121 goto end;
122 }
123 CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
124 ctx->last_untrusted=1;
125 }
126
127 /* We use a temporary STACK so we can chop and hack at it */
128 if (ctx->untrusted != NULL
129 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
130 {
131 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
132 goto end;
133 }
134
135 num=sk_X509_num(ctx->chain);
136 x=sk_X509_value(ctx->chain,num-1);
137 depth=ctx->depth;
138
139
140 for (;;)
141 {
142 /* If we have enough, we break */
143 if (depth < num) break; /* FIXME: If this happens, we should take
144 * note of it and, if appropriate, use the
145 * X509_V_ERR_CERT_CHAIN_TOO_LONG error
146 * code later.
147 */
148
149 /* If we are self signed, we break */
150 xn=X509_get_issuer_name(x);
151 if (ctx->check_issued(ctx, x,x)) break;
152
153 /* If we were passed a cert chain, use it first */
154 if (ctx->untrusted != NULL)
155 {
156 xtmp=find_issuer(ctx, sktmp,x);
157 if (xtmp != NULL)
158 {
159 if (!sk_X509_push(ctx->chain,xtmp))
160 {
161 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
162 goto end;
163 }
164 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
165 sk_X509_delete_ptr(sktmp,xtmp);
166 ctx->last_untrusted++;
167 x=xtmp;
168 num++;
169 /* reparse the full chain for
170 * the next one */
171 continue;
172 }
173 }
174 break;
175 }
176
177 /* at this point, chain should contain a list of untrusted
178 * certificates. We now need to add at least one trusted one,
179 * if possible, otherwise we complain. */
180
181 /* Examine last certificate in chain and see if it
182 * is self signed.
183 */
184
185 i=sk_X509_num(ctx->chain);
186 x=sk_X509_value(ctx->chain,i-1);
187 xn = X509_get_subject_name(x);
188 if (ctx->check_issued(ctx, x, x))
189 {
190 /* we have a self signed certificate */
191 if (sk_X509_num(ctx->chain) == 1)
192 {
193 /* We have a single self signed certificate: see if
194 * we can find it in the store. We must have an exact
195 * match to avoid possible impersonation.
196 */
197 ok = ctx->get_issuer(&xtmp, ctx, x);
198 if ((ok <= 0) || X509_cmp(x, xtmp))
199 {
200 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
201 ctx->current_cert=x;
202 ctx->error_depth=i-1;
203 if (ok == 1) X509_free(xtmp);
204 ok=cb(0,ctx);
205 if (!ok) goto end;
206 }
207 else
208 {
209 /* We have a match: replace certificate with store version
210 * so we get any trust settings.
211 */
212 X509_free(x);
213 x = xtmp;
214 sk_X509_set(ctx->chain, i - 1, x);
215 ctx->last_untrusted=0;
216 }
217 }
218 else
219 {
220 /* extract and save self signed certificate for later use */
221 chain_ss=sk_X509_pop(ctx->chain);
222 ctx->last_untrusted--;
223 num--;
224 x=sk_X509_value(ctx->chain,num-1);
225 }
226 }
227
228 /* We now lookup certs from the certificate store */
229 for (;;)
230 {
231 /* If we have enough, we break */
232 if (depth < num) break;
233
234 /* If we are self signed, we break */
235 xn=X509_get_issuer_name(x);
236 if (ctx->check_issued(ctx,x,x)) break;
237
238 ok = ctx->get_issuer(&xtmp, ctx, x);
239
240 if (ok < 0) return ok;
241 if (ok == 0) break;
242
243 x = xtmp;
244 if (!sk_X509_push(ctx->chain,x))
245 {
246 X509_free(xtmp);
247 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
248 return 0;
249 }
250 num++;
251 }
252
253 /* we now have our chain, lets check it... */
254 xn=X509_get_issuer_name(x);
255
256 /* Is last certificate looked up self signed? */
257 if (!ctx->check_issued(ctx,x,x))
258 {
259 if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss))
260 {
261 if (ctx->last_untrusted >= num)
262 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
263 else
264 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
265 ctx->current_cert=x;
266 }
267 else
268 {
269
270 sk_X509_push(ctx->chain,chain_ss);
271 num++;
272 ctx->last_untrusted=num;
273 ctx->current_cert=chain_ss;
274 ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
275 chain_ss=NULL;
276 }
277
278 ctx->error_depth=num-1;
279 ok=cb(0,ctx);
280 if (!ok) goto end;
281 }
282
283 /* We have the chain complete: now we need to check its purpose */
284 ok = check_chain_extensions(ctx);
285
286 if (!ok) goto end;
287
288 /* The chain extensions are OK: check trust */
289
290 if (ctx->trust > 0) ok = check_trust(ctx);
291
292 if (!ok) goto end;
293
294 /* We may as well copy down any DSA parameters that are required */
295 X509_get_pubkey_parameters(NULL,ctx->chain);
296
297 /* Check revocation status: we do this after copying parameters
298 * because they may be needed for CRL signature verification.
299 */
300
301 ok = ctx->check_revocation(ctx);
302 if(!ok) goto end;
303
304 /* At this point, we have a chain and just need to verify it */
305 if (ctx->verify != NULL)
306 ok=ctx->verify(ctx);
307 else
308 ok=internal_verify(ctx);
309 if (0)
310 {
311end:
312 X509_get_pubkey_parameters(NULL,ctx->chain);
313 }
314 if (sktmp != NULL) sk_X509_free(sktmp);
315 if (chain_ss != NULL) X509_free(chain_ss);
316 return ok;
317 }
318
319
320/* Given a STACK_OF(X509) find the issuer of cert (if any)
321 */
322
323static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x)
324{
325 int i;
326 X509 *issuer;
327 for (i = 0; i < sk_X509_num(sk); i++)
328 {
329 issuer = sk_X509_value(sk, i);
330 if (ctx->check_issued(ctx, x, issuer))
331 return issuer;
332 }
333 return NULL;
334}
335
336/* Given a possible certificate and issuer check them */
337
338static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer)
339{
340 int ret;
341 ret = X509_check_issued(issuer, x);
342 if (ret == X509_V_OK)
343 return 1;
344 /* If we haven't asked for issuer errors don't set ctx */
345 if (!(ctx->flags & X509_V_FLAG_CB_ISSUER_CHECK))
346 return 0;
347
348 ctx->error = ret;
349 ctx->current_cert = x;
350 ctx->current_issuer = issuer;
351 return ctx->verify_cb(0, ctx);
352 return 0;
353}
354
355/* Alternative lookup method: look from a STACK stored in other_ctx */
356
357static int get_issuer_sk(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
358{
359 *issuer = find_issuer(ctx, ctx->other_ctx, x);
360 if (*issuer)
361 {
362 CRYPTO_add(&(*issuer)->references,1,CRYPTO_LOCK_X509);
363 return 1;
364 }
365 else
366 return 0;
367}
368
369
370/* Check a certificate chains extensions for consistency
371 * with the supplied purpose
372 */
373
374static int check_chain_extensions(X509_STORE_CTX *ctx)
375{
376#ifdef OPENSSL_NO_CHAIN_VERIFY
377 return 1;
378#else
379 int i, ok=0, must_be_ca;
380 X509 *x;
381 int (*cb)();
382 int proxy_path_length = 0;
383 int allow_proxy_certs = !!(ctx->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
384 cb=ctx->verify_cb;
385
386 /* must_be_ca can have 1 of 3 values:
387 -1: we accept both CA and non-CA certificates, to allow direct
388 use of self-signed certificates (which are marked as CA).
389 0: we only accept non-CA certificates. This is currently not
390 used, but the possibility is present for future extensions.
391 1: we only accept CA certificates. This is currently used for
392 all certificates in the chain except the leaf certificate.
393 */
394 must_be_ca = -1;
395
396 /* A hack to keep people who don't want to modify their software
397 happy */
398 if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
399 allow_proxy_certs = 1;
400
401 /* Check all untrusted certificates */
402 for (i = 0; i < ctx->last_untrusted; i++)
403 {
404 int ret;
405 x = sk_X509_value(ctx->chain, i);
406 if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL)
407 && (x->ex_flags & EXFLAG_CRITICAL))
408 {
409 ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
410 ctx->error_depth = i;
411 ctx->current_cert = x;
412 ok=cb(0,ctx);
413 if (!ok) goto end;
414 }
415 if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))
416 {
417 ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
418 ctx->error_depth = i;
419 ctx->current_cert = x;
420 ok=cb(0,ctx);
421 if (!ok) goto end;
422 }
423 ret = X509_check_ca(x);
424 switch(must_be_ca)
425 {
426 case -1:
427 if ((ctx->flags & X509_V_FLAG_X509_STRICT)
428 && (ret != 1) && (ret != 0))
429 {
430 ret = 0;
431 ctx->error = X509_V_ERR_INVALID_CA;
432 }
433 else
434 ret = 1;
435 break;
436 case 0:
437 if (ret != 0)
438 {
439 ret = 0;
440 ctx->error = X509_V_ERR_INVALID_NON_CA;
441 }
442 else
443 ret = 1;
444 break;
445 default:
446 if ((ret == 0)
447 || ((ctx->flags & X509_V_FLAG_X509_STRICT)
448 && (ret != 1)))
449 {
450 ret = 0;
451 ctx->error = X509_V_ERR_INVALID_CA;
452 }
453 else
454 ret = 1;
455 break;
456 }
457 if (ret == 0)
458 {
459 ctx->error_depth = i;
460 ctx->current_cert = x;
461 ok=cb(0,ctx);
462 if (!ok) goto end;
463 }
464 if (ctx->purpose > 0)
465 {
466 ret = X509_check_purpose(x, ctx->purpose,
467 must_be_ca > 0);
468 if ((ret == 0)
469 || ((ctx->flags & X509_V_FLAG_X509_STRICT)
470 && (ret != 1)))
471 {
472 ctx->error = X509_V_ERR_INVALID_PURPOSE;
473 ctx->error_depth = i;
474 ctx->current_cert = x;
475 ok=cb(0,ctx);
476 if (!ok) goto end;
477 }
478 }
479 /* Check pathlen */
480 if ((i > 1) && (x->ex_pathlen != -1)
481 && (i > (x->ex_pathlen + proxy_path_length + 1)))
482 {
483 ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
484 ctx->error_depth = i;
485 ctx->current_cert = x;
486 ok=cb(0,ctx);
487 if (!ok) goto end;
488 }
489 /* If this certificate is a proxy certificate, the next
490 certificate must be another proxy certificate or a EE
491 certificate. If not, the next certificate must be a
492 CA certificate. */
493 if (x->ex_flags & EXFLAG_PROXY)
494 {
495 PROXY_CERT_INFO_EXTENSION *pci =
496 X509_get_ext_d2i(x, NID_proxyCertInfo,
497 NULL, NULL);
498 if (pci->pcPathLengthConstraint &&
499 ASN1_INTEGER_get(pci->pcPathLengthConstraint)
500 < i)
501 {
502 PROXY_CERT_INFO_EXTENSION_free(pci);
503 ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
504 ctx->error_depth = i;
505 ctx->current_cert = x;
506 ok=cb(0,ctx);
507 if (!ok) goto end;
508 }
509 PROXY_CERT_INFO_EXTENSION_free(pci);
510 proxy_path_length++;
511 must_be_ca = 0;
512 }
513 else
514 must_be_ca = 1;
515 }
516 ok = 1;
517 end:
518 return ok;
519#endif
520}
521
522static int check_trust(X509_STORE_CTX *ctx)
523{
524#ifdef OPENSSL_NO_CHAIN_VERIFY
525 return 1;
526#else
527 int i, ok;
528 X509 *x;
529 int (*cb)();
530 cb=ctx->verify_cb;
531/* For now just check the last certificate in the chain */
532 i = sk_X509_num(ctx->chain) - 1;
533 x = sk_X509_value(ctx->chain, i);
534 ok = X509_check_trust(x, ctx->trust, 0);
535 if (ok == X509_TRUST_TRUSTED)
536 return 1;
537 ctx->error_depth = i;
538 ctx->current_cert = x;
539 if (ok == X509_TRUST_REJECTED)
540 ctx->error = X509_V_ERR_CERT_REJECTED;
541 else
542 ctx->error = X509_V_ERR_CERT_UNTRUSTED;
543 ok = cb(0, ctx);
544 return ok;
545#endif
546}
547
548static int check_revocation(X509_STORE_CTX *ctx)
549 {
550 int i, last, ok;
551 if (!(ctx->flags & X509_V_FLAG_CRL_CHECK))
552 return 1;
553 if (ctx->flags & X509_V_FLAG_CRL_CHECK_ALL)
554 last = sk_X509_num(ctx->chain) - 1;
555 else
556 last = 0;
557 for(i = 0; i <= last; i++)
558 {
559 ctx->error_depth = i;
560 ok = check_cert(ctx);
561 if (!ok) return ok;
562 }
563 return 1;
564 }
565
566static int check_cert(X509_STORE_CTX *ctx)
567 {
568 X509_CRL *crl = NULL;
569 X509 *x;
570 int ok, cnum;
571 cnum = ctx->error_depth;
572 x = sk_X509_value(ctx->chain, cnum);
573 ctx->current_cert = x;
574 /* Try to retrieve relevant CRL */
575 ok = ctx->get_crl(ctx, &crl, x);
576 /* If error looking up CRL, nothing we can do except
577 * notify callback
578 */
579 if(!ok)
580 {
581 ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
582 ok = ctx->verify_cb(0, ctx);
583 goto err;
584 }
585 ctx->current_crl = crl;
586 ok = ctx->check_crl(ctx, crl);
587 if (!ok) goto err;
588 ok = ctx->cert_crl(ctx, crl, x);
589 err:
590 ctx->current_crl = NULL;
591 X509_CRL_free(crl);
592 return ok;
593
594 }
595
596/* Retrieve CRL corresponding to certificate: currently just a
597 * subject lookup: maybe use AKID later...
598 * Also might look up any included CRLs too (e.g PKCS#7 signedData).
599 */
600static int get_crl(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x)
601 {
602 int ok;
603 X509_OBJECT xobj;
604 ok = X509_STORE_get_by_subject(ctx, X509_LU_CRL, X509_get_issuer_name(x), &xobj);
605 if (!ok) return 0;
606 *crl = xobj.data.crl;
607 return 1;
608 }
609
610/* Check CRL validity */
611static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
612 {
613 X509 *issuer = NULL;
614 EVP_PKEY *ikey = NULL;
615 int ok = 0, chnum, cnum, i;
616 time_t *ptime;
617 cnum = ctx->error_depth;
618 chnum = sk_X509_num(ctx->chain) - 1;
619 /* Find CRL issuer: if not last certificate then issuer
620 * is next certificate in chain.
621 */
622 if(cnum < chnum)
623 issuer = sk_X509_value(ctx->chain, cnum + 1);
624 else
625 {
626 issuer = sk_X509_value(ctx->chain, chnum);
627 /* If not self signed, can't check signature */
628 if(!ctx->check_issued(ctx, issuer, issuer))
629 {
630 ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER;
631 ok = ctx->verify_cb(0, ctx);
632 if(!ok) goto err;
633 }
634 }
635
636 if(issuer)
637 {
638 /* Check for cRLSign bit if keyUsage present */
639 if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
640 !(issuer->ex_kusage & KU_CRL_SIGN))
641 {
642 ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
643 ok = ctx->verify_cb(0, ctx);
644 if(!ok) goto err;
645 }
646
647 /* Attempt to get issuer certificate public key */
648 ikey = X509_get_pubkey(issuer);
649
650 if(!ikey)
651 {
652 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
653 ok = ctx->verify_cb(0, ctx);
654 if (!ok) goto err;
655 }
656 else
657 {
658 /* Verify CRL signature */
659 if(X509_CRL_verify(crl, ikey) <= 0)
660 {
661 ctx->error=X509_V_ERR_CRL_SIGNATURE_FAILURE;
662 ok = ctx->verify_cb(0, ctx);
663 if (!ok) goto err;
664 }
665 }
666 }
667
668 /* OK, CRL signature valid check times */
669 if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
670 ptime = &ctx->check_time;
671 else
672 ptime = NULL;
673
674 i=X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
675 if (i == 0)
676 {
677 ctx->error=X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
678 ok = ctx->verify_cb(0, ctx);
679 if (!ok) goto err;
680 }
681
682 if (i > 0)
683 {
684 ctx->error=X509_V_ERR_CRL_NOT_YET_VALID;
685 ok = ctx->verify_cb(0, ctx);
686 if (!ok) goto err;
687 }
688
689 if(X509_CRL_get_nextUpdate(crl))
690 {
691 i=X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime);
692
693 if (i == 0)
694 {
695 ctx->error=X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
696 ok = ctx->verify_cb(0, ctx);
697 if (!ok) goto err;
698 }
699
700 if (i < 0)
701 {
702 ctx->error=X509_V_ERR_CRL_HAS_EXPIRED;
703 ok = ctx->verify_cb(0, ctx);
704 if (!ok) goto err;
705 }
706 }
707
708 ok = 1;
709
710 err:
711 EVP_PKEY_free(ikey);
712 return ok;
713 }
714
715/* Check certificate against CRL */
716static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x)
717 {
718 int idx, ok;
719 X509_REVOKED rtmp;
720 STACK_OF(X509_EXTENSION) *exts;
721 X509_EXTENSION *ext;
722 /* Look for serial number of certificate in CRL */
723 rtmp.serialNumber = X509_get_serialNumber(x);
724 /* Sort revoked into serial number order if not already sorted.
725 * Do this under a lock to avoid race condition.
726 */
727 if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked))
728 {
729 CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
730 sk_X509_REVOKED_sort(crl->crl->revoked);
731 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
732 }
733 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
734 /* If found assume revoked: want something cleverer than
735 * this to handle entry extensions in V2 CRLs.
736 */
737 if(idx >= 0)
738 {
739 ctx->error = X509_V_ERR_CERT_REVOKED;
740 ok = ctx->verify_cb(0, ctx);
741 if (!ok) return 0;
742 }
743
744 if (ctx->flags & X509_V_FLAG_IGNORE_CRITICAL)
745 return 1;
746
747 /* See if we have any critical CRL extensions: since we
748 * currently don't handle any CRL extensions the CRL must be
749 * rejected.
750 * This code accesses the X509_CRL structure directly: applications
751 * shouldn't do this.
752 */
753
754 exts = crl->crl->extensions;
755
756 for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++)
757 {
758 ext = sk_X509_EXTENSION_value(exts, idx);
759 if (ext->critical > 0)
760 {
761 ctx->error =
762 X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
763 ok = ctx->verify_cb(0, ctx);
764 if(!ok) return 0;
765 break;
766 }
767 }
768 return 1;
769 }
770
771static int internal_verify(X509_STORE_CTX *ctx)
772 {
773 int i,ok=0,n;
774 X509 *xs,*xi;
775 EVP_PKEY *pkey=NULL;
776 time_t *ptime;
777 int (*cb)();
778
779 cb=ctx->verify_cb;
780
781 n=sk_X509_num(ctx->chain);
782 ctx->error_depth=n-1;
783 n--;
784 xi=sk_X509_value(ctx->chain,n);
785 if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
786 ptime = &ctx->check_time;
787 else
788 ptime = NULL;
789 if (ctx->check_issued(ctx, xi, xi))
790 xs=xi;
791 else
792 {
793 if (n <= 0)
794 {
795 ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
796 ctx->current_cert=xi;
797 ok=cb(0,ctx);
798 goto end;
799 }
800 else
801 {
802 n--;
803 ctx->error_depth=n;
804 xs=sk_X509_value(ctx->chain,n);
805 }
806 }
807
808/* ctx->error=0; not needed */
809 while (n >= 0)
810 {
811 ctx->error_depth=n;
812 if (!xs->valid)
813 {
814 if ((pkey=X509_get_pubkey(xi)) == NULL)
815 {
816 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
817 ctx->current_cert=xi;
818 ok=(*cb)(0,ctx);
819 if (!ok) goto end;
820 }
821 else if (X509_verify(xs,pkey) <= 0)
822 /* XXX For the final trusted self-signed cert,
823 * this is a waste of time. That check should
824 * optional so that e.g. 'openssl x509' can be
825 * used to detect invalid self-signatures, but
826 * we don't verify again and again in SSL
827 * handshakes and the like once the cert has
828 * been declared trusted. */
829 {
830 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
831 ctx->current_cert=xs;
832 ok=(*cb)(0,ctx);
833 if (!ok)
834 {
835 EVP_PKEY_free(pkey);
836 goto end;
837 }
838 }
839 EVP_PKEY_free(pkey);
840 pkey=NULL;
841
842 i=X509_cmp_time(X509_get_notBefore(xs), ptime);
843 if (i == 0)
844 {
845 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
846 ctx->current_cert=xs;
847 ok=(*cb)(0,ctx);
848 if (!ok) goto end;
849 }
850 if (i > 0)
851 {
852 ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
853 ctx->current_cert=xs;
854 ok=(*cb)(0,ctx);
855 if (!ok) goto end;
856 }
857 xs->valid=1;
858 }
859
860 i=X509_cmp_time(X509_get_notAfter(xs), ptime);
861 if (i == 0)
862 {
863 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
864 ctx->current_cert=xs;
865 ok=(*cb)(0,ctx);
866 if (!ok) goto end;
867 }
868
869 if (i < 0)
870 {
871 ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
872 ctx->current_cert=xs;
873 ok=(*cb)(0,ctx);
874 if (!ok) goto end;
875 }
876
877 /* The last error (if any) is still in the error value */
878 ctx->current_issuer=xi;
879 ctx->current_cert=xs;
880 ok=(*cb)(1,ctx);
881 if (!ok) goto end;
882
883 n--;
884 if (n >= 0)
885 {
886 xi=xs;
887 xs=sk_X509_value(ctx->chain,n);
888 }
889 }
890 ok=1;
891end:
892 return ok;
893 }
894
895int X509_cmp_current_time(ASN1_TIME *ctm)
896{
897 return X509_cmp_time(ctm, NULL);
898}
899
900int X509_cmp_time(ASN1_TIME *ctm, time_t *cmp_time)
901 {
902 char *str;
903 ASN1_TIME atm;
904 long offset;
905 char buff1[24],buff2[24],*p;
906 int i,j;
907
908 p=buff1;
909 i=ctm->length;
910 str=(char *)ctm->data;
911 if (ctm->type == V_ASN1_UTCTIME)
912 {
913 if ((i < 11) || (i > 17)) return 0;
914 memcpy(p,str,10);
915 p+=10;
916 str+=10;
917 }
918 else
919 {
920 if (i < 13) return 0;
921 memcpy(p,str,12);
922 p+=12;
923 str+=12;
924 }
925
926 if ((*str == 'Z') || (*str == '-') || (*str == '+'))
927 { *(p++)='0'; *(p++)='0'; }
928 else
929 {
930 *(p++)= *(str++);
931 *(p++)= *(str++);
932 /* Skip any fractional seconds... */
933 if (*str == '.')
934 {
935 str++;
936 while ((*str >= '0') && (*str <= '9')) str++;
937 }
938
939 }
940 *(p++)='Z';
941 *(p++)='\0';
942
943 if (*str == 'Z')
944 offset=0;
945 else
946 {
947 if ((*str != '+') && (str[5] != '-'))
948 return 0;
949 offset=((str[1]-'0')*10+(str[2]-'0'))*60;
950 offset+=(str[3]-'0')*10+(str[4]-'0');
951 if (*str == '-')
952 offset= -offset;
953 }
954 atm.type=ctm->type;
955 atm.length=sizeof(buff2);
956 atm.data=(unsigned char *)buff2;
957
958 if (X509_time_adj(&atm,-offset*60, cmp_time) == NULL)
959 return 0;
960
961 if (ctm->type == V_ASN1_UTCTIME)
962 {
963 i=(buff1[0]-'0')*10+(buff1[1]-'0');
964 if (i < 50) i+=100; /* cf. RFC 2459 */
965 j=(buff2[0]-'0')*10+(buff2[1]-'0');
966 if (j < 50) j+=100;
967
968 if (i < j) return -1;
969 if (i > j) return 1;
970 }
971 i=strcmp(buff1,buff2);
972 if (i == 0) /* wait a second then return younger :-) */
973 return -1;
974 else
975 return i;
976 }
977
978ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj)
979{
980 return X509_time_adj(s, adj, NULL);
981}
982
983ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *in_tm)
984 {
985 time_t t;
986 int type = -1;
987
988 if (in_tm) t = *in_tm;
989 else time(&t);
990
991 t+=adj;
992 if (s) type = s->type;
993 if (type == V_ASN1_UTCTIME) return ASN1_UTCTIME_set(s,t);
994 if (type == V_ASN1_GENERALIZEDTIME) return ASN1_GENERALIZEDTIME_set(s, t);
995 return ASN1_TIME_set(s, t);
996 }
997
998int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
999 {
1000 EVP_PKEY *ktmp=NULL,*ktmp2;
1001 int i,j;
1002
1003 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return 1;
1004
1005 for (i=0; i<sk_X509_num(chain); i++)
1006 {
1007 ktmp=X509_get_pubkey(sk_X509_value(chain,i));
1008 if (ktmp == NULL)
1009 {
1010 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
1011 return 0;
1012 }
1013 if (!EVP_PKEY_missing_parameters(ktmp))
1014 break;
1015 else
1016 {
1017 EVP_PKEY_free(ktmp);
1018 ktmp=NULL;
1019 }
1020 }
1021 if (ktmp == NULL)
1022 {
1023 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
1024 return 0;
1025 }
1026
1027 /* first, populate the other certs */
1028 for (j=i-1; j >= 0; j--)
1029 {
1030 ktmp2=X509_get_pubkey(sk_X509_value(chain,j));
1031 EVP_PKEY_copy_parameters(ktmp2,ktmp);
1032 EVP_PKEY_free(ktmp2);
1033 }
1034
1035 if (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp);
1036 EVP_PKEY_free(ktmp);
1037 return 1;
1038 }
1039
1040int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1041 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
1042 {
1043 /* This function is (usually) called only once, by
1044 * SSL_get_ex_data_X509_STORE_CTX_idx (ssl/ssl_cert.c). */
1045 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE_CTX, argl, argp,
1046 new_func, dup_func, free_func);
1047 }
1048
1049int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data)
1050 {
1051 return CRYPTO_set_ex_data(&ctx->ex_data,idx,data);
1052 }
1053
1054void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx)
1055 {
1056 return CRYPTO_get_ex_data(&ctx->ex_data,idx);
1057 }
1058
1059int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx)
1060 {
1061 return ctx->error;
1062 }
1063
1064void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err)
1065 {
1066 ctx->error=err;
1067 }
1068
1069int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx)
1070 {
1071 return ctx->error_depth;
1072 }
1073
1074X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx)
1075 {
1076 return ctx->current_cert;
1077 }
1078
1079STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
1080 {
1081 return ctx->chain;
1082 }
1083
1084STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
1085 {
1086 int i;
1087 X509 *x;
1088 STACK_OF(X509) *chain;
1089 if (!ctx->chain || !(chain = sk_X509_dup(ctx->chain))) return NULL;
1090 for (i = 0; i < sk_X509_num(chain); i++)
1091 {
1092 x = sk_X509_value(chain, i);
1093 CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
1094 }
1095 return chain;
1096 }
1097
1098void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
1099 {
1100 ctx->cert=x;
1101 }
1102
1103void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
1104 {
1105 ctx->untrusted=sk;
1106 }
1107
1108int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose)
1109 {
1110 return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
1111 }
1112
1113int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust)
1114 {
1115 return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust);
1116 }
1117
1118/* This function is used to set the X509_STORE_CTX purpose and trust
1119 * values. This is intended to be used when another structure has its
1120 * own trust and purpose values which (if set) will be inherited by
1121 * the ctx. If they aren't set then we will usually have a default
1122 * purpose in mind which should then be used to set the trust value.
1123 * An example of this is SSL use: an SSL structure will have its own
1124 * purpose and trust settings which the application can set: if they
1125 * aren't set then we use the default of SSL client/server.
1126 */
1127
1128int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
1129 int purpose, int trust)
1130{
1131 int idx;
1132 /* If purpose not set use default */
1133 if (!purpose) purpose = def_purpose;
1134 /* If we have a purpose then check it is valid */
1135 if (purpose)
1136 {
1137 X509_PURPOSE *ptmp;
1138 idx = X509_PURPOSE_get_by_id(purpose);
1139 if (idx == -1)
1140 {
1141 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
1142 X509_R_UNKNOWN_PURPOSE_ID);
1143 return 0;
1144 }
1145 ptmp = X509_PURPOSE_get0(idx);
1146 if (ptmp->trust == X509_TRUST_DEFAULT)
1147 {
1148 idx = X509_PURPOSE_get_by_id(def_purpose);
1149 if (idx == -1)
1150 {
1151 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
1152 X509_R_UNKNOWN_PURPOSE_ID);
1153 return 0;
1154 }
1155 ptmp = X509_PURPOSE_get0(idx);
1156 }
1157 /* If trust not set then get from purpose default */
1158 if (!trust) trust = ptmp->trust;
1159 }
1160 if (trust)
1161 {
1162 idx = X509_TRUST_get_by_id(trust);
1163 if (idx == -1)
1164 {
1165 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
1166 X509_R_UNKNOWN_TRUST_ID);
1167 return 0;
1168 }
1169 }
1170
1171 if (purpose && !ctx->purpose) ctx->purpose = purpose;
1172 if (trust && !ctx->trust) ctx->trust = trust;
1173 return 1;
1174}
1175
1176X509_STORE_CTX *X509_STORE_CTX_new(void)
1177{
1178 X509_STORE_CTX *ctx;
1179 ctx = (X509_STORE_CTX *)OPENSSL_malloc(sizeof(X509_STORE_CTX));
1180 if (!ctx)
1181 {
1182 X509err(X509_F_X509_STORE_CTX_NEW,ERR_R_MALLOC_FAILURE);
1183 return NULL;
1184 }
1185 memset(ctx, 0, sizeof(X509_STORE_CTX));
1186 return ctx;
1187}
1188
1189void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
1190{
1191 X509_STORE_CTX_cleanup(ctx);
1192 OPENSSL_free(ctx);
1193}
1194
1195int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
1196 STACK_OF(X509) *chain)
1197 {
1198 ctx->ctx=store;
1199 ctx->current_method=0;
1200 ctx->cert=x509;
1201 ctx->untrusted=chain;
1202 ctx->last_untrusted=0;
1203 ctx->check_time=0;
1204 ctx->other_ctx=NULL;
1205 ctx->valid=0;
1206 ctx->chain=NULL;
1207 ctx->depth=9;
1208 ctx->error=0;
1209 ctx->error_depth=0;
1210 ctx->current_cert=NULL;
1211 ctx->current_issuer=NULL;
1212
1213 /* Inherit callbacks and flags from X509_STORE if not set
1214 * use defaults.
1215 */
1216
1217
1218 if (store)
1219 {
1220 ctx->purpose=store->purpose;
1221 ctx->trust=store->trust;
1222 ctx->flags = store->flags;
1223 ctx->cleanup = store->cleanup;
1224 }
1225 else
1226 {
1227 ctx->purpose = 0;
1228 ctx->trust = 0;
1229 ctx->flags = 0;
1230 ctx->cleanup = 0;
1231 }
1232
1233 if (store && store->check_issued)
1234 ctx->check_issued = store->check_issued;
1235 else
1236 ctx->check_issued = check_issued;
1237
1238 if (store && store->get_issuer)
1239 ctx->get_issuer = store->get_issuer;
1240 else
1241 ctx->get_issuer = X509_STORE_CTX_get1_issuer;
1242
1243 if (store && store->verify_cb)
1244 ctx->verify_cb = store->verify_cb;
1245 else
1246 ctx->verify_cb = null_callback;
1247
1248 if (store && store->verify)
1249 ctx->verify = store->verify;
1250 else
1251 ctx->verify = internal_verify;
1252
1253 if (store && store->check_revocation)
1254 ctx->check_revocation = store->check_revocation;
1255 else
1256 ctx->check_revocation = check_revocation;
1257
1258 if (store && store->get_crl)
1259 ctx->get_crl = store->get_crl;
1260 else
1261 ctx->get_crl = get_crl;
1262
1263 if (store && store->check_crl)
1264 ctx->check_crl = store->check_crl;
1265 else
1266 ctx->check_crl = check_crl;
1267
1268 if (store && store->cert_crl)
1269 ctx->cert_crl = store->cert_crl;
1270 else
1271 ctx->cert_crl = cert_crl;
1272
1273
1274 /* This memset() can't make any sense anyway, so it's removed. As
1275 * X509_STORE_CTX_cleanup does a proper "free" on the ex_data, we put a
1276 * corresponding "new" here and remove this bogus initialisation. */
1277 /* memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); */
1278 if(!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx,
1279 &(ctx->ex_data)))
1280 {
1281 OPENSSL_free(ctx);
1282 X509err(X509_F_X509_STORE_CTX_INIT,ERR_R_MALLOC_FAILURE);
1283 return 0;
1284 }
1285 return 1;
1286 }
1287
1288/* Set alternative lookup method: just a STACK of trusted certificates.
1289 * This avoids X509_STORE nastiness where it isn't needed.
1290 */
1291
1292void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
1293{
1294 ctx->other_ctx = sk;
1295 ctx->get_issuer = get_issuer_sk;
1296}
1297
1298void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
1299 {
1300 if (ctx->cleanup) ctx->cleanup(ctx);
1301 if (ctx->chain != NULL)
1302 {
1303 sk_X509_pop_free(ctx->chain,X509_free);
1304 ctx->chain=NULL;
1305 }
1306 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx, &(ctx->ex_data));
1307 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
1308 }
1309
1310void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, long flags)
1311 {
1312 ctx->flags |= flags;
1313 }
1314
1315void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, long flags, time_t t)
1316 {
1317 ctx->check_time = t;
1318 ctx->flags |= X509_V_FLAG_USE_CHECK_TIME;
1319 }
1320
1321void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
1322 int (*verify_cb)(int, X509_STORE_CTX *))
1323 {
1324 ctx->verify_cb=verify_cb;
1325 }
1326
1327IMPLEMENT_STACK_OF(X509)
1328IMPLEMENT_ASN1_SET_OF(X509)
1329
1330IMPLEMENT_STACK_OF(X509_NAME)
1331
1332IMPLEMENT_STACK_OF(X509_ATTRIBUTE)
1333IMPLEMENT_ASN1_SET_OF(X509_ATTRIBUTE)
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h
new file mode 100644
index 0000000000..7fd1f0bc4d
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_vfy.h
@@ -0,0 +1,422 @@
1/* crypto/x509/x509_vfy.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_X509_H
60#include <openssl/x509.h>
61/* openssl/x509.h ends up #include-ing this file at about the only
62 * appropriate moment. */
63#endif
64
65#ifndef HEADER_X509_VFY_H
66#define HEADER_X509_VFY_H
67
68#ifndef OPENSSL_NO_LHASH
69#include <openssl/lhash.h>
70#endif
71#include <openssl/bio.h>
72#include <openssl/crypto.h>
73#include <openssl/symhacks.h>
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79/* Outer object */
80typedef struct x509_hash_dir_st
81 {
82 int num_dirs;
83 char **dirs;
84 int *dirs_type;
85 int num_dirs_alloced;
86 } X509_HASH_DIR_CTX;
87
88typedef struct x509_file_st
89 {
90 int num_paths; /* number of paths to files or directories */
91 int num_alloced;
92 char **paths; /* the list of paths or directories */
93 int *path_type;
94 } X509_CERT_FILE_CTX;
95
96/*******************************/
97/*
98SSL_CTX -> X509_STORE
99 -> X509_LOOKUP
100 ->X509_LOOKUP_METHOD
101 -> X509_LOOKUP
102 ->X509_LOOKUP_METHOD
103
104SSL -> X509_STORE_CTX
105 ->X509_STORE
106
107The X509_STORE holds the tables etc for verification stuff.
108A X509_STORE_CTX is used while validating a single certificate.
109The X509_STORE has X509_LOOKUPs for looking up certs.
110The X509_STORE then calls a function to actually verify the
111certificate chain.
112*/
113
114#define X509_LU_RETRY -1
115#define X509_LU_FAIL 0
116#define X509_LU_X509 1
117#define X509_LU_CRL 2
118#define X509_LU_PKEY 3
119
120typedef struct x509_object_st
121 {
122 /* one of the above types */
123 int type;
124 union {
125 char *ptr;
126 X509 *x509;
127 X509_CRL *crl;
128 EVP_PKEY *pkey;
129 } data;
130 } X509_OBJECT;
131
132typedef struct x509_lookup_st X509_LOOKUP;
133
134DECLARE_STACK_OF(X509_LOOKUP)
135DECLARE_STACK_OF(X509_OBJECT)
136
137/* This is a static that defines the function interface */
138typedef struct x509_lookup_method_st
139 {
140 const char *name;
141 int (*new_item)(X509_LOOKUP *ctx);
142 void (*free)(X509_LOOKUP *ctx);
143 int (*init)(X509_LOOKUP *ctx);
144 int (*shutdown)(X509_LOOKUP *ctx);
145 int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl,
146 char **ret);
147 int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name,
148 X509_OBJECT *ret);
149 int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name,
150 ASN1_INTEGER *serial,X509_OBJECT *ret);
151 int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type,
152 unsigned char *bytes,int len,
153 X509_OBJECT *ret);
154 int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len,
155 X509_OBJECT *ret);
156 } X509_LOOKUP_METHOD;
157
158/* This is used to hold everything. It is used for all certificate
159 * validation. Once we have a certificate chain, the 'verify'
160 * function is then called to actually check the cert chain. */
161struct x509_store_st
162 {
163 /* The following is a cache of trusted certs */
164 int cache; /* if true, stash any hits */
165 STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */
166
167 /* These are external lookup methods */
168 STACK_OF(X509_LOOKUP) *get_cert_methods;
169
170 /* The following fields are not used by X509_STORE but are
171 * inherited by X509_STORE_CTX when it is initialised.
172 */
173
174 unsigned long flags; /* Various verify flags */
175 int purpose;
176 int trust;
177 /* Callbacks for various operations */
178 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
179 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
180 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
181 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
182 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
183 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
184 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
185 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
186 int (*cleanup)(X509_STORE_CTX *ctx);
187
188 CRYPTO_EX_DATA ex_data;
189 int references;
190 int depth; /* how deep to look (still unused -- X509_STORE_CTX's depth is used) */
191 } /* X509_STORE */;
192
193#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d))
194
195#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))
196#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func))
197
198/* This is the functions plus an instance of the local variables. */
199struct x509_lookup_st
200 {
201 int init; /* have we been started */
202 int skip; /* don't use us. */
203 X509_LOOKUP_METHOD *method; /* the functions */
204 char *method_data; /* method data */
205
206 X509_STORE *store_ctx; /* who owns us */
207 } /* X509_LOOKUP */;
208
209/* This is a used when verifying cert chains. Since the
210 * gathering of the cert chain can take some time (and have to be
211 * 'retried', this needs to be kept and passed around. */
212struct x509_store_ctx_st /* X509_STORE_CTX */
213 {
214 X509_STORE *ctx;
215 int current_method; /* used when looking up certs */
216
217 /* The following are set by the caller */
218 X509 *cert; /* The cert to check */
219 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
220 int purpose; /* purpose to check untrusted certificates */
221 int trust; /* trust setting to check */
222 time_t check_time; /* time to make verify at */
223 unsigned long flags; /* Various verify flags */
224 void *other_ctx; /* Other info for use with get_issuer() */
225
226 /* Callbacks for various operations */
227 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
228 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
229 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
230 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
231 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
232 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
233 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
234 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
235 int (*cleanup)(X509_STORE_CTX *ctx);
236
237 /* The following is built up */
238 int depth; /* how far to go looking up certs */
239 int valid; /* if 0, rebuild chain */
240 int last_untrusted; /* index of last untrusted cert */
241 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
242
243 /* When something goes wrong, this is why */
244 int error_depth;
245 int error;
246 X509 *current_cert;
247 X509 *current_issuer; /* cert currently being tested as valid issuer */
248 X509_CRL *current_crl; /* current CRL */
249
250 CRYPTO_EX_DATA ex_data;
251 } /* X509_STORE_CTX */;
252
253#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d))
254
255#define X509_STORE_CTX_set_app_data(ctx,data) \
256 X509_STORE_CTX_set_ex_data(ctx,0,data)
257#define X509_STORE_CTX_get_app_data(ctx) \
258 X509_STORE_CTX_get_ex_data(ctx,0)
259
260#define X509_L_FILE_LOAD 1
261#define X509_L_ADD_DIR 2
262
263#define X509_LOOKUP_load_file(x,name,type) \
264 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
265
266#define X509_LOOKUP_add_dir(x,name,type) \
267 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
268
269#define X509_V_OK 0
270/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */
271
272#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
273#define X509_V_ERR_UNABLE_TO_GET_CRL 3
274#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
275#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
276#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
277#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
278#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
279#define X509_V_ERR_CERT_NOT_YET_VALID 9
280#define X509_V_ERR_CERT_HAS_EXPIRED 10
281#define X509_V_ERR_CRL_NOT_YET_VALID 11
282#define X509_V_ERR_CRL_HAS_EXPIRED 12
283#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
284#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
285#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
286#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
287#define X509_V_ERR_OUT_OF_MEM 17
288#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
289#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
290#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
291#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
292#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
293#define X509_V_ERR_CERT_REVOKED 23
294#define X509_V_ERR_INVALID_CA 24
295#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25
296#define X509_V_ERR_INVALID_PURPOSE 26
297#define X509_V_ERR_CERT_UNTRUSTED 27
298#define X509_V_ERR_CERT_REJECTED 28
299/* These are 'informational' when looking for issuer cert */
300#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29
301#define X509_V_ERR_AKID_SKID_MISMATCH 30
302#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31
303#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32
304
305#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33
306#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34
307#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35
308#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36
309#define X509_V_ERR_INVALID_NON_CA 37
310#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38
311#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39
312#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40
313
314/* The application is not happy */
315#define X509_V_ERR_APPLICATION_VERIFICATION 50
316
317/* Certificate verify flags */
318
319/* Send issuer+subject checks to verify_cb */
320#define X509_V_FLAG_CB_ISSUER_CHECK 0x1
321/* Use check time instead of current time */
322#define X509_V_FLAG_USE_CHECK_TIME 0x2
323/* Lookup CRLs */
324#define X509_V_FLAG_CRL_CHECK 0x4
325/* Lookup CRLs for whole chain */
326#define X509_V_FLAG_CRL_CHECK_ALL 0x8
327/* Ignore unhandled critical extensions */
328#define X509_V_FLAG_IGNORE_CRITICAL 0x10
329/* Disable workarounds for broken certificates */
330#define X509_V_FLAG_X509_STRICT 0x20
331/* Enable proxy certificate validation */
332#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40
333
334int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
335 X509_NAME *name);
336X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,int type,X509_NAME *name);
337X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x);
338void X509_OBJECT_up_ref_count(X509_OBJECT *a);
339void X509_OBJECT_free_contents(X509_OBJECT *a);
340X509_STORE *X509_STORE_new(void );
341void X509_STORE_free(X509_STORE *v);
342
343void X509_STORE_set_flags(X509_STORE *ctx, long flags);
344int X509_STORE_set_purpose(X509_STORE *ctx, int purpose);
345int X509_STORE_set_trust(X509_STORE *ctx, int trust);
346
347X509_STORE_CTX *X509_STORE_CTX_new(void);
348
349int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
350
351void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
352int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
353 X509 *x509, STACK_OF(X509) *chain);
354void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
355void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
356
357X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
358
359X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
360X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
361
362int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
363int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
364
365int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
366 X509_OBJECT *ret);
367
368int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
369 long argl, char **ret);
370
371#ifndef OPENSSL_NO_STDIO
372int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
373int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
374int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);
375#endif
376
377
378X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
379void X509_LOOKUP_free(X509_LOOKUP *ctx);
380int X509_LOOKUP_init(X509_LOOKUP *ctx);
381int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
382 X509_OBJECT *ret);
383int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
384 ASN1_INTEGER *serial, X509_OBJECT *ret);
385int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
386 unsigned char *bytes, int len, X509_OBJECT *ret);
387int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
388 int len, X509_OBJECT *ret);
389int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
390
391#ifndef OPENSSL_NO_STDIO
392int X509_STORE_load_locations (X509_STORE *ctx,
393 const char *file, const char *dir);
394int X509_STORE_set_default_paths(X509_STORE *ctx);
395#endif
396
397int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
398 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
399int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
400void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
401int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
402void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
403int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
404X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
405STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
406STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
407void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
408void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
409int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
410int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
411int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
412 int purpose, int trust);
413void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, long flags);
414void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, long flags, time_t t);
415void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
416 int (*verify_cb)(int, X509_STORE_CTX *));
417
418#ifdef __cplusplus
419}
420#endif
421#endif
422
diff --git a/src/lib/libcrypto/x509/x509cset.c b/src/lib/libcrypto/x509/x509cset.c
new file mode 100644
index 0000000000..9d1646d5c8
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509cset.c
@@ -0,0 +1,170 @@
1/* crypto/x509/x509cset.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_CRL_set_version(X509_CRL *x, long version)
67 {
68 if (x == NULL) return(0);
69 if (x->crl->version == NULL)
70 {
71 if ((x->crl->version=M_ASN1_INTEGER_new()) == NULL)
72 return(0);
73 }
74 return(ASN1_INTEGER_set(x->crl->version,version));
75 }
76
77int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
78 {
79 if ((x == NULL) || (x->crl == NULL)) return(0);
80 return(X509_NAME_set(&x->crl->issuer,name));
81 }
82
83
84int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm)
85 {
86 ASN1_TIME *in;
87
88 if (x == NULL) return(0);
89 in=x->crl->lastUpdate;
90 if (in != tm)
91 {
92 in=M_ASN1_TIME_dup(tm);
93 if (in != NULL)
94 {
95 M_ASN1_TIME_free(x->crl->lastUpdate);
96 x->crl->lastUpdate=in;
97 }
98 }
99 return(in != NULL);
100 }
101
102int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm)
103 {
104 ASN1_TIME *in;
105
106 if (x == NULL) return(0);
107 in=x->crl->nextUpdate;
108 if (in != tm)
109 {
110 in=M_ASN1_TIME_dup(tm);
111 if (in != NULL)
112 {
113 M_ASN1_TIME_free(x->crl->nextUpdate);
114 x->crl->nextUpdate=in;
115 }
116 }
117 return(in != NULL);
118 }
119
120int X509_CRL_sort(X509_CRL *c)
121 {
122 int i;
123 X509_REVOKED *r;
124 /* sort the data so it will be written in serial
125 * number order */
126 sk_X509_REVOKED_sort(c->crl->revoked);
127 for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++)
128 {
129 r=sk_X509_REVOKED_value(c->crl->revoked,i);
130 r->sequence=i;
131 }
132 c->crl->enc.modified = 1;
133 return 1;
134 }
135
136int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
137 {
138 ASN1_TIME *in;
139
140 if (x == NULL) return(0);
141 in=x->revocationDate;
142 if (in != tm)
143 {
144 in=M_ASN1_TIME_dup(tm);
145 if (in != NULL)
146 {
147 M_ASN1_TIME_free(x->revocationDate);
148 x->revocationDate=in;
149 }
150 }
151 return(in != NULL);
152 }
153
154int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
155 {
156 ASN1_INTEGER *in;
157
158 if (x == NULL) return(0);
159 in=x->serialNumber;
160 if (in != serial)
161 {
162 in=M_ASN1_INTEGER_dup(serial);
163 if (in != NULL)
164 {
165 M_ASN1_INTEGER_free(x->serialNumber);
166 x->serialNumber=in;
167 }
168 }
169 return(in != NULL);
170 }
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
new file mode 100644
index 0000000000..068abfe5f0
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509name.c
@@ -0,0 +1,383 @@
1/* crypto/x509/x509name.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66
67int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
68 {
69 ASN1_OBJECT *obj;
70
71 obj=OBJ_nid2obj(nid);
72 if (obj == NULL) return(-1);
73 return(X509_NAME_get_text_by_OBJ(name,obj,buf,len));
74 }
75
76int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,
77 int len)
78 {
79 int i;
80 ASN1_STRING *data;
81
82 i=X509_NAME_get_index_by_OBJ(name,obj,-1);
83 if (i < 0) return(-1);
84 data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i));
85 i=(data->length > (len-1))?(len-1):data->length;
86 if (buf == NULL) return(data->length);
87 memcpy(buf,data->data,i);
88 buf[i]='\0';
89 return(i);
90 }
91
92int X509_NAME_entry_count(X509_NAME *name)
93 {
94 if (name == NULL) return(0);
95 return(sk_X509_NAME_ENTRY_num(name->entries));
96 }
97
98int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
99 {
100 ASN1_OBJECT *obj;
101
102 obj=OBJ_nid2obj(nid);
103 if (obj == NULL) return(-2);
104 return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));
105 }
106
107/* NOTE: you should be passsing -1, not 0 as lastpos */
108int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
109 int lastpos)
110 {
111 int n;
112 X509_NAME_ENTRY *ne;
113 STACK_OF(X509_NAME_ENTRY) *sk;
114
115 if (name == NULL) return(-1);
116 if (lastpos < 0)
117 lastpos= -1;
118 sk=name->entries;
119 n=sk_X509_NAME_ENTRY_num(sk);
120 for (lastpos++; lastpos < n; lastpos++)
121 {
122 ne=sk_X509_NAME_ENTRY_value(sk,lastpos);
123 if (OBJ_cmp(ne->object,obj) == 0)
124 return(lastpos);
125 }
126 return(-1);
127 }
128
129X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
130 {
131 if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
132 || loc < 0)
133 return(NULL);
134 else
135 return(sk_X509_NAME_ENTRY_value(name->entries,loc));
136 }
137
138X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)
139 {
140 X509_NAME_ENTRY *ret;
141 int i,n,set_prev,set_next;
142 STACK_OF(X509_NAME_ENTRY) *sk;
143
144 if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
145 || loc < 0)
146 return(NULL);
147 sk=name->entries;
148 ret=sk_X509_NAME_ENTRY_delete(sk,loc);
149 n=sk_X509_NAME_ENTRY_num(sk);
150 name->modified=1;
151 if (loc == n) return(ret);
152
153 /* else we need to fixup the set field */
154 if (loc != 0)
155 set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set;
156 else
157 set_prev=ret->set-1;
158 set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set;
159
160 /* set_prev is the previous set
161 * set is the current set
162 * set_next is the following
163 * prev 1 1 1 1 1 1 1 1
164 * set 1 1 2 2
165 * next 1 1 2 2 2 2 3 2
166 * so basically only if prev and next differ by 2, then
167 * re-number down by 1 */
168 if (set_prev+1 < set_next)
169 for (i=loc; i<n; i++)
170 sk_X509_NAME_ENTRY_value(sk,i)->set--;
171 return(ret);
172 }
173
174int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
175 unsigned char *bytes, int len, int loc, int set)
176{
177 X509_NAME_ENTRY *ne;
178 int ret;
179 ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len);
180 if(!ne) return 0;
181 ret = X509_NAME_add_entry(name, ne, loc, set);
182 X509_NAME_ENTRY_free(ne);
183 return ret;
184}
185
186int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
187 unsigned char *bytes, int len, int loc, int set)
188{
189 X509_NAME_ENTRY *ne;
190 int ret;
191 ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len);
192 if(!ne) return 0;
193 ret = X509_NAME_add_entry(name, ne, loc, set);
194 X509_NAME_ENTRY_free(ne);
195 return ret;
196}
197
198int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
199 const unsigned char *bytes, int len, int loc, int set)
200{
201 X509_NAME_ENTRY *ne;
202 int ret;
203 ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len);
204 if(!ne) return 0;
205 ret = X509_NAME_add_entry(name, ne, loc, set);
206 X509_NAME_ENTRY_free(ne);
207 return ret;
208}
209
210/* if set is -1, append to previous set, 0 'a new one', and 1,
211 * prepend to the guy we are about to stomp on. */
212int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
213 int set)
214 {
215 X509_NAME_ENTRY *new_name=NULL;
216 int n,i,inc;
217 STACK_OF(X509_NAME_ENTRY) *sk;
218
219 if (name == NULL) return(0);
220 sk=name->entries;
221 n=sk_X509_NAME_ENTRY_num(sk);
222 if (loc > n) loc=n;
223 else if (loc < 0) loc=n;
224
225 name->modified=1;
226
227 if (set == -1)
228 {
229 if (loc == 0)
230 {
231 set=0;
232 inc=1;
233 }
234 else
235 {
236 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set;
237 inc=0;
238 }
239 }
240 else /* if (set >= 0) */
241 {
242 if (loc >= n)
243 {
244 if (loc != 0)
245 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1;
246 else
247 set=0;
248 }
249 else
250 set=sk_X509_NAME_ENTRY_value(sk,loc)->set;
251 inc=(set == 0)?1:0;
252 }
253
254 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)
255 goto err;
256 new_name->set=set;
257 if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc))
258 {
259 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);
260 goto err;
261 }
262 if (inc)
263 {
264 n=sk_X509_NAME_ENTRY_num(sk);
265 for (i=loc+1; i<n; i++)
266 sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1;
267 }
268 return(1);
269err:
270 if (new_name != NULL)
271 X509_NAME_ENTRY_free(new_name);
272 return(0);
273 }
274
275X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
276 const char *field, int type, const unsigned char *bytes, int len)
277 {
278 ASN1_OBJECT *obj;
279 X509_NAME_ENTRY *nentry;
280
281 obj=OBJ_txt2obj(field, 0);
282 if (obj == NULL)
283 {
284 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,
285 X509_R_INVALID_FIELD_NAME);
286 ERR_add_error_data(2, "name=", field);
287 return(NULL);
288 }
289 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len);
290 ASN1_OBJECT_free(obj);
291 return nentry;
292 }
293
294X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
295 int type, unsigned char *bytes, int len)
296 {
297 ASN1_OBJECT *obj;
298 X509_NAME_ENTRY *nentry;
299
300 obj=OBJ_nid2obj(nid);
301 if (obj == NULL)
302 {
303 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID);
304 return(NULL);
305 }
306 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len);
307 ASN1_OBJECT_free(obj);
308 return nentry;
309 }
310
311X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
312 ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len)
313 {
314 X509_NAME_ENTRY *ret;
315
316 if ((ne == NULL) || (*ne == NULL))
317 {
318 if ((ret=X509_NAME_ENTRY_new()) == NULL)
319 return(NULL);
320 }
321 else
322 ret= *ne;
323
324 if (!X509_NAME_ENTRY_set_object(ret,obj))
325 goto err;
326 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len))
327 goto err;
328
329 if ((ne != NULL) && (*ne == NULL)) *ne=ret;
330 return(ret);
331err:
332 if ((ne == NULL) || (ret != *ne))
333 X509_NAME_ENTRY_free(ret);
334 return(NULL);
335 }
336
337int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj)
338 {
339 if ((ne == NULL) || (obj == NULL))
340 {
341 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER);
342 return(0);
343 }
344 ASN1_OBJECT_free(ne->object);
345 ne->object=OBJ_dup(obj);
346 return((ne->object == NULL)?0:1);
347 }
348
349int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
350 const unsigned char *bytes, int len)
351 {
352 int i;
353
354 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0);
355 if((type > 0) && (type & MBSTRING_FLAG))
356 return ASN1_STRING_set_by_NID(&ne->value, bytes,
357 len, type,
358 OBJ_obj2nid(ne->object)) ? 1 : 0;
359 if (len < 0) len=strlen((char *)bytes);
360 i=ASN1_STRING_set(ne->value,bytes,len);
361 if (!i) return(0);
362 if (type != V_ASN1_UNDEF)
363 {
364 if (type == V_ASN1_APP_CHOOSE)
365 ne->value->type=ASN1_PRINTABLE_type(bytes,len);
366 else
367 ne->value->type=type;
368 }
369 return(1);
370 }
371
372ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
373 {
374 if (ne == NULL) return(NULL);
375 return(ne->object);
376 }
377
378ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
379 {
380 if (ne == NULL) return(NULL);
381 return(ne->value);
382 }
383
diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c
new file mode 100644
index 0000000000..d9f6b57372
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509rset.c
@@ -0,0 +1,83 @@
1/* crypto/x509/x509rset.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_REQ_set_version(X509_REQ *x, long version)
67 {
68 if (x == NULL) return(0);
69 return(ASN1_INTEGER_set(x->req_info->version,version));
70 }
71
72int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name)
73 {
74 if ((x == NULL) || (x->req_info == NULL)) return(0);
75 return(X509_NAME_set(&x->req_info->subject,name));
76 }
77
78int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey)
79 {
80 if ((x == NULL) || (x->req_info == NULL)) return(0);
81 return(X509_PUBKEY_set(&x->req_info->pubkey,pkey));
82 }
83
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c
new file mode 100644
index 0000000000..4c3af946ec
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509spki.c
@@ -0,0 +1,120 @@
1/* x509spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62
63int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
64{
65 if ((x == NULL) || (x->spkac == NULL)) return(0);
66 return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey));
67}
68
69EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x)
70{
71 if ((x == NULL) || (x->spkac == NULL))
72 return(NULL);
73 return(X509_PUBKEY_get(x->spkac->pubkey));
74}
75
76/* Load a Netscape SPKI from a base64 encoded string */
77
78NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
79{
80 unsigned char *spki_der, *p;
81 int spki_len;
82 NETSCAPE_SPKI *spki;
83 if(len <= 0) len = strlen(str);
84 if (!(spki_der = OPENSSL_malloc(len + 1))) {
85 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
86 return NULL;
87 }
88 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
89 if(spki_len < 0) {
90 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE,
91 X509_R_BASE64_DECODE_ERROR);
92 OPENSSL_free(spki_der);
93 return NULL;
94 }
95 p = spki_der;
96 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
97 OPENSSL_free(spki_der);
98 return spki;
99}
100
101/* Generate a base64 encoded string from an SPKI */
102
103char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
104{
105 unsigned char *der_spki, *p;
106 char *b64_str;
107 int der_len;
108 der_len = i2d_NETSCAPE_SPKI(spki, NULL);
109 der_spki = OPENSSL_malloc(der_len);
110 b64_str = OPENSSL_malloc(der_len * 2);
111 if(!der_spki || !b64_str) {
112 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115 p = der_spki;
116 i2d_NETSCAPE_SPKI(spki, &p);
117 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
118 OPENSSL_free(der_spki);
119 return b64_str;
120}
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c
new file mode 100644
index 0000000000..c25959a742
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509type.c
@@ -0,0 +1,115 @@
1/* crypto/x509/x509type.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int X509_certificate_type(X509 *x, EVP_PKEY *pkey)
66 {
67 EVP_PKEY *pk;
68 int ret=0,i;
69
70 if (x == NULL) return(0);
71
72 if (pkey == NULL)
73 pk=X509_get_pubkey(x);
74 else
75 pk=pkey;
76
77 if (pk == NULL) return(0);
78
79 switch (pk->type)
80 {
81 case EVP_PKEY_RSA:
82 ret=EVP_PK_RSA|EVP_PKT_SIGN;
83/* if (!sign only extension) */
84 ret|=EVP_PKT_ENC;
85 break;
86 case EVP_PKEY_DSA:
87 ret=EVP_PK_DSA|EVP_PKT_SIGN;
88 break;
89 case EVP_PKEY_DH:
90 ret=EVP_PK_DH|EVP_PKT_EXCH;
91 break;
92 default:
93 break;
94 }
95
96 i=X509_get_signature_type(x);
97 switch (i)
98 {
99 case EVP_PKEY_RSA:
100 ret|=EVP_PKS_RSA;
101 break;
102 case EVP_PKEY_DSA:
103 ret|=EVP_PKS_DSA;
104 break;
105 default:
106 break;
107 }
108
109 if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look
110 for, not bytes */
111 ret|=EVP_PKT_EXP;
112 if(pkey==NULL) EVP_PKEY_free(pk);
113 return(ret);
114 }
115
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
new file mode 100644
index 0000000000..ac6dea493a
--- /dev/null
+++ b/src/lib/libcrypto/x509/x_all.c
@@ -0,0 +1,489 @@
1/* crypto/x509/x_all.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include <openssl/stack.h>
62#include "cryptlib.h"
63#include <openssl/buffer.h>
64#include <openssl/asn1.h>
65#include <openssl/evp.h>
66#include <openssl/x509.h>
67
68int X509_verify(X509 *a, EVP_PKEY *r)
69 {
70 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg,
71 a->signature,a->cert_info,r));
72 }
73
74int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
75 {
76 return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO),
77 a->sig_alg,a->signature,a->req_info,r));
78 }
79
80int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r)
81 {
82 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
83 a->sig_alg, a->signature,a->crl,r));
84 }
85
86int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r)
87 {
88 return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC),
89 a->sig_algor,a->signature,a->spkac,r));
90 }
91
92int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
93 {
94 return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature,
95 x->sig_alg, x->signature, x->cert_info,pkey,md));
96 }
97
98int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md)
99 {
100 return(ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO),x->sig_alg, NULL,
101 x->signature, x->req_info,pkey,md));
102 }
103
104int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
105 {
106 x->crl->enc.modified = 1;
107 return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO),x->crl->sig_alg,
108 x->sig_alg, x->signature, x->crl,pkey,md));
109 }
110
111int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
112 {
113 return(ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,NULL,
114 x->signature, x->spkac,pkey,md));
115 }
116
117#ifndef OPENSSL_NO_FP_API
118X509 *d2i_X509_fp(FILE *fp, X509 **x509)
119 {
120 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509);
121 }
122
123int i2d_X509_fp(FILE *fp, X509 *x509)
124 {
125 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509);
126 }
127#endif
128
129X509 *d2i_X509_bio(BIO *bp, X509 **x509)
130 {
131 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509);
132 }
133
134int i2d_X509_bio(BIO *bp, X509 *x509)
135 {
136 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509);
137 }
138
139#ifndef OPENSSL_NO_FP_API
140X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl)
141 {
142 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
143 }
144
145int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl)
146 {
147 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
148 }
149#endif
150
151X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl)
152 {
153 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
154 }
155
156int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl)
157 {
158 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
159 }
160
161#ifndef OPENSSL_NO_FP_API
162PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
163 {
164 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
165 }
166
167int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
168 {
169 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
170 }
171#endif
172
173PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
174 {
175 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
176 }
177
178int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
179 {
180 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
181 }
182
183#ifndef OPENSSL_NO_FP_API
184X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req)
185 {
186 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
187 }
188
189int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req)
190 {
191 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
192 }
193#endif
194
195X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req)
196 {
197 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
198 }
199
200int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req)
201 {
202 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
203 }
204
205#ifndef OPENSSL_NO_RSA
206
207#ifndef OPENSSL_NO_FP_API
208RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa)
209 {
210 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa);
211 }
212
213int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa)
214 {
215 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa);
216 }
217
218RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
219 {
220 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa);
221 }
222
223
224RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
225 {
226 return((RSA *)ASN1_d2i_fp((char *(*)())
227 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (fp),
228 (unsigned char **)(rsa)));
229 }
230
231int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
232 {
233 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa);
234 }
235
236int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
237 {
238 return(ASN1_i2d_fp(i2d_RSA_PUBKEY,fp,(unsigned char *)rsa));
239 }
240#endif
241
242RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
243 {
244 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa);
245 }
246
247int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa)
248 {
249 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa);
250 }
251
252RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
253 {
254 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa);
255 }
256
257
258RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
259 {
260 return((RSA *)ASN1_d2i_bio((char *(*)())
261 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (bp),
262 (unsigned char **)(rsa)));
263 }
264
265int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
266 {
267 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa);
268 }
269
270int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
271 {
272 return(ASN1_i2d_bio(i2d_RSA_PUBKEY,bp,(unsigned char *)rsa));
273 }
274#endif
275
276#ifndef OPENSSL_NO_DSA
277#ifndef OPENSSL_NO_FP_API
278DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
279 {
280 return((DSA *)ASN1_d2i_fp((char *(*)())
281 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
282 (unsigned char **)(dsa)));
283 }
284
285int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
286 {
287 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
288 }
289
290DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
291 {
292 return((DSA *)ASN1_d2i_fp((char *(*)())
293 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (fp),
294 (unsigned char **)(dsa)));
295 }
296
297int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
298 {
299 return(ASN1_i2d_fp(i2d_DSA_PUBKEY,fp,(unsigned char *)dsa));
300 }
301#endif
302
303DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
304 {
305 return((DSA *)ASN1_d2i_bio((char *(*)())
306 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
307 (unsigned char **)(dsa)));
308 }
309
310int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
311 {
312 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
313 }
314
315DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
316 {
317 return((DSA *)ASN1_d2i_bio((char *(*)())
318 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (bp),
319 (unsigned char **)(dsa)));
320 }
321
322int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
323 {
324 return(ASN1_i2d_bio(i2d_DSA_PUBKEY,bp,(unsigned char *)dsa));
325 }
326
327#endif
328
329int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
330 unsigned int *len)
331 {
332 ASN1_BIT_STRING *key;
333 key = X509_get0_pubkey_bitstr(data);
334 if(!key) return 0;
335 return EVP_Digest(key->data, key->length, md, len, type, NULL);
336 }
337
338int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
339 unsigned int *len)
340 {
341 return(ASN1_item_digest(ASN1_ITEM_rptr(X509),type,(char *)data,md,len));
342 }
343
344int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md,
345 unsigned int *len)
346 {
347 return(ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL),type,(char *)data,md,len));
348 }
349
350int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md,
351 unsigned int *len)
352 {
353 return(ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ),type,(char *)data,md,len));
354 }
355
356int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md,
357 unsigned int *len)
358 {
359 return(ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME),type,(char *)data,md,len));
360 }
361
362int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type,
363 unsigned char *md, unsigned int *len)
364 {
365 return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL),type,
366 (char *)data,md,len));
367 }
368
369
370#ifndef OPENSSL_NO_FP_API
371X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
372 {
373 return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
374 (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
375 }
376
377int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
378 {
379 return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
380 }
381#endif
382
383X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
384 {
385 return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
386 (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
387 }
388
389int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
390 {
391 return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
392 }
393
394#ifndef OPENSSL_NO_FP_API
395PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
396 PKCS8_PRIV_KEY_INFO **p8inf)
397 {
398 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
399 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
400 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
401 (unsigned char **)(p8inf)));
402 }
403
404int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
405 {
406 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
407 }
408
409int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
410 {
411 PKCS8_PRIV_KEY_INFO *p8inf;
412 int ret;
413 p8inf = EVP_PKEY2PKCS8(key);
414 if(!p8inf) return 0;
415 ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf);
416 PKCS8_PRIV_KEY_INFO_free(p8inf);
417 return ret;
418 }
419
420int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
421 {
422 return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey));
423 }
424
425EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
426{
427 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
428 (char *(*)())d2i_AutoPrivateKey, (fp),(unsigned char **)(a)));
429}
430
431int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey)
432 {
433 return(ASN1_i2d_fp(i2d_PUBKEY,fp,(unsigned char *)pkey));
434 }
435
436EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a)
437{
438 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
439 (char *(*)())d2i_PUBKEY, (fp),(unsigned char **)(a)));
440}
441
442#endif
443
444PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
445 PKCS8_PRIV_KEY_INFO **p8inf)
446 {
447 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
448 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
449 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
450 (unsigned char **)(p8inf)));
451 }
452
453int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
454 {
455 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
456 }
457
458int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
459 {
460 PKCS8_PRIV_KEY_INFO *p8inf;
461 int ret;
462 p8inf = EVP_PKEY2PKCS8(key);
463 if(!p8inf) return 0;
464 ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
465 PKCS8_PRIV_KEY_INFO_free(p8inf);
466 return ret;
467 }
468
469int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey)
470 {
471 return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey));
472 }
473
474EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
475 {
476 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
477 (char *(*)())d2i_AutoPrivateKey, (bp),(unsigned char **)(a)));
478 }
479
480int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey)
481 {
482 return(ASN1_i2d_bio(i2d_PUBKEY,bp,(unsigned char *)pkey));
483 }
484
485EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a)
486 {
487 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
488 (char *(*)())d2i_PUBKEY, (bp),(unsigned char **)(a)));
489 }
diff --git a/src/lib/libcrypto/x509v3/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
new file mode 100644
index 0000000000..d8328ac468
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/ext_dat.h
@@ -0,0 +1,118 @@
1/* ext_dat.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* This file contains a table of "standard" extensions */
59
60extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
61extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info, v3_sinfo;
62extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
63extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_crl_invdate;
64extern X509V3_EXT_METHOD v3_delta_crl, v3_cpols, v3_crld;
65extern X509V3_EXT_METHOD v3_ocsp_nonce, v3_ocsp_accresp, v3_ocsp_acutoff;
66extern X509V3_EXT_METHOD v3_ocsp_crlid, v3_ocsp_nocheck, v3_ocsp_serviceloc;
67extern X509V3_EXT_METHOD v3_crl_hold, v3_pci;
68
69/* This table will be searched using OBJ_bsearch so it *must* kept in
70 * order of the ext_nid values.
71 */
72
73static X509V3_EXT_METHOD *standard_exts[] = {
74&v3_nscert,
75&v3_ns_ia5_list[0],
76&v3_ns_ia5_list[1],
77&v3_ns_ia5_list[2],
78&v3_ns_ia5_list[3],
79&v3_ns_ia5_list[4],
80&v3_ns_ia5_list[5],
81&v3_ns_ia5_list[6],
82&v3_skey_id,
83&v3_key_usage,
84&v3_pkey_usage_period,
85&v3_alt[0],
86&v3_alt[1],
87&v3_bcons,
88&v3_crl_num,
89&v3_cpols,
90&v3_akey_id,
91&v3_crld,
92&v3_ext_ku,
93&v3_delta_crl,
94&v3_crl_reason,
95#ifndef OPENSSL_NO_OCSP
96&v3_crl_invdate,
97#endif
98&v3_sxnet,
99&v3_info,
100#ifndef OPENSSL_NO_OCSP
101&v3_ocsp_nonce,
102&v3_ocsp_crlid,
103&v3_ocsp_accresp,
104&v3_ocsp_nocheck,
105&v3_ocsp_acutoff,
106&v3_ocsp_serviceloc,
107#endif
108&v3_sinfo,
109#ifndef OPENSSL_NO_OCSP
110&v3_crl_hold,
111#endif
112&v3_pci,
113};
114
115/* Number of standard extensions */
116
117#define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))
118
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
new file mode 100644
index 0000000000..97e686f97a
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_akey.c
@@ -0,0 +1,190 @@
1/* v3_akey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
67 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist);
68static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
70
71X509V3_EXT_METHOD v3_akey_id = {
72NID_authority_key_identifier, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_KEYID),
730,0,0,0,
740,0,
75(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID,
76(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
770,0,
78NULL
79};
80
81static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
82 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist)
83{
84 char *tmp;
85 if(akeyid->keyid) {
86 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
87 X509V3_add_value("keyid", tmp, &extlist);
88 OPENSSL_free(tmp);
89 }
90 if(akeyid->issuer)
91 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
92 if(akeyid->serial) {
93 tmp = hex_to_string(akeyid->serial->data,
94 akeyid->serial->length);
95 X509V3_add_value("serial", tmp, &extlist);
96 OPENSSL_free(tmp);
97 }
98 return extlist;
99}
100
101/* Currently two options:
102 * keyid: use the issuers subject keyid, the value 'always' means its is
103 * an error if the issuer certificate doesn't have a key id.
104 * issuer: use the issuers cert issuer and serial number. The default is
105 * to only use this if keyid is not present. With the option 'always'
106 * this is always included.
107 */
108
109static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
110 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
111{
112char keyid=0, issuer=0;
113int i;
114CONF_VALUE *cnf;
115ASN1_OCTET_STRING *ikeyid = NULL;
116X509_NAME *isname = NULL;
117GENERAL_NAMES * gens = NULL;
118GENERAL_NAME *gen = NULL;
119ASN1_INTEGER *serial = NULL;
120X509_EXTENSION *ext;
121X509 *cert;
122AUTHORITY_KEYID *akeyid;
123for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
124 cnf = sk_CONF_VALUE_value(values, i);
125 if(!strcmp(cnf->name, "keyid")) {
126 keyid = 1;
127 if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2;
128 } else if(!strcmp(cnf->name, "issuer")) {
129 issuer = 1;
130 if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2;
131 } else {
132 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
133 ERR_add_error_data(2, "name=", cnf->name);
134 return NULL;
135 }
136}
137
138if(!ctx || !ctx->issuer_cert) {
139 if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new();
140 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
141 return NULL;
142}
143
144cert = ctx->issuer_cert;
145
146if(keyid) {
147 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
148 if((i >= 0) && (ext = X509_get_ext(cert, i)))
149 ikeyid = X509V3_EXT_d2i(ext);
150 if(keyid==2 && !ikeyid) {
151 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
152 return NULL;
153 }
154}
155
156if((issuer && !ikeyid) || (issuer == 2)) {
157 isname = X509_NAME_dup(X509_get_issuer_name(cert));
158 serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert));
159 if(!isname || !serial) {
160 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
161 goto err;
162 }
163}
164
165if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
166
167if(isname) {
168 if(!(gens = sk_GENERAL_NAME_new_null()) || !(gen = GENERAL_NAME_new())
169 || !sk_GENERAL_NAME_push(gens, gen)) {
170 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
171 goto err;
172 }
173 gen->type = GEN_DIRNAME;
174 gen->d.dirn = isname;
175}
176
177akeyid->issuer = gens;
178akeyid->serial = serial;
179akeyid->keyid = ikeyid;
180
181return akeyid;
182
183err:
184X509_NAME_free(isname);
185M_ASN1_INTEGER_free(serial);
186M_ASN1_OCTET_STRING_free(ikeyid);
187return NULL;
188
189}
190
diff --git a/src/lib/libcrypto/x509v3/v3_akeya.c b/src/lib/libcrypto/x509v3/v3_akeya.c
new file mode 100644
index 0000000000..2aafa26ba7
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_akeya.c
@@ -0,0 +1,72 @@
1/* v3_akey_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(AUTHORITY_KEYID) = {
67 ASN1_IMP_OPT(AUTHORITY_KEYID, keyid, ASN1_OCTET_STRING, 0),
68 ASN1_IMP_SEQUENCE_OF_OPT(AUTHORITY_KEYID, issuer, GENERAL_NAME, 1),
69 ASN1_IMP_OPT(AUTHORITY_KEYID, serial, ASN1_INTEGER, 2)
70} ASN1_SEQUENCE_END(AUTHORITY_KEYID)
71
72IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_KEYID)
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
new file mode 100644
index 0000000000..58b935a3b6
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_alt.c
@@ -0,0 +1,458 @@
1/* v3_alt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
65static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p);
67static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens);
68X509V3_EXT_METHOD v3_alt[] = {
69{ NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
700,0,0,0,
710,0,
72(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
73(X509V3_EXT_V2I)v2i_subject_alt,
74NULL, NULL, NULL},
75
76{ NID_issuer_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
770,0,0,0,
780,0,
79(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
80(X509V3_EXT_V2I)v2i_issuer_alt,
81NULL, NULL, NULL},
82};
83
84STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
85 GENERAL_NAMES *gens, STACK_OF(CONF_VALUE) *ret)
86{
87 int i;
88 GENERAL_NAME *gen;
89 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
90 gen = sk_GENERAL_NAME_value(gens, i);
91 ret = i2v_GENERAL_NAME(method, gen, ret);
92 }
93 if(!ret) return sk_CONF_VALUE_new_null();
94 return ret;
95}
96
97STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
98 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
99{
100 unsigned char *p;
101 char oline[256];
102 switch (gen->type)
103 {
104 case GEN_OTHERNAME:
105 X509V3_add_value("othername","<unsupported>", &ret);
106 break;
107
108 case GEN_X400:
109 X509V3_add_value("X400Name","<unsupported>", &ret);
110 break;
111
112 case GEN_EDIPARTY:
113 X509V3_add_value("EdiPartyName","<unsupported>", &ret);
114 break;
115
116 case GEN_EMAIL:
117 X509V3_add_value_uchar("email",gen->d.ia5->data, &ret);
118 break;
119
120 case GEN_DNS:
121 X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);
122 break;
123
124 case GEN_URI:
125 X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);
126 break;
127
128 case GEN_DIRNAME:
129 X509_NAME_oneline(gen->d.dirn, oline, 256);
130 X509V3_add_value("DirName",oline, &ret);
131 break;
132
133 case GEN_IPADD:
134 p = gen->d.ip->data;
135 /* BUG: doesn't support IPV6 */
136 if(gen->d.ip->length != 4) {
137 X509V3_add_value("IP Address","<invalid>", &ret);
138 break;
139 }
140 BIO_snprintf(oline, sizeof oline,
141 "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
142 X509V3_add_value("IP Address",oline, &ret);
143 break;
144
145 case GEN_RID:
146 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
147 X509V3_add_value("Registered ID",oline, &ret);
148 break;
149 }
150 return ret;
151}
152
153int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
154{
155 unsigned char *p;
156 switch (gen->type)
157 {
158 case GEN_OTHERNAME:
159 BIO_printf(out, "othername:<unsupported>");
160 break;
161
162 case GEN_X400:
163 BIO_printf(out, "X400Name:<unsupported>");
164 break;
165
166 case GEN_EDIPARTY:
167 /* Maybe fix this: it is supported now */
168 BIO_printf(out, "EdiPartyName:<unsupported>");
169 break;
170
171 case GEN_EMAIL:
172 BIO_printf(out, "email:%s",gen->d.ia5->data);
173 break;
174
175 case GEN_DNS:
176 BIO_printf(out, "DNS:%s",gen->d.ia5->data);
177 break;
178
179 case GEN_URI:
180 BIO_printf(out, "URI:%s",gen->d.ia5->data);
181 break;
182
183 case GEN_DIRNAME:
184 BIO_printf(out, "DirName: ");
185 X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE);
186 break;
187
188 case GEN_IPADD:
189 p = gen->d.ip->data;
190 /* BUG: doesn't support IPV6 */
191 if(gen->d.ip->length != 4) {
192 BIO_printf(out,"IP Address:<invalid>");
193 break;
194 }
195 BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
196 break;
197
198 case GEN_RID:
199 BIO_printf(out, "Registered ID");
200 i2a_ASN1_OBJECT(out, gen->d.rid);
201 break;
202 }
203 return 1;
204}
205
206static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
207 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
208{
209 GENERAL_NAMES *gens = NULL;
210 CONF_VALUE *cnf;
211 int i;
212 if(!(gens = sk_GENERAL_NAME_new_null())) {
213 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
214 return NULL;
215 }
216 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
217 cnf = sk_CONF_VALUE_value(nval, i);
218 if(!name_cmp(cnf->name, "issuer") && cnf->value &&
219 !strcmp(cnf->value, "copy")) {
220 if(!copy_issuer(ctx, gens)) goto err;
221 } else {
222 GENERAL_NAME *gen;
223 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
224 goto err;
225 sk_GENERAL_NAME_push(gens, gen);
226 }
227 }
228 return gens;
229 err:
230 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
231 return NULL;
232}
233
234/* Append subject altname of issuer to issuer alt name of subject */
235
236static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
237{
238 GENERAL_NAMES *ialt;
239 GENERAL_NAME *gen;
240 X509_EXTENSION *ext;
241 int i;
242 if(ctx && (ctx->flags == CTX_TEST)) return 1;
243 if(!ctx || !ctx->issuer_cert) {
244 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS);
245 goto err;
246 }
247 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
248 if(i < 0) return 1;
249 if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
250 !(ialt = X509V3_EXT_d2i(ext)) ) {
251 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
252 goto err;
253 }
254
255 for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
256 gen = sk_GENERAL_NAME_value(ialt, i);
257 if(!sk_GENERAL_NAME_push(gens, gen)) {
258 X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
259 goto err;
260 }
261 }
262 sk_GENERAL_NAME_free(ialt);
263
264 return 1;
265
266 err:
267 return 0;
268
269}
270
271static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
272 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
273{
274 GENERAL_NAMES *gens = NULL;
275 CONF_VALUE *cnf;
276 int i;
277 if(!(gens = sk_GENERAL_NAME_new_null())) {
278 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
279 return NULL;
280 }
281 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
282 cnf = sk_CONF_VALUE_value(nval, i);
283 if(!name_cmp(cnf->name, "email") && cnf->value &&
284 !strcmp(cnf->value, "copy")) {
285 if(!copy_email(ctx, gens, 0)) goto err;
286 } else if(!name_cmp(cnf->name, "email") && cnf->value &&
287 !strcmp(cnf->value, "move")) {
288 if(!copy_email(ctx, gens, 1)) goto err;
289 } else {
290 GENERAL_NAME *gen;
291 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
292 goto err;
293 sk_GENERAL_NAME_push(gens, gen);
294 }
295 }
296 return gens;
297 err:
298 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
299 return NULL;
300}
301
302/* Copy any email addresses in a certificate or request to
303 * GENERAL_NAMES
304 */
305
306static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
307{
308 X509_NAME *nm;
309 ASN1_IA5STRING *email = NULL;
310 X509_NAME_ENTRY *ne;
311 GENERAL_NAME *gen = NULL;
312 int i;
313 if(ctx->flags == CTX_TEST) return 1;
314 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
315 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
316 goto err;
317 }
318 /* Find the subject name */
319 if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert);
320 else nm = X509_REQ_get_subject_name(ctx->subject_req);
321
322 /* Now add any email address(es) to STACK */
323 i = -1;
324 while((i = X509_NAME_get_index_by_NID(nm,
325 NID_pkcs9_emailAddress, i)) >= 0) {
326 ne = X509_NAME_get_entry(nm, i);
327 email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
328 if (move_p)
329 {
330 X509_NAME_delete_entry(nm, i);
331 i--;
332 }
333 if(!email || !(gen = GENERAL_NAME_new())) {
334 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
335 goto err;
336 }
337 gen->d.ia5 = email;
338 email = NULL;
339 gen->type = GEN_EMAIL;
340 if(!sk_GENERAL_NAME_push(gens, gen)) {
341 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
342 goto err;
343 }
344 gen = NULL;
345 }
346
347
348 return 1;
349
350 err:
351 GENERAL_NAME_free(gen);
352 M_ASN1_IA5STRING_free(email);
353 return 0;
354
355}
356
357GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
358 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
359{
360 GENERAL_NAME *gen;
361 GENERAL_NAMES *gens = NULL;
362 CONF_VALUE *cnf;
363 int i;
364 if(!(gens = sk_GENERAL_NAME_new_null())) {
365 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
366 return NULL;
367 }
368 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
369 cnf = sk_CONF_VALUE_value(nval, i);
370 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
371 sk_GENERAL_NAME_push(gens, gen);
372 }
373 return gens;
374 err:
375 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
376 return NULL;
377}
378
379GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
380 CONF_VALUE *cnf)
381{
382char is_string = 0;
383int type;
384GENERAL_NAME *gen = NULL;
385
386char *name, *value;
387
388name = cnf->name;
389value = cnf->value;
390
391if(!value) {
392 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
393 return NULL;
394}
395
396if(!(gen = GENERAL_NAME_new())) {
397 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
398 return NULL;
399}
400
401if(!name_cmp(name, "email")) {
402 is_string = 1;
403 type = GEN_EMAIL;
404} else if(!name_cmp(name, "URI")) {
405 is_string = 1;
406 type = GEN_URI;
407} else if(!name_cmp(name, "DNS")) {
408 is_string = 1;
409 type = GEN_DNS;
410} else if(!name_cmp(name, "RID")) {
411 ASN1_OBJECT *obj;
412 if(!(obj = OBJ_txt2obj(value,0))) {
413 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
414 ERR_add_error_data(2, "value=", value);
415 goto err;
416 }
417 gen->d.rid = obj;
418 type = GEN_RID;
419} else if(!name_cmp(name, "IP")) {
420 int i1,i2,i3,i4;
421 unsigned char ip[4];
422 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
423 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
424 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
425 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
426 ERR_add_error_data(2, "value=", value);
427 goto err;
428 }
429 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
430 if(!(gen->d.ip = M_ASN1_OCTET_STRING_new()) ||
431 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
432 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
433 goto err;
434 }
435 type = GEN_IPADD;
436} else {
437 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
438 ERR_add_error_data(2, "name=", name);
439 goto err;
440}
441
442if(is_string) {
443 if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) ||
444 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
445 strlen(value))) {
446 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
447 goto err;
448 }
449}
450
451gen->type = type;
452
453return gen;
454
455err:
456GENERAL_NAME_free(gen);
457return NULL;
458}
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
new file mode 100644
index 0000000000..cbb012715e
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_bcons.c
@@ -0,0 +1,124 @@
1/* v3_bcons.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist);
68static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
69
70X509V3_EXT_METHOD v3_bcons = {
71NID_basic_constraints, 0,
72ASN1_ITEM_ref(BASIC_CONSTRAINTS),
730,0,0,0,
740,0,
75(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS,
76(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
77NULL,NULL,
78NULL
79};
80
81ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
82 ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
83 ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)
84} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
85
86IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
87
88
89static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
90 BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist)
91{
92 X509V3_add_value_bool("CA", bcons->ca, &extlist);
93 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
94 return extlist;
95}
96
97static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
98 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
99{
100 BASIC_CONSTRAINTS *bcons=NULL;
101 CONF_VALUE *val;
102 int i;
103 if(!(bcons = BASIC_CONSTRAINTS_new())) {
104 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
105 return NULL;
106 }
107 for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
108 val = sk_CONF_VALUE_value(values, i);
109 if(!strcmp(val->name, "CA")) {
110 if(!X509V3_get_value_bool(val, &bcons->ca)) goto err;
111 } else if(!strcmp(val->name, "pathlen")) {
112 if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err;
113 } else {
114 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
115 X509V3_conf_err(val);
116 goto err;
117 }
118 }
119 return bcons;
120 err:
121 BASIC_CONSTRAINTS_free(bcons);
122 return NULL;
123}
124
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
new file mode 100644
index 0000000000..274965306d
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_bitst.c
@@ -0,0 +1,147 @@
1/* v3_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
65 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
67 ASN1_BIT_STRING *bits,
68 STACK_OF(CONF_VALUE) *extlist);
69
70static BIT_STRING_BITNAME ns_cert_type_table[] = {
71{0, "SSL Client", "client"},
72{1, "SSL Server", "server"},
73{2, "S/MIME", "email"},
74{3, "Object Signing", "objsign"},
75{4, "Unused", "reserved"},
76{5, "SSL CA", "sslCA"},
77{6, "S/MIME CA", "emailCA"},
78{7, "Object Signing CA", "objCA"},
79{-1, NULL, NULL}
80};
81
82static BIT_STRING_BITNAME key_usage_type_table[] = {
83{0, "Digital Signature", "digitalSignature"},
84{1, "Non Repudiation", "nonRepudiation"},
85{2, "Key Encipherment", "keyEncipherment"},
86{3, "Data Encipherment", "dataEncipherment"},
87{4, "Key Agreement", "keyAgreement"},
88{5, "Certificate Sign", "keyCertSign"},
89{6, "CRL Sign", "cRLSign"},
90{7, "Encipher Only", "encipherOnly"},
91{8, "Decipher Only", "decipherOnly"},
92{-1, NULL, NULL}
93};
94
95
96
97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
98X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
99
100static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
101 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
102{
103 BIT_STRING_BITNAME *bnam;
104 for(bnam =method->usr_data; bnam->lname; bnam++) {
105 if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
106 X509V3_add_value(bnam->lname, NULL, &ret);
107 }
108 return ret;
109}
110
111static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
112 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
113{
114 CONF_VALUE *val;
115 ASN1_BIT_STRING *bs;
116 int i;
117 BIT_STRING_BITNAME *bnam;
118 if(!(bs = M_ASN1_BIT_STRING_new())) {
119 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
120 return NULL;
121 }
122 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
123 val = sk_CONF_VALUE_value(nval, i);
124 for(bnam = method->usr_data; bnam->lname; bnam++) {
125 if(!strcmp(bnam->sname, val->name) ||
126 !strcmp(bnam->lname, val->name) ) {
127 if(!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
128 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
129 ERR_R_MALLOC_FAILURE);
130 M_ASN1_BIT_STRING_free(bs);
131 return NULL;
132 }
133 break;
134 }
135 }
136 if(!bnam->lname) {
137 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
138 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
139 X509V3_conf_err(val);
140 M_ASN1_BIT_STRING_free(bs);
141 return NULL;
142 }
143 }
144 return bs;
145}
146
147
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
new file mode 100644
index 0000000000..1284d5aaa5
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_conf.c
@@ -0,0 +1,485 @@
1/* v3_conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* extension creation utilities */
59
60
61
62#include <stdio.h>
63#include <ctype.h>
64#include "cryptlib.h"
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69static int v3_check_critical(char **value);
70static int v3_check_generic(char **value);
71static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value);
72static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type);
73static char *conf_lhash_get_string(void *db, char *section, char *value);
74static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section);
75static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
76 int crit, void *ext_struc);
77/* CONF *conf: Config file */
78/* char *name: Name */
79/* char *value: Value */
80X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name,
81 char *value)
82 {
83 int crit;
84 int ext_type;
85 X509_EXTENSION *ret;
86 crit = v3_check_critical(&value);
87 if ((ext_type = v3_check_generic(&value)))
88 return v3_generic_extension(name, value, crit, ext_type);
89 ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
90 if (!ret)
91 {
92 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION);
93 ERR_add_error_data(4,"name=", name, ", value=", value);
94 }
95 return ret;
96 }
97
98/* CONF *conf: Config file */
99/* char *value: Value */
100X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
101 char *value)
102 {
103 int crit;
104 int ext_type;
105 crit = v3_check_critical(&value);
106 if ((ext_type = v3_check_generic(&value)))
107 return v3_generic_extension(OBJ_nid2sn(ext_nid),
108 value, crit, ext_type);
109 return do_ext_nconf(conf, ctx, ext_nid, crit, value);
110 }
111
112/* CONF *conf: Config file */
113/* char *value: Value */
114static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
115 int crit, char *value)
116 {
117 X509V3_EXT_METHOD *method;
118 X509_EXTENSION *ext;
119 STACK_OF(CONF_VALUE) *nval;
120 void *ext_struc;
121 if (ext_nid == NID_undef)
122 {
123 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
124 return NULL;
125 }
126 if (!(method = X509V3_EXT_get_nid(ext_nid)))
127 {
128 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION);
129 return NULL;
130 }
131 /* Now get internal extension representation based on type */
132 if (method->v2i)
133 {
134 if(*value == '@') nval = NCONF_get_section(conf, value + 1);
135 else nval = X509V3_parse_list(value);
136 if(!nval)
137 {
138 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING);
139 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
140 return NULL;
141 }
142 ext_struc = method->v2i(method, ctx, nval);
143 if(*value != '@') sk_CONF_VALUE_pop_free(nval,
144 X509V3_conf_free);
145 if(!ext_struc) return NULL;
146 }
147 else if(method->s2i)
148 {
149 if(!(ext_struc = method->s2i(method, ctx, value))) return NULL;
150 }
151 else if(method->r2i)
152 {
153 if(!ctx->db)
154 {
155 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE);
156 return NULL;
157 }
158 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
159 }
160 else
161 {
162 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
163 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
164 return NULL;
165 }
166
167 ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
168 if(method->it) ASN1_item_free(ext_struc, ASN1_ITEM_ptr(method->it));
169 else method->ext_free(ext_struc);
170 return ext;
171
172 }
173
174static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
175 int crit, void *ext_struc)
176 {
177 unsigned char *ext_der;
178 int ext_len;
179 ASN1_OCTET_STRING *ext_oct;
180 X509_EXTENSION *ext;
181 /* Convert internal representation to DER */
182 if (method->it)
183 {
184 ext_der = NULL;
185 ext_len = ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it));
186 if (ext_len < 0) goto merr;
187 }
188 else
189 {
190 unsigned char *p;
191 ext_len = method->i2d(ext_struc, NULL);
192 if(!(ext_der = OPENSSL_malloc(ext_len))) goto merr;
193 p = ext_der;
194 method->i2d(ext_struc, &p);
195 }
196 if (!(ext_oct = M_ASN1_OCTET_STRING_new())) goto merr;
197 ext_oct->data = ext_der;
198 ext_oct->length = ext_len;
199
200 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
201 if (!ext) goto merr;
202 M_ASN1_OCTET_STRING_free(ext_oct);
203
204 return ext;
205
206 merr:
207 X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE);
208 return NULL;
209
210 }
211
212/* Given an internal structure, nid and critical flag create an extension */
213
214X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
215 {
216 X509V3_EXT_METHOD *method;
217 if (!(method = X509V3_EXT_get_nid(ext_nid))) {
218 X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
219 return NULL;
220 }
221 return do_ext_i2d(method, ext_nid, crit, ext_struc);
222}
223
224/* Check the extension string for critical flag */
225static int v3_check_critical(char **value)
226{
227 char *p = *value;
228 if ((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0;
229 p+=9;
230 while(isspace((unsigned char)*p)) p++;
231 *value = p;
232 return 1;
233}
234
235/* Check extension string for generic extension and return the type */
236static int v3_check_generic(char **value)
237{
238 char *p = *value;
239 if ((strlen(p) < 4) || strncmp(p, "DER:", 4)) return 0;
240 p+=4;
241 while (isspace((unsigned char)*p)) p++;
242 *value = p;
243 return 1;
244}
245
246/* Create a generic extension: for now just handle DER type */
247static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
248 int crit, int type)
249 {
250 unsigned char *ext_der=NULL;
251 long ext_len;
252 ASN1_OBJECT *obj=NULL;
253 ASN1_OCTET_STRING *oct=NULL;
254 X509_EXTENSION *extension=NULL;
255 if (!(obj = OBJ_txt2obj(ext, 0)))
256 {
257 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
258 ERR_add_error_data(2, "name=", ext);
259 goto err;
260 }
261
262 if (!(ext_der = string_to_hex(value, &ext_len)))
263 {
264 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
265 ERR_add_error_data(2, "value=", value);
266 goto err;
267 }
268
269 if (!(oct = M_ASN1_OCTET_STRING_new()))
270 {
271 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
272 goto err;
273 }
274
275 oct->data = ext_der;
276 oct->length = ext_len;
277 ext_der = NULL;
278
279 extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
280
281 err:
282 ASN1_OBJECT_free(obj);
283 M_ASN1_OCTET_STRING_free(oct);
284 if(ext_der) OPENSSL_free(ext_der);
285 return extension;
286
287 }
288
289
290/* This is the main function: add a bunch of extensions based on a config file
291 * section to an extension STACK.
292 */
293
294
295int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section,
296 STACK_OF(X509_EXTENSION) **sk)
297 {
298 X509_EXTENSION *ext;
299 STACK_OF(CONF_VALUE) *nval;
300 CONF_VALUE *val;
301 int i;
302 if (!(nval = NCONF_get_section(conf, section))) return 0;
303 for (i = 0; i < sk_CONF_VALUE_num(nval); i++)
304 {
305 val = sk_CONF_VALUE_value(nval, i);
306 if (!(ext = X509V3_EXT_nconf(conf, ctx, val->name, val->value)))
307 return 0;
308 if (sk) X509v3_add_ext(sk, ext, -1);
309 X509_EXTENSION_free(ext);
310 }
311 return 1;
312 }
313
314/* Convenience functions to add extensions to a certificate, CRL and request */
315
316int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
317 X509 *cert)
318 {
319 STACK_OF(X509_EXTENSION) **sk = NULL;
320 if (cert)
321 sk = &cert->cert_info->extensions;
322 return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
323 }
324
325/* Same as above but for a CRL */
326
327int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
328 X509_CRL *crl)
329 {
330 STACK_OF(X509_EXTENSION) **sk = NULL;
331 if (crl)
332 sk = &crl->crl->extensions;
333 return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
334 }
335
336/* Add extensions to certificate request */
337
338int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
339 X509_REQ *req)
340 {
341 STACK_OF(X509_EXTENSION) *extlist = NULL, **sk = NULL;
342 int i;
343 if (req)
344 sk = &extlist;
345 i = X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
346 if (!i || !sk)
347 return i;
348 i = X509_REQ_add_extensions(req, extlist);
349 sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
350 return i;
351 }
352
353/* Config database functions */
354
355char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
356 {
357 if (ctx->db_meth->get_string)
358 return ctx->db_meth->get_string(ctx->db, name, section);
359 return NULL;
360 }
361
362STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
363 {
364 if (ctx->db_meth->get_section)
365 return ctx->db_meth->get_section(ctx->db, section);
366 return NULL;
367 }
368
369void X509V3_string_free(X509V3_CTX *ctx, char *str)
370 {
371 if (!str) return;
372 if (ctx->db_meth->free_string)
373 ctx->db_meth->free_string(ctx->db, str);
374 }
375
376void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
377 {
378 if (!section) return;
379 if (ctx->db_meth->free_section)
380 ctx->db_meth->free_section(ctx->db, section);
381 }
382
383static char *nconf_get_string(void *db, char *section, char *value)
384 {
385 return NCONF_get_string(db, section, value);
386 }
387
388static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, char *section)
389 {
390 return NCONF_get_section(db, section);
391 }
392
393static X509V3_CONF_METHOD nconf_method = {
394nconf_get_string,
395nconf_get_section,
396NULL,
397NULL
398};
399
400void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf)
401 {
402 ctx->db_meth = &nconf_method;
403 ctx->db = conf;
404 }
405
406void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
407 X509_CRL *crl, int flags)
408 {
409 ctx->issuer_cert = issuer;
410 ctx->subject_cert = subj;
411 ctx->crl = crl;
412 ctx->subject_req = req;
413 ctx->flags = flags;
414 }
415
416/* Old conf compatibility functions */
417
418X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
419 char *value)
420 {
421 CONF ctmp;
422 CONF_set_nconf(&ctmp, conf);
423 return X509V3_EXT_nconf(&ctmp, ctx, name, value);
424 }
425
426/* LHASH *conf: Config file */
427/* char *value: Value */
428X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
429 char *value)
430 {
431 CONF ctmp;
432 CONF_set_nconf(&ctmp, conf);
433 return X509V3_EXT_nconf_nid(&ctmp, ctx, ext_nid, value);
434 }
435
436static char *conf_lhash_get_string(void *db, char *section, char *value)
437 {
438 return CONF_get_string(db, section, value);
439 }
440
441static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
442 {
443 return CONF_get_section(db, section);
444 }
445
446static X509V3_CONF_METHOD conf_lhash_method = {
447conf_lhash_get_string,
448conf_lhash_get_section,
449NULL,
450NULL
451};
452
453void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
454 {
455 ctx->db_meth = &conf_lhash_method;
456 ctx->db = lhash;
457 }
458
459int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
460 X509 *cert)
461 {
462 CONF ctmp;
463 CONF_set_nconf(&ctmp, conf);
464 return X509V3_EXT_add_nconf(&ctmp, ctx, section, cert);
465 }
466
467/* Same as above but for a CRL */
468
469int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
470 X509_CRL *crl)
471 {
472 CONF ctmp;
473 CONF_set_nconf(&ctmp, conf);
474 return X509V3_EXT_CRL_add_nconf(&ctmp, ctx, section, crl);
475 }
476
477/* Add extensions to certificate request */
478
479int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
480 X509_REQ *req)
481 {
482 CONF ctmp;
483 CONF_set_nconf(&ctmp, conf);
484 return X509V3_EXT_REQ_add_nconf(&ctmp, ctx, section, req);
485 }
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
new file mode 100644
index 0000000000..0d554f3a2c
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_cpols.c
@@ -0,0 +1,422 @@
1/* v3_cpols.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66/* Certificate policies extension support: this one is a bit complex... */
67
68static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
69static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
70static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
71static void print_notice(BIO *out, USERNOTICE *notice, int indent);
72static POLICYINFO *policy_section(X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *polstrs, int ia5org);
74static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
75 STACK_OF(CONF_VALUE) *unot, int ia5org);
76static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
77
78X509V3_EXT_METHOD v3_cpols = {
79NID_certificate_policies, 0,ASN1_ITEM_ref(CERTIFICATEPOLICIES),
800,0,0,0,
810,0,
820,0,
83(X509V3_EXT_I2R)i2r_certpol,
84(X509V3_EXT_R2I)r2i_certpol,
85NULL
86};
87
88ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) =
89 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO)
90ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES)
91
92IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
93
94ASN1_SEQUENCE(POLICYINFO) = {
95 ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT),
96 ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO)
97} ASN1_SEQUENCE_END(POLICYINFO)
98
99IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO)
100
101ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY);
102
103ASN1_ADB(POLICYQUALINFO) = {
104 ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)),
105 ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE))
106} ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL);
107
108ASN1_SEQUENCE(POLICYQUALINFO) = {
109 ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT),
110 ASN1_ADB_OBJECT(POLICYQUALINFO)
111} ASN1_SEQUENCE_END(POLICYQUALINFO)
112
113IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO)
114
115ASN1_SEQUENCE(USERNOTICE) = {
116 ASN1_OPT(USERNOTICE, noticeref, NOTICEREF),
117 ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT)
118} ASN1_SEQUENCE_END(USERNOTICE)
119
120IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE)
121
122ASN1_SEQUENCE(NOTICEREF) = {
123 ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT),
124 ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER)
125} ASN1_SEQUENCE_END(NOTICEREF)
126
127IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
128
129static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
130 X509V3_CTX *ctx, char *value)
131{
132 STACK_OF(POLICYINFO) *pols = NULL;
133 char *pstr;
134 POLICYINFO *pol;
135 ASN1_OBJECT *pobj;
136 STACK_OF(CONF_VALUE) *vals;
137 CONF_VALUE *cnf;
138 int i, ia5org;
139 pols = sk_POLICYINFO_new_null();
140 vals = X509V3_parse_list(value);
141 ia5org = 0;
142 for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
143 cnf = sk_CONF_VALUE_value(vals, i);
144 if(cnf->value || !cnf->name ) {
145 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
146 X509V3_conf_err(cnf);
147 goto err;
148 }
149 pstr = cnf->name;
150 if(!strcmp(pstr,"ia5org")) {
151 ia5org = 1;
152 continue;
153 } else if(*pstr == '@') {
154 STACK_OF(CONF_VALUE) *polsect;
155 polsect = X509V3_get_section(ctx, pstr + 1);
156 if(!polsect) {
157 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
158
159 X509V3_conf_err(cnf);
160 goto err;
161 }
162 pol = policy_section(ctx, polsect, ia5org);
163 X509V3_section_free(ctx, polsect);
164 if(!pol) goto err;
165 } else {
166 if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
167 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
168 X509V3_conf_err(cnf);
169 goto err;
170 }
171 pol = POLICYINFO_new();
172 pol->policyid = pobj;
173 }
174 sk_POLICYINFO_push(pols, pol);
175 }
176 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
177 return pols;
178 err:
179 sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
180 return NULL;
181}
182
183static POLICYINFO *policy_section(X509V3_CTX *ctx,
184 STACK_OF(CONF_VALUE) *polstrs, int ia5org)
185{
186 int i;
187 CONF_VALUE *cnf;
188 POLICYINFO *pol;
189 POLICYQUALINFO *qual;
190 if(!(pol = POLICYINFO_new())) goto merr;
191 for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
192 cnf = sk_CONF_VALUE_value(polstrs, i);
193 if(!strcmp(cnf->name, "policyIdentifier")) {
194 ASN1_OBJECT *pobj;
195 if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
196 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
197 X509V3_conf_err(cnf);
198 goto err;
199 }
200 pol->policyid = pobj;
201
202 } else if(!name_cmp(cnf->name, "CPS")) {
203 if(!pol->qualifiers) pol->qualifiers =
204 sk_POLICYQUALINFO_new_null();
205 if(!(qual = POLICYQUALINFO_new())) goto merr;
206 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
207 goto merr;
208 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
209 qual->d.cpsuri = M_ASN1_IA5STRING_new();
210 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
211 strlen(cnf->value))) goto merr;
212 } else if(!name_cmp(cnf->name, "userNotice")) {
213 STACK_OF(CONF_VALUE) *unot;
214 if(*cnf->value != '@') {
215 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
216 X509V3_conf_err(cnf);
217 goto err;
218 }
219 unot = X509V3_get_section(ctx, cnf->value + 1);
220 if(!unot) {
221 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
222
223 X509V3_conf_err(cnf);
224 goto err;
225 }
226 qual = notice_section(ctx, unot, ia5org);
227 X509V3_section_free(ctx, unot);
228 if(!qual) goto err;
229 if(!pol->qualifiers) pol->qualifiers =
230 sk_POLICYQUALINFO_new_null();
231 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
232 goto merr;
233 } else {
234 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
235
236 X509V3_conf_err(cnf);
237 goto err;
238 }
239 }
240 if(!pol->policyid) {
241 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
242 goto err;
243 }
244
245 return pol;
246
247 merr:
248 X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
249
250 err:
251 POLICYINFO_free(pol);
252 return NULL;
253
254
255}
256
257static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
258 STACK_OF(CONF_VALUE) *unot, int ia5org)
259{
260 int i, ret;
261 CONF_VALUE *cnf;
262 USERNOTICE *not;
263 POLICYQUALINFO *qual;
264 if(!(qual = POLICYQUALINFO_new())) goto merr;
265 qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
266 if(!(not = USERNOTICE_new())) goto merr;
267 qual->d.usernotice = not;
268 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
269 cnf = sk_CONF_VALUE_value(unot, i);
270 if(!strcmp(cnf->name, "explicitText")) {
271 not->exptext = M_ASN1_VISIBLESTRING_new();
272 if(!ASN1_STRING_set(not->exptext, cnf->value,
273 strlen(cnf->value))) goto merr;
274 } else if(!strcmp(cnf->name, "organization")) {
275 NOTICEREF *nref;
276 if(!not->noticeref) {
277 if(!(nref = NOTICEREF_new())) goto merr;
278 not->noticeref = nref;
279 } else nref = not->noticeref;
280 if(ia5org) nref->organization->type = V_ASN1_IA5STRING;
281 else nref->organization->type = V_ASN1_VISIBLESTRING;
282 if(!ASN1_STRING_set(nref->organization, cnf->value,
283 strlen(cnf->value))) goto merr;
284 } else if(!strcmp(cnf->name, "noticeNumbers")) {
285 NOTICEREF *nref;
286 STACK_OF(CONF_VALUE) *nos;
287 if(!not->noticeref) {
288 if(!(nref = NOTICEREF_new())) goto merr;
289 not->noticeref = nref;
290 } else nref = not->noticeref;
291 nos = X509V3_parse_list(cnf->value);
292 if(!nos || !sk_CONF_VALUE_num(nos)) {
293 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
294 X509V3_conf_err(cnf);
295 goto err;
296 }
297 ret = nref_nos(nref->noticenos, nos);
298 sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
299 if (!ret)
300 goto err;
301 } else {
302 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
303 X509V3_conf_err(cnf);
304 goto err;
305 }
306 }
307
308 if(not->noticeref &&
309 (!not->noticeref->noticenos || !not->noticeref->organization)) {
310 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
311 goto err;
312 }
313
314 return qual;
315
316 merr:
317 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
318
319 err:
320 POLICYQUALINFO_free(qual);
321 return NULL;
322}
323
324static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
325{
326 CONF_VALUE *cnf;
327 ASN1_INTEGER *aint;
328
329 int i;
330
331 for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
332 cnf = sk_CONF_VALUE_value(nos, i);
333 if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
334 X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
335 goto err;
336 }
337 if(!sk_ASN1_INTEGER_push(nnums, aint)) goto merr;
338 }
339 return 1;
340
341 merr:
342 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
343
344 err:
345 sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
346 return 0;
347}
348
349
350static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
351 BIO *out, int indent)
352{
353 int i;
354 POLICYINFO *pinfo;
355 /* First print out the policy OIDs */
356 for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
357 pinfo = sk_POLICYINFO_value(pol, i);
358 BIO_printf(out, "%*sPolicy: ", indent, "");
359 i2a_ASN1_OBJECT(out, pinfo->policyid);
360 BIO_puts(out, "\n");
361 if(pinfo->qualifiers)
362 print_qualifiers(out, pinfo->qualifiers, indent + 2);
363 }
364 return 1;
365}
366
367static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
368 int indent)
369{
370 POLICYQUALINFO *qualinfo;
371 int i;
372 for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
373 qualinfo = sk_POLICYQUALINFO_value(quals, i);
374 switch(OBJ_obj2nid(qualinfo->pqualid))
375 {
376 case NID_id_qt_cps:
377 BIO_printf(out, "%*sCPS: %s\n", indent, "",
378 qualinfo->d.cpsuri->data);
379 break;
380
381 case NID_id_qt_unotice:
382 BIO_printf(out, "%*sUser Notice:\n", indent, "");
383 print_notice(out, qualinfo->d.usernotice, indent + 2);
384 break;
385
386 default:
387 BIO_printf(out, "%*sUnknown Qualifier: ",
388 indent + 2, "");
389
390 i2a_ASN1_OBJECT(out, qualinfo->pqualid);
391 BIO_puts(out, "\n");
392 break;
393 }
394 }
395}
396
397static void print_notice(BIO *out, USERNOTICE *notice, int indent)
398{
399 int i;
400 if(notice->noticeref) {
401 NOTICEREF *ref;
402 ref = notice->noticeref;
403 BIO_printf(out, "%*sOrganization: %s\n", indent, "",
404 ref->organization->data);
405 BIO_printf(out, "%*sNumber%s: ", indent, "",
406 sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
407 for(i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
408 ASN1_INTEGER *num;
409 char *tmp;
410 num = sk_ASN1_INTEGER_value(ref->noticenos, i);
411 if(i) BIO_puts(out, ", ");
412 tmp = i2s_ASN1_INTEGER(NULL, num);
413 BIO_puts(out, tmp);
414 OPENSSL_free(tmp);
415 }
416 BIO_puts(out, "\n");
417 }
418 if(notice->exptext)
419 BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
420 notice->exptext->data);
421}
422
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
new file mode 100644
index 0000000000..f90829c574
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_crld.c
@@ -0,0 +1,162 @@
1/* v3_crld.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
67 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
68static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70
71X509V3_EXT_METHOD v3_crld = {
72NID_crl_distribution_points, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(CRL_DIST_POINTS),
730,0,0,0,
740,0,
75(X509V3_EXT_I2V)i2v_crld,
76(X509V3_EXT_V2I)v2i_crld,
770,0,
78NULL
79};
80
81static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
82 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
83{
84 DIST_POINT *point;
85 int i;
86 for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
87 point = sk_DIST_POINT_value(crld, i);
88 if(point->distpoint) {
89 if(point->distpoint->type == 0)
90 exts = i2v_GENERAL_NAMES(NULL,
91 point->distpoint->name.fullname, exts);
92 else X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
93 }
94 if(point->reasons)
95 X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
96 if(point->CRLissuer)
97 X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
98 }
99 return exts;
100}
101
102static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
103 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
104{
105 STACK_OF(DIST_POINT) *crld = NULL;
106 GENERAL_NAMES *gens = NULL;
107 GENERAL_NAME *gen = NULL;
108 CONF_VALUE *cnf;
109 int i;
110 if(!(crld = sk_DIST_POINT_new_null())) goto merr;
111 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
112 DIST_POINT *point;
113 cnf = sk_CONF_VALUE_value(nval, i);
114 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
115 if(!(gens = GENERAL_NAMES_new())) goto merr;
116 if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
117 gen = NULL;
118 if(!(point = DIST_POINT_new())) goto merr;
119 if(!sk_DIST_POINT_push(crld, point)) {
120 DIST_POINT_free(point);
121 goto merr;
122 }
123 if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
124 point->distpoint->name.fullname = gens;
125 point->distpoint->type = 0;
126 gens = NULL;
127 }
128 return crld;
129
130 merr:
131 X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE);
132 err:
133 GENERAL_NAME_free(gen);
134 GENERAL_NAMES_free(gens);
135 sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
136 return NULL;
137}
138
139IMPLEMENT_STACK_OF(DIST_POINT)
140IMPLEMENT_ASN1_SET_OF(DIST_POINT)
141
142
143ASN1_CHOICE(DIST_POINT_NAME) = {
144 ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0),
145 ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1)
146} ASN1_CHOICE_END(DIST_POINT_NAME)
147
148IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME)
149
150ASN1_SEQUENCE(DIST_POINT) = {
151 ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0),
152 ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1),
153 ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2)
154} ASN1_SEQUENCE_END(DIST_POINT)
155
156IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT)
157
158ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) =
159 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT)
160ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS)
161
162IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS)
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
new file mode 100644
index 0000000000..010c9d6260
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_enum.c
@@ -0,0 +1,94 @@
1/* v3_enum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ENUMERATED_NAMES crl_reasons[] = {
64{0, "Unspecified", "unspecified"},
65{1, "Key Compromise", "keyCompromise"},
66{2, "CA Compromise", "CACompromise"},
67{3, "Affiliation Changed", "affiliationChanged"},
68{4, "Superseded", "superseded"},
69{5, "Cessation Of Operation", "cessationOfOperation"},
70{6, "Certificate Hold", "certificateHold"},
71{8, "Remove From CRL", "removeFromCRL"},
72{-1, NULL, NULL}
73};
74
75X509V3_EXT_METHOD v3_crl_reason = {
76NID_crl_reason, 0, ASN1_ITEM_ref(ASN1_ENUMERATED),
770,0,0,0,
78(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
790,
800,0,0,0,
81crl_reasons};
82
83
84char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
85 ASN1_ENUMERATED *e)
86{
87 ENUMERATED_NAMES *enam;
88 long strval;
89 strval = ASN1_ENUMERATED_get(e);
90 for(enam = method->usr_data; enam->lname; enam++) {
91 if(strval == enam->bitnum) return BUF_strdup(enam->lname);
92 }
93 return i2s_ASN1_ENUMERATED(method, e);
94}
diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c
new file mode 100644
index 0000000000..b1cfaba1aa
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_extku.c
@@ -0,0 +1,142 @@
1/* v3_extku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1t.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
67 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
69 void *eku, STACK_OF(CONF_VALUE) *extlist);
70
71X509V3_EXT_METHOD v3_ext_ku = {
72 NID_ext_key_usage, 0,
73 ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
74 0,0,0,0,
75 0,0,
76 i2v_EXTENDED_KEY_USAGE,
77 v2i_EXTENDED_KEY_USAGE,
78 0,0,
79 NULL
80};
81
82/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
83X509V3_EXT_METHOD v3_ocsp_accresp = {
84 NID_id_pkix_OCSP_acceptableResponses, 0,
85 ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
86 0,0,0,0,
87 0,0,
88 i2v_EXTENDED_KEY_USAGE,
89 v2i_EXTENDED_KEY_USAGE,
90 0,0,
91 NULL
92};
93
94ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) =
95 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
96ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
97
98IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
99
100static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
101 void *a, STACK_OF(CONF_VALUE) *ext_list)
102{
103 EXTENDED_KEY_USAGE *eku = a;
104 int i;
105 ASN1_OBJECT *obj;
106 char obj_tmp[80];
107 for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
108 obj = sk_ASN1_OBJECT_value(eku, i);
109 i2t_ASN1_OBJECT(obj_tmp, 80, obj);
110 X509V3_add_value(NULL, obj_tmp, &ext_list);
111 }
112 return ext_list;
113}
114
115static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
116 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
117{
118 EXTENDED_KEY_USAGE *extku;
119 char *extval;
120 ASN1_OBJECT *objtmp;
121 CONF_VALUE *val;
122 int i;
123
124 if(!(extku = sk_ASN1_OBJECT_new_null())) {
125 X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE);
126 return NULL;
127 }
128
129 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
130 val = sk_CONF_VALUE_value(nval, i);
131 if(val->value) extval = val->value;
132 else extval = val->name;
133 if(!(objtmp = OBJ_txt2obj(extval, 0))) {
134 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
135 X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER);
136 X509V3_conf_err(val);
137 return NULL;
138 }
139 sk_ASN1_OBJECT_push(extku, objtmp);
140 }
141 return extku;
142}
diff --git a/src/lib/libcrypto/x509v3/v3_genn.c b/src/lib/libcrypto/x509v3/v3_genn.c
new file mode 100644
index 0000000000..650b510980
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_genn.c
@@ -0,0 +1,101 @@
1/* v3_genn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1t.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(OTHERNAME) = {
67 ASN1_SIMPLE(OTHERNAME, type_id, ASN1_OBJECT),
68 /* Maybe have a true ANY DEFINED BY later */
69 ASN1_EXP(OTHERNAME, value, ASN1_ANY, 0)
70} ASN1_SEQUENCE_END(OTHERNAME)
71
72IMPLEMENT_ASN1_FUNCTIONS(OTHERNAME)
73
74ASN1_SEQUENCE(EDIPARTYNAME) = {
75 ASN1_IMP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
76 ASN1_IMP_OPT(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
77} ASN1_SEQUENCE_END(EDIPARTYNAME)
78
79IMPLEMENT_ASN1_FUNCTIONS(EDIPARTYNAME)
80
81ASN1_CHOICE(GENERAL_NAME) = {
82 ASN1_IMP(GENERAL_NAME, d.otherName, OTHERNAME, GEN_OTHERNAME),
83 ASN1_IMP(GENERAL_NAME, d.rfc822Name, ASN1_IA5STRING, GEN_EMAIL),
84 ASN1_IMP(GENERAL_NAME, d.dNSName, ASN1_IA5STRING, GEN_DNS),
85 /* Don't decode this */
86 ASN1_IMP(GENERAL_NAME, d.x400Address, ASN1_SEQUENCE, GEN_X400),
87 /* X509_NAME is a CHOICE type so use EXPLICIT */
88 ASN1_EXP(GENERAL_NAME, d.directoryName, X509_NAME, GEN_DIRNAME),
89 ASN1_IMP(GENERAL_NAME, d.ediPartyName, EDIPARTYNAME, GEN_EDIPARTY),
90 ASN1_IMP(GENERAL_NAME, d.uniformResourceIdentifier, ASN1_IA5STRING, GEN_URI),
91 ASN1_IMP(GENERAL_NAME, d.iPAddress, ASN1_OCTET_STRING, GEN_IPADD),
92 ASN1_IMP(GENERAL_NAME, d.registeredID, ASN1_OBJECT, GEN_RID)
93} ASN1_CHOICE_END(GENERAL_NAME)
94
95IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAME)
96
97ASN1_ITEM_TEMPLATE(GENERAL_NAMES) =
98 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, GENERAL_NAME)
99ASN1_ITEM_TEMPLATE_END(GENERAL_NAMES)
100
101IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAMES)
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
new file mode 100644
index 0000000000..9683afa47c
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_ia5.c
@@ -0,0 +1,116 @@
1/* v3_ia5.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
67static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
68X509V3_EXT_METHOD v3_ns_ia5_list[] = {
69EXT_IA5STRING(NID_netscape_base_url),
70EXT_IA5STRING(NID_netscape_revocation_url),
71EXT_IA5STRING(NID_netscape_ca_revocation_url),
72EXT_IA5STRING(NID_netscape_renewal_url),
73EXT_IA5STRING(NID_netscape_ca_policy_url),
74EXT_IA5STRING(NID_netscape_ssl_server_name),
75EXT_IA5STRING(NID_netscape_comment),
76EXT_END
77};
78
79
80static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
81 ASN1_IA5STRING *ia5)
82{
83 char *tmp;
84 if(!ia5 || !ia5->length) return NULL;
85 if(!(tmp = OPENSSL_malloc(ia5->length + 1))) {
86 X509V3err(X509V3_F_I2S_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 memcpy(tmp, ia5->data, ia5->length);
90 tmp[ia5->length] = 0;
91 return tmp;
92}
93
94static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
95 X509V3_CTX *ctx, char *str)
96{
97 ASN1_IA5STRING *ia5;
98 if(!str) {
99 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
100 return NULL;
101 }
102 if(!(ia5 = M_ASN1_IA5STRING_new())) goto err;
103 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
104 strlen(str))) {
105 M_ASN1_IA5STRING_free(ia5);
106 goto err;
107 }
108#ifdef CHARSET_EBCDIC
109 ebcdic2ascii(ia5->data, ia5->data, ia5->length);
110#endif /*CHARSET_EBCDIC*/
111 return ia5;
112 err:
113 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
114 return NULL;
115}
116
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
new file mode 100644
index 0000000000..53e3f48859
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_info.c
@@ -0,0 +1,194 @@
1/* v3_info.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
67 AUTHORITY_INFO_ACCESS *ainfo,
68 STACK_OF(CONF_VALUE) *ret);
69static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
71
72X509V3_EXT_METHOD v3_info =
73{ NID_info_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
740,0,0,0,
750,0,
76(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
77(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
780,0,
79NULL};
80
81X509V3_EXT_METHOD v3_sinfo =
82{ NID_sinfo_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
830,0,0,0,
840,0,
85(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
86(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
870,0,
88NULL};
89
90ASN1_SEQUENCE(ACCESS_DESCRIPTION) = {
91 ASN1_SIMPLE(ACCESS_DESCRIPTION, method, ASN1_OBJECT),
92 ASN1_SIMPLE(ACCESS_DESCRIPTION, location, GENERAL_NAME)
93} ASN1_SEQUENCE_END(ACCESS_DESCRIPTION)
94
95IMPLEMENT_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
96
97ASN1_ITEM_TEMPLATE(AUTHORITY_INFO_ACCESS) =
98 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, ACCESS_DESCRIPTION)
99ASN1_ITEM_TEMPLATE_END(AUTHORITY_INFO_ACCESS)
100
101IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
102
103static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
104 AUTHORITY_INFO_ACCESS *ainfo,
105 STACK_OF(CONF_VALUE) *ret)
106{
107 ACCESS_DESCRIPTION *desc;
108 int i,nlen;
109 char objtmp[80], *ntmp;
110 CONF_VALUE *vtmp;
111 for(i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
112 desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
113 ret = i2v_GENERAL_NAME(method, desc->location, ret);
114 if(!ret) break;
115 vtmp = sk_CONF_VALUE_value(ret, i);
116 i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method);
117 nlen = strlen(objtmp) + strlen(vtmp->name) + 5;
118 ntmp = OPENSSL_malloc(nlen);
119 if(!ntmp) {
120 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
121 ERR_R_MALLOC_FAILURE);
122 return NULL;
123 }
124 BUF_strlcpy(ntmp, objtmp, nlen);
125 BUF_strlcat(ntmp, " - ", nlen);
126 BUF_strlcat(ntmp, vtmp->name, nlen);
127 OPENSSL_free(vtmp->name);
128 vtmp->name = ntmp;
129
130 }
131 if(!ret) return sk_CONF_VALUE_new_null();
132 return ret;
133}
134
135static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
136 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
137{
138 AUTHORITY_INFO_ACCESS *ainfo = NULL;
139 CONF_VALUE *cnf, ctmp;
140 ACCESS_DESCRIPTION *acc;
141 int i, objlen;
142 char *objtmp, *ptmp;
143 if(!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) {
144 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
148 cnf = sk_CONF_VALUE_value(nval, i);
149 if(!(acc = ACCESS_DESCRIPTION_new())
150 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
151 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
152 goto err;
153 }
154 ptmp = strchr(cnf->name, ';');
155 if(!ptmp) {
156 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_INVALID_SYNTAX);
157 goto err;
158 }
159 objlen = ptmp - cnf->name;
160 ctmp.name = ptmp + 1;
161 ctmp.value = cnf->value;
162 GENERAL_NAME_free(acc->location);
163 if(!(acc->location = v2i_GENERAL_NAME(method, ctx, &ctmp)))
164 goto err;
165 if(!(objtmp = OPENSSL_malloc(objlen + 1))) {
166 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
167 goto err;
168 }
169 strncpy(objtmp, cnf->name, objlen);
170 objtmp[objlen] = 0;
171 acc->method = OBJ_txt2obj(objtmp, 0);
172 if(!acc->method) {
173 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_BAD_OBJECT);
174 ERR_add_error_data(2, "value=", objtmp);
175 OPENSSL_free(objtmp);
176 goto err;
177 }
178 OPENSSL_free(objtmp);
179
180 }
181 return ainfo;
182 err:
183 sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
184 return NULL;
185}
186
187int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION* a)
188 {
189 i2a_ASN1_OBJECT(bp, a->method);
190#ifdef UNDEF
191 i2a_GENERAL_NAME(bp, a->location);
192#endif
193 return 2;
194 }
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
new file mode 100644
index 0000000000..7a43b4717b
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_int.c
@@ -0,0 +1,76 @@
1/* v3_int.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63X509V3_EXT_METHOD v3_crl_num = {
64 NID_crl_number, 0, ASN1_ITEM_ref(ASN1_INTEGER),
65 0,0,0,0,
66 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
67 0,
68 0,0,0,0, NULL};
69
70X509V3_EXT_METHOD v3_delta_crl = {
71 NID_delta_crl, 0, ASN1_ITEM_ref(ASN1_INTEGER),
72 0,0,0,0,
73 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
74 0,
75 0,0,0,0, NULL};
76
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
new file mode 100644
index 0000000000..ca5a4a4a57
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_lib.c
@@ -0,0 +1,302 @@
1/* v3_lib.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65#include "ext_dat.h"
66
67static STACK_OF(X509V3_EXT_METHOD) *ext_list = NULL;
68
69static int ext_cmp(const X509V3_EXT_METHOD * const *a,
70 const X509V3_EXT_METHOD * const *b);
71static void ext_list_free(X509V3_EXT_METHOD *ext);
72
73int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
74{
75 if(!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp))) {
76 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
77 return 0;
78 }
79 if(!sk_X509V3_EXT_METHOD_push(ext_list, ext)) {
80 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
81 return 0;
82 }
83 return 1;
84}
85
86static int ext_cmp(const X509V3_EXT_METHOD * const *a,
87 const X509V3_EXT_METHOD * const *b)
88{
89 return ((*a)->ext_nid - (*b)->ext_nid);
90}
91
92X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
93{
94 X509V3_EXT_METHOD tmp, *t = &tmp, **ret;
95 int idx;
96 if(nid < 0) return NULL;
97 tmp.ext_nid = nid;
98 ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
99 (char *)standard_exts, STANDARD_EXTENSION_COUNT,
100 sizeof(X509V3_EXT_METHOD *), (int (*)(const void *, const void *))ext_cmp);
101 if(ret) return *ret;
102 if(!ext_list) return NULL;
103 idx = sk_X509V3_EXT_METHOD_find(ext_list, &tmp);
104 if(idx == -1) return NULL;
105 return sk_X509V3_EXT_METHOD_value(ext_list, idx);
106}
107
108X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
109{
110 int nid;
111 if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
112 return X509V3_EXT_get_nid(nid);
113}
114
115
116int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
117{
118 for(;extlist->ext_nid!=-1;extlist++)
119 if(!X509V3_EXT_add(extlist)) return 0;
120 return 1;
121}
122
123int X509V3_EXT_add_alias(int nid_to, int nid_from)
124{
125 X509V3_EXT_METHOD *ext, *tmpext;
126 if(!(ext = X509V3_EXT_get_nid(nid_from))) {
127 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
128 return 0;
129 }
130 if(!(tmpext = (X509V3_EXT_METHOD *)OPENSSL_malloc(sizeof(X509V3_EXT_METHOD)))) {
131 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
132 return 0;
133 }
134 *tmpext = *ext;
135 tmpext->ext_nid = nid_to;
136 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
137 return X509V3_EXT_add(tmpext);
138}
139
140void X509V3_EXT_cleanup(void)
141{
142 sk_X509V3_EXT_METHOD_pop_free(ext_list, ext_list_free);
143 ext_list = NULL;
144}
145
146static void ext_list_free(X509V3_EXT_METHOD *ext)
147{
148 if(ext->ext_flags & X509V3_EXT_DYNAMIC) OPENSSL_free(ext);
149}
150
151/* Legacy function: we don't need to add standard extensions
152 * any more because they are now kept in ext_dat.h.
153 */
154
155int X509V3_add_standard_extensions(void)
156{
157 return 1;
158}
159
160/* Return an extension internal structure */
161
162void *X509V3_EXT_d2i(X509_EXTENSION *ext)
163{
164 X509V3_EXT_METHOD *method;
165 unsigned char *p;
166 if(!(method = X509V3_EXT_get(ext))) return NULL;
167 p = ext->value->data;
168 if(method->it) return ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it));
169 return method->d2i(NULL, &p, ext->value->length);
170}
171
172/* Get critical flag and decoded version of extension from a NID.
173 * The "idx" variable returns the last found extension and can
174 * be used to retrieve multiple extensions of the same NID.
175 * However multiple extensions with the same NID is usually
176 * due to a badly encoded certificate so if idx is NULL we
177 * choke if multiple extensions exist.
178 * The "crit" variable is set to the critical value.
179 * The return value is the decoded extension or NULL on
180 * error. The actual error can have several different causes,
181 * the value of *crit reflects the cause:
182 * >= 0, extension found but not decoded (reflects critical value).
183 * -1 extension not found.
184 * -2 extension occurs more than once.
185 */
186
187void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
188{
189 int lastpos, i;
190 X509_EXTENSION *ex, *found_ex = NULL;
191 if(!x) {
192 if(idx) *idx = -1;
193 if(crit) *crit = -1;
194 return NULL;
195 }
196 if(idx) lastpos = *idx + 1;
197 else lastpos = 0;
198 if(lastpos < 0) lastpos = 0;
199 for(i = lastpos; i < sk_X509_EXTENSION_num(x); i++)
200 {
201 ex = sk_X509_EXTENSION_value(x, i);
202 if(OBJ_obj2nid(ex->object) == nid) {
203 if(idx) {
204 *idx = i;
205 found_ex = ex;
206 break;
207 } else if(found_ex) {
208 /* Found more than one */
209 if(crit) *crit = -2;
210 return NULL;
211 }
212 found_ex = ex;
213 }
214 }
215 if(found_ex) {
216 /* Found it */
217 if(crit) *crit = X509_EXTENSION_get_critical(found_ex);
218 return X509V3_EXT_d2i(found_ex);
219 }
220
221 /* Extension not found */
222 if(idx) *idx = -1;
223 if(crit) *crit = -1;
224 return NULL;
225}
226
227/* This function is a general extension append, replace and delete utility.
228 * The precise operation is governed by the 'flags' value. The 'crit' and
229 * 'value' arguments (if relevant) are the extensions internal structure.
230 */
231
232int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
233 int crit, unsigned long flags)
234{
235 int extidx = -1;
236 int errcode;
237 X509_EXTENSION *ext, *extmp;
238 unsigned long ext_op = flags & X509V3_ADD_OP_MASK;
239
240 /* If appending we don't care if it exists, otherwise
241 * look for existing extension.
242 */
243 if(ext_op != X509V3_ADD_APPEND)
244 extidx = X509v3_get_ext_by_NID(*x, nid, -1);
245
246 /* See if extension exists */
247 if(extidx >= 0) {
248 /* If keep existing, nothing to do */
249 if(ext_op == X509V3_ADD_KEEP_EXISTING)
250 return 1;
251 /* If default then its an error */
252 if(ext_op == X509V3_ADD_DEFAULT) {
253 errcode = X509V3_R_EXTENSION_EXISTS;
254 goto err;
255 }
256 /* If delete, just delete it */
257 if(ext_op == X509V3_ADD_DELETE) {
258 if(!sk_X509_EXTENSION_delete(*x, extidx)) return -1;
259 return 1;
260 }
261 } else {
262 /* If replace existing or delete, error since
263 * extension must exist
264 */
265 if((ext_op == X509V3_ADD_REPLACE_EXISTING) ||
266 (ext_op == X509V3_ADD_DELETE)) {
267 errcode = X509V3_R_EXTENSION_NOT_FOUND;
268 goto err;
269 }
270 }
271
272 /* If we get this far then we have to create an extension:
273 * could have some flags for alternative encoding schemes...
274 */
275
276 ext = X509V3_EXT_i2d(nid, crit, value);
277
278 if(!ext) {
279 X509V3err(X509V3_F_X509V3_ADD_I2D, X509V3_R_ERROR_CREATING_EXTENSION);
280 return 0;
281 }
282
283 /* If extension exists replace it.. */
284 if(extidx >= 0) {
285 extmp = sk_X509_EXTENSION_value(*x, extidx);
286 X509_EXTENSION_free(extmp);
287 if(!sk_X509_EXTENSION_set(*x, extidx, ext)) return -1;
288 return 1;
289 }
290
291 if(!*x && !(*x = sk_X509_EXTENSION_new_null())) return -1;
292 if(!sk_X509_EXTENSION_push(*x, ext)) return -1;
293
294 return 1;
295
296 err:
297 if(!(flags & X509V3_ADD_SILENT))
298 X509V3err(X509V3_F_X509V3_ADD_I2D, errcode);
299 return 0;
300}
301
302IMPLEMENT_STACK_OF(X509V3_EXT_METHOD)
diff --git a/src/lib/libcrypto/x509v3/v3_ocsp.c b/src/lib/libcrypto/x509v3/v3_ocsp.c
new file mode 100644
index 0000000000..21badc13f9
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_ocsp.c
@@ -0,0 +1,275 @@
1/* v3_ocsp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef OPENSSL_NO_OCSP
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/asn1.h>
65#include <openssl/ocsp.h>
66#include <openssl/x509v3.h>
67
68/* OCSP extensions and a couple of CRL entry extensions
69 */
70
71static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
72static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
73static int i2r_object(X509V3_EXT_METHOD *method, void *obj, BIO *out, int indent);
74
75static void *ocsp_nonce_new(void);
76static int i2d_ocsp_nonce(void *a, unsigned char **pp);
77static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length);
78static void ocsp_nonce_free(void *a);
79static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
80
81static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent);
82static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
83static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind);
84
85X509V3_EXT_METHOD v3_ocsp_crlid = {
86 NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID),
87 0,0,0,0,
88 0,0,
89 0,0,
90 i2r_ocsp_crlid,0,
91 NULL
92};
93
94X509V3_EXT_METHOD v3_ocsp_acutoff = {
95 NID_id_pkix_OCSP_archiveCutoff, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
96 0,0,0,0,
97 0,0,
98 0,0,
99 i2r_ocsp_acutoff,0,
100 NULL
101};
102
103X509V3_EXT_METHOD v3_crl_invdate = {
104 NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
105 0,0,0,0,
106 0,0,
107 0,0,
108 i2r_ocsp_acutoff,0,
109 NULL
110};
111
112X509V3_EXT_METHOD v3_crl_hold = {
113 NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT),
114 0,0,0,0,
115 0,0,
116 0,0,
117 i2r_object,0,
118 NULL
119};
120
121X509V3_EXT_METHOD v3_ocsp_nonce = {
122 NID_id_pkix_OCSP_Nonce, 0, NULL,
123 ocsp_nonce_new,
124 ocsp_nonce_free,
125 d2i_ocsp_nonce,
126 i2d_ocsp_nonce,
127 0,0,
128 0,0,
129 i2r_ocsp_nonce,0,
130 NULL
131};
132
133X509V3_EXT_METHOD v3_ocsp_nocheck = {
134 NID_id_pkix_OCSP_noCheck, 0, ASN1_ITEM_ref(ASN1_NULL),
135 0,0,0,0,
136 0,s2i_ocsp_nocheck,
137 0,0,
138 i2r_ocsp_nocheck,0,
139 NULL
140};
141
142X509V3_EXT_METHOD v3_ocsp_serviceloc = {
143 NID_id_pkix_OCSP_serviceLocator, 0, ASN1_ITEM_ref(OCSP_SERVICELOC),
144 0,0,0,0,
145 0,0,
146 0,0,
147 i2r_ocsp_serviceloc,0,
148 NULL
149};
150
151static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
152{
153 OCSP_CRLID *a = in;
154 if (a->crlUrl)
155 {
156 if (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;
157 if (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;
158 if (!BIO_write(bp, "\n", 1)) goto err;
159 }
160 if (a->crlNum)
161 {
162 if (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;
163 if (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;
164 if (!BIO_write(bp, "\n", 1)) goto err;
165 }
166 if (a->crlTime)
167 {
168 if (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;
169 if (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;
170 if (!BIO_write(bp, "\n", 1)) goto err;
171 }
172 return 1;
173 err:
174 return 0;
175}
176
177static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *cutoff, BIO *bp, int ind)
178{
179 if (!BIO_printf(bp, "%*s", ind, "")) return 0;
180 if(!ASN1_GENERALIZEDTIME_print(bp, cutoff)) return 0;
181 return 1;
182}
183
184
185static int i2r_object(X509V3_EXT_METHOD *method, void *oid, BIO *bp, int ind)
186{
187 if (!BIO_printf(bp, "%*s", ind, "")) return 0;
188 if(!i2a_ASN1_OBJECT(bp, oid)) return 0;
189 return 1;
190}
191
192/* OCSP nonce. This is needs special treatment because it doesn't have
193 * an ASN1 encoding at all: it just contains arbitrary data.
194 */
195
196static void *ocsp_nonce_new(void)
197{
198 return ASN1_OCTET_STRING_new();
199}
200
201static int i2d_ocsp_nonce(void *a, unsigned char **pp)
202{
203 ASN1_OCTET_STRING *os = a;
204 if(pp) {
205 memcpy(*pp, os->data, os->length);
206 *pp += os->length;
207 }
208 return os->length;
209}
210
211static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length)
212{
213 ASN1_OCTET_STRING *os, **pos;
214 pos = a;
215 if(!pos || !*pos) os = ASN1_OCTET_STRING_new();
216 else os = *pos;
217 if(!ASN1_OCTET_STRING_set(os, *pp, length)) goto err;
218
219 *pp += length;
220
221 if(pos) *pos = os;
222 return os;
223
224 err:
225 if(os && (!pos || (*pos != os))) M_ASN1_OCTET_STRING_free(os);
226 OCSPerr(OCSP_F_D2I_OCSP_NONCE, ERR_R_MALLOC_FAILURE);
227 return NULL;
228}
229
230static void ocsp_nonce_free(void *a)
231{
232 M_ASN1_OCTET_STRING_free(a);
233}
234
235static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent)
236{
237 if(BIO_printf(out, "%*s", indent, "") <= 0) return 0;
238 if(i2a_ASN1_STRING(out, nonce, V_ASN1_OCTET_STRING) <= 0) return 0;
239 return 1;
240}
241
242/* Nocheck is just a single NULL. Don't print anything and always set it */
243
244static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent)
245{
246 return 1;
247}
248
249static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
250{
251 return ASN1_NULL_new();
252}
253
254static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
255 {
256 int i;
257 OCSP_SERVICELOC *a = in;
258 ACCESS_DESCRIPTION *ad;
259
260 if (BIO_printf(bp, "%*sIssuer: ", ind, "") <= 0) goto err;
261 if (X509_NAME_print_ex(bp, a->issuer, 0, XN_FLAG_ONELINE) <= 0) goto err;
262 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(a->locator); i++)
263 {
264 ad = sk_ACCESS_DESCRIPTION_value(a->locator,i);
265 if (BIO_printf(bp, "\n%*s", (2*ind), "") <= 0)
266 goto err;
267 if(i2a_ASN1_OBJECT(bp, ad->method) <= 0) goto err;
268 if(BIO_puts(bp, " - ") <= 0) goto err;
269 if(GENERAL_NAME_print(bp, ad->location) <= 0) goto err;
270 }
271 return 1;
272err:
273 return 0;
274 }
275#endif
diff --git a/src/lib/libcrypto/x509v3/v3_pci.c b/src/lib/libcrypto/x509v3/v3_pci.c
new file mode 100644
index 0000000000..b32d968619
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_pci.c
@@ -0,0 +1,313 @@
1/* v3_pci.c -*- mode:C; c-file-style: "eay" -*- */
2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org)
4 */
5/* Copyright (c) 2004 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <stdio.h>
38#include "cryptlib.h"
39#include <openssl/conf.h>
40#include <openssl/x509v3.h>
41
42static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *ext,
43 BIO *out, int indent);
44static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method,
45 X509V3_CTX *ctx, char *str);
46
47X509V3_EXT_METHOD v3_pci =
48 { NID_proxyCertInfo, 0, ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION),
49 0,0,0,0,
50 0,0,
51 NULL, NULL,
52 (X509V3_EXT_I2R)i2r_pci,
53 (X509V3_EXT_R2I)r2i_pci,
54 NULL,
55 };
56
57static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci,
58 BIO *out, int indent)
59 {
60 BIO_printf(out, "%*sPath Length Constraint: ", indent, "");
61 if (pci->pcPathLengthConstraint)
62 i2a_ASN1_INTEGER(out, pci->pcPathLengthConstraint);
63 else
64 BIO_printf(out, "infinite");
65 BIO_puts(out, "\n");
66 BIO_printf(out, "%*sPolicy Language: ", indent, "");
67 i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage);
68 BIO_puts(out, "\n");
69 if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data)
70 BIO_printf(out, "%*sPolicy Text: %s\n", indent, "",
71 pci->proxyPolicy->policy->data);
72 return 1;
73 }
74
75static int process_pci_value(CONF_VALUE *val,
76 ASN1_OBJECT **language, ASN1_INTEGER **pathlen,
77 ASN1_OCTET_STRING **policy)
78 {
79 int free_policy = 0;
80
81 if (strcmp(val->name, "language") == 0)
82 {
83 if (*language)
84 {
85 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED);
86 X509V3_conf_err(val);
87 return 0;
88 }
89 if (!(*language = OBJ_txt2obj(val->value, 0)))
90 {
91 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_OBJECT_IDENTIFIER);
92 X509V3_conf_err(val);
93 return 0;
94 }
95 }
96 else if (strcmp(val->name, "pathlen") == 0)
97 {
98 if (*pathlen)
99 {
100 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED);
101 X509V3_conf_err(val);
102 return 0;
103 }
104 if (!X509V3_get_value_int(val, pathlen))
105 {
106 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_PATH_LENGTH);
107 X509V3_conf_err(val);
108 return 0;
109 }
110 }
111 else if (strcmp(val->name, "policy") == 0)
112 {
113 unsigned char *tmp_data = NULL;
114 long val_len;
115 if (!*policy)
116 {
117 *policy = ASN1_OCTET_STRING_new();
118 if (!*policy)
119 {
120 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
121 X509V3_conf_err(val);
122 return 0;
123 }
124 free_policy = 1;
125 }
126 if (strncmp(val->value, "hex:", 4) == 0)
127 {
128 unsigned char *tmp_data2 =
129 string_to_hex(val->value + 4, &val_len);
130
131 if (!tmp_data2) goto err;
132
133 tmp_data = OPENSSL_realloc((*policy)->data,
134 (*policy)->length + val_len + 1);
135 if (tmp_data)
136 {
137 (*policy)->data = tmp_data;
138 memcpy(&(*policy)->data[(*policy)->length],
139 tmp_data2, val_len);
140 (*policy)->length += val_len;
141 (*policy)->data[(*policy)->length] = '\0';
142 }
143 }
144 else if (strncmp(val->value, "file:", 5) == 0)
145 {
146 unsigned char buf[2048];
147 int n;
148 BIO *b = BIO_new_file(val->value + 5, "r");
149 if (!b)
150 {
151 X509V3err(X509V3_F_R2I_PCI,ERR_R_BIO_LIB);
152 X509V3_conf_err(val);
153 goto err;
154 }
155 while((n = BIO_read(b, buf, sizeof(buf))) > 0
156 || (n == 0 && BIO_should_retry(b)))
157 {
158 if (!n) continue;
159
160 tmp_data = OPENSSL_realloc((*policy)->data,
161 (*policy)->length + n + 1);
162
163 if (!tmp_data)
164 break;
165
166 (*policy)->data = tmp_data;
167 memcpy(&(*policy)->data[(*policy)->length],
168 buf, n);
169 (*policy)->length += n;
170 (*policy)->data[(*policy)->length] = '\0';
171 }
172
173 if (n < 0)
174 {
175 X509V3err(X509V3_F_R2I_PCI,ERR_R_BIO_LIB);
176 X509V3_conf_err(val);
177 goto err;
178 }
179 }
180 else if (strncmp(val->value, "text:", 5) == 0)
181 {
182 val_len = strlen(val->value + 5);
183 tmp_data = OPENSSL_realloc((*policy)->data,
184 (*policy)->length + val_len + 1);
185 if (tmp_data)
186 {
187 (*policy)->data = tmp_data;
188 memcpy(&(*policy)->data[(*policy)->length],
189 val->value + 5, val_len);
190 (*policy)->length += val_len;
191 (*policy)->data[(*policy)->length] = '\0';
192 }
193 }
194 else
195 {
196 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INCORRECT_POLICY_SYNTAX_TAG);
197 X509V3_conf_err(val);
198 goto err;
199 }
200 if (!tmp_data)
201 {
202 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
203 X509V3_conf_err(val);
204 goto err;
205 }
206 }
207 return 1;
208err:
209 if (free_policy)
210 {
211 ASN1_OCTET_STRING_free(*policy);
212 *policy = NULL;
213 }
214 return 0;
215 }
216
217static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method,
218 X509V3_CTX *ctx, char *value)
219 {
220 PROXY_CERT_INFO_EXTENSION *pci = NULL;
221 STACK_OF(CONF_VALUE) *vals;
222 ASN1_OBJECT *language = NULL;
223 ASN1_INTEGER *pathlen = NULL;
224 ASN1_OCTET_STRING *policy = NULL;
225 int i, j;
226
227 vals = X509V3_parse_list(value);
228 for (i = 0; i < sk_CONF_VALUE_num(vals); i++)
229 {
230 CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i);
231 if (!cnf->name || (*cnf->name != '@' && !cnf->value))
232 {
233 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_PROXY_POLICY_SETTING);
234 X509V3_conf_err(cnf);
235 goto err;
236 }
237 if (*cnf->name == '@')
238 {
239 STACK_OF(CONF_VALUE) *sect;
240 int success_p = 1;
241
242 sect = X509V3_get_section(ctx, cnf->name + 1);
243 if (!sect)
244 {
245 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_SECTION);
246 X509V3_conf_err(cnf);
247 goto err;
248 }
249 for (j = 0; success_p && j < sk_CONF_VALUE_num(sect); j++)
250 {
251 success_p =
252 process_pci_value(sk_CONF_VALUE_value(sect, j),
253 &language, &pathlen, &policy);
254 }
255 X509V3_section_free(ctx, sect);
256 if (!success_p)
257 goto err;
258 }
259 else
260 {
261 if (!process_pci_value(cnf,
262 &language, &pathlen, &policy))
263 {
264 X509V3_conf_err(cnf);
265 goto err;
266 }
267 }
268 }
269
270 /* Language is mandatory */
271 if (!language)
272 {
273 X509V3err(X509V3_F_R2I_PCI,X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED);
274 goto err;
275 }
276 i = OBJ_obj2nid(language);
277 if ((i == NID_Independent || i == NID_id_ppl_inheritAll) && policy)
278 {
279 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY);
280 goto err;
281 }
282
283 pci = PROXY_CERT_INFO_EXTENSION_new();
284 if (!pci)
285 {
286 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
287 goto err;
288 }
289 pci->proxyPolicy = PROXY_POLICY_new();
290 if (!pci->proxyPolicy)
291 {
292 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
293 goto err;
294 }
295
296 pci->proxyPolicy->policyLanguage = language; language = NULL;
297 pci->proxyPolicy->policy = policy; policy = NULL;
298 pci->pcPathLengthConstraint = pathlen; pathlen = NULL;
299 goto end;
300err:
301 if (language) { ASN1_OBJECT_free(language); language = NULL; }
302 if (pathlen) { ASN1_INTEGER_free(pathlen); pathlen = NULL; }
303 if (policy) { ASN1_OCTET_STRING_free(policy); policy = NULL; }
304 if (pci && pci->proxyPolicy)
305 {
306 PROXY_POLICY_free(pci->proxyPolicy);
307 pci->proxyPolicy = NULL;
308 }
309 if (pci) { PROXY_CERT_INFO_EXTENSION_free(pci); pci = NULL; }
310end:
311 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
312 return pci;
313 }
diff --git a/src/lib/libcrypto/x509v3/v3_pcia.c b/src/lib/libcrypto/x509v3/v3_pcia.c
new file mode 100644
index 0000000000..bb362e0e5a
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_pcia.c
@@ -0,0 +1,55 @@
1/* v3_pcia.c -*- mode:C; c-file-style: "eay" -*- */
2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org)
4 */
5/* Copyright (c) 2004 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <openssl/asn1.h>
38#include <openssl/asn1t.h>
39#include <openssl/x509v3.h>
40
41ASN1_SEQUENCE(PROXY_POLICY) =
42 {
43 ASN1_SIMPLE(PROXY_POLICY,policyLanguage,ASN1_OBJECT),
44 ASN1_OPT(PROXY_POLICY,policy,ASN1_OCTET_STRING)
45} ASN1_SEQUENCE_END(PROXY_POLICY)
46
47IMPLEMENT_ASN1_FUNCTIONS(PROXY_POLICY)
48
49ASN1_SEQUENCE(PROXY_CERT_INFO_EXTENSION) =
50 {
51 ASN1_OPT(PROXY_CERT_INFO_EXTENSION,pcPathLengthConstraint,ASN1_INTEGER),
52 ASN1_SIMPLE(PROXY_CERT_INFO_EXTENSION,proxyPolicy,PROXY_POLICY)
53} ASN1_SEQUENCE_END(PROXY_CERT_INFO_EXTENSION)
54
55IMPLEMENT_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
new file mode 100644
index 0000000000..49a2e4697a
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_pku.c
@@ -0,0 +1,108 @@
1/* v3_pku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63#include <openssl/x509v3.h>
64
65static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *usage, BIO *out, int indent);
66/*
67static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
68*/
69X509V3_EXT_METHOD v3_pkey_usage_period = {
70NID_private_key_usage_period, 0, ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
710,0,0,0,
720,0,0,0,
73(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
74NULL
75};
76
77ASN1_SEQUENCE(PKEY_USAGE_PERIOD) = {
78 ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notBefore, ASN1_GENERALIZEDTIME, 0),
79 ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notAfter, ASN1_GENERALIZEDTIME, 1)
80} ASN1_SEQUENCE_END(PKEY_USAGE_PERIOD)
81
82IMPLEMENT_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
83
84static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
85 PKEY_USAGE_PERIOD *usage, BIO *out, int indent)
86{
87 BIO_printf(out, "%*s", indent, "");
88 if(usage->notBefore) {
89 BIO_write(out, "Not Before: ", 12);
90 ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
91 if(usage->notAfter) BIO_write(out, ", ", 2);
92 }
93 if(usage->notAfter) {
94 BIO_write(out, "Not After: ", 11);
95 ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
96 }
97 return 1;
98}
99
100/*
101static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values)
102X509V3_EXT_METHOD *method;
103X509V3_CTX *ctx;
104STACK_OF(CONF_VALUE) *values;
105{
106return NULL;
107}
108*/
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
new file mode 100644
index 0000000000..5d268eb768
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_prn.c
@@ -0,0 +1,233 @@
1/* v3_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65/* Extension printing routines */
66
67static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported);
68
69/* Print out a name+value stack */
70
71void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
72{
73 int i;
74 CONF_VALUE *nval;
75 if(!val) return;
76 if(!ml || !sk_CONF_VALUE_num(val)) {
77 BIO_printf(out, "%*s", indent, "");
78 if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n");
79 }
80 for(i = 0; i < sk_CONF_VALUE_num(val); i++) {
81 if(ml) BIO_printf(out, "%*s", indent, "");
82 else if(i > 0) BIO_printf(out, ", ");
83 nval = sk_CONF_VALUE_value(val, i);
84 if(!nval->name) BIO_puts(out, nval->value);
85 else if(!nval->value) BIO_puts(out, nval->name);
86#ifndef CHARSET_EBCDIC
87 else BIO_printf(out, "%s:%s", nval->name, nval->value);
88#else
89 else {
90 int len;
91 char *tmp;
92 len = strlen(nval->value)+1;
93 tmp = OPENSSL_malloc(len);
94 if (tmp)
95 {
96 ascii2ebcdic(tmp, nval->value, len);
97 BIO_printf(out, "%s:%s", nval->name, tmp);
98 OPENSSL_free(tmp);
99 }
100 }
101#endif
102 if(ml) BIO_puts(out, "\n");
103 }
104}
105
106/* Main routine: print out a general extension */
107
108int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent)
109{
110 void *ext_str = NULL;
111 char *value = NULL;
112 unsigned char *p;
113 X509V3_EXT_METHOD *method;
114 STACK_OF(CONF_VALUE) *nval = NULL;
115 int ok = 1;
116 if(!(method = X509V3_EXT_get(ext)))
117 return unknown_ext_print(out, ext, flag, indent, 0);
118 p = ext->value->data;
119 if(method->it) ext_str = ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it));
120 else ext_str = method->d2i(NULL, &p, ext->value->length);
121
122 if(!ext_str) return unknown_ext_print(out, ext, flag, indent, 1);
123
124 if(method->i2s) {
125 if(!(value = method->i2s(method, ext_str))) {
126 ok = 0;
127 goto err;
128 }
129#ifndef CHARSET_EBCDIC
130 BIO_printf(out, "%*s%s", indent, "", value);
131#else
132 {
133 int len;
134 char *tmp;
135 len = strlen(value)+1;
136 tmp = OPENSSL_malloc(len);
137 if (tmp)
138 {
139 ascii2ebcdic(tmp, value, len);
140 BIO_printf(out, "%*s%s", indent, "", tmp);
141 OPENSSL_free(tmp);
142 }
143 }
144#endif
145 } else if(method->i2v) {
146 if(!(nval = method->i2v(method, ext_str, NULL))) {
147 ok = 0;
148 goto err;
149 }
150 X509V3_EXT_val_prn(out, nval, indent,
151 method->ext_flags & X509V3_EXT_MULTILINE);
152 } else if(method->i2r) {
153 if(!method->i2r(method, ext_str, out, indent)) ok = 0;
154 } else ok = 0;
155
156 err:
157 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
158 if(value) OPENSSL_free(value);
159 if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));
160 else method->ext_free(ext_str);
161 return ok;
162}
163
164int X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent)
165{
166 int i, j;
167
168 if(sk_X509_EXTENSION_num(exts) <= 0) return 1;
169
170 if(title)
171 {
172 BIO_printf(bp,"%*s%s:\n",indent, "", title);
173 indent += 4;
174 }
175
176 for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
177 {
178 ASN1_OBJECT *obj;
179 X509_EXTENSION *ex;
180 ex=sk_X509_EXTENSION_value(exts, i);
181 if (indent && BIO_printf(bp,"%*s",indent, "") <= 0) return 0;
182 obj=X509_EXTENSION_get_object(ex);
183 i2a_ASN1_OBJECT(bp,obj);
184 j=X509_EXTENSION_get_critical(ex);
185 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
186 return 0;
187 if(!X509V3_EXT_print(bp, ex, flag, indent + 4))
188 {
189 BIO_printf(bp, "%*s", indent + 4, "");
190 M_ASN1_OCTET_STRING_print(bp,ex->value);
191 }
192 if (BIO_write(bp,"\n",1) <= 0) return 0;
193 }
194 return 1;
195}
196
197static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported)
198{
199 switch(flag & X509V3_EXT_UNKNOWN_MASK) {
200
201 case X509V3_EXT_DEFAULT:
202 return 0;
203
204 case X509V3_EXT_ERROR_UNKNOWN:
205 if(supported)
206 BIO_printf(out, "%*s<Parse Error>", indent, "");
207 else
208 BIO_printf(out, "%*s<Not Supported>", indent, "");
209 return 1;
210
211 case X509V3_EXT_PARSE_UNKNOWN:
212 return ASN1_parse_dump(out,
213 ext->value->data, ext->value->length, indent, -1);
214 case X509V3_EXT_DUMP_UNKNOWN:
215 return BIO_dump_indent(out, (char *)ext->value->data, ext->value->length, indent);
216
217 default:
218 return 1;
219 }
220}
221
222
223#ifndef OPENSSL_NO_FP_API
224int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
225{
226 BIO *bio_tmp;
227 int ret;
228 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0;
229 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
230 BIO_free(bio_tmp);
231 return ret;
232}
233#endif
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
new file mode 100644
index 0000000000..bbdf6da493
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_purp.c
@@ -0,0 +1,647 @@
1/* v3_purp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62#include <openssl/x509_vfy.h>
63
64static void x509v3_cache_extensions(X509 *x);
65
66static int check_ssl_ca(const X509 *x);
67static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca);
68static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca);
69static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca);
70static int purpose_smime(const X509 *x, int ca);
71static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
72static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, int ca);
73static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
74static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca);
75static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca);
76
77static int xp_cmp(const X509_PURPOSE * const *a,
78 const X509_PURPOSE * const *b);
79static void xptable_free(X509_PURPOSE *p);
80
81static X509_PURPOSE xstandard[] = {
82 {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, 0, check_purpose_ssl_client, "SSL client", "sslclient", NULL},
83 {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ssl_server, "SSL server", "sslserver", NULL},
84 {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ns_ssl_server, "Netscape SSL server", "nssslserver", NULL},
85 {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, 0, check_purpose_smime_sign, "S/MIME signing", "smimesign", NULL},
86 {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, 0, check_purpose_smime_encrypt, "S/MIME encryption", "smimeencrypt", NULL},
87 {X509_PURPOSE_CRL_SIGN, X509_TRUST_COMPAT, 0, check_purpose_crl_sign, "CRL signing", "crlsign", NULL},
88 {X509_PURPOSE_ANY, X509_TRUST_DEFAULT, 0, no_check, "Any Purpose", "any", NULL},
89 {X509_PURPOSE_OCSP_HELPER, X509_TRUST_COMPAT, 0, ocsp_helper, "OCSP helper", "ocsphelper", NULL},
90};
91
92#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
93
94IMPLEMENT_STACK_OF(X509_PURPOSE)
95
96static STACK_OF(X509_PURPOSE) *xptable = NULL;
97
98static int xp_cmp(const X509_PURPOSE * const *a,
99 const X509_PURPOSE * const *b)
100{
101 return (*a)->purpose - (*b)->purpose;
102}
103
104/* As much as I'd like to make X509_check_purpose use a "const" X509*
105 * I really can't because it does recalculate hashes and do other non-const
106 * things. */
107int X509_check_purpose(X509 *x, int id, int ca)
108{
109 int idx;
110 const X509_PURPOSE *pt;
111 if(!(x->ex_flags & EXFLAG_SET)) {
112 CRYPTO_w_lock(CRYPTO_LOCK_X509);
113 x509v3_cache_extensions(x);
114 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
115 }
116 if(id == -1) return 1;
117 idx = X509_PURPOSE_get_by_id(id);
118 if(idx == -1) return -1;
119 pt = X509_PURPOSE_get0(idx);
120 return pt->check_purpose(pt, x, ca);
121}
122
123int X509_PURPOSE_set(int *p, int purpose)
124{
125 if(X509_PURPOSE_get_by_id(purpose) == -1) {
126 X509V3err(X509V3_F_X509_PURPOSE_SET, X509V3_R_INVALID_PURPOSE);
127 return 0;
128 }
129 *p = purpose;
130 return 1;
131}
132
133int X509_PURPOSE_get_count(void)
134{
135 if(!xptable) return X509_PURPOSE_COUNT;
136 return sk_X509_PURPOSE_num(xptable) + X509_PURPOSE_COUNT;
137}
138
139X509_PURPOSE * X509_PURPOSE_get0(int idx)
140{
141 if(idx < 0) return NULL;
142 if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
143 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
144}
145
146int X509_PURPOSE_get_by_sname(char *sname)
147{
148 int i;
149 X509_PURPOSE *xptmp;
150 for(i = 0; i < X509_PURPOSE_get_count(); i++) {
151 xptmp = X509_PURPOSE_get0(i);
152 if(!strcmp(xptmp->sname, sname)) return i;
153 }
154 return -1;
155}
156
157int X509_PURPOSE_get_by_id(int purpose)
158{
159 X509_PURPOSE tmp;
160 int idx;
161 if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
162 return purpose - X509_PURPOSE_MIN;
163 tmp.purpose = purpose;
164 if(!xptable) return -1;
165 idx = sk_X509_PURPOSE_find(xptable, &tmp);
166 if(idx == -1) return -1;
167 return idx + X509_PURPOSE_COUNT;
168}
169
170int X509_PURPOSE_add(int id, int trust, int flags,
171 int (*ck)(const X509_PURPOSE *, const X509 *, int),
172 char *name, char *sname, void *arg)
173{
174 int idx;
175 X509_PURPOSE *ptmp;
176 /* This is set according to what we change: application can't set it */
177 flags &= ~X509_PURPOSE_DYNAMIC;
178 /* This will always be set for application modified trust entries */
179 flags |= X509_PURPOSE_DYNAMIC_NAME;
180 /* Get existing entry if any */
181 idx = X509_PURPOSE_get_by_id(id);
182 /* Need a new entry */
183 if(idx == -1) {
184 if(!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) {
185 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
186 return 0;
187 }
188 ptmp->flags = X509_PURPOSE_DYNAMIC;
189 } else ptmp = X509_PURPOSE_get0(idx);
190
191 /* OPENSSL_free existing name if dynamic */
192 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
193 OPENSSL_free(ptmp->name);
194 OPENSSL_free(ptmp->sname);
195 }
196 /* dup supplied name */
197 ptmp->name = BUF_strdup(name);
198 ptmp->sname = BUF_strdup(sname);
199 if(!ptmp->name || !ptmp->sname) {
200 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
201 return 0;
202 }
203 /* Keep the dynamic flag of existing entry */
204 ptmp->flags &= X509_PURPOSE_DYNAMIC;
205 /* Set all other flags */
206 ptmp->flags |= flags;
207
208 ptmp->purpose = id;
209 ptmp->trust = trust;
210 ptmp->check_purpose = ck;
211 ptmp->usr_data = arg;
212
213 /* If its a new entry manage the dynamic table */
214 if(idx == -1) {
215 if(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
216 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
217 return 0;
218 }
219 if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
220 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
221 return 0;
222 }
223 }
224 return 1;
225}
226
227static void xptable_free(X509_PURPOSE *p)
228 {
229 if(!p) return;
230 if (p->flags & X509_PURPOSE_DYNAMIC)
231 {
232 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) {
233 OPENSSL_free(p->name);
234 OPENSSL_free(p->sname);
235 }
236 OPENSSL_free(p);
237 }
238 }
239
240void X509_PURPOSE_cleanup(void)
241{
242 int i;
243 sk_X509_PURPOSE_pop_free(xptable, xptable_free);
244 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i);
245 xptable = NULL;
246}
247
248int X509_PURPOSE_get_id(X509_PURPOSE *xp)
249{
250 return xp->purpose;
251}
252
253char *X509_PURPOSE_get0_name(X509_PURPOSE *xp)
254{
255 return xp->name;
256}
257
258char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp)
259{
260 return xp->sname;
261}
262
263int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
264{
265 return xp->trust;
266}
267
268static int nid_cmp(int *a, int *b)
269 {
270 return *a - *b;
271 }
272
273int X509_supported_extension(X509_EXTENSION *ex)
274 {
275 /* This table is a list of the NIDs of supported extensions:
276 * that is those which are used by the verify process. If
277 * an extension is critical and doesn't appear in this list
278 * then the verify process will normally reject the certificate.
279 * The list must be kept in numerical order because it will be
280 * searched using bsearch.
281 */
282
283 static int supported_nids[] = {
284 NID_netscape_cert_type, /* 71 */
285 NID_key_usage, /* 83 */
286 NID_subject_alt_name, /* 85 */
287 NID_basic_constraints, /* 87 */
288 NID_ext_key_usage, /* 126 */
289 NID_proxyCertInfo /* 661 */
290 };
291
292 int ex_nid;
293
294 ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex));
295
296 if (ex_nid == NID_undef)
297 return 0;
298
299 if (OBJ_bsearch((char *)&ex_nid, (char *)supported_nids,
300 sizeof(supported_nids)/sizeof(int), sizeof(int),
301 (int (*)(const void *, const void *))nid_cmp))
302 return 1;
303 return 0;
304 }
305
306
307static void x509v3_cache_extensions(X509 *x)
308{
309 BASIC_CONSTRAINTS *bs;
310 PROXY_CERT_INFO_EXTENSION *pci;
311 ASN1_BIT_STRING *usage;
312 ASN1_BIT_STRING *ns;
313 EXTENDED_KEY_USAGE *extusage;
314 X509_EXTENSION *ex;
315
316 int i;
317 if(x->ex_flags & EXFLAG_SET) return;
318#ifndef OPENSSL_NO_SHA
319 X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);
320#endif
321 /* Does subject name match issuer ? */
322 if(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))
323 x->ex_flags |= EXFLAG_SS;
324 /* V1 should mean no extensions ... */
325 if(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;
326 /* Handle basic constraints */
327 if((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {
328 if(bs->ca) x->ex_flags |= EXFLAG_CA;
329 if(bs->pathlen) {
330 if((bs->pathlen->type == V_ASN1_NEG_INTEGER)
331 || !bs->ca) {
332 x->ex_flags |= EXFLAG_INVALID;
333 x->ex_pathlen = 0;
334 } else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);
335 } else x->ex_pathlen = -1;
336 BASIC_CONSTRAINTS_free(bs);
337 x->ex_flags |= EXFLAG_BCONS;
338 }
339 /* Handle proxy certificates */
340 if((pci=X509_get_ext_d2i(x, NID_proxyCertInfo, NULL, NULL))) {
341 if (x->ex_flags & EXFLAG_CA
342 || X509_get_ext_by_NID(x, NID_subject_alt_name, 0) >= 0
343 || X509_get_ext_by_NID(x, NID_issuer_alt_name, 0) >= 0) {
344 x->ex_flags |= EXFLAG_INVALID;
345 }
346 PROXY_CERT_INFO_EXTENSION_free(pci);
347 x->ex_flags |= EXFLAG_PROXY;
348 }
349 /* Handle key usage */
350 if((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {
351 if(usage->length > 0) {
352 x->ex_kusage = usage->data[0];
353 if(usage->length > 1)
354 x->ex_kusage |= usage->data[1] << 8;
355 } else x->ex_kusage = 0;
356 x->ex_flags |= EXFLAG_KUSAGE;
357 ASN1_BIT_STRING_free(usage);
358 }
359 x->ex_xkusage = 0;
360 if((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {
361 x->ex_flags |= EXFLAG_XKUSAGE;
362 for(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {
363 switch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {
364 case NID_server_auth:
365 x->ex_xkusage |= XKU_SSL_SERVER;
366 break;
367
368 case NID_client_auth:
369 x->ex_xkusage |= XKU_SSL_CLIENT;
370 break;
371
372 case NID_email_protect:
373 x->ex_xkusage |= XKU_SMIME;
374 break;
375
376 case NID_code_sign:
377 x->ex_xkusage |= XKU_CODE_SIGN;
378 break;
379
380 case NID_ms_sgc:
381 case NID_ns_sgc:
382 x->ex_xkusage |= XKU_SGC;
383 break;
384
385 case NID_OCSP_sign:
386 x->ex_xkusage |= XKU_OCSP_SIGN;
387 break;
388
389 case NID_time_stamp:
390 x->ex_xkusage |= XKU_TIMESTAMP;
391 break;
392
393 case NID_dvcs:
394 x->ex_xkusage |= XKU_DVCS;
395 break;
396 }
397 }
398 sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);
399 }
400
401 if((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {
402 if(ns->length > 0) x->ex_nscert = ns->data[0];
403 else x->ex_nscert = 0;
404 x->ex_flags |= EXFLAG_NSCERT;
405 ASN1_BIT_STRING_free(ns);
406 }
407 x->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);
408 x->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);
409 for (i = 0; i < X509_get_ext_count(x); i++)
410 {
411 ex = X509_get_ext(x, i);
412 if (!X509_EXTENSION_get_critical(ex))
413 continue;
414 if (!X509_supported_extension(ex))
415 {
416 x->ex_flags |= EXFLAG_CRITICAL;
417 break;
418 }
419 }
420 x->ex_flags |= EXFLAG_SET;
421}
422
423/* CA checks common to all purposes
424 * return codes:
425 * 0 not a CA
426 * 1 is a CA
427 * 2 basicConstraints absent so "maybe" a CA
428 * 3 basicConstraints absent but self signed V1.
429 * 4 basicConstraints absent but keyUsage present and keyCertSign asserted.
430 */
431
432#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
433#define ku_reject(x, usage) \
434 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
435#define xku_reject(x, usage) \
436 (((x)->ex_flags & EXFLAG_XKUSAGE) && !((x)->ex_xkusage & (usage)))
437#define ns_reject(x, usage) \
438 (((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage)))
439
440static int check_ca(const X509 *x)
441{
442 /* keyUsage if present should allow cert signing */
443 if(ku_reject(x, KU_KEY_CERT_SIGN)) return 0;
444 if(x->ex_flags & EXFLAG_BCONS) {
445 if(x->ex_flags & EXFLAG_CA) return 1;
446 /* If basicConstraints says not a CA then say so */
447 else return 0;
448 } else {
449 /* we support V1 roots for... uh, I don't really know why. */
450 if((x->ex_flags & V1_ROOT) == V1_ROOT) return 3;
451 /* If key usage present it must have certSign so tolerate it */
452 else if (x->ex_flags & EXFLAG_KUSAGE) return 4;
453 /* Older certificates could have Netscape-specific CA types */
454 else if (x->ex_flags & EXFLAG_NSCERT
455 && x->ex_nscert & NS_ANY_CA) return 5;
456 /* can this still be regarded a CA certificate? I doubt it */
457 return 0;
458 }
459}
460
461int X509_check_ca(X509 *x)
462{
463 if(!(x->ex_flags & EXFLAG_SET)) {
464 CRYPTO_w_lock(CRYPTO_LOCK_X509);
465 x509v3_cache_extensions(x);
466 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
467 }
468
469 return check_ca(x);
470}
471
472/* Check SSL CA: common checks for SSL client and server */
473static int check_ssl_ca(const X509 *x)
474{
475 int ca_ret;
476 ca_ret = check_ca(x);
477 if(!ca_ret) return 0;
478 /* check nsCertType if present */
479 if(ca_ret != 5 || x->ex_nscert & NS_SSL_CA) return ca_ret;
480 else return 0;
481}
482
483
484static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca)
485{
486 if(xku_reject(x,XKU_SSL_CLIENT)) return 0;
487 if(ca) return check_ssl_ca(x);
488 /* We need to do digital signatures with it */
489 if(ku_reject(x,KU_DIGITAL_SIGNATURE)) return 0;
490 /* nsCertType if present should allow SSL client use */
491 if(ns_reject(x, NS_SSL_CLIENT)) return 0;
492 return 1;
493}
494
495static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca)
496{
497 if(xku_reject(x,XKU_SSL_SERVER|XKU_SGC)) return 0;
498 if(ca) return check_ssl_ca(x);
499
500 if(ns_reject(x, NS_SSL_SERVER)) return 0;
501 /* Now as for keyUsage: we'll at least need to sign OR encipher */
502 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT)) return 0;
503
504 return 1;
505
506}
507
508static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca)
509{
510 int ret;
511 ret = check_purpose_ssl_server(xp, x, ca);
512 if(!ret || ca) return ret;
513 /* We need to encipher or Netscape complains */
514 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
515 return ret;
516}
517
518/* common S/MIME checks */
519static int purpose_smime(const X509 *x, int ca)
520{
521 if(xku_reject(x,XKU_SMIME)) return 0;
522 if(ca) {
523 int ca_ret;
524 ca_ret = check_ca(x);
525 if(!ca_ret) return 0;
526 /* check nsCertType if present */
527 if(ca_ret != 5 || x->ex_nscert & NS_SMIME_CA) return ca_ret;
528 else return 0;
529 }
530 if(x->ex_flags & EXFLAG_NSCERT) {
531 if(x->ex_nscert & NS_SMIME) return 1;
532 /* Workaround for some buggy certificates */
533 if(x->ex_nscert & NS_SSL_CLIENT) return 2;
534 return 0;
535 }
536 return 1;
537}
538
539static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca)
540{
541 int ret;
542 ret = purpose_smime(x, ca);
543 if(!ret || ca) return ret;
544 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_NON_REPUDIATION)) return 0;
545 return ret;
546}
547
548static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, int ca)
549{
550 int ret;
551 ret = purpose_smime(x, ca);
552 if(!ret || ca) return ret;
553 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
554 return ret;
555}
556
557static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, int ca)
558{
559 if(ca) {
560 int ca_ret;
561 if((ca_ret = check_ca(x)) != 2) return ca_ret;
562 else return 0;
563 }
564 if(ku_reject(x, KU_CRL_SIGN)) return 0;
565 return 1;
566}
567
568/* OCSP helper: this is *not* a full OCSP check. It just checks that
569 * each CA is valid. Additional checks must be made on the chain.
570 */
571
572static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca)
573{
574 /* Must be a valid CA. Should we really support the "I don't know"
575 value (2)? */
576 if(ca) return check_ca(x);
577 /* leaf certificate is checked in OCSP_verify() */
578 return 1;
579}
580
581static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca)
582{
583 return 1;
584}
585
586/* Various checks to see if one certificate issued the second.
587 * This can be used to prune a set of possible issuer certificates
588 * which have been looked up using some simple method such as by
589 * subject name.
590 * These are:
591 * 1. Check issuer_name(subject) == subject_name(issuer)
592 * 2. If akid(subject) exists check it matches issuer
593 * 3. If key_usage(issuer) exists check it supports certificate signing
594 * returns 0 for OK, positive for reason for mismatch, reasons match
595 * codes for X509_verify_cert()
596 */
597
598int X509_check_issued(X509 *issuer, X509 *subject)
599{
600 if(X509_NAME_cmp(X509_get_subject_name(issuer),
601 X509_get_issuer_name(subject)))
602 return X509_V_ERR_SUBJECT_ISSUER_MISMATCH;
603 x509v3_cache_extensions(issuer);
604 x509v3_cache_extensions(subject);
605 if(subject->akid) {
606 /* Check key ids (if present) */
607 if(subject->akid->keyid && issuer->skid &&
608 ASN1_OCTET_STRING_cmp(subject->akid->keyid, issuer->skid) )
609 return X509_V_ERR_AKID_SKID_MISMATCH;
610 /* Check serial number */
611 if(subject->akid->serial &&
612 ASN1_INTEGER_cmp(X509_get_serialNumber(issuer),
613 subject->akid->serial))
614 return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
615 /* Check issuer name */
616 if(subject->akid->issuer) {
617 /* Ugh, for some peculiar reason AKID includes
618 * SEQUENCE OF GeneralName. So look for a DirName.
619 * There may be more than one but we only take any
620 * notice of the first.
621 */
622 GENERAL_NAMES *gens;
623 GENERAL_NAME *gen;
624 X509_NAME *nm = NULL;
625 int i;
626 gens = subject->akid->issuer;
627 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
628 gen = sk_GENERAL_NAME_value(gens, i);
629 if(gen->type == GEN_DIRNAME) {
630 nm = gen->d.dirn;
631 break;
632 }
633 }
634 if(nm && X509_NAME_cmp(nm, X509_get_issuer_name(issuer)))
635 return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
636 }
637 }
638 if(subject->ex_flags & EXFLAG_PROXY)
639 {
640 if(ku_reject(issuer, KU_DIGITAL_SIGNATURE))
641 return X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE;
642 }
643 else if(ku_reject(issuer, KU_KEY_CERT_SIGN))
644 return X509_V_ERR_KEYUSAGE_NO_CERTSIGN;
645 return X509_V_OK;
646}
647
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
new file mode 100644
index 0000000000..c0f044ac1b
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_skey.c
@@ -0,0 +1,144 @@
1/* v3_skey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/x509v3.h>
63
64static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
65X509V3_EXT_METHOD v3_skey_id = {
66NID_subject_key_identifier, 0, ASN1_ITEM_ref(ASN1_OCTET_STRING),
670,0,0,0,
68(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
69(X509V3_EXT_S2I)s2i_skey_id,
700,0,0,0,
71NULL};
72
73char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
74 ASN1_OCTET_STRING *oct)
75{
76 return hex_to_string(oct->data, oct->length);
77}
78
79ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
80 X509V3_CTX *ctx, char *str)
81{
82 ASN1_OCTET_STRING *oct;
83 long length;
84
85 if(!(oct = M_ASN1_OCTET_STRING_new())) {
86 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89
90 if(!(oct->data = string_to_hex(str, &length))) {
91 M_ASN1_OCTET_STRING_free(oct);
92 return NULL;
93 }
94
95 oct->length = length;
96
97 return oct;
98
99}
100
101static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
102 X509V3_CTX *ctx, char *str)
103{
104 ASN1_OCTET_STRING *oct;
105 ASN1_BIT_STRING *pk;
106 unsigned char pkey_dig[EVP_MAX_MD_SIZE];
107 unsigned int diglen;
108
109 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
110
111 if(!(oct = M_ASN1_OCTET_STRING_new())) {
112 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115
116 if(ctx && (ctx->flags == CTX_TEST)) return oct;
117
118 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
119 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
120 goto err;
121 }
122
123 if(ctx->subject_req)
124 pk = ctx->subject_req->req_info->pubkey->public_key;
125 else pk = ctx->subject_cert->cert_info->key->public_key;
126
127 if(!pk) {
128 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
129 goto err;
130 }
131
132 EVP_Digest(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL);
133
134 if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
135 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
136 goto err;
137 }
138
139 return oct;
140
141 err:
142 M_ASN1_OCTET_STRING_free(oct);
143 return NULL;
144}
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
new file mode 100644
index 0000000000..d3f4ba3a72
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_sxnet.c
@@ -0,0 +1,262 @@
1/* v3_sxnet.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66/* Support for Thawte strong extranet extension */
67
68#define SXNET_TEST
69
70static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent);
71#ifdef SXNET_TEST
72static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *nval);
74#endif
75X509V3_EXT_METHOD v3_sxnet = {
76NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET),
770,0,0,0,
780,0,
790,
80#ifdef SXNET_TEST
81(X509V3_EXT_V2I)sxnet_v2i,
82#else
830,
84#endif
85(X509V3_EXT_I2R)sxnet_i2r,
860,
87NULL
88};
89
90ASN1_SEQUENCE(SXNETID) = {
91 ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER),
92 ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING)
93} ASN1_SEQUENCE_END(SXNETID)
94
95IMPLEMENT_ASN1_FUNCTIONS(SXNETID)
96
97ASN1_SEQUENCE(SXNET) = {
98 ASN1_SIMPLE(SXNET, version, ASN1_INTEGER),
99 ASN1_SEQUENCE_OF(SXNET, ids, SXNETID)
100} ASN1_SEQUENCE_END(SXNET)
101
102IMPLEMENT_ASN1_FUNCTIONS(SXNET)
103
104static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
105 int indent)
106{
107 long v;
108 char *tmp;
109 SXNETID *id;
110 int i;
111 v = ASN1_INTEGER_get(sx->version);
112 BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v);
113 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
114 id = sk_SXNETID_value(sx->ids, i);
115 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
116 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
117 OPENSSL_free(tmp);
118 M_ASN1_OCTET_STRING_print(out, id->user);
119 }
120 return 1;
121}
122
123#ifdef SXNET_TEST
124
125/* NBB: this is used for testing only. It should *not* be used for anything
126 * else because it will just take static IDs from the configuration file and
127 * they should really be separate values for each user.
128 */
129
130
131static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
132 STACK_OF(CONF_VALUE) *nval)
133{
134 CONF_VALUE *cnf;
135 SXNET *sx = NULL;
136 int i;
137 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
138 cnf = sk_CONF_VALUE_value(nval, i);
139 if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
140 return NULL;
141 }
142 return sx;
143}
144
145
146#endif
147
148/* Strong Extranet utility functions */
149
150/* Add an id given the zone as an ASCII number */
151
152int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
153 int userlen)
154{
155 ASN1_INTEGER *izone = NULL;
156 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
157 X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
158 return 0;
159 }
160 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
161}
162
163/* Add an id given the zone as an unsigned long */
164
165int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
166 int userlen)
167{
168 ASN1_INTEGER *izone = NULL;
169 if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
170 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
171 M_ASN1_INTEGER_free(izone);
172 return 0;
173 }
174 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
175
176}
177
178/* Add an id given the zone as an ASN1_INTEGER.
179 * Note this version uses the passed integer and doesn't make a copy so don't
180 * free it up afterwards.
181 */
182
183int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
184 int userlen)
185{
186 SXNET *sx = NULL;
187 SXNETID *id = NULL;
188 if(!psx || !zone || !user) {
189 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
190 return 0;
191 }
192 if(userlen == -1) userlen = strlen(user);
193 if(userlen > 64) {
194 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
195 return 0;
196 }
197 if(!*psx) {
198 if(!(sx = SXNET_new())) goto err;
199 if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
200 *psx = sx;
201 } else sx = *psx;
202 if(SXNET_get_id_INTEGER(sx, zone)) {
203 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
204 return 0;
205 }
206
207 if(!(id = SXNETID_new())) goto err;
208 if(userlen == -1) userlen = strlen(user);
209
210 if(!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
211 if(!sk_SXNETID_push(sx->ids, id)) goto err;
212 id->zone = zone;
213 return 1;
214
215 err:
216 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
217 SXNETID_free(id);
218 SXNET_free(sx);
219 *psx = NULL;
220 return 0;
221}
222
223ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
224{
225 ASN1_INTEGER *izone = NULL;
226 ASN1_OCTET_STRING *oct;
227 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
228 X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
229 return NULL;
230 }
231 oct = SXNET_get_id_INTEGER(sx, izone);
232 M_ASN1_INTEGER_free(izone);
233 return oct;
234}
235
236ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
237{
238 ASN1_INTEGER *izone = NULL;
239 ASN1_OCTET_STRING *oct;
240 if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
241 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
242 M_ASN1_INTEGER_free(izone);
243 return NULL;
244 }
245 oct = SXNET_get_id_INTEGER(sx, izone);
246 M_ASN1_INTEGER_free(izone);
247 return oct;
248}
249
250ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
251{
252 SXNETID *id;
253 int i;
254 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
255 id = sk_SXNETID_value(sx->ids, i);
256 if(!M_ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
257 }
258 return NULL;
259}
260
261IMPLEMENT_STACK_OF(SXNETID)
262IMPLEMENT_ASN1_SET_OF(SXNETID)
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
new file mode 100644
index 0000000000..466c91d0e8
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -0,0 +1,535 @@
1/* v3_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60
61#include <stdio.h>
62#include <ctype.h>
63#include "cryptlib.h"
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static char *strip_spaces(char *name);
68static int sk_strcmp(const char * const *a, const char * const *b);
69static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
70static void str_free(void *str);
71static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
72
73/* Add a CONF_VALUE name value pair to stack */
74
75int X509V3_add_value(const char *name, const char *value,
76 STACK_OF(CONF_VALUE) **extlist)
77{
78 CONF_VALUE *vtmp = NULL;
79 char *tname = NULL, *tvalue = NULL;
80 if(name && !(tname = BUF_strdup(name))) goto err;
81 if(value && !(tvalue = BUF_strdup(value))) goto err;
82 if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err;
83 if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err;
84 vtmp->section = NULL;
85 vtmp->name = tname;
86 vtmp->value = tvalue;
87 if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;
88 return 1;
89 err:
90 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
91 if(vtmp) OPENSSL_free(vtmp);
92 if(tname) OPENSSL_free(tname);
93 if(tvalue) OPENSSL_free(tvalue);
94 return 0;
95}
96
97int X509V3_add_value_uchar(const char *name, const unsigned char *value,
98 STACK_OF(CONF_VALUE) **extlist)
99 {
100 return X509V3_add_value(name,(const char *)value,extlist);
101 }
102
103/* Free function for STACK_OF(CONF_VALUE) */
104
105void X509V3_conf_free(CONF_VALUE *conf)
106{
107 if(!conf) return;
108 if(conf->name) OPENSSL_free(conf->name);
109 if(conf->value) OPENSSL_free(conf->value);
110 if(conf->section) OPENSSL_free(conf->section);
111 OPENSSL_free(conf);
112}
113
114int X509V3_add_value_bool(const char *name, int asn1_bool,
115 STACK_OF(CONF_VALUE) **extlist)
116{
117 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
118 return X509V3_add_value(name, "FALSE", extlist);
119}
120
121int X509V3_add_value_bool_nf(char *name, int asn1_bool,
122 STACK_OF(CONF_VALUE) **extlist)
123{
124 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
125 return 1;
126}
127
128
129char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a)
130{
131 BIGNUM *bntmp = NULL;
132 char *strtmp = NULL;
133 if(!a) return NULL;
134 if(!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
135 !(strtmp = BN_bn2dec(bntmp)) )
136 X509V3err(X509V3_F_I2S_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
137 BN_free(bntmp);
138 return strtmp;
139}
140
141char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)
142{
143 BIGNUM *bntmp = NULL;
144 char *strtmp = NULL;
145 if(!a) return NULL;
146 if(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
147 !(strtmp = BN_bn2dec(bntmp)) )
148 X509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
149 BN_free(bntmp);
150 return strtmp;
151}
152
153ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
154{
155 BIGNUM *bn = NULL;
156 ASN1_INTEGER *aint;
157 int isneg, ishex;
158 int ret;
159 bn = BN_new();
160 if (!value) {
161 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
162 return 0;
163 }
164 if (value[0] == '-') {
165 value++;
166 isneg = 1;
167 } else isneg = 0;
168
169 if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) {
170 value += 2;
171 ishex = 1;
172 } else ishex = 0;
173
174 if (ishex) ret = BN_hex2bn(&bn, value);
175 else ret = BN_dec2bn(&bn, value);
176
177 if (!ret) {
178 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
179 return 0;
180 }
181
182 if (isneg && BN_is_zero(bn)) isneg = 0;
183
184 aint = BN_to_ASN1_INTEGER(bn, NULL);
185 BN_free(bn);
186 if (!aint) {
187 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
188 return 0;
189 }
190 if (isneg) aint->type |= V_ASN1_NEG;
191 return aint;
192}
193
194int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
195 STACK_OF(CONF_VALUE) **extlist)
196{
197 char *strtmp;
198 int ret;
199 if(!aint) return 1;
200 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;
201 ret = X509V3_add_value(name, strtmp, extlist);
202 OPENSSL_free(strtmp);
203 return ret;
204}
205
206int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool)
207{
208 char *btmp;
209 if(!(btmp = value->value)) goto err;
210 if(!strcmp(btmp, "TRUE") || !strcmp(btmp, "true")
211 || !strcmp(btmp, "Y") || !strcmp(btmp, "y")
212 || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
213 *asn1_bool = 0xff;
214 return 1;
215 } else if(!strcmp(btmp, "FALSE") || !strcmp(btmp, "false")
216 || !strcmp(btmp, "N") || !strcmp(btmp, "n")
217 || !strcmp(btmp, "NO") || !strcmp(btmp, "no")) {
218 *asn1_bool = 0;
219 return 1;
220 }
221 err:
222 X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL,X509V3_R_INVALID_BOOLEAN_STRING);
223 X509V3_conf_err(value);
224 return 0;
225}
226
227int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint)
228{
229 ASN1_INTEGER *itmp;
230 if(!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) {
231 X509V3_conf_err(value);
232 return 0;
233 }
234 *aint = itmp;
235 return 1;
236}
237
238#define HDR_NAME 1
239#define HDR_VALUE 2
240
241/*#define DEBUG*/
242
243STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line)
244{
245 char *p, *q, c;
246 char *ntmp, *vtmp;
247 STACK_OF(CONF_VALUE) *values = NULL;
248 char *linebuf;
249 int state;
250 /* We are going to modify the line so copy it first */
251 linebuf = BUF_strdup(line);
252 state = HDR_NAME;
253 ntmp = NULL;
254 /* Go through all characters */
255 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
256
257 switch(state) {
258 case HDR_NAME:
259 if(c == ':') {
260 state = HDR_VALUE;
261 *p = 0;
262 ntmp = strip_spaces(q);
263 if(!ntmp) {
264 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
265 goto err;
266 }
267 q = p + 1;
268 } else if(c == ',') {
269 *p = 0;
270 ntmp = strip_spaces(q);
271 q = p + 1;
272#if 0
273 printf("%s\n", ntmp);
274#endif
275 if(!ntmp) {
276 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
277 goto err;
278 }
279 X509V3_add_value(ntmp, NULL, &values);
280 }
281 break ;
282
283 case HDR_VALUE:
284 if(c == ',') {
285 state = HDR_NAME;
286 *p = 0;
287 vtmp = strip_spaces(q);
288#if 0
289 printf("%s\n", ntmp);
290#endif
291 if(!vtmp) {
292 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
293 goto err;
294 }
295 X509V3_add_value(ntmp, vtmp, &values);
296 ntmp = NULL;
297 q = p + 1;
298 }
299
300 }
301 }
302
303 if(state == HDR_VALUE) {
304 vtmp = strip_spaces(q);
305#if 0
306 printf("%s=%s\n", ntmp, vtmp);
307#endif
308 if(!vtmp) {
309 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
310 goto err;
311 }
312 X509V3_add_value(ntmp, vtmp, &values);
313 } else {
314 ntmp = strip_spaces(q);
315#if 0
316 printf("%s\n", ntmp);
317#endif
318 if(!ntmp) {
319 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
320 goto err;
321 }
322 X509V3_add_value(ntmp, NULL, &values);
323 }
324OPENSSL_free(linebuf);
325return values;
326
327err:
328OPENSSL_free(linebuf);
329sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
330return NULL;
331
332}
333
334/* Delete leading and trailing spaces from a string */
335static char *strip_spaces(char *name)
336{
337 char *p, *q;
338 /* Skip over leading spaces */
339 p = name;
340 while(*p && isspace((unsigned char)*p)) p++;
341 if(!*p) return NULL;
342 q = p + strlen(p) - 1;
343 while((q != p) && isspace((unsigned char)*q)) q--;
344 if(p != q) q[1] = 0;
345 if(!*p) return NULL;
346 return p;
347}
348
349/* hex string utilities */
350
351/* Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its
352 * hex representation
353 * @@@ (Contents of buffer are always kept in ASCII, also on EBCDIC machines)
354 */
355
356char *hex_to_string(unsigned char *buffer, long len)
357{
358 char *tmp, *q;
359 unsigned char *p;
360 int i;
361 static char hexdig[] = "0123456789ABCDEF";
362 if(!buffer || !len) return NULL;
363 if(!(tmp = OPENSSL_malloc(len * 3 + 1))) {
364 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
365 return NULL;
366 }
367 q = tmp;
368 for(i = 0, p = buffer; i < len; i++,p++) {
369 *q++ = hexdig[(*p >> 4) & 0xf];
370 *q++ = hexdig[*p & 0xf];
371 *q++ = ':';
372 }
373 q[-1] = 0;
374#ifdef CHARSET_EBCDIC
375 ebcdic2ascii(tmp, tmp, q - tmp - 1);
376#endif
377
378 return tmp;
379}
380
381/* Give a string of hex digits convert to
382 * a buffer
383 */
384
385unsigned char *string_to_hex(char *str, long *len)
386{
387 unsigned char *hexbuf, *q;
388 unsigned char ch, cl, *p;
389 if(!str) {
390 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT);
391 return NULL;
392 }
393 if(!(hexbuf = OPENSSL_malloc(strlen(str) >> 1))) goto err;
394 for(p = (unsigned char *)str, q = hexbuf; *p;) {
395 ch = *p++;
396#ifdef CHARSET_EBCDIC
397 ch = os_toebcdic[ch];
398#endif
399 if(ch == ':') continue;
400 cl = *p++;
401#ifdef CHARSET_EBCDIC
402 cl = os_toebcdic[cl];
403#endif
404 if(!cl) {
405 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS);
406 OPENSSL_free(hexbuf);
407 return NULL;
408 }
409 if(isupper(ch)) ch = tolower(ch);
410 if(isupper(cl)) cl = tolower(cl);
411
412 if((ch >= '0') && (ch <= '9')) ch -= '0';
413 else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10;
414 else goto badhex;
415
416 if((cl >= '0') && (cl <= '9')) cl -= '0';
417 else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10;
418 else goto badhex;
419
420 *q++ = (ch << 4) | cl;
421 }
422
423 if(len) *len = q - hexbuf;
424
425 return hexbuf;
426
427 err:
428 if(hexbuf) OPENSSL_free(hexbuf);
429 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE);
430 return NULL;
431
432 badhex:
433 OPENSSL_free(hexbuf);
434 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT);
435 return NULL;
436
437}
438
439/* V2I name comparison function: returns zero if 'name' matches
440 * cmp or cmp.*
441 */
442
443int name_cmp(const char *name, const char *cmp)
444{
445 int len, ret;
446 char c;
447 len = strlen(cmp);
448 if((ret = strncmp(name, cmp, len))) return ret;
449 c = name[len];
450 if(!c || (c=='.')) return 0;
451 return 1;
452}
453
454static int sk_strcmp(const char * const *a, const char * const *b)
455{
456 return strcmp(*a, *b);
457}
458
459STACK *X509_get1_email(X509 *x)
460{
461 GENERAL_NAMES *gens;
462 STACK *ret;
463 gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
464 ret = get_email(X509_get_subject_name(x), gens);
465 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
466 return ret;
467}
468
469STACK *X509_REQ_get1_email(X509_REQ *x)
470{
471 GENERAL_NAMES *gens;
472 STACK_OF(X509_EXTENSION) *exts;
473 STACK *ret;
474 exts = X509_REQ_get_extensions(x);
475 gens = X509V3_get_d2i(exts, NID_subject_alt_name, NULL, NULL);
476 ret = get_email(X509_REQ_get_subject_name(x), gens);
477 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
478 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
479 return ret;
480}
481
482
483static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
484{
485 STACK *ret = NULL;
486 X509_NAME_ENTRY *ne;
487 ASN1_IA5STRING *email;
488 GENERAL_NAME *gen;
489 int i;
490 /* Now add any email address(es) to STACK */
491 i = -1;
492 /* First supplied X509_NAME */
493 while((i = X509_NAME_get_index_by_NID(name,
494 NID_pkcs9_emailAddress, i)) >= 0) {
495 ne = X509_NAME_get_entry(name, i);
496 email = X509_NAME_ENTRY_get_data(ne);
497 if(!append_ia5(&ret, email)) return NULL;
498 }
499 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
500 {
501 gen = sk_GENERAL_NAME_value(gens, i);
502 if(gen->type != GEN_EMAIL) continue;
503 if(!append_ia5(&ret, gen->d.ia5)) return NULL;
504 }
505 return ret;
506}
507
508static void str_free(void *str)
509{
510 OPENSSL_free(str);
511}
512
513static int append_ia5(STACK **sk, ASN1_IA5STRING *email)
514{
515 char *emtmp;
516 /* First some sanity checks */
517 if(email->type != V_ASN1_IA5STRING) return 1;
518 if(!email->data || !email->length) return 1;
519 if(!*sk) *sk = sk_new(sk_strcmp);
520 if(!*sk) return 0;
521 /* Don't add duplicates */
522 if(sk_find(*sk, (char *)email->data) != -1) return 1;
523 emtmp = BUF_strdup((char *)email->data);
524 if(!emtmp || !sk_push(*sk, emtmp)) {
525 X509_email_free(*sk);
526 *sk = NULL;
527 return 0;
528 }
529 return 1;
530}
531
532void X509_email_free(STACK *sk)
533{
534 sk_pop_free(sk, str_free);
535}
diff --git a/src/lib/libcrypto/x509v3/v3err.c b/src/lib/libcrypto/x509v3/v3err.c
new file mode 100644
index 0000000000..2df0c3ef01
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3err.c
@@ -0,0 +1,193 @@
1/* crypto/x509v3/v3err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/x509v3.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA X509V3_str_functs[]=
68 {
69{ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"},
70{ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"},
71{ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"},
72{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"},
73{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"},
74{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"},
75{ERR_PACK(0,X509V3_F_I2S_ASN1_IA5STRING,0), "I2S_ASN1_IA5STRING"},
76{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"},
77{ERR_PACK(0,X509V3_F_I2V_AUTHORITY_INFO_ACCESS,0), "I2V_AUTHORITY_INFO_ACCESS"},
78{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"},
79{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"},
80{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"},
81{ERR_PACK(0,X509V3_F_R2I_CERTPOL,0), "R2I_CERTPOL"},
82{ERR_PACK(0,X509V3_F_R2I_PCI,0), "R2I_PCI"},
83{ERR_PACK(0,X509V3_F_S2I_ASN1_IA5STRING,0), "S2I_ASN1_IA5STRING"},
84{ERR_PACK(0,X509V3_F_S2I_ASN1_INTEGER,0), "s2i_ASN1_INTEGER"},
85{ERR_PACK(0,X509V3_F_S2I_ASN1_OCTET_STRING,0), "s2i_ASN1_OCTET_STRING"},
86{ERR_PACK(0,X509V3_F_S2I_ASN1_SKEY_ID,0), "S2I_ASN1_SKEY_ID"},
87{ERR_PACK(0,X509V3_F_S2I_S2I_SKEY_ID,0), "S2I_S2I_SKEY_ID"},
88{ERR_PACK(0,X509V3_F_STRING_TO_HEX,0), "string_to_hex"},
89{ERR_PACK(0,X509V3_F_SXNET_ADD_ASC,0), "SXNET_ADD_ASC"},
90{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_INTEGER,0), "SXNET_add_id_INTEGER"},
91{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"},
92{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"},
93{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"},
94{ERR_PACK(0,X509V3_F_V2I_ACCESS_DESCRIPTION,0), "V2I_ACCESS_DESCRIPTION"},
95{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"},
96{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"},
97{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"},
98{ERR_PACK(0,X509V3_F_V2I_CRLD,0), "V2I_CRLD"},
99{ERR_PACK(0,X509V3_F_V2I_EXT_KU,0), "V2I_EXT_KU"},
100{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAME,0), "v2i_GENERAL_NAME"},
101{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAMES,0), "v2i_GENERAL_NAMES"},
102{ERR_PACK(0,X509V3_F_V3_GENERIC_EXTENSION,0), "V3_GENERIC_EXTENSION"},
103{ERR_PACK(0,X509V3_F_X509V3_ADD_I2D,0), "X509V3_ADD_I2D"},
104{ERR_PACK(0,X509V3_F_X509V3_ADD_VALUE,0), "X509V3_add_value"},
105{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"},
106{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"},
107{ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"},
108{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"},
109{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"},
110{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"},
111{ERR_PACK(0,X509V3_F_X509_PURPOSE_ADD,0), "X509_PURPOSE_add"},
112{ERR_PACK(0,X509V3_F_X509_PURPOSE_SET,0), "X509_PURPOSE_set"},
113{0,NULL}
114 };
115
116static ERR_STRING_DATA X509V3_str_reasons[]=
117 {
118{X509V3_R_BAD_IP_ADDRESS ,"bad ip address"},
119{X509V3_R_BAD_OBJECT ,"bad object"},
120{X509V3_R_BN_DEC2BN_ERROR ,"bn dec2bn error"},
121{X509V3_R_BN_TO_ASN1_INTEGER_ERROR ,"bn to asn1 integer error"},
122{X509V3_R_DUPLICATE_ZONE_ID ,"duplicate zone id"},
123{X509V3_R_ERROR_CONVERTING_ZONE ,"error converting zone"},
124{X509V3_R_ERROR_CREATING_EXTENSION ,"error creating extension"},
125{X509V3_R_ERROR_IN_EXTENSION ,"error in extension"},
126{X509V3_R_EXPECTED_A_SECTION_NAME ,"expected a section name"},
127{X509V3_R_EXTENSION_EXISTS ,"extension exists"},
128{X509V3_R_EXTENSION_NAME_ERROR ,"extension name error"},
129{X509V3_R_EXTENSION_NOT_FOUND ,"extension not found"},
130{X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,"extension setting not supported"},
131{X509V3_R_EXTENSION_VALUE_ERROR ,"extension value error"},
132{X509V3_R_ILLEGAL_HEX_DIGIT ,"illegal hex digit"},
133{X509V3_R_INCORRECT_POLICY_SYNTAX_TAG ,"incorrect policy syntax tag"},
134{X509V3_R_INVALID_BOOLEAN_STRING ,"invalid boolean string"},
135{X509V3_R_INVALID_EXTENSION_STRING ,"invalid extension string"},
136{X509V3_R_INVALID_NAME ,"invalid name"},
137{X509V3_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
138{X509V3_R_INVALID_NULL_NAME ,"invalid null name"},
139{X509V3_R_INVALID_NULL_VALUE ,"invalid null value"},
140{X509V3_R_INVALID_NUMBER ,"invalid number"},
141{X509V3_R_INVALID_NUMBERS ,"invalid numbers"},
142{X509V3_R_INVALID_OBJECT_IDENTIFIER ,"invalid object identifier"},
143{X509V3_R_INVALID_OPTION ,"invalid option"},
144{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"},
145{X509V3_R_INVALID_PROXY_POLICY_IDENTIFIER,"invalid proxy policy identifier"},
146{X509V3_R_INVALID_PROXY_POLICY_SETTING ,"invalid proxy policy setting"},
147{X509V3_R_INVALID_PURPOSE ,"invalid purpose"},
148{X509V3_R_INVALID_SECTION ,"invalid section"},
149{X509V3_R_INVALID_SYNTAX ,"invalid syntax"},
150{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"},
151{X509V3_R_MISSING_VALUE ,"missing value"},
152{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"},
153{X509V3_R_NO_CONFIG_DATABASE ,"no config database"},
154{X509V3_R_NO_ISSUER_CERTIFICATE ,"no issuer certificate"},
155{X509V3_R_NO_ISSUER_DETAILS ,"no issuer details"},
156{X509V3_R_NO_POLICY_IDENTIFIER ,"no policy identifier"},
157{X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED,"no proxy cert policy language defined"},
158{X509V3_R_NO_PUBLIC_KEY ,"no public key"},
159{X509V3_R_NO_SUBJECT_DETAILS ,"no subject details"},
160{X509V3_R_ODD_NUMBER_OF_DIGITS ,"odd number of digits"},
161{X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED,"policy language alreadty defined"},
162{X509V3_R_POLICY_PATH_LENGTH ,"policy path length"},
163{X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED,"policy path length alreadty defined"},
164{X509V3_R_POLICY_SYNTAX_NOT ,"policy syntax not"},
165{X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED,"policy syntax not currently supported"},
166{X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY,"policy when proxy language requires no policy"},
167{X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS ,"unable to get issuer details"},
168{X509V3_R_UNABLE_TO_GET_ISSUER_KEYID ,"unable to get issuer keyid"},
169{X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT ,"unknown bit string argument"},
170{X509V3_R_UNKNOWN_EXTENSION ,"unknown extension"},
171{X509V3_R_UNKNOWN_EXTENSION_NAME ,"unknown extension name"},
172{X509V3_R_UNKNOWN_OPTION ,"unknown option"},
173{X509V3_R_UNSUPPORTED_OPTION ,"unsupported option"},
174{X509V3_R_USER_TOO_LONG ,"user too long"},
175{0,NULL}
176 };
177
178#endif
179
180void ERR_load_X509V3_strings(void)
181 {
182 static int init=1;
183
184 if (init)
185 {
186 init=0;
187#ifndef OPENSSL_NO_ERR
188 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_functs);
189 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_reasons);
190#endif
191
192 }
193 }
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h
new file mode 100644
index 0000000000..e6d91251c2
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/x509v3.h
@@ -0,0 +1,687 @@
1/* x509v3.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#ifndef HEADER_X509V3_H
59#define HEADER_X509V3_H
60
61#include <openssl/bio.h>
62#include <openssl/x509.h>
63#include <openssl/conf.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* Forward reference */
70struct v3_ext_method;
71struct v3_ext_ctx;
72
73/* Useful typedefs */
74
75typedef void * (*X509V3_EXT_NEW)(void);
76typedef void (*X509V3_EXT_FREE)(void *);
77typedef void * (*X509V3_EXT_D2I)(void *, unsigned char ** , long);
78typedef int (*X509V3_EXT_I2D)(void *, unsigned char **);
79typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist);
80typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);
81typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext);
82typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
83typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent);
84typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
85
86/* V3 extension structure */
87
88struct v3_ext_method {
89int ext_nid;
90int ext_flags;
91/* If this is set the following four fields are ignored */
92ASN1_ITEM_EXP *it;
93/* Old style ASN1 calls */
94X509V3_EXT_NEW ext_new;
95X509V3_EXT_FREE ext_free;
96X509V3_EXT_D2I d2i;
97X509V3_EXT_I2D i2d;
98
99/* The following pair is used for string extensions */
100X509V3_EXT_I2S i2s;
101X509V3_EXT_S2I s2i;
102
103/* The following pair is used for multi-valued extensions */
104X509V3_EXT_I2V i2v;
105X509V3_EXT_V2I v2i;
106
107/* The following are used for raw extensions */
108X509V3_EXT_I2R i2r;
109X509V3_EXT_R2I r2i;
110
111void *usr_data; /* Any extension specific data */
112};
113
114typedef struct X509V3_CONF_METHOD_st {
115char * (*get_string)(void *db, char *section, char *value);
116STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
117void (*free_string)(void *db, char * string);
118void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
119} X509V3_CONF_METHOD;
120
121/* Context specific info */
122struct v3_ext_ctx {
123#define CTX_TEST 0x1
124int flags;
125X509 *issuer_cert;
126X509 *subject_cert;
127X509_REQ *subject_req;
128X509_CRL *crl;
129X509V3_CONF_METHOD *db_meth;
130void *db;
131/* Maybe more here */
132};
133
134typedef struct v3_ext_method X509V3_EXT_METHOD;
135typedef struct v3_ext_ctx X509V3_CTX;
136
137DECLARE_STACK_OF(X509V3_EXT_METHOD)
138
139/* ext_flags values */
140#define X509V3_EXT_DYNAMIC 0x1
141#define X509V3_EXT_CTX_DEP 0x2
142#define X509V3_EXT_MULTILINE 0x4
143
144typedef BIT_STRING_BITNAME ENUMERATED_NAMES;
145
146typedef struct BASIC_CONSTRAINTS_st {
147int ca;
148ASN1_INTEGER *pathlen;
149} BASIC_CONSTRAINTS;
150
151
152typedef struct PKEY_USAGE_PERIOD_st {
153ASN1_GENERALIZEDTIME *notBefore;
154ASN1_GENERALIZEDTIME *notAfter;
155} PKEY_USAGE_PERIOD;
156
157typedef struct otherName_st {
158ASN1_OBJECT *type_id;
159ASN1_TYPE *value;
160} OTHERNAME;
161
162typedef struct EDIPartyName_st {
163 ASN1_STRING *nameAssigner;
164 ASN1_STRING *partyName;
165} EDIPARTYNAME;
166
167typedef struct GENERAL_NAME_st {
168
169#define GEN_OTHERNAME 0
170#define GEN_EMAIL 1
171#define GEN_DNS 2
172#define GEN_X400 3
173#define GEN_DIRNAME 4
174#define GEN_EDIPARTY 5
175#define GEN_URI 6
176#define GEN_IPADD 7
177#define GEN_RID 8
178
179int type;
180union {
181 char *ptr;
182 OTHERNAME *otherName; /* otherName */
183 ASN1_IA5STRING *rfc822Name;
184 ASN1_IA5STRING *dNSName;
185 ASN1_TYPE *x400Address;
186 X509_NAME *directoryName;
187 EDIPARTYNAME *ediPartyName;
188 ASN1_IA5STRING *uniformResourceIdentifier;
189 ASN1_OCTET_STRING *iPAddress;
190 ASN1_OBJECT *registeredID;
191
192 /* Old names */
193 ASN1_OCTET_STRING *ip; /* iPAddress */
194 X509_NAME *dirn; /* dirn */
195 ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */
196 ASN1_OBJECT *rid; /* registeredID */
197 ASN1_TYPE *other; /* x400Address */
198} d;
199} GENERAL_NAME;
200
201typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES;
202
203typedef struct ACCESS_DESCRIPTION_st {
204 ASN1_OBJECT *method;
205 GENERAL_NAME *location;
206} ACCESS_DESCRIPTION;
207
208typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS;
209
210typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE;
211
212DECLARE_STACK_OF(GENERAL_NAME)
213DECLARE_ASN1_SET_OF(GENERAL_NAME)
214
215DECLARE_STACK_OF(ACCESS_DESCRIPTION)
216DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)
217
218typedef struct DIST_POINT_NAME_st {
219int type;
220union {
221 GENERAL_NAMES *fullname;
222 STACK_OF(X509_NAME_ENTRY) *relativename;
223} name;
224} DIST_POINT_NAME;
225
226typedef struct DIST_POINT_st {
227DIST_POINT_NAME *distpoint;
228ASN1_BIT_STRING *reasons;
229GENERAL_NAMES *CRLissuer;
230} DIST_POINT;
231
232typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS;
233
234DECLARE_STACK_OF(DIST_POINT)
235DECLARE_ASN1_SET_OF(DIST_POINT)
236
237typedef struct AUTHORITY_KEYID_st {
238ASN1_OCTET_STRING *keyid;
239GENERAL_NAMES *issuer;
240ASN1_INTEGER *serial;
241} AUTHORITY_KEYID;
242
243/* Strong extranet structures */
244
245typedef struct SXNET_ID_st {
246 ASN1_INTEGER *zone;
247 ASN1_OCTET_STRING *user;
248} SXNETID;
249
250DECLARE_STACK_OF(SXNETID)
251DECLARE_ASN1_SET_OF(SXNETID)
252
253typedef struct SXNET_st {
254 ASN1_INTEGER *version;
255 STACK_OF(SXNETID) *ids;
256} SXNET;
257
258typedef struct NOTICEREF_st {
259 ASN1_STRING *organization;
260 STACK_OF(ASN1_INTEGER) *noticenos;
261} NOTICEREF;
262
263typedef struct USERNOTICE_st {
264 NOTICEREF *noticeref;
265 ASN1_STRING *exptext;
266} USERNOTICE;
267
268typedef struct POLICYQUALINFO_st {
269 ASN1_OBJECT *pqualid;
270 union {
271 ASN1_IA5STRING *cpsuri;
272 USERNOTICE *usernotice;
273 ASN1_TYPE *other;
274 } d;
275} POLICYQUALINFO;
276
277DECLARE_STACK_OF(POLICYQUALINFO)
278DECLARE_ASN1_SET_OF(POLICYQUALINFO)
279
280typedef struct POLICYINFO_st {
281 ASN1_OBJECT *policyid;
282 STACK_OF(POLICYQUALINFO) *qualifiers;
283} POLICYINFO;
284
285typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES;
286
287DECLARE_STACK_OF(POLICYINFO)
288DECLARE_ASN1_SET_OF(POLICYINFO)
289
290/* Proxy certificate structures, see RFC 3820 */
291typedef struct PROXY_POLICY_st
292 {
293 ASN1_OBJECT *policyLanguage;
294 ASN1_OCTET_STRING *policy;
295 } PROXY_POLICY;
296
297typedef struct PROXY_CERT_INFO_EXTENSION_st
298 {
299 ASN1_INTEGER *pcPathLengthConstraint;
300 PROXY_POLICY *proxyPolicy;
301 } PROXY_CERT_INFO_EXTENSION;
302
303DECLARE_ASN1_FUNCTIONS(PROXY_POLICY)
304DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
305
306
307#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
308",name:", val->name, ",value:", val->value);
309
310#define X509V3_set_ctx_test(ctx) \
311 X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)
312#define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL;
313
314#define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \
315 0,0,0,0, \
316 0,0, \
317 (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
318 (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
319 NULL, NULL, \
320 table}
321
322#define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \
323 0,0,0,0, \
324 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
325 (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
326 0,0,0,0, \
327 NULL}
328
329#define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
330
331
332/* X509_PURPOSE stuff */
333
334#define EXFLAG_BCONS 0x1
335#define EXFLAG_KUSAGE 0x2
336#define EXFLAG_XKUSAGE 0x4
337#define EXFLAG_NSCERT 0x8
338
339#define EXFLAG_CA 0x10
340#define EXFLAG_SS 0x20
341#define EXFLAG_V1 0x40
342#define EXFLAG_INVALID 0x80
343#define EXFLAG_SET 0x100
344#define EXFLAG_CRITICAL 0x200
345#define EXFLAG_PROXY 0x400
346
347#define KU_DIGITAL_SIGNATURE 0x0080
348#define KU_NON_REPUDIATION 0x0040
349#define KU_KEY_ENCIPHERMENT 0x0020
350#define KU_DATA_ENCIPHERMENT 0x0010
351#define KU_KEY_AGREEMENT 0x0008
352#define KU_KEY_CERT_SIGN 0x0004
353#define KU_CRL_SIGN 0x0002
354#define KU_ENCIPHER_ONLY 0x0001
355#define KU_DECIPHER_ONLY 0x8000
356
357#define NS_SSL_CLIENT 0x80
358#define NS_SSL_SERVER 0x40
359#define NS_SMIME 0x20
360#define NS_OBJSIGN 0x10
361#define NS_SSL_CA 0x04
362#define NS_SMIME_CA 0x02
363#define NS_OBJSIGN_CA 0x01
364#define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA)
365
366#define XKU_SSL_SERVER 0x1
367#define XKU_SSL_CLIENT 0x2
368#define XKU_SMIME 0x4
369#define XKU_CODE_SIGN 0x8
370#define XKU_SGC 0x10
371#define XKU_OCSP_SIGN 0x20
372#define XKU_TIMESTAMP 0x40
373#define XKU_DVCS 0x80
374
375#define X509_PURPOSE_DYNAMIC 0x1
376#define X509_PURPOSE_DYNAMIC_NAME 0x2
377
378typedef struct x509_purpose_st {
379 int purpose;
380 int trust; /* Default trust ID */
381 int flags;
382 int (*check_purpose)(const struct x509_purpose_st *,
383 const X509 *, int);
384 char *name;
385 char *sname;
386 void *usr_data;
387} X509_PURPOSE;
388
389#define X509_PURPOSE_SSL_CLIENT 1
390#define X509_PURPOSE_SSL_SERVER 2
391#define X509_PURPOSE_NS_SSL_SERVER 3
392#define X509_PURPOSE_SMIME_SIGN 4
393#define X509_PURPOSE_SMIME_ENCRYPT 5
394#define X509_PURPOSE_CRL_SIGN 6
395#define X509_PURPOSE_ANY 7
396#define X509_PURPOSE_OCSP_HELPER 8
397
398#define X509_PURPOSE_MIN 1
399#define X509_PURPOSE_MAX 8
400
401/* Flags for X509V3_EXT_print() */
402
403#define X509V3_EXT_UNKNOWN_MASK (0xfL << 16)
404/* Return error for unknown extensions */
405#define X509V3_EXT_DEFAULT 0
406/* Print error for unknown extensions */
407#define X509V3_EXT_ERROR_UNKNOWN (1L << 16)
408/* ASN1 parse unknown extensions */
409#define X509V3_EXT_PARSE_UNKNOWN (2L << 16)
410/* BIO_dump unknown extensions */
411#define X509V3_EXT_DUMP_UNKNOWN (3L << 16)
412
413/* Flags for X509V3_add1_i2d */
414
415#define X509V3_ADD_OP_MASK 0xfL
416#define X509V3_ADD_DEFAULT 0L
417#define X509V3_ADD_APPEND 1L
418#define X509V3_ADD_REPLACE 2L
419#define X509V3_ADD_REPLACE_EXISTING 3L
420#define X509V3_ADD_KEEP_EXISTING 4L
421#define X509V3_ADD_DELETE 5L
422#define X509V3_ADD_SILENT 0x10
423
424DECLARE_STACK_OF(X509_PURPOSE)
425
426DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
427
428DECLARE_ASN1_FUNCTIONS(SXNET)
429DECLARE_ASN1_FUNCTIONS(SXNETID)
430
431int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen);
432int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen);
433int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen);
434
435ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone);
436ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone);
437ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone);
438
439DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID)
440
441DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
442
443DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)
444
445STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);
446int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen);
447
448DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES)
449
450STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
451 GENERAL_NAMES *gen, STACK_OF(CONF_VALUE) *extlist);
452GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
453 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
454
455DECLARE_ASN1_FUNCTIONS(OTHERNAME)
456DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME)
457
458char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
459ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
460
461DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
462int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION* a);
463
464DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
465DECLARE_ASN1_FUNCTIONS(POLICYINFO)
466DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO)
467DECLARE_ASN1_FUNCTIONS(USERNOTICE)
468DECLARE_ASN1_FUNCTIONS(NOTICEREF)
469
470DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS)
471DECLARE_ASN1_FUNCTIONS(DIST_POINT)
472DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME)
473
474DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
475DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
476
477#ifdef HEADER_CONF_H
478GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
479void X509V3_conf_free(CONF_VALUE *val);
480
481X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value);
482X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name, char *value);
483int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section, STACK_OF(X509_EXTENSION) **sk);
484int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509 *cert);
485int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
486int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
487
488X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
489X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
490int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
491int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
492int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
493
494int X509V3_add_value_bool_nf(char *name, int asn1_bool,
495 STACK_OF(CONF_VALUE) **extlist);
496int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
497int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
498void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf);
499void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
500#endif
501
502char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
503STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
504void X509V3_string_free(X509V3_CTX *ctx, char *str);
505void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
506void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
507 X509_REQ *req, X509_CRL *crl, int flags);
508
509int X509V3_add_value(const char *name, const char *value,
510 STACK_OF(CONF_VALUE) **extlist);
511int X509V3_add_value_uchar(const char *name, const unsigned char *value,
512 STACK_OF(CONF_VALUE) **extlist);
513int X509V3_add_value_bool(const char *name, int asn1_bool,
514 STACK_OF(CONF_VALUE) **extlist);
515int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
516 STACK_OF(CONF_VALUE) **extlist);
517char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
518ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
519char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
520char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
521int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
522int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);
523int X509V3_EXT_add_alias(int nid_to, int nid_from);
524void X509V3_EXT_cleanup(void);
525
526X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
527X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
528int X509V3_add_standard_extensions(void);
529STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line);
530void *X509V3_EXT_d2i(X509_EXTENSION *ext);
531void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
532
533
534X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
535int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int crit, unsigned long flags);
536
537char *hex_to_string(unsigned char *buffer, long len);
538unsigned char *string_to_hex(char *str, long *len);
539int name_cmp(const char *name, const char *cmp);
540
541void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
542 int ml);
543int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent);
544int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
545
546int X509V3_extensions_print(BIO *out, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent);
547
548int X509_check_ca(X509 *x);
549int X509_check_purpose(X509 *x, int id, int ca);
550int X509_supported_extension(X509_EXTENSION *ex);
551int X509_PURPOSE_set(int *p, int purpose);
552int X509_check_issued(X509 *issuer, X509 *subject);
553int X509_PURPOSE_get_count(void);
554X509_PURPOSE * X509_PURPOSE_get0(int idx);
555int X509_PURPOSE_get_by_sname(char *sname);
556int X509_PURPOSE_get_by_id(int id);
557int X509_PURPOSE_add(int id, int trust, int flags,
558 int (*ck)(const X509_PURPOSE *, const X509 *, int),
559 char *name, char *sname, void *arg);
560char *X509_PURPOSE_get0_name(X509_PURPOSE *xp);
561char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp);
562int X509_PURPOSE_get_trust(X509_PURPOSE *xp);
563void X509_PURPOSE_cleanup(void);
564int X509_PURPOSE_get_id(X509_PURPOSE *);
565
566STACK *X509_get1_email(X509 *x);
567STACK *X509_REQ_get1_email(X509_REQ *x);
568void X509_email_free(STACK *sk);
569
570
571/* BEGIN ERROR CODES */
572/* The following lines are auto generated by the script mkerr.pl. Any changes
573 * made after this point may be overwritten when the script is next run.
574 */
575void ERR_load_X509V3_strings(void);
576
577/* Error codes for the X509V3 functions. */
578
579/* Function codes. */
580#define X509V3_F_COPY_EMAIL 122
581#define X509V3_F_COPY_ISSUER 123
582#define X509V3_F_DO_EXT_CONF 124
583#define X509V3_F_DO_EXT_I2D 135
584#define X509V3_F_HEX_TO_STRING 111
585#define X509V3_F_I2S_ASN1_ENUMERATED 121
586#define X509V3_F_I2S_ASN1_IA5STRING 142
587#define X509V3_F_I2S_ASN1_INTEGER 120
588#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138
589#define X509V3_F_NOTICE_SECTION 132
590#define X509V3_F_NREF_NOS 133
591#define X509V3_F_POLICY_SECTION 131
592#define X509V3_F_R2I_CERTPOL 130
593#define X509V3_F_R2I_PCI 142
594#define X509V3_F_S2I_ASN1_IA5STRING 100
595#define X509V3_F_S2I_ASN1_INTEGER 108
596#define X509V3_F_S2I_ASN1_OCTET_STRING 112
597#define X509V3_F_S2I_ASN1_SKEY_ID 114
598#define X509V3_F_S2I_S2I_SKEY_ID 115
599#define X509V3_F_STRING_TO_HEX 113
600#define X509V3_F_SXNET_ADD_ASC 125
601#define X509V3_F_SXNET_ADD_ID_INTEGER 126
602#define X509V3_F_SXNET_ADD_ID_ULONG 127
603#define X509V3_F_SXNET_GET_ID_ASC 128
604#define X509V3_F_SXNET_GET_ID_ULONG 129
605#define X509V3_F_V2I_ACCESS_DESCRIPTION 139
606#define X509V3_F_V2I_ASN1_BIT_STRING 101
607#define X509V3_F_V2I_AUTHORITY_KEYID 119
608#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
609#define X509V3_F_V2I_CRLD 134
610#define X509V3_F_V2I_EXT_KU 103
611#define X509V3_F_V2I_GENERAL_NAME 117
612#define X509V3_F_V2I_GENERAL_NAMES 118
613#define X509V3_F_V3_GENERIC_EXTENSION 116
614#define X509V3_F_X509V3_ADD_I2D 140
615#define X509V3_F_X509V3_ADD_VALUE 105
616#define X509V3_F_X509V3_EXT_ADD 104
617#define X509V3_F_X509V3_EXT_ADD_ALIAS 106
618#define X509V3_F_X509V3_EXT_CONF 107
619#define X509V3_F_X509V3_EXT_I2D 136
620#define X509V3_F_X509V3_GET_VALUE_BOOL 110
621#define X509V3_F_X509V3_PARSE_LIST 109
622#define X509V3_F_X509_PURPOSE_ADD 137
623#define X509V3_F_X509_PURPOSE_SET 141
624
625/* Reason codes. */
626#define X509V3_R_BAD_IP_ADDRESS 118
627#define X509V3_R_BAD_OBJECT 119
628#define X509V3_R_BN_DEC2BN_ERROR 100
629#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101
630#define X509V3_R_DUPLICATE_ZONE_ID 133
631#define X509V3_R_ERROR_CONVERTING_ZONE 131
632#define X509V3_R_ERROR_CREATING_EXTENSION 144
633#define X509V3_R_ERROR_IN_EXTENSION 128
634#define X509V3_R_EXPECTED_A_SECTION_NAME 137
635#define X509V3_R_EXTENSION_EXISTS 145
636#define X509V3_R_EXTENSION_NAME_ERROR 115
637#define X509V3_R_EXTENSION_NOT_FOUND 102
638#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103
639#define X509V3_R_EXTENSION_VALUE_ERROR 116
640#define X509V3_R_ILLEGAL_HEX_DIGIT 113
641#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 153
642#define X509V3_R_INVALID_BOOLEAN_STRING 104
643#define X509V3_R_INVALID_EXTENSION_STRING 105
644#define X509V3_R_INVALID_NAME 106
645#define X509V3_R_INVALID_NULL_ARGUMENT 107
646#define X509V3_R_INVALID_NULL_NAME 108
647#define X509V3_R_INVALID_NULL_VALUE 109
648#define X509V3_R_INVALID_NUMBER 140
649#define X509V3_R_INVALID_NUMBERS 141
650#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110
651#define X509V3_R_INVALID_OPTION 138
652#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
653#define X509V3_R_INVALID_PROXY_POLICY_IDENTIFIER 147
654#define X509V3_R_INVALID_PROXY_POLICY_SETTING 151
655#define X509V3_R_INVALID_PURPOSE 146
656#define X509V3_R_INVALID_SECTION 135
657#define X509V3_R_INVALID_SYNTAX 143
658#define X509V3_R_ISSUER_DECODE_ERROR 126
659#define X509V3_R_MISSING_VALUE 124
660#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142
661#define X509V3_R_NO_CONFIG_DATABASE 136
662#define X509V3_R_NO_ISSUER_CERTIFICATE 121
663#define X509V3_R_NO_ISSUER_DETAILS 127
664#define X509V3_R_NO_POLICY_IDENTIFIER 139
665#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 148
666#define X509V3_R_NO_PUBLIC_KEY 114
667#define X509V3_R_NO_SUBJECT_DETAILS 125
668#define X509V3_R_ODD_NUMBER_OF_DIGITS 112
669#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED 149
670#define X509V3_R_POLICY_PATH_LENGTH 152
671#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED 150
672#define X509V3_R_POLICY_SYNTAX_NOT 154
673#define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED 155
674#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 156
675#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122
676#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123
677#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111
678#define X509V3_R_UNKNOWN_EXTENSION 129
679#define X509V3_R_UNKNOWN_EXTENSION_NAME 130
680#define X509V3_R_UNKNOWN_OPTION 120
681#define X509V3_R_UNSUPPORTED_OPTION 117
682#define X509V3_R_USER_TOO_LONG 132
683
684#ifdef __cplusplus
685}
686#endif
687#endif