├── .clang-format ├── .editorconfig ├── .gitignore ├── .vscode ├── extensions.json └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin └── main │ ├── unleashed │ ├── array.gsc │ ├── http.gsc │ ├── json.gsc │ ├── spec.gsc │ └── tests │ │ ├── array_spec.gsc │ │ └── suite.gsc │ └── xiceops_00.iwd ├── build_elf.sh ├── build_win32.cmd ├── dis ├── array.txt ├── badwords.txt ├── botnames.txt ├── cvar_flagchanger.c ├── hashgen.c ├── mac_authorize.c ├── mac_authorize.h ├── md5.c ├── other.c ├── plugin_handler.c ├── plugin_handler.h └── tcprcon.txt ├── lib ├── libtomcrypt_linux.a ├── libtomcrypt_mach.a ├── libtomcrypt_win32.a ├── libtommath_linux.a ├── libtommath_mach.a └── libtommath_win32.a ├── lib_tomcrypt ├── ciphers │ ├── aes │ │ ├── aes.c │ │ └── aes_tab.c │ ├── anubis.c │ ├── blowfish.c │ ├── cast5.c │ ├── des.c │ ├── kasumi.c │ ├── khazad.c │ ├── kseed.c │ ├── multi2.c │ ├── noekeon.c │ ├── rc2.c │ ├── rc5.c │ ├── rc6.c │ ├── safer │ │ ├── safer.c │ │ ├── safer_tab.c │ │ └── saferp.c │ ├── skipjack.c │ ├── twofish │ │ ├── twofish.c │ │ └── twofish_tab.c │ └── xtea.c ├── encauth │ ├── ccm │ │ ├── ccm_memory.c │ │ └── ccm_test.c │ ├── eax │ │ ├── eax_addheader.c │ │ ├── eax_decrypt.c │ │ ├── eax_decrypt_verify_memory.c │ │ ├── eax_done.c │ │ ├── eax_encrypt.c │ │ ├── eax_encrypt_authenticate_memory.c │ │ ├── eax_init.c │ │ └── eax_test.c │ ├── gcm │ │ ├── gcm_add_aad.c │ │ ├── gcm_add_iv.c │ │ ├── gcm_done.c │ │ ├── gcm_gf_mult.c │ │ ├── gcm_init.c │ │ ├── gcm_memory.c │ │ ├── gcm_mult_h.c │ │ ├── gcm_process.c │ │ ├── gcm_reset.c │ │ └── gcm_test.c │ └── ocb │ │ ├── ocb_decrypt.c │ │ ├── ocb_decrypt_verify_memory.c │ │ ├── ocb_done_decrypt.c │ │ ├── ocb_done_encrypt.c │ │ ├── ocb_encrypt.c │ │ ├── ocb_encrypt_authenticate_memory.c │ │ ├── ocb_init.c │ │ ├── ocb_ntz.c │ │ ├── ocb_shift_xor.c │ │ ├── ocb_test.c │ │ └── s_ocb_done.c ├── hashes │ ├── chc │ │ └── chc.c │ ├── helper │ │ ├── hash_file.c │ │ ├── hash_filehandle.c │ │ ├── hash_memory.c │ │ └── hash_memory_multi.c │ ├── md2.c │ ├── md4.c │ ├── md5.c │ ├── rmd128.c │ ├── rmd160.c │ ├── rmd256.c │ ├── rmd320.c │ ├── sha1.c │ ├── sha2 │ │ ├── sha224.c │ │ ├── sha256.c │ │ ├── sha384.c │ │ └── sha512.c │ ├── tiger.c │ └── whirl │ │ ├── whirl.c │ │ └── whirltab.c ├── headers │ ├── tomcrypt.h │ ├── tomcrypt_argchk.h │ ├── tomcrypt_cfg.h │ ├── tomcrypt_cipher.h │ ├── tomcrypt_custom.h │ ├── tomcrypt_hash.h │ ├── tomcrypt_mac.h │ ├── tomcrypt_macros.h │ ├── tomcrypt_math.h │ ├── tomcrypt_misc.h │ ├── tomcrypt_pk.h │ ├── tomcrypt_pkcs.h │ └── tomcrypt_prng.h ├── mac │ ├── f9 │ │ ├── f9_done.c │ │ ├── f9_file.c │ │ ├── f9_init.c │ │ ├── f9_memory.c │ │ ├── f9_memory_multi.c │ │ ├── f9_process.c │ │ └── f9_test.c │ ├── hmac │ │ ├── hmac_done.c │ │ ├── hmac_file.c │ │ ├── hmac_init.c │ │ ├── hmac_memory.c │ │ ├── hmac_memory_multi.c │ │ ├── hmac_process.c │ │ └── hmac_test.c │ ├── omac │ │ ├── omac_done.c │ │ ├── omac_file.c │ │ ├── omac_init.c │ │ ├── omac_memory.c │ │ ├── omac_memory_multi.c │ │ ├── omac_process.c │ │ └── omac_test.c │ ├── pelican │ │ ├── pelican.c │ │ ├── pelican_memory.c │ │ └── pelican_test.c │ ├── pmac │ │ ├── pmac_done.c │ │ ├── pmac_file.c │ │ ├── pmac_init.c │ │ ├── pmac_memory.c │ │ ├── pmac_memory_multi.c │ │ ├── pmac_ntz.c │ │ ├── pmac_process.c │ │ ├── pmac_shift_xor.c │ │ └── pmac_test.c │ └── xcbc │ │ ├── xcbc_done.c │ │ ├── xcbc_file.c │ │ ├── xcbc_init.c │ │ ├── xcbc_memory.c │ │ ├── xcbc_memory_multi.c │ │ ├── xcbc_process.c │ │ └── xcbc_test.c ├── main.h ├── math │ ├── fp │ │ └── ltc_ecc_fp_mulmod.c │ ├── gmp_desc.c │ ├── ltm_desc.c │ ├── multi.c │ ├── rand_prime.c │ ├── tfm_desc.c │ └── tommath │ │ ├── LICENSE │ │ ├── bn.tex │ │ ├── bn_error.c │ │ ├── bn_fast_mp_invmod.c │ │ ├── bn_fast_mp_montgomery_reduce.c │ │ ├── bn_fast_s_mp_mul_digs.c │ │ ├── bn_fast_s_mp_mul_high_digs.c │ │ ├── bn_fast_s_mp_sqr.c │ │ ├── bn_mp_2expt.c │ │ ├── bn_mp_abs.c │ │ ├── bn_mp_add.c │ │ ├── bn_mp_add_d.c │ │ ├── bn_mp_addmod.c │ │ ├── bn_mp_and.c │ │ ├── bn_mp_clamp.c │ │ ├── bn_mp_clear.c │ │ ├── bn_mp_clear_multi.c │ │ ├── bn_mp_cmp.c │ │ ├── bn_mp_cmp_d.c │ │ ├── bn_mp_cmp_mag.c │ │ ├── bn_mp_cnt_lsb.c │ │ ├── bn_mp_copy.c │ │ ├── bn_mp_count_bits.c │ │ ├── bn_mp_div.c │ │ ├── bn_mp_div_2.c │ │ ├── bn_mp_div_2d.c │ │ ├── bn_mp_div_3.c │ │ ├── bn_mp_div_d.c │ │ ├── bn_mp_dr_is_modulus.c │ │ ├── bn_mp_dr_reduce.c │ │ ├── bn_mp_dr_setup.c │ │ ├── bn_mp_exch.c │ │ ├── bn_mp_expt_d.c │ │ ├── bn_mp_exptmod.c │ │ ├── bn_mp_exptmod_fast.c │ │ ├── bn_mp_exteuclid.c │ │ ├── bn_mp_fread.c │ │ ├── bn_mp_fwrite.c │ │ ├── bn_mp_gcd.c │ │ ├── bn_mp_get_int.c │ │ ├── bn_mp_grow.c │ │ ├── bn_mp_init.c │ │ ├── bn_mp_init_copy.c │ │ ├── bn_mp_init_multi.c │ │ ├── bn_mp_init_set.c │ │ ├── bn_mp_init_set_int.c │ │ ├── bn_mp_init_size.c │ │ ├── bn_mp_invmod.c │ │ ├── bn_mp_invmod_slow.c │ │ ├── bn_mp_is_square.c │ │ ├── bn_mp_jacobi.c │ │ ├── bn_mp_karatsuba_mul.c │ │ ├── bn_mp_karatsuba_sqr.c │ │ ├── bn_mp_lcm.c │ │ ├── bn_mp_lshd.c │ │ ├── bn_mp_mod.c │ │ ├── bn_mp_mod_2d.c │ │ ├── bn_mp_mod_d.c │ │ ├── bn_mp_montgomery_calc_normalization.c │ │ ├── bn_mp_montgomery_reduce.c │ │ ├── bn_mp_montgomery_setup.c │ │ ├── bn_mp_mul.c │ │ ├── bn_mp_mul_2.c │ │ ├── bn_mp_mul_2d.c │ │ ├── bn_mp_mul_d.c │ │ ├── bn_mp_mulmod.c │ │ ├── bn_mp_n_root.c │ │ ├── bn_mp_neg.c │ │ ├── bn_mp_or.c │ │ ├── bn_mp_prime_fermat.c │ │ ├── bn_mp_prime_is_divisible.c │ │ ├── bn_mp_prime_is_prime.c │ │ ├── bn_mp_prime_miller_rabin.c │ │ ├── bn_mp_prime_next_prime.c │ │ ├── bn_mp_prime_rabin_miller_trials.c │ │ ├── bn_mp_prime_random_ex.c │ │ ├── bn_mp_radix_size.c │ │ ├── bn_mp_radix_smap.c │ │ ├── bn_mp_rand.c │ │ ├── bn_mp_read_radix.c │ │ ├── bn_mp_read_signed_bin.c │ │ ├── bn_mp_read_unsigned_bin.c │ │ ├── bn_mp_reduce.c │ │ ├── bn_mp_reduce_2k.c │ │ ├── bn_mp_reduce_2k_l.c │ │ ├── bn_mp_reduce_2k_setup.c │ │ ├── bn_mp_reduce_2k_setup_l.c │ │ ├── bn_mp_reduce_is_2k.c │ │ ├── bn_mp_reduce_is_2k_l.c │ │ ├── bn_mp_reduce_setup.c │ │ ├── bn_mp_rshd.c │ │ ├── bn_mp_set.c │ │ ├── bn_mp_set_int.c │ │ ├── bn_mp_shrink.c │ │ ├── bn_mp_signed_bin_size.c │ │ ├── bn_mp_sqr.c │ │ ├── bn_mp_sqrmod.c │ │ ├── bn_mp_sqrt.c │ │ ├── bn_mp_sub.c │ │ ├── bn_mp_sub_d.c │ │ ├── bn_mp_submod.c │ │ ├── bn_mp_to_signed_bin.c │ │ ├── bn_mp_to_signed_bin_n.c │ │ ├── bn_mp_to_unsigned_bin.c │ │ ├── bn_mp_to_unsigned_bin_n.c │ │ ├── bn_mp_toom_mul.c │ │ ├── bn_mp_toom_sqr.c │ │ ├── bn_mp_toradix.c │ │ ├── bn_mp_toradix_n.c │ │ ├── bn_mp_unsigned_bin_size.c │ │ ├── bn_mp_xor.c │ │ ├── bn_mp_zero.c │ │ ├── bn_prime_tab.c │ │ ├── bn_reverse.c │ │ ├── bn_s_mp_add.c │ │ ├── bn_s_mp_exptmod.c │ │ ├── bn_s_mp_mul_digs.c │ │ ├── bn_s_mp_mul_high_digs.c │ │ ├── bn_s_mp_sqr.c │ │ ├── bn_s_mp_sub.c │ │ ├── bncore.c │ │ ├── booker.pl │ │ ├── callgraph.txt │ │ ├── changes.txt │ │ ├── demo │ │ ├── demo.c │ │ └── timing.c │ │ ├── dep.pl │ │ ├── etc │ │ ├── 2kprime.1 │ │ ├── 2kprime.c │ │ ├── drprime.c │ │ ├── drprimes.28 │ │ ├── drprimes.txt │ │ ├── makefile │ │ ├── makefile.icc │ │ ├── makefile.msvc │ │ ├── mersenne.c │ │ ├── mont.c │ │ ├── pprime.c │ │ ├── prime.1024 │ │ ├── prime.512 │ │ ├── timer.asm │ │ └── tune.c │ │ ├── gen.pl │ │ ├── libtommath.a │ │ ├── libtommath.dsp │ │ ├── libtommath_VS2005.sln │ │ ├── libtommath_VS2005.vcproj │ │ ├── libtommath_VS2008.sln │ │ ├── libtommath_VS2008.vcproj │ │ ├── logs │ │ ├── README │ │ ├── addsub.png │ │ ├── expt.png │ │ ├── graphs.dem │ │ ├── index.html │ │ ├── invmod.png │ │ └── mult.png │ │ ├── makefile │ │ ├── makefile.bcc │ │ ├── makefile.cygwin_dll │ │ ├── makefile.icc │ │ ├── makefile.msvc │ │ ├── makefile.shared │ │ ├── mess.sh │ │ ├── mtest │ │ ├── logtab.h │ │ ├── mpi-config.h │ │ ├── mpi-types.h │ │ ├── mpi.c │ │ ├── mpi.h │ │ └── mtest.c │ │ ├── pics │ │ ├── design_process.sxd │ │ ├── design_process.tif │ │ ├── expt_state.sxd │ │ ├── expt_state.tif │ │ ├── makefile │ │ ├── primality.tif │ │ ├── radix.sxd │ │ ├── sliding_window.sxd │ │ └── sliding_window.tif │ │ ├── poster.out │ │ ├── poster.tex │ │ ├── pre_gen │ │ └── mpi.c │ │ ├── pretty.build │ │ ├── tombc │ │ └── grammar.txt │ │ ├── tommath.h │ │ ├── tommath.out │ │ ├── tommath.src │ │ ├── tommath_class.h │ │ └── tommath_superclass.h ├── misc │ ├── base64 │ │ ├── base64_decode.c │ │ └── base64_encode.c │ ├── burn_stack.c │ ├── crypt │ │ ├── crypt.c │ │ ├── crypt_argchk.c │ │ ├── crypt_cipher_descriptor.c │ │ ├── crypt_cipher_is_valid.c │ │ ├── crypt_find_cipher.c │ │ ├── crypt_find_cipher_any.c │ │ ├── crypt_find_cipher_id.c │ │ ├── crypt_find_hash.c │ │ ├── crypt_find_hash_any.c │ │ ├── crypt_find_hash_id.c │ │ ├── crypt_find_hash_oid.c │ │ ├── crypt_find_prng.c │ │ ├── crypt_fsa.c │ │ ├── crypt_hash_descriptor.c │ │ ├── crypt_hash_is_valid.c │ │ ├── crypt_ltc_mp_descriptor.c │ │ ├── crypt_prng_descriptor.c │ │ ├── crypt_prng_is_valid.c │ │ ├── crypt_register_cipher.c │ │ ├── crypt_register_hash.c │ │ ├── crypt_register_prng.c │ │ ├── crypt_unregister_cipher.c │ │ ├── crypt_unregister_hash.c │ │ └── crypt_unregister_prng.c │ ├── error_to_string.c │ ├── pkcs5 │ │ ├── pkcs_5_1.c │ │ └── pkcs_5_2.c │ └── zeromem.c ├── modes │ ├── cbc │ │ ├── cbc_decrypt.c │ │ ├── cbc_done.c │ │ ├── cbc_encrypt.c │ │ ├── cbc_getiv.c │ │ ├── cbc_setiv.c │ │ └── cbc_start.c │ ├── cfb │ │ ├── cfb_decrypt.c │ │ ├── cfb_done.c │ │ ├── cfb_encrypt.c │ │ ├── cfb_getiv.c │ │ ├── cfb_setiv.c │ │ └── cfb_start.c │ ├── ctr │ │ ├── ctr_decrypt.c │ │ ├── ctr_done.c │ │ ├── ctr_encrypt.c │ │ ├── ctr_getiv.c │ │ ├── ctr_setiv.c │ │ ├── ctr_start.c │ │ └── ctr_test.c │ ├── ecb │ │ ├── ecb_decrypt.c │ │ ├── ecb_done.c │ │ ├── ecb_encrypt.c │ │ └── ecb_start.c │ ├── f8 │ │ ├── f8_decrypt.c │ │ ├── f8_done.c │ │ ├── f8_encrypt.c │ │ ├── f8_getiv.c │ │ ├── f8_setiv.c │ │ ├── f8_start.c │ │ └── f8_test_mode.c │ ├── lrw │ │ ├── lrw_decrypt.c │ │ ├── lrw_done.c │ │ ├── lrw_encrypt.c │ │ ├── lrw_getiv.c │ │ ├── lrw_process.c │ │ ├── lrw_setiv.c │ │ ├── lrw_start.c │ │ └── lrw_test.c │ ├── ofb │ │ ├── ofb_decrypt.c │ │ ├── ofb_done.c │ │ ├── ofb_encrypt.c │ │ ├── ofb_getiv.c │ │ ├── ofb_setiv.c │ │ └── ofb_start.c │ └── xts │ │ ├── xts_decrypt.c │ │ ├── xts_done.c │ │ ├── xts_encrypt.c │ │ ├── xts_init.c │ │ ├── xts_mult_x.c │ │ └── xts_test.c ├── pk │ ├── asn1 │ │ └── der │ │ │ ├── bit │ │ │ ├── der_decode_bit_string.c │ │ │ ├── der_encode_bit_string.c │ │ │ └── der_length_bit_string.c │ │ │ ├── boolean │ │ │ ├── der_decode_boolean.c │ │ │ ├── der_encode_boolean.c │ │ │ └── der_length_boolean.c │ │ │ ├── choice │ │ │ └── der_decode_choice.c │ │ │ ├── ia5 │ │ │ ├── der_decode_ia5_string.c │ │ │ ├── der_encode_ia5_string.c │ │ │ └── der_length_ia5_string.c │ │ │ ├── integer │ │ │ ├── der_decode_integer.c │ │ │ ├── der_encode_integer.c │ │ │ └── der_length_integer.c │ │ │ ├── object_identifier │ │ │ ├── der_decode_object_identifier.c │ │ │ ├── der_encode_object_identifier.c │ │ │ └── der_length_object_identifier.c │ │ │ ├── octet │ │ │ ├── der_decode_octet_string.c │ │ │ ├── der_encode_octet_string.c │ │ │ └── der_length_octet_string.c │ │ │ ├── printable_string │ │ │ ├── der_decode_printable_string.c │ │ │ ├── der_encode_printable_string.c │ │ │ └── der_length_printable_string.c │ │ │ ├── sequence │ │ │ ├── der_decode_sequence_ex.c │ │ │ ├── der_decode_sequence_flexi.c │ │ │ ├── der_decode_sequence_multi.c │ │ │ ├── der_encode_sequence_ex.c │ │ │ ├── der_encode_sequence_multi.c │ │ │ ├── der_length_sequence.c │ │ │ └── der_sequence_free.c │ │ │ ├── set │ │ │ ├── der_encode_set.c │ │ │ └── der_encode_setof.c │ │ │ ├── short_integer │ │ │ ├── der_decode_short_integer.c │ │ │ ├── der_encode_short_integer.c │ │ │ └── der_length_short_integer.c │ │ │ ├── utctime │ │ │ ├── der_decode_utctime.c │ │ │ ├── der_encode_utctime.c │ │ │ └── der_length_utctime.c │ │ │ └── utf8 │ │ │ ├── der_decode_utf8_string.c │ │ │ ├── der_encode_utf8_string.c │ │ │ └── der_length_utf8_string.c │ ├── dsa │ │ ├── dsa_decrypt_key.c │ │ ├── dsa_encrypt_key.c │ │ ├── dsa_export.c │ │ ├── dsa_free.c │ │ ├── dsa_import.c │ │ ├── dsa_make_key.c │ │ ├── dsa_shared_secret.c │ │ ├── dsa_sign_hash.c │ │ ├── dsa_verify_hash.c │ │ └── dsa_verify_key.c │ ├── ecc │ │ ├── ecc.c │ │ ├── ecc_ansi_x963_export.c │ │ ├── ecc_ansi_x963_import.c │ │ ├── ecc_decrypt_key.c │ │ ├── ecc_encrypt_key.c │ │ ├── ecc_export.c │ │ ├── ecc_free.c │ │ ├── ecc_get_size.c │ │ ├── ecc_import.c │ │ ├── ecc_make_key.c │ │ ├── ecc_shared_secret.c │ │ ├── ecc_sign_hash.c │ │ ├── ecc_sizes.c │ │ ├── ecc_test.c │ │ ├── ecc_verify_hash.c │ │ ├── ltc_ecc_is_valid_idx.c │ │ ├── ltc_ecc_map.c │ │ ├── ltc_ecc_mul2add.c │ │ ├── ltc_ecc_mulmod.c │ │ ├── ltc_ecc_mulmod_timing.c │ │ ├── ltc_ecc_points.c │ │ ├── ltc_ecc_projective_add_point.c │ │ └── ltc_ecc_projective_dbl_point.c │ ├── katja │ │ ├── katja_decrypt_key.c │ │ ├── katja_encrypt_key.c │ │ ├── katja_export.c │ │ ├── katja_exptmod.c │ │ ├── katja_free.c │ │ ├── katja_import.c │ │ └── katja_make_key.c │ ├── pkcs1 │ │ ├── pkcs_1_i2osp.c │ │ ├── pkcs_1_mgf1.c │ │ ├── pkcs_1_oaep_decode.c │ │ ├── pkcs_1_oaep_encode.c │ │ ├── pkcs_1_os2ip.c │ │ ├── pkcs_1_pss_decode.c │ │ ├── pkcs_1_pss_encode.c │ │ ├── pkcs_1_v1_5_decode.c │ │ └── pkcs_1_v1_5_encode.c │ └── rsa │ │ ├── rsa_decrypt_key.c │ │ ├── rsa_encrypt_key.c │ │ ├── rsa_export.c │ │ ├── rsa_exptmod.c │ │ ├── rsa_free.c │ │ ├── rsa_import.c │ │ ├── rsa_make_key.c │ │ ├── rsa_sign_hash.c │ │ └── rsa_verify_hash.c └── prngs │ ├── fortuna.c │ ├── rc4.c │ ├── rng_get_bytes.c │ ├── rng_make_prng.c │ ├── sober128.c │ ├── sober128tab.c │ ├── sprng.c │ └── yarrow.c ├── linkerscript.ld ├── linkerscript_win32.ld ├── pbsv_exec ├── makedll32 └── pbsv.c ├── plugins ├── antikoncept │ ├── antikoncept.so │ ├── antikoncept_plugin.c │ ├── compile.cmd │ ├── compile.sh │ ├── makedll.cmd │ └── makedll32 ├── antinamechange │ ├── antinamespoof_plugin.c │ ├── makedll32 │ └── makedll_win32.cmd ├── antinamesteal │ ├── antinamesteal.c │ ├── makedll32 │ └── makedll_win32 ├── antispam │ ├── antispam_plugin.c │ ├── makedll32 │ └── makedll_win32.cmd ├── callback_declarations.h ├── censor │ ├── censor.c │ ├── censor.h │ ├── censor_plugin.c │ ├── makedll32 │ └── makedll_win32.cmd ├── clan-tag-protection │ ├── clanP.c │ ├── makedll32 │ └── makedll_win32 ├── cpptest │ ├── cpptest.so │ ├── cpptest_plugin.cpp │ └── makedll32 ├── declarations.h ├── function_declarations.h ├── pinc.h ├── plugin_declarations.h └── readme.txt ├── src ├── cmd.c ├── cmd.h ├── cmd_completion.c ├── cmd_completion.h ├── cmd_hooks.asm ├── common.c ├── common_io.c ├── common_logprint.c ├── cvar.c ├── cvar.h ├── entity.h ├── filesystem.c ├── filesystem.h ├── filesystem_hooks.asm ├── functions │ ├── client.c │ ├── client.h │ ├── functions.h │ ├── http.c │ ├── http.h │ ├── types.c │ └── types.h ├── g_entity.c ├── g_hud.c ├── g_hud.h ├── g_shared.h ├── g_sv_client.c ├── g_sv_cmds.c ├── g_sv_hooks.asm ├── g_sv_main.c ├── g_sv_messages.c ├── g_sv_movement.c ├── g_sv_shared.h ├── g_team.c ├── hl2rcon.c ├── hl2rcon.h ├── httpftp.c ├── httpftp.h ├── httprequest.c ├── httprequest.h ├── huffman.c ├── huffman.h ├── math_vector.h ├── maxmind_geoip.c ├── maxmind_geoip.h ├── misc.c ├── misc.h ├── misc_hooks.asm ├── msg.c ├── msg.h ├── msg_hooks.asm ├── murmurhash1.c ├── murmurhash1.h ├── net_game.c ├── net_game.h ├── net_game_conf.h ├── net_reliabletransport.c ├── net_reliabletransport.h ├── netchan.c ├── netchan.h ├── nvconfig.c ├── nvconfig.h ├── objfile_parser.h ├── player.h ├── plugin_com.c ├── plugin_crypto.c ├── plugin_crypto.h ├── plugin_events.h ├── plugin_exports.c ├── plugin_handler.c ├── plugin_handler.h ├── plugin_internal.c ├── pluginexports.asm ├── punkbuster.h ├── q_math.h ├── q_parse.c ├── q_platform.h ├── q_shared.h ├── qcommon.h ├── qcommon_hooks.asm ├── qcommon_io.h ├── qcommon_logprint.h ├── qcommon_mem.c ├── qcommon_mem.h ├── qcommon_parsecmdline.c ├── qcommon_parsecmdline.h ├── qshared.c ├── scr_vm.h ├── scr_vm_callbacks.c ├── scr_vm_classfunc.c ├── scr_vm_cmd.c ├── scr_vm_fs.c ├── scr_vm_functions.c ├── scr_vm_functions.h ├── scr_vm_hooks.asm ├── scr_vm_main.c ├── sec_common.c ├── sec_common.h ├── sec_crypto.c ├── sec_crypto.h ├── sec_init.c ├── sec_init.h ├── sec_main.c ├── sec_main.h ├── sec_sign.c ├── sec_sign.h ├── sec_update.c ├── sec_update.h ├── server.h ├── server_hooks.asm ├── sha.h ├── sha1.c ├── sha256.c ├── sha256.h ├── sv_auth.c ├── sv_auth.h ├── sv_banlist.c ├── sv_client.c ├── sv_cmds.c ├── sv_demo.c ├── sv_game.c ├── sv_ingameadmin.c ├── sv_main.c ├── sv_net_chan.c ├── sv_punkbuster.c ├── sv_snapshot.c ├── sv_world.c ├── sys_cod4defs.h ├── sys_cod4loader.c ├── sys_cod4loader.h ├── sys_main.c ├── sys_main.h ├── sys_net.c ├── sys_net.h ├── sys_patch.c ├── sys_patch.h ├── sys_thread.c ├── sys_thread.h ├── trace.h ├── trace_hooks.asm ├── unix │ ├── elf32_parser.c │ ├── sys_cod4linker_linux.c │ ├── sys_cod4linker_mach.c │ ├── sys_con_tty.c │ ├── sys_linux.c │ ├── sys_mach.c │ └── sys_unix.c ├── varstorage.c ├── varstorage.h ├── version.h ├── webadmin.c ├── webadmin.h ├── win32 │ ├── pe32_parser.c │ ├── sys_cod4linker_win32.c │ ├── sys_win32.c │ ├── sys_win32.h │ ├── win32_usleep.c │ ├── win32_usleep.h │ ├── win_cod4.rc │ ├── win_cod4.res │ └── win_syscon.c ├── xassets.c ├── xassets.h ├── xassets │ └── xmodel.h ├── xassets_hooks.asm ├── yyparse.c └── zlib │ ├── crc32.c │ ├── crc32.h │ ├── unzip.c │ ├── unzip.h │ └── zconf.h ├── tools ├── asm_objdump_converter.c ├── asm_objdump_converter.cmd ├── asm_objdump_converter.sh ├── converted_dump.asm ├── make_gcc_compatible_asm.c ├── make_gcc_compatible_asm.cmd └── make_gcc_compatible_asm.sh └── version_make_progress.sh /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 2 3 | PointerAlignment: Left 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #ignore thumbnails created by windows 3 | Thumbs.db 4 | #Ignore files build by Visual Studio 5 | *.obj 6 | *.pdb 7 | *.user 8 | *.aps 9 | *.pch 10 | *.vspscc 11 | *_i.c 12 | *_p.c 13 | *.ncb 14 | *.suo 15 | *.tlb 16 | *.tlh 17 | *.bak 18 | *.cache 19 | *.ilk 20 | *.log 21 | *.dll 22 | *.lib 23 | *.sbr 24 | *.o 25 | *.exe 26 | plugins/*.a 27 | 28 | bin/cod4u_lnx 29 | bin/cod4u_mach 30 | bin/cod4u_win32.exe 31 | bin/cod4u_win32.def 32 | 33 | build_elf_official.sh 34 | build_win32_official.cmd 35 | 36 | assets/ 37 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "EditorConfig.EditorConfig", 4 | "ms-vscode.cpptools", 5 | "13xforever.language-x86-64-assembly" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.defaultFormatter": "ms-vscode.cpptools", 4 | "files.autoSave": "onFocusChange" 5 | } 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [Unreleased] 9 | 10 | ### Added 11 | 12 | - Secondary protocol version to support 1.8 Steam patch 13 | - getProtocol function to retrieve player protocol 14 | - HTTPS support (using libcurl) 15 | - New FPS related functions: getCountedFps (detects lag spikes properly), isLagging 16 | 17 | ## [1.1.1] \(Hotfix) - 2019-03-09 18 | 19 | ### Fixed 20 | 21 | - Fixed JSON module not parsing booleans properly 22 | 23 | ## [1.1.0] - 2019-03-09 24 | 25 | ### Added 26 | 27 | - Full support for HTTP 1.1 28 | - JSON support (GSC module, see unleashed\\json in bin) 29 | - isArray function 30 | - getEpochTime and epochTimeToString 31 | - setSpectatedClient 32 | 33 | ### Changed 34 | 35 | - Project renamed to CoD4: Unleashed 36 | - Updated compile info 37 | - Deprecated httpPostRequest 38 | 39 | ## 1.0 - 2016-08-13 40 | 41 | - Initial release 42 | 43 | [unreleased]: https://github.com/atrX/CoD4-Unleashed-Server/compare/1.1.0...HEAD 44 | [1.1.1]: https://github.com/atrX/CoD4-Unleashed-Server/compare/1.1.0...1.1.1 45 | [1.1.0]: https://github.com/atrX/CoD4-Unleashed-Server/compare/1.0...1.1.0 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoD4: Unleashed - Server 2 | 3 | A custom CoD4 Dedicated Server mainly to improve the functionality and usability of the stock CoD4 Server. 4 | 5 | ## License 6 | 7 | This software is released under the GNU Affero General Public License v3.0 8 | 9 | ## Compiling 10 | 11 | To compile CoD4U-Server you'll need the following installed: 12 | 13 | - gcc (Linux) or mingw32 (Windows) 14 | - nasm 15 | - libcurl 16 | 17 | Debian/Ubuntu 32-bit: 18 | 19 | ```bash 20 | sudo apt-get install nasm build-essential libcurl4-openssl-dev 21 | ``` 22 | 23 | Debian/Ubuntu 64-bit: 24 | 25 | ```bash 26 | sudo dpkg --add-architecture i386 27 | sudo apt-get update 28 | sudo apt-get install nasm:i386 build-essential gcc-multilib g++-multilib libcurl4-openssl-dev:i386 29 | ``` 30 | 31 | Arch Linux 32-bit: 32 | 33 | ```bash 34 | sudo pacman -S base-devel nasm curl 35 | ``` 36 | 37 | Compiling is as simple as running the appropriate build script. E.g. for Linux: `./build_elf.sh`. 38 | 39 | ## Dependencies 40 | 41 | To run this software on Windows, you'll need to install the following dependencies separately: 42 | 43 | - OpenSSL 32-bit: https://slproweb.com/products/Win32OpenSSL.html (Win32 OpenSSL v1.1.1g or later) 44 | 45 | ## Documentation 46 | 47 | All included functions are documented in our official Scripting API at https://docs.raid-gaming.net/ 48 | 49 | ## Support 50 | 51 | If you have a question, feel free to ask over at https://raid-gaming.net/forum/18-call-of-duty-4-unleashed/ 52 | -------------------------------------------------------------------------------- /bin/main/unleashed/spec.gsc: -------------------------------------------------------------------------------- 1 | assertThat(statement, msg) { 2 | if (!statement) { 3 | print("^1Fail:^1 " + msg + "\n"); 4 | } 5 | } 6 | 7 | describe(name) { 8 | if (!isDefined(level.testSuite)) { 9 | level.testSuite = []; 10 | } 11 | 12 | spec = []; 13 | spec["name"] = name; 14 | spec["tests"] = []; 15 | 16 | index = level.testSuite.size; 17 | level.testSuite[index] = spec; 18 | 19 | return index; 20 | } 21 | 22 | it(spec, name, callback) { 23 | self test(spec, name, callback); 24 | } 25 | 26 | run() { 27 | assertEx(isDefined(level.testSuite), "no test suite has been set up"); 28 | 29 | if (!isDefined(level.testSuite)) { 30 | print("^1Test suite has not been set up correctly\n"); 31 | return; 32 | } 33 | 34 | print("^2Running unit tests\n"); 35 | for (i = 0; i < level.testSuite.size; i++) { 36 | spec = level.testSuite[i]; 37 | print("^2" + spec["name"] + "\n"); 38 | for (j = 0; j < spec["tests"].size; j++) { 39 | testCase = spec["tests"][j]; 40 | print("--> " + testCase["name"] + "\n"); 41 | [[testCase["function"]]](); 42 | } 43 | } 44 | } 45 | 46 | test(spec, name, callback) { 47 | assertEx(isDefined(level.testSuite), "no test suite has been set up"); 48 | 49 | testCase = []; 50 | testCase["name"] = name; 51 | testCase["function"] = callback; 52 | 53 | index = level.testSuite[spec]["tests"].size; 54 | level.testSuite[spec]["tests"][index] = testCase; 55 | } 56 | -------------------------------------------------------------------------------- /bin/main/unleashed/tests/suite.gsc: -------------------------------------------------------------------------------- 1 | main() { 2 | unleashed\tests\array_spec::main(); 3 | 4 | unleashed\spec::run(); 5 | } 6 | -------------------------------------------------------------------------------- /bin/main/xiceops_00.iwd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/bin/main/xiceops_00.iwd -------------------------------------------------------------------------------- /dis/array.txt: -------------------------------------------------------------------------------- 1 | { name, 0, 0, 0x808b5b2, 0x808b5d6 }, 2 | { sessionteam, 0, 0, 0x808b764, 0x808b3da }, 3 | { sessionstate, 0, 0, 0x808b508, 0x808b376 }, 4 | { maxhealth, 12264, 12264, 0x808b1c8, NULL }, 5 | { score, 12152, 12152, 0x808b73e, NULL }, 6 | { deaths, 12156, 12156, NULL, NULL }, 7 | { statusicon, 0, 0, 0x808b718, 0x808b672 }, 8 | { headicon, 0, 0, 0x808b6ce, 0x808b5e6 }, 9 | { headiconteam, 0, 0, 0x808b43e, 0x808b2fa }, 10 | { kills, 12160, 12160, NULL, NULL }, 11 | { assists, 12164, 12164, NULL, NULL }, 12 | { hasradar, 12664, 12664, NULL, NULL }, 13 | { spectatorclient, 12136, 12136, 0x808b2c2, NULL }, 14 | { killcamentity, 12140, 12140, 0x808b288, NULL }, 15 | { archivetime, 12148, 12148, 0x808b258, 0x808b23c }, 16 | { psoffsettime, 12400, 12400, 0x808b1aa, 0x808b194 }, 17 | { pers, 12168, 12168, 0x808b5b2, NULL }, -------------------------------------------------------------------------------- /dis/badwords.txt: -------------------------------------------------------------------------------- 1 | shit 2 | fuck 3 | fck 4 | #fak 5 | fack 6 | #faker 7 | kanker 8 | fick 9 | pusy 10 | pusies 11 | ashole 12 | dick 13 | idiot 14 | prick 15 | moron 16 | cunt 17 | tard 18 | kurw 19 | bitch 20 | btch 21 | biatch 22 | niger 23 | pizd 24 | ciota 25 | cioto 26 | cioty 27 | dup 28 | jeba 29 | jebn 30 | pierdo 31 | pierdal 32 | kurv 33 | kurac 34 | kurc 35 | #ass 36 | #ciot 37 | #cazz 38 | -------------------------------------------------------------------------------- /dis/botnames.txt: -------------------------------------------------------------------------------- 1 | Sarge 2 | Hossmen 3 | Daemia 4 | Grunt 5 | Major 6 | Orbb 7 | Myst 8 | Visor 9 | Stripe 10 | Doom 11 | Lucy 12 | Gorre 13 | Cadavre -------------------------------------------------------------------------------- /dis/cvar_flagchanger.c: -------------------------------------------------------------------------------- 1 | void Cvar_DisplayFlags_f(); 2 | void Cvar_SetFlags_f(); 3 | 4 | Cmd_AddCommand ("cvarflags", Cvar_DisplayFlags_f); 5 | Cmd_AddCommand ("cvarsetflags", Cvar_SetFlags_f); 6 | 7 | 8 | void Cvar_DisplayFlags_f() 9 | { 10 | cvar_t *var; 11 | 12 | if(Cmd_Argc() != 2) 13 | { 14 | Com_Printf("Usage: cvarflags \n"); 15 | return; 16 | } 17 | var = Cvar_FindVar(Cmd_Argv(1)); 18 | 19 | if (!var) 20 | return; 21 | 22 | Com_Printf("Flags are: %d\n", var->flags); 23 | } 24 | 25 | 26 | void Cvar_SetFlags_f() 27 | { 28 | cvar_t *var; 29 | short flags; 30 | 31 | if(Cmd_Argc() != 3) 32 | { 33 | Com_Printf("Usage: cvarsetflags \n"); 34 | return; 35 | } 36 | var = Cvar_FindVar(Cmd_Argv(1)); 37 | 38 | if (!var) 39 | return; 40 | 41 | flags = atoi(Cmd_Argv(2)); 42 | var->flags = flags; 43 | Com_Printf("Flags updated\n"); 44 | } -------------------------------------------------------------------------------- /dis/hashgen.c: -------------------------------------------------------------------------------- 1 | #include "sha256.c" 2 | #include "md5.c" 3 | 4 | char* Com_CreateHash(const char* string){ 5 | 6 | MD5_CTX md5; 7 | int i; 8 | int r = strlen(string); 9 | static char finalsha[65]; 10 | static char finalmd5[33] = {""}; 11 | unsigned char digestmd5[16] = {""}; 12 | sha256_context ctx; 13 | unsigned char digestsha[32]; 14 | const char *hex = "0123456789abcdef"; 15 | 16 | sha256_starts( &ctx ); //Create SHA-256 of HWID 17 | sha256_update( &ctx, (unsigned char*)string, r ); 18 | sha256_finish( &ctx, digestsha ); 19 | for(i = 0, r=0; i < 32; i++) { 20 | finalsha[r++] = hex[digestsha[i] >> 4]; 21 | finalsha[r++] = hex[digestsha[i] & 0xf]; 22 | } 23 | finalsha[65] = 0x00; 24 | MD5Init(&md5); //Create MD5 of SHA-256 25 | MD5Update(&md5 , (unsigned char*)finalsha, 64); 26 | MD5Final(&md5, digestmd5); 27 | for(i = 0, r=0; i < 16; i++) { 28 | finalmd5[r++] = hex[digestmd5[i] >> 4]; 29 | finalmd5[r++] = hex[digestmd5[i] & 0xf]; 30 | } 31 | finalmd5[33] = 0x00; 32 | return finalmd5; 33 | } -------------------------------------------------------------------------------- /dis/mac_authorize.h: -------------------------------------------------------------------------------- 1 | #define MAC_MIN_UID 10*1000*1000 2 | 3 | typedef struct macDB_s{ 4 | struct macDB_s *next; 5 | char name[33]; 6 | char pass[65]; 7 | char salt[16]; 8 | int uid; 9 | }macDB_t; 10 | 11 | qboolean Mac_LoadDB(); 12 | void Mac_SaveDB(); 13 | void Mac_UnloadDB(); 14 | int Mac_Authorize(char *,char *); 15 | int Mac_Register(char *,char *); -------------------------------------------------------------------------------- /dis/other.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ================= 4 | Search the memory given by buffer pointer for a set of patterns limited by memsize 5 | Special feature: Don't care characters 6 | ================= 7 | */ 8 | //Pattern search function begin 9 | patternseek_t patternseek(unsigned const char *patternarray, int sizeofarray, unsigned const char *buffer, unsigned int memsize) 10 | { 11 | unsigned char c1, c2; 12 | patternseek_t z; 13 | unsigned const char *s1 = patternarray; 14 | unsigned const char *s2 = buffer; 15 | char dontcare=0x66; 16 | int i; 17 | int j; 18 | 19 | 20 | if ( patternarray == NULL || buffer == NULL) { 21 | 22 | z.end = NULL; 23 | z.start = NULL; 24 | return z; 25 | } 26 | 27 | for(i=0, j=0 ; j < memsize; i++, j++){ 28 | 29 | if(i >= sizeofarray){ 30 | z.start = (s2-i+1); 31 | z.end = (s2+1); 32 | return z; 33 | } 34 | 35 | c1 = *s1++; 36 | c2 = *s2++; 37 | 38 | if(c1 == dontcare){ 39 | continue; 40 | } else if (c1 != c2){ 41 | s1 = patternarray; 42 | i=0; 43 | continue; 44 | } 45 | }//end for 46 | z.end = NULL; 47 | z.start = NULL; 48 | return z; 49 | } 50 | -------------------------------------------------------------------------------- /lib/libtomcrypt_linux.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib/libtomcrypt_linux.a -------------------------------------------------------------------------------- /lib/libtomcrypt_mach.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib/libtomcrypt_mach.a -------------------------------------------------------------------------------- /lib/libtomcrypt_win32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib/libtomcrypt_win32.a -------------------------------------------------------------------------------- /lib/libtommath_linux.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib/libtommath_linux.a -------------------------------------------------------------------------------- /lib/libtommath_mach.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib/libtommath_mach.a -------------------------------------------------------------------------------- /lib/libtommath_win32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib/libtommath_win32.a -------------------------------------------------------------------------------- /lib_tomcrypt/encauth/eax/eax_addheader.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | /** 12 | @file eax_addheader.c 13 | EAX implementation, add meta-data, by Tom St Denis 14 | */ 15 | #include "tomcrypt.h" 16 | 17 | #ifdef LTC_EAX_MODE 18 | 19 | /** 20 | add header (metadata) to the stream 21 | @param eax The current EAX state 22 | @param header The header (meta-data) data you wish to add to the state 23 | @param length The length of the header data 24 | @return CRYPT_OK if successful 25 | */ 26 | int eax_addheader(eax_state *eax, const unsigned char *header, 27 | unsigned long length) 28 | { 29 | LTC_ARGCHK(eax != NULL); 30 | LTC_ARGCHK(header != NULL); 31 | return omac_process(&eax->headeromac, header, length); 32 | } 33 | 34 | #endif 35 | 36 | /* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_addheader.c,v $ */ 37 | /* $Revision: 1.6 $ */ 38 | /* $Date: 2007/05/12 14:32:35 $ */ 39 | -------------------------------------------------------------------------------- /lib_tomcrypt/encauth/eax/eax_decrypt.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /** 13 | @file eax_decrypt.c 14 | EAX implementation, decrypt block, by Tom St Denis 15 | */ 16 | #include "tomcrypt.h" 17 | 18 | #ifdef LTC_EAX_MODE 19 | 20 | /** 21 | Decrypt data with the EAX protocol 22 | @param eax The EAX state 23 | @param ct The ciphertext 24 | @param pt [out] The plaintext 25 | @param length The length (octets) of the ciphertext 26 | @return CRYPT_OK if successful 27 | */ 28 | int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, 29 | unsigned long length) 30 | { 31 | int err; 32 | 33 | LTC_ARGCHK(eax != NULL); 34 | LTC_ARGCHK(pt != NULL); 35 | LTC_ARGCHK(ct != NULL); 36 | 37 | /* omac ciphertext */ 38 | if ((err = omac_process(&eax->ctomac, ct, length)) != CRYPT_OK) { 39 | return err; 40 | } 41 | 42 | /* decrypt */ 43 | return ctr_decrypt(ct, pt, length, &eax->ctr); 44 | } 45 | 46 | #endif 47 | 48 | /* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_decrypt.c,v $ */ 49 | /* $Revision: 1.6 $ */ 50 | /* $Date: 2007/05/12 14:32:35 $ */ 51 | -------------------------------------------------------------------------------- /lib_tomcrypt/encauth/eax/eax_encrypt.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /** 13 | @file eax_encrypt.c 14 | EAX implementation, encrypt block by Tom St Denis 15 | */ 16 | #include "tomcrypt.h" 17 | 18 | #ifdef LTC_EAX_MODE 19 | 20 | /** 21 | Encrypt with EAX a block of data. 22 | @param eax The EAX state 23 | @param pt The plaintext to encrypt 24 | @param ct [out] The ciphertext as encrypted 25 | @param length The length of the plaintext (octets) 26 | @return CRYPT_OK if successful 27 | */ 28 | int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, 29 | unsigned long length) 30 | { 31 | int err; 32 | 33 | LTC_ARGCHK(eax != NULL); 34 | LTC_ARGCHK(pt != NULL); 35 | LTC_ARGCHK(ct != NULL); 36 | 37 | /* encrypt */ 38 | if ((err = ctr_encrypt(pt, ct, length, &eax->ctr)) != CRYPT_OK) { 39 | return err; 40 | } 41 | 42 | /* omac ciphertext */ 43 | return omac_process(&eax->ctomac, ct, length); 44 | } 45 | 46 | #endif 47 | 48 | 49 | /* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_encrypt.c,v $ */ 50 | /* $Revision: 1.6 $ */ 51 | /* $Date: 2007/05/12 14:32:35 $ */ 52 | -------------------------------------------------------------------------------- /lib_tomcrypt/encauth/gcm/gcm_reset.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /** 13 | @file gcm_reset.c 14 | GCM implementation, reset a used state so it can accept IV data, by Tom St Denis 15 | */ 16 | #include "tomcrypt.h" 17 | 18 | #ifdef LTC_GCM_MODE 19 | 20 | /** 21 | Reset a GCM state to as if you just called gcm_init(). This saves the initialization time. 22 | @param gcm The GCM state to reset 23 | @return CRYPT_OK on success 24 | */ 25 | int gcm_reset(gcm_state *gcm) 26 | { 27 | LTC_ARGCHK(gcm != NULL); 28 | 29 | zeromem(gcm->buf, sizeof(gcm->buf)); 30 | zeromem(gcm->X, sizeof(gcm->X)); 31 | gcm->mode = LTC_GCM_MODE_IV; 32 | gcm->ivmode = 0; 33 | gcm->buflen = 0; 34 | gcm->totlen = 0; 35 | gcm->pttotlen = 0; 36 | 37 | return CRYPT_OK; 38 | } 39 | 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_reset.c,v $ */ 43 | /* $Revision: 1.6 $ */ 44 | /* $Date: 2007/05/12 14:32:35 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/encauth/ocb/ocb_ntz.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /** 13 | @file ocb_ntz.c 14 | OCB implementation, internal function, by Tom St Denis 15 | */ 16 | 17 | #include "tomcrypt.h" 18 | 19 | #ifdef LTC_OCB_MODE 20 | 21 | /** 22 | Returns the number of leading zero bits [from lsb up] 23 | @param x The 32-bit value to observe 24 | @return The number of bits [from the lsb up] that are zero 25 | */ 26 | int ocb_ntz(unsigned long x) 27 | { 28 | int c; 29 | x &= 0xFFFFFFFFUL; 30 | c = 0; 31 | while ((x & 1) == 0) { 32 | ++c; 33 | x >>= 1; 34 | } 35 | return c; 36 | } 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_ntz.c,v $ */ 41 | /* $Revision: 1.6 $ */ 42 | /* $Date: 2007/05/12 14:32:35 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/encauth/ocb/ocb_shift_xor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /** 13 | @file ocb_shift_xor.c 14 | OCB implementation, internal function, by Tom St Denis 15 | */ 16 | #include "tomcrypt.h" 17 | 18 | #ifdef LTC_OCB_MODE 19 | 20 | /** 21 | Compute the shift/xor for OCB (internal function) 22 | @param ocb The OCB state 23 | @param Z The destination of the shift 24 | */ 25 | void ocb_shift_xor(ocb_state *ocb, unsigned char *Z) 26 | { 27 | int x, y; 28 | y = ocb_ntz(ocb->block_index++); 29 | for (x = 0; x < ocb->block_len; x++) { 30 | ocb->Li[x] ^= ocb->Ls[y][x]; 31 | Z[x] = ocb->Li[x] ^ ocb->R[x]; 32 | } 33 | } 34 | 35 | #endif 36 | 37 | /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_shift_xor.c,v $ */ 38 | /* $Revision: 1.6 $ */ 39 | /* $Date: 2007/05/12 14:32:35 $ */ 40 | -------------------------------------------------------------------------------- /lib_tomcrypt/headers/tomcrypt_argchk.h: -------------------------------------------------------------------------------- 1 | /* Defines the LTC_ARGCHK macro used within the library */ 2 | /* ARGTYPE is defined in mycrypt_cfg.h */ 3 | #if ARGTYPE == 0 4 | 5 | #include 6 | 7 | /* this is the default LibTomCrypt macro */ 8 | void crypt_argchk(char *v, char *s, int d); 9 | #define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } 10 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 11 | 12 | #elif ARGTYPE == 1 13 | 14 | /* fatal type of error */ 15 | #define LTC_ARGCHK(x) assert((x)) 16 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 17 | 18 | #elif ARGTYPE == 2 19 | 20 | #define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); } 21 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 22 | 23 | #elif ARGTYPE == 3 24 | 25 | #define LTC_ARGCHK(x) 26 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 27 | 28 | #elif ARGTYPE == 4 29 | 30 | #define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG; 31 | #define LTC_ARGCHKVD(x) if (!(x)) return; 32 | 33 | #endif 34 | 35 | 36 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_argchk.h,v $ */ 37 | /* $Revision: 1.5 $ */ 38 | /* $Date: 2006/08/27 20:50:21 $ */ 39 | -------------------------------------------------------------------------------- /lib_tomcrypt/headers/tomcrypt_misc.h: -------------------------------------------------------------------------------- 1 | /* ---- LTC_BASE64 Routines ---- */ 2 | #ifdef LTC_BASE64 3 | int base64_encode(const unsigned char *in, unsigned long len, 4 | unsigned char *out, unsigned long *outlen); 5 | 6 | int base64_decode(const unsigned char *in, unsigned long len, 7 | unsigned char *out, unsigned long *outlen); 8 | #endif 9 | 10 | /* ---- MEM routines ---- */ 11 | void zeromem(void *dst, size_t len); 12 | void burn_stack(unsigned long len); 13 | 14 | const char *error_to_string(int err); 15 | 16 | extern const char *crypt_build_settings; 17 | 18 | /* ---- HMM ---- */ 19 | int crypt_fsa(void *mp, ...); 20 | 21 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_misc.h,v $ */ 22 | /* $Revision: 1.5 $ */ 23 | /* $Date: 2007/05/12 14:32:35 $ */ 24 | -------------------------------------------------------------------------------- /lib_tomcrypt/mac/hmac/hmac_process.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file hmac_process.c 15 | LTC_HMAC support, process data, Tom St Denis/Dobes Vandermeer 16 | */ 17 | 18 | #ifdef LTC_HMAC 19 | 20 | /** 21 | Process data through LTC_HMAC 22 | @param hmac The hmac state 23 | @param in The data to send through LTC_HMAC 24 | @param inlen The length of the data to LTC_HMAC (octets) 25 | @return CRYPT_OK if successful 26 | */ 27 | int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen) 28 | { 29 | int err; 30 | LTC_ARGCHK(hmac != NULL); 31 | LTC_ARGCHK(in != NULL); 32 | if ((err = hash_is_valid(hmac->hash)) != CRYPT_OK) { 33 | return err; 34 | } 35 | return hash_descriptor[hmac->hash].process(&hmac->md, in, inlen); 36 | } 37 | 38 | #endif 39 | 40 | 41 | /* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_process.c,v $ */ 42 | /* $Revision: 1.7 $ */ 43 | /* $Date: 2007/05/12 14:37:41 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/mac/pmac/pmac_ntz.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file pmac_ntz.c 15 | PMAC implementation, internal function, by Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_PMAC 19 | 20 | /** 21 | Internal PMAC function 22 | */ 23 | int pmac_ntz(unsigned long x) 24 | { 25 | int c; 26 | x &= 0xFFFFFFFFUL; 27 | c = 0; 28 | while ((x & 1) == 0) { 29 | ++c; 30 | x >>= 1; 31 | } 32 | return c; 33 | } 34 | 35 | #endif 36 | 37 | /* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_ntz.c,v $ */ 38 | /* $Revision: 1.6 $ */ 39 | /* $Date: 2006/12/28 01:27:23 $ */ 40 | -------------------------------------------------------------------------------- /lib_tomcrypt/mac/pmac/pmac_shift_xor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file pmac_shift_xor.c 15 | PMAC implementation, internal function, by Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_PMAC 19 | 20 | /** 21 | Internal function. Performs the state update (adding correct multiple) 22 | @param pmac The PMAC state. 23 | */ 24 | void pmac_shift_xor(pmac_state *pmac) 25 | { 26 | int x, y; 27 | y = pmac_ntz(pmac->block_index++); 28 | #ifdef LTC_FAST 29 | for (x = 0; x < pmac->block_len; x += sizeof(LTC_FAST_TYPE)) { 30 | *((LTC_FAST_TYPE*)((unsigned char *)pmac->Li + x)) ^= 31 | *((LTC_FAST_TYPE*)((unsigned char *)pmac->Ls[y] + x)); 32 | } 33 | #else 34 | for (x = 0; x < pmac->block_len; x++) { 35 | pmac->Li[x] ^= pmac->Ls[y][x]; 36 | } 37 | #endif 38 | } 39 | 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_shift_xor.c,v $ */ 43 | /* $Revision: 1.7 $ */ 44 | /* $Date: 2006/12/28 01:27:23 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/main.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/LICENSE: -------------------------------------------------------------------------------- 1 | LibTomMath is hereby released into the Public Domain. 2 | 3 | -- Tom St Denis 4 | 5 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_ERROR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | static const struct { 19 | int code; 20 | char *msg; 21 | } msgs[] = { 22 | { MP_OKAY, "Successful" }, 23 | { MP_MEM, "Out of heap" }, 24 | { MP_VAL, "Value out of range" } 25 | }; 26 | 27 | /* return a char * string for a given code */ 28 | char *mp_error_to_string(int code) 29 | { 30 | int x; 31 | 32 | /* scan the lookup table for the given message */ 33 | for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) { 34 | if (msgs[x].code == code) { 35 | return msgs[x].msg; 36 | } 37 | } 38 | 39 | /* generic reply for invalid code */ 40 | return "Invalid error code"; 41 | } 42 | 43 | #endif 44 | 45 | /* $Source$ */ 46 | /* $Revision: 0.41 $ */ 47 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 48 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_2expt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_2EXPT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* computes a = 2**b 19 | * 20 | * Simple algorithm which zeroes the int, grows it then just sets one bit 21 | * as required. 22 | */ 23 | int 24 | mp_2expt (mp_int * a, int b) 25 | { 26 | int res; 27 | 28 | /* zero a as per default */ 29 | mp_zero (a); 30 | 31 | /* grow a to accomodate the single bit */ 32 | if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) { 33 | return res; 34 | } 35 | 36 | /* set the used count of where the bit will go */ 37 | a->used = b / DIGIT_BIT + 1; 38 | 39 | /* put the single bit in its place */ 40 | a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); 41 | 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source$ */ 47 | /* $Revision: 0.41 $ */ 48 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 49 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_abs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_ABS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* b = |a| 19 | * 20 | * Simple function copies the input and fixes the sign to positive 21 | */ 22 | int 23 | mp_abs (mp_int * a, mp_int * b) 24 | { 25 | int res; 26 | 27 | /* copy a to b */ 28 | if (a != b) { 29 | if ((res = mp_copy (a, b)) != MP_OKAY) { 30 | return res; 31 | } 32 | } 33 | 34 | /* force the sign of b to positive */ 35 | b->sign = MP_ZPOS; 36 | 37 | return MP_OKAY; 38 | } 39 | #endif 40 | 41 | /* $Source$ */ 42 | /* $Revision: 0.41 $ */ 43 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_addmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_ADDMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* d = a + b (mod c) */ 19 | int 20 | mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 21 | { 22 | int res; 23 | mp_int t; 24 | 25 | if ((res = mp_init (&t)) != MP_OKAY) { 26 | return res; 27 | } 28 | 29 | if ((res = mp_add (a, b, &t)) != MP_OKAY) { 30 | mp_clear (&t); 31 | return res; 32 | } 33 | res = mp_mod (&t, c, d); 34 | mp_clear (&t); 35 | return res; 36 | } 37 | #endif 38 | 39 | /* $Source$ */ 40 | /* $Revision: 0.41 $ */ 41 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 42 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_and.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_AND_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* AND two ints together */ 19 | int 20 | mp_and (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | int res, ix, px; 23 | mp_int t, *x; 24 | 25 | if (a->used > b->used) { 26 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 27 | return res; 28 | } 29 | px = b->used; 30 | x = b; 31 | } else { 32 | if ((res = mp_init_copy (&t, b)) != MP_OKAY) { 33 | return res; 34 | } 35 | px = a->used; 36 | x = a; 37 | } 38 | 39 | for (ix = 0; ix < px; ix++) { 40 | t.dp[ix] &= x->dp[ix]; 41 | } 42 | 43 | /* zero digits above the last from the smallest mp_int */ 44 | for (; ix < t.used; ix++) { 45 | t.dp[ix] = 0; 46 | } 47 | 48 | mp_clamp (&t); 49 | mp_exch (c, &t); 50 | mp_clear (&t); 51 | return MP_OKAY; 52 | } 53 | #endif 54 | 55 | /* $Source$ */ 56 | /* $Revision: 0.41 $ */ 57 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 58 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_clamp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CLAMP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* trim unused digits 19 | * 20 | * This is used to ensure that leading zero digits are 21 | * trimed and the leading "used" digit will be non-zero 22 | * Typically very fast. Also fixes the sign if there 23 | * are no more leading digits 24 | */ 25 | void 26 | mp_clamp (mp_int * a) 27 | { 28 | /* decrease used while the most significant digit is 29 | * zero. 30 | */ 31 | while (a->used > 0 && a->dp[a->used - 1] == 0) { 32 | --(a->used); 33 | } 34 | 35 | /* reset the sign flag if used == 0 */ 36 | if (a->used == 0) { 37 | a->sign = MP_ZPOS; 38 | } 39 | } 40 | #endif 41 | 42 | /* $Source$ */ 43 | /* $Revision: 0.41 $ */ 44 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_clear.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CLEAR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* clear one (frees) */ 19 | void 20 | mp_clear (mp_int * a) 21 | { 22 | int i; 23 | 24 | /* only do anything if a hasn't been freed previously */ 25 | if (a->dp != NULL) { 26 | /* first zero the digits */ 27 | for (i = 0; i < a->used; i++) { 28 | a->dp[i] = 0; 29 | } 30 | 31 | /* free ram */ 32 | XFREE(a->dp); 33 | 34 | /* reset members to make debugging easier */ 35 | a->dp = NULL; 36 | a->alloc = a->used = 0; 37 | a->sign = MP_ZPOS; 38 | } 39 | } 40 | #endif 41 | 42 | /* $Source$ */ 43 | /* $Revision: 0.41 $ */ 44 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_clear_multi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CLEAR_MULTI_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | #include 18 | 19 | void mp_clear_multi(mp_int *mp, ...) 20 | { 21 | mp_int* next_mp = mp; 22 | va_list args; 23 | va_start(args, mp); 24 | while (next_mp != NULL) { 25 | mp_clear(next_mp); 26 | next_mp = va_arg(args, mp_int*); 27 | } 28 | va_end(args); 29 | } 30 | #endif 31 | 32 | /* $Source$ */ 33 | /* $Revision: 0.41 $ */ 34 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_cmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CMP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* compare two ints (signed)*/ 19 | int 20 | mp_cmp (mp_int * a, mp_int * b) 21 | { 22 | /* compare based on sign */ 23 | if (a->sign != b->sign) { 24 | if (a->sign == MP_NEG) { 25 | return MP_LT; 26 | } else { 27 | return MP_GT; 28 | } 29 | } 30 | 31 | /* compare digits */ 32 | if (a->sign == MP_NEG) { 33 | /* if negative compare opposite direction */ 34 | return mp_cmp_mag(b, a); 35 | } else { 36 | return mp_cmp_mag(a, b); 37 | } 38 | } 39 | #endif 40 | 41 | /* $Source$ */ 42 | /* $Revision: 0.41 $ */ 43 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_cmp_d.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CMP_D_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* compare a digit */ 19 | int mp_cmp_d(mp_int * a, mp_digit b) 20 | { 21 | /* compare based on sign */ 22 | if (a->sign == MP_NEG) { 23 | return MP_LT; 24 | } 25 | 26 | /* compare based on magnitude */ 27 | if (a->used > 1) { 28 | return MP_GT; 29 | } 30 | 31 | /* compare the only digit of a to b */ 32 | if (a->dp[0] > b) { 33 | return MP_GT; 34 | } else if (a->dp[0] < b) { 35 | return MP_LT; 36 | } else { 37 | return MP_EQ; 38 | } 39 | } 40 | #endif 41 | 42 | /* $Source$ */ 43 | /* $Revision: 0.41 $ */ 44 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_cmp_mag.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CMP_MAG_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* compare maginitude of two ints (unsigned) */ 19 | int mp_cmp_mag (mp_int * a, mp_int * b) 20 | { 21 | int n; 22 | mp_digit *tmpa, *tmpb; 23 | 24 | /* compare based on # of non-zero digits */ 25 | if (a->used > b->used) { 26 | return MP_GT; 27 | } 28 | 29 | if (a->used < b->used) { 30 | return MP_LT; 31 | } 32 | 33 | /* alias for a */ 34 | tmpa = a->dp + (a->used - 1); 35 | 36 | /* alias for b */ 37 | tmpb = b->dp + (a->used - 1); 38 | 39 | /* compare based on digits */ 40 | for (n = 0; n < a->used; ++n, --tmpa, --tmpb) { 41 | if (*tmpa > *tmpb) { 42 | return MP_GT; 43 | } 44 | 45 | if (*tmpa < *tmpb) { 46 | return MP_LT; 47 | } 48 | } 49 | return MP_EQ; 50 | } 51 | #endif 52 | 53 | /* $Source$ */ 54 | /* $Revision: 0.41 $ */ 55 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 56 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_cnt_lsb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_CNT_LSB_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | static const int lnz[16] = { 19 | 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 20 | }; 21 | 22 | /* Counts the number of lsbs which are zero before the first zero bit */ 23 | int mp_cnt_lsb(mp_int *a) 24 | { 25 | int x; 26 | mp_digit q, qq; 27 | 28 | /* easy out */ 29 | if (mp_iszero(a) == 1) { 30 | return 0; 31 | } 32 | 33 | /* scan lower digits until non-zero */ 34 | for (x = 0; x < a->used && a->dp[x] == 0; x++); 35 | q = a->dp[x]; 36 | x *= DIGIT_BIT; 37 | 38 | /* now scan this digit until a 1 is found */ 39 | if ((q & 1) == 0) { 40 | do { 41 | qq = q & 15; 42 | x += lnz[qq]; 43 | q >>= 4; 44 | } while (qq == 0); 45 | } 46 | return x; 47 | } 48 | 49 | #endif 50 | 51 | /* $Source$ */ 52 | /* $Revision: 0.41 $ */ 53 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 54 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_count_bits.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_COUNT_BITS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* returns the number of bits in an int */ 19 | int 20 | mp_count_bits (mp_int * a) 21 | { 22 | int r; 23 | mp_digit q; 24 | 25 | /* shortcut */ 26 | if (a->used == 0) { 27 | return 0; 28 | } 29 | 30 | /* get number of digits and add that */ 31 | r = (a->used - 1) * DIGIT_BIT; 32 | 33 | /* take the last digit and count the bits in it */ 34 | q = a->dp[a->used - 1]; 35 | while (q > ((mp_digit) 0)) { 36 | ++r; 37 | q >>= ((mp_digit) 1); 38 | } 39 | return r; 40 | } 41 | #endif 42 | 43 | /* $Source$ */ 44 | /* $Revision: 0.41 $ */ 45 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 46 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_dr_is_modulus.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_DR_IS_MODULUS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if a number is a valid DR modulus */ 19 | int mp_dr_is_modulus(mp_int *a) 20 | { 21 | int ix; 22 | 23 | /* must be at least two digits */ 24 | if (a->used < 2) { 25 | return 0; 26 | } 27 | 28 | /* must be of the form b**k - a [a <= b] so all 29 | * but the first digit must be equal to -1 (mod b). 30 | */ 31 | for (ix = 1; ix < a->used; ix++) { 32 | if (a->dp[ix] != MP_MASK) { 33 | return 0; 34 | } 35 | } 36 | return 1; 37 | } 38 | 39 | #endif 40 | 41 | /* $Source$ */ 42 | /* $Revision: 0.41 $ */ 43 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_dr_setup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_DR_SETUP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines the setup value */ 19 | void mp_dr_setup(mp_int *a, mp_digit *d) 20 | { 21 | /* the casts are required if DIGIT_BIT is one less than 22 | * the number of bits in a mp_digit [e.g. DIGIT_BIT==31] 23 | */ 24 | *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - 25 | ((mp_word)a->dp[0])); 26 | } 27 | 28 | #endif 29 | 30 | /* $Source$ */ 31 | /* $Revision: 0.41 $ */ 32 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 33 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_exch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_EXCH_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* swap the elements of two integers, for cases where you can't simply swap the 19 | * mp_int pointers around 20 | */ 21 | void 22 | mp_exch (mp_int * a, mp_int * b) 23 | { 24 | mp_int t; 25 | 26 | t = *a; 27 | *a = *b; 28 | *b = t; 29 | } 30 | #endif 31 | 32 | /* $Source$ */ 33 | /* $Revision: 0.41 $ */ 34 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_fwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_FWRITE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | int mp_fwrite(mp_int *a, int radix, FILE *stream) 19 | { 20 | char *buf; 21 | int err, len, x; 22 | 23 | if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) { 24 | return err; 25 | } 26 | 27 | buf = OPT_CAST(char) XMALLOC (len); 28 | if (buf == NULL) { 29 | return MP_MEM; 30 | } 31 | 32 | if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) { 33 | XFREE (buf); 34 | return err; 35 | } 36 | 37 | for (x = 0; x < len; x++) { 38 | if (fputc(buf[x], stream) == EOF) { 39 | XFREE (buf); 40 | return MP_VAL; 41 | } 42 | } 43 | 44 | XFREE (buf); 45 | return MP_OKAY; 46 | } 47 | 48 | #endif 49 | 50 | /* $Source$ */ 51 | /* $Revision: 0.41 $ */ 52 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 53 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_get_int.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_GET_INT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* get the lower 32-bits of an mp_int */ 19 | unsigned long mp_get_int(mp_int * a) 20 | { 21 | int i; 22 | unsigned long res; 23 | 24 | if (a->used == 0) { 25 | return 0; 26 | } 27 | 28 | /* get number of digits of the lsb we have to read */ 29 | i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1; 30 | 31 | /* get most significant digit of result */ 32 | res = DIGIT(a,i); 33 | 34 | while (--i >= 0) { 35 | res = (res << DIGIT_BIT) | DIGIT(a,i); 36 | } 37 | 38 | /* force result to 32-bits always so it is consistent on non 32-bit platforms */ 39 | return res & 0xFFFFFFFFUL; 40 | } 41 | #endif 42 | 43 | /* $Source$ */ 44 | /* $Revision: 0.41 $ */ 45 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 46 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_INIT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* init a new mp_int */ 19 | int mp_init (mp_int * a) 20 | { 21 | int i; 22 | 23 | /* allocate memory required and clear it */ 24 | a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * MP_PREC); 25 | if (a->dp == NULL) { 26 | return MP_MEM; 27 | } 28 | 29 | /* set the digits to zero */ 30 | for (i = 0; i < MP_PREC; i++) { 31 | a->dp[i] = 0; 32 | } 33 | 34 | /* set the used to zero, allocated digits to the default precision 35 | * and sign to positive */ 36 | a->used = 0; 37 | a->alloc = MP_PREC; 38 | a->sign = MP_ZPOS; 39 | 40 | return MP_OKAY; 41 | } 42 | #endif 43 | 44 | /* $Source$ */ 45 | /* $Revision: 0.41 $ */ 46 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_init_copy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_INIT_COPY_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* creates "a" then copies b into it */ 19 | int mp_init_copy (mp_int * a, mp_int * b) 20 | { 21 | int res; 22 | 23 | if ((res = mp_init (a)) != MP_OKAY) { 24 | return res; 25 | } 26 | return mp_copy (b, a); 27 | } 28 | #endif 29 | 30 | /* $Source$ */ 31 | /* $Revision: 0.41 $ */ 32 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 33 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_init_set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_INIT_SET_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* initialize and set a digit */ 19 | int mp_init_set (mp_int * a, mp_digit b) 20 | { 21 | int err; 22 | if ((err = mp_init(a)) != MP_OKAY) { 23 | return err; 24 | } 25 | mp_set(a, b); 26 | return err; 27 | } 28 | #endif 29 | 30 | /* $Source$ */ 31 | /* $Revision: 0.41 $ */ 32 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 33 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_init_set_int.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_INIT_SET_INT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* initialize and set a digit */ 19 | int mp_init_set_int (mp_int * a, unsigned long b) 20 | { 21 | int err; 22 | if ((err = mp_init(a)) != MP_OKAY) { 23 | return err; 24 | } 25 | return mp_set_int(a, b); 26 | } 27 | #endif 28 | 29 | /* $Source$ */ 30 | /* $Revision: 0.41 $ */ 31 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 32 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_init_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_INIT_SIZE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* init an mp_init for a given size */ 19 | int mp_init_size (mp_int * a, int size) 20 | { 21 | int x; 22 | 23 | /* pad size so there are always extra digits */ 24 | size += (MP_PREC * 2) - (size % MP_PREC); 25 | 26 | /* alloc mem */ 27 | a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size); 28 | if (a->dp == NULL) { 29 | return MP_MEM; 30 | } 31 | 32 | /* set the members */ 33 | a->used = 0; 34 | a->alloc = size; 35 | a->sign = MP_ZPOS; 36 | 37 | /* zero the digits */ 38 | for (x = 0; x < size; x++) { 39 | a->dp[x] = 0; 40 | } 41 | 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source$ */ 47 | /* $Revision: 0.41 $ */ 48 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 49 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_invmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_INVMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* hac 14.61, pp608 */ 19 | int mp_invmod (mp_int * a, mp_int * b, mp_int * c) 20 | { 21 | /* b cannot be negative */ 22 | if (b->sign == MP_NEG || mp_iszero(b) == 1) { 23 | return MP_VAL; 24 | } 25 | 26 | #ifdef BN_FAST_MP_INVMOD_C 27 | /* if the modulus is odd we can use a faster routine instead */ 28 | if (mp_isodd (b) == 1) { 29 | return fast_mp_invmod (a, b, c); 30 | } 31 | #endif 32 | 33 | #ifdef BN_MP_INVMOD_SLOW_C 34 | return mp_invmod_slow(a, b, c); 35 | #endif 36 | 37 | return MP_VAL; 38 | } 39 | #endif 40 | 41 | /* $Source$ */ 42 | /* $Revision: 0.41 $ */ 43 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_mod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_MOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* c = a mod b, 0 <= c < b */ 19 | int 20 | mp_mod (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | mp_int t; 23 | int res; 24 | 25 | if ((res = mp_init (&t)) != MP_OKAY) { 26 | return res; 27 | } 28 | 29 | if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) { 30 | mp_clear (&t); 31 | return res; 32 | } 33 | 34 | if (t.sign != b->sign) { 35 | res = mp_add (b, &t, c); 36 | } else { 37 | res = MP_OKAY; 38 | mp_exch (&t, c); 39 | } 40 | 41 | mp_clear (&t); 42 | return res; 43 | } 44 | #endif 45 | 46 | /* $Source$ */ 47 | /* $Revision: 0.41 $ */ 48 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 49 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_mod_d.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_MOD_D_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | int 19 | mp_mod_d (mp_int * a, mp_digit b, mp_digit * c) 20 | { 21 | return mp_div_d(a, b, NULL, c); 22 | } 23 | #endif 24 | 25 | /* $Source$ */ 26 | /* $Revision: 0.41 $ */ 27 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 28 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_mulmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_MULMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* d = a * b (mod c) */ 19 | int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 20 | { 21 | int res; 22 | mp_int t; 23 | 24 | if ((res = mp_init (&t)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | if ((res = mp_mul (a, b, &t)) != MP_OKAY) { 29 | mp_clear (&t); 30 | return res; 31 | } 32 | res = mp_mod (&t, c, d); 33 | mp_clear (&t); 34 | return res; 35 | } 36 | #endif 37 | 38 | /* $Source$ */ 39 | /* $Revision: 0.41 $ */ 40 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_neg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_NEG_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* b = -a */ 19 | int mp_neg (mp_int * a, mp_int * b) 20 | { 21 | int res; 22 | if (a != b) { 23 | if ((res = mp_copy (a, b)) != MP_OKAY) { 24 | return res; 25 | } 26 | } 27 | 28 | if (mp_iszero(b) != MP_YES) { 29 | b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS; 30 | } else { 31 | b->sign = MP_ZPOS; 32 | } 33 | 34 | return MP_OKAY; 35 | } 36 | #endif 37 | 38 | /* $Source$ */ 39 | /* $Revision: 0.41 $ */ 40 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_or.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_OR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* OR two ints together */ 19 | int mp_or (mp_int * a, mp_int * b, mp_int * c) 20 | { 21 | int res, ix, px; 22 | mp_int t, *x; 23 | 24 | if (a->used > b->used) { 25 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 26 | return res; 27 | } 28 | px = b->used; 29 | x = b; 30 | } else { 31 | if ((res = mp_init_copy (&t, b)) != MP_OKAY) { 32 | return res; 33 | } 34 | px = a->used; 35 | x = a; 36 | } 37 | 38 | for (ix = 0; ix < px; ix++) { 39 | t.dp[ix] |= x->dp[ix]; 40 | } 41 | mp_clamp (&t); 42 | mp_exch (c, &t); 43 | mp_clear (&t); 44 | return MP_OKAY; 45 | } 46 | #endif 47 | 48 | /* $Source$ */ 49 | /* $Revision: 0.41 $ */ 50 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 51 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_prime_is_divisible.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_PRIME_IS_DIVISIBLE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if an integers is divisible by one 19 | * of the first PRIME_SIZE primes or not 20 | * 21 | * sets result to 0 if not, 1 if yes 22 | */ 23 | int mp_prime_is_divisible (mp_int * a, int *result) 24 | { 25 | int err, ix; 26 | mp_digit res; 27 | 28 | /* default to not */ 29 | *result = MP_NO; 30 | 31 | for (ix = 0; ix < PRIME_SIZE; ix++) { 32 | /* what is a mod LBL_prime_tab[ix] */ 33 | if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) { 34 | return err; 35 | } 36 | 37 | /* is the residue zero? */ 38 | if (res == 0) { 39 | *result = MP_YES; 40 | return MP_OKAY; 41 | } 42 | } 43 | 44 | return MP_OKAY; 45 | } 46 | #endif 47 | 48 | /* $Source$ */ 49 | /* $Revision: 0.41 $ */ 50 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 51 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_prime_rabin_miller_trials.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | 19 | static const struct { 20 | int k, t; 21 | } sizes[] = { 22 | { 128, 28 }, 23 | { 256, 16 }, 24 | { 384, 10 }, 25 | { 512, 7 }, 26 | { 640, 6 }, 27 | { 768, 5 }, 28 | { 896, 4 }, 29 | { 1024, 4 } 30 | }; 31 | 32 | /* returns # of RM trials required for a given bit size */ 33 | int mp_prime_rabin_miller_trials(int size) 34 | { 35 | int x; 36 | 37 | for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) { 38 | if (sizes[x].k == size) { 39 | return sizes[x].t; 40 | } else if (sizes[x].k > size) { 41 | return (x == 0) ? sizes[0].t : sizes[x - 1].t; 42 | } 43 | } 44 | return sizes[x-1].t + 1; 45 | } 46 | 47 | 48 | #endif 49 | 50 | /* $Source$ */ 51 | /* $Revision: 0.41 $ */ 52 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 53 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_radix_smap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_RADIX_SMAP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* chars used in radix conversions */ 19 | const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; 20 | #endif 21 | 22 | /* $Source$ */ 23 | /* $Revision: 0.41 $ */ 24 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 25 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_rand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_RAND_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* makes a pseudo-random int of a given size */ 19 | int 20 | mp_rand (mp_int * a, int digits) 21 | { 22 | int res; 23 | mp_digit d; 24 | 25 | mp_zero (a); 26 | if (digits <= 0) { 27 | return MP_OKAY; 28 | } 29 | 30 | /* first place a random non-zero digit */ 31 | do { 32 | d = ((mp_digit) abs (rand ())) & MP_MASK; 33 | } while (d == 0); 34 | 35 | if ((res = mp_add_d (a, d, a)) != MP_OKAY) { 36 | return res; 37 | } 38 | 39 | while (--digits > 0) { 40 | if ((res = mp_lshd (a, 1)) != MP_OKAY) { 41 | return res; 42 | } 43 | 44 | if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) { 45 | return res; 46 | } 47 | } 48 | 49 | return MP_OKAY; 50 | } 51 | #endif 52 | 53 | /* $Source$ */ 54 | /* $Revision: 0.41 $ */ 55 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 56 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_read_signed_bin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_READ_SIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* read signed bin, big endian, first byte is 0==positive or 1==negative */ 19 | int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c) 20 | { 21 | int res; 22 | 23 | /* read magnitude */ 24 | if ((res = mp_read_unsigned_bin (a, b + 1, c - 1)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | /* first byte is 0 for positive, non-zero for negative */ 29 | if (b[0] == 0) { 30 | a->sign = MP_ZPOS; 31 | } else { 32 | a->sign = MP_NEG; 33 | } 34 | 35 | return MP_OKAY; 36 | } 37 | #endif 38 | 39 | /* $Source$ */ 40 | /* $Revision: 0.41 $ */ 41 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 42 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_reduce_2k_setup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_REDUCE_2K_SETUP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines the setup value */ 19 | int mp_reduce_2k_setup(mp_int *a, mp_digit *d) 20 | { 21 | int res, p; 22 | mp_int tmp; 23 | 24 | if ((res = mp_init(&tmp)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | p = mp_count_bits(a); 29 | if ((res = mp_2expt(&tmp, p)) != MP_OKAY) { 30 | mp_clear(&tmp); 31 | return res; 32 | } 33 | 34 | if ((res = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) { 35 | mp_clear(&tmp); 36 | return res; 37 | } 38 | 39 | *d = tmp.dp[0]; 40 | mp_clear(&tmp); 41 | return MP_OKAY; 42 | } 43 | #endif 44 | 45 | /* $Source$ */ 46 | /* $Revision: 0.41 $ */ 47 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 48 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_reduce_2k_setup_l.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_REDUCE_2K_SETUP_L_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines the setup value */ 19 | int mp_reduce_2k_setup_l(mp_int *a, mp_int *d) 20 | { 21 | int res; 22 | mp_int tmp; 23 | 24 | if ((res = mp_init(&tmp)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) { 29 | goto ERR; 30 | } 31 | 32 | if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) { 33 | goto ERR; 34 | } 35 | 36 | ERR: 37 | mp_clear(&tmp); 38 | return res; 39 | } 40 | #endif 41 | 42 | /* $Source$ */ 43 | /* $Revision: 0.41 $ */ 44 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_reduce_is_2k.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_REDUCE_IS_2K_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if mp_reduce_2k can be used */ 19 | int mp_reduce_is_2k(mp_int *a) 20 | { 21 | int ix, iy, iw; 22 | mp_digit iz; 23 | 24 | if (a->used == 0) { 25 | return MP_NO; 26 | } else if (a->used == 1) { 27 | return MP_YES; 28 | } else if (a->used > 1) { 29 | iy = mp_count_bits(a); 30 | iz = 1; 31 | iw = 1; 32 | 33 | /* Test every bit from the second digit up, must be 1 */ 34 | for (ix = DIGIT_BIT; ix < iy; ix++) { 35 | if ((a->dp[iw] & iz) == 0) { 36 | return MP_NO; 37 | } 38 | iz <<= 1; 39 | if (iz > (mp_digit)MP_MASK) { 40 | ++iw; 41 | iz = 1; 42 | } 43 | } 44 | } 45 | return MP_YES; 46 | } 47 | 48 | #endif 49 | 50 | /* $Source$ */ 51 | /* $Revision: 0.41 $ */ 52 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 53 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_reduce_is_2k_l.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_REDUCE_IS_2K_L_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if reduce_2k_l can be used */ 19 | int mp_reduce_is_2k_l(mp_int *a) 20 | { 21 | int ix, iy; 22 | 23 | if (a->used == 0) { 24 | return MP_NO; 25 | } else if (a->used == 1) { 26 | return MP_YES; 27 | } else if (a->used > 1) { 28 | /* if more than half of the digits are -1 we're sold */ 29 | for (iy = ix = 0; ix < a->used; ix++) { 30 | if (a->dp[ix] == MP_MASK) { 31 | ++iy; 32 | } 33 | } 34 | return (iy >= (a->used/2)) ? MP_YES : MP_NO; 35 | 36 | } 37 | return MP_NO; 38 | } 39 | 40 | #endif 41 | 42 | /* $Source$ */ 43 | /* $Revision: 0.41 $ */ 44 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_reduce_setup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_REDUCE_SETUP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* pre-calculate the value required for Barrett reduction 19 | * For a given modulus "b" it calulates the value required in "a" 20 | */ 21 | int mp_reduce_setup (mp_int * a, mp_int * b) 22 | { 23 | int res; 24 | 25 | if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) { 26 | return res; 27 | } 28 | return mp_div (a, b, a, NULL); 29 | } 30 | #endif 31 | 32 | /* $Source$ */ 33 | /* $Revision: 0.41 $ */ 34 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_SET_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* set to a digit */ 19 | void mp_set (mp_int * a, mp_digit b) 20 | { 21 | mp_zero (a); 22 | a->dp[0] = b & MP_MASK; 23 | a->used = (a->dp[0] != 0) ? 1 : 0; 24 | } 25 | #endif 26 | 27 | /* $Source$ */ 28 | /* $Revision: 0.41 $ */ 29 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 30 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_set_int.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_SET_INT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* set a 32-bit const */ 19 | int mp_set_int (mp_int * a, unsigned long b) 20 | { 21 | int x, res; 22 | 23 | mp_zero (a); 24 | 25 | /* set four bits at a time */ 26 | for (x = 0; x < 8; x++) { 27 | /* shift the number up four bits */ 28 | if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) { 29 | return res; 30 | } 31 | 32 | /* OR in the top four bits of the source */ 33 | a->dp[0] |= (b >> 28) & 15; 34 | 35 | /* shift the source up to the next four bits */ 36 | b <<= 4; 37 | 38 | /* ensure that digits are not clamped off */ 39 | a->used += 1; 40 | } 41 | mp_clamp (a); 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source$ */ 47 | /* $Revision: 0.41 $ */ 48 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 49 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_shrink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_SHRINK_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* shrink a bignum */ 19 | int mp_shrink (mp_int * a) 20 | { 21 | mp_digit *tmp; 22 | int used = 1; 23 | 24 | if(a->used > 0) 25 | used = a->used; 26 | 27 | if (a->alloc != used) { 28 | if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * used)) == NULL) { 29 | return MP_MEM; 30 | } 31 | a->dp = tmp; 32 | a->alloc = used; 33 | } 34 | return MP_OKAY; 35 | } 36 | #endif 37 | 38 | /* $Source$ */ 39 | /* $Revision: v0.42.0 $ */ 40 | /* $Date: 2010-06-02 15:09:36 +0200 $ */ 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_signed_bin_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_SIGNED_BIN_SIZE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* get the size for an signed equivalent */ 19 | int mp_signed_bin_size (mp_int * a) 20 | { 21 | return 1 + mp_unsigned_bin_size (a); 22 | } 23 | #endif 24 | 25 | /* $Source$ */ 26 | /* $Revision: 0.41 $ */ 27 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 28 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_sqrmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_SQRMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* c = a * a (mod b) */ 19 | int 20 | mp_sqrmod (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | int res; 23 | mp_int t; 24 | 25 | if ((res = mp_init (&t)) != MP_OKAY) { 26 | return res; 27 | } 28 | 29 | if ((res = mp_sqr (a, &t)) != MP_OKAY) { 30 | mp_clear (&t); 31 | return res; 32 | } 33 | res = mp_mod (&t, b, c); 34 | mp_clear (&t); 35 | return res; 36 | } 37 | #endif 38 | 39 | /* $Source$ */ 40 | /* $Revision: 0.41 $ */ 41 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 42 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_submod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_SUBMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* d = a - b (mod c) */ 19 | int 20 | mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 21 | { 22 | int res; 23 | mp_int t; 24 | 25 | 26 | if ((res = mp_init (&t)) != MP_OKAY) { 27 | return res; 28 | } 29 | 30 | if ((res = mp_sub (a, b, &t)) != MP_OKAY) { 31 | mp_clear (&t); 32 | return res; 33 | } 34 | res = mp_mod (&t, c, d); 35 | mp_clear (&t); 36 | return res; 37 | } 38 | #endif 39 | 40 | /* $Source$ */ 41 | /* $Revision: 0.41 $ */ 42 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_to_signed_bin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_TO_SIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in signed [big endian] format */ 19 | int mp_to_signed_bin (mp_int * a, unsigned char *b) 20 | { 21 | int res; 22 | 23 | if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) { 24 | return res; 25 | } 26 | b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1); 27 | return MP_OKAY; 28 | } 29 | #endif 30 | 31 | /* $Source$ */ 32 | /* $Revision: 0.41 $ */ 33 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 34 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_to_signed_bin_n.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_TO_SIGNED_BIN_N_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in signed [big endian] format */ 19 | int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) 20 | { 21 | if (*outlen < (unsigned long)mp_signed_bin_size(a)) { 22 | return MP_VAL; 23 | } 24 | *outlen = mp_signed_bin_size(a); 25 | return mp_to_signed_bin(a, b); 26 | } 27 | #endif 28 | 29 | /* $Source$ */ 30 | /* $Revision: 0.41 $ */ 31 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 32 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_to_unsigned_bin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_TO_UNSIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in unsigned [big endian] format */ 19 | int mp_to_unsigned_bin (mp_int * a, unsigned char *b) 20 | { 21 | int x, res; 22 | mp_int t; 23 | 24 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | x = 0; 29 | while (mp_iszero (&t) == 0) { 30 | #ifndef MP_8BIT 31 | b[x++] = (unsigned char) (t.dp[0] & 255); 32 | #else 33 | b[x++] = (unsigned char) (t.dp[0] | ((t.dp[1] & 0x01) << 7)); 34 | #endif 35 | if ((res = mp_div_2d (&t, 8, &t, NULL)) != MP_OKAY) { 36 | mp_clear (&t); 37 | return res; 38 | } 39 | } 40 | bn_reverse (b, x); 41 | mp_clear (&t); 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source$ */ 47 | /* $Revision: 0.41 $ */ 48 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 49 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_to_unsigned_bin_n.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_TO_UNSIGNED_BIN_N_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in unsigned [big endian] format */ 19 | int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) 20 | { 21 | if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) { 22 | return MP_VAL; 23 | } 24 | *outlen = mp_unsigned_bin_size(a); 25 | return mp_to_unsigned_bin(a, b); 26 | } 27 | #endif 28 | 29 | /* $Source$ */ 30 | /* $Revision: 0.41 $ */ 31 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 32 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_unsigned_bin_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_UNSIGNED_BIN_SIZE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* get the size for an unsigned equivalent */ 19 | int mp_unsigned_bin_size (mp_int * a) 20 | { 21 | int size = mp_count_bits (a); 22 | return (size / 8 + ((size & 7) != 0 ? 1 : 0)); 23 | } 24 | #endif 25 | 26 | /* $Source$ */ 27 | /* $Revision: 0.41 $ */ 28 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 29 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_xor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_XOR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* XOR two ints together */ 19 | int 20 | mp_xor (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | int res, ix, px; 23 | mp_int t, *x; 24 | 25 | if (a->used > b->used) { 26 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 27 | return res; 28 | } 29 | px = b->used; 30 | x = b; 31 | } else { 32 | if ((res = mp_init_copy (&t, b)) != MP_OKAY) { 33 | return res; 34 | } 35 | px = a->used; 36 | x = a; 37 | } 38 | 39 | for (ix = 0; ix < px; ix++) { 40 | t.dp[ix] ^= x->dp[ix]; 41 | } 42 | mp_clamp (&t); 43 | mp_exch (c, &t); 44 | mp_clear (&t); 45 | return MP_OKAY; 46 | } 47 | #endif 48 | 49 | /* $Source$ */ 50 | /* $Revision: 0.41 $ */ 51 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 52 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_mp_zero.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_MP_ZERO_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* set to zero */ 19 | void mp_zero (mp_int * a) 20 | { 21 | int n; 22 | mp_digit *tmp; 23 | 24 | a->sign = MP_ZPOS; 25 | a->used = 0; 26 | 27 | tmp = a->dp; 28 | for (n = 0; n < a->alloc; n++) { 29 | *tmp++ = 0; 30 | } 31 | } 32 | #endif 33 | 34 | /* $Source$ */ 35 | /* $Revision: 0.41 $ */ 36 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bn_reverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BN_REVERSE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* reverse an array, used for radix code */ 19 | void 20 | bn_reverse (unsigned char *s, int len) 21 | { 22 | int ix, iy; 23 | unsigned char t; 24 | 25 | ix = 0; 26 | iy = len - 1; 27 | while (ix < iy) { 28 | t = s[ix]; 29 | s[ix] = s[iy]; 30 | s[iy] = t; 31 | ++ix; 32 | --iy; 33 | } 34 | } 35 | #endif 36 | 37 | /* $Source$ */ 38 | /* $Revision: 0.41 $ */ 39 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 40 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/bncore.c: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef BNCORE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* Known optimal configurations 19 | 20 | CPU /Compiler /MUL CUTOFF/SQR CUTOFF 21 | ------------------------------------------------------------- 22 | Intel P4 Northwood /GCC v3.4.1 / 88/ 128/LTM 0.32 ;-) 23 | AMD Athlon64 /GCC v3.4.4 / 80/ 120/LTM 0.35 24 | 25 | */ 26 | 27 | int KARATSUBA_MUL_CUTOFF = 80, /* Min. number of digits before Karatsuba multiplication is used. */ 28 | KARATSUBA_SQR_CUTOFF = 120, /* Min. number of digits before Karatsuba squaring is used. */ 29 | 30 | TOOM_MUL_CUTOFF = 350, /* no optimal values of these are known yet so set em high */ 31 | TOOM_SQR_CUTOFF = 400; 32 | #endif 33 | 34 | /* $Source$ */ 35 | /* $Revision: 0.41 $ */ 36 | /* $Date: 2007-04-18 09:58:18 +0000 $ */ 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/etc/2kprime.1: -------------------------------------------------------------------------------- 1 | 256-bits (k = 36113) = 115792089237316195423570985008687907853269984665640564039457584007913129603823 2 | 512-bits (k = 38117) = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006045979 3 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/etc/drprimes.txt: -------------------------------------------------------------------------------- 1 | 300-bit prime: 2 | p == 2037035976334486086268445688409378161051468393665936250636140449354381298610415201576637819 3 | 4 | 540-bit prime: 5 | p == 3599131035634557106248430806148785487095757694641533306480604458089470064537190296255232548883112685719936728506816716098566612844395439751206810991770626477344739 6 | 7 | 780-bit prime: 8 | p == 6359114106063703798370219984742410466332205126109989319225557147754704702203399726411277962562135973685197744935448875852478791860694279747355800678568677946181447581781401213133886609947027230004277244697462656003655947791725966271167 9 | 10 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/etc/makefile.msvc: -------------------------------------------------------------------------------- 1 | #MSVC Makefile 2 | # 3 | #Tom St Denis 4 | 5 | CFLAGS = /I../ /Ox /DWIN32 /W3 6 | 7 | pprime: pprime.obj 8 | cl pprime.obj ../tommath.lib 9 | 10 | mersenne: mersenne.obj 11 | cl mersenne.obj ../tommath.lib 12 | 13 | tune: tune.obj 14 | cl tune.obj ../tommath.lib 15 | 16 | mont: mont.obj 17 | cl mont.obj ../tommath.lib 18 | 19 | drprime: drprime.obj 20 | cl drprime.obj ../tommath.lib 21 | 22 | 2kprime: 2kprime.obj 23 | cl 2kprime.obj ../tommath.lib 24 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/etc/mont.c: -------------------------------------------------------------------------------- 1 | /* tests the montgomery routines */ 2 | #include 3 | 4 | int main(void) 5 | { 6 | mp_int modulus, R, p, pp; 7 | mp_digit mp; 8 | long x, y; 9 | 10 | srand(time(NULL)); 11 | mp_init_multi(&modulus, &R, &p, &pp, NULL); 12 | 13 | /* loop through various sizes */ 14 | for (x = 4; x < 256; x++) { 15 | printf("DIGITS == %3ld...", x); fflush(stdout); 16 | 17 | /* make up the odd modulus */ 18 | mp_rand(&modulus, x); 19 | modulus.dp[0] |= 1; 20 | 21 | /* now find the R value */ 22 | mp_montgomery_calc_normalization(&R, &modulus); 23 | mp_montgomery_setup(&modulus, &mp); 24 | 25 | /* now run through a bunch tests */ 26 | for (y = 0; y < 1000; y++) { 27 | mp_rand(&p, x/2); /* p = random */ 28 | mp_mul(&p, &R, &pp); /* pp = R * p */ 29 | mp_montgomery_reduce(&pp, &modulus, mp); 30 | 31 | /* should be equal to p */ 32 | if (mp_cmp(&pp, &p) != MP_EQ) { 33 | printf("FAILURE!\n"); 34 | exit(-1); 35 | } 36 | } 37 | printf("PASSED\n"); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | /* $Source$ */ 49 | /* $Revision: 0.36 $ */ 50 | /* $Date: 2005-08-01 16:37:28 +0000 $ */ 51 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/etc/timer.asm: -------------------------------------------------------------------------------- 1 | ; x86 timer in NASM 2 | ; 3 | ; Tom St Denis, tomstdenis@iahu.ca 4 | [bits 32] 5 | [section .data] 6 | time dd 0, 0 7 | 8 | [section .text] 9 | 10 | %ifdef USE_ELF 11 | [global t_start] 12 | t_start: 13 | %else 14 | [global _t_start] 15 | _t_start: 16 | %endif 17 | push edx 18 | push eax 19 | rdtsc 20 | mov [time+0],edx 21 | mov [time+4],eax 22 | pop eax 23 | pop edx 24 | ret 25 | 26 | %ifdef USE_ELF 27 | [global t_read] 28 | t_read: 29 | %else 30 | [global _t_read] 31 | _t_read: 32 | %endif 33 | rdtsc 34 | sub eax,[time+4] 35 | sbb edx,[time+0] 36 | ret 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/gen.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # Generates a "single file" you can use to quickly 4 | # add the whole source without any makefile troubles 5 | # 6 | use strict; 7 | 8 | open( OUT, ">mpi.c" ) or die "Couldn't open mpi.c for writing: $!"; 9 | foreach my $filename (glob "bn*.c") { 10 | open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!"; 11 | print OUT "/* Start: $filename */\n"; 12 | print OUT while ; 13 | print OUT "\n/* End: $filename */\n\n"; 14 | close SRC or die "Error closing $filename after reading: $!"; 15 | } 16 | print OUT "\n/* EOF */\n"; 17 | close OUT or die "Error closing mpi.c after writing: $!"; -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/libtommath.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/libtommath.a -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/libtommath_VS2005.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtommath", "libtommath_VS2005.vcproj", "{0272C9B2-D68B-4F24-B32D-C1FD552F7E51}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0272C9B2-D68B-4F24-B32D-C1FD552F7E51}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {0272C9B2-D68B-4F24-B32D-C1FD552F7E51}.Debug|Win32.Build.0 = Debug|Win32 14 | {0272C9B2-D68B-4F24-B32D-C1FD552F7E51}.Release|Win32.ActiveCfg = Release|Win32 15 | {0272C9B2-D68B-4F24-B32D-C1FD552F7E51}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/libtommath_VS2008.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtommath", "libtommath_VS2008.vcproj", "{42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|Win32.Build.0 = Debug|Win32 14 | {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|Win32.ActiveCfg = Release|Win32 15 | {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/README: -------------------------------------------------------------------------------- 1 | To use the pretty graphs you have to first build/run the ltmtest from the root directory of the package. 2 | Todo this type 3 | 4 | make timing ; ltmtest 5 | 6 | in the root. It will run for a while [about ten minutes on most PCs] and produce a series of .log files in logs/. 7 | 8 | After doing that run "gnuplot graphs.dem" to make the PNGs. If you managed todo that all so far just open index.html to view 9 | them all :-) 10 | 11 | Have fun 12 | 13 | Tom -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/addsub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/logs/addsub.png -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/expt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/logs/expt.png -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/graphs.dem: -------------------------------------------------------------------------------- 1 | set terminal png 2 | set size 1.75 3 | set ylabel "Cycles per Operation" 4 | set xlabel "Operand size (bits)" 5 | 6 | set output "addsub.png" 7 | plot 'add.log' smooth bezier title "Addition", 'sub.log' smooth bezier title "Subtraction" 8 | 9 | set output "mult.png" 10 | plot 'sqr.log' smooth bezier title "Squaring (without Karatsuba)", 'sqr_kara.log' smooth bezier title "Squaring (Karatsuba)", 'mult.log' smooth bezier title "Multiplication (without Karatsuba)", 'mult_kara.log' smooth bezier title "Multiplication (Karatsuba)" 11 | 12 | set output "expt.png" 13 | plot 'expt.log' smooth bezier title "Exptmod (Montgomery)", 'expt_dr.log' smooth bezier title "Exptmod (Dimminished Radix)", 'expt_2k.log' smooth bezier title "Exptmod (2k Reduction)" 14 | 15 | set output "invmod.png" 16 | plot 'invmod.log' smooth bezier title "Modular Inverse" 17 | 18 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | LibTomMath Log Plots 4 | 5 | 6 | 7 |

