diff options
32 files changed, 3249 insertions, 512 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5503d83..4d18488 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,20 @@ set(TOMCRYPT_FILES             src/libtomcrypt/src/pk/asn1/der_decode_short_integer.c             src/libtomcrypt/src/pk/asn1/der_decode_utctime.c             src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.c +           src/libtomcrypt/src/pk/asn1/der_encode_bit_string.c +           src/libtomcrypt/src/pk/asn1/der_encode_boolean.c +           src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.c +           src/libtomcrypt/src/pk/asn1/der_encode_integer.c +           src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.c +           src/libtomcrypt/src/pk/asn1/der_encode_octet_string.c +           src/libtomcrypt/src/pk/asn1/der_encode_printable_string.c +           src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.c +           src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.c +           src/libtomcrypt/src/pk/asn1/der_encode_set.c +           src/libtomcrypt/src/pk/asn1/der_encode_setof.c +           src/libtomcrypt/src/pk/asn1/der_encode_short_integer.c +           src/libtomcrypt/src/pk/asn1/der_encode_utctime.c +           src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.c             src/libtomcrypt/src/pk/asn1/der_length_bit_string.c             src/libtomcrypt/src/pk/asn1/der_length_boolean.c             src/libtomcrypt/src/pk/asn1/der_length_ia5_string.c @@ -88,11 +102,14 @@ set(TOMCRYPT_FILES             src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.c             src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.c             src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.c +           src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c             src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.c +           src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c             src/libtomcrypt/src/pk/rsa/rsa_exptmod.c             src/libtomcrypt/src/pk/rsa/rsa_free.c             src/libtomcrypt/src/pk/rsa/rsa_import.c             src/libtomcrypt/src/pk/rsa/rsa_make_key.c +           src/libtomcrypt/src/pk/rsa/rsa_sign_hash.c             src/libtomcrypt/src/pk/rsa/rsa_verify_hash.c  ) diff --git a/Makefile.linux b/Makefile.linux index 46cdd1c..c588d61 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -28,8 +28,9 @@ CFLAGS = -fPIC -D_7ZIP_ST  CFLAGS += $(OFLAGS) $(DFLAGS)  OBJS =  src/adpcm/adpcm.o \ -	src/FileStream.o \  	src/huffman/huff.o \ +	src/sparse/sparse.o \ +	src/FileStream.o \  	src/SBaseCommon.o \          src/SBaseDumpData.o \  	src/SBaseFileTable.o \ @@ -47,8 +48,7 @@ OBJS =  src/adpcm/adpcm.o \  	src/SFileOpenFileEx.o \  	src/SFilePatchArchives.o \  	src/SFileReadFile.o \ -	src/SFileVerify.o \ -	src/sparse/sparse.o +	src/SFileVerify.o  COBJS = src/libtomcrypt/src/hashes/sha1.o \  	src/libtomcrypt/src/hashes/hash_memory.o \ @@ -69,48 +69,65 @@ COBJS = src/libtomcrypt/src/hashes/sha1.o \  	src/libtomcrypt/src/math/multi.o \  	src/libtomcrypt/src/math/ltm_desc.o \  	src/libtomcrypt/src/math/rand_prime.o \ -	src/libtomcrypt/src/pk/asn1/der_length_ia5_string.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_utctime.o \ -	src/libtomcrypt/src/pk/asn1/der_length_boolean.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_object_identifier.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_sequence_multi.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_octet_string.o \ -	src/libtomcrypt/src/pk/asn1/der_length_object_identifier.o \ -	src/libtomcrypt/src/pk/asn1/der_length_bit_string.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_ia5_string.o \ -	src/libtomcrypt/src/pk/asn1/der_length_integer.o \ -	src/libtomcrypt/src/pk/asn1/der_length_sequence.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_choice.o \ -	src/libtomcrypt/src/pk/asn1/der_length_octet_string.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_sequence_flexi.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_printable_string.o \  	src/libtomcrypt/src/pk/asn1/der_decode_bit_string.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_short_integer.o \ -	src/libtomcrypt/src/pk/asn1/der_length_utctime.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_integer.o \  	src/libtomcrypt/src/pk/asn1/der_decode_boolean.o \ -	src/libtomcrypt/src/pk/asn1/der_sequence_free.o \ -	src/libtomcrypt/src/pk/asn1/der_decode_sequence_ex.o \ -	src/libtomcrypt/src/pk/asn1/der_length_short_integer.o \ -	src/libtomcrypt/src/pk/asn1/der_length_printable_string.o \ -	src/libtomcrypt/src/pk/asn1/der_length_utf8_string.o \ -	src/libtomcrypt/src/pk/rsa/rsa_make_key.o \ -	src/libtomcrypt/src/pk/rsa/rsa_free.o \ -	src/libtomcrypt/src/pk/rsa/rsa_verify_simple.o \ -	src/libtomcrypt/src/pk/rsa/rsa_import.o \ -	src/libtomcrypt/src/pk/rsa/rsa_verify_hash.o \ -	src/libtomcrypt/src/pk/rsa/rsa_exptmod.o \ -	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.o \ -	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.o \ -	src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.o \ -	src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_choice.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_ex.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_flexi.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_multi.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_short_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_bit_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_set.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_setof.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_short_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_bit_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_length_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_length_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_length_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_sequence.o \ +        src/libtomcrypt/src/pk/asn1/der_length_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_sequence_free.o \ +        src/libtomcrypt/src/pk/asn1/der_length_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_short_integer.o \  	src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_point.o \  	src/libtomcrypt/src/pk/ecc/ltc_ecc_mulmod.o \  	src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.o \  	src/libtomcrypt/src/pk/ecc/ltc_ecc_map.o \  	src/libtomcrypt/src/pk/ecc/ltc_ecc_points.o \  	src/libtomcrypt/src/pk/ecc/ltc_ecc_mul2add.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.o \ +	src/libtomcrypt/src/pk/rsa/rsa_make_key.o \ +	src/libtomcrypt/src/pk/rsa/rsa_free.o \ +	src/libtomcrypt/src/pk/rsa/rsa_verify_simple.o \ +	src/libtomcrypt/src/pk/rsa/rsa_import.o \ +	src/libtomcrypt/src/pk/rsa/rsa_verify_hash.o \ +	src/libtomcrypt/src/pk/rsa/rsa_sign_hash.o \ +	src/libtomcrypt/src/pk/rsa/rsa_exptmod.o \  	src/libtommath/bn_mp_exptmod_fast.o \  	src/libtommath/bn_mp_jacobi.o \  	src/libtommath/bn_mp_mod.o \ diff --git a/Makefile.mac b/Makefile.mac index f024f2c..b5c59db 100644 --- a/Makefile.mac +++ b/Makefile.mac @@ -19,215 +19,241 @@ ARFLAGS= rcs  LIBRARY  = libStorm.dylib -OBJS_CPP = src/adpcm/adpcm.obj \ -           src/huffman/huff.obj \ -           src/sparse/sparse.obj \ -           src/FileStream.obj \ -           src/SBaseCommon.o \ -           src/SBaseDumpData.o \ -           src/SBaseFileTable.o \ -           src/SBaseSubTypes.o \ -           src/SCompression.obj \ -           src/SFileAddFile.obj \ -           src/SFileAttributes.obj \ -           src/SFileCompactArchive.obj \ -           src/SFileCreateArchive.obj \ -           src/SFileExtractFile.obj \ -           src/SFileFindFile.obj \ -           src/SFileGetFileInfo.obj \ -           src/SFileListFile.obj \ -           src/SFileOpenArchive.obj \ -           src/SFileOpenFileEx.obj \ -           src/SFilePatchArchives.obj \ -           src/SFileReadFile.obj \ -           src/SFileVerify.obj +OBJS  = src/adpcm/adpcm.o \ +        src/huffman/huff.o \ +        src/sparse/sparse.o \ +        src/FileStream.o \ +        src/SBaseCommon.o \ +        src/SBaseDumpData.o \ +        src/SBaseFileTable.o \ +        src/SBaseSubTypes.o \ +        src/SCompression.o \ +        src/SFileAddFile.o \ +        src/SFileAttributes.o \ +        src/SFileCompactArchive.o \ +        src/SFileCreateArchive.o \ +        src/SFileExtractFile.o \ +        src/SFileFindFile.o \ +        src/SFileGetFileInfo.o \ +        src/SFileListFile.o \ +        src/SFileOpenArchive.o \ +        src/SFileOpenFileEx.o \ +        src/SFilePatchArchives.o \ +        src/SFileReadFile.o \ +        src/SFileVerify.o - -OBJS_C   = src/jenkins/lookup3.o \ -           src/libtomcrypt/src/hashes/hash_memory.obj \ -           src/libtomcrypt/src/hashes/md5.obj \ -           src/libtomcrypt/src/hashes/sha1.obj\ -           src/libtomcrypt/src/math/ltm_desc.obj \ -           src/libtomcrypt/src/math/multi.obj \ -           src/libtomcrypt/src/math/rand_prime.obj \ -           src/libtomcrypt/src/misc/base64_decode.obj \ -           src/libtomcrypt/src/misc/crypt_argchk.obj \ -           src/libtomcrypt/src/misc/crypt_find_hash.obj \ -           src/libtomcrypt/src/misc/crypt_find_prng.obj \ -           src/libtomcrypt/src/misc/crypt_hash_descriptor.obj \ -           src/libtomcrypt/src/misc/crypt_hash_is_valid.obj \ -           src/libtomcrypt/src/misc/crypt_libc.obj \ -           src/libtomcrypt/src/misc/crypt_ltc_mp_descriptor.obj \ -           src/libtomcrypt/src/misc/crypt_prng_descriptor.obj \ -           src/libtomcrypt/src/misc/crypt_prng_is_valid.obj \ -           src/libtomcrypt/src/misc/crypt_register_hash.obj \ -           src/libtomcrypt/src/misc/crypt_register_prng.obj \ -           src/libtomcrypt/src/misc/zeromem.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_bit_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_boolean.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_choice.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_ia5_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_integer.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_object_identifier.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_octet_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_printable_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_sequence_ex.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_sequence_flexi.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_sequence_multi.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_short_integer.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_utctime.obj \ -           src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_bit_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_boolean.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_ia5_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_integer.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_object_identifier.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_octet_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_printable_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_sequence.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_short_integer.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_utctime.obj \ -           src/libtomcrypt/src/pk/asn1/der_length_utf8_string.obj \ -           src/libtomcrypt/src/pk/asn1/der_sequence_free.obj \ -           src/libtomcrypt/src/pk/ecc/ltc_ecc_map.obj \ -           src/libtomcrypt/src/pk/ecc/ltc_ecc_mul2add.obj \ -           src/libtomcrypt/src/pk/ecc/ltc_ecc_mulmod.obj \ -           src/libtomcrypt/src/pk/ecc/ltc_ecc_points.obj \ -           src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.obj \ -           src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_point.obj \ -           src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.obj \ -           src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.obj \ -           src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.obj \ -           src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.obj \ -           src/libtomcrypt/src/pk/rsa/rsa_exptmod.obj \ -           src/libtomcrypt/src/pk/rsa/rsa_free.obj \ -           src/libtomcrypt/src/pk/rsa/rsa_import.obj \ -           src/libtomcrypt/src/pk/rsa/rsa_make_key.obj \ -           src/libtomcrypt/src/pk/rsa/rsa_verify_hash.obj \ -           src/libtomcrypt/src/pk/rsa/rsa_verify_simple.obj \ -           src/libtommath/bncore.obj \ -           src/libtommath/bn_fast_mp_invmod.obj \ -           src/libtommath/bn_fast_mp_montgomery_reduce.obj \ -           src/libtommath/bn_fast_s_mp_mul_digs.obj \ -           src/libtommath/bn_fast_s_mp_mul_high_digs.obj \ -           src/libtommath/bn_fast_s_mp_sqr.obj \ -           src/libtommath/bn_mp_2expt.obj \ -           src/libtommath/bn_mp_abs.obj \ -           src/libtommath/bn_mp_add.obj \ -           src/libtommath/bn_mp_addmod.obj \ -           src/libtommath/bn_mp_add_d.obj \ -           src/libtommath/bn_mp_and.obj \ -           src/libtommath/bn_mp_clamp.obj \ -           src/libtommath/bn_mp_clear.obj \ -           src/libtommath/bn_mp_clear_multi.obj \ -           src/libtommath/bn_mp_cmp.obj \ -           src/libtommath/bn_mp_cmp_d.obj \ -           src/libtommath/bn_mp_cmp_mag.obj \ -           src/libtommath/bn_mp_cnt_lsb.obj \ -           src/libtommath/bn_mp_copy.obj \ -           src/libtommath/bn_mp_count_bits.obj \ -           src/libtommath/bn_mp_div.obj \ -           src/libtommath/bn_mp_div_2.obj \ -           src/libtommath/bn_mp_div_2d.obj \ -           src/libtommath/bn_mp_div_3.obj \ -           src/libtommath/bn_mp_div_d.obj \ -           src/libtommath/bn_mp_dr_is_modulus.obj \ -           src/libtommath/bn_mp_dr_reduce.obj \ -           src/libtommath/bn_mp_dr_setup.obj \ -           src/libtommath/bn_mp_exch.obj \ -           src/libtommath/bn_mp_exptmod.obj \ -           src/libtommath/bn_mp_exptmod_fast.obj \ -           src/libtommath/bn_mp_expt_d.obj \ -           src/libtommath/bn_mp_exteuclid.obj \ -           src/libtommath/bn_mp_fread.obj \ -           src/libtommath/bn_mp_fwrite.obj \ -           src/libtommath/bn_mp_gcd.obj \ -           src/libtommath/bn_mp_get_int.obj \ -           src/libtommath/bn_mp_grow.obj \ -           src/libtommath/bn_mp_init.obj \ -           src/libtommath/bn_mp_init_copy.obj \ -           src/libtommath/bn_mp_init_multi.obj \ -           src/libtommath/bn_mp_init_set.obj \ -           src/libtommath/bn_mp_init_set_int.obj \ -           src/libtommath/bn_mp_init_size.obj \ -           src/libtommath/bn_mp_invmod.obj \ -           src/libtommath/bn_mp_invmod_slow.obj \ -           src/libtommath/bn_mp_is_square.obj \ -           src/libtommath/bn_mp_jacobi.obj \ -           src/libtommath/bn_mp_karatsuba_mul.obj \ -           src/libtommath/bn_mp_karatsuba_sqr.obj \ -           src/libtommath/bn_mp_lcm.obj \ -           src/libtommath/bn_mp_lshd.obj \ -           src/libtommath/bn_mp_mod.obj \ -           src/libtommath/bn_mp_mod_2d.obj \ -           src/libtommath/bn_mp_mod_d.obj \ -           src/libtommath/bn_mp_montgomery_calc_normalization.obj \ -           src/libtommath/bn_mp_montgomery_reduce.obj \ -           src/libtommath/bn_mp_montgomery_setup.obj \ -           src/libtommath/bn_mp_mul.obj \ -           src/libtommath/bn_mp_mulmod.obj \ -           src/libtommath/bn_mp_mul_2.obj \ -           src/libtommath/bn_mp_mul_2d.obj \ -           src/libtommath/bn_mp_mul_d.obj \ -           src/libtommath/bn_mp_neg.obj \ -           src/libtommath/bn_mp_n_root.obj \ -           src/libtommath/bn_mp_or.obj \ -           src/libtommath/bn_mp_prime_fermat.obj \ -           src/libtommath/bn_mp_prime_is_divisible.obj \ -           src/libtommath/bn_mp_prime_is_prime.obj \ -           src/libtommath/bn_mp_prime_miller_rabin.obj \ -           src/libtommath/bn_mp_prime_next_prime.obj \ -           src/libtommath/bn_mp_prime_rabin_miller_trials.obj \ -           src/libtommath/bn_mp_prime_random_ex.obj \ -           src/libtommath/bn_mp_radix_size.obj \ -           src/libtommath/bn_mp_radix_smap.obj \ -           src/libtommath/bn_mp_rand.obj \ -           src/libtommath/bn_mp_read_radix.obj \ -           src/libtommath/bn_mp_read_signed_bin.obj \ -           src/libtommath/bn_mp_read_unsigned_bin.obj \ -           src/libtommath/bn_mp_reduce.obj \ -           src/libtommath/bn_mp_reduce_2k.obj \ -           src/libtommath/bn_mp_reduce_2k_l.obj \ -           src/libtommath/bn_mp_reduce_2k_setup.obj \ -           src/libtommath/bn_mp_reduce_2k_setup_l.obj \ -           src/libtommath/bn_mp_reduce_is_2k.obj \ -           src/libtommath/bn_mp_reduce_is_2k_l.obj \ -           src/libtommath/bn_mp_reduce_setup.obj \ -           src/libtommath/bn_mp_rshd.obj \ -           src/libtommath/bn_mp_set.obj \ -           src/libtommath/bn_mp_set_int.obj \ -           src/libtommath/bn_mp_shrink.obj \ -           src/libtommath/bn_mp_signed_bin_size.obj \ -           src/libtommath/bn_mp_sqr.obj \ -           src/libtommath/bn_mp_sqrmod.obj \ -           src/libtommath/bn_mp_sqrt.obj \ -           src/libtommath/bn_mp_sub.obj \ -           src/libtommath/bn_mp_submod.obj \ -           src/libtommath/bn_mp_sub_d.obj \ -           src/libtommath/bn_mp_toom_mul.obj \ -           src/libtommath/bn_mp_toom_sqr.obj \ -           src/libtommath/bn_mp_toradix.obj \ -           src/libtommath/bn_mp_toradix_n.obj \ -           src/libtommath/bn_mp_to_signed_bin.obj \ -           src/libtommath/bn_mp_to_signed_bin_n.obj \ -           src/libtommath/bn_mp_to_unsigned_bin.obj \ -           src/libtommath/bn_mp_to_unsigned_bin_n.obj \ -           src/libtommath/bn_mp_unsigned_bin_size.obj \ -           src/libtommath/bn_mp_xor.obj \ -           src/libtommath/bn_mp_zero.obj \ -           src/libtommath/bn_prime_tab.obj \ -           src/libtommath/bn_reverse.obj \ -           src/libtommath/bn_s_mp_add.obj \ -           src/libtommath/bn_s_mp_exptmod.obj \ -           src/libtommath/bn_s_mp_mul_digs.obj \ -           src/libtommath/bn_s_mp_mul_high_digs.obj \ -           src/libtommath/bn_s_mp_sqr.obj \ -           src/libtommath/bn_s_mp_sub.obj \ -           src/lzma/C/LzFind.obj \ -           src/lzma/C/LzmaDec.obj \ -           src/lzma/C/LzmaEnc.obj \ -           src/pklib/explode.obj \ -           src/pklib/implode.obj +COBJS = src/libtomcrypt/src/hashes/sha1.o \ +	src/libtomcrypt/src/hashes/hash_memory.o \ +	src/libtomcrypt/src/hashes/md5.o \ +	src/libtomcrypt/src/misc/crypt_hash_is_valid.o \ +	src/libtomcrypt/src/misc/crypt_prng_descriptor.o \ +	src/libtomcrypt/src/misc/crypt_register_prng.o \ +	src/libtomcrypt/src/misc/crypt_ltc_mp_descriptor.o \ +	src/libtomcrypt/src/misc/crypt_find_hash.o \ +	src/libtomcrypt/src/misc/zeromem.o \ +	src/libtomcrypt/src/misc/base64_decode.o \ +	src/libtomcrypt/src/misc/crypt_register_hash.o \ +	src/libtomcrypt/src/misc/crypt_find_prng.o \ +	src/libtomcrypt/src/misc/crypt_prng_is_valid.o \ +	src/libtomcrypt/src/misc/crypt_hash_descriptor.o \ +	src/libtomcrypt/src/misc/crypt_libc.o \ +	src/libtomcrypt/src/misc/crypt_argchk.o \ +	src/libtomcrypt/src/math/multi.o \ +	src/libtomcrypt/src/math/ltm_desc.o \ +	src/libtomcrypt/src/math/rand_prime.o \ +	src/libtomcrypt/src/pk/asn1/der_decode_bit_string.o \ +	src/libtomcrypt/src/pk/asn1/der_decode_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_choice.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_ex.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_flexi.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_multi.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_short_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_bit_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_set.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_setof.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_short_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_bit_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_length_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_length_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_length_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_sequence.o \ +        src/libtomcrypt/src/pk/asn1/der_length_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_sequence_free.o \ +        src/libtomcrypt/src/pk/asn1/der_length_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_short_integer.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_point.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_mulmod.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_map.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_points.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_mul2add.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.o \ +	src/libtomcrypt/src/pk/rsa/rsa_make_key.o \ +	src/libtomcrypt/src/pk/rsa/rsa_free.o \ +	src/libtomcrypt/src/pk/rsa/rsa_verify_simple.o \ +	src/libtomcrypt/src/pk/rsa/rsa_import.o \ +	src/libtomcrypt/src/pk/rsa/rsa_verify_hash.o \ +	src/libtomcrypt/src/pk/rsa/rsa_sign_hash.o \ +	src/libtomcrypt/src/pk/rsa/rsa_exptmod.o \ +	src/libtommath/bn_mp_exptmod_fast.o \ +	src/libtommath/bn_mp_jacobi.o \ +	src/libtommath/bn_mp_mod.o \ +	src/libtommath/bn_mp_signed_bin_size.o \ +	src/libtommath/bn_mp_invmod.o \ +	src/libtommath/bn_mp_is_square.o \ +	src/libtommath/bn_mp_neg.o \ +	src/libtommath/bn_mp_reduce_2k.o \ +	src/libtommath/bn_mp_xor.o \ +	src/libtommath/bn_mp_karatsuba_mul.o \ +	src/libtommath/bn_mp_dr_setup.o \ +	src/libtommath/bn_mp_mul.o \ +	src/libtommath/bn_mp_init_multi.o \ +	src/libtommath/bn_mp_clear.o \ +	src/libtommath/bn_s_mp_sqr.o \ +	src/libtommath/bn_mp_rshd.o \ +	src/libtommath/bn_s_mp_sub.o \ +	src/libtommath/bn_mp_sub.o \ +	src/libtommath/bn_mp_toradix.o \ +	src/libtommath/bn_mp_reduce.o \ +	src/libtommath/bn_mp_prime_is_prime.o \ +	src/libtommath/bn_mp_prime_next_prime.o \ +	src/libtommath/bn_mp_exptmod.o \ +	src/libtommath/bn_mp_mod_2d.o \ +	src/libtommath/bn_reverse.o \ +	src/libtommath/bn_mp_init.o \ +	src/libtommath/bn_fast_s_mp_sqr.o \ +	src/libtommath/bn_mp_sqr.o \ +	src/libtommath/bn_mp_cnt_lsb.o \ +	src/libtommath/bn_mp_clear_multi.o \ +	src/libtommath/bn_mp_exch.o \ +	src/libtommath/bn_fast_s_mp_mul_digs.o \ +	src/libtommath/bn_mp_grow.o \ +	src/libtommath/bn_mp_read_radix.o \ +	src/libtommath/bn_mp_mul_2.o \ +	src/libtommath/bn_mp_shrink.o \ +	src/libtommath/bn_mp_div_2.o \ +	src/libtommath/bn_fast_mp_invmod.o \ +	src/libtommath/bn_mp_prime_miller_rabin.o \ +	src/libtommath/bn_mp_to_unsigned_bin.o \ +	src/libtommath/bn_mp_prime_rabin_miller_trials.o \ +	src/libtommath/bn_mp_2expt.o \ +	src/libtommath/bn_mp_cmp_mag.o \ +	src/libtommath/bn_mp_to_signed_bin.o \ +	src/libtommath/bn_mp_get_int.o \ +	src/libtommath/bn_mp_montgomery_reduce.o \ +	src/libtommath/bn_mp_dr_reduce.o \ +	src/libtommath/bn_mp_fwrite.o \ +	src/libtommath/bn_mp_and.o \ +	src/libtommath/bn_mp_exteuclid.o \ +	src/libtommath/bn_fast_mp_montgomery_reduce.o \ +	src/libtommath/bn_s_mp_mul_high_digs.o \ +	src/libtommath/bn_mp_reduce_setup.o \ +	src/libtommath/bn_mp_lcm.o \ +	src/libtommath/bn_mp_abs.o \ +	src/libtommath/bn_mp_cmp.o \ +	src/libtommath/bn_mp_submod.o \ +	src/libtommath/bn_mp_div_d.o \ +	src/libtommath/bn_s_mp_mul_digs.o \ +	src/libtommath/bn_mp_mul_d.o \ +	src/libtommath/bn_mp_to_unsigned_bin_n.o \ +	src/libtommath/bn_mp_prime_random_ex.o \ +	src/libtommath/bn_mp_rand.o \ +	src/libtommath/bn_mp_div_2d.o \ +	src/libtommath/bn_mp_addmod.o \ +	src/libtommath/bn_mp_init_copy.o \ +	src/libtommath/bn_mp_read_unsigned_bin.o \ +	src/libtommath/bn_mp_toradix_n.o \ +	src/libtommath/bn_fast_s_mp_mul_high_digs.o \ +	src/libtommath/bn_mp_toom_sqr.o \ +	src/libtommath/bn_mp_to_signed_bin_n.o \ +	src/libtommath/bn_mp_reduce_2k_setup_l.o \ +	src/libtommath/bn_mp_div.o \ +	src/libtommath/bn_prime_tab.o \ +	src/libtommath/bn_mp_karatsuba_sqr.o \ +	src/libtommath/bn_mp_gcd.o \ +	src/libtommath/bn_mp_prime_is_divisible.o \ +	src/libtommath/bn_mp_set_int.o \ +	src/libtommath/bn_mp_prime_fermat.o \ +	src/libtommath/bn_mp_cmp_d.o \ +	src/libtommath/bn_mp_add.o \ +	src/libtommath/bn_mp_sub_d.o \ +	src/libtommath/bn_s_mp_exptmod.o \ +	src/libtommath/bn_mp_init_size.o \ +	src/libtommath/bncore.o \ +	src/libtommath/bn_mp_radix_smap.o \ +	src/libtommath/bn_mp_reduce_2k_l.o \ +	src/libtommath/bn_mp_montgomery_calc_normalization.o \ +	src/libtommath/bn_mp_mod_d.o \ +	src/libtommath/bn_mp_set.o \ +	src/libtommath/bn_mp_or.o \ +	src/libtommath/bn_mp_sqrt.o \ +	src/libtommath/bn_mp_invmod_slow.o \ +	src/libtommath/bn_mp_count_bits.o \ +	src/libtommath/bn_mp_read_signed_bin.o \ +	src/libtommath/bn_mp_div_3.o \ +	src/libtommath/bn_mp_unsigned_bin_size.o \ +	src/libtommath/bn_mp_mulmod.o \ +	src/libtommath/bn_mp_clamp.o \ +	src/libtommath/bn_mp_reduce_2k_setup.o \ +	src/libtommath/bn_mp_toom_mul.o \ +	src/libtommath/bn_mp_montgomery_setup.o \ +	src/libtommath/bn_mp_expt_d.o \ +	src/libtommath/bn_mp_copy.o \ +	src/libtommath/bn_mp_dr_is_modulus.o \ +	src/libtommath/bn_mp_sqrmod.o \ +	src/libtommath/bn_mp_reduce_is_2k_l.o \ +	src/libtommath/bn_mp_mul_2d.o \ +	src/libtommath/bn_mp_fread.o \ +	src/libtommath/bn_mp_init_set.o \ +	src/libtommath/bn_mp_add_d.o \ +	src/libtommath/bn_mp_zero.o \ +	src/libtommath/bn_s_mp_add.o \ +	src/libtommath/bn_mp_radix_size.o \ +	src/libtommath/bn_mp_init_set_int.o \ +	src/libtommath/bn_mp_n_root.o \ +	src/libtommath/bn_mp_lshd.o \ +	src/libtommath/bn_mp_reduce_is_2k.o \ +	src/pklib/implode.o \ +	src/pklib/crc32.o \ +	src/pklib/explode.o \ +	src/zlib/crc32.o \ +	src/zlib/trees.o \ +	src/zlib/compress.o \ +	src/zlib/adler32.o \ +	src/zlib/inftrees.o \ +	src/zlib/inffast.o \ +	src/zlib/deflate.o \ +	src/zlib/inflate.o \ +	src/zlib/zutil.o \ +	src/lzma/C/LzFind.o \ +	src/lzma/C/LzmaEnc.o \ +	src/lzma/C/LzmaDec.o \ +	src/jenkins/lookup3.o  all: $(LIBRARY) @@ -240,13 +266,13 @@ all: $(LIBRARY)  #   cp StormLib.h /usr/local/include/StormLib  #   cp StormPort.h /usr/local/include/StormLib -$(LIBRARY): $(OBJS_C) $(OBJS_CPP) -	$(CPP) $(CFLAGS) $(DFLAGS) $(ARCH) $(LFLAGS) -shared -o $(LIBRARY) $(OBJS_C) $(OBJS_CPP) -#	$(AR) $(ARFLAGS) $(LIBRARY) $(OBJS_C) $(OBJS_CPP) +$(LIBRARY): $(COBJS) $(OBJS) +	$(CPP) $(CFLAGS) $(DFLAGS) $(ARCH) $(LFLAGS) -shared -o $(LIBRARY) $(COBJS) $(OBJS) +#	$(AR) $(ARFLAGS) $(LIBRARY) $(COBJS) $(OBJS) -$(OBJS_C): %.obj: %.c +$(COBJS): %.o: %.c  	$(CC) -o $@ $(CFLAGS) $(DFLAGS) -c $< -$(OBJS_CPP): %.obj: %.cpp +$(OBJS): %.o: %.cpp  	$(CC) -o $@ $(CFLAGS) $(DFLAGS) -c $< diff --git a/StormLib.vcproj b/StormLib.vcproj index be45757..db947a7 100644 --- a/StormLib.vcproj +++ b/StormLib.vcproj @@ -4228,6 +4228,62 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_bit_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_boolean.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_ia5_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_integer.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_object_identifier.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_octet_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_printable_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_sequence_ex.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_sequence_multi.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_set.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_setof.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_short_integer.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_utctime.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_utf8_string.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_length_bit_string.c"  							>  						</File> @@ -4320,9 +4376,17 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_pss_encode.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_v1_5_decode.c"  							>  						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_v1_5_encode.c" +							> +						</File>  					</Filter>  					<Filter  						Name="rsa" @@ -4344,6 +4408,10 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\rsa\rsa_sign_hash.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\rsa\rsa_verify_hash.c"  							>  						</File> diff --git a/StormLib_dll.vcproj b/StormLib_dll.vcproj index 1850ed4..0b8d247 100644 --- a/StormLib_dll.vcproj +++ b/StormLib_dll.vcproj @@ -1874,6 +1874,62 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_bit_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_boolean.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_ia5_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_integer.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_object_identifier.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_octet_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_printable_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_sequence_ex.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_sequence_multi.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_set.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_setof.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_short_integer.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_utctime.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_utf8_string.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_length_bit_string.c"  							>  						</File> @@ -1966,9 +2022,17 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_pss_encode.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_v1_5_decode.c"  							>  						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_v1_5_encode.c" +							> +						</File>  					</Filter>  					<Filter  						Name="rsa" @@ -1990,6 +2054,10 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\rsa\rsa_sign_hash.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\rsa\rsa_verify_hash.c"  							>  						</File> diff --git a/StormLib_test.vcproj b/StormLib_test.vcproj index 337ac78..09cef44 100644 --- a/StormLib_test.vcproj +++ b/StormLib_test.vcproj @@ -1308,6 +1308,62 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_bit_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_boolean.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_ia5_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_integer.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_object_identifier.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_octet_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_printable_string.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_sequence_ex.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_sequence_multi.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_set.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_setof.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_short_integer.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_utctime.c" +							> +						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_encode_utf8_string.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\asn1\der_length_bit_string.c"  							>  						</File> @@ -1400,9 +1456,17 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_pss_encode.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_v1_5_decode.c"  							>  						</File> +						<File +							RelativePath=".\src\libtomcrypt\src\pk\pkcs1\pkcs_1_v1_5_encode.c" +							> +						</File>  					</Filter>  					<Filter  						Name="rsa" @@ -1424,6 +1488,10 @@  							>  						</File>  						<File +							RelativePath=".\src\libtomcrypt\src\pk\rsa\rsa_sign_hash.c" +							> +						</File> +						<File  							RelativePath=".\src\libtomcrypt\src\pk\rsa\rsa_verify_hash.c"  							>  						</File> diff --git a/makefile.w32 b/makefile.w32 index 9c88fae..88662ba 100644 --- a/makefile.w32 +++ b/makefile.w32 @@ -20,231 +20,241 @@ ARFLAGS   = rcs  LIBRARY   = StormLib.dll  TESTEXE   = StormLib_test.exe -OBJS_CPP  = src/adpcm/adpcm.o \ -            src/huffman/huff.o \ -            src/sparse/sparse.o \ -            src/FileStream.o \ -            src/SBaseCommon.o \ -            src/SBaseDumpData.o \ -            src/SBaseFileTable.o \ -            src/SBaseSubTypes.o \ -            src/SCompression.o \ -            src/SFileAddFile.o \ -            src/SFileAttributes.o \ -            src/SFileCompactArchive.o \ -            src/SFileCreateArchive.o \ -            src/SFileExtractFile.o \ -            src/SFileFindFile.o \ -            src/SFileGetFileInfo.o \ -            src/SFileListFile.o \ -            src/SFileOpenArchive.o \ -            src/SFileOpenFileEx.o \ -            src/SFilePatchArchives.o \ -            src/SFileReadFile.o \ -            src/SFileVerify.o -               +OBJS =  src/adpcm/adpcm.o \ +	src/huffman/huff.o \ +	src/sparse/sparse.o \ +	src/FileStream.o \ +	src/SBaseCommon.o \ +        src/SBaseDumpData.o \ +	src/SBaseFileTable.o \ +	src/SBaseSubTypes.o \ +	src/SCompression.o \ +	src/SFileAddFile.o \ +	src/SFileAttributes.o \ +	src/SFileCompactArchive.o \ +	src/SFileCreateArchive.o \ +	src/SFileExtractFile.o \ +	src/SFileFindFile.o \ +	src/SFileGetFileInfo.o \ +	src/SFileListFile.o \ +	src/SFileOpenArchive.o \ +	src/SFileOpenFileEx.o \ +	src/SFilePatchArchives.o \ +	src/SFileReadFile.o \ +	src/SFileVerify.o -OBJS_C    = src/bzip2/blocksort.o \ -            src/bzip2/bzlib.o \ -            src/bzip2/compress.o \ -            src/bzip2/crctable.o \ -            src/bzip2/decompress.o \ -            src/bzip2/huffman.o \ -            src/bzip2/randtable.o \ -            src/jenkins/lookup3.o \ -            src/libtomcrypt/src/hashes/hash_memory.o \ -            src/libtomcrypt/src/hashes/md5.o \ -            src/libtomcrypt/src/hashes/sha1.o\ -            src/libtomcrypt/src/math/ltm_desc.o \ -            src/libtomcrypt/src/math/multi.o \ -            src/libtomcrypt/src/math/rand_prime.o \ -            src/libtomcrypt/src/misc/base64_decode.o \ -            src/libtomcrypt/src/misc/crypt_argchk.o \ -            src/libtomcrypt/src/misc/crypt_find_hash.o \ -            src/libtomcrypt/src/misc/crypt_find_prng.o \ -            src/libtomcrypt/src/misc/crypt_hash_descriptor.o \ -            src/libtomcrypt/src/misc/crypt_hash_is_valid.o \ -            src/libtomcrypt/src/misc/crypt_libc.o \ -            src/libtomcrypt/src/misc/crypt_ltc_mp_descriptor.o \ -            src/libtomcrypt/src/misc/crypt_prng_descriptor.o \ -            src/libtomcrypt/src/misc/crypt_prng_is_valid.o \ -            src/libtomcrypt/src/misc/crypt_register_hash.o \ -            src/libtomcrypt/src/misc/crypt_register_prng.o \ -            src/libtomcrypt/src/misc/zeromem.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_bit_string.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_boolean.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_choice.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_ia5_string.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_integer.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_object_identifier.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_octet_string.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_printable_string.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_sequence_ex.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_sequence_flexi.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_sequence_multi.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_short_integer.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_utctime.o \ -            src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.o \ -            src/libtomcrypt/src/pk/asn1/der_length_bit_string.o \ -            src/libtomcrypt/src/pk/asn1/der_length_boolean.o \ -            src/libtomcrypt/src/pk/asn1/der_length_ia5_string.o \ -            src/libtomcrypt/src/pk/asn1/der_length_integer.o \ -            src/libtomcrypt/src/pk/asn1/der_length_object_identifier.o \ -            src/libtomcrypt/src/pk/asn1/der_length_octet_string.o \ -            src/libtomcrypt/src/pk/asn1/der_length_printable_string.o \ -            src/libtomcrypt/src/pk/asn1/der_length_sequence.o \ -            src/libtomcrypt/src/pk/asn1/der_length_short_integer.o \ -            src/libtomcrypt/src/pk/asn1/der_length_utctime.o \ -            src/libtomcrypt/src/pk/asn1/der_length_utf8_string.o \ -            src/libtomcrypt/src/pk/asn1/der_sequence_free.o \ -            src/libtomcrypt/src/pk/ecc/ltc_ecc_map.o \ -            src/libtomcrypt/src/pk/ecc/ltc_ecc_mul2add.o \ -            src/libtomcrypt/src/pk/ecc/ltc_ecc_mulmod.o \ -            src/libtomcrypt/src/pk/ecc/ltc_ecc_points.o \ -            src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.o \ -            src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_point.o \ -            src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.o \ -            src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.o \ -            src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.o \ -            src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.o \ -            src/libtomcrypt/src/pk/rsa/rsa_exptmod.o \ -            src/libtomcrypt/src/pk/rsa/rsa_free.o \ -            src/libtomcrypt/src/pk/rsa/rsa_import.o \ -            src/libtomcrypt/src/pk/rsa/rsa_make_key.o \ -            src/libtomcrypt/src/pk/rsa/rsa_verify_hash.o \ -            src/libtomcrypt/src/pk/rsa/rsa_verify_simple.o \ -            src/libtommath/bncore.o \ -            src/libtommath/bn_fast_mp_invmod.o \ -            src/libtommath/bn_fast_mp_montgomery_reduce.o \ -            src/libtommath/bn_fast_s_mp_mul_digs.o \ -            src/libtommath/bn_fast_s_mp_mul_high_digs.o \ -            src/libtommath/bn_fast_s_mp_sqr.o \ -            src/libtommath/bn_mp_2expt.o \ -            src/libtommath/bn_mp_abs.o \ -            src/libtommath/bn_mp_add.o \ -            src/libtommath/bn_mp_addmod.o \ -            src/libtommath/bn_mp_add_d.o \ -            src/libtommath/bn_mp_and.o \ -            src/libtommath/bn_mp_clamp.o \ -            src/libtommath/bn_mp_clear.o \ -            src/libtommath/bn_mp_clear_multi.o \ -            src/libtommath/bn_mp_cmp.o \ -            src/libtommath/bn_mp_cmp_d.o \ -            src/libtommath/bn_mp_cmp_mag.o \ -            src/libtommath/bn_mp_cnt_lsb.o \ -            src/libtommath/bn_mp_copy.o \ -            src/libtommath/bn_mp_count_bits.o \ -            src/libtommath/bn_mp_div.o \ -            src/libtommath/bn_mp_div_2.o \ -            src/libtommath/bn_mp_div_2d.o \ -            src/libtommath/bn_mp_div_3.o \ -            src/libtommath/bn_mp_div_d.o \ -            src/libtommath/bn_mp_dr_is_modulus.o \ -            src/libtommath/bn_mp_dr_reduce.o \ -            src/libtommath/bn_mp_dr_setup.o \ -            src/libtommath/bn_mp_exch.o \ -            src/libtommath/bn_mp_exptmod.o \ -            src/libtommath/bn_mp_exptmod_fast.o \ -            src/libtommath/bn_mp_expt_d.o \ -            src/libtommath/bn_mp_exteuclid.o \ -            src/libtommath/bn_mp_fread.o \ -            src/libtommath/bn_mp_fwrite.o \ -            src/libtommath/bn_mp_gcd.o \ -            src/libtommath/bn_mp_get_int.o \ -            src/libtommath/bn_mp_grow.o \ -            src/libtommath/bn_mp_init.o \ -            src/libtommath/bn_mp_init_copy.o \ -            src/libtommath/bn_mp_init_multi.o \ -            src/libtommath/bn_mp_init_set.o \ -            src/libtommath/bn_mp_init_set_int.o \ -            src/libtommath/bn_mp_init_size.o \ -            src/libtommath/bn_mp_invmod.o \ -            src/libtommath/bn_mp_invmod_slow.o \ -            src/libtommath/bn_mp_is_square.o \ -            src/libtommath/bn_mp_jacobi.o \ -            src/libtommath/bn_mp_karatsuba_mul.o \ -            src/libtommath/bn_mp_karatsuba_sqr.o \ -            src/libtommath/bn_mp_lcm.o \ -            src/libtommath/bn_mp_lshd.o \ -            src/libtommath/bn_mp_mod.o \ -            src/libtommath/bn_mp_mod_2d.o \ -            src/libtommath/bn_mp_mod_d.o \ -            src/libtommath/bn_mp_montgomery_calc_normalization.o \ -            src/libtommath/bn_mp_montgomery_reduce.o \ -            src/libtommath/bn_mp_montgomery_setup.o \ -            src/libtommath/bn_mp_mul.o \ -            src/libtommath/bn_mp_mulmod.o \ -            src/libtommath/bn_mp_mul_2.o \ -            src/libtommath/bn_mp_mul_2d.o \ -            src/libtommath/bn_mp_mul_d.o \ -            src/libtommath/bn_mp_neg.o \ -            src/libtommath/bn_mp_n_root.o \ -            src/libtommath/bn_mp_or.o \ -            src/libtommath/bn_mp_prime_fermat.o \ -            src/libtommath/bn_mp_prime_is_divisible.o \ -            src/libtommath/bn_mp_prime_is_prime.o \ -            src/libtommath/bn_mp_prime_miller_rabin.o \ -            src/libtommath/bn_mp_prime_next_prime.o \ -            src/libtommath/bn_mp_prime_rabin_miller_trials.o \ -            src/libtommath/bn_mp_prime_random_ex.o \ -            src/libtommath/bn_mp_radix_size.o \ -            src/libtommath/bn_mp_radix_smap.o \ -            src/libtommath/bn_mp_rand.o \ -            src/libtommath/bn_mp_read_radix.o \ -            src/libtommath/bn_mp_read_signed_bin.o \ -            src/libtommath/bn_mp_read_unsigned_bin.o \ -            src/libtommath/bn_mp_reduce.o \ -            src/libtommath/bn_mp_reduce_2k.o \ -            src/libtommath/bn_mp_reduce_2k_l.o \ -            src/libtommath/bn_mp_reduce_2k_setup.o \ -            src/libtommath/bn_mp_reduce_2k_setup_l.o \ -            src/libtommath/bn_mp_reduce_is_2k.o \ -            src/libtommath/bn_mp_reduce_is_2k_l.o \ -            src/libtommath/bn_mp_reduce_setup.o \ -            src/libtommath/bn_mp_rshd.o \ -            src/libtommath/bn_mp_set.o \ -            src/libtommath/bn_mp_set_int.o \ -            src/libtommath/bn_mp_shrink.o \ -            src/libtommath/bn_mp_signed_bin_size.o \ -            src/libtommath/bn_mp_sqr.o \ -            src/libtommath/bn_mp_sqrmod.o \ -            src/libtommath/bn_mp_sqrt.o \ -            src/libtommath/bn_mp_sub.o \ -            src/libtommath/bn_mp_submod.o \ -            src/libtommath/bn_mp_sub_d.o \ -            src/libtommath/bn_mp_toom_mul.o \ -            src/libtommath/bn_mp_toom_sqr.o \ -            src/libtommath/bn_mp_toradix.o \ -            src/libtommath/bn_mp_toradix_n.o \ -            src/libtommath/bn_mp_to_signed_bin.o \ -            src/libtommath/bn_mp_to_signed_bin_n.o \ -            src/libtommath/bn_mp_to_unsigned_bin.o \ -            src/libtommath/bn_mp_to_unsigned_bin_n.o \ -            src/libtommath/bn_mp_unsigned_bin_size.o \ -            src/libtommath/bn_mp_xor.o \ -            src/libtommath/bn_mp_zero.o \ -            src/libtommath/bn_prime_tab.o \ -            src/libtommath/bn_reverse.o \ -            src/libtommath/bn_s_mp_add.o \ -            src/libtommath/bn_s_mp_exptmod.o \ -            src/libtommath/bn_s_mp_mul_digs.o \ -            src/libtommath/bn_s_mp_mul_high_digs.o \ -            src/libtommath/bn_s_mp_sqr.o \ -            src/libtommath/bn_s_mp_sub.o \ -            src/lzma/C/LzFind.o \ -            src/lzma/C/LzmaDec.o \ -            src/lzma/C/LzmaEnc.o \ -            src/pklib/explode.o \ -            src/pklib/implode.o \ -            src/zlib/adler32.o \ -            src/zlib/compress.o \ -            src/zlib/crc32.o \ -            src/zlib/deflate.o \ -            src/zlib/inffast.o \ -            src/zlib/inflate.o \ -            src/zlib/inftrees.o \ -            src/zlib/trees.o \ -            src/zlib/zutil.o +COBJS = src/libtomcrypt/src/hashes/sha1.o \ +	src/libtomcrypt/src/hashes/hash_memory.o \ +	src/libtomcrypt/src/hashes/md5.o \ +	src/libtomcrypt/src/misc/crypt_hash_is_valid.o \ +	src/libtomcrypt/src/misc/crypt_prng_descriptor.o \ +	src/libtomcrypt/src/misc/crypt_register_prng.o \ +	src/libtomcrypt/src/misc/crypt_ltc_mp_descriptor.o \ +	src/libtomcrypt/src/misc/crypt_find_hash.o \ +	src/libtomcrypt/src/misc/zeromem.o \ +	src/libtomcrypt/src/misc/base64_decode.o \ +	src/libtomcrypt/src/misc/crypt_register_hash.o \ +	src/libtomcrypt/src/misc/crypt_find_prng.o \ +	src/libtomcrypt/src/misc/crypt_prng_is_valid.o \ +	src/libtomcrypt/src/misc/crypt_hash_descriptor.o \ +	src/libtomcrypt/src/misc/crypt_libc.o \ +	src/libtomcrypt/src/misc/crypt_argchk.o \ +	src/libtomcrypt/src/math/multi.o \ +	src/libtomcrypt/src/math/ltm_desc.o \ +	src/libtomcrypt/src/math/rand_prime.o \ +	src/libtomcrypt/src/pk/asn1/der_decode_bit_string.o \ +	src/libtomcrypt/src/pk/asn1/der_decode_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_choice.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_ex.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_flexi.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_sequence_multi.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_short_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_decode_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_bit_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_set.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_setof.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_short_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_bit_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_boolean.o \ +        src/libtomcrypt/src/pk/asn1/der_length_ia5_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_integer.o \ +        src/libtomcrypt/src/pk/asn1/der_length_object_identifier.o \ +        src/libtomcrypt/src/pk/asn1/der_length_octet_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_printable_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_sequence.o \ +        src/libtomcrypt/src/pk/asn1/der_length_utctime.o \ +        src/libtomcrypt/src/pk/asn1/der_sequence_free.o \ +        src/libtomcrypt/src/pk/asn1/der_length_utf8_string.o \ +        src/libtomcrypt/src/pk/asn1/der_length_short_integer.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_dbl_point.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_mulmod.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_projective_add_point.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_map.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_points.o \ +	src/libtomcrypt/src/pk/ecc/ltc_ecc_mul2add.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_decode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.o \ +	src/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.o \ +	src/libtomcrypt/src/pk/rsa/rsa_make_key.o \ +	src/libtomcrypt/src/pk/rsa/rsa_free.o \ +	src/libtomcrypt/src/pk/rsa/rsa_verify_simple.o \ +	src/libtomcrypt/src/pk/rsa/rsa_import.o \ +	src/libtomcrypt/src/pk/rsa/rsa_verify_hash.o \ +	src/libtomcrypt/src/pk/rsa/rsa_sign_hash.o \ +	src/libtomcrypt/src/pk/rsa/rsa_exptmod.o \ +	src/libtommath/bn_mp_exptmod_fast.o \ +	src/libtommath/bn_mp_jacobi.o \ +	src/libtommath/bn_mp_mod.o \ +	src/libtommath/bn_mp_signed_bin_size.o \ +	src/libtommath/bn_mp_invmod.o \ +	src/libtommath/bn_mp_is_square.o \ +	src/libtommath/bn_mp_neg.o \ +	src/libtommath/bn_mp_reduce_2k.o \ +	src/libtommath/bn_mp_xor.o \ +	src/libtommath/bn_mp_karatsuba_mul.o \ +	src/libtommath/bn_mp_dr_setup.o \ +	src/libtommath/bn_mp_mul.o \ +	src/libtommath/bn_mp_init_multi.o \ +	src/libtommath/bn_mp_clear.o \ +	src/libtommath/bn_s_mp_sqr.o \ +	src/libtommath/bn_mp_rshd.o \ +	src/libtommath/bn_s_mp_sub.o \ +	src/libtommath/bn_mp_sub.o \ +	src/libtommath/bn_mp_toradix.o \ +	src/libtommath/bn_mp_reduce.o \ +	src/libtommath/bn_mp_prime_is_prime.o \ +	src/libtommath/bn_mp_prime_next_prime.o \ +	src/libtommath/bn_mp_exptmod.o \ +	src/libtommath/bn_mp_mod_2d.o \ +	src/libtommath/bn_reverse.o \ +	src/libtommath/bn_mp_init.o \ +	src/libtommath/bn_fast_s_mp_sqr.o \ +	src/libtommath/bn_mp_sqr.o \ +	src/libtommath/bn_mp_cnt_lsb.o \ +	src/libtommath/bn_mp_clear_multi.o \ +	src/libtommath/bn_mp_exch.o \ +	src/libtommath/bn_fast_s_mp_mul_digs.o \ +	src/libtommath/bn_mp_grow.o \ +	src/libtommath/bn_mp_read_radix.o \ +	src/libtommath/bn_mp_mul_2.o \ +	src/libtommath/bn_mp_shrink.o \ +	src/libtommath/bn_mp_div_2.o \ +	src/libtommath/bn_fast_mp_invmod.o \ +	src/libtommath/bn_mp_prime_miller_rabin.o \ +	src/libtommath/bn_mp_to_unsigned_bin.o \ +	src/libtommath/bn_mp_prime_rabin_miller_trials.o \ +	src/libtommath/bn_mp_2expt.o \ +	src/libtommath/bn_mp_cmp_mag.o \ +	src/libtommath/bn_mp_to_signed_bin.o \ +	src/libtommath/bn_mp_get_int.o \ +	src/libtommath/bn_mp_montgomery_reduce.o \ +	src/libtommath/bn_mp_dr_reduce.o \ +	src/libtommath/bn_mp_fwrite.o \ +	src/libtommath/bn_mp_and.o \ +	src/libtommath/bn_mp_exteuclid.o \ +	src/libtommath/bn_fast_mp_montgomery_reduce.o \ +	src/libtommath/bn_s_mp_mul_high_digs.o \ +	src/libtommath/bn_mp_reduce_setup.o \ +	src/libtommath/bn_mp_lcm.o \ +	src/libtommath/bn_mp_abs.o \ +	src/libtommath/bn_mp_cmp.o \ +	src/libtommath/bn_mp_submod.o \ +	src/libtommath/bn_mp_div_d.o \ +	src/libtommath/bn_s_mp_mul_digs.o \ +	src/libtommath/bn_mp_mul_d.o \ +	src/libtommath/bn_mp_to_unsigned_bin_n.o \ +	src/libtommath/bn_mp_prime_random_ex.o \ +	src/libtommath/bn_mp_rand.o \ +	src/libtommath/bn_mp_div_2d.o \ +	src/libtommath/bn_mp_addmod.o \ +	src/libtommath/bn_mp_init_copy.o \ +	src/libtommath/bn_mp_read_unsigned_bin.o \ +	src/libtommath/bn_mp_toradix_n.o \ +	src/libtommath/bn_fast_s_mp_mul_high_digs.o \ +	src/libtommath/bn_mp_toom_sqr.o \ +	src/libtommath/bn_mp_to_signed_bin_n.o \ +	src/libtommath/bn_mp_reduce_2k_setup_l.o \ +	src/libtommath/bn_mp_div.o \ +	src/libtommath/bn_prime_tab.o \ +	src/libtommath/bn_mp_karatsuba_sqr.o \ +	src/libtommath/bn_mp_gcd.o \ +	src/libtommath/bn_mp_prime_is_divisible.o \ +	src/libtommath/bn_mp_set_int.o \ +	src/libtommath/bn_mp_prime_fermat.o \ +	src/libtommath/bn_mp_cmp_d.o \ +	src/libtommath/bn_mp_add.o \ +	src/libtommath/bn_mp_sub_d.o \ +	src/libtommath/bn_s_mp_exptmod.o \ +	src/libtommath/bn_mp_init_size.o \ +	src/libtommath/bncore.o \ +	src/libtommath/bn_mp_radix_smap.o \ +	src/libtommath/bn_mp_reduce_2k_l.o \ +	src/libtommath/bn_mp_montgomery_calc_normalization.o \ +	src/libtommath/bn_mp_mod_d.o \ +	src/libtommath/bn_mp_set.o \ +	src/libtommath/bn_mp_or.o \ +	src/libtommath/bn_mp_sqrt.o \ +	src/libtommath/bn_mp_invmod_slow.o \ +	src/libtommath/bn_mp_count_bits.o \ +	src/libtommath/bn_mp_read_signed_bin.o \ +	src/libtommath/bn_mp_div_3.o \ +	src/libtommath/bn_mp_unsigned_bin_size.o \ +	src/libtommath/bn_mp_mulmod.o \ +	src/libtommath/bn_mp_clamp.o \ +	src/libtommath/bn_mp_reduce_2k_setup.o \ +	src/libtommath/bn_mp_toom_mul.o \ +	src/libtommath/bn_mp_montgomery_setup.o \ +	src/libtommath/bn_mp_expt_d.o \ +	src/libtommath/bn_mp_copy.o \ +	src/libtommath/bn_mp_dr_is_modulus.o \ +	src/libtommath/bn_mp_sqrmod.o \ +	src/libtommath/bn_mp_reduce_is_2k_l.o \ +	src/libtommath/bn_mp_mul_2d.o \ +	src/libtommath/bn_mp_fread.o \ +	src/libtommath/bn_mp_init_set.o \ +	src/libtommath/bn_mp_add_d.o \ +	src/libtommath/bn_mp_zero.o \ +	src/libtommath/bn_s_mp_add.o \ +	src/libtommath/bn_mp_radix_size.o \ +	src/libtommath/bn_mp_init_set_int.o \ +	src/libtommath/bn_mp_n_root.o \ +	src/libtommath/bn_mp_lshd.o \ +	src/libtommath/bn_mp_reduce_is_2k.o \ +	src/pklib/implode.o \ +	src/pklib/crc32.o \ +	src/pklib/explode.o \ +	src/zlib/crc32.o \ +	src/zlib/trees.o \ +	src/zlib/compress.o \ +	src/zlib/adler32.o \ +	src/zlib/inftrees.o \ +	src/zlib/inffast.o \ +	src/zlib/deflate.o \ +	src/zlib/inflate.o \ +	src/zlib/zutil.o \ +	src/lzma/C/LzFind.o \ +	src/lzma/C/LzmaEnc.o \ +	src/lzma/C/LzmaDec.o \ +	src/jenkins/lookup3.o  OBJS_DLL  = stormlib_dll/DllMain.o @@ -253,7 +263,7 @@ OBJS_TEST = test/test.o  all: $(LIBRARY) $(TESTEXE)  #clean: -#   rm -f $(OBJS) $(LIBRARY) +#   rm -f $(COBJS) $(LIBRARY)  #install: $(LIBRARY)  #   install $(LIBRARY) /usr/local/lib @@ -261,16 +271,16 @@ all: $(LIBRARY) $(TESTEXE)  #   cp StormLib.h /usr/local/include/StormLib  #   cp StormPort.h /usr/local/include/StormLib -$(LIBRARY): $(OBJS_C) $(OBJS_CPP) $(OBJS_DLL) -	$(CPP) $(CFLAGS) $(DFLAGS) -o $(LIBRARY) $(OBJS_C) $(OBJS_CPP) $(OBJS_DLL) $(DLLLFLAGS) +$(LIBRARY): $(COBJS) $(OBJS) $(OBJS_DLL) +	$(CPP) $(CFLAGS) $(DFLAGS) -o $(LIBRARY) $(COBJS) $(OBJS) $(OBJS_DLL) $(DLLLFLAGS) -$(TESTEXE): $(OBJS_C) $(OBJS_CPP) $(OBJS_TEST) -	$(CPP) $(CFLAGS) $(DFLAGS) -o "$@" $(OBJS_C) $(OBJS_CPP) $(OBJS_TEST) $(EXELFLAGS) +$(TESTEXE): $(COBJS) $(OBJS) $(OBJS_TEST) +	$(CPP) $(CFLAGS) $(DFLAGS) -o "$@" $(COBJS) $(OBJS) $(OBJS_TEST) $(EXELFLAGS) -$(OBJS_C): %.o: %.c +$(COBJS): %.o: %.c  	$(CC) -o $@ $(CFLAGS) $(DFLAGS) -c $< -$(OBJS_CPP): %.o: %.cpp +$(OBJS): %.o: %.cpp  	$(CC) -o $@ $(CFLAGS) $(DFLAGS) -c $<  $(OBJS_DLL): %.o: %.c diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index 33e1472..906edce 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -1943,6 +1943,7 @@ void InvalidateInternalFiles(TMPQArchive * ha)      TFileEntry * pFileTableEnd;      TFileEntry * pFileEntry1 = NULL;      TFileEntry * pFileEntry2 = NULL; +    TFileEntry * pFileEntry3 = NULL;      // Do nothing if we are in the middle of saving internal files      if(!(ha->dwFlags & MPQ_FLAG_SAVING_TABLES)) @@ -1979,17 +1980,33 @@ void InvalidateInternalFiles(TMPQArchive * ha)              ha->dwReservedFiles++;          } +        // Invalidate the (signature), if not done yet +        if(ha->dwFileFlags3 != 0 && (ha->dwFlags & MPQ_FLAG_SIGNATURE_INVALID) == 0) +        { +            // Delete the existing entry for (attributes) +            pFileEntry3 = GetFileEntryExact(ha, SIGNATURE_NAME, LANG_NEUTRAL); +            if(pFileEntry3 != NULL) +                DeleteFileEntry(ha, pFileEntry3); + +            // Reserve one entry for (attributes) +            ha->dwFlags |= MPQ_FLAG_SIGNATURE_INVALID; +            ha->dwReservedFiles++; +        } + +          // If the internal files are at the end of the file table (they usually are), -        // we want to free these 2 entries, so when new files are added, they get +        // we want to free these 3 entries, so when new files are added, they get          // added to the freed entries and the internal files get added after that          if(ha->dwFileTableSize > 0)          {              pFileTableEnd = ha->pFileTable + ha->dwFileTableSize;              // Is one of the entries the last one? -            if(pFileEntry1 == pFileTableEnd - 1 || pFileEntry2 == pFileTableEnd - 1) +            if(pFileEntry1 == pFileTableEnd - 1 || pFileEntry2 == pFileTableEnd - 1 || pFileEntry3 == pFileTableEnd - 1) +                pFileTableEnd--; +            if(pFileEntry1 == pFileTableEnd - 1 || pFileEntry2 == pFileTableEnd - 1 || pFileEntry3 == pFileTableEnd - 1)                  pFileTableEnd--; -            if(pFileEntry1 == pFileTableEnd - 1 || pFileEntry2 == pFileTableEnd - 1) +            if(pFileEntry1 == pFileTableEnd - 1 || pFileEntry2 == pFileTableEnd - 1 || pFileEntry3 == pFileTableEnd - 1)                  pFileTableEnd--;              // Calculate the new file table size diff --git a/src/SFileAttributes.cpp b/src/SFileAttributes.cpp index 479363d..0278426 100644 --- a/src/SFileAttributes.cpp +++ b/src/SFileAttributes.cpp @@ -368,7 +368,7 @@ int SAttrLoadAttributes(TMPQArchive * ha)      // File table must be initialized      assert(ha->pFileTable != NULL); -    // Don't load the attributes file from malformer Warcraft III maps +    // Don't load the attributes file from malformed Warcraft III maps      if(ha->dwFlags & MPQ_FLAG_MALFORMED)          return ERROR_FILE_CORRUPT; diff --git a/src/SFileCreateArchive.cpp b/src/SFileCreateArchive.cpp index 569b953..206baff 100644 --- a/src/SFileCreateArchive.cpp +++ b/src/SFileCreateArchive.cpp @@ -80,6 +80,7 @@ bool WINAPI SFileCreateArchive(const TCHAR * szMpqName, DWORD dwCreateFlags, DWO      CreateInfo.dwStreamFlags  = STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE;      CreateInfo.dwFileFlags1   = (dwCreateFlags & MPQ_CREATE_LISTFILE)   ? MPQ_FILE_EXISTS : 0;      CreateInfo.dwFileFlags2   = (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? MPQ_FILE_EXISTS : 0; +    CreateInfo.dwFileFlags3   = (dwCreateFlags & MPQ_CREATE_SIGNATURE)  ? MPQ_FILE_EXISTS : 0;      CreateInfo.dwAttrFlags    = (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? (MPQ_ATTRIBUTE_CRC32 | MPQ_ATTRIBUTE_FILETIME | MPQ_ATTRIBUTE_MD5) : 0;      CreateInfo.dwSectorSize   = (CreateInfo.dwMpqVersion >= MPQ_FORMAT_VERSION_3) ? 0x4000 : 0x1000;      CreateInfo.dwRawChunkSize = (CreateInfo.dwMpqVersion >= MPQ_FORMAT_VERSION_4) ? 0x4000 : 0; @@ -118,11 +119,11 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea      }      // Verify if all variables in SFILE_CREATE_MPQ are correct -    if((pCreateInfo->cbSize == 0 || pCreateInfo->cbSize > sizeof(SFILE_CREATE_MPQ)) || -       (pCreateInfo->dwMpqVersion > MPQ_FORMAT_VERSION_4)                        || -       (pCreateInfo->pvUserData != NULL || pCreateInfo->cbUserData != 0)            || -       (pCreateInfo->dwAttrFlags & ~MPQ_ATTRIBUTE_ALL)                              || -       (pCreateInfo->dwSectorSize & (pCreateInfo->dwSectorSize - 1))                || +    if((pCreateInfo->cbSize == 0 || pCreateInfo->cbSize > sizeof(SFILE_CREATE_MPQ))    || +       (pCreateInfo->dwMpqVersion > MPQ_FORMAT_VERSION_4)                              || +       (pCreateInfo->pvUserData != NULL || pCreateInfo->cbUserData != 0)               || +       (pCreateInfo->dwAttrFlags & ~MPQ_ATTRIBUTE_ALL)                                 || +       (pCreateInfo->dwSectorSize & (pCreateInfo->dwSectorSize - 1))                   ||         (pCreateInfo->dwRawChunkSize & (pCreateInfo->dwRawChunkSize - 1)))      {          SetLastError(ERROR_INVALID_PARAMETER); @@ -169,6 +170,13 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea          dwReservedFiles++;      } +    // Increment the maximum amount of files to have space for (signature) +    if(pCreateInfo->dwMaxFileCount && pCreateInfo->dwFileFlags3) +    { +        dwMpqFlags |= MPQ_FLAG_SIGNATURE_INVALID; +        dwReservedFiles++; +    } +      // If file count is not zero, initialize the hash table size      dwHashTableSize = GetHashTableSizeForFileCount(pCreateInfo->dwMaxFileCount + dwReservedFiles); @@ -205,6 +213,7 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea          ha->dwReservedFiles = dwReservedFiles;          ha->dwFileFlags1    = pCreateInfo->dwFileFlags1;          ha->dwFileFlags2    = pCreateInfo->dwFileFlags2; +        ha->dwFileFlags3    = pCreateInfo->dwFileFlags3 ? MPQ_FILE_EXISTS : 0;          ha->dwAttrFlags     = pCreateInfo->dwAttrFlags;          ha->dwFlags         = dwMpqFlags | MPQ_FLAG_CHANGED;          pStream = NULL; diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp index 98d8766..15c395c 100644 --- a/src/SFileOpenArchive.cpp +++ b/src/SFileOpenArchive.cpp @@ -388,7 +388,7 @@ bool WINAPI SFileOpenArchive(      // Load the internal listfile and include it to the file table      if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_LISTFILE) == 0)      { -        // Save the flags for (listfile) +        // Quick check for (listfile)          pFileEntry = GetFileEntryLocale(ha, LISTFILE_NAME, LANG_NEUTRAL);          if(pFileEntry != NULL)          { @@ -401,7 +401,7 @@ bool WINAPI SFileOpenArchive(      // Load the "(attributes)" file and merge it to the file table      if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_ATTRIBUTES) == 0)      { -        // Save the flags for (attributes) +        // Quick check for (attributes)          pFileEntry = GetFileEntryLocale(ha, ATTRIBUTES_NAME, LANG_NEUTRAL);          if(pFileEntry != NULL)          { @@ -411,6 +411,19 @@ bool WINAPI SFileOpenArchive(          }      } +    // Remember whether the archive has weak signature. Only for MPQs format 1.0. +    if(nError == ERROR_SUCCESS) +    { +        // Quick check for (signature) +        pFileEntry = GetFileEntryLocale(ha, SIGNATURE_NAME, LANG_NEUTRAL); +        if(pFileEntry != NULL) +        { +            // Just remember that the archive is weak-signed +            assert(pFileEntry->dwFlags == MPQ_FILE_EXISTS); +            ha->dwFileFlags3 = pFileEntry->dwFlags; +        } +    } +      // Cleanup and exit      if(nError != ERROR_SUCCESS)      { @@ -469,6 +482,14 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq)      // Indicate that we are saving MPQ internal structures      ha->dwFlags |= MPQ_FLAG_SAVING_TABLES; +    // If the (signature) has been invalidated, save it +    if(ha->dwFlags & MPQ_FLAG_SIGNATURE_INVALID) +    { +        nError = SSignFileCreate(ha); +        if(nError != ERROR_SUCCESS) +            nResultError = nError; +    } +      // If the (listfile) has been invalidated, save it      if(ha->dwFlags & MPQ_FLAG_LISTFILE_INVALID)      { @@ -488,9 +509,18 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq)      // Save HET table, BET table, hash table, block table, hi-block table      if(ha->dwFlags & MPQ_FLAG_CHANGED)      { +        // Save all MPQ tables first          nError = SaveMPQTables(ha);          if(nError != ERROR_SUCCESS)              nResultError = nError; + +        // If the archive has weak signature, we need to finish it +        if(ha->dwFileFlags3 != 0) +        { +            nError = SSignFileFinish(ha); +            if(nError != ERROR_SUCCESS) +                nResultError = nError; +        }      }      // We are no longer saving internal MPQ structures diff --git a/src/SFileVerify.cpp b/src/SFileVerify.cpp index 8d7e950..a506fc3 100644 --- a/src/SFileVerify.cpp +++ b/src/SFileVerify.cpp @@ -726,9 +726,8 @@ bool QueryMpqSignatureInfo(      TMPQArchive * ha,      PMPQ_SIGNATURE_INFO pSI)  { +    TFileEntry * pFileEntry;      ULONGLONG ExtraBytes; -    TMPQFile * hf; -    HANDLE hFile;      DWORD dwFileSize;      // Make sure it's all zeroed @@ -738,23 +737,25 @@ bool QueryMpqSignatureInfo(      CalculateArchiveRange(ha, pSI);      // If there is "(signature)" file in the MPQ, it has a weak signature -    if(SFileOpenFileEx((HANDLE)ha, SIGNATURE_NAME, SFILE_OPEN_BASE_FILE, &hFile)) +    pFileEntry = GetFileEntryLocale(ha, SIGNATURE_NAME, LANG_NEUTRAL); +    if(pFileEntry != NULL)      { -        // Get the content of the signature -        SFileReadFile(hFile, pSI->Signature, sizeof(pSI->Signature), &pSI->cbSignatureSize, NULL); +        // Calculate the begin and end of the signature file itself +        pSI->BeginExclude = ha->MpqPos + pFileEntry->ByteOffset; +        pSI->EndExclude = pSI->BeginExclude + pFileEntry->dwCmpSize; +        dwFileSize = (DWORD)(pSI->EndExclude - pSI->BeginExclude); -        // Verify the size of the signature -        hf = (TMPQFile *)hFile; - -        // We have to exclude the signature file from the digest -        pSI->BeginExclude = ha->MpqPos + hf->pFileEntry->ByteOffset; -        pSI->EndExclude = pSI->BeginExclude + hf->pFileEntry->dwCmpSize; -        dwFileSize = hf->dwDataSize; +        // Does the signature have proper size? +        if(dwFileSize == MPQ_SIGNATURE_FILE_SIZE) +        { +            // Read the weak signature +            if(!FileStream_Read(ha->pStream, &pSI->BeginExclude, pSI->Signature, dwFileSize)) +                return false; -        // Close the file -        SFileCloseFile(hFile); -        pSI->SignatureTypes |= SIGNATURE_TYPE_WEAK; -        return (dwFileSize == (MPQ_WEAK_SIGNATURE_SIZE + 8)) ? true : false; +            pSI->cbSignatureSize = dwFileSize; +            pSI->SignatureTypes |= SIGNATURE_TYPE_WEAK; +            return true; +        }      }      // If there is extra bytes beyond the end of the archive, @@ -779,6 +780,96 @@ bool QueryMpqSignatureInfo(  }  //----------------------------------------------------------------------------- +// Support for weak signature + +int SSignFileCreate(TMPQArchive * ha) +{ +    TMPQFile * hf = NULL; +    BYTE EmptySignature[MPQ_SIGNATURE_FILE_SIZE]; +    int nError = ERROR_SUCCESS; + +    // Only save the signature if we should do so +    if(ha->dwFileFlags3 != 0) +    { +        // The (signature) file must be non-encrypted and non-compressed +        assert(ha->dwFileFlags3 == MPQ_FILE_EXISTS); + +        // Create the (signature) file file in the MPQ +        // Note that the file must not be compressed or encrypted +        nError = SFileAddFile_Init(ha, SIGNATURE_NAME, +                                       0, +                                       sizeof(EmptySignature), +                                       LANG_NEUTRAL, +                                       ha->dwFileFlags3 | MPQ_FILE_REPLACEEXISTING, +                                      &hf); + +        // Write the empty signature file to the archive +        if(nError == ERROR_SUCCESS) +        { +            // Write the empty zeroed fiel to the MPQ +            memset(EmptySignature, 0, sizeof(EmptySignature)); +            nError = SFileAddFile_Write(hf, EmptySignature, (DWORD)sizeof(EmptySignature), 0); +        } + +        // If the save process succeeded, we clear the MPQ_FLAG_ATTRIBUTE_INVALID flag +        if(nError == ERROR_SUCCESS) +        { +            ha->dwFlags &= ~MPQ_FLAG_SIGNATURE_INVALID; +            ha->dwReservedFiles--; +        } + +        // Free the file +        if(hf != NULL) +            SFileAddFile_Finish(hf); +    } + +    return nError; +} + +int SSignFileFinish(TMPQArchive * ha) +{ +    MPQ_SIGNATURE_INFO si; +    unsigned long signature_len = MPQ_WEAK_SIGNATURE_SIZE; +    BYTE WeakSignature[MPQ_SIGNATURE_FILE_SIZE]; +    BYTE Md5Digest[MD5_DIGEST_SIZE]; +    rsa_key key; +    int hash_idx = find_hash("md5"); + +    // Sanity checks +    assert((ha->dwFlags & MPQ_FLAG_CHANGED) == 0); +    assert(ha->dwFileFlags3 == MPQ_FILE_EXISTS); + +    // Query the weak signature info +    memset(&si, 0, sizeof(MPQ_SIGNATURE_INFO)); +    if(!QueryMpqSignatureInfo(ha, &si)) +        return ERROR_FILE_CORRUPT; + +    // There must be exactly one signature +    if(si.SignatureTypes != SIGNATURE_TYPE_WEAK) +        return ERROR_FILE_CORRUPT; + +    // Calculate MD5 of the entire archive +    if(!CalculateMpqHashMd5(ha, &si, Md5Digest)) +        return ERROR_VERIFY_FAILED; + +    // Decode the private key +    if(!decode_base64_key(szBlizzardWeakPrivateKey, &key)) +        return ERROR_VERIFY_FAILED; + +    // Sign the hash +    memset(WeakSignature, 0, sizeof(WeakSignature)); +    rsa_sign_hash_ex(Md5Digest, sizeof(Md5Digest), WeakSignature + 8, &signature_len, LTC_LTC_PKCS_1_V1_5, 0, 0, hash_idx, 0, &key); +	memrev(WeakSignature + 8, MPQ_WEAK_SIGNATURE_SIZE);  +    rsa_free(&key); + +    // Write the signature to the MPQ. Don't use SFile* functions, but write the hash directly +    if(!FileStream_Write(ha->pStream, &si.BeginExclude, WeakSignature, MPQ_SIGNATURE_FILE_SIZE)) +        return GetLastError(); + +    return ERROR_SUCCESS; +} + +//-----------------------------------------------------------------------------  // Public (exported) functions  bool WINAPI SFileGetFileChecksums(HANDLE hMpq, const char * szFileName, LPDWORD pdwCrc32, char * pMD5) @@ -900,6 +991,10 @@ DWORD WINAPI SFileVerifyArchive(HANDLE hMpq)      if(!IsValidMpqHandle(hMpq))          return ERROR_VERIFY_FAILED; +    // If the archive was modified, we need to flush it +    if(ha->dwFlags & MPQ_FLAG_CHANGED) +        SFileFlushArchive(hMpq); +      // Get the MPQ signature and signature type      memset(&si, 0, sizeof(MPQ_SIGNATURE_INFO));      if(!QueryMpqSignatureInfo(ha, &si)) @@ -922,3 +1017,44 @@ DWORD WINAPI SFileVerifyArchive(HANDLE hMpq)      return ERROR_NO_SIGNATURE;  } + +// Verifies the archive against the signature +bool WINAPI SFileSignArchive(HANDLE hMpq, DWORD dwSignatureType) +{ +    TMPQArchive * ha; + +    // Verify the archive handle +    ha = IsValidMpqHandle(hMpq); +    if(ha == NULL) +    { +        SetLastError(ERROR_INVALID_PARAMETER); +        return false; +    } + +    // We only support weak signature, and only for MPQs version 1.0 +    if(dwSignatureType != SIGNATURE_TYPE_WEAK) +    { +        SetLastError(ERROR_INVALID_PARAMETER); +        return false; +    } + +    // The archive must not be malformed and must not be read-only +    if(ha->dwFlags & (MPQ_FLAG_READ_ONLY | MPQ_FLAG_MALFORMED)) +    { +        SetLastError(ERROR_ACCESS_DENIED); +        return false; +    } + +    // If the signature is not there yet +    if(ha->dwFileFlags3 == 0) +    { +        // Turn the signature on. The signature will +        // be applied when the archive is closed +        ha->dwFlags |= MPQ_FLAG_SIGNATURE_INVALID | MPQ_FLAG_CHANGED; +        ha->dwFileFlags3 = MPQ_FILE_EXISTS; +        ha->dwReservedFiles++; +    } + +    return true; +} + diff --git a/src/StormCommon.h b/src/StormCommon.h index 52a5620..25cc981 100644 --- a/src/StormCommon.h +++ b/src/StormCommon.h @@ -77,6 +77,7 @@  #define MPQ_WEAK_SIGNATURE_SIZE                 64  #define MPQ_STRONG_SIGNATURE_SIZE              256   #define MPQ_STRONG_SIGNATURE_ID         0x5349474E      // ID of the strong signature ("NGIS") +#define MPQ_SIGNATURE_FILE_SIZE (MPQ_WEAK_SIGNATURE_SIZE + 8)  // MPQ signature info  typedef struct _MPQ_SIGNATURE_INFO @@ -303,6 +304,12 @@ int  SAttrFileSaveToMpq(TMPQArchive * ha);  int  SListFileSaveToMpq(TMPQArchive * ha);  //----------------------------------------------------------------------------- +// Weak signature support + +int SSignFileCreate(TMPQArchive * ha); +int SSignFileFinish(TMPQArchive * ha); + +//-----------------------------------------------------------------------------  // Dump data support  #ifdef __STORMLIB_DUMP_DATA__ diff --git a/src/StormLib.h b/src/StormLib.h index 3ff72e8..ce1c02f 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -68,6 +68,7 @@  /* 29.05.12  8.20  Lad  C-only interface                                     */  /* 14.01.13  8.21  Lad  ADPCM and Huffmann (de)compression refactored        */  /* 04.12.13  9.00  Lad  Unit tests, bug fixes                                */ +/* 27.08.14  9.10  Lad  Signing archives with weak digital signature         */  /*****************************************************************************/  #ifndef __STORMLIB_H__ @@ -132,8 +133,8 @@ extern "C" {  //-----------------------------------------------------------------------------  // Defines -#define STORMLIB_VERSION                0x0900  // Current version of StormLib (9.0) -#define STORMLIB_VERSION_STRING         "9.00"  // String version of StormLib version +#define STORMLIB_VERSION                0x090A  // Current version of StormLib (9.1) +#define STORMLIB_VERSION_STRING         "9.10"  // String version of StormLib version  #define ID_MPQ                      0x1A51504D  // MPQ archive header ID ('MPQ\x1A')  #define ID_MPQ_USERDATA             0x1B51504D  // MPQ userdata entry ('MPQ\x1B') @@ -180,7 +181,8 @@ extern "C" {  #define MPQ_FLAG_CHECK_SECTOR_CRC   0x00000008  // Checking sector CRC when reading files  #define MPQ_FLAG_LISTFILE_INVALID   0x00000020  // If set, it means that the (listfile) has been invalidated  #define MPQ_FLAG_ATTRIBUTES_INVALID 0x00000040  // If set, it means that the (attributes) has been invalidated -#define MPQ_FLAG_SAVING_TABLES      0x00000080  // If set, we are saving MPQ internal files and MPQ tables +#define MPQ_FLAG_SIGNATURE_INVALID  0x00000080  // If set, it means that the (signature) has been invalidated +#define MPQ_FLAG_SAVING_TABLES      0x00000100  // If set, we are saving MPQ internal files and MPQ tables  // Values for TMPQArchive::dwSubType  #define MPQ_SUBTYPE_MPQ             0x00000000  // The file is a MPQ file (Blizzard games) @@ -290,6 +292,7 @@ extern "C" {  // Flags for SFileCreateArchive  #define MPQ_CREATE_LISTFILE         0x00100000  // Also add the (listfile) file  #define MPQ_CREATE_ATTRIBUTES       0x00200000  // Also add the (attributes) file +#define MPQ_CREATE_SIGNATURE        0x00400000  // Also add the (signature) file  #define MPQ_CREATE_ARCHIVE_V1       0x00000000  // Creates archive of version 1 (size up to 4GB)  #define MPQ_CREATE_ARCHIVE_V2       0x01000000  // Creates archive of version 2 (larger than 4 GB)  #define MPQ_CREATE_ARCHIVE_V3       0x02000000  // Creates archive of version 3 @@ -852,6 +855,7 @@ typedef struct _TMPQArchive      DWORD          dwSectorSize;                // Default size of one file sector      DWORD          dwFileFlags1;                // Flags for (listfile)      DWORD          dwFileFlags2;                // Flags for (attributes) +    DWORD          dwFileFlags3;                // Flags for (signature)      DWORD          dwAttrFlags;                 // Flags for the (attributes) file, see MPQ_ATTRIBUTE_XXX      DWORD          dwFlags;                     // See MPQ_FLAG_XXXXX      DWORD          dwSubType;                   // See MPQ_SUBTYPE_XXX @@ -929,6 +933,7 @@ typedef struct _SFILE_CREATE_MPQ      DWORD dwStreamFlags;                        // Stream flags for creating the MPQ      DWORD dwFileFlags1;                         // File flags for (listfile). 0 = default      DWORD dwFileFlags2;                         // File flags for (attributes). 0 = default +    DWORD dwFileFlags3;                         // File flags for (signature). 0 = default      DWORD dwAttrFlags;                          // Flags for the (attributes) file. If 0, no attributes will be created      DWORD dwSectorSize;                         // Sector size for compressed files      DWORD dwRawChunkSize;                       // Size of raw data chunk @@ -1058,6 +1063,7 @@ DWORD  WINAPI SFileVerifyFile(HANDLE hMpq, const char * szFileName, DWORD dwFlag  int    WINAPI SFileVerifyRawData(HANDLE hMpq, DWORD dwWhatToVerify, const char * szFileName);  // Verifies the signature, if present +bool   WINAPI SFileSignArchive(HANDLE hMpq, DWORD dwSignatureType);  DWORD  WINAPI SFileVerifyArchive(HANDLE hMpq);  //----------------------------------------------------------------------------- diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_bit_string.c b/src/libtomcrypt/src/pk/asn1/der_encode_bit_string.c new file mode 100644 index 0000000..ca29c58 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_bit_string.c @@ -0,0 +1,89 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_bit_string.c +  ASN.1 DER, encode a BIT STRING, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** +  Store a BIT STRING +  @param in       The array of bits to store (one per char) +  @param inlen    The number of bits tostore +  @param out      [out] The destination for the DER encoded BIT STRING +  @param outlen   [in/out] The max size and resulting size of the DER BIT STRING +  @return CRYPT_OK if successful +*/ +int der_encode_bit_string(const unsigned char *in, unsigned long inlen, +                                unsigned char *out, unsigned long *outlen) +{ +   unsigned long len, x, y; +   unsigned char buf; +   int           err; + +   LTC_ARGCHK(in     != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* avoid overflows */ +   if ((err = der_length_bit_string(inlen, &len)) != CRYPT_OK) { +      return err; +   } + +   if (len > *outlen) { +      *outlen = len; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* store header (include bit padding count in length) */ +   x = 0; +   y = (inlen >> 3) + ((inlen&7) ? 1 : 0) + 1; + +   out[x++] = 0x03; +   if (y < 128) { +      out[x++] = (unsigned char)y; +   } else if (y < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)y; +   } else if (y < 65536) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((y>>8)&255); +      out[x++] = (unsigned char)(y&255); +   } + +   /* store number of zero padding bits */ +   out[x++] = (unsigned char)((8 - inlen) & 7); + +   /* store the bits in big endian format */ +   for (y = buf = 0; y < inlen; y++) { +       buf |= (in[y] ? 1 : 0) << (7 - (y & 7)); +       if ((y & 7) == 7) { +          out[x++] = buf; +          buf      = 0; +       } +   } +   /* store last byte */ +   if (inlen & 7) { +      out[x++] = buf; +   } +   *outlen = x; +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_encode_bit_string.c,v $ */ +/* $Revision: 1.5 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_boolean.c b/src/libtomcrypt/src/pk/asn1/der_encode_boolean.c new file mode 100644 index 0000000..ded2731 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_boolean.c @@ -0,0 +1,51 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_boolean.c +  ASN.1 DER, encode a BOOLEAN, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** +  Store a BOOLEAN +  @param in       The boolean to encode +  @param out      [out] The destination for the DER encoded BOOLEAN +  @param outlen   [in/out] The max size and resulting size of the DER BOOLEAN +  @return CRYPT_OK if successful +*/ +int der_encode_boolean(int in,  +                       unsigned char *out, unsigned long *outlen) +{ +   LTC_ARGCHK(outlen != NULL); +   LTC_ARGCHK(out    != NULL); +    +   if (*outlen < 3) { +       *outlen = 3; +       return CRYPT_BUFFER_OVERFLOW; +   } +    +   *outlen = 3; +   out[0] = 0x01; +   out[1] = 0x01; +   out[2] = in ? 0xFF : 0x00; +    +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_encode_boolean.c,v $ */ +/* $Revision: 1.4 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.c b/src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.c new file mode 100644 index 0000000..30d3f43 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_ia5_string.c @@ -0,0 +1,85 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_ia5_string.c +  ASN.1 DER, encode a IA5 STRING, Tom St Denis +*/ + +#ifdef LTC_DER + +/** +  Store an IA5 STRING +  @param in       The array of IA5 to store (one per char) +  @param inlen    The number of IA5 to store +  @param out      [out] The destination for the DER encoded IA5 STRING +  @param outlen   [in/out] The max size and resulting size of the DER IA5 STRING +  @return CRYPT_OK if successful +*/ +int der_encode_ia5_string(const unsigned char *in, unsigned long inlen, +                                unsigned char *out, unsigned long *outlen) +{ +   unsigned long x, y, len; +   int           err; + +   LTC_ARGCHK(in     != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* get the size */ +   if ((err = der_length_ia5_string(in, inlen, &len)) != CRYPT_OK) { +      return err;  +   } + +   /* too big? */ +   if (len > *outlen) { +      *outlen = len; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* encode the header+len */ +   x = 0; +   out[x++] = 0x16; +   if (inlen < 128) { +      out[x++] = (unsigned char)inlen; +   } else if (inlen < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)inlen; +   } else if (inlen < 65536UL) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((inlen>>8)&255); +      out[x++] = (unsigned char)(inlen&255); +   } else if (inlen < 16777216UL) { +      out[x++] = 0x83; +      out[x++] = (unsigned char)((inlen>>16)&255); +      out[x++] = (unsigned char)((inlen>>8)&255); +      out[x++] = (unsigned char)(inlen&255); +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* store octets */ +   for (y = 0; y < inlen; y++) { +       out[x++] = der_ia5_char_encode(in[y]); +   } + +   /* retun length */ +   *outlen = x; + +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c,v $ */ +/* $Revision: 1.5 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_integer.c b/src/libtomcrypt/src/pk/asn1/der_encode_integer.c new file mode 100644 index 0000000..4137a94 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_integer.c @@ -0,0 +1,130 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_integer.c +  ASN.1 DER, encode an integer, Tom St Denis +*/ + + +#ifdef LTC_DER + +/* Exports a positive bignum as DER format (upto 2^32 bytes in size) */ +/** +  Store a mp_int integer +  @param num      The first mp_int to encode +  @param out      [out] The destination for the DER encoded integers +  @param outlen   [in/out] The max size and resulting size of the DER encoded integers +  @return CRYPT_OK if successful +*/ +int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen) +{   +   unsigned long tmplen, y; +   int           err, leading_zero; + +   LTC_ARGCHK(num    != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* find out how big this will be */ +   if ((err = der_length_integer(num, &tmplen)) != CRYPT_OK) { +      return err; +   } + +   if (*outlen < tmplen) { +      *outlen = tmplen; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   if (mp_cmp_d(num, 0) != LTC_MP_LT) { +      /* we only need a leading zero if the msb of the first byte is one */ +      if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == LTC_MP_YES) { +         leading_zero = 1; +      } else { +         leading_zero = 0; +      } + +      /* get length of num in bytes (plus 1 since we force the msbyte to zero) */ +      y = mp_unsigned_bin_size(num) + leading_zero; +   } else { +      leading_zero = 0; +      y            = mp_count_bits(num); +      y            = y + (8 - (y & 7)); +      y            = y >> 3; +      if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --y; +   } + +   /* now store initial data */ +   *out++ = 0x02; +   if (y < 128) { +      /* short form */ +      *out++ = (unsigned char)y; +   } else if (y < 256) { +      *out++ = 0x81; +      *out++ = (unsigned char)y; +   } else if (y < 65536UL) { +      *out++ = 0x82; +      *out++ = (unsigned char)((y>>8)&255); +      *out++ = (unsigned char)y; +   } else if (y < 16777216UL) { +      *out++ = 0x83; +      *out++ = (unsigned char)((y>>16)&255); +      *out++ = (unsigned char)((y>>8)&255); +      *out++ = (unsigned char)y; +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* now store msbyte of zero if num is non-zero */ +   if (leading_zero) { +      *out++ = 0x00; +   } + +   /* if it's not zero store it as big endian */ +   if (mp_cmp_d(num, 0) == LTC_MP_GT) { +      /* now store the mpint */ +      if ((err = mp_to_unsigned_bin(num, out)) != CRYPT_OK) { +          return err; +      } +   } else if (mp_iszero(num) != LTC_MP_YES) { +      void *tmp; +          +      /* negative */ +      if (mp_init(&tmp) != CRYPT_OK) { +         return CRYPT_MEM; +      } + +      /* 2^roundup and subtract */ +      y = mp_count_bits(num); +      y = y + (8 - (y & 7)); +      if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) y -= 8; +      if (mp_2expt(tmp, y) != CRYPT_OK || mp_add(tmp, num, tmp) != CRYPT_OK) { +         mp_clear(tmp); +         return CRYPT_MEM; +      } +      if ((err = mp_to_unsigned_bin(tmp, out)) != CRYPT_OK) { +         mp_clear(tmp); +         return err; +      } +      mp_clear(tmp); +   } + +   /* we good */ +   *outlen = tmplen;  +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_encode_integer.c,v $ */ +/* $Revision: 1.9 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.c b/src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.c new file mode 100644 index 0000000..68e2162 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_object_identifier.c @@ -0,0 +1,111 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_object_identifier.c +  ASN.1 DER, Encode Object Identifier, Tom St Denis +*/ + +#ifdef LTC_DER +/** +  Encode an OID +  @param words   The words to encode  (upto 32-bits each) +  @param nwords  The number of words in the OID +  @param out     [out] Destination of OID data +  @param outlen  [in/out] The max and resulting size of the OID +  @return CRYPT_OK if successful +*/ +int der_encode_object_identifier(unsigned long *words, unsigned long  nwords, +                                 unsigned char *out,   unsigned long *outlen) +{ +   unsigned long i, x, y, z, t, mask, wordbuf; +   int           err; + +   LTC_ARGCHK(words  != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* check length */ +   if ((err = der_length_object_identifier(words, nwords, &x)) != CRYPT_OK) { +      return err; +   } +   if (x > *outlen) { +      *outlen = x; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* compute length to store OID data */ +   z = 0; +   wordbuf = words[0] * 40 + words[1]; +   for (y = 1; y < nwords; y++) { +       t = der_object_identifier_bits(wordbuf); +       z += t/7 + ((t%7) ? 1 : 0) + (wordbuf == 0 ? 1 : 0); +       if (y < nwords - 1) { +          wordbuf = words[y + 1]; +       } +   } + +   /* store header + length */ +   x = 0;  +   out[x++] = 0x06; +   if (z < 128) { +      out[x++] = (unsigned char)z; +   } else if (z < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)z; +   } else if (z < 65536UL) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((z>>8)&255); +      out[x++] = (unsigned char)(z&255); +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* store first byte */ +    wordbuf = words[0] * 40 + words[1];    +    for (i = 1; i < nwords; i++) { +        /* store 7 bit words in little endian */ +        t    = wordbuf & 0xFFFFFFFF; +        if (t) { +           y    = x; +           mask = 0; +           while (t) { +               out[x++] = (unsigned char)((t & 0x7F) | mask); +               t    >>= 7; +               mask  |= 0x80;  /* upper bit is set on all but the last byte */ +           } +           /* now swap bytes y...x-1 */ +           z = x - 1; +           while (y < z) { +               t = out[y]; out[y] = out[z]; out[z] = (unsigned char)t; +               ++y;  +               --z; +           } +       } else { +          /* zero word */ +          out[x++] = 0x00; +       } +        +       if (i < nwords - 1) { +          wordbuf = words[i + 1]; +       } +   } + +   *outlen = x; +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c,v $ */ +/* $Revision: 1.7 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_octet_string.c b/src/libtomcrypt/src/pk/asn1/der_encode_octet_string.c new file mode 100644 index 0000000..b3ee7f4 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_octet_string.c @@ -0,0 +1,86 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_octet_string.c +  ASN.1 DER, encode a OCTET STRING, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** +  Store an OCTET STRING +  @param in       The array of OCTETS to store (one per char) +  @param inlen    The number of OCTETS to store +  @param out      [out] The destination for the DER encoded OCTET STRING +  @param outlen   [in/out] The max size and resulting size of the DER OCTET STRING +  @return CRYPT_OK if successful +*/ +int der_encode_octet_string(const unsigned char *in, unsigned long inlen, +                                  unsigned char *out, unsigned long *outlen) +{ +   unsigned long x, y, len; +   int           err; + +   LTC_ARGCHK(in     != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* get the size */ +   if ((err = der_length_octet_string(inlen, &len)) != CRYPT_OK) { +      return err;  +   } + +   /* too big? */ +   if (len > *outlen) { +      *outlen = len; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* encode the header+len */ +   x = 0; +   out[x++] = 0x04; +   if (inlen < 128) { +      out[x++] = (unsigned char)inlen; +   } else if (inlen < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)inlen; +   } else if (inlen < 65536UL) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((inlen>>8)&255); +      out[x++] = (unsigned char)(inlen&255); +   } else if (inlen < 16777216UL) { +      out[x++] = 0x83; +      out[x++] = (unsigned char)((inlen>>16)&255); +      out[x++] = (unsigned char)((inlen>>8)&255); +      out[x++] = (unsigned char)(inlen&255); +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* store octets */ +   for (y = 0; y < inlen; y++) { +       out[x++] = in[y]; +   } + +   /* retun length */ +   *outlen = x; + +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_encode_octet_string.c,v $ */ +/* $Revision: 1.5 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_printable_string.c b/src/libtomcrypt/src/pk/asn1/der_encode_printable_string.c new file mode 100644 index 0000000..a1dab5f --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_printable_string.c @@ -0,0 +1,85 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_printable_string.c +  ASN.1 DER, encode a printable STRING, Tom St Denis +*/ + +#ifdef LTC_DER + +/** +  Store an printable STRING +  @param in       The array of printable to store (one per char) +  @param inlen    The number of printable to store +  @param out      [out] The destination for the DER encoded printable STRING +  @param outlen   [in/out] The max size and resulting size of the DER printable STRING +  @return CRYPT_OK if successful +*/ +int der_encode_printable_string(const unsigned char *in, unsigned long inlen, +                                unsigned char *out, unsigned long *outlen) +{ +   unsigned long x, y, len; +   int           err; + +   LTC_ARGCHK(in     != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* get the size */ +   if ((err = der_length_printable_string(in, inlen, &len)) != CRYPT_OK) { +      return err;  +   } + +   /* too big? */ +   if (len > *outlen) { +      *outlen = len; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* encode the header+len */ +   x = 0; +   out[x++] = 0x13; +   if (inlen < 128) { +      out[x++] = (unsigned char)inlen; +   } else if (inlen < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)inlen; +   } else if (inlen < 65536UL) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((inlen>>8)&255); +      out[x++] = (unsigned char)(inlen&255); +   } else if (inlen < 16777216UL) { +      out[x++] = 0x83; +      out[x++] = (unsigned char)((inlen>>16)&255); +      out[x++] = (unsigned char)((inlen>>8)&255); +      out[x++] = (unsigned char)(inlen&255); +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* store octets */ +   for (y = 0; y < inlen; y++) { +       out[x++] = der_printable_char_encode(in[y]); +   } + +   /* retun length */ +   *outlen = x; + +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/printable_string/der_encode_printable_string.c,v $ */ +/* $Revision: 1.5 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.c b/src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.c new file mode 100644 index 0000000..3df19cf --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_sequence_ex.c @@ -0,0 +1,335 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" +#include <stdarg.h> + + +/** +  @file der_encode_sequence_ex.c +  ASN.1 DER, encode a SEQUENCE, Tom St Denis +*/ + +#ifdef LTC_DER + +/** +   Encode a SEQUENCE +   @param list      The list of items to encode +   @param inlen     The number of items in the list +   @param out       [out] The destination  +   @param outlen    [in/out] The size of the output +   @param type_of   LTC_ASN1_SEQUENCE or LTC_ASN1_SET/LTC_ASN1_SETOF +   @return CRYPT_OK on success +*/ +int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen, +                           unsigned char *out,  unsigned long *outlen, int type_of)  +{ +   int           err, type; +   unsigned long size, x, y, z, i; +   void          *data; + +   LTC_ARGCHK(list    != NULL); +   LTC_ARGCHK(out     != NULL); +   LTC_ARGCHK(outlen  != NULL); + +   /* get size of output that will be required */ +   y = 0; +   for (i = 0; i < inlen; i++) { +       type = list[i].type; +       size = list[i].size; +       data = list[i].data; + +       if (type == LTC_ASN1_EOL) {  +          break; +       } + +       switch (type) { +            case LTC_ASN1_BOOLEAN: +               if ((err = der_length_boolean(&x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_INTEGER: +               if ((err = der_length_integer(data, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_SHORT_INTEGER: +               if ((err = der_length_short_integer(*((unsigned long*)data), &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_BIT_STRING: +               if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_OCTET_STRING: +               if ((err = der_length_octet_string(size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_NULL: +               y += 2; +               break; + +           case LTC_ASN1_OBJECT_IDENTIFIER: +               if ((err = der_length_object_identifier(data, size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_IA5_STRING: +               if ((err = der_length_ia5_string(data, size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_PRINTABLE_STRING: +               if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_UTF8_STRING: +               if ((err = der_length_utf8_string(data, size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_UTCTIME: +               if ((err = der_length_utctime(data, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; + +           case LTC_ASN1_SET: +           case LTC_ASN1_SETOF: +           case LTC_ASN1_SEQUENCE: +               if ((err = der_length_sequence(data, size, &x)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               y += x; +               break; +           +           default: +               err = CRYPT_INVALID_ARG; +               goto LBL_ERR; +       } +   } + +   /* calc header size */ +   z = y; +   if (y < 128) { +      y += 2; +   } else if (y < 256) { +      /* 0x30 0x81 LL */ +      y += 3; +   } else if (y < 65536UL) { +      /* 0x30 0x82 LL LL */ +      y += 4; +   } else if (y < 16777216UL) { +      /* 0x30 0x83 LL LL LL */ +      y += 5; +   } else { +      err = CRYPT_INVALID_ARG; +      goto LBL_ERR; +   } + +   /* too big ? */ +   if (*outlen < y) { +      *outlen = y; +      err = CRYPT_BUFFER_OVERFLOW; +      goto LBL_ERR; +   } + +   /* store header */ +   x = 0; +   out[x++] = (type_of == LTC_ASN1_SEQUENCE) ? 0x30 : 0x31; +       +   if (z < 128) { +      out[x++] = (unsigned char)z; +   } else if (z < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)z; +   } else if (z < 65536UL) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((z>>8UL)&255); +      out[x++] = (unsigned char)(z&255); +   } else if (z < 16777216UL) { +      out[x++] = 0x83; +      out[x++] = (unsigned char)((z>>16UL)&255); +      out[x++] = (unsigned char)((z>>8UL)&255); +      out[x++] = (unsigned char)(z&255); +   } + +   /* store data */ +   *outlen -= x; +   for (i = 0; i < inlen; i++) { +       type = list[i].type; +       size = list[i].size; +       data = list[i].data; + +       if (type == LTC_ASN1_EOL) {  +          break; +       } + +       switch (type) { +            case LTC_ASN1_BOOLEAN: +               z = *outlen; +               if ((err = der_encode_boolean(*((int *)data), out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; +           +           case LTC_ASN1_INTEGER: +               z = *outlen; +               if ((err = der_encode_integer(data, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_SHORT_INTEGER: +               z = *outlen; +               if ((err = der_encode_short_integer(*((unsigned long*)data), out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_BIT_STRING: +               z = *outlen; +               if ((err = der_encode_bit_string(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_OCTET_STRING: +               z = *outlen; +               if ((err = der_encode_octet_string(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_NULL: +               out[x++] = 0x05; +               out[x++] = 0x00; +               *outlen -= 2; +               break; + +           case LTC_ASN1_OBJECT_IDENTIFIER: +               z = *outlen; +               if ((err = der_encode_object_identifier(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_IA5_STRING: +               z = *outlen; +               if ((err = der_encode_ia5_string(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; +           +           case LTC_ASN1_PRINTABLE_STRING: +               z = *outlen; +               if ((err = der_encode_printable_string(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_UTF8_STRING: +               z = *outlen; +               if ((err = der_encode_utf8_string(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_UTCTIME: +               z = *outlen; +               if ((err = der_encode_utctime(data, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_SET: +               z = *outlen; +               if ((err = der_encode_set(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_SETOF: +               z = *outlen; +               if ((err = der_encode_setof(data, size, out + x, &z)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; + +           case LTC_ASN1_SEQUENCE: +               z = *outlen; +               if ((err = der_encode_sequence_ex(data, size, out + x, &z, type)) != CRYPT_OK) { +                  goto LBL_ERR; +               } +               x       += z; +               *outlen -= z; +               break; +            +           default: +               err = CRYPT_INVALID_ARG; +               goto LBL_ERR; +       } +   } +   *outlen = x; +   err = CRYPT_OK;    + +LBL_ERR: +   return err; +} + +#endif diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.c b/src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.c new file mode 100644 index 0000000..782f042 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_sequence_multi.c @@ -0,0 +1,138 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" +#include <stdarg.h> + + +/** +  @file der_encode_sequence_multi.c +  ASN.1 DER, encode a SEQUENCE, Tom St Denis +*/ + +#ifdef LTC_DER + +/** +  Encode a SEQUENCE type using a VA list +  @param out    [out] Destination for data +  @param outlen [in/out] Length of buffer and resulting length of output +  @remark <...> is of the form <type, size, data> (int, unsigned long, void*) +  @return CRYPT_OK on success +*/   +int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...) +{ +   int           err, type; +   unsigned long size, x; +   void          *data; +   va_list       args; +   ltc_asn1_list *list; + +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* get size of output that will be required */ +   va_start(args, outlen); +   x = 0; +   for (;;) { +       type = va_arg(args, int); +       size = va_arg(args, unsigned long); +       data = va_arg(args, void*); + +       if (type == LTC_ASN1_EOL) {  +          break; +       } + +       switch (type) { +           case LTC_ASN1_BOOLEAN: +           case LTC_ASN1_INTEGER: +           case LTC_ASN1_SHORT_INTEGER: +           case LTC_ASN1_BIT_STRING: +           case LTC_ASN1_OCTET_STRING: +           case LTC_ASN1_NULL: +           case LTC_ASN1_OBJECT_IDENTIFIER: +           case LTC_ASN1_IA5_STRING: +           case LTC_ASN1_PRINTABLE_STRING: +           case LTC_ASN1_UTF8_STRING: +           case LTC_ASN1_UTCTIME: +           case LTC_ASN1_SEQUENCE: +           case LTC_ASN1_SET: +           case LTC_ASN1_SETOF: +                ++x;  +                break; +           +           default: +               va_end(args); +               return CRYPT_INVALID_ARG; +       } +   } +   va_end(args); + +   /* allocate structure for x elements */ +   if (x == 0) { +      return CRYPT_NOP; +   } + +   list = XCALLOC(sizeof(*list), x); +   if (list == NULL) { +      return CRYPT_MEM; +   } + +   /* fill in the structure */ +   va_start(args, outlen); +   x = 0; +   for (;;) { +       type = va_arg(args, int); +       size = va_arg(args, unsigned long); +       data = va_arg(args, void*); + +       if (type == LTC_ASN1_EOL) {  +          break; +       } + +       switch (type) { +           case LTC_ASN1_BOOLEAN: +           case LTC_ASN1_INTEGER: +           case LTC_ASN1_SHORT_INTEGER: +           case LTC_ASN1_BIT_STRING: +           case LTC_ASN1_OCTET_STRING: +           case LTC_ASN1_NULL: +           case LTC_ASN1_OBJECT_IDENTIFIER: +           case LTC_ASN1_IA5_STRING: +           case LTC_ASN1_PRINTABLE_STRING: +           case LTC_ASN1_UTF8_STRING: +           case LTC_ASN1_UTCTIME: +           case LTC_ASN1_SEQUENCE: +           case LTC_ASN1_SET: +           case LTC_ASN1_SETOF: +                list[x].type   = type; +                list[x].size   = size; +                list[x++].data = data; +                break; +          +           default: +               va_end(args); +               err = CRYPT_INVALID_ARG; +               goto LBL_ERR; +       } +   } +   va_end(args); + +   err = der_encode_sequence(list, x, out, outlen);    +LBL_ERR: +   XFREE(list); +   return err; +} + +#endif + + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_multi.c,v $ */ +/* $Revision: 1.12 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_set.c b/src/libtomcrypt/src/pk/asn1/der_encode_set.c new file mode 100644 index 0000000..41f6587 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_set.c @@ -0,0 +1,103 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * +  * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_set.c +  ASN.1 DER, Encode a SET, Tom St Denis +*/ + +#ifdef LTC_DER + +/* LTC define to ASN.1 TAG */ +static int ltc_to_asn1(int v) +{ +   switch (v) { +      case LTC_ASN1_BOOLEAN:                 return 0x01; +      case LTC_ASN1_INTEGER: +      case LTC_ASN1_SHORT_INTEGER:           return 0x02; +      case LTC_ASN1_BIT_STRING:              return 0x03; +      case LTC_ASN1_OCTET_STRING:            return 0x04; +      case LTC_ASN1_NULL:                    return 0x05; +      case LTC_ASN1_OBJECT_IDENTIFIER:       return 0x06; +      case LTC_ASN1_UTF8_STRING:             return 0x0C; +      case LTC_ASN1_PRINTABLE_STRING:        return 0x13; +      case LTC_ASN1_IA5_STRING:              return 0x16; +      case LTC_ASN1_UTCTIME:                 return 0x17; +      case LTC_ASN1_SEQUENCE:                return 0x30; +      case LTC_ASN1_SET: +      case LTC_ASN1_SETOF:                   return 0x31; +      default: return -1; +   } +}          +       + +static int qsort_helper(const void *a, const void *b) +{ +   ltc_asn1_list *A = (ltc_asn1_list *)a, *B = (ltc_asn1_list *)b; +   int            r; +    +   r = ltc_to_asn1(A->type) - ltc_to_asn1(B->type); +    +   /* for QSORT the order is UNDEFINED if they are "equal" which means it is NOT DETERMINISTIC.  So we force it to be :-) */ +   if (r == 0) { +      /* their order in the original list now determines the position */ +      return A->used - B->used; +   } else { +      return r; +   } +}    + +/* +   Encode a SET type +   @param list      The list of items to encode +   @param inlen     The number of items in the list +   @param out       [out] The destination  +   @param outlen    [in/out] The size of the output +   @return CRYPT_OK on success +*/ +int der_encode_set(ltc_asn1_list *list, unsigned long inlen, +                   unsigned char *out,  unsigned long *outlen) +{ +   ltc_asn1_list  *copy; +   unsigned long   x; +   int             err; +    +   /* make copy of list */ +   copy = XCALLOC(inlen, sizeof(*copy)); +   if (copy == NULL) { +      return CRYPT_MEM; +   }       +    +   /* fill in used member with index so we can fully sort it */ +   for (x = 0; x < inlen; x++) { +       copy[x]      = list[x]; +       copy[x].used = x; +   }        +    +   /* sort it by the "type" field */ +   XQSORT(copy, inlen, sizeof(*copy), &qsort_helper);    +    +   /* call der_encode_sequence_ex() */ +   err = der_encode_sequence_ex(copy, inlen, out, outlen, LTC_ASN1_SET);    +    +   /* free list */ +   XFREE(copy); +    +   return err; +}                    + + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/set/der_encode_set.c,v $ */ +/* $Revision: 1.12 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_setof.c b/src/libtomcrypt/src/pk/asn1/der_encode_setof.c new file mode 100644 index 0000000..ad7b0f6 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_setof.c @@ -0,0 +1,162 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_setof.c +  ASN.1 DER, Encode SET OF, Tom St Denis +*/ + +#ifdef LTC_DER + +struct edge { +   unsigned char *start; +   unsigned long  size; +}; + +static int qsort_helper(const void *a, const void *b) +{ +   struct edge   *A = (struct edge *)a, *B = (struct edge *)b; +   int            r; +   unsigned long  x; +    +   /* compare min length */ +   r = XMEMCMP(A->start, B->start, MIN(A->size, B->size)); +    +   if (r == 0 && A->size != B->size) { +      if (A->size > B->size) { +         for (x = B->size; x < A->size; x++) { +            if (A->start[x]) { +               return 1; +            } +         } +      } else { +         for (x = A->size; x < B->size; x++) { +            if (B->start[x]) { +               return -1; +            } +         } +      }          +   } +    +   return r;       +} + +/** +   Encode a SETOF stucture +   @param list      The list of items to encode +   @param inlen     The number of items in the list +   @param out       [out] The destination  +   @param outlen    [in/out] The size of the output +   @return CRYPT_OK on success +*/    +int der_encode_setof(ltc_asn1_list *list, unsigned long inlen, +                     unsigned char *out,  unsigned long *outlen) +{ +   unsigned long  x, y, z, hdrlen; +   int            err; +   struct edge   *edges; +   unsigned char *ptr, *buf; +    +   /* check that they're all the same type */ +   for (x = 1; x < inlen; x++) { +      if (list[x].type != list[x-1].type) { +         return CRYPT_INVALID_ARG; +      } +   } + +   /* alloc buffer to store copy of output */ +   buf = XCALLOC(1, *outlen); +   if (buf == NULL) { +      return CRYPT_MEM; +   }       +                   +   /* encode list */ +   if ((err = der_encode_sequence_ex(list, inlen, buf, outlen, LTC_ASN1_SETOF)) != CRYPT_OK) { +       XFREE(buf); +       return err; +   } +    +   /* allocate edges */ +   edges = XCALLOC(inlen, sizeof(*edges)); +   if (edges == NULL) { +      XFREE(buf); +      return CRYPT_MEM; +   }       +    +   /* skip header */ +      ptr = buf + 1; + +      /* now skip length data */ +      x = *ptr++; +      if (x >= 0x80) { +         ptr += (x & 0x7F); +      } +       +      /* get the size of the static header */ +      hdrlen = ((unsigned long)ptr) - ((unsigned long)buf); +       +       +   /* scan for edges */ +   x = 0; +   while (ptr < (buf + *outlen)) { +      /* store start */ +      edges[x].start = ptr; +       +      /* skip type */ +      z = 1; +       +      /* parse length */ +      y = ptr[z++]; +      if (y < 128) { +         edges[x].size = y; +      } else { +         y &= 0x7F; +         edges[x].size = 0; +         while (y--) { +            edges[x].size = (edges[x].size << 8) | ((unsigned long)ptr[z++]); +         } +      } +       +      /* skip content */ +      edges[x].size += z; +      ptr           += edges[x].size; +      ++x; +   }       +       +   /* sort based on contents (using edges) */ +   XQSORT(edges, inlen, sizeof(*edges), &qsort_helper); +    +   /* copy static header */ +   XMEMCPY(out, buf, hdrlen); +    +   /* copy+sort using edges+indecies to output from buffer */ +   for (y = hdrlen, x = 0; x < inlen; x++) { +      XMEMCPY(out+y, edges[x].start, edges[x].size); +      y += edges[x].size; +   }       +    +#ifdef LTC_CLEAN_STACK +   zeromem(buf, *outlen); +#endif       +    +   /* free buffers */ +   XFREE(edges); +   XFREE(buf); +    +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/set/der_encode_setof.c,v $ */ +/* $Revision: 1.12 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_short_integer.c b/src/libtomcrypt/src/pk/asn1/der_encode_short_integer.c new file mode 100644 index 0000000..9b167d0 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_short_integer.c @@ -0,0 +1,97 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_short_integer.c +  ASN.1 DER, encode an integer, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** +  Store a short integer in the range (0,2^32-1) +  @param num      The integer to encode +  @param out      [out] The destination for the DER encoded integers +  @param outlen   [in/out] The max size and resulting size of the DER encoded integers +  @return CRYPT_OK if successful +*/ +int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen) +{   +   unsigned long len, x, y, z; +   int           err; +    +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* force to 32 bits */ +   num &= 0xFFFFFFFFUL; + +   /* find out how big this will be */ +   if ((err = der_length_short_integer(num, &len)) != CRYPT_OK) { +      return err; +   } + +   if (*outlen < len) { +      *outlen = len; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* get len of output */ +   z = 0; +   y = num; +   while (y) { +     ++z; +     y >>= 8; +   } + +   /* handle zero */ +   if (z == 0) { +      z = 1; +   } + +   /* see if msb is set */ +   z += (num&(1UL<<((z<<3) - 1))) ? 1 : 0; + +   /* adjust the number so the msB is non-zero */ +   for (x = 0; (z <= 4) && (x < (4 - z)); x++) { +      num <<= 8; +   } + +   /* store header */ +   x = 0; +   out[x++] = 0x02; +   out[x++] = (unsigned char)z; + +   /* if 31st bit is set output a leading zero and decrement count */ +   if (z == 5) { +      out[x++] = 0; +      --z; +   } + +   /* store values */ +   for (y = 0; y < z; y++) { +      out[x++] = (unsigned char)((num >> 24) & 0xFF); +      num    <<= 8; +   } + +   /* we good */ +   *outlen = x; +  +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_encode_short_integer.c,v $ */ +/* $Revision: 1.8 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_utctime.c b/src/libtomcrypt/src/pk/asn1/der_encode_utctime.c new file mode 100644 index 0000000..167a2b4 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_utctime.c @@ -0,0 +1,83 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_utctime.c +  ASN.1 DER, encode a  UTCTIME, Tom St Denis +*/ + +#ifdef LTC_DER + +static const char *baseten = "0123456789"; + +#define STORE_V(y) \ +    out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \ +    out[x++] = der_ia5_char_encode(baseten[y % 10]); + +/** +  Encodes a UTC time structure in DER format +  @param utctime      The UTC time structure to encode +  @param out          The destination of the DER encoding of the UTC time structure +  @param outlen       [in/out] The length of the DER encoding +  @return CRYPT_OK if successful +*/ +int der_encode_utctime(ltc_utctime *utctime,  +                       unsigned char *out,   unsigned long *outlen) +{ +    unsigned long x, tmplen; +    int           err; +  +    LTC_ARGCHK(utctime != NULL); +    LTC_ARGCHK(out     != NULL); +    LTC_ARGCHK(outlen  != NULL); + +    if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) { +       return err; +    } +    if (tmplen > *outlen) { +        *outlen = tmplen; +        return CRYPT_BUFFER_OVERFLOW; +    } +     +    /* store header */ +    out[0] = 0x17; + +    /* store values */ +    x = 2; +    STORE_V(utctime->YY); +    STORE_V(utctime->MM); +    STORE_V(utctime->DD); +    STORE_V(utctime->hh); +    STORE_V(utctime->mm); +    STORE_V(utctime->ss); + +    if (utctime->off_mm || utctime->off_hh) { +       out[x++] = der_ia5_char_encode(utctime->off_dir ? '-' : '+'); +       STORE_V(utctime->off_hh); +       STORE_V(utctime->off_mm); +    } else { +       out[x++] = der_ia5_char_encode('Z'); +    } + +    /* store length */ +    out[1] = (unsigned char)(x - 2); +    +    /* all good let's return */ +    *outlen = x; +    return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c,v $ */ +/* $Revision: 1.10 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.c b/src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.c new file mode 100644 index 0000000..84d8d06 --- /dev/null +++ b/src/libtomcrypt/src/pk/asn1/der_encode_utf8_string.c @@ -0,0 +1,105 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file der_encode_utf8_string.c +  ASN.1 DER, encode a UTF8 STRING, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** +  Store an UTF8 STRING +  @param in       The array of UTF8 to store (one per wchar_t) +  @param inlen    The number of UTF8 to store +  @param out      [out] The destination for the DER encoded UTF8 STRING +  @param outlen   [in/out] The max size and resulting size of the DER UTF8 STRING +  @return CRYPT_OK if successful +*/ +int der_encode_utf8_string(const wchar_t *in,  unsigned long inlen, +                           unsigned char *out, unsigned long *outlen) +{ +   unsigned long x, y, len; + +   LTC_ARGCHK(in     != NULL); +   LTC_ARGCHK(out    != NULL); +   LTC_ARGCHK(outlen != NULL); + +   /* get the size */ +   for (x = len = 0; x < inlen; x++) { +       if (in[x] < 0 || in[x] > 0x1FFFF) {  +          return CRYPT_INVALID_ARG; +       } +       len += der_utf8_charsize(in[x]); +   } + +   if (len < 128) { +      y = 2 + len; +   } else if (len < 256) { +      y = 3 + len; +   } else if (len < 65536UL) { +      y = 4 + len; +   } else if (len < 16777216UL) { +      y = 5 + len; +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* too big? */ +   if (y > *outlen) { +      *outlen = len; +      return CRYPT_BUFFER_OVERFLOW; +   } + +   /* encode the header+len */ +   x = 0; +   out[x++] = 0x0C; +   if (len < 128) { +      out[x++] = (unsigned char)len; +   } else if (len < 256) { +      out[x++] = 0x81; +      out[x++] = (unsigned char)len; +   } else if (len < 65536UL) { +      out[x++] = 0x82; +      out[x++] = (unsigned char)((len>>8)&255); +      out[x++] = (unsigned char)(len&255); +   } else if (len < 16777216UL) { +      out[x++] = 0x83; +      out[x++] = (unsigned char)((len>>16)&255); +      out[x++] = (unsigned char)((len>>8)&255); +      out[x++] = (unsigned char)(len&255); +   } else { +      return CRYPT_INVALID_ARG; +   } + +   /* store UTF8 */ +   for (y = 0; y < inlen; y++) { +       switch (der_utf8_charsize(in[y])) { +          case 1: out[x++] = (unsigned char)in[y]; break; +          case 2: out[x++] = 0xC0 | ((in[y] >> 6) & 0x1F);  out[x++] = 0x80 | (in[y] & 0x3F); break; +          case 3: out[x++] = 0xE0 | ((in[y] >> 12) & 0x0F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break; +          case 4: out[x++] = 0xF0 | ((in[y] >> 18) & 0x07); out[x++] = 0x80 | ((in[y] >> 12) & 0x3F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break; +       } +   } + +   /* retun length */ +   *outlen = x; + +   return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utf8/der_encode_utf8_string.c,v $ */ +/* $Revision: 1.9 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c b/src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c new file mode 100644 index 0000000..68d5e86 --- /dev/null +++ b/src/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c @@ -0,0 +1,175 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/**  +  @file pkcs_1_pss_encode.c +  LTC_PKCS #1 PSS Signature Padding, Tom St Denis  +*/ + +#ifdef LTC_PKCS_1 + +/** +   LTC_PKCS #1 v2.00 Signature Encoding +   @param msghash          The hash to encode +   @param msghashlen       The length of the hash (octets) +   @param saltlen          The length of the salt desired (octets) +   @param prng             An active PRNG context +   @param prng_idx         The index of the PRNG desired +   @param hash_idx         The index of the hash desired +   @param modulus_bitlen   The bit length of the RSA modulus +   @param out              [out] The destination of the encoding +   @param outlen           [in/out] The max size and resulting size of the encoded data +   @return CRYPT_OK if successful +*/ +int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen, +                            unsigned long saltlen,  prng_state   *prng,      +                            int           prng_idx, int           hash_idx, +                            unsigned long modulus_bitlen, +                            unsigned char *out,     unsigned long *outlen) +{ +   unsigned char *DB, *mask, *salt, *hash; +   unsigned long x, y, hLen, modulus_len; +   int           err; +   hash_state    md; + +   LTC_ARGCHK(msghash != NULL); +   LTC_ARGCHK(out     != NULL); +   LTC_ARGCHK(outlen  != NULL); + +   /* ensure hash and PRNG are valid */ +   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { +      return err; +   } +   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) { +      return err; +   } + +   hLen        = hash_descriptor[hash_idx].hashsize; +   modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0); + +   /* check sizes */ +   if ((saltlen > modulus_len) || (modulus_len < hLen + saltlen + 2)) { +      return CRYPT_PK_INVALID_SIZE; +   } + +   /* allocate ram for DB/mask/salt/hash of size modulus_len */ +   DB   = XMALLOC(modulus_len); +   mask = XMALLOC(modulus_len); +   salt = XMALLOC(modulus_len); +   hash = XMALLOC(modulus_len); +   if (DB == NULL || mask == NULL || salt == NULL || hash == NULL) { +      if (DB != NULL) { +         XFREE(DB); +      } +      if (mask != NULL) { +         XFREE(mask); +      } +      if (salt != NULL) { +         XFREE(salt); +      } +      if (hash != NULL) { +         XFREE(hash); +      } +      return CRYPT_MEM; +   } + + +   /* generate random salt */ +   if (saltlen > 0) { +      if (prng_descriptor[prng_idx].read(salt, saltlen, prng) != saltlen) { +         err = CRYPT_ERROR_READPRNG; +         goto LBL_ERR; +      } +   } + +   /* M = (eight) 0x00 || msghash || salt, hash = H(M) */ +   if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) { +      goto LBL_ERR; +   } +   zeromem(DB, 8); +   if ((err = hash_descriptor[hash_idx].process(&md, DB, 8)) != CRYPT_OK) { +      goto LBL_ERR; +   } +   if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) { +      goto LBL_ERR; +   } +   if ((err = hash_descriptor[hash_idx].process(&md, salt, saltlen)) != CRYPT_OK) { +      goto LBL_ERR; +   } +   if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) { +      goto LBL_ERR; +   } + +   /* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */ +   x = 0; +   XMEMSET(DB + x, 0, modulus_len - saltlen - hLen - 2); +   x += modulus_len - saltlen - hLen - 2; +   DB[x++] = 0x01; +   XMEMCPY(DB + x, salt, saltlen); +   x += saltlen; + +   /* generate mask of length modulus_len - hLen - 1 from hash */ +   if ((err = pkcs_1_mgf1(hash_idx, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) { +      goto LBL_ERR; +   } + +   /* xor against DB */ +   for (y = 0; y < (modulus_len - hLen - 1); y++) { +      DB[y] ^= mask[y]; +   } + +   /* output is DB || hash || 0xBC */ +   if (*outlen < modulus_len) { +      *outlen = modulus_len; +      err = CRYPT_BUFFER_OVERFLOW; +      goto LBL_ERR; +   } + +   /* DB len = modulus_len - hLen - 1 */ +   y = 0; +   XMEMCPY(out + y, DB, modulus_len - hLen - 1); +   y += modulus_len - hLen - 1; + +   /* hash */ +   XMEMCPY(out + y, hash, hLen); +   y += hLen; + +   /* 0xBC */ +   out[y] = 0xBC; + +   /* now clear the 8*modulus_len - modulus_bitlen most significant bits */ +   out[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)); + +   /* store output size */ +   *outlen = modulus_len; +   err = CRYPT_OK; +LBL_ERR: +#ifdef LTC_CLEAN_STACK +   zeromem(DB,   modulus_len);    +   zeromem(mask, modulus_len);    +   zeromem(salt, modulus_len);    +   zeromem(hash, modulus_len);    +#endif + +   XFREE(hash); +   XFREE(salt); +   XFREE(mask); +   XFREE(DB); + +   return err; +} + +#endif /* LTC_PKCS_1 */ + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c,v $ */ +/* $Revision: 1.9 $ */ +/* $Date: 2007/05/12 14:32:35 $ */ diff --git a/src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c b/src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c new file mode 100644 index 0000000..4342919 --- /dev/null +++ b/src/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c @@ -0,0 +1,111 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/*! \file pkcs_1_v1_5_encode.c + * + *  LTC_PKCS #1 v1.5 Padding (Andreas Lange) + */ + +#ifdef LTC_PKCS_1 + +/*! \brief LTC_PKCS #1 v1.5 encode. + * + *  \param msg              The data to encode + *  \param msglen           The length of the data to encode (octets) + *  \param block_type       Block type to use in padding (\sa ltc_pkcs_1_v1_5_blocks) + *  \param modulus_bitlen   The bit length of the RSA modulus + *  \param prng             An active PRNG state (only for LTC_LTC_PKCS_1_EME) + *  \param prng_idx         The index of the PRNG desired (only for LTC_LTC_PKCS_1_EME) + *  \param out              [out] The destination for the encoded data + *  \param outlen           [in/out] The max size and resulting size of the encoded data + * + *  \return CRYPT_OK if successful + */ +int pkcs_1_v1_5_encode(const unsigned char *msg,  +                             unsigned long  msglen, +                                       int  block_type, +                             unsigned long  modulus_bitlen, +                                prng_state *prng,  +                                       int  prng_idx, +                             unsigned char *out,  +                             unsigned long *outlen) +{ +  unsigned long modulus_len, ps_len, i; +  unsigned char *ps; +  int result; + +  /* valid block_type? */ +  if ((block_type != LTC_LTC_PKCS_1_EMSA) && +      (block_type != LTC_LTC_PKCS_1_EME)) { +     return CRYPT_PK_INVALID_PADDING; +  } + +  if (block_type == LTC_LTC_PKCS_1_EME) {    /* encryption padding, we need a valid PRNG */ +    if ((result = prng_is_valid(prng_idx)) != CRYPT_OK) { +       return result; +    } +  } + +  modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0); + +  /* test message size */ +  if ((msglen + 11) > modulus_len) { +    return CRYPT_PK_INVALID_SIZE; +  } + +  if (*outlen < modulus_len) { +    *outlen = modulus_len; +    result = CRYPT_BUFFER_OVERFLOW; +    goto bail; +  } + +  /* generate an octets string PS */ +  ps = &out[2]; +  ps_len = modulus_len - msglen - 3; + +  if (block_type == LTC_LTC_PKCS_1_EME) { +    /* now choose a random ps */ +    if (prng_descriptor[prng_idx].read(ps, ps_len, prng) != ps_len) { +      result = CRYPT_ERROR_READPRNG; +      goto bail; +    } + +    /* transform zero bytes (if any) to non-zero random bytes */ +    for (i = 0; i < ps_len; i++) { +      while (ps[i] == 0) { +        if (prng_descriptor[prng_idx].read(&ps[i], 1, prng) != 1) { +          result = CRYPT_ERROR_READPRNG; +          goto bail; +        } +      } +    } +  } else { +    XMEMSET(ps, 0xFF, ps_len); +  } + +  /* create string of length modulus_len */ +  out[0]          = 0x00; +  out[1]          = (unsigned char)block_type;  /* block_type 1 or 2 */ +  out[2 + ps_len] = 0x00; +  XMEMCPY(&out[2 + ps_len + 1], msg, msglen); +  *outlen = modulus_len; + +  result  = CRYPT_OK; +bail: +  return result; +} /* pkcs_1_v1_5_encode */ + +#endif /* #ifdef LTC_PKCS_1 */ + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c,v $ */ +/* $Revision: 1.4 $ */ +/* $Date: 2007/05/12 14:32:35 $ */ diff --git a/src/libtomcrypt/src/pk/rsa/rsa_sign_hash.c b/src/libtomcrypt/src/pk/rsa/rsa_sign_hash.c new file mode 100644 index 0000000..49fb858 --- /dev/null +++ b/src/libtomcrypt/src/pk/rsa/rsa_sign_hash.c @@ -0,0 +1,134 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "../../headers/tomcrypt.h" + +/** +  @file rsa_sign_hash.c +  RSA LTC_PKCS #1 v1.5 and v2 PSS sign hash, Tom St Denis and Andreas Lange +*/ + +#ifdef LTC_MRSA + +/** +  LTC_PKCS #1 pad then sign +  @param in        The hash to sign +  @param inlen     The length of the hash to sign (octets) +  @param out       [out] The signature +  @param outlen    [in/out] The max size and resulting size of the signature +  @param padding   Type of padding (LTC_LTC_PKCS_1_PSS or LTC_LTC_PKCS_1_V1_5) +  @param prng      An active PRNG state +  @param prng_idx  The index of the PRNG desired +  @param hash_idx  The index of the hash desired +  @param saltlen   The length of the salt desired (octets) +  @param key       The private RSA key to use +  @return CRYPT_OK if successful +*/ +int rsa_sign_hash_ex(const unsigned char *in,       unsigned long  inlen, +                           unsigned char *out,      unsigned long *outlen, +                           int            padding, +                           prng_state    *prng,     int            prng_idx, +                           int            hash_idx, unsigned long  saltlen, +                           rsa_key *key) +{ +   unsigned long modulus_bitlen, modulus_bytelen, x, y; +   int           err; + +   LTC_ARGCHK(in       != NULL); +   LTC_ARGCHK(out      != NULL); +   LTC_ARGCHK(outlen   != NULL); +   LTC_ARGCHK(key      != NULL); + +   /* valid padding? */ +   if ((padding != LTC_LTC_PKCS_1_V1_5) && (padding != LTC_LTC_PKCS_1_PSS)) { +     return CRYPT_PK_INVALID_PADDING; +   } + +   if (padding == LTC_LTC_PKCS_1_PSS) { +     /* valid prng and hash ? */ +     if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) { +        return err; +     } +     if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { +        return err; +     } +   } + +   /* get modulus len in bits */ +   modulus_bitlen = mp_count_bits((key->N)); + +  /* outlen must be at least the size of the modulus */ +  modulus_bytelen = mp_unsigned_bin_size((key->N)); +  if (modulus_bytelen > *outlen) { +     *outlen = modulus_bytelen; +     return CRYPT_BUFFER_OVERFLOW; +  } + +  if (padding == LTC_LTC_PKCS_1_PSS) { +    /* PSS pad the key */ +    x = *outlen; +    if ((err = pkcs_1_pss_encode(in, inlen, saltlen, prng, prng_idx, +                                 hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) { +       return err; +    } +  } else { +    /* LTC_PKCS #1 v1.5 pad the hash */ +    unsigned char *tmpin; +    ltc_asn1_list digestinfo[2], siginfo[2]; + +    /* not all hashes have OIDs... so sad */ +    if (hash_descriptor[hash_idx].OIDlen == 0) { +       return CRYPT_INVALID_ARG; +    } + +    /* construct the SEQUENCE  +      SEQUENCE { +         SEQUENCE {hashoid OID +                   blah    NULL +         } +         hash    OCTET STRING  +      } +   */ +    LTC_SET_ASN1(digestinfo, 0, LTC_ASN1_OBJECT_IDENTIFIER, hash_descriptor[hash_idx].OID, hash_descriptor[hash_idx].OIDlen); +    LTC_SET_ASN1(digestinfo, 1, LTC_ASN1_NULL,              NULL,                          0); +    LTC_SET_ASN1(siginfo,    0, LTC_ASN1_SEQUENCE,          digestinfo,                    2); +    LTC_SET_ASN1(siginfo,    1, LTC_ASN1_OCTET_STRING,      in,                            inlen); + +    /* allocate memory for the encoding */ +    y = mp_unsigned_bin_size(key->N); +    tmpin = XMALLOC(y); +    if (tmpin == NULL) { +       return CRYPT_MEM; +    } + +    if ((err = der_encode_sequence(siginfo, 2, tmpin, &y)) != CRYPT_OK) { +       XFREE(tmpin); +       return err; +    } + +    x = *outlen; +    if ((err = pkcs_1_v1_5_encode(tmpin, y, LTC_LTC_PKCS_1_EMSA, +                                  modulus_bitlen, NULL, 0, +                                  out, &x)) != CRYPT_OK) { +      XFREE(tmpin); +      return err; +    } +    XFREE(tmpin); +  } + +  /* RSA encode it */ +  return ltc_mp.rsa_me(out, x, out, outlen, PK_PRIVATE, key); +} + +#endif /* LTC_MRSA */ + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_sign_hash.c,v $ */ +/* $Revision: 1.11 $ */ +/* $Date: 2007/05/12 14:32:35 $ */ diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 63669e9..c70115c 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -1655,6 +1655,7 @@ static int CreateNewArchive_V2(TLogHelper * pLogger, const char * szPlainName, D      CreateInfo.dwStreamFlags  = STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE;      CreateInfo.dwFileFlags1   = (dwCreateFlags & MPQ_CREATE_LISTFILE)   ? MPQ_FILE_EXISTS : 0;      CreateInfo.dwFileFlags2   = (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? MPQ_FILE_EXISTS : 0; +    CreateInfo.dwFileFlags3   = (dwCreateFlags & MPQ_CREATE_SIGNATURE)  ? MPQ_FILE_EXISTS : 0;      CreateInfo.dwAttrFlags    = (dwCreateFlags & MPQ_CREATE_ATTRIBUTES) ? (MPQ_ATTRIBUTE_CRC32 | MPQ_ATTRIBUTE_FILETIME | MPQ_ATTRIBUTE_MD5) : 0;      CreateInfo.dwSectorSize   = (CreateInfo.dwMpqVersion >= MPQ_FORMAT_VERSION_3) ? 0x4000 : 0x1000;      CreateInfo.dwRawChunkSize = (CreateInfo.dwMpqVersion >= MPQ_FORMAT_VERSION_4) ? 0x4000 : 0; @@ -2594,6 +2595,114 @@ static int TestOpenArchive_VerifySignature(const char * szPlainName, const char      return nError;  } +static int TestOpenArchive_ModifySigned(const char * szPlainName, const char * szOriginalName) +{ +    TLogHelper Logger("ModifySignedTest", szPlainName); +    HANDLE hMpq = NULL; +    int nVerifyError; +    int nError = ERROR_SUCCESS; + +    // We need original name for the signature check +    nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szOriginalName, &hMpq); +    if(nError == ERROR_SUCCESS) +    { +        // Verify the weak signature +        Logger.PrintProgress("Verifying archive signature ..."); +        nVerifyError = SFileVerifyArchive(hMpq); + +        // Check the result signature +        if(nVerifyError != ERROR_WEAK_SIGNATURE_OK) +        { +            Logger.PrintMessage("Weak signature verification error"); +            nError = ERROR_FILE_CORRUPT; +        } +    } + +    // Add a file and verify the signature again +    if(nError == ERROR_SUCCESS) +    { +        // Verify any of the present signatures +        Logger.PrintProgress("Modifying signed archive ..."); +        nError = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is a file added to signed MPQ", 0, 0, true); +    } + +    // Verify the signature again +    if(nError == ERROR_SUCCESS) +    { +        // Verify the weak signature +        Logger.PrintProgress("Verifying archive signature ..."); +        nVerifyError = SFileVerifyArchive(hMpq); + +        // Check the result signature +        if(nVerifyError != ERROR_WEAK_SIGNATURE_OK) +        { +            Logger.PrintMessage("Weak signature verification error"); +            nError = ERROR_FILE_CORRUPT; +        } +    } + +    // Close the MPQ +    if(hMpq != NULL) +        SFileCloseArchive(hMpq); +    return nError; +} + +static int TestOpenArchive_SignExisting(const char * szPlainName) +{ +    TLogHelper Logger("SignExistingMpq", szPlainName); +    HANDLE hMpq = NULL; +    int nVerifyError; +    int nError = ERROR_SUCCESS; + +    // We need original name for the signature check +    nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szPlainName, &hMpq); +    if(nError == ERROR_SUCCESS) +    { +        // Verify the weak signature +        Logger.PrintProgress("Verifying archive signature ..."); +        nVerifyError = SFileVerifyArchive(hMpq); + +        // Check the result signature +        if(nVerifyError != ERROR_NO_SIGNATURE) +        { +            Logger.PrintMessage("There already is a signature in the MPQ"); +            nError = ERROR_FILE_CORRUPT; +        } +    } + +    // Add a file and verify the signature again +    if(nError == ERROR_SUCCESS) +    { +        // Verify any of the present signatures +        Logger.PrintProgress("Signing the MPQ ..."); +        if(!SFileSignArchive(hMpq, SIGNATURE_TYPE_WEAK)) +        { +            Logger.PrintMessage("Failed to create archive signature"); +            nError = ERROR_FILE_CORRUPT; +        } +    } + +    // Verify the signature again +    if(nError == ERROR_SUCCESS) +    { +        // Verify the weak signature +        Logger.PrintProgress("Verifying archive signature ..."); +        nVerifyError = SFileVerifyArchive(hMpq); + +        // Check the result signature +        if(nVerifyError != ERROR_WEAK_SIGNATURE_OK) +        { +            Logger.PrintMessage("Weak signature verification error"); +            nError = ERROR_FILE_CORRUPT; +        } +    } + +    // Close the MPQ +    if(hMpq != NULL) +        SFileCloseArchive(hMpq); +    return nError; +} +  // Open an empty archive (found in WoW cache - it's just a header)  static int TestOpenArchive_CraftedUserData(const char * szPlainName, const char * szCopyName)  { @@ -2895,7 +3004,7 @@ static int TestCreateArchive_EmptyMpq(const char * szPlainName, DWORD dwCreateFl  static int TestCreateArchive_TestGaps(const char * szPlainName)  { -    TLogHelper Logger("CreateMpqEditor", szPlainName); +    TLogHelper Logger("CreateGapsTest", szPlainName);      ULONGLONG ByteOffset1 = 0xFFFFFFFF;      ULONGLONG ByteOffset2 = 0xEEEEEEEE;      HANDLE hMpq = NULL; @@ -2966,6 +3075,60 @@ static int TestCreateArchive_TestGaps(const char * szPlainName)      return nError;  } +static int TestCreateArchive_Signed(const char * szPlainName, bool bSignAtCreate) +{ +    TLogHelper Logger("CreateSignedMpq", szPlainName); +    HANDLE hMpq = NULL; +    DWORD dwCreateFlags = MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_FORMAT_VERSION_1; +    DWORD dwSignatures = 0; +    DWORD nVerifyError = 0; +    int nError = ERROR_SUCCESS; + +    // Method 1: Create the archive as signed +    if(bSignAtCreate) +        dwCreateFlags |= MPQ_CREATE_SIGNATURE; + +    // Create new MPQ +    nError = CreateNewArchive_V2(&Logger, szPlainName, dwCreateFlags, 4000, &hMpq); +    if(nError == ERROR_SUCCESS) +    { +        // Add one file and flush the archive +        nError = AddFileToMpq(&Logger, hMpq, "AddedFile01.txt", "This is the file data.", MPQ_FILE_COMPRESS); +    } + +    // Sign the archive with weak signature +    if(nError == ERROR_SUCCESS) +    { +        if(!SFileSignArchive(hMpq, SIGNATURE_TYPE_WEAK)) +            nError = ERROR_SUCCESS; +    } + +    // Reopen the MPQ and add another file. +    // The new file must be added to the position of the (listfile) +    if(nError == ERROR_SUCCESS) +    { +        // Query the signature types +        Logger.PrintProgress("Retrieving signatures ..."); +        TestGetFileInfo(&Logger, hMpq, SFileMpqSignatures, &dwSignatures, sizeof(DWORD), NULL, true, ERROR_SUCCESS); + +        // Verify any of the present signatures +        Logger.PrintProgress("Verifying archive signature ..."); +        nVerifyError = SFileVerifyArchive(hMpq); + +        // Verify the result +        if((dwSignatures != SIGNATURE_TYPE_WEAK) && (nVerifyError != ERROR_WEAK_SIGNATURE_OK)) +        { +            Logger.PrintMessage("Weak signature verification error"); +            nError = ERROR_FILE_CORRUPT; +        } +    } + +    // Close the archive +    if(hMpq != NULL) +        SFileCloseArchive(hMpq); +    return nError; +} +  static int TestCreateArchive_MpqEditor(const char * szPlainName, const char * szFileName)  {      TLogHelper Logger("CreateMpqEditor", szPlainName); @@ -3866,6 +4029,21 @@ int main(int argc, char * argv[])      if(nError == ERROR_SUCCESS)          nError = TestCreateArchive_TestGaps("StormLibTest_GapsTest.mpq"); +    // Sign an existing non-signed archive +    if(nError == ERROR_SUCCESS) +        nError = TestOpenArchive_SignExisting("MPQ_1998_v1_StarDat.mpq"); + +    // Open a signed archive, add a file and verify the signature +    if(nError == ERROR_SUCCESS) +        nError = TestOpenArchive_ModifySigned("MPQ_1999_v1_WeakSignature.exe", "War2Patch_202.exe"); + +    // Create new archive and sign it +    if(nError == ERROR_SUCCESS) +        nError = TestCreateArchive_Signed("MPQ_1999_v1_WeakSigned1.mpq", true); + +    if(nError == ERROR_SUCCESS) +        nError = TestCreateArchive_Signed("MPQ_1999_v1_WeakSigned2.mpq", false); +      // Test creating of an archive the same way like MPQ Editor does      if(nError == ERROR_SUCCESS)          nError = TestCreateArchive_MpqEditor("StormLibTest_MpqEditorTest.mpq", "AddedFile.exe");  | 
