├── Android.mk ├── CHANGES ├── INSTALL ├── LICENSE ├── MULTI ├── Makefile.in ├── README ├── SMALL ├── TODO ├── agentfwd.h ├── algo.h ├── atomicio.c ├── atomicio.h ├── auth.h ├── bignum.c ├── bignum.h ├── buffer.c ├── buffer.h ├── channel.h ├── chansession.h ├── circbuffer.c ├── circbuffer.h ├── cli-algo.c ├── cli-auth.c ├── cli-authinteract.c ├── cli-authpasswd.c ├── cli-authpubkey.c ├── cli-channel.c ├── cli-chansession.c ├── cli-kex.c ├── cli-main.c ├── cli-runopts.c ├── cli-service.c ├── cli-session.c ├── cli-tcpfwd.c ├── common-algo.c ├── common-channel.c ├── common-chansession.c ├── common-kex.c ├── common-runopts.c ├── common-session.c ├── compat.c ├── compat.h ├── config.guess ├── config.h ├── config.h.in ├── config.sub ├── configure ├── configure.in ├── dbclient.1 ├── dbmulti.c ├── dbutil.c ├── dbutil.h ├── debian ├── README.Debian ├── README.Debian.diet ├── README.runit ├── changelog ├── control ├── copyright.in ├── dropbear.README.Debian ├── dropbear.conffiles ├── dropbear.default ├── dropbear.docs ├── dropbear.init ├── dropbear.postinst ├── dropbear.postrm ├── dropbear.prerm ├── implicit ├── rules └── service │ ├── log │ └── run ├── debug.h ├── dropbear.8 ├── dropbearconvert.c ├── dropbearkey.8 ├── dropbearkey.c ├── dss.c ├── dss.h ├── fake-rfc2553.c ├── fake-rfc2553.h ├── filelist.txt ├── freebsd_crypt.c ├── freebsd_crypt.h ├── gendss.c ├── gendss.h ├── genrsa.c ├── genrsa.h ├── includes.h ├── install-sh ├── kex.h ├── keyimport.c ├── keyimport.h ├── libtomcrypt ├── Android.mk ├── Doxyfile ├── LICENSE ├── Makefile.in ├── README ├── TODO ├── build.sh ├── changes ├── crypt.lof ├── crypt.tex ├── demos │ ├── encrypt.c │ ├── hashsum.c │ ├── multi.c │ ├── small.c │ ├── test.c │ ├── timing.c │ └── tv_gen.c ├── doc │ ├── footer.html │ └── header.html ├── filter.pl ├── fixupind.pl ├── genlist.sh ├── makefile.icc ├── makefile.msvc ├── makefile.shared ├── makefile.unix ├── mess.sh ├── notes │ ├── base64_tv.txt │ ├── ccm_tv.txt │ ├── cipher_tv.txt │ ├── eax_tv.txt │ ├── ecc_tv.txt │ ├── etc │ │ ├── saferp_optimizer.c │ │ ├── whirlgen.c │ │ └── whirltest.c │ ├── gcm_tv.txt │ ├── hash_tv.txt │ ├── hmac_tv.txt │ ├── lrw_tv.txt │ ├── ocb_tv.txt │ ├── omac_tv.txt │ ├── pmac_tv.txt │ ├── tech0001.txt │ ├── tech0002.txt │ ├── tech0003.txt │ ├── tech0004.txt │ ├── tech0005.txt │ ├── tech0006.txt │ └── tech0007.txt ├── parsenames.pl ├── run.sh ├── src │ ├── ciphers │ │ ├── aes │ │ │ ├── aes.c │ │ │ └── aes_tab.c │ │ ├── anubis.c │ │ ├── blowfish.c │ │ ├── cast5.c │ │ ├── des.c │ │ ├── kasumi.c │ │ ├── khazad.c │ │ ├── kseed.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 │ ├── math │ │ ├── fp │ │ │ └── ltc_ecc_fp_mulmod.c │ │ ├── gmp_desc.c │ │ ├── ltm_desc.c │ │ ├── multi.c │ │ ├── rand_prime.c │ │ └── tfm_desc.c │ ├── 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 │ ├── 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 ├── testbuild.sh ├── testme.sh ├── testprof │ ├── base64_test.c │ ├── cipher_hash_test.c │ ├── der_tests.c │ ├── dsa_test.c │ ├── ecc_test.c │ ├── katja_test.c │ ├── mac_test.c │ ├── makefile │ ├── makefile.icc │ ├── makefile.msvc │ ├── makefile.shared │ ├── modes_test.c │ ├── pkcs_1_test.c │ ├── rsa_test.c │ ├── store_test.c │ ├── test.der │ ├── test.key │ ├── test_driver.c │ ├── tomcrypt_test.h │ └── x86_prof.c └── updatemakes.sh ├── libtommath ├── Android.mk ├── LICENSE ├── Makefile.in ├── 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 ├── 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 ├── logs │ ├── README │ ├── add.log │ ├── addsub.png │ ├── expt.log │ ├── expt.png │ ├── expt_2k.log │ ├── expt_2kl.log │ ├── expt_dr.log │ ├── graphs.dem │ ├── index.html │ ├── invmod.log │ ├── invmod.png │ ├── mult.log │ ├── mult.png │ ├── mult_kara.log │ ├── sqr.log │ ├── sqr_kara.log │ └── sub.log ├── 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_class.h └── tommath_superclass.h ├── listener.c ├── listener.h ├── loginrec.c ├── loginrec.h ├── netbsd_getpass.c ├── openpty.c ├── options.h ├── packet.c ├── packet.h ├── process-packet.c ├── progressmeter.c ├── progressmeter.h ├── queue.c ├── queue.h ├── random.c ├── random.h ├── rsa.c ├── rsa.h ├── runopts.h ├── scp.c ├── scpmisc.c ├── scpmisc.h ├── service.h ├── session.h ├── sftp-server ├── Android.mk ├── LICENCE ├── addrmatch.c ├── bufaux.c ├── buffer.c ├── buffer.h ├── channels.h ├── compat.c ├── compat.h ├── config.h ├── config.h.in ├── defines.h ├── entropy.h ├── includes.h ├── log.c ├── log.h ├── match.c ├── match.h ├── misc.c ├── misc.h ├── openbsd-compat │ ├── base64.h │ ├── bsd-cray.h │ ├── bsd-cygwin_util.h │ ├── bsd-misc.c │ ├── bsd-misc.h │ ├── bsd-nextstep.h │ ├── bsd-poll.h │ ├── bsd-statvfs.c │ ├── bsd-statvfs.h │ ├── bsd-waitpid.h │ ├── fake-rfc2553.h │ ├── fmt_scaled.c │ ├── getopt.c │ ├── getrrsetbyname.h │ ├── glob.h │ ├── openbsd-compat.h │ ├── port-aix.h │ ├── port-irix.h │ ├── port-linux.h │ ├── port-solaris.h │ ├── port-tun.c │ ├── port-tun.h │ ├── port-uw.h │ ├── pwcache.c │ ├── readpassphrase.h │ ├── sha2.h │ ├── sigact.h │ ├── strmode.c │ ├── strtonum.c │ ├── sys-queue.h │ ├── vis.c │ └── vis.h ├── openssl │ ├── bn.h │ └── opensslv.h ├── packet.h ├── platform.h ├── sftp-client.h ├── sftp-common.c ├── sftp-common.h ├── sftp-server-main.c ├── sftp-server.c ├── sftp.h ├── ssh.h ├── uidswap.h ├── xmalloc.c └── xmalloc.h ├── signkey.c ├── signkey.h ├── ssh.h ├── sshpty.c ├── sshpty.h ├── svr-agentfwd.c ├── svr-algo.c ├── svr-auth.c ├── svr-authpam.c ├── svr-authpasswd.c ├── svr-authpubkey.c ├── svr-authpubkeyoptions.c ├── svr-chansession.c ├── svr-kex.c ├── svr-main.c ├── svr-runopts.c ├── svr-service.c ├── svr-session.c ├── svr-tcpfwd.c ├── svr-x11fwd.c ├── sysoptions.h ├── tcp-accept.c ├── tcpfwd.h ├── termcodes.c ├── termcodes.h └── x11fwd.h /CHANGES: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/CHANGES -------------------------------------------------------------------------------- /MULTI: -------------------------------------------------------------------------------- 1 | Multi-binary compilation 2 | ======================== 3 | 4 | To compile for systems without much space (floppy distributions etc), you 5 | can create a single binary. This will save disk space by avoiding repeated 6 | code between the various parts. 7 | If you are familiar with "busybox", it's the same principle. 8 | 9 | To compile the multi-binary, first "make clean" (if you've compiled 10 | previously), then 11 | 12 | make PROGRAMS="programs you want here" MULTI=1 13 | 14 | To use the binary, symlink it from the desired executable: 15 | 16 | ln -s dropbearmulti dropbear 17 | ln -s dropbearmulti dbclient 18 | etc 19 | 20 | then execute as normal: 21 | 22 | ./dropbear 23 | 24 | "make install" doesn't currently work for multi-binary configuration, though 25 | in most situations where it is being used, the target and build systems will 26 | differ. 27 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Current: 2 | 3 | Things which might need doing: 4 | 5 | - default private dbclient keys 6 | 7 | - Make options.h generated from configure perhaps? 8 | 9 | - handle /etc/environment in AIX 10 | 11 | - check that there aren't timing issues with valid/invalid user authentication 12 | feedback. 13 | 14 | - Binding to different interfaces 15 | 16 | - CTR mode 17 | - SSH_MSG_IGNORE sending to improve CBC security 18 | - DH Group Exchange possibly, or just add group14 (whatever it's called today) 19 | 20 | - fix scp.c for IRIX 21 | 22 | - Be able to use OpenSSH keys for the client? or at least have some form of 23 | encrypted keys. 24 | 25 | - Client agent forwarding 26 | 27 | - Handle restrictions in ~/.ssh/authorized_keys ? 28 | -------------------------------------------------------------------------------- /debian/README.Debian.diet: -------------------------------------------------------------------------------- 1 | Building with the diet libc 2 | --------------------------- 3 | 4 | This package optionally can be built with the diet libc instead of the 5 | glibc to provide small statically linked programs. The resulting package 6 | has no dependency on any other package. 7 | 8 | To use the diet libc, make sure the latest versions of the dietlibc-dev 9 | package is installed, and set DEB_BUILD_OPTIONS=diet in the environment 10 | when building the package, e.g.: 11 | 12 | # apt-get install dietlibc-dev 13 | $ DEB_BUILD_OPTIONS=diet fakeroot apt-get source -b dropbear 14 | 15 | -- Gerrit Pape , Sat, 17 Jul 2004 19:09:34 +0000 16 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: dropbear 2 | Section: net 3 | Priority: optional 4 | Maintainer: Gerrit Pape 5 | Build-Depends: libz-dev 6 | Standards-Version: 3.7.3.0 7 | 8 | Package: dropbear 9 | Architecture: any 10 | Depends: ${shlibs:Depends} 11 | Suggests: openssh-client, runit 12 | Description: lightweight SSH2 server and client 13 | dropbear is a SSH 2 server and client designed to be small enough to 14 | be used in small memory environments, while still being functional and 15 | secure enough for general use. 16 | . 17 | It implements most required features of the SSH 2 protocol, and other 18 | features such as X11 and authentication agent forwarding. 19 | . 20 | See http://matt.ucc.asn.au/dropbear/dropbear.html 21 | -------------------------------------------------------------------------------- /debian/copyright.in: -------------------------------------------------------------------------------- 1 | This package was debianized by Grahame Bowland on 2 | Tue, 17 Jun 2003 15:04:47 +0800, maintained temporarily by Matt Johnston 3 | , and was adopted by Gerrit Pape on 4 | Sun, 16 May 2004 14:38:33 +0000. 5 | 6 | It was downloaded from http://matt.ucc.asn.au/dropbear/ 7 | 8 | Upstream Author: Matt Johnston 9 | 10 | Copyright: 11 | 12 | -------------------------------------------------------------------------------- /debian/dropbear.README.Debian: -------------------------------------------------------------------------------- 1 | Dropbear for Debian 2 | ------------------- 3 | 4 | This package will attempt to setup the Dropbear ssh server to listen on 5 | port 22. If the OpenSSH server package ("openssh-server") is installed, 6 | the file /etc/default/dropbear will be set up so that the server does not 7 | start by default. 8 | 9 | You can run Dropbear concurrently with OpenSSH 'sshd' by modifying 10 | /etc/default/dropbear so that "NO_START" is set to "0", and changing the 11 | port number that Dropbear runs on. Follow the instructions in the file. 12 | 13 | This package suggests you install the "openssh-client" package, which 14 | provides the "ssh" client program, as well as the "/usr/bin/scp" binary 15 | you will need to be able to retrieve files via SCP from a server running 16 | Dropbear. 17 | 18 | See the Dropbear homepage for more information: 19 | http://matt.ucc.asn.au/dropbear/dropbear.html 20 | -------------------------------------------------------------------------------- /debian/dropbear.conffiles: -------------------------------------------------------------------------------- 1 | /etc/init.d/dropbear 2 | /etc/dropbear/run 3 | /etc/dropbear/log/run 4 | -------------------------------------------------------------------------------- /debian/dropbear.default: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/debian/dropbear.default -------------------------------------------------------------------------------- /debian/dropbear.docs: -------------------------------------------------------------------------------- 1 | README 2 | TODO 3 | debian/README.runit 4 | debian/README.Debian.diet 5 | -------------------------------------------------------------------------------- /debian/dropbear.postrm: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | set -e 3 | 4 | test "$1" = 'purge' || exit 0 5 | if test -e /etc/dropbear; then 6 | rm -f /etc/dropbear/dropbear_rsa_host_key 7 | rm -f /etc/dropbear/dropbear_dss_host_key 8 | rmdir --ignore-fail-on-non-empty /etc/dropbear 9 | fi 10 | update-rc.d dropbear remove >/dev/null 11 | rm -f /etc/default/dropbear 12 | rm -rf /etc/dropbear/supervise /etc/dropbear/log/supervise 13 | -------------------------------------------------------------------------------- /debian/dropbear.prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | test "$1" = 'remove' || test "$1" = 'deconfigure' || exit 0 5 | if test -x /etc/init.d/dropbear; then 6 | if test -x /usr/sbin/invoke-rc.d; then 7 | invoke-rc.d dropbear stop 8 | else 9 | /etc/init.d/dropbear stop 10 | fi 11 | fi 12 | -------------------------------------------------------------------------------- /debian/service/log: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec chpst -udropbearlog svlogd -tt ./main 3 | -------------------------------------------------------------------------------- /debian/service/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec 2>&1 3 | exec dropbear -d ./dropbear_dss_host_key -r ./dropbear_rsa_host_key -F -E -p 22 4 | -------------------------------------------------------------------------------- /dropbearkey.8: -------------------------------------------------------------------------------- 1 | .TH dropbearkey 8 2 | .SH NAME 3 | dropbearkey \- create private keys for the use with dropbear(8) 4 | .SH SYNOPSIS 5 | .B dropbearkey 6 | \-t 7 | .I type 8 | \-f 9 | .I file 10 | [\-s 11 | .IR bits ] 12 | .SH DESCRIPTION 13 | .B dropbearkey 14 | generates a 15 | .I RSA 16 | or 17 | .I DSS 18 | format SSH private key, and saves it to a file for the use with the 19 | .BR dropbear (8) 20 | SSH 2 server. 21 | Note that 22 | some SSH implementations 23 | use the term "DSA" rather than "DSS", they mean the same thing. 24 | .SH OPTIONS 25 | .TP 26 | .B \-t \fItype 27 | Type of key to generate. 28 | Must be one of 29 | .I rsa 30 | or 31 | .IR dss . 32 | .TP 33 | .B \-f \fIfile 34 | Write the secret key to the file 35 | .IR file . 36 | .TP 37 | .B \-s \fIbits 38 | Set the key size to 39 | .I bits 40 | bits, should be multiple of 8 (optional). 41 | .SH EXAMPLE 42 | # dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key 43 | .SH AUTHOR 44 | Matt Johnston (matt@ucc.asn.au). 45 | .br 46 | Gerrit Pape (pape@smarden.org) wrote this manual page. 47 | .SH SEE ALSO 48 | dropbear(8), dbclient(1) 49 | .P 50 | http://matt.ucc.asn.au/dropbear/dropbear.html 51 | -------------------------------------------------------------------------------- /freebsd_crypt.h: -------------------------------------------------------------------------------- 1 | char *crypt(const char *pw, const char *salt); 2 | -------------------------------------------------------------------------------- /gendss.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dropbear - a SSH2 server 3 | * 4 | * Copyright (c) 2002,2003 Matt Johnston 5 | * All rights reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. */ 24 | 25 | #ifndef _GENDSS_H_ 26 | #define _GENDSS_H_ 27 | 28 | #include "dss.h" 29 | 30 | #ifdef DROPBEAR_DSS 31 | 32 | dss_key * gen_dss_priv_key(unsigned int size); 33 | 34 | #endif /* DROPBEAR_DSS */ 35 | 36 | #endif /* _GENDSS_H_ */ 37 | -------------------------------------------------------------------------------- /genrsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dropbear - a SSH2 server 3 | * 4 | * Copyright (c) 2002,2003 Matt Johnston 5 | * All rights reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. */ 24 | 25 | #ifndef _GENRSA_H_ 26 | #define _GENRSA_H_ 27 | 28 | #include "rsa.h" 29 | 30 | #ifdef DROPBEAR_RSA 31 | 32 | rsa_key * gen_rsa_priv_key(unsigned int size); 33 | 34 | #endif /* DROPBEAR_RSA */ 35 | 36 | #endif /* _GENRSA_H_ */ 37 | -------------------------------------------------------------------------------- /libtomcrypt/LICENSE: -------------------------------------------------------------------------------- 1 | LibTomCrypt is public domain. As should all quality software be. 2 | 3 | Tom St Denis 4 | 5 | 6 | -------------------------------------------------------------------------------- /libtomcrypt/README: -------------------------------------------------------------------------------- 1 | See doc/crypt.pdf 2 | 3 | 4 | -------------------------------------------------------------------------------- /libtomcrypt/TODO: -------------------------------------------------------------------------------- 1 | stopped at ch12 2 | -- needs examples for ecc/dsa!!! (and for asn.1) 3 | 4 | must have for v1.16 5 | - document PK build flags 6 | - document makefile flags [INSTALL_* for instance] 7 | - prepare manual for printing (both soft and hard cover) 8 | 9 | Nice to have [in order of precedence] 10 | - add X9.63 IES 11 | - add CPP macros like OpenSSL has for ASN1 (e.g. encode/decode functions, etc) shameless ripoff :-) 12 | -------------------------------------------------------------------------------- /libtomcrypt/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "$1 ($2, $3)..." 3 | make clean 1>/dev/null 2>/dev/null 4 | echo -n "building..." 5 | CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j4 -f $3 test tv_gen 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && exit 1) 6 | echo -n "testing..." 7 | if [ -a test ] && [ -f test ] && [ -x test ]; then 8 | ((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed" && cat test_err.txt && exit 1) 9 | if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then 10 | for f in *_tv.txt; do if (diff --ignore-case $f notes/$f) then true; else (echo "tv_gen $f failed" && rm -f testok.txt && exit 1); fi; done 11 | fi 12 | fi 13 | if [ -a testok.txt ] && [ -f testok.txt ]; then 14 | exit 0 15 | fi 16 | exit 1 17 | 18 | # $Source: /cvs/libtom/libtomcrypt/build.sh,v $ 19 | # $Revision: 1.9 $ 20 | # $Date: 2006/03/18 14:10:55 $ 21 | -------------------------------------------------------------------------------- /libtomcrypt/crypt.lof: -------------------------------------------------------------------------------- 1 | \addvspace {10\p@ } 2 | \addvspace {10\p@ } 3 | \contentsline {figure}{\numberline {2.1}{\ignorespaces Load And Store Macros}}{9}{figure.2.1} 4 | \contentsline {figure}{\numberline {2.2}{\ignorespaces Rotate Macros}}{9}{figure.2.2} 5 | \addvspace {10\p@ } 6 | \contentsline {figure}{\numberline {3.1}{\ignorespaces Built--In Software Ciphers}}{19}{figure.3.1} 7 | \contentsline {figure}{\numberline {3.2}{\ignorespaces Twofish Build Options}}{21}{figure.3.2} 8 | \addvspace {10\p@ } 9 | \contentsline {figure}{\numberline {4.1}{\ignorespaces Built--In Software Hashes}}{57}{figure.4.1} 10 | \addvspace {10\p@ } 11 | \addvspace {10\p@ } 12 | \contentsline {figure}{\numberline {6.1}{\ignorespaces List of Provided PRNGs}}{82}{figure.6.1} 13 | \addvspace {10\p@ } 14 | \addvspace {10\p@ } 15 | \addvspace {10\p@ } 16 | \contentsline {figure}{\numberline {9.1}{\ignorespaces DSA Key Sizes}}{119}{figure.9.1} 17 | \addvspace {10\p@ } 18 | \contentsline {figure}{\numberline {10.1}{\ignorespaces List of ASN.1 Supported Types}}{127}{figure.10.1} 19 | \addvspace {10\p@ } 20 | \addvspace {10\p@ } 21 | \contentsline {figure}{\numberline {12.1}{\ignorespaces RSA/DH Key Strength}}{149}{figure.12.1} 22 | \contentsline {figure}{\numberline {12.2}{\ignorespaces ECC Key Strength}}{149}{figure.12.2} 23 | \addvspace {10\p@ } 24 | \addvspace {10\p@ } 25 | -------------------------------------------------------------------------------- /libtomcrypt/demos/small.c: -------------------------------------------------------------------------------- 1 | /* small demo app that just includes a cipher/hash/prng */ 2 | #include 3 | 4 | int main(void) 5 | { 6 | register_cipher(&rijndael_enc_desc); 7 | register_prng(&yarrow_desc); 8 | register_hash(&sha256_desc); 9 | return 0; 10 | } 11 | 12 | /* $Source: /cvs/libtom/libtomcrypt/demos/small.c,v $ */ 13 | /* $Revision: 1.3 $ */ 14 | /* $Date: 2006/06/07 22:25:09 $ */ 15 | -------------------------------------------------------------------------------- /libtomcrypt/demos/timing.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | 6 | init_timer(); 7 | reg_algs(); 8 | 9 | #ifdef USE_LTM 10 | ltc_mp = ltm_desc; 11 | #elif defined(USE_TFM) 12 | ltc_mp = tfm_desc; 13 | #elif defined(USE_GMP) 14 | ltc_mp = gmp_desc; 15 | #else 16 | extern ltc_math_descriptor EXT_MATH_LIB; 17 | ltc_mp = EXT_MATH_LIB; 18 | #endif 19 | 20 | time_keysched(); 21 | time_cipher(); 22 | time_cipher2(); 23 | time_cipher3(); 24 | time_cipher4(); 25 | time_hash(); 26 | time_macs(); 27 | time_encmacs(); 28 | time_prng(); 29 | time_mult(); 30 | time_sqr(); 31 | time_rsa(); 32 | time_ecc(); 33 | #ifdef USE_LTM 34 | time_katja(); 35 | #endif 36 | return EXIT_SUCCESS; 37 | 38 | } 39 | 40 | /* $Source: /cvs/libtom/libtomcrypt/demos/timing.c,v $ */ 41 | /* $Revision: 1.61 $ */ 42 | /* $Date: 2006/12/03 03:08:35 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/doc/footer.html: -------------------------------------------------------------------------------- 1 |
2 | Code by Tom
3 | Docs using doxygen 4 | 5 | 6 | 11 | -------------------------------------------------------------------------------- /libtomcrypt/doc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | LibTomCrypt: Main Page 4 | 5 | 6 | 7 | 8 | 13 | -------------------------------------------------------------------------------- /libtomcrypt/filter.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # we want to filter every between START_INS and END_INS out and then insert crap from another file (this is fun) 4 | 5 | $dst = shift; 6 | $ins = shift; 7 | 8 | open(SRC,"<$dst"); 9 | open(INS,"<$ins"); 10 | open(TMP,">tmp.delme"); 11 | 12 | $l = 0; 13 | while () { 14 | if ($_ =~ /START_INS/) { 15 | print TMP $_; 16 | $l = 1; 17 | while () { 18 | print TMP $_; 19 | } 20 | close INS; 21 | } elsif ($_ =~ /END_INS/) { 22 | print TMP $_; 23 | $l = 0; 24 | } elsif ($l == 0) { 25 | print TMP $_; 26 | } 27 | } 28 | 29 | close TMP; 30 | close SRC; 31 | -------------------------------------------------------------------------------- /libtomcrypt/fixupind.pl: -------------------------------------------------------------------------------- 1 | open(IN,"crypt.ind.tmp"); 3 | $a = ; 4 | print OUT "$a\n\\addcontentsline{toc}{chapter}{Index}\n"; 5 | while () { 6 | print OUT $_; 7 | } 8 | close OUT; 9 | close IN; 10 | system("mv -f crypt.ind.tmp crypt.ind"); 11 | 12 | -------------------------------------------------------------------------------- /libtomcrypt/genlist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # aes_tab.o is a pseudo object as it's made from aes.o and MPI is optional 3 | export a=`echo -n "src/ciphers/aes/aes_enc.o " ; find . -type f | sort | grep "[.]/src" | grep "[.]c" | grep -v "sha224" | grep -v "sha384" | grep -v "aes_tab" | grep -v "twofish_tab" | grep -v "whirltab" | grep -v "dh_sys" | grep -v "ecc_sys" | grep -v "mpi[.]c" | grep -v "sober128tab" | sed -e 'sE\./EE' | sed -e 's/\.c/\.o/' | xargs` 4 | perl ./parsenames.pl OBJECTS "$a" 5 | export a=`find . -type f | grep [.]/src | grep [.]h | sed -e 'se\./ee' | xargs` 6 | perl ./parsenames.pl HEADERS "$a" 7 | 8 | # $Source: /cvs/libtom/libtomcrypt/genlist.sh,v $ 9 | # $Revision: 1.4 $ 10 | # $Date: 2005/07/17 23:15:12 $ 11 | -------------------------------------------------------------------------------- /libtomcrypt/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, removed"; rm -f $1 ; fi 3 | 4 | 5 | -------------------------------------------------------------------------------- /libtomcrypt/notes/base64_tv.txt: -------------------------------------------------------------------------------- 1 | Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1 2 | 3 | 0: 4 | 1: AA== 5 | 2: AAE= 6 | 3: AAEC 7 | 4: AAECAw== 8 | 5: AAECAwQ= 9 | 6: AAECAwQF 10 | 7: AAECAwQFBg== 11 | 8: AAECAwQFBgc= 12 | 9: AAECAwQFBgcI 13 | 10: AAECAwQFBgcICQ== 14 | 11: AAECAwQFBgcICQo= 15 | 12: AAECAwQFBgcICQoL 16 | 13: AAECAwQFBgcICQoLDA== 17 | 14: AAECAwQFBgcICQoLDA0= 18 | 15: AAECAwQFBgcICQoLDA0O 19 | 16: AAECAwQFBgcICQoLDA0ODw== 20 | 17: AAECAwQFBgcICQoLDA0ODxA= 21 | 18: AAECAwQFBgcICQoLDA0ODxAR 22 | 19: AAECAwQFBgcICQoLDA0ODxAREg== 23 | 20: AAECAwQFBgcICQoLDA0ODxAREhM= 24 | 21: AAECAwQFBgcICQoLDA0ODxAREhMU 25 | 22: AAECAwQFBgcICQoLDA0ODxAREhMUFQ== 26 | 23: AAECAwQFBgcICQoLDA0ODxAREhMUFRY= 27 | 24: AAECAwQFBgcICQoLDA0ODxAREhMUFRYX 28 | 25: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGA== 29 | 26: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBk= 30 | 27: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBka 31 | 28: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGw== 32 | 29: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxw= 33 | 30: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd 34 | 31: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHg== 35 | 32: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8= 36 | -------------------------------------------------------------------------------- /libtomcrypt/notes/etc/whirltest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char buf[4096]; 6 | int x; 7 | 8 | while (fgets(buf, sizeof(buf)-2, stdin) != NULL) { 9 | for (x = 0; x < 128; ) { 10 | printf("0x%c%c, ", buf[x], buf[x+1]); 11 | if (!((x += 2) & 31)) printf("\n"); 12 | } 13 | } 14 | } 15 | 16 | 17 | /* $Source: /cvs/libtom/libtomcrypt/notes/etc/whirltest.c,v $ */ 18 | /* $Revision: 1.2 $ */ 19 | /* $Date: 2005/05/05 14:35:58 $ */ 20 | -------------------------------------------------------------------------------- /libtomcrypt/notes/tech0005.txt: -------------------------------------------------------------------------------- 1 | Tech Note 0005 2 | Minimizing Code Space 3 | Tom St Denis 4 | 5 | Introduction 6 | ------------ 7 | 8 | Tweaking... 9 | 10 | You can disable whole classes of algorithms on the command line with the LTC_NO_* defines. From there you can manually turn on what you want to enable. 11 | 12 | The following build with GCC 3.4.4 on an AMD64 box gets you AES, CTR mode, SHA-256, HMAC, Yarrow, full RSA PKCS #1, PKCS #5 and ASN.1 DER in 13 | roughly 40KB of code (49KB on the ARMv4) (both excluding the math library). 14 | 15 | CFLAGS="-DLTC_NO_CIPHERS -DLTC_NO_HASHES -DLTC_NO_PRNGS -DLTC_NO_MACS -DLTC_NO_MODES -DLTC_NO_PK -DRIJNDAEL -DLTC_CTR_MODE -DSHA256 \ 16 | -DLTC_HMAC -DYARROW -DMRSA -DMPI -DTFM_DESC -DARGTYPE=3 -Os -DLTC_SMALL_CODE -fomit-frame-pointer" make IGNORE_SPEED=1 17 | 18 | Obviously this won't get you performance but if you need to pack a crypto lib in a device with limited means it's more than enough... 19 | 20 | Neato eh? 21 | -------------------------------------------------------------------------------- /libtomcrypt/notes/tech0007.txt: -------------------------------------------------------------------------------- 1 | Tech Note #7 2 | Quick building for testing with LTM 3 | 4 | EXTRALIBS=-ltommath CFLAGS="-g3 -DLTC_NO_ASM -DUSE_LTM -DLTM_DESC" make -j3 IGNORE_SPEED=1 test 5 | 6 | -------------------------------------------------------------------------------- /libtomcrypt/parsenames.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # Splits the list of files and outputs for makefile type files 4 | # wrapped at 80 chars 5 | # 6 | # Tom St Denis 7 | @a = split(" ", $ARGV[1]); 8 | $b = "$ARGV[0]="; 9 | $len = length($b); 10 | print $b; 11 | foreach my $obj (@a) { 12 | $len = $len + length($obj); 13 | $obj =~ s/\*/\$/; 14 | if ($len > 100) { 15 | printf "\\\n"; 16 | $len = length($obj); 17 | } 18 | print "$obj "; 19 | } 20 | if ($ARGV[0] eq "HEADERS") { print "testprof/tomcrypt_test.h"; } 21 | 22 | print "\n\n"; 23 | 24 | # $Source: /cvs/libtom/libtomcrypt/parsenames.pl,v $ 25 | # $Revision: 1.3 $ 26 | # $Date: 2005/05/05 14:49:27 $ 27 | -------------------------------------------------------------------------------- /libtomcrypt/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | bash build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1" "$4" "$5" 3 | if [ -a testok.txt ] && [ -f testok.txt ]; then 4 | echo 5 | else 6 | echo 7 | echo "Test failed" 8 | exit 1 9 | fi 10 | 11 | rm -f testok.txt 12 | bash build.sh " $1" "$2 -Os" " $3 IGNORE_SPEED=1 LTC_SMALL=1" "$4" "$5" 13 | if [ -a testok.txt ] && [ -f testok.txt ]; then 14 | echo 15 | else 16 | echo 17 | echo "Test failed" 18 | exit 1 19 | fi 20 | 21 | rm -f testok.txt 22 | bash build.sh " $1" " $2" " $3 " "$4" "$5" 23 | if [ -a testok.txt ] && [ -f testok.txt ]; then 24 | echo 25 | else 26 | echo 27 | echo "Test failed" 28 | exit 1 29 | fi 30 | 31 | exit 0 32 | 33 | # $Source: /cvs/libtom/libtomcrypt/run.sh,v $ 34 | # $Revision: 1.15 $ 35 | # $Date: 2005/07/23 14:18:31 $ 36 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 38 | /* $Date: 2006/03/31 14:15:35 $ */ 39 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 50 | /* $Date: 2006/03/31 14:15:35 $ */ 51 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 51 | /* $Date: 2006/03/31 14:15:35 $ */ 52 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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 = 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.4 $ */ 44 | /* $Date: 2006/03/31 14:15:35 $ */ 45 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 42 | /* $Date: 2006/03/31 14:15:35 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 39 | /* $Date: 2006/03/31 14:15:35 $ */ 40 | -------------------------------------------------------------------------------- /libtomcrypt/src/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 | -------------------------------------------------------------------------------- /libtomcrypt/src/headers/tomcrypt_misc.h: -------------------------------------------------------------------------------- 1 | /* ---- BASE64 Routines ---- */ 2 | #ifdef 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.4 $ */ 23 | /* $Date: 2006/11/06 03:03:01 $ */ 24 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file hmac_process.c 15 | HMAC support, process data, Tom St Denis/Dobes Vandermeer 16 | */ 17 | 18 | #ifdef LTC_HMAC 19 | 20 | /** 21 | Process data through HMAC 22 | @param hmac The hmac state 23 | @param in The data to send through HMAC 24 | @param inlen The length of the data to 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.5 $ */ 43 | /* $Date: 2006/11/03 00:39:49 $ */ 44 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 39 | /* $Date: 2006/11/03 00:39:49 $ */ 40 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 44 | /* $Date: 2006/11/03 00:39:49 $ */ 45 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.4 $ */ 34 | /* $Date: 2006/03/31 14:15:35 $ */ 35 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.4 $ */ 30 | /* $Date: 2006/03/31 14:15:35 $ */ 31 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.12 $ */ 27 | /* $Date: 2006/11/08 23:01:06 $ */ 28 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 36 | /* $Date: 2006/03/31 14:15:35 $ */ 37 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 41 | /* $Date: 2006/11/29 23:43:57 $ */ 42 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 40 | /* $Date: 2006/03/31 14:15:35 $ */ 41 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 40 | /* $Date: 2006/11/29 23:43:57 $ */ 41 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 40 | /* $Date: 2006/03/31 14:15:35 $ */ 41 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.4 $ */ 35 | /* $Date: 2006/11/01 09:28:17 $ */ 36 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 41 | /* $Date: 2006/11/29 23:43:57 $ */ 42 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.9 $ */ 27 | /* $Date: 2006/03/31 14:15:35 $ */ 28 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 36 | /* $Date: 2006/03/31 14:15:35 $ */ 37 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | ltc_math_descriptor ltc_mp; 14 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.7 $ */ 26 | /* $Date: 2006/03/31 14:15:35 $ */ 27 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 36 | /* $Date: 2006/03/31 14:15:35 $ */ 37 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 45 | /* $Date: 2006/11/01 09:28:17 $ */ 46 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 44 | /* $Date: 2006/11/01 09:28:17 $ */ 45 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 44 | /* $Date: 2006/11/01 09:28:17 $ */ 45 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 34 | /* $Date: 2006/06/09 01:38:13 $ */ 35 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 42 | /* $Date: 2006/06/29 01:46:46 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 46 | /* $Date: 2006/06/29 01:46:46 $ */ 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 44 | /* $Date: 2006/06/29 01:46:46 $ */ 45 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 42 | /* $Date: 2006/06/29 01:51:34 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 46 | /* $Date: 2006/06/29 01:51:34 $ */ 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 52 | /* $Date: 2006/06/29 01:51:34 $ */ 53 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 42 | /* $Date: 2006/06/29 01:46:46 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 42 | /* $Date: 2006/06/29 01:46:46 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 46 | /* $Date: 2006/06/29 01:46:46 $ */ 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.7 $ */ 42 | /* $Date: 2006/06/29 01:51:34 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.2 $ */ 43 | /* $Date: 2006/06/16 22:49:25 $ */ 44 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.2 $ */ 42 | /* $Date: 2006/06/16 22:49:25 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.2 $ */ 46 | /* $Date: 2006/06/16 22:49:25 $ */ 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.2 $ */ 52 | /* $Date: 2006/06/16 22:49:25 $ */ 53 | -------------------------------------------------------------------------------- /libtomcrypt/src/modes/lrw/lrw_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://libtomcrypt.com 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file lrw_decrypt.c 15 | LRW_MODE implementation, Decrypt blocks, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_LRW_MODE 19 | 20 | /** 21 | LRW decrypt blocks 22 | @param ct The ciphertext 23 | @param pt [out] The plaintext 24 | @param len The length in octets, must be a multiple of 16 25 | @param lrw The LRW state 26 | */ 27 | int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw) 28 | { 29 | int err; 30 | 31 | LTC_ARGCHK(pt != NULL); 32 | LTC_ARGCHK(ct != NULL); 33 | LTC_ARGCHK(lrw != NULL); 34 | 35 | if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { 36 | return err; 37 | } 38 | 39 | if (cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) { 40 | return cipher_descriptor[lrw->cipher].accel_lrw_decrypt(ct, pt, len, lrw->IV, lrw->tweak, &lrw->key); 41 | } 42 | 43 | return lrw_process(ct, pt, len, LRW_DECRYPT, lrw); 44 | } 45 | 46 | 47 | #endif 48 | 49 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_decrypt.c,v $ */ 50 | /* $Revision: 1.8 $ */ 51 | /* $Date: 2006/06/29 01:53:13 $ */ 52 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 42 | /* $Date: 2006/06/29 01:53:13 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/modes/lrw/lrw_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://libtomcrypt.com 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file lrw_encrypt.c 15 | LRW_MODE implementation, Encrypt blocks, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_LRW_MODE 19 | 20 | /** 21 | LRW encrypt blocks 22 | @param pt The plaintext 23 | @param ct [out] The ciphertext 24 | @param len The length in octets, must be a multiple of 16 25 | @param lrw The LRW state 26 | */ 27 | int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw) 28 | { 29 | int err; 30 | 31 | LTC_ARGCHK(pt != NULL); 32 | LTC_ARGCHK(ct != NULL); 33 | LTC_ARGCHK(lrw != NULL); 34 | 35 | if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { 36 | return err; 37 | } 38 | 39 | if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL) { 40 | return cipher_descriptor[lrw->cipher].accel_lrw_encrypt(pt, ct, len, lrw->IV, lrw->tweak, &lrw->key); 41 | } 42 | 43 | return lrw_process(pt, ct, len, LRW_ENCRYPT, lrw); 44 | } 45 | 46 | 47 | #endif 48 | /* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_encrypt.c,v $ */ 49 | /* $Revision: 1.9 $ */ 50 | /* $Date: 2006/06/29 01:53:13 $ */ 51 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.9 $ */ 45 | /* $Date: 2006/06/29 01:53:13 $ */ 46 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.5 $ */ 43 | /* $Date: 2006/06/29 01:51:34 $ */ 44 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 42 | /* $Date: 2006/06/29 01:51:34 $ */ 43 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 46 | /* $Date: 2006/06/29 01:51:34 $ */ 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.6 $ */ 52 | /* $Date: 2006/06/29 01:51:34 $ */ 53 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.1 $ */ 47 | /* $Date: 2006/04/22 17:01:59 $ */ 48 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.3 $ */ 51 | /* $Date: 2006/06/16 21:53:41 $ */ 52 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.2 $ */ 35 | /* $Date: 2006/04/22 17:28:38 $ */ 36 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.4 $ */ 46 | /* $Date: 2006/03/31 14:15:35 $ */ 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.6 $ */ 34 | /* $Date: 2006/06/09 01:38:13 $ */ 35 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 39 | /* $Date: 2006/06/09 01:38:14 $ */ 40 | 41 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 43 | /* $Date: 2006/11/21 00:10:18 $ */ 44 | 45 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 47 | /* $Date: 2006/06/09 01:38:14 $ */ 48 | 49 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 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.4 $ */ 45 | /* $Date: 2006/11/21 00:10:18 $ */ 46 | 47 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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.2 $ */ 35 | /* $Date: 2006/03/31 14:15:35 $ */ 36 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 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 PKCS_1 19 | 20 | /* always stores the same # of bytes, pads with leading zero bytes 21 | as required 22 | */ 23 | 24 | /** 25 | 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 /* PKCS_1 */ 47 | 48 | 49 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_i2osp.c,v $ */ 50 | /* $Revision: 1.5 $ */ 51 | /* $Date: 2006/03/31 14:15:35 $ */ 52 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file pkcs_1_os2ip.c 15 | Octet to Integer OS2IP, Tom St Denis 16 | */ 17 | #ifdef 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 /* PKCS_1 */ 32 | 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_os2ip.c,v $ */ 35 | /* $Revision: 1.5 $ */ 36 | /* $Date: 2006/03/31 14:15:35 $ */ 37 | -------------------------------------------------------------------------------- /libtomcrypt/src/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://libtomcrypt.com 10 | */ 11 | #include "tomcrypt.h" 12 | 13 | /** 14 | @file rsa_free.c 15 | Free an RSA key, Tom St Denis 16 | */ 17 | 18 | #ifdef 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.8 $ */ 34 | /* $Date: 2006/12/04 22:23:27 $ */ 35 | -------------------------------------------------------------------------------- /libtomcrypt/testbuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "$1 (Build Only, $2, $3)..." 3 | make clean 1>/dev/null 2>/dev/null 4 | echo -n "building..." 5 | touch testok.txt 6 | CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -f $3 test tv_gen 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && rm -f testok.txt && exit 1) 7 | if find testok.txt -type f 1>/dev/null 2>/dev/null ; then 8 | echo "successful" 9 | exit 0 10 | fi 11 | exit 1 12 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/base64_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int base64_test(void) 4 | { 5 | unsigned char in[64], out[256], tmp[64]; 6 | unsigned long x, l1, l2; 7 | 8 | for (x = 0; x < 64; x++) { 9 | yarrow_read(in, x, &yarrow_prng); 10 | l1 = sizeof(out); 11 | DO(base64_encode(in, x, out, &l1)); 12 | l2 = sizeof(tmp); 13 | DO(base64_decode(out, l1, tmp, &l2)); 14 | if (l2 != x || memcmp(tmp, in, x)) { 15 | fprintf(stderr, "base64 failed %lu %lu %lu", x, l1, l2); 16 | return 1; 17 | } 18 | } 19 | return 0; 20 | } 21 | 22 | /* $Source: /cvs/libtom/libtomcrypt/testprof/base64_test.c,v $ */ 23 | /* $Revision: 1.5 $ */ 24 | /* $Date: 2005/05/21 12:51:25 $ */ 25 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/cipher_hash_test.c: -------------------------------------------------------------------------------- 1 | /* test the ciphers and hashes using their built-in self-tests */ 2 | 3 | #include 4 | 5 | int cipher_hash_test(void) 6 | { 7 | int x; 8 | unsigned char buf[4096]; 9 | unsigned long n; 10 | prng_state nprng; 11 | 12 | /* test ciphers */ 13 | for (x = 0; cipher_descriptor[x].name != NULL; x++) { 14 | DO(cipher_descriptor[x].test()); 15 | } 16 | 17 | /* test hashes */ 18 | for (x = 0; hash_descriptor[x].name != NULL; x++) { 19 | DO(hash_descriptor[x].test()); 20 | } 21 | 22 | /* test prngs (test, import/export */ 23 | for (x = 0; prng_descriptor[x].name != NULL; x++) { 24 | DO(prng_descriptor[x].test()); 25 | DO(prng_descriptor[x].start(&nprng)); 26 | DO(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng)); 27 | DO(prng_descriptor[x].ready(&nprng)); 28 | n = sizeof(buf); 29 | DO(prng_descriptor[x].pexport(buf, &n, &nprng)); 30 | prng_descriptor[x].done(&nprng); 31 | DO(prng_descriptor[x].pimport(buf, n, &nprng)); 32 | DO(prng_descriptor[x].ready(&nprng)); 33 | if (prng_descriptor[x].read(buf, 100, &nprng) != 100) { 34 | fprintf(stderr, "Error reading from imported PRNG!\n"); 35 | exit(EXIT_FAILURE); 36 | } 37 | prng_descriptor[x].done(&nprng); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | /* $Source: /cvs/libtom/libtomcrypt/testprof/cipher_hash_test.c,v $ */ 44 | /* $Revision: 1.3 $ */ 45 | /* $Date: 2005/05/05 14:35:59 $ */ 46 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/mac_test.c: -------------------------------------------------------------------------------- 1 | /* test pmac/omac/hmac */ 2 | #include 3 | 4 | int mac_test(void) 5 | { 6 | #ifdef LTC_HMAC 7 | DO(hmac_test()); 8 | #endif 9 | #ifdef LTC_PMAC 10 | DO(pmac_test()); 11 | #endif 12 | #ifdef LTC_OMAC 13 | DO(omac_test()); 14 | #endif 15 | #ifdef LTC_XCBC 16 | DO(xcbc_test()); 17 | #endif 18 | #ifdef LTC_F9_MODE 19 | DO(f9_test()); 20 | #endif 21 | #ifdef EAX_MODE 22 | DO(eax_test()); 23 | #endif 24 | #ifdef OCB_MODE 25 | DO(ocb_test()); 26 | #endif 27 | #ifdef CCM_MODE 28 | DO(ccm_test()); 29 | #endif 30 | #ifdef GCM_MODE 31 | DO(gcm_test()); 32 | #endif 33 | #ifdef PELICAN 34 | DO(pelican_test()); 35 | #endif 36 | return 0; 37 | } 38 | 39 | /* $Source: /cvs/libtom/libtomcrypt/testprof/mac_test.c,v $ */ 40 | /* $Revision: 1.5 $ */ 41 | /* $Date: 2006/11/08 21:57:04 $ */ 42 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/makefile: -------------------------------------------------------------------------------- 1 | CFLAGS += -I../src/headers -I./ -Wall -W 2 | 3 | # ranlib tools 4 | ifndef RANLIB 5 | RANLIB=ranlib 6 | endif 7 | 8 | OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \ 9 | dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \ 10 | store_test.o test_driver.o x86_prof.o katja_test.o 11 | 12 | ifndef LIBTEST_S 13 | LIBTEST_S=libtomcrypt_prof.a 14 | endif 15 | 16 | default: $(LIBTEST_S) 17 | 18 | $(LIBTEST_S): $(OBJECTS) 19 | $(AR) $(ARFLAGS) $@ $(OBJECTS) 20 | $(RANLIB) $@ 21 | 22 | clean: 23 | rm -f *.o *.a 24 | 25 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/makefile.icc: -------------------------------------------------------------------------------- 1 | CFLAGS += -I../src/headers -I./ 2 | CC=icc 3 | 4 | OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \ 5 | dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \ 6 | store_test.o test_driver.o x86_prof.o katja_test.o 7 | 8 | ifndef LIBTEST_S 9 | LIBTEST_S = libtomcrypt_prof.a 10 | endif 11 | 12 | default: $(LIBTEST_S) 13 | 14 | $(LIBTEST_S): $(OBJECTS) 15 | $(AR) $(ARFLAGS) $@ $(OBJECTS) 16 | ranlib $@ 17 | 18 | clean: 19 | rm -f *.o *.a 20 | 21 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/makefile.msvc: -------------------------------------------------------------------------------- 1 | CFLAGS = /I../src/headers/ /I./ /Ox /DWIN32 /DLTC_SOURCE /W3 /Fo$@ 2 | 3 | OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj \ 4 | dsa_test.obj ecc_test.obj mac_test.obj modes_test.obj pkcs_1_test.obj \ 5 | rsa_test.obj store_test.obj test_driver.obj x86_prof.obj katja_test.obj 6 | 7 | tomcrypt_prof.lib: $(OBJECTS) 8 | lib /out:tomcrypt_prof.lib $(OBJECTS) 9 | 10 | 11 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/makefile.shared: -------------------------------------------------------------------------------- 1 | CC=libtool --mode=compile gcc 2 | 3 | CFLAGS += -I../src/headers -I./ -Wall -W 4 | 5 | # ranlib tools 6 | ifndef RANLIB 7 | RANLIB=ranlib 8 | endif 9 | 10 | OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \ 11 | dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \ 12 | store_test.o test_driver.o x86_prof.o katja_test.o 13 | 14 | ifndef LIBTEST 15 | LIBTEST=libtomcrypt_prof.la 16 | endif 17 | 18 | default: $(LIBTEST) 19 | 20 | $(LIBTEST): $(OBJECTS) 21 | libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]lo" | xargs` -o $@ -rpath $(LIBPATH) -version-info $(VERSION) 22 | 23 | install: $(LIBTEST) 24 | libtool --silent --mode=install install -c $(LIBTEST) $(DESTDIR)$(LIBPATH)/$(LIBTEST) 25 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/test.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtomcrypt/testprof/test.der -------------------------------------------------------------------------------- /libtomcrypt/testprof/test.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXgIBAAKBgQDPmt5kitrIMyCp14MxGVSymoWnobd1M7aprIQks97bfYUtlmXl 3 | P3KVJJ8oaMpP20QcPmASit0mpev/C17UiDhJKm5bvxI3R70Fa7zb8+7kEY5BaHxh 4 | E9dCyIC+No/cCItPrKTidgzJY2xJWJPtzKrcJTsKYD+LVDrDTTHnlKRE/QIDAQAB 5 | AoGBAMhiuereRFMdVpfZl54azzAeCohFhikwo02fYWVz4NaHj7bzBqOC3Hys/pso 6 | mq79+/4vDtiXBOO7H9HsDbqjSX9HrIpEBH6GtzlCP60etw6lUfRAYx79veqfQZ+o 7 | kB1vClqVExENgK9fZJiKLHhoZbAri6JTh8rxZASr8nvbg8iBAkEA975eI8MyP7+L 8 | jjru/PzL5ffxC7xCgq7Vej7K99VpP2Qloh+3dXUFkkLruPHzCgXjlNFVeDWgNqCb 9 | fJKEbN3cTQJBANaGDoVCCwQIhCFg8A4NiP0eNhBlTx5TtAhygFw/WWYX5pjy6Wx6 10 | Bkysdj3tjKHOrRu9tH0ovOMOOI2Z2AW1o3ECQG3rwy0u8F6kiDEFKQCK0ZUpm4PP 11 | ddsx43on3jp0MAx2TNRQKkAtOdmZY6ldgK5TypQ/BSMe+AUE4bg18hezoIkCQQCr 12 | kIj6YAgpUJpDi6BQzNha/pdkY3F0IqMgAlrP68YWlVTRy6uNGsYA+giSnHHVUlI1 13 | lnFLi5IM0Om/rWMLpemxAkEA3MwnyOTcYkjVm6/1q2D2If1T4rddCckaoQSp/GEs 14 | XQRYOlo58UohVmf9zCCjj3gYWnk9Lo5+hgrmqDPBBBdKnw== 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /libtomcrypt/testprof/test_driver.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void run_cmd(int res, int line, char *file, char *cmd) 4 | { 5 | if (res != CRYPT_OK) { 6 | fprintf(stderr, "%s (%d)\n%s:%d:%s\n", error_to_string(res), res, file, line, cmd); 7 | if (res != CRYPT_NOP) { 8 | exit(EXIT_FAILURE); 9 | } 10 | } 11 | } 12 | 13 | /* $Source: /cvs/libtom/libtomcrypt/testprof/test_driver.c,v $ */ 14 | /* $Revision: 1.2 $ */ 15 | /* $Date: 2006/11/13 23:14:33 $ */ 16 | -------------------------------------------------------------------------------- /libtomcrypt/updatemakes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | bash genlist.sh > tmplist 4 | 5 | perl filter.pl makefile tmplist 6 | mv -f tmp.delme makefile 7 | 8 | perl filter.pl makefile.icc tmplist 9 | mv -f tmp.delme makefile.icc 10 | 11 | perl filter.pl makefile.shared tmplist 12 | mv -f tmp.delme makefile.shared 13 | 14 | perl filter.pl makefile.unix tmplist 15 | mv -f tmp.delme makefile.unix 16 | 17 | perl filter.pl makefile.msvc tmplist 18 | sed -e 's/\.o /.obj /g' < tmp.delme > makefile.msvc 19 | 20 | rm -f tmplist 21 | rm -f tmp.delme 22 | -------------------------------------------------------------------------------- /libtommath/LICENSE: -------------------------------------------------------------------------------- 1 | LibTomMath is hereby released into the Public Domain. 2 | 3 | -- Tom St Denis 4 | 5 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_error.c,v $ */ 46 | /* $Revision: 1.3 $ */ 47 | /* $Date: 2006/03/31 14:18:44 $ */ 48 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */ 47 | /* $Revision: 1.3 $ */ 48 | /* $Date: 2006/03/31 14:18:44 $ */ 49 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */ 42 | /* $Revision: 1.3 $ */ 43 | /* $Date: 2006/03/31 14:18:44 $ */ 44 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */ 40 | /* $Revision: 1.3 $ */ 41 | /* $Date: 2006/03/31 14:18:44 $ */ 42 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_and.c,v $ */ 56 | /* $Revision: 1.3 $ */ 57 | /* $Date: 2006/03/31 14:18:44 $ */ 58 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */ 43 | /* $Revision: 1.3 $ */ 44 | /* $Date: 2006/03/31 14:18:44 $ */ 45 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 16 | */ 17 | 18 | /* clear one (frees) */ 19 | void 20 | mp_clear (mp_int * a) 21 | { 22 | volatile mp_digit *p; 23 | int len; 24 | 25 | /* only do anything if a hasn't been freed previously */ 26 | if (a->dp != NULL) { 27 | /* first zero the digits */ 28 | len = a->alloc; 29 | p = a->dp; 30 | while (len--) { 31 | *p++ = 0; 32 | } 33 | 34 | /* free ram */ 35 | XFREE(a->dp); 36 | 37 | /* reset members to make debugging easier */ 38 | a->dp = NULL; 39 | a->alloc = a->used = 0; 40 | a->sign = MP_ZPOS; 41 | } 42 | } 43 | #endif 44 | 45 | /* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */ 46 | /* $Revision: 1.3 $ */ 47 | /* $Date: 2006/03/31 14:18:44 $ */ 48 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */ 33 | /* $Revision: 1.3 $ */ 34 | /* $Date: 2006/03/31 14:18:44 $ */ 35 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */ 42 | /* $Revision: 1.3 $ */ 43 | /* $Date: 2006/03/31 14:18:44 $ */ 44 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */ 43 | /* $Revision: 1.3 $ */ 44 | /* $Date: 2006/03/31 14:18:44 $ */ 45 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */ 54 | /* $Revision: 1.3 $ */ 55 | /* $Date: 2006/03/31 14:18:44 $ */ 56 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */ 52 | /* $Revision: 1.3 $ */ 53 | /* $Date: 2006/03/31 14:18:44 $ */ 54 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */ 44 | /* $Revision: 1.3 $ */ 45 | /* $Date: 2006/03/31 14:18:44 $ */ 46 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */ 42 | /* $Revision: 1.3 $ */ 43 | /* $Date: 2006/03/31 14:18:44 $ */ 44 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */ 31 | /* $Revision: 1.3 $ */ 32 | /* $Date: 2006/03/31 14:18:44 $ */ 33 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */ 33 | /* $Revision: 1.3 $ */ 34 | /* $Date: 2006/03/31 14:18:44 $ */ 35 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */ 51 | /* $Revision: 1.3 $ */ 52 | /* $Date: 2006/03/31 14:18:44 $ */ 53 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */ 44 | /* $Revision: 1.3 $ */ 45 | /* $Date: 2006/03/31 14:18:44 $ */ 46 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_init.c,v $ */ 45 | /* $Revision: 1.3 $ */ 46 | /* $Date: 2006/03/31 14:18:44 $ */ 47 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */ 31 | /* $Revision: 1.3 $ */ 32 | /* $Date: 2006/03/31 14:18:44 $ */ 33 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */ 31 | /* $Revision: 1.3 $ */ 32 | /* $Date: 2006/03/31 14:18:44 $ */ 33 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */ 30 | /* $Revision: 1.3 $ */ 31 | /* $Date: 2006/03/31 14:18:44 $ */ 32 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */ 47 | /* $Revision: 1.3 $ */ 48 | /* $Date: 2006/03/31 14:18:44 $ */ 49 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */ 42 | /* $Revision: 1.3 $ */ 43 | /* $Date: 2006/03/31 14:18:44 $ */ 44 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */ 47 | /* $Revision: 1.3 $ */ 48 | /* $Date: 2006/03/31 14:18:44 $ */ 49 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */ 26 | /* $Revision: 1.3 $ */ 27 | /* $Date: 2006/03/31 14:18:44 $ */ 28 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */ 39 | /* $Revision: 1.4 $ */ 40 | /* $Date: 2006/03/31 14:18:44 $ */ 41 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */ 39 | /* $Revision: 1.3 $ */ 40 | /* $Date: 2006/03/31 14:18:44 $ */ 41 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_or.c,v $ */ 49 | /* $Revision: 1.3 $ */ 50 | /* $Date: 2006/03/31 14:18:44 $ */ 51 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */ 49 | /* $Revision: 1.3 $ */ 50 | /* $Date: 2006/03/31 14:18:44 $ */ 51 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 16 | */ 17 | 18 | /* chars used in radix conversions */ 19 | const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; 20 | #endif 21 | 22 | /* $Source: /cvs/libtom/libtommath/bn_mp_radix_smap.c,v $ */ 23 | /* $Revision: 1.3 $ */ 24 | /* $Date: 2006/03/31 14:18:44 $ */ 25 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */ 54 | /* $Revision: 1.3 $ */ 55 | /* $Date: 2006/03/31 14:18:44 $ */ 56 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */ 40 | /* $Revision: 1.4 $ */ 41 | /* $Date: 2006/03/31 14:18:44 $ */ 42 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */ 46 | /* $Revision: 1.3 $ */ 47 | /* $Date: 2006/03/31 14:18:44 $ */ 48 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */ 43 | /* $Revision: 1.3 $ */ 44 | /* $Date: 2006/03/31 14:18:44 $ */ 45 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */ 43 | /* $Revision: 1.3 $ */ 44 | /* $Date: 2006/03/31 14:18:44 $ */ 45 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */ 33 | /* $Revision: 1.3 $ */ 34 | /* $Date: 2006/03/31 14:18:44 $ */ 35 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_set.c,v $ */ 28 | /* $Revision: 1.3 $ */ 29 | /* $Date: 2006/03/31 14:18:44 $ */ 30 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */ 47 | /* $Revision: 1.3 $ */ 48 | /* $Date: 2006/03/31 14:18:44 $ */ 49 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 16 | */ 17 | 18 | /* shrink a bignum */ 19 | int mp_shrink (mp_int * a) 20 | { 21 | mp_digit *tmp; 22 | if (a->alloc != a->used && a->used > 0) { 23 | if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * a->used)) == NULL) { 24 | return MP_MEM; 25 | } 26 | a->dp = tmp; 27 | a->alloc = a->used; 28 | } 29 | return MP_OKAY; 30 | } 31 | #endif 32 | 33 | /* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */ 34 | /* $Revision: 1.3 $ */ 35 | /* $Date: 2006/03/31 14:18:44 $ */ 36 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */ 26 | /* $Revision: 1.3 $ */ 27 | /* $Date: 2006/03/31 14:18:44 $ */ 28 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */ 40 | /* $Revision: 1.3 $ */ 41 | /* $Date: 2006/03/31 14:18:44 $ */ 42 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */ 41 | /* $Revision: 1.3 $ */ 42 | /* $Date: 2006/03/31 14:18:44 $ */ 43 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_to_signed_bin.c,v $ */ 32 | /* $Revision: 1.3 $ */ 33 | /* $Date: 2006/03/31 14:18:44 $ */ 34 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */ 30 | /* $Revision: 1.3 $ */ 31 | /* $Date: 2006/03/31 14:18:44 $ */ 32 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */ 47 | /* $Revision: 1.3 $ */ 48 | /* $Date: 2006/03/31 14:18:44 $ */ 49 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */ 30 | /* $Revision: 1.3 $ */ 31 | /* $Date: 2006/03/31 14:18:44 $ */ 32 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_unsigned_bin_size.c,v $ */ 27 | /* $Revision: 1.3 $ */ 28 | /* $Date: 2006/03/31 14:18:44 $ */ 29 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */ 50 | /* $Revision: 1.3 $ */ 51 | /* $Date: 2006/03/31 14:18:44 $ */ 52 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */ 35 | /* $Revision: 1.3 $ */ 36 | /* $Date: 2006/03/31 14:18:44 $ */ 37 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bn_reverse.c,v $ */ 38 | /* $Revision: 1.3 $ */ 39 | /* $Date: 2006/03/31 14:18:44 $ */ 40 | -------------------------------------------------------------------------------- /libtommath/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://math.libtomcrypt.com 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: /cvs/libtom/libtommath/bncore.c,v $ */ 35 | /* $Revision: 1.4 $ */ 36 | /* $Date: 2006/03/31 14:18:44 $ */ 37 | -------------------------------------------------------------------------------- /libtommath/etc/2kprime.1: -------------------------------------------------------------------------------- 1 | 256-bits (k = 36113) = 115792089237316195423570985008687907853269984665640564039457584007913129603823 2 | 512-bits (k = 38117) = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006045979 3 | -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/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: /cvs/libtom/libtommath/etc/mont.c,v $ */ 49 | /* $Revision: 1.2 $ */ 50 | /* $Date: 2005/05/05 14:38:47 $ */ 51 | -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/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: $!"; -------------------------------------------------------------------------------- /libtommath/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 -------------------------------------------------------------------------------- /libtommath/logs/add.log: -------------------------------------------------------------------------------- 1 | 480 87 2 | 960 111 3 | 1440 135 4 | 1920 159 5 | 2400 200 6 | 2880 224 7 | 3360 248 8 | 3840 272 9 | 4320 296 10 | 4800 320 11 | 5280 344 12 | 5760 368 13 | 6240 392 14 | 6720 416 15 | 7200 440 16 | 7680 464 17 | -------------------------------------------------------------------------------- /libtommath/logs/addsub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/logs/addsub.png -------------------------------------------------------------------------------- /libtommath/logs/expt.log: -------------------------------------------------------------------------------- 1 | 513 1435869 2 | 769 3544970 3 | 1025 7791638 4 | 2049 46902238 5 | 2561 85334899 6 | 3073 141451412 7 | 4097 308770310 8 | -------------------------------------------------------------------------------- /libtommath/logs/expt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/logs/expt.png -------------------------------------------------------------------------------- /libtommath/logs/expt_2k.log: -------------------------------------------------------------------------------- 1 | 607 2109225 2 | 1279 10148314 3 | 2203 34126877 4 | 3217 82716424 5 | 4253 161569606 6 | -------------------------------------------------------------------------------- /libtommath/logs/expt_2kl.log: -------------------------------------------------------------------------------- 1 | 1024 7705271 2 | 2048 34286851 3 | 4096 165207491 4 | 521 1618631 5 | -------------------------------------------------------------------------------- /libtommath/logs/expt_dr.log: -------------------------------------------------------------------------------- 1 | 532 1928550 2 | 784 3763908 3 | 1036 7564221 4 | 1540 16566059 5 | 2072 32283784 6 | 3080 79851565 7 | 4116 157843530 8 | -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/logs/invmod.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/logs/invmod.log -------------------------------------------------------------------------------- /libtommath/logs/invmod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/logs/invmod.png -------------------------------------------------------------------------------- /libtommath/logs/mult.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/logs/mult.png -------------------------------------------------------------------------------- /libtommath/logs/sub.log: -------------------------------------------------------------------------------- 1 | 480 94 2 | 960 116 3 | 1440 140 4 | 1920 164 5 | 2400 205 6 | 2880 229 7 | 3360 253 8 | 3840 277 9 | 4320 299 10 | 4800 321 11 | 5280 345 12 | 5760 371 13 | 6240 395 14 | 6720 419 15 | 7200 441 16 | 7680 465 17 | -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/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: /cvs/libtom/libtommath/mtest/logtab.h,v $ */ 23 | /* $Revision: 1.2 $ */ 24 | /* $Date: 2005/05/05 14:38:47 $ */ 25 | -------------------------------------------------------------------------------- /libtommath/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: /cvs/libtom/libtommath/mtest/mpi-types.h,v $ */ 19 | /* $Revision: 1.2 $ */ 20 | /* $Date: 2005/05/05 14:38:47 $ */ 21 | -------------------------------------------------------------------------------- /libtommath/pics/design_process.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/design_process.sxd -------------------------------------------------------------------------------- /libtommath/pics/design_process.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/design_process.tif -------------------------------------------------------------------------------- /libtommath/pics/expt_state.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/expt_state.sxd -------------------------------------------------------------------------------- /libtommath/pics/expt_state.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/expt_state.tif -------------------------------------------------------------------------------- /libtommath/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 | -------------------------------------------------------------------------------- /libtommath/pics/primality.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/primality.tif -------------------------------------------------------------------------------- /libtommath/pics/radix.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/radix.sxd -------------------------------------------------------------------------------- /libtommath/pics/sliding_window.sxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/sliding_window.sxd -------------------------------------------------------------------------------- /libtommath/pics/sliding_window.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/pics/sliding_window.tif -------------------------------------------------------------------------------- /libtommath/poster.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/libtommath/poster.out -------------------------------------------------------------------------------- /openpty.c: -------------------------------------------------------------------------------- 1 | #include "includes.h" 2 | 3 | int 4 | openpty (int *amaster, int *aslave, char *name, struct termios *termp, 5 | struct winsize *winp) 6 | { 7 | int master, slave; 8 | char *name_slave; 9 | 10 | master = open("/dev/ptmx", O_RDWR | O_NONBLOCK); 11 | if (master == -1) { 12 | TRACE(("Fail to open master")) 13 | return -1; 14 | } 15 | 16 | if (grantpt(master)) 17 | goto fail; 18 | 19 | if (unlockpt(master)) 20 | goto fail; 21 | 22 | name_slave = ptsname(master); 23 | TRACE(("openpty: slave name %s", name_slave)) 24 | slave = open(name_slave, O_RDWR | O_NOCTTY); 25 | if (slave == -1) 26 | { 27 | goto fail; 28 | } 29 | 30 | if(termp) 31 | tcsetattr(slave, TCSAFLUSH, termp); 32 | if (winp) 33 | ioctl (slave, TIOCSWINSZ, winp); 34 | 35 | *amaster = master; 36 | *aslave = slave; 37 | if (name != NULL) 38 | strcpy(name, name_slave); 39 | 40 | return 0; 41 | 42 | fail: 43 | close (master); 44 | return -1; 45 | } 46 | -------------------------------------------------------------------------------- /service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dropbear - a SSH2 server 3 | * 4 | * Copyright (c) 2002,2003 Matt Johnston 5 | * All rights reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. */ 24 | 25 | #ifndef _SERVICE_H_ 26 | #define _SERVICE_H_ 27 | 28 | void recv_msg_service_request(); /* Server */ 29 | void send_msg_service_request(); /* Client */ 30 | void recv_msg_service_accept(); /* Client */ 31 | 32 | #endif /* _SERVICE_H_ */ 33 | -------------------------------------------------------------------------------- /sftp-server/Android.mk: -------------------------------------------------------------------------------- 1 | ifneq ($(TARGET_SIMULATOR),true) 2 | 3 | LOCAL_PATH:= $(call my-dir) 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_SRC_FILES:=\ 7 | sftp-server.c sftp-common.c sftp-server-main.c \ 8 | addrmatch.c bufaux.c buffer.c compat.c log.c \ 9 | openbsd-compat/bsd-misc.c openbsd-compat/bsd-statvfs.c \ 10 | openbsd-compat/fmt_scaled.c openbsd-compat/getopt.c openbsd-compat/port-tun.c \ 11 | openbsd-compat/pwcache.c \ 12 | openbsd-compat/strmode.c openbsd-compat/strtonum.c openbsd-compat/vis.c \ 13 | match.c misc.c \ 14 | xmalloc.c 15 | 16 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 17 | LOCAL_MODULE_TAGS := eng 18 | LOCAL_MODULE := sftp-server 19 | 20 | include $(BUILD_EXECUTABLE) 21 | 22 | include $(CLEAR_VARS) 23 | 24 | endif # TARGET_SIMULATOR != true 25 | 26 | include $(call all-makefiles-under,$(LOCAL_PATH)) 27 | -------------------------------------------------------------------------------- /sftp-server/LICENCE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/sftp-server/LICENCE -------------------------------------------------------------------------------- /sftp-server/match.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: match.h,v 1.15 2010/02/26 20:29:54 djm Exp $ */ 2 | 3 | /* 4 | * Author: Tatu Ylonen 5 | * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland 6 | * All rights reserved 7 | * 8 | * As far as I am concerned, the code I have written for this software 9 | * can be used freely for any purpose. Any derived versions of this 10 | * software must be clearly marked as such, and if the derived work is 11 | * incompatible with the protocol description in the RFC file, it must be 12 | * called by a name other than "ssh" or "Secure Shell". 13 | */ 14 | #ifndef MATCH_H 15 | #define MATCH_H 16 | 17 | int match_pattern(const char *, const char *); 18 | int match_pattern_list(const char *, const char *, u_int, int); 19 | int match_hostname(const char *, const char *, u_int); 20 | int match_host_and_ip(const char *, const char *, const char *); 21 | int match_user(const char *, const char *, const char *, const char *); 22 | char *match_list(const char *, const char *, u_int *); 23 | 24 | /* addrmatch.c */ 25 | int addr_match_list(const char *, const char *); 26 | int addr_match_cidr_list(const char *, const char *); 27 | #endif 28 | -------------------------------------------------------------------------------- /sftp-server/openbsd-compat/bsd-statvfs.c: -------------------------------------------------------------------------------- 1 | /* $Id: bsd-statvfs.c,v 1.1 2008/06/08 17:32:29 dtucker Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2008 Darren Tucker 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "includes.h" 20 | 21 | #include 22 | 23 | #ifndef HAVE_STATVFS 24 | int statvfs(const char *path, struct statvfs *buf) 25 | { 26 | errno = ENOSYS; 27 | return -1; 28 | } 29 | #endif 30 | 31 | #ifndef HAVE_FSTATVFS 32 | int fstatvfs(int fd, struct statvfs *buf) 33 | { 34 | errno = ENOSYS; 35 | return -1; 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /sftp-server/openbsd-compat/port-linux.h: -------------------------------------------------------------------------------- 1 | /* $Id: port-linux.h,v 1.4 2009/12/08 02:39:48 dtucker Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2006 Damien Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _PORT_LINUX_H 20 | #define _PORT_LINUX_H 21 | 22 | #ifdef WITH_SELINUX 23 | int ssh_selinux_enabled(void); 24 | void ssh_selinux_setup_pty(char *, const char *); 25 | void ssh_selinux_setup_exec_context(char *); 26 | void ssh_selinux_change_context(const char *); 27 | #endif 28 | 29 | #ifdef LINUX_OOM_ADJUST 30 | void oom_adjust_restore(void); 31 | void oom_adjust_setup(void); 32 | #endif 33 | 34 | #endif /* ! _PORT_LINUX_H */ 35 | -------------------------------------------------------------------------------- /sftp-server/openbsd-compat/port-solaris.h: -------------------------------------------------------------------------------- 1 | /* $Id: port-solaris.h,v 1.1 2006/08/30 17:24:42 djm Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2006 Chad Mynhier. 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _PORT_SOLARIS_H 20 | 21 | #include 22 | 23 | void solaris_contract_pre_fork(void); 24 | void solaris_contract_post_fork_child(void); 25 | void solaris_contract_post_fork_parent(pid_t pid); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sftp-server/openbsd-compat/port-tun.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Reyk Floeter 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _PORT_TUN_H 18 | #define _PORT_TUN_H 19 | 20 | struct Channel; 21 | 22 | #if defined(SSH_TUN_LINUX) || defined(SSH_TUN_FREEBSD) 23 | # define CUSTOM_SYS_TUN_OPEN 24 | int sys_tun_open(int, int); 25 | #endif 26 | 27 | #if defined(SSH_TUN_COMPAT_AF) || defined(SSH_TUN_PREPEND_AF) 28 | # define SSH_TUN_FILTER 29 | int sys_tun_infilter(struct Channel *, char *, int); 30 | u_char *sys_tun_outfilter(struct Channel *, u_char **, u_int *); 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /sftp-server/openbsd-compat/port-uw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Tim Rice. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #include "includes.h" 26 | 27 | #ifdef USE_LIBIAF 28 | char * get_iaf_password(struct passwd *pw); 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /sftp-server/openssl/bn.h: -------------------------------------------------------------------------------- 1 | #define BIGNUM int 2 | -------------------------------------------------------------------------------- /sftp-server/openssl/opensslv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barryk/android_external_dropbear/805bd6a62e2507144d16790f70e3d0bfba80cc38/sftp-server/openssl/opensslv.h -------------------------------------------------------------------------------- /sftp-server/platform.h: -------------------------------------------------------------------------------- 1 | /* $Id: platform.h,v 1.4 2010/01/14 01:44:16 djm Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2006 Darren Tucker. All rights reserved. 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | void platform_pre_listen(void); 22 | void platform_pre_fork(void); 23 | void platform_post_fork_parent(pid_t child_pid); 24 | void platform_post_fork_child(void); 25 | char *platform_get_krb5_client(const char *); 26 | char *platform_krb5_get_principal_name(const char *); 27 | 28 | 29 | -------------------------------------------------------------------------------- /sftp-server/uidswap.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: uidswap.h,v 1.13 2006/08/03 03:34:42 deraadt Exp $ */ 2 | 3 | /* 4 | * Author: Tatu Ylonen 5 | * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland 6 | * All rights reserved 7 | * 8 | * As far as I am concerned, the code I have written for this software 9 | * can be used freely for any purpose. Any derived versions of this 10 | * software must be clearly marked as such, and if the derived work is 11 | * incompatible with the protocol description in the RFC file, it must be 12 | * called by a name other than "ssh" or "Secure Shell". 13 | */ 14 | 15 | void temporarily_use_uid(struct passwd *); 16 | void restore_uid(void); 17 | void permanently_set_uid(struct passwd *); 18 | void permanently_drop_suid(uid_t); 19 | -------------------------------------------------------------------------------- /sftp-server/xmalloc.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: xmalloc.h,v 1.13 2006/08/03 03:34:42 deraadt Exp $ */ 2 | 3 | /* 4 | * Author: Tatu Ylonen 5 | * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland 6 | * All rights reserved 7 | * Created: Mon Mar 20 22:09:17 1995 ylo 8 | * 9 | * Versions of malloc and friends that check their results, and never return 10 | * failure (they call fatal if they encounter an error). 11 | * 12 | * As far as I am concerned, the code I have written for this software 13 | * can be used freely for any purpose. Any derived versions of this 14 | * software must be clearly marked as such, and if the derived work is 15 | * incompatible with the protocol description in the RFC file, it must be 16 | * called by a name other than "ssh" or "Secure Shell". 17 | */ 18 | 19 | void *xmalloc(size_t); 20 | void *xcalloc(size_t, size_t); 21 | void *xrealloc(void *, size_t, size_t); 22 | void xfree(void *); 23 | char *xstrdup(const char *); 24 | int xasprintf(char **, const char *, ...) 25 | __attribute__((__format__ (printf, 2, 3))) 26 | __attribute__((__nonnull__ (2))); 27 | -------------------------------------------------------------------------------- /sshpty.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: sshpty.h,v 1.4 2002/03/04 17:27:39 stevesk Exp $ */ 2 | 3 | /* 4 | * Copied from openssh-3.5p1 source by Matt Johnston 2003 5 | * 6 | * Author: Tatu Ylonen 7 | * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland 8 | * All rights reserved 9 | * Functions for allocating a pseudo-terminal and making it the controlling 10 | * tty. 11 | * 12 | * As far as I am concerned, the code I have written for this software 13 | * can be used freely for any purpose. Any derived versions of this 14 | * software must be clearly marked as such, and if the derived work is 15 | * incompatible with the protocol description in the RFC file, it must be 16 | * called by a name other than "ssh" or "Secure Shell". 17 | */ 18 | 19 | #ifndef SSHPTY_H 20 | #define SSHPTY_H 21 | 22 | int pty_allocate(int *, int *, char *, int); 23 | void pty_release(const char *); 24 | void pty_make_controlling_tty(int *, const char *); 25 | void pty_change_window_size(int, int, int, int, int); 26 | void pty_setowner(struct passwd *, const char *); 27 | 28 | #endif /* SSHPTY_H */ 29 | --------------------------------------------------------------------------------