Addition and Subtraction

8 |
9 |
10 | 11 |

Multipliers

12 |
13 |
14 | 15 |

Exptmod

16 |
17 |
18 | 19 |

Modular Inverse

20 |
21 |
22 | 23 | 24 | 25 | /* $Source: /cvs/libtom/libtommath/logs/index.html,v $ */ 26 | /* $Revision: 1.2 $ */ 27 | /* $Date: 2005/05/05 14:38:47 $ */ 28 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/invmod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/logs/invmod.png -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/logs/mult.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/logs/mult.png -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/mess.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if cvs log $1 >/dev/null 2>/dev/null; then exit 0; else echo "$1 shouldn't be here" ; exit 1; fi 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/mtest/logtab.h: -------------------------------------------------------------------------------- 1 | const float s_logv_2[] = { 2 | 0.000000000, 0.000000000, 1.000000000, 0.630929754, /* 0 1 2 3 */ 3 | 0.500000000, 0.430676558, 0.386852807, 0.356207187, /* 4 5 6 7 */ 4 | 0.333333333, 0.315464877, 0.301029996, 0.289064826, /* 8 9 10 11 */ 5 | 0.278942946, 0.270238154, 0.262649535, 0.255958025, /* 12 13 14 15 */ 6 | 0.250000000, 0.244650542, 0.239812467, 0.235408913, /* 16 17 18 19 */ 7 | 0.231378213, 0.227670249, 0.224243824, 0.221064729, /* 20 21 22 23 */ 8 | 0.218104292, 0.215338279, 0.212746054, 0.210309918, /* 24 25 26 27 */ 9 | 0.208014598, 0.205846832, 0.203795047, 0.201849087, /* 28 29 30 31 */ 10 | 0.200000000, 0.198239863, 0.196561632, 0.194959022, /* 32 33 34 35 */ 11 | 0.193426404, 0.191958720, 0.190551412, 0.189200360, /* 36 37 38 39 */ 12 | 0.187901825, 0.186652411, 0.185449023, 0.184288833, /* 40 41 42 43 */ 13 | 0.183169251, 0.182087900, 0.181042597, 0.180031327, /* 44 45 46 47 */ 14 | 0.179052232, 0.178103594, 0.177183820, 0.176291434, /* 48 49 50 51 */ 15 | 0.175425064, 0.174583430, 0.173765343, 0.172969690, /* 52 53 54 55 */ 16 | 0.172195434, 0.171441601, 0.170707280, 0.169991616, /* 56 57 58 59 */ 17 | 0.169293808, 0.168613099, 0.167948779, 0.167300179, /* 60 61 62 63 */ 18 | 0.166666667 19 | }; 20 | 21 | 22 | /* $Source$ */ 23 | /* $Revision: 0.36 $ */ 24 | /* $Date: 2005-08-01 16:37:28 +0000 $ */ 25 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/mtest/mpi-types.h: -------------------------------------------------------------------------------- 1 | /* Type definitions generated by 'types.pl' */ 2 | typedef char mp_sign; 3 | typedef unsigned short mp_digit; /* 2 byte type */ 4 | typedef unsigned int mp_word; /* 4 byte type */ 5 | typedef unsigned int mp_size; 6 | typedef int mp_err; 7 | 8 | #define MP_DIGIT_BIT (CHAR_BIT*sizeof(mp_digit)) 9 | #define MP_DIGIT_MAX USHRT_MAX 10 | #define MP_WORD_BIT (CHAR_BIT*sizeof(mp_word)) 11 | #define MP_WORD_MAX UINT_MAX 12 | 13 | #define MP_DIGIT_SIZE 2 14 | #define DIGIT_FMT "%04X" 15 | #define RADIX (MP_DIGIT_MAX+1) 16 | 17 | 18 | /* $Source$ */ 19 | /* $Revision: 0.36 $ */ 20 | /* $Date: 2005-08-01 16:37:28 +0000 $ */ 21 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/design_process.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/design_process.sxd -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/design_process.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/design_process.tif -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/expt_state.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/expt_state.sxd -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/expt_state.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/expt_state.tif -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/makefile: -------------------------------------------------------------------------------- 1 | # makes the images... yeah 2 | 3 | default: pses 4 | 5 | design_process.ps: design_process.tif 6 | tiff2ps -s -e design_process.tif > design_process.ps 7 | 8 | sliding_window.ps: sliding_window.tif 9 | tiff2ps -s -e sliding_window.tif > sliding_window.ps 10 | 11 | expt_state.ps: expt_state.tif 12 | tiff2ps -s -e expt_state.tif > expt_state.ps 13 | 14 | primality.ps: primality.tif 15 | tiff2ps -s -e primality.tif > primality.ps 16 | 17 | design_process.pdf: design_process.ps 18 | epstopdf design_process.ps 19 | 20 | sliding_window.pdf: sliding_window.ps 21 | epstopdf sliding_window.ps 22 | 23 | expt_state.pdf: expt_state.ps 24 | epstopdf expt_state.ps 25 | 26 | primality.pdf: primality.ps 27 | epstopdf primality.ps 28 | 29 | 30 | pses: sliding_window.ps expt_state.ps primality.ps design_process.ps 31 | pdfes: sliding_window.pdf expt_state.pdf primality.pdf design_process.pdf 32 | 33 | clean: 34 | rm -rf *.ps *.pdf .xvpics 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/primality.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/primality.tif -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/radix.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/radix.sxd -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/sliding_window.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/sliding_window.sxd -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/pics/sliding_window.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/pics/sliding_window.tif -------------------------------------------------------------------------------- /lib_tomcrypt/math/tommath/poster.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/lib_tomcrypt/math/tommath/poster.out -------------------------------------------------------------------------------- /lib_tomcrypt/misc/burn_stack.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file burn_stack.c 15 | Burn stack, Tom St Denis 16 | */ 17 | 18 | /** 19 | Burn some stack memory 20 | @param len amount of stack to burn in bytes 21 | */ 22 | void burn_stack(unsigned long len) 23 | { 24 | unsigned char buf[32]; 25 | zeromem(buf, sizeof(buf)); 26 | if (len > (unsigned long)sizeof(buf)) 27 | burn_stack(len - sizeof(buf)); 28 | } 29 | 30 | 31 | 32 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/burn_stack.c,v $ */ 33 | /* $Revision: 1.5 $ */ 34 | /* $Date: 2006/12/28 01:27:24 $ */ 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_argchk.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | #include 13 | 14 | /** 15 | @file crypt_argchk.c 16 | Perform argument checking, Tom St Denis 17 | */ 18 | 19 | #if (ARGTYPE == 0) 20 | void crypt_argchk(char *v, char *s, int d) 21 | { 22 | fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n", 23 | v, d, s); 24 | (void)raise(SIGABRT); 25 | } 26 | #endif 27 | 28 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_argchk.c,v $ */ 29 | /* $Revision: 1.5 $ */ 30 | /* $Date: 2006/12/28 01:27:24 $ */ 31 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_cipher_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_cipher_descriptor.c 15 | Stores the cipher descriptor table, Tom St Denis 16 | */ 17 | 18 | struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = { 19 | { NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } 20 | }; 21 | 22 | LTC_MUTEX_GLOBAL(ltc_cipher_mutex) 23 | 24 | 25 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_cipher_descriptor.c,v $ */ 26 | /* $Revision: 1.13 $ */ 27 | /* $Date: 2006/12/28 01:27:24 $ */ 28 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_cipher_is_valid.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_cipher_is_valid.c 15 | Determine if cipher is valid, Tom St Denis 16 | */ 17 | 18 | /* 19 | Test if a cipher index is valid 20 | @param idx The index of the cipher to search for 21 | @return CRYPT_OK if valid 22 | */ 23 | int cipher_is_valid(int idx) 24 | { 25 | LTC_MUTEX_LOCK(<c_cipher_mutex); 26 | if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) { 27 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 28 | return CRYPT_INVALID_CIPHER; 29 | } 30 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 31 | return CRYPT_OK; 32 | } 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_cipher_is_valid.c,v $ */ 35 | /* $Revision: 1.6 $ */ 36 | /* $Date: 2006/12/28 01:27:24 $ */ 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_find_cipher.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_cipher.c 15 | Find a cipher in the descriptor tables, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a registered cipher by name 20 | @param name The name of the cipher to look for 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_cipher(const char *name) 24 | { 25 | int x; 26 | LTC_ARGCHK(name != NULL); 27 | LTC_MUTEX_LOCK(<c_cipher_mutex); 28 | for (x = 0; x < TAB_SIZE; x++) { 29 | if (cipher_descriptor[x].name != NULL && !XSTRCMP(cipher_descriptor[x].name, name)) { 30 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 35 | return -1; 36 | } 37 | 38 | 39 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_cipher.c,v $ */ 40 | /* $Revision: 1.7 $ */ 41 | /* $Date: 2006/12/28 01:27:24 $ */ 42 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_find_cipher_id.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_cipher_id.c 15 | Find cipher by ID, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a cipher by ID number 20 | @param ID The ID (not same as index) of the cipher to find 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_cipher_id(unsigned char ID) 24 | { 25 | int x; 26 | LTC_MUTEX_LOCK(<c_cipher_mutex); 27 | for (x = 0; x < TAB_SIZE; x++) { 28 | if (cipher_descriptor[x].ID == ID) { 29 | x = (cipher_descriptor[x].name == NULL) ? -1 : x; 30 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 35 | return -1; 36 | } 37 | 38 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_cipher_id.c,v $ */ 39 | /* $Revision: 1.6 $ */ 40 | /* $Date: 2006/12/28 01:27:24 $ */ 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_find_hash.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_hash.c 15 | Find a hash, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a registered hash by name 20 | @param name The name of the hash to look for 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_hash(const char *name) 24 | { 25 | int x; 26 | LTC_ARGCHK(name != NULL); 27 | LTC_MUTEX_LOCK(<c_hash_mutex); 28 | for (x = 0; x < TAB_SIZE; x++) { 29 | if (hash_descriptor[x].name != NULL && XSTRCMP(hash_descriptor[x].name, name) == 0) { 30 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 35 | return -1; 36 | } 37 | 38 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash.c,v $ */ 39 | /* $Revision: 1.7 $ */ 40 | /* $Date: 2006/12/28 01:27:24 $ */ 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_find_hash_id.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_hash_id.c 15 | Find hash by ID, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a hash by ID number 20 | @param ID The ID (not same as index) of the hash to find 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_hash_id(unsigned char ID) 24 | { 25 | int x; 26 | LTC_MUTEX_LOCK(<c_hash_mutex); 27 | for (x = 0; x < TAB_SIZE; x++) { 28 | if (hash_descriptor[x].ID == ID) { 29 | x = (hash_descriptor[x].name == NULL) ? -1 : x; 30 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 35 | return -1; 36 | } 37 | 38 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash_id.c,v $ */ 39 | /* $Revision: 1.7 $ */ 40 | /* $Date: 2006/12/28 01:27:24 $ */ 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_find_hash_oid.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_hash_oid.c 15 | Find a hash, Tom St Denis 16 | */ 17 | 18 | int find_hash_oid(const unsigned long *ID, unsigned long IDlen) 19 | { 20 | int x; 21 | LTC_ARGCHK(ID != NULL); 22 | LTC_MUTEX_LOCK(<c_hash_mutex); 23 | for (x = 0; x < TAB_SIZE; x++) { 24 | if (hash_descriptor[x].name != NULL && hash_descriptor[x].OIDlen == IDlen && !XMEMCMP(hash_descriptor[x].OID, ID, sizeof(unsigned long) * IDlen)) { 25 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 26 | return x; 27 | } 28 | } 29 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 30 | return -1; 31 | } 32 | 33 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash_oid.c,v $ */ 34 | /* $Revision: 1.5 $ */ 35 | /* $Date: 2006/12/28 01:27:24 $ */ 36 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_find_prng.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_prng.c 15 | Find a PRNG, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a registered PRNG by name 20 | @param name The name of the PRNG to look for 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_prng(const char *name) 24 | { 25 | int x; 26 | LTC_ARGCHK(name != NULL); 27 | LTC_MUTEX_LOCK(<c_prng_mutex); 28 | for (x = 0; x < TAB_SIZE; x++) { 29 | if ((prng_descriptor[x].name != NULL) && XSTRCMP(prng_descriptor[x].name, name) == 0) { 30 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 35 | return -1; 36 | } 37 | 38 | 39 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_prng.c,v $ */ 40 | /* $Revision: 1.7 $ */ 41 | /* $Date: 2006/12/28 01:27:24 $ */ 42 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_hash_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_hash_descriptor.c 15 | Stores the hash descriptor table, Tom St Denis 16 | */ 17 | 18 | struct ltc_hash_descriptor hash_descriptor[TAB_SIZE] = { 19 | { NULL, 0, 0, 0, { 0 }, 0, NULL, NULL, NULL, NULL, NULL } 20 | }; 21 | 22 | LTC_MUTEX_GLOBAL(ltc_hash_mutex) 23 | 24 | 25 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_descriptor.c,v $ */ 26 | /* $Revision: 1.10 $ */ 27 | /* $Date: 2006/12/28 01:27:24 $ */ 28 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_hash_is_valid.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_hash_is_valid.c 15 | Determine if hash is valid, Tom St Denis 16 | */ 17 | 18 | /* 19 | Test if a hash index is valid 20 | @param idx The index of the hash to search for 21 | @return CRYPT_OK if valid 22 | */ 23 | int hash_is_valid(int idx) 24 | { 25 | LTC_MUTEX_LOCK(<c_hash_mutex); 26 | if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) { 27 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 28 | return CRYPT_INVALID_HASH; 29 | } 30 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 31 | return CRYPT_OK; 32 | } 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c,v $ */ 35 | /* $Revision: 1.6 $ */ 36 | /* $Date: 2006/12/28 01:27:24 $ */ 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_ltc_mp_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | ltc_math_descriptor ltc_mp; 14 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_prng_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_prng_descriptor.c 15 | Stores the PRNG descriptors, Tom St Denis 16 | */ 17 | struct ltc_prng_descriptor prng_descriptor[TAB_SIZE] = { 18 | { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } 19 | }; 20 | 21 | LTC_MUTEX_GLOBAL(ltc_prng_mutex) 22 | 23 | 24 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_prng_descriptor.c,v $ */ 25 | /* $Revision: 1.8 $ */ 26 | /* $Date: 2006/12/28 01:27:24 $ */ 27 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_prng_is_valid.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_prng_is_valid.c 15 | Determine if PRNG is valid, Tom St Denis 16 | */ 17 | 18 | /* 19 | Test if a PRNG index is valid 20 | @param idx The index of the PRNG to search for 21 | @return CRYPT_OK if valid 22 | */ 23 | int prng_is_valid(int idx) 24 | { 25 | LTC_MUTEX_LOCK(<c_prng_mutex); 26 | if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) { 27 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 28 | return CRYPT_INVALID_PRNG; 29 | } 30 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 31 | return CRYPT_OK; 32 | } 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_prng_is_valid.c,v $ */ 35 | /* $Revision: 1.6 $ */ 36 | /* $Date: 2006/12/28 01:27:24 $ */ 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_unregister_cipher.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_unregister_cipher.c 15 | Unregister a cipher, Tom St Denis 16 | */ 17 | 18 | /** 19 | Unregister a cipher from the descriptor table 20 | @param cipher The cipher descriptor to remove 21 | @return CRYPT_OK on success 22 | */ 23 | int unregister_cipher(const struct ltc_cipher_descriptor *cipher) 24 | { 25 | int x; 26 | 27 | LTC_ARGCHK(cipher != NULL); 28 | 29 | /* is it already registered? */ 30 | LTC_MUTEX_LOCK(<c_cipher_mutex); 31 | for (x = 0; x < TAB_SIZE; x++) { 32 | if (XMEMCMP(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor)) == 0) { 33 | cipher_descriptor[x].name = NULL; 34 | cipher_descriptor[x].ID = 255; 35 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 36 | return CRYPT_OK; 37 | } 38 | } 39 | LTC_MUTEX_UNLOCK(<c_cipher_mutex); 40 | return CRYPT_ERROR; 41 | } 42 | 43 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_unregister_cipher.c,v $ */ 44 | /* $Revision: 1.7 $ */ 45 | /* $Date: 2006/12/28 01:27:24 $ */ 46 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_unregister_hash.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_unregister_hash.c 15 | Unregister a hash, Tom St Denis 16 | */ 17 | 18 | /** 19 | Unregister a hash from the descriptor table 20 | @param hash The hash descriptor to remove 21 | @return CRYPT_OK on success 22 | */ 23 | int unregister_hash(const struct ltc_hash_descriptor *hash) 24 | { 25 | int x; 26 | 27 | LTC_ARGCHK(hash != NULL); 28 | 29 | /* is it already registered? */ 30 | LTC_MUTEX_LOCK(<c_hash_mutex); 31 | for (x = 0; x < TAB_SIZE; x++) { 32 | if (XMEMCMP(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) { 33 | hash_descriptor[x].name = NULL; 34 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 35 | return CRYPT_OK; 36 | } 37 | } 38 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 39 | return CRYPT_ERROR; 40 | } 41 | 42 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_unregister_hash.c,v $ */ 43 | /* $Revision: 1.7 $ */ 44 | /* $Date: 2006/12/28 01:27:24 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/crypt/crypt_unregister_prng.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file crypt_unregister_prng.c 15 | Unregister a PRNG, Tom St Denis 16 | */ 17 | 18 | /** 19 | Unregister a PRNG from the descriptor table 20 | @param prng The PRNG descriptor to remove 21 | @return CRYPT_OK on success 22 | */ 23 | int unregister_prng(const struct ltc_prng_descriptor *prng) 24 | { 25 | int x; 26 | 27 | LTC_ARGCHK(prng != NULL); 28 | 29 | /* is it already registered? */ 30 | LTC_MUTEX_LOCK(<c_prng_mutex); 31 | for (x = 0; x < TAB_SIZE; x++) { 32 | if (XMEMCMP(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) != 0) { 33 | prng_descriptor[x].name = NULL; 34 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 35 | return CRYPT_OK; 36 | } 37 | } 38 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 39 | return CRYPT_ERROR; 40 | } 41 | 42 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_unregister_prng.c,v $ */ 43 | /* $Revision: 1.7 $ */ 44 | /* $Date: 2006/12/28 01:27:24 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/misc/zeromem.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file zeromem.c 15 | Zero a block of memory, Tom St Denis 16 | */ 17 | 18 | /** 19 | Zero a block of memory 20 | @param out The destination of the area to zero 21 | @param outlen The length of the area to zero (octets) 22 | */ 23 | void zeromem(void *out, size_t outlen) 24 | { 25 | unsigned char *mem = out; 26 | LTC_ARGCHKVD(out != NULL); 27 | while (outlen-- > 0) { 28 | *mem++ = 0; 29 | } 30 | } 31 | 32 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/zeromem.c,v $ */ 33 | /* $Revision: 1.7 $ */ 34 | /* $Date: 2006/12/28 01:27:24 $ */ 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/cbc/cbc_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file cbc_done.c 15 | CBC implementation, finish chain, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CBC_MODE 19 | 20 | /** Terminate the chain 21 | @param cbc The CBC chain to terminate 22 | @return CRYPT_OK on success 23 | */ 24 | int cbc_done(symmetric_CBC *cbc) 25 | { 26 | int err; 27 | LTC_ARGCHK(cbc != NULL); 28 | 29 | if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) { 30 | return err; 31 | } 32 | cipher_descriptor[cbc->cipher].done(&cbc->key); 33 | return CRYPT_OK; 34 | } 35 | 36 | 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_done.c,v $ */ 41 | /* $Revision: 1.7 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/cbc/cbc_getiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file cbc_getiv.c 15 | CBC implementation, get IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CBC_MODE 19 | 20 | /** 21 | Get the current initial vector 22 | @param IV [out] The destination of the initial vector 23 | @param len [in/out] The max size and resulting size of the initial vector 24 | @param cbc The CBC state 25 | @return CRYPT_OK if successful 26 | */ 27 | int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc) 28 | { 29 | LTC_ARGCHK(IV != NULL); 30 | LTC_ARGCHK(len != NULL); 31 | LTC_ARGCHK(cbc != NULL); 32 | if ((unsigned long)cbc->blocklen > *len) { 33 | *len = cbc->blocklen; 34 | return CRYPT_BUFFER_OVERFLOW; 35 | } 36 | XMEMCPY(IV, cbc->IV, cbc->blocklen); 37 | *len = cbc->blocklen; 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_getiv.c,v $ */ 45 | /* $Revision: 1.7 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/cbc/cbc_setiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file cbc_setiv.c 15 | CBC implementation, set IV, Tom St Denis 16 | */ 17 | 18 | 19 | #ifdef LTC_CBC_MODE 20 | 21 | /** 22 | Set an initial vector 23 | @param IV The initial vector 24 | @param len The length of the vector (in octets) 25 | @param cbc The CBC state 26 | @return CRYPT_OK if successful 27 | */ 28 | int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc) 29 | { 30 | LTC_ARGCHK(IV != NULL); 31 | LTC_ARGCHK(cbc != NULL); 32 | if (len != (unsigned long)cbc->blocklen) { 33 | return CRYPT_INVALID_ARG; 34 | } 35 | XMEMCPY(cbc->IV, IV, len); 36 | return CRYPT_OK; 37 | } 38 | 39 | #endif 40 | 41 | 42 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_setiv.c,v $ */ 43 | /* $Revision: 1.6 $ */ 44 | /* $Date: 2006/12/28 01:27:24 $ */ 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/cfb/cfb_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file cfb_done.c 15 | CFB implementation, finish chain, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CFB_MODE 19 | 20 | /** Terminate the chain 21 | @param cfb The CFB chain to terminate 22 | @return CRYPT_OK on success 23 | */ 24 | int cfb_done(symmetric_CFB *cfb) 25 | { 26 | int err; 27 | LTC_ARGCHK(cfb != NULL); 28 | 29 | if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) { 30 | return err; 31 | } 32 | cipher_descriptor[cfb->cipher].done(&cfb->key); 33 | return CRYPT_OK; 34 | } 35 | 36 | 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_done.c,v $ */ 41 | /* $Revision: 1.7 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/cfb/cfb_getiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file cfb_getiv.c 15 | CFB implementation, get IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CFB_MODE 19 | 20 | /** 21 | Get the current initial vector 22 | @param IV [out] The destination of the initial vector 23 | @param len [in/out] The max size and resulting size of the initial vector 24 | @param cfb The CFB state 25 | @return CRYPT_OK if successful 26 | */ 27 | int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb) 28 | { 29 | LTC_ARGCHK(IV != NULL); 30 | LTC_ARGCHK(len != NULL); 31 | LTC_ARGCHK(cfb != NULL); 32 | if ((unsigned long)cfb->blocklen > *len) { 33 | *len = cfb->blocklen; 34 | return CRYPT_BUFFER_OVERFLOW; 35 | } 36 | XMEMCPY(IV, cfb->IV, cfb->blocklen); 37 | *len = cfb->blocklen; 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_getiv.c,v $ */ 45 | /* $Revision: 1.7 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/cfb/cfb_setiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file cfb_setiv.c 15 | CFB implementation, set IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CFB_MODE 19 | 20 | /** 21 | Set an initial vector 22 | @param IV The initial vector 23 | @param len The length of the vector (in octets) 24 | @param cfb The CFB state 25 | @return CRYPT_OK if successful 26 | */ 27 | int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb) 28 | { 29 | int err; 30 | 31 | LTC_ARGCHK(IV != NULL); 32 | LTC_ARGCHK(cfb != NULL); 33 | 34 | if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) { 35 | return err; 36 | } 37 | 38 | if (len != (unsigned long)cfb->blocklen) { 39 | return CRYPT_INVALID_ARG; 40 | } 41 | 42 | /* force next block */ 43 | cfb->padlen = 0; 44 | return cipher_descriptor[cfb->cipher].ecb_encrypt(IV, cfb->IV, &cfb->key); 45 | } 46 | 47 | #endif 48 | 49 | 50 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_setiv.c,v $ */ 51 | /* $Revision: 1.7 $ */ 52 | /* $Date: 2006/12/28 01:27:24 $ */ 53 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ctr/ctr_decrypt.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ctr_decrypt.c 15 | CTR implementation, decrypt data, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CTR_MODE 19 | 20 | /** 21 | CTR decrypt 22 | @param ct Ciphertext 23 | @param pt [out] Plaintext 24 | @param len Length of ciphertext (octets) 25 | @param ctr CTR state 26 | @return CRYPT_OK if successful 27 | */ 28 | int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr) 29 | { 30 | LTC_ARGCHK(pt != NULL); 31 | LTC_ARGCHK(ct != NULL); 32 | LTC_ARGCHK(ctr != NULL); 33 | 34 | return ctr_encrypt(ct, pt, len, ctr); 35 | } 36 | 37 | #endif 38 | 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_decrypt.c,v $ */ 41 | /* $Revision: 1.6 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ctr/ctr_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ctr_done.c 15 | CTR implementation, finish chain, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CTR_MODE 19 | 20 | /** Terminate the chain 21 | @param ctr The CTR chain to terminate 22 | @return CRYPT_OK on success 23 | */ 24 | int ctr_done(symmetric_CTR *ctr) 25 | { 26 | int err; 27 | LTC_ARGCHK(ctr != NULL); 28 | 29 | if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) { 30 | return err; 31 | } 32 | cipher_descriptor[ctr->cipher].done(&ctr->key); 33 | return CRYPT_OK; 34 | } 35 | 36 | 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_done.c,v $ */ 41 | /* $Revision: 1.7 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ctr/ctr_getiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ctr_getiv.c 15 | CTR implementation, get IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_CTR_MODE 19 | 20 | /** 21 | Get the current initial vector 22 | @param IV [out] The destination of the initial vector 23 | @param len [in/out] The max size and resulting size of the initial vector 24 | @param ctr The CTR state 25 | @return CRYPT_OK if successful 26 | */ 27 | int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr) 28 | { 29 | LTC_ARGCHK(IV != NULL); 30 | LTC_ARGCHK(len != NULL); 31 | LTC_ARGCHK(ctr != NULL); 32 | if ((unsigned long)ctr->blocklen > *len) { 33 | *len = ctr->blocklen; 34 | return CRYPT_BUFFER_OVERFLOW; 35 | } 36 | XMEMCPY(IV, ctr->ctr, ctr->blocklen); 37 | *len = ctr->blocklen; 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_getiv.c,v $ */ 45 | /* $Revision: 1.7 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ecb/ecb_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ecb_done.c 15 | ECB implementation, finish chain, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_ECB_MODE 19 | 20 | /** Terminate the chain 21 | @param ecb The ECB chain to terminate 22 | @return CRYPT_OK on success 23 | */ 24 | int ecb_done(symmetric_ECB *ecb) 25 | { 26 | int err; 27 | LTC_ARGCHK(ecb != NULL); 28 | 29 | if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) { 30 | return err; 31 | } 32 | cipher_descriptor[ecb->cipher].done(&ecb->key); 33 | return CRYPT_OK; 34 | } 35 | 36 | 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_done.c,v $ */ 41 | /* $Revision: 1.8 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/f8/f8_decrypt.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file f8_decrypt.c 15 | F8 implementation, decrypt data, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_F8_MODE 19 | 20 | /** 21 | F8 decrypt 22 | @param ct Ciphertext 23 | @param pt [out] Plaintext 24 | @param len Length of ciphertext (octets) 25 | @param f8 F8 state 26 | @return CRYPT_OK if successful 27 | */ 28 | int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8) 29 | { 30 | LTC_ARGCHK(pt != NULL); 31 | LTC_ARGCHK(ct != NULL); 32 | LTC_ARGCHK(f8 != NULL); 33 | return f8_encrypt(ct, pt, len, f8); 34 | } 35 | 36 | 37 | #endif 38 | 39 | 40 | 41 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_decrypt.c,v $ */ 42 | /* $Revision: 1.3 $ */ 43 | /* $Date: 2006/12/28 01:27:24 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/f8/f8_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file f8_done.c 15 | F8 implementation, finish chain, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_F8_MODE 19 | 20 | /** Terminate the chain 21 | @param f8 The F8 chain to terminate 22 | @return CRYPT_OK on success 23 | */ 24 | int f8_done(symmetric_F8 *f8) 25 | { 26 | int err; 27 | LTC_ARGCHK(f8 != NULL); 28 | 29 | if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { 30 | return err; 31 | } 32 | cipher_descriptor[f8->cipher].done(&f8->key); 33 | return CRYPT_OK; 34 | } 35 | 36 | 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_done.c,v $ */ 41 | /* $Revision: 1.3 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/f8/f8_getiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ofb_getiv.c 15 | F8 implementation, get IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_F8_MODE 19 | 20 | /** 21 | Get the current initial vector 22 | @param IV [out] The destination of the initial vector 23 | @param len [in/out] The max size and resulting size of the initial vector 24 | @param f8 The F8 state 25 | @return CRYPT_OK if successful 26 | */ 27 | int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8) 28 | { 29 | LTC_ARGCHK(IV != NULL); 30 | LTC_ARGCHK(len != NULL); 31 | LTC_ARGCHK(f8 != NULL); 32 | if ((unsigned long)f8->blocklen > *len) { 33 | *len = f8->blocklen; 34 | return CRYPT_BUFFER_OVERFLOW; 35 | } 36 | XMEMCPY(IV, f8->IV, f8->blocklen); 37 | *len = f8->blocklen; 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_getiv.c,v $ */ 45 | /* $Revision: 1.3 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/f8/f8_setiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file f8_setiv.c 15 | F8 implementation, set IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_F8_MODE 19 | 20 | /** 21 | Set an initial vector 22 | @param IV The initial vector 23 | @param len The length of the vector (in octets) 24 | @param f8 The F8 state 25 | @return CRYPT_OK if successful 26 | */ 27 | int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8) 28 | { 29 | int err; 30 | 31 | LTC_ARGCHK(IV != NULL); 32 | LTC_ARGCHK(f8 != NULL); 33 | 34 | if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { 35 | return err; 36 | } 37 | 38 | if (len != (unsigned long)f8->blocklen) { 39 | return CRYPT_INVALID_ARG; 40 | } 41 | 42 | /* force next block */ 43 | f8->padlen = 0; 44 | return cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->IV, &f8->key); 45 | } 46 | 47 | #endif 48 | 49 | 50 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_setiv.c,v $ */ 51 | /* $Revision: 1.3 $ */ 52 | /* $Date: 2006/12/28 01:27:24 $ */ 53 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/lrw/lrw_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file lrw_done.c 15 | LRW_MODE implementation, Free resources, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_LRW_MODE 19 | 20 | /** 21 | Terminate a LRW state 22 | @param lrw The state to terminate 23 | @return CRYPT_OK if successful 24 | */ 25 | int lrw_done(symmetric_LRW *lrw) 26 | { 27 | int err; 28 | 29 | LTC_ARGCHK(lrw != NULL); 30 | 31 | if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { 32 | return err; 33 | } 34 | cipher_descriptor[lrw->cipher].done(&lrw->key); 35 | 36 | return CRYPT_OK; 37 | } 38 | 39 | #endif 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_done.c,v $ */ 41 | /* $Revision: 1.7 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/lrw/lrw_getiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file lrw_getiv.c 15 | LRW_MODE implementation, Retrieve the current IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_LRW_MODE 19 | 20 | /** 21 | Get the IV for LRW 22 | @param IV [out] The IV, must be 16 octets 23 | @param len Length ... must be at least 16 :-) 24 | @param lrw The LRW state to read 25 | @return CRYPT_OK if successful 26 | */ 27 | int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw) 28 | { 29 | LTC_ARGCHK(IV != NULL); 30 | LTC_ARGCHK(len != NULL); 31 | LTC_ARGCHK(lrw != NULL); 32 | if (*len < 16) { 33 | *len = 16; 34 | return CRYPT_BUFFER_OVERFLOW; 35 | } 36 | 37 | XMEMCPY(IV, lrw->IV, 16); 38 | *len = 16; 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_getiv.c,v $ */ 44 | /* $Revision: 1.10 $ */ 45 | /* $Date: 2006/12/28 01:27:24 $ */ 46 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ofb/ofb_decrypt.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ofb_decrypt.c 15 | OFB implementation, decrypt data, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_OFB_MODE 19 | 20 | /** 21 | OFB decrypt 22 | @param ct Ciphertext 23 | @param pt [out] Plaintext 24 | @param len Length of ciphertext (octets) 25 | @param ofb OFB state 26 | @return CRYPT_OK if successful 27 | */ 28 | int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb) 29 | { 30 | LTC_ARGCHK(pt != NULL); 31 | LTC_ARGCHK(ct != NULL); 32 | LTC_ARGCHK(ofb != NULL); 33 | return ofb_encrypt(ct, pt, len, ofb); 34 | } 35 | 36 | 37 | #endif 38 | 39 | 40 | 41 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_decrypt.c,v $ */ 42 | /* $Revision: 1.6 $ */ 43 | /* $Date: 2006/12/28 01:27:24 $ */ 44 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ofb/ofb_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ofb_done.c 15 | OFB implementation, finish chain, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_OFB_MODE 19 | 20 | /** Terminate the chain 21 | @param ofb The OFB chain to terminate 22 | @return CRYPT_OK on success 23 | */ 24 | int ofb_done(symmetric_OFB *ofb) 25 | { 26 | int err; 27 | LTC_ARGCHK(ofb != NULL); 28 | 29 | if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) { 30 | return err; 31 | } 32 | cipher_descriptor[ofb->cipher].done(&ofb->key); 33 | return CRYPT_OK; 34 | } 35 | 36 | 37 | 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_done.c,v $ */ 41 | /* $Revision: 1.7 $ */ 42 | /* $Date: 2006/12/28 01:27:24 $ */ 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ofb/ofb_getiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ofb_getiv.c 15 | OFB implementation, get IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_OFB_MODE 19 | 20 | /** 21 | Get the current initial vector 22 | @param IV [out] The destination of the initial vector 23 | @param len [in/out] The max size and resulting size of the initial vector 24 | @param ofb The OFB state 25 | @return CRYPT_OK if successful 26 | */ 27 | int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb) 28 | { 29 | LTC_ARGCHK(IV != NULL); 30 | LTC_ARGCHK(len != NULL); 31 | LTC_ARGCHK(ofb != NULL); 32 | if ((unsigned long)ofb->blocklen > *len) { 33 | *len = ofb->blocklen; 34 | return CRYPT_BUFFER_OVERFLOW; 35 | } 36 | XMEMCPY(IV, ofb->IV, ofb->blocklen); 37 | *len = ofb->blocklen; 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_getiv.c,v $ */ 45 | /* $Revision: 1.7 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/ofb/ofb_setiv.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file ofb_setiv.c 15 | OFB implementation, set IV, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_OFB_MODE 19 | 20 | /** 21 | Set an initial vector 22 | @param IV The initial vector 23 | @param len The length of the vector (in octets) 24 | @param ofb The OFB state 25 | @return CRYPT_OK if successful 26 | */ 27 | int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb) 28 | { 29 | int err; 30 | 31 | LTC_ARGCHK(IV != NULL); 32 | LTC_ARGCHK(ofb != NULL); 33 | 34 | if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) { 35 | return err; 36 | } 37 | 38 | if (len != (unsigned long)ofb->blocklen) { 39 | return CRYPT_INVALID_ARG; 40 | } 41 | 42 | /* force next block */ 43 | ofb->padlen = 0; 44 | return cipher_descriptor[ofb->cipher].ecb_encrypt(IV, ofb->IV, &ofb->key); 45 | } 46 | 47 | #endif 48 | 49 | 50 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_setiv.c,v $ */ 51 | /* $Revision: 1.7 $ */ 52 | /* $Date: 2006/12/28 01:27:24 $ */ 53 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/xts/xts_done.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects 15 | */ 16 | 17 | #ifdef LTC_XTS_MODE 18 | 19 | /** Terminate XTS state 20 | @param XTS The state to terminate 21 | */ 22 | void xts_done(symmetric_xts *xts) 23 | { 24 | LTC_ARGCHKVD(xts != NULL); 25 | cipher_descriptor[xts->cipher].done(&xts->key1); 26 | cipher_descriptor[xts->cipher].done(&xts->key2); 27 | } 28 | 29 | #endif 30 | 31 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/xts/xts_done.c,v $ */ 32 | /* $Revision: 1.4 $ */ 33 | /* $Date: 2007/03/10 23:59:09 $ */ 34 | 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/modes/xts/xts_mult_x.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects 15 | */ 16 | 17 | #ifdef LTC_XTS_MODE 18 | 19 | /** multiply by x 20 | @param I The value to multiply by x (LFSR shift) 21 | */ 22 | void xts_mult_x(unsigned char *I) 23 | { 24 | int x; 25 | unsigned char t, tt; 26 | 27 | for (x = t = 0; x < 16; x++) { 28 | tt = I[x] >> 7; 29 | I[x] = ((I[x] << 1) | t) & 0xFF; 30 | t = tt; 31 | } 32 | if (tt) { 33 | I[0] ^= 0x87; 34 | } 35 | } 36 | 37 | #endif 38 | 39 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/xts/xts_mult_x.c,v $ */ 40 | /* $Revision: 1.4 $ */ 41 | /* $Date: 2007/03/10 23:59:09 $ */ 42 | 43 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/asn1/der/boolean/der_decode_boolean.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file der_decode_boolean.c 15 | ASN.1 DER, decode a BOOLEAN, Tom St Denis 16 | */ 17 | 18 | 19 | #ifdef LTC_DER 20 | 21 | /** 22 | Read a BOOLEAN 23 | @param in The destination for the DER encoded BOOLEAN 24 | @param inlen The size of the DER BOOLEAN 25 | @param out [out] The boolean to decode 26 | @return CRYPT_OK if successful 27 | */ 28 | int der_decode_boolean(const unsigned char *in, unsigned long inlen, 29 | int *out) 30 | { 31 | LTC_ARGCHK(in != NULL); 32 | LTC_ARGCHK(out != NULL); 33 | 34 | if (inlen != 3 || in[0] != 0x01 || in[1] != 0x01 || (in[2] != 0x00 && in[2] != 0xFF)) { 35 | return CRYPT_INVALID_ARG; 36 | } 37 | 38 | *out = (in[2]==0xFF) ? 1 : 0; 39 | 40 | return CRYPT_OK; 41 | } 42 | 43 | #endif 44 | 45 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_decode_boolean.c,v $ */ 46 | /* $Revision: 1.2 $ */ 47 | /* $Date: 2006/12/28 01:27:24 $ */ 48 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/asn1/der/boolean/der_encode_boolean.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file der_encode_boolean.c 15 | ASN.1 DER, encode a BOOLEAN, Tom St Denis 16 | */ 17 | 18 | 19 | #ifdef LTC_DER 20 | 21 | /** 22 | Store a BOOLEAN 23 | @param in The boolean to encode 24 | @param out [out] The destination for the DER encoded BOOLEAN 25 | @param outlen [in/out] The max size and resulting size of the DER BOOLEAN 26 | @return CRYPT_OK if successful 27 | */ 28 | int der_encode_boolean(int in, 29 | unsigned char *out, unsigned long *outlen) 30 | { 31 | LTC_ARGCHK(outlen != NULL); 32 | LTC_ARGCHK(out != NULL); 33 | 34 | if (*outlen < 3) { 35 | *outlen = 3; 36 | return CRYPT_BUFFER_OVERFLOW; 37 | } 38 | 39 | *outlen = 3; 40 | out[0] = 0x01; 41 | out[1] = 0x01; 42 | out[2] = in ? 0xFF : 0x00; 43 | 44 | return CRYPT_OK; 45 | } 46 | 47 | #endif 48 | 49 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_encode_boolean.c,v $ */ 50 | /* $Revision: 1.4 $ */ 51 | /* $Date: 2006/12/28 01:27:24 $ */ 52 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/asn1/der/boolean/der_length_boolean.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file der_length_boolean.c 15 | ASN.1 DER, get length of a BOOLEAN, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_DER 19 | /** 20 | Gets length of DER encoding of a BOOLEAN 21 | @param outlen [out] The length of the DER encoding 22 | @return CRYPT_OK if successful 23 | */ 24 | int der_length_boolean(unsigned long *outlen) 25 | { 26 | LTC_ARGCHK(outlen != NULL); 27 | *outlen = 3; 28 | return CRYPT_OK; 29 | } 30 | 31 | #endif 32 | 33 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_length_boolean.c,v $ */ 34 | /* $Revision: 1.3 $ */ 35 | /* $Date: 2006/12/28 01:27:24 $ */ 36 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/asn1/der/utctime/der_length_utctime.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file der_length_utctime.c 15 | ASN.1 DER, get length of UTCTIME, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_DER 19 | 20 | /** 21 | Gets length of DER encoding of UTCTIME 22 | @param utctime The UTC time structure to get the size of 23 | @param outlen [out] The length of the DER encoding 24 | @return CRYPT_OK if successful 25 | */ 26 | int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen) 27 | { 28 | LTC_ARGCHK(outlen != NULL); 29 | LTC_ARGCHK(utctime != NULL); 30 | 31 | if (utctime->off_hh == 0 && utctime->off_mm == 0) { 32 | /* we encode as YYMMDDhhmmssZ */ 33 | *outlen = 2 + 13; 34 | } else { 35 | /* we encode as YYMMDDhhmmss{+|-}hh'mm' */ 36 | *outlen = 2 + 17; 37 | } 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_length_utctime.c,v $ */ 45 | /* $Revision: 1.5 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/dsa/dsa_free.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file dsa_free.c 15 | DSA implementation, free a DSA key, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_MDSA 19 | 20 | /** 21 | Free a DSA key 22 | @param key The key to free from memory 23 | */ 24 | void dsa_free(dsa_key *key) 25 | { 26 | LTC_ARGCHKVD(key != NULL); 27 | mp_clear_multi(key->g, key->q, key->p, key->x, key->y, NULL); 28 | } 29 | 30 | #endif 31 | 32 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_free.c,v $ */ 33 | /* $Revision: 1.8 $ */ 34 | /* $Date: 2007/05/12 14:32:35 $ */ 35 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/ecc/ecc_free.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 13 | * 14 | * All curves taken from NIST recommendation paper of July 1999 15 | * Available at http://csrc.nist.gov/cryptval/dss.htm 16 | */ 17 | #include "tomcrypt.h" 18 | 19 | /** 20 | @file ecc_free.c 21 | ECC Crypto, Tom St Denis 22 | */ 23 | 24 | #ifdef LTC_MECC 25 | 26 | /** 27 | Free an ECC key from memory 28 | @param key The key you wish to free 29 | */ 30 | void ecc_free(ecc_key *key) 31 | { 32 | LTC_ARGCHKVD(key != NULL); 33 | mp_clear_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL); 34 | } 35 | 36 | #endif 37 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_free.c,v $ */ 38 | /* $Revision: 1.6 $ */ 39 | /* $Date: 2007/05/12 14:32:35 $ */ 40 | 41 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/ecc/ecc_get_size.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 13 | * 14 | * All curves taken from NIST recommendation paper of July 1999 15 | * Available at http://csrc.nist.gov/cryptval/dss.htm 16 | */ 17 | #include "tomcrypt.h" 18 | 19 | /** 20 | @file ecc_get_size.c 21 | ECC Crypto, Tom St Denis 22 | */ 23 | 24 | #ifdef LTC_MECC 25 | 26 | /** 27 | Get the size of an ECC key 28 | @param key The key to get the size of 29 | @return The size (octets) of the key or INT_MAX on error 30 | */ 31 | int ecc_get_size(ecc_key *key) 32 | { 33 | LTC_ARGCHK(key != NULL); 34 | if (ltc_ecc_is_valid_idx(key->idx)) 35 | return key->dp->size; 36 | else 37 | return INT_MAX; /* large value known to cause it to fail when passed to ecc_make_key() */ 38 | } 39 | 40 | #endif 41 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_get_size.c,v $ */ 42 | /* $Revision: 1.6 $ */ 43 | /* $Date: 2007/05/12 14:32:35 $ */ 44 | 45 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/ecc/ecc_sizes.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 13 | * 14 | * All curves taken from NIST recommendation paper of July 1999 15 | * Available at http://csrc.nist.gov/cryptval/dss.htm 16 | */ 17 | #include "tomcrypt.h" 18 | 19 | /** 20 | @file ecc_sizes.c 21 | ECC Crypto, Tom St Denis 22 | */ 23 | 24 | #ifdef LTC_MECC 25 | 26 | void ecc_sizes(int *low, int *high) 27 | { 28 | int i; 29 | LTC_ARGCHKVD(low != NULL); 30 | LTC_ARGCHKVD(high != NULL); 31 | 32 | *low = INT_MAX; 33 | *high = 0; 34 | for (i = 0; ltc_ecc_sets[i].size != 0; i++) { 35 | if (ltc_ecc_sets[i].size < *low) { 36 | *low = ltc_ecc_sets[i].size; 37 | } 38 | if (ltc_ecc_sets[i].size > *high) { 39 | *high = ltc_ecc_sets[i].size; 40 | } 41 | } 42 | } 43 | 44 | #endif 45 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_sizes.c,v $ */ 46 | /* $Revision: 1.6 $ */ 47 | /* $Date: 2007/05/12 14:32:35 $ */ 48 | 49 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/ecc/ltc_ecc_is_valid_idx.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 13 | * 14 | * All curves taken from NIST recommendation paper of July 1999 15 | * Available at http://csrc.nist.gov/cryptval/dss.htm 16 | */ 17 | #include "tomcrypt.h" 18 | 19 | /** 20 | @file ltc_ecc_is_valid_idx.c 21 | ECC Crypto, Tom St Denis 22 | */ 23 | 24 | #ifdef LTC_MECC 25 | 26 | /** Returns whether an ECC idx is valid or not 27 | @param n The idx number to check 28 | @return 1 if valid, 0 if not 29 | */ 30 | int ltc_ecc_is_valid_idx(int n) 31 | { 32 | int x; 33 | 34 | for (x = 0; ltc_ecc_sets[x].size != 0; x++); 35 | /* -1 is a valid index --- indicating that the domain params were supplied by the user */ 36 | if ((n >= -1) && (n < x)) { 37 | return 1; 38 | } 39 | return 0; 40 | } 41 | 42 | #endif 43 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ltc_ecc_is_valid_idx.c,v $ */ 44 | /* $Revision: 1.7 $ */ 45 | /* $Date: 2007/05/12 14:32:35 $ */ 46 | 47 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/katja/katja_free.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file katja_free.c 15 | Free an Katja key, Tom St Denis 16 | */ 17 | 18 | #ifdef MKAT 19 | 20 | /** 21 | Free an Katja key from memory 22 | @param key The RSA key to free 23 | */ 24 | void katja_free(katja_key *key) 25 | { 26 | LTC_ARGCHK(key != NULL); 27 | mp_clear_multi( key->d, key->N, key->dQ, key->dP, 28 | key->qP, key->p, key->q, key->pq, NULL); 29 | } 30 | 31 | #endif 32 | 33 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/katja/katja_free.c,v $ */ 34 | /* $Revision: 1.3 $ */ 35 | /* $Date: 2006/12/28 01:27:24 $ */ 36 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/pkcs1/pkcs_1_i2osp.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file pkcs_1_i2osp.c 15 | Integer to Octet I2OSP, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_PKCS_1 19 | 20 | /* always stores the same # of bytes, pads with leading zero bytes 21 | as required 22 | */ 23 | 24 | /** 25 | LTC_PKCS #1 Integer to binary 26 | @param n The integer to store 27 | @param modulus_len The length of the RSA modulus 28 | @param out [out] The destination for the integer 29 | @return CRYPT_OK if successful 30 | */ 31 | int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out) 32 | { 33 | unsigned long size; 34 | 35 | size = mp_unsigned_bin_size(n); 36 | 37 | if (size > modulus_len) { 38 | return CRYPT_BUFFER_OVERFLOW; 39 | } 40 | 41 | /* store it */ 42 | zeromem(out, modulus_len); 43 | return mp_to_unsigned_bin(n, out+(modulus_len-size)); 44 | } 45 | 46 | #endif /* LTC_PKCS_1 */ 47 | 48 | 49 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_i2osp.c,v $ */ 50 | /* $Revision: 1.7 $ */ 51 | /* $Date: 2007/05/12 14:32:35 $ */ 52 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/pkcs1/pkcs_1_os2ip.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file pkcs_1_os2ip.c 15 | Octet to Integer OS2IP, Tom St Denis 16 | */ 17 | #ifdef LTC_PKCS_1 18 | 19 | /** 20 | Read a binary string into an mp_int 21 | @param n [out] The mp_int destination 22 | @param in The binary string to read 23 | @param inlen The length of the binary string 24 | @return CRYPT_OK if successful 25 | */ 26 | int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen) 27 | { 28 | return mp_read_unsigned_bin(n, in, inlen); 29 | } 30 | 31 | #endif /* LTC_PKCS_1 */ 32 | 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_os2ip.c,v $ */ 35 | /* $Revision: 1.7 $ */ 36 | /* $Date: 2007/05/12 14:32:35 $ */ 37 | -------------------------------------------------------------------------------- /lib_tomcrypt/pk/rsa/rsa_free.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file rsa_free.c 15 | Free an RSA key, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_MRSA 19 | 20 | /** 21 | Free an RSA key from memory 22 | @param key The RSA key to free 23 | */ 24 | void rsa_free(rsa_key *key) 25 | { 26 | LTC_ARGCHKVD(key != NULL); 27 | mp_clear_multi(key->e, key->d, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL); 28 | } 29 | 30 | #endif 31 | 32 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_free.c,v $ */ 33 | /* $Revision: 1.10 $ */ 34 | /* $Date: 2007/05/12 14:32:35 $ */ 35 | -------------------------------------------------------------------------------- /pbsv_exec/makedll32: -------------------------------------------------------------------------------- 1 | gcc -m32 -Wall -fPIC -g -c pbsv.c 2 | gcc -m32 -shared -Wl,-soname,pbsv.so -o pbsv.so *.o 3 | -------------------------------------------------------------------------------- /plugins/antikoncept/antikoncept.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/plugins/antikoncept/antikoncept.so -------------------------------------------------------------------------------- /plugins/antikoncept/antikoncept_plugin.c: -------------------------------------------------------------------------------- 1 | #include "../pinc.h" 2 | PCL int OnInit(){ // Funciton called on server initiation 3 | // Load function pointers 4 | // Function pointers loaded, add your plugin's content here 5 | return 0; 6 | } 7 | 8 | PCL void OnMessageSent(char *message, int slot, qboolean *show, int mode){ 9 | if(strstr(message, "^7just got owned by ^2k^7oncept COD4")){ 10 | Plugin_Printf("[Anti Koncept] Koncept CoD4 Detected! (Client: %s, Message: \"%s\")\n",Plugin_GetPlayerName(slot), message); 11 | Plugin_G_LogPrintf("[Anti Koncept] Koncept CoD4 Detected! (Client: %s %s, Message: \"%s\")\n",Plugin_GetPlayerName(slot),Plugin_GetPlayerGUID(slot), message); 12 | Plugin_BanClient( slot, -1, 0, "Koncept Detected (Autoban)" ); 13 | } 14 | } 15 | PCL void OnInfoRequest(pluginInfo_t *info){ // Function used to obtain information about the plugin 16 | // Memory pointed by info is allocated by the server binary, just fill in the fields 17 | 18 | // ===== MANDATORY FIELDS ===== 19 | info->handlerVersion.major = PLUGIN_HANDLER_VERSION_MAJOR; 20 | info->handlerVersion.minor = PLUGIN_HANDLER_VERSION_MINOR; // Requested handler version 21 | // Requested handler version 22 | 23 | // ===== OPTIONAL FIELDS ===== 24 | info->pluginVersion.major = 1; 25 | info->pluginVersion.minor = 1; // Plugin version 26 | strncpy(info->fullName,"Anti Koncept Plugin by NNJ (thecod4ninja)",sizeof(info->fullName)); 27 | } 28 | -------------------------------------------------------------------------------- /plugins/antikoncept/compile.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling: release 4 | gcc -m32 -Wall -O1 -s -march=nocona -c *.c 5 | 6 | echo Linking 7 | gcc -m32 -s -shared -o antikoncept.dll *.o -L..\ -lcom_plugin 8 | echo Cleaning up 9 | del *.o 10 | 11 | pause 12 | -------------------------------------------------------------------------------- /plugins/antikoncept/compile.sh: -------------------------------------------------------------------------------- 1 | gcc -g -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c 2 | 3 | gcc -m32 -s -shared -fvisibility=hidden -o antikoncept.so *.o 4 | rm *.o 5 | -------------------------------------------------------------------------------- /plugins/antikoncept/makedll.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling: release 4 | gcc -m32 -Wall -O1 -s -march=nocona -c *.c 5 | 6 | echo Linking 7 | gcc -m32 -s -shared -o clantp.dll *.o -L..\ -lcom_plugin 8 | echo Cleaning up 9 | del *.o 10 | 11 | pause 12 | -------------------------------------------------------------------------------- /plugins/antikoncept/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='clantp' 3 | 4 | #Compiling: debugging 5 | #echo `gcc -g -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c` 6 | 7 | #Compiling: release 8 | echo `gcc -m32 -Wall -O1 -s -fvisibility=hidden -mtune=prescott -c *.c` 9 | 10 | #Linking 11 | echo `gcc -m32 -s -shared -fvisibility=hidden -o $NAME''.so *.o` 12 | 13 | #Cleaning up 14 | echo `rm *.o` 15 | -------------------------------------------------------------------------------- /plugins/antinamechange/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='antinamechange' 3 | 4 | #Compiling: release 5 | echo `gcc -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c` 6 | 7 | #Linking 8 | echo `gcc -m32 -s -shared -fvisibility=hidden -o $NAME''.so *.o` 9 | 10 | #Cleaning up 11 | echo `rm *.o` 12 | -------------------------------------------------------------------------------- /plugins/antinamechange/makedll_win32.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling: release 4 | gcc -m32 -Wall -O1 -s -march=nocona -c *.c 5 | 6 | echo Linking 7 | gcc -m32 -s -shared -o antinamespoof.dll *.o -L..\ -lcom_plugin 8 | echo Cleaning up 9 | del *.o 10 | 11 | pause 12 | -------------------------------------------------------------------------------- /plugins/antinamesteal/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='antinamesteal' 3 | 4 | #Compiling: release 5 | echo `gcc -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c` 6 | 7 | #Linking 8 | echo `gcc -m32 -s -shared -fvisibility=hidden -o $NAME''.so *.o` 9 | 10 | #Cleaning up 11 | echo `rm *.o` 12 | -------------------------------------------------------------------------------- /plugins/antinamesteal/makedll_win32: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling: release 4 | gcc -m32 -Wall -O1 -s -march=nocona -c *.c 5 | 6 | echo Linking 7 | gcc -m32 -s -shared -o antinamesteal.dll *.o -L..\ -lcom_plugin 8 | echo Cleaning up 9 | del *.o 10 | 11 | pause 12 | -------------------------------------------------------------------------------- /plugins/antispam/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='antispam' 3 | 4 | #Compiling: release 5 | echo `gcc -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c` 6 | 7 | #Linking 8 | echo `gcc -m32 -s -shared -fvisibility=hidden -o $NAME''.so *.o` 9 | 10 | #Cleaning up 11 | echo `rm *.o` 12 | -------------------------------------------------------------------------------- /plugins/antispam/makedll_win32.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling: release 4 | gcc -m32 -Wall -O1 -s -mtune=core2 -c *.c 5 | 6 | echo Linking 7 | gcc -m32 -s -shared -o antispam.dll *.o -L..\ -lcom_plugin 8 | echo Cleaning up 9 | del *.o 10 | 11 | pause 12 | -------------------------------------------------------------------------------- /plugins/censor/censor.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 4 | 5 | This file is part of IceOps Plugin Handler source code. 6 | 7 | IceOps Plugin Handler source code is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Affero General Public License as 9 | published by the Free Software Foundation, either version 3 of the 10 | License, or (at your option) any later version. 11 | 12 | IceOps Plugin Handler source code is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Affero General Public License for more details. 16 | 17 | You should have received a copy of the GNU Affero General Public License 18 | along with this program. If not, see 19 | =========================================================================== 20 | */ 21 | 22 | void G_SayCensor_Init(void); 23 | char* G_SayCensor(char *msg); 24 | 25 | 26 | #define DLL_PUBLIC __attribute__ ((visibility ("default"))) __attribute__ ((cdecl)) 27 | #define DLL_LOCAL __attribute__ ((visibility ("hidden"))) 28 | -------------------------------------------------------------------------------- /plugins/censor/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='censor' 3 | 4 | #Compiling: debugging 5 | #echo `gcc -g -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c` 6 | 7 | #Compiling: release 8 | echo `gcc -m32 -Wall -O1 -s -fvisibility=hidden -mtune=prescott -c *.c` 9 | 10 | #Linking 11 | echo `gcc -m32 -s -shared -fvisibility=hidden -o $NAME''.so *.o` 12 | 13 | #Cleaning up 14 | echo `rm *.o` 15 | -------------------------------------------------------------------------------- /plugins/censor/makedll_win32.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Compiling: debugging 4 | REM echo `gcc -g -m32 -Wall -O1 -s -mtune=core2 -c *.c` 5 | 6 | echo Compiling: release 7 | gcc -m32 -Wall -O1 -s -mtune=core2 -c *.c 8 | 9 | echo Linking 10 | gcc -m32 -s -shared -o censor.dll *.o -L..\ -lcom_plugin 11 | echo Cleaning up 12 | del *.o 13 | 14 | pause 15 | -------------------------------------------------------------------------------- /plugins/clan-tag-protection/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='clanP' 3 | 4 | #Compiling: release 5 | echo `gcc -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.c` 6 | 7 | #Linking 8 | echo `gcc -m32 -s -shared -fvisibility=hidden -o $NAME''.so *.o` 9 | 10 | #Cleaning up 11 | echo `rm *.o` 12 | -------------------------------------------------------------------------------- /plugins/clan-tag-protection/makedll_win32: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling: release 4 | gcc -m32 -Wall -O1 -s -mtune=core2 -c *.c 5 | 6 | echo Linking 7 | gcc -m32 -s -shared -o clanP.dll *.o -L..\ -lcom_plugin 8 | echo Cleaning up 9 | del *.o 10 | 11 | pause 12 | -------------------------------------------------------------------------------- /plugins/cpptest/cpptest.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/plugins/cpptest/cpptest.so -------------------------------------------------------------------------------- /plugins/cpptest/makedll32: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | NAME='cpptest' 3 | 4 | #Compiling: debugging 5 | echo `g++ -g -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.cpp` 6 | 7 | #Compiling: release 8 | #echo `g++ -m32 -Wall -O1 -s -fvisibility=hidden -mtune=core2 -c *.cpp` 9 | 10 | #Linking 11 | echo `g++ -m32 -shared -fvisibility=hidden -o $NAME''.so *.o` 12 | 13 | #Cleaning up 14 | echo `rm *.o` 15 | -------------------------------------------------------------------------------- /src/cmd_hooks.asm: -------------------------------------------------------------------------------- 1 | ;=========================================================================== 2 | ; Copyright (c) 2015-2019 atrX of Raid Gaming 3 | ; Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 4 | 5 | ; This file is part of CoD4-Unleashed-Server source code. 6 | 7 | ; CoD4-Unleashed-Server source code is free software: you can redistribute it and/or modify 8 | ; it under the terms of the GNU Affero General Public License as 9 | ; published by the Free Software Foundation, either version 3 of the 10 | ; License, or (at your option) any later version. 11 | 12 | ; CoD4-Unleashed-Server source code is distributed in the hope that it will be useful, 13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ; GNU Affero General Public License for more details. 16 | 17 | ; You should have received a copy of the GNU Affero General Public License 18 | ; along with this program. If not, see 19 | ;=========================================================================== 20 | 21 | 22 | SECTION .text 23 | 24 | global SV_Cmd_TokenizeString 25 | SV_Cmd_TokenizeString: 26 | jmp dword [oSV_Cmd_TokenizeString] 27 | 28 | global SV_Cmd_EndTokenizedString 29 | SV_Cmd_EndTokenizedString: 30 | jmp dword [oSV_Cmd_EndTokenizedString] 31 | 32 | SECTION .rodata 33 | oSV_Cmd_TokenizeString dd 0x811139c 34 | oSV_Cmd_EndTokenizedString dd 0x8110d8c 35 | -------------------------------------------------------------------------------- /src/functions/client.c: -------------------------------------------------------------------------------- 1 | #include "client.h" 2 | 3 | void PlayerCmd_GetProtocolVersion(scr_entref_t arg) { 4 | gentity_t* gentity; 5 | int entityNum = 0; 6 | mvabuf; 7 | 8 | if (HIWORD(arg)) { 9 | Scr_ObjectError("Not an entity"); 10 | } else { 11 | entityNum = LOWORD(arg); 12 | gentity = &g_entities[entityNum]; 13 | 14 | if (!gentity->client) { 15 | Scr_ObjectError(va("Entity: %i is not a player", entityNum)); 16 | } 17 | } 18 | 19 | client_t* cl = &svs.clients[entityNum]; 20 | Scr_AddInt(cl->protocol); 21 | } 22 | -------------------------------------------------------------------------------- /src/functions/client.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "../scr_vm.h" 5 | #include "../server.h" 6 | 7 | void PlayerCmd_GetProtocolVersion(scr_entref_t arg); 8 | -------------------------------------------------------------------------------- /src/functions/functions.h: -------------------------------------------------------------------------------- 1 | #include "client.h" 2 | #include "http.h" 3 | #include "types.h" 4 | -------------------------------------------------------------------------------- /src/functions/http.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "../qcommon_io.h" 5 | #include "../scr_vm.h" 6 | 7 | typedef struct { 8 | char* buffer; 9 | size_t len; 10 | } StringBuffer; 11 | 12 | StringBuffer initStringBuffer(); 13 | void freeStringBuffer(StringBuffer*); 14 | 15 | void initHttpModule(); 16 | void unloadHttpModule(); 17 | 18 | size_t curlWriteCallback(void*, size_t, size_t, void*); 19 | 20 | void curlRequest(char*, char*, char*, unsigned int); 21 | 22 | void GScr_HttpGet(); 23 | void GScr_HttpPost(); 24 | void GScr_HttpPut(); 25 | void GScr_HttpPatch(); 26 | void GScr_HttpDelete(); 27 | void GScr_HttpRequest(); 28 | -------------------------------------------------------------------------------- /src/functions/types.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "../qcommon_io.h" 6 | #include "../scr_vm.h" 7 | 8 | void GScr_getTypeIndex(); 9 | void GScr_getType(); 10 | void isCheck(int condition, char* funcName); 11 | void GScr_isFunction(); 12 | void GScr_isLocalizedString(); 13 | void GScr_isInt(); 14 | void GScr_isFloat(); 15 | void GScr_isBool(); 16 | void GScr_isObject(); 17 | void GScr_isVector(); 18 | -------------------------------------------------------------------------------- /src/httprequest.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Argument struct holding data required to send an asynchronous POST request 5 | typedef struct { 6 | // POST request info 7 | char host[64]; 8 | char port[5]; 9 | char path[128]; 10 | char data[4096]; 11 | 12 | // Server response 13 | char getResponse[1]; 14 | char response[4096]; 15 | } asyncPostRequestArgs; 16 | 17 | void* processAsyncPostRequest(void* args); 18 | char* asyncPostRequest(char* host, int port, char* path, char* data, 19 | int getResponse); 20 | -------------------------------------------------------------------------------- /src/maxmind_geoip.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | unsigned int _GeoIP_seek_record(unsigned long ipnum); 25 | const char* _GeoIP_country_code(unsigned int index); 26 | const char* _GeoIP_country_code3(unsigned int index); 27 | const char* _GeoIP_country_name(unsigned int index); 28 | const char* _GeoIP_continent_name(unsigned int index); 29 | -------------------------------------------------------------------------------- /src/murmurhash1.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash1 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | 5 | #ifndef _MURMURHASH1_H_ 6 | #define _MURMURHASH1_H_ 7 | 8 | #include 9 | 10 | //----------------------------------------------------------------------------- 11 | 12 | uint32_t MurmurHash1(const void* key, int len, uint32_t seed); 13 | uint32_t MurmurHash1Aligned(const void* key, int len, uint32_t seed); 14 | 15 | //----------------------------------------------------------------------------- 16 | 17 | #endif // _MURMURHASH1_H_ 18 | -------------------------------------------------------------------------------- /src/nvconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | #ifndef __NVCONFIG_H__ 25 | #define __NVCONFIG_H__ 26 | 27 | #define NV_ProcessBegin NV_LoadConfig 28 | #define NV_ProcessEnd NV_WriteConfig 29 | 30 | void NV_LoadConfig(); 31 | void NV_WriteConfig(); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/objfile_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | #ifndef __OBJFILE_PARSER_H__ 25 | #define __OBJFILE_PARSER_H__ 26 | typedef struct { 27 | long size; 28 | long offset; 29 | } sharedlib_data_t; 30 | 31 | char** GetStrTable(void* fbuf, int len, sharedlib_data_t* text); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/plugin_crypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | #include "../lib_tomcrypt/main.h" 25 | #include "plugin_handler.h" 26 | 27 | qboolean PHandler_Hash(pluginHash_t algo, void* in, size_t inSize, void* out, 28 | size_t outSize); 29 | -------------------------------------------------------------------------------- /src/qcommon_logprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | #ifndef __QCOMMON_LOGPRINT_H__ 25 | #define __QCOMMON_LOGPRINT_H__ 26 | 27 | #include "q_shared.h" 28 | 29 | void QDECL SV_EnterLeaveLog(const char* fmt, ...); 30 | void QDECL Com_PrintAdministrativeLog(const char* msg); 31 | void Com_PrintLogfile(const char* msg); 32 | void Com_CloseLogFiles(void); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/qcommon_parsecmdline.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | #ifndef __COMMON_PARSECMDLINE_H__ 25 | #define __COMMON_PARSECMDLINE_H__ 26 | 27 | #include "q_shared.h" 28 | 29 | void Com_StartupVariable(const char* match); 30 | qboolean Com_AddStartupCommands(void); 31 | void Com_ParseCommandLine(char* commandLine); 32 | qboolean Com_SafeMode(void); 33 | #endif 34 | -------------------------------------------------------------------------------- /src/sec_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | 24 | #include "sec_common.h" 25 | #include 26 | #include 27 | 28 | void* Sec_Malloc(size_t size) { 29 | void* ptr = malloc(size); 30 | if (ptr == NULL) { 31 | printf("ERROR: Sec_Malloc - No memory!\nTerminating...\n"); 32 | exit(666); // Because lack of memory is EVIL! 33 | } 34 | return ptr; 35 | } 36 | -------------------------------------------------------------------------------- /src/sec_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | #ifndef SEC_INIT_H 24 | #define SEC_INIT_H 25 | 26 | #include "sec_sign.h" 27 | #include "sec_update.h" 28 | 29 | void Sec_Init(void); 30 | qboolean Sec_Initialized(); 31 | #endif 32 | -------------------------------------------------------------------------------- /src/sec_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (c) 2015-2019 atrX of Raid Gaming 4 | Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team 5 | Copyright (C) 1999-2005 Id Software, Inc. 6 | 7 | This file is part of CoD4-Unleashed-Server source code. 8 | 9 | CoD4-Unleashed-Server source code is free software: you can redistribute it 10 | and/or modify it under the terms of the GNU Affero General Public License as 11 | published by the Free Software Foundation, either version 3 of the 12 | License, or (at your option) any later version. 13 | 14 | CoD4-Unleashed-Server source code is distributed in the hope that it will be 15 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see 21 | =========================================================================== 22 | */ 23 | #ifndef SEC_MAIN_H 24 | #define SEC_MAIN_H 25 | 26 | #include "../lib_tomcrypt/main.h" 27 | #include "q_shared.h" 28 | #include "qcommon_io.h" 29 | #include "sec_common.h" 30 | #include "sec_crypto.h" 31 | #include "sec_init.h" 32 | extern int SecCryptErr; 33 | char* Sec_CryptErrStr(int); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/sha.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void sha_transform(uint32_t* digest, const char* in, uint32_t* W); 4 | void sha_init(uint32_t* buf); 5 | -------------------------------------------------------------------------------- /src/sha256.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FIPS-180-2 compliant SHA-256 implementation 3 | * 4 | * Copyright (C) 2001-2003 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef _SHA256_H 22 | #define _SHA256_H 23 | #include 24 | 25 | const char* Com_SHA256(const char*); 26 | 27 | #endif /* sha256.h */ 28 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | #define BUILD_NUMBER 3663 2 | -------------------------------------------------------------------------------- /src/webadmin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * webadmin.h 3 | * CoD4U_testing 4 | * 5 | * Created by Florian on 5/23/14. 6 | * Copyright 2014 Dorg. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "cmd.h" 11 | #include "filesystem.h" 12 | #include "g_shared.h" 13 | #include "g_sv_shared.h" 14 | #include "httpftp.h" 15 | #include "msg.h" 16 | #include "q_shared.h" 17 | #include "qcommon_io.h" 18 | #include "qcommon_mem.h" 19 | #include "server.h" 20 | #include "sv_auth.h" 21 | 22 | #include 23 | 24 | qboolean HTTPCreateWebadminMessage(ftRequest_t* request, msg_t* msg, 25 | char* sessionkey, httpPostVals_t* values); 26 | -------------------------------------------------------------------------------- /src/win32/win32_usleep.c: -------------------------------------------------------------------------------- 1 | #include "win32_usleep.h" 2 | #include 3 | 4 | void _usleep(unsigned int usec) { 5 | HANDLE timer; 6 | LARGE_INTEGER ft; 7 | 8 | ft.QuadPart = -(10 * (__int64)usec); 9 | 10 | timer = CreateWaitableTimer(NULL, TRUE, NULL); 11 | SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); 12 | WaitForSingleObject(timer, INFINITE); 13 | CloseHandle(timer); 14 | } 15 | -------------------------------------------------------------------------------- /src/win32/win32_usleep.h: -------------------------------------------------------------------------------- 1 | void _usleep(unsigned int usec); 2 | -------------------------------------------------------------------------------- /src/win32/win_cod4.rc: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Icon 4 | // 5 | 6 | #define IDS_STRING1 1 7 | #define IDI_ICON1 1 8 | 9 | // Icon with lowest ID value placed first to ensure application icon 10 | // remains consistent on all systems. 11 | IDI_ICON1 ICON DISCARDABLE "cod4.ico" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // 15 | // String Table 16 | // 17 | 18 | STRINGTABLE DISCARDABLE 19 | BEGIN 20 | IDS_STRING1 "CallofDuty4" 21 | END 22 | -------------------------------------------------------------------------------- /src/win32/win_cod4.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raid-Gaming/CoD4-Unleashed-Server/8631226305408ba87d8c0281d9288212b9953510/src/win32/win_cod4.res -------------------------------------------------------------------------------- /src/yyparse.c: -------------------------------------------------------------------------------- 1 | #include "q_shared.h" 2 | #include 3 | #include 4 | 5 | typedef struct { 6 | FILE* yy_input_file; 7 | byte* yy_ch_buf; 8 | byte* yy_buf_pos; 9 | int yy_buf_size; 10 | int yy_n_chars; 11 | int yy_is_our_buffer; 12 | int yy_is_interactive; 13 | int yy_at_bol; 14 | int yy_fill_buffer; 15 | int yy_buffer_status; 16 | } yy_buffer_state; 17 | 18 | yy_buffer_state* __cdecl yy_create_buffer(FILE* file, int bufferSize) { 19 | yy_buffer_state* yybufState; 20 | 21 | yybufState = (yy_buffer_state*)malloc(sizeof(yy_buffer_state)); 22 | if (yybufState == NULL) { 23 | Com_Error(ERR_FATAL, "out of dynamic memory in yy_create_buffer()"); 24 | return NULL; 25 | } 26 | 27 | yybufState->yy_buf_size = bufferSize; 28 | 29 | yybufState->yy_ch_buf = malloc(bufferSize + 2); 30 | 31 | if (yybufState->yy_ch_buf == NULL) { 32 | Com_Error(ERR_FATAL, "out of dynamic memory in yy_create_buffer()"); 33 | return NULL; 34 | } 35 | 36 | yybufState->yy_is_our_buffer = 1; 37 | yybufState->yy_n_chars = 0; 38 | yybufState->yy_ch_buf[0] = 0; 39 | yybufState->yy_ch_buf[1] = 0; 40 | yybufState->yy_buf_pos = yybufState->yy_ch_buf; 41 | yybufState->yy_at_bol = 1; 42 | yybufState->yy_buffer_status = 0; 43 | 44 | yybufState->yy_input_file = file; 45 | yybufState->yy_fill_buffer = 1; 46 | yybufState->yy_is_interactive = 0; 47 | return yybufState; 48 | } 49 | -------------------------------------------------------------------------------- /tools/asm_objdump_converter.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | del *.o 3 | gcc -m32 -Wall -g -c asm_objdump_converter.c 4 | gcc -m32 -Wl -o asm_objdump_converter *.o 5 | pause 6 | -------------------------------------------------------------------------------- /tools/asm_objdump_converter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm *.o 4 | gcc -m32 -Wall -g -c asm_objdump_converter.c 5 | gcc -m32 -Wl -o asm_objdump_converter *.o 6 | -------------------------------------------------------------------------------- /tools/converted_dump.asm: -------------------------------------------------------------------------------- 1 | push %ebp 2 | mov %esp,%ebp 3 | push %edi 4 | push %esi 5 | push %ebx 6 | sub $0x1c,%esp 7 | mov 0x8(%ebp),%eax 8 | mov (%eax),%eax 9 | mov %eax,-0x10(%ebp) 10 | xor %edi,%edi 11 | xor %esi,%esi 12 | movl $0x0,-0x14(%ebp) 13 | jmp Scr_GetFunction_loc1 14 | 15 | Scr_GetFunction_loc3: 16 | add $0x1,%edi 17 | addl $0x6,-0x14(%ebp) 18 | add $0xc,%esi 19 | cmp $0xcd,%edi 20 | je Scr_GetFunction_loc2 21 | 22 | Scr_GetFunction_loc1: 23 | mov 0x826e060(%esi),%ebx 24 | mov %ebx,0x4(%esp) 25 | mov -0x10(%ebp),%edx 26 | mov %edx,(%esp) 27 | mov $0x804ab9c, %eax 28 | call *%eax 29 | test %eax,%eax 30 | jne Scr_GetFunction_loc3 31 | mov 0x8(%ebp),%eax 32 | mov %ebx,(%eax) 33 | mov -0x14(%ebp),%eax 34 | mov 0x826e068(%eax,%eax,1),%edx 35 | mov 0xc(%ebp),%eax 36 | mov %edx,(%eax) 37 | mov -0x14(%ebp),%edx 38 | mov 0x826e064(%edx,%edx,1),%eax 39 | add $0x1c,%esp 40 | pop %ebx 41 | pop %esi 42 | pop %edi 43 | pop %ebp 44 | ret 45 | 46 | Scr_GetFunction_loc2: 47 | xor %eax,%eax 48 | add $0x1c,%esp 49 | pop %ebx 50 | pop %esi 51 | pop %edi 52 | pop %ebp 53 | ret 54 | -------------------------------------------------------------------------------- /tools/make_gcc_compatible_asm.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | del *.o 3 | gcc -Wall -g -c make_gcc_compatible_asm.c 4 | gcc -Wl -o make_gcc_compatible_asm *.o 5 | pause 6 | -------------------------------------------------------------------------------- /tools/make_gcc_compatible_asm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm *.o 4 | gcc -Wall -g -c make_gcc_compatible_asm.c 5 | gcc -Wl -o make_gcc_compatible_asm *.o 6 | -------------------------------------------------------------------------------- /version_make_progress.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read line < src/version.h 4 | tokens=($line) 5 | version=$(echo "${tokens[2]}" | tr -d $'\r') 6 | newversion=$(echo "$version + 1" | bc) 7 | echo "#define BUILD_NUMBER $newversion" > src/version.h 8 | --------------------------------------------------------------------------------