]> git.sesse.net Git - freerainbowtables/commitdiff
initial
authorunknown <mwj@.(none)>
Tue, 11 Aug 2009 19:03:05 +0000 (21:03 +0200)
committerunknown <mwj@.(none)>
Tue, 11 Aug 2009 19:03:05 +0000 (21:03 +0200)
504 files changed:
BOINC software/BOINC client apps/chain_checker/Debug/BuildLog.htm [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/ChainWalkContext.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/HashAlgorithm.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/HashRoutine.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/Public.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest.res [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.intermediate.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/des_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/des_setkey.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/ecb_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/md4.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/md5.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/mt.dep [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/vc90.idb [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Debug/vc90.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/ReadMe.txt [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/BuildLog.htm [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/ChainWalkContext.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/HashAlgorithm.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/HashRoutine.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/Public.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/chain_checker.exe.intermediate.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/chain_checker.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/des_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/des_setkey.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/ecb_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/md4.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/md5.obj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/mt.dep [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/vc90.idb [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/Release/vc90.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/boinc_lockfile [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.h [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.ncb [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.sln [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.suo [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj.mwj-PC.mwj.user [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/chains [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/charset.txt [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/result [new file with mode: 0644]
BOINC software/BOINC client apps/chain_checker/stderr.txt [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/BuildLog.htm [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/ChainWalkContext.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/HashAlgorithm.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/HashRoutine.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/Public.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.ilk [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/des_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/des_setkey.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest.res [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.intermediate.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.ilk [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/ecb_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/md4.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/md5.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/mt.dep [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/vc90.idb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Debug/vc90.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Makefile [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/BuildLog.htm [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkContext.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkSet.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/HashAlgorithm.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/HashRoutine.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/Public.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/des_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/des_setkey.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe.intermediate.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.17_windows_intelx86.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.18_windows_intelx86.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.19_windows_intelx86.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/ecb_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/md4.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/md5.obj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/mt.dep [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rcracki.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rcracki.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rsearch.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rsearch.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.exe [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/sched_util.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/validate_util.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/vc90.idb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/Release/vc90.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/boinc_lockfile [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/charset.txt [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.ncb [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.sln [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.suo [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj.MWJ-PC.mwj.user [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/result [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/stderr.txt [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkContext.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkContext.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkSet.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkSet.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/HashAlgorithm.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/HashAlgorithm.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/HashRoutine.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/HashRoutine.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/Public.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/Public.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/RainbowTableGenerator.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/RainbowTableGenerator.h [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/md5.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/distrrtgen/tmp/md5.h [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/BuildLog.htm [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkContext.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkSet.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/HashAlgorithm.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/HashRoutine.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/Public.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/des_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/des_setkey.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/ecb_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.exe.intermediate.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/md4.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/md5.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/mt.dep [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/vc90.idb [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Debug/vc90.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/BuildLog.htm [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/ChainWalkContext.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/ChainWalkSet.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/HashAlgorithm.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/HashRoutine.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/Public.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/des_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/des_setkey.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/ecb_enc.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/index_calculator.exe.intermediate.manifest [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/index_calculator.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/md4.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/md5.obj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/mt.dep [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/vc90.idb [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/Release/vc90.pdb [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/boinc_finish_called [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/boinc_lockfile [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/chains [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/charset.txt [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.cpp [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.h [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.ncb [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.suo [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj.MWJ-PC.mwj.user [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/init_data.xml [new file with mode: 0644]
BOINC software/BOINC client apps/index_calculator/stderr.txt [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_assimilator/Makefile [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_assimilator/assimilate_handler.h [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_assimilator/assimilator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_assimilator/chain_checker_assimilator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_assimilator/validate_util.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_workgenerator/Makefile [new file with mode: 0644]
BOINC software/BOINC server apps/chain_checker_workgenerator/chain_checker_workgenerator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/ChainWalkContext.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/ChainWalkContext.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/HashAlgorithm.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/HashAlgorithm.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/HashRoutine.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/HashRoutine.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/Makefile [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/MemoryPool.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/MemoryPool.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/Public.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/Public.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/charset.txt [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/des.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/des_enc.c [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/des_locl.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/des_setkey.c [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/ecb_enc.c [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/md4.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/md4.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/md5.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/md5.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/part_validator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/part_validator.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/podd.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/sk.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/spr.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/validate_util.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/validate_util.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/validate_util2.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/validate_util2.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/validator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_validator/validator.h [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_workgenerator/Makefile [new file with mode: 0644]
BOINC software/BOINC server apps/distrrtgen_workgenerator/distrrtgen_workgenerator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_assimilator/Makefile [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_assimilator/assimilate_handler.h [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_assimilator/assimilator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_assimilator/index_calculator_assimilator.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_assimilator/validate_util.cpp [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_workgenerator/Makefile [new file with mode: 0644]
BOINC software/BOINC server apps/index_calculator_workgenerator/index_calculator_workgenerator.cpp [new file with mode: 0644]
Client Applications/converti2/Debug/BuildLog.htm [new file with mode: 0644]
Client Applications/converti2/Debug/MemoryPool.obj [new file with mode: 0644]
Client Applications/converti2/Debug/Public.obj [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.exe [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.exe.embed.manifest [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.exe.embed.manifest.res [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.ilk [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.obj [new file with mode: 0644]
Client Applications/converti2/Debug/converti2.pdb [new file with mode: 0644]
Client Applications/converti2/Debug/convertrti2.exe [new file with mode: 0644]
Client Applications/converti2/Debug/convertrti2.exe.embed.manifest [new file with mode: 0644]
Client Applications/converti2/Debug/convertrti2.exe.embed.manifest.res [new file with mode: 0644]
Client Applications/converti2/Debug/convertrti2.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/converti2/Debug/convertrti2.ilk [new file with mode: 0644]
Client Applications/converti2/Debug/convertrti2.pdb [new file with mode: 0644]
Client Applications/converti2/Debug/mt.dep [new file with mode: 0644]
Client Applications/converti2/Debug/vc90.idb [new file with mode: 0644]
Client Applications/converti2/Debug/vc90.pdb [new file with mode: 0644]
Client Applications/converti2/Public.cpp [new file with mode: 0644]
Client Applications/converti2/Public.h [new file with mode: 0644]
Client Applications/converti2/Release/BuildLog.htm [new file with mode: 0644]
Client Applications/converti2/Release/MemoryPool.obj [new file with mode: 0644]
Client Applications/converti2/Release/Public.obj [new file with mode: 0644]
Client Applications/converti2/Release/converti2.exe [new file with mode: 0644]
Client Applications/converti2/Release/converti2.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/converti2/Release/converti2.obj [new file with mode: 0644]
Client Applications/converti2/Release/converti2.pdb [new file with mode: 0644]
Client Applications/converti2/Release/convertrti2.exe [new file with mode: 0644]
Client Applications/converti2/Release/convertrti2.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/converti2/Release/convertrti2.pdb [new file with mode: 0644]
Client Applications/converti2/Release/mt.dep [new file with mode: 0644]
Client Applications/converti2/Release/vc90.idb [new file with mode: 0644]
Client Applications/converti2/Release/vc90.pdb [new file with mode: 0644]
Client Applications/converti2/converti2.cpp [new file with mode: 0644]
Client Applications/converti2/converti2.ncb [new file with mode: 0644]
Client Applications/converti2/converti2.sln [new file with mode: 0644]
Client Applications/converti2/converti2.suo [new file with mode: 0644]
Client Applications/converti2/converti2.vcproj [new file with mode: 0644]
Client Applications/converti2/converti2.vcproj.W-L-10643.Administrator.user [new file with mode: 0644]
Client Applications/converti2/converti2.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
Client Applications/converti2/converti2.vcproj.mwj-PC.mwj.user [new file with mode: 0644]
Client Applications/converti2/makefile [new file with mode: 0644]
Client Applications/converti2/md5_loweralpha-numeric-space#1-8_0_10000x67108864_distrrtgen[p][i]_00.rti2 [new file with mode: 0644]
Client Applications/rcracki/CrackEngine.cpp [new file with mode: 0644]
Client Applications/rcracki/CrackEngine.h [new file with mode: 0644]
Client Applications/rcracki/Debug/BaseRTReader.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/BuildLog.htm [new file with mode: 0644]
Client Applications/rcracki/Debug/ChainWalkContext.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/ChainWalkSet.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/CrackEngine.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/HashAlgorithm.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/HashRoutine.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/HashSet.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/MemoryPool.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/Public.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/RTI2Reader.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/RTIReader.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/RTReader.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/RainbowCrack.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/des_enc.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/des_setkey.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/ecb_enc.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/md4.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/md5.obj [new file with mode: 0644]
Client Applications/rcracki/Debug/mt.dep [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.exe [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.exe.embed.manifest [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.exe.embed.manifest.res [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.exp [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.ilk [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.lib [new file with mode: 0644]
Client Applications/rcracki/Debug/rcracki.pdb [new file with mode: 0644]
Client Applications/rcracki/Debug/vc90.idb [new file with mode: 0644]
Client Applications/rcracki/Debug/vc90.pdb [new file with mode: 0644]
Client Applications/rcracki/HashSet.cpp [new file with mode: 0644]
Client Applications/rcracki/HashSet.h [new file with mode: 0644]
Client Applications/rcracki/RainbowCrack.cpp [new file with mode: 0644]
Client Applications/rcracki/Release/BaseRTReader.obj [new file with mode: 0644]
Client Applications/rcracki/Release/BuildLog.htm [new file with mode: 0644]
Client Applications/rcracki/Release/ChainWalkContext.obj [new file with mode: 0644]
Client Applications/rcracki/Release/ChainWalkSet.obj [new file with mode: 0644]
Client Applications/rcracki/Release/CrackEngine.obj [new file with mode: 0644]
Client Applications/rcracki/Release/HashAlgorithm.obj [new file with mode: 0644]
Client Applications/rcracki/Release/HashRoutine.obj [new file with mode: 0644]
Client Applications/rcracki/Release/HashSet.obj [new file with mode: 0644]
Client Applications/rcracki/Release/MemoryPool.obj [new file with mode: 0644]
Client Applications/rcracki/Release/Public.obj [new file with mode: 0644]
Client Applications/rcracki/Release/RTI2Reader.obj [new file with mode: 0644]
Client Applications/rcracki/Release/RTIReader.obj [new file with mode: 0644]
Client Applications/rcracki/Release/RTReader.obj [new file with mode: 0644]
Client Applications/rcracki/Release/RainbowCrack.obj [new file with mode: 0644]
Client Applications/rcracki/Release/charset.txt [new file with mode: 0644]
Client Applications/rcracki/Release/des_enc.obj [new file with mode: 0644]
Client Applications/rcracki/Release/des_setkey.obj [new file with mode: 0644]
Client Applications/rcracki/Release/ecb_enc.obj [new file with mode: 0644]
Client Applications/rcracki/Release/md4.obj [new file with mode: 0644]
Client Applications/rcracki/Release/md5.obj [new file with mode: 0644]
Client Applications/rcracki/Release/mt.dep [new file with mode: 0644]
Client Applications/rcracki/Release/rcracki.exe [new file with mode: 0644]
Client Applications/rcracki/Release/rcracki.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/rcracki/Release/rcracki.pdb [new file with mode: 0644]
Client Applications/rcracki/Release/vc90.idb [new file with mode: 0644]
Client Applications/rcracki/Release/vc90.pdb [new file with mode: 0644]
Client Applications/rcracki/charset.txt [new file with mode: 0644]
Client Applications/rcracki/rcracki.ncb [new file with mode: 0644]
Client Applications/rcracki/rcracki.sln [new file with mode: 0644]
Client Applications/rcracki/rcracki.suo [new file with mode: 0644]
Client Applications/rcracki/rcracki.vcproj [new file with mode: 0644]
Client Applications/rcracki/rcracki.vcproj.W-L-10643.Administrator.user [new file with mode: 0644]
Client Applications/rcracki/rcracki.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
Client Applications/rcracki/rcracki.vcproj.mwj-PC.mwj.user [new file with mode: 0644]
Client Applications/rcracki/tmp/MemoryPool.cpp [new file with mode: 0644]
Client Applications/rcracki/tmp/MemoryPool.h [new file with mode: 0644]
Client Applications/rcracki/tmp/Public.cpp [new file with mode: 0644]
Client Applications/rcracki/tmp/Public.h [new file with mode: 0644]
Client Applications/rti2rto/Debug/BaseRTReader.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/BuildLog.htm [new file with mode: 0644]
Client Applications/rti2rto/Debug/MemoryPool.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/Public.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/RTI2Reader.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/RTIReader.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/RTReader.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/mt.dep [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.exe [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest.res [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.ilk [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.obj [new file with mode: 0644]
Client Applications/rti2rto/Debug/rti2rto.pdb [new file with mode: 0644]
Client Applications/rti2rto/Debug/vc90.idb [new file with mode: 0644]
Client Applications/rti2rto/Debug/vc90.pdb [new file with mode: 0644]
Client Applications/rti2rto/Release/BaseRTReader.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/BuildLog.htm [new file with mode: 0644]
Client Applications/rti2rto/Release/MemoryPool.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/Public.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/RTI2Reader.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/RTIReader.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/RTReader.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/mt.dep [new file with mode: 0644]
Client Applications/rti2rto/Release/rti2rto.exe.intermediate.manifest [new file with mode: 0644]
Client Applications/rti2rto/Release/rti2rto.obj [new file with mode: 0644]
Client Applications/rti2rto/Release/vc90.idb [new file with mode: 0644]
Client Applications/rti2rto/Release/vc90.pdb [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.cpp [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.ncb [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.sln [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.suo [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.vcproj [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.vcproj.MWJ-PC.mwj.user [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.vcproj.W-L-10643.Administrator.user [new file with mode: 0644]
Client Applications/rti2rto/rti2rto.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
Common/rt api/BaseRTReader.cpp [new file with mode: 0644]
Common/rt api/BaseRTReader.h [new file with mode: 0644]
Common/rt api/ChainWalkContext.cpp [new file with mode: 0644]
Common/rt api/ChainWalkContext.h [new file with mode: 0644]
Common/rt api/ChainWalkSet.cpp [new file with mode: 0644]
Common/rt api/ChainWalkSet.h [new file with mode: 0644]
Common/rt api/HashAlgorithm.cpp [new file with mode: 0644]
Common/rt api/HashAlgorithm.h [new file with mode: 0644]
Common/rt api/HashRoutine.cpp [new file with mode: 0644]
Common/rt api/HashRoutine.h [new file with mode: 0644]
Common/rt api/MemoryPool.cpp [new file with mode: 0644]
Common/rt api/MemoryPool.h [new file with mode: 0644]
Common/rt api/Public.cpp [new file with mode: 0644]
Common/rt api/Public.h [new file with mode: 0644]
Common/rt api/RTI2Reader.cpp [new file with mode: 0644]
Common/rt api/RTI2Reader.h [new file with mode: 0644]
Common/rt api/RTIReader.cpp [new file with mode: 0644]
Common/rt api/RTIReader.h [new file with mode: 0644]
Common/rt api/RTReader.cpp [new file with mode: 0644]
Common/rt api/RTReader.h [new file with mode: 0644]
Common/rt api/des.h [new file with mode: 0644]
Common/rt api/des_enc.c [new file with mode: 0644]
Common/rt api/des_locl.h [new file with mode: 0644]
Common/rt api/des_setkey.c [new file with mode: 0644]
Common/rt api/ecb_enc.c [new file with mode: 0644]
Common/rt api/md4.cpp [new file with mode: 0644]
Common/rt api/md4.h [new file with mode: 0644]
Common/rt api/md5.cpp [new file with mode: 0644]
Common/rt api/md5.h [new file with mode: 0644]
Common/rt api/podd.h [new file with mode: 0644]
Common/rt api/sk.h [new file with mode: 0644]
Common/rt api/spr.h [new file with mode: 0644]
Common/rt api/tmp/HashAlgorithm.cpp [new file with mode: 0644]
Common/rt api/tmp/HashAlgorithm.h [new file with mode: 0644]
Common/rt api/tmp/HashRoutine.cpp [new file with mode: 0644]
Common/rt api/tmp/HashRoutine.h [new file with mode: 0644]
Server Applications/rsearchi/ChainWalkContext.cpp [new file with mode: 0644]
Server Applications/rsearchi/ChainWalkContext.h [new file with mode: 0644]
Server Applications/rsearchi/ChainWalkSet.cpp [new file with mode: 0644]
Server Applications/rsearchi/ChainWalkSet.h [new file with mode: 0644]
Server Applications/rsearchi/CrackEngine.cpp [new file with mode: 0644]
Server Applications/rsearchi/CrackEngine.h [new file with mode: 0644]
Server Applications/rsearchi/Database.h [new file with mode: 0644]
Server Applications/rsearchi/Exception.cpp [new file with mode: 0644]
Server Applications/rsearchi/Exception.h [new file with mode: 0644]
Server Applications/rsearchi/HashAlgorithm.cpp [new file with mode: 0644]
Server Applications/rsearchi/HashAlgorithm.h [new file with mode: 0644]
Server Applications/rsearchi/HashRoutine.cpp [new file with mode: 0644]
Server Applications/rsearchi/HashRoutine.h [new file with mode: 0644]
Server Applications/rsearchi/HashSet.cpp [new file with mode: 0644]
Server Applications/rsearchi/HashSet.h [new file with mode: 0644]
Server Applications/rsearchi/Makefile [new file with mode: 0644]
Server Applications/rsearchi/MemoryPool.cpp [new file with mode: 0644]
Server Applications/rsearchi/MemoryPool.h [new file with mode: 0644]
Server Applications/rsearchi/MySQL.cpp [new file with mode: 0644]
Server Applications/rsearchi/MySQL.h [new file with mode: 0644]
Server Applications/rsearchi/Public.cpp [new file with mode: 0644]
Server Applications/rsearchi/Public.h [new file with mode: 0644]
Server Applications/rsearchi/RainbowTableSort.cpp [new file with mode: 0644]
Server Applications/rsearchi/config.h [new file with mode: 0644]
Server Applications/rsearchi/rsearch [new file with mode: 0644]
Server Applications/rsearchi/rsearch.cpp [new file with mode: 0644]
Server Applications/rsearchi/rsearchi [new file with mode: 0644]
Server Applications/rsearchi/stdafx.cpp [new file with mode: 0644]
Server Applications/rsearchi/stdafx.h [new file with mode: 0644]
Server Applications/rtperfecter0.0/RTCommon.h [new file with mode: 0644]
Server Applications/rtperfecter0.0/RTRead.cpp [new file with mode: 0644]
Server Applications/rtperfecter0.0/RTRead.h [new file with mode: 0644]
Server Applications/rtperfecter0.0/RTWrite.cpp [new file with mode: 0644]
Server Applications/rtperfecter0.0/RTWrite.h [new file with mode: 0644]
Server Applications/rtperfecter0.0/main.cpp [new file with mode: 0644]
Server Applications/rtperfecter0.0/makefile [new file with mode: 0644]
Server Applications/rtperfecter0.0/rtperfecter0 [new file with mode: 0644]
Server Applications/rtperfecter0.0/rtperfecter0.0.7z [new file with mode: 0644]
Server Applications/rtperfecter0.1/RTCommon.h [new file with mode: 0644]
Server Applications/rtperfecter0.1/RTRead.cpp [new file with mode: 0644]
Server Applications/rtperfecter0.1/RTRead.h [new file with mode: 0644]
Server Applications/rtperfecter0.1/RTWrite.cpp [new file with mode: 0644]
Server Applications/rtperfecter0.1/RTWrite.h [new file with mode: 0644]
Server Applications/rtperfecter0.1/main.cpp [new file with mode: 0644]
Server Applications/rtperfecter0.1/makefile [new file with mode: 0644]
Server Applications/rtperfecter0.1/rtperfecter1 [new file with mode: 0644]
Server Applications/rtperfectp/Debug/BuildLog.htm [new file with mode: 0644]
Server Applications/rtperfectp/Debug/RTRead.obj [new file with mode: 0644]
Server Applications/rtperfectp/Debug/RTWrite.obj [new file with mode: 0644]
Server Applications/rtperfectp/Debug/main.obj [new file with mode: 0644]
Server Applications/rtperfectp/Debug/mt.dep [new file with mode: 0644]
Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest [new file with mode: 0644]
Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest.res [new file with mode: 0644]
Server Applications/rtperfectp/Debug/rtperfectp.exe.intermediate.manifest [new file with mode: 0644]
Server Applications/rtperfectp/Debug/vc90.idb [new file with mode: 0644]
Server Applications/rtperfectp/Debug/vc90.pdb [new file with mode: 0644]
Server Applications/rtperfectp/RTCommon.h [new file with mode: 0644]
Server Applications/rtperfectp/RTRead.cpp [new file with mode: 0644]
Server Applications/rtperfectp/RTRead.h [new file with mode: 0644]
Server Applications/rtperfectp/RTWrite.cpp [new file with mode: 0644]
Server Applications/rtperfectp/RTWrite.h [new file with mode: 0644]
Server Applications/rtperfectp/Release/BuildLog.htm [new file with mode: 0644]
Server Applications/rtperfectp/Release/RTRead.obj [new file with mode: 0644]
Server Applications/rtperfectp/Release/RTWrite.obj [new file with mode: 0644]
Server Applications/rtperfectp/Release/main.obj [new file with mode: 0644]
Server Applications/rtperfectp/Release/mt.dep [new file with mode: 0644]
Server Applications/rtperfectp/Release/rtperfectp.exe.intermediate.manifest [new file with mode: 0644]
Server Applications/rtperfectp/Release/vc90.idb [new file with mode: 0644]
Server Applications/rtperfectp/Release/vc90.pdb [new file with mode: 0644]
Server Applications/rtperfectp/dirent.h [new file with mode: 0644]
Server Applications/rtperfectp/main.cpp [new file with mode: 0644]
Server Applications/rtperfectp/rtperfectp.vcproj [new file with mode: 0644]
Server Applications/rtperfectp/rtperfectp.vcproj.MWJ-PC.mwj.user [new file with mode: 0644]
Server Applications/rtperfectp/rtperfectp.vcproj.W-L-MWJ.Administrator.user [new file with mode: 0644]
Server Applications/rtperfectp/whatitis.txt [new file with mode: 0644]

diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/BuildLog.htm b/BOINC software/BOINC client apps/chain_checker/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..989a24a
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/BuildLog.htm differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/ChainWalkContext.obj b/BOINC software/BOINC client apps/chain_checker/Debug/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..bf1bb3f
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/ChainWalkContext.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/HashAlgorithm.obj b/BOINC software/BOINC client apps/chain_checker/Debug/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..4dcae37
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/HashAlgorithm.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/HashRoutine.obj b/BOINC software/BOINC client apps/chain_checker/Debug/HashRoutine.obj
new file mode 100644 (file)
index 0000000..f79446c
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/HashRoutine.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/Public.obj b/BOINC software/BOINC client apps/chain_checker/Debug/Public.obj
new file mode 100644 (file)
index 0000000..a0c9d44
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/Public.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest b/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest
new file mode 100644 (file)
index 0000000..11bb704
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
\ No newline at end of file
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest.res b/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..9c8df0e
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.embed.manifest.res differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.intermediate.manifest b/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.obj b/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.obj
new file mode 100644 (file)
index 0000000..723e15c
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/chain_checker.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/des_enc.obj b/BOINC software/BOINC client apps/chain_checker/Debug/des_enc.obj
new file mode 100644 (file)
index 0000000..856aea8
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/des_enc.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/des_setkey.obj b/BOINC software/BOINC client apps/chain_checker/Debug/des_setkey.obj
new file mode 100644 (file)
index 0000000..3a2afa9
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/des_setkey.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/ecb_enc.obj b/BOINC software/BOINC client apps/chain_checker/Debug/ecb_enc.obj
new file mode 100644 (file)
index 0000000..a83f885
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/ecb_enc.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/md4.obj b/BOINC software/BOINC client apps/chain_checker/Debug/md4.obj
new file mode 100644 (file)
index 0000000..dd3abc7
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/md4.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/md5.obj b/BOINC software/BOINC client apps/chain_checker/Debug/md5.obj
new file mode 100644 (file)
index 0000000..d09f579
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/md5.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/mt.dep b/BOINC software/BOINC client apps/chain_checker/Debug/mt.dep
new file mode 100644 (file)
index 0000000..7da780d
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 21:46:51,37 on 28-11-2008 
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/vc90.idb b/BOINC software/BOINC client apps/chain_checker/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..f76af2a
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/vc90.idb differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Debug/vc90.pdb b/BOINC software/BOINC client apps/chain_checker/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..abb6e5e
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Debug/vc90.pdb differ
diff --git a/BOINC software/BOINC client apps/chain_checker/ReadMe.txt b/BOINC software/BOINC client apps/chain_checker/ReadMe.txt
new file mode 100644 (file)
index 0000000..4a7b573
--- /dev/null
@@ -0,0 +1,33 @@
+========================================================================
+    CONSOLE APPLICATION : chain_checker Project Overview
+========================================================================
+
+AppWizard has created this chain_checker application for you.
+
+This file contains a summary of what you will find in each of the files that
+make up your chain_checker application.
+
+
+chain_checker.vcproj
+    This is the main project file for VC++ projects generated using an Application Wizard.
+    It contains information about the version of Visual C++ that generated the file, and
+    information about the platforms, configurations, and project features selected with the
+    Application Wizard.
+
+chain_checker.cpp
+    This is the main application source file.
+
+/////////////////////////////////////////////////////////////////////////////
+Other standard files:
+
+StdAfx.h, StdAfx.cpp
+    These files are used to build a precompiled header (PCH) file
+    named chain_checker.pch and a precompiled types file named StdAfx.obj.
+
+/////////////////////////////////////////////////////////////////////////////
+Other notes:
+
+AppWizard uses "TODO:" comments to indicate parts of the source code you
+should add to or customize.
+
+/////////////////////////////////////////////////////////////////////////////
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/BuildLog.htm b/BOINC software/BOINC client apps/chain_checker/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..3240473
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/BuildLog.htm differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/ChainWalkContext.obj b/BOINC software/BOINC client apps/chain_checker/Release/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..603b434
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/ChainWalkContext.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/HashAlgorithm.obj b/BOINC software/BOINC client apps/chain_checker/Release/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..63fdbe0
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/HashAlgorithm.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/HashRoutine.obj b/BOINC software/BOINC client apps/chain_checker/Release/HashRoutine.obj
new file mode 100644 (file)
index 0000000..6483539
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/HashRoutine.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/Public.obj b/BOINC software/BOINC client apps/chain_checker/Release/Public.obj
new file mode 100644 (file)
index 0000000..f91d39a
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/Public.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/chain_checker.exe.intermediate.manifest b/BOINC software/BOINC client apps/chain_checker/Release/chain_checker.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/chain_checker.obj b/BOINC software/BOINC client apps/chain_checker/Release/chain_checker.obj
new file mode 100644 (file)
index 0000000..c4ef26f
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/chain_checker.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/des_enc.obj b/BOINC software/BOINC client apps/chain_checker/Release/des_enc.obj
new file mode 100644 (file)
index 0000000..eaf9b3a
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/des_enc.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/des_setkey.obj b/BOINC software/BOINC client apps/chain_checker/Release/des_setkey.obj
new file mode 100644 (file)
index 0000000..c3b113d
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/des_setkey.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/ecb_enc.obj b/BOINC software/BOINC client apps/chain_checker/Release/ecb_enc.obj
new file mode 100644 (file)
index 0000000..c30e9fc
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/ecb_enc.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/md4.obj b/BOINC software/BOINC client apps/chain_checker/Release/md4.obj
new file mode 100644 (file)
index 0000000..d49f3cf
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/md4.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/md5.obj b/BOINC software/BOINC client apps/chain_checker/Release/md5.obj
new file mode 100644 (file)
index 0000000..91a8b6b
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/md5.obj differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/mt.dep b/BOINC software/BOINC client apps/chain_checker/Release/mt.dep
new file mode 100644 (file)
index 0000000..331b271
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 23:22:47,51 on 28-11-2008 
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/vc90.idb b/BOINC software/BOINC client apps/chain_checker/Release/vc90.idb
new file mode 100644 (file)
index 0000000..0f4b159
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/vc90.idb differ
diff --git a/BOINC software/BOINC client apps/chain_checker/Release/vc90.pdb b/BOINC software/BOINC client apps/chain_checker/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..9f4325a
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/Release/vc90.pdb differ
diff --git a/BOINC software/BOINC client apps/chain_checker/boinc_lockfile b/BOINC software/BOINC client apps/chain_checker/boinc_lockfile
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.cpp b/BOINC software/BOINC client apps/chain_checker/chain_checker.cpp
new file mode 100644 (file)
index 0000000..041ff6e
--- /dev/null
@@ -0,0 +1,188 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Modified by Martin Westergaard for the chain check usage
+#ifdef _WIN32
+#include "boinc_win.h"
+#else
+#include "config.h"
+#include <cstdio>
+#include <cctype>
+#include <ctime>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+#include <unistd.h>
+#endif
+
+#include <string>
+#include <fstream>
+
+#include "str_util.h"
+#include "util.h"
+#include "filesys.h"
+#include "boinc_api.h"
+#include "Public.h"
+// Rainbowcrack code
+#include "ChainWalkContext.h"
+#include "chain_checker.h"
+
+typedef unsigned int uint32;
+
+
+using std::string;
+
+int main(int argc, char **argv) {
+    int retval;
+    char output_path[512], chkpt_path[512];
+       string sHashRoutineName, sCharsetName, sHash;
+       uint32 nPlainLenMin, nPlainLenMax, nRainbowTableIndex;
+    FILE* state, *infile, *outfile;    
+    retval = boinc_init();
+    if (retval) {
+        fprintf(stderr, "boinc_init returned %d\n", retval);
+        exit(retval);
+    }
+       
+       if(argc < 7)
+       {
+               std::cerr << "Not enough parameters";
+               return -1;
+       }
+
+       // Initialize the args
+       sHashRoutineName = argv[1];
+       sCharsetName = argv[2];
+       nPlainLenMin = atoi(argv[3]);
+       nPlainLenMax = atoi(argv[4]);
+       nRainbowTableIndex = atoi(argv[5]);
+       sHash = argv[6];
+
+
+       // Setup the ChainWalkContext
+       if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
+       {
+               std::cerr << "hash routine " << sHashRoutineName << " not supported" << std::endl;
+               return 1;
+       }
+
+       if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+       {       
+               std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
+               return 2;
+       }
+       
+       if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
+               return 3;
+       }
+
+       
+       // Open the file containing the chains we have to check.
+    boinc_resolve_filename("chains", output_path, sizeof(output_path));
+       infile = boinc_fopen(output_path, "rb");    
+       if (infile == NULL)
+       {
+               std::cerr << "failed to open " << output_path << std::endl;
+               return 4;
+       }
+
+       // Open the resulting file. This will *maybe* contain the password (if found)
+       boinc_resolve_filename("result", output_path, sizeof(output_path));
+       outfile = boinc_fopen(output_path, "wb");       
+       if (outfile == NULL)
+       {
+               std::cerr << "failed to create " << output_path << std::endl;
+               return 5;
+       }
+
+       // Read the chains from the input file
+       int len = GetFileLen(infile); 
+       int numchains = len / 12;  // Each chain is 12 bytes. 8 bytes startpoint and 4 bytes for the guessed position
+       fseek(infile, 0, SEEK_SET);
+       ChainCheckChain *pChain = new ChainCheckChain[numchains];
+       int totalread = 0, read;
+       for(int i = 0; i < numchains; i++)
+       {
+               int read = fread(&pChain[i].nIndexS, sizeof(pChain[i].nIndexS), 1, infile);
+               if(read != 1)
+               {
+                       std::cerr << "Error reading chaincheck file" << std::endl;
+                       return 6;
+               }
+               read = fread(&pChain[i].nGuessedPos, sizeof(pChain[i].nGuessedPos), 1, infile);
+               if(read != 1)
+               {
+                       std::cerr << "Error reading chaincheck file" << std::endl;
+                       return 7;
+               }
+
+       }
+       fclose(infile);
+
+
+       // Start checking the chains for false alarms
+       CChainWalkContext cwc;  
+       int found = 0;
+       for(int i = 0; i < numchains; i++)
+       {
+               cwc.SetIndex(pChain[i].nIndexS);        
+               int nPos;
+               for (nPos = 0; nPos < pChain[i].nGuessedPos; nPos++)
+               {
+                       cwc.IndexToPlain();
+                       cwc.PlainToHash();
+                       cwc.HashToIndex(nPos);
+               }
+               cwc.IndexToPlain();
+               cwc.PlainToHash();
+               std::string sHashme = cwc.GetHash();
+               // Check if this is a matching chain
+               if(sHashme.compare(sHash) == 0)
+               {
+                       fwrite(cwc.GetPlain().c_str(), 1, cwc.GetPlain().length(), outfile);
+                       std::cout << "Password is " << cwc.GetPlain() << std::endl;
+                       found = 1;
+                       break; // Password is found. Lets break out.
+               }
+               // This chain didn't contain the password, so we update the progress
+               boinc_fraction_done((double)i / (double)numchains); 
+               
+       }
+       if(found == 0)
+               fwrite("0x00", 4, 1, outfile);
+       // Last step: Clean up
+       fclose(outfile);    
+    boinc_fraction_done(1);
+    boinc_finish(0);
+}
+
+#ifdef _WIN32
+int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
+    LPSTR command_line;
+    char* argv[100];
+    int argc;
+
+    command_line = GetCommandLine();
+    argc = parse_command_line( command_line, argv );
+    return main(argc, argv);
+}
+#endif
+
+const char *BOINC_RCSID_33ac47a071 = "$Id: chain_checker.cpp 2008-11-28 Martin Westergaard $";
+
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.h b/BOINC software/BOINC client apps/chain_checker/chain_checker.h
new file mode 100644 (file)
index 0000000..d385ee6
--- /dev/null
@@ -0,0 +1,12 @@
+#include "boinc_api.h"
+
+struct UC_SHMEM {
+    double update_time;
+    double fraction_done;
+    double cpu_time;
+    BOINC_STATUS status;
+    int countdown;
+        // graphics app sets this to 5 repeatedly,
+        // main program decrements it once/sec.
+        // If it's zero, don't bother updating shmem
+};
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.ncb b/BOINC software/BOINC client apps/chain_checker/chain_checker.ncb
new file mode 100644 (file)
index 0000000..732b725
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/chain_checker.ncb differ
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.sln b/BOINC software/BOINC client apps/chain_checker/chain_checker.sln
new file mode 100644 (file)
index 0000000..efe9687
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chain_checker", "chain_checker.vcproj", "{74C09EAC-2EA2-4548-9B61-0FEE56147DFE}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Debug|Win32.ActiveCfg = Debug|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Debug|Win32.Build.0 = Debug|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Release|Win32.ActiveCfg = Release|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.suo b/BOINC software/BOINC client apps/chain_checker/chain_checker.suo
new file mode 100644 (file)
index 0000000..d24e681
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/chain_checker.suo differ
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj b/BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj
new file mode 100644 (file)
index 0000000..423716c
--- /dev/null
@@ -0,0 +1,294 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="chain_checker"
+       ProjectGUID="{74C09EAC-2EA2-4548-9B61-0FEE56147DFE}"
+       RootNamespace="chain_checker"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="196613"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="2"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               WholeProgramOptimization="false"
+                               AdditionalIncludeDirectories="/boinc/lib;/boinc/api;&quot;/boinc/zip&quot;;&quot;/boinc/client/win&quot;;&quot;/boinc/&quot;;../distrrtgen;../../rt api"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_MT;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="1"
+                               EnableEnhancedInstructionSet="2"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="libcmtd.lib libcpmtd.lib kernel32.lib user32.lib ole32.lib delayimp.lib ..\lib_debug\libboinc_staticcrt.lib ..\lib_debug\libboincapi_staticcrt.lib c:/openssl/lib/libeay32.lib"
+                               LinkIncremental="2"
+                               IgnoreAllDefaultLibraries="true"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="2"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               InlineFunctionExpansion="2"
+                               EnableIntrinsicFunctions="true"
+                               FavorSizeOrSpeed="1"
+                               AdditionalIncludeDirectories="/boinc/lib;/boinc/api;&quot;/boinc/zip&quot;;&quot;/boinc/client/win&quot;;&quot;/boinc/&quot;;../distrrtgen;../../rt api"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_MT"
+                               RuntimeLibrary="0"
+                               EnableFunctionLevelLinking="false"
+                               EnableEnhancedInstructionSet="2"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="false"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="odbc32.lib odbccp32.lib libcmt.lib libcpmt.lib ..\lib_release\libboinc_staticcrt.lib ..\lib_release\libboincapi_staticcrt.lib c:/openssl/lib/libeay32.lib"
+                               LinkIncremental="1"
+                               IgnoreAllDefaultLibraries="true"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               RandomizedBaseAddress="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath=".\chain_checker.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_setkey.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ecb_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\Public.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath=".\chain_checker.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_locl.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\podd.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\Public.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\sk.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\spr.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+               <File
+                       RelativePath=".\ReadMe.txt"
+                       >
+               </File>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj.W-L-MWJ.Administrator.user b/BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..34fec73
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="md5 hybrid(loweralpha#6-6,numeric#1-3) 0 0 1 76EDAA7204D558565A7183AA83D76C91"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj.mwj-PC.mwj.user b/BOINC software/BOINC client apps/chain_checker/chain_checker.vcproj.mwj-PC.mwj.user
new file mode 100644 (file)
index 0000000..15b19f6
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/BOINC software/BOINC client apps/chain_checker/chains b/BOINC software/BOINC client apps/chain_checker/chains
new file mode 100644 (file)
index 0000000..118bde5
Binary files /dev/null and b/BOINC software/BOINC client apps/chain_checker/chains differ
diff --git a/BOINC software/BOINC client apps/chain_checker/charset.txt b/BOINC software/BOINC client apps/chain_checker/charset.txt
new file mode 100644 (file)
index 0000000..d1e0179
--- /dev/null
@@ -0,0 +1,61 @@
+# charset configuration file for DistrRTgen v3.2 by Martin Westergaard (martinwj2005@gmail.com)
+
+byte                        = []
+alpha                       = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+alpha-space                 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+alpha-numeric               = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+alpha-numeric-space         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+alpha-numeric-symbol14      = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+= ]
+all                         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+all-space                   = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+lm-frt-cp437                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥àáâãäæçèéêëî]
+lm-frt-cp850                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9c\9d\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãåæèéêëíï]
+lm-frt-cp437-850            = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãäåæçèéêëíîï]
+
+numeric                     = [0123456789]
+numeric-space               = [0123456789 ]
+loweralpha                  = [abcdefghijklmnopqrstuvwxyz]
+loweralpha-space            = [abcdefghijklmnopqrstuvwxyz ]
+loweralpha-numeric          = [abcdefghijklmnopqrstuvwxyz0123456789]
+loweralpha-numeric-space    = [abcdefghijklmnopqrstuvwxyz0123456789 ]
+loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=]
+loweralpha-numeric-all             = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+mixalpha                    = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
+mixalpha-space              = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+mixalpha-numeric            = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+mixalpha-numeric-space      = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+mixalpha-numeric-symbol14   = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+mixalpha-numeric-all        = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+mixalpha-numeric-symbol32-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+mixalpha-numeric-all-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+                                                                                                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                            
\ No newline at end of file
diff --git a/BOINC software/BOINC client apps/chain_checker/result b/BOINC software/BOINC client apps/chain_checker/result
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/BOINC software/BOINC client apps/chain_checker/stderr.txt b/BOINC software/BOINC client apps/chain_checker/stderr.txt
new file mode 100644 (file)
index 0000000..edd0888
--- /dev/null
@@ -0,0 +1,3 @@
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/BuildLog.htm b/BOINC software/BOINC client apps/distrrtgen/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..8dfe859
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/BuildLog.htm differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/ChainWalkContext.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..def2732
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/ChainWalkContext.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/HashAlgorithm.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..cab0de9
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/HashAlgorithm.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/HashRoutine.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/HashRoutine.obj
new file mode 100644 (file)
index 0000000..c60dfde
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/HashRoutine.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/Public.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/Public.obj
new file mode 100644 (file)
index 0000000..9a64abf
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/Public.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.exe
new file mode 100644 (file)
index 0000000..94b12a5
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.ilk b/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.ilk
new file mode 100644 (file)
index 0000000..a1bc805
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.ilk differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.pdb
new file mode 100644 (file)
index 0000000..2a6d03f
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/chain_checker.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.exe
new file mode 100644 (file)
index 0000000..c71afbb
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.pdb
new file mode 100644 (file)
index 0000000..60e01f1
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/convertrti2.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/des_enc.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/des_enc.obj
new file mode 100644 (file)
index 0000000..f9c88e4
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/des_enc.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/des_setkey.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/des_setkey.obj
new file mode 100644 (file)
index 0000000..ab943e3
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/des_setkey.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe
new file mode 100644 (file)
index 0000000..060fca3
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest
new file mode 100644 (file)
index 0000000..d2d2076
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"></assembly>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
\ No newline at end of file
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest.res b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..3a6eb75
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.embed.manifest.res differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.intermediate.manifest b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.ilk b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.ilk
new file mode 100644 (file)
index 0000000..227ea3a
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.ilk differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.obj
new file mode 100644 (file)
index 0000000..8335a00
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.pdb
new file mode 100644 (file)
index 0000000..a0d24c7
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/distrrtgen.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/ecb_enc.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/ecb_enc.obj
new file mode 100644 (file)
index 0000000..b0fa5f9
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/ecb_enc.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.exe
new file mode 100644 (file)
index 0000000..9a36288
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.pdb
new file mode 100644 (file)
index 0000000..7362924
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/index_calculator.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/md4.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/md4.obj
new file mode 100644 (file)
index 0000000..6a63e2a
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/md4.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/md5.obj b/BOINC software/BOINC client apps/distrrtgen/Debug/md5.obj
new file mode 100644 (file)
index 0000000..3dee2f8
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/md5.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/mt.dep b/BOINC software/BOINC client apps/distrrtgen/Debug/mt.dep
new file mode 100644 (file)
index 0000000..bce7c40
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 18:46:19,51 on 28-11-2008 
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.exe
new file mode 100644 (file)
index 0000000..e38e71f
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.pdb
new file mode 100644 (file)
index 0000000..07e3a69
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rcracki.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.exe
new file mode 100644 (file)
index 0000000..df7686c
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.pdb
new file mode 100644 (file)
index 0000000..35c7f3c
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rsearch.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.exe
new file mode 100644 (file)
index 0000000..9f3371b
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.pdb
new file mode 100644 (file)
index 0000000..e03c832
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rti2rto.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.exe b/BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.exe
new file mode 100644 (file)
index 0000000..7b2825d
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.pdb
new file mode 100644 (file)
index 0000000..4d50d8c
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/rtperfectp.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/vc90.idb b/BOINC software/BOINC client apps/distrrtgen/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..b2ed940
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/vc90.idb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Debug/vc90.pdb b/BOINC software/BOINC client apps/distrrtgen/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..001d111
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Debug/vc90.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Makefile b/BOINC software/BOINC client apps/distrrtgen/Makefile
new file mode 100644 (file)
index 0000000..0963011
--- /dev/null
@@ -0,0 +1,32 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/frt/server_stable
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L /usr/X11R6/lib \
+    -L.
+
+
+PROGS = distrrtgen \
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+distrrtgen: distrrtgen.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a
+       $(CXX) Public.cpp ChainWalkContext.cpp HashAlgorithm.cpp HashRoutine.cpp md5.cpp $(CXXFLAGS) -o distrrtgen distrrtgen.o libstdc++.a -pthread -lboinc_api -lboinc -lssl -O3
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/BuildLog.htm b/BOINC software/BOINC client apps/distrrtgen/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..d752f6b
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/BuildLog.htm differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkContext.obj b/BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..ea146c8
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkContext.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkSet.obj b/BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkSet.obj
new file mode 100644 (file)
index 0000000..fa49662
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/ChainWalkSet.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/HashAlgorithm.obj b/BOINC software/BOINC client apps/distrrtgen/Release/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..d928d5d
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/HashAlgorithm.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/HashRoutine.obj b/BOINC software/BOINC client apps/distrrtgen/Release/HashRoutine.obj
new file mode 100644 (file)
index 0000000..7fc80b5
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/HashRoutine.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/Public.obj b/BOINC software/BOINC client apps/distrrtgen/Release/Public.obj
new file mode 100644 (file)
index 0000000..1d09354
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/Public.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.exe b/BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.exe
new file mode 100644 (file)
index 0000000..4322fb0
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.pdb
new file mode 100644 (file)
index 0000000..53bd84f
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/chain_checker.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.exe b/BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.exe
new file mode 100644 (file)
index 0000000..096a655
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.pdb
new file mode 100644 (file)
index 0000000..09e55b1
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/convertrti2.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/des_enc.obj b/BOINC software/BOINC client apps/distrrtgen/Release/des_enc.obj
new file mode 100644 (file)
index 0000000..528ad51
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/des_enc.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/des_setkey.obj b/BOINC software/BOINC client apps/distrrtgen/Release/des_setkey.obj
new file mode 100644 (file)
index 0000000..4c11adb
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/des_setkey.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe
new file mode 100644 (file)
index 0000000..8f1ce49
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe.intermediate.manifest b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.obj b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.obj
new file mode 100644 (file)
index 0000000..6647311
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.pdb
new file mode 100644 (file)
index 0000000..c0f5e43
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.17_windows_intelx86.exe b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.17_windows_intelx86.exe
new file mode 100644 (file)
index 0000000..a09d632
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.17_windows_intelx86.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.18_windows_intelx86.exe b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.18_windows_intelx86.exe
new file mode 100644 (file)
index 0000000..56b32ab
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.18_windows_intelx86.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.19_windows_intelx86.exe b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.19_windows_intelx86.exe
new file mode 100644 (file)
index 0000000..fcb3fe4
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/distrrtgen_2.19_windows_intelx86.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/ecb_enc.obj b/BOINC software/BOINC client apps/distrrtgen/Release/ecb_enc.obj
new file mode 100644 (file)
index 0000000..a249083
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/ecb_enc.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.exe b/BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.exe
new file mode 100644 (file)
index 0000000..c9b1467
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.pdb
new file mode 100644 (file)
index 0000000..cbff30b
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/index_calculator.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/md4.obj b/BOINC software/BOINC client apps/distrrtgen/Release/md4.obj
new file mode 100644 (file)
index 0000000..ffed4b0
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/md4.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/md5.obj b/BOINC software/BOINC client apps/distrrtgen/Release/md5.obj
new file mode 100644 (file)
index 0000000..3d75ae7
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/md5.obj differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/mt.dep b/BOINC software/BOINC client apps/distrrtgen/Release/mt.dep
new file mode 100644 (file)
index 0000000..8d0afae
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 18:29:03,89 on 28-11-2008 
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rcracki.exe b/BOINC software/BOINC client apps/distrrtgen/Release/rcracki.exe
new file mode 100644 (file)
index 0000000..36f5f5f
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rcracki.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rcracki.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/rcracki.pdb
new file mode 100644 (file)
index 0000000..9612176
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rcracki.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rsearch.exe b/BOINC software/BOINC client apps/distrrtgen/Release/rsearch.exe
new file mode 100644 (file)
index 0000000..64d4c88
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rsearch.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rsearch.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/rsearch.pdb
new file mode 100644 (file)
index 0000000..1ba5703
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rsearch.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.exe b/BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.exe
new file mode 100644 (file)
index 0000000..b2b2e9b
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.pdb
new file mode 100644 (file)
index 0000000..8dfa421
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rti2rto.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.exe b/BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.exe
new file mode 100644 (file)
index 0000000..b4ac5a8
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.exe differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.pdb
new file mode 100644 (file)
index 0000000..aebd777
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/rtperfectp.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/sched_util.cpp b/BOINC software/BOINC client apps/distrrtgen/Release/sched_util.cpp
new file mode 100644 (file)
index 0000000..d680b14
--- /dev/null
@@ -0,0 +1,333 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+using namespace std;
+
+#include "config.h"
+#include <cstdlib>
+#include <csignal>
+#include <cerrno>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "filesys.h"
+#include "md5_file.h"
+#include "error_numbers.h"
+
+#include "sched_msgs.h"
+#include "sched_util.h"
+#include "util.h"
+
+#ifdef _USING_FCGI_
+#include "boinc_fcgi.h"
+#endif
+
+const char* STOP_DAEMONS_FILENAME = "../stop_daemons";
+    // NOTE: this must be same as in the "start" script
+const char* STOP_SCHED_FILENAME = "../stop_sched";
+    // NOTE: this must be same as in the "start" script
+const int STOP_SIGNAL = SIGHUP;
+    // NOTE: this must be same as in the "start" script
+
+void write_pid_file(const char* filename) {
+#ifndef _USING_FCGI_
+    FILE* fpid = fopen(filename, "w");
+#else
+    FCGI_FILE* fpid = FCGI::fopen(filename,"w");
+#endif
+
+    if (!fpid) {
+        log_messages.printf(MSG_CRITICAL, "Couldn't write pid file\n");
+        return;
+    }
+    fprintf(fpid, "%d\n", (int)getpid());
+    fclose(fpid);
+}
+
+// caught_sig_int will be set to true if STOP_SIGNAL (normally SIGHUP)
+//  is caught.
+bool caught_stop_signal = false;
+static void stop_signal_handler(int) {
+    fprintf(stderr, "GOT STOP SIGNAL\n");
+    caught_stop_signal = true;
+}
+
+void install_stop_signal_handler() {
+    signal(STOP_SIGNAL, stop_signal_handler);
+    // handler is now default again so hitting ^C again will kill the program.
+}
+
+void check_stop_daemons() {
+    if (caught_stop_signal) {
+        log_messages.printf(MSG_NORMAL, "Quitting due to SIGHUP\n");
+        exit(0);
+    }
+    if (boinc_file_exists(STOP_DAEMONS_FILENAME)) {
+        log_messages.printf(MSG_NORMAL,
+            "Quitting because trigger file '%s' is present\n",
+            STOP_DAEMONS_FILENAME
+        );
+        exit(0);
+    }
+}
+
+bool check_stop_sched() {
+    return boinc_file_exists(STOP_SCHED_FILENAME);
+}
+
+// try to open a file.
+// On failure:
+//   return ERR_FOPEN if the dir is there but not file
+//     (this is generally a nonrecoverable failure)
+//   return ERR_OPENDIR if dir is not there.
+//     (this is generally a recoverable error,
+//     like NFS mount failure, that may go away later)
+//
+#ifndef _USING_FCGI_
+int try_fopen(const char* path, FILE*& f, const char* mode) {
+#else
+int try_fopen(const char* path, FCGI_FILE*& f, const char *mode) {
+#endif
+    char* p;
+    DIR* d;
+    char dirpath[256];
+
+#ifndef _USING_FCGI_
+    f = fopen(path, mode);
+#else
+    f = FCGI::fopen(path, mode);
+#endif
+
+    if (!f) {
+        memset(dirpath, '\0', sizeof(dirpath));
+        p = strrchr(path, '/');
+        if (p) {
+            strncpy(dirpath, path, (int)(p-path));
+        } else {
+            strcpy(dirpath, ".");
+        }
+        if ((d = opendir(dirpath)) == NULL) {
+            return ERR_OPENDIR;
+        } else {
+            closedir(d);
+            return ERR_FOPEN;
+        }
+    }
+    return 0;
+}
+
+void get_log_path(char* p, const char* filename) {
+    char host[256];
+    char dir[256];
+    gethostname(host, 256);
+    char* q = strchr(host, '.');
+    if (q) *q=0;
+    sprintf(dir, "../log_%s", host);
+    sprintf(p, "%s/%s", dir, filename);
+    mode_t old_mask = umask(0);
+    mkdir(dir, 01770);
+        // make log_x directory sticky and group-rwx
+        // so that whatever apache puts there will be owned by us
+    umask(old_mask);
+}
+
+static void filename_hash(const char* filename, int fanout, char* dir) {
+       std::string s = md5_string((const unsigned char*)filename, strlen(filename));
+       int x = strtol(s.substr(1, 7).c_str(), 0, 16);
+    sprintf(dir, "%x", x % fanout);
+}
+
+// given a filename, compute its path in a directory hierarchy
+// If create is true, create the directory if needed
+//
+int dir_hier_path(
+    const char* filename, const char* root, int fanout,
+       char* path, bool create
+) {
+    char dir[256], dirpath[256];
+    int retval;
+
+    if (fanout==0) {
+        sprintf(path, "%s/%s", root, filename);
+        return 0;
+    }
+
+    filename_hash(filename, fanout, dir);
+
+    sprintf(dirpath, "%s/%s", root, dir);
+    if (create) {
+        retval = boinc_mkdir(dirpath);
+        if (retval && (errno != EEXIST)) {
+            fprintf(stderr, "boinc_mkdir(%s): retval %d errno %d\n", dirpath, retval, errno);
+            return ERR_MKDIR;
+        }
+    }
+    sprintf(path, "%s/%s", dirpath, filename);
+    return 0;
+}
+
+// same, but the output is a URL (used by tools/backend_lib.C)
+//
+int dir_hier_url(
+    const char* filename, const char* root, int fanout,
+       char* result
+) {
+    char dir[256];
+
+    if (fanout==0) {
+        sprintf(result, "%s/%s", root, filename);
+        return 0;
+    }
+
+    filename_hash(filename, fanout, dir);
+    sprintf(result, "%s/%s/%s", root, dir, filename);
+    return 0;
+}
+
+// Locality scheduling: get filename from result name
+//
+
+int extract_filename(char* in, char* out) {
+    strcpy(out, in);
+    char* p = strstr(out, "__");
+    if (!p) return -1;
+    *p = 0;
+    return 0;
+}
+
+void compute_avg_turnaround(HOST& host, double turnaround) {
+    double new_avg;
+    if (host.avg_turnaround == 0) {
+        new_avg = turnaround;
+    } else {
+        new_avg = .7*host.avg_turnaround + .3*turnaround;
+    }
+    host.avg_turnaround = new_avg;
+}
+
+double elapsed_wallclock_time() {
+    static double wallclock_execution_time=0.0;
+
+    if (wallclock_execution_time == 0.0) {
+        wallclock_execution_time=dtime();
+        return 0.0;
+    }
+
+    return dtime()-wallclock_execution_time;
+}
+
+// Request lock on the given file with given fd.  Returns:
+// 0 if we get lock
+// PID (>0) if another process has lock
+// -1 if error
+//
+int mylockf(int fd) {
+    struct flock fl;
+    fl.l_type=F_WRLCK;
+    fl.l_whence=SEEK_SET;
+    fl.l_start=0;
+    fl.l_len=0;
+    if (-1 != fcntl(fd, F_SETLK, &fl)) return 0;
+
+    // if lock failed, find out why
+    errno=0;
+    fcntl(fd, F_GETLK, &fl);
+    if (fl.l_pid>0) return fl.l_pid;
+    return -1;
+}
+
+double fpops_to_credit(double fpops, double intops) {
+    // TODO: use fp_weight if specified in config file
+    double fpc = (fpops/1e9)*COBBLESTONE_FACTOR/SECONDS_PER_DAY;
+    double intc = (intops/1e9)*COBBLESTONE_FACTOR/SECONDS_PER_DAY;
+    return std::max(fpc, intc);
+}
+
+double credit_multiplier(int appid, time_t create_time) {
+    DB_CREDIT_MULTIPLIER mult;
+    mult.get_nearest(appid,create_time);
+    return mult.multiplier;
+}
+
+int count_results(char* query, int& n) {
+    DB_RESULT result;
+    int retval = result.count(n, query);
+    if (retval) return retval;
+    return 0;
+}
+
+int count_workunits(int& n, const char* query) {
+    DB_WORKUNIT workunit;
+    int retval = workunit.count(n, query);
+    if (retval) return retval;
+    return 0;
+}
+
+int count_unsent_results(int& n, int appid) {
+    char buf[256];
+    if (appid) {
+        sprintf(buf, "where server_state=%d and appid=%d ",
+            RESULT_SERVER_STATE_UNSENT, appid
+        );
+    } else {
+        sprintf(buf, "where server_state=%d", RESULT_SERVER_STATE_UNSENT);
+    }
+    return count_results(buf, n);
+
+}
+
+#ifdef GCL_SIMULATOR
+
+void simulator_signal_handler(int signum){    
+    FILE *fsim;
+    char currenttime[64];
+    fsim = fopen("../simulator/sim_time.txt","r");
+    if(fsim){
+        fscanf(fsim,"%s", currenttime);
+        simtime = atof(currenttime); 
+        fclose(fsim);
+    }
+    log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
+        "Invoked by the simulator at time %.0f... \n", simtime
+    );
+}
+
+int itime() {
+    return (int) simtime;
+}
+
+void continue_simulation(const char *daemonname){
+    char daemonfilelok[64];
+    char daemonfile[64];
+    sprintf(daemonfile, "../simulator/sim_%s.txt",daemonname);
+    sprintf(daemonfilelok, "../simulator/sim_%s.lok",daemonname);
+    FILE *fsimlok = fopen(daemonfilelok, "w");
+    if (fsimlok){
+        fclose(fsimlok);
+        FILE *fsim = fopen(daemonfile, "w");
+        if (fsim) {
+            fclose(fsim);
+        }
+    }
+    remove(daemonfilelok);
+}
+
+#endif
+
+const char *BOINC_RCSID_affa6ef1e4 = "$Id: sched_util.cpp 16097 2008-09-30 18:21:41Z davea $";
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/validate_util.cpp b/BOINC software/BOINC client apps/distrrtgen/Release/validate_util.cpp
new file mode 100644 (file)
index 0000000..f3bf361
--- /dev/null
@@ -0,0 +1,564 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Code to facilitate writing validators.
+// Can be used as the basis for a validator that accepts everything
+// (see sample_trivial_validator.C),
+// or that requires strict equality (see sample_bitwise_validator.C)
+// or that uses fuzzy comparison.
+
+#include <cstring>
+#include "config.h"
+
+#include "error_numbers.h"
+#include "parse.h"
+#include "util.h"
+#include "filesys.h"
+
+#include "sched_util.h"
+#include "sched_config.h"
+#include "sched_msgs.h"
+#include "validator.h"
+#include "validate_util.h"
+
+using std::vector;
+using std::string;
+
+int FILE_INFO::parse(XML_PARSER& xp) {
+    char tag[256];
+    bool is_tag, found=false;
+    optional = false;
+    no_validate = false;
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "/file_ref")) {
+            return found?0:ERR_XML_PARSE;
+        }
+        if (xp.parse_string(tag, "file_name", name)) {
+            found = true;
+            continue;
+        }
+        if (xp.parse_bool(tag, "optional", optional)) continue;
+        if (xp.parse_bool(tag, "no_validate", no_validate)) continue;
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_info(RESULT& result, FILE_INFO& fi) {
+    char tag[256], path[1024];
+    bool is_tag;
+    string name;
+    MIOFILE mf;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            int retval = fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_infos(RESULT& result, vector<FILE_INFO>& fis) {
+    char tag[256], path[1024];
+    bool is_tag;
+    MIOFILE mf;
+    string name;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    fis.clear();
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_INFO fi;
+            int retval =  fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            fis.push_back(fi);
+        }
+    }
+    return 0;
+}
+
+int get_output_file_path(RESULT& result, string& path) {
+    FILE_INFO fi;
+    int retval = get_output_file_info(result, fi);
+    if (retval) return retval;
+    path = fi.path;
+    return 0;
+}
+
+int get_output_file_paths(RESULT& result, vector<string>& paths) {
+    vector<FILE_INFO> fis;
+    int retval = get_output_file_infos(result, fis);
+    if (retval) return retval;
+    paths.clear();
+    for (unsigned int i=0; i<fis.size(); i++) {
+        paths.push_back(fis[i].path);
+    }
+    return 0;
+}
+
+struct FILE_REF {
+    char file_name[256];
+    char open_name[256];
+    int parse(XML_PARSER& xp) {
+        char tag[256];
+        bool is_tag;
+
+        strcpy(file_name, "");
+        strcpy(open_name, "");
+        while (!xp.get(tag, sizeof(tag), is_tag)) {
+            if (!is_tag) continue;
+            if (!strcmp(tag, "/file_ref")) {
+                return 0;
+            }
+            if (xp.parse_str(tag, "file_name", file_name, sizeof(file_name))) continue;
+            if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) continue;
+        }
+        return ERR_XML_PARSE;
+    }
+};
+
+// given a path returned by the above, get the corresponding logical name
+//
+int get_logical_name(RESULT& result, string& path, string& name) {
+    char phys_name[1024];
+    char tag[256];
+    bool is_tag;
+    MIOFILE mf;
+    int retval;
+
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+
+    strcpy(phys_name, path.c_str());
+    char* p = strrchr(phys_name, '/');
+    if (!p) return ERR_NOT_FOUND;
+    strcpy(phys_name, p+1);
+
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "result")) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_REF fr;
+            retval = fr.parse(xp);
+            if (retval) continue;
+            if (!strcmp(phys_name, fr.file_name)) {
+                name = fr.open_name;
+                return 0;
+            }
+            continue;
+        }
+        xp.skip_unexpected(tag, false, 0);
+    }
+    return ERR_XML_PARSE;
+}
+
+#define CREDIT_EPSILON .001
+
+// If we have N correct results with nonzero claimed credit,
+// compute a canonical credit as follows:
+// - if N==0 (all claimed credits are infinitesmal), return CREDIT_EPSILON
+// - if N==1, return that credit
+// - if N==2, return min
+// - if N>2, toss out min and max, return average of rest
+//
+double median_mean_credit(WORKUNIT& /*wu*/, vector<RESULT>& results) {
+    int ilow=-1, ihigh=-1;
+    double credit_low = 0, credit_high = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < CREDIT_EPSILON) continue;
+        if (ilow < 0) {
+            ilow = ihigh = i;
+            credit_low = credit_high = result.claimed_credit;
+        } else {
+            if (result.claimed_credit < credit_low) {
+                ilow = i;
+                credit_low = result.claimed_credit;
+            }
+            if (result.claimed_credit > credit_high) {
+                ihigh = i;
+                credit_high = result.claimed_credit;
+            }
+        }
+        nvalid++;
+    }
+
+    switch(nvalid) {
+    case 0:
+        return CREDIT_EPSILON;
+    case 1:
+    case 2:
+        return credit_low;
+    default:
+        double sum = 0;
+        for (i=0; i<results.size(); i++) {
+            if (i == (unsigned int) ilow) continue;
+            if (i == (unsigned int) ihigh) continue;
+            RESULT& result = results[i];
+            if (result.validate_state != VALIDATE_STATE_VALID) continue;
+
+            sum += result.claimed_credit;
+        }
+        return sum/(nvalid-2);
+    }
+}
+
+int get_credit_from_wu(WORKUNIT& wu, vector<RESULT>&, double& credit) {
+    double x;
+    int retval;
+    DB_WORKUNIT dbwu;
+
+    dbwu.id = wu.id;
+    retval = dbwu.get_field_str("xml_doc", dbwu.xml_doc, sizeof(dbwu.xml_doc));
+    if (!retval) {
+        if (parse_double(dbwu.xml_doc, "<credit>", x)) {
+            credit = x;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+// This function should be called from the validator whenever credit
+// is granted to a host.  It's purpose is to track the average credit
+// per cpu time for that host.
+//
+// It updates an exponentially-decaying estimate of credit_per_cpu_sec
+// Note that this does NOT decay with time, but instead decays with
+// total credits earned.  If a host stops earning credits, then this
+// quantity stops decaying.  So credit_per_cpu_sec must NOT be
+// periodically decayed using the update_stats utility or similar
+// methods.
+//
+// The intended purpose is for cross-project credit comparisons on
+// BOINC statistics pages, for hosts attached to multiple machines.
+// One day people will write PhD theses on how to normalize credit
+// values to equalize them across projects.  I hope this will be done
+// according to "Allen's principle": "Credits granted by a project
+// should be normalized so that, averaged across all hosts attached to
+// multiple projects, projects grant equal credit per cpu second."
+// This principle ensures that (on average) participants will choose
+// projects based on merit, not based on credits.  It also ensures
+// that (on average) host machines migrate to the projects for which
+// they are best suited.
+//
+// For cross-project comparison the value of credit_per_cpu_sec should
+// be exported in the statistics file host_id.gz, which is written by
+// the code in db_dump.C.
+//
+// Algorithm: credits_per_cpu_second should be updated each time that
+// a host is granted credit, according to:
+//
+//     CREDIT_AVERAGE_CONST = 500           [see Note 5]
+//     MAX_CREDIT_PER_CPU_SEC = 0.1         [see Note 6]
+//
+//     e = tanh(granted_credit/CREDIT_AVERAGE_CONST)
+//     if (e < 0) then e = 0
+//     if (e > 1) then e = 1
+//     if (credit_per_cpu_sec <= 0) then e = 1
+//     if (cpu_time <= 0) then e = 0        [see Note 4]
+//     if (granted_credit <= 0) then e = 0  [see Note 3]
+//
+//     rate = granted_credit/cpu_time
+//     if (rate < 0) rate = 0
+//     if (rate > MAX_CREDIT_PER_CPU_SEC) rate = MAX_CREDIT_PER_CPU_SEC
+//
+//     credit_per_cpu_sec = e * rate + (1 - e) * credit_per_cpu_sec
+
+// Note 0: all quantities above should be treated as real numbers
+// Note 1: cpu_time is measured in seconds
+// Note 2: When a host is created, the initial value of
+//         credit_per_cpu_sec, should be zero.
+// Note 3: If a host has done invalid work (granted_credit==0) we have
+//         chosen not to include it.  One might argue that the
+//         boundary case granted_credit==0 should be treated the same
+//         as granted_credit>0.  However the goal here is not to
+//         identify cpus whose host machines sometimes produce
+//         rubbish.  It is to get a measure of how effectively the cpu
+//         runs the application code.
+// Note 4: e==0 means 'DO NOT include the first term on the rhs of the
+//         equation defining credit_per_cpu_sec' which is equivalent
+//         to 'DO NOT update credit_per_cpu_sec'.
+// Note 5: CREDIT_AVERAGE_CONST determines the exponential decay
+//         credit used in averaging credit_per_cpu_sec.  It may be
+//         changed at any time, even if the project database has
+//         already been populated with non-zero values of
+//         credit_per_cpu_sec.
+// Note 6: Typical VERY FAST cpus have credit_per_cpu_sec of around
+//         0.02.  This is a safety mechanism designed to prevent
+//         trouble if a client or host has reported absurd values (due
+//         to a bug in client or server software or by cheating).  In
+//         five years when cpus are five time faster, please increase
+//         the value of R.  You may also want to increase the value of
+//         CREDIT_AVERAGE_CONST.
+//
+//         Nonzero return value: host exceeded the max allowed
+//         credit/cpu_sec.
+//
+int update_credit_per_cpu_sec(
+    double  granted_credit,     // credit granted for this work
+    double  cpu_time,           // cpu time (seconds) used for this work
+    double& credit_per_cpu_sec  // (average) credit per cpu second
+) {
+    int retval = 0;
+
+    // Either of these values may be freely changed in the future.
+    // When CPUs get much faster one must increase the 'sanity-check'
+    // value of max_credit_per_cpu_sec.  At that time it would also
+    // make sense to proportionally increase the credit_average_const.
+    //
+    const double credit_average_const = 500;
+    const double max_credit_per_cpu_sec = 0.07;
+
+    double e = tanh(granted_credit/credit_average_const);
+    if (e <= 0.0 || cpu_time == 0.0 || granted_credit == 0.0) return retval;
+    if (e > 1.0 || credit_per_cpu_sec == 0.0) e = 1.0;
+
+    double rate =  granted_credit/cpu_time;
+    if (rate < 0.0) rate = 0.0;
+    if (rate > max_credit_per_cpu_sec) {
+        rate = max_credit_per_cpu_sec;
+        retval = 1;
+    }
+
+    credit_per_cpu_sec = e * rate + (1.0 - e) * credit_per_cpu_sec;
+
+    return retval;
+}
+
+double stddev_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    double credit_low_bound = 0, credit_high_bound = 0;
+    double penalize_credit_high_bound = 0;
+    double credit_avg = 0;
+    double credit = 0;
+    double old = 0;
+    double std_dev = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    nvalid = 0;
+    //calculate stddev difference
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        std_dev = pow(credit_avg - result.claimed_credit,2) + std_dev;
+        nvalid++;
+    }
+
+    std_dev = std_dev/ (double) nvalid;
+    std_dev = sqrt(std_dev);
+
+    credit_low_bound = credit_avg-std_dev;
+    if (credit_low_bound > credit_avg*.85) {
+        credit_low_bound = credit_avg*.85;
+    }
+    credit_low_bound = credit_low_bound - 2.5;
+    if (credit_low_bound < 1) credit_low_bound = 1;
+
+    credit_high_bound = credit_avg+std_dev;
+    if (credit_high_bound < credit_avg*1.15) {
+        credit_high_bound = credit_avg*1.15;
+    }
+    credit_high_bound = credit_high_bound + 5;
+
+
+    nvalid=0;
+    credit = 0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < credit_high_bound && result.claimed_credit > credit_low_bound) {
+            credit = credit + result.claimed_credit;
+            nvalid++;
+        } else {
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_SD Discarding invalid credit %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit,
+                credit_avg, credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    double grant_credit;
+    switch(nvalid) {
+    case 0:
+        grant_credit = median_mean_credit(wu, results);
+        old = grant_credit;
+        break;
+    default:
+        grant_credit = credit/nvalid;
+        old = median_mean_credit(wu, results);
+    }
+
+    // Log what happened
+    if (old > grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Less awarded\n",
+            grant_credit, old
+        );
+    } else if (old == grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Same awarded\n",
+            grant_credit, old
+        );
+    } else {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  More awarded\n",
+            grant_credit, old
+        );
+    }
+
+    // penalize hosts that are claiming too much
+    penalize_credit_high_bound = grant_credit+1.5*std_dev;
+    if (penalize_credit_high_bound < grant_credit*1.65) {
+        penalize_credit_high_bound = grant_credit*1.65;
+    }
+    penalize_credit_high_bound = penalize_credit_high_bound + 20;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit > penalize_credit_high_bound) {
+            result.granted_credit = grant_credit * 0.5;
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_PENALTY Penalizing host for too high credit %.1lf, grant %.1lf, penalize %.1lf, stddev %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit, grant_credit,
+                penalize_credit_high_bound, std_dev, credit_avg,
+                credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    return grant_credit;
+}
+
+double two_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    unsigned int i;
+    double credit = 0;
+    double credit_avg = 0;
+    double last_credit = 0;
+    int nvalid = 0;
+    double grant_credit;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        last_credit = result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    // If more then 2 valid results, compute via stddev method
+    if (nvalid > 2) return stddev_credit(wu, results);
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Only 2 results \n",wu.id, wu.name
+    );
+
+    // If only 2, then check to see if range is reasonable
+    if (fabs(last_credit - credit_avg) < 0.15*credit_avg) return credit_avg;
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Average is more than 15 percent from each value \n",
+        wu.id, wu.name
+    );
+
+    // log data on large variance in runtime
+    float cpu_time = 0.0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.cpu_time < 30) continue;
+        if (cpu_time == 0) {
+            cpu_time = result.cpu_time*1.0;
+        } else {
+            if (cpu_time/result.cpu_time > 2 || cpu_time/result.cpu_time < 0.5) {
+                log_messages.printf(MSG_DEBUG,
+                    "[WORKUNIT#%d %s] Large difference in runtime \n",
+                    wu.id, wu.name
+                );
+            }
+        }
+    }
+
+
+    //find result with smallest deviation from historical credit and award that value
+    DB_HOST host;
+    double deviation = -1;
+    grant_credit = credit_avg; // default award in case nobody matches the cases
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        host.lookup_id(result.hostid);
+        log_messages.printf(MSG_DEBUG,
+            "[RESULT#%d %s] Claimed Credit = %.2lf  Historical Credit = %.2lf \n",
+            result.id, result.name, result.claimed_credit,
+            result.cpu_time*host.credit_per_cpu_sec
+        );
+        if ((deviation < 0 || deviation > fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec)) && result.cpu_time > 30) {
+            deviation = fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec);
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] Credit deviation = %.2lf \n",
+                result.id, result.name, deviation
+            );
+            grant_credit = result.claimed_credit;
+        }
+    }
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Credit granted = %.2lf \n",
+        wu.id, wu.name, grant_credit
+    );
+    return grant_credit;
+}
+
+const char *BOINC_RCSID_07049e8a0e = "$Id: validate_util.cpp 16069 2008-09-26 18:20:24Z davea $";
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/vc90.idb b/BOINC software/BOINC client apps/distrrtgen/Release/vc90.idb
new file mode 100644 (file)
index 0000000..01c4579
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/vc90.idb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/Release/vc90.pdb b/BOINC software/BOINC client apps/distrrtgen/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..734223a
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/Release/vc90.pdb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/boinc_lockfile b/BOINC software/BOINC client apps/distrrtgen/boinc_lockfile
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/BOINC software/BOINC client apps/distrrtgen/charset.txt b/BOINC software/BOINC client apps/distrrtgen/charset.txt
new file mode 100644 (file)
index 0000000..6e749fa
--- /dev/null
@@ -0,0 +1,34 @@
+# charset configuration file for DistrRTgen v3.2 by Martin Westergaard (martinwj2005@gmail.com)
+
+byte                        = []
+alpha                       = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+alpha-space                 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+alpha-numeric               = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+alpha-numeric-space         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+alpha-numeric-symbol14      = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+= ]
+all                         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+all-space                   = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+lm-frt-cp437                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥àáâãäæçèéêëî]
+lm-frt-cp850                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9c\9d\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãåæèéêëíï]
+lm-frt-cp437-850            = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãäåæçèéêëíîï]
+
+numeric                     = [0123456789]
+numeric-space               = [0123456789 ]
+loweralpha                  = [abcdefghijklmnopqrstuvwxyz]
+loweralpha-space            = [abcdefghijklmnopqrstuvwxyz ]
+loweralpha-numeric          = [abcdefghijklmnopqrstuvwxyz0123456789]
+loweralpha-numeric-space    = [abcdefghijklmnopqrstuvwxyz0123456789 ]
+loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=]
+loweralpha-numeric-all             = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+mixalpha                    = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
+mixalpha-space              = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+mixalpha-numeric            = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+mixalpha-numeric-space      = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+mixalpha-numeric-symbol14   = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+mixalpha-numeric-all        = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+mixalpha-numeric-symbol32-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+mixalpha-numeric-all-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen b/BOINC software/BOINC client apps/distrrtgen/distrrtgen
new file mode 100644 (file)
index 0000000..ec1bac7
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/distrrtgen differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.cpp b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.cpp
new file mode 100644 (file)
index 0000000..5271512
--- /dev/null
@@ -0,0 +1,345 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// This program serves as both
+// - An example BOINC application, illustrating the use of the BOINC API
+// - A program for testing various features of BOINC
+//
+// NOTE: this file exists as both
+// boinc/apps/upper_case.C
+// and
+// boinc_samples/example_app/uc2.C
+// If you update one, please update the other!
+
+// The program converts a mixed-case file to upper case:
+// read "in", convert to upper case, write to "out"
+//
+// command line options
+// -run_slow: sleep 1 second after each character
+// -cpu_time N: use about N CPU seconds after copying files
+// -early_exit: exit(10) after 30 chars
+// -early_crash: crash after 30 chars
+//
+
+#ifdef _WIN32
+#include "boinc_win.h"
+#else
+#include "config.h"
+#include <cstdio>
+#include <cctype>
+#include <ctime>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+#include <unistd.h>
+#endif
+
+#include <string>
+#include <fstream>
+#include <iostream>
+#include "str_util.h"
+#include "util.h"
+#include "filesys.h"
+#include "boinc_api.h"
+#include "Public.h"
+// Rainbowcrack code
+#include "ChainWalkContext.h"
+typedef unsigned int uint32;
+//typedef unsigned __int64 uint64;
+
+
+using std::string;
+
+/*
+bool early_exit = false;
+bool early_crash = false;
+bool early_sleep = false;
+double cpu_time = 20, comp_result;
+*/
+int QuickSortPartition(RainbowChainCP* pChain, int nLow, int nHigh)
+{
+       int nRandomIndex = nLow + ((unsigned int)rand() * (RAND_MAX + 1) + (unsigned int)rand()) % (nHigh - nLow + 1);
+       RainbowChainCP TempChain;
+       TempChain = pChain[nLow];
+       pChain[nLow] = pChain[nRandomIndex];
+       pChain[nRandomIndex] = TempChain;
+
+       TempChain = pChain[nLow];
+       uint64 nPivotKey = pChain[nLow].nIndexE;
+       while (nLow < nHigh)
+       {
+               while (nLow < nHigh && pChain[nHigh].nIndexE >= nPivotKey)
+                       nHigh--;
+               pChain[nLow] = pChain[nHigh];
+               while (nLow < nHigh && pChain[nLow].nIndexE <= nPivotKey)
+                       nLow++;
+               pChain[nHigh] = pChain[nLow];
+       }
+       pChain[nLow] = TempChain;
+       return nLow;
+}
+
+void QuickSort(RainbowChainCP* pChain, int nLow, int nHigh)
+{
+       if (nLow < nHigh)
+       {
+               int nPivotLoc = QuickSortPartition(pChain, nLow, nHigh);
+               QuickSort(pChain, nLow, nPivotLoc - 1);
+               QuickSort(pChain, nPivotLoc + 1, nHigh);
+       }
+}
+
+int main(int argc, char **argv) {    
+    int retval;
+    double fd;
+    char output_path[512], chkpt_path[512];
+    FILE* state;       
+    retval = boinc_init();
+    if (retval) {
+        fprintf(stderr, "boinc_init returned %d\n", retval);
+        exit(retval);
+    }
+       
+
+    // get size of input file (used to compute fraction done)
+    //
+    //file_size(input_path, fsize);
+
+    // See if there's a valid checkpoint file.
+    // If so seek input file and truncate output file
+    //
+
+
+       if(argc < 10)
+       {
+               fprintf(stderr, "Not enough parameters");
+               return -1;
+       }
+       string sHashRoutineName, sCharsetName, sSalt, sCheckPoints;
+       uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
+       uint64 nChainStart;
+       sHashRoutineName = argv[1];
+       sCharsetName = argv[2];
+       nPlainLenMin = atoi(argv[3]);
+       nPlainLenMax = atoi(argv[4]);
+       nRainbowTableIndex = atoi(argv[5]);
+       nRainbowChainLen = atoi(argv[6]);
+       nRainbowChainCount = atoi(argv[7]);
+#ifdef _WIN32
+
+       nChainStart = _atoi64(argv[8]);
+
+#else
+       nChainStart = atoll(argv[8]);
+#endif
+       sCheckPoints = argv[9];
+       vector<int> vCPPositions;
+       char *cp = strtok((char *)sCheckPoints.c_str(), ",");
+       while(cp != NULL)
+       {
+               vCPPositions.push_back(atoi(cp));
+               cp = strtok(NULL, ",");
+       }
+       if(argc == 11)
+       {
+               sSalt = argv[10];
+       }
+       //std::cout << "Starting ChainGenerator" << std::endl;
+       // Setup CChainWalkContext
+       //std::cout << "ChainGenerator started." << std::endl;
+
+       if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
+       {
+               fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str());
+               return 1;
+       }
+       //std::cout << "Hash routine validated" << std::endl;
+
+       if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+       {       
+               std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
+               return 2;
+       }
+       //std::cout << "Plain charset validated" << std::endl;
+
+       if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
+               return 3;
+       }
+       //std::cout << "Rainbowtable index validated" << std::endl;
+
+       if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
+       {
+               // Convert username to unicode
+               const char *szSalt = sSalt.c_str();
+               int salt_length = strlen(szSalt);
+               unsigned char cur_salt[256];
+               for (int i=0; i<salt_length; i++)
+               {
+                       cur_salt[i*2] = szSalt[i];
+                       cur_salt[i*2+1] = 0x00;
+               }
+               CChainWalkContext::SetSalt(cur_salt, salt_length*2);
+       }
+       else if(sHashRoutineName == "halflmchall")
+       { // The salt is hardcoded into the hash routine
+       //      CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
+       }
+       else if(sHashRoutineName == "oracle")
+       {
+               CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
+       }
+       //std::cout << "Opening chain file" << std::endl;
+
+       
+       // Open file
+//     fclose(fopen(sFilename.c_str(), "a"));
+//     FILE* file = fopen(sFilename.c_str(), "r+b");
+    boinc_resolve_filename("result", output_path, sizeof(output_path));
+       fclose(boinc_fopen(output_path, "a"));
+       FILE *outfile = boinc_fopen(output_path, "r+b");
+       
+       if (outfile == NULL)
+       {
+               std::cerr << "failed to create " << output_path << std::endl;
+               return 4;
+       }
+       
+       
+       // Check existing chains
+       unsigned int nDataLen = (unsigned int)GetFileLen(outfile);
+       unsigned int nFileLen;
+       
+       // Round to boundary
+       nDataLen = nDataLen / 18 * 18;
+       if ((int)nDataLen == nRainbowChainCount * 18)
+       {               
+               std::cerr << "precomputation of this rainbow table already finished" << std::endl;
+               fclose(outfile);
+               return 0;
+       }
+       nChainStart += (nDataLen / 18);
+       fseek(outfile, nDataLen, SEEK_SET);
+       size_t nReturn;
+       CChainWalkContext cwc;
+       uint64 nIndex[2];
+       time_t tStart = time(NULL);
+//     std::cout << "Starting to generate chains" << std::endl;
+       for(int nCurrentCalculatedChains = nDataLen / 18; nCurrentCalculatedChains < nRainbowChainCount; nCurrentCalculatedChains++)
+       {               
+               int cpcheck = 0;
+               unsigned short checkpoint = 0;
+               fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount;
+               boinc_fraction_done(fd);
+               cwc.SetIndex(nChainStart++); // use a given index now!
+               nIndex[0] = cwc.GetIndex();
+               
+               for (int nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
+               {
+               //      std::cout << "IndexToPlain()" << std::endl;
+                       cwc.IndexToPlain();
+               //      std::cout << "PlainToHash()" << std::endl;
+                       cwc.PlainToHash();
+               //      std::cout << "HashToIndex()" << std::endl;
+                       cwc.HashToIndex(nPos);
+                       if(cpcheck < vCPPositions.size() && nPos == vCPPositions[cpcheck])
+                       {
+                               
+                               checkpoint |= (1 << cpcheck) & (unsigned short)cwc.GetIndex() << cpcheck;
+                               cpcheck++;
+                       }
+               }
+               //std::cout << "GetIndex()" << std::endl;
+
+               nIndex[1] = cwc.GetIndex();
+               // Write chain to disk
+               if ((nReturn = fwrite(nIndex, 1, 16, outfile)) != 16)
+               {
+                       std::cerr << "disk write fail" << std::endl;
+                       fclose(outfile);
+                       return 9;
+               }
+               if((nReturn = fwrite(&checkpoint, 1, 2, outfile)) != 2)
+               {
+                       std::cerr << "disk write fail" << std::endl;
+                       fclose(outfile);
+                       return 9;
+               }
+//             fflush(file);
+       }
+       //std::cout << "Generation completed" << std::endl;
+    fseek(outfile, 0, SEEK_SET);
+       nFileLen = GetFileLen(outfile);
+       nRainbowChainCount = nFileLen / 18;
+
+       RainbowChainCP* pChain = (RainbowChainCP*)new unsigned char[sizeof(RainbowChainCP) * nRainbowChainCount];
+
+       if (pChain != NULL)
+       {
+               // Load file
+               fseek(outfile, 0, SEEK_SET);
+               for(int i = 0; i < nRainbowChainCount; i++)
+               {
+                       if(fread(&pChain[i], 1, 16, outfile) != 16)
+                       {
+                               printf("disk read fail\n");
+                               return 9;
+                       }
+                       if(fread(&pChain[i].nCheckPoint, 1, sizeof(pChain[i].nCheckPoint), outfile) != 2)
+                       {
+                               printf("disk read fail\n");
+                               return 9;
+                       }
+               }
+
+               // Sort file
+               QuickSort(pChain, 0, nRainbowChainCount - 1);
+
+               // Write file
+               fseek(outfile, 0, SEEK_SET);
+               for(int i = 0; i < nRainbowChainCount; i++)
+               {
+                       fwrite(&pChain[i], 1, 16, outfile);
+                       fwrite(&pChain[i].nCheckPoint, 2, 1, outfile);
+               }
+               delete[] pChain;
+       }
+
+       fclose(outfile);
+    
+       // main loop - read characters, convert to UC, write
+    //
+
+    boinc_fraction_done(1);
+    boinc_finish(0);
+}
+
+#ifdef _WIN32
+int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
+    LPSTR command_line;
+    char* argv[100];
+    int argc;
+
+    command_line = GetCommandLine();
+    argc = parse_command_line( command_line, argv );
+    return main(argc, argv);
+}
+#endif
+
+const char *BOINC_RCSID_33ac47a071 = "$Id: upper_case.C 12135 2007-02-21 20:04:14Z davea $";
+
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.h b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.h
new file mode 100644 (file)
index 0000000..d360617
--- /dev/null
@@ -0,0 +1,29 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "boinc_api.h"
+
+struct UC_SHMEM {
+    double update_time;
+    double fraction_done;
+    double cpu_time;
+    BOINC_STATUS status;
+    int countdown;
+        // graphics app sets this to 5 repeatedly,
+        // main program decrements it once/sec.
+        // If it's zero, don't bother updating shmem
+};
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.ncb b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.ncb
new file mode 100644 (file)
index 0000000..50ed39d
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.ncb differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.sln b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.sln
new file mode 100644 (file)
index 0000000..24b2d5b
--- /dev/null
@@ -0,0 +1,62 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "distrrtgen", "distrrtgen.vcproj", "{A3BDF5F8-4D0A-4B27-B1D9-7E77CBDA86C7}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "index_calculator", "..\index_calculator\index_calculator.vcproj", "{C7A957CF-9FDC-4C72-9C3E-7C029E915D1E}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rti2rto", "..\..\standalone\rti2rto\rti2rto.vcproj", "{E0FBC06A-C902-4468-A614-CBF9F591AA7C}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "convertrti2", "..\..\standalone\converti2\converti2.vcproj", "{066FD6F1-5990-47AD-B095-7AE0029CF5AE}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rsearch", "..\..\standalone\rsearch\rsearch.vcproj", "{40F12861-0A31-4E0E-8324-24F897271C8E}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rtperfectp", "..\..\standalone\rtperfectp\rtperfectp.vcproj", "{9725038C-A07B-40DD-87CD-3A119021A244}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rcracki", "..\..\standalone\rcracki\rcracki.vcproj", "{966DA4B4-E13C-449D-9A93-303C6FEA25C4}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chain_checker", "..\chain_checker\chain_checker.vcproj", "{74C09EAC-2EA2-4548-9B61-0FEE56147DFE}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {A3BDF5F8-4D0A-4B27-B1D9-7E77CBDA86C7}.Debug|Win32.ActiveCfg = Debug|Win32
+               {A3BDF5F8-4D0A-4B27-B1D9-7E77CBDA86C7}.Debug|Win32.Build.0 = Debug|Win32
+               {A3BDF5F8-4D0A-4B27-B1D9-7E77CBDA86C7}.Release|Win32.ActiveCfg = Release|Win32
+               {A3BDF5F8-4D0A-4B27-B1D9-7E77CBDA86C7}.Release|Win32.Build.0 = Release|Win32
+               {C7A957CF-9FDC-4C72-9C3E-7C029E915D1E}.Debug|Win32.ActiveCfg = Debug|Win32
+               {C7A957CF-9FDC-4C72-9C3E-7C029E915D1E}.Debug|Win32.Build.0 = Debug|Win32
+               {C7A957CF-9FDC-4C72-9C3E-7C029E915D1E}.Release|Win32.ActiveCfg = Release|Win32
+               {C7A957CF-9FDC-4C72-9C3E-7C029E915D1E}.Release|Win32.Build.0 = Release|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Debug|Win32.ActiveCfg = Debug|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Debug|Win32.Build.0 = Debug|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Release|Win32.ActiveCfg = Release|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Release|Win32.Build.0 = Release|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Debug|Win32.ActiveCfg = Debug|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Debug|Win32.Build.0 = Debug|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Release|Win32.ActiveCfg = Release|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Release|Win32.Build.0 = Release|Win32
+               {40F12861-0A31-4E0E-8324-24F897271C8E}.Debug|Win32.ActiveCfg = Debug|Win32
+               {40F12861-0A31-4E0E-8324-24F897271C8E}.Debug|Win32.Build.0 = Debug|Win32
+               {40F12861-0A31-4E0E-8324-24F897271C8E}.Release|Win32.ActiveCfg = Release|Win32
+               {40F12861-0A31-4E0E-8324-24F897271C8E}.Release|Win32.Build.0 = Release|Win32
+               {9725038C-A07B-40DD-87CD-3A119021A244}.Debug|Win32.ActiveCfg = Debug|Win32
+               {9725038C-A07B-40DD-87CD-3A119021A244}.Debug|Win32.Build.0 = Debug|Win32
+               {9725038C-A07B-40DD-87CD-3A119021A244}.Release|Win32.ActiveCfg = Release|Win32
+               {9725038C-A07B-40DD-87CD-3A119021A244}.Release|Win32.Build.0 = Release|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Debug|Win32.ActiveCfg = Debug|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Debug|Win32.Build.0 = Debug|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Release|Win32.ActiveCfg = Release|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Release|Win32.Build.0 = Release|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Debug|Win32.ActiveCfg = Debug|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Debug|Win32.Build.0 = Debug|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Release|Win32.ActiveCfg = Release|Win32
+               {74C09EAC-2EA2-4548-9B61-0FEE56147DFE}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.suo b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.suo
new file mode 100644 (file)
index 0000000..afd4f0d
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.suo differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj
new file mode 100644 (file)
index 0000000..92f0648
--- /dev/null
@@ -0,0 +1,274 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="distrrtgen"
+       ProjectGUID="{A3BDF5F8-4D0A-4B27-B1D9-7E77CBDA86C7}"
+       RootNamespace="distrrtgen"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="196613"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="0"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="/boinc/lib;/boinc/api;&quot;/boinc/zip&quot;;&quot;/boinc/client/win&quot;;&quot;/boinc/&quot;;../../rt api"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_MT;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="1"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="libcmtd.lib libcpmtd.lib kernel32.lib user32.lib ole32.lib delayimp.lib ..\lib_debug\libboinc_staticcrt.lib ..\lib_debug\libboincapi_staticcrt.lib c:/openssl/lib/libeay32.lib"
+                               LinkIncremental="0"
+                               IgnoreAllDefaultLibraries="true"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="0"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               InlineFunctionExpansion="2"
+                               EnableIntrinsicFunctions="true"
+                               FavorSizeOrSpeed="1"
+                               WholeProgramOptimization="true"
+                               AdditionalIncludeDirectories="/boinc/lib;/boinc/api;&quot;/boinc/zip&quot;;&quot;/boinc/client/win&quot;;&quot;/boinc/&quot;;../../rt api"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_MT;_CONSOLE"
+                               RuntimeLibrary="0"
+                               EnableFunctionLevelLinking="true"
+                               EnableEnhancedInstructionSet="2"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="odbc32.lib odbccp32.lib libcmt.lib libcpmt.lib ..\lib_release\libboinc_staticcrt.lib ..\lib_release\libboincapi_staticcrt.lib c:/openssl/lib/libeay32.lib"
+                               LinkIncremental="0"
+                               IgnoreAllDefaultLibraries="true"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               RandomizedBaseAddress="1"
+                               DataExecutionPrevention="0"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_setkey.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\distrrtgen.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ecb_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\Public.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\distrrtgen.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\Public.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj.MWJ-PC.mwj.user b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj.MWJ-PC.mwj.user
new file mode 100644 (file)
index 0000000..15b19f6
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj.W-L-MWJ.Administrator.user b/BOINC software/BOINC client apps/distrrtgen/distrrtgen.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..621d7cb
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="lm lm-frt-cp437-850 1 7 0 20000 500000 302500000 15100,15400,15700,16000,16300,16600,16900,17200,17500,17800,18100,18400,18700,19000,19300,19600"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment="BOINC_HOME=C:\BOINC"
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/BOINC software/BOINC client apps/distrrtgen/result b/BOINC software/BOINC client apps/distrrtgen/result
new file mode 100644 (file)
index 0000000..e5cf1ea
Binary files /dev/null and b/BOINC software/BOINC client apps/distrrtgen/result differ
diff --git a/BOINC software/BOINC client apps/distrrtgen/stderr.txt b/BOINC software/BOINC client apps/distrrtgen/stderr.txt
new file mode 100644 (file)
index 0000000..61cbb07
--- /dev/null
@@ -0,0 +1,7 @@
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkContext.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkContext.cpp
new file mode 100644 (file)
index 0000000..03d3831
--- /dev/null
@@ -0,0 +1,584 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkContext.h"
+
+#include <ctype.h>
+#include <openssl/rand.h>
+#include <iostream>
+#include <string.h>
+#ifdef _WIN32
+       #pragma comment(lib, "libeay32.lib")
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+string CChainWalkContext::m_sHashRoutineName;
+HASHROUTINE CChainWalkContext::m_pHashRoutine;
+int CChainWalkContext::m_nHashLen;
+int CChainWalkContext::m_nPlainLenMinTotal = 0;
+int CChainWalkContext::m_nPlainLenMaxTotal = 0;
+int CChainWalkContext::m_nHybridCharset = 0;
+vector<stCharset> CChainWalkContext::m_vCharset;
+uint64 CChainWalkContext::m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];
+uint64 CChainWalkContext::m_nPlainSpaceTotal;
+unsigned char CChainWalkContext::m_Salt[MAX_SALT_LEN];
+int CChainWalkContext::m_nSaltLen = 0;
+int CChainWalkContext::m_nRainbowTableIndex;
+uint64 CChainWalkContext::m_nReduceOffset;
+
+//////////////////////////////////////////////////////////////////////
+
+CChainWalkContext::CChainWalkContext()
+{
+}
+
+CChainWalkContext::~CChainWalkContext()
+{
+}
+
+bool CChainWalkContext::LoadCharset(string sName)
+{
+       m_vCharset.clear();
+       if (sName == "byte")
+       {
+               stCharset tCharset;
+               int i;
+               for (i = 0x00; i <= 0xff; i++)
+                       tCharset.m_PlainCharset[i] = i;
+               tCharset.m_nPlainCharsetLen = 256;
+               tCharset.m_sPlainCharsetName = sName;
+               tCharset.m_sPlainCharsetContent = "0x00, 0x01, ... 0xff";
+               m_vCharset.push_back(tCharset);
+               return true;
+       }
+       if(sName.substr(0, 6) == "hybrid") // Hybrid charset consisting of 2 charsets
+       {
+               m_nHybridCharset = 1;           
+       }
+       else
+       {
+               m_nHybridCharset = 0;
+       }
+       vector<string> vLine;
+       if (ReadLinesFromFile("charset.txt", vLine))
+       {
+               int i;
+               for (i = 0; i < vLine.size(); i++)
+               {
+                       // Filter comment
+                       if (vLine[i][0] == '#')
+                               continue;
+
+                       vector<string> vPart;
+                       if (SeperateString(vLine[i], "=", vPart))
+                       {
+                               // sCharsetName
+                               string sCharsetName = TrimString(vPart[0]);
+                               if (sCharsetName == "")
+                                       continue;
+                                                               
+                               // sCharsetName charset check
+                               bool fCharsetNameCheckPass = true;
+                               int j;
+                               for (j = 0; j < sCharsetName.size(); j++)
+                               {
+                                       if (   !isalpha(sCharsetName[j])
+                                               && !isdigit(sCharsetName[j])
+                                               && (sCharsetName[j] != '-'))
+                                       {
+                                               fCharsetNameCheckPass = false;
+                                               break;
+                                       }
+                               }
+                               if (!fCharsetNameCheckPass)
+                               {
+                                       printf("invalid charset name %s in charset configuration file\n", sCharsetName.c_str());
+                                       continue;
+                               }
+
+                               // sCharsetContent
+                               string sCharsetContent = TrimString(vPart[1]);
+                               if (sCharsetContent == "" || sCharsetContent == "[]")
+                                       continue;
+                               if (sCharsetContent[0] != '[' || sCharsetContent[sCharsetContent.size() - 1] != ']')
+                               {
+                                       printf("invalid charset content %s in charset configuration file\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+                               sCharsetContent = sCharsetContent.substr(1, sCharsetContent.size() - 2);
+                               if (sCharsetContent.size() > 256)
+                               {
+                                       printf("charset content %s too long\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+
+                               //printf("%s = [%s]\n", sCharsetName.c_str(), sCharsetContent.c_str());
+
+                               // Is it the wanted charset?
+                               if(m_nHybridCharset == 1)
+                               {
+                                       vector<tCharset> vCharsets;
+                                       GetHybridCharsets(sName, vCharsets);
+                                       if(sCharsetName == vCharsets[m_vCharset.size()].sName)
+                                       {
+                                               stCharset tCharset = {0};
+                                               tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                               memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                               tCharset.m_sPlainCharsetName = sCharsetName;
+                                               tCharset.m_sPlainCharsetContent = sCharsetContent;      
+                                               tCharset.m_nPlainLenMin = vCharsets[m_vCharset.size()].nPlainLenMin;
+                                               tCharset.m_nPlainLenMax = vCharsets[m_vCharset.size()].nPlainLenMax;
+                                               m_vCharset.push_back(tCharset);
+                                               if(vCharsets.size() == m_vCharset.size())
+                                                       return true;
+                                               i = 0; // Start the lookup over again for the next charset
+                                       }                                               
+                               }
+                               else if (sCharsetName == sName)
+                               {
+                                       stCharset tCharset;
+                                       tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                       memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                       tCharset.m_sPlainCharsetName = sCharsetName;
+                                       tCharset.m_sPlainCharsetContent = sCharsetContent;                                                      
+                                       m_vCharset.push_back(tCharset);
+                                       return true;
+                               }
+                       }
+               }
+               printf("charset %s not found in charset.txt\n", sName.c_str());
+       }
+       else
+               printf("can't open charset configuration file\n");
+       return false;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+bool CChainWalkContext::SetHashRoutine(string sHashRoutineName)
+{
+       CHashRoutine hr;
+       hr.GetHashRoutine(sHashRoutineName, m_pHashRoutine, m_nHashLen);
+       if (m_pHashRoutine != NULL)
+       {
+               m_sHashRoutineName = sHashRoutineName;
+               return true;
+       }
+       else
+               return false;
+}
+
+bool CChainWalkContext::SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax)
+{
+       // m_PlainCharset, m_nPlainCharsetLen, m_sPlainCharsetName, m_sPlainCharsetContent
+       if (!LoadCharset(sCharsetName))
+               return false;
+
+       if(m_vCharset.size() == 1) // Not hybrid charset
+       {
+               // m_nPlainLenMin, m_nPlainLenMax
+               if (nPlainLenMin < 1 || nPlainLenMax > MAX_PLAIN_LEN || nPlainLenMin > nPlainLenMax)
+               {
+                       printf("invalid plaintext length range: %d - %d\n", nPlainLenMin, nPlainLenMax);
+                       return false;
+               }
+               m_vCharset[0].m_nPlainLenMin = nPlainLenMin;
+               m_vCharset[0].m_nPlainLenMax = nPlainLenMax;
+       }
+       // m_nPlainSpaceUpToX
+       m_nPlainSpaceUpToX[0] = 0;
+       m_nPlainLenMaxTotal = 0;
+       m_nPlainLenMinTotal = 0;
+       uint64 nTemp = 1;
+       int j, k = 1;
+       for(j = 0; j < m_vCharset.size(); j++)
+       {
+               int i;
+               m_nPlainLenMaxTotal += m_vCharset[j].m_nPlainLenMax;
+               m_nPlainLenMinTotal += m_vCharset[j].m_nPlainLenMin;
+               for (i = 1; i <= m_vCharset[j].m_nPlainLenMax; i++)
+               {                       
+                       nTemp *= m_vCharset[j].m_nPlainCharsetLen;
+                       if (i < m_vCharset[j].m_nPlainLenMin)
+                               m_nPlainSpaceUpToX[k] = 0;
+                       else
+                               m_nPlainSpaceUpToX[k] = m_nPlainSpaceUpToX[k - 1] + nTemp;
+                       k++;
+               }               
+       }
+       // m_nPlainSpaceTotal
+       m_nPlainSpaceTotal = m_nPlainSpaceUpToX[m_nPlainLenMaxTotal];
+
+       return true;
+}
+
+bool CChainWalkContext::SetRainbowTableIndex(int nRainbowTableIndex)
+{
+       if (nRainbowTableIndex < 0)
+               return false;
+       m_nRainbowTableIndex = nRainbowTableIndex;
+       m_nReduceOffset = 65536 * nRainbowTableIndex;
+
+       return true;
+}
+
+bool CChainWalkContext::SetSalt(unsigned char *Salt, int nSaltLength)
+{
+       memcpy(&m_Salt[0], Salt, nSaltLength);
+       
+       m_nSaltLen = nSaltLength;
+//     m_sSalt = sSalt;
+       return true;
+}
+
+bool CChainWalkContext::SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount)
+{
+       // something like lm_alpha#1-7_0_100x16_test.rt
+
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       if (nIndex != -1)
+               sPathName = sPathName.substr(nIndex + 1);
+
+       if (sPathName.size() < 3)
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+       if (sPathName.substr(sPathName.size() - 3) != ".rt")
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+
+       // Parse
+       vector<string> vPart;
+       if (!SeperateString(sPathName, "___x_", vPart))
+       {
+               printf("filename %s not identified\n", sPathName.c_str());
+               return false;
+       }
+
+       string sHashRoutineName   = vPart[0];
+       int nRainbowTableIndex    = atoi(vPart[2].c_str());
+       nRainbowChainLen          = atoi(vPart[3].c_str());
+       nRainbowChainCount        = atoi(vPart[4].c_str());
+
+       // Parse charset definition
+       string sCharsetDefinition = vPart[1];
+       string sCharsetName;
+       int nPlainLenMin = 0, nPlainLenMax = 0;         
+
+       //printf("Charset: %s", sCharsetDefinition.c_str());
+       
+       if(sCharsetDefinition.substr(0, 6) == "hybrid") // Hybrid table
+       {
+               sCharsetName = sCharsetDefinition;
+       }
+       else
+       {
+               if (sCharsetDefinition.find('#') == -1)         // For backward compatibility, "#1-7" is implied
+               {                       
+                       sCharsetName = sCharsetDefinition;
+                       nPlainLenMin = 1;
+                       nPlainLenMax = 7;
+               }
+               else
+               {
+                       vector<string> vCharsetDefinitionPart;
+                       if (!SeperateString(sCharsetDefinition, "#-", vCharsetDefinitionPart))
+                       {
+                               printf("filename %s not identified\n", sPathName.c_str());
+                               return false;   
+                       }
+                       else
+                       {
+                               sCharsetName = vCharsetDefinitionPart[0];
+                               nPlainLenMin = atoi(vCharsetDefinitionPart[1].c_str());
+                               nPlainLenMax = atoi(vCharsetDefinitionPart[2].c_str());
+                       }
+               }
+       }
+       // Setup
+       if (!SetHashRoutine(sHashRoutineName))
+       {
+               printf("hash routine %s not supported\n", sHashRoutineName.c_str());
+               return false;
+       }
+       if (!SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+               return false;
+       if (!SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               printf("invalid rainbow table index %d\n", nRainbowTableIndex);
+               return false;
+       }
+
+       return true;
+}
+
+string CChainWalkContext::GetHashRoutineName()
+{
+       return m_sHashRoutineName;
+}
+
+int CChainWalkContext::GetHashLen()
+{
+       return m_nHashLen;
+}
+
+string CChainWalkContext::GetPlainCharsetName()
+{
+       return m_vCharset[0].m_sPlainCharsetName;
+}
+
+string CChainWalkContext::GetPlainCharsetContent()
+{
+       return m_vCharset[0].m_sPlainCharsetContent;
+}
+
+int CChainWalkContext::GetPlainLenMin()
+{
+       return m_vCharset[0].m_nPlainLenMin;
+}
+
+int CChainWalkContext::GetPlainLenMax()
+{
+       return m_vCharset[0].m_nPlainLenMax;
+}
+
+uint64 CChainWalkContext::GetPlainSpaceTotal()
+{
+       return m_nPlainSpaceTotal;
+}
+
+int CChainWalkContext::GetRainbowTableIndex()
+{
+       return m_nRainbowTableIndex;
+}
+
+void CChainWalkContext::Dump()
+{
+       printf("hash routine: %s\n", m_sHashRoutineName.c_str());
+       printf("hash length: %d\n", m_nHashLen);
+
+       printf("plain charset: ");
+       int i;
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+       {
+               if (isprint(m_vCharset[0].m_PlainCharset[i]))
+                       printf("%c", m_vCharset[0].m_PlainCharset[i]);
+               else
+                       printf("?");
+       }
+       printf("\n");
+
+       printf("plain charset in hex: ");
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+               printf("%02x ", m_vCharset[0].m_PlainCharset[i]);
+       printf("\n");
+
+       printf("plain length range: %d - %d\n", m_vCharset[0].m_nPlainLenMin, m_vCharset[0].m_nPlainLenMax);
+       printf("plain charset name: %s\n", m_vCharset[0].m_sPlainCharsetName.c_str());
+       //printf("plain charset content: %s\n", m_sPlainCharsetContent.c_str());
+       //for (i = 0; i <= m_nPlainLenMax; i++)
+       //      printf("plain space up to %d: %s\n", i, uint64tostr(m_nPlainSpaceUpToX[i]).c_str());
+       printf("plain space total: %s\n", uint64tostr(m_nPlainSpaceTotal).c_str());
+
+       printf("rainbow table index: %d\n", m_nRainbowTableIndex);
+       printf("reduce offset: %s\n", uint64tostr(m_nReduceOffset).c_str());
+       printf("\n");
+}
+
+void CChainWalkContext::SetIndex(uint64 nIndex)
+{
+       m_nIndex = nIndex;
+}
+
+void CChainWalkContext::SetHash(unsigned char* pHash)
+{
+       memcpy(m_Hash, pHash, m_nHashLen);
+}
+
+void CChainWalkContext::IndexToPlain()
+{
+       int i;
+       m_nPlainLen = 0;
+       for (i = m_nPlainLenMaxTotal - 1; i >= m_nPlainLenMinTotal - 1; i--)
+       {
+               if (m_nIndex >= m_nPlainSpaceUpToX[i])
+               {
+                       m_nPlainLen = i + 1;
+                       break;
+               }
+       }
+       if(m_nPlainLen == 0)
+               m_nPlainLen = m_nPlainLenMinTotal;
+       uint64 nIndexOfX = m_nIndex - m_nPlainSpaceUpToX[m_nPlainLen - 1];
+
+#ifdef _WIN64
+       
+       // Slow version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_vCharset[j].m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                       }
+               }
+       }
+#else
+
+
+       // Fast version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+#ifdef _WIN32
+               if (nIndexOfX < 0x100000000I64)
+                       break;
+#else
+               if (nIndexOfX < 0x100000000llu)
+                       break;
+#endif
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_vCharset[j].m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                               break;
+                       }
+               }
+       }
+
+       unsigned int nIndexOfX32 = (unsigned int)nIndexOfX;
+       for (; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+
+//             m_Plain[i] = m_PlainCharset[nIndexOfX32 % m_vCharset[j].m_nPlainCharsetLen];
+//             nIndexOfX32 /= m_vCharset[j].m_nPlainCharsetLen;
+
+               unsigned int nPlainCharsetLen = m_vCharset[j].m_nPlainCharsetLen;
+               unsigned int volatile nTemp;
+#ifdef _WIN32
+               __asm
+               {
+                       mov eax, nIndexOfX32
+                       xor edx, edx
+                       div nPlainCharsetLen
+                       mov nIndexOfX32, eax
+                       mov nTemp, edx
+               }
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#else
+               __asm__ __volatile__ (  "mov %2, %%eax;"
+                                                               "xor %%edx, %%edx;"
+                                                               "divl %3;"
+                                                               "mov %%eax, %0;"
+                                                               "mov %%edx, %1;"
+                                                               : "=m"(nIndexOfX32), "=m"(nTemp)
+                                                               : "m"(nIndexOfX32), "m"(nPlainCharsetLen)
+                                                               : "%eax", "%edx"
+                                                        );
+                                                        
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#endif
+               break;
+                       }
+               }
+       }
+#endif
+}
+
+void CChainWalkContext::PlainToHash()
+{      
+       m_pHashRoutine(m_Plain, m_nPlainLen, m_Hash);
+}
+
+void CChainWalkContext::HashToIndex(int nPos)
+{
+       m_nIndex = (*(uint64*)m_Hash + m_nReduceOffset + nPos) % m_nPlainSpaceTotal;
+}
+
+uint64 CChainWalkContext::GetIndex()
+{
+       return m_nIndex;
+}
+const uint64 *CChainWalkContext::GetIndexPtr()
+{
+       return &m_nIndex;
+}
+
+string CChainWalkContext::GetPlain()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < m_nPlainLen; i++)
+       {
+               char c = m_Plain[i];
+               if (c >= 32 && c <= 126)
+                       sRet += c;
+               else
+                       sRet += '?';
+       }
+       
+       return sRet;
+}
+
+string CChainWalkContext::GetBinary()
+{
+       return HexToStr(m_Plain, m_nPlainLen);
+}
+/*
+string CChainWalkContext::GetPlainBinary()
+{
+       string sRet;
+       sRet += GetPlain();
+       int i;
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += ' ';
+
+       sRet += "|";
+
+       sRet += GetBinary();
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += "  ";
+
+       return sRet;
+}
+*/
+string CChainWalkContext::GetHash()
+{
+       return HexToStr(m_Hash, m_nHashLen);
+}
+
+bool CChainWalkContext::CheckHash(unsigned char* pHash)
+{
+       if (memcmp(m_Hash, pHash, m_nHashLen) == 0)
+               return true;
+
+       return false;
+}
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkContext.h b/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkContext.h
new file mode 100644 (file)
index 0000000..7348cdf
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKCONTEXT_H
+#define _CHAINWALKCONTEXT_H
+
+#include "HashRoutine.h"
+#include "Public.h"
+
+typedef struct 
+{
+       unsigned char m_PlainCharset[255];
+       int m_nPlainCharsetLen;
+       int m_nPlainLenMin;
+       int m_nPlainLenMax;
+       string m_sPlainCharsetName;
+       string m_sPlainCharsetContent;
+} stCharset;
+class CChainWalkContext 
+{
+public:
+       CChainWalkContext();
+       virtual ~CChainWalkContext();
+
+private:
+       static string m_sHashRoutineName;       
+       static HASHROUTINE m_pHashRoutine;                                                      // Configuration
+       static int m_nHashLen;                                                                          // Configuration
+
+//     static unsigned char m_PlainCharset[256];                                       // Configuration
+//     static unsigned char m_PlainCharset2[256];                                      // Configuration
+       static vector<stCharset> m_vCharset;
+       static int m_nPlainLenMinTotal, m_nPlainLenMaxTotal;
+       static uint64 m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];            // Performance consideration
+       static uint64 m_nPlainSpaceTotal;                                                       // Performance consideration
+       static int m_nHybridCharset;
+       static int m_nRainbowTableIndex;                                                        // Configuration
+       static uint64 m_nReduceOffset;                                                          // Performance consideration
+
+       // Context
+       uint64 m_nIndex;
+       unsigned char m_Plain[MAX_PLAIN_LEN];
+       int m_nPlainLen;
+       unsigned char m_Hash[MAX_HASH_LEN];
+       static unsigned char m_Salt[MAX_SALT_LEN];
+       static int m_nSaltLen;
+private:
+       static bool LoadCharset(string sCharset);
+
+public:
+       static bool SetHashRoutine(string sHashRoutineName);                                                                                            // Configuration
+       static bool SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax);                           // Configuration
+       static bool SetRainbowTableIndex(int nRainbowTableIndex);       
+       static bool SetSalt(unsigned char *Salt, int nSaltLength);// Configuration
+       static bool SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount);        // Wrapper
+       static string GetHashRoutineName();
+       static int GetHashLen();
+       static string GetPlainCharsetName();
+       static string GetPlainCharsetContent();
+       static int GetPlainLenMin();
+       static int GetPlainLenMax();
+       static uint64 GetPlainSpaceTotal();
+       static int GetRainbowTableIndex();
+       static void Dump();
+
+       void SetIndex(uint64 nIndex);
+       void SetHash(unsigned char* pHash);             // The length should be m_nHashLen
+
+       void IndexToPlain();
+       void PlainToHash();
+       void HashToIndex(int nPos);
+
+       uint64 GetIndex();
+       const uint64* GetIndexPtr();
+       string GetPlain();
+       string GetBinary();
+//     string GetPlainBinary();
+       string GetHash();
+       bool CheckHash(unsigned char* pHash);   // The length should be m_nHashLen
+};
+
+#endif
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkSet.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkSet.cpp
new file mode 100644 (file)
index 0000000..a081eb8
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkSet.h"
+
+CChainWalkSet::CChainWalkSet()
+{
+       m_sHashRoutineName   = "";
+       m_sPlainCharsetName  = "";
+       m_nPlainLenMin       = 0;
+       m_nPlainLenMax       = 0;
+       m_nRainbowTableIndex = 0;
+       m_nRainbowChainLen   = 0;
+}
+
+CChainWalkSet::~CChainWalkSet()
+{
+       DiscardAll();
+}
+
+void CChainWalkSet::DiscardAll()
+{
+       //printf("debug: discarding all walk...\n");
+
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+               delete it->pIndexE;
+       m_lChainWalk.clear();
+}
+
+uint64* CChainWalkSet::RequestWalk(unsigned char* pHash, int nHashLen,
+                                                                  string sHashRoutineName,
+                                                                  string sPlainCharsetName, int nPlainLenMin, int nPlainLenMax, 
+                                                                  int nRainbowTableIndex, 
+                                                                  int nRainbowChainLen,
+                                                                  bool& fNewlyGenerated)
+{
+       if (   m_sHashRoutineName   != sHashRoutineName
+               || m_sPlainCharsetName  != sPlainCharsetName
+               || m_nPlainLenMin       != nPlainLenMin
+               || m_nPlainLenMax       != nPlainLenMax
+               || m_nRainbowTableIndex != nRainbowTableIndex
+               || m_nRainbowChainLen   != nRainbowChainLen)
+       {
+               DiscardAll();
+
+               m_sHashRoutineName   = sHashRoutineName;
+               m_sPlainCharsetName  = sPlainCharsetName;
+               m_nPlainLenMin       = nPlainLenMin;
+               m_nPlainLenMax       = nPlainLenMax;
+               m_nRainbowTableIndex = nRainbowTableIndex;
+               m_nRainbowChainLen   = nRainbowChainLen;
+
+               ChainWalk cw;
+               memcpy(cw.Hash, pHash, nHashLen);
+               cw.pIndexE = new uint64[nRainbowChainLen - 1];
+               m_lChainWalk.push_back(cw);
+
+               fNewlyGenerated = true;
+               return cw.pIndexE;
+       }
+
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+       {
+               if (memcmp(it->Hash, pHash, nHashLen) == 0)
+               {
+                       fNewlyGenerated = false;
+                       return it->pIndexE;
+               }
+       }
+
+       ChainWalk cw;
+       memcpy(cw.Hash, pHash, nHashLen);
+       cw.pIndexE = new uint64[nRainbowChainLen - 1];
+       m_lChainWalk.push_back(cw);
+
+       fNewlyGenerated = true;
+       return cw.pIndexE;
+}
+
+void CChainWalkSet::DiscardWalk(uint64* pIndexE)
+{
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+       {
+               if (it->pIndexE == pIndexE)
+               {
+                       delete it->pIndexE;
+                       m_lChainWalk.erase(it);
+                       return;
+               }
+       }
+
+       printf("debug: pIndexE not found\n");
+}
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkSet.h b/BOINC software/BOINC client apps/distrrtgen/tmp/ChainWalkSet.h
new file mode 100644 (file)
index 0000000..4276894
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKSET_H
+#define _CHAINWALKSET_H
+
+#include "Public.h"
+
+struct ChainWalk
+{
+       unsigned char Hash[MAX_HASH_LEN];
+       //int nHashLen;         // Implied
+       uint64* pIndexE;        // mapStartPosIndexE, Len = nRainbowChainLen - 1
+};
+
+class CChainWalkSet
+{
+public:
+       CChainWalkSet();
+       virtual ~CChainWalkSet();
+
+private:
+       string m_sHashRoutineName;              // Discard all if not match
+       string m_sPlainCharsetName;             // Discard all if not match
+       int    m_nPlainLenMin;                  // Discard all if not match
+       int    m_nPlainLenMax;                  // Discard all if not match
+       int    m_nRainbowTableIndex;    // Discard all if not match
+       int    m_nRainbowChainLen;              // Discard all if not match
+       list<ChainWalk> m_lChainWalk;
+
+private:
+       void DiscardAll();
+
+public:
+       uint64* RequestWalk(unsigned char* pHash, int nHashLen,
+                                               string sHashRoutineName,
+                                               string sPlainCharsetName, int nPlainLenMin, int nPlainLenMax, 
+                                               int nRainbowTableIndex, 
+                                               int nRainbowChainLen,
+                                               bool& fNewlyGenerated);
+       void DiscardWalk(uint64* pIndexE);
+};
+
+#endif
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/HashAlgorithm.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/HashAlgorithm.cpp
new file mode 100644 (file)
index 0000000..6573620
--- /dev/null
@@ -0,0 +1,357 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "HashAlgorithm.h"
+
+#include "Public.h"
+#include <string.h>
+#include "md4.h"
+#include "md5.h"
+#include "des.h"
+#define MSCACHE_HASH_SIZE 16
+void setup_des_key(unsigned char key_56[], des_key_schedule &ks)
+{
+       des_cblock key;
+
+       key[0] = key_56[0];
+       key[1] = (key_56[0] << 7) | (key_56[1] >> 1);
+       key[2] = (key_56[1] << 6) | (key_56[2] >> 2);
+       key[3] = (key_56[2] << 5) | (key_56[3] >> 3);
+       key[4] = (key_56[3] << 4) | (key_56[4] >> 4);
+       key[5] = (key_56[4] << 3) | (key_56[5] >> 5);
+       key[6] = (key_56[5] << 2) | (key_56[6] >> 6);
+       key[7] = (key_56[6] << 1);
+
+       //des_set_odd_parity(&key);
+       des_set_key(&key, ks);
+}
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       /*
+       unsigned char data[7] = {0};
+       memcpy(data, pPlain, nPlainLen > 7 ? 7 : nPlainLen);
+       */
+
+       int i;
+       for (i = nPlainLen; i < 7; i++)
+               pPlain[i] = 0;
+
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       des_key_schedule ks;
+       //setup_des_key(data, ks);
+       setup_des_key(pPlain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pHash, ks, DES_ENCRYPT);
+}
+
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char pass[14];
+       unsigned char pre_lmresp[21];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+       des_key_schedule ks;
+
+       memset (pass,0,sizeof(pass));
+       memset (pre_lmresp,0,sizeof(pre_lmresp));
+
+       memcpy (pass,pPlain, nPlainLen);
+
+       setup_des_key(pass, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(&pass[7], ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)&pre_lmresp[8], ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[7], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[14], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+
+} 
+
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{      
+       unsigned char pre_lmresp[8];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char salt[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+       des_key_schedule ks;
+       unsigned char plain[8] = {0};   
+       memcpy(plain, pPlain, nPlainLen);
+       setup_des_key(plain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)salt, (des_cblock*)pHash, ks, DES_ENCRYPT);
+} 
+
+
+
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+  unsigned char UnicodePlain[MAX_PLAIN_LEN];
+  static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+  
+  int len = (nPlainLen < 127) ? nPlainLen : 127;
+  int i;
+  
+  for (i = 0; i < len; i++)
+  {
+    UnicodePlain[i * 2] = pPlain[i];
+    UnicodePlain[i * 2 + 1] = 0x00;
+  }
+
+  des_key_schedule ks;
+  unsigned char lm[21];
+
+  MD4_NEW(UnicodePlain, len * 2, lm);
+  lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
+
+  setup_des_key(lm, ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[7], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[14], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+}
+
+/*
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char ToEncrypt[256];
+       char temp[256];
+       char username[256];
+
+       DES_cblock iv,iv2;
+       DES_key_schedule ks1,ks2;
+       unsigned char deskey_fixed[]={ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
+       int i,j;
+#ifdef _WIN32
+       strcpy_s(username, sizeof(username), "SYS");
+#else
+       strcpy(username, "SYS");
+#endif
+       int userlen = 3;
+#ifdef _WIN32
+       _strupr((char*) pPlain);
+#else
+       strupr((char*) pPlain);
+#endif
+       memset (ToEncrypt,0,sizeof(ToEncrypt));
+
+       for (i=1,j=0; j<userlen; i++,j++)
+       {
+               ToEncrypt[i] = username[j];
+               i++;
+       }
+
+       for (j=0; j<nPlainLen; i++,j++)
+       {
+               ToEncrypt[i] = pPlain[j];
+               i++;
+       }
+
+       i=i-1;
+       memset (iv,0,8);
+       memset (iv2,0,8);
+       DES_set_key((DES_cblock*) deskey_fixed, &ks1);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks1, &iv, DES_ENCRYPT);
+       DES_set_key((DES_cblock*) &iv, &ks2);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks2, &iv2, DES_ENCRYPT);
+       memcpy (pHash,iv2,8);
+}
+*/
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char UnicodePlain[MAX_PLAIN_LEN * 2];
+       int i;
+       for (i = 0; i < nPlainLen; i++)
+       {
+               UnicodePlain[i * 2] = pPlain[i];
+               UnicodePlain[i * 2 + 1] = 0x00;
+       }
+
+       MD4_NEW(UnicodePlain, nPlainLen * 2, pHash);
+}
+/*
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD2(pPlain, nPlainLen, pHash);
+}
+*/
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD4_NEW(pPlain, nPlainLen, pHash);
+}
+
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5_NEW(pPlain, nPlainLen, pHash);
+}
+void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5_NEW(pPlain, nPlainLen, pHash);
+       unsigned char hash[16];
+       memcpy(hash, pHash, 16);
+       MD5_NEW(hash, 16, pHash);
+}
+/*
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       SHA1(pPlain, nPlainLen, pHash);
+}
+
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       RIPEMD160(pPlain, nPlainLen, pHash);
+}
+
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char unicode_pwd[256];
+       char unicode_user[256];
+       static unsigned char username[] = "administrator";
+       static int userlen = 13;
+       unsigned char   final1[MD4_DIGEST_LENGTH];
+       MD4_CTX ctx;
+       int i;
+
+//     strcpy (username, "administrator");
+//     userlen = 13;
+
+       for (i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }
+
+       for (i=0; i<userlen; i++)
+       {
+               unicode_user[i*2] = username[i];
+               unicode_user[i*2+1] = 0x00;
+       }
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,unicode_pwd,nPlainLen*2);
+       MD4_Final(final1,&ctx);
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,final1,MD4_DIGEST_LENGTH);
+       MD4_Update(&ctx,(unsigned char*) unicode_user,userlen*2);
+       MD4_Final(pHash,&ctx);
+
+       /*
+       unsigned char unicode_pwd[256];
+       for (int i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }*/     
+       /*
+       unsigned char *buf = (unsigned char*)calloc(MSCACHE_HASH_SIZE + nSaltLength, sizeof(unsigned char));    
+       HashNTLM(pPlain, nPlainLen, buf, NULL);
+       //MD4(unicode_pwd, nPlainLen*2, buf);
+       memcpy(buf + MSCACHE_HASH_SIZE, pSalt, nSaltLength);
+       MD4(buf, MSCACHE_HASH_SIZE + nSaltLength, pHash); 
+       free(buf);
+       */
+//}
+
+//*********************************************************************************
+// Code for MySQL password hashing
+//*********************************************************************************
+/*
+inline void mysql_hash_password_323(unsigned long *result, const char *password) 
+{
+  register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
+  unsigned long tmp;
+  for (; *password ; password++) 
+  {
+    if (*password == ' ' || *password == '\t') continue;
+       tmp= (unsigned long) (unsigned char) *password;
+       nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
+       nr2+=(nr2 << 8) ^ nr;
+       add+=tmp;
+  }
+  result[0]=nr & (((unsigned long) 1L << 31) -1L); ;
+  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
+  return;
+}
+
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned long hash_pass[2];     
+       unsigned char* f = (unsigned char*) hash_pass;
+
+       unsigned char* pass = (unsigned char*) calloc (nPlainLen+4,sizeof(unsigned char));
+       memcpy(pass,pPlain,nPlainLen);
+
+       mysql_hash_password_323(hash_pass, (char*) pass);
+       pHash[0]=*(f+3); pHash[1]=*(f+2); pHash[2]=*(f+1); pHash[3]=*(f+0);
+       pHash[4]=*(f+7); pHash[5]=*(f+6); pHash[6]=*(f+5); pHash[7]=*(f+4);
+
+       free (pass);
+}
+
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char hash_stage1[SHA_DIGEST_LENGTH];
+       SHA_CTX ctx;
+
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, (unsigned char *) pPlain, nPlainLen);
+       SHA1_Final(hash_stage1, &ctx);
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, hash_stage1, SHA_DIGEST_LENGTH);
+       SHA1_Final(pHash, &ctx);
+}
+*/
+//*********************************************************************************
+// Code for PIX password hashing
+//*********************************************************************************
+static char itoa64[] =          /* 0 ... 63 => ascii - 64 */
+        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void _crypt_to64(char *s, unsigned long v, int n)
+{
+        while (--n >= 0) {
+                *s++ = itoa64[v&0x3f];
+                v >>= 6;
+        }
+}
+/*
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char temp[MD5_DIGEST_LENGTH+1];
+       unsigned char final[MD5_DIGEST_LENGTH];
+       char* pass = (char*) calloc (nPlainLen+MD5_DIGEST_LENGTH,sizeof(char));
+
+       memcpy (pass,pPlain,nPlainLen);
+
+       MD5_CTX ctx;
+       MD5_Init(&ctx);
+       MD5_Update(&ctx, (unsigned char *) pass, MD5_DIGEST_LENGTH);
+       MD5_Final(final, &ctx);
+
+       char* p = (char*) temp;
+       _crypt_to64(p,*(unsigned long*) (final+0),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+4),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+8),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+12),4); p += 4;
+       *p=0;
+
+       memcpy(pHash,temp,MD5_DIGEST_LENGTH);
+
+       free (pass);
+}
+*/
\ No newline at end of file
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/HashAlgorithm.h b/BOINC software/BOINC client apps/distrrtgen/tmp/HashAlgorithm.h
new file mode 100644 (file)
index 0000000..667245a
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHALGORITHM_H
+#define _HASHALGORITHM_H
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+//void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+/*void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash);
+//****************************************************************************
+// MySQL Password Hashing
+//****************************************************************************
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// Cisco PIX Password Hashing
+//****************************************************************************
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+*/
+//****************************************************************************
+// (HALF) LM CHALL hashing
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+// From mao
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+//void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+#endif
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/HashRoutine.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/HashRoutine.cpp
new file mode 100644 (file)
index 0000000..496f399
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "HashRoutine.h"
+#include "HashAlgorithm.h"
+
+//////////////////////////////////////////////////////////////////////
+
+CHashRoutine::CHashRoutine()
+{
+       // Notice: MIN_HASH_LEN <= nHashLen <= MAX_HASH_LEN
+
+
+       AddHashRoutine("lm",   HashLM,   8);
+       AddHashRoutine("ntlm", HashNTLM, 16);
+//     AddHashRoutine("md2",  HashMD2,  16);
+       AddHashRoutine("md4",  HashMD4,  16);
+       AddHashRoutine("md5",  HashMD5,  16);
+       AddHashRoutine("doublemd5",  HashDoubleMD5,  16);
+/*     AddHashRoutine("sha1", HashSHA1, 20);
+       AddHashRoutine("ripemd160", HashRIPEMD160, 20);
+       AddHashRoutine("mysql323", HashMySQL323, 8);
+       AddHashRoutine("mysqlsha1", HashMySQLSHA1, 20);
+       AddHashRoutine("ciscopix", HashPIX, 16);*/
+//     AddHashRoutine("mscache", HashMSCACHE, 16);
+       AddHashRoutine("halflmchall", HashHALFLMCHALL, 8);
+
+       // Added from mao
+       AddHashRoutine("lmchall", HashLMCHALL, 24);
+       AddHashRoutine("ntlmchall", HashNTLMCHALL, 24);
+//     AddHashRoutine("oracle", HashORACLE, 8);
+
+}
+
+CHashRoutine::~CHashRoutine()
+{
+}
+
+void CHashRoutine::AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen)
+{
+       vHashRoutineName.push_back(sHashRoutineName);
+       vHashRoutine.push_back(pHashRoutine);
+       vHashLen.push_back(nHashLen);
+}
+
+string CHashRoutine::GetAllHashRoutineName()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+               sRet += vHashRoutineName[i] + " ";
+
+       return sRet;
+}
+
+void CHashRoutine::GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+       {
+               if (sHashRoutineName == vHashRoutineName[i])
+               {
+                       pHashRoutine = vHashRoutine[i];
+                       nHashLen = vHashLen[i];
+                       return;
+               }
+       }
+
+       pHashRoutine = NULL;
+       nHashLen = 0;
+}
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/HashRoutine.h b/BOINC software/BOINC client apps/distrrtgen/tmp/HashRoutine.h
new file mode 100644 (file)
index 0000000..681fa78
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHROUTINE_H
+#define _HASHROUTINE_H
+
+#include <string>
+#include <vector>
+using namespace std;
+
+typedef void (*HASHROUTINE)(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+class CHashRoutine  
+{
+public:
+       CHashRoutine();
+       virtual ~CHashRoutine();
+
+private:
+       vector<string>          vHashRoutineName;
+       vector<HASHROUTINE>     vHashRoutine;
+       vector<int>                     vHashLen;
+       void AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen);
+
+public:
+       string GetAllHashRoutineName();
+       void GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen);
+};
+
+#endif
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/Public.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/Public.cpp
new file mode 100644 (file)
index 0000000..c7c6823
--- /dev/null
@@ -0,0 +1,242 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#ifdef _WIN32
+#include "boinc_win.h"
+#else
+#include "config.h"
+#include <cstdio>
+#include <cctype>
+#include <ctime>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+#include <unistd.h>
+
+#endif
+#include "filesys.h"
+#include "boinc_api.h"
+
+#include "Public.h"
+#ifdef _WIN32
+       #include <windows.h>
+#else
+       #include <sys/sysinfo.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+unsigned int GetFileLen(FILE* file)
+{
+       unsigned int pos = ftell(file);
+       fseek(file, 0, SEEK_END);
+       unsigned int len = ftell(file);
+       fseek(file, pos, SEEK_SET);
+
+       return len;
+}
+
+string TrimString(string s)
+{
+       while (s.size() > 0)
+       {
+               if (s[0] == ' ' || s[0] == '\t')
+                       s = s.substr(1);
+               else
+                       break;
+       }
+
+       while (s.size() > 0)
+       {
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+                       s = s.substr(0, s.size() - 1);
+               else
+                       break;
+       }
+
+       return s;
+}
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+       // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+       if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+               return false;
+       size_t nEnd = sCharset.rfind(')');
+       size_t nStart = sCharset.rfind('(');
+       string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+       vector<string> vParts;
+       SeperateString(sChar, ",", vParts);
+       for(int i = 0; i < vParts.size(); i++)
+       {
+               tCharset stCharset;
+               vector<string> vParts2;
+               SeperateString(vParts[i], "#", vParts2);
+               stCharset.sName = vParts2[0];
+               vector<string> vParts3;
+               SeperateString(vParts2[1], "-", vParts3);
+               stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+               stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+               vCharset.push_back(stCharset);
+       }
+       return true;
+}
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+    // open the input file (resolve logical name first)
+    char input_path[512];
+    boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
+    FILE *file = boinc_fopen(input_path, "rb");
+    if (!file) {
+        fprintf(stderr,
+            "Couldn't find input file, resolved name %s.\n", input_path
+        );
+        exit(-1);
+    }
+       
+
+       if (file != NULL)
+       {
+               unsigned int len = GetFileLen(file);
+               char* data = new char[len + 1];
+               fread(data, 1, len, file);
+               data[len] = '\0';
+               string content = data;
+               content += "\n";
+               delete data;
+
+               unsigned int i;
+               for (i = 0; i < content.size(); i++)
+               {
+                       if (content[i] == '\r')
+                               content[i] = '\n';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       string line = content.substr(0, n);
+                       line = TrimString(line);
+                       if (line != "")
+                               vLine.push_back(line);
+                       content = content.substr(n + 1);
+               }
+
+               fclose(file);
+       }
+       else
+               return false;
+
+       return true;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+       vPart.clear();
+
+       unsigned int i;
+       for (i = 0; i < sSeperator.size(); i++)
+       {
+               int n = s.find(sSeperator[i]);
+               if (n != -1)
+               {
+                       vPart.push_back(s.substr(0, n));
+                       s = s.substr(n + 1);
+               }
+               else
+                       return false;
+       }
+       vPart.push_back(s);
+
+       return true;
+}
+
+string uint64tostr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf_s(str, sizeof(str), "%I64u", n);
+#else
+       sprintf(str, "%llu", n);
+#endif
+
+       return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf_s(str, sizeof(str), "%016I64x", n);
+#else
+       sprintf(str, "%016llx", n);
+#endif
+
+       return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+       string sRet;
+       int i;
+       for (i = 0; i < nLen; i++)
+       {
+               char szByte[3];
+#ifdef _WIN32
+               sprintf_s(szByte, sizeof(szByte), "%02x", pData[i]);
+#else
+               sprintf(szByte, "%02x", pData[i]);
+
+#endif
+               sRet += szByte;
+       }
+
+       return sRet;
+}
+
+unsigned int GetAvailPhysMemorySize()
+{
+#ifdef _WIN32
+               MEMORYSTATUS ms;
+               GlobalMemoryStatus(&ms);
+               return ms.dwAvailPhys;
+#else
+       struct sysinfo info;
+       sysinfo(&info);                 // This function is Linux-specific
+       return info.freeram;
+#endif
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < sHash.size() / 2; i++)
+       {
+               string sSub = sHash.substr(i * 2, 2);
+               int nValue;
+#ifdef _WIN32
+               sscanf_s(sSub.c_str(), "%02x", &nValue);
+#else
+               sscanf(sSub.c_str(), "%02x", &nValue);
+#endif
+               pHash[i] = (unsigned char)nValue;
+       }
+
+       nHashLen = sHash.size() / 2;
+}
+
+void Logo()
+{
+       printf("RainbowCrack 1.2 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+       printf("by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+       printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/Public.h b/BOINC software/BOINC client apps/distrrtgen/tmp/Public.h
new file mode 100644 (file)
index 0000000..70d788c
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _PUBLIC_H
+#define _PUBLIC_H
+
+#include <stdio.h>
+
+#include <string>
+#include <vector>
+#include <list>
+using namespace std;
+#define INPUT_FILENAME "charset.txt"
+#define OUTPUT_FILENAME "result"
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       //#define uint64 u_int64_t
+       #define uint64 unsigned long long
+#endif
+
+struct RainbowChain
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+};
+
+
+struct RainbowChainCP
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+       unsigned short checkpoint;
+};
+
+typedef struct
+{
+       string sName;
+       int nPlainLenMin;
+       int nPlainLenMax;
+} tCharset;
+
+#define MAX_PLAIN_LEN 256
+#define MIN_HASH_LEN  8
+#define MAX_HASH_LEN  256
+#define MAX_SALT_LEN  256
+
+unsigned int GetFileLen(FILE* file);
+string TrimString(string s);
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine);
+bool SeperateString(string s, string sSeperator, vector<string>& vPart);
+string uint64tostr(uint64 n);
+string uint64tohexstr(uint64 n);
+string HexToStr(const unsigned char* pData, int nLen);
+unsigned int GetAvailPhysMemorySize();
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen);
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset);
+void Logo();
+
+#endif
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/RainbowTableGenerator.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/RainbowTableGenerator.cpp
new file mode 100644 (file)
index 0000000..399cd31
--- /dev/null
@@ -0,0 +1,22 @@
+
+#include "RainbowTableGenerator.h"
+#include "ChainWalkContext.h"
+#include <iostream>
+#include <sstream>
+#include <time.h>
+#include <conio.h>
+
+CRainbowTableGenerator::CRainbowTableGenerator()
+{
+       m_nCurrentCalculatedChains = 0;
+}
+
+CRainbowTableGenerator::~CRainbowTableGenerator(void)
+{
+}
+
+int CRainbowTableGenerator::CalculateTable(std::string sFilename, int nRainbowChainCount, std::string sHashRoutineName, std::string sCharsetName, int nPlainLenMin, int nPlainLenMax, int nRainbowTableIndex, int nRainbowChainLen, uint64 nChainStart, std::string sSalt)
+{
+       return 0;
+}
+
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/RainbowTableGenerator.h b/BOINC software/BOINC client apps/distrrtgen/tmp/RainbowTableGenerator.h
new file mode 100644 (file)
index 0000000..c720bac
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __RAINBOWTABLEGENERATOR_H_
+#define __RAINBOWTABLEGENERATOR_H_
+
+
+class CRainbowTableGenerator
+{
+private:
+
+       //void CRainbowTableGenerator::GetCharset(std::string sCharsetName, char **pCharset);
+public:
+       CRainbowTableGenerator();
+public:
+       ~CRainbowTableGenerator(void);
+       int CalculateTable(std::string sFilename, int nRainbowChainCount, std::string sHashRoutineName, std::string sCharsetName, int nPlainLenMin, int nPlainLenMax, int nRainbowTableIndex, int nRainbowChainLen, uint64 nChainStart, std::string sSalt = "");
+private:
+       int m_nCurrentCalculatedChains;
+};
+
+#endif
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/md5.cpp b/BOINC software/BOINC client apps/distrrtgen/tmp/md5.cpp
new file mode 100644 (file)
index 0000000..bc25b95
--- /dev/null
@@ -0,0 +1,1286 @@
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+/* Brutally hacked by John Walker back from ANSI C to K&R (no
+   prototypes) to maintain the tradition that Netfone will compile
+   with Sun's original "cc". */
+
+/*
+       Brutally modified by daVajj, optimized for lengths of 1 - 10.
+       Generic version used for longer indata
+*/
+
+#include <cstdlib>
+#include <cstring>
+#include "md5.h"
+
+/* The four core functions - F1 is optimized somewhat */
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+//Here's two different ways to do a left bitwise rotation. I've seen no major speed differences between them.
+//#define ROL(x, n) ( _lrotl(x, n) ) //This also requires #include <windows.h>
+#define ROL(x,n) ( x << n | x >>(32-n) )
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+       ( w += f(x, y, z) + data,  w = ROL(w,s) + x )
+       
+void MD5_NEW( unsigned char * pData, int len, unsigned char * pDigest)
+{
+       //Use optimized versions if available
+       switch( len )
+       {
+               case 1:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 1);
+                       in[1] = 0x80;
+                       memset(in + 2, 0, 2);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 8 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 8 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 8 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 8 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 2:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 2);
+                       in[2] = 0x80;
+                       memset(in + 3, 0, 1);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 16 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 16 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 16 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 16 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 3:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 3);
+                       in[3] = 0x80;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 24 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 24 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 24 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 24 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 4:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 4);
+                       //in[4] = 0x80; //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 128 + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 32 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 128 + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 32 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 32 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 128 + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 32 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 128 + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 5:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 5);
+                       in[5] = 0x80;
+                       memset(in + 6, 0, 2); //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 40 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 40 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 40 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 40 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 6:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 6);
+                       in[6] = 0x80;
+                       memset(in + 7, 0, 1); //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 48 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 48 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 48 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 48 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 7:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 7);
+                       in[7] = 0x80;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 56 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 56 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 56 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 56 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 8:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 8);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 128 + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 64 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 64 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 128 + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 64 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 128 + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 64 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 128 + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 9:
+               {
+                       //Main variables
+                       unsigned char in[12];
+                       
+                       memcpy(in, pData, 9);
+                       in[9] = 0x80;
+                       memset(in + 10, 0, 2);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 72 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 72 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 72 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 72 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 10:
+               {
+                       //Main variables
+                       unsigned char in[12];
+                       
+                       memcpy(in, pData, 10);
+                       in[10] = 0x80;
+                       memset(in + 11, 0, 1);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 80 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 80 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 80 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 80 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               default:
+                       //Main variables
+                       uint32 buf[4];
+                       unsigned char in[64];
+                       
+                       //Initialize
+                       buf[0] = 0x67452301;
+                       buf[1] = 0xefcdab89;
+                       buf[2] = 0x98badcfe;
+                       buf[3] = 0x10325476;
+
+                       /* Process data in 64-byte chunks */
+                       if( len >= 64 )
+                       {
+                               while( len >= 64 )
+                               {
+                                       memcpy(in, pData, 64);
+
+                                       //START OF MD5TRANSFORM CODE
+                                       //====================================================
+                                       register uint32 a, b, c, d;
+                                       uint32 * pUiIn = (uint32 *) in;
+                               
+                                       a = buf[0];
+                                       b = buf[1];
+                                       c = buf[2];
+                                       d = buf[3];
+                               
+                                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+                               
+                                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+                               
+                                       MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+                               
+                                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+                               
+                                       buf[0] += a;
+                                       buf[1] += b;
+                                       buf[2] += c;
+                                       buf[3] += d;
+                                       //END OF MD5TRANSFORM CODE
+                                       //====================================================
+
+                                       pData += 64;
+                                       len -= 64;
+                               }
+                       }
+
+                       /* Handle any remaining bytes of data. */
+                       memcpy(in, pData, len);
+                   
+                       //MD5FINAL STARTS HERE
+                       //===========================================
+                       unsigned count = len & 0x3F;
+                       unsigned char * p = in + count;
+                       *p++ = 0x80;
+
+                       // Bytes of padding needed to make 64 bytes
+                       count = 63 - count;
+
+                       /* Pad out to 56 mod 64 */
+                       if(count < 8)
+                       {
+                               // Two lots of padding:  Pad the first block to 64 bytes
+                               memset(p, 0, count);
+
+                               //START OF MD5TRANSFORM CODE
+                               //====================================================
+                               register uint32 a, b, c, d;
+                               uint32 * pUiIn = (uint32 *) in;
+                       
+                               a = buf[0];
+                               b = buf[1];
+                               c = buf[2];
+                               d = buf[3];
+                       
+                               MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+                       
+                               MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+                       
+                               MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+                       
+                               MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+                       
+                               buf[0] += a;
+                               buf[1] += b;
+                               buf[2] += c;
+                               buf[3] += d;
+                               //END OF MD5TRANSFORM CODE
+                               //====================================================      
+
+                               // Now fill the next block with 56 bytes
+                               memset(in, 0, 56);
+                       }
+                       else
+                       {
+                               // Pad block to 56 bytes
+                               memset(p, 0, count - 8);
+                       }//*/
+                   
+
+                       /* Append length in bits and transform */
+                       ((uint32 *) in)[14] = len << 3;
+                       ((uint32 *) in)[15] = len >> 29;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = buf[0];
+                       b = buf[1];
+                       c = buf[2];
+                       d = buf[3];
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+
+                       buf[0] += a;
+                       buf[1] += b;
+                       buf[2] += c;
+                       buf[3] += d;
+                       //END OF MD5TRANSFORM CODE
+                       //====================================================
+                           
+                       memcpy(pDigest, buf, 16);
+                       return;
+
+               break;
+       }
+}
diff --git a/BOINC software/BOINC client apps/distrrtgen/tmp/md5.h b/BOINC software/BOINC client apps/distrrtgen/tmp/md5.h
new file mode 100644 (file)
index 0000000..1d3da9e
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef MD5_H
+#define MD5_H
+
+typedef unsigned long uint32;
+
+//Main function
+void MD5_NEW( unsigned char * buf, int len, unsigned char * pDigest);
+
+#endif /* !MD5_H */
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/BuildLog.htm b/BOINC software/BOINC client apps/index_calculator/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..30d7c09
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/BuildLog.htm differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkContext.obj b/BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..857a7d8
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkContext.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkSet.obj b/BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkSet.obj
new file mode 100644 (file)
index 0000000..1a4fb1e
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/ChainWalkSet.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/HashAlgorithm.obj b/BOINC software/BOINC client apps/index_calculator/Debug/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..11fc6c1
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/HashAlgorithm.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/HashRoutine.obj b/BOINC software/BOINC client apps/index_calculator/Debug/HashRoutine.obj
new file mode 100644 (file)
index 0000000..edbd0c7
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/HashRoutine.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/Public.obj b/BOINC software/BOINC client apps/index_calculator/Debug/Public.obj
new file mode 100644 (file)
index 0000000..da49af9
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/Public.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/des_enc.obj b/BOINC software/BOINC client apps/index_calculator/Debug/des_enc.obj
new file mode 100644 (file)
index 0000000..61d88c8
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/des_enc.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/des_setkey.obj b/BOINC software/BOINC client apps/index_calculator/Debug/des_setkey.obj
new file mode 100644 (file)
index 0000000..7deb3d4
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/des_setkey.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/ecb_enc.obj b/BOINC software/BOINC client apps/index_calculator/Debug/ecb_enc.obj
new file mode 100644 (file)
index 0000000..8fe0c81
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/ecb_enc.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.exe.intermediate.manifest b/BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.obj b/BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.obj
new file mode 100644 (file)
index 0000000..523eb8c
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/index_calculator.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/md4.obj b/BOINC software/BOINC client apps/index_calculator/Debug/md4.obj
new file mode 100644 (file)
index 0000000..e567809
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/md4.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/md5.obj b/BOINC software/BOINC client apps/index_calculator/Debug/md5.obj
new file mode 100644 (file)
index 0000000..5bea775
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/md5.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/mt.dep b/BOINC software/BOINC client apps/index_calculator/Debug/mt.dep
new file mode 100644 (file)
index 0000000..aa1d48b
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 18:36:11,43 on 28-11-2008 
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/vc90.idb b/BOINC software/BOINC client apps/index_calculator/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..67cbee1
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/vc90.idb differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Debug/vc90.pdb b/BOINC software/BOINC client apps/index_calculator/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..554ebd6
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Debug/vc90.pdb differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/BuildLog.htm b/BOINC software/BOINC client apps/index_calculator/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..e0a5e0e
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/BuildLog.htm differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/ChainWalkContext.obj b/BOINC software/BOINC client apps/index_calculator/Release/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..90fc802
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/ChainWalkContext.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/ChainWalkSet.obj b/BOINC software/BOINC client apps/index_calculator/Release/ChainWalkSet.obj
new file mode 100644 (file)
index 0000000..3b91d25
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/ChainWalkSet.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/HashAlgorithm.obj b/BOINC software/BOINC client apps/index_calculator/Release/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..0a323d2
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/HashAlgorithm.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/HashRoutine.obj b/BOINC software/BOINC client apps/index_calculator/Release/HashRoutine.obj
new file mode 100644 (file)
index 0000000..bfcd4c8
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/HashRoutine.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/Public.obj b/BOINC software/BOINC client apps/index_calculator/Release/Public.obj
new file mode 100644 (file)
index 0000000..6091aff
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/Public.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/des_enc.obj b/BOINC software/BOINC client apps/index_calculator/Release/des_enc.obj
new file mode 100644 (file)
index 0000000..691c507
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/des_enc.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/des_setkey.obj b/BOINC software/BOINC client apps/index_calculator/Release/des_setkey.obj
new file mode 100644 (file)
index 0000000..0b0b664
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/des_setkey.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/ecb_enc.obj b/BOINC software/BOINC client apps/index_calculator/Release/ecb_enc.obj
new file mode 100644 (file)
index 0000000..6c74416
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/ecb_enc.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/index_calculator.exe.intermediate.manifest b/BOINC software/BOINC client apps/index_calculator/Release/index_calculator.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/index_calculator.obj b/BOINC software/BOINC client apps/index_calculator/Release/index_calculator.obj
new file mode 100644 (file)
index 0000000..2cc1ae9
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/index_calculator.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/md4.obj b/BOINC software/BOINC client apps/index_calculator/Release/md4.obj
new file mode 100644 (file)
index 0000000..6c4c273
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/md4.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/md5.obj b/BOINC software/BOINC client apps/index_calculator/Release/md5.obj
new file mode 100644 (file)
index 0000000..bc69341
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/md5.obj differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/mt.dep b/BOINC software/BOINC client apps/index_calculator/Release/mt.dep
new file mode 100644 (file)
index 0000000..5c47aba
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 18:30:10,73 on 28-11-2008 
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/vc90.idb b/BOINC software/BOINC client apps/index_calculator/Release/vc90.idb
new file mode 100644 (file)
index 0000000..2bf7ad5
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/vc90.idb differ
diff --git a/BOINC software/BOINC client apps/index_calculator/Release/vc90.pdb b/BOINC software/BOINC client apps/index_calculator/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..e0b0585
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/Release/vc90.pdb differ
diff --git a/BOINC software/BOINC client apps/index_calculator/boinc_finish_called b/BOINC software/BOINC client apps/index_calculator/boinc_finish_called
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/BOINC software/BOINC client apps/index_calculator/boinc_lockfile b/BOINC software/BOINC client apps/index_calculator/boinc_lockfile
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/BOINC software/BOINC client apps/index_calculator/chains b/BOINC software/BOINC client apps/index_calculator/chains
new file mode 100644 (file)
index 0000000..9a4a0e0
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/chains differ
diff --git a/BOINC software/BOINC client apps/index_calculator/charset.txt b/BOINC software/BOINC client apps/index_calculator/charset.txt
new file mode 100644 (file)
index 0000000..6e749fa
--- /dev/null
@@ -0,0 +1,34 @@
+# charset configuration file for DistrRTgen v3.2 by Martin Westergaard (martinwj2005@gmail.com)
+
+byte                        = []
+alpha                       = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+alpha-space                 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+alpha-numeric               = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+alpha-numeric-space         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+alpha-numeric-symbol14      = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+= ]
+all                         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+all-space                   = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+lm-frt-cp437                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥àáâãäæçèéêëî]
+lm-frt-cp850                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9c\9d\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãåæèéêëíï]
+lm-frt-cp437-850            = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãäåæçèéêëíîï]
+
+numeric                     = [0123456789]
+numeric-space               = [0123456789 ]
+loweralpha                  = [abcdefghijklmnopqrstuvwxyz]
+loweralpha-space            = [abcdefghijklmnopqrstuvwxyz ]
+loweralpha-numeric          = [abcdefghijklmnopqrstuvwxyz0123456789]
+loweralpha-numeric-space    = [abcdefghijklmnopqrstuvwxyz0123456789 ]
+loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=]
+loweralpha-numeric-all             = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+mixalpha                    = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
+mixalpha-space              = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+mixalpha-numeric            = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+mixalpha-numeric-space      = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+mixalpha-numeric-symbol14   = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+mixalpha-numeric-all        = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+mixalpha-numeric-symbol32-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+mixalpha-numeric-all-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.cpp b/BOINC software/BOINC client apps/index_calculator/index_calculator.cpp
new file mode 100644 (file)
index 0000000..04041be
--- /dev/null
@@ -0,0 +1,225 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifdef _WIN32
+#include "boinc_win.h"
+#else
+#include "config.h"
+#include <cstdio>
+#include <cctype>
+#include <ctime>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+#include <unistd.h>
+#endif
+
+#include <string>
+#include <fstream>
+
+#include "str_util.h"
+#include "util.h"
+#include "filesys.h"
+#include "boinc_api.h"
+#include "Public.h"
+// Rainbowcrack code
+#include "ChainWalkSet.h"
+#include "ChainWalkContext.h"
+typedef unsigned int uint32;
+//typedef unsigned __int64 uint64;
+
+
+using std::string;
+
+int main(int argc, char **argv) {
+    int i;
+    int c, nchars = 0, retval, n;
+    double fsize, fd;
+    char output_path[512], chkpt_path[512];
+    FILE* state, *infile;      
+    retval = boinc_init();
+    if (retval) {
+        fprintf(stderr, "boinc_init returned %d\n", retval);
+        exit(retval);
+    }
+       
+
+    // get size of input file (used to compute fraction done)
+    //
+    //file_size(input_path, fsize);
+
+    // See if there's a valid checkpoint file.
+    // If so seek input file and truncate output file
+    //
+
+
+       if(argc < 8)
+       {
+               std::cerr << "Not enough parameters";
+               return -1;
+       }
+       string sHashRoutineName, sCharsetName, sHash;
+       uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
+       uint64 nChainStart;
+       sHashRoutineName = argv[1];
+       sCharsetName = argv[2];
+       nPlainLenMin = atoi(argv[3]);
+       nPlainLenMax = atoi(argv[4]);
+       nRainbowTableIndex = atoi(argv[5]);
+       nRainbowChainLen = atoi(argv[6]);
+       sHash = argv[7];
+       //std::cout << "Starting ChainGenerator" << std::endl;
+       // Setup CChainWalkContext
+       //std::cout << "ChainGenerator started." << std::endl;
+
+       if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
+       {
+               std::cerr << "hash routine " << sHashRoutineName << " not supported" << std::endl;
+               return 1;
+       }
+       //std::cout << "Hash routine validated" << std::endl;
+
+       if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+       {       
+               std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
+               return 2;
+       }
+       //std::cout << "Plain charset validated" << std::endl;
+
+       if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
+               return 3;
+       }
+       //std::cout << "Rainbowtable index validated" << std::endl;
+/*
+       if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
+       {
+               // Convert username to unicode
+               const char *szSalt = sSalt.c_str();
+               int salt_length = strlen(szSalt);
+               unsigned char cur_salt[256];
+               for (int i=0; i<salt_length; i++)
+               {
+                       cur_salt[i*2] = szSalt[i];
+                       cur_salt[i*2+1] = 0x00;
+               }
+               CChainWalkContext::SetSalt(cur_salt, salt_length*2);
+       }*/
+       else if(sHashRoutineName == "halflmchall")
+       { // The salt is hardcoded into the hash routine
+       //      CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
+       }
+       /*
+       else if(sHashRoutineName == "oracle")
+       {
+               CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
+       }
+       */
+       //std::cout << "Opening chain file" << std::endl;
+
+       
+       // Open file
+    boinc_resolve_filename("result", output_path, sizeof(output_path));
+       FILE *outfile = boinc_fopen(output_path, "wb");
+       
+       if (outfile == NULL)
+       {
+               std::cerr << "failed to create " << output_path << std::endl;
+               return 4;
+       }
+       unsigned char TargetHash[255];
+       int nHashLen = 0;
+       ParseHash(sHash, TargetHash, nHashLen);
+       CChainWalkSet m_cws;
+       CChainWalkContext cwc;
+
+       bool fNewlyGenerated;
+       uint64* pStartPosIndexE = m_cws.RequestWalk(TargetHash,
+                                                                                               nHashLen,
+                                                                                               sHashRoutineName,
+                                                                                               sCharsetName,
+                                                                                               nPlainLenMin,
+                                                                                               nPlainLenMax,
+                                                                                               nRainbowTableIndex,
+                                                                                               nRainbowChainLen,
+                                                                                               fNewlyGenerated);
+       int nPos;
+       double nTargetChains = pow((double)nRainbowChainLen - 2, 2) / 2 - (nRainbowChainLen - 2);
+       if (fNewlyGenerated)
+       {
+               time_t tStart = time(NULL);
+               for (nPos = nRainbowChainLen - 2; nPos >= 0; nPos--)
+               {
+                       if(time(NULL) - tStart > 1)
+                       {
+                               time(&tStart);
+                               double nCurrentChains = pow(((double)nRainbowChainLen - 2 - (double)nPos), 2) / 2 - (nRainbowChainLen - 2);
+                               double fResult = ((double)((double)(nCurrentChains) / nTargetChains));
+                               if(fResult < 0)
+                                       fResult = 0;
+                               boinc_fraction_done(fResult);
+                       }
+                       
+                       cwc.SetHash(TargetHash);
+                       cwc.HashToIndex(nPos);
+                       int i;
+                       for (i = nPos + 1; i <= nRainbowChainLen - 2; i++)
+                       {
+                               cwc.IndexToPlain();
+                               cwc.PlainToHash();
+                               cwc.HashToIndex(i);
+                       }
+                       uint64 index = cwc.GetIndex();
+                       if(fwrite(&index, 8, 1, outfile) != 1)
+                       {
+                               fprintf(stderr, "unable to write to outfile");
+                               return 9;
+                       }
+                               //nChainWalkStep += nRainbowChainLen - 2 - nPos;
+               }
+//                     printf("ok\n");                 
+               double nCurrentChains = pow(((double)nRainbowChainLen - 2 - (double)nPos), 2) / 2 - (nRainbowChainLen - 2);
+               double fResult = ((double)((double)(nCurrentChains) / nTargetChains));
+               boinc_fraction_done(fResult);
+       }
+       
+       
+       fclose(outfile);
+    
+       // main loop - read characters, convert to UC, write
+    //
+
+    boinc_fraction_done(1);
+    boinc_finish(0);
+}
+
+#ifdef _WIN32
+int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
+    LPSTR command_line;
+    char* argv[100];
+    int argc;
+
+    command_line = GetCommandLine();
+    argc = parse_command_line( command_line, argv );
+    return main(argc, argv);
+}
+#endif
+
+const char *BOINC_RCSID_33ac47a071 = "$Id: upper_case.C 12135 2007-02-21 20:04:14Z davea $";
+
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.h b/BOINC software/BOINC client apps/index_calculator/index_calculator.h
new file mode 100644 (file)
index 0000000..d360617
--- /dev/null
@@ -0,0 +1,29 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "boinc_api.h"
+
+struct UC_SHMEM {
+    double update_time;
+    double fraction_done;
+    double cpu_time;
+    BOINC_STATUS status;
+    int countdown;
+        // graphics app sets this to 5 repeatedly,
+        // main program decrements it once/sec.
+        // If it's zero, don't bother updating shmem
+};
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.ncb b/BOINC software/BOINC client apps/index_calculator/index_calculator.ncb
new file mode 100644 (file)
index 0000000..b2a5b5c
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/index_calculator.ncb differ
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.suo b/BOINC software/BOINC client apps/index_calculator/index_calculator.suo
new file mode 100644 (file)
index 0000000..393645d
Binary files /dev/null and b/BOINC software/BOINC client apps/index_calculator/index_calculator.suo differ
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj b/BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj
new file mode 100644 (file)
index 0000000..c372b13
--- /dev/null
@@ -0,0 +1,301 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="index_calculator"
+       ProjectGUID="{C7A957CF-9FDC-4C72-9C3E-7C029E915D1E}"
+       RootNamespace="index_calculator"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="196613"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="2"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="/boinc/lib;/boinc/api;&quot;/boinc/zip&quot;;&quot;/boinc/client/win&quot;;&quot;/boinc/&quot;;../distrrtgen;&quot;../../rt api&quot;"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_MT;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="1"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="libcmtd.lib libcpmtd.lib kernel32.lib user32.lib ole32.lib delayimp.lib ..\lib_debug\libboinc_staticcrt.lib ..\lib_debug\libboincapi_staticcrt.lib c:/openssl/lib/libeay32.lib"
+                               LinkIncremental="0"
+                               IgnoreAllDefaultLibraries="true"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               RandomizedBaseAddress="1"
+                               DataExecutionPrevention="0"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="2"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               InlineFunctionExpansion="2"
+                               EnableIntrinsicFunctions="true"
+                               FavorSizeOrSpeed="1"
+                               WholeProgramOptimization="true"
+                               AdditionalIncludeDirectories="/boinc/lib;/boinc/api;&quot;/boinc/zip&quot;;&quot;/boinc/client/win&quot;;&quot;/boinc/&quot;;../distrrtgen;&quot;../../rt api&quot;"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_MT;_CONSOLE"
+                               RuntimeLibrary="0"
+                               EnableFunctionLevelLinking="true"
+                               EnableEnhancedInstructionSet="2"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               AdditionalDependencies="odbc32.lib odbccp32.lib libcmt.lib libcpmt.lib ..\lib_release\libboinc_staticcrt.lib ..\lib_release\libboincapi_staticcrt.lib c:/openssl/lib/libeay32.lib"
+                               LinkIncremental="1"
+                               IgnoreAllDefaultLibraries="true"
+                               GenerateDebugInformation="true"
+                               SubSystem="2"
+                               OptimizeReferences="0"
+                               EnableCOMDATFolding="0"
+                               LinkTimeCodeGeneration="0"
+                               RandomizedBaseAddress="1"
+                               DataExecutionPrevention="0"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkSet.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_setkey.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ecb_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\index_calculator.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\Public.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkSet.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_locl.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\index_calculator.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\podd.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\Public.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\sk.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\spr.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj.MWJ-PC.mwj.user b/BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj.MWJ-PC.mwj.user
new file mode 100644 (file)
index 0000000..15b19f6
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj.W-L-MWJ.Administrator.user b/BOINC software/BOINC client apps/index_calculator/index_calculator.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..7284908
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="md5 loweralpha-numeric-space 1 8 0 10000 098f6bcd4621d373cade4e832627b4f6"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="md5 loweralpha-numeric-space 1 8 0 10000 098f6bcd4621d373cade4e832627b4f6"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/BOINC software/BOINC client apps/index_calculator/init_data.xml b/BOINC software/BOINC client apps/index_calculator/init_data.xml
new file mode 100644 (file)
index 0000000..4a7e047
--- /dev/null
@@ -0,0 +1,78 @@
+<app_init_data>
+<major_version>0</major_version>
+<minor_version>0</minor_version>
+<release>0</release>
+<app_version>0</app_version>
+<slot>0</slot>
+<wu_cpu_time>0.000000</wu_cpu_time>
+<user_total_credit>0.000000</user_total_credit>
+<user_expavg_credit>0.000000</user_expavg_credit>
+<host_total_credit>0.000000</host_total_credit>
+<host_expavg_credit>0.000000</host_expavg_credit>
+<resource_share_fraction>0.000000</resource_share_fraction>
+<checkpoint_period>300.000000</checkpoint_period>
+<fraction_done_start>0.000000</fraction_done_start>
+<fraction_done_end>0.000000</fraction_done_end>
+<rsc_fpops_est>0.000000</rsc_fpops_est>
+<rsc_fpops_bound>0.000000</rsc_fpops_bound>
+<rsc_memory_bound>0.000000</rsc_memory_bound>
+<rsc_disk_bound>0.000000</rsc_disk_bound>
+<computation_deadline>0.000000</computation_deadline>
+<host_info>
+    <timezone>0</timezone>
+    <domain_name></domain_name>
+    <ip_addr></ip_addr>
+    <host_cpid></host_cpid>
+    <p_ncpus>0</p_ncpus>
+    <p_vendor></p_vendor>
+    <p_model></p_model>
+    <p_features></p_features>
+    <p_fpops>0.000000</p_fpops>
+    <p_iops>0.000000</p_iops>
+    <p_membw>0.000000</p_membw>
+    <p_calculated>0.000000</p_calculated>
+    <m_nbytes>0.000000</m_nbytes>
+    <m_cache>0.000000</m_cache>
+    <m_swap>0.000000</m_swap>
+    <d_total>0.000000</d_total>
+    <d_free>0.000000</d_free>
+    <os_name></os_name>
+    <os_version></os_version>
+</host_info>
+<proxy_info>
+    <socks_version>0</socks_version>
+    <socks_server_name></socks_server_name>
+    <socks_server_port>0</socks_server_port>
+    <http_server_name></http_server_name>
+    <http_server_port>0</http_server_port>
+    <socks5_user_name></socks5_user_name>
+    <socks5_user_passwd></socks5_user_passwd>
+    <http_user_name></http_user_name>
+    <http_user_passwd></http_user_passwd>
+    <no_proxy></no_proxy>
+</proxy_info>
+<global_preferences>
+   <source_project></source_project>
+   <mod_time>0.000000</mod_time>
+   <suspend_if_no_recent_input>0.000000</suspend_if_no_recent_input>
+   <start_hour>0.000000</start_hour>
+   <end_hour>0.000000</end_hour>
+   <net_start_hour>0.000000</net_start_hour>
+   <net_end_hour>0.000000</net_end_hour>
+   <work_buf_min_days>0.000000</work_buf_min_days>
+   <work_buf_additional_days>0.000000</work_buf_additional_days>
+   <max_ncpus_pct>0.000000</max_ncpus_pct>
+   <cpu_scheduling_period_minutes>0.000000</cpu_scheduling_period_minutes>
+   <disk_interval>0.000000</disk_interval>
+   <disk_max_used_gb>0.000000</disk_max_used_gb>
+   <disk_max_used_pct>0.000000</disk_max_used_pct>
+   <disk_min_free_gb>0.000000</disk_min_free_gb>
+   <vm_max_used_pct>0.000000</vm_max_used_pct>
+   <ram_max_used_busy_pct>0.000000</ram_max_used_busy_pct>
+   <ram_max_used_idle_pct>0.000000</ram_max_used_idle_pct>
+   <idle_time_to_run>0.000000</idle_time_to_run>
+   <max_bytes_sec_up>0.000000</max_bytes_sec_up>
+   <max_bytes_sec_down>0.000000</max_bytes_sec_down>
+   <cpu_usage_limit>0.000000</cpu_usage_limit>
+</global_preferences>
+</app_init_data>
diff --git a/BOINC software/BOINC client apps/index_calculator/stderr.txt b/BOINC software/BOINC client apps/index_calculator/stderr.txt
new file mode 100644 (file)
index 0000000..2ed796c
--- /dev/null
@@ -0,0 +1,22 @@
+Can't open init data file - running in standalone mode
+Couldn't find input file, resolved name charset.txt.
+Detected memory leaks!
+Dumping objects ->
+{96} normal block at 0x00A95A50, 32 bytes long.
+ Data: <loweralpha-numer> 6C 6F 77 65 72 61 6C 70 68 61 2D 6E 75 6D 65 72 
+{95} normal block at 0x00A959F0, 32 bytes long.
+ Data: <loweralpha-numer> 6C 6F 77 65 72 61 6C 70 68 61 2D 6E 75 6D 65 72 
+{70} normal block at 0x00A95980, 48 bytes long.
+ Data: <098f6bcd4621d373> 30 39 38 66 36 62 63 64 34 36 32 31 64 33 37 33 
+{69} normal block at 0x00A95920, 32 bytes long.
+ Data: <loweralpha-numer> 6C 6F 77 65 72 61 6C 70 68 61 2D 6E 75 6D 65 72 
+..\lib\diagnostics_win.cpp(642) : {66} normal block at 0x00A954B8, 1068 bytes long.
+ Data: <do              > 64 6F 00 00 B0 1F 00 00 01 00 00 00 00 00 00 00 
+Object dump complete.
+Can't open init data file - running in standalone mode
+Can't open init data file - running in standalone mode
+called boinc_finish
+Can't set up shared mem: -1
+Will run in standalone mode.
+Can't set up shared mem: -1
+Will run in standalone mode.
diff --git a/BOINC software/BOINC server apps/chain_checker_assimilator/Makefile b/BOINC software/BOINC server apps/chain_checker_assimilator/Makefile
new file mode 100644 (file)
index 0000000..3ec1e40
--- /dev/null
@@ -0,0 +1,56 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/boincadm/src/boinc
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+BOINC_SCHED_DIR = $(BOINC_DIR)/sched
+BOINC_DB_DIR = $(BOINC_DIR)/db
+BOINC_TOOLS_DIR = $(BOINC_DIR)/tools
+MYSQL_DIR = /usr/include/mysql
+
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -I$(BOINC_SCHED_DIR) \
+    -I$(BOINC_DB_DIR) \
+    -I$(MYSQL_DIR) \
+    -I$(BOINC_TOOLS_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L$(BOINC_SCHED_DIR) \
+    -L/usr/X11R6/lib \
+    -L/usr/lib/mysql \
+    -L.
+
+# the following should be freeglut; use nm to check
+# you may have to change the paths for your system
+
+ifeq ($(wildcard /usr/local/lib/libglut.a),)
+       LIBGLUT = /usr/lib/libglut.a
+       LIBGLU = /usr/lib/libGLU.a
+       LIBJPEG = /usr/lib/libjpeg.a
+else
+       LIBGLUT = /usr/local/lib/libglut.a
+       LIBGLU = /usr/local/lib/libGLU.a
+       LIBJPEG = /usr/local/lib/libjpeg.a
+endif
+
+PROGS = distrrtgen \
+# uc2_graphics
+# make this optional so compile doesn't break on systems without OpenGL
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+distrrtgen: chain_checker_assimilator.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_SCHED_DIR)/libsched.a 
+       $(CXX) chain_checker_assimilator.cpp assimilator.cpp validate_util.cpp $(CXXFLAGS) -o chain_checker_assimilator libstdc++.a -pthread -lboinc_api -lsched -lboinc -lmysqlclient -lssl -O3 
diff --git a/BOINC software/BOINC server apps/chain_checker_assimilator/assimilate_handler.h b/BOINC software/BOINC server apps/chain_checker_assimilator/assimilate_handler.h
new file mode 100644 (file)
index 0000000..e3086c9
--- /dev/null
@@ -0,0 +1,31 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Include this in assimilate handlers
+
+#include <vector>
+#include "boinc_db.h"
+#define DEFER_ASSIMILATION 123321
+    // if the assimilate handler returns this,
+    // don't mark WU as assimilated; instead, wait for another
+    // result to be returned and try again
+    // (kludge for WCG)
+
+extern int assimilate_handler(WORKUNIT&, std::vector<RESULT>&, RESULT&);
+
+extern int g_argc;
+extern char** g_argv;
diff --git a/BOINC software/BOINC server apps/chain_checker_assimilator/assimilator.cpp b/BOINC software/BOINC server apps/chain_checker_assimilator/assimilator.cpp
new file mode 100644 (file)
index 0000000..6cdba52
--- /dev/null
@@ -0,0 +1,285 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// This is a framework for an assimilator.
+// You need to link this with an (application-specific) function
+// assimilate_handler()
+// in order to make a complete program.
+//
+
+#include "config.h"
+#include <cstring>
+#include <cstdlib>
+#include <unistd.h>
+#include <ctime>
+#include <vector>
+
+#include "boinc_db.h"
+#include "parse.h"
+#include "util.h"
+#include "error_numbers.h"
+#include "str_util.h"
+
+#include "sched_config.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+#include "assimilate_handler.h"
+
+using std::vector;
+
+#define LOCKFILE "assimilator.out"
+#define PIDFILE  "assimilator.pid"
+#define SLEEP_INTERVAL 10
+
+bool update_db = true;
+bool noinsert = false;
+int wu_id_modulus=0, wu_id_remainder=0;
+int sleep_interval = SLEEP_INTERVAL;
+int one_pass_N_WU=0;
+int g_argc;
+char** g_argv;
+
+void usage(char** argv) {
+    fprintf(stderr,
+        "This program is an 'assimilator'; it handles completed jobs.\n"
+        "Normally it is run as a daemon from config.xml.\n"
+        "See: http://boinc.berkeley.edu/trac/wiki/BackendPrograms\n\n"
+    );
+
+    fprintf(stderr, "usage: %s [options]\n"
+        "    Options:\n"
+        "    -app name            Process jobs for the given application\n"
+        "    [-sleep_interval X]  Sleep X seconds if no jobs to process (default 10)\n"
+        "    [-mod N R]           Process jobs with mod(ID, N) == R\n"
+        "    [-one_pass]          Do one DB enumeration, then exit\n"
+        "    [-one_pass_N_WU N]   Process at most N jobs\n"
+        "    [-d N]               Set verbosity level (1, 2, 3=most verbose)\n"
+        "    [-dont_update_db]    Don't update DB (for testing)\n"
+        "    [-noinsert]          Don't insert records in app-specific DB\n",
+        argv[0]
+    );
+    exit(0);
+}
+
+// assimilate all WUs that need it
+// return nonzero if did anything
+//
+bool do_pass(APP& app) {
+    DB_WORKUNIT wu;
+    DB_RESULT canonical_result, result;
+    bool did_something = false;
+    char buf[256];
+    char mod_clause[256];
+    int retval;
+    int num_assimilated=0;
+
+    check_stop_daemons();
+
+    if (wu_id_modulus) {
+        sprintf(mod_clause, " and workunit.id %% %d = %d ",
+                wu_id_modulus, wu_id_remainder
+        );
+    } else {
+        strcpy(mod_clause, "");
+    }
+
+    sprintf(buf,
+        "where appid=%d and assimilate_state=%d %s limit %d",
+        app.id, ASSIMILATE_READY, mod_clause,
+        one_pass_N_WU ? one_pass_N_WU : 1000
+    );
+    while (1) {
+        retval = wu.enumerate(buf);
+        if (retval) {
+            if (retval != ERR_DB_NOT_FOUND) {
+                log_messages.printf(MSG_DEBUG,
+                    "DB connection lost, exiting\n"
+                );
+                exit(0);
+            }
+            break;
+        }
+        vector<RESULT> results;     // must be inside while()!
+
+        // for testing purposes, pretend we did nothing
+        //
+        if (update_db) {
+            did_something = true;
+        }
+
+        log_messages.printf(MSG_DEBUG,
+            "[%s] assimilating WU %d; state=%d\n", wu.name, wu.id, wu.assimilate_state
+        );
+
+        sprintf(buf, "where workunitid=%d", wu.id);
+        canonical_result.clear();
+        bool found = false;
+        while (!result.enumerate(buf)) {
+            results.push_back(result);
+            if (result.id == wu.canonical_resultid) {
+                canonical_result = result;
+                found = true;
+            }
+        }
+
+        // If no canonical result found and WU had no other errors,
+        // something is wrong, e.g. result records got deleted prematurely.
+        // This is probably unrecoverable, so mark the WU as having
+        // an assimilation error and keep going.
+        //
+        if (!found && !wu.error_mask) {
+            log_messages.printf(MSG_CRITICAL,
+                "[%s] no canonical result\n", wu.name
+            );
+            wu.error_mask = WU_ERROR_NO_CANONICAL_RESULT;
+            sprintf(buf, "error_mask=%d", wu.error_mask);
+            wu.update_field(buf);
+        }
+
+        retval = assimilate_handler(wu, results, canonical_result);
+        if (retval && retval != DEFER_ASSIMILATION) {
+            log_messages.printf(MSG_CRITICAL,
+                "[%s] handler returned error %d; exiting\n", wu.name, retval
+            );
+            exit(retval);
+        }
+
+        if (update_db) {
+            // Defer assimilation until next result is returned
+            int assimilate_state = ASSIMILATE_DONE;
+            if (retval == DEFER_ASSIMILATION) {
+                assimilate_state = ASSIMILATE_INIT;
+            }
+            sprintf(
+                buf, "assimilate_state=%d, transition_time=%d", 
+                assimilate_state, (int)time(0)
+            );
+            retval = wu.update_field(buf);
+            if (retval) {
+                log_messages.printf(MSG_CRITICAL,
+                    "[%s] update failed: %d\n", wu.name, retval
+                );
+                exit(1);
+            }
+        }
+
+        num_assimilated++;
+
+    }
+
+    if (did_something) {
+        boinc_db.commit_transaction();
+    }
+
+    if (num_assimilated)  {
+        log_messages.printf(MSG_NORMAL,
+            "Assimilated %d workunits.\n", num_assimilated
+        );
+    }
+
+    return did_something;
+}
+
+int main(int argc, char** argv) {
+    int retval;
+    bool one_pass = false;
+    DB_APP app;
+    int i;
+    char buf[256];
+
+    strcpy(app.name, "");
+    check_stop_daemons();
+    g_argc = argc;
+    g_argv = argv;
+    for (i=1; i<argc; i++) {
+        if (!strcmp(argv[i], "-one_pass_N_WU")) {
+            one_pass_N_WU = atoi(argv[++i]);
+            one_pass = true;
+        } else if (!strcmp(argv[i], "-sleep_interval")) {
+            sleep_interval = atoi(argv[++i]);
+        } else if (!strcmp(argv[i], "-one_pass")) {
+            one_pass = true;
+        } else if (!strcmp(argv[i], "-d")) {
+            log_messages.set_debug_level(atoi(argv[++i]));
+        } else if (!strcmp(argv[i], "-app")) {
+            strcpy(app.name, argv[++i]);
+        } else if (!strcmp(argv[i], "-dont_update_db")) {
+            // This option is for testing your assimilator.  When set,
+            // it ensures that the assimilator does not actually modify
+            // the assimilate_state of the workunits, so you can run
+            // your assimilator over and over again without affecting
+            // your project.
+            update_db = false;
+        } else if (!strcmp(argv[i], "-noinsert")) {
+            // This option is also for testing and is used to 
+            // prevent the inserting of results into the *backend*
+            // (as opposed to the boinc) DB.
+            noinsert = true;
+        } else if (!strcmp(argv[i], "-mod")) {
+            wu_id_modulus   = atoi(argv[++i]);
+            wu_id_remainder = atoi(argv[++i]);
+        } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
+            usage(argv);
+        } else {
+            log_messages.printf(MSG_CRITICAL, "Unrecognized arg: %s\n", argv[i]);
+            usage(argv);
+        }
+    }
+
+    if (!strlen(app.name)) {
+        usage(argv);
+    }
+
+    if (wu_id_modulus) {
+        log_messages.printf(MSG_DEBUG,
+            "Using mod'ed WU enumeration.  modulus = %d  remainder = %d\n",
+            wu_id_modulus, wu_id_remainder
+        );
+    }
+
+    retval = config.parse_file("..");
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "Can't parse ../config.xml: %s\n", boincerror(retval)
+        );
+        exit(1);
+    }
+
+    log_messages.printf(MSG_NORMAL, "Starting\n");
+
+    retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "Can't open DB\n");
+        exit(1);
+    }
+    sprintf(buf, "where name='%s'", app.name);
+    retval = app.lookup(buf);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "Can't find app\n");
+        exit(1);
+    }
+    install_stop_signal_handler();
+    while (1) {
+        if (!do_pass(app)) {
+            if (one_pass) break;
+            sleep(sleep_interval);
+        }
+    }
+}
+
+
+const char *BOINC_RCSID_7841370789 = "$Id: assimilator.cpp 16121 2008-10-03 19:31:56Z davea $";
diff --git a/BOINC software/BOINC server apps/chain_checker_assimilator/chain_checker_assimilator.cpp b/BOINC software/BOINC server apps/chain_checker_assimilator/chain_checker_assimilator.cpp
new file mode 100644 (file)
index 0000000..d8c9994
--- /dev/null
@@ -0,0 +1,136 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// A sample assimilator that:
+// 1) if success, copy the output file(s) to a directory
+// 2) if failure, append a message to an error log
+
+#include <vector>
+#include <string>
+#include <cstdlib>
+#include <sys/types.h>
+#include <pwd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "lib/util.h"
+#include "boinc_db.h"
+#include "error_numbers.h"
+#include "filesys.h"
+#include "sched_msgs.h"
+#include "validate_util.h"
+#include "sched_config.h"
+using std::vector;
+using std::string;
+
+int write_error(char* p) {
+    static FILE* f = 0;
+    if (!f) {
+        f = fopen("../../results/errors", "a");
+        if (!f) return ERR_FOPEN;
+    }
+    fprintf(f, "%s", p);
+    fflush(f);
+    return 0;
+}
+
+int GetNumFilesInDir(char *dir)
+{
+       DIR *partsdir;
+       struct dirent *part;
+       if((partsdir  = opendir(dir)) == NULL) {
+               return 0;
+       }
+       int numfiles = 0;
+       while ((part = readdir(partsdir)) != NULL) 
+       {
+               char *partname = part->d_name;
+               if(partname != "." && partname != "..")
+               {
+                       numfiles++;
+               }
+       }
+       return numfiles;
+
+}
+int assimilate_handler(
+    WORKUNIT& wu, vector<RESULT>& /*results*/, RESULT& canonical_result
+) {
+    DB_CONN frt;
+    int retval;
+    char buf[1024];
+    char query[1024];
+    unsigned int i;
+    int tableid;
+    MYSQL_RES* resp;
+    MYSQL_ROW row;
+    retval = frt.open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
+        exit(1);
+    }
+
+    
+    const char *pos = strchr(wu.name, '_');
+    char partnum[256] = {0};
+    strncpy(partnum, wu.name, pos - wu.name);
+    int lookupid = atoi(partnum);
+    log_messages.printf(MSG_DEBUG, "Handling lookupid %i\n", lookupid);    
+
+    
+    if (wu.canonical_resultid) {
+        sprintf(query, "DELETE FROM rainbowcrack_cracker_verificationqueue WHERE lookupid = %i", lookupid);
+        frt.do_query(query);
+        if(retval)  goto cleanup;
+
+        
+        vector<FILE_INFO> output_files;
+        char copy_path[256];
+        get_output_file_infos(canonical_result, output_files);
+        unsigned int n = output_files.size();
+        if(n < 1)
+        {
+               log_messages.printf(MSG_CRITICAL, "No files found!\n");
+               retval = -3;
+               goto cleanup;
+        }
+        FILE_INFO& fi = output_files[0];
+        string filedata;
+        read_file_string(fi.path.c_str(), filedata);
+        if(strcmp(filedata.c_str(),"0x00") != 0)
+        {
+               sprintf(query, "UPDATE rainbowcrack_cracker_hashlist SET password = '%s' WHERE lookupid = %i", filedata.c_str(), lookupid);
+               log_messages.printf(MSG_CRITICAL, "BINGO! Password %s is belonging to %i\n", filedata.c_str(), lookupid);
+               log_messages.printf(MSG_CRITICAL, "%s\n", query);
+        }
+        else log_messages.printf(MSG_DEBUG, "Ew. Password NOT found in %i (%s)\n", lookupid, filedata.c_str());
+        sprintf(query, "DELETE FROM rainbowcrack_cracker_verificationqueue WHERE lookupid = %i", lookupid);    
+        frt.do_query(query);
+        if(retval)  goto cleanup;       
+        sprintf(query, "UPDATE rainbowcrack_cracker_lookups SET status = 2 WHERE lookupid = %i", lookupid);    
+        frt.do_query(query);
+        if(retval)  goto cleanup;
+
+    } else {
+        sprintf(buf, "%s: 0x%x\n", wu.name, wu.error_mask);
+        return write_error(buf);
+    }
+    retval = 0;
+cleanup:
+    frt.close();       
+    return retval;
+}
diff --git a/BOINC software/BOINC server apps/chain_checker_assimilator/validate_util.cpp b/BOINC software/BOINC server apps/chain_checker_assimilator/validate_util.cpp
new file mode 100644 (file)
index 0000000..f3bf361
--- /dev/null
@@ -0,0 +1,564 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Code to facilitate writing validators.
+// Can be used as the basis for a validator that accepts everything
+// (see sample_trivial_validator.C),
+// or that requires strict equality (see sample_bitwise_validator.C)
+// or that uses fuzzy comparison.
+
+#include <cstring>
+#include "config.h"
+
+#include "error_numbers.h"
+#include "parse.h"
+#include "util.h"
+#include "filesys.h"
+
+#include "sched_util.h"
+#include "sched_config.h"
+#include "sched_msgs.h"
+#include "validator.h"
+#include "validate_util.h"
+
+using std::vector;
+using std::string;
+
+int FILE_INFO::parse(XML_PARSER& xp) {
+    char tag[256];
+    bool is_tag, found=false;
+    optional = false;
+    no_validate = false;
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "/file_ref")) {
+            return found?0:ERR_XML_PARSE;
+        }
+        if (xp.parse_string(tag, "file_name", name)) {
+            found = true;
+            continue;
+        }
+        if (xp.parse_bool(tag, "optional", optional)) continue;
+        if (xp.parse_bool(tag, "no_validate", no_validate)) continue;
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_info(RESULT& result, FILE_INFO& fi) {
+    char tag[256], path[1024];
+    bool is_tag;
+    string name;
+    MIOFILE mf;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            int retval = fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_infos(RESULT& result, vector<FILE_INFO>& fis) {
+    char tag[256], path[1024];
+    bool is_tag;
+    MIOFILE mf;
+    string name;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    fis.clear();
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_INFO fi;
+            int retval =  fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            fis.push_back(fi);
+        }
+    }
+    return 0;
+}
+
+int get_output_file_path(RESULT& result, string& path) {
+    FILE_INFO fi;
+    int retval = get_output_file_info(result, fi);
+    if (retval) return retval;
+    path = fi.path;
+    return 0;
+}
+
+int get_output_file_paths(RESULT& result, vector<string>& paths) {
+    vector<FILE_INFO> fis;
+    int retval = get_output_file_infos(result, fis);
+    if (retval) return retval;
+    paths.clear();
+    for (unsigned int i=0; i<fis.size(); i++) {
+        paths.push_back(fis[i].path);
+    }
+    return 0;
+}
+
+struct FILE_REF {
+    char file_name[256];
+    char open_name[256];
+    int parse(XML_PARSER& xp) {
+        char tag[256];
+        bool is_tag;
+
+        strcpy(file_name, "");
+        strcpy(open_name, "");
+        while (!xp.get(tag, sizeof(tag), is_tag)) {
+            if (!is_tag) continue;
+            if (!strcmp(tag, "/file_ref")) {
+                return 0;
+            }
+            if (xp.parse_str(tag, "file_name", file_name, sizeof(file_name))) continue;
+            if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) continue;
+        }
+        return ERR_XML_PARSE;
+    }
+};
+
+// given a path returned by the above, get the corresponding logical name
+//
+int get_logical_name(RESULT& result, string& path, string& name) {
+    char phys_name[1024];
+    char tag[256];
+    bool is_tag;
+    MIOFILE mf;
+    int retval;
+
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+
+    strcpy(phys_name, path.c_str());
+    char* p = strrchr(phys_name, '/');
+    if (!p) return ERR_NOT_FOUND;
+    strcpy(phys_name, p+1);
+
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "result")) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_REF fr;
+            retval = fr.parse(xp);
+            if (retval) continue;
+            if (!strcmp(phys_name, fr.file_name)) {
+                name = fr.open_name;
+                return 0;
+            }
+            continue;
+        }
+        xp.skip_unexpected(tag, false, 0);
+    }
+    return ERR_XML_PARSE;
+}
+
+#define CREDIT_EPSILON .001
+
+// If we have N correct results with nonzero claimed credit,
+// compute a canonical credit as follows:
+// - if N==0 (all claimed credits are infinitesmal), return CREDIT_EPSILON
+// - if N==1, return that credit
+// - if N==2, return min
+// - if N>2, toss out min and max, return average of rest
+//
+double median_mean_credit(WORKUNIT& /*wu*/, vector<RESULT>& results) {
+    int ilow=-1, ihigh=-1;
+    double credit_low = 0, credit_high = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < CREDIT_EPSILON) continue;
+        if (ilow < 0) {
+            ilow = ihigh = i;
+            credit_low = credit_high = result.claimed_credit;
+        } else {
+            if (result.claimed_credit < credit_low) {
+                ilow = i;
+                credit_low = result.claimed_credit;
+            }
+            if (result.claimed_credit > credit_high) {
+                ihigh = i;
+                credit_high = result.claimed_credit;
+            }
+        }
+        nvalid++;
+    }
+
+    switch(nvalid) {
+    case 0:
+        return CREDIT_EPSILON;
+    case 1:
+    case 2:
+        return credit_low;
+    default:
+        double sum = 0;
+        for (i=0; i<results.size(); i++) {
+            if (i == (unsigned int) ilow) continue;
+            if (i == (unsigned int) ihigh) continue;
+            RESULT& result = results[i];
+            if (result.validate_state != VALIDATE_STATE_VALID) continue;
+
+            sum += result.claimed_credit;
+        }
+        return sum/(nvalid-2);
+    }
+}
+
+int get_credit_from_wu(WORKUNIT& wu, vector<RESULT>&, double& credit) {
+    double x;
+    int retval;
+    DB_WORKUNIT dbwu;
+
+    dbwu.id = wu.id;
+    retval = dbwu.get_field_str("xml_doc", dbwu.xml_doc, sizeof(dbwu.xml_doc));
+    if (!retval) {
+        if (parse_double(dbwu.xml_doc, "<credit>", x)) {
+            credit = x;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+// This function should be called from the validator whenever credit
+// is granted to a host.  It's purpose is to track the average credit
+// per cpu time for that host.
+//
+// It updates an exponentially-decaying estimate of credit_per_cpu_sec
+// Note that this does NOT decay with time, but instead decays with
+// total credits earned.  If a host stops earning credits, then this
+// quantity stops decaying.  So credit_per_cpu_sec must NOT be
+// periodically decayed using the update_stats utility or similar
+// methods.
+//
+// The intended purpose is for cross-project credit comparisons on
+// BOINC statistics pages, for hosts attached to multiple machines.
+// One day people will write PhD theses on how to normalize credit
+// values to equalize them across projects.  I hope this will be done
+// according to "Allen's principle": "Credits granted by a project
+// should be normalized so that, averaged across all hosts attached to
+// multiple projects, projects grant equal credit per cpu second."
+// This principle ensures that (on average) participants will choose
+// projects based on merit, not based on credits.  It also ensures
+// that (on average) host machines migrate to the projects for which
+// they are best suited.
+//
+// For cross-project comparison the value of credit_per_cpu_sec should
+// be exported in the statistics file host_id.gz, which is written by
+// the code in db_dump.C.
+//
+// Algorithm: credits_per_cpu_second should be updated each time that
+// a host is granted credit, according to:
+//
+//     CREDIT_AVERAGE_CONST = 500           [see Note 5]
+//     MAX_CREDIT_PER_CPU_SEC = 0.1         [see Note 6]
+//
+//     e = tanh(granted_credit/CREDIT_AVERAGE_CONST)
+//     if (e < 0) then e = 0
+//     if (e > 1) then e = 1
+//     if (credit_per_cpu_sec <= 0) then e = 1
+//     if (cpu_time <= 0) then e = 0        [see Note 4]
+//     if (granted_credit <= 0) then e = 0  [see Note 3]
+//
+//     rate = granted_credit/cpu_time
+//     if (rate < 0) rate = 0
+//     if (rate > MAX_CREDIT_PER_CPU_SEC) rate = MAX_CREDIT_PER_CPU_SEC
+//
+//     credit_per_cpu_sec = e * rate + (1 - e) * credit_per_cpu_sec
+
+// Note 0: all quantities above should be treated as real numbers
+// Note 1: cpu_time is measured in seconds
+// Note 2: When a host is created, the initial value of
+//         credit_per_cpu_sec, should be zero.
+// Note 3: If a host has done invalid work (granted_credit==0) we have
+//         chosen not to include it.  One might argue that the
+//         boundary case granted_credit==0 should be treated the same
+//         as granted_credit>0.  However the goal here is not to
+//         identify cpus whose host machines sometimes produce
+//         rubbish.  It is to get a measure of how effectively the cpu
+//         runs the application code.
+// Note 4: e==0 means 'DO NOT include the first term on the rhs of the
+//         equation defining credit_per_cpu_sec' which is equivalent
+//         to 'DO NOT update credit_per_cpu_sec'.
+// Note 5: CREDIT_AVERAGE_CONST determines the exponential decay
+//         credit used in averaging credit_per_cpu_sec.  It may be
+//         changed at any time, even if the project database has
+//         already been populated with non-zero values of
+//         credit_per_cpu_sec.
+// Note 6: Typical VERY FAST cpus have credit_per_cpu_sec of around
+//         0.02.  This is a safety mechanism designed to prevent
+//         trouble if a client or host has reported absurd values (due
+//         to a bug in client or server software or by cheating).  In
+//         five years when cpus are five time faster, please increase
+//         the value of R.  You may also want to increase the value of
+//         CREDIT_AVERAGE_CONST.
+//
+//         Nonzero return value: host exceeded the max allowed
+//         credit/cpu_sec.
+//
+int update_credit_per_cpu_sec(
+    double  granted_credit,     // credit granted for this work
+    double  cpu_time,           // cpu time (seconds) used for this work
+    double& credit_per_cpu_sec  // (average) credit per cpu second
+) {
+    int retval = 0;
+
+    // Either of these values may be freely changed in the future.
+    // When CPUs get much faster one must increase the 'sanity-check'
+    // value of max_credit_per_cpu_sec.  At that time it would also
+    // make sense to proportionally increase the credit_average_const.
+    //
+    const double credit_average_const = 500;
+    const double max_credit_per_cpu_sec = 0.07;
+
+    double e = tanh(granted_credit/credit_average_const);
+    if (e <= 0.0 || cpu_time == 0.0 || granted_credit == 0.0) return retval;
+    if (e > 1.0 || credit_per_cpu_sec == 0.0) e = 1.0;
+
+    double rate =  granted_credit/cpu_time;
+    if (rate < 0.0) rate = 0.0;
+    if (rate > max_credit_per_cpu_sec) {
+        rate = max_credit_per_cpu_sec;
+        retval = 1;
+    }
+
+    credit_per_cpu_sec = e * rate + (1.0 - e) * credit_per_cpu_sec;
+
+    return retval;
+}
+
+double stddev_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    double credit_low_bound = 0, credit_high_bound = 0;
+    double penalize_credit_high_bound = 0;
+    double credit_avg = 0;
+    double credit = 0;
+    double old = 0;
+    double std_dev = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    nvalid = 0;
+    //calculate stddev difference
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        std_dev = pow(credit_avg - result.claimed_credit,2) + std_dev;
+        nvalid++;
+    }
+
+    std_dev = std_dev/ (double) nvalid;
+    std_dev = sqrt(std_dev);
+
+    credit_low_bound = credit_avg-std_dev;
+    if (credit_low_bound > credit_avg*.85) {
+        credit_low_bound = credit_avg*.85;
+    }
+    credit_low_bound = credit_low_bound - 2.5;
+    if (credit_low_bound < 1) credit_low_bound = 1;
+
+    credit_high_bound = credit_avg+std_dev;
+    if (credit_high_bound < credit_avg*1.15) {
+        credit_high_bound = credit_avg*1.15;
+    }
+    credit_high_bound = credit_high_bound + 5;
+
+
+    nvalid=0;
+    credit = 0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < credit_high_bound && result.claimed_credit > credit_low_bound) {
+            credit = credit + result.claimed_credit;
+            nvalid++;
+        } else {
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_SD Discarding invalid credit %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit,
+                credit_avg, credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    double grant_credit;
+    switch(nvalid) {
+    case 0:
+        grant_credit = median_mean_credit(wu, results);
+        old = grant_credit;
+        break;
+    default:
+        grant_credit = credit/nvalid;
+        old = median_mean_credit(wu, results);
+    }
+
+    // Log what happened
+    if (old > grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Less awarded\n",
+            grant_credit, old
+        );
+    } else if (old == grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Same awarded\n",
+            grant_credit, old
+        );
+    } else {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  More awarded\n",
+            grant_credit, old
+        );
+    }
+
+    // penalize hosts that are claiming too much
+    penalize_credit_high_bound = grant_credit+1.5*std_dev;
+    if (penalize_credit_high_bound < grant_credit*1.65) {
+        penalize_credit_high_bound = grant_credit*1.65;
+    }
+    penalize_credit_high_bound = penalize_credit_high_bound + 20;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit > penalize_credit_high_bound) {
+            result.granted_credit = grant_credit * 0.5;
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_PENALTY Penalizing host for too high credit %.1lf, grant %.1lf, penalize %.1lf, stddev %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit, grant_credit,
+                penalize_credit_high_bound, std_dev, credit_avg,
+                credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    return grant_credit;
+}
+
+double two_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    unsigned int i;
+    double credit = 0;
+    double credit_avg = 0;
+    double last_credit = 0;
+    int nvalid = 0;
+    double grant_credit;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        last_credit = result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    // If more then 2 valid results, compute via stddev method
+    if (nvalid > 2) return stddev_credit(wu, results);
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Only 2 results \n",wu.id, wu.name
+    );
+
+    // If only 2, then check to see if range is reasonable
+    if (fabs(last_credit - credit_avg) < 0.15*credit_avg) return credit_avg;
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Average is more than 15 percent from each value \n",
+        wu.id, wu.name
+    );
+
+    // log data on large variance in runtime
+    float cpu_time = 0.0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.cpu_time < 30) continue;
+        if (cpu_time == 0) {
+            cpu_time = result.cpu_time*1.0;
+        } else {
+            if (cpu_time/result.cpu_time > 2 || cpu_time/result.cpu_time < 0.5) {
+                log_messages.printf(MSG_DEBUG,
+                    "[WORKUNIT#%d %s] Large difference in runtime \n",
+                    wu.id, wu.name
+                );
+            }
+        }
+    }
+
+
+    //find result with smallest deviation from historical credit and award that value
+    DB_HOST host;
+    double deviation = -1;
+    grant_credit = credit_avg; // default award in case nobody matches the cases
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        host.lookup_id(result.hostid);
+        log_messages.printf(MSG_DEBUG,
+            "[RESULT#%d %s] Claimed Credit = %.2lf  Historical Credit = %.2lf \n",
+            result.id, result.name, result.claimed_credit,
+            result.cpu_time*host.credit_per_cpu_sec
+        );
+        if ((deviation < 0 || deviation > fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec)) && result.cpu_time > 30) {
+            deviation = fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec);
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] Credit deviation = %.2lf \n",
+                result.id, result.name, deviation
+            );
+            grant_credit = result.claimed_credit;
+        }
+    }
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Credit granted = %.2lf \n",
+        wu.id, wu.name, grant_credit
+    );
+    return grant_credit;
+}
+
+const char *BOINC_RCSID_07049e8a0e = "$Id: validate_util.cpp 16069 2008-09-26 18:20:24Z davea $";
diff --git a/BOINC software/BOINC server apps/chain_checker_workgenerator/Makefile b/BOINC software/BOINC server apps/chain_checker_workgenerator/Makefile
new file mode 100644 (file)
index 0000000..f95f992
--- /dev/null
@@ -0,0 +1,56 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/boincadm/src/boinc
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+BOINC_SCHED_DIR = $(BOINC_DIR)/sched
+BOINC_DB_DIR = $(BOINC_DIR)/db
+BOINC_TOOLS_DIR = $(BOINC_DIR)/tools
+MYSQL_DIR = /usr/include/mysql
+
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -I$(BOINC_SCHED_DIR) \
+    -I$(BOINC_DB_DIR) \
+    -I$(MYSQL_DIR) \
+    -I$(BOINC_TOOLS_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L$(BOINC_SCHED_DIR) \
+    -L/usr/X11R6/lib \
+    -L/usr/lib/mysql \
+    -L.
+
+# the following should be freeglut; use nm to check
+# you may have to change the paths for your system
+
+ifeq ($(wildcard /usr/local/lib/libglut.a),)
+       LIBGLUT = /usr/lib/libglut.a
+       LIBGLU = /usr/lib/libGLU.a
+       LIBJPEG = /usr/lib/libjpeg.a
+else
+       LIBGLUT = /usr/local/lib/libglut.a
+       LIBGLU = /usr/local/lib/libGLU.a
+       LIBJPEG = /usr/local/lib/libjpeg.a
+endif
+
+PROGS = distrrtgen \
+# uc2_graphics
+# make this optional so compile doesn't break on systems without OpenGL
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+distrrtgen: chain_checker_workgenerator.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_SCHED_DIR)/libsched.a 
+       $(CXX) chain_checker_workgenerator.cpp $(CXXFLAGS) -o chain_checker_workgenerator libstdc++.a -pthread -lboinc_api -lsched -lboinc -lmysqlclient -lssl -O3 
diff --git a/BOINC software/BOINC server apps/chain_checker_workgenerator/chain_checker_workgenerator.cpp b/BOINC software/BOINC server apps/chain_checker_workgenerator/chain_checker_workgenerator.cpp
new file mode 100644 (file)
index 0000000..351b25d
--- /dev/null
@@ -0,0 +1,218 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// sample_work_generator.C: an example BOINC work generator.
+// This work generator has the following properties
+// (you may need to change some or all of these):
+//
+// - Runs as a daemon, and creates an unbounded supply of work.
+//   It attempts to maintain a "cushion" of 100 unsent job instances.
+//   (your app may not work this way; e.g. you might create work in batches)
+// - Creates work for the application "uppercase".
+// - Creates a new input file for each job;
+//   the file (and the workunit names) contain a timestamp
+//   and sequence number, so that they're unique.
+
+#include <unistd.h>
+#include <cstdlib>
+#include <string>
+#include <cstring>
+
+#include "boinc_db.h"
+#include "filesys.h"
+#include "error_numbers.h"
+#include "backend_lib.h"
+#include "parse.h"
+#include "util.h"
+
+#include "sched_config.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+
+#define CUSHION 100
+#define int64 long long
+    // maintain at least this many unsent results
+#define REPLICATION_FACTOR 2
+// globals
+//
+char* wu_template;
+DB_APP app;
+DB_CONN *frt;
+int start_time;
+int seqno;
+
+using namespace std;
+// create one new job
+//
+int make_job() { 
+    DB_WORKUNIT wu;
+    MYSQL_RES* resp;    
+    MYSQL_ROW row;
+    char name[256], path[256], query[1024];
+    const char* infiles[1];
+    int retval;
+    string charset;
+    sprintf(query, "SELECT lookupid, hashroutine, charset, minletters, maxletters, `index`, hash FROM rainbowcrack_cracker_verificationqueue WHERE inuse = 0 LIMIT 1");
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval) {
+       log_messages.printf(MSG_DEBUG, "Query returned %i\n", retval);  
+       return retval;
+
+    }
+    resp = mysql_store_result(frt->mysql);
+    if (!resp) return ERR_DB_NOT_FOUND;
+    row = mysql_fetch_row(resp);
+    mysql_free_result(resp);
+    if (!row) return ERR_DB_NOT_FOUND;
+       
+    sprintf(query, "UPDATE rainbowcrack_cracker_verificationqueue SET inuse = 1 WHERE lookupid = %s", row[0]);
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval)  return retval;
+
+    char command_line[256];
+    char filename[256];
+    sprintf(command_line, "%s %s %s %s %s %s", row[1], row[2], row[3], row[4], row[5], row[6]);
+
+    // make a unique name (for the job and its input file)
+    //
+    sprintf(name, "%s_cc", row[0]);
+    retval = config.download_path(name, path);
+    if (retval) return retval;
+    log_messages.printf(MSG_DEBUG, "Path determined to be %s\n", path);
+    sprintf(filename, "/home/boincadm/chains/%s.chains", row[0]);
+    log_messages.printf(MSG_DEBUG, "Copying from %s to %s\n", filename, path);
+    retval = boinc_copy(filename, path);
+    if (retval) return retval;
+    log_messages.printf(MSG_DEBUG, "Removing old file %s\n", filename);
+    unlink(filename);
+
+    log_messages.printf(MSG_DEBUG, "%s\n", name); 
+    infiles[0] = name;
+    read_file_malloc("../templates/chain_checker_input_template.xml", wu_template);
+    // Fill in the job parameters
+    //
+    wu.clear();
+    wu.appid = app.id;
+    strcpy(wu.name, name);
+    wu.rsc_fpops_est = 1e12;
+    wu.rsc_fpops_bound = 1e14;
+    wu.rsc_memory_bound = 1e8;
+    wu.rsc_disk_bound = 1e8;
+    wu.delay_bound = 86400;
+    wu.min_quorum = 2;
+    wu.target_nresults = 2;
+    wu.max_error_results = 8;
+    wu.max_total_results = 10;
+    wu.max_success_results = 2;
+    // Register the job with BOINC
+    //
+    return create_work(
+        wu,
+        wu_template,
+        "templates/output_template.xml",
+        "../templates/output_template.xml",
+        infiles,
+        1,
+        config,
+       command_line
+    );
+}
+
+void main_loop() {
+    int retval;
+
+    while (1) {
+        check_stop_daemons();
+        int n;
+        retval = count_unsent_results(n, 0);
+        if (n > CUSHION) {
+            sleep(60);
+        } else {
+            int njobs = (CUSHION-n)/REPLICATION_FACTOR;
+            log_messages.printf(MSG_DEBUG,
+                "Making %d jobs\n", njobs
+            );
+            for (int i=0; i<njobs; i++) {
+                retval = make_job();
+                if (retval) {
+                    log_messages.printf(MSG_CRITICAL,
+                        "can't make job: %d\n", retval
+                    );
+                    exit(retval);
+                }
+            }
+            // Now sleep for a few seconds to let the transitioner
+            // create instances for the jobs we just created.
+            // Otherwise we could end up creating an excess of jobs.
+            sleep(5);
+        }
+    }
+}
+
+int main(int argc, char** argv) {
+    int i, retval;
+    frt = new DB_CONN();
+
+    for (i=1; i<argc; i++) {
+        if (!strcmp(argv[i], "-d")) {
+            log_messages.set_debug_level(atoi(argv[++i]));
+        } else {
+            log_messages.printf(MSG_CRITICAL,
+                "bad cmdline arg: %s", argv[i]
+            );
+        }
+    }
+
+    if (config.parse_file("..")) {
+        log_messages.printf(MSG_CRITICAL,
+            "can't read config file\n"
+        );
+        exit(1);
+    }
+    retval = frt->open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
+        exit(1);
+    }
+
+    retval = boinc_db.open(
+        config.db_name, config.db_host, config.db_user, config.db_passwd
+    );
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db\n");
+        exit(1);
+    }
+    if (app.lookup("where name='chain_checker'")) {
+        log_messages.printf(MSG_CRITICAL, "can't find app\n");
+        exit(1);
+    }
+    if (read_file_malloc("../templates/chain_checker_input_template.xml", wu_template)) {
+        log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
+        exit(1);
+    }
+
+    start_time = time(0);
+    seqno = 0;
+
+    log_messages.printf(MSG_NORMAL, "Starting\n");
+
+    main_loop();
+}
+
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/ChainWalkContext.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/ChainWalkContext.cpp
new file mode 100644 (file)
index 0000000..221fb15
--- /dev/null
@@ -0,0 +1,584 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkContext.h"
+
+#include <ctype.h>
+#include <openssl/rand.h>
+#ifdef _WIN32
+       #pragma comment(lib, "libeay32.lib")
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+string CChainWalkContext::m_sHashRoutineName;
+HASHROUTINE CChainWalkContext::m_pHashRoutine;
+int CChainWalkContext::m_nHashLen;
+int CChainWalkContext::m_nPlainLenMinTotal = 0;
+int CChainWalkContext::m_nPlainLenMaxTotal = 0;
+int CChainWalkContext::m_nHybridCharset = 0;
+vector<stCharset> CChainWalkContext::m_vCharset;
+uint64 CChainWalkContext::m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];
+uint64 CChainWalkContext::m_nPlainSpaceTotal;
+unsigned char CChainWalkContext::m_Salt[MAX_SALT_LEN];
+int CChainWalkContext::m_nSaltLen = 0;
+int CChainWalkContext::m_nRainbowTableIndex;
+uint64 CChainWalkContext::m_nReduceOffset;
+
+//////////////////////////////////////////////////////////////////////
+
+CChainWalkContext::CChainWalkContext()
+{
+}
+
+CChainWalkContext::~CChainWalkContext()
+{
+}
+
+bool CChainWalkContext::LoadCharset(string sName)
+{
+       m_vCharset.clear();
+       if (sName == "byte")
+       {
+               stCharset tCharset;
+               int i;
+               for (i = 0x00; i <= 0xff; i++)
+                       tCharset.m_PlainCharset[i] = i;
+               tCharset.m_nPlainCharsetLen = 256;
+               tCharset.m_sPlainCharsetName = sName;
+               tCharset.m_sPlainCharsetContent = "0x00, 0x01, ... 0xff";
+               m_vCharset.push_back(tCharset);
+               return true;
+       }
+       if(sName.substr(0, 6) == "hybrid") // Hybrid charset consisting of 2 charsets
+       {
+               m_nHybridCharset = 1;           
+       }
+       vector<string> vLine;
+       if (ReadLinesFromFile(CHARSET_TXT, vLine))
+       {
+               int i;
+               for (i = 0; i < vLine.size(); i++)
+               {
+                       // Filter comment
+                       if (vLine[i][0] == '#')
+                               continue;
+
+                       vector<string> vPart;
+                       if (SeperateString(vLine[i], "=", vPart))
+                       {
+                               // sCharsetName
+                               string sCharsetName = TrimString(vPart[0]);
+                               if (sCharsetName == "")
+                                       continue;
+                                                               
+                               // sCharsetName charset check
+                               bool fCharsetNameCheckPass = true;
+                               int j;
+                               for (j = 0; j < sCharsetName.size(); j++)
+                               {
+                                       if (   !isalpha(sCharsetName[j])
+                                               && !isdigit(sCharsetName[j])
+                                               && (sCharsetName[j] != '-'))
+                                       {
+                                               fCharsetNameCheckPass = false;
+                                               break;
+                                       }
+                               }
+                               if (!fCharsetNameCheckPass)
+                               {
+                                       printf("invalid charset name %s in charset configuration file\n", sCharsetName.c_str());
+                                       continue;
+                               }
+
+                               // sCharsetContent
+                               string sCharsetContent = TrimString(vPart[1]);
+                               if (sCharsetContent == "" || sCharsetContent == "[]")
+                                       continue;
+                               if (sCharsetContent[0] != '[' || sCharsetContent[sCharsetContent.size() - 1] != ']')
+                               {
+                                       printf("invalid charset content %s in charset configuration file\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+                               sCharsetContent = sCharsetContent.substr(1, sCharsetContent.size() - 2);
+                               if (sCharsetContent.size() > 256)
+                               {
+                                       printf("charset content %s too long\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+
+                               //printf("%s = [%s]\n", sCharsetName.c_str(), sCharsetContent.c_str());
+
+                               // Is it the wanted charset?
+                               if(m_nHybridCharset == 1)
+                               {
+                                       vector<tCharset> vCharsets;
+                                       GetHybridCharsets(sName, vCharsets);
+                                       if(sCharsetName == vCharsets[m_vCharset.size()].sName)
+                                       {
+                                               stCharset tCharset = {0};
+                                               tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                               memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                               tCharset.m_sPlainCharsetName = sCharsetName;
+                                               tCharset.m_sPlainCharsetContent = sCharsetContent;      
+                                               tCharset.m_nPlainLenMin = vCharsets[m_vCharset.size()].nPlainLenMin;
+                                               tCharset.m_nPlainLenMax = vCharsets[m_vCharset.size()].nPlainLenMax;
+                                               m_vCharset.push_back(tCharset);
+                                               if(vCharsets.size() == m_vCharset.size())
+                                                       return true;
+                                               i = 0; // Start the lookup over again for the next charset
+                                       }                                               
+                               }
+                               else if (sCharsetName == sName)
+                               {
+                                       stCharset tCharset;
+                                       tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                       memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                       tCharset.m_sPlainCharsetName = sCharsetName;
+                                       tCharset.m_sPlainCharsetContent = sCharsetContent;                                                      
+                                       m_vCharset.push_back(tCharset);
+                                       return true;
+                               }
+                       }
+               }
+               printf("charset %s not found in charset.txt\n", sName.c_str());
+       }
+       else
+               printf("can't open charset configuration file\n");
+       return false;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+bool CChainWalkContext::SetHashRoutine(string sHashRoutineName)
+{
+       CHashRoutine hr;
+       hr.GetHashRoutine(sHashRoutineName, m_pHashRoutine, m_nHashLen);
+       if (m_pHashRoutine != NULL)
+       {
+               m_sHashRoutineName = sHashRoutineName;
+               return true;
+       }
+       else
+               return false;
+}
+
+bool CChainWalkContext::SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax)
+{
+       // m_PlainCharset, m_nPlainCharsetLen, m_sPlainCharsetName, m_sPlainCharsetContent
+       if (!LoadCharset(sCharsetName))
+               return false;
+
+       if(m_vCharset.size() == 1) // Not hybrid charset
+       {
+               // m_nPlainLenMin, m_nPlainLenMax
+               if (nPlainLenMin < 1 || nPlainLenMax > MAX_PLAIN_LEN || nPlainLenMin > nPlainLenMax)
+               {
+                       printf("invalid plaintext length range: %d - %d\n", nPlainLenMin, nPlainLenMax);
+                       return false;
+               }
+               m_vCharset[0].m_nPlainLenMin = nPlainLenMin;
+               m_vCharset[0].m_nPlainLenMax = nPlainLenMax;
+       }
+       // m_nPlainSpaceUpToX
+       m_nPlainSpaceUpToX[0] = 0;
+       m_nPlainLenMaxTotal = 0;
+       m_nPlainLenMinTotal = 0;
+       uint64 nTemp = 1;
+       int j, k = 1;
+       for(j = 0; j < m_vCharset.size(); j++)
+       {
+               int i;
+               m_nPlainLenMaxTotal += m_vCharset[j].m_nPlainLenMax;
+               m_nPlainLenMinTotal += m_vCharset[j].m_nPlainLenMin;
+               for (i = 1; i <= m_vCharset[j].m_nPlainLenMax; i++)
+               {                       
+                       nTemp *= m_vCharset[j].m_nPlainCharsetLen;
+                       if (i < m_vCharset[j].m_nPlainLenMin)
+                               m_nPlainSpaceUpToX[k] = 0;
+                       else
+                               m_nPlainSpaceUpToX[k] = m_nPlainSpaceUpToX[k - 1] + nTemp;
+                       k++;
+               }               
+       }
+       // m_nPlainSpaceTotal
+       m_nPlainSpaceTotal = m_nPlainSpaceUpToX[m_nPlainLenMaxTotal];
+
+       return true;
+}
+
+bool CChainWalkContext::SetRainbowTableIndex(int nRainbowTableIndex)
+{
+       if (nRainbowTableIndex < 0)
+               return false;
+       m_nRainbowTableIndex = nRainbowTableIndex;
+       m_nReduceOffset = 65536 * nRainbowTableIndex;
+
+       return true;
+}
+
+bool CChainWalkContext::SetSalt(unsigned char *Salt, int nSaltLength)
+{
+       memcpy(&m_Salt[0], Salt, nSaltLength);
+       
+       m_nSaltLen = nSaltLength;
+//     m_sSalt = sSalt;
+       return true;
+}
+
+bool CChainWalkContext::SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount)
+{
+       // something like lm_alpha#1-7_0_100x16_test.rt
+
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       if (nIndex != -1)
+               sPathName = sPathName.substr(nIndex + 1);
+
+       if (sPathName.size() < 3)
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+       /*
+       if (sPathName.substr(sPathName.size() - 4) != ".rti")
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+*/
+       // Parse
+       vector<string> vPart;
+       if (!SeperateString(sPathName, "___x_", vPart))
+       {
+               printf("filename %s not identified\n", sPathName.c_str());
+               return false;
+       }
+
+       string sHashRoutineName   = vPart[0];
+       int nRainbowTableIndex    = atoi(vPart[2].c_str());
+       nRainbowChainLen          = atoi(vPart[3].c_str());
+       nRainbowChainCount        = atoi(vPart[4].c_str());
+
+       // Parse charset definition
+       string sCharsetDefinition = vPart[1];
+       string sCharsetName;
+       int nPlainLenMin = 0, nPlainLenMax = 0;         
+
+//     printf("Charset: %s", sCharsetDefinition.c_str());
+       
+       if(sCharsetDefinition.substr(0, 6) == "hybrid") // Hybrid table
+       {
+               sCharsetName = sCharsetDefinition;
+       }
+       else
+       {
+               if (sCharsetDefinition.find('#') == -1)         // For backward compatibility, "#1-7" is implied
+               {                       
+                       sCharsetName = sCharsetDefinition;
+                       nPlainLenMin = 1;
+                       nPlainLenMax = 7;
+               }
+               else
+               {
+                       vector<string> vCharsetDefinitionPart;
+                       if (!SeperateString(sCharsetDefinition, "#-", vCharsetDefinitionPart))
+                       {
+                               printf("filename %s not identified\n", sPathName.c_str());
+                               return false;   
+                       }
+                       else
+                       {
+                               sCharsetName = vCharsetDefinitionPart[0];
+                               nPlainLenMin = atoi(vCharsetDefinitionPart[1].c_str());
+                               nPlainLenMax = atoi(vCharsetDefinitionPart[2].c_str());
+                       }
+               }
+       }
+       // Setup
+       if (!SetHashRoutine(sHashRoutineName))
+       {
+               printf("hash routine %s not supported\n", sHashRoutineName.c_str());
+               return false;
+       }
+       if (!SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+               return false;
+       if (!SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               printf("invalid rainbow table index %d\n", nRainbowTableIndex);
+               return false;
+       }
+       m_nPlainSpaceTotal = m_nPlainSpaceUpToX[m_nPlainLenMaxTotal];
+       return true;
+}
+
+string CChainWalkContext::GetHashRoutineName()
+{
+       return m_sHashRoutineName;
+}
+
+int CChainWalkContext::GetHashLen()
+{
+       return m_nHashLen;
+}
+
+string CChainWalkContext::GetPlainCharsetName()
+{
+       return m_vCharset[0].m_sPlainCharsetName;
+}
+
+string CChainWalkContext::GetPlainCharsetContent()
+{
+       return m_vCharset[0].m_sPlainCharsetContent;
+}
+
+int CChainWalkContext::GetPlainLenMin()
+{
+       return m_vCharset[0].m_nPlainLenMin;
+}
+
+int CChainWalkContext::GetPlainLenMax()
+{
+       return m_vCharset[0].m_nPlainLenMax;
+}
+
+uint64 CChainWalkContext::GetPlainSpaceTotal()
+{
+       return m_nPlainSpaceTotal;
+}
+
+int CChainWalkContext::GetRainbowTableIndex()
+{
+       return m_nRainbowTableIndex;
+}
+
+void CChainWalkContext::Dump()
+{
+       printf("hash routine: %s\n", m_sHashRoutineName.c_str());
+       printf("hash length: %d\n", m_nHashLen);
+
+       printf("plain charset: ");
+       int i;
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+       {
+               if (isprint(m_vCharset[0].m_PlainCharset[i]))
+                       printf("%c", m_vCharset[0].m_PlainCharset[i]);
+               else
+                       printf("?");
+       }
+       printf("\n");
+
+       printf("plain charset in hex: ");
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+               printf("%02x ", m_vCharset[0].m_PlainCharset[i]);
+       printf("\n");
+
+       printf("plain length range: %d - %d\n", m_vCharset[0].m_nPlainLenMin, m_vCharset[0].m_nPlainLenMax);
+       printf("plain charset name: %s\n", m_vCharset[0].m_sPlainCharsetName.c_str());
+       //printf("plain charset content: %s\n", m_sPlainCharsetContent.c_str());
+       //for (i = 0; i <= m_nPlainLenMax; i++)
+       //      printf("plain space up to %d: %s\n", i, uint64tostr(m_nPlainSpaceUpToX[i]).c_str());
+       printf("plain space total: %s\n", uint64tostr(m_nPlainSpaceTotal).c_str());
+
+       printf("rainbow table index: %d\n", m_nRainbowTableIndex);
+       printf("reduce offset: %s\n", uint64tostr(m_nReduceOffset).c_str());
+       printf("\n");
+}
+/*
+void CChainWalkContext::GenerateRandomIndex()
+{
+       RAND_bytes((unsigned char*)&m_nIndex, 8);
+       m_nIndex = m_nIndex % m_nPlainSpaceTotal;
+}
+*/
+void CChainWalkContext::SetIndex(uint64 nIndex)
+{
+       m_nIndex = nIndex;
+}
+
+void CChainWalkContext::SetHash(unsigned char* pHash)
+{
+       memcpy(m_Hash, pHash, m_nHashLen);
+}
+
+void CChainWalkContext::IndexToPlain()
+{
+       int i;
+       m_nPlainLen = 0;
+       for (i = m_nPlainLenMaxTotal - 1; i >= m_nPlainLenMinTotal - 1; i--)
+       {
+               if (m_nIndex >= m_nPlainSpaceUpToX[i])
+               {
+                       m_nPlainLen = i + 1;
+                       break;
+               }
+       }
+       if(m_nPlainLen == 0)
+               m_nPlainLen = m_nPlainLenMinTotal;
+       uint64 nIndexOfX = m_nIndex - m_nPlainSpaceUpToX[m_nPlainLen - 1];
+
+#ifdef _WIN64
+       
+       // Slow version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); i++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                       }
+               }
+       }
+#else
+
+
+       // Fast version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+#ifdef _WIN32
+               if (nIndexOfX < 0x100000000I64)
+                       break;
+#else
+               if (nIndexOfX < 0x100000000llu)
+                       break;
+#endif
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_vCharset[j].m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                               break;
+                       }
+               }
+       }
+
+       unsigned int nIndexOfX32 = (unsigned int)nIndexOfX;
+       for (; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+
+//             m_Plain[i] = m_PlainCharset[nIndexOfX32 % m_vCharset[j].m_nPlainCharsetLen];
+//             nIndexOfX32 /= m_vCharset[j].m_nPlainCharsetLen;
+
+               unsigned int nPlainCharsetLen = m_vCharset[j].m_nPlainCharsetLen;
+               unsigned int nTemp;
+#ifdef _WIN32
+               __asm
+               {
+                       mov eax, nIndexOfX32
+                       xor edx, edx
+                       div nPlainCharsetLen
+                       mov nIndexOfX32, eax
+                       mov nTemp, edx
+               }
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#else
+               __asm__ __volatile__ (  "mov %2, %%eax;"
+                                                               "xor %%edx, %%edx;"
+                                                               "divl %3;"
+                                                               "mov %%eax, %0;"
+                                                               "mov %%edx, %1;"
+                                                               : "=m"(nIndexOfX32), "=m"(nTemp)
+                                                               : "m"(nIndexOfX32), "m"(nPlainCharsetLen)
+                                                               : "%eax", "%edx"
+                                                        );
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#endif
+               break;
+                       }
+               }
+       }
+#endif
+}
+
+void CChainWalkContext::PlainToHash()
+{      
+       m_pHashRoutine(m_Plain, m_nPlainLen, m_Hash);
+}
+
+void CChainWalkContext::HashToIndex(int nPos)
+{
+       m_nIndex = (*(uint64*)m_Hash + m_nReduceOffset + nPos) % m_nPlainSpaceTotal;
+}
+
+uint64 CChainWalkContext::GetIndex()
+{
+       return m_nIndex;
+}
+const uint64 *CChainWalkContext::GetIndexPtr()
+{
+       return &m_nIndex;
+}
+
+string CChainWalkContext::GetPlain()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < m_nPlainLen; i++)
+       {
+               char c = m_Plain[i];
+               if (c >= 32 && c <= 126)
+                       sRet += c;
+               else
+                       sRet += '?';
+       }
+       
+       return sRet;
+}
+
+string CChainWalkContext::GetBinary()
+{
+       return HexToStr(m_Plain, m_nPlainLen);
+}
+/*
+string CChainWalkContext::GetPlainBinary()
+{
+       string sRet;
+       sRet += GetPlain();
+       int i;
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += ' ';
+
+       sRet += "|";
+
+       sRet += GetBinary();
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += "  ";
+
+       return sRet;
+}
+*/
+string CChainWalkContext::GetHash()
+{
+       return HexToStr(m_Hash, m_nHashLen);
+}
+
+bool CChainWalkContext::CheckHash(unsigned char* pHash)
+{
+       if (memcmp(m_Hash, pHash, m_nHashLen) == 0)
+               return true;
+
+       return false;
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/ChainWalkContext.h b/BOINC software/BOINC server apps/distrrtgen_validator/ChainWalkContext.h
new file mode 100644 (file)
index 0000000..de7e2fb
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKCONTEXT_H
+#define _CHAINWALKCONTEXT_H
+
+#include "HashRoutine.h"
+#include "Public.h"
+
+typedef struct 
+{
+       unsigned char m_PlainCharset[255];
+       int m_nPlainCharsetLen;
+       int m_nPlainLenMin;
+       int m_nPlainLenMax;
+       string m_sPlainCharsetName;
+       string m_sPlainCharsetContent;
+} stCharset;
+class CChainWalkContext 
+{
+public:
+       CChainWalkContext();
+       virtual ~CChainWalkContext();
+
+private:
+       static string m_sHashRoutineName;       
+       static HASHROUTINE m_pHashRoutine;                                                      // Configuration
+       static int m_nHashLen;                                                                          // Configuration
+
+//     static unsigned char m_PlainCharset[256];                                       // Configuration
+//     static unsigned char m_PlainCharset2[256];                                      // Configuration
+       static vector<stCharset> m_vCharset;
+       static int m_nPlainLenMinTotal, m_nPlainLenMaxTotal;
+       static uint64 m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];            // Performance consideration
+       static uint64 m_nPlainSpaceTotal;                                                       // Performance consideration
+       static int m_nHybridCharset;
+       static int m_nRainbowTableIndex;                                                        // Configuration
+       static uint64 m_nReduceOffset;                                                          // Performance consideration
+
+       // Context
+       uint64 m_nIndex;
+       unsigned char m_Plain[MAX_PLAIN_LEN];
+       int m_nPlainLen;
+       unsigned char m_Hash[MAX_HASH_LEN];
+       static unsigned char m_Salt[MAX_SALT_LEN];
+       static int m_nSaltLen;
+private:
+       static bool LoadCharset(string sCharset);
+
+public:
+       static bool SetHashRoutine(string sHashRoutineName);                                                                                            // Configuration
+       static bool SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax);                           // Configuration
+       static bool SetRainbowTableIndex(int nRainbowTableIndex);       
+       static bool SetSalt(unsigned char *Salt, int nSaltLength);// Configuration
+       static bool SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount);        // Wrapper
+       static string GetHashRoutineName();
+       static int GetHashLen();
+       static string GetPlainCharsetName();
+       static string GetPlainCharsetContent();
+       static int GetPlainLenMin();
+       static int GetPlainLenMax();
+       static uint64 GetPlainSpaceTotal();
+       static int GetRainbowTableIndex();
+       static void Dump();
+
+//     void GenerateRandomIndex();
+       void SetIndex(uint64 nIndex);
+       void SetHash(unsigned char* pHash);             // The length should be m_nHashLen
+
+       void IndexToPlain();
+       void PlainToHash();
+       void HashToIndex(int nPos);
+
+       uint64 GetIndex();
+       const uint64* GetIndexPtr();
+       string GetPlain();
+       string GetBinary();
+//     string GetPlainBinary();
+       string GetHash();
+       bool CheckHash(unsigned char* pHash);   // The length should be m_nHashLen
+};
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/HashAlgorithm.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/HashAlgorithm.cpp
new file mode 100644 (file)
index 0000000..09fbb18
--- /dev/null
@@ -0,0 +1,359 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "HashAlgorithm.h"
+
+#include "Public.h"
+#include <string.h>
+//#include "md4.h"
+#include <openssl/md4.h>
+#include "md5.h"
+#include "des.h"
+#define MSCACHE_HASH_SIZE 16
+void setup_des_key(unsigned char key_56[], des_key_schedule &ks)
+{
+       des_cblock key;
+
+       key[0] = key_56[0];
+       key[1] = (key_56[0] << 7) | (key_56[1] >> 1);
+       key[2] = (key_56[1] << 6) | (key_56[2] >> 2);
+       key[3] = (key_56[2] << 5) | (key_56[3] >> 3);
+       key[4] = (key_56[3] << 4) | (key_56[4] >> 4);
+       key[5] = (key_56[4] << 3) | (key_56[5] >> 5);
+       key[6] = (key_56[5] << 2) | (key_56[6] >> 6);
+       key[7] = (key_56[6] << 1);
+
+       //des_set_odd_parity(&key);
+       des_set_key(&key, ks);
+}
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       /*
+       unsigned char data[7] = {0};
+       memcpy(data, pPlain, nPlainLen > 7 ? 7 : nPlainLen);
+       */
+
+       int i;
+       for (i = nPlainLen; i < 7; i++)
+               pPlain[i] = 0;
+
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       des_key_schedule ks;
+       //setup_des_key(data, ks);
+       setup_des_key(pPlain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pHash, ks, DES_ENCRYPT);
+}
+
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char pass[14];
+       unsigned char pre_lmresp[21];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+       des_key_schedule ks;
+
+       memset (pass,0,sizeof(pass));
+       memset (pre_lmresp,0,sizeof(pre_lmresp));
+
+       memcpy (pass,pPlain, nPlainLen);
+
+       setup_des_key(pass, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(&pass[7], ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)&pre_lmresp[8], ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[7], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[14], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+
+} 
+
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{      
+       unsigned char pre_lmresp[8];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char salt[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+       des_key_schedule ks;
+       unsigned char plain[8] = {0};   
+       memcpy(plain, pPlain, nPlainLen);
+       setup_des_key(plain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)salt, (des_cblock*)pHash, ks, DES_ENCRYPT);
+} 
+
+
+
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+  unsigned char UnicodePlain[MAX_PLAIN_LEN];
+  static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+  
+  int len = (nPlainLen < 127) ? nPlainLen : 127;
+  int i;
+  
+  for (i = 0; i < len; i++)
+  {
+    UnicodePlain[i * 2] = pPlain[i];
+    UnicodePlain[i * 2 + 1] = 0x00;
+  }
+
+  des_key_schedule ks;
+  unsigned char lm[21];
+
+  MD4(UnicodePlain, len * 2, lm);
+  lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
+
+  setup_des_key(lm, ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[7], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[14], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+}
+
+/*
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char ToEncrypt[256];
+       char temp[256];
+       char username[256];
+
+       DES_cblock iv,iv2;
+       DES_key_schedule ks1,ks2;
+       unsigned char deskey_fixed[]={ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
+       int i,j;
+#ifdef _WIN32
+       strcpy_s(username, sizeof(username), "SYS");
+#else
+       strcpy(username, "SYS");
+#endif
+       int userlen = 3;
+#ifdef _WIN32
+       _strupr((char*) pPlain);
+#else
+       strupr((char*) pPlain);
+#endif
+       memset (ToEncrypt,0,sizeof(ToEncrypt));
+
+       for (i=1,j=0; j<userlen; i++,j++)
+       {
+               ToEncrypt[i] = username[j];
+               i++;
+       }
+
+       for (j=0; j<nPlainLen; i++,j++)
+       {
+               ToEncrypt[i] = pPlain[j];
+               i++;
+       }
+
+       i=i-1;
+       memset (iv,0,8);
+       memset (iv2,0,8);
+       DES_set_key((DES_cblock*) deskey_fixed, &ks1);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks1, &iv, DES_ENCRYPT);
+       DES_set_key((DES_cblock*) &iv, &ks2);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks2, &iv2, DES_ENCRYPT);
+       memcpy (pHash,iv2,8);
+}
+*/
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char UnicodePlain[MAX_PLAIN_LEN * 2];
+       int i;
+       for (i = 0; i < nPlainLen; i++)
+       {
+               UnicodePlain[i * 2] = pPlain[i];
+               UnicodePlain[i * 2 + 1] = 0x00;
+       }
+
+       MD4(UnicodePlain, nPlainLen * 2, pHash);
+//     printf("Plain: %s Hash: %x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x\n", pPlain, pHash[0], pHash[1], pHash[2], pHash[3], pHash[4], pHash[5], pHash[6], pHash[7], pHash[8], pHash[9], pHash[10], pHash[11], pHash[12], pHash[13], pHash[14], pHash[15]);
+}
+/*
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD2(pPlain, nPlainLen, pHash);
+}
+*/
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD4(pPlain, nPlainLen, pHash);
+}
+
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5_NEW(pPlain, nPlainLen, pHash);
+}
+void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5_NEW(pPlain, nPlainLen, pHash);
+       unsigned char hash[16];
+       memcpy(hash, pHash, 16);
+       MD5_NEW(hash, 16, pHash);
+}
+/*
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       SHA1(pPlain, nPlainLen, pHash);
+}
+
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       RIPEMD160(pPlain, nPlainLen, pHash);
+}
+
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char unicode_pwd[256];
+       char unicode_user[256];
+       static unsigned char username[] = "administrator";
+       static int userlen = 13;
+       unsigned char   final1[MD4_DIGEST_LENGTH];
+       MD4_CTX ctx;
+       int i;
+
+//     strcpy (username, "administrator");
+//     userlen = 13;
+
+       for (i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }
+
+       for (i=0; i<userlen; i++)
+       {
+               unicode_user[i*2] = username[i];
+               unicode_user[i*2+1] = 0x00;
+       }
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,unicode_pwd,nPlainLen*2);
+       MD4_Final(final1,&ctx);
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,final1,MD4_DIGEST_LENGTH);
+       MD4_Update(&ctx,(unsigned char*) unicode_user,userlen*2);
+       MD4_Final(pHash,&ctx);
+
+       /*
+       unsigned char unicode_pwd[256];
+       for (int i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }*/     
+       /*
+       unsigned char *buf = (unsigned char*)calloc(MSCACHE_HASH_SIZE + nSaltLength, sizeof(unsigned char));    
+       HashNTLM(pPlain, nPlainLen, buf, NULL);
+       //MD4(unicode_pwd, nPlainLen*2, buf);
+       memcpy(buf + MSCACHE_HASH_SIZE, pSalt, nSaltLength);
+       MD4(buf, MSCACHE_HASH_SIZE + nSaltLength, pHash); 
+       free(buf);
+       */
+//}
+
+//*********************************************************************************
+// Code for MySQL password hashing
+//*********************************************************************************
+/*
+inline void mysql_hash_password_323(unsigned long *result, const char *password) 
+{
+  register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
+  unsigned long tmp;
+  for (; *password ; password++) 
+  {
+    if (*password == ' ' || *password == '\t') continue;
+       tmp= (unsigned long) (unsigned char) *password;
+       nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
+       nr2+=(nr2 << 8) ^ nr;
+       add+=tmp;
+  }
+  result[0]=nr & (((unsigned long) 1L << 31) -1L); ;
+  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
+  return;
+}
+
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned long hash_pass[2];     
+       unsigned char* f = (unsigned char*) hash_pass;
+
+       unsigned char* pass = (unsigned char*) calloc (nPlainLen+4,sizeof(unsigned char));
+       memcpy(pass,pPlain,nPlainLen);
+
+       mysql_hash_password_323(hash_pass, (char*) pass);
+       pHash[0]=*(f+3); pHash[1]=*(f+2); pHash[2]=*(f+1); pHash[3]=*(f+0);
+       pHash[4]=*(f+7); pHash[5]=*(f+6); pHash[6]=*(f+5); pHash[7]=*(f+4);
+
+       free (pass);
+}
+
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char hash_stage1[SHA_DIGEST_LENGTH];
+       SHA_CTX ctx;
+
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, (unsigned char *) pPlain, nPlainLen);
+       SHA1_Final(hash_stage1, &ctx);
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, hash_stage1, SHA_DIGEST_LENGTH);
+       SHA1_Final(pHash, &ctx);
+}
+*/
+//*********************************************************************************
+// Code for PIX password hashing
+//*********************************************************************************
+static char itoa64[] =          /* 0 ... 63 => ascii - 64 */
+        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void _crypt_to64(char *s, unsigned long v, int n)
+{
+        while (--n >= 0) {
+                *s++ = itoa64[v&0x3f];
+                v >>= 6;
+        }
+}
+/*
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char temp[MD5_DIGEST_LENGTH+1];
+       unsigned char final[MD5_DIGEST_LENGTH];
+       char* pass = (char*) calloc (nPlainLen+MD5_DIGEST_LENGTH,sizeof(char));
+
+       memcpy (pass,pPlain,nPlainLen);
+
+       MD5_CTX ctx;
+       MD5_Init(&ctx);
+       MD5_Update(&ctx, (unsigned char *) pass, MD5_DIGEST_LENGTH);
+       MD5_Final(final, &ctx);
+
+       char* p = (char*) temp;
+       _crypt_to64(p,*(unsigned long*) (final+0),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+4),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+8),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+12),4); p += 4;
+       *p=0;
+
+       memcpy(pHash,temp,MD5_DIGEST_LENGTH);
+
+       free (pass);
+}
+*/
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/HashAlgorithm.h b/BOINC software/BOINC server apps/distrrtgen_validator/HashAlgorithm.h
new file mode 100644 (file)
index 0000000..667245a
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHALGORITHM_H
+#define _HASHALGORITHM_H
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+//void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+/*void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash);
+//****************************************************************************
+// MySQL Password Hashing
+//****************************************************************************
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// Cisco PIX Password Hashing
+//****************************************************************************
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+*/
+//****************************************************************************
+// (HALF) LM CHALL hashing
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+// From mao
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+//void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/HashRoutine.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/HashRoutine.cpp
new file mode 100644 (file)
index 0000000..496f399
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "HashRoutine.h"
+#include "HashAlgorithm.h"
+
+//////////////////////////////////////////////////////////////////////
+
+CHashRoutine::CHashRoutine()
+{
+       // Notice: MIN_HASH_LEN <= nHashLen <= MAX_HASH_LEN
+
+
+       AddHashRoutine("lm",   HashLM,   8);
+       AddHashRoutine("ntlm", HashNTLM, 16);
+//     AddHashRoutine("md2",  HashMD2,  16);
+       AddHashRoutine("md4",  HashMD4,  16);
+       AddHashRoutine("md5",  HashMD5,  16);
+       AddHashRoutine("doublemd5",  HashDoubleMD5,  16);
+/*     AddHashRoutine("sha1", HashSHA1, 20);
+       AddHashRoutine("ripemd160", HashRIPEMD160, 20);
+       AddHashRoutine("mysql323", HashMySQL323, 8);
+       AddHashRoutine("mysqlsha1", HashMySQLSHA1, 20);
+       AddHashRoutine("ciscopix", HashPIX, 16);*/
+//     AddHashRoutine("mscache", HashMSCACHE, 16);
+       AddHashRoutine("halflmchall", HashHALFLMCHALL, 8);
+
+       // Added from mao
+       AddHashRoutine("lmchall", HashLMCHALL, 24);
+       AddHashRoutine("ntlmchall", HashNTLMCHALL, 24);
+//     AddHashRoutine("oracle", HashORACLE, 8);
+
+}
+
+CHashRoutine::~CHashRoutine()
+{
+}
+
+void CHashRoutine::AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen)
+{
+       vHashRoutineName.push_back(sHashRoutineName);
+       vHashRoutine.push_back(pHashRoutine);
+       vHashLen.push_back(nHashLen);
+}
+
+string CHashRoutine::GetAllHashRoutineName()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+               sRet += vHashRoutineName[i] + " ";
+
+       return sRet;
+}
+
+void CHashRoutine::GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+       {
+               if (sHashRoutineName == vHashRoutineName[i])
+               {
+                       pHashRoutine = vHashRoutine[i];
+                       nHashLen = vHashLen[i];
+                       return;
+               }
+       }
+
+       pHashRoutine = NULL;
+       nHashLen = 0;
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/HashRoutine.h b/BOINC software/BOINC server apps/distrrtgen_validator/HashRoutine.h
new file mode 100644 (file)
index 0000000..681fa78
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHROUTINE_H
+#define _HASHROUTINE_H
+
+#include <string>
+#include <vector>
+using namespace std;
+
+typedef void (*HASHROUTINE)(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+class CHashRoutine  
+{
+public:
+       CHashRoutine();
+       virtual ~CHashRoutine();
+
+private:
+       vector<string>          vHashRoutineName;
+       vector<HASHROUTINE>     vHashRoutine;
+       vector<int>                     vHashLen;
+       void AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen);
+
+public:
+       string GetAllHashRoutineName();
+       void GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen);
+};
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/Makefile b/BOINC software/BOINC server apps/distrrtgen_validator/Makefile
new file mode 100644 (file)
index 0000000..6c1d9aa
--- /dev/null
@@ -0,0 +1,43 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/frt/server_stable
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+BOINC_SCHED_DIR = $(BOINC_DIR)/sched
+BOINC_DB_DIR = $(BOINC_DIR)/db
+MYSQL_DIR = /usr/local/include/mysql
+MYSQL_LIB_DIR = /usr/local/lib/mysql
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -I$(BOINC_SCHED_DIR) \
+    -I$(BOINC_DB_DIR) \
+    -I$(MYSQL_DIR) \
+    -L$(MYSQL_LIB_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L$(BOINC_SCHED_DIR) \
+    -L/usr/X11R6/lib \
+    -L/usr/local/lib/mysql \
+    -L.
+
+# the following should be freeglut; use nm to check
+# you may have to change the paths for your system
+
+PROGS = distrrtgen \
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) distrrtgen_validator *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+distrrtgen: part_validator.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_SCHED_DIR)/libsched.a
+       $(CXX) Public.cpp *.c md4.cpp ChainWalkContext.cpp HashAlgorithm.cpp HashRoutine.cpp md5.cpp MemoryPool.cpp validate_util.cpp validate_util2.cpp validator.cpp $(CXXFLAGS) -o distrrtgen_validator part_validator.o libstdc++.a -pthread -lboinc_api $(BOINC_SCHED_DIR)/libsched.a -lboinc $(BOINC_LIB_DIR)/libboinc.a -lcrypto -lssl -lmysqlclient -O3 
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/MemoryPool.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/MemoryPool.cpp
new file mode 100644 (file)
index 0000000..35177ca
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "MemoryPool.h"
+#include "Public.h"
+
+CMemoryPool::CMemoryPool()
+{
+       m_pMem = NULL;
+       m_nMemSize = 0;
+
+       unsigned int nAvailPhys = GetAvailPhysMemorySize();
+       if (nAvailPhys < 16 * 1024 * 1024)
+       {
+               nAvailPhys = 512 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize()
+       }
+       if (nAvailPhys < 16 * 1024 * 1024)
+               m_nMemMax = nAvailPhys / 2;                                     // Leave some memory for CChainWalkSet
+       else
+               m_nMemMax = nAvailPhys - 8 * 1024 * 1024;       // Leave some memory for CChainWalkSet  
+}
+
+CMemoryPool::~CMemoryPool()
+{
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+}
+
+unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
+{
+       if (nFileLen <= m_nMemSize)
+       {
+               nAllocatedSize = nFileLen;
+               return m_pMem;
+       }
+
+       unsigned int nTargetSize;
+       if (nFileLen < m_nMemMax)
+               nTargetSize = nFileLen;
+       else
+               nTargetSize = m_nMemMax;
+
+       // Free existing memory
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+
+       // Allocate new memory
+       //printf("allocating %u bytes memory\n", nTargetSize);
+       m_pMem = new unsigned char[nTargetSize];
+       if (m_pMem != NULL)
+       {
+               m_nMemSize = nTargetSize;
+               nAllocatedSize = nTargetSize;
+               return m_pMem;
+       }
+       else
+       {
+               nAllocatedSize = 0;
+               return NULL;
+       }
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/MemoryPool.h b/BOINC software/BOINC server apps/distrrtgen_validator/MemoryPool.h
new file mode 100644 (file)
index 0000000..9f2ea4e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _MEMORYPOOL_H
+#define _MEMORYPOOL_H
+
+class CMemoryPool  
+{
+public:
+       CMemoryPool();
+       virtual ~CMemoryPool();
+
+private:
+       unsigned char* m_pMem;
+       unsigned int m_nMemSize;
+
+       unsigned int m_nMemMax;
+
+public:
+       unsigned char* Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize);
+};
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/Public.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/Public.cpp
new file mode 100644 (file)
index 0000000..ce2d430
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "Public.h"
+
+#ifdef _WIN32
+       #include <windows.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+unsigned int GetFileLen(FILE* file)
+{
+       unsigned int pos = ftell(file);
+       fseek(file, 0, SEEK_END);
+       unsigned int len = ftell(file);
+       fseek(file, pos, SEEK_SET);
+
+       return len;
+}
+
+string TrimString(string s)
+{
+       while (s.size() > 0)
+       {
+               if (s[0] == ' ' || s[0] == '\t')
+                       s = s.substr(1);
+               else
+                       break;
+       }
+
+       while (s.size() > 0)
+       {
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+                       s = s.substr(0, s.size() - 1);
+               else
+                       break;
+       }
+
+       return s;
+}
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+       // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+       if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+               return false;
+       size_t nEnd = sCharset.rfind(')');
+       size_t nStart = sCharset.rfind('(');
+       string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+       vector<string> vParts;
+       SeperateString(sChar, ",", vParts);
+       for(int i = 0; i < vParts.size(); i++)
+       {
+               tCharset stCharset;
+               vector<string> vParts2;
+               SeperateString(vParts[i], "#", vParts2);
+               stCharset.sName = vParts2[0];
+               vector<string> vParts3;
+               SeperateString(vParts2[1], "-", vParts3);
+               stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+               stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+               vCharset.push_back(stCharset);
+       }
+       return true;
+}
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+
+       FILE* file = fopen(sPathName.c_str(), "rb");
+       if (file != NULL) 
+       {
+               unsigned int len = GetFileLen(file);
+               char* data = new char[len + 1];
+               fread(data, 1, len, file);
+               data[len] = '\0';
+               string content = data;
+               content += "\n";
+               delete data;
+
+               unsigned int i;
+               for (i = 0; i < content.size(); i++)
+               {
+                       if (content[i] == '\r')
+                               content[i] = '\n';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       string line = content.substr(0, n);
+                       line = TrimString(line);
+                       if (line != "")
+                               vLine.push_back(line);
+                       content = content.substr(n + 1);
+               }
+
+               fclose(file);
+       }
+       else
+               return false;
+
+       return true;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+       vPart.clear();
+
+       unsigned int i;
+       for (i = 0; i < sSeperator.size(); i++)
+       {
+               int n = s.find(sSeperator[i]);
+               if (n != -1)
+               {
+                       vPart.push_back(s.substr(0, n));
+                       s = s.substr(n + 1);
+               }
+               else
+                       return false;
+       }
+       vPart.push_back(s);
+
+       return true;
+}
+
+string uint64tostr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%I64u", n);
+#else
+       sprintf(str, "%llu", n);
+#endif
+
+       return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%016I64x", n);
+#else
+       sprintf(str, "%016llx", n);
+#endif
+
+       return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+       string sRet;
+       int i;
+       for (i = 0; i < nLen; i++)
+       {
+               char szByte[3];
+               sprintf(szByte, "%02x", pData[i]);
+               sRet += szByte;
+       }
+
+       return sRet;
+}
+
+unsigned int GetAvailPhysMemorySize()
+{
+#ifdef _WIN32
+               MEMORYSTATUS ms;
+               GlobalMemoryStatus(&ms);
+               return ms.dwAvailPhys;
+#else
+/*     struct sysinfo info;
+       sysinfo(&info);                 // This function is Linux-specific
+       return info.freeram;*/
+       return 1024 * 1024 * 512;
+#endif
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < sHash.size() / 2; i++)
+       {
+               string sSub = sHash.substr(i * 2, 2);
+               int nValue;
+               sscanf(sSub.c_str(), "%02x", &nValue);
+               pHash[i] = (unsigned char)nValue;
+       }
+
+       nHashLen = sHash.size() / 2;
+}
+
+void Logo()
+{
+       printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+       printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+       printf("http://www.freerainbowtables.com/\n");
+       printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+       printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/Public.h b/BOINC software/BOINC server apps/distrrtgen_validator/Public.h
new file mode 100644 (file)
index 0000000..cb4c071
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _PUBLIC_H
+#define _PUBLIC_H
+
+#include <stdio.h>
+
+#include <string>
+#include <string.h>
+#include <cstdlib>
+#include <vector>
+#include <list>
+using namespace std;
+#define CHARSET_TXT "/home/frt/projects/distrrtgen/download/charset.txt"
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 unsigned long long
+#endif
+
+struct RainbowChain
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+};
+struct RainbowChainCP
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+       unsigned short nCheckPoint;
+};
+struct IndexChain
+{
+       uint64 nPrefix;
+       int nFirstChain;
+       unsigned int nChainCount;
+};
+struct FoundRainbowChain
+{
+       uint64 nIndexS;
+       int nIndexE;
+       int nCheckPoint;
+       int nGuessedPos;
+};
+struct IndexRow
+{
+       uint64 prefix;
+       unsigned int prefixstart, numchains;
+};
+
+typedef struct
+{
+       string sName;
+       int nPlainLenMin;
+       int nPlainLenMax;
+} tCharset;
+
+#define MAX_PLAIN_LEN 256
+#define MIN_HASH_LEN  8
+#define MAX_HASH_LEN  256
+#define MAX_SALT_LEN  256
+
+unsigned int GetFileLen(FILE* file);
+string TrimString(string s);
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine);
+bool SeperateString(string s, string sSeperator, vector<string>& vPart);
+string uint64tostr(uint64 n);
+string uint64tohexstr(uint64 n);
+string HexToStr(const unsigned char* pData, int nLen);
+unsigned int GetAvailPhysMemorySize();
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen);
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset);
+void Logo();
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/charset.txt b/BOINC software/BOINC server apps/distrrtgen_validator/charset.txt
new file mode 100644 (file)
index 0000000..6e749fa
--- /dev/null
@@ -0,0 +1,34 @@
+# charset configuration file for DistrRTgen v3.2 by Martin Westergaard (martinwj2005@gmail.com)
+
+byte                        = []
+alpha                       = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+alpha-space                 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+alpha-numeric               = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+alpha-numeric-space         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+alpha-numeric-symbol14      = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+= ]
+all                         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+all-space                   = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+lm-frt-cp437                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥àáâãäæçèéêëî]
+lm-frt-cp850                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9c\9d\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãåæèéêëíï]
+lm-frt-cp437-850            = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãäåæçèéêëíîï]
+
+numeric                     = [0123456789]
+numeric-space               = [0123456789 ]
+loweralpha                  = [abcdefghijklmnopqrstuvwxyz]
+loweralpha-space            = [abcdefghijklmnopqrstuvwxyz ]
+loweralpha-numeric          = [abcdefghijklmnopqrstuvwxyz0123456789]
+loweralpha-numeric-space    = [abcdefghijklmnopqrstuvwxyz0123456789 ]
+loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=]
+loweralpha-numeric-all             = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+mixalpha                    = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
+mixalpha-space              = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+mixalpha-numeric            = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+mixalpha-numeric-space      = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+mixalpha-numeric-symbol14   = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+mixalpha-numeric-all        = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+mixalpha-numeric-symbol32-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+mixalpha-numeric-all-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/des.h b/BOINC software/BOINC server apps/distrrtgen_validator/des.h
new file mode 100644 (file)
index 0000000..abe1401
--- /dev/null
@@ -0,0 +1,118 @@
+/*     $FreeBSD: src/sys/crypto/des/des.h,v 1.6 2002/03/20 05:13:51 alfred Exp $       */
+/*     $KAME: des.h,v 1.8 2001/09/10 04:03:57 itojun Exp $     */
+
+/* lib/des/des.h */
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_DES_H
+#define HEADER_DES_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+typedef unsigned int u_int32_t;
+
+/* must be 32bit quantity */
+#define DES_LONG u_int32_t
+
+typedef unsigned char des_cblock[8];
+typedef struct des_ks_struct
+       {
+       union   {
+       des_cblock cblock;
+       /* make sure things are correct size on machines with
+        * 8 byte longs */
+       DES_LONG deslong[2];
+       } ks;
+       int weak_key;
+} des_key_schedule[16];
+
+#define DES_KEY_SZ     (sizeof(des_cblock))
+#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
+
+#define DES_ENCRYPT    1
+#define DES_DECRYPT    0
+
+#define DES_CBC_MODE   0
+#define DES_PCBC_MODE  1
+
+extern int des_check_key;      /* defaults to false */
+
+char *des_options(void);
+void des_ecb_encrypt(des_cblock *, des_cblock *, des_key_schedule, int);
+
+void des_encrypt1(DES_LONG *, des_key_schedule, int);
+void des_encrypt2(DES_LONG *, des_key_schedule, int);
+void des_encrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
+                     des_key_schedule);
+void des_decrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
+                     des_key_schedule);
+
+void des_ecb3_encrypt(des_cblock *, des_cblock *, des_key_schedule, 
+                         des_key_schedule, des_key_schedule, int);
+
+void des_ncbc_encrypt(const unsigned char *, unsigned char *, long,
+                         des_key_schedule, des_cblock *, int);
+
+void des_ede3_cbc_encrypt(const unsigned char *, unsigned char *, long,
+                         des_key_schedule, des_key_schedule, 
+                         des_key_schedule, des_cblock *, int);
+
+void des_set_odd_parity(des_cblock *);
+void des_fixup_key_parity(des_cblock *); 
+int des_is_weak_key(des_cblock *);
+int des_set_key(des_cblock *, des_key_schedule);
+int des_key_sched(des_cblock *, des_key_schedule);
+int des_set_key_checked(des_cblock *, des_key_schedule);
+void des_set_key_unchecked(des_cblock *, des_key_schedule);
+int des_check_key_parity(des_cblock *);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/des_enc.c b/BOINC software/BOINC server apps/distrrtgen_validator/des_enc.c
new file mode 100644 (file)
index 0000000..78d2e78
--- /dev/null
@@ -0,0 +1,292 @@
+/*     $KAME: des_enc.c,v 1.1 2001/09/10 04:03:58 itojun Exp $ */
+
+/* crypto/des/des_enc.c */
+
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#include "des_locl.h"
+
+extern const DES_LONG DES_SPtrans[8][64];
+void des_encrypt1(DES_LONG *data, des_key_schedule ks, int enc)
+{
+       register DES_LONG l,r,t,u;
+#ifdef DES_PTR
+       register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
+#endif
+#ifndef DES_UNROLL
+       register int i;
+#endif
+       register DES_LONG *s;
+
+       r=data[0];
+       l=data[1];
+
+       IP(r,l);
+       /* Things have been modified so that the initial rotate is
+        * done outside the loop.  This required the
+        * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
+        * One perl script later and things have a 5% speed up on a sparc2.
+        * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
+        * for pointing this out. */
+       /* clear the top bits on machines with 8byte longs */
+       /* shift left by 2 */
+       r=ROTATE(r,29)&0xffffffffL;
+       l=ROTATE(l,29)&0xffffffffL;
+
+       s=ks->ks.deslong;
+       /* I don't know if it is worth the effort of loop unrolling the
+        * inner loop */
+       if (enc)
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r, 0); /*  1 */
+               D_ENCRYPT(r,l, 2); /*  2 */
+               D_ENCRYPT(l,r, 4); /*  3 */
+               D_ENCRYPT(r,l, 6); /*  4 */
+               D_ENCRYPT(l,r, 8); /*  5 */
+               D_ENCRYPT(r,l,10); /*  6 */
+               D_ENCRYPT(l,r,12); /*  7 */
+               D_ENCRYPT(r,l,14); /*  8 */
+               D_ENCRYPT(l,r,16); /*  9 */
+               D_ENCRYPT(r,l,18); /*  10 */
+               D_ENCRYPT(l,r,20); /*  11 */
+               D_ENCRYPT(r,l,22); /*  12 */
+               D_ENCRYPT(l,r,24); /*  13 */
+               D_ENCRYPT(r,l,26); /*  14 */
+               D_ENCRYPT(l,r,28); /*  15 */
+               D_ENCRYPT(r,l,30); /*  16 */
+#else
+               for (i=0; i<32; i+=8)
+                       {
+                       D_ENCRYPT(l,r,i+0); /*  1 */
+                       D_ENCRYPT(r,l,i+2); /*  2 */
+                       D_ENCRYPT(l,r,i+4); /*  3 */
+                       D_ENCRYPT(r,l,i+6); /*  4 */
+                       }
+#endif
+               }
+       else
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r,30); /* 16 */
+               D_ENCRYPT(r,l,28); /* 15 */
+               D_ENCRYPT(l,r,26); /* 14 */
+               D_ENCRYPT(r,l,24); /* 13 */
+               D_ENCRYPT(l,r,22); /* 12 */
+               D_ENCRYPT(r,l,20); /* 11 */
+               D_ENCRYPT(l,r,18); /* 10 */
+               D_ENCRYPT(r,l,16); /*  9 */
+               D_ENCRYPT(l,r,14); /*  8 */
+               D_ENCRYPT(r,l,12); /*  7 */
+               D_ENCRYPT(l,r,10); /*  6 */
+               D_ENCRYPT(r,l, 8); /*  5 */
+               D_ENCRYPT(l,r, 6); /*  4 */
+               D_ENCRYPT(r,l, 4); /*  3 */
+               D_ENCRYPT(l,r, 2); /*  2 */
+               D_ENCRYPT(r,l, 0); /*  1 */
+#else
+               for (i=30; i>0; i-=8)
+                       {
+                       D_ENCRYPT(l,r,i-0); /* 16 */
+                       D_ENCRYPT(r,l,i-2); /* 15 */
+                       D_ENCRYPT(l,r,i-4); /* 14 */
+                       D_ENCRYPT(r,l,i-6); /* 13 */
+                       }
+#endif
+               }
+
+       /* rotate and clear the top bits on machines with 8byte longs */
+       l=ROTATE(l,3)&0xffffffffL;
+       r=ROTATE(r,3)&0xffffffffL;
+
+       FP(r,l);
+       data[0]=l;
+       data[1]=r;
+       l=r=t=u=0;
+}
+
+void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
+{
+       register DES_LONG l,r,t,u;
+#ifdef DES_PTR
+       register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
+#endif
+#ifndef DES_UNROLL
+       register int i;
+#endif
+       register DES_LONG *s;
+
+       r=data[0];
+       l=data[1];
+
+       /* Things have been modified so that the initial rotate is
+        * done outside the loop.  This required the
+        * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
+        * One perl script later and things have a 5% speed up on a sparc2.
+        * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
+        * for pointing this out. */
+       /* clear the top bits on machines with 8byte longs */
+       r=ROTATE(r,29)&0xffffffffL;
+       l=ROTATE(l,29)&0xffffffffL;
+
+       s=ks->ks.deslong;
+       /* I don't know if it is worth the effort of loop unrolling the
+        * inner loop */
+       if (enc)
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r, 0); /*  1 */
+               D_ENCRYPT(r,l, 2); /*  2 */
+               D_ENCRYPT(l,r, 4); /*  3 */
+               D_ENCRYPT(r,l, 6); /*  4 */
+               D_ENCRYPT(l,r, 8); /*  5 */
+               D_ENCRYPT(r,l,10); /*  6 */
+               D_ENCRYPT(l,r,12); /*  7 */
+               D_ENCRYPT(r,l,14); /*  8 */
+               D_ENCRYPT(l,r,16); /*  9 */
+               D_ENCRYPT(r,l,18); /*  10 */
+               D_ENCRYPT(l,r,20); /*  11 */
+               D_ENCRYPT(r,l,22); /*  12 */
+               D_ENCRYPT(l,r,24); /*  13 */
+               D_ENCRYPT(r,l,26); /*  14 */
+               D_ENCRYPT(l,r,28); /*  15 */
+               D_ENCRYPT(r,l,30); /*  16 */
+#else
+               for (i=0; i<32; i+=8)
+                       {
+                       D_ENCRYPT(l,r,i+0); /*  1 */
+                       D_ENCRYPT(r,l,i+2); /*  2 */
+                       D_ENCRYPT(l,r,i+4); /*  3 */
+                       D_ENCRYPT(r,l,i+6); /*  4 */
+                       }
+#endif
+               }
+       else
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r,30); /* 16 */
+               D_ENCRYPT(r,l,28); /* 15 */
+               D_ENCRYPT(l,r,26); /* 14 */
+               D_ENCRYPT(r,l,24); /* 13 */
+               D_ENCRYPT(l,r,22); /* 12 */
+               D_ENCRYPT(r,l,20); /* 11 */
+               D_ENCRYPT(l,r,18); /* 10 */
+               D_ENCRYPT(r,l,16); /*  9 */
+               D_ENCRYPT(l,r,14); /*  8 */
+               D_ENCRYPT(r,l,12); /*  7 */
+               D_ENCRYPT(l,r,10); /*  6 */
+               D_ENCRYPT(r,l, 8); /*  5 */
+               D_ENCRYPT(l,r, 6); /*  4 */
+               D_ENCRYPT(r,l, 4); /*  3 */
+               D_ENCRYPT(l,r, 2); /*  2 */
+               D_ENCRYPT(r,l, 0); /*  1 */
+#else
+               for (i=30; i>0; i-=8)
+                       {
+                       D_ENCRYPT(l,r,i-0); /* 16 */
+                       D_ENCRYPT(r,l,i-2); /* 15 */
+                       D_ENCRYPT(l,r,i-4); /* 14 */
+                       D_ENCRYPT(r,l,i-6); /* 13 */
+                       }
+#endif
+               }
+       /* rotate and clear the top bits on machines with 8byte longs */
+       data[0]=ROTATE(l,3)&0xffffffffL;
+       data[1]=ROTATE(r,3)&0xffffffffL;
+       l=r=t=u=0;
+}
+
+void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
+            des_key_schedule ks3)
+{
+       register DES_LONG l,r;
+
+       l=data[0];
+       r=data[1];
+       IP(l,r);
+       data[0]=l;
+       data[1]=r;
+       des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
+       des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
+       des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
+       l=data[0];
+       r=data[1];
+       FP(r,l);
+       data[0]=l;
+       data[1]=r;
+}
+
+void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
+            des_key_schedule ks3)
+{
+       register DES_LONG l,r;
+
+       l=data[0];
+       r=data[1];
+       IP(l,r);
+       data[0]=l;
+       data[1]=r;
+       des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
+       des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
+       des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
+       l=data[0];
+       r=data[1];
+       FP(r,l);
+       data[0]=l;
+       data[1]=r;
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/des_locl.h b/BOINC software/BOINC server apps/distrrtgen_validator/des_locl.h
new file mode 100644 (file)
index 0000000..667c2dd
--- /dev/null
@@ -0,0 +1,364 @@
+/*     $FreeBSD: src/sys/crypto/des/des_locl.h,v 1.6 2002/03/05 09:19:02 ume Exp $     */
+/*     $KAME: des_locl.h,v 1.7 2001/09/10 04:03:58 itojun Exp $        */
+
+/* crypto/des/des_locl.h */
+/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_DES_LOCL_H
+#define HEADER_DES_LOCL_H
+
+#include "des.h"
+
+#undef DES_PTR
+
+#ifdef __STDC__
+#undef NOPROTO
+#endif
+
+#define ITERATIONS 16
+#define HALF_ITERATIONS 8
+
+/* used in des_read and des_write */
+#define MAXWRITE       (1024*16)
+#define BSIZE          (MAXWRITE+4)
+
+#define c2l(c,l)       (l =((DES_LONG)(*((c)++)))    , \
+                        l|=((DES_LONG)(*((c)++)))<< 8L, \
+                        l|=((DES_LONG)(*((c)++)))<<16L, \
+                        l|=((DES_LONG)(*((c)++)))<<24L)
+
+/* NOTE - c is not incremented as per c2l */
+#define c2ln(c,l1,l2,n)        { \
+                       c+=n; \
+                       l1=l2=0; \
+                       switch (n) { \
+                       case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
+                       case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
+                       case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
+                       case 5: l2|=((DES_LONG)(*(--(c))));     \
+                       case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
+                       case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
+                       case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
+                       case 1: l1|=((DES_LONG)(*(--(c))));     \
+                               } \
+                       }
+
+#define l2c(l,c)       (*((c)++)=(unsigned char)(((l)     )&0xff), \
+                        *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>24L)&0xff))
+
+/* replacements for htonl and ntohl since I have no idea what to do
+ * when faced with machines with 8 byte longs. */
+#define HDRSIZE 4
+
+#define n2l(c,l)       (l =((DES_LONG)(*((c)++)))<<24L, \
+                        l|=((DES_LONG)(*((c)++)))<<16L, \
+                        l|=((DES_LONG)(*((c)++)))<< 8L, \
+                        l|=((DES_LONG)(*((c)++))))
+
+#define l2n(l,c)       (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)     )&0xff))
+
+/* NOTE - c is not incremented as per l2c */
+#define l2cn(l1,l2,c,n)        { \
+                       c+=n; \
+                       switch (n) { \
+                       case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
+                       case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
+                       case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
+                       case 5: *(--(c))=(unsigned char)(((l2)     )&0xff); \
+                       case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
+                       case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
+                       case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
+                       case 1: *(--(c))=(unsigned char)(((l1)     )&0xff); \
+                               } \
+                       }
+
+#define        ROTATE(a,n)     (((a)>>(n))+((a)<<(32-(n))))
+
+#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
+#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
+       u=R^s[S  ]; \
+       t=R^s[S+1]
+
+/* The changes to this macro may help or hinder, depending on the
+ * compiler and the achitecture.  gcc2 always seems to do well :-).
+ * Inspired by Dana How <how@isl.stanford.edu>
+ * DO NOT use the alternative version on machines with 8 byte longs.
+ * It does not seem to work on the Alpha, even when DES_LONG is 4
+ * bytes, probably an issue of accessing non-word aligned objects :-( */
+#ifdef DES_PTR
+
+/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
+ * is no reason to not xor all the sub items together.  This potentially
+ * saves a register since things can be xored directly into L */
+
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+#define D_ENCRYPT(LL,R,S) { \
+        unsigned int u1,u2,u3; \
+        LOAD_DATA(R,S,u,t,E0,E1,u1); \
+        u2=(int)u>>8L; \
+        u1=(int)u&0xfc; \
+        u2&=0xfc; \
+        t=ROTATE(t,4); \
+        u>>=16L; \
+        LL^= *(const DES_LONG *)(des_SP      +u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
+        u3=(int)(u>>8L); \
+        u1=(int)u&0xfc; \
+        u3&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
+        u2=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u2&=0xfc; \
+        t>>=16L; \
+        LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
+        u3=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u3&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
+#endif /* DES_RISC1 */
+#ifdef DES_RISC2
+#define D_ENCRYPT(LL,R,S) { \
+        unsigned int u1,u2,s1,s2; \
+        LOAD_DATA(R,S,u,t,E0,E1,u1); \
+        u2=(int)u>>8L; \
+        u1=(int)u&0xfc; \
+        u2&=0xfc; \
+        t=ROTATE(t,4); \
+        LL^= *(const DES_LONG *)(des_SP      +u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
+        s1=(int)(u>>16L); \
+        s2=(int)(u>>24L); \
+        s1&=0xfc; \
+        s2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
+        LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
+        u2=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
+        s1=(int)(t>>16L); \
+        s2=(int)(t>>24L); \
+        s1&=0xfc; \
+        s2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
+        LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
+        u2=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
+        s1=(int)(t>>16L); \
+        s2=(int)(t>>24L); \
+        s1&=0xfc; \
+        s2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
+        LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
+#endif /* DES_RISC2 */
+#else  /* DES_RISC1 || DES_RISC2 */
+#define D_ENCRYPT(LL,R,S) { \
+       LOAD_DATA_tmp(R,S,u,t,E0,E1); \
+       t=ROTATE(t,4); \
+       LL^= \
+       *(const DES_LONG *)(des_SP      +((u     )&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x100+((t     )&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
+#endif /* DES_RISC1 || DES_RISC2 */
+#else /* original version */
+
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+#define D_ENCRYPT(LL,R,S) {\
+       unsigned int u1,u2,u3; \
+       LOAD_DATA(R,S,u,t,E0,E1,u1); \
+       u>>=2L; \
+       t=ROTATE(t,6); \
+       u2=(int)u>>8L; \
+       u1=(int)u&0x3f; \
+       u2&=0x3f; \
+       u>>=16L; \
+       LL^=DES_SPtrans[0][u1]; \
+       LL^=DES_SPtrans[2][u2]; \
+       u3=(int)u>>8L; \
+       u1=(int)u&0x3f; \
+       u3&=0x3f; \
+       LL^=DES_SPtrans[4][u1]; \
+       LL^=DES_SPtrans[6][u3]; \
+       u2=(int)t>>8L; \
+       u1=(int)t&0x3f; \
+       u2&=0x3f; \
+       t>>=16L; \
+       LL^=DES_SPtrans[1][u1]; \
+       LL^=DES_SPtrans[3][u2]; \
+       u3=(int)t>>8L; \
+       u1=(int)t&0x3f; \
+       u3&=0x3f; \
+       LL^=DES_SPtrans[5][u1]; \
+       LL^=DES_SPtrans[7][u3]; }
+#endif /* DES_RISC1 */
+#ifdef DES_RISC2
+#define D_ENCRYPT(LL,R,S) {\
+       unsigned int u1,u2,s1,s2; \
+       LOAD_DATA(R,S,u,t,E0,E1,u1); \
+       u>>=2L; \
+       t=ROTATE(t,6); \
+       u2=(int)u>>8L; \
+       u1=(int)u&0x3f; \
+       u2&=0x3f; \
+       LL^=DES_SPtrans[0][u1]; \
+       LL^=DES_SPtrans[2][u2]; \
+       s1=(int)u>>16L; \
+       s2=(int)u>>24L; \
+       s1&=0x3f; \
+       s2&=0x3f; \
+       LL^=DES_SPtrans[4][s1]; \
+       LL^=DES_SPtrans[6][s2]; \
+       u2=(int)t>>8L; \
+       u1=(int)t&0x3f; \
+       u2&=0x3f; \
+       LL^=DES_SPtrans[1][u1]; \
+       LL^=DES_SPtrans[3][u2]; \
+       s1=(int)t>>16; \
+       s2=(int)t>>24L; \
+       s1&=0x3f; \
+       s2&=0x3f; \
+       LL^=DES_SPtrans[5][s1]; \
+       LL^=DES_SPtrans[7][s2]; }
+#endif /* DES_RISC2 */
+
+#else /* DES_RISC1 || DES_RISC2 */
+
+#define D_ENCRYPT(LL,R,S) {\
+       LOAD_DATA_tmp(R,S,u,t,E0,E1); \
+       t=ROTATE(t,4); \
+       LL^=\
+               DES_SPtrans[0][(u>> 2L)&0x3f]^ \
+               DES_SPtrans[2][(u>>10L)&0x3f]^ \
+               DES_SPtrans[4][(u>>18L)&0x3f]^ \
+               DES_SPtrans[6][(u>>26L)&0x3f]^ \
+               DES_SPtrans[1][(t>> 2L)&0x3f]^ \
+               DES_SPtrans[3][(t>>10L)&0x3f]^ \
+               DES_SPtrans[5][(t>>18L)&0x3f]^ \
+               DES_SPtrans[7][(t>>26L)&0x3f]; }
+#endif /* DES_RISC1 || DES_RISC2 */
+#endif /* DES_PTR */
+
+       /* IP and FP
+        * The problem is more of a geometric problem that random bit fiddling.
+        0  1  2  3  4  5  6  7      62 54 46 38 30 22 14  6
+        8  9 10 11 12 13 14 15      60 52 44 36 28 20 12  4
+       16 17 18 19 20 21 22 23      58 50 42 34 26 18 10  2
+       24 25 26 27 28 29 30 31  to  56 48 40 32 24 16  8  0
+
+       32 33 34 35 36 37 38 39      63 55 47 39 31 23 15  7
+       40 41 42 43 44 45 46 47      61 53 45 37 29 21 13  5
+       48 49 50 51 52 53 54 55      59 51 43 35 27 19 11  3
+       56 57 58 59 60 61 62 63      57 49 41 33 25 17  9  1
+
+       The output has been subject to swaps of the form
+       0 1 -> 3 1 but the odd and even bits have been put into
+       2 3    2 0
+       different words.  The main trick is to remember that
+       t=((l>>size)^r)&(mask);
+       r^=t;
+       l^=(t<<size);
+       can be used to swap and move bits between words.
+
+       So l =  0  1  2  3  r = 16 17 18 19
+               4  5  6  7      20 21 22 23
+               8  9 10 11      24 25 26 27
+              12 13 14 15      28 29 30 31
+       becomes (for size == 2 and mask == 0x3333)
+          t =   2^16  3^17 -- --   l =  0  1 16 17  r =  2  3 18 19
+                6^20  7^21 -- --        4  5 20 21       6  7 22 23
+               10^24 11^25 -- --        8  9 24 25      10 11 24 25
+               14^28 15^29 -- --       12 13 28 29      14 15 28 29
+
+       Thanks for hints from Richard Outerbridge - he told me IP&FP
+       could be done in 15 xor, 10 shifts and 5 ands.
+       When I finally started to think of the problem in 2D
+       I first got ~42 operations without xors.  When I remembered
+       how to use xors :-) I got it to its final state.
+       */
+#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
+       (b)^=(t),\
+       (a)^=((t)<<(n)))
+
+#define IP(l,r) \
+       { \
+       register DES_LONG tt; \
+       PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
+       PERM_OP(l,r,tt,16,0x0000ffffL); \
+       PERM_OP(r,l,tt, 2,0x33333333L); \
+       PERM_OP(l,r,tt, 8,0x00ff00ffL); \
+       PERM_OP(r,l,tt, 1,0x55555555L); \
+       }
+
+#define FP(l,r) \
+       { \
+       register DES_LONG tt; \
+       PERM_OP(l,r,tt, 1,0x55555555L); \
+       PERM_OP(r,l,tt, 8,0x00ff00ffL); \
+       PERM_OP(l,r,tt, 2,0x33333333L); \
+       PERM_OP(r,l,tt,16,0x0000ffffL); \
+       PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
+       }
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/des_setkey.c b/BOINC software/BOINC server apps/distrrtgen_validator/des_setkey.c
new file mode 100644 (file)
index 0000000..de8641d
--- /dev/null
@@ -0,0 +1,235 @@
+/*     $KAME: des_setkey.c,v 1.7 2001/09/10 04:03:58 itojun Exp $      */
+
+/* crypto/des/set_key.c */
+
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+/* set_key.c v 1.4 eay 24/9/91
+ * 1.4 Speed up by 400% :-)
+ * 1.3 added register declarations.
+ * 1.2 unrolled make_key_sched a bit more
+ * 1.1 added norm_expand_bits
+ * 1.0 First working version
+ */
+#ifndef _WIN32
+       #include <sys/cdefs.h>
+       #include <sys/param.h>
+#endif
+#include <string.h>
+#include "des_locl.h"
+#include "podd.h"
+#include "sk.h"
+
+int des_check_key=0;
+
+void des_set_odd_parity(des_cblock *key)
+{
+       int i;
+
+       for (i=0; i<DES_KEY_SZ; i++)
+               (*key)[i]=odd_parity[(*key)[i]];
+}
+
+int des_check_key_parity(des_cblock *key)
+{
+       int i;
+
+       for (i=0; i<DES_KEY_SZ; i++)
+               {
+               if ((*key)[i] != odd_parity[(*key)[i]])
+                       return(0);
+               }
+       return(1);
+}
+
+/* Weak and semi week keys as take from
+ * %A D.W. Davies
+ * %A W.L. Price
+ * %T Security for Computer Networks
+ * %I John Wiley & Sons
+ * %D 1984
+ * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
+ * (and actual cblock values).
+ */
+#define NUM_WEAK_KEY   16
+static des_cblock weak_keys[NUM_WEAK_KEY]={
+       /* weak keys */
+       {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
+       {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
+       {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
+       {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
+       /* semi-weak keys */
+       {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
+       {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
+       {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
+       {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
+       {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
+       {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
+       {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
+       {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
+       {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
+       {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
+       {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
+       {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
+
+int des_is_weak_key(des_cblock *key)
+{
+       int i;
+
+       for (i=0; i<NUM_WEAK_KEY; i++)
+               /* Added == 0 to comparison, I obviously don't run
+                * this section very often :-(, thanks to
+                * engineering@MorningStar.Com for the fix
+                * eay 93/06/29
+                * Another problem, I was comparing only the first 4
+                * bytes, 97/03/18 */
+               if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
+       return(0);
+}
+
+/* NOW DEFINED IN des_local.h
+ * See ecb_encrypt.c for a pseudo description of these macros. 
+ * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
+ *     (b)^=(t),\
+ *     (a)=((a)^((t)<<(n))))
+ */
+
+#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
+       (a)=(a)^(t)^(t>>(16-(n))))
+
+int des_set_key(des_cblock *key, des_key_schedule schedule)
+{
+       if (des_check_key)
+       {
+               return des_set_key_checked(key, schedule);
+       }
+       else
+       {
+               des_set_key_unchecked(key, schedule);
+               return 0;
+       }
+}
+
+/* return 0 if key parity is odd (correct),
+ * return -1 if key parity error,
+ * return -2 if illegal weak key.
+ */
+int des_set_key_checked(des_cblock *key, des_key_schedule schedule)
+{
+       if (!des_check_key_parity(key))
+               return(-1);
+       if (des_is_weak_key(key))
+               return(-2);
+       des_set_key_unchecked(key, schedule);
+       return 0;
+}
+
+void des_set_key_unchecked(des_cblock *key, des_key_schedule schedule)
+{
+       static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
+       register DES_LONG c,d,t,s,t2;
+       register const unsigned char *in;
+       register DES_LONG *k;
+       register int i;
+
+       k = &schedule->ks.deslong[0];
+       in = &(*key)[0];
+
+       c2l(in,c);
+       c2l(in,d);
+
+       /* do PC1 in 47 simple operations :-)
+        * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
+        * for the inspiration. :-) */
+       PERM_OP (d,c,t,4,0x0f0f0f0fL);
+       HPERM_OP(c,t,-2,0xcccc0000L);
+       HPERM_OP(d,t,-2,0xcccc0000L);
+       PERM_OP (d,c,t,1,0x55555555L);
+       PERM_OP (c,d,t,8,0x00ff00ffL);
+       PERM_OP (d,c,t,1,0x55555555L);
+       d=      (((d&0x000000ffL)<<16L)| (d&0x0000ff00L)     |
+                ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
+       c&=0x0fffffffL;
+
+       for (i=0; i<ITERATIONS; i++)
+       {
+               if (shifts2[i])
+                       { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
+               else
+                       { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
+               c&=0x0fffffffL;
+               d&=0x0fffffffL;
+               /* could be a few less shifts but I am to lazy at this
+               * point in time to investigate */
+               s=      des_skb[0][ (c    )&0x3f                ]|
+                       des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
+                       des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
+                       des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
+                                                       ((c>>22L)&0x38)];
+               t=      des_skb[4][ (d    )&0x3f                ]|
+                       des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
+                       des_skb[6][ (d>>15L)&0x3f                ]|
+                       des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
+
+               /* table contained 0213 4657 */
+               t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
+               *(k++)=ROTATE(t2,30)&0xffffffffL;
+
+               t2=((s>>16L)|(t&0xffff0000L));
+               *(k++)=ROTATE(t2,26)&0xffffffffL;
+       }
+}
+
+int des_key_sched(des_cblock *key, des_key_schedule schedule)
+{
+       return(des_set_key(key,schedule));
+}
+
+void des_fixup_key_parity(des_cblock *key)
+{
+       des_set_odd_parity(key);
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/ecb_enc.c b/BOINC software/BOINC server apps/distrrtgen_validator/ecb_enc.c
new file mode 100644 (file)
index 0000000..4a6093d
--- /dev/null
@@ -0,0 +1,136 @@
+/*     $KAME: des_ecb.c,v 1.6 2001/09/10 04:03:58 itojun Exp $ */
+
+/* crypto/des/ecb_enc.c */
+
+/* Copyright (C) 1995-1998 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+
+#include <stdio.h>
+#include "des_locl.h"
+#include "spr.h"
+
+/* char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; */ /* wrong */
+/* char *DES_version="DES part of SSLeay 0.6.4 30-Aug-1996"; */
+
+char *des_options(void)
+        {
+        static int init=1;
+        static char buf[32];
+
+        if (init)
+                {
+                const char *ptr,*unroll,*risc,*size;
+
+#ifdef DES_PTR
+                ptr="ptr";
+#else
+                ptr="idx";
+#endif
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+                risc="risc1";
+#endif
+#ifdef DES_RISC2
+                risc="risc2";
+#endif
+#else
+                risc="cisc";
+#endif
+#ifdef DES_UNROLL
+                unroll="16";
+#else
+                unroll="4";
+#endif
+                if (sizeof(DES_LONG) != sizeof(long))
+                        size="int";
+                else
+                        size="long";
+                sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);
+                init=0;
+                }
+        return(buf);
+}
+void des_ecb_encrypt(des_cblock *input, des_cblock *output, 
+                    des_key_schedule ks, int enc)
+{
+       register DES_LONG l;
+       DES_LONG ll[2];
+       const unsigned char *in=&(*input)[0];
+       unsigned char *out = &(*output)[0];
+
+       c2l(in,l); ll[0]=l;
+       c2l(in,l); ll[1]=l;
+       des_encrypt1(ll,ks,enc);
+       l=ll[0]; l2c(l,out);
+       l=ll[1]; l2c(l,out);
+       l=ll[0]=ll[1]=0;
+}
+
+void des_ecb3_encrypt(des_cblock *input, des_cblock *output,
+             des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
+             int enc)
+{
+       register DES_LONG l0,l1;
+       DES_LONG ll[2];
+       const unsigned char *in = &(*input)[0];
+       unsigned char *out = &(*output)[0];
+       c2l(in,l0); 
+       c2l(in,l1);
+       ll[0]=l0; 
+       ll[1]=l1;
+
+       if (enc)
+               des_encrypt3(ll,ks1,ks2,ks3);
+       else
+               des_decrypt3(ll,ks1,ks2,ks3);
+
+       l0=ll[0];
+       l1=ll[1];
+       l2c(l0,out);
+       l2c(l1,out);
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/md4.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/md4.cpp
new file mode 100644 (file)
index 0000000..7a6f91a
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * This code implements the MD4 message-digest algorithm.
+ * "Just the reference implementation, single stage. Hardly "optimized." Though a good bit faster than libssl's MD4, as it isn't doing nearly the same amount of work." - Bitweasil
+ * 
+ * little bit optimized (or at least attempted) for NTLM (unicode) by neinbrucke
+ */
+
+
+//#include <cstdlib>
+#include <cstring>
+#include "md4.h"
+
+/* MD4 Defines as per RFC reference implementation */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+#define FF(a, b, c, d, x, s) { \
+    (a) += F ((b), (c), (d)) + (x); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+  }
+#define GG(a, b, c, d, x, s) { \
+    (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \
+    (a) = ROTATE_LEFT ((a), (s)); \
+  }
+#define HH(a, b, c, d, x, s) { \
+    (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \
+    (a) = ROTATE_LEFT ((a), (s)); \
+  }
+#define S11 3
+#define S12 7
+#define S13 11
+#define S14 19
+#define S21 3
+#define S22 5
+#define S23 9
+#define S24 13
+#define S31 3
+#define S32 9
+#define S33 11
+#define S34 15
+/* End MD4 Defines */
+
+
+void MD4_NEW( unsigned char * pData, int length, unsigned char * pDigest)
+{
+       // For the hash working space
+       UINT4 b0,b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15;
+
+       // For the output result
+       UINT4 a,b,c,d;
+
+       b0 = 0x00000000;
+       b1 = 0x00000000;
+       b2 = 0x00000000;
+       b3 = 0x00000000;
+       b4 = 0x00000000;
+       b5 = 0x00000000;
+       b6 = 0x00000000;
+       b7 = 0x00000000;
+       b8 = 0x00000000;
+       b9 = 0x00000000;
+       b10 = 0x00000000;
+       b11 = 0x00000000;
+       b12 = 0x00000000;
+       b13 = 0x00000000;
+       b14 = 0x00000000;
+       b15 = 0x00000000; 
+
+       // LOAD DATA INTO b0 ... whatever here.   
+       switch (length)
+       {
+               case 2:
+               {
+                       unsigned char in[4];
+                       memcpy(in, pData, length);
+                       in[2] = 0x80;
+                       in[3] = 0x00;
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+               }
+               break;
+               case 4:
+               {
+                       unsigned char in[4];
+                       memcpy(in, pData, length);
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = 0x00000080;
+               }
+               break;
+               case 6:
+               {
+                       unsigned char in[8];
+                       memcpy(in, pData, length);
+                       in[6] = 0x80;
+                       in[7] = 0x00;
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+               }
+               break;
+               case 8:
+               {
+                       unsigned char in[8];
+                       memcpy(in, pData, length);
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+                       b2 = 0x00000080;
+               }
+               break;
+               case 10:
+               {
+                       unsigned char in[12];
+                       memcpy(in, pData, length);
+                       in[10] = 0x80;
+                       in[11] = 0x00;
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+                       b2 = pUiIn[2];
+               }
+               break;
+               default:
+               {
+                       unsigned char in[32];
+                       memcpy(in, pData, length);
+                       in[length] = 0x80;
+                       memset(in + length + 1, 0, 32 - length - 1);
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+                       b2 = pUiIn[2];
+                       b3 = pUiIn[3];
+                       b4 = pUiIn[4];
+                       b5 = pUiIn[5];
+                       b6 = pUiIn[6];
+                       b7 = pUiIn[7]; // max 14 2byte chars (ntlm)
+                       b8 = pUiIn[8];
+               }
+               break;
+       }
+
+       b14 = length << 3;
+
+       a = 0x67452301;
+       b = 0xefcdab89;
+       c = 0x98badcfe;
+       d = 0x10325476;
+
+       /* Round 1 */
+       FF (a, b, c, d, b0, S11); /* 1 */
+       FF (d, a, b, c, b1, S12); /* 2 */
+       FF (c, d, a, b, b2, S13); /* 3 */
+       FF (b, c, d, a, b3, S14); /* 4 */
+       FF (a, b, c, d, b4, S11); /* 5 */
+       FF (d, a, b, c, b5, S12); /* 6 */
+       FF (c, d, a, b, b6, S13); /* 7 */
+       FF (b, c, d, a, b7, S14); /* 8 */
+       FF (a, b, c, d, 0, S11); /* 9 */
+       FF (d, a, b, c, 0, S12); /* 10 */
+       FF (c, d, a, b, 0, S13); /* 11 */
+       FF (b, c, d, a, 0, S14); /* 12 */
+       FF (a, b, c, d, 0, S11); /* 13 */
+       FF (d, a, b, c, 0, S12); /* 14 */
+       FF (c, d, a, b, b14, S13); /* 15 */
+       FF (b, c, d, a, 0, S14); /* 16 */
+
+       /* Round 2 */
+       GG (a, b, c, d, b0, S21); /* 17 */
+       GG (d, a, b, c, b4, S22); /* 18 */
+       GG (c, d, a, b, 0, S23); /* 19 */
+       GG (b, c, d, a, 0, S24); /* 20 */
+       GG (a, b, c, d, b1, S21); /* 21 */
+       GG (d, a, b, c, b5, S22); /* 22 */
+       GG (c, d, a, b, 0, S23); /* 23 */
+       GG (b, c, d, a, 0, S24); /* 24 */
+       GG (a, b, c, d, b2, S21); /* 25 */
+       GG (d, a, b, c, b6, S22); /* 26 */
+       GG (c, d, a, b, 0, S23); /* 27 */
+       GG (b, c, d, a, b14, S24); /* 28 */
+       GG (a, b, c, d, b3, S21); /* 29 */
+       GG (d, a, b, c, b7, S22); /* 30 */
+       GG (c, d, a, b, 0, S23); /* 31 */
+       GG (b, c, d, a, 0, S24); /* 32 */
+
+       /* Round 3 */
+       HH (a, b, c, d, b0, S31); /* 33 */
+       HH (d, a, b, c, 0, S32); /* 34 */
+       HH (c, d, a, b, b4, S33); /* 35 */
+       HH (b, c, d, a, 0, S34); /* 36 */
+       HH (a, b, c, d, b2, S31); /* 37 */
+       HH (d, a, b, c, 0, S32); /* 38 */
+       HH (c, d, a, b, b6, S33); /* 39 */
+       HH (b, c, d, a, b14, S34); /* 40 */
+       HH (a, b, c, d, b1, S31); /* 41 */
+       HH (d, a, b, c, 0, S32); /* 42 */
+       HH (c, d, a, b, b5, S33); /* 43 */
+       HH (b, c, d, a, 0, S34); /* 44 */
+       HH (a, b, c, d, b3, S31); /* 45 */
+       HH (d, a, b, c, 0, S32); /* 46 */
+       HH (c, d, a, b, b7, S33); /* 47 */
+       HH (b, c, d, a, 0, S34); /* 48 */
+
+       // Finally, add initial values, as this is the only pass we make.
+       a += 0x67452301;
+       b += 0xefcdab89;
+       c += 0x98badcfe;
+       d += 0x10325476;
+
+       UINT4 buf[4] = { a, b, c, d};
+       memcpy(pDigest, buf, 16);
+
+       return;
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/md4.h b/BOINC software/BOINC server apps/distrrtgen_validator/md4.h
new file mode 100644 (file)
index 0000000..8a5c428
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef MD4_H
+#define MD4_H
+
+//typedef unsigned long uint32;
+typedef unsigned long UINT4;
+
+//Main function
+void MD4_NEW( unsigned char * buf, int len, unsigned char * pDigest);
+
+#endif /* !MD4_H */
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/md5.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/md5.cpp
new file mode 100644 (file)
index 0000000..bc25b95
--- /dev/null
@@ -0,0 +1,1286 @@
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+/* Brutally hacked by John Walker back from ANSI C to K&R (no
+   prototypes) to maintain the tradition that Netfone will compile
+   with Sun's original "cc". */
+
+/*
+       Brutally modified by daVajj, optimized for lengths of 1 - 10.
+       Generic version used for longer indata
+*/
+
+#include <cstdlib>
+#include <cstring>
+#include "md5.h"
+
+/* The four core functions - F1 is optimized somewhat */
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+//Here's two different ways to do a left bitwise rotation. I've seen no major speed differences between them.
+//#define ROL(x, n) ( _lrotl(x, n) ) //This also requires #include <windows.h>
+#define ROL(x,n) ( x << n | x >>(32-n) )
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+       ( w += f(x, y, z) + data,  w = ROL(w,s) + x )
+       
+void MD5_NEW( unsigned char * pData, int len, unsigned char * pDigest)
+{
+       //Use optimized versions if available
+       switch( len )
+       {
+               case 1:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 1);
+                       in[1] = 0x80;
+                       memset(in + 2, 0, 2);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 8 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 8 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 8 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 8 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 2:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 2);
+                       in[2] = 0x80;
+                       memset(in + 3, 0, 1);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 16 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 16 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 16 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 16 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 3:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 3);
+                       in[3] = 0x80;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 24 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 24 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 24 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 24 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 4:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 4);
+                       //in[4] = 0x80; //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 128 + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 32 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 128 + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 32 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 32 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 128 + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 32 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 128 + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 5:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 5);
+                       in[5] = 0x80;
+                       memset(in + 6, 0, 2); //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 40 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 40 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 40 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 40 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 6:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 6);
+                       in[6] = 0x80;
+                       memset(in + 7, 0, 1); //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 48 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 48 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 48 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 48 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 7:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 7);
+                       in[7] = 0x80;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 56 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 56 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 56 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 56 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 8:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 8);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 128 + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 64 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 64 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 128 + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 64 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 128 + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 64 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 128 + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 9:
+               {
+                       //Main variables
+                       unsigned char in[12];
+                       
+                       memcpy(in, pData, 9);
+                       in[9] = 0x80;
+                       memset(in + 10, 0, 2);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 72 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 72 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 72 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 72 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 10:
+               {
+                       //Main variables
+                       unsigned char in[12];
+                       
+                       memcpy(in, pData, 10);
+                       in[10] = 0x80;
+                       memset(in + 11, 0, 1);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 80 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 80 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 80 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 80 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               default:
+                       //Main variables
+                       uint32 buf[4];
+                       unsigned char in[64];
+                       
+                       //Initialize
+                       buf[0] = 0x67452301;
+                       buf[1] = 0xefcdab89;
+                       buf[2] = 0x98badcfe;
+                       buf[3] = 0x10325476;
+
+                       /* Process data in 64-byte chunks */
+                       if( len >= 64 )
+                       {
+                               while( len >= 64 )
+                               {
+                                       memcpy(in, pData, 64);
+
+                                       //START OF MD5TRANSFORM CODE
+                                       //====================================================
+                                       register uint32 a, b, c, d;
+                                       uint32 * pUiIn = (uint32 *) in;
+                               
+                                       a = buf[0];
+                                       b = buf[1];
+                                       c = buf[2];
+                                       d = buf[3];
+                               
+                                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+                               
+                                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+                               
+                                       MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+                               
+                                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+                               
+                                       buf[0] += a;
+                                       buf[1] += b;
+                                       buf[2] += c;
+                                       buf[3] += d;
+                                       //END OF MD5TRANSFORM CODE
+                                       //====================================================
+
+                                       pData += 64;
+                                       len -= 64;
+                               }
+                       }
+
+                       /* Handle any remaining bytes of data. */
+                       memcpy(in, pData, len);
+                   
+                       //MD5FINAL STARTS HERE
+                       //===========================================
+                       unsigned count = len & 0x3F;
+                       unsigned char * p = in + count;
+                       *p++ = 0x80;
+
+                       // Bytes of padding needed to make 64 bytes
+                       count = 63 - count;
+
+                       /* Pad out to 56 mod 64 */
+                       if(count < 8)
+                       {
+                               // Two lots of padding:  Pad the first block to 64 bytes
+                               memset(p, 0, count);
+
+                               //START OF MD5TRANSFORM CODE
+                               //====================================================
+                               register uint32 a, b, c, d;
+                               uint32 * pUiIn = (uint32 *) in;
+                       
+                               a = buf[0];
+                               b = buf[1];
+                               c = buf[2];
+                               d = buf[3];
+                       
+                               MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+                       
+                               MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+                       
+                               MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+                       
+                               MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+                       
+                               buf[0] += a;
+                               buf[1] += b;
+                               buf[2] += c;
+                               buf[3] += d;
+                               //END OF MD5TRANSFORM CODE
+                               //====================================================      
+
+                               // Now fill the next block with 56 bytes
+                               memset(in, 0, 56);
+                       }
+                       else
+                       {
+                               // Pad block to 56 bytes
+                               memset(p, 0, count - 8);
+                       }//*/
+                   
+
+                       /* Append length in bits and transform */
+                       ((uint32 *) in)[14] = len << 3;
+                       ((uint32 *) in)[15] = len >> 29;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = buf[0];
+                       b = buf[1];
+                       c = buf[2];
+                       d = buf[3];
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+
+                       buf[0] += a;
+                       buf[1] += b;
+                       buf[2] += c;
+                       buf[3] += d;
+                       //END OF MD5TRANSFORM CODE
+                       //====================================================
+                           
+                       memcpy(pDigest, buf, 16);
+                       return;
+
+               break;
+       }
+}
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/md5.h b/BOINC software/BOINC server apps/distrrtgen_validator/md5.h
new file mode 100644 (file)
index 0000000..1d3da9e
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef MD5_H
+#define MD5_H
+
+typedef unsigned long uint32;
+
+//Main function
+void MD5_NEW( unsigned char * buf, int len, unsigned char * pDigest);
+
+#endif /* !MD5_H */
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/part_validator.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/part_validator.cpp
new file mode 100644 (file)
index 0000000..44eede2
--- /dev/null
@@ -0,0 +1,117 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// A sample validator that grants credit if the majority of results are
+// bitwise identical.
+// This is useful only if either
+// 1) your application does no floating-point math, or
+// 2) you use homogeneous redundancy
+
+
+#include "config.h"
+#include "util.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+#include "validate_util.h"
+#include "ChainWalkContext.h"
+#include "MemoryPool.h"
+#include "filesys.h"
+#include "error_numbers.h"
+#include "part_validator.h"
+using std::string;
+using std::vector;
+
+
+int read_file_binary(const char *path, RainbowPartFile *data, int &isize)
+{
+    int retval;
+    double size;
+
+    retval = file_size(path, size);
+    if (retval) return retval;
+    FILE *f = fopen(path, "rb");
+    if (!f) return ERR_FOPEN;
+    isize = (int) size;
+        log_messages.printf(MSG_DEBUG,
+                    "malloc %i bytes. size: %i\n",
+                    (isize / 18 * sizeof(RainbowPartFile)), sizeof(RainbowPartFile)
+                );          
+    data->pChain = (RainbowChainCP*)malloc(isize / 18 * sizeof(RainbowChainCP));
+    data->numchains = isize / 18;
+    for(int i = 0; i < data->numchains; i++)
+    {  
+        size_t n = fread(&data->pChain[i].nIndexS, 1, 8, f);
+        n = fread(&data->pChain[i].nIndexE, 1, 8, f);
+        n = fread(&data->pChain[i].nCheckPoint, 1, 2, f);
+    }
+    fclose(f);
+    return 0;  
+}
+int init_result(RESULT& result, void*& data) {
+    int retval;
+    vector<FILE_INFO> files;
+
+    retval = get_output_file_infos(result, files);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d %s] check_set: can't get output filenames\n",
+            result.id, result.name
+        );
+        return retval;
+    }
+
+    RainbowPartFile *filedata = new RainbowPartFile();
+    int filelen;
+    for (unsigned int i=0; i<files.size(); i++) {
+        FILE_INFO& fi = files[i];
+        if (fi.no_validate) continue;
+        retval = read_file_binary(fi.path.c_str(), filedata, filelen);
+        if (retval) {
+            if (fi.optional) {
+                filedata = NULL;
+            } else {
+                log_messages.printf(MSG_CRITICAL,
+                    "[RESULT#%d %s] Couldn't open %s\n",
+                    result.id, result.name, fi.path.c_str()
+                );
+                return retval;
+            }
+            
+        }
+        log_messages.printf(MSG_DEBUG,
+                    "[RESULT#%d %s] Size of file %s is %u\n",
+                    result.id, result.name, fi.path.c_str(), filelen
+                );          
+        data = (void*)filedata;
+    }
+    return 0;
+}
+
+int cleanup_result(RESULT const& /*result*/, void *data) {
+    if(data)
+    {
+    delete ((RainbowPartFile*)data)->pChain;
+       delete ((RainbowPartFile*)data);
+    }
+    return 0;
+}
+
+double compute_granted_credit(WORKUNIT& wu, vector<RESULT>& results) {
+    return median_mean_credit(wu, results);
+}
+
+const char *BOINC_RCSID_7ab2b7189c = "$Id: sample_bitwise_validator.cpp 16069 2008-09-26 18:20:24Z davea $";
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/part_validator.h b/BOINC software/BOINC server apps/distrrtgen_validator/part_validator.h
new file mode 100644 (file)
index 0000000..0791196
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __PART_VALIDATOR_H__
+#define __PART_VALIDATOR_H__
+
+struct RainbowPartFile
+{
+       RainbowChainCP *pChain;
+       int numchains;
+};
+
+#endif
+
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/podd.h b/BOINC software/BOINC server apps/distrrtgen_validator/podd.h
new file mode 100644 (file)
index 0000000..8d77aac
--- /dev/null
@@ -0,0 +1,67 @@
+/*     $FreeBSD: src/sys/crypto/des/podd.h,v 1.4 2002/04/19 04:46:21 suz Exp $ */
+/*     $KAME: podd.h,v 1.4 2001/09/10 04:03:58 itojun Exp $    */
+
+/* crypto/des/podd.h */
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+static const unsigned char odd_parity[256]={
+  1,  1,  2,  2,  4,  4,  7,  7,  8,  8, 11, 11, 13, 13, 14, 14,
+ 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
+ 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
+ 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
+ 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
+ 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
+ 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
+112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
+128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
+145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
+161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
+176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
+193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
+208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
+224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
+241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/sk.h b/BOINC software/BOINC server apps/distrrtgen_validator/sk.h
new file mode 100644 (file)
index 0000000..209dca6
--- /dev/null
@@ -0,0 +1,196 @@
+/*     $FreeBSD: src/sys/crypto/des/sk.h,v 1.4 2002/04/19 04:46:21 suz Exp $   */
+/*     $KAME: sk.h,v 1.4 2001/09/10 04:03:58 itojun Exp $      */
+
+/* crypto/des/sk.h */
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+static const DES_LONG des_skb[8][64]={
+{
+/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
+0x00000000L,0x00000010L,0x20000000L,0x20000010L,
+0x00010000L,0x00010010L,0x20010000L,0x20010010L,
+0x00000800L,0x00000810L,0x20000800L,0x20000810L,
+0x00010800L,0x00010810L,0x20010800L,0x20010810L,
+0x00000020L,0x00000030L,0x20000020L,0x20000030L,
+0x00010020L,0x00010030L,0x20010020L,0x20010030L,
+0x00000820L,0x00000830L,0x20000820L,0x20000830L,
+0x00010820L,0x00010830L,0x20010820L,0x20010830L,
+0x00080000L,0x00080010L,0x20080000L,0x20080010L,
+0x00090000L,0x00090010L,0x20090000L,0x20090010L,
+0x00080800L,0x00080810L,0x20080800L,0x20080810L,
+0x00090800L,0x00090810L,0x20090800L,0x20090810L,
+0x00080020L,0x00080030L,0x20080020L,0x20080030L,
+0x00090020L,0x00090030L,0x20090020L,0x20090030L,
+0x00080820L,0x00080830L,0x20080820L,0x20080830L,
+0x00090820L,0x00090830L,0x20090820L,0x20090830L,
+},{
+/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
+0x00000000L,0x02000000L,0x00002000L,0x02002000L,
+0x00200000L,0x02200000L,0x00202000L,0x02202000L,
+0x00000004L,0x02000004L,0x00002004L,0x02002004L,
+0x00200004L,0x02200004L,0x00202004L,0x02202004L,
+0x00000400L,0x02000400L,0x00002400L,0x02002400L,
+0x00200400L,0x02200400L,0x00202400L,0x02202400L,
+0x00000404L,0x02000404L,0x00002404L,0x02002404L,
+0x00200404L,0x02200404L,0x00202404L,0x02202404L,
+0x10000000L,0x12000000L,0x10002000L,0x12002000L,
+0x10200000L,0x12200000L,0x10202000L,0x12202000L,
+0x10000004L,0x12000004L,0x10002004L,0x12002004L,
+0x10200004L,0x12200004L,0x10202004L,0x12202004L,
+0x10000400L,0x12000400L,0x10002400L,0x12002400L,
+0x10200400L,0x12200400L,0x10202400L,0x12202400L,
+0x10000404L,0x12000404L,0x10002404L,0x12002404L,
+0x10200404L,0x12200404L,0x10202404L,0x12202404L,
+},{
+/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
+0x00000000L,0x00000001L,0x00040000L,0x00040001L,
+0x01000000L,0x01000001L,0x01040000L,0x01040001L,
+0x00000002L,0x00000003L,0x00040002L,0x00040003L,
+0x01000002L,0x01000003L,0x01040002L,0x01040003L,
+0x00000200L,0x00000201L,0x00040200L,0x00040201L,
+0x01000200L,0x01000201L,0x01040200L,0x01040201L,
+0x00000202L,0x00000203L,0x00040202L,0x00040203L,
+0x01000202L,0x01000203L,0x01040202L,0x01040203L,
+0x08000000L,0x08000001L,0x08040000L,0x08040001L,
+0x09000000L,0x09000001L,0x09040000L,0x09040001L,
+0x08000002L,0x08000003L,0x08040002L,0x08040003L,
+0x09000002L,0x09000003L,0x09040002L,0x09040003L,
+0x08000200L,0x08000201L,0x08040200L,0x08040201L,
+0x09000200L,0x09000201L,0x09040200L,0x09040201L,
+0x08000202L,0x08000203L,0x08040202L,0x08040203L,
+0x09000202L,0x09000203L,0x09040202L,0x09040203L,
+},{
+/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
+0x00000000L,0x00100000L,0x00000100L,0x00100100L,
+0x00000008L,0x00100008L,0x00000108L,0x00100108L,
+0x00001000L,0x00101000L,0x00001100L,0x00101100L,
+0x00001008L,0x00101008L,0x00001108L,0x00101108L,
+0x04000000L,0x04100000L,0x04000100L,0x04100100L,
+0x04000008L,0x04100008L,0x04000108L,0x04100108L,
+0x04001000L,0x04101000L,0x04001100L,0x04101100L,
+0x04001008L,0x04101008L,0x04001108L,0x04101108L,
+0x00020000L,0x00120000L,0x00020100L,0x00120100L,
+0x00020008L,0x00120008L,0x00020108L,0x00120108L,
+0x00021000L,0x00121000L,0x00021100L,0x00121100L,
+0x00021008L,0x00121008L,0x00021108L,0x00121108L,
+0x04020000L,0x04120000L,0x04020100L,0x04120100L,
+0x04020008L,0x04120008L,0x04020108L,0x04120108L,
+0x04021000L,0x04121000L,0x04021100L,0x04121100L,
+0x04021008L,0x04121008L,0x04021108L,0x04121108L,
+},{
+/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
+0x00000000L,0x10000000L,0x00010000L,0x10010000L,
+0x00000004L,0x10000004L,0x00010004L,0x10010004L,
+0x20000000L,0x30000000L,0x20010000L,0x30010000L,
+0x20000004L,0x30000004L,0x20010004L,0x30010004L,
+0x00100000L,0x10100000L,0x00110000L,0x10110000L,
+0x00100004L,0x10100004L,0x00110004L,0x10110004L,
+0x20100000L,0x30100000L,0x20110000L,0x30110000L,
+0x20100004L,0x30100004L,0x20110004L,0x30110004L,
+0x00001000L,0x10001000L,0x00011000L,0x10011000L,
+0x00001004L,0x10001004L,0x00011004L,0x10011004L,
+0x20001000L,0x30001000L,0x20011000L,0x30011000L,
+0x20001004L,0x30001004L,0x20011004L,0x30011004L,
+0x00101000L,0x10101000L,0x00111000L,0x10111000L,
+0x00101004L,0x10101004L,0x00111004L,0x10111004L,
+0x20101000L,0x30101000L,0x20111000L,0x30111000L,
+0x20101004L,0x30101004L,0x20111004L,0x30111004L,
+},{
+/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
+0x00000000L,0x08000000L,0x00000008L,0x08000008L,
+0x00000400L,0x08000400L,0x00000408L,0x08000408L,
+0x00020000L,0x08020000L,0x00020008L,0x08020008L,
+0x00020400L,0x08020400L,0x00020408L,0x08020408L,
+0x00000001L,0x08000001L,0x00000009L,0x08000009L,
+0x00000401L,0x08000401L,0x00000409L,0x08000409L,
+0x00020001L,0x08020001L,0x00020009L,0x08020009L,
+0x00020401L,0x08020401L,0x00020409L,0x08020409L,
+0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
+0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
+0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
+0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
+0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
+0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
+0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
+0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
+},{
+/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
+0x00000000L,0x00000100L,0x00080000L,0x00080100L,
+0x01000000L,0x01000100L,0x01080000L,0x01080100L,
+0x00000010L,0x00000110L,0x00080010L,0x00080110L,
+0x01000010L,0x01000110L,0x01080010L,0x01080110L,
+0x00200000L,0x00200100L,0x00280000L,0x00280100L,
+0x01200000L,0x01200100L,0x01280000L,0x01280100L,
+0x00200010L,0x00200110L,0x00280010L,0x00280110L,
+0x01200010L,0x01200110L,0x01280010L,0x01280110L,
+0x00000200L,0x00000300L,0x00080200L,0x00080300L,
+0x01000200L,0x01000300L,0x01080200L,0x01080300L,
+0x00000210L,0x00000310L,0x00080210L,0x00080310L,
+0x01000210L,0x01000310L,0x01080210L,0x01080310L,
+0x00200200L,0x00200300L,0x00280200L,0x00280300L,
+0x01200200L,0x01200300L,0x01280200L,0x01280300L,
+0x00200210L,0x00200310L,0x00280210L,0x00280310L,
+0x01200210L,0x01200310L,0x01280210L,0x01280310L,
+},{
+/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
+0x00000000L,0x04000000L,0x00040000L,0x04040000L,
+0x00000002L,0x04000002L,0x00040002L,0x04040002L,
+0x00002000L,0x04002000L,0x00042000L,0x04042000L,
+0x00002002L,0x04002002L,0x00042002L,0x04042002L,
+0x00000020L,0x04000020L,0x00040020L,0x04040020L,
+0x00000022L,0x04000022L,0x00040022L,0x04040022L,
+0x00002020L,0x04002020L,0x00042020L,0x04042020L,
+0x00002022L,0x04002022L,0x00042022L,0x04042022L,
+0x00000800L,0x04000800L,0x00040800L,0x04040800L,
+0x00000802L,0x04000802L,0x00040802L,0x04040802L,
+0x00002800L,0x04002800L,0x00042800L,0x04042800L,
+0x00002802L,0x04002802L,0x00042802L,0x04042802L,
+0x00000820L,0x04000820L,0x00040820L,0x04040820L,
+0x00000822L,0x04000822L,0x00040822L,0x04040822L,
+0x00002820L,0x04002820L,0x00042820L,0x04042820L,
+0x00002822L,0x04002822L,0x00042822L,0x04042822L,
+}};
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/spr.h b/BOINC software/BOINC server apps/distrrtgen_validator/spr.h
new file mode 100644 (file)
index 0000000..4fd00b6
--- /dev/null
@@ -0,0 +1,207 @@
+/*     $FreeBSD: src/sys/crypto/des/spr.h,v 1.4 2002/03/05 09:19:02 ume Exp $  */
+/*     $KAME: spr.h,v 1.4 2001/09/10 04:03:58 itojun Exp $     */
+
+/* crypto/des/spr.h */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+const DES_LONG des_SPtrans[8][64]={
+{
+/* nibble 0 */
+0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
+0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
+0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
+0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
+0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
+0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
+0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
+0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
+0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
+0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
+0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
+0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
+0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
+0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
+0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
+0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
+},{
+/* nibble 1 */
+0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
+0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
+0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
+0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
+0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
+0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
+0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
+0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
+0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
+0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
+0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
+0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
+0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
+0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
+0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
+0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
+},{
+/* nibble 2 */
+0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
+0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
+0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
+0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
+0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
+0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
+0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
+0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
+0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
+0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
+0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
+0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
+0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
+0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
+0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
+0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
+},{
+/* nibble 3 */
+0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
+0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
+0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
+0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
+0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
+0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
+0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
+0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
+0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
+0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
+0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
+0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
+0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
+0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
+0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
+0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
+},{
+/* nibble 4 */
+0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
+0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
+0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
+0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
+0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
+0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
+0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
+0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
+0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
+0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
+0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
+0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
+0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
+0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
+0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
+0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
+},{
+/* nibble 5 */
+0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
+0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
+0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
+0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
+0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
+0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
+0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
+0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
+0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
+0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
+0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
+0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
+0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
+0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
+0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
+0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
+},{
+/* nibble 6 */
+0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
+0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
+0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
+0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
+0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
+0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
+0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
+0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
+0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
+0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
+0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
+0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
+0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
+0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
+0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
+0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
+},{
+/* nibble 7 */
+0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
+0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
+0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
+0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
+0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
+0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
+0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
+0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
+0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
+0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
+0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
+0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
+0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
+0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
+0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
+0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
+}};
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/validate_util.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/validate_util.cpp
new file mode 100644 (file)
index 0000000..d1248aa
--- /dev/null
@@ -0,0 +1,565 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Code to facilitate writing validators.
+// Can be used as the basis for a validator that accepts everything
+// (see sample_trivial_validator.C),
+// or that requires strict equality (see sample_bitwise_validator.C)
+// or that uses fuzzy comparison.
+
+#include <cstring>
+#include "config.h"
+
+#include "error_numbers.h"
+#include "parse.h"
+#include "util.h"
+#include "filesys.h"
+
+#include "sched_util.h"
+#include "sched_config.h"
+#include "sched_msgs.h"
+#include "validator.h"
+#include "validate_util.h"
+
+using std::vector;
+using std::string;
+
+
+int FILE_INFO::parse(XML_PARSER& xp) {
+    char tag[256];
+    bool is_tag, found=false;
+    optional = false;
+    no_validate = false;
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "/file_ref")) {
+            return found?0:ERR_XML_PARSE;
+        }
+        if (xp.parse_string(tag, "file_name", name)) {
+            found = true;
+            continue;
+        }
+        if (xp.parse_bool(tag, "optional", optional)) continue;
+        if (xp.parse_bool(tag, "no_validate", no_validate)) continue;
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_info(RESULT& result, FILE_INFO& fi) {
+    char tag[256], path[1024];
+    bool is_tag;
+    string name;
+    MIOFILE mf;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            int retval = fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_infos(RESULT& result, vector<FILE_INFO>& fis) {
+    char tag[256], path[1024];
+    bool is_tag;
+    MIOFILE mf;
+    string name;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    fis.clear();
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_INFO fi;
+            int retval =  fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            fis.push_back(fi);
+        }
+    }
+    return 0;
+}
+
+int get_output_file_path(RESULT& result, string& path) {
+    FILE_INFO fi;
+    int retval = get_output_file_info(result, fi);
+    if (retval) return retval;
+    path = fi.path;
+    return 0;
+}
+
+int get_output_file_paths(RESULT& result, vector<string>& paths) {
+    vector<FILE_INFO> fis;
+    int retval = get_output_file_infos(result, fis);
+    if (retval) return retval;
+    paths.clear();
+    for (unsigned int i=0; i<fis.size(); i++) {
+        paths.push_back(fis[i].path);
+    }
+    return 0;
+}
+
+struct FILE_REF {
+    char file_name[256];
+    char open_name[256];
+    int parse(XML_PARSER& xp) {
+        char tag[256];
+        bool is_tag;
+
+        strcpy(file_name, "");
+        strcpy(open_name, "");
+        while (!xp.get(tag, sizeof(tag), is_tag)) {
+            if (!is_tag) continue;
+            if (!strcmp(tag, "/file_ref")) {
+                return 0;
+            }
+            if (xp.parse_str(tag, "file_name", file_name, sizeof(file_name))) continue;
+            if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) continue;
+        }
+        return ERR_XML_PARSE;
+    }
+};
+
+// given a path returned by the above, get the corresponding logical name
+//
+int get_logical_name(RESULT& result, string& path, string& name) {
+    char phys_name[1024];
+    char tag[256];
+    bool is_tag;
+    MIOFILE mf;
+    int retval;
+
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+
+    strcpy(phys_name, path.c_str());
+    char* p = strrchr(phys_name, '/');
+    if (!p) return ERR_NOT_FOUND;
+    strcpy(phys_name, p+1);
+
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "result")) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_REF fr;
+            retval = fr.parse(xp);
+            if (retval) continue;
+            if (!strcmp(phys_name, fr.file_name)) {
+                name = fr.open_name;
+                return 0;
+            }
+            continue;
+        }
+        xp.skip_unexpected(tag, false, 0);
+    }
+    return ERR_XML_PARSE;
+}
+
+#define CREDIT_EPSILON .001
+
+// If we have N correct results with nonzero claimed credit,
+// compute a canonical credit as follows:
+// - if N==0 (all claimed credits are infinitesmal), return CREDIT_EPSILON
+// - if N==1, return that credit
+// - if N==2, return min
+// - if N>2, toss out min and max, return average of rest
+//
+double median_mean_credit(WORKUNIT& /*wu*/, vector<RESULT>& results) {
+    int ilow=-1, ihigh=-1;
+    double credit_low = 0, credit_high = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < CREDIT_EPSILON) continue;
+        if (ilow < 0) {
+            ilow = ihigh = i;
+            credit_low = credit_high = result.claimed_credit;
+        } else {
+            if (result.claimed_credit < credit_low) {
+                ilow = i;
+                credit_low = result.claimed_credit;
+            }
+            if (result.claimed_credit > credit_high) {
+                ihigh = i;
+                credit_high = result.claimed_credit;
+            }
+        }
+        nvalid++;
+    }
+
+    switch(nvalid) {
+    case 0:
+        return CREDIT_EPSILON;
+    case 1:
+    case 2:
+        return credit_low;
+    default:
+        double sum = 0;
+        for (i=0; i<results.size(); i++) {
+            if (i == (unsigned int) ilow) continue;
+            if (i == (unsigned int) ihigh) continue;
+            RESULT& result = results[i];
+            if (result.validate_state != VALIDATE_STATE_VALID) continue;
+
+            sum += result.claimed_credit;
+        }
+        return sum/(nvalid-2);
+    }
+}
+
+int get_credit_from_wu(WORKUNIT& wu, vector<RESULT>&, double& credit) {
+    double x;
+    int retval;
+    DB_WORKUNIT dbwu;
+
+    dbwu.id = wu.id;
+    retval = dbwu.get_field_str("xml_doc", dbwu.xml_doc, sizeof(dbwu.xml_doc));
+    if (!retval) {
+        if (parse_double(dbwu.xml_doc, "<credit>", x)) {
+            credit = x;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+// This function should be called from the validator whenever credit
+// is granted to a host.  It's purpose is to track the average credit
+// per cpu time for that host.
+//
+// It updates an exponentially-decaying estimate of credit_per_cpu_sec
+// Note that this does NOT decay with time, but instead decays with
+// total credits earned.  If a host stops earning credits, then this
+// quantity stops decaying.  So credit_per_cpu_sec must NOT be
+// periodically decayed using the update_stats utility or similar
+// methods.
+//
+// The intended purpose is for cross-project credit comparisons on
+// BOINC statistics pages, for hosts attached to multiple machines.
+// One day people will write PhD theses on how to normalize credit
+// values to equalize them across projects.  I hope this will be done
+// according to "Allen's principle": "Credits granted by a project
+// should be normalized so that, averaged across all hosts attached to
+// multiple projects, projects grant equal credit per cpu second."
+// This principle ensures that (on average) participants will choose
+// projects based on merit, not based on credits.  It also ensures
+// that (on average) host machines migrate to the projects for which
+// they are best suited.
+//
+// For cross-project comparison the value of credit_per_cpu_sec should
+// be exported in the statistics file host_id.gz, which is written by
+// the code in db_dump.C.
+//
+// Algorithm: credits_per_cpu_second should be updated each time that
+// a host is granted credit, according to:
+//
+//     CREDIT_AVERAGE_CONST = 500           [see Note 5]
+//     MAX_CREDIT_PER_CPU_SEC = 0.1         [see Note 6]
+//
+//     e = tanh(granted_credit/CREDIT_AVERAGE_CONST)
+//     if (e < 0) then e = 0
+//     if (e > 1) then e = 1
+//     if (credit_per_cpu_sec <= 0) then e = 1
+//     if (cpu_time <= 0) then e = 0        [see Note 4]
+//     if (granted_credit <= 0) then e = 0  [see Note 3]
+//
+//     rate = granted_credit/cpu_time
+//     if (rate < 0) rate = 0
+//     if (rate > MAX_CREDIT_PER_CPU_SEC) rate = MAX_CREDIT_PER_CPU_SEC
+//
+//     credit_per_cpu_sec = e * rate + (1 - e) * credit_per_cpu_sec
+
+// Note 0: all quantities above should be treated as real numbers
+// Note 1: cpu_time is measured in seconds
+// Note 2: When a host is created, the initial value of
+//         credit_per_cpu_sec, should be zero.
+// Note 3: If a host has done invalid work (granted_credit==0) we have
+//         chosen not to include it.  One might argue that the
+//         boundary case granted_credit==0 should be treated the same
+//         as granted_credit>0.  However the goal here is not to
+//         identify cpus whose host machines sometimes produce
+//         rubbish.  It is to get a measure of how effectively the cpu
+//         runs the application code.
+// Note 4: e==0 means 'DO NOT include the first term on the rhs of the
+//         equation defining credit_per_cpu_sec' which is equivalent
+//         to 'DO NOT update credit_per_cpu_sec'.
+// Note 5: CREDIT_AVERAGE_CONST determines the exponential decay
+//         credit used in averaging credit_per_cpu_sec.  It may be
+//         changed at any time, even if the project database has
+//         already been populated with non-zero values of
+//         credit_per_cpu_sec.
+// Note 6: Typical VERY FAST cpus have credit_per_cpu_sec of around
+//         0.02.  This is a safety mechanism designed to prevent
+//         trouble if a client or host has reported absurd values (due
+//         to a bug in client or server software or by cheating).  In
+//         five years when cpus are five time faster, please increase
+//         the value of R.  You may also want to increase the value of
+//         CREDIT_AVERAGE_CONST.
+//
+//         Nonzero return value: host exceeded the max allowed
+//         credit/cpu_sec.
+//
+int update_credit_per_cpu_sec(
+    double  granted_credit,     // credit granted for this work
+    double  cpu_time,           // cpu time (seconds) used for this work
+    double& credit_per_cpu_sec  // (average) credit per cpu second
+) {
+    int retval = 0;
+
+    // Either of these values may be freely changed in the future.
+    // When CPUs get much faster one must increase the 'sanity-check'
+    // value of max_credit_per_cpu_sec.  At that time it would also
+    // make sense to proportionally increase the credit_average_const.
+    //
+    const double credit_average_const = 500;
+    const double max_credit_per_cpu_sec = 0.07;
+
+    double e = tanh(granted_credit/credit_average_const);
+    if (e <= 0.0 || cpu_time == 0.0 || granted_credit == 0.0) return retval;
+    if (e > 1.0 || credit_per_cpu_sec == 0.0) e = 1.0;
+
+    double rate =  granted_credit/cpu_time;
+    if (rate < 0.0) rate = 0.0;
+    if (rate > max_credit_per_cpu_sec) {
+        rate = max_credit_per_cpu_sec;
+        retval = 1;
+    }
+
+    credit_per_cpu_sec = e * rate + (1.0 - e) * credit_per_cpu_sec;
+
+    return retval;
+}
+
+double stddev_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    double credit_low_bound = 0, credit_high_bound = 0;
+    double penalize_credit_high_bound = 0;
+    double credit_avg = 0;
+    double credit = 0;
+    double old = 0;
+    double std_dev = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    nvalid = 0;
+    //calculate stddev difference
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        std_dev = pow(credit_avg - result.claimed_credit,2) + std_dev;
+        nvalid++;
+    }
+
+    std_dev = std_dev/ (double) nvalid;
+    std_dev = sqrt(std_dev);
+
+    credit_low_bound = credit_avg-std_dev;
+    if (credit_low_bound > credit_avg*.85) {
+        credit_low_bound = credit_avg*.85;
+    }
+    credit_low_bound = credit_low_bound - 2.5;
+    if (credit_low_bound < 1) credit_low_bound = 1;
+
+    credit_high_bound = credit_avg+std_dev;
+    if (credit_high_bound < credit_avg*1.15) {
+        credit_high_bound = credit_avg*1.15;
+    }
+    credit_high_bound = credit_high_bound + 5;
+
+
+    nvalid=0;
+    credit = 0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < credit_high_bound && result.claimed_credit > credit_low_bound) {
+            credit = credit + result.claimed_credit;
+            nvalid++;
+        } else {
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_SD Discarding invalid credit %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit,
+                credit_avg, credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    double grant_credit;
+    switch(nvalid) {
+    case 0:
+        grant_credit = median_mean_credit(wu, results);
+        old = grant_credit;
+        break;
+    default:
+        grant_credit = credit/nvalid;
+        old = median_mean_credit(wu, results);
+    }
+
+    // Log what happened
+    if (old > grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Less awarded\n",
+            grant_credit, old
+        );
+    } else if (old == grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Same awarded\n",
+            grant_credit, old
+        );
+    } else {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  More awarded\n",
+            grant_credit, old
+        );
+    }
+
+    // penalize hosts that are claiming too much
+    penalize_credit_high_bound = grant_credit+1.5*std_dev;
+    if (penalize_credit_high_bound < grant_credit*1.65) {
+        penalize_credit_high_bound = grant_credit*1.65;
+    }
+    penalize_credit_high_bound = penalize_credit_high_bound + 20;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit > penalize_credit_high_bound) {
+            result.granted_credit = grant_credit * 0.5;
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_PENALTY Penalizing host for too high credit %.1lf, grant %.1lf, penalize %.1lf, stddev %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit, grant_credit,
+                penalize_credit_high_bound, std_dev, credit_avg,
+                credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    return grant_credit;
+}
+
+double two_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    unsigned int i;
+    double credit = 0;
+    double credit_avg = 0;
+    double last_credit = 0;
+    int nvalid = 0;
+    double grant_credit;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        last_credit = result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    // If more then 2 valid results, compute via stddev method
+    if (nvalid > 2) return stddev_credit(wu, results);
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Only 2 results \n",wu.id, wu.name
+    );
+
+    // If only 2, then check to see if range is reasonable
+    if (fabs(last_credit - credit_avg) < 0.15*credit_avg) return credit_avg;
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Average is more than 15 percent from each value \n",
+        wu.id, wu.name
+    );
+
+    // log data on large variance in runtime
+    float cpu_time = 0.0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.cpu_time < 30) continue;
+        if (cpu_time == 0) {
+            cpu_time = result.cpu_time*1.0;
+        } else {
+            if (cpu_time/result.cpu_time > 2 || cpu_time/result.cpu_time < 0.5) {
+                log_messages.printf(MSG_DEBUG,
+                    "[WORKUNIT#%d %s] Large difference in runtime \n",
+                    wu.id, wu.name
+                );
+            }
+        }
+    }
+
+
+    //find result with smallest deviation from historical credit and award that value
+    DB_HOST host;
+    double deviation = -1;
+    grant_credit = credit_avg; // default award in case nobody matches the cases
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        host.lookup_id(result.hostid);
+        log_messages.printf(MSG_DEBUG,
+            "[RESULT#%d %s] Claimed Credit = %.2lf  Historical Credit = %.2lf \n",
+            result.id, result.name, result.claimed_credit,
+            result.cpu_time*host.credit_per_cpu_sec
+        );
+        if ((deviation < 0 || deviation > fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec)) && result.cpu_time > 30) {
+            deviation = fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec);
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] Credit deviation = %.2lf \n",
+                result.id, result.name, deviation
+            );
+            grant_credit = result.claimed_credit;
+        }
+    }
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Credit granted = %.2lf \n",
+        wu.id, wu.name, grant_credit
+    );
+    return grant_credit;
+}
+
+const char *BOINC_RCSID_07049e8a0e = "$Id: validate_util.cpp 16069 2008-09-26 18:20:24Z davea $";
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/validate_util.h b/BOINC software/BOINC server apps/distrrtgen_validator/validate_util.h
new file mode 100644 (file)
index 0000000..bd8c766
--- /dev/null
@@ -0,0 +1,54 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef H_VALIDATE_UTIL
+#define H_VALIDATE_UTIL
+
+#include <vector>
+#include <string>
+
+#include "boinc_db.h"
+#include "parse.h"
+
+// bit of a misnomer - this actually taken from the <file_ref> elements
+// of result.xml_doc_in
+//
+struct FILE_INFO {
+    std::string name;
+    std::string path;
+    bool optional;
+    bool no_validate;
+
+    int parse(XML_PARSER&);
+};
+
+extern int get_output_file_info(RESULT& result, FILE_INFO&);
+extern int get_output_file_infos(RESULT& result, std::vector<FILE_INFO>&);
+extern int get_output_file_path(RESULT& result, std::string&);
+extern int get_output_file_paths(RESULT& result, std::vector<std::string>&);
+extern int get_logical_name(
+    RESULT& result, std::string& path, std::string& name
+);
+
+extern double median_mean_credit(WORKUNIT&, std::vector<RESULT>& results);
+extern int get_credit_from_wu(WORKUNIT&, std::vector<RESULT>& results, double&);
+extern double stddev_credit(WORKUNIT&, std::vector<RESULT>& results);
+extern double two_credit(WORKUNIT&, std::vector<RESULT>& results);
+extern int update_credit_per_cpu_sec(
+    double credit, double cpu_time, double& credit_per_cpu_sec
+);
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/validate_util2.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/validate_util2.cpp
new file mode 100644 (file)
index 0000000..15f7f32
--- /dev/null
@@ -0,0 +1,352 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Simple validator framework:
+// Lets you create a custom validator by supplying three functions.
+// See http://boinc.berkeley.edu/trac/wiki/ValidationSimple
+//
+
+#include "config.h"
+#include <vector>
+#include <cstdlib>
+#include <string>
+
+#include "boinc_db.h"
+#include "error_numbers.h"
+
+#include "sched_config.h"
+#include "sched_msgs.h"
+
+#include "validator.h"
+#include "validate_util.h"
+#include "validate_util2.h"
+#include "ChainWalkContext.h"
+#include "Public.h"
+#include "part_validator.h"
+
+using std::vector;
+
+// Given a set of results, check for a canonical result,
+// i.e. a set of at least min_quorum/2+1 results for which
+// that are equivalent according to check_pair().
+//
+// invariants:
+// results.size() >= wu.min_quorum
+// for each result:
+//   result.outcome == SUCCESS
+//   result.validate_state == INIT
+//
+int check_set(
+    vector<RESULT>& results, WORKUNIT& wu,
+    int& canonicalid, double& credit, bool& retry
+) {
+    DB_CONN frt;
+    char query[1024];
+    MYSQL_RES* resp;
+    MYSQL_ROW row;
+    int retval = frt.open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
+        return retry = true;
+    }
+    log_messages.printf(MSG_DEBUG, "Validating WU %i\n", wu.id);
+    
+    vector<void *> data;
+    vector<bool> had_error;
+    int i, j, neq = 0, n;
+    int min_valid = wu.min_quorum/2+1;
+
+    retry = false;
+    n = results.size();
+    data.resize(n);
+    had_error.resize(n);
+
+    // Initialize results
+
+    for (i=0; i<n; i++) {
+//        data[i] = "";
+        had_error[i] = false;
+    }
+    int good_results = 0;
+    for (i=0; i<n; i++) {
+        retval = init_result(results[i], data[i]);
+        if (retval == ERR_OPENDIR) {
+            log_messages.printf(MSG_CRITICAL,
+                "check_set: init_result([RESULT#%d %s]) transient failure\n",
+                results[i].id, results[i].name
+            );
+            had_error[i] = true;
+        } else if (retval) {
+            log_messages.printf(MSG_CRITICAL,
+                "check_set: init_result([RESULT#%d %s]) failed: %d\n",
+                results[i].id, results[i].name, retval
+            );
+            results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+            results[i].validate_state = VALIDATE_STATE_INVALID;
+            had_error[i] = true;
+        } else  {
+           log_messages.printf(MSG_DEBUG, "check_set: init_result([RESULTÂ#%d %s]) fie is ok\n", results[i].id, results[i].name);
+            good_results++;
+
+        }
+    }
+    if (good_results < wu.min_quorum) {
+       log_messages.printf(MSG_DEBUG, "good_results < wu.min_quorum (%d < %d)", good_results, wu.min_quorum);
+       goto cleanup;
+       }
+    // Compare results
+
+    for (i=0; i<n; i++) {
+        if (had_error[i]) continue;
+        vector<bool> matches;
+        matches.resize(n);
+        neq = 0;
+        RainbowPartFile *curData = (RainbowPartFile*)data[i];
+        const char *pos = strchr(results[i].name, ' ');
+        char partnum[256] = {0};
+        strncpy(partnum, results[i].name, pos - results[i].name);
+        int partid = atoi(partnum);
+        sprintf(query, "SELECT t.PartSize, t.HashRoutine, t.Charset, t.MinLetters, t.MaxLetters, t.Index, t.ChainLength, p.ChainStart, t.Credits FROM generator_parts p INNER JOIN generator_tables t ON t.TableID = p.TableID WHERE p.PartID = %i", partid);
+        retval = frt.do_query(query);
+        if(retval)  {
+               retry = true;
+               log_messages.printf(MSG_CRITICAL, "Error executing query '%s'", query);
+               goto cleanup;
+       }
+        resp = mysql_store_result(frt.mysql);
+        if (!resp) {
+               log_messages.printf(MSG_CRITICAL, "Error doing mysql_store_result()");
+               retry = true;
+               goto cleanup;
+       }
+        row = mysql_fetch_row(resp);
+        if (!row) { 
+               log_messages.printf(MSG_CRITICAL, "mysql row not found for query '%s'", query);
+               retry = true;
+               goto cleanup;
+       }
+        int PartSize = atoi(row[0]);
+       log_messages.printf(MSG_DEBUG, "Starting verification...\n");
+       log_messages.printf(MSG_DEBUG, "Num chains: %i PartSize: %i...\n", curData->numchains, PartSize);
+        
+        if(curData->numchains != PartSize)
+        {              
+               log_messages.printf(MSG_CRITICAL,
+                    "[RESULT#%d %s] File size doesn't match. Expectected %i, but got %i chains\n",
+                    results[i].id, results[i].name, PartSize, curData->numchains
+                );
+            results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+            results[i].validate_state = VALIDATE_STATE_INVALID;                
+            break;
+        }
+       log_messages.printf(MSG_DEBUG, "Converting %i %s %s %s %s %s %s %s %s...\n", partid, row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]);
+       
+        string sHashRoutineName = row[1];
+        string sCharsetName = row[2];
+        int nPlainLenMin = atoi(row[3]);
+        int nPlainLenMax = atoi(row[4]);
+        int nRainbowTableIndex = atoi(row[5]);
+        int nRainbowChainLen = atoi(row[6]);
+    mysql_free_result(resp);
+
+        uint64 nChainStartPosition = atoll(row[7]);
+        float creditvalue = atof(row[8]);
+       log_messages.printf(MSG_DEBUG, "Setting hash routine to %s...\n", sHashRoutineName.c_str());
+        if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
+        {
+               log_messages.printf(MSG_CRITICAL,"[RESULT#%d %s]hash routine %s not supported\n", results[i].id, results[i].name, sHashRoutineName.c_str());
+              results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+              results[i].validate_state = VALIDATE_STATE_INVALID;                                      
+               break;
+        }
+       log_messages.printf(MSG_DEBUG, "Setting charset to %s (%i-%i)...\n", sCharsetName.c_str(), nPlainLenMin, nPlainLenMax);
+        if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+        {
+               log_messages.printf(MSG_CRITICAL,"[RESULT#%d %s]charset %s (%i - %i) not supported\n", results[i].id, results[i].name, sCharsetName.c_str(), nPlainLenMin, nPlainLenMax);
+              results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+              results[i].validate_state = VALIDATE_STATE_INVALID;                                      
+               break;
+        }
+       log_messages.printf(MSG_DEBUG, "Setting index to %i...\n", nRainbowTableIndex);
+
+        if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
+        {
+               log_messages.printf(MSG_CRITICAL,"[RESULT#%d %s]invalid rainbow table index %d\n", results[i].id, results[i].name, nRainbowTableIndex);
+              results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+              results[i].validate_state = VALIDATE_STATE_INVALID;                                      
+               break;
+        }
+        RainbowChainCP *pChain = curData->pChain;
+        int nRainbowChainCountRead = curData->numchains;
+                                               // Chain length test
+       for(j = 1; j <= 25; j++)
+       {
+               int nIndexToVerify = nRainbowChainCountRead / 25 * j - 1;
+               CChainWalkContext cwc;
+       log_messages.printf(MSG_DEBUG, "Setting seed to %lld for verification step %i...\n", pChain[nIndexToVerify].nIndexS, j);
+
+               cwc.SetIndex(pChain[nIndexToVerify].nIndexS);
+               int nPos;
+               for (nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
+               {
+                       cwc.IndexToPlain();
+                       cwc.PlainToHash();
+                       cwc.HashToIndex(nPos);
+               }
+               
+               if (cwc.GetIndex() != pChain[nIndexToVerify].nIndexE)
+               {
+                       log_messages.printf(MSG_CRITICAL,
+                               "[RESULT#%d %s] Rainbow chain length verification failed at step %i index %i (%lld != %lld)\n", results[i].id, results[i].name, j, nIndexToVerify, cwc.GetIndex(), pChain[nIndexToVerify].nIndexE);
+                     results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+                     results[i].validate_state = VALIDATE_STATE_INVALID;               
+                       break;
+               }
+       }
+       if(results[i].outcome == RESULT_OUTCOME_VALIDATE_ERROR && results[i].validate_state == VALIDATE_STATE_INVALID) break;
+       log_messages.printf(MSG_DEBUG, "Checking if all %i chains is within bounds...\n", PartSize);
+
+       for(j = 0; j < PartSize; j++)
+       {
+               if(pChain[j].nIndexS < (nChainStartPosition - 500000) ||  pChain[j].nIndexS > (nChainStartPosition + PartSize))
+               {
+                       log_messages.printf(MSG_CRITICAL,
+                       "[RESULT#%d %s] Start index verification failed at step %i with number %llu. (< %llu | > %llu)\n", results[i].id, results[i].name, j, pChain[j].nIndexS, nChainStartPosition, (nChainStartPosition + PartSize));
+                     results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+                     results[i].validate_state = VALIDATE_STATE_INVALID;               
+                       break;
+               }
+               if(j > 0 && pChain[j].nIndexE < pChain[j-1].nIndexE)
+               {
+                       log_messages.printf(MSG_CRITICAL,
+                       "[RESULT#%d %s] Chain sort test failed at step %i with number %llu < %llu\n", results[i].id, results[i].name, j, pChain[j].nIndexE, pChain[j-1].nIndexE);
+                     results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+                     results[i].validate_state = VALIDATE_STATE_INVALID;               
+                       break;
+               }
+       }
+       if(results[i].outcome == RESULT_OUTCOME_VALIDATE_ERROR && results[i].validate_state == VALIDATE_STATE_INVALID) break;
+
+       results[i].validate_state = VALIDATE_STATE_VALID;
+       canonicalid = results[i].id;    
+       credit = creditvalue;
+       log_messages.printf(MSG_DEBUG, "WU %i is OK\n", wu.id);
+        /*
+        for (j=0; j!=n; j++) {
+            if (had_error[j]) continue;
+            bool match = false;
+            if (i == j) {
+                ++neq;
+                matches[j] = true;
+            } else if (compare_results(results[i], data[i], results[j], data[j], match)) {
+                log_messages.printf(MSG_CRITICAL,
+                    "generic_check_set: check_pair_with_data([RESULT#%d %s], [RESULT#%d %s]) failed\n",
+                    results[i].id, results[i].name, results[j].id, results[j].name
+                );
+            } else if (match) {
+                ++neq;
+                matches[j] = true;
+            }
+        }
+        if (neq >= min_valid) {
+
+            // set validate state for each result
+            //
+            for (j=0; j!=n; j++) {
+                if (had_error[j]) continue;
+                if (max_claimed_credit && results[j].claimed_credit > max_claimed_credit) {
+                    results[j].validate_state = VALIDATE_STATE_INVALID;
+                } else {
+                    results[j].validate_state = matches[j] ? VALIDATE_STATE_VALID : VALIDATE_STATE_INVALID;
+                }
+            }
+            canonicalid = results[i].id;
+            credit = compute_granted_credit(wu, results);
+            break;
+        }*/
+    }
+
+cleanup:
+
+    for (i=0; i<n; i++) {
+        cleanup_result(results[i], data[i]);
+    }
+    frt.close();
+//     exit(0);
+    return 0;
+}
+
+// r1 is the new result; r2 is canonical result
+//
+
+/*
+void check_pair(RESULT& r1, RESULT& r2, bool& retry) {
+    string data1;
+    string data2;
+    int retval;
+    bool match;
+
+    retry = false;
+    retval = init_result(r1, data1);
+    if (retval == ERR_OPENDIR) {
+        log_messages.printf(MSG_CRITICAL,
+            "check_pair: init_result([RESULT#%d %s]) transient failure 1\n",
+            r1.id, r1.name
+        );
+        retry = true;
+        return;
+    } else if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "check_pair: init_result([RESULT#%d %s]) perm failure 1\n",
+            r1.id, r1.name
+        );
+        r1.outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+        r1.validate_state = VALIDATE_STATE_INVALID;
+        return;
+    }
+
+    retval = init_result(r2, data2);
+    if (retval == ERR_OPENDIR) {
+        log_messages.printf(MSG_CRITICAL,
+            "check_pair: init_result([RESULT#%d %s]) transient failure 2\n",
+            r2.id, r2.name
+        );
+        cleanup_result(r1, data1);
+        retry = true;
+        return;
+    } else if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "check_pair: init_result([RESULT#%d %s]) perm failure2\n",
+            r2.id, r2.name
+        );
+        cleanup_result(r1, data1);
+        r1.outcome = RESULT_OUTCOME_VALIDATE_ERROR;
+        r1.validate_state = VALIDATE_STATE_INVALID;
+        return;
+    }
+
+    retval = compare_results(r1, data1, r2, data2, match);
+    if (max_claimed_credit && r1.claimed_credit > max_claimed_credit) {
+        r1.validate_state = VALIDATE_STATE_INVALID;
+    } else {
+        r1.validate_state = match?VALIDATE_STATE_VALID:VALIDATE_STATE_INVALID;
+    }
+    cleanup_result(r1, data1);
+    cleanup_result(r2, data2);
+}
+
+*/
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/validate_util2.h b/BOINC software/BOINC server apps/distrrtgen_validator/validate_util2.h
new file mode 100644 (file)
index 0000000..283f312
--- /dev/null
@@ -0,0 +1,31 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef _VALIDATE_UTIL2_
+#define _VALIDATE_UTIL2_
+
+#include <string>
+#include <vector>
+
+using std::string;
+
+extern int init_result(RESULT&, void*&);
+extern int compare_results(RESULT &, void*, RESULT const&, void*, bool&);
+extern int cleanup_result(RESULT const&, void*);
+extern double compute_granted_credit(WORKUNIT&, std::vector<RESULT>& results);
+
+#endif
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/validator.cpp b/BOINC software/BOINC server apps/distrrtgen_validator/validator.cpp
new file mode 100644 (file)
index 0000000..a0c4eb0
--- /dev/null
@@ -0,0 +1,668 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// validator - check and validate results, and grant credit
+//  -app appname
+//  [-d debug_level]
+//  [-one_pass_N_WU N]      // Validate only N WU in one pass, then exit
+//  [-one_pass]             // make one pass through WU table, then exit
+//  [-mod n i]              // process only WUs with (id mod n) == i
+//  [-max_granted_credit X] // limit maximum granted credit to X
+//  [-max_claimed_credit Y] // invalid if claims more than Y
+//  [-grant_claimed_credit] // just grant whatever is claimed 
+//  [-update_credited_job]  // add userid/wuid pair to credited_job table
+//  [-credit_from_wu]       // get credit from WU XML
+//
+// This program must be linked with two project-specific functions:
+// check_set() and check_pair().
+// See doc/validate.php for a description.
+
+using namespace std;
+
+#include "config.h"
+#include <unistd.h>
+#include <climits>
+#include <cmath>
+#include <vector>
+#include <cstdlib>
+#include <string>
+#include <signal.h>
+
+#include "boinc_db.h"
+#include "util.h"
+#include "str_util.h"
+#include "error_numbers.h"
+
+#include "sched_config.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+#include "validator.h"
+#include "validate_util.h"
+#ifdef GCL_SIMULATOR
+#include "gcl_simulator.h"
+#endif
+
+#define LOCKFILE "validate.out"
+#define PIDFILE  "validate.pid"
+
+#define SELECT_LIMIT    1000
+#define SLEEP_PERIOD    5
+
+int sleep_interval = SLEEP_PERIOD;
+
+typedef enum {
+    NEVER,
+    DELAYED,
+    IMMEDIATE,
+    NO_CHANGE
+} TRANSITION_TIME;
+
+extern int check_set(
+    vector<RESULT>&, WORKUNIT& wu, int& canonical, double& credit,
+    bool& retry
+);
+extern int check_pair(
+    RESULT & new_result, RESULT & canonical_result, bool& retry
+);
+
+char app_name[256];
+DB_APP app;
+int wu_id_modulus=0;
+int wu_id_remainder=0;
+int one_pass_N_WU=0;
+bool one_pass = false;
+double max_granted_credit = 0;
+double max_claimed_credit = 0;
+bool grant_claimed_credit = false;
+bool update_credited_job = false;
+bool credit_from_wu = false;
+WORKUNIT* g_wup;
+
+bool is_unreplicated(WORKUNIT& wu) {
+    return (wu.target_nresults == 1 && app.target_nresults > 1);
+}
+
+void update_error_rate(DB_HOST& host, bool valid) {
+    if (valid) {
+        host.error_rate *= 0.95;
+    } else {
+        host.error_rate += 0.1;
+    }
+    if (host.error_rate > 1) host.error_rate = 1;
+    if (host.error_rate <= 0) host.error_rate = 0.1;
+}
+
+// Here when a result has been validated and its granted_credit has been set.
+// Grant credit to host, user and team, and update host error rate.
+//
+int is_valid(RESULT& result, WORKUNIT& wu) {
+    DB_USER user;
+    DB_HOST host;
+    DB_TEAM team;
+    DB_CREDITED_JOB credited_job;
+    int retval;
+    char buf[256];
+
+    retval = host.lookup_id(result.hostid);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d] lookup of host %d failed %d\n",
+            result.id, result.hostid, retval
+        );
+        return retval;
+    }
+
+    retval = user.lookup_id(host.userid);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d] lookup of user %d failed %d\n",
+            result.id, host.userid, retval
+        );
+        return retval;
+    }
+
+    update_average(
+        result.sent_time, result.granted_credit, CREDIT_HALF_LIFE,
+        user.expavg_credit, user.expavg_time
+    );
+    sprintf(
+        buf, "total_credit=total_credit+%f, expavg_credit=%f, expavg_time=%f",
+        result.granted_credit,  user.expavg_credit, user.expavg_time
+    ); 
+    retval = user.update_field(buf);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d] update of user %d failed %d\n",
+            result.id, host.userid, retval
+        );
+    }
+
+    update_average(
+        result.sent_time, result.granted_credit, CREDIT_HALF_LIFE,
+        host.expavg_credit, host.expavg_time
+    );
+
+    double turnaround = result.received_time - result.sent_time;
+    compute_avg_turnaround(host, turnaround);
+
+        
+    // compute new credit per CPU time
+    //
+    retval = update_credit_per_cpu_sec(
+        result.granted_credit, result.cpu_time, host.credit_per_cpu_sec
+    );
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d][HOST#%d] claimed too much credit (%f) in too little CPU time (%f)\n",
+            result.id, result.hostid, result.granted_credit, result.cpu_time
+        );
+    }
+
+    double old_error_rate = host.error_rate;
+    if (!is_unreplicated(wu)) {
+        update_error_rate(host, true);
+    }
+    sprintf(
+        buf,
+        "total_credit=total_credit+%f, expavg_credit=%f, expavg_time=%f, avg_turnaround=%f, credit_per_cpu_sec=%f, error_rate=%f",
+        result.granted_credit,  host.expavg_credit, host.expavg_time, host.avg_turnaround, host.credit_per_cpu_sec, host.error_rate
+    );
+    retval = host.update_field(buf);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d] update of host %d failed %d\n",
+            result.id, result.hostid, retval
+        );
+    }
+    log_messages.printf(MSG_DEBUG,
+        "[HOST#%d] error rate %f->%f\n",
+        host.id, old_error_rate, host.error_rate
+    );
+
+    if (user.teamid) {
+        retval = team.lookup_id(user.teamid);
+        if (retval) {
+            log_messages.printf(MSG_CRITICAL,
+                "[RESULT#%d] lookup of team %d failed %d\n",
+                result.id, user.teamid, retval
+            );
+            return retval;
+        }
+        update_average(result.sent_time, result.granted_credit, CREDIT_HALF_LIFE, team.expavg_credit, team.expavg_time);
+        sprintf(
+            buf, "total_credit=total_credit+%f, expavg_credit=%f, expavg_time=%f",
+            result.granted_credit,  team.expavg_credit, team.expavg_time
+        );
+        retval = team.update_field(buf);
+        if (retval) {
+            log_messages.printf(MSG_CRITICAL,
+                "[RESULT#%d] update of team %d failed %d\n",
+                result.id, team.id, retval
+            );
+        }
+    }
+
+    if (update_credited_job) {
+        credited_job.userid = user.id;
+        credited_job.workunitid = long(wu.opaque);
+        retval = credited_job.insert();
+        if (retval) {
+            log_messages.printf(MSG_CRITICAL,
+                "[RESULT#%d] Warning: credited_job insert failed (userid: %d workunit: %f err: %d)\n",
+                result.id, user.id, wu.opaque, retval
+            );
+        } else {
+            log_messages.printf(MSG_DEBUG,
+                "[RESULT#%d %s] added credited_job record [WU#%d OPAQUE#%f USER#%d]\n",
+                result.id, result.name, wu.id, wu.opaque, user.id
+            );
+        }
+    }
+
+    return 0;
+}
+
+int is_invalid(WORKUNIT& wu, RESULT& result) {
+    char buf[256];
+    int retval;
+    DB_HOST host;
+
+    retval = host.lookup_id(result.hostid);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d] lookup of host %d failed %d\n",
+            result.id, result.hostid, retval
+        );
+        return retval;
+    }
+    double old_error_rate = host.error_rate;
+    if (!is_unreplicated(wu)) {
+        update_error_rate(host, false);
+    }
+    sprintf(buf, "error_rate=%f", host.error_rate);
+    retval = host.update_field(buf);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[RESULT#%d] update of host %d failed %d\n",
+            result.id, result.hostid, retval
+        );
+        return retval;
+    }
+    log_messages.printf(MSG_DEBUG,
+        "[HOST#%d] invalid result; error rate %f->%f\n",
+        host.id, old_error_rate, host.error_rate
+    );
+    return 0;
+}
+
+// Return zero iff we resolved the WU
+//
+int handle_wu(
+    DB_VALIDATOR_ITEM_SET& validator, std::vector<VALIDATOR_ITEM>& items
+) { 
+    int canonical_result_index = -1;
+    bool update_result, retry;
+    TRANSITION_TIME transition_time = NO_CHANGE;
+    int retval = 0, canonicalid = 0, x;
+    double credit = 0;
+    unsigned int i;
+
+    WORKUNIT& wu = items[0].wu;
+    g_wup = &wu;
+        vector<RESULT> results;
+        int nsuccess_results;
+
+        // Here if WU doesn't have a canonical result yet.
+        // Try to get one
+/*
+        log_messages.printf(MSG_NORMAL,
+            "[WU#%d %s] handle_wu(): No canonical result yet\n",
+            wu.id, wu.name
+        );*/
+        ++log_messages;
+
+        // make a vector of only successful results
+        //
+        for (i=0; i<items.size(); i++) {
+            RESULT& result = items[i].res;
+
+            if ((result.server_state == RESULT_SERVER_STATE_OVER) &&
+                (result.outcome == RESULT_OUTCOME_SUCCESS)
+            ) {
+                results.push_back(result);
+            }
+
+        }
+
+        log_messages.printf(MSG_DEBUG,
+            "[WU#%d %s] Found %d successful results\n",
+            wu.id, wu.name, (int)results.size()
+        );
+        if (results.size() >= (unsigned int)wu.min_quorum) {
+            log_messages.printf(MSG_DEBUG,
+                "[WU#%d %s] Enough for quorum, checking set.\n",
+                wu.id, wu.name
+            );
+           
+            retval = check_set(results, wu, canonicalid, credit, retry);
+            if (retval) {
+                log_messages.printf(MSG_CRITICAL,
+                    "[WU#%d %s] check_set returned %d, exiting\n",
+                    wu.id, wu.name, retval
+                );
+                return retval;
+            }
+            if (retry) transition_time = DELAYED;
+
+            if (credit_from_wu) {
+                retval = get_credit_from_wu(wu, results, credit);
+                if (retval) {
+                    log_messages.printf(MSG_CRITICAL,
+                        "[WU#%d %s] get_credit_from_wu returned %d\n",
+                        wu.id, wu.name, retval
+                    );
+                    return retval;
+                }
+            }
+            if (max_granted_credit && credit>max_granted_credit) {
+                credit = max_granted_credit;
+            }
+
+            // scan results.
+            // update as needed, and count the # of results
+            // that are still outcome=SUCCESS
+            // (some may have changed to VALIDATE_ERROR)
+            //
+            nsuccess_results = 0;
+            for (i=0; i<results.size(); i++) {
+                update_result = false;
+                RESULT& result = results[i];
+                if (result.outcome == RESULT_OUTCOME_VALIDATE_ERROR) {
+                    transition_time = IMMEDIATE;
+                    update_result = true;
+                } else {
+                    nsuccess_results++;
+                }
+
+                switch (result.validate_state) {
+                case VALIDATE_STATE_VALID:
+                    // grant credit for valid results
+                    //
+                    update_result = true;
+                    if (result.granted_credit == 0) {
+                        result.granted_credit = grant_claimed_credit ? result.claimed_credit : credit;
+                        if (max_granted_credit && result.granted_credit > max_granted_credit) {
+                            result.granted_credit = max_granted_credit;
+                        }
+                    }
+                    retval = is_valid(result, wu);
+                    if (retval) {
+                        log_messages.printf(MSG_DEBUG,
+                            "[RESULT#%d %s] is_valid() failed: %d\n",
+                            result.id, result.name, retval
+                        );
+                    }
+                    log_messages.printf(MSG_NORMAL,
+                        "[RESULT#%d %s] Valid; granted %f credit [HOST#%d]\n",
+                        result.id, result.name, result.granted_credit,
+                        result.hostid
+                    );
+                    break;
+                case VALIDATE_STATE_INVALID:
+                    log_messages.printf(MSG_NORMAL,
+                        "[RESULT#%d %s] Invalid [HOST#%d]\n",
+                        result.id, result.name, result.hostid
+                    );
+                    is_invalid(wu, result);
+                    update_result = true;
+                    break;
+                case VALIDATE_STATE_INIT:
+                    log_messages.printf(MSG_NORMAL,
+                        "[RESULT#%d %s] Inconclusive [HOST#%d]\n",
+                        result.id, result.name, result.hostid
+                    );
+                    result.validate_state = VALIDATE_STATE_INCONCLUSIVE;
+                    update_result = true;
+                    break;
+                }
+
+                if (update_result) {
+                    retval = validator.update_result(result);
+                    if (retval) {
+                        log_messages.printf(MSG_CRITICAL,
+                            "[RESULT#%d %s] result.update() failed: %d\n",
+                            result.id, result.name, retval
+                        );
+                    }
+                }
+
+            if (canonicalid) {
+                // if we found a canonical result,
+                // trigger the assimilator, but do NOT trigger
+                // the transitioner - doing so creates a race condition
+                //
+                transition_time = NEVER;
+                log_messages.printf(MSG_DEBUG,
+                    "[WU#%d %s] Found a canonical result: id=%d\n",
+                    wu.id, wu.name, canonicalid
+                );
+                wu.canonical_resultid = canonicalid;
+                wu.canonical_credit = credit;
+                wu.assimilate_state = ASSIMILATE_READY;
+
+                // If found a canonical result, don't send any unsent results
+                //
+                for (i=0; i<items.size(); i++) {
+                    RESULT& result = items[i].res;
+
+                    if (result.server_state != RESULT_SERVER_STATE_UNSENT) {
+                        continue;
+                    }
+
+                    result.server_state = RESULT_SERVER_STATE_OVER;
+                    result.outcome = RESULT_OUTCOME_DIDNT_NEED;
+                    retval = validator.update_result(result);
+                    if (retval) {
+                        log_messages.printf(MSG_CRITICAL,
+                            "[RESULT#%d %s] result.update() failed: %d\n",
+                            result.id, result.name, retval
+                        );
+                    }
+                }
+            } else {
+                // here if no consensus.
+
+                // check if #success results is too large
+                //
+                if (nsuccess_results > wu.max_success_results) {
+                    wu.error_mask |= WU_ERROR_TOO_MANY_SUCCESS_RESULTS;
+                    transition_time = IMMEDIATE;
+                }
+
+                // if #success results == than target_nresults,
+                // we need more results, so bump target_nresults
+                // NOTE: nsuccess_results should never be > target_nresults,
+                // but accommodate that if it should happen
+                //
+                if (nsuccess_results >= wu.target_nresults) {
+                    wu.target_nresults = nsuccess_results+1;
+                    transition_time = IMMEDIATE;
+                }
+            }
+        }
+    }
+
+    --log_messages;
+
+    switch (transition_time) {
+    case IMMEDIATE:
+        wu.transition_time = time(0);
+        break;
+    case DELAYED:
+        x = time(0) + 6*3600;
+        if (x < wu.transition_time) wu.transition_time = x;
+        break;
+    case NEVER:
+        wu.transition_time = INT_MAX;
+        break;
+    case NO_CHANGE:
+        break;
+    }
+
+    wu.need_validate = 0;
+    
+    retval = validator.update_workunit(wu);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "[WU#%d %s] update_workunit() failed: %d; exiting\n",
+            wu.id, wu.name, retval
+        );
+        return retval;
+    }
+    return 0;
+}
+
+// make one pass through the workunits with need_validate set.
+// return true if there were any
+//
+bool do_validate_scan() {
+    DB_VALIDATOR_ITEM_SET validator;
+    std::vector<VALIDATOR_ITEM> items;
+    bool found=false;
+    int retval;
+
+    // loop over entries that need to be checked
+    //
+    while (1) {
+        retval = validator.enumerate(
+            app.id, one_pass_N_WU?one_pass_N_WU:SELECT_LIMIT,
+            wu_id_modulus, wu_id_remainder,
+            items
+        );
+        if (retval) {
+            if (retval != ERR_DB_NOT_FOUND) {
+                log_messages.printf(MSG_DEBUG,
+                    "DB connection lost, exiting\n"
+                );
+                exit(0);
+            }
+            break;
+        }
+        retval = handle_wu(validator, items);
+        if (!retval) found = true;
+    }
+    return found;
+}
+
+int main_loop() {
+    int retval;
+    bool did_something;
+    char buf[256];
+
+    retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "boinc_db.open failed: %d\n", retval);
+        exit(1);
+    }
+
+    sprintf(buf, "where name='%s'", app_name);
+    retval = app.lookup(buf);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't find app %s\n", app_name);
+        exit(1);
+    }
+
+    while (1) {
+        check_stop_daemons();
+        did_something = do_validate_scan();
+        if (!did_something) {
+            if (one_pass) break;
+#ifdef GCL_SIMULATOR
+             char nameforsim[64];
+             sprintf(nameforsim, "validator%i", app.id);
+             continue_simulation(nameforsim);
+             signal(SIGUSR2, simulator_signal_handler);
+             pause();
+#else
+            sleep(sleep_interval);
+#endif
+        }
+    }
+    return 0;
+}
+
+// For use by user routines check_set() and check_match() that link to
+// this code.
+int boinc_validator_debuglevel=0;
+
+int main(int argc, char** argv) {
+    int i, retval;
+
+#if 0
+    int mypid=getpid();
+    char debugcmd[512];
+    sprintf(debugcmd, "ddd %s %d &", argv[0], mypid);
+    system(debugcmd);
+    sleep(30);
+#endif
+
+    const char *usage = 
+      "\nUsage: %s -app <app-name> [OPTIONS]\n"
+      "Start validator for application <app-name>\n\n"
+      "Optional arguments:\n"
+      "  -one_pass_N_WU N       Validate at most N WUs, then exit\n"
+      "  -one_pass              Make one pass through WU table, then exit\n"
+      "  -mod n i               Process only WUs with (id mod n) == i\n"
+      "  -max_claimed_credit X  If a result claims more credit than this, mark it as invalid\n"
+      "  -max_granted_credit X  Grant no more than this amount of credit to a result\n"
+      "  -grant_claimed_credit  Grant the claimed credit, regardless of what other results for this workunit claimed\n"
+      "  -update_credited_job   Add record to credited_job table after granting credit\n"
+      "  -credit_from_wu        Credit is specified in WU XML\n"
+      "  -sleep_interval n      Set sleep-interval to n\n"
+      "  -d level               Set debug-level\n\n";
+
+    if ((argc > 1) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
+      printf (usage, argv[0] );
+      exit(1);
+    }
+
+
+    check_stop_daemons();
+
+    for (i=1; i<argc; i++) {
+        if (!strcmp(argv[i], "-one_pass_N_WU")) {
+            one_pass_N_WU = atoi(argv[++i]);
+            one_pass = true;
+        } else if (!strcmp(argv[i], "-sleep_interval")) {
+            sleep_interval = atoi(argv[++i]);
+        } else if (!strcmp(argv[i], "-one_pass")) {
+            one_pass = true;
+        } else if (!strcmp(argv[i], "-app")) {
+            strcpy(app_name, argv[++i]);
+        } else if (!strcmp(argv[i], "-d")) {
+            boinc_validator_debuglevel=atoi(argv[++i]);
+            log_messages.set_debug_level(boinc_validator_debuglevel);
+        } else if (!strcmp(argv[i], "-mod")) {
+            wu_id_modulus = atoi(argv[++i]);
+            wu_id_remainder = atoi(argv[++i]);
+        } else if (!strcmp(argv[i], "-max_granted_credit")) {
+            max_granted_credit = atof(argv[++i]);
+        } else if (!strcmp(argv[i], "-max_claimed_credit")) {
+            max_claimed_credit = atof(argv[++i]);
+        } else if (!strcmp(argv[i], "-grant_claimed_credit")) {
+            grant_claimed_credit = true;
+        } else if (!strcmp(argv[i], "-update_credited_job")) {
+            update_credited_job = true;
+        } else if (!strcmp(argv[i], "-credit_from_wu")) {
+            credit_from_wu = true;
+        } else {
+            fprintf(stderr, "Invalid option '%s'\nTry `%s --help` for more information\n", argv[i], argv[0]);
+            log_messages.printf(MSG_CRITICAL, "unrecognized arg: %s\n", argv[i]);
+            exit(1);
+        }
+    }
+
+    // -app is required
+    if (app_name[0] == 0) {
+      fprintf (stderr, "\nERROR: use '-app' to specify the application to run the validator for.\n");
+      printf (usage, argv[0] );
+      exit(1);      
+    }
+
+    retval = config.parse_file("..");
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "Can't parse ../config.xml: %s\n", boincerror(retval)
+        );
+        exit(1);
+    }
+
+    log_messages.printf(MSG_NORMAL,
+        "Starting validator, debug level %d\n", log_messages.debug_level
+    );
+    if (wu_id_modulus) {
+        log_messages.printf(MSG_NORMAL,
+            "Modulus %d, remainder %d\n", wu_id_modulus, wu_id_remainder
+        );
+    }
+
+    install_stop_signal_handler();
+
+    main_loop();
+}
+
+const char *BOINC_RCSID_634dbda0b9 = "$Id: validator.cpp 16097 2008-09-30 18:21:41Z davea $";
diff --git a/BOINC software/BOINC server apps/distrrtgen_validator/validator.h b/BOINC software/BOINC server apps/distrrtgen_validator/validator.h
new file mode 100644 (file)
index 0000000..0f7fc48
--- /dev/null
@@ -0,0 +1,30 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "sched_config.h"
+
+extern double max_granted_credit;
+    // the -max_granted_credit cmdline arg, or 0
+extern double max_claimed_credit;
+    // the -max_claimed_credit cmdline arg, or 0
+extern bool grant_claimed_credit;
+    // the -grant_claimed_credit cmdline arg, or false
+
+extern WORKUNIT* g_wup;
+    // A pointer to the WU currently being processed;
+    // you can use this in your init_result() etc. functions
+
diff --git a/BOINC software/BOINC server apps/distrrtgen_workgenerator/Makefile b/BOINC software/BOINC server apps/distrrtgen_workgenerator/Makefile
new file mode 100644 (file)
index 0000000..222b83a
--- /dev/null
@@ -0,0 +1,46 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/frt/server_stable
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+BOINC_SCHED_DIR = $(BOINC_DIR)/sched
+BOINC_DB_DIR = $(BOINC_DIR)/db
+BOINC_TOOLS_DIR = $(BOINC_DIR)/tools
+MYSQL_DIR = /usr/local/include/mysql
+
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -I$(BOINC_SCHED_DIR) \
+    -I$(BOINC_DB_DIR) \
+    -I$(MYSQL_DIR) \
+    -I$(BOINC_TOOLS_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L$(BOINC_SCHED_DIR) \
+    -L/usr/X11R6/lib \
+    -L/usr/local/lib/mysql \
+    -L.
+
+# the following should be freeglut; use nm to check
+# you may have to change the paths for your system
+
+PROGS = distrrtgen \
+# uc2_graphics
+# make this optional so compile doesn't break on systems without OpenGL
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+distrrtgen: distrrtgen_workgenerator.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_SCHED_DIR)/libsched.a 
+       $(CXX) distrrtgen_workgenerator.cpp $(CXXFLAGS) -o distrrtgen_workgenerator libstdc++.a -pthread -lboinc_api -lsched -lboinc -lmysqlclient -lssl -O3 
diff --git a/BOINC software/BOINC server apps/distrrtgen_workgenerator/distrrtgen_workgenerator.cpp b/BOINC software/BOINC server apps/distrrtgen_workgenerator/distrrtgen_workgenerator.cpp
new file mode 100644 (file)
index 0000000..8b0bf51
--- /dev/null
@@ -0,0 +1,228 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// sample_work_generator.C: an example BOINC work generator.
+// This work generator has the following properties
+// (you may need to change some or all of these):
+//
+// - Runs as a daemon, and creates an unbounded supply of work.
+//   It attempts to maintain a "cushion" of 100 unsent job instances.
+//   (your app may not work this way; e.g. you might create work in batches)
+// - Creates work for the application "uppercase".
+// - Creates a new input file for each job;
+//   the file (and the workunit names) contain a timestamp
+//   and sequence number, so that they're unique.
+
+#include <unistd.h>
+#include <cstdlib>
+#include <string>
+#include <cstring>
+
+#include "boinc_db.h"
+#include "error_numbers.h"
+#include "backend_lib.h"
+#include "parse.h"
+#include "util.h"
+
+#include "sched_config.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+
+#define CUSHION 100
+#define int64 long long
+    // maintain at least this many unsent results
+#define REPLICATION_FACTOR 2
+// globals
+//
+char* wu_template;
+DB_APP app;
+DB_CONN *frt;
+int start_time;
+int seqno;
+
+using namespace std;
+// create one new job
+//
+int make_job() {
+    DB_WORKUNIT wu;
+    MYSQL_RES* resp;    
+    MYSQL_ROW row;
+    char name[256], path[256], query[1024];
+    const char* infiles[1];
+    int retval;
+    string charset;
+//    retval = frt->do_query("CALL requestwork(1)");    
+    frt->do_query("SELECT TableID, ChainStartPosition FROM generator_tables WHERE ChainsDone < (NumTargetChains/* - (NumTargetChains / 20)*/) AND ChainStartPosition < Keyspace - PartSize AND IsCompleted = 0 LIMIT 1;");
+    if(retval)         return retval;
+    resp = mysql_store_result(frt->mysql);
+    if (!resp) return ERR_DB_NOT_FOUND;
+    row = mysql_fetch_row(resp);
+    mysql_free_result(resp);
+    if (!row) return ERR_DB_NOT_FOUND;
+    int tableid = atoi(row[0]);
+    int64 chainstart = atol(row[1]);
+    sprintf(query, "INSERT INTO generator_parts SET TableID = %s, ClientID = 1, AssignedTime = NOW(), Status = 1, ChainStart = %s\0", row[0], row[1]);
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval)  return retval;
+    int partid = frt->insert_id();
+
+    sprintf(query, "UPDATE generator_tables SET ChainStartPosition = ChainStartPosition + PartSize WHERE TableID = %i\0", tableid);
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval)  return retval;
+
+    
+    log_messages.printf(MSG_DEBUG, "SELECTING FROM DB\n");
+    sprintf(query, "SELECT %i AS PartID, HashRoutine, Charset, MinLetters, MaxLetters, `Index`, ChainLength, PartSize AS ChainCount, '%lld' AS ChainStart, CheckPoints, Salt  FROM generator_tables WHERE TableID = %i;\0", partid, chainstart, tableid);    
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+
+    retval = frt->do_query(query);
+    if(retval)  return retval;
+    resp = mysql_store_result(frt->mysql);
+    if (!resp) return ERR_DB_NOT_FOUND;
+    row = mysql_fetch_row(resp);
+    mysql_free_result(resp);
+    if (!row) return ERR_DB_NOT_FOUND;
+    char command_line[256];
+//    char filename[256];
+    sprintf(command_line, "%s %s %s %s %s %s %s %s %s", row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9]);
+
+    // make a unique name (for the job and its input file)
+    //
+    sprintf(name, "%s %s_%s#%s-%s_%s_%sx%s - %s", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]);
+//    sprintf(filename, "%s.txt", row[0]);
+    log_messages.printf(MSG_DEBUG, "%s\n", name);
+    
+    read_file_malloc("templates/input_template.xml", wu_template);
+  //  read_file_string("../download/charset.txt", charset);
+ /*   retval = config.download_path(filename, path);
+    if (retval) return retval;
+    FILE* f = fopen(path, "wb");
+    if (!f) return ERR_FOPEN;
+    fwrite(charset.c_str(), charset.length(), 1, f);
+    fclose(f);
+    infiles[0] = filename;*/
+    // Fill in the job parameters
+    //
+    wu.clear();
+    wu.appid = app.id;
+    strcpy(wu.name, name);
+    wu.rsc_fpops_est = 1e13;
+    wu.rsc_fpops_bound = 1e16;
+    wu.rsc_memory_bound = 1e8;
+    wu.rsc_disk_bound = 1e8;
+    wu.delay_bound = 4*86400;
+    wu.min_quorum = 1;
+    wu.target_nresults = 1;
+    wu.max_error_results = 8;
+    wu.max_total_results = 10;
+    wu.max_success_results = 2;
+    // Register the job with BOINC
+    //
+    return create_work(
+        wu,
+        wu_template,
+        "templates/output_template.xml",
+        "../templates/output_template.xml",
+        NULL,
+        0,
+        config,
+       command_line
+    );
+}
+
+void main_loop() {
+    int retval;
+
+    while (1) {
+        check_stop_daemons();
+        int n;
+        retval = count_unsent_results(n, 0);
+        if (n > CUSHION) {
+            sleep(60);
+        } else {
+            int njobs = (CUSHION-n)/REPLICATION_FACTOR;
+            log_messages.printf(MSG_DEBUG,
+                "Making %d jobs\n", njobs
+            );
+            for (int i=0; i<njobs; i++) {
+                retval = make_job();
+                if (retval) {
+                    log_messages.printf(MSG_CRITICAL,
+                        "can't make job: %d\n", retval
+                    );
+                    exit(retval);
+                }
+            }
+            // Now sleep for a few seconds to let the transitioner
+            // create instances for the jobs we just created.
+            // Otherwise we could end up creating an excess of jobs.
+            sleep(5);
+        }
+    }
+}
+
+int main(int argc, char** argv) {
+    int i, retval;
+    frt = new DB_CONN();
+
+    for (i=1; i<argc; i++) {
+        if (!strcmp(argv[i], "-d")) {
+            log_messages.set_debug_level(atoi(argv[++i]));
+        } else {
+            log_messages.printf(MSG_CRITICAL,
+                "bad cmdline arg: %s", argv[i]
+            );
+        }
+    }
+
+    if (config.parse_file("..")) {
+        log_messages.printf(MSG_CRITICAL,
+            "can't read config file\n"
+        );
+        exit(1);
+    }
+    retval = frt->open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
+        exit(1);
+    }
+
+    retval = boinc_db.open(
+        config.db_name, config.db_host, config.db_user, config.db_passwd
+    );
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db\n");
+        exit(1);
+    }
+    if (app.lookup("where name='distrrtgen'")) {
+        log_messages.printf(MSG_CRITICAL, "can't find app\n");
+        exit(1);
+    }
+    if (read_file_malloc("../templates/input_template.xml", wu_template)) {
+        log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
+        exit(1);
+    }
+
+    start_time = time(0);
+    seqno = 0;
+
+    log_messages.printf(MSG_NORMAL, "Starting\n");
+
+    main_loop();
+}
diff --git a/BOINC software/BOINC server apps/index_calculator_assimilator/Makefile b/BOINC software/BOINC server apps/index_calculator_assimilator/Makefile
new file mode 100644 (file)
index 0000000..25a90bc
--- /dev/null
@@ -0,0 +1,56 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/boincadm/src/boinc
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+BOINC_SCHED_DIR = $(BOINC_DIR)/sched
+BOINC_DB_DIR = $(BOINC_DIR)/db
+BOINC_TOOLS_DIR = $(BOINC_DIR)/tools
+MYSQL_DIR = /usr/include/mysql
+
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -I$(BOINC_SCHED_DIR) \
+    -I$(BOINC_DB_DIR) \
+    -I$(MYSQL_DIR) \
+    -I$(BOINC_TOOLS_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L$(BOINC_SCHED_DIR) \
+    -L/usr/X11R6/lib \
+    -L/usr/lib/mysql \
+    -L.
+
+# the following should be freeglut; use nm to check
+# you may have to change the paths for your system
+
+ifeq ($(wildcard /usr/local/lib/libglut.a),)
+       LIBGLUT = /usr/lib/libglut.a
+       LIBGLU = /usr/lib/libGLU.a
+       LIBJPEG = /usr/lib/libjpeg.a
+else
+       LIBGLUT = /usr/local/lib/libglut.a
+       LIBGLU = /usr/local/lib/libGLU.a
+       LIBJPEG = /usr/local/lib/libjpeg.a
+endif
+
+PROGS = distrrtgen \
+# uc2_graphics
+# make this optional so compile doesn't break on systems without OpenGL
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+distrrtgen: index_calculator_assimilator.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_SCHED_DIR)/libsched.a 
+       $(CXX) index_calculator_assimilator.cpp assimilator.cpp validate_util.cpp $(CXXFLAGS) -o index_calculator_assimilator libstdc++.a -pthread -lboinc_api -lsched -lboinc -lmysqlclient -lssl -O3 
diff --git a/BOINC software/BOINC server apps/index_calculator_assimilator/assimilate_handler.h b/BOINC software/BOINC server apps/index_calculator_assimilator/assimilate_handler.h
new file mode 100644 (file)
index 0000000..e3086c9
--- /dev/null
@@ -0,0 +1,31 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Include this in assimilate handlers
+
+#include <vector>
+#include "boinc_db.h"
+#define DEFER_ASSIMILATION 123321
+    // if the assimilate handler returns this,
+    // don't mark WU as assimilated; instead, wait for another
+    // result to be returned and try again
+    // (kludge for WCG)
+
+extern int assimilate_handler(WORKUNIT&, std::vector<RESULT>&, RESULT&);
+
+extern int g_argc;
+extern char** g_argv;
diff --git a/BOINC software/BOINC server apps/index_calculator_assimilator/assimilator.cpp b/BOINC software/BOINC server apps/index_calculator_assimilator/assimilator.cpp
new file mode 100644 (file)
index 0000000..6cdba52
--- /dev/null
@@ -0,0 +1,285 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// This is a framework for an assimilator.
+// You need to link this with an (application-specific) function
+// assimilate_handler()
+// in order to make a complete program.
+//
+
+#include "config.h"
+#include <cstring>
+#include <cstdlib>
+#include <unistd.h>
+#include <ctime>
+#include <vector>
+
+#include "boinc_db.h"
+#include "parse.h"
+#include "util.h"
+#include "error_numbers.h"
+#include "str_util.h"
+
+#include "sched_config.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+#include "assimilate_handler.h"
+
+using std::vector;
+
+#define LOCKFILE "assimilator.out"
+#define PIDFILE  "assimilator.pid"
+#define SLEEP_INTERVAL 10
+
+bool update_db = true;
+bool noinsert = false;
+int wu_id_modulus=0, wu_id_remainder=0;
+int sleep_interval = SLEEP_INTERVAL;
+int one_pass_N_WU=0;
+int g_argc;
+char** g_argv;
+
+void usage(char** argv) {
+    fprintf(stderr,
+        "This program is an 'assimilator'; it handles completed jobs.\n"
+        "Normally it is run as a daemon from config.xml.\n"
+        "See: http://boinc.berkeley.edu/trac/wiki/BackendPrograms\n\n"
+    );
+
+    fprintf(stderr, "usage: %s [options]\n"
+        "    Options:\n"
+        "    -app name            Process jobs for the given application\n"
+        "    [-sleep_interval X]  Sleep X seconds if no jobs to process (default 10)\n"
+        "    [-mod N R]           Process jobs with mod(ID, N) == R\n"
+        "    [-one_pass]          Do one DB enumeration, then exit\n"
+        "    [-one_pass_N_WU N]   Process at most N jobs\n"
+        "    [-d N]               Set verbosity level (1, 2, 3=most verbose)\n"
+        "    [-dont_update_db]    Don't update DB (for testing)\n"
+        "    [-noinsert]          Don't insert records in app-specific DB\n",
+        argv[0]
+    );
+    exit(0);
+}
+
+// assimilate all WUs that need it
+// return nonzero if did anything
+//
+bool do_pass(APP& app) {
+    DB_WORKUNIT wu;
+    DB_RESULT canonical_result, result;
+    bool did_something = false;
+    char buf[256];
+    char mod_clause[256];
+    int retval;
+    int num_assimilated=0;
+
+    check_stop_daemons();
+
+    if (wu_id_modulus) {
+        sprintf(mod_clause, " and workunit.id %% %d = %d ",
+                wu_id_modulus, wu_id_remainder
+        );
+    } else {
+        strcpy(mod_clause, "");
+    }
+
+    sprintf(buf,
+        "where appid=%d and assimilate_state=%d %s limit %d",
+        app.id, ASSIMILATE_READY, mod_clause,
+        one_pass_N_WU ? one_pass_N_WU : 1000
+    );
+    while (1) {
+        retval = wu.enumerate(buf);
+        if (retval) {
+            if (retval != ERR_DB_NOT_FOUND) {
+                log_messages.printf(MSG_DEBUG,
+                    "DB connection lost, exiting\n"
+                );
+                exit(0);
+            }
+            break;
+        }
+        vector<RESULT> results;     // must be inside while()!
+
+        // for testing purposes, pretend we did nothing
+        //
+        if (update_db) {
+            did_something = true;
+        }
+
+        log_messages.printf(MSG_DEBUG,
+            "[%s] assimilating WU %d; state=%d\n", wu.name, wu.id, wu.assimilate_state
+        );
+
+        sprintf(buf, "where workunitid=%d", wu.id);
+        canonical_result.clear();
+        bool found = false;
+        while (!result.enumerate(buf)) {
+            results.push_back(result);
+            if (result.id == wu.canonical_resultid) {
+                canonical_result = result;
+                found = true;
+            }
+        }
+
+        // If no canonical result found and WU had no other errors,
+        // something is wrong, e.g. result records got deleted prematurely.
+        // This is probably unrecoverable, so mark the WU as having
+        // an assimilation error and keep going.
+        //
+        if (!found && !wu.error_mask) {
+            log_messages.printf(MSG_CRITICAL,
+                "[%s] no canonical result\n", wu.name
+            );
+            wu.error_mask = WU_ERROR_NO_CANONICAL_RESULT;
+            sprintf(buf, "error_mask=%d", wu.error_mask);
+            wu.update_field(buf);
+        }
+
+        retval = assimilate_handler(wu, results, canonical_result);
+        if (retval && retval != DEFER_ASSIMILATION) {
+            log_messages.printf(MSG_CRITICAL,
+                "[%s] handler returned error %d; exiting\n", wu.name, retval
+            );
+            exit(retval);
+        }
+
+        if (update_db) {
+            // Defer assimilation until next result is returned
+            int assimilate_state = ASSIMILATE_DONE;
+            if (retval == DEFER_ASSIMILATION) {
+                assimilate_state = ASSIMILATE_INIT;
+            }
+            sprintf(
+                buf, "assimilate_state=%d, transition_time=%d", 
+                assimilate_state, (int)time(0)
+            );
+            retval = wu.update_field(buf);
+            if (retval) {
+                log_messages.printf(MSG_CRITICAL,
+                    "[%s] update failed: %d\n", wu.name, retval
+                );
+                exit(1);
+            }
+        }
+
+        num_assimilated++;
+
+    }
+
+    if (did_something) {
+        boinc_db.commit_transaction();
+    }
+
+    if (num_assimilated)  {
+        log_messages.printf(MSG_NORMAL,
+            "Assimilated %d workunits.\n", num_assimilated
+        );
+    }
+
+    return did_something;
+}
+
+int main(int argc, char** argv) {
+    int retval;
+    bool one_pass = false;
+    DB_APP app;
+    int i;
+    char buf[256];
+
+    strcpy(app.name, "");
+    check_stop_daemons();
+    g_argc = argc;
+    g_argv = argv;
+    for (i=1; i<argc; i++) {
+        if (!strcmp(argv[i], "-one_pass_N_WU")) {
+            one_pass_N_WU = atoi(argv[++i]);
+            one_pass = true;
+        } else if (!strcmp(argv[i], "-sleep_interval")) {
+            sleep_interval = atoi(argv[++i]);
+        } else if (!strcmp(argv[i], "-one_pass")) {
+            one_pass = true;
+        } else if (!strcmp(argv[i], "-d")) {
+            log_messages.set_debug_level(atoi(argv[++i]));
+        } else if (!strcmp(argv[i], "-app")) {
+            strcpy(app.name, argv[++i]);
+        } else if (!strcmp(argv[i], "-dont_update_db")) {
+            // This option is for testing your assimilator.  When set,
+            // it ensures that the assimilator does not actually modify
+            // the assimilate_state of the workunits, so you can run
+            // your assimilator over and over again without affecting
+            // your project.
+            update_db = false;
+        } else if (!strcmp(argv[i], "-noinsert")) {
+            // This option is also for testing and is used to 
+            // prevent the inserting of results into the *backend*
+            // (as opposed to the boinc) DB.
+            noinsert = true;
+        } else if (!strcmp(argv[i], "-mod")) {
+            wu_id_modulus   = atoi(argv[++i]);
+            wu_id_remainder = atoi(argv[++i]);
+        } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
+            usage(argv);
+        } else {
+            log_messages.printf(MSG_CRITICAL, "Unrecognized arg: %s\n", argv[i]);
+            usage(argv);
+        }
+    }
+
+    if (!strlen(app.name)) {
+        usage(argv);
+    }
+
+    if (wu_id_modulus) {
+        log_messages.printf(MSG_DEBUG,
+            "Using mod'ed WU enumeration.  modulus = %d  remainder = %d\n",
+            wu_id_modulus, wu_id_remainder
+        );
+    }
+
+    retval = config.parse_file("..");
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL,
+            "Can't parse ../config.xml: %s\n", boincerror(retval)
+        );
+        exit(1);
+    }
+
+    log_messages.printf(MSG_NORMAL, "Starting\n");
+
+    retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "Can't open DB\n");
+        exit(1);
+    }
+    sprintf(buf, "where name='%s'", app.name);
+    retval = app.lookup(buf);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "Can't find app\n");
+        exit(1);
+    }
+    install_stop_signal_handler();
+    while (1) {
+        if (!do_pass(app)) {
+            if (one_pass) break;
+            sleep(sleep_interval);
+        }
+    }
+}
+
+
+const char *BOINC_RCSID_7841370789 = "$Id: assimilator.cpp 16121 2008-10-03 19:31:56Z davea $";
diff --git a/BOINC software/BOINC server apps/index_calculator_assimilator/index_calculator_assimilator.cpp b/BOINC software/BOINC server apps/index_calculator_assimilator/index_calculator_assimilator.cpp
new file mode 100644 (file)
index 0000000..98c2a94
--- /dev/null
@@ -0,0 +1,152 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// A sample assimilator that:
+// 1) if success, copy the output file(s) to a directory
+// 2) if failure, append a message to an error log
+
+#include <vector>
+#include <string>
+#include <cstdlib>
+#include <sys/types.h>
+#include <pwd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "boinc_db.h"
+#include "error_numbers.h"
+#include "filesys.h"
+#include "sched_msgs.h"
+#include "validate_util.h"
+#include "sched_config.h"
+using std::vector;
+using std::string;
+
+int write_error(char* p) {
+    static FILE* f = 0;
+    if (!f) {
+        f = fopen("../../results/errors", "a");
+        if (!f) return ERR_FOPEN;
+    }
+    fprintf(f, "%s", p);
+    fflush(f);
+    return 0;
+}
+
+int GetNumFilesInDir(char *dir)
+{
+       DIR *partsdir;
+       struct dirent *part;
+       if((partsdir  = opendir(dir)) == NULL) {
+               return 0;
+       }
+       int numfiles = 0;
+       while ((part = readdir(partsdir)) != NULL) 
+       {
+               char *partname = part->d_name;
+               if(partname != "." && partname != "..")
+               {
+                       numfiles++;
+               }
+       }
+       return numfiles;
+
+}
+int assimilate_handler(
+    WORKUNIT& wu, vector<RESULT>& /*results*/, RESULT& canonical_result
+) {
+    DB_CONN frt;
+    int retval;
+    char buf[1024];
+    char query[1024];
+    unsigned int i;
+    int tableid;
+    MYSQL_RES* resp;
+    MYSQL_ROW row;
+    retval = frt.open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
+        exit(1);
+    }
+
+    
+    const char *pos = strchr(wu.name, ' ');
+    char partnum[256] = {0};
+    strncpy(partnum, wu.name, pos - wu.name);
+    int lookupid = atoi(partnum);
+    log_messages.printf(MSG_DEBUG, "Handling lookupid %i\n", lookupid);    
+
+    
+    if (wu.canonical_resultid) {
+        char resdir[512];
+struct passwd *pwd;
+struct group *grp;
+pwd = getpwnam("rainbow");
+grp = getgrnam("rainbow");
+
+        sprintf(query, "UPDATE rainbowcrack_cracker_lookups SET hasindices = 2 WHERE lookupid = %i", lookupid);
+//     log_messages.printf(MSG_DEBUG, "%s\n", query);
+        frt.do_query(query);
+        if(retval)  goto cleanup;
+        sprintf(query, "SELECT tableid FROM rainbowcrack_cracker_lookups WHERE lookupid = %i", lookupid);
+//     log_messages.printf(MSG_DEBUG, "%s\n", query);
+       retval = frt.do_query(query);
+       if(retval) {
+               log_messages.printf(MSG_DEBUG, "Query returned %i\n", retval);
+               goto cleanup;
+       }
+       resp = mysql_store_result(frt.mysql);
+       if (!resp) {retval = ERR_DB_NOT_FOUND; goto cleanup; }
+       row = mysql_fetch_row(resp);
+       mysql_free_result(resp);
+       if (!row) { retval = ERR_DB_NOT_FOUND; goto cleanup; }
+       int tableid = atoi(row[0]);
+        sprintf(resdir, "../../indices/%s", row[0]);
+//     log_messages.printf(MSG_DEBUG, "Result dir: %s\n", resdir);     
+        retval = boinc_mkdir(resdir);
+        vector<FILE_INFO> output_files;
+        char copy_path[256];
+        get_output_file_infos(canonical_result, output_files);
+        unsigned int n = output_files.size();
+//     log_messages.printf(MSG_DEBUG, "Number of output files: %i\n", n);
+        for (i=0; i<n; i++) {
+            FILE_INFO& fi = output_files[i];
+                if (n==1) {
+                     sprintf(copy_path, "../../indices/%i/%i.index", tableid, lookupid);
+                } else {
+                    sprintf(copy_path, "../../indices/%i/%i_%d.index", tableid, lookupid, i);
+                }
+//             log_messages.printf(MSG_DEBUG, "Copying from %s to %s\n", fi.path.c_str(), copy_path);
+                retval = boinc_copy(fi.path.c_str() , copy_path);
+               int fildes = open(copy_path, O_RDWR);
+               fchown(fildes, pwd->pw_uid, grp->gr_gid);
+                if (retval && !fi.optional) {
+                   log_messages.printf(MSG_CRITICAL, "FAILED copy operation of %s to %s\n", fi.path.c_str(), copy_path);
+                    sprintf(buf, "couldn't copy file %s\n", fi.path.c_str());
+                    write_error(buf);
+                   goto cleanup;
+                }
+        }
+    } else {
+        sprintf(buf, "%s: 0x%x\n", wu.name, wu.error_mask);
+        return write_error(buf);
+    }
+    retval = 0;
+cleanup:
+    frt.close();       
+    return retval;
+}
diff --git a/BOINC software/BOINC server apps/index_calculator_assimilator/validate_util.cpp b/BOINC software/BOINC server apps/index_calculator_assimilator/validate_util.cpp
new file mode 100644 (file)
index 0000000..f3bf361
--- /dev/null
@@ -0,0 +1,564 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// Code to facilitate writing validators.
+// Can be used as the basis for a validator that accepts everything
+// (see sample_trivial_validator.C),
+// or that requires strict equality (see sample_bitwise_validator.C)
+// or that uses fuzzy comparison.
+
+#include <cstring>
+#include "config.h"
+
+#include "error_numbers.h"
+#include "parse.h"
+#include "util.h"
+#include "filesys.h"
+
+#include "sched_util.h"
+#include "sched_config.h"
+#include "sched_msgs.h"
+#include "validator.h"
+#include "validate_util.h"
+
+using std::vector;
+using std::string;
+
+int FILE_INFO::parse(XML_PARSER& xp) {
+    char tag[256];
+    bool is_tag, found=false;
+    optional = false;
+    no_validate = false;
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "/file_ref")) {
+            return found?0:ERR_XML_PARSE;
+        }
+        if (xp.parse_string(tag, "file_name", name)) {
+            found = true;
+            continue;
+        }
+        if (xp.parse_bool(tag, "optional", optional)) continue;
+        if (xp.parse_bool(tag, "no_validate", no_validate)) continue;
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_info(RESULT& result, FILE_INFO& fi) {
+    char tag[256], path[1024];
+    bool is_tag;
+    string name;
+    MIOFILE mf;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            int retval = fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+int get_output_file_infos(RESULT& result, vector<FILE_INFO>& fis) {
+    char tag[256], path[1024];
+    bool is_tag;
+    MIOFILE mf;
+    string name;
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+    fis.clear();
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_INFO fi;
+            int retval =  fi.parse(xp);
+            if (retval) return retval;
+            dir_hier_path(
+                fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
+            );
+            fi.path = path;
+            fis.push_back(fi);
+        }
+    }
+    return 0;
+}
+
+int get_output_file_path(RESULT& result, string& path) {
+    FILE_INFO fi;
+    int retval = get_output_file_info(result, fi);
+    if (retval) return retval;
+    path = fi.path;
+    return 0;
+}
+
+int get_output_file_paths(RESULT& result, vector<string>& paths) {
+    vector<FILE_INFO> fis;
+    int retval = get_output_file_infos(result, fis);
+    if (retval) return retval;
+    paths.clear();
+    for (unsigned int i=0; i<fis.size(); i++) {
+        paths.push_back(fis[i].path);
+    }
+    return 0;
+}
+
+struct FILE_REF {
+    char file_name[256];
+    char open_name[256];
+    int parse(XML_PARSER& xp) {
+        char tag[256];
+        bool is_tag;
+
+        strcpy(file_name, "");
+        strcpy(open_name, "");
+        while (!xp.get(tag, sizeof(tag), is_tag)) {
+            if (!is_tag) continue;
+            if (!strcmp(tag, "/file_ref")) {
+                return 0;
+            }
+            if (xp.parse_str(tag, "file_name", file_name, sizeof(file_name))) continue;
+            if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) continue;
+        }
+        return ERR_XML_PARSE;
+    }
+};
+
+// given a path returned by the above, get the corresponding logical name
+//
+int get_logical_name(RESULT& result, string& path, string& name) {
+    char phys_name[1024];
+    char tag[256];
+    bool is_tag;
+    MIOFILE mf;
+    int retval;
+
+    mf.init_buf_read(result.xml_doc_in);
+    XML_PARSER xp(&mf);
+
+    strcpy(phys_name, path.c_str());
+    char* p = strrchr(phys_name, '/');
+    if (!p) return ERR_NOT_FOUND;
+    strcpy(phys_name, p+1);
+
+    while (!xp.get(tag, sizeof(tag), is_tag)) {
+        if (!is_tag) continue;
+        if (!strcmp(tag, "result")) continue;
+        if (!strcmp(tag, "file_ref")) {
+            FILE_REF fr;
+            retval = fr.parse(xp);
+            if (retval) continue;
+            if (!strcmp(phys_name, fr.file_name)) {
+                name = fr.open_name;
+                return 0;
+            }
+            continue;
+        }
+        xp.skip_unexpected(tag, false, 0);
+    }
+    return ERR_XML_PARSE;
+}
+
+#define CREDIT_EPSILON .001
+
+// If we have N correct results with nonzero claimed credit,
+// compute a canonical credit as follows:
+// - if N==0 (all claimed credits are infinitesmal), return CREDIT_EPSILON
+// - if N==1, return that credit
+// - if N==2, return min
+// - if N>2, toss out min and max, return average of rest
+//
+double median_mean_credit(WORKUNIT& /*wu*/, vector<RESULT>& results) {
+    int ilow=-1, ihigh=-1;
+    double credit_low = 0, credit_high = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < CREDIT_EPSILON) continue;
+        if (ilow < 0) {
+            ilow = ihigh = i;
+            credit_low = credit_high = result.claimed_credit;
+        } else {
+            if (result.claimed_credit < credit_low) {
+                ilow = i;
+                credit_low = result.claimed_credit;
+            }
+            if (result.claimed_credit > credit_high) {
+                ihigh = i;
+                credit_high = result.claimed_credit;
+            }
+        }
+        nvalid++;
+    }
+
+    switch(nvalid) {
+    case 0:
+        return CREDIT_EPSILON;
+    case 1:
+    case 2:
+        return credit_low;
+    default:
+        double sum = 0;
+        for (i=0; i<results.size(); i++) {
+            if (i == (unsigned int) ilow) continue;
+            if (i == (unsigned int) ihigh) continue;
+            RESULT& result = results[i];
+            if (result.validate_state != VALIDATE_STATE_VALID) continue;
+
+            sum += result.claimed_credit;
+        }
+        return sum/(nvalid-2);
+    }
+}
+
+int get_credit_from_wu(WORKUNIT& wu, vector<RESULT>&, double& credit) {
+    double x;
+    int retval;
+    DB_WORKUNIT dbwu;
+
+    dbwu.id = wu.id;
+    retval = dbwu.get_field_str("xml_doc", dbwu.xml_doc, sizeof(dbwu.xml_doc));
+    if (!retval) {
+        if (parse_double(dbwu.xml_doc, "<credit>", x)) {
+            credit = x;
+            return 0;
+        }
+    }
+    return ERR_XML_PARSE;
+}
+
+// This function should be called from the validator whenever credit
+// is granted to a host.  It's purpose is to track the average credit
+// per cpu time for that host.
+//
+// It updates an exponentially-decaying estimate of credit_per_cpu_sec
+// Note that this does NOT decay with time, but instead decays with
+// total credits earned.  If a host stops earning credits, then this
+// quantity stops decaying.  So credit_per_cpu_sec must NOT be
+// periodically decayed using the update_stats utility or similar
+// methods.
+//
+// The intended purpose is for cross-project credit comparisons on
+// BOINC statistics pages, for hosts attached to multiple machines.
+// One day people will write PhD theses on how to normalize credit
+// values to equalize them across projects.  I hope this will be done
+// according to "Allen's principle": "Credits granted by a project
+// should be normalized so that, averaged across all hosts attached to
+// multiple projects, projects grant equal credit per cpu second."
+// This principle ensures that (on average) participants will choose
+// projects based on merit, not based on credits.  It also ensures
+// that (on average) host machines migrate to the projects for which
+// they are best suited.
+//
+// For cross-project comparison the value of credit_per_cpu_sec should
+// be exported in the statistics file host_id.gz, which is written by
+// the code in db_dump.C.
+//
+// Algorithm: credits_per_cpu_second should be updated each time that
+// a host is granted credit, according to:
+//
+//     CREDIT_AVERAGE_CONST = 500           [see Note 5]
+//     MAX_CREDIT_PER_CPU_SEC = 0.1         [see Note 6]
+//
+//     e = tanh(granted_credit/CREDIT_AVERAGE_CONST)
+//     if (e < 0) then e = 0
+//     if (e > 1) then e = 1
+//     if (credit_per_cpu_sec <= 0) then e = 1
+//     if (cpu_time <= 0) then e = 0        [see Note 4]
+//     if (granted_credit <= 0) then e = 0  [see Note 3]
+//
+//     rate = granted_credit/cpu_time
+//     if (rate < 0) rate = 0
+//     if (rate > MAX_CREDIT_PER_CPU_SEC) rate = MAX_CREDIT_PER_CPU_SEC
+//
+//     credit_per_cpu_sec = e * rate + (1 - e) * credit_per_cpu_sec
+
+// Note 0: all quantities above should be treated as real numbers
+// Note 1: cpu_time is measured in seconds
+// Note 2: When a host is created, the initial value of
+//         credit_per_cpu_sec, should be zero.
+// Note 3: If a host has done invalid work (granted_credit==0) we have
+//         chosen not to include it.  One might argue that the
+//         boundary case granted_credit==0 should be treated the same
+//         as granted_credit>0.  However the goal here is not to
+//         identify cpus whose host machines sometimes produce
+//         rubbish.  It is to get a measure of how effectively the cpu
+//         runs the application code.
+// Note 4: e==0 means 'DO NOT include the first term on the rhs of the
+//         equation defining credit_per_cpu_sec' which is equivalent
+//         to 'DO NOT update credit_per_cpu_sec'.
+// Note 5: CREDIT_AVERAGE_CONST determines the exponential decay
+//         credit used in averaging credit_per_cpu_sec.  It may be
+//         changed at any time, even if the project database has
+//         already been populated with non-zero values of
+//         credit_per_cpu_sec.
+// Note 6: Typical VERY FAST cpus have credit_per_cpu_sec of around
+//         0.02.  This is a safety mechanism designed to prevent
+//         trouble if a client or host has reported absurd values (due
+//         to a bug in client or server software or by cheating).  In
+//         five years when cpus are five time faster, please increase
+//         the value of R.  You may also want to increase the value of
+//         CREDIT_AVERAGE_CONST.
+//
+//         Nonzero return value: host exceeded the max allowed
+//         credit/cpu_sec.
+//
+int update_credit_per_cpu_sec(
+    double  granted_credit,     // credit granted for this work
+    double  cpu_time,           // cpu time (seconds) used for this work
+    double& credit_per_cpu_sec  // (average) credit per cpu second
+) {
+    int retval = 0;
+
+    // Either of these values may be freely changed in the future.
+    // When CPUs get much faster one must increase the 'sanity-check'
+    // value of max_credit_per_cpu_sec.  At that time it would also
+    // make sense to proportionally increase the credit_average_const.
+    //
+    const double credit_average_const = 500;
+    const double max_credit_per_cpu_sec = 0.07;
+
+    double e = tanh(granted_credit/credit_average_const);
+    if (e <= 0.0 || cpu_time == 0.0 || granted_credit == 0.0) return retval;
+    if (e > 1.0 || credit_per_cpu_sec == 0.0) e = 1.0;
+
+    double rate =  granted_credit/cpu_time;
+    if (rate < 0.0) rate = 0.0;
+    if (rate > max_credit_per_cpu_sec) {
+        rate = max_credit_per_cpu_sec;
+        retval = 1;
+    }
+
+    credit_per_cpu_sec = e * rate + (1.0 - e) * credit_per_cpu_sec;
+
+    return retval;
+}
+
+double stddev_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    double credit_low_bound = 0, credit_high_bound = 0;
+    double penalize_credit_high_bound = 0;
+    double credit_avg = 0;
+    double credit = 0;
+    double old = 0;
+    double std_dev = 0;
+    int nvalid = 0;
+    unsigned int i;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    nvalid = 0;
+    //calculate stddev difference
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        std_dev = pow(credit_avg - result.claimed_credit,2) + std_dev;
+        nvalid++;
+    }
+
+    std_dev = std_dev/ (double) nvalid;
+    std_dev = sqrt(std_dev);
+
+    credit_low_bound = credit_avg-std_dev;
+    if (credit_low_bound > credit_avg*.85) {
+        credit_low_bound = credit_avg*.85;
+    }
+    credit_low_bound = credit_low_bound - 2.5;
+    if (credit_low_bound < 1) credit_low_bound = 1;
+
+    credit_high_bound = credit_avg+std_dev;
+    if (credit_high_bound < credit_avg*1.15) {
+        credit_high_bound = credit_avg*1.15;
+    }
+    credit_high_bound = credit_high_bound + 5;
+
+
+    nvalid=0;
+    credit = 0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit < credit_high_bound && result.claimed_credit > credit_low_bound) {
+            credit = credit + result.claimed_credit;
+            nvalid++;
+        } else {
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_SD Discarding invalid credit %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit,
+                credit_avg, credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    double grant_credit;
+    switch(nvalid) {
+    case 0:
+        grant_credit = median_mean_credit(wu, results);
+        old = grant_credit;
+        break;
+    default:
+        grant_credit = credit/nvalid;
+        old = median_mean_credit(wu, results);
+    }
+
+    // Log what happened
+    if (old > grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Less awarded\n",
+            grant_credit, old
+        );
+    } else if (old == grant_credit) {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  Same awarded\n",
+            grant_credit, old
+        );
+    } else {
+        log_messages.printf(MSG_DEBUG,
+            "CREDIT_CALC_VAL New Method grant: %.1lf  Old Method grant: %.1lf  More awarded\n",
+            grant_credit, old
+        );
+    }
+
+    // penalize hosts that are claiming too much
+    penalize_credit_high_bound = grant_credit+1.5*std_dev;
+    if (penalize_credit_high_bound < grant_credit*1.65) {
+        penalize_credit_high_bound = grant_credit*1.65;
+    }
+    penalize_credit_high_bound = penalize_credit_high_bound + 20;
+
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.claimed_credit > penalize_credit_high_bound) {
+            result.granted_credit = grant_credit * 0.5;
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] CREDIT_CALC_PENALTY Penalizing host for too high credit %.1lf, grant %.1lf, penalize %.1lf, stddev %.1lf, avg %.1lf, low %.1lf, high %.1lf \n",
+                result.id, result.name, result.claimed_credit, grant_credit,
+                penalize_credit_high_bound, std_dev, credit_avg,
+                credit_low_bound, credit_high_bound
+            );
+        }
+    }
+
+    return grant_credit;
+}
+
+double two_credit(WORKUNIT& wu, std::vector<RESULT>& results) {
+    unsigned int i;
+    double credit = 0;
+    double credit_avg = 0;
+    double last_credit = 0;
+    int nvalid = 0;
+    double grant_credit;
+
+    //calculate average
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        credit = credit + result.claimed_credit;
+        last_credit = result.claimed_credit;
+        nvalid++;
+    }
+
+    if (nvalid == 0) {
+        return CREDIT_EPSILON;
+    }
+
+    credit_avg = credit/nvalid;
+
+    // If more then 2 valid results, compute via stddev method
+    if (nvalid > 2) return stddev_credit(wu, results);
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Only 2 results \n",wu.id, wu.name
+    );
+
+    // If only 2, then check to see if range is reasonable
+    if (fabs(last_credit - credit_avg) < 0.15*credit_avg) return credit_avg;
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Average is more than 15 percent from each value \n",
+        wu.id, wu.name
+    );
+
+    // log data on large variance in runtime
+    float cpu_time = 0.0;
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        if (result.cpu_time < 30) continue;
+        if (cpu_time == 0) {
+            cpu_time = result.cpu_time*1.0;
+        } else {
+            if (cpu_time/result.cpu_time > 2 || cpu_time/result.cpu_time < 0.5) {
+                log_messages.printf(MSG_DEBUG,
+                    "[WORKUNIT#%d %s] Large difference in runtime \n",
+                    wu.id, wu.name
+                );
+            }
+        }
+    }
+
+
+    //find result with smallest deviation from historical credit and award that value
+    DB_HOST host;
+    double deviation = -1;
+    grant_credit = credit_avg; // default award in case nobody matches the cases
+    for (i=0; i<results.size(); i++) {
+        RESULT& result = results[i];
+        if (result.validate_state != VALIDATE_STATE_VALID) continue;
+        host.lookup_id(result.hostid);
+        log_messages.printf(MSG_DEBUG,
+            "[RESULT#%d %s] Claimed Credit = %.2lf  Historical Credit = %.2lf \n",
+            result.id, result.name, result.claimed_credit,
+            result.cpu_time*host.credit_per_cpu_sec
+        );
+        if ((deviation < 0 || deviation > fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec)) && result.cpu_time > 30) {
+            deviation = fabs(result.claimed_credit - result.cpu_time*host.credit_per_cpu_sec);
+            log_messages.printf(MSG_NORMAL,
+                "[RESULT#%d %s] Credit deviation = %.2lf \n",
+                result.id, result.name, deviation
+            );
+            grant_credit = result.claimed_credit;
+        }
+    }
+    log_messages.printf(MSG_DEBUG,
+        "[WORKUNIT#%d %s] Credit granted = %.2lf \n",
+        wu.id, wu.name, grant_credit
+    );
+    return grant_credit;
+}
+
+const char *BOINC_RCSID_07049e8a0e = "$Id: validate_util.cpp 16069 2008-09-26 18:20:24Z davea $";
diff --git a/BOINC software/BOINC server apps/index_calculator_workgenerator/Makefile b/BOINC software/BOINC server apps/index_calculator_workgenerator/Makefile
new file mode 100644 (file)
index 0000000..8c74501
--- /dev/null
@@ -0,0 +1,46 @@
+# This should work on Linux.  Modify as needed for other platforms.
+
+BOINC_DIR = /home/frt/server_stable
+BOINC_API_DIR = $(BOINC_DIR)/api
+BOINC_LIB_DIR = $(BOINC_DIR)/lib
+BOINC_SCHED_DIR = $(BOINC_DIR)/sched
+BOINC_DB_DIR = $(BOINC_DIR)/db
+BOINC_TOOLS_DIR = $(BOINC_DIR)/tools
+MYSQL_DIR = /usr/local/include/mysql
+MYSQL_LIB_DIR = /usr/local/lib/mysql
+CXXFLAGS = -g \
+    -DAPP_GRAPHICS \
+    -I$(BOINC_DIR) \
+    -I$(BOINC_LIB_DIR) \
+    -I$(BOINC_API_DIR) \
+    -I$(BOINC_SCHED_DIR) \
+    -I$(BOINC_DB_DIR) \
+    -I$(MYSQL_DIR) \
+    -I$(BOINC_TOOLS_DIR) \
+    -L$(MYSQL_LIB_DIR) \
+    -L$(BOINC_API_DIR) \
+    -L$(BOINC_LIB_DIR) \
+    -L$(BOINC_SCHED_DIR) \
+    -L/usr/X11R6/lib \
+    -L/usr/local/lib/mysql \
+    -L.
+
+# the following should be freeglut; use nm to check
+# you may have to change the paths for your system
+
+PROGS = distrrtgen \
+
+all: $(PROGS)
+
+libstdc++.a:
+       ln -s `g++ -print-file-name=libstdc++.a`
+
+clean:
+       /bin/rm -f $(PROGS) distrrtgen_validator *.o
+
+distclean:
+       /bin/rm -f $(PROGS) *.o libstdc++.a
+
+
+distrrtgen: index_calculator_workgenerator.o libstdc++.a $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_SCHED_DIR)/libsched.a 
+       $(CXX) index_calculator_workgenerator.cpp $(CXXFLAGS) -o index_calculator_workgenerator libstdc++.a -pthread -lboinc_api -lsched -lboinc -lmysqlclient -lssl -O3 
diff --git a/BOINC software/BOINC server apps/index_calculator_workgenerator/index_calculator_workgenerator.cpp b/BOINC software/BOINC server apps/index_calculator_workgenerator/index_calculator_workgenerator.cpp
new file mode 100644 (file)
index 0000000..b8d4b33
--- /dev/null
@@ -0,0 +1,215 @@
+// This file is part of BOINC.
+// http://boinc.berkeley.edu
+// Copyright (C) 2008 University of California
+//
+// BOINC is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation,
+// either version 3 of the License, or (at your option) any later version.
+//
+// BOINC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
+
+// sample_work_generator.C: an example BOINC work generator.
+// This work generator has the following properties
+// (you may need to change some or all of these):
+//
+// - Runs as a daemon, and creates an unbounded supply of work.
+//   It attempts to maintain a "cushion" of 100 unsent job instances.
+//   (your app may not work this way; e.g. you might create work in batches)
+// - Creates work for the application "uppercase".
+// - Creates a new input file for each job;
+//   the file (and the workunit names) contain a timestamp
+//   and sequence number, so that they're unique.
+
+#include <unistd.h>
+#include <cstdlib>
+#include <string>
+#include <cstring>
+
+#include "boinc_db.h"
+#include "error_numbers.h"
+#include "backend_lib.h"
+#include "parse.h"
+#include "util.h"
+
+#include "sched_config.h"
+#include "sched_util.h"
+#include "sched_msgs.h"
+
+#define CUSHION 100
+#define int64 long long
+    // maintain at least this many unsent results
+#define REPLICATION_FACTOR 2
+// globals
+//
+char* wu_template;
+DB_APP app;
+DB_CONN *frt;
+int start_time;
+int seqno;
+
+using namespace std;
+// create one new job
+//
+int make_job() { 
+    DB_WORKUNIT wu;
+    MYSQL_RES* resp;    
+    MYSQL_ROW row;
+    char name[256], path[256], query[1024];
+    const char* infiles[1];
+    int retval;
+    string charset;
+//    frt->do_query("SELECT lookupid, hashroutine, charset, minletters, maxletters, `index`, chainlength, hash WHERE inuse = 0 LIMIT 1;");
+    sprintf(query, "SELECT rcl.lookupid, rchl.hashroutine, rcts.charset, rcts.minletters, rcts.maxletters, rct.`index`, rcts.chainlength, rchl.hash FROM rainbowcrack_cracker_lookups rcl INNER JOIN rainbowcrack_cracker_hashlist rchl ON rchl.hashid = rcl.hashid INNER JOIN rainbowcrack_cracker_tables rct ON rcl.tableid = rct.tableid INNER JOIN rainbowcrack_cracker_tablesets rcts ON rcts.tablesetid = rct.tablesetid INNER JOIN rainbowcrack_cracker_requests rcr ON rcr.hashid = rcl.hashid WHERE rchl.password IS NULL AND hasindices = 0 AND rchl.hashid  = 139192 LIMIT 1");
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval) {
+       log_messages.printf(MSG_DEBUG, "Query returned %i\n", retval);  
+       return retval;
+
+    }
+    resp = mysql_store_result(frt->mysql);
+    if (!resp) return ERR_DB_NOT_FOUND;
+    row = mysql_fetch_row(resp);
+    mysql_free_result(resp);
+    if (!row) return ERR_DB_NOT_FOUND;
+       
+               /*
+    sprintf(query, "UPDATE rainbowcrack_cracker_lookupqueue SET inuse = 1 WHERE lookupid = %s", row[0]);
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval)  return retval; 
+*/
+    sprintf(query, "UPDATE rainbowcrack_cracker_lookups SET hasindices = 1 WHERE lookupid = %s", row[0]);
+    log_messages.printf(MSG_DEBUG, "%s\n", query);
+    retval = frt->do_query(query);
+    if(retval)  return retval;
+
+    char command_line[256];
+    char filename[256];
+    sprintf(command_line, "%s %s %s %s %s %s %s", row[1], row[2], row[3], row[4], row[5], row[6], row[7]);
+
+    // make a unique name (for the job and its input file)
+    //
+    sprintf(name, "%s %s_%s#%s-%s_%s_%s", row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
+//    sprintf(filename, "%s.txt", row[0]);
+    log_messages.printf(MSG_DEBUG, "%s\n", name); 
+    
+    read_file_malloc("../templates/index_calculator_input_template.xml", wu_template);
+    // Fill in the job parameters
+    //
+    wu.clear();
+    wu.appid = app.id;
+    strcpy(wu.name, name);
+    wu.rsc_fpops_est = 1e12;
+    wu.rsc_fpops_bound = 1e14;
+    wu.rsc_memory_bound = 1e8;
+    wu.rsc_disk_bound = 1e8;
+    wu.delay_bound = 86400;
+    wu.min_quorum = 2;
+    wu.target_nresults = 2;
+    wu.max_error_results = 8;
+    wu.max_total_results = 10;
+    wu.max_success_results = 2;
+    // Register the job with BOINC
+    //
+    return create_work(
+        wu,
+        wu_template,
+        "templates/output_template.xml",
+        "../templates/output_template.xml",
+        NULL,
+        0,
+        config,
+       command_line
+    );
+}
+
+void main_loop() {
+    int retval;
+
+    while (1) {
+        check_stop_daemons();
+        int n;
+        retval = count_unsent_results(n, 0);
+        if (n > CUSHION) {
+            sleep(60);
+        } else {
+            int njobs = (CUSHION-n)/REPLICATION_FACTOR;
+            log_messages.printf(MSG_DEBUG,
+                "Making %d jobs\n", njobs
+            );
+            for (int i=0; i<njobs; i++) {
+                retval = make_job();
+                if (retval) {
+                    log_messages.printf(MSG_CRITICAL,
+                        "can't make job: %d\n", retval
+                    );
+                    exit(retval);
+                }
+            }
+            // Now sleep for a few seconds to let the transitioner
+            // create instances for the jobs we just created.
+            // Otherwise we could end up creating an excess of jobs.
+            sleep(5);
+        }
+    }
+}
+
+int main(int argc, char** argv) {
+    int i, retval;
+    frt = new DB_CONN();
+
+    for (i=1; i<argc; i++) {
+        if (!strcmp(argv[i], "-d")) {
+            log_messages.set_debug_level(atoi(argv[++i]));
+        } else {
+            log_messages.printf(MSG_CRITICAL,
+                "bad cmdline arg: %s", argv[i]
+            );
+        }
+    }
+
+    if (config.parse_file("..")) {
+        log_messages.printf(MSG_CRITICAL,
+            "can't read config file\n"
+        );
+        exit(1);
+    }
+    retval = frt->open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
+        exit(1);
+    }
+
+    retval = boinc_db.open(
+        config.db_name, config.db_host, config.db_user, config.db_passwd
+    );
+    if (retval) {
+        log_messages.printf(MSG_CRITICAL, "can't open db\n");
+        exit(1);
+    }
+    if (app.lookup("where name='index_calculator'")) {
+        log_messages.printf(MSG_CRITICAL, "can't find app\n");
+        exit(1);
+    }
+    if (read_file_malloc("../templates/index_calculator_input_template.xml", wu_template)) {
+        log_messages.printf(MSG_CRITICAL, "can't read WU template\n");
+        exit(1);
+    }
+
+    start_time = time(0);
+    seqno = 0;
+
+    log_messages.printf(MSG_NORMAL, "Starting\n");
+
+    main_loop();
+}
+
diff --git a/Client Applications/converti2/Debug/BuildLog.htm b/Client Applications/converti2/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..0e2d879
Binary files /dev/null and b/Client Applications/converti2/Debug/BuildLog.htm differ
diff --git a/Client Applications/converti2/Debug/MemoryPool.obj b/Client Applications/converti2/Debug/MemoryPool.obj
new file mode 100644 (file)
index 0000000..f7e00c5
Binary files /dev/null and b/Client Applications/converti2/Debug/MemoryPool.obj differ
diff --git a/Client Applications/converti2/Debug/Public.obj b/Client Applications/converti2/Debug/Public.obj
new file mode 100644 (file)
index 0000000..5b5c1bf
Binary files /dev/null and b/Client Applications/converti2/Debug/Public.obj differ
diff --git a/Client Applications/converti2/Debug/converti2.exe b/Client Applications/converti2/Debug/converti2.exe
new file mode 100644 (file)
index 0000000..69874fc
Binary files /dev/null and b/Client Applications/converti2/Debug/converti2.exe differ
diff --git a/Client Applications/converti2/Debug/converti2.exe.embed.manifest b/Client Applications/converti2/Debug/converti2.exe.embed.manifest
new file mode 100644 (file)
index 0000000..fac40ba
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
\ No newline at end of file
diff --git a/Client Applications/converti2/Debug/converti2.exe.embed.manifest.res b/Client Applications/converti2/Debug/converti2.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..9e54244
Binary files /dev/null and b/Client Applications/converti2/Debug/converti2.exe.embed.manifest.res differ
diff --git a/Client Applications/converti2/Debug/converti2.exe.intermediate.manifest b/Client Applications/converti2/Debug/converti2.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..3351598
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Client Applications/converti2/Debug/converti2.ilk b/Client Applications/converti2/Debug/converti2.ilk
new file mode 100644 (file)
index 0000000..2f85267
Binary files /dev/null and b/Client Applications/converti2/Debug/converti2.ilk differ
diff --git a/Client Applications/converti2/Debug/converti2.obj b/Client Applications/converti2/Debug/converti2.obj
new file mode 100644 (file)
index 0000000..622632f
Binary files /dev/null and b/Client Applications/converti2/Debug/converti2.obj differ
diff --git a/Client Applications/converti2/Debug/converti2.pdb b/Client Applications/converti2/Debug/converti2.pdb
new file mode 100644 (file)
index 0000000..e21b2ca
Binary files /dev/null and b/Client Applications/converti2/Debug/converti2.pdb differ
diff --git a/Client Applications/converti2/Debug/convertrti2.exe b/Client Applications/converti2/Debug/convertrti2.exe
new file mode 100644 (file)
index 0000000..e1e8f52
Binary files /dev/null and b/Client Applications/converti2/Debug/convertrti2.exe differ
diff --git a/Client Applications/converti2/Debug/convertrti2.exe.embed.manifest b/Client Applications/converti2/Debug/convertrti2.exe.embed.manifest
new file mode 100644 (file)
index 0000000..fac40ba
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
\ No newline at end of file
diff --git a/Client Applications/converti2/Debug/convertrti2.exe.embed.manifest.res b/Client Applications/converti2/Debug/convertrti2.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..9e54244
Binary files /dev/null and b/Client Applications/converti2/Debug/convertrti2.exe.embed.manifest.res differ
diff --git a/Client Applications/converti2/Debug/convertrti2.exe.intermediate.manifest b/Client Applications/converti2/Debug/convertrti2.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..3351598
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Client Applications/converti2/Debug/convertrti2.ilk b/Client Applications/converti2/Debug/convertrti2.ilk
new file mode 100644 (file)
index 0000000..3faf6b8
Binary files /dev/null and b/Client Applications/converti2/Debug/convertrti2.ilk differ
diff --git a/Client Applications/converti2/Debug/convertrti2.pdb b/Client Applications/converti2/Debug/convertrti2.pdb
new file mode 100644 (file)
index 0000000..be644e9
Binary files /dev/null and b/Client Applications/converti2/Debug/convertrti2.pdb differ
diff --git a/Client Applications/converti2/Debug/mt.dep b/Client Applications/converti2/Debug/mt.dep
new file mode 100644 (file)
index 0000000..6c8d293
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 10:24:22,83 on 05-03-2009 
diff --git a/Client Applications/converti2/Debug/vc90.idb b/Client Applications/converti2/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..87b39f5
Binary files /dev/null and b/Client Applications/converti2/Debug/vc90.idb differ
diff --git a/Client Applications/converti2/Debug/vc90.pdb b/Client Applications/converti2/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..b5c8b51
Binary files /dev/null and b/Client Applications/converti2/Debug/vc90.pdb differ
diff --git a/Client Applications/converti2/Public.cpp b/Client Applications/converti2/Public.cpp
new file mode 100644 (file)
index 0000000..e279c56
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#ifdef _WIN32
+
+#else
+#include <cstdio>
+#include <cctype>
+#include <ctime>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+#include <unistd.h>
+
+#endif
+
+#include "Public.h"
+
+#ifdef _WIN32
+       #include <windows.h>
+#else
+       #include <sys/sysinfo.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+unsigned int GetFileLen(FILE* file)
+{
+       unsigned int pos = ftell(file);
+       fseek(file, 0, SEEK_END);
+       unsigned int len = ftell(file);
+       fseek(file, pos, SEEK_SET);
+
+       return len;
+}
+
+string TrimString(string s)
+{
+       while (s.size() > 0)
+       {
+               if (s[0] == ' ' || s[0] == '\t')
+                       s = s.substr(1);
+               else
+                       break;
+       }
+
+       while (s.size() > 0)
+       {
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+                       s = s.substr(0, s.size() - 1);
+               else
+                       break;
+       }
+
+       return s;
+}
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+       // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+       if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+               return false;
+       size_t nEnd = sCharset.rfind(')');
+       size_t nStart = sCharset.rfind('(');
+       string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+       vector<string> vParts;
+       SeperateString(sChar, ",", vParts);
+       for(int i = 0; i < vParts.size(); i++)
+       {
+               tCharset stCharset;
+               vector<string> vParts2;
+               SeperateString(vParts[i], "#", vParts2);
+               stCharset.sName = vParts2[0];
+               vector<string> vParts3;
+               SeperateString(vParts2[1], "-", vParts3);
+               stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+               stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+               vCharset.push_back(stCharset);
+       }
+       return true;
+}
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+    FILE *file = fopen(sPathName.c_str(), "rb");
+       if (file != NULL)
+       {
+               unsigned int len = GetFileLen(file);
+               char* data = new char[len + 1];
+               fread(data, 1, len, file);
+               data[len] = '\0';
+               string content = data;
+               content += "\n";
+               delete data;
+
+               unsigned int i;
+               for (i = 0; i < content.size(); i++)
+               {
+                       if (content[i] == '\r')
+                               content[i] = '\n';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       string line = content.substr(0, n);
+                       line = TrimString(line);
+                       if (line != "")
+                               vLine.push_back(line);
+                       content = content.substr(n + 1);
+               }
+
+               fclose(file);
+       }
+       else
+               return false;
+
+       return true;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+       vPart.clear();
+
+       unsigned int i;
+       for (i = 0; i < sSeperator.size(); i++)
+       {
+               int n = s.find(sSeperator[i]);
+               if (n != -1)
+               {
+                       vPart.push_back(s.substr(0, n));
+                       s = s.substr(n + 1);
+               }
+               else
+                       return false;
+       }
+       vPart.push_back(s);
+
+       return true;
+}
+
+string uint64tostr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%I64u", n);
+#else
+       sprintf(str, "%llu", n);
+#endif
+
+       return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%016I64x", n);
+#else
+       sprintf(str, "%016llx", n);
+#endif
+
+       return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+       string sRet;
+       int i;
+       for (i = 0; i < nLen; i++)
+       {
+               char szByte[3];
+               sprintf(szByte, "%02x", pData[i]);
+               sRet += szByte;
+       }
+
+       return sRet;
+}
+
+unsigned int GetAvailPhysMemorySize()
+{
+#ifdef _WIN32
+               MEMORYSTATUS ms;
+               GlobalMemoryStatus(&ms);
+               return ms.dwAvailPhys;
+#else
+       struct sysinfo info;
+       sysinfo(&info);                 // This function is Linux-specific
+       return info.freeram;
+#endif
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < sHash.size() / 2; i++)
+       {
+               string sSub = sHash.substr(i * 2, 2);
+               int nValue;
+               sscanf(sSub.c_str(), "%02x", &nValue);
+               pHash[i] = (unsigned char)nValue;
+       }
+
+       nHashLen = sHash.size() / 2;
+}
+
+void Logo()
+{
+       printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+       printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+       printf("http://www.freerainbowtables.com/\n");
+       printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+       printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
diff --git a/Client Applications/converti2/Public.h b/Client Applications/converti2/Public.h
new file mode 100644 (file)
index 0000000..a2f5657
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _PUBLIC_H
+#define _PUBLIC_H
+
+#include <stdio.h>
+
+#include <string>
+#include <vector>
+#include <list>
+using namespace std;
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 u_int64_t
+#endif
+
+struct RainbowChain
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+};
+
+struct RainbowChainCP
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+       unsigned short nCheckPoint;
+};
+struct IndexChain
+{
+       uint64 nPrefix;
+       int nFirstChain;
+       unsigned int nChainCount;
+};
+struct FoundRainbowChain
+{
+       uint64 nIndexS;
+       int nIndexE;
+       int nCheckPoint;
+       int nGuessedPos;
+};
+struct ChainCheckChain
+{
+       uint64 nIndexS;
+       int nGuessedPos;
+};
+struct IndexRow
+{
+       uint64 prefix;
+       unsigned int prefixstart, numchains;
+};
+
+typedef struct
+{
+       string sName;
+       int nPlainLenMin;
+       int nPlainLenMax;
+} tCharset;
+
+#define MAX_PLAIN_LEN 256
+#define MIN_HASH_LEN  8
+#define MAX_HASH_LEN  256
+#define MAX_SALT_LEN  256
+
+unsigned int GetFileLen(FILE* file);
+string TrimString(string s);
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine);
+bool SeperateString(string s, string sSeperator, vector<string>& vPart);
+string uint64tostr(uint64 n);
+string uint64tohexstr(uint64 n);
+string HexToStr(const unsigned char* pData, int nLen);
+unsigned int GetAvailPhysMemorySize();
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen);
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset);
+void Logo();
+
+#endif
diff --git a/Client Applications/converti2/Release/BuildLog.htm b/Client Applications/converti2/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..06bf49e
Binary files /dev/null and b/Client Applications/converti2/Release/BuildLog.htm differ
diff --git a/Client Applications/converti2/Release/MemoryPool.obj b/Client Applications/converti2/Release/MemoryPool.obj
new file mode 100644 (file)
index 0000000..ff5ae87
Binary files /dev/null and b/Client Applications/converti2/Release/MemoryPool.obj differ
diff --git a/Client Applications/converti2/Release/Public.obj b/Client Applications/converti2/Release/Public.obj
new file mode 100644 (file)
index 0000000..1b42328
Binary files /dev/null and b/Client Applications/converti2/Release/Public.obj differ
diff --git a/Client Applications/converti2/Release/converti2.exe b/Client Applications/converti2/Release/converti2.exe
new file mode 100644 (file)
index 0000000..6a06def
Binary files /dev/null and b/Client Applications/converti2/Release/converti2.exe differ
diff --git a/Client Applications/converti2/Release/converti2.exe.intermediate.manifest b/Client Applications/converti2/Release/converti2.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/Client Applications/converti2/Release/converti2.obj b/Client Applications/converti2/Release/converti2.obj
new file mode 100644 (file)
index 0000000..406d6bd
Binary files /dev/null and b/Client Applications/converti2/Release/converti2.obj differ
diff --git a/Client Applications/converti2/Release/converti2.pdb b/Client Applications/converti2/Release/converti2.pdb
new file mode 100644 (file)
index 0000000..2353378
Binary files /dev/null and b/Client Applications/converti2/Release/converti2.pdb differ
diff --git a/Client Applications/converti2/Release/convertrti2.exe b/Client Applications/converti2/Release/convertrti2.exe
new file mode 100644 (file)
index 0000000..5f7e9e5
Binary files /dev/null and b/Client Applications/converti2/Release/convertrti2.exe differ
diff --git a/Client Applications/converti2/Release/convertrti2.exe.intermediate.manifest b/Client Applications/converti2/Release/convertrti2.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/Client Applications/converti2/Release/convertrti2.pdb b/Client Applications/converti2/Release/convertrti2.pdb
new file mode 100644 (file)
index 0000000..285c147
Binary files /dev/null and b/Client Applications/converti2/Release/convertrti2.pdb differ
diff --git a/Client Applications/converti2/Release/mt.dep b/Client Applications/converti2/Release/mt.dep
new file mode 100644 (file)
index 0000000..b300065
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 11:00:17,04 on 04-03-2009 
diff --git a/Client Applications/converti2/Release/vc90.idb b/Client Applications/converti2/Release/vc90.idb
new file mode 100644 (file)
index 0000000..4f0c5e6
Binary files /dev/null and b/Client Applications/converti2/Release/vc90.idb differ
diff --git a/Client Applications/converti2/Release/vc90.pdb b/Client Applications/converti2/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..08e439b
Binary files /dev/null and b/Client Applications/converti2/Release/vc90.pdb differ
diff --git a/Client Applications/converti2/converti2.cpp b/Client Applications/converti2/converti2.cpp
new file mode 100644 (file)
index 0000000..dec2b64
--- /dev/null
@@ -0,0 +1,624 @@
+#include <string>
+#include <vector>
+#ifdef _WIN32
+#include <io.h>
+#else
+       #include <sys/types.h>
+       #include <sys/stat.h>
+       #include <unistd.h>
+#endif
+
+#include <time.h>
+#include <math.h>
+#include <vector>
+#include "Public.h"
+#include "MemoryPool.h"
+using namespace std;
+
+void Usage()
+{
+       printf("converti2 - Original to Indexed rainbow table converter\n");
+       printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+       printf("http://www.freerainbowtables.com\n\n");
+
+       printf("usage: converti2 rainbow_table_pathname\n");
+       printf("rainbow_table_pathname: pathname of the rainbow table(s), wildchar(*, ?) supported\n");
+       printf("\n");
+       printf("example: converti2 *.rt\n");
+       printf("         converti2 md5_*.rt\n");
+}
+
+
+int GetMaxBits(uint64 highvalue)
+{
+       if(highvalue < 0x02)
+               return 1;
+       if(highvalue < 0x04)
+               return 2;
+       if(highvalue < 0x08)
+               return 3;
+       if(highvalue < 0x10)
+               return 4;
+       if(highvalue < 0x20)
+               return 5;
+       if(highvalue < 0x40)
+               return 6;
+       if(highvalue < 0x80)
+               return 7;
+       if(highvalue < 0x100)
+               return 8;
+       if(highvalue < 0x200)
+               return 9;
+       if(highvalue < 0x400)
+               return 10;
+       if(highvalue < 0x800)
+               return 11;
+       if(highvalue < 0x1000)
+               return 12;
+       if(highvalue < 0x2000)
+               return 13;
+       if(highvalue < 0x4000)
+               return 14;
+       if(highvalue < 0x8000)
+               return 15;
+       if(highvalue < 0x10000)
+               return 16;
+       if(highvalue < 0x20000)
+               return 17;
+       if(highvalue < 0x40000)
+               return 18;
+       if(highvalue < 0x80000)
+               return 19;
+       if(highvalue < 0x100000)
+               return 20;
+       if(highvalue < 0x200000)
+               return 21;
+       if(highvalue < 0x400000)
+               return 22;
+       if(highvalue < 0x800000)
+               return 23;
+       if(highvalue < 0x1000000)
+               return 24;
+       if(highvalue < 0x2000000)
+               return 25;
+       if(highvalue < 0x4000000)
+               return 26;
+       if(highvalue < 0x8000000)
+               return 27;
+       if(highvalue < 0x10000000)
+               return 28;
+       if(highvalue < 0x20000000)
+               return 29;
+       if(highvalue < 0x40000000)
+               return 30;
+       if(highvalue < 0x80000000)
+               return 31;
+#ifdef WIN32
+       if(highvalue < 0x0000000100000000I64)
+               return 32;
+       if(highvalue < 0x0000000200000000I64)
+               return 33;
+       if(highvalue < 0x0000000400000000I64)
+               return 34;
+       if(highvalue < 0x0000000800000000I64)
+               return 35;
+       if(highvalue < 0x0000001000000000I64)
+               return 36;
+       if(highvalue < 0x0000002000000000I64)
+               return 37;
+       if(highvalue < 0x0000004000000000I64)
+               return 38;
+       if(highvalue < 0x0000008000000000I64)
+               return 39;
+       if(highvalue < 0x0000010000000000I64)
+               return 40;
+       if(highvalue < 0x0000020000000000I64)
+               return 41;
+       if(highvalue < 0x0000040000000000I64)
+               return 42;
+       if(highvalue < 0x0000080000000000I64)
+               return 43;
+       if(highvalue < 0x0000100000000000I64)
+               return 44;
+       if(highvalue < 0x0000200000000000I64)
+               return 45;
+       if(highvalue < 0x0000400000000000I64)
+               return 46;
+       if(highvalue < 0x0000800000000000I64)
+               return 47;
+       if(highvalue < 0x0001000000000000I64)
+               return 48;
+       if(highvalue < 0x0002000000000000I64)
+               return 49;
+       if(highvalue < 0x0004000000000000I64)
+               return 50;
+       if(highvalue < 0x0008000000000000I64)
+               return 51;
+       if(highvalue < 0x0010000000000000I64)
+               return 52;
+       if(highvalue < 0x0020000000000000I64)
+               return 53;
+       if(highvalue < 0x0040000000000000I64)
+               return 54;
+       if(highvalue < 0x0080000000000000I64)
+               return 55;
+       if(highvalue < 0x0100000000000000I64)
+               return 56;
+       if(highvalue < 0x0200000000000000I64)
+               return 57;
+       if(highvalue < 0x0400000000000000I64)
+               return 58;
+       if(highvalue < 0x0800000000000000I64)
+               return 59;
+       if(highvalue < 0x1000000000000000I64)
+               return 60;
+       if(highvalue < 0x2000000000000000I64)
+               return 61;
+       if(highvalue < 0x4000000000000000I64)
+               return 62;
+       if(highvalue < 0x8000000000000000I64)
+               return 63;
+#else
+       if(highvalue < 0x0000000100000000LL)
+               return 32;
+       if(highvalue < 0x0000000200000000LL)
+               return 33;
+       if(highvalue < 0x0000000400000000LL)
+               return 34;
+       if(highvalue < 0x0000000800000000LL)
+               return 35;
+       if(highvalue < 0x0000001000000000LL)
+               return 36;
+       if(highvalue < 0x0000002000000000LL)
+               return 37;
+       if(highvalue < 0x0000004000000000LL)
+               return 38;
+       if(highvalue < 0x0000008000000000LL)
+               return 39;
+       if(highvalue < 0x0000010000000000LL)
+               return 40;
+       if(highvalue < 0x0000020000000000LL)
+               return 41;
+       if(highvalue < 0x0000040000000000LL)
+               return 42;
+       if(highvalue < 0x0000080000000000LL)
+               return 43;
+       if(highvalue < 0x0000100000000000LL)
+               return 44;
+       if(highvalue < 0x0000200000000000LL)
+               return 45;
+       if(highvalue < 0x0000400000000000LL)
+               return 46;
+       if(highvalue < 0x0000800000000000LL)
+               return 47;
+       if(highvalue < 0x0001000000000000LL)
+               return 48;
+       if(highvalue < 0x0002000000000000LL)
+               return 49;
+       if(highvalue < 0x0004000000000000LL)
+               return 50;
+       if(highvalue < 0x0008000000000000LL)
+               return 51;
+       if(highvalue < 0x0010000000000000LL)
+               return 52;
+       if(highvalue < 0x0020000000000000LL)
+               return 53;
+       if(highvalue < 0x0040000000000000LL)
+               return 54;
+       if(highvalue < 0x0080000000000000LL)
+               return 55;
+       if(highvalue < 0x0100000000000000LL)
+               return 56;
+       if(highvalue < 0x0200000000000000LL)
+               return 57;
+       if(highvalue < 0x0400000000000000LL)
+               return 58;
+       if(highvalue < 0x0800000000000000LL)
+               return 59;
+       if(highvalue < 0x1000000000000000LL)
+               return 60;
+       if(highvalue < 0x2000000000000000LL)
+               return 61;
+       if(highvalue < 0x4000000000000000LL)
+               return 62;
+       if(highvalue < 0x8000000000000000LL)
+               return 63;
+
+#endif
+       return 64;
+
+}
+
+#ifdef _WIN32
+void GetTableList(string sWildCharPathName, vector<string>& vPathName)
+{
+       vPathName.clear();
+
+       string sPath;
+       int n = sWildCharPathName.find_last_of('\\');
+       if (n != -1)
+               sPath = sWildCharPathName.substr(0, n + 1);
+
+       _finddata_t fd;
+       long handle = _findfirst(sWildCharPathName.c_str(), &fd);
+       if (handle != -1)
+       {
+               do
+               {
+                       string sName = fd.name;
+                       if (sName != "." && sName != ".." && !(fd.attrib & _A_SUBDIR))
+                       {
+                               string sPathName = sPath + sName;
+                               vPathName.push_back(sPathName);
+                       }
+               } while (_findnext(handle, &fd) == 0);
+
+               _findclose(handle);
+       }
+}
+#else
+void GetTableList(int argc, char* argv[], vector<string>& vPathName)
+{
+       vPathName.clear();
+
+       int i;
+       for (i = 1; i < argc; i++)
+       {
+               string sPathName = argv[i];
+               struct stat buf;
+               if (lstat(sPathName.c_str(), &buf) == 0)
+               {
+                       if (S_ISREG(buf.st_mode))
+                               vPathName.push_back(sPathName);
+
+               }
+       }
+}
+#endif
+
+
+void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int rti_startptlength, unsigned int rti_endptlength, int showDistribution, int hascp, int rti_cplength, vector<unsigned int> rti_cppos)
+{
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       string sFileName;
+       if (nIndex != -1)
+               sFileName = sPathName.substr(nIndex + 1);
+       else
+               sFileName = sPathName;
+       // Info
+       printf("%s:\n", sFileName.c_str());
+       FILE* file = fopen(sPathName.c_str(), "rb");
+       FILE* fileR = fopen(sResultFileName.c_str(), "wb");
+       unsigned int distribution[64] = {0};
+       unsigned int numProcessedChains = 0;
+       
+       if (file != NULL && fileR != NULL)
+       {
+               // File length check
+               unsigned int nFileLen = GetFileLen(file);
+               unsigned int nTotalChainCount = 0;
+               if(hascp == 0) nTotalChainCount = nFileLen / 16;
+               else nTotalChainCount = nFileLen / 18;
+               if ((hascp == 0 && nFileLen % 16 != 0) || (hascp == 1 && nFileLen % 18 != 0))
+               {
+                       printf("file length mismatch\n");
+               }
+               else
+               {
+                       static CMemoryPool mp;
+                       unsigned int nAllocatedSize;
+                       RainbowChainCP* pChain = (RainbowChainCP*)mp.Allocate(nFileLen, nAllocatedSize);
+                       
+                       unsigned int chainrowsize = ceil((float)(rti_startptlength + rti_endptlength + rti_cplength) / 8) * 8 ; // The size in bits (in whole bytes)
+                       unsigned int chainrowsizebytes = chainrowsize / 8;
+
+
+                       if (pChain != NULL)
+                       {
+                               nAllocatedSize = nAllocatedSize / sizeof(RainbowChainCP) * sizeof(RainbowChainCP);
+                               fseek(file, 0, SEEK_SET);
+                               uint64 curPrefix = 0, prefixStart = 0;
+                               vector<IndexRow> indexes;
+                               int nRainbowChainCountRead = 0;
+                               while (true)    // Chunk read loop
+                               {
+/*                                     if (ftell(file) == nFileLen)
+                                               break;*/
+                                       int nReadThisRound;
+                                       memset(pChain, 0x00, nAllocatedSize);
+                                       printf("reading...\n");
+                                       clock_t t1 = clock();
+                                       for(nReadThisRound = 0; nReadThisRound < nAllocatedSize / sizeof(RainbowChainCP) && nRainbowChainCountRead < nTotalChainCount; nReadThisRound++)
+                                       {                                               
+                                               if(fread(&pChain[nReadThisRound], 16, 1, file) != 1) 
+                                               { 
+                                                       printf("Error reading file\n"); exit(1);
+                                               }
+                                               if(hascp == 1)
+                                               {
+                                                       if(fread(&pChain[nReadThisRound].nCheckPoint, 2, 1, file) != 1) 
+                                                       { 
+                                                               printf("Error reading file\n"); exit(2);
+                                                       }
+                                               }
+                                               nRainbowChainCountRead++;
+                                       }
+                                       clock_t t2 = clock();
+                                       float fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+                                       int nDataRead = nRainbowChainCountRead * 16;
+                                       if(hascp == 1) nDataRead += nRainbowChainCountRead * 2; // Add the index readings too
+                                       printf("%u bytes read, disk access time: %.2f s\n", nDataRead , fTime);
+                                       t1 = clock();
+
+                                       for(int i = 0; i < nReadThisRound; i++)
+                                       {
+                                               if(showDistribution == 1)
+                                               {
+                                                       distribution[GetMaxBits(pChain[i].nIndexS)-1]++;
+                                               }
+                                               else
+                                               {
+                                                       uint64 chainrow = pChain[i].nIndexS; // Insert the complete start point                                                          
+                                                       chainrow |= ((uint64)pChain[i].nIndexE & (0xffffffff >> (32 - rti_endptlength))) << rti_startptlength; // 
+                                                       if(hascp == 1 && rti_cplength > 0) 
+                                                       {
+                                                               chainrow |= (uint64)pChain[i].nCheckPoint << rti_startptlength + rti_endptlength;
+                                                       }
+                                                       fwrite(&chainrow, 1, chainrowsizebytes, fileR);                 
+                                                       uint64 prefix = pChain[i].nIndexE >> rti_endptlength;
+                                                       if(i == 0) curPrefix = prefix;
+                                                       if(prefix != curPrefix && numProcessedChains - prefixStart > 0)
+                                                       {
+                                                                       if(prefix < curPrefix)
+                                                                       {
+                                                                               printf("**** Error writeChain(): Prefix is smaller than previous prefix. %llu < %llu****\n", prefix, curPrefix);
+                                                                               exit(1);                                                                        
+                                                                       }
+                                                                       //unsigned char index[11] = {0}; // [0 - 10]
+                                                                       unsigned int numchains = numProcessedChains - prefixStart;
+                                                                       IndexRow index;
+                                                                       index.prefix = curPrefix;
+//                                                                             index.prefixstart = prefixStart;
+                                                                       index.numchains = numchains;
+                                                                       indexes.push_back(index);
+                                                                       prefixStart = numProcessedChains;
+                                                                       curPrefix = prefix; 
+                                                       }
+                                               }
+                                               numProcessedChains++;
+                                       }               
+                                       t2 = clock();
+                                       fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+                                       printf("conversion time: %.2f s\n", fTime);             
+                                       if(nRainbowChainCountRead == nTotalChainCount)
+                                               break;
+                                       if(showDistribution == 1)
+                                       {
+                                               for(int i = 0; i < 64; i++)
+                                               {
+                                                       printf("%u - %u\n", (i+1), distribution[i]);
+                                               }
+                                               return;
+                                       }
+
+                               }
+       
+               
+       
+                               // We need to write the last index down
+                               IndexRow index;
+                               index.prefix = curPrefix;
+                               index.prefixstart = prefixStart;
+                               index.numchains = numProcessedChains - prefixStart;
+                               indexes.push_back(index);
+
+                               IndexRow high = {0}; // Used to find the highest numbers. This tells us how much we can pack the index bits
+                               for(int i = 0; i < indexes.size(); i++)
+                               {
+                                       if(indexes[i].numchains > high.numchains)
+                                               high.numchains = indexes[i].numchains;
+/*                                             if(indexes[i].prefixstart > high.prefixstart)
+                                               high.prefixstart = indexes[i].prefixstart;
+                                       if(indexes[i].prefix > high.prefix)
+                                               high.prefix = indexes[i].prefix;
+*/
+                               }
+                               high.prefix = indexes[indexes.size()-1].prefix; // The last prefix is always the highest prefix
+//                                     unsigned int m_rti_index_prefixlength = GetMaxBits(high.prefix);
+                               unsigned int m_rti_index_numchainslength = GetMaxBits(high.numchains);
+//                                     unsigned int m_rti_index_indexlength = GetMaxBits(high.prefixstart);
+                               unsigned int m_indexrowsize = ceil((float)(/*m_rti_index_indexlength + */m_rti_index_numchainslength) / 8) * 8; // The size in bits (in whole bytes)    
+                               unsigned int m_indexrowsizebytes = m_indexrowsize / 8;
+                               FILE *pFileIndex = fopen(sResultFileName.append(".index").c_str(), "wb");
+                               fwrite("RTI2", 1, 4, pFileIndex);
+                               fwrite(&rti_startptlength, 1, 1, pFileIndex);
+                               fwrite(&rti_endptlength, 1, 1, pFileIndex);
+                               fwrite(&rti_cplength, 1, 1, pFileIndex);
+//                                     fwrite(&m_rti_index_indexlength , 1, 1, pFileIndex);
+                               fwrite(&m_rti_index_numchainslength, 1, 1, pFileIndex);
+                               for(int i = 0; i < rti_cppos.size(); i++)
+                               {
+                                       fwrite(&rti_cppos[i], 1, 4, pFileIndex); // The position of the checkpoints
+                               }
+//                                     fwrite(&m_rti_index_prefixlength, 1, 1, pFileIndex);
+                               int zero = 0;
+                               fwrite(&indexes[0].prefix, 1, 8, pFileIndex); // Write the first prefix
+                               unsigned int lastPrefix = 0;
+                               for(int i = 0; i < indexes.size(); i++)
+                               {
+                                       if(i == 0)
+                                               lastPrefix = indexes[0].prefix;
+                                       unsigned int indexrow = 0;
+                                       // Checks how big a distance there is between the current and the next prefix. eg cur is 3 and next is 10 = 7.
+                                       unsigned int diffSize = indexes[i].prefix - lastPrefix; 
+                                       if(i > 0 && diffSize > 1)
+                                       {
+                                               //indexrow |= indexes[i].prefixstart;
+                                               //printf("Diffsize is %u\n", diffSize);
+
+                                               // then write the distance amount of 00's
+                                               for(int j = 1; j < diffSize; j++)
+                                               {                                                               
+                                                       fwrite(&zero, 1, m_indexrowsizebytes, pFileIndex);
+                                               }
+                                       }                                       
+                                       fwrite(&indexes[i].numchains, 1, m_indexrowsizebytes, pFileIndex);
+                                       lastPrefix = indexes[i].prefix;
+                               }
+                               fclose(pFileIndex);
+                       }
+                       else printf("memory allocation fail\n");
+
+                       
+                                       // Already finished?
+
+               }
+               fclose(file);
+       }
+       else
+               printf("can't open file\n");
+
+}
+
+int main(int argc, char* argv[])
+{
+       int argi = 1, i, argsUsed = 0;
+       unsigned int sptl = 40, eptl = 16;
+       int showDistribution = 0;
+       int usecp = 0;// How many bits to use from the index
+       int hascp = 0; 
+       vector<unsigned int> cppositions;
+       if (argc == 1)
+       {
+               Usage();                
+               return 0;
+       }
+       else if(argc > 2)
+       {
+               for (; argi < argc; argi++)
+               {
+                       if (strcmp(argv[argi], "-d") == 0 && (argsUsed & 0x8) == 0)
+                       {
+                               // Enable verbose mode
+                               argsUsed |= 0x8;                                
+                               showDistribution = 1;
+                       }                       
+                       else if (strncmp(argv[argi], "-sptl=", 6) == 0 && (argsUsed & 0x1) == 0)
+                       {
+                               // Maximum index for starting point
+                               argsUsed |= 0x1;
+                               sptl = 0;
+                               for (i = 6; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       sptl *= 10;
+                                       sptl += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       Usage();
+                                       return 1;
+                               }
+                               if (i > 23) // i - 3 > 20
+                               {
+                                       printf("Error: Number is too large.\n\n");
+                                       Usage();
+                                       return 1;
+                               }                       
+                       }
+
+                       else if (strncmp(argv[argi], "-eptl=", 6) == 0 && (argsUsed & 0x2) == 0)
+                       {
+                               // Maximum index for ending points
+                               argsUsed |= 0x2;
+                               eptl = 0;
+                               for (i = 6; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       eptl *= 10;
+                                       eptl += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       Usage();
+                                       return 1;
+                               }
+                               if (i > 23) // i - 3 > 20
+                               {
+                                       printf("Error: Number is too large.\n\n");
+                                       Usage();
+                                       return 1;
+                               }                       
+                       }
+                       else if(strncmp(argv[argi], "-usecp=", 7) == 0 && (argsUsed & 0x4) == 0)
+                       {
+                               argsUsed |= 0x4;
+                               hascp = 1;
+                               usecp = 0;
+                               unsigned int cppos = 0;
+                               for(i = 7; argv[argi][i] != ' ' && argv[argi][i] != '\n' && argv[argi][i] != 0;)
+                               {
+                                       if(cppositions.size() > 0) i++;
+                                       for (; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                                       {
+                                               cppos *= 10;
+                                               cppos += ((int) argv[argi][i]) - 0x30;
+                                       }
+/*                                     if(argv[argi][i] == ',')
+                                       {*/
+                                               cppositions.push_back(cppos);
+                                               usecp++;
+                                               cppos = 0;
+                                       //}
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       Usage();
+                                       return 1;
+                               }
+                               if (usecp > 16) // i - 3 > 20
+                               {
+                                       printf("Error: Number is too large.\n\n");
+                                       Usage();
+                                       return 1;
+                               }                               
+                               else printf("Using %i bits of the checkpoints\n", usecp);
+                       }
+
+               }               
+       }
+       vector<string> vPathName;
+#ifdef WIN32
+       string sWildCharPathName = argv[1];
+       GetTableList(sWildCharPathName, vPathName);
+#else
+       GetTableList(argc, argv, vPathName);
+#endif
+       if (vPathName.size() == 0)
+       {
+               printf("no rainbow table found\n");
+               return 0;
+       }
+       for (int i = 0; i < vPathName.size(); i++)
+       {
+               string sResultFile;
+               int n = vPathName[i].find_last_of('\\');
+               if (n != -1)
+                       sResultFile = vPathName[i].substr(n+1, vPathName[i].length()) + "i2";
+               else 
+                       sResultFile = vPathName[i] + "i2"; // Resulting file is .rt, not .rti
+               printf("Using %i of 64 bits\n", (sptl + eptl + usecp));
+               if(sptl + eptl + usecp > 64)
+               {
+                       exit(1);
+               }
+               ConvertRainbowTable(vPathName[i], sResultFile, sptl, eptl, showDistribution, hascp, usecp, cppositions);
+               printf("\n");
+       }
+       return 0;
+}
\ No newline at end of file
diff --git a/Client Applications/converti2/converti2.ncb b/Client Applications/converti2/converti2.ncb
new file mode 100644 (file)
index 0000000..12f4890
Binary files /dev/null and b/Client Applications/converti2/converti2.ncb differ
diff --git a/Client Applications/converti2/converti2.sln b/Client Applications/converti2/converti2.sln
new file mode 100644 (file)
index 0000000..ec9020e
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "convertrti2", "converti2.vcproj", "{066FD6F1-5990-47AD-B095-7AE0029CF5AE}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Debug|Win32.ActiveCfg = Debug|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Debug|Win32.Build.0 = Debug|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Release|Win32.ActiveCfg = Release|Win32
+               {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/Client Applications/converti2/converti2.suo b/Client Applications/converti2/converti2.suo
new file mode 100644 (file)
index 0000000..84a0d09
Binary files /dev/null and b/Client Applications/converti2/converti2.suo differ
diff --git a/Client Applications/converti2/converti2.vcproj b/Client Applications/converti2/converti2.vcproj
new file mode 100644 (file)
index 0000000..dbbdaf0
--- /dev/null
@@ -0,0 +1,211 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="converti2"
+       ProjectGUID="{066FD6F1-5990-47AD-B095-7AE0029CF5AE}"
+       RootNamespace="convertrti2"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="131072"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="../../rt api"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="2"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               EnableIntrinsicFunctions="true"
+                               AdditionalIncludeDirectories="../../rt api"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="0"
+                               EnableFunctionLevelLinking="true"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath=".\converti2.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\MemoryPool.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\Public.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\MemoryPool.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\Public.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/Client Applications/converti2/converti2.vcproj.W-L-10643.Administrator.user b/Client Applications/converti2/converti2.vcproj.W-L-10643.Administrator.user
new file mode 100644 (file)
index 0000000..8fc4d7f
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory="C:\Documents and Settings\Administrator\Desktop\FreeRainbowTables.com\BOINC apps\standalone\converti2\tables"
+                               CommandArguments="-d *.rt"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-10643"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-10643"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/converti2/converti2.vcproj.W-L-MWJ.Administrator.user b/Client Applications/converti2/converti2.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..32e4dde
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="*.rt -sptl=42 -eptl=14"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/converti2/converti2.vcproj.mwj-PC.mwj.user b/Client Applications/converti2/converti2.vcproj.mwj-PC.mwj.user
new file mode 100644 (file)
index 0000000..7c3f11c
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="tables\21_67108864_125.rt -usecp=17500,17800,18100,18400,18700,19000,19300,19600"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/converti2/makefile b/Client Applications/converti2/makefile
new file mode 100644 (file)
index 0000000..52bd857
--- /dev/null
@@ -0,0 +1,7 @@
+all: main
+
+main: 
+       g++ Public.cpp MemoryPool.cpp converti2.cpp -O3 -o converti2
+clean:
+       -rm *.o
+
diff --git a/Client Applications/converti2/md5_loweralpha-numeric-space#1-8_0_10000x67108864_distrrtgen[p][i]_00.rti2 b/Client Applications/converti2/md5_loweralpha-numeric-space#1-8_0_10000x67108864_distrrtgen[p][i]_00.rti2
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Client Applications/rcracki/CrackEngine.cpp b/Client Applications/rcracki/CrackEngine.cpp
new file mode 100644 (file)
index 0000000..23bb838
--- /dev/null
@@ -0,0 +1,394 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "CrackEngine.h"
+#include "BaseRTReader.h"
+#include "RTReader.h"
+#include "RTIReader.h"
+#include "RTI2Reader.h"
+#include <time.h>
+
+CCrackEngine::CCrackEngine()
+{
+       ResetStatistics();
+}
+
+CCrackEngine::~CCrackEngine()
+{
+}
+
+//////////////////////////////////////////////////////////////////////
+
+void CCrackEngine::ResetStatistics()
+{
+       m_fTotalDiskAccessTime               = 0.0f;
+       m_fTotalCryptanalysisTime            = 0.0f;
+       m_nTotalChainWalkStep                = 0;
+       m_nTotalFalseAlarm                   = 0;
+       m_nTotalChainWalkStepDueToFalseAlarm = 0;
+//     m_nTotalFalseAlarmSkipped                        = 0;
+}
+
+int CCrackEngine::BinarySearch(RainbowChainCP* pChain, int nRainbowChainCount, uint64 nIndex)
+{
+       int nLow = 0;
+       int nHigh = nRainbowChainCount - 1;
+       while (nLow <= nHigh)
+       {
+               int nMid = (nLow + nHigh) / 2;
+               if (nIndex == pChain[nMid].nIndexE)
+                       return nMid;
+               else if (nIndex < pChain[nMid].nIndexE)
+                       nHigh = nMid - 1;
+               else
+                       nLow = nMid + 1;
+       }
+
+       return -1;
+}
+bool CCrackEngine::CheckAlarm(RainbowChainCP* pChain, int nGuessedPos, unsigned char* pHash, CHashSet& hs)
+{
+       CChainWalkContext cwc;
+       cwc.SetIndex(pChain->nIndexS);
+//     printf("Checking alarm for %ui64\n", pChain->nIndexS);
+       int nPos, i = 0;
+       if(m_pHeader != NULL)
+       {
+               int nNextPos = m_pHeader->m_cppos[i];
+               for (nPos = 0; nPos < nGuessedPos; nPos++)
+               {
+                       cwc.IndexToPlain();
+                       cwc.PlainToHash();
+                       cwc.HashToIndex(nPos);
+                       if(nPos == nNextPos) // Check if we reached the next checkpoint position
+                       {
+                               if(i <= m_pHeader->rti_cplength) 
+                                       nNextPos = m_pHeader->m_cppos[++i];
+                               if((cwc.GetIndex() & 0x00000001) != (pChain->nCheckPoint & (1 << 15 - m_pHeader->rti_cplength - i) >> 15 - m_pHeader->rti_cplength - i))
+                               {
+//                                     m_nTotalFalseAlarmSkipped += 10000 - 5000;
+                                       printf("CheckPoint caught false alarm at position %i\n", nPos);
+                                       return false;
+                               }                               
+                       }
+               }
+       }
+       else
+       {
+               for (nPos = 0; nPos < nGuessedPos; nPos++)
+               {
+                       cwc.IndexToPlain();
+                       cwc.PlainToHash();
+                       cwc.HashToIndex(nPos);
+               }
+       }
+       cwc.IndexToPlain();
+       cwc.PlainToHash();
+
+       if (cwc.CheckHash(pHash))
+       {
+               printf("plaintext of %s is %s\n", cwc.GetHash().c_str(), cwc.GetPlain().c_str());
+               hs.SetPlain(cwc.GetHash(), cwc.GetPlain(), cwc.GetBinary());
+               return true;
+       }
+
+       return false;
+}
+
+
+void CCrackEngine::GetChainIndexRangeWithSameEndpoint(RainbowChainCP* pChain,
+                                                                                                         int nRainbowChainCount,
+                                                                                                         int nMatchingIndexE,
+                                                                                                         int& nMatchingIndexEFrom,
+                                                                                                         int& nMatchingIndexETo)
+{
+       nMatchingIndexEFrom = nMatchingIndexE;
+       nMatchingIndexETo   = nMatchingIndexE;
+       while (nMatchingIndexEFrom > 0)
+       {
+               if (pChain[nMatchingIndexEFrom - 1].nIndexE == pChain[nMatchingIndexE].nIndexE)
+                       nMatchingIndexEFrom--;
+               else
+                       break;
+       }
+       while (nMatchingIndexETo < nRainbowChainCount - 1)
+       {
+               if (pChain[nMatchingIndexETo + 1].nIndexE == pChain[nMatchingIndexE].nIndexE)
+                       nMatchingIndexETo++;
+               else
+                       break;
+       }
+}
+
+void CCrackEngine::SearchTableChunk(RainbowChainCP* pChain, int nRainbowChainLen, int nRainbowChainCount, CHashSet& hs)
+{
+       vector<string> vHash;
+       hs.GetLeftHashWithLen(vHash, CChainWalkContext::GetHashLen());
+       printf("searching for %d hash%s...\n", vHash.size(),
+                                                                                  vHash.size() > 1 ? "es" : "");
+
+       int nChainWalkStep = 0;
+       int nFalseAlarm = 0;
+       int nChainWalkStepDueToFalseAlarm = 0;
+
+       int nHashIndex;
+       for (nHashIndex = 0; nHashIndex < vHash.size(); nHashIndex++)
+       {
+               unsigned char TargetHash[MAX_HASH_LEN];
+               int nHashLen;
+               ParseHash(vHash[nHashIndex], TargetHash, nHashLen);
+               if (nHashLen != CChainWalkContext::GetHashLen())
+                       printf("debug: nHashLen mismatch\n");
+
+               // Rqeuest ChainWalk
+               bool fNewlyGenerated;
+               uint64* pStartPosIndexE = m_cws.RequestWalk(TargetHash,
+                                                                                                       nHashLen,
+                                                                                                       CChainWalkContext::GetHashRoutineName(),
+                                                                                                       CChainWalkContext::GetPlainCharsetName(),
+                                                                                                       CChainWalkContext::GetPlainLenMin(),
+                                                                                                       CChainWalkContext::GetPlainLenMax(),
+                                                                                                       CChainWalkContext::GetRainbowTableIndex(),
+                                                                                                       nRainbowChainLen,
+                                                                                                       fNewlyGenerated);
+               //printf("debug: using %s walk for %s\n", fNewlyGenerated ? "newly generated" : "existing",
+               //                                                                              vHash[nHashIndex].c_str());
+
+               // Walk
+               int nPos;
+               for (nPos = nRainbowChainLen - 2; nPos >= 0; nPos--)
+               {
+                       if (fNewlyGenerated)
+                       {
+                               CChainWalkContext cwc;
+                               cwc.SetHash(TargetHash);
+                               cwc.HashToIndex(nPos);
+                               int i;
+                               for (i = nPos + 1; i <= nRainbowChainLen - 2; i++)
+                               {
+                                       cwc.IndexToPlain();
+                                       cwc.PlainToHash();
+                                       cwc.HashToIndex(i);
+                               }
+
+                               pStartPosIndexE[nPos] = cwc.GetIndex();
+                               nChainWalkStep += nRainbowChainLen - 2 - nPos;
+                       }
+                       uint64 nIndexEOfCurPos = pStartPosIndexE[nPos];
+
+                       // Search matching nIndexE
+                       int nMatchingIndexE = BinarySearch(pChain, nRainbowChainCount, nIndexEOfCurPos);
+                       if (nMatchingIndexE != -1)
+                       {
+                               int nMatchingIndexEFrom, nMatchingIndexETo;
+                               GetChainIndexRangeWithSameEndpoint(pChain, nRainbowChainCount,
+                                                                                                  nMatchingIndexE,
+                                                                                                  nMatchingIndexEFrom, nMatchingIndexETo);
+                               int i;
+                               for (i = nMatchingIndexEFrom; i <= nMatchingIndexETo; i++)
+                               {
+                                       if (CheckAlarm(pChain + i, nPos, TargetHash, hs))
+                                       {
+                                               //printf("debug: discarding walk for %s\n", vHash[nHashIndex].c_str());
+                                               m_cws.DiscardWalk(pStartPosIndexE);
+                                               goto NEXT_HASH;
+                                       }
+                                       else
+                                       {
+                                               nChainWalkStepDueToFalseAlarm += nPos + 1;
+                                               nFalseAlarm++;
+                                       }
+                               }
+                       }
+               }
+NEXT_HASH:;
+       }
+
+       //printf("debug: chain walk step: %d\n", nChainWalkStep);
+       //printf("debug: false alarm: %d\n", nFalseAlarm);
+       //printf("debug: chain walk step due to false alarm: %d\n", nChainWalkStepDueToFalseAlarm);
+
+       m_nTotalChainWalkStep += nChainWalkStep;
+       m_nTotalFalseAlarm += nFalseAlarm;
+       m_nTotalChainWalkStepDueToFalseAlarm += nChainWalkStepDueToFalseAlarm;
+}
+
+void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
+{
+       // FileName
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       string sFileName;
+       if (nIndex != -1)
+               sFileName = sPathName.substr(nIndex + 1);
+       else
+               sFileName = sPathName;
+
+       // Info
+       printf("%s:\n", sFileName.c_str());
+
+       // Setup
+       int nRainbowChainLen, nRainbowChainCount;
+       if (!CChainWalkContext::SetupWithPathName(sPathName, nRainbowChainLen, nRainbowChainCount))
+               return;
+       //printf("keyspace: %u\n", CChainWalkContext::GetPlainSpaceTotal());
+       // Already finished?
+       if (!hs.AnyHashLeftWithLen(CChainWalkContext::GetHashLen()))
+       {
+               printf("this table contains hashes with length %d only\n", CChainWalkContext::GetHashLen());
+               return;
+       }
+       BaseRTReader *reader = NULL;
+       if(sFileName.substr(sFileName.length() - 4, sFileName.length()) == "rti2")
+       {
+               reader = (BaseRTReader*)new RTI2Reader(sPathName);
+               m_pHeader = ((RTI2Reader*)reader)->GetHeader();
+               m_TableType = RTI2;
+       }
+       else if(sFileName.substr(sFileName.length() - 3, sFileName.length()) == "rti")
+       {
+               reader = (BaseRTReader*)new RTIReader(sPathName);               
+               m_TableType = RTI;
+       }
+       else if(sFileName.substr(sFileName.length() - 2, sFileName.length()) == "rt")
+       {
+               reader = (BaseRTReader*)new RTReader(sPathName);
+               m_TableType = RT;
+       }
+       else 
+       {
+               printf("Invalid rainbow table type");
+               return;
+       }
+       static CMemoryPool mp;
+       unsigned int nAllocatedSize;
+       int chainsleft = reader->GetChainsLeft();
+       RainbowChainCP* pChain = (RainbowChainCP*)mp.Allocate(chainsleft * sizeof(RainbowChainCP), nAllocatedSize);
+       nAllocatedSize = nAllocatedSize / sizeof(RainbowChainCP) * sizeof(RainbowChainCP);              // Round to boundary
+       unsigned int nChains = nAllocatedSize / sizeof(RainbowChainCP);
+       bool fVerified = false;
+       while (reader->GetChainsLeft() > 0)     // Chunk read loop
+       {
+               clock_t t1 = clock();
+               reader->ReadChains(nChains, pChain);
+               clock_t t2 = clock();
+               float fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+               printf("%u chains read, disk access time: %.2f s\n", nChains, fTime);
+               m_fTotalDiskAccessTime += fTime;
+               int nRainbowChainCountRead = nChains;
+
+               if (!fVerified)
+               {
+                       printf("verifying the file...\n");
+
+                       // Chain length test
+                       int nIndexToVerify = nRainbowChainCountRead / 2;
+                       CChainWalkContext cwc;
+                       cwc.SetIndex(pChain[nIndexToVerify].nIndexS);
+                       int nPos;
+                       for (nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
+                       {
+                               cwc.IndexToPlain();
+                               cwc.PlainToHash();
+                               cwc.HashToIndex(nPos);
+                       }
+                       if (cwc.GetIndex() != pChain[nIndexToVerify].nIndexE)
+                       {
+                               printf("rainbow chain length verify fail\n");
+                               break;
+                       }
+
+                       // Chain sort test
+                       int i;
+                       for (i = 0; i < nRainbowChainCountRead - 1; i++)
+                       {
+                               if (pChain[i].nIndexE > pChain[i + 1].nIndexE)
+                                       break;
+                       }
+                       if (i != nRainbowChainCountRead - 1)
+                       {
+                               printf("this file is not sorted\n");
+                               break;
+                       }
+
+                       fVerified = true;
+
+               }
+               // Search table chunk
+               t1 = clock();
+               SearchTableChunk(pChain, nRainbowChainLen, nRainbowChainCountRead, hs);
+               t2 = clock();
+               fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+               printf("cryptanalysis time: %.2f s\n", fTime);
+               m_fTotalCryptanalysisTime += fTime;
+
+               // Already finished?
+               if (!hs.AnyHashLeftWithLen(CChainWalkContext::GetHashLen()))
+                       break;
+       }
+}
+
+void CCrackEngine::Run(vector<string> vPathName, CHashSet& hs)
+{
+       // Reset statistics
+       ResetStatistics();
+
+       // Sort vPathName (CChainWalkSet need it)
+       int i, j;
+       for (i = 0; i < vPathName.size() - 1; i++)
+               for (j = 0; j < vPathName.size() - i - 1; j++)
+               {
+                       if (vPathName[j] > vPathName[j + 1])
+                       {
+                               string sTemp;
+                               sTemp = vPathName[j];
+                               vPathName[j] = vPathName[j + 1];
+                               vPathName[j + 1] = sTemp;
+                       }
+               }
+
+       // Run
+       for (i = 0; i < vPathName.size() && hs.AnyhashLeft(); i++)
+       {
+               SearchRainbowTable(vPathName[i], hs);
+               printf("\n");
+       }
+}
+
+float CCrackEngine::GetStatTotalDiskAccessTime()
+{
+       return m_fTotalDiskAccessTime;
+}
+/*float CCrackEngine::GetWastedTime()
+{
+       return m_fIndexTime;
+}*/
+float CCrackEngine::GetStatTotalCryptanalysisTime()
+{
+       return m_fTotalCryptanalysisTime;
+}
+
+int CCrackEngine::GetStatTotalChainWalkStep()
+{
+       return m_nTotalChainWalkStep;
+}
+
+int CCrackEngine::GetStatTotalFalseAlarm()
+{
+       return m_nTotalFalseAlarm;
+}
+
+int CCrackEngine::GetStatTotalChainWalkStepDueToFalseAlarm()
+{
+       return m_nTotalChainWalkStepDueToFalseAlarm;
+}
diff --git a/Client Applications/rcracki/CrackEngine.h b/Client Applications/rcracki/CrackEngine.h
new file mode 100644 (file)
index 0000000..210ad87
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CRACKENGINE_H
+#define _CRACKENGINE_H
+
+#include "Public.h"
+#include "HashSet.h"
+#include "ChainWalkContext.h"
+#include "MemoryPool.h"
+#include "ChainWalkSet.h"
+#include "RTI2Reader.h"
+enum RTTYPE { RT, RTI, RTI2 };
+class CCrackEngine
+{
+public:
+       CCrackEngine();
+       virtual ~CCrackEngine();
+
+private:
+       CChainWalkSet m_cws;
+       RTI2Header *m_pHeader;
+       // Statistics
+       float m_fTotalDiskAccessTime;
+       float m_fTotalCryptanalysisTime;
+       int m_nTotalChainWalkStep;
+       int m_nTotalFalseAlarm;
+       int m_nTotalChainWalkStepDueToFalseAlarm;
+       FILE *m_fChains;
+       RTTYPE m_TableType;
+private:
+       void ResetStatistics();
+       int BinarySearch(RainbowChainCP* pChain, int nRainbowChainCount, uint64 nIndex);
+       void SearchTableChunk(RainbowChainCP* pChain, int nRainbowChainLen, int nRainbowChainCount, CHashSet& hs);
+       bool CheckAlarm(RainbowChainCP* pChain, int nGuessedPos, unsigned char* pHash, CHashSet& hs);
+void GetChainIndexRangeWithSameEndpoint(RainbowChainCP* pChain,
+                                                                                                         int nRainbowChainCount,
+                                                                                                         int nMatchingIndexE,
+                                                                                                         int& nMatchingIndexEFrom,
+                                                                                                         int& nMatchingIndexETo);
+public:
+       void SearchRainbowTable(string sPathName, CHashSet& hs);
+       void Run(vector<string> vPathName, CHashSet& hs);
+       float GetStatTotalDiskAccessTime();
+       float GetStatTotalCryptanalysisTime();
+       int   GetStatTotalChainWalkStep();
+       int   GetStatTotalFalseAlarm();
+       int   GetStatTotalChainWalkStepDueToFalseAlarm();
+};
+
+#endif
diff --git a/Client Applications/rcracki/Debug/BaseRTReader.obj b/Client Applications/rcracki/Debug/BaseRTReader.obj
new file mode 100644 (file)
index 0000000..756ffd8
Binary files /dev/null and b/Client Applications/rcracki/Debug/BaseRTReader.obj differ
diff --git a/Client Applications/rcracki/Debug/BuildLog.htm b/Client Applications/rcracki/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..e0ab7ea
Binary files /dev/null and b/Client Applications/rcracki/Debug/BuildLog.htm differ
diff --git a/Client Applications/rcracki/Debug/ChainWalkContext.obj b/Client Applications/rcracki/Debug/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..8ba20b6
Binary files /dev/null and b/Client Applications/rcracki/Debug/ChainWalkContext.obj differ
diff --git a/Client Applications/rcracki/Debug/ChainWalkSet.obj b/Client Applications/rcracki/Debug/ChainWalkSet.obj
new file mode 100644 (file)
index 0000000..bd1b61e
Binary files /dev/null and b/Client Applications/rcracki/Debug/ChainWalkSet.obj differ
diff --git a/Client Applications/rcracki/Debug/CrackEngine.obj b/Client Applications/rcracki/Debug/CrackEngine.obj
new file mode 100644 (file)
index 0000000..182ede4
Binary files /dev/null and b/Client Applications/rcracki/Debug/CrackEngine.obj differ
diff --git a/Client Applications/rcracki/Debug/HashAlgorithm.obj b/Client Applications/rcracki/Debug/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..4a944ab
Binary files /dev/null and b/Client Applications/rcracki/Debug/HashAlgorithm.obj differ
diff --git a/Client Applications/rcracki/Debug/HashRoutine.obj b/Client Applications/rcracki/Debug/HashRoutine.obj
new file mode 100644 (file)
index 0000000..4288b9f
Binary files /dev/null and b/Client Applications/rcracki/Debug/HashRoutine.obj differ
diff --git a/Client Applications/rcracki/Debug/HashSet.obj b/Client Applications/rcracki/Debug/HashSet.obj
new file mode 100644 (file)
index 0000000..e9695e6
Binary files /dev/null and b/Client Applications/rcracki/Debug/HashSet.obj differ
diff --git a/Client Applications/rcracki/Debug/MemoryPool.obj b/Client Applications/rcracki/Debug/MemoryPool.obj
new file mode 100644 (file)
index 0000000..fa50be0
Binary files /dev/null and b/Client Applications/rcracki/Debug/MemoryPool.obj differ
diff --git a/Client Applications/rcracki/Debug/Public.obj b/Client Applications/rcracki/Debug/Public.obj
new file mode 100644 (file)
index 0000000..b1ed326
Binary files /dev/null and b/Client Applications/rcracki/Debug/Public.obj differ
diff --git a/Client Applications/rcracki/Debug/RTI2Reader.obj b/Client Applications/rcracki/Debug/RTI2Reader.obj
new file mode 100644 (file)
index 0000000..4d18114
Binary files /dev/null and b/Client Applications/rcracki/Debug/RTI2Reader.obj differ
diff --git a/Client Applications/rcracki/Debug/RTIReader.obj b/Client Applications/rcracki/Debug/RTIReader.obj
new file mode 100644 (file)
index 0000000..2baad60
Binary files /dev/null and b/Client Applications/rcracki/Debug/RTIReader.obj differ
diff --git a/Client Applications/rcracki/Debug/RTReader.obj b/Client Applications/rcracki/Debug/RTReader.obj
new file mode 100644 (file)
index 0000000..16e84e2
Binary files /dev/null and b/Client Applications/rcracki/Debug/RTReader.obj differ
diff --git a/Client Applications/rcracki/Debug/RainbowCrack.obj b/Client Applications/rcracki/Debug/RainbowCrack.obj
new file mode 100644 (file)
index 0000000..106f540
Binary files /dev/null and b/Client Applications/rcracki/Debug/RainbowCrack.obj differ
diff --git a/Client Applications/rcracki/Debug/des_enc.obj b/Client Applications/rcracki/Debug/des_enc.obj
new file mode 100644 (file)
index 0000000..9d77047
Binary files /dev/null and b/Client Applications/rcracki/Debug/des_enc.obj differ
diff --git a/Client Applications/rcracki/Debug/des_setkey.obj b/Client Applications/rcracki/Debug/des_setkey.obj
new file mode 100644 (file)
index 0000000..87b7e5d
Binary files /dev/null and b/Client Applications/rcracki/Debug/des_setkey.obj differ
diff --git a/Client Applications/rcracki/Debug/ecb_enc.obj b/Client Applications/rcracki/Debug/ecb_enc.obj
new file mode 100644 (file)
index 0000000..ac2a6e6
Binary files /dev/null and b/Client Applications/rcracki/Debug/ecb_enc.obj differ
diff --git a/Client Applications/rcracki/Debug/md4.obj b/Client Applications/rcracki/Debug/md4.obj
new file mode 100644 (file)
index 0000000..8723978
Binary files /dev/null and b/Client Applications/rcracki/Debug/md4.obj differ
diff --git a/Client Applications/rcracki/Debug/md5.obj b/Client Applications/rcracki/Debug/md5.obj
new file mode 100644 (file)
index 0000000..df88fe9
Binary files /dev/null and b/Client Applications/rcracki/Debug/md5.obj differ
diff --git a/Client Applications/rcracki/Debug/mt.dep b/Client Applications/rcracki/Debug/mt.dep
new file mode 100644 (file)
index 0000000..e0f9454
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 18:17:01,15 on 14-03-2009 
diff --git a/Client Applications/rcracki/Debug/rcracki.exe b/Client Applications/rcracki/Debug/rcracki.exe
new file mode 100644 (file)
index 0000000..38a1991
Binary files /dev/null and b/Client Applications/rcracki/Debug/rcracki.exe differ
diff --git a/Client Applications/rcracki/Debug/rcracki.exe.embed.manifest b/Client Applications/rcracki/Debug/rcracki.exe.embed.manifest
new file mode 100644 (file)
index 0000000..fac40ba
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
\ No newline at end of file
diff --git a/Client Applications/rcracki/Debug/rcracki.exe.embed.manifest.res b/Client Applications/rcracki/Debug/rcracki.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..9e54244
Binary files /dev/null and b/Client Applications/rcracki/Debug/rcracki.exe.embed.manifest.res differ
diff --git a/Client Applications/rcracki/Debug/rcracki.exe.intermediate.manifest b/Client Applications/rcracki/Debug/rcracki.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..3351598
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Client Applications/rcracki/Debug/rcracki.exp b/Client Applications/rcracki/Debug/rcracki.exp
new file mode 100644 (file)
index 0000000..412a3d9
Binary files /dev/null and b/Client Applications/rcracki/Debug/rcracki.exp differ
diff --git a/Client Applications/rcracki/Debug/rcracki.ilk b/Client Applications/rcracki/Debug/rcracki.ilk
new file mode 100644 (file)
index 0000000..74cd7fc
Binary files /dev/null and b/Client Applications/rcracki/Debug/rcracki.ilk differ
diff --git a/Client Applications/rcracki/Debug/rcracki.lib b/Client Applications/rcracki/Debug/rcracki.lib
new file mode 100644 (file)
index 0000000..f85d942
Binary files /dev/null and b/Client Applications/rcracki/Debug/rcracki.lib differ
diff --git a/Client Applications/rcracki/Debug/rcracki.pdb b/Client Applications/rcracki/Debug/rcracki.pdb
new file mode 100644 (file)
index 0000000..3cb4d75
Binary files /dev/null and b/Client Applications/rcracki/Debug/rcracki.pdb differ
diff --git a/Client Applications/rcracki/Debug/vc90.idb b/Client Applications/rcracki/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..8b06bb7
Binary files /dev/null and b/Client Applications/rcracki/Debug/vc90.idb differ
diff --git a/Client Applications/rcracki/Debug/vc90.pdb b/Client Applications/rcracki/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..e445bf9
Binary files /dev/null and b/Client Applications/rcracki/Debug/vc90.pdb differ
diff --git a/Client Applications/rcracki/HashSet.cpp b/Client Applications/rcracki/HashSet.cpp
new file mode 100644 (file)
index 0000000..5b15661
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "HashSet.h"
+
+CHashSet::CHashSet()
+{
+}
+
+CHashSet::~CHashSet()
+{
+}
+
+void CHashSet::AddHash(string sHash)
+{
+       if (sHash == "aad3b435b51404ee")
+               return;
+
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vHash[i] == sHash)
+                       return;
+       }
+
+       //printf("debug: adding hash %s\n", sHash.c_str());
+
+       m_vHash.push_back(sHash);
+       m_vFound.push_back(false);
+       m_vPlain.push_back("");
+       m_vBinary.push_back("");
+}
+
+bool CHashSet::AnyhashLeft()
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (!m_vFound[i])
+                       return true;
+       }
+
+       return false;
+}
+
+bool CHashSet::AnyHashLeftWithLen(int nLen)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (!m_vFound[i])
+                       if (m_vHash[i].size() == nLen * 2)
+                               return true;
+       }
+
+       return false;
+}
+
+void CHashSet::GetLeftHashWithLen(vector<string>& vHash, int nLen)
+{
+       vHash.clear();
+
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (!m_vFound[i])
+                       if (m_vHash[i].size() == nLen * 2)
+                               vHash.push_back(m_vHash[i]);
+       }
+}
+
+void CHashSet::SetPlain(string sHash, string sPlain, string sBinary)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vHash[i] == sHash)
+               {
+                       m_vFound[i]    = true;
+                       m_vPlain[i]    = sPlain;
+                       m_vBinary[i]   = sBinary;
+                       return;
+               }
+       }
+}
+
+bool CHashSet::GetPlain(string sHash, string& sPlain, string& sBinary)
+{
+       if (sHash == "aad3b435b51404ee")
+       {
+               sPlain  = "";
+               sBinary = "";
+               return true;
+       }
+
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vHash[i] == sHash)
+               {
+                       if (m_vFound[i])
+                       {
+                               sPlain  = m_vPlain[i];
+                               sBinary = m_vBinary[i];
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
+int CHashSet::GetStatHashFound()
+{
+       int nHashFound = 0;
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vFound[i])
+                       nHashFound++;
+       }
+
+       return nHashFound;
+}
+
+int CHashSet::GetStatHashTotal()
+{
+       return m_vHash.size();
+}
diff --git a/Client Applications/rcracki/HashSet.h b/Client Applications/rcracki/HashSet.h
new file mode 100644 (file)
index 0000000..38b5f42
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHSET_H
+#define _HASHSET_H
+
+#include "Public.h"
+
+class CHashSet
+{
+public:
+       CHashSet();
+       virtual ~CHashSet();
+
+private:
+       vector<string> m_vHash;
+       vector<bool>   m_vFound;
+       vector<string> m_vPlain;
+       vector<string> m_vBinary;
+
+public:
+       void AddHash(string sHash);             // lowercase, len % 2 == 0, MIN_HASH_LEN * 2 <= len <= MAX_HASH_LEN * 2
+       bool AnyhashLeft();
+       bool AnyHashLeftWithLen(int nLen);
+       void GetLeftHashWithLen(vector<string>& vHash, int nLen);
+       
+       void SetPlain(string sHash, string sPlain, string sBinary);
+       bool GetPlain(string sHash, string& sPlain, string& sBinary);
+
+       int GetStatHashFound();
+       int GetStatHashTotal();
+};
+
+#endif
diff --git a/Client Applications/rcracki/RainbowCrack.cpp b/Client Applications/rcracki/RainbowCrack.cpp
new file mode 100644 (file)
index 0000000..a6ec66e
--- /dev/null
@@ -0,0 +1,401 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+
+   Modified by Martin Westergaard Jørgensen <martinwj2005@gmail.com> to support indexed and hybrid tables
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "CrackEngine.h"
+
+#ifdef _WIN32
+       #include <io.h>
+#else
+       #include <sys/types.h>
+       #include <sys/stat.h>
+       #include <unistd.h>
+#endif
+#include "md4.h"
+
+//////////////////////////////////////////////////////////////////////
+
+#ifdef _WIN32
+void GetTableList(string sWildCharPathName, vector<string>& vPathName)
+{
+       vPathName.clear();
+
+       string sPath;
+       int n = sWildCharPathName.find_last_of('\\');
+       if (n != -1)
+               sPath = sWildCharPathName.substr(0, n + 1);
+
+       _finddata_t fd;
+       long handle = _findfirst(sWildCharPathName.c_str(), &fd);
+       if (handle != -1)
+       {
+               do
+               {
+                       string sName = fd.name;
+                       if (sName != "." && sName != ".." && !(fd.attrib & _A_SUBDIR))
+                       {
+                               string sPathName = sPath + sName;
+                               vPathName.push_back(sPathName);
+                       }
+               } while (_findnext(handle, &fd) == 0);
+
+               _findclose(handle);
+       }
+}
+#else
+void GetTableList(int argc, char* argv[], vector<string>& vPathName)
+{
+       vPathName.clear();
+
+       int i;
+       for (i = 1; i <= argc - 3; i++)
+       {
+               string sPathName = argv[i];
+
+               struct stat buf;
+               if (lstat(sPathName.c_str(), &buf) == 0)
+               {
+                       if (S_ISREG(buf.st_mode))
+                               vPathName.push_back(sPathName);
+               }
+       }
+}
+#endif
+
+bool NormalizeHash(string& sHash)
+{
+       string sNormalizedHash = sHash;
+
+       if (   sNormalizedHash.size() % 2 != 0
+               || sNormalizedHash.size() < MIN_HASH_LEN * 2
+               || sNormalizedHash.size() > MAX_HASH_LEN * 2)
+               return false;
+
+       // Make lower
+       int i;
+       for (i = 0; i < sNormalizedHash.size(); i++)
+       {
+               if (sNormalizedHash[i] >= 'A' && sNormalizedHash[i] <= 'F')
+                       sNormalizedHash[i] = sNormalizedHash[i] - 'A' + 'a';
+       }
+
+       // Character check
+       for (i = 0; i < sNormalizedHash.size(); i++)
+       {
+               if (   (sNormalizedHash[i] < 'a' || sNormalizedHash[i] > 'f')
+                       && (sNormalizedHash[i] < '0' || sNormalizedHash[i] > '9'))
+                       return false;
+       }
+
+       sHash = sNormalizedHash;
+       return true;
+}
+
+void LoadLMHashFromPwdumpFile(string sPathName, vector<string>& vUserName, vector<string>& vLMHash, vector<string>& vNTLMHash)
+{
+       vector<string> vLine;
+       if (ReadLinesFromFile(sPathName, vLine))
+       {
+               int i;
+               for (i = 0; i < vLine.size(); i++)
+               {
+                       vector<string> vPart;
+                       if (SeperateString(vLine[i], "::::", vPart))
+                       {
+                               string sUserName = vPart[0];
+                               string sLMHash   = vPart[2];
+                               string sNTLMHash = vPart[3];
+
+                               if (sLMHash.size() == 32 && sNTLMHash.size() == 32)
+                               {
+                                       if (NormalizeHash(sLMHash) && NormalizeHash(sNTLMHash))
+                                       {
+                                               vUserName.push_back(sUserName);
+                                               vLMHash.push_back(sLMHash);
+                                               vNTLMHash.push_back(sNTLMHash);
+                                       }
+                                       else
+                                               printf("invalid lm/ntlm hash %s:%s\n", sLMHash.c_str(), sNTLMHash.c_str());
+                               }
+                       }
+               }
+       }
+       else
+               printf("can't open %s\n", sPathName.c_str());
+}
+
+bool NTLMPasswordSeek(unsigned char* pLMPassword, int nLMPasswordLen, int nLMPasswordNext,
+                                         unsigned char* pNTLMHash, string& sNTLMPassword)
+{
+       if (nLMPasswordNext == nLMPasswordLen)
+       {
+               unsigned char md[16];
+               MD4_NEW(pLMPassword, nLMPasswordLen * 2, md);
+               if (memcmp(md, pNTLMHash, 16) == 0)
+               {
+                       sNTLMPassword = "";
+                       int i;
+                       for (i = 0; i < nLMPasswordLen; i++)
+                               sNTLMPassword += char(pLMPassword[i * 2]);
+                       return true;
+               }
+               else
+                       return false;
+       }
+
+       if (NTLMPasswordSeek(pLMPassword, nLMPasswordLen, nLMPasswordNext + 1, pNTLMHash, sNTLMPassword))
+               return true;
+
+       if (   pLMPassword[nLMPasswordNext * 2] >= 'A'
+               && pLMPassword[nLMPasswordNext * 2] <= 'Z')
+       {
+               pLMPassword[nLMPasswordNext * 2] = pLMPassword[nLMPasswordNext * 2] - 'A' + 'a';
+               if (NTLMPasswordSeek(pLMPassword, nLMPasswordLen, nLMPasswordNext + 1, pNTLMHash, sNTLMPassword))
+                       return true;
+               pLMPassword[nLMPasswordNext * 2] = pLMPassword[nLMPasswordNext * 2] - 'a' + 'A';
+       }
+
+       return false;
+}
+
+bool LMPasswordCorrectCase(string sLMPassword,
+                                                  unsigned char* pNTLMHash, string& sNTLMPassword)
+{
+       if (sLMPassword.size() == 0)
+       {
+               sNTLMPassword = "";
+               return true;
+       }
+
+       unsigned char* pLMPassword = new unsigned char[sLMPassword.size() * 2];
+       int i;
+       for (i = 0; i < sLMPassword.size(); i++)
+       {
+               pLMPassword[i * 2    ] = sLMPassword[i];
+               pLMPassword[i * 2 + 1] = 0x00;
+       }
+       bool fRet = NTLMPasswordSeek(pLMPassword, sLMPassword.size(), 0, pNTLMHash, sNTLMPassword);
+       delete pLMPassword;
+
+       return fRet;
+}
+
+void Usage()
+{
+       Logo();
+
+       printf("usage: rcracki rainbow_table_pathname -h hash\n");
+       printf("       rcracki rainbow_table_pathname -l hash_list_file\n");
+       printf("       rcracki rainbow_table_pathname -f pwdump_file\n");
+       printf("rainbow_table_pathname: pathname of the rainbow table(s), wildchar(*, ?) supported\n");
+       printf("-h hash:                use raw hash as input\n");
+       printf("-l hash_list_file:      use hash list file as input, each hash in a line\n");
+       printf("-f pwdump_file:         use pwdump file as input, this will handle lanmanager hash only\n");
+       printf("\n");
+       printf("example: rcracki *.rti -h 5d41402abc4b2a76b9719d911017c592\n");
+       printf("         rcracki *.rti -l hash.txt\n");
+       printf("         rcracki *.rti -f hash.txt\n");
+}
+
+int main(int argc, char* argv[])
+{
+#ifdef _WIN32
+       if (argc != 4)
+       {
+               Usage();
+               return 0;
+       }
+       string sWildCharPathName = argv[1];
+       string sInputType        = argv[2];
+       string sInput            = argv[3];
+
+       // vPathName
+       vector<string> vPathName;
+       GetTableList(sWildCharPathName, vPathName);
+#else
+       if (argc < 4)
+       {
+               Usage();
+               return 0;
+       }
+       string sInputType        = argv[argc - 2];
+       string sInput            = argv[argc - 1];
+
+       // vPathName
+       vector<string> vPathName;
+       GetTableList(argc, argv, vPathName);
+#endif
+       if (vPathName.size() == 0)
+       {
+               printf("no rainbow table found\n");
+               return 0;
+       }
+
+       // fCrackerType, vHash, vUserName, vLMHash
+       bool fCrackerType;                      // true: hash cracker, false: lm cracker
+       vector<string> vHash;           // hash cracker
+       vector<string> vUserName;       // lm cracker
+       vector<string> vLMHash;         // lm cracker
+       vector<string> vNTLMHash;       // lm cracker
+       if (sInputType == "-h")
+       {
+               fCrackerType = true;
+
+               string sHash = sInput;
+               if (NormalizeHash(sHash))
+                       vHash.push_back(sHash);
+               else
+                       printf("invalid hash: %s\n", sHash.c_str());
+       }
+       else if (sInputType == "-l")
+       {
+               fCrackerType = true;
+
+               string sPathName = sInput;
+               vector<string> vLine;
+               if (ReadLinesFromFile(sPathName, vLine))
+               {
+                       int i;
+                       for (i = 0; i < vLine.size(); i++)
+                       {
+                               string sHash = vLine[i];
+                               if (NormalizeHash(sHash))
+                                       vHash.push_back(sHash);
+                               else
+                                       printf("invalid hash: %s\n", sHash.c_str());
+                       }
+               }
+               else
+                       printf("can't open %s\n", sPathName.c_str());
+       }
+       else if (sInputType == "-f")
+       {
+               fCrackerType = false;
+
+               string sPathName = sInput;
+               LoadLMHashFromPwdumpFile(sPathName, vUserName, vLMHash, vNTLMHash);
+       }
+       else
+       {
+               Usage();
+               return 0;
+       }
+       
+       if (fCrackerType && vHash.size() == 0)
+               return 0;
+       if (!fCrackerType && vLMHash.size() == 0)
+               return 0;
+
+       // hs
+       CHashSet hs;
+       if (fCrackerType)
+       {
+               int i;
+               for (i = 0; i < vHash.size(); i++)
+                       hs.AddHash(vHash[i]);
+       }
+       else
+       {
+               int i;
+               for (i = 0; i < vLMHash.size(); i++)
+               {
+                       hs.AddHash(vLMHash[i].substr(0, 16));
+                       hs.AddHash(vLMHash[i].substr(16, 16));
+               }
+       }
+
+       // Run
+       CCrackEngine ce;
+       ce.Run(vPathName, hs);
+
+       // Statistics
+       printf("statistics\n");
+       printf("-------------------------------------------------------\n");
+       printf("plaintext found:          %d of %d (%.2f%%)\n", hs.GetStatHashFound(),
+                                                                                                                       hs.GetStatHashTotal(),
+                                                                                                                       100.0f * hs.GetStatHashFound() / hs.GetStatHashTotal());
+       printf("total disk access time:   %.2f s\n", ce.GetStatTotalDiskAccessTime());
+       printf("total cryptanalysis time: %.2f s\n", ce.GetStatTotalCryptanalysisTime());
+       printf("total chain walk step:    %d\n",     ce.GetStatTotalChainWalkStep());
+       printf("total false alarm:        %d\n",     ce.GetStatTotalFalseAlarm());
+       printf("total chain walk step due to false alarm: %d\n", ce.GetStatTotalChainWalkStepDueToFalseAlarm());
+//     printf("total chain walk step skipped due to checkpoints: %d\n", ce.GetStatTotalFalseAlarmSkipped()); // Checkpoints not used - yet
+       printf("\n");
+
+       // Result
+       printf("result\n");
+       printf("-------------------------------------------------------\n");
+       if (fCrackerType)
+       {
+               int i;
+               for (i = 0; i < vHash.size(); i++)
+               {
+                       string sPlain, sBinary;
+                       if (!hs.GetPlain(vHash[i], sPlain, sBinary))
+                       {
+                               sPlain  = "<notfound>";
+                               sBinary = "<notfound>";
+                       }
+
+                       printf("%s  %s  hex:%s\n", vHash[i].c_str(), sPlain.c_str(), sBinary.c_str());
+               }
+       }
+       else
+       {
+               int i;
+               for (i = 0; i < vLMHash.size(); i++)
+               {
+                       string sPlain1, sBinary1;
+                       bool fPart1Found = hs.GetPlain(vLMHash[i].substr(0, 16), sPlain1, sBinary1);
+                       if (!fPart1Found)
+                       {
+                               sPlain1  = "<notfound>";
+                               sBinary1 = "<notfound>";
+                       }
+
+                       string sPlain2, sBinary2;
+                       bool fPart2Found = hs.GetPlain(vLMHash[i].substr(16, 16), sPlain2, sBinary2);
+                       if (!fPart2Found)
+                       {
+                               sPlain2  = "<notfound>";
+                               sBinary2 = "<notfound>";
+                       }
+
+                       string sPlain = sPlain1 + sPlain2;
+                       string sBinary = sBinary1 + sBinary2;
+
+                       // Correct case
+                       if (fPart1Found && fPart2Found)
+                       {
+                               unsigned char NTLMHash[16];
+                               int nHashLen;
+                               ParseHash(vNTLMHash[i], NTLMHash, nHashLen);
+                               if (nHashLen != 16)
+                                       printf("debug: nHashLen mismatch\n");
+                               string sNTLMPassword;
+                               if (LMPasswordCorrectCase(sPlain, NTLMHash, sNTLMPassword))
+                               {
+                                       sPlain = sNTLMPassword;
+                                       sBinary = HexToStr((const unsigned char*)sNTLMPassword.c_str(), sNTLMPassword.size());
+                               }
+                               else
+                                       printf("case correction for password %s fail!\n", sPlain.c_str());
+                       }
+
+                       // Display
+                       printf("%-14s  %s  hex:%s\n", vUserName[i].c_str(),
+                                                                                 sPlain.c_str(),
+                                                                                 sBinary.c_str());
+               }
+       }
+
+       return 0;
+}
diff --git a/Client Applications/rcracki/Release/BaseRTReader.obj b/Client Applications/rcracki/Release/BaseRTReader.obj
new file mode 100644 (file)
index 0000000..5ad0b97
Binary files /dev/null and b/Client Applications/rcracki/Release/BaseRTReader.obj differ
diff --git a/Client Applications/rcracki/Release/BuildLog.htm b/Client Applications/rcracki/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..d4467c7
Binary files /dev/null and b/Client Applications/rcracki/Release/BuildLog.htm differ
diff --git a/Client Applications/rcracki/Release/ChainWalkContext.obj b/Client Applications/rcracki/Release/ChainWalkContext.obj
new file mode 100644 (file)
index 0000000..5cf7456
Binary files /dev/null and b/Client Applications/rcracki/Release/ChainWalkContext.obj differ
diff --git a/Client Applications/rcracki/Release/ChainWalkSet.obj b/Client Applications/rcracki/Release/ChainWalkSet.obj
new file mode 100644 (file)
index 0000000..5edd979
Binary files /dev/null and b/Client Applications/rcracki/Release/ChainWalkSet.obj differ
diff --git a/Client Applications/rcracki/Release/CrackEngine.obj b/Client Applications/rcracki/Release/CrackEngine.obj
new file mode 100644 (file)
index 0000000..2409ddd
Binary files /dev/null and b/Client Applications/rcracki/Release/CrackEngine.obj differ
diff --git a/Client Applications/rcracki/Release/HashAlgorithm.obj b/Client Applications/rcracki/Release/HashAlgorithm.obj
new file mode 100644 (file)
index 0000000..8f5f758
Binary files /dev/null and b/Client Applications/rcracki/Release/HashAlgorithm.obj differ
diff --git a/Client Applications/rcracki/Release/HashRoutine.obj b/Client Applications/rcracki/Release/HashRoutine.obj
new file mode 100644 (file)
index 0000000..e12c739
Binary files /dev/null and b/Client Applications/rcracki/Release/HashRoutine.obj differ
diff --git a/Client Applications/rcracki/Release/HashSet.obj b/Client Applications/rcracki/Release/HashSet.obj
new file mode 100644 (file)
index 0000000..0240a50
Binary files /dev/null and b/Client Applications/rcracki/Release/HashSet.obj differ
diff --git a/Client Applications/rcracki/Release/MemoryPool.obj b/Client Applications/rcracki/Release/MemoryPool.obj
new file mode 100644 (file)
index 0000000..9902ea6
Binary files /dev/null and b/Client Applications/rcracki/Release/MemoryPool.obj differ
diff --git a/Client Applications/rcracki/Release/Public.obj b/Client Applications/rcracki/Release/Public.obj
new file mode 100644 (file)
index 0000000..8d0a300
Binary files /dev/null and b/Client Applications/rcracki/Release/Public.obj differ
diff --git a/Client Applications/rcracki/Release/RTI2Reader.obj b/Client Applications/rcracki/Release/RTI2Reader.obj
new file mode 100644 (file)
index 0000000..c51932a
Binary files /dev/null and b/Client Applications/rcracki/Release/RTI2Reader.obj differ
diff --git a/Client Applications/rcracki/Release/RTIReader.obj b/Client Applications/rcracki/Release/RTIReader.obj
new file mode 100644 (file)
index 0000000..c707ffa
Binary files /dev/null and b/Client Applications/rcracki/Release/RTIReader.obj differ
diff --git a/Client Applications/rcracki/Release/RTReader.obj b/Client Applications/rcracki/Release/RTReader.obj
new file mode 100644 (file)
index 0000000..250d08e
Binary files /dev/null and b/Client Applications/rcracki/Release/RTReader.obj differ
diff --git a/Client Applications/rcracki/Release/RainbowCrack.obj b/Client Applications/rcracki/Release/RainbowCrack.obj
new file mode 100644 (file)
index 0000000..bba4049
Binary files /dev/null and b/Client Applications/rcracki/Release/RainbowCrack.obj differ
diff --git a/Client Applications/rcracki/Release/charset.txt b/Client Applications/rcracki/Release/charset.txt
new file mode 100644 (file)
index 0000000..d1e0179
--- /dev/null
@@ -0,0 +1,61 @@
+# charset configuration file for DistrRTgen v3.2 by Martin Westergaard (martinwj2005@gmail.com)
+
+byte                        = []
+alpha                       = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+alpha-space                 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+alpha-numeric               = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+alpha-numeric-space         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+alpha-numeric-symbol14      = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+= ]
+all                         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+all-space                   = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+lm-frt-cp437                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥àáâãäæçèéêëî]
+lm-frt-cp850                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9c\9d\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãåæèéêëíï]
+lm-frt-cp437-850            = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãäåæçèéêëíîï]
+
+numeric                     = [0123456789]
+numeric-space               = [0123456789 ]
+loweralpha                  = [abcdefghijklmnopqrstuvwxyz]
+loweralpha-space            = [abcdefghijklmnopqrstuvwxyz ]
+loweralpha-numeric          = [abcdefghijklmnopqrstuvwxyz0123456789]
+loweralpha-numeric-space    = [abcdefghijklmnopqrstuvwxyz0123456789 ]
+loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=]
+loweralpha-numeric-all             = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+mixalpha                    = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
+mixalpha-space              = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+mixalpha-numeric            = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+mixalpha-numeric-space      = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+mixalpha-numeric-symbol14   = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+mixalpha-numeric-all        = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+mixalpha-numeric-symbol32-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+mixalpha-numeric-all-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+                                                                                                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                            
\ No newline at end of file
diff --git a/Client Applications/rcracki/Release/des_enc.obj b/Client Applications/rcracki/Release/des_enc.obj
new file mode 100644 (file)
index 0000000..68e2b07
Binary files /dev/null and b/Client Applications/rcracki/Release/des_enc.obj differ
diff --git a/Client Applications/rcracki/Release/des_setkey.obj b/Client Applications/rcracki/Release/des_setkey.obj
new file mode 100644 (file)
index 0000000..b4a0c1f
Binary files /dev/null and b/Client Applications/rcracki/Release/des_setkey.obj differ
diff --git a/Client Applications/rcracki/Release/ecb_enc.obj b/Client Applications/rcracki/Release/ecb_enc.obj
new file mode 100644 (file)
index 0000000..8f68669
Binary files /dev/null and b/Client Applications/rcracki/Release/ecb_enc.obj differ
diff --git a/Client Applications/rcracki/Release/md4.obj b/Client Applications/rcracki/Release/md4.obj
new file mode 100644 (file)
index 0000000..475aa5c
Binary files /dev/null and b/Client Applications/rcracki/Release/md4.obj differ
diff --git a/Client Applications/rcracki/Release/md5.obj b/Client Applications/rcracki/Release/md5.obj
new file mode 100644 (file)
index 0000000..0abcf04
Binary files /dev/null and b/Client Applications/rcracki/Release/md5.obj differ
diff --git a/Client Applications/rcracki/Release/mt.dep b/Client Applications/rcracki/Release/mt.dep
new file mode 100644 (file)
index 0000000..94bde96
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 11:55:59,32 on 07-03-2009 
diff --git a/Client Applications/rcracki/Release/rcracki.exe b/Client Applications/rcracki/Release/rcracki.exe
new file mode 100644 (file)
index 0000000..e565d9c
Binary files /dev/null and b/Client Applications/rcracki/Release/rcracki.exe differ
diff --git a/Client Applications/rcracki/Release/rcracki.exe.intermediate.manifest b/Client Applications/rcracki/Release/rcracki.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..7256947
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Client Applications/rcracki/Release/rcracki.pdb b/Client Applications/rcracki/Release/rcracki.pdb
new file mode 100644 (file)
index 0000000..3dcd0f1
Binary files /dev/null and b/Client Applications/rcracki/Release/rcracki.pdb differ
diff --git a/Client Applications/rcracki/Release/vc90.idb b/Client Applications/rcracki/Release/vc90.idb
new file mode 100644 (file)
index 0000000..999dc6a
Binary files /dev/null and b/Client Applications/rcracki/Release/vc90.idb differ
diff --git a/Client Applications/rcracki/Release/vc90.pdb b/Client Applications/rcracki/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..a40e8c3
Binary files /dev/null and b/Client Applications/rcracki/Release/vc90.pdb differ
diff --git a/Client Applications/rcracki/charset.txt b/Client Applications/rcracki/charset.txt
new file mode 100644 (file)
index 0000000..d1e0179
--- /dev/null
@@ -0,0 +1,61 @@
+# charset configuration file for DistrRTgen v3.2 by Martin Westergaard (martinwj2005@gmail.com)
+
+byte                        = []
+alpha                       = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+alpha-space                 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+alpha-numeric               = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+alpha-numeric-space         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+alpha-numeric-symbol14      = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+= ]
+all                         = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+all-space                   = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+lm-frt-cp437                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥àáâãäæçèéêëî]
+lm-frt-cp850                = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9c\9d\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãåæèéêëíï]
+lm-frt-cp437-850            = [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~\80\8e\8f\90\92\99\9a\9b\9c\9d\9e\9f¥µ¶·½¾ÇÏÑÒÓÔÕÖ×ØÞàáâãäåæçèéêëíîï]
+
+numeric                     = [0123456789]
+numeric-space               = [0123456789 ]
+loweralpha                  = [abcdefghijklmnopqrstuvwxyz]
+loweralpha-space            = [abcdefghijklmnopqrstuvwxyz ]
+loweralpha-numeric          = [abcdefghijklmnopqrstuvwxyz0123456789]
+loweralpha-numeric-space    = [abcdefghijklmnopqrstuvwxyz0123456789 ]
+loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=]
+loweralpha-numeric-all             = [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+mixalpha                    = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
+mixalpha-space              = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]
+mixalpha-numeric            = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]
+mixalpha-numeric-space      = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]
+mixalpha-numeric-symbol14   = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=]
+mixalpha-numeric-all        = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
+mixalpha-numeric-symbol32-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+mixalpha-numeric-all-space  = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
+
+                                                                                                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                            
\ No newline at end of file
diff --git a/Client Applications/rcracki/rcracki.ncb b/Client Applications/rcracki/rcracki.ncb
new file mode 100644 (file)
index 0000000..d17c65e
Binary files /dev/null and b/Client Applications/rcracki/rcracki.ncb differ
diff --git a/Client Applications/rcracki/rcracki.sln b/Client Applications/rcracki/rcracki.sln
new file mode 100644 (file)
index 0000000..18468b3
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rcracki", "rcracki.vcproj", "{966DA4B4-E13C-449D-9A93-303C6FEA25C4}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Debug|Win32.ActiveCfg = Debug|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Debug|Win32.Build.0 = Debug|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Release|Win32.ActiveCfg = Release|Win32
+               {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/Client Applications/rcracki/rcracki.suo b/Client Applications/rcracki/rcracki.suo
new file mode 100644 (file)
index 0000000..7159e21
Binary files /dev/null and b/Client Applications/rcracki/rcracki.suo differ
diff --git a/Client Applications/rcracki/rcracki.vcproj b/Client Applications/rcracki/rcracki.vcproj
new file mode 100644 (file)
index 0000000..23d068d
--- /dev/null
@@ -0,0 +1,327 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="rcracki"
+       ProjectGUID="{966DA4B4-E13C-449D-9A93-303C6FEA25C4}"
+       RootNamespace="rcracki"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="131072"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="..\..\rt api"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="2"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               EnableIntrinsicFunctions="true"
+                               AdditionalIncludeDirectories="..\..\rt api"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="2"
+                               EnableFunctionLevelLinking="true"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\BaseRTReader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkSet.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\CrackEngine.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_setkey.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ecb_enc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\HashSet.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\MemoryPool.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\converti2\Public.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\RainbowCrack.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTI2Reader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTIReader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTReader.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\BaseRTReader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkContext.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\ChainWalkSet.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\CrackEngine.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\des_locl.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashAlgorithm.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\HashRoutine.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\HashSet.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md4.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\md5.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\MemoryPool.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\converti2\Public.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTI2Reader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTIReader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTReader.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/Client Applications/rcracki/rcracki.vcproj.W-L-10643.Administrator.user b/Client Applications/rcracki/rcracki.vcproj.W-L-10643.Administrator.user
new file mode 100644 (file)
index 0000000..b51d689
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="&quot;C:\Documents and Settings\Administrator\Desktop\FreeRainbowTables.com\BOINC apps\standalone\rti2 tables\*.rti2&quot; -h 74F3B129133FFA23"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-10643"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-10643"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/rcracki/rcracki.vcproj.W-L-MWJ.Administrator.user b/Client Applications/rcracki/rcracki.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..91c7670
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="*.rti2 -h 098f6bcd4621d373cade4e832627b4f6"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/rcracki/rcracki.vcproj.mwj-PC.mwj.user b/Client Applications/rcracki/rcracki.vcproj.mwj-PC.mwj.user
new file mode 100644 (file)
index 0000000..d32b9ac
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory="C:\Users\mwj\Desktop\tables"
+                               CommandArguments="*.rti2 -h 1AA818381E4E281B"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/rcracki/tmp/MemoryPool.cpp b/Client Applications/rcracki/tmp/MemoryPool.cpp
new file mode 100644 (file)
index 0000000..35177ca
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "MemoryPool.h"
+#include "Public.h"
+
+CMemoryPool::CMemoryPool()
+{
+       m_pMem = NULL;
+       m_nMemSize = 0;
+
+       unsigned int nAvailPhys = GetAvailPhysMemorySize();
+       if (nAvailPhys < 16 * 1024 * 1024)
+       {
+               nAvailPhys = 512 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize()
+       }
+       if (nAvailPhys < 16 * 1024 * 1024)
+               m_nMemMax = nAvailPhys / 2;                                     // Leave some memory for CChainWalkSet
+       else
+               m_nMemMax = nAvailPhys - 8 * 1024 * 1024;       // Leave some memory for CChainWalkSet  
+}
+
+CMemoryPool::~CMemoryPool()
+{
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+}
+
+unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
+{
+       if (nFileLen <= m_nMemSize)
+       {
+               nAllocatedSize = nFileLen;
+               return m_pMem;
+       }
+
+       unsigned int nTargetSize;
+       if (nFileLen < m_nMemMax)
+               nTargetSize = nFileLen;
+       else
+               nTargetSize = m_nMemMax;
+
+       // Free existing memory
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+
+       // Allocate new memory
+       //printf("allocating %u bytes memory\n", nTargetSize);
+       m_pMem = new unsigned char[nTargetSize];
+       if (m_pMem != NULL)
+       {
+               m_nMemSize = nTargetSize;
+               nAllocatedSize = nTargetSize;
+               return m_pMem;
+       }
+       else
+       {
+               nAllocatedSize = 0;
+               return NULL;
+       }
+}
diff --git a/Client Applications/rcracki/tmp/MemoryPool.h b/Client Applications/rcracki/tmp/MemoryPool.h
new file mode 100644 (file)
index 0000000..9f2ea4e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _MEMORYPOOL_H
+#define _MEMORYPOOL_H
+
+class CMemoryPool  
+{
+public:
+       CMemoryPool();
+       virtual ~CMemoryPool();
+
+private:
+       unsigned char* m_pMem;
+       unsigned int m_nMemSize;
+
+       unsigned int m_nMemMax;
+
+public:
+       unsigned char* Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize);
+};
+
+#endif
diff --git a/Client Applications/rcracki/tmp/Public.cpp b/Client Applications/rcracki/tmp/Public.cpp
new file mode 100644 (file)
index 0000000..9c43927
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "Public.h"
+
+#ifdef _WIN32
+       #include <windows.h>
+#else
+       #include <sys/sysinfo.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+unsigned int GetFileLen(FILE* file)
+{
+       unsigned int pos = ftell(file);
+       fseek(file, 0, SEEK_END);
+       unsigned int len = ftell(file);
+       fseek(file, pos, SEEK_SET);
+
+       return len;
+}
+
+string TrimString(string s)
+{
+       while (s.size() > 0)
+       {
+               if (s[0] == ' ' || s[0] == '\t')
+                       s = s.substr(1);
+               else
+                       break;
+       }
+
+       while (s.size() > 0)
+       {
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+                       s = s.substr(0, s.size() - 1);
+               else
+                       break;
+       }
+
+       return s;
+}
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+       // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+       if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+               return false;
+       size_t nEnd = sCharset.rfind(')');
+       size_t nStart = sCharset.rfind('(');
+       string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+       vector<string> vParts;
+       SeperateString(sChar, ",", vParts);
+       for(int i = 0; i < vParts.size(); i++)
+       {
+               tCharset stCharset;
+               vector<string> vParts2;
+               SeperateString(vParts[i], "#", vParts2);
+               stCharset.sName = vParts2[0];
+               vector<string> vParts3;
+               SeperateString(vParts2[1], "-", vParts3);
+               stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+               stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+               vCharset.push_back(stCharset);
+       }
+       return true;
+}
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+
+       FILE* file = fopen(sPathName.c_str(), "rb");
+       if (file != NULL)
+       {
+               unsigned int len = GetFileLen(file);
+               char* data = new char[len + 1];
+               fread(data, 1, len, file);
+               data[len] = '\0';
+               string content = data;
+               content += "\n";
+               delete data;
+
+               unsigned int i;
+               for (i = 0; i < content.size(); i++)
+               {
+                       if (content[i] == '\r')
+                               content[i] = '\n';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       string line = content.substr(0, n);
+                       line = TrimString(line);
+                       if (line != "")
+                               vLine.push_back(line);
+                       content = content.substr(n + 1);
+               }
+
+               fclose(file);
+       }
+       else
+               return false;
+
+       return true;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+       vPart.clear();
+
+       unsigned int i;
+       for (i = 0; i < sSeperator.size(); i++)
+       {
+               int n = s.find(sSeperator[i]);
+               if (n != -1)
+               {
+                       vPart.push_back(s.substr(0, n));
+                       s = s.substr(n + 1);
+               }
+               else
+                       return false;
+       }
+       vPart.push_back(s);
+
+       return true;
+}
+
+string uint64tostr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%I64u", n);
+#else
+       sprintf(str, "%llu", n);
+#endif
+
+       return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%016I64x", n);
+#else
+       sprintf(str, "%016llx", n);
+#endif
+
+       return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+       string sRet;
+       int i;
+       for (i = 0; i < nLen; i++)
+       {
+               char szByte[3];
+               sprintf(szByte, "%02x", pData[i]);
+               sRet += szByte;
+       }
+
+       return sRet;
+}
+
+unsigned int GetAvailPhysMemorySize()
+{
+#ifdef _WIN32
+               MEMORYSTATUS ms;
+               GlobalMemoryStatus(&ms);
+               return ms.dwAvailPhys;
+#else
+       struct sysinfo info;
+       sysinfo(&info);                 // This function is Linux-specific
+       return info.freeram;
+#endif
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < sHash.size() / 2; i++)
+       {
+               string sSub = sHash.substr(i * 2, 2);
+               int nValue;
+               sscanf(sSub.c_str(), "%02x", &nValue);
+               pHash[i] = (unsigned char)nValue;
+       }
+
+       nHashLen = sHash.size() / 2;
+}
+
+void Logo()
+{
+       printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+       printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+       printf("http://www.freerainbowtables.com/\n");
+       printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+       printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
diff --git a/Client Applications/rcracki/tmp/Public.h b/Client Applications/rcracki/tmp/Public.h
new file mode 100644 (file)
index 0000000..6e7387e
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _PUBLIC_H
+#define _PUBLIC_H
+
+#include <stdio.h>
+
+#include <string>
+#include <vector>
+#include <list>
+using namespace std;
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 u_int64_t
+#endif
+
+struct RainbowChainO
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+};
+struct RainbowChain
+{
+       uint64 nIndexS;
+       int nIndexE;
+       int nCheckPoint;
+};
+struct RainbowChainCP
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+       int nCheckPoint;
+};
+
+struct IndexChain
+{
+       uint64 nPrefix;
+       int nFirstChain;
+       unsigned int nChainCount;
+};
+typedef struct
+{
+       string sName;
+       int nPlainLenMin;
+       int nPlainLenMax;
+} tCharset;
+
+#define MAX_PLAIN_LEN 256
+#define MIN_HASH_LEN  8
+#define MAX_HASH_LEN  256
+#define MAX_SALT_LEN  256
+
+unsigned int GetFileLen(FILE* file);
+string TrimString(string s);
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine);
+bool SeperateString(string s, string sSeperator, vector<string>& vPart);
+string uint64tostr(uint64 n);
+string uint64tohexstr(uint64 n);
+string HexToStr(const unsigned char* pData, int nLen);
+unsigned int GetAvailPhysMemorySize();
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen);
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset);
+void Logo();
+
+#endif
diff --git a/Client Applications/rti2rto/Debug/BaseRTReader.obj b/Client Applications/rti2rto/Debug/BaseRTReader.obj
new file mode 100644 (file)
index 0000000..62d92f3
Binary files /dev/null and b/Client Applications/rti2rto/Debug/BaseRTReader.obj differ
diff --git a/Client Applications/rti2rto/Debug/BuildLog.htm b/Client Applications/rti2rto/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..536aca4
Binary files /dev/null and b/Client Applications/rti2rto/Debug/BuildLog.htm differ
diff --git a/Client Applications/rti2rto/Debug/MemoryPool.obj b/Client Applications/rti2rto/Debug/MemoryPool.obj
new file mode 100644 (file)
index 0000000..5121e81
Binary files /dev/null and b/Client Applications/rti2rto/Debug/MemoryPool.obj differ
diff --git a/Client Applications/rti2rto/Debug/Public.obj b/Client Applications/rti2rto/Debug/Public.obj
new file mode 100644 (file)
index 0000000..dc7e5af
Binary files /dev/null and b/Client Applications/rti2rto/Debug/Public.obj differ
diff --git a/Client Applications/rti2rto/Debug/RTI2Reader.obj b/Client Applications/rti2rto/Debug/RTI2Reader.obj
new file mode 100644 (file)
index 0000000..331f580
Binary files /dev/null and b/Client Applications/rti2rto/Debug/RTI2Reader.obj differ
diff --git a/Client Applications/rti2rto/Debug/RTIReader.obj b/Client Applications/rti2rto/Debug/RTIReader.obj
new file mode 100644 (file)
index 0000000..d832701
Binary files /dev/null and b/Client Applications/rti2rto/Debug/RTIReader.obj differ
diff --git a/Client Applications/rti2rto/Debug/RTReader.obj b/Client Applications/rti2rto/Debug/RTReader.obj
new file mode 100644 (file)
index 0000000..165e076
Binary files /dev/null and b/Client Applications/rti2rto/Debug/RTReader.obj differ
diff --git a/Client Applications/rti2rto/Debug/mt.dep b/Client Applications/rti2rto/Debug/mt.dep
new file mode 100644 (file)
index 0000000..0416a21
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 12:31:21,12 on 16-01-2009 
diff --git a/Client Applications/rti2rto/Debug/rti2rto.exe b/Client Applications/rti2rto/Debug/rti2rto.exe
new file mode 100644 (file)
index 0000000..aef0a83
Binary files /dev/null and b/Client Applications/rti2rto/Debug/rti2rto.exe differ
diff --git a/Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest b/Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest
new file mode 100644 (file)
index 0000000..fac40ba
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
\ No newline at end of file
diff --git a/Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest.res b/Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..9e54244
Binary files /dev/null and b/Client Applications/rti2rto/Debug/rti2rto.exe.embed.manifest.res differ
diff --git a/Client Applications/rti2rto/Debug/rti2rto.exe.intermediate.manifest b/Client Applications/rti2rto/Debug/rti2rto.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..3351598
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Client Applications/rti2rto/Debug/rti2rto.ilk b/Client Applications/rti2rto/Debug/rti2rto.ilk
new file mode 100644 (file)
index 0000000..32bc02f
Binary files /dev/null and b/Client Applications/rti2rto/Debug/rti2rto.ilk differ
diff --git a/Client Applications/rti2rto/Debug/rti2rto.obj b/Client Applications/rti2rto/Debug/rti2rto.obj
new file mode 100644 (file)
index 0000000..f65bc03
Binary files /dev/null and b/Client Applications/rti2rto/Debug/rti2rto.obj differ
diff --git a/Client Applications/rti2rto/Debug/rti2rto.pdb b/Client Applications/rti2rto/Debug/rti2rto.pdb
new file mode 100644 (file)
index 0000000..ab4ed15
Binary files /dev/null and b/Client Applications/rti2rto/Debug/rti2rto.pdb differ
diff --git a/Client Applications/rti2rto/Debug/vc90.idb b/Client Applications/rti2rto/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..da15c8c
Binary files /dev/null and b/Client Applications/rti2rto/Debug/vc90.idb differ
diff --git a/Client Applications/rti2rto/Debug/vc90.pdb b/Client Applications/rti2rto/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..309e6d0
Binary files /dev/null and b/Client Applications/rti2rto/Debug/vc90.pdb differ
diff --git a/Client Applications/rti2rto/Release/BaseRTReader.obj b/Client Applications/rti2rto/Release/BaseRTReader.obj
new file mode 100644 (file)
index 0000000..eed7989
Binary files /dev/null and b/Client Applications/rti2rto/Release/BaseRTReader.obj differ
diff --git a/Client Applications/rti2rto/Release/BuildLog.htm b/Client Applications/rti2rto/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..8530848
Binary files /dev/null and b/Client Applications/rti2rto/Release/BuildLog.htm differ
diff --git a/Client Applications/rti2rto/Release/MemoryPool.obj b/Client Applications/rti2rto/Release/MemoryPool.obj
new file mode 100644 (file)
index 0000000..ee2a825
Binary files /dev/null and b/Client Applications/rti2rto/Release/MemoryPool.obj differ
diff --git a/Client Applications/rti2rto/Release/Public.obj b/Client Applications/rti2rto/Release/Public.obj
new file mode 100644 (file)
index 0000000..7d91eef
Binary files /dev/null and b/Client Applications/rti2rto/Release/Public.obj differ
diff --git a/Client Applications/rti2rto/Release/RTI2Reader.obj b/Client Applications/rti2rto/Release/RTI2Reader.obj
new file mode 100644 (file)
index 0000000..035f0e9
Binary files /dev/null and b/Client Applications/rti2rto/Release/RTI2Reader.obj differ
diff --git a/Client Applications/rti2rto/Release/RTIReader.obj b/Client Applications/rti2rto/Release/RTIReader.obj
new file mode 100644 (file)
index 0000000..de5c724
Binary files /dev/null and b/Client Applications/rti2rto/Release/RTIReader.obj differ
diff --git a/Client Applications/rti2rto/Release/RTReader.obj b/Client Applications/rti2rto/Release/RTReader.obj
new file mode 100644 (file)
index 0000000..f4d535d
Binary files /dev/null and b/Client Applications/rti2rto/Release/RTReader.obj differ
diff --git a/Client Applications/rti2rto/Release/mt.dep b/Client Applications/rti2rto/Release/mt.dep
new file mode 100644 (file)
index 0000000..2921ce3
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 17:31:33,23 on 17-11-2008 
diff --git a/Client Applications/rti2rto/Release/rti2rto.exe.intermediate.manifest b/Client Applications/rti2rto/Release/rti2rto.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..ecea6f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/Client Applications/rti2rto/Release/rti2rto.obj b/Client Applications/rti2rto/Release/rti2rto.obj
new file mode 100644 (file)
index 0000000..e74c112
Binary files /dev/null and b/Client Applications/rti2rto/Release/rti2rto.obj differ
diff --git a/Client Applications/rti2rto/Release/vc90.idb b/Client Applications/rti2rto/Release/vc90.idb
new file mode 100644 (file)
index 0000000..447d3da
Binary files /dev/null and b/Client Applications/rti2rto/Release/vc90.idb differ
diff --git a/Client Applications/rti2rto/Release/vc90.pdb b/Client Applications/rti2rto/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..c2d91b7
Binary files /dev/null and b/Client Applications/rti2rto/Release/vc90.pdb differ
diff --git a/Client Applications/rti2rto/rti2rto.cpp b/Client Applications/rti2rto/rti2rto.cpp
new file mode 100644 (file)
index 0000000..bf08be3
--- /dev/null
@@ -0,0 +1,182 @@
+#include <string>
+#include <vector>
+#ifdef _WIN32
+#include <io.h>
+#else
+       #include <sys/types.h>
+       #include <sys/stat.h>
+       #include <unistd.h>
+#endif
+
+#include <time.h>
+#include "Public.h"
+#include "MemoryPool.h"
+#include "RTI2Reader.h"
+#include "RTIReader.h"
+using namespace std;
+
+void Usage()
+{
+       printf("rti2rto - Indexed to Original rainbow table converter\n");
+       printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+       printf("http://www.freerainbowtables.com\n\n");
+
+       printf("usage: rti2rto rainbow_table_pathname\n");
+       printf("rainbow_table_pathname: pathname of the rainbow table(s), wildchar(*, ?) supported\n");
+       printf("\n");
+       printf("example: rti2rto *.rti\n");
+       printf("         rti2rto md5_*.rti\n");
+}
+#ifdef _WIN32
+void GetTableList(string sWildCharPathName, vector<string>& vPathName)
+{
+       vPathName.clear();
+
+       string sPath;
+       int n = sWildCharPathName.find_last_of('\\');
+       if (n != -1)
+               sPath = sWildCharPathName.substr(0, n + 1);
+
+       _finddata_t fd;
+       long handle = _findfirst(sWildCharPathName.c_str(), &fd);
+       if (handle != -1)
+       {
+               do
+               {
+                       string sName = fd.name;
+                       if (sName != "." && sName != ".." && !(fd.attrib & _A_SUBDIR))
+                       {
+                               string sPathName = sPath + sName;
+                               vPathName.push_back(sPathName);
+                       }
+               } while (_findnext(handle, &fd) == 0);
+
+               _findclose(handle);
+       }
+}
+#else
+void GetTableList(int argc, char* argv[], vector<string>& vPathName)
+{
+       vPathName.clear();
+
+       int i;
+       for (i = 1; i < argc; i++)
+       {
+               string sPathName = argv[i];
+               struct stat buf;
+               if (lstat(sPathName.c_str(), &buf) == 0)
+               {
+                       if (S_ISREG(buf.st_mode))
+                               vPathName.push_back(sPathName);
+
+               }
+       }
+}
+#endif
+
+
+void ConvertRainbowTable(string sPathName, string sResultFileName, string sType)
+{
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       string sFileName;
+       if (nIndex != -1)
+               sFileName = sPathName.substr(nIndex + 1);
+       else
+               sFileName = sPathName;
+       // Info
+       printf("%s:\n", sFileName.c_str());
+       FILE *fResult = fopen(sResultFileName.c_str(), "wb");
+       if(fResult == NULL)
+       {
+               printf("Could not open %s for write access", sResultFileName.c_str());
+               return;
+       }
+       static CMemoryPool mp;
+       unsigned int nAllocatedSize;
+       BaseRTReader *reader = NULL;
+       if(sType == "RTI2")
+               reader = (BaseRTReader*)new RTI2Reader(sFileName);
+       else if(sType == "RTI")
+               reader = (BaseRTReader*)new RTIReader(sFileName);
+       else 
+       {
+               printf("Invalid table type '%s'", sType.c_str());
+               return ;
+       }
+       RainbowChainCP* pChain = (RainbowChainCP*)mp.Allocate(reader->GetChainsLeft() * sizeof(RainbowChainCP), nAllocatedSize);
+       if (pChain != NULL)
+       {
+               nAllocatedSize = nAllocatedSize / sizeof(RainbowChainCP) * sizeof(RainbowChainCP);              // Round to boundary
+               unsigned int nChains = nAllocatedSize / sizeof(RainbowChainCP);
+               while(reader->GetChainsLeft() > 0)
+               {
+                       reader->ReadChains(nChains, pChain);
+                       for(int i = 0; i < nChains; i++)
+                       {
+                               fwrite(&pChain[i], 1, 16, fResult);
+                       }
+               }
+       }
+       fclose(fResult);
+       if(reader != NULL)
+               delete reader;
+}
+int main(int argc, char* argv[])
+{
+#ifdef _WIN32
+       if (argc != 2)
+       {
+               Usage();
+               
+               return 0;
+       }
+       string sWildCharPathName = argv[1];
+       vector<string> vPathName;
+       GetTableList(sWildCharPathName, vPathName);
+#else
+       if (argc < 2)
+       {
+               Usage();
+               return 0;
+       }
+       for(int i = 0; i < argc; i++)
+       {
+               printf("%i: %s\n", i, argv[i]);
+       }
+       // vPathName
+       vector<string> vPathName;
+       GetTableList(argc, argv, vPathName);
+#endif
+       if (vPathName.size() == 0)
+       {
+               printf("no rainbow table found\n");
+               return 0;
+       }
+       for (int i = 0; i < vPathName.size(); i++)
+       {
+               string sResultFile, sType;
+                       
+               if(vPathName[i].substr(vPathName[i].length() - 4, vPathName[i].length()) == "rti2")
+               {
+                       sResultFile = vPathName[i].substr(0, vPathName[i].length() - 2); // Resulting file is .rt, not .rti2
+                       sType = "RTI2";
+               }
+               else if(vPathName[i].substr(vPathName[i].length() - 3, vPathName[i].length()) == "rti")
+               {
+                       sResultFile = vPathName[i].substr(0, vPathName[i].length() - 1); // Resulting file is .rt, not .rti
+                       sType = "RTI";
+               }
+               else 
+               {
+                       printf("File %s is not a RTI or a RTI2 file", vPathName[i].c_str());
+                       continue;
+               }
+               ConvertRainbowTable(vPathName[i], sResultFile, sType);
+               printf("\n");
+       }
+       return 0;
+}
\ No newline at end of file
diff --git a/Client Applications/rti2rto/rti2rto.ncb b/Client Applications/rti2rto/rti2rto.ncb
new file mode 100644 (file)
index 0000000..69413c8
Binary files /dev/null and b/Client Applications/rti2rto/rti2rto.ncb differ
diff --git a/Client Applications/rti2rto/rti2rto.sln b/Client Applications/rti2rto/rti2rto.sln
new file mode 100644 (file)
index 0000000..a8000e5
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rti2rto", "rti2rto.vcproj", "{E0FBC06A-C902-4468-A614-CBF9F591AA7C}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Debug|Win32.ActiveCfg = Debug|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Debug|Win32.Build.0 = Debug|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Release|Win32.ActiveCfg = Release|Win32
+               {E0FBC06A-C902-4468-A614-CBF9F591AA7C}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/Client Applications/rti2rto/rti2rto.suo b/Client Applications/rti2rto/rti2rto.suo
new file mode 100644 (file)
index 0000000..3fdc2e6
Binary files /dev/null and b/Client Applications/rti2rto/rti2rto.suo differ
diff --git a/Client Applications/rti2rto/rti2rto.vcproj b/Client Applications/rti2rto/rti2rto.vcproj
new file mode 100644 (file)
index 0000000..6dc5986
--- /dev/null
@@ -0,0 +1,243 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="rti2rto"
+       ProjectGUID="{E0FBC06A-C902-4468-A614-CBF9F591AA7C}"
+       RootNamespace="rti2rto"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="196613"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="../../rt api"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="2"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               EnableIntrinsicFunctions="true"
+                               AdditionalIncludeDirectories="..\..\rt api"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="0"
+                               EnableFunctionLevelLinking="true"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\BaseRTReader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\MemoryPool.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\converti2\Public.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTI2Reader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\rti2rto.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTIReader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTReader.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath="..\..\rt api\BaseRTReader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\MemoryPool.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\converti2\Public.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTI2Reader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTIReader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\rt api\RTReader.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/Client Applications/rti2rto/rti2rto.vcproj.MWJ-PC.mwj.user b/Client Applications/rti2rto/rti2rto.vcproj.MWJ-PC.mwj.user
new file mode 100644 (file)
index 0000000..15b19f6
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/rti2rto/rti2rto.vcproj.W-L-10643.Administrator.user b/Client Applications/rti2rto/rti2rto.vcproj.W-L-10643.Administrator.user
new file mode 100644 (file)
index 0000000..5bb4127
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="21_67108864_0.rti2"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-10643"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-10643"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Client Applications/rti2rto/rti2rto.vcproj.W-L-MWJ.Administrator.user b/Client Applications/rti2rto/rti2rto.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..541525c
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments="*.rti"
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor="0"
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Common/rt api/BaseRTReader.cpp b/Common/rt api/BaseRTReader.cpp
new file mode 100644 (file)
index 0000000..d762e26
--- /dev/null
@@ -0,0 +1,2 @@
+#include "BaseRTReader.h"
+
diff --git a/Common/rt api/BaseRTReader.h b/Common/rt api/BaseRTReader.h
new file mode 100644 (file)
index 0000000..b94114f
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __BASERTREADER_H__
+#define __BASERTREADER_H__
+
+#include "Public.h"
+#include <string>
+#ifdef WIN32
+#include <io.h>
+#endif
+using namespace std;
+
+class BaseRTReader
+{
+public:
+       virtual int ReadChains(unsigned int &numChains, RainbowChainCP *pData) = 0;
+       virtual unsigned int GetChainsLeft() = 0;
+       
+};
+
+#endif
diff --git a/Common/rt api/ChainWalkContext.cpp b/Common/rt api/ChainWalkContext.cpp
new file mode 100644 (file)
index 0000000..3d7dcf8
--- /dev/null
@@ -0,0 +1,581 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkContext.h"
+
+#include <ctype.h>
+
+
+//////////////////////////////////////////////////////////////////////
+
+string CChainWalkContext::m_sHashRoutineName;
+HASHROUTINE CChainWalkContext::m_pHashRoutine;
+int CChainWalkContext::m_nHashLen;
+int CChainWalkContext::m_nPlainLenMinTotal = 0;
+int CChainWalkContext::m_nPlainLenMaxTotal = 0;
+int CChainWalkContext::m_nHybridCharset = 0;
+vector<stCharset> CChainWalkContext::m_vCharset;
+uint64 CChainWalkContext::m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];
+uint64 CChainWalkContext::m_nPlainSpaceTotal;
+unsigned char CChainWalkContext::m_Salt[MAX_SALT_LEN];
+int CChainWalkContext::m_nSaltLen = 0;
+int CChainWalkContext::m_nRainbowTableIndex;
+uint64 CChainWalkContext::m_nReduceOffset;
+
+//////////////////////////////////////////////////////////////////////
+
+CChainWalkContext::CChainWalkContext()
+{
+}
+
+CChainWalkContext::~CChainWalkContext()
+{
+}
+
+bool CChainWalkContext::LoadCharset(string sName)
+{
+       m_vCharset.clear();
+       if (sName == "byte")
+       {
+               stCharset tCharset;
+               int i;
+               for (i = 0x00; i <= 0xff; i++)
+                       tCharset.m_PlainCharset[i] = i;
+               tCharset.m_nPlainCharsetLen = 256;
+               tCharset.m_sPlainCharsetName = sName;
+               tCharset.m_sPlainCharsetContent = "0x00, 0x01, ... 0xff";
+               m_vCharset.push_back(tCharset);
+               return true;
+       }
+       if(sName.substr(0, 6) == "hybrid") // Hybrid charset consisting of 2 charsets
+       {
+               m_nHybridCharset = 1;           
+       }
+       vector<string> vLine;
+       if (ReadLinesFromFile("charset.txt", vLine))
+       {
+               int i;
+               for (i = 0; i < vLine.size(); i++)
+               {
+                       // Filter comment
+                       if (vLine[i][0] == '#')
+                               continue;
+
+                       vector<string> vPart;
+                       if (SeperateString(vLine[i], "=", vPart))
+                       {
+                               // sCharsetName
+                               string sCharsetName = TrimString(vPart[0]);
+                               if (sCharsetName == "")
+                                       continue;
+                                                               
+                               // sCharsetName charset check
+                               bool fCharsetNameCheckPass = true;
+                               int j;
+                               for (j = 0; j < sCharsetName.size(); j++)
+                               {
+                                       if (   !isalpha(sCharsetName[j])
+                                               && !isdigit(sCharsetName[j])
+                                               && (sCharsetName[j] != '-'))
+                                       {
+                                               fCharsetNameCheckPass = false;
+                                               break;
+                                       }
+                               }
+                               if (!fCharsetNameCheckPass)
+                               {
+                                       printf("invalid charset name %s in charset configuration file\n", sCharsetName.c_str());
+                                       continue;
+                               }
+
+                               // sCharsetContent
+                               string sCharsetContent = TrimString(vPart[1]);
+                               if (sCharsetContent == "" || sCharsetContent == "[]")
+                                       continue;
+                               if (sCharsetContent[0] != '[' || sCharsetContent[sCharsetContent.size() - 1] != ']')
+                               {
+                                       printf("invalid charset content %s in charset configuration file\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+                               sCharsetContent = sCharsetContent.substr(1, sCharsetContent.size() - 2);
+                               if (sCharsetContent.size() > 256)
+                               {
+                                       printf("charset content %s too long\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+
+                               //printf("%s = [%s]\n", sCharsetName.c_str(), sCharsetContent.c_str());
+
+                               // Is it the wanted charset?
+                               if(m_nHybridCharset == 1)
+                               {
+                                       vector<tCharset> vCharsets;
+                                       GetHybridCharsets(sName, vCharsets);
+                                       if(sCharsetName == vCharsets[m_vCharset.size()].sName)
+                                       {
+                                               stCharset tCharset = {0};
+                                               tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                               memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                               tCharset.m_sPlainCharsetName = sCharsetName;
+                                               tCharset.m_sPlainCharsetContent = sCharsetContent;      
+                                               tCharset.m_nPlainLenMin = vCharsets[m_vCharset.size()].nPlainLenMin;
+                                               tCharset.m_nPlainLenMax = vCharsets[m_vCharset.size()].nPlainLenMax;
+                                               m_vCharset.push_back(tCharset);
+                                               if(vCharsets.size() == m_vCharset.size())
+                                                       return true;
+                                               i = 0; // Start the lookup over again for the next charset
+                                       }                                               
+                               }
+                               else if (sCharsetName == sName)
+                               {
+                                       stCharset tCharset;
+                                       tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                       memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                       tCharset.m_sPlainCharsetName = sCharsetName;
+                                       tCharset.m_sPlainCharsetContent = sCharsetContent;                                                      
+                                       m_vCharset.push_back(tCharset);
+                                       return true;
+                               }
+                       }
+               }
+               printf("charset %s not found in charset.txt\n", sName.c_str());
+       }
+       else
+               printf("can't open charset configuration file\n");
+       return false;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+bool CChainWalkContext::SetHashRoutine(string sHashRoutineName)
+{
+       CHashRoutine hr;
+       hr.GetHashRoutine(sHashRoutineName, m_pHashRoutine, m_nHashLen);
+       if (m_pHashRoutine != NULL)
+       {
+               m_sHashRoutineName = sHashRoutineName;
+               return true;
+       }
+       else
+               return false;
+}
+
+bool CChainWalkContext::SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax)
+{
+       // m_PlainCharset, m_nPlainCharsetLen, m_sPlainCharsetName, m_sPlainCharsetContent
+       if (!LoadCharset(sCharsetName))
+               return false;
+
+       if(m_vCharset.size() == 1) // Not hybrid charset
+       {
+               // m_nPlainLenMin, m_nPlainLenMax
+               if (nPlainLenMin < 1 || nPlainLenMax > MAX_PLAIN_LEN || nPlainLenMin > nPlainLenMax)
+               {
+                       printf("invalid plaintext length range: %d - %d\n", nPlainLenMin, nPlainLenMax);
+                       return false;
+               }
+               m_vCharset[0].m_nPlainLenMin = nPlainLenMin;
+               m_vCharset[0].m_nPlainLenMax = nPlainLenMax;
+       }
+       // m_nPlainSpaceUpToX
+       m_nPlainSpaceUpToX[0] = 0;
+       m_nPlainLenMaxTotal = 0;
+       m_nPlainLenMinTotal = 0;
+       uint64 nTemp = 1;
+       int j, k = 1;
+       for(j = 0; j < m_vCharset.size(); j++)
+       {
+               int i;
+               m_nPlainLenMaxTotal += m_vCharset[j].m_nPlainLenMax;
+               m_nPlainLenMinTotal += m_vCharset[j].m_nPlainLenMin;
+               for (i = 1; i <= m_vCharset[j].m_nPlainLenMax; i++)
+               {                       
+                       nTemp *= m_vCharset[j].m_nPlainCharsetLen;
+                       if (i < m_vCharset[j].m_nPlainLenMin)
+                               m_nPlainSpaceUpToX[k] = 0;
+                       else
+                               m_nPlainSpaceUpToX[k] = m_nPlainSpaceUpToX[k - 1] + nTemp;
+                       k++;
+               }               
+       }
+       // m_nPlainSpaceTotal
+       m_nPlainSpaceTotal = m_nPlainSpaceUpToX[m_nPlainLenMaxTotal];
+
+       return true;
+}
+
+bool CChainWalkContext::SetRainbowTableIndex(int nRainbowTableIndex)
+{
+       if (nRainbowTableIndex < 0)
+               return false;
+       m_nRainbowTableIndex = nRainbowTableIndex;
+       m_nReduceOffset = 65536 * nRainbowTableIndex;
+
+       return true;
+}
+
+bool CChainWalkContext::SetSalt(unsigned char *Salt, int nSaltLength)
+{
+       memcpy(&m_Salt[0], Salt, nSaltLength);
+       
+       m_nSaltLen = nSaltLength;
+//     m_sSalt = sSalt;
+       return true;
+}
+
+bool CChainWalkContext::SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount)
+{
+       // something like lm_alpha#1-7_0_100x16_test.rt
+
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       if (nIndex != -1)
+               sPathName = sPathName.substr(nIndex + 1);
+
+       if (sPathName.size() < 3)
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+       /*
+       if (sPathName.substr(sPathName.size() - 4) != ".rti")
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+*/
+       // Parse
+       vector<string> vPart;
+       if (!SeperateString(sPathName, "___x_", vPart))
+       {
+               printf("filename %s not identified\n", sPathName.c_str());
+               return false;
+       }
+
+       string sHashRoutineName   = vPart[0];
+       int nRainbowTableIndex    = atoi(vPart[2].c_str());
+       nRainbowChainLen          = atoi(vPart[3].c_str());
+       nRainbowChainCount        = atoi(vPart[4].c_str());
+
+       // Parse charset definition
+       string sCharsetDefinition = vPart[1];
+       string sCharsetName;
+       int nPlainLenMin = 0, nPlainLenMax = 0;         
+
+//     printf("Charset: %s", sCharsetDefinition.c_str());
+       
+       if(sCharsetDefinition.substr(0, 6) == "hybrid") // Hybrid table
+       {
+               sCharsetName = sCharsetDefinition;
+       }
+       else
+       {
+               if (sCharsetDefinition.find('#') == -1)         // For backward compatibility, "#1-7" is implied
+               {                       
+                       sCharsetName = sCharsetDefinition;
+                       nPlainLenMin = 1;
+                       nPlainLenMax = 7;
+               }
+               else
+               {
+                       vector<string> vCharsetDefinitionPart;
+                       if (!SeperateString(sCharsetDefinition, "#-", vCharsetDefinitionPart))
+                       {
+                               printf("filename %s not identified\n", sPathName.c_str());
+                               return false;   
+                       }
+                       else
+                       {
+                               sCharsetName = vCharsetDefinitionPart[0];
+                               nPlainLenMin = atoi(vCharsetDefinitionPart[1].c_str());
+                               nPlainLenMax = atoi(vCharsetDefinitionPart[2].c_str());
+                       }
+               }
+       }
+       // Setup
+       if (!SetHashRoutine(sHashRoutineName))
+       {
+               printf("hash routine %s not supported\n", sHashRoutineName.c_str());
+               return false;
+       }
+       if (!SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+               return false;
+       if (!SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               printf("invalid rainbow table index %d\n", nRainbowTableIndex);
+               return false;
+       }
+       m_nPlainSpaceTotal = m_nPlainSpaceUpToX[m_nPlainLenMaxTotal];
+       return true;
+}
+
+string CChainWalkContext::GetHashRoutineName()
+{
+       return m_sHashRoutineName;
+}
+
+int CChainWalkContext::GetHashLen()
+{
+       return m_nHashLen;
+}
+
+string CChainWalkContext::GetPlainCharsetName()
+{
+       return m_vCharset[0].m_sPlainCharsetName;
+}
+
+string CChainWalkContext::GetPlainCharsetContent()
+{
+       return m_vCharset[0].m_sPlainCharsetContent;
+}
+
+int CChainWalkContext::GetPlainLenMin()
+{
+       return m_vCharset[0].m_nPlainLenMin;
+}
+
+int CChainWalkContext::GetPlainLenMax()
+{
+       return m_vCharset[0].m_nPlainLenMax;
+}
+
+uint64 CChainWalkContext::GetPlainSpaceTotal()
+{
+       return m_nPlainSpaceTotal;
+}
+
+int CChainWalkContext::GetRainbowTableIndex()
+{
+       return m_nRainbowTableIndex;
+}
+
+void CChainWalkContext::Dump()
+{
+       printf("hash routine: %s\n", m_sHashRoutineName.c_str());
+       printf("hash length: %d\n", m_nHashLen);
+
+       printf("plain charset: ");
+       int i;
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+       {
+               if (isprint(m_vCharset[0].m_PlainCharset[i]))
+                       printf("%c", m_vCharset[0].m_PlainCharset[i]);
+               else
+                       printf("?");
+       }
+       printf("\n");
+
+       printf("plain charset in hex: ");
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+               printf("%02x ", m_vCharset[0].m_PlainCharset[i]);
+       printf("\n");
+
+       printf("plain length range: %d - %d\n", m_vCharset[0].m_nPlainLenMin, m_vCharset[0].m_nPlainLenMax);
+       printf("plain charset name: %s\n", m_vCharset[0].m_sPlainCharsetName.c_str());
+       //printf("plain charset content: %s\n", m_sPlainCharsetContent.c_str());
+       //for (i = 0; i <= m_nPlainLenMax; i++)
+       //      printf("plain space up to %d: %s\n", i, uint64tostr(m_nPlainSpaceUpToX[i]).c_str());
+       printf("plain space total: %s\n", uint64tostr(m_nPlainSpaceTotal).c_str());
+
+       printf("rainbow table index: %d\n", m_nRainbowTableIndex);
+       printf("reduce offset: %s\n", uint64tostr(m_nReduceOffset).c_str());
+       printf("\n");
+}
+/*
+void CChainWalkContext::GenerateRandomIndex()
+{
+       RAND_bytes((unsigned char*)&m_nIndex, 8);
+       m_nIndex = m_nIndex % m_nPlainSpaceTotal;
+}
+*/
+void CChainWalkContext::SetIndex(uint64 nIndex)
+{
+       m_nIndex = nIndex;
+}
+
+void CChainWalkContext::SetHash(unsigned char* pHash)
+{
+       memcpy(m_Hash, pHash, m_nHashLen);
+}
+
+void CChainWalkContext::IndexToPlain()
+{
+       int i;
+       m_nPlainLen = 0;
+       for (i = m_nPlainLenMaxTotal - 1; i >= m_nPlainLenMinTotal - 1; i--)
+       {
+               if (m_nIndex >= m_nPlainSpaceUpToX[i])
+               {
+                       m_nPlainLen = i + 1;
+                       break;
+               }
+       }
+       if(m_nPlainLen == 0)
+               m_nPlainLen = m_nPlainLenMinTotal;
+       uint64 nIndexOfX = m_nIndex - m_nPlainSpaceUpToX[m_nPlainLen - 1];
+
+#ifdef _WIN64
+       
+       // Slow version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); i++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                       }
+               }
+       }
+#else
+
+
+       // Fast version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+#ifdef _WIN32
+               if (nIndexOfX < 0x100000000I64)
+                       break;
+#else
+               if (nIndexOfX < 0x100000000llu)
+                       break;
+#endif
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_vCharset[j].m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                               break;
+                       }
+               }
+       }
+
+       unsigned int nIndexOfX32 = (unsigned int)nIndexOfX;
+       for (; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+
+//             m_Plain[i] = m_PlainCharset[nIndexOfX32 % m_vCharset[j].m_nPlainCharsetLen];
+//             nIndexOfX32 /= m_vCharset[j].m_nPlainCharsetLen;
+
+               unsigned int nPlainCharsetLen = m_vCharset[j].m_nPlainCharsetLen;
+               unsigned int nTemp;
+#ifdef _WIN32
+               __asm
+               {
+                       mov eax, nIndexOfX32
+                       xor edx, edx
+                       div nPlainCharsetLen
+                       mov nIndexOfX32, eax
+                       mov nTemp, edx
+               }
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#else
+               __asm__ __volatile__ (  "mov %2, %%eax;"
+                                                               "xor %%edx, %%edx;"
+                                                               "divl %3;"
+                                                               "mov %%eax, %0;"
+                                                               "mov %%edx, %1;"
+                                                               : "=m"(nIndexOfX32), "=m"(nTemp)
+                                                               : "m"(nIndexOfX32), "m"(nPlainCharsetLen)
+                                                               : "%eax", "%edx"
+                                                        );
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#endif
+               break;
+                       }
+               }
+       }
+#endif
+}
+
+void CChainWalkContext::PlainToHash()
+{      
+       m_pHashRoutine(m_Plain, m_nPlainLen, m_Hash);
+}
+
+void CChainWalkContext::HashToIndex(int nPos)
+{
+       m_nIndex = (*(uint64*)m_Hash + m_nReduceOffset + nPos) % m_nPlainSpaceTotal;
+}
+
+uint64 CChainWalkContext::GetIndex()
+{
+       return m_nIndex;
+}
+const uint64 *CChainWalkContext::GetIndexPtr()
+{
+       return &m_nIndex;
+}
+
+string CChainWalkContext::GetPlain()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < m_nPlainLen; i++)
+       {
+               char c = m_Plain[i];
+               if (c >= 32 && c <= 126)
+                       sRet += c;
+               else
+                       sRet += '?';
+       }
+       
+       return sRet;
+}
+
+string CChainWalkContext::GetBinary()
+{
+       return HexToStr(m_Plain, m_nPlainLen);
+}
+/*
+string CChainWalkContext::GetPlainBinary()
+{
+       string sRet;
+       sRet += GetPlain();
+       int i;
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += ' ';
+
+       sRet += "|";
+
+       sRet += GetBinary();
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += "  ";
+
+       return sRet;
+}
+*/
+string CChainWalkContext::GetHash()
+{
+       return HexToStr(m_Hash, m_nHashLen);
+}
+
+bool CChainWalkContext::CheckHash(unsigned char* pHash)
+{
+       if (memcmp(m_Hash, pHash, m_nHashLen) == 0)
+               return true;
+
+       return false;
+}
diff --git a/Common/rt api/ChainWalkContext.h b/Common/rt api/ChainWalkContext.h
new file mode 100644 (file)
index 0000000..de7e2fb
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKCONTEXT_H
+#define _CHAINWALKCONTEXT_H
+
+#include "HashRoutine.h"
+#include "Public.h"
+
+typedef struct 
+{
+       unsigned char m_PlainCharset[255];
+       int m_nPlainCharsetLen;
+       int m_nPlainLenMin;
+       int m_nPlainLenMax;
+       string m_sPlainCharsetName;
+       string m_sPlainCharsetContent;
+} stCharset;
+class CChainWalkContext 
+{
+public:
+       CChainWalkContext();
+       virtual ~CChainWalkContext();
+
+private:
+       static string m_sHashRoutineName;       
+       static HASHROUTINE m_pHashRoutine;                                                      // Configuration
+       static int m_nHashLen;                                                                          // Configuration
+
+//     static unsigned char m_PlainCharset[256];                                       // Configuration
+//     static unsigned char m_PlainCharset2[256];                                      // Configuration
+       static vector<stCharset> m_vCharset;
+       static int m_nPlainLenMinTotal, m_nPlainLenMaxTotal;
+       static uint64 m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];            // Performance consideration
+       static uint64 m_nPlainSpaceTotal;                                                       // Performance consideration
+       static int m_nHybridCharset;
+       static int m_nRainbowTableIndex;                                                        // Configuration
+       static uint64 m_nReduceOffset;                                                          // Performance consideration
+
+       // Context
+       uint64 m_nIndex;
+       unsigned char m_Plain[MAX_PLAIN_LEN];
+       int m_nPlainLen;
+       unsigned char m_Hash[MAX_HASH_LEN];
+       static unsigned char m_Salt[MAX_SALT_LEN];
+       static int m_nSaltLen;
+private:
+       static bool LoadCharset(string sCharset);
+
+public:
+       static bool SetHashRoutine(string sHashRoutineName);                                                                                            // Configuration
+       static bool SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax);                           // Configuration
+       static bool SetRainbowTableIndex(int nRainbowTableIndex);       
+       static bool SetSalt(unsigned char *Salt, int nSaltLength);// Configuration
+       static bool SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount);        // Wrapper
+       static string GetHashRoutineName();
+       static int GetHashLen();
+       static string GetPlainCharsetName();
+       static string GetPlainCharsetContent();
+       static int GetPlainLenMin();
+       static int GetPlainLenMax();
+       static uint64 GetPlainSpaceTotal();
+       static int GetRainbowTableIndex();
+       static void Dump();
+
+//     void GenerateRandomIndex();
+       void SetIndex(uint64 nIndex);
+       void SetHash(unsigned char* pHash);             // The length should be m_nHashLen
+
+       void IndexToPlain();
+       void PlainToHash();
+       void HashToIndex(int nPos);
+
+       uint64 GetIndex();
+       const uint64* GetIndexPtr();
+       string GetPlain();
+       string GetBinary();
+//     string GetPlainBinary();
+       string GetHash();
+       bool CheckHash(unsigned char* pHash);   // The length should be m_nHashLen
+};
+
+#endif
diff --git a/Common/rt api/ChainWalkSet.cpp b/Common/rt api/ChainWalkSet.cpp
new file mode 100644 (file)
index 0000000..a081eb8
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkSet.h"
+
+CChainWalkSet::CChainWalkSet()
+{
+       m_sHashRoutineName   = "";
+       m_sPlainCharsetName  = "";
+       m_nPlainLenMin       = 0;
+       m_nPlainLenMax       = 0;
+       m_nRainbowTableIndex = 0;
+       m_nRainbowChainLen   = 0;
+}
+
+CChainWalkSet::~CChainWalkSet()
+{
+       DiscardAll();
+}
+
+void CChainWalkSet::DiscardAll()
+{
+       //printf("debug: discarding all walk...\n");
+
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+               delete it->pIndexE;
+       m_lChainWalk.clear();
+}
+
+uint64* CChainWalkSet::RequestWalk(unsigned char* pHash, int nHashLen,
+                                                                  string sHashRoutineName,
+                                                                  string sPlainCharsetName, int nPlainLenMin, int nPlainLenMax, 
+                                                                  int nRainbowTableIndex, 
+                                                                  int nRainbowChainLen,
+                                                                  bool& fNewlyGenerated)
+{
+       if (   m_sHashRoutineName   != sHashRoutineName
+               || m_sPlainCharsetName  != sPlainCharsetName
+               || m_nPlainLenMin       != nPlainLenMin
+               || m_nPlainLenMax       != nPlainLenMax
+               || m_nRainbowTableIndex != nRainbowTableIndex
+               || m_nRainbowChainLen   != nRainbowChainLen)
+       {
+               DiscardAll();
+
+               m_sHashRoutineName   = sHashRoutineName;
+               m_sPlainCharsetName  = sPlainCharsetName;
+               m_nPlainLenMin       = nPlainLenMin;
+               m_nPlainLenMax       = nPlainLenMax;
+               m_nRainbowTableIndex = nRainbowTableIndex;
+               m_nRainbowChainLen   = nRainbowChainLen;
+
+               ChainWalk cw;
+               memcpy(cw.Hash, pHash, nHashLen);
+               cw.pIndexE = new uint64[nRainbowChainLen - 1];
+               m_lChainWalk.push_back(cw);
+
+               fNewlyGenerated = true;
+               return cw.pIndexE;
+       }
+
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+       {
+               if (memcmp(it->Hash, pHash, nHashLen) == 0)
+               {
+                       fNewlyGenerated = false;
+                       return it->pIndexE;
+               }
+       }
+
+       ChainWalk cw;
+       memcpy(cw.Hash, pHash, nHashLen);
+       cw.pIndexE = new uint64[nRainbowChainLen - 1];
+       m_lChainWalk.push_back(cw);
+
+       fNewlyGenerated = true;
+       return cw.pIndexE;
+}
+
+void CChainWalkSet::DiscardWalk(uint64* pIndexE)
+{
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+       {
+               if (it->pIndexE == pIndexE)
+               {
+                       delete it->pIndexE;
+                       m_lChainWalk.erase(it);
+                       return;
+               }
+       }
+
+       printf("debug: pIndexE not found\n");
+}
diff --git a/Common/rt api/ChainWalkSet.h b/Common/rt api/ChainWalkSet.h
new file mode 100644 (file)
index 0000000..4276894
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKSET_H
+#define _CHAINWALKSET_H
+
+#include "Public.h"
+
+struct ChainWalk
+{
+       unsigned char Hash[MAX_HASH_LEN];
+       //int nHashLen;         // Implied
+       uint64* pIndexE;        // mapStartPosIndexE, Len = nRainbowChainLen - 1
+};
+
+class CChainWalkSet
+{
+public:
+       CChainWalkSet();
+       virtual ~CChainWalkSet();
+
+private:
+       string m_sHashRoutineName;              // Discard all if not match
+       string m_sPlainCharsetName;             // Discard all if not match
+       int    m_nPlainLenMin;                  // Discard all if not match
+       int    m_nPlainLenMax;                  // Discard all if not match
+       int    m_nRainbowTableIndex;    // Discard all if not match
+       int    m_nRainbowChainLen;              // Discard all if not match
+       list<ChainWalk> m_lChainWalk;
+
+private:
+       void DiscardAll();
+
+public:
+       uint64* RequestWalk(unsigned char* pHash, int nHashLen,
+                                               string sHashRoutineName,
+                                               string sPlainCharsetName, int nPlainLenMin, int nPlainLenMax, 
+                                               int nRainbowTableIndex, 
+                                               int nRainbowChainLen,
+                                               bool& fNewlyGenerated);
+       void DiscardWalk(uint64* pIndexE);
+};
+
+#endif
diff --git a/Common/rt api/HashAlgorithm.cpp b/Common/rt api/HashAlgorithm.cpp
new file mode 100644 (file)
index 0000000..909f79c
--- /dev/null
@@ -0,0 +1,357 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "HashAlgorithm.h"
+
+#include "Public.h"
+#include <string.h>
+#include "md4.h"
+#include "md5.h"
+#include "des.h"
+#define MSCACHE_HASH_SIZE 16
+void setup_des_key(unsigned char key_56[], des_key_schedule &ks)
+{
+       des_cblock key;
+
+       key[0] = key_56[0];
+       key[1] = (key_56[0] << 7) | (key_56[1] >> 1);
+       key[2] = (key_56[1] << 6) | (key_56[2] >> 2);
+       key[3] = (key_56[2] << 5) | (key_56[3] >> 3);
+       key[4] = (key_56[3] << 4) | (key_56[4] >> 4);
+       key[5] = (key_56[4] << 3) | (key_56[5] >> 5);
+       key[6] = (key_56[5] << 2) | (key_56[6] >> 6);
+       key[7] = (key_56[6] << 1);
+
+       //des_set_odd_parity(&key);
+       des_set_key(&key, ks);
+}
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       /*
+       unsigned char data[7] = {0};
+       memcpy(data, pPlain, nPlainLen > 7 ? 7 : nPlainLen);
+       */
+
+       int i;
+       for (i = nPlainLen; i < 7; i++)
+               pPlain[i] = 0;
+
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       des_key_schedule ks;
+       //setup_des_key(data, ks);
+       setup_des_key(pPlain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pHash, ks, DES_ENCRYPT);
+}
+
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char pass[14];
+       unsigned char pre_lmresp[21];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+       des_key_schedule ks;
+
+       memset (pass,0,sizeof(pass));
+       memset (pre_lmresp,0,sizeof(pre_lmresp));
+
+       memcpy (pass,pPlain, nPlainLen);
+
+       setup_des_key(pass, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(&pass[7], ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)&pre_lmresp[8], ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[7], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[14], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+
+} 
+
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{      
+       unsigned char pre_lmresp[8];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char salt[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+       des_key_schedule ks;
+       unsigned char plain[8] = {0};   
+       memcpy(plain, pPlain, nPlainLen);
+       setup_des_key(plain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)salt, (des_cblock*)pHash, ks, DES_ENCRYPT);
+} 
+
+
+
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+  unsigned char UnicodePlain[MAX_PLAIN_LEN];
+  static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+  
+  int len = (nPlainLen < 127) ? nPlainLen : 127;
+  int i;
+  
+  for (i = 0; i < len; i++)
+  {
+    UnicodePlain[i * 2] = pPlain[i];
+    UnicodePlain[i * 2 + 1] = 0x00;
+  }
+
+  des_key_schedule ks;
+  unsigned char lm[21];
+
+  MD4_NEW(UnicodePlain, len * 2, lm);
+  lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
+
+  setup_des_key(lm, ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[7], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[14], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+}
+
+/*
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char ToEncrypt[256];
+       char temp[256];
+       char username[256];
+
+       DES_cblock iv,iv2;
+       DES_key_schedule ks1,ks2;
+       unsigned char deskey_fixed[]={ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
+       int i,j;
+#ifdef _WIN32
+       strcpy_s(username, sizeof(username), "SYS");
+#else
+       strcpy(username, "SYS");
+#endif
+       int userlen = 3;
+#ifdef _WIN32
+       _strupr((char*) pPlain);
+#else
+       strupr((char*) pPlain);
+#endif
+       memset (ToEncrypt,0,sizeof(ToEncrypt));
+
+       for (i=1,j=0; j<userlen; i++,j++)
+       {
+               ToEncrypt[i] = username[j];
+               i++;
+       }
+
+       for (j=0; j<nPlainLen; i++,j++)
+       {
+               ToEncrypt[i] = pPlain[j];
+               i++;
+       }
+
+       i=i-1;
+       memset (iv,0,8);
+       memset (iv2,0,8);
+       DES_set_key((DES_cblock*) deskey_fixed, &ks1);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks1, &iv, DES_ENCRYPT);
+       DES_set_key((DES_cblock*) &iv, &ks2);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks2, &iv2, DES_ENCRYPT);
+       memcpy (pHash,iv2,8);
+}
+*/
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char UnicodePlain[MAX_PLAIN_LEN * 2];
+       int i;
+       for (i = 0; i < nPlainLen; i++)
+       {
+               UnicodePlain[i * 2] = pPlain[i];
+               UnicodePlain[i * 2 + 1] = 0x00;
+       }
+
+       MD4_NEW(UnicodePlain, nPlainLen * 2, pHash);
+}
+/*
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD2(pPlain, nPlainLen, pHash);
+}
+*/
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD4_NEW(pPlain, nPlainLen, pHash);
+}
+
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5_NEW(pPlain, nPlainLen, pHash);
+}
+void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5_NEW(pPlain, nPlainLen, pHash);
+       unsigned char hash[16];
+       memcpy(hash, pHash, 16);
+       MD5_NEW(hash, 16, pHash);
+}
+/*
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       SHA1(pPlain, nPlainLen, pHash);
+}
+
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       RIPEMD160(pPlain, nPlainLen, pHash);
+}
+
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char unicode_pwd[256];
+       char unicode_user[256];
+       static unsigned char username[] = "administrator";
+       static int userlen = 13;
+       unsigned char   final1[MD4_DIGEST_LENGTH];
+       MD4_CTX ctx;
+       int i;
+
+//     strcpy (username, "administrator");
+//     userlen = 13;
+
+       for (i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }
+
+       for (i=0; i<userlen; i++)
+       {
+               unicode_user[i*2] = username[i];
+               unicode_user[i*2+1] = 0x00;
+       }
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,unicode_pwd,nPlainLen*2);
+       MD4_Final(final1,&ctx);
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,final1,MD4_DIGEST_LENGTH);
+       MD4_Update(&ctx,(unsigned char*) unicode_user,userlen*2);
+       MD4_Final(pHash,&ctx);
+
+       /*
+       unsigned char unicode_pwd[256];
+       for (int i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }*/     
+       /*
+       unsigned char *buf = (unsigned char*)calloc(MSCACHE_HASH_SIZE + nSaltLength, sizeof(unsigned char));    
+       HashNTLM(pPlain, nPlainLen, buf, NULL);
+       //MD4(unicode_pwd, nPlainLen*2, buf);
+       memcpy(buf + MSCACHE_HASH_SIZE, pSalt, nSaltLength);
+       MD4(buf, MSCACHE_HASH_SIZE + nSaltLength, pHash); 
+       free(buf);
+       */
+//}
+
+//*********************************************************************************
+// Code for MySQL password hashing
+//*********************************************************************************
+/*
+inline void mysql_hash_password_323(unsigned long *result, const char *password) 
+{
+  register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
+  unsigned long tmp;
+  for (; *password ; password++) 
+  {
+    if (*password == ' ' || *password == '\t') continue;
+       tmp= (unsigned long) (unsigned char) *password;
+       nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
+       nr2+=(nr2 << 8) ^ nr;
+       add+=tmp;
+  }
+  result[0]=nr & (((unsigned long) 1L << 31) -1L); ;
+  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
+  return;
+}
+
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned long hash_pass[2];     
+       unsigned char* f = (unsigned char*) hash_pass;
+
+       unsigned char* pass = (unsigned char*) calloc (nPlainLen+4,sizeof(unsigned char));
+       memcpy(pass,pPlain,nPlainLen);
+
+       mysql_hash_password_323(hash_pass, (char*) pass);
+       pHash[0]=*(f+3); pHash[1]=*(f+2); pHash[2]=*(f+1); pHash[3]=*(f+0);
+       pHash[4]=*(f+7); pHash[5]=*(f+6); pHash[6]=*(f+5); pHash[7]=*(f+4);
+
+       free (pass);
+}
+
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char hash_stage1[SHA_DIGEST_LENGTH];
+       SHA_CTX ctx;
+
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, (unsigned char *) pPlain, nPlainLen);
+       SHA1_Final(hash_stage1, &ctx);
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, hash_stage1, SHA_DIGEST_LENGTH);
+       SHA1_Final(pHash, &ctx);
+}
+*/
+//*********************************************************************************
+// Code for PIX password hashing
+//*********************************************************************************
+static char itoa64[] =          /* 0 ... 63 => ascii - 64 */
+        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void _crypt_to64(char *s, unsigned long v, int n)
+{
+        while (--n >= 0) {
+                *s++ = itoa64[v&0x3f];
+                v >>= 6;
+        }
+}
+/*
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char temp[MD5_DIGEST_LENGTH+1];
+       unsigned char final[MD5_DIGEST_LENGTH];
+       char* pass = (char*) calloc (nPlainLen+MD5_DIGEST_LENGTH,sizeof(char));
+
+       memcpy (pass,pPlain,nPlainLen);
+
+       MD5_CTX ctx;
+       MD5_Init(&ctx);
+       MD5_Update(&ctx, (unsigned char *) pass, MD5_DIGEST_LENGTH);
+       MD5_Final(final, &ctx);
+
+       char* p = (char*) temp;
+       _crypt_to64(p,*(unsigned long*) (final+0),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+4),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+8),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+12),4); p += 4;
+       *p=0;
+
+       memcpy(pHash,temp,MD5_DIGEST_LENGTH);
+
+       free (pass);
+}
+*/
diff --git a/Common/rt api/HashAlgorithm.h b/Common/rt api/HashAlgorithm.h
new file mode 100644 (file)
index 0000000..667245a
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHALGORITHM_H
+#define _HASHALGORITHM_H
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+//void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+/*void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash);
+//****************************************************************************
+// MySQL Password Hashing
+//****************************************************************************
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// Cisco PIX Password Hashing
+//****************************************************************************
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+*/
+//****************************************************************************
+// (HALF) LM CHALL hashing
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+// From mao
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+//void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+#endif
diff --git a/Common/rt api/HashRoutine.cpp b/Common/rt api/HashRoutine.cpp
new file mode 100644 (file)
index 0000000..496f399
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "HashRoutine.h"
+#include "HashAlgorithm.h"
+
+//////////////////////////////////////////////////////////////////////
+
+CHashRoutine::CHashRoutine()
+{
+       // Notice: MIN_HASH_LEN <= nHashLen <= MAX_HASH_LEN
+
+
+       AddHashRoutine("lm",   HashLM,   8);
+       AddHashRoutine("ntlm", HashNTLM, 16);
+//     AddHashRoutine("md2",  HashMD2,  16);
+       AddHashRoutine("md4",  HashMD4,  16);
+       AddHashRoutine("md5",  HashMD5,  16);
+       AddHashRoutine("doublemd5",  HashDoubleMD5,  16);
+/*     AddHashRoutine("sha1", HashSHA1, 20);
+       AddHashRoutine("ripemd160", HashRIPEMD160, 20);
+       AddHashRoutine("mysql323", HashMySQL323, 8);
+       AddHashRoutine("mysqlsha1", HashMySQLSHA1, 20);
+       AddHashRoutine("ciscopix", HashPIX, 16);*/
+//     AddHashRoutine("mscache", HashMSCACHE, 16);
+       AddHashRoutine("halflmchall", HashHALFLMCHALL, 8);
+
+       // Added from mao
+       AddHashRoutine("lmchall", HashLMCHALL, 24);
+       AddHashRoutine("ntlmchall", HashNTLMCHALL, 24);
+//     AddHashRoutine("oracle", HashORACLE, 8);
+
+}
+
+CHashRoutine::~CHashRoutine()
+{
+}
+
+void CHashRoutine::AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen)
+{
+       vHashRoutineName.push_back(sHashRoutineName);
+       vHashRoutine.push_back(pHashRoutine);
+       vHashLen.push_back(nHashLen);
+}
+
+string CHashRoutine::GetAllHashRoutineName()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+               sRet += vHashRoutineName[i] + " ";
+
+       return sRet;
+}
+
+void CHashRoutine::GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+       {
+               if (sHashRoutineName == vHashRoutineName[i])
+               {
+                       pHashRoutine = vHashRoutine[i];
+                       nHashLen = vHashLen[i];
+                       return;
+               }
+       }
+
+       pHashRoutine = NULL;
+       nHashLen = 0;
+}
diff --git a/Common/rt api/HashRoutine.h b/Common/rt api/HashRoutine.h
new file mode 100644 (file)
index 0000000..681fa78
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHROUTINE_H
+#define _HASHROUTINE_H
+
+#include <string>
+#include <vector>
+using namespace std;
+
+typedef void (*HASHROUTINE)(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+class CHashRoutine  
+{
+public:
+       CHashRoutine();
+       virtual ~CHashRoutine();
+
+private:
+       vector<string>          vHashRoutineName;
+       vector<HASHROUTINE>     vHashRoutine;
+       vector<int>                     vHashLen;
+       void AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen);
+
+public:
+       string GetAllHashRoutineName();
+       void GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen);
+};
+
+#endif
diff --git a/Common/rt api/MemoryPool.cpp b/Common/rt api/MemoryPool.cpp
new file mode 100644 (file)
index 0000000..1019b4f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "MemoryPool.h"
+#include "Public.h"
+
+CMemoryPool::CMemoryPool()
+{
+       m_pMem = NULL;
+       m_nMemSize = 0;
+
+       unsigned int nAvailPhys = GetAvailPhysMemorySize();
+       if (nAvailPhys < 16 * 1024 * 1024)
+       {
+               nAvailPhys = 512 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize()
+       }
+       if (nAvailPhys < 16 * 1024 * 1024)
+               m_nMemMax = nAvailPhys / 2;                                     // Leave some memory for CChainWalkSet
+       else
+               m_nMemMax = nAvailPhys - 8 * 1024 * 1024;       // Leave some memory for CChainWalkSet  
+}
+
+CMemoryPool::~CMemoryPool()
+{
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+}
+
+unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
+{
+       if (nFileLen <= m_nMemSize)
+       {
+               nAllocatedSize = nFileLen;
+               return m_pMem;
+       }
+
+       unsigned int nTargetSize;
+       if (nFileLen < m_nMemMax)
+               nTargetSize = nFileLen;
+       else
+               nTargetSize = m_nMemMax;
+
+       // Free existing memory
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+
+       // Allocate new memory
+       //printf("allocating %u bytes memory\n", nTargetSize);
+//     m_pMem = new unsigned char[nTargetSize];
+m_pMem = new (nothrow) unsigned char[nTargetSize];
+while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 )
+{
+   nTargetSize -= 16 * 1024 * 1024;
+   m_pMem = new (nothrow) unsigned char[nTargetSize];
+}
+       if (m_pMem != NULL)
+       {
+               m_nMemSize = nTargetSize;
+               nAllocatedSize = nTargetSize;
+               return m_pMem;
+       }
+       else
+       {
+               nAllocatedSize = 0;
+               return NULL;
+       }
+}
diff --git a/Common/rt api/MemoryPool.h b/Common/rt api/MemoryPool.h
new file mode 100644 (file)
index 0000000..9f2ea4e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _MEMORYPOOL_H
+#define _MEMORYPOOL_H
+
+class CMemoryPool  
+{
+public:
+       CMemoryPool();
+       virtual ~CMemoryPool();
+
+private:
+       unsigned char* m_pMem;
+       unsigned int m_nMemSize;
+
+       unsigned int m_nMemMax;
+
+public:
+       unsigned char* Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize);
+};
+
+#endif
diff --git a/Common/rt api/Public.cpp b/Common/rt api/Public.cpp
new file mode 100644 (file)
index 0000000..60d7072
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#ifdef _WIN32
+#include "boinc_win.h"
+#else
+#include "config.h"
+#include <cstdio>
+#include <cctype>
+#include <ctime>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+#include <unistd.h>
+
+#endif
+#include "filesys.h"
+#include "boinc_api.h"
+
+#include "Public.h"
+
+#ifdef _WIN32
+       #include <windows.h>
+#else
+       #include <sys/sysinfo.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+unsigned int GetFileLen(FILE* file)
+{
+       unsigned int pos = ftell(file);
+       fseek(file, 0, SEEK_END);
+       unsigned int len = ftell(file);
+       fseek(file, pos, SEEK_SET);
+
+       return len;
+}
+
+string TrimString(string s)
+{
+       while (s.size() > 0)
+       {
+               if (s[0] == ' ' || s[0] == '\t')
+                       s = s.substr(1);
+               else
+                       break;
+       }
+
+       while (s.size() > 0)
+       {
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+                       s = s.substr(0, s.size() - 1);
+               else
+                       break;
+       }
+
+       return s;
+}
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+       // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+       if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+               return false;
+       size_t nEnd = sCharset.rfind(')');
+       size_t nStart = sCharset.rfind('(');
+       string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+       vector<string> vParts;
+       SeperateString(sChar, ",", vParts);
+       for(int i = 0; i < vParts.size(); i++)
+       {
+               tCharset stCharset;
+               vector<string> vParts2;
+               SeperateString(vParts[i], "#", vParts2);
+               stCharset.sName = vParts2[0];
+               vector<string> vParts3;
+               SeperateString(vParts2[1], "-", vParts3);
+               stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+               stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+               vCharset.push_back(stCharset);
+       }
+       return true;
+}
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+    char input_path[512];
+    boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
+    FILE *file = boinc_fopen(input_path, "rb");
+    if (!file) {
+        fprintf(stderr,
+            "Couldn't find input file, resolved name %s.\n", input_path
+        );
+        exit(-1);
+    }
+       if (file != NULL)
+       {
+               unsigned int len = GetFileLen(file);
+               char* data = new char[len + 1];
+               fread(data, 1, len, file);
+               data[len] = '\0';
+               string content = data;
+               content += "\n";
+               delete data;
+
+               unsigned int i;
+               for (i = 0; i < content.size(); i++)
+               {
+                       if (content[i] == '\r')
+                               content[i] = '\n';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       string line = content.substr(0, n);
+                       line = TrimString(line);
+                       if (line != "")
+                               vLine.push_back(line);
+                       content = content.substr(n + 1);
+               }
+
+               fclose(file);
+       }
+       else
+               return false;
+
+       return true;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+       vPart.clear();
+
+       unsigned int i;
+       for (i = 0; i < sSeperator.size(); i++)
+       {
+               int n = s.find(sSeperator[i]);
+               if (n != -1)
+               {
+                       vPart.push_back(s.substr(0, n));
+                       s = s.substr(n + 1);
+               }
+               else
+                       return false;
+       }
+       vPart.push_back(s);
+
+       return true;
+}
+
+string uint64tostr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%I64u", n);
+#else
+       sprintf(str, "%llu", n);
+#endif
+
+       return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%016I64x", n);
+#else
+       sprintf(str, "%016llx", n);
+#endif
+
+       return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+       string sRet;
+       int i;
+       for (i = 0; i < nLen; i++)
+       {
+               char szByte[3];
+               sprintf(szByte, "%02x", pData[i]);
+               sRet += szByte;
+       }
+
+       return sRet;
+}
+
+unsigned int GetAvailPhysMemorySize()
+{
+#ifdef _WIN32
+               MEMORYSTATUS ms;
+               GlobalMemoryStatus(&ms);
+               return ms.dwAvailPhys;
+#else
+       struct sysinfo info;
+       sysinfo(&info);                 // This function is Linux-specific
+       return info.freeram;
+#endif
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < sHash.size() / 2; i++)
+       {
+               string sSub = sHash.substr(i * 2, 2);
+               int nValue;
+               sscanf(sSub.c_str(), "%02x", &nValue);
+               pHash[i] = (unsigned char)nValue;
+       }
+
+       nHashLen = sHash.size() / 2;
+}
+
+void Logo()
+{
+       printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+       printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+       printf("http://www.freerainbowtables.com/\n");
+       printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+       printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
diff --git a/Common/rt api/Public.h b/Common/rt api/Public.h
new file mode 100644 (file)
index 0000000..a2f5657
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _PUBLIC_H
+#define _PUBLIC_H
+
+#include <stdio.h>
+
+#include <string>
+#include <vector>
+#include <list>
+using namespace std;
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 u_int64_t
+#endif
+
+struct RainbowChain
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+};
+
+struct RainbowChainCP
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+       unsigned short nCheckPoint;
+};
+struct IndexChain
+{
+       uint64 nPrefix;
+       int nFirstChain;
+       unsigned int nChainCount;
+};
+struct FoundRainbowChain
+{
+       uint64 nIndexS;
+       int nIndexE;
+       int nCheckPoint;
+       int nGuessedPos;
+};
+struct ChainCheckChain
+{
+       uint64 nIndexS;
+       int nGuessedPos;
+};
+struct IndexRow
+{
+       uint64 prefix;
+       unsigned int prefixstart, numchains;
+};
+
+typedef struct
+{
+       string sName;
+       int nPlainLenMin;
+       int nPlainLenMax;
+} tCharset;
+
+#define MAX_PLAIN_LEN 256
+#define MIN_HASH_LEN  8
+#define MAX_HASH_LEN  256
+#define MAX_SALT_LEN  256
+
+unsigned int GetFileLen(FILE* file);
+string TrimString(string s);
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine);
+bool SeperateString(string s, string sSeperator, vector<string>& vPart);
+string uint64tostr(uint64 n);
+string uint64tohexstr(uint64 n);
+string HexToStr(const unsigned char* pData, int nLen);
+unsigned int GetAvailPhysMemorySize();
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen);
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset);
+void Logo();
+
+#endif
diff --git a/Common/rt api/RTI2Reader.cpp b/Common/rt api/RTI2Reader.cpp
new file mode 100644 (file)
index 0000000..443fd1c
--- /dev/null
@@ -0,0 +1,125 @@
+#include "RTI2Reader.h"
+
+#include <math.h>
+RTI2Header *RTI2Reader::m_pHeader = NULL;
+RTI2Reader::RTI2Reader(string Filename)
+{
+       //m_pIndexPos = NULL, m_pChainPos = NULL;;
+       m_pIndex = NULL;
+       m_pFile = fopen(Filename.c_str(), "rb");
+       if(m_pFile == NULL)
+       {
+               printf("Unable to open file %s", Filename.c_str());
+               exit(1);
+       }
+       FILE *pFileIndex = fopen(Filename.append(".index").c_str(), "rb");
+       if(pFileIndex == NULL)
+       {
+               printf("Unable to open file %s", Filename.append(".index").c_str());
+               exit(1);
+       }
+       m_chainPosition = 0;
+
+       unsigned int len = GetFileLen(pFileIndex);
+       fseek(pFileIndex, 0, SEEK_SET);
+
+       m_pIndex = new unsigned char[len];
+       if(fread(m_pIndex, 1, len, pFileIndex) != len)
+       {
+               printf("Error while reading index file");
+               exit(1);
+       }
+       fclose(pFileIndex);
+       m_pHeader = new RTI2Header();   
+       memcpy(m_pHeader, m_pIndex, sizeof(RTI2Header));
+       m_pHeader->m_cppos = (unsigned int*)(m_pIndex + 8);
+       m_pHeader->prefixstart = *(uint64*)(m_pIndex + 8 + (m_pHeader->rti_cplength * 4));
+       m_chainsizebytes = ceil((float)(m_pHeader->rti_startptlength + m_pHeader->rti_endptlength + m_pHeader->rti_cplength) / 8); // Get the size of each chain in bytes
+       m_indexrowsizebytes = ceil((float)m_pHeader->rti_index_numchainslength / 8);
+       // Check the filesize
+       fseek(m_pFile, 0, SEEK_END);
+       len = ftell(m_pFile);
+       fseek(m_pFile, 0, SEEK_SET);
+       if(len % m_chainsizebytes > 0)
+       {
+               printf("Invalid filesize %u\n", len);
+               return;
+       }
+       
+
+}
+
+RTI2Reader::~RTI2Reader(void)
+{
+       if(m_pIndex != NULL) delete m_pIndex;
+       if(m_pFile != NULL) fclose(m_pFile);
+
+}
+
+unsigned int RTI2Reader::GetChainsLeft()
+{
+       int len = GetFileLen(m_pFile);
+       return len / m_chainsizebytes - m_chainPosition;
+}
+
+int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChainCP *pData)
+{
+       if(strncmp(m_pHeader->header, "RTI2", 4) != 0)
+       {
+               numChains = 0;
+               return -1;
+       }
+       unsigned char *pNumChains = m_pIndex + (m_pHeader->rti_cplength * 4) + 16; // Pointer into the index containing info about how many numbers are in the first chain prefix
+       unsigned int i = 0;
+       unsigned int indexRow = 0; // Current offset into the index
+       unsigned int curRowPosition = 0;
+       
+       while(true) // Fast forward to current position
+       {
+               // ALERT: Possible problem here if m_indexrowsizebytes > 1 as pNumChains is a unsigned char.
+               unsigned int NumChainsInRow = (unsigned int)*(pNumChains + indexRow * m_indexrowsizebytes);
+               if(m_indexrowsizebytes > 1)     { printf("Have to find a solution to this problem"); exit(2);}
+               if(i + NumChainsInRow > m_chainPosition)
+               {
+                       curRowPosition = m_chainPosition - i;
+                       break; // The current position is somewhere within this prefix
+               }
+               indexRow++;             
+               i += NumChainsInRow;
+       }
+       
+       uint64 chainrow = 0; // Buffer to store a single read chain
+       unsigned int chainsProcessed = 0; // Number of chains processed
+
+       // ALERT: same problem with unsigned char here.
+       unsigned int NumChainsInRow = *(pNumChains + indexRow);
+       while(chainsProcessed < numChains && fread(&chainrow, 1, m_chainsizebytes, m_pFile) == m_chainsizebytes)
+       {
+               if(curRowPosition >= NumChainsInRow)
+               { // Skip to next index row position
+                       indexRow++;
+                       curRowPosition = 0;
+                       NumChainsInRow = *(pNumChains + indexRow);
+               }
+               while(NumChainsInRow == 0) // We skip forward until we hit a index with > 0 chains
+               {
+                       indexRow++;
+                       NumChainsInRow = *(pNumChains + indexRow);
+                       curRowPosition = 0;
+               }
+               // Load the starting point from the data
+               pData[chainsProcessed].nIndexS = chainrow << 64 - m_pHeader->rti_startptlength;
+               pData[chainsProcessed].nIndexS = pData[chainsProcessed].nIndexS >> 64 - m_pHeader->rti_startptlength;
+
+               // Load the ending point prefix 
+               pData[chainsProcessed].nIndexE = m_pHeader->prefixstart + indexRow << m_pHeader->rti_endptlength;
+               // Append the ending point suffix
+               pData[chainsProcessed].nIndexE |= (chainrow & (0xFFFFFFFFFFFFFFFF >> m_pHeader->rti_cplength)) >> m_pHeader->rti_startptlength;
+               pData[chainsProcessed].nCheckPoint = (chainrow >> m_pHeader->rti_startptlength + m_pHeader->rti_endptlength);
+               curRowPosition++;
+               chainsProcessed++;
+       }
+       numChains = chainsProcessed;
+       m_chainPosition += numChains;
+       return 0;
+}
diff --git a/Common/rt api/RTI2Reader.h b/Common/rt api/RTI2Reader.h
new file mode 100644 (file)
index 0000000..fb17dd8
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef __RTI2READER_H__
+#define __RTI2READER_H__
+
+#include "Public.h"
+#include <string>
+#ifdef WIN32
+#include <io.h>
+#endif
+#include <vector>
+#include "BaseRTReader.h"
+using namespace std;
+
+typedef struct 
+{
+       char header[4];
+       unsigned char rti_startptlength, rti_endptlength, rti_cplength, rti_index_numchainslength;
+       uint64 prefixstart;
+       unsigned int *m_cppos;
+} RTI2Header;
+
+class RTI2Reader : BaseRTReader
+{
+private:
+       FILE *m_pFile;
+       unsigned int m_chainPosition;
+       unsigned char *m_pPos, *m_pChainPos;
+       static RTI2Header *m_pHeader;
+       unsigned char *m_pIndex;
+       unsigned int m_chainsizebytes;
+       unsigned int m_indexrowsizebytes;
+       
+
+public:
+       RTI2Reader(string Filename);
+       ~RTI2Reader(void);
+       int ReadChains(unsigned int &numChains, RainbowChainCP *pData);
+       unsigned int GetChainsLeft();
+       static RTI2Header *GetHeader() { return m_pHeader; }
+};
+
+
+#endif
diff --git a/Common/rt api/RTIReader.cpp b/Common/rt api/RTIReader.cpp
new file mode 100644 (file)
index 0000000..d96edc3
--- /dev/null
@@ -0,0 +1,110 @@
+#include "RTIReader.h"
+
+RTIReader::RTIReader(string Filename)
+{
+       m_pIndex = NULL;
+       m_pFile = fopen(Filename.c_str(), "rb");
+       FILE *pFileIndex = fopen(Filename.append(".index").c_str(), "rb");
+       m_chainPosition = 0;
+
+       // Load the index file
+       unsigned int nIndexFileLen = GetFileLen(pFileIndex);
+       unsigned int nFileLen = GetFileLen(m_pFile);
+       unsigned int nTotalChainCount = nFileLen / 8;
+       if (nFileLen % 8 != 0)
+               printf("file length mismatch (%u bytes)\n", nFileLen);
+       else
+       {
+               // File length check
+               if (nIndexFileLen % 11 != 0)
+                       printf("index file length mismatch (%u bytes)\n", nIndexFileLen);
+               else
+               {
+                       m_pIndex = new IndexChain[nIndexFileLen / 11];
+                       memset(m_pIndex, 0x00, sizeof(IndexChain) * (nIndexFileLen / 11));
+                       fseek(pFileIndex, 0, SEEK_SET);
+                       int nRead = 0;
+                       int nRows;
+                       for(nRows = 0; (nRows * 11) < nIndexFileLen; nRows++)
+                       {
+                               if(fread(&m_pIndex[nRows].nPrefix, 5, 1, pFileIndex) != 1) break;                                                       
+                               if(fread(&m_pIndex[nRows].nFirstChain, 4, 1, pFileIndex) != 1) break;                                                   
+                               if(fread(&m_pIndex[nRows].nChainCount, 2, 1, pFileIndex) != 1) break;                                                   
+                               // Index checking part
+                               if(nRows != 0 && m_pIndex[nRows].nFirstChain < m_pIndex[nRows-1].nFirstChain)
+                               {
+                                       printf("Corrupted index detected (FirstChain is lower than previous)\n");
+                                       exit(-1);
+                               }
+                               else if(nRows != 0 && m_pIndex[nRows].nFirstChain != m_pIndex[nRows-1].nFirstChain + m_pIndex[nRows-1].nChainCount)
+                               {
+                                       printf("Corrupted index detected (LastChain + nChainCount != FirstChain)\n");
+                                       exit(-1);
+                               }
+                               
+                       }
+                       m_nIndexSize = nRows;
+                       if(m_pIndex[m_nIndexSize - 1].nFirstChain + m_pIndex[m_nIndexSize - 1].nChainCount + 1 <= nTotalChainCount) // +1 is needed.
+                       {
+                               printf("Corrupted index detected: Not covering the entire file\n");
+                               exit(-1);
+                       }
+                       if(m_pIndex[m_nIndexSize - 1].nFirstChain + m_pIndex[m_nIndexSize - 1].nChainCount > nTotalChainCount) // +1 is not needed here
+                       {
+                               printf("Corrupted index detected: The index is covering more than the file\n");
+                               exit(-1);
+                       }
+
+       /*                                      if(nIndexSize != pIndex[i].nFirstChain + pIndex[i].nChainCount)
+                       {
+                               printf("Index is not covering the entire tables\n");
+                       }*/
+                       fclose(pFileIndex);             
+       //                                      printf("debug: Index loaded successfully (%u entries)\n", nIndexSize);
+               }               
+       }
+
+
+}
+
+int RTIReader::ReadChains(unsigned int &numChains, RainbowChainCP *pData)
+{      
+       // We HAVE to reset the data to 0x00's or we will get in trouble
+       memset(pData, 0x00, sizeof(RainbowChainCP) * numChains);
+       unsigned int readChains = 0;
+       unsigned int chainsleft = GetChainsLeft();
+       for(int i = 0; i < m_nIndexSize; i++)
+       {
+               if(m_chainPosition + readChains > m_pIndex[i].nFirstChain + m_pIndex[i].nChainCount) // We found the matching index
+                       continue;
+               while(m_chainPosition + readChains < m_pIndex[i].nFirstChain + m_pIndex[i].nChainCount)
+               {
+                       pData[readChains].nIndexE = m_pIndex[i].nPrefix << 16;
+                       int endpoint = 0; // We have to set it to 0
+                       fread(&pData[readChains].nIndexS, 6, 1, m_pFile);
+                       fread(&endpoint, 2, 1, m_pFile);
+                       pData[readChains].nIndexE += endpoint;
+                       readChains++;
+                       if(readChains == numChains || readChains == chainsleft) break;
+               }
+               if(readChains == numChains) break;              
+       }
+       if(readChains != numChains) numChains = readChains; // Update how many chains we read
+       m_chainPosition += readChains;
+       return 0;
+}
+
+unsigned int RTIReader::GetChainsLeft()
+{
+       int len = GetFileLen(m_pFile) / 8 - m_chainPosition;
+       return len;
+}
+
+RTIReader::~RTIReader(void)
+{
+       if(m_pIndex != NULL)
+               delete m_pIndex;
+       if(m_pFile != NULL)
+               fclose(m_pFile);
+
+}
diff --git a/Common/rt api/RTIReader.h b/Common/rt api/RTIReader.h
new file mode 100644 (file)
index 0000000..6d53e80
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __RTIREADER_H__
+#define __RTIREADER_H__
+
+#include <string>
+#ifdef WIN32
+#include <io.h>
+#endif
+#include "Public.h"
+#include "BaseRTReader.h"
+using namespace std;
+
+class RTIReader : BaseRTReader
+{
+private:
+       FILE *m_pFile;
+       unsigned int m_chainPosition;
+       unsigned int m_nIndexSize;
+       IndexChain *m_pIndex;
+public:
+       RTIReader(string Filename);
+       ~RTIReader(void);
+
+       int ReadChains(unsigned int &numChains, RainbowChainCP *pData);
+       unsigned int GetChainsLeft();
+
+};
+
+#endif
diff --git a/Common/rt api/RTReader.cpp b/Common/rt api/RTReader.cpp
new file mode 100644 (file)
index 0000000..b0de54e
--- /dev/null
@@ -0,0 +1,22 @@
+#include "RTReader.h"
+
+RTReader::RTReader(string Filename)
+{
+       m_pFile = fopen(Filename.c_str(), "rb");
+}
+
+RTReader::~RTReader(void)
+{
+}
+
+int RTReader::ReadChains(unsigned int &numChains, RainbowChainCP *pData)
+{
+       unsigned int numRead = fread(pData, 1, 16 * numChains, m_pFile);
+       numChains = numRead / 16;
+       return 0;
+}
+unsigned int RTReader::GetChainsLeft()
+{
+       unsigned int len = GetFileLen(m_pFile);
+       return len / 16 - m_chainPosition;
+}
diff --git a/Common/rt api/RTReader.h b/Common/rt api/RTReader.h
new file mode 100644 (file)
index 0000000..3d189c3
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __RTREADER_H__
+#define __RTREADER_H__
+
+#include <string>
+#ifdef WIN32
+#include <io.h>
+#endif
+#include "Public.h"
+#include "BaseRTReader.h"
+using namespace std;
+
+class RTReader : BaseRTReader
+{
+private:
+       FILE *m_pFile;
+       unsigned int m_chainPosition;
+
+public:
+       RTReader(string Filename);
+       ~RTReader(void);
+       int ReadChains(unsigned int &numChains, RainbowChainCP *pData);
+       unsigned int GetChainsLeft();
+
+};
+
+#endif
diff --git a/Common/rt api/des.h b/Common/rt api/des.h
new file mode 100644 (file)
index 0000000..abe1401
--- /dev/null
@@ -0,0 +1,118 @@
+/*     $FreeBSD: src/sys/crypto/des/des.h,v 1.6 2002/03/20 05:13:51 alfred Exp $       */
+/*     $KAME: des.h,v 1.8 2001/09/10 04:03:57 itojun Exp $     */
+
+/* lib/des/des.h */
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_DES_H
+#define HEADER_DES_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+typedef unsigned int u_int32_t;
+
+/* must be 32bit quantity */
+#define DES_LONG u_int32_t
+
+typedef unsigned char des_cblock[8];
+typedef struct des_ks_struct
+       {
+       union   {
+       des_cblock cblock;
+       /* make sure things are correct size on machines with
+        * 8 byte longs */
+       DES_LONG deslong[2];
+       } ks;
+       int weak_key;
+} des_key_schedule[16];
+
+#define DES_KEY_SZ     (sizeof(des_cblock))
+#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
+
+#define DES_ENCRYPT    1
+#define DES_DECRYPT    0
+
+#define DES_CBC_MODE   0
+#define DES_PCBC_MODE  1
+
+extern int des_check_key;      /* defaults to false */
+
+char *des_options(void);
+void des_ecb_encrypt(des_cblock *, des_cblock *, des_key_schedule, int);
+
+void des_encrypt1(DES_LONG *, des_key_schedule, int);
+void des_encrypt2(DES_LONG *, des_key_schedule, int);
+void des_encrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
+                     des_key_schedule);
+void des_decrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
+                     des_key_schedule);
+
+void des_ecb3_encrypt(des_cblock *, des_cblock *, des_key_schedule, 
+                         des_key_schedule, des_key_schedule, int);
+
+void des_ncbc_encrypt(const unsigned char *, unsigned char *, long,
+                         des_key_schedule, des_cblock *, int);
+
+void des_ede3_cbc_encrypt(const unsigned char *, unsigned char *, long,
+                         des_key_schedule, des_key_schedule, 
+                         des_key_schedule, des_cblock *, int);
+
+void des_set_odd_parity(des_cblock *);
+void des_fixup_key_parity(des_cblock *); 
+int des_is_weak_key(des_cblock *);
+int des_set_key(des_cblock *, des_key_schedule);
+int des_key_sched(des_cblock *, des_key_schedule);
+int des_set_key_checked(des_cblock *, des_key_schedule);
+void des_set_key_unchecked(des_cblock *, des_key_schedule);
+int des_check_key_parity(des_cblock *);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
diff --git a/Common/rt api/des_enc.c b/Common/rt api/des_enc.c
new file mode 100644 (file)
index 0000000..320f570
--- /dev/null
@@ -0,0 +1,292 @@
+/*     $KAME: des_enc.c,v 1.1 2001/09/10 04:03:58 itojun Exp $ */
+
+/* crypto/des/des_enc.c */
+
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#include "des_locl.h"
+
+extern const DES_LONG des_SPtrans[8][64];
+void des_encrypt1(DES_LONG *data, des_key_schedule ks, int enc)
+{
+       register DES_LONG l,r,t,u;
+#ifdef DES_PTR
+       register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
+#endif
+#ifndef DES_UNROLL
+       register int i;
+#endif
+       register DES_LONG *s;
+
+       r=data[0];
+       l=data[1];
+
+       IP(r,l);
+       /* Things have been modified so that the initial rotate is
+        * done outside the loop.  This required the
+        * des_SPtrans values in sp.h to be rotated 1 bit to the right.
+        * One perl script later and things have a 5% speed up on a sparc2.
+        * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
+        * for pointing this out. */
+       /* clear the top bits on machines with 8byte longs */
+       /* shift left by 2 */
+       r=ROTATE(r,29)&0xffffffffL;
+       l=ROTATE(l,29)&0xffffffffL;
+
+       s=ks->ks.deslong;
+       /* I don't know if it is worth the effort of loop unrolling the
+        * inner loop */
+       if (enc)
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r, 0); /*  1 */
+               D_ENCRYPT(r,l, 2); /*  2 */
+               D_ENCRYPT(l,r, 4); /*  3 */
+               D_ENCRYPT(r,l, 6); /*  4 */
+               D_ENCRYPT(l,r, 8); /*  5 */
+               D_ENCRYPT(r,l,10); /*  6 */
+               D_ENCRYPT(l,r,12); /*  7 */
+               D_ENCRYPT(r,l,14); /*  8 */
+               D_ENCRYPT(l,r,16); /*  9 */
+               D_ENCRYPT(r,l,18); /*  10 */
+               D_ENCRYPT(l,r,20); /*  11 */
+               D_ENCRYPT(r,l,22); /*  12 */
+               D_ENCRYPT(l,r,24); /*  13 */
+               D_ENCRYPT(r,l,26); /*  14 */
+               D_ENCRYPT(l,r,28); /*  15 */
+               D_ENCRYPT(r,l,30); /*  16 */
+#else
+               for (i=0; i<32; i+=8)
+                       {
+                       D_ENCRYPT(l,r,i+0); /*  1 */
+                       D_ENCRYPT(r,l,i+2); /*  2 */
+                       D_ENCRYPT(l,r,i+4); /*  3 */
+                       D_ENCRYPT(r,l,i+6); /*  4 */
+                       }
+#endif
+               }
+       else
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r,30); /* 16 */
+               D_ENCRYPT(r,l,28); /* 15 */
+               D_ENCRYPT(l,r,26); /* 14 */
+               D_ENCRYPT(r,l,24); /* 13 */
+               D_ENCRYPT(l,r,22); /* 12 */
+               D_ENCRYPT(r,l,20); /* 11 */
+               D_ENCRYPT(l,r,18); /* 10 */
+               D_ENCRYPT(r,l,16); /*  9 */
+               D_ENCRYPT(l,r,14); /*  8 */
+               D_ENCRYPT(r,l,12); /*  7 */
+               D_ENCRYPT(l,r,10); /*  6 */
+               D_ENCRYPT(r,l, 8); /*  5 */
+               D_ENCRYPT(l,r, 6); /*  4 */
+               D_ENCRYPT(r,l, 4); /*  3 */
+               D_ENCRYPT(l,r, 2); /*  2 */
+               D_ENCRYPT(r,l, 0); /*  1 */
+#else
+               for (i=30; i>0; i-=8)
+                       {
+                       D_ENCRYPT(l,r,i-0); /* 16 */
+                       D_ENCRYPT(r,l,i-2); /* 15 */
+                       D_ENCRYPT(l,r,i-4); /* 14 */
+                       D_ENCRYPT(r,l,i-6); /* 13 */
+                       }
+#endif
+               }
+
+       /* rotate and clear the top bits on machines with 8byte longs */
+       l=ROTATE(l,3)&0xffffffffL;
+       r=ROTATE(r,3)&0xffffffffL;
+
+       FP(r,l);
+       data[0]=l;
+       data[1]=r;
+       l=r=t=u=0;
+}
+
+void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
+{
+       register DES_LONG l,r,t,u;
+#ifdef DES_PTR
+       register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
+#endif
+#ifndef DES_UNROLL
+       register int i;
+#endif
+       register DES_LONG *s;
+
+       r=data[0];
+       l=data[1];
+
+       /* Things have been modified so that the initial rotate is
+        * done outside the loop.  This required the
+        * des_SPtrans values in sp.h to be rotated 1 bit to the right.
+        * One perl script later and things have a 5% speed up on a sparc2.
+        * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
+        * for pointing this out. */
+       /* clear the top bits on machines with 8byte longs */
+       r=ROTATE(r,29)&0xffffffffL;
+       l=ROTATE(l,29)&0xffffffffL;
+
+       s=ks->ks.deslong;
+       /* I don't know if it is worth the effort of loop unrolling the
+        * inner loop */
+       if (enc)
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r, 0); /*  1 */
+               D_ENCRYPT(r,l, 2); /*  2 */
+               D_ENCRYPT(l,r, 4); /*  3 */
+               D_ENCRYPT(r,l, 6); /*  4 */
+               D_ENCRYPT(l,r, 8); /*  5 */
+               D_ENCRYPT(r,l,10); /*  6 */
+               D_ENCRYPT(l,r,12); /*  7 */
+               D_ENCRYPT(r,l,14); /*  8 */
+               D_ENCRYPT(l,r,16); /*  9 */
+               D_ENCRYPT(r,l,18); /*  10 */
+               D_ENCRYPT(l,r,20); /*  11 */
+               D_ENCRYPT(r,l,22); /*  12 */
+               D_ENCRYPT(l,r,24); /*  13 */
+               D_ENCRYPT(r,l,26); /*  14 */
+               D_ENCRYPT(l,r,28); /*  15 */
+               D_ENCRYPT(r,l,30); /*  16 */
+#else
+               for (i=0; i<32; i+=8)
+                       {
+                       D_ENCRYPT(l,r,i+0); /*  1 */
+                       D_ENCRYPT(r,l,i+2); /*  2 */
+                       D_ENCRYPT(l,r,i+4); /*  3 */
+                       D_ENCRYPT(r,l,i+6); /*  4 */
+                       }
+#endif
+               }
+       else
+               {
+#ifdef DES_UNROLL
+               D_ENCRYPT(l,r,30); /* 16 */
+               D_ENCRYPT(r,l,28); /* 15 */
+               D_ENCRYPT(l,r,26); /* 14 */
+               D_ENCRYPT(r,l,24); /* 13 */
+               D_ENCRYPT(l,r,22); /* 12 */
+               D_ENCRYPT(r,l,20); /* 11 */
+               D_ENCRYPT(l,r,18); /* 10 */
+               D_ENCRYPT(r,l,16); /*  9 */
+               D_ENCRYPT(l,r,14); /*  8 */
+               D_ENCRYPT(r,l,12); /*  7 */
+               D_ENCRYPT(l,r,10); /*  6 */
+               D_ENCRYPT(r,l, 8); /*  5 */
+               D_ENCRYPT(l,r, 6); /*  4 */
+               D_ENCRYPT(r,l, 4); /*  3 */
+               D_ENCRYPT(l,r, 2); /*  2 */
+               D_ENCRYPT(r,l, 0); /*  1 */
+#else
+               for (i=30; i>0; i-=8)
+                       {
+                       D_ENCRYPT(l,r,i-0); /* 16 */
+                       D_ENCRYPT(r,l,i-2); /* 15 */
+                       D_ENCRYPT(l,r,i-4); /* 14 */
+                       D_ENCRYPT(r,l,i-6); /* 13 */
+                       }
+#endif
+               }
+       /* rotate and clear the top bits on machines with 8byte longs */
+       data[0]=ROTATE(l,3)&0xffffffffL;
+       data[1]=ROTATE(r,3)&0xffffffffL;
+       l=r=t=u=0;
+}
+
+void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
+            des_key_schedule ks3)
+{
+       register DES_LONG l,r;
+
+       l=data[0];
+       r=data[1];
+       IP(l,r);
+       data[0]=l;
+       data[1]=r;
+       des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
+       des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
+       des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
+       l=data[0];
+       r=data[1];
+       FP(r,l);
+       data[0]=l;
+       data[1]=r;
+}
+
+void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
+            des_key_schedule ks3)
+{
+       register DES_LONG l,r;
+
+       l=data[0];
+       r=data[1];
+       IP(l,r);
+       data[0]=l;
+       data[1]=r;
+       des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
+       des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
+       des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
+       l=data[0];
+       r=data[1];
+       FP(r,l);
+       data[0]=l;
+       data[1]=r;
+}
diff --git a/Common/rt api/des_locl.h b/Common/rt api/des_locl.h
new file mode 100644 (file)
index 0000000..b298c6f
--- /dev/null
@@ -0,0 +1,364 @@
+/*     $FreeBSD: src/sys/crypto/des/des_locl.h,v 1.6 2002/03/05 09:19:02 ume Exp $     */
+/*     $KAME: des_locl.h,v 1.7 2001/09/10 04:03:58 itojun Exp $        */
+
+/* crypto/des/des_locl.h */
+/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_DES_LOCL_H
+#define HEADER_DES_LOCL_H
+
+#include "des.h"
+
+#undef DES_PTR
+
+#ifdef __STDC__
+#undef NOPROTO
+#endif
+
+#define ITERATIONS 16
+#define HALF_ITERATIONS 8
+
+/* used in des_read and des_write */
+#define MAXWRITE       (1024*16)
+#define BSIZE          (MAXWRITE+4)
+
+#define c2l(c,l)       (l =((DES_LONG)(*((c)++)))    , \
+                        l|=((DES_LONG)(*((c)++)))<< 8L, \
+                        l|=((DES_LONG)(*((c)++)))<<16L, \
+                        l|=((DES_LONG)(*((c)++)))<<24L)
+
+/* NOTE - c is not incremented as per c2l */
+#define c2ln(c,l1,l2,n)        { \
+                       c+=n; \
+                       l1=l2=0; \
+                       switch (n) { \
+                       case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
+                       case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
+                       case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
+                       case 5: l2|=((DES_LONG)(*(--(c))));     \
+                       case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
+                       case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
+                       case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
+                       case 1: l1|=((DES_LONG)(*(--(c))));     \
+                               } \
+                       }
+
+#define l2c(l,c)       (*((c)++)=(unsigned char)(((l)     )&0xff), \
+                        *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>24L)&0xff))
+
+/* replacements for htonl and ntohl since I have no idea what to do
+ * when faced with machines with 8 byte longs. */
+#define HDRSIZE 4
+
+#define n2l(c,l)       (l =((DES_LONG)(*((c)++)))<<24L, \
+                        l|=((DES_LONG)(*((c)++)))<<16L, \
+                        l|=((DES_LONG)(*((c)++)))<< 8L, \
+                        l|=((DES_LONG)(*((c)++))))
+
+#define l2n(l,c)       (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
+                        *((c)++)=(unsigned char)(((l)     )&0xff))
+
+/* NOTE - c is not incremented as per l2c */
+#define l2cn(l1,l2,c,n)        { \
+                       c+=n; \
+                       switch (n) { \
+                       case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
+                       case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
+                       case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
+                       case 5: *(--(c))=(unsigned char)(((l2)     )&0xff); \
+                       case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
+                       case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
+                       case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
+                       case 1: *(--(c))=(unsigned char)(((l1)     )&0xff); \
+                               } \
+                       }
+
+#define        ROTATE(a,n)     (((a)>>(n))+((a)<<(32-(n))))
+
+#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
+#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
+       u=R^s[S  ]; \
+       t=R^s[S+1]
+
+/* The changes to this macro may help or hinder, depending on the
+ * compiler and the achitecture.  gcc2 always seems to do well :-).
+ * Inspired by Dana How <how@isl.stanford.edu>
+ * DO NOT use the alternative version on machines with 8 byte longs.
+ * It does not seem to work on the Alpha, even when DES_LONG is 4
+ * bytes, probably an issue of accessing non-word aligned objects :-( */
+#ifdef DES_PTR
+
+/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
+ * is no reason to not xor all the sub items together.  This potentially
+ * saves a register since things can be xored directly into L */
+
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+#define D_ENCRYPT(LL,R,S) { \
+        unsigned int u1,u2,u3; \
+        LOAD_DATA(R,S,u,t,E0,E1,u1); \
+        u2=(int)u>>8L; \
+        u1=(int)u&0xfc; \
+        u2&=0xfc; \
+        t=ROTATE(t,4); \
+        u>>=16L; \
+        LL^= *(const DES_LONG *)(des_SP      +u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
+        u3=(int)(u>>8L); \
+        u1=(int)u&0xfc; \
+        u3&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
+        u2=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u2&=0xfc; \
+        t>>=16L; \
+        LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
+        u3=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u3&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
+#endif /* DES_RISC1 */
+#ifdef DES_RISC2
+#define D_ENCRYPT(LL,R,S) { \
+        unsigned int u1,u2,s1,s2; \
+        LOAD_DATA(R,S,u,t,E0,E1,u1); \
+        u2=(int)u>>8L; \
+        u1=(int)u&0xfc; \
+        u2&=0xfc; \
+        t=ROTATE(t,4); \
+        LL^= *(const DES_LONG *)(des_SP      +u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
+        s1=(int)(u>>16L); \
+        s2=(int)(u>>24L); \
+        s1&=0xfc; \
+        s2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
+        LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
+        u2=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
+        s1=(int)(t>>16L); \
+        s2=(int)(t>>24L); \
+        s1&=0xfc; \
+        s2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
+        LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
+        u2=(int)t>>8L; \
+        u1=(int)t&0xfc; \
+        u2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
+        LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
+        s1=(int)(t>>16L); \
+        s2=(int)(t>>24L); \
+        s1&=0xfc; \
+        s2&=0xfc; \
+        LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
+        LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
+#endif /* DES_RISC2 */
+#else  /* DES_RISC1 || DES_RISC2 */
+#define D_ENCRYPT(LL,R,S) { \
+       LOAD_DATA_tmp(R,S,u,t,E0,E1); \
+       t=ROTATE(t,4); \
+       LL^= \
+       *(const DES_LONG *)(des_SP      +((u     )&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x100+((t     )&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
+       *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
+#endif /* DES_RISC1 || DES_RISC2 */
+#else /* original version */
+
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+#define D_ENCRYPT(LL,R,S) {\
+       unsigned int u1,u2,u3; \
+       LOAD_DATA(R,S,u,t,E0,E1,u1); \
+       u>>=2L; \
+       t=ROTATE(t,6); \
+       u2=(int)u>>8L; \
+       u1=(int)u&0x3f; \
+       u2&=0x3f; \
+       u>>=16L; \
+       LL^=des_SPtrans[0][u1]; \
+       LL^=des_SPtrans[2][u2]; \
+       u3=(int)u>>8L; \
+       u1=(int)u&0x3f; \
+       u3&=0x3f; \
+       LL^=des_SPtrans[4][u1]; \
+       LL^=des_SPtrans[6][u3]; \
+       u2=(int)t>>8L; \
+       u1=(int)t&0x3f; \
+       u2&=0x3f; \
+       t>>=16L; \
+       LL^=des_SPtrans[1][u1]; \
+       LL^=des_SPtrans[3][u2]; \
+       u3=(int)t>>8L; \
+       u1=(int)t&0x3f; \
+       u3&=0x3f; \
+       LL^=des_SPtrans[5][u1]; \
+       LL^=des_SPtrans[7][u3]; }
+#endif /* DES_RISC1 */
+#ifdef DES_RISC2
+#define D_ENCRYPT(LL,R,S) {\
+       unsigned int u1,u2,s1,s2; \
+       LOAD_DATA(R,S,u,t,E0,E1,u1); \
+       u>>=2L; \
+       t=ROTATE(t,6); \
+       u2=(int)u>>8L; \
+       u1=(int)u&0x3f; \
+       u2&=0x3f; \
+       LL^=des_SPtrans[0][u1]; \
+       LL^=des_SPtrans[2][u2]; \
+       s1=(int)u>>16L; \
+       s2=(int)u>>24L; \
+       s1&=0x3f; \
+       s2&=0x3f; \
+       LL^=des_SPtrans[4][s1]; \
+       LL^=des_SPtrans[6][s2]; \
+       u2=(int)t>>8L; \
+       u1=(int)t&0x3f; \
+       u2&=0x3f; \
+       LL^=des_SPtrans[1][u1]; \
+       LL^=des_SPtrans[3][u2]; \
+       s1=(int)t>>16; \
+       s2=(int)t>>24L; \
+       s1&=0x3f; \
+       s2&=0x3f; \
+       LL^=des_SPtrans[5][s1]; \
+       LL^=des_SPtrans[7][s2]; }
+#endif /* DES_RISC2 */
+
+#else /* DES_RISC1 || DES_RISC2 */
+
+#define D_ENCRYPT(LL,R,S) {\
+       LOAD_DATA_tmp(R,S,u,t,E0,E1); \
+       t=ROTATE(t,4); \
+       LL^=\
+               des_SPtrans[0][(u>> 2L)&0x3f]^ \
+               des_SPtrans[2][(u>>10L)&0x3f]^ \
+               des_SPtrans[4][(u>>18L)&0x3f]^ \
+               des_SPtrans[6][(u>>26L)&0x3f]^ \
+               des_SPtrans[1][(t>> 2L)&0x3f]^ \
+               des_SPtrans[3][(t>>10L)&0x3f]^ \
+               des_SPtrans[5][(t>>18L)&0x3f]^ \
+               des_SPtrans[7][(t>>26L)&0x3f]; }
+#endif /* DES_RISC1 || DES_RISC2 */
+#endif /* DES_PTR */
+
+       /* IP and FP
+        * The problem is more of a geometric problem that random bit fiddling.
+        0  1  2  3  4  5  6  7      62 54 46 38 30 22 14  6
+        8  9 10 11 12 13 14 15      60 52 44 36 28 20 12  4
+       16 17 18 19 20 21 22 23      58 50 42 34 26 18 10  2
+       24 25 26 27 28 29 30 31  to  56 48 40 32 24 16  8  0
+
+       32 33 34 35 36 37 38 39      63 55 47 39 31 23 15  7
+       40 41 42 43 44 45 46 47      61 53 45 37 29 21 13  5
+       48 49 50 51 52 53 54 55      59 51 43 35 27 19 11  3
+       56 57 58 59 60 61 62 63      57 49 41 33 25 17  9  1
+
+       The output has been subject to swaps of the form
+       0 1 -> 3 1 but the odd and even bits have been put into
+       2 3    2 0
+       different words.  The main trick is to remember that
+       t=((l>>size)^r)&(mask);
+       r^=t;
+       l^=(t<<size);
+       can be used to swap and move bits between words.
+
+       So l =  0  1  2  3  r = 16 17 18 19
+               4  5  6  7      20 21 22 23
+               8  9 10 11      24 25 26 27
+              12 13 14 15      28 29 30 31
+       becomes (for size == 2 and mask == 0x3333)
+          t =   2^16  3^17 -- --   l =  0  1 16 17  r =  2  3 18 19
+                6^20  7^21 -- --        4  5 20 21       6  7 22 23
+               10^24 11^25 -- --        8  9 24 25      10 11 24 25
+               14^28 15^29 -- --       12 13 28 29      14 15 28 29
+
+       Thanks for hints from Richard Outerbridge - he told me IP&FP
+       could be done in 15 xor, 10 shifts and 5 ands.
+       When I finally started to think of the problem in 2D
+       I first got ~42 operations without xors.  When I remembered
+       how to use xors :-) I got it to its final state.
+       */
+#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
+       (b)^=(t),\
+       (a)^=((t)<<(n)))
+
+#define IP(l,r) \
+       { \
+       register DES_LONG tt; \
+       PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
+       PERM_OP(l,r,tt,16,0x0000ffffL); \
+       PERM_OP(r,l,tt, 2,0x33333333L); \
+       PERM_OP(l,r,tt, 8,0x00ff00ffL); \
+       PERM_OP(r,l,tt, 1,0x55555555L); \
+       }
+
+#define FP(l,r) \
+       { \
+       register DES_LONG tt; \
+       PERM_OP(l,r,tt, 1,0x55555555L); \
+       PERM_OP(r,l,tt, 8,0x00ff00ffL); \
+       PERM_OP(l,r,tt, 2,0x33333333L); \
+       PERM_OP(r,l,tt,16,0x0000ffffL); \
+       PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
+       }
+#endif
diff --git a/Common/rt api/des_setkey.c b/Common/rt api/des_setkey.c
new file mode 100644 (file)
index 0000000..de8641d
--- /dev/null
@@ -0,0 +1,235 @@
+/*     $KAME: des_setkey.c,v 1.7 2001/09/10 04:03:58 itojun Exp $      */
+
+/* crypto/des/set_key.c */
+
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+/* set_key.c v 1.4 eay 24/9/91
+ * 1.4 Speed up by 400% :-)
+ * 1.3 added register declarations.
+ * 1.2 unrolled make_key_sched a bit more
+ * 1.1 added norm_expand_bits
+ * 1.0 First working version
+ */
+#ifndef _WIN32
+       #include <sys/cdefs.h>
+       #include <sys/param.h>
+#endif
+#include <string.h>
+#include "des_locl.h"
+#include "podd.h"
+#include "sk.h"
+
+int des_check_key=0;
+
+void des_set_odd_parity(des_cblock *key)
+{
+       int i;
+
+       for (i=0; i<DES_KEY_SZ; i++)
+               (*key)[i]=odd_parity[(*key)[i]];
+}
+
+int des_check_key_parity(des_cblock *key)
+{
+       int i;
+
+       for (i=0; i<DES_KEY_SZ; i++)
+               {
+               if ((*key)[i] != odd_parity[(*key)[i]])
+                       return(0);
+               }
+       return(1);
+}
+
+/* Weak and semi week keys as take from
+ * %A D.W. Davies
+ * %A W.L. Price
+ * %T Security for Computer Networks
+ * %I John Wiley & Sons
+ * %D 1984
+ * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
+ * (and actual cblock values).
+ */
+#define NUM_WEAK_KEY   16
+static des_cblock weak_keys[NUM_WEAK_KEY]={
+       /* weak keys */
+       {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
+       {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
+       {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
+       {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
+       /* semi-weak keys */
+       {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
+       {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
+       {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
+       {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
+       {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
+       {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
+       {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
+       {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
+       {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
+       {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
+       {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
+       {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
+
+int des_is_weak_key(des_cblock *key)
+{
+       int i;
+
+       for (i=0; i<NUM_WEAK_KEY; i++)
+               /* Added == 0 to comparison, I obviously don't run
+                * this section very often :-(, thanks to
+                * engineering@MorningStar.Com for the fix
+                * eay 93/06/29
+                * Another problem, I was comparing only the first 4
+                * bytes, 97/03/18 */
+               if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
+       return(0);
+}
+
+/* NOW DEFINED IN des_local.h
+ * See ecb_encrypt.c for a pseudo description of these macros. 
+ * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
+ *     (b)^=(t),\
+ *     (a)=((a)^((t)<<(n))))
+ */
+
+#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
+       (a)=(a)^(t)^(t>>(16-(n))))
+
+int des_set_key(des_cblock *key, des_key_schedule schedule)
+{
+       if (des_check_key)
+       {
+               return des_set_key_checked(key, schedule);
+       }
+       else
+       {
+               des_set_key_unchecked(key, schedule);
+               return 0;
+       }
+}
+
+/* return 0 if key parity is odd (correct),
+ * return -1 if key parity error,
+ * return -2 if illegal weak key.
+ */
+int des_set_key_checked(des_cblock *key, des_key_schedule schedule)
+{
+       if (!des_check_key_parity(key))
+               return(-1);
+       if (des_is_weak_key(key))
+               return(-2);
+       des_set_key_unchecked(key, schedule);
+       return 0;
+}
+
+void des_set_key_unchecked(des_cblock *key, des_key_schedule schedule)
+{
+       static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
+       register DES_LONG c,d,t,s,t2;
+       register const unsigned char *in;
+       register DES_LONG *k;
+       register int i;
+
+       k = &schedule->ks.deslong[0];
+       in = &(*key)[0];
+
+       c2l(in,c);
+       c2l(in,d);
+
+       /* do PC1 in 47 simple operations :-)
+        * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
+        * for the inspiration. :-) */
+       PERM_OP (d,c,t,4,0x0f0f0f0fL);
+       HPERM_OP(c,t,-2,0xcccc0000L);
+       HPERM_OP(d,t,-2,0xcccc0000L);
+       PERM_OP (d,c,t,1,0x55555555L);
+       PERM_OP (c,d,t,8,0x00ff00ffL);
+       PERM_OP (d,c,t,1,0x55555555L);
+       d=      (((d&0x000000ffL)<<16L)| (d&0x0000ff00L)     |
+                ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
+       c&=0x0fffffffL;
+
+       for (i=0; i<ITERATIONS; i++)
+       {
+               if (shifts2[i])
+                       { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
+               else
+                       { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
+               c&=0x0fffffffL;
+               d&=0x0fffffffL;
+               /* could be a few less shifts but I am to lazy at this
+               * point in time to investigate */
+               s=      des_skb[0][ (c    )&0x3f                ]|
+                       des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
+                       des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
+                       des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
+                                                       ((c>>22L)&0x38)];
+               t=      des_skb[4][ (d    )&0x3f                ]|
+                       des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
+                       des_skb[6][ (d>>15L)&0x3f                ]|
+                       des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
+
+               /* table contained 0213 4657 */
+               t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
+               *(k++)=ROTATE(t2,30)&0xffffffffL;
+
+               t2=((s>>16L)|(t&0xffff0000L));
+               *(k++)=ROTATE(t2,26)&0xffffffffL;
+       }
+}
+
+int des_key_sched(des_cblock *key, des_key_schedule schedule)
+{
+       return(des_set_key(key,schedule));
+}
+
+void des_fixup_key_parity(des_cblock *key)
+{
+       des_set_odd_parity(key);
+}
diff --git a/Common/rt api/ecb_enc.c b/Common/rt api/ecb_enc.c
new file mode 100644 (file)
index 0000000..4a6093d
--- /dev/null
@@ -0,0 +1,136 @@
+/*     $KAME: des_ecb.c,v 1.6 2001/09/10 04:03:58 itojun Exp $ */
+
+/* crypto/des/ecb_enc.c */
+
+/* Copyright (C) 1995-1998 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+
+#include <stdio.h>
+#include "des_locl.h"
+#include "spr.h"
+
+/* char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; */ /* wrong */
+/* char *DES_version="DES part of SSLeay 0.6.4 30-Aug-1996"; */
+
+char *des_options(void)
+        {
+        static int init=1;
+        static char buf[32];
+
+        if (init)
+                {
+                const char *ptr,*unroll,*risc,*size;
+
+#ifdef DES_PTR
+                ptr="ptr";
+#else
+                ptr="idx";
+#endif
+#if defined(DES_RISC1) || defined(DES_RISC2)
+#ifdef DES_RISC1
+                risc="risc1";
+#endif
+#ifdef DES_RISC2
+                risc="risc2";
+#endif
+#else
+                risc="cisc";
+#endif
+#ifdef DES_UNROLL
+                unroll="16";
+#else
+                unroll="4";
+#endif
+                if (sizeof(DES_LONG) != sizeof(long))
+                        size="int";
+                else
+                        size="long";
+                sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);
+                init=0;
+                }
+        return(buf);
+}
+void des_ecb_encrypt(des_cblock *input, des_cblock *output, 
+                    des_key_schedule ks, int enc)
+{
+       register DES_LONG l;
+       DES_LONG ll[2];
+       const unsigned char *in=&(*input)[0];
+       unsigned char *out = &(*output)[0];
+
+       c2l(in,l); ll[0]=l;
+       c2l(in,l); ll[1]=l;
+       des_encrypt1(ll,ks,enc);
+       l=ll[0]; l2c(l,out);
+       l=ll[1]; l2c(l,out);
+       l=ll[0]=ll[1]=0;
+}
+
+void des_ecb3_encrypt(des_cblock *input, des_cblock *output,
+             des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
+             int enc)
+{
+       register DES_LONG l0,l1;
+       DES_LONG ll[2];
+       const unsigned char *in = &(*input)[0];
+       unsigned char *out = &(*output)[0];
+       c2l(in,l0); 
+       c2l(in,l1);
+       ll[0]=l0; 
+       ll[1]=l1;
+
+       if (enc)
+               des_encrypt3(ll,ks1,ks2,ks3);
+       else
+               des_decrypt3(ll,ks1,ks2,ks3);
+
+       l0=ll[0];
+       l1=ll[1];
+       l2c(l0,out);
+       l2c(l1,out);
+}
diff --git a/Common/rt api/md4.cpp b/Common/rt api/md4.cpp
new file mode 100644 (file)
index 0000000..7a6f91a
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * This code implements the MD4 message-digest algorithm.
+ * "Just the reference implementation, single stage. Hardly "optimized." Though a good bit faster than libssl's MD4, as it isn't doing nearly the same amount of work." - Bitweasil
+ * 
+ * little bit optimized (or at least attempted) for NTLM (unicode) by neinbrucke
+ */
+
+
+//#include <cstdlib>
+#include <cstring>
+#include "md4.h"
+
+/* MD4 Defines as per RFC reference implementation */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+#define FF(a, b, c, d, x, s) { \
+    (a) += F ((b), (c), (d)) + (x); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+  }
+#define GG(a, b, c, d, x, s) { \
+    (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \
+    (a) = ROTATE_LEFT ((a), (s)); \
+  }
+#define HH(a, b, c, d, x, s) { \
+    (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \
+    (a) = ROTATE_LEFT ((a), (s)); \
+  }
+#define S11 3
+#define S12 7
+#define S13 11
+#define S14 19
+#define S21 3
+#define S22 5
+#define S23 9
+#define S24 13
+#define S31 3
+#define S32 9
+#define S33 11
+#define S34 15
+/* End MD4 Defines */
+
+
+void MD4_NEW( unsigned char * pData, int length, unsigned char * pDigest)
+{
+       // For the hash working space
+       UINT4 b0,b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15;
+
+       // For the output result
+       UINT4 a,b,c,d;
+
+       b0 = 0x00000000;
+       b1 = 0x00000000;
+       b2 = 0x00000000;
+       b3 = 0x00000000;
+       b4 = 0x00000000;
+       b5 = 0x00000000;
+       b6 = 0x00000000;
+       b7 = 0x00000000;
+       b8 = 0x00000000;
+       b9 = 0x00000000;
+       b10 = 0x00000000;
+       b11 = 0x00000000;
+       b12 = 0x00000000;
+       b13 = 0x00000000;
+       b14 = 0x00000000;
+       b15 = 0x00000000; 
+
+       // LOAD DATA INTO b0 ... whatever here.   
+       switch (length)
+       {
+               case 2:
+               {
+                       unsigned char in[4];
+                       memcpy(in, pData, length);
+                       in[2] = 0x80;
+                       in[3] = 0x00;
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+               }
+               break;
+               case 4:
+               {
+                       unsigned char in[4];
+                       memcpy(in, pData, length);
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = 0x00000080;
+               }
+               break;
+               case 6:
+               {
+                       unsigned char in[8];
+                       memcpy(in, pData, length);
+                       in[6] = 0x80;
+                       in[7] = 0x00;
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+               }
+               break;
+               case 8:
+               {
+                       unsigned char in[8];
+                       memcpy(in, pData, length);
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+                       b2 = 0x00000080;
+               }
+               break;
+               case 10:
+               {
+                       unsigned char in[12];
+                       memcpy(in, pData, length);
+                       in[10] = 0x80;
+                       in[11] = 0x00;
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+                       b2 = pUiIn[2];
+               }
+               break;
+               default:
+               {
+                       unsigned char in[32];
+                       memcpy(in, pData, length);
+                       in[length] = 0x80;
+                       memset(in + length + 1, 0, 32 - length - 1);
+                       UINT4 * pUiIn = (UINT4 *) in;
+                       b0 = pUiIn[0];
+                       b1 = pUiIn[1];
+                       b2 = pUiIn[2];
+                       b3 = pUiIn[3];
+                       b4 = pUiIn[4];
+                       b5 = pUiIn[5];
+                       b6 = pUiIn[6];
+                       b7 = pUiIn[7]; // max 14 2byte chars (ntlm)
+                       b8 = pUiIn[8];
+               }
+               break;
+       }
+
+       b14 = length << 3;
+
+       a = 0x67452301;
+       b = 0xefcdab89;
+       c = 0x98badcfe;
+       d = 0x10325476;
+
+       /* Round 1 */
+       FF (a, b, c, d, b0, S11); /* 1 */
+       FF (d, a, b, c, b1, S12); /* 2 */
+       FF (c, d, a, b, b2, S13); /* 3 */
+       FF (b, c, d, a, b3, S14); /* 4 */
+       FF (a, b, c, d, b4, S11); /* 5 */
+       FF (d, a, b, c, b5, S12); /* 6 */
+       FF (c, d, a, b, b6, S13); /* 7 */
+       FF (b, c, d, a, b7, S14); /* 8 */
+       FF (a, b, c, d, 0, S11); /* 9 */
+       FF (d, a, b, c, 0, S12); /* 10 */
+       FF (c, d, a, b, 0, S13); /* 11 */
+       FF (b, c, d, a, 0, S14); /* 12 */
+       FF (a, b, c, d, 0, S11); /* 13 */
+       FF (d, a, b, c, 0, S12); /* 14 */
+       FF (c, d, a, b, b14, S13); /* 15 */
+       FF (b, c, d, a, 0, S14); /* 16 */
+
+       /* Round 2 */
+       GG (a, b, c, d, b0, S21); /* 17 */
+       GG (d, a, b, c, b4, S22); /* 18 */
+       GG (c, d, a, b, 0, S23); /* 19 */
+       GG (b, c, d, a, 0, S24); /* 20 */
+       GG (a, b, c, d, b1, S21); /* 21 */
+       GG (d, a, b, c, b5, S22); /* 22 */
+       GG (c, d, a, b, 0, S23); /* 23 */
+       GG (b, c, d, a, 0, S24); /* 24 */
+       GG (a, b, c, d, b2, S21); /* 25 */
+       GG (d, a, b, c, b6, S22); /* 26 */
+       GG (c, d, a, b, 0, S23); /* 27 */
+       GG (b, c, d, a, b14, S24); /* 28 */
+       GG (a, b, c, d, b3, S21); /* 29 */
+       GG (d, a, b, c, b7, S22); /* 30 */
+       GG (c, d, a, b, 0, S23); /* 31 */
+       GG (b, c, d, a, 0, S24); /* 32 */
+
+       /* Round 3 */
+       HH (a, b, c, d, b0, S31); /* 33 */
+       HH (d, a, b, c, 0, S32); /* 34 */
+       HH (c, d, a, b, b4, S33); /* 35 */
+       HH (b, c, d, a, 0, S34); /* 36 */
+       HH (a, b, c, d, b2, S31); /* 37 */
+       HH (d, a, b, c, 0, S32); /* 38 */
+       HH (c, d, a, b, b6, S33); /* 39 */
+       HH (b, c, d, a, b14, S34); /* 40 */
+       HH (a, b, c, d, b1, S31); /* 41 */
+       HH (d, a, b, c, 0, S32); /* 42 */
+       HH (c, d, a, b, b5, S33); /* 43 */
+       HH (b, c, d, a, 0, S34); /* 44 */
+       HH (a, b, c, d, b3, S31); /* 45 */
+       HH (d, a, b, c, 0, S32); /* 46 */
+       HH (c, d, a, b, b7, S33); /* 47 */
+       HH (b, c, d, a, 0, S34); /* 48 */
+
+       // Finally, add initial values, as this is the only pass we make.
+       a += 0x67452301;
+       b += 0xefcdab89;
+       c += 0x98badcfe;
+       d += 0x10325476;
+
+       UINT4 buf[4] = { a, b, c, d};
+       memcpy(pDigest, buf, 16);
+
+       return;
+}
diff --git a/Common/rt api/md4.h b/Common/rt api/md4.h
new file mode 100644 (file)
index 0000000..8a5c428
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef MD4_H
+#define MD4_H
+
+//typedef unsigned long uint32;
+typedef unsigned long UINT4;
+
+//Main function
+void MD4_NEW( unsigned char * buf, int len, unsigned char * pDigest);
+
+#endif /* !MD4_H */
diff --git a/Common/rt api/md5.cpp b/Common/rt api/md5.cpp
new file mode 100644 (file)
index 0000000..bc25b95
--- /dev/null
@@ -0,0 +1,1286 @@
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+/* Brutally hacked by John Walker back from ANSI C to K&R (no
+   prototypes) to maintain the tradition that Netfone will compile
+   with Sun's original "cc". */
+
+/*
+       Brutally modified by daVajj, optimized for lengths of 1 - 10.
+       Generic version used for longer indata
+*/
+
+#include <cstdlib>
+#include <cstring>
+#include "md5.h"
+
+/* The four core functions - F1 is optimized somewhat */
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+//Here's two different ways to do a left bitwise rotation. I've seen no major speed differences between them.
+//#define ROL(x, n) ( _lrotl(x, n) ) //This also requires #include <windows.h>
+#define ROL(x,n) ( x << n | x >>(32-n) )
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+       ( w += f(x, y, z) + data,  w = ROL(w,s) + x )
+       
+void MD5_NEW( unsigned char * pData, int len, unsigned char * pDigest)
+{
+       //Use optimized versions if available
+       switch( len )
+       {
+               case 1:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 1);
+                       in[1] = 0x80;
+                       memset(in + 2, 0, 2);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 8 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 8 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 8 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 8 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 2:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 2);
+                       in[2] = 0x80;
+                       memset(in + 3, 0, 1);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 16 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 16 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 16 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 16 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 3:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 3);
+                       in[3] = 0x80;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 24 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 24 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 24 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 24 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 4:
+               {
+                       //Main variables
+                       unsigned char in[4];
+                       
+                       memcpy(in, pData, 4);
+                       //in[4] = 0x80; //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, 128 + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 32 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, 128 + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 32 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 32 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, 128 + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 32 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, 128 + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 5:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 5);
+                       in[5] = 0x80;
+                       memset(in + 6, 0, 2); //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 40 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 40 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 40 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 40 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 6:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 6);
+                       in[6] = 0x80;
+                       memset(in + 7, 0, 1); //(uint32 *)in[1] = 128;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 48 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 48 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 48 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 48 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 7:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 7);
+                       in[7] = 0x80;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 56 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 56 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 56 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 56 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 8:
+               {
+                       //Main variables
+                       unsigned char in[8];
+                       
+                       memcpy(in, pData, 8);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, 128 + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 64 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 64 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, 128 + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 64 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, 128 + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 64 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, 128 + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 9:
+               {
+                       //Main variables
+                       unsigned char in[12];
+                       
+                       memcpy(in, pData, 9);
+                       in[9] = 0x80;
+                       memset(in + 10, 0, 2);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 72 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 72 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 72 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 72 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               case 10:
+               {
+                       //Main variables
+                       unsigned char in[12];
+                       
+                       memcpy(in, pData, 10);
+                       in[10] = 0x80;
+                       memset(in + 11, 0, 1);
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = 0x67452301;
+                       b = 0xefcdab89;
+                       c = 0x98badcfe;
+                       d = 0x10325476;
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, 80 + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, 80 + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, 80 + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, 80 + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, 0xeb86d391, 21);
+
+                       uint32 buf[4] = { 0x67452301 + a, 0xefcdab89 + b, 0x98badcfe + c, 0x10325476 + d };
+                       memcpy(pDigest, buf, 16);
+                       return;
+               }
+               break;
+
+               default:
+                       //Main variables
+                       uint32 buf[4];
+                       unsigned char in[64];
+                       
+                       //Initialize
+                       buf[0] = 0x67452301;
+                       buf[1] = 0xefcdab89;
+                       buf[2] = 0x98badcfe;
+                       buf[3] = 0x10325476;
+
+                       /* Process data in 64-byte chunks */
+                       if( len >= 64 )
+                       {
+                               while( len >= 64 )
+                               {
+                                       memcpy(in, pData, 64);
+
+                                       //START OF MD5TRANSFORM CODE
+                                       //====================================================
+                                       register uint32 a, b, c, d;
+                                       uint32 * pUiIn = (uint32 *) in;
+                               
+                                       a = buf[0];
+                                       b = buf[1];
+                                       c = buf[2];
+                                       d = buf[3];
+                               
+                                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                                       MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                                       MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                                       MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                                       MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+                               
+                                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                                       MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                                       MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                                       MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+                               
+                                       MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                                       MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                                       MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                                       MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+                               
+                                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                                       MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                                       MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                                       MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+                               
+                                       buf[0] += a;
+                                       buf[1] += b;
+                                       buf[2] += c;
+                                       buf[3] += d;
+                                       //END OF MD5TRANSFORM CODE
+                                       //====================================================
+
+                                       pData += 64;
+                                       len -= 64;
+                               }
+                       }
+
+                       /* Handle any remaining bytes of data. */
+                       memcpy(in, pData, len);
+                   
+                       //MD5FINAL STARTS HERE
+                       //===========================================
+                       unsigned count = len & 0x3F;
+                       unsigned char * p = in + count;
+                       *p++ = 0x80;
+
+                       // Bytes of padding needed to make 64 bytes
+                       count = 63 - count;
+
+                       /* Pad out to 56 mod 64 */
+                       if(count < 8)
+                       {
+                               // Two lots of padding:  Pad the first block to 64 bytes
+                               memset(p, 0, count);
+
+                               //START OF MD5TRANSFORM CODE
+                               //====================================================
+                               register uint32 a, b, c, d;
+                               uint32 * pUiIn = (uint32 *) in;
+                       
+                               a = buf[0];
+                               b = buf[1];
+                               c = buf[2];
+                               d = buf[3];
+                       
+                               MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                               MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                               MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                               MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                               MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+                       
+                               MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                               MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                               MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                               MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                               MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+                       
+                               MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                               MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                               MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                               MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                               MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+                       
+                               MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                               MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                               MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                               MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                               MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+                       
+                               buf[0] += a;
+                               buf[1] += b;
+                               buf[2] += c;
+                               buf[3] += d;
+                               //END OF MD5TRANSFORM CODE
+                               //====================================================      
+
+                               // Now fill the next block with 56 bytes
+                               memset(in, 0, 56);
+                       }
+                       else
+                       {
+                               // Pad block to 56 bytes
+                               memset(p, 0, count - 8);
+                       }//*/
+                   
+
+                       /* Append length in bits and transform */
+                       ((uint32 *) in)[14] = len << 3;
+                       ((uint32 *) in)[15] = len >> 29;
+
+                       //START OF MD5TRANSFORM CODE
+                       //====================================================
+                       register uint32 a, b, c, d;
+                       uint32 * pUiIn = (uint32 *) in;
+
+                       a = buf[0];
+                       b = buf[1];
+                       c = buf[2];
+                       d = buf[3];
+
+                       MD5STEP(F1, a, b, c, d, pUiIn[0] + 0xd76aa478, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[1] + 0xe8c7b756, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[2] + 0x242070db, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[3] + 0xc1bdceee, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[4] + 0xf57c0faf, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[5] + 0x4787c62a, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[6] + 0xa8304613, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[7] + 0xfd469501, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[8] + 0x698098d8, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[9] + 0x8b44f7af, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[10] + 0xffff5bb1, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[11] + 0x895cd7be, 22);
+                       MD5STEP(F1, a, b, c, d, pUiIn[12] + 0x6b901122, 7);
+                       MD5STEP(F1, d, a, b, c, pUiIn[13] + 0xfd987193, 12);
+                       MD5STEP(F1, c, d, a, b, pUiIn[14] + 0xa679438e, 17);
+                       MD5STEP(F1, b, c, d, a, pUiIn[15] + 0x49b40821, 22);
+
+                       MD5STEP(F2, a, b, c, d, pUiIn[1] + 0xf61e2562, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[6] + 0xc040b340, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[11] + 0x265e5a51, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[0] + 0xe9b6c7aa, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[5] + 0xd62f105d, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[10] + 0x02441453, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[15] + 0xd8a1e681, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[4] + 0xe7d3fbc8, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[9] + 0x21e1cde6, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[14] + 0xc33707d6, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[3] + 0xf4d50d87, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[8] + 0x455a14ed, 20);
+                       MD5STEP(F2, a, b, c, d, pUiIn[13] + 0xa9e3e905, 5);
+                       MD5STEP(F2, d, a, b, c, pUiIn[2] + 0xfcefa3f8, 9);
+                       MD5STEP(F2, c, d, a, b, pUiIn[7] + 0x676f02d9, 14);
+                       MD5STEP(F2, b, c, d, a, pUiIn[12] + 0x8d2a4c8a, 20);
+
+                       MD5STEP(F3, a, b, c, d, pUiIn[5] + 0xfffa3942, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[8] + 0x8771f681, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[11] + 0x6d9d6122, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[14] + 0xfde5380c, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[1] + 0xa4beea44, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[4] + 0x4bdecfa9, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[7] + 0xf6bb4b60, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[10] + 0xbebfbc70, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[13] + 0x289b7ec6, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[0] + 0xeaa127fa, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[3] + 0xd4ef3085, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[6] + 0x04881d05, 23);
+                       MD5STEP(F3, a, b, c, d, pUiIn[9] + 0xd9d4d039, 4);
+                       MD5STEP(F3, d, a, b, c, pUiIn[12] + 0xe6db99e5, 11);
+                       MD5STEP(F3, c, d, a, b, pUiIn[15] + 0x1fa27cf8, 16);
+                       MD5STEP(F3, b, c, d, a, pUiIn[2] + 0xc4ac5665, 23);
+
+                       MD5STEP(F4, a, b, c, d, pUiIn[0] + 0xf4292244, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[7] + 0x432aff97, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[14] + 0xab9423a7, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[5] + 0xfc93a039, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[12] + 0x655b59c3, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[3] + 0x8f0ccc92, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[10] + 0xffeff47d, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[1] + 0x85845dd1, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[8] + 0x6fa87e4f, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[15] + 0xfe2ce6e0, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[6] + 0xa3014314, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[13] + 0x4e0811a1, 21);
+                       MD5STEP(F4, a, b, c, d, pUiIn[4] + 0xf7537e82, 6);
+                       MD5STEP(F4, d, a, b, c, pUiIn[11] + 0xbd3af235, 10);
+                       MD5STEP(F4, c, d, a, b, pUiIn[2] + 0x2ad7d2bb, 15);
+                       MD5STEP(F4, b, c, d, a, pUiIn[9] + 0xeb86d391, 21);
+
+                       buf[0] += a;
+                       buf[1] += b;
+                       buf[2] += c;
+                       buf[3] += d;
+                       //END OF MD5TRANSFORM CODE
+                       //====================================================
+                           
+                       memcpy(pDigest, buf, 16);
+                       return;
+
+               break;
+       }
+}
diff --git a/Common/rt api/md5.h b/Common/rt api/md5.h
new file mode 100644 (file)
index 0000000..1d3da9e
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef MD5_H
+#define MD5_H
+
+typedef unsigned long uint32;
+
+//Main function
+void MD5_NEW( unsigned char * buf, int len, unsigned char * pDigest);
+
+#endif /* !MD5_H */
diff --git a/Common/rt api/podd.h b/Common/rt api/podd.h
new file mode 100644 (file)
index 0000000..8d77aac
--- /dev/null
@@ -0,0 +1,67 @@
+/*     $FreeBSD: src/sys/crypto/des/podd.h,v 1.4 2002/04/19 04:46:21 suz Exp $ */
+/*     $KAME: podd.h,v 1.4 2001/09/10 04:03:58 itojun Exp $    */
+
+/* crypto/des/podd.h */
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+static const unsigned char odd_parity[256]={
+  1,  1,  2,  2,  4,  4,  7,  7,  8,  8, 11, 11, 13, 13, 14, 14,
+ 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
+ 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
+ 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
+ 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
+ 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
+ 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
+112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
+128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
+145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
+161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
+176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
+193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
+208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
+224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
+241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
diff --git a/Common/rt api/sk.h b/Common/rt api/sk.h
new file mode 100644 (file)
index 0000000..209dca6
--- /dev/null
@@ -0,0 +1,196 @@
+/*     $FreeBSD: src/sys/crypto/des/sk.h,v 1.4 2002/04/19 04:46:21 suz Exp $   */
+/*     $KAME: sk.h,v 1.4 2001/09/10 04:03:58 itojun Exp $      */
+
+/* crypto/des/sk.h */
+/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This file is part of an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL
+ * specification.  This library and applications are
+ * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
+ * as long as the following conditions are aheared to.
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.  If this code is used in a product,
+ * Eric Young should be given attribution as the author of the parts used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Eric Young (eay@mincom.oz.au)
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+static const DES_LONG des_skb[8][64]={
+{
+/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
+0x00000000L,0x00000010L,0x20000000L,0x20000010L,
+0x00010000L,0x00010010L,0x20010000L,0x20010010L,
+0x00000800L,0x00000810L,0x20000800L,0x20000810L,
+0x00010800L,0x00010810L,0x20010800L,0x20010810L,
+0x00000020L,0x00000030L,0x20000020L,0x20000030L,
+0x00010020L,0x00010030L,0x20010020L,0x20010030L,
+0x00000820L,0x00000830L,0x20000820L,0x20000830L,
+0x00010820L,0x00010830L,0x20010820L,0x20010830L,
+0x00080000L,0x00080010L,0x20080000L,0x20080010L,
+0x00090000L,0x00090010L,0x20090000L,0x20090010L,
+0x00080800L,0x00080810L,0x20080800L,0x20080810L,
+0x00090800L,0x00090810L,0x20090800L,0x20090810L,
+0x00080020L,0x00080030L,0x20080020L,0x20080030L,
+0x00090020L,0x00090030L,0x20090020L,0x20090030L,
+0x00080820L,0x00080830L,0x20080820L,0x20080830L,
+0x00090820L,0x00090830L,0x20090820L,0x20090830L,
+},{
+/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
+0x00000000L,0x02000000L,0x00002000L,0x02002000L,
+0x00200000L,0x02200000L,0x00202000L,0x02202000L,
+0x00000004L,0x02000004L,0x00002004L,0x02002004L,
+0x00200004L,0x02200004L,0x00202004L,0x02202004L,
+0x00000400L,0x02000400L,0x00002400L,0x02002400L,
+0x00200400L,0x02200400L,0x00202400L,0x02202400L,
+0x00000404L,0x02000404L,0x00002404L,0x02002404L,
+0x00200404L,0x02200404L,0x00202404L,0x02202404L,
+0x10000000L,0x12000000L,0x10002000L,0x12002000L,
+0x10200000L,0x12200000L,0x10202000L,0x12202000L,
+0x10000004L,0x12000004L,0x10002004L,0x12002004L,
+0x10200004L,0x12200004L,0x10202004L,0x12202004L,
+0x10000400L,0x12000400L,0x10002400L,0x12002400L,
+0x10200400L,0x12200400L,0x10202400L,0x12202400L,
+0x10000404L,0x12000404L,0x10002404L,0x12002404L,
+0x10200404L,0x12200404L,0x10202404L,0x12202404L,
+},{
+/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
+0x00000000L,0x00000001L,0x00040000L,0x00040001L,
+0x01000000L,0x01000001L,0x01040000L,0x01040001L,
+0x00000002L,0x00000003L,0x00040002L,0x00040003L,
+0x01000002L,0x01000003L,0x01040002L,0x01040003L,
+0x00000200L,0x00000201L,0x00040200L,0x00040201L,
+0x01000200L,0x01000201L,0x01040200L,0x01040201L,
+0x00000202L,0x00000203L,0x00040202L,0x00040203L,
+0x01000202L,0x01000203L,0x01040202L,0x01040203L,
+0x08000000L,0x08000001L,0x08040000L,0x08040001L,
+0x09000000L,0x09000001L,0x09040000L,0x09040001L,
+0x08000002L,0x08000003L,0x08040002L,0x08040003L,
+0x09000002L,0x09000003L,0x09040002L,0x09040003L,
+0x08000200L,0x08000201L,0x08040200L,0x08040201L,
+0x09000200L,0x09000201L,0x09040200L,0x09040201L,
+0x08000202L,0x08000203L,0x08040202L,0x08040203L,
+0x09000202L,0x09000203L,0x09040202L,0x09040203L,
+},{
+/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
+0x00000000L,0x00100000L,0x00000100L,0x00100100L,
+0x00000008L,0x00100008L,0x00000108L,0x00100108L,
+0x00001000L,0x00101000L,0x00001100L,0x00101100L,
+0x00001008L,0x00101008L,0x00001108L,0x00101108L,
+0x04000000L,0x04100000L,0x04000100L,0x04100100L,
+0x04000008L,0x04100008L,0x04000108L,0x04100108L,
+0x04001000L,0x04101000L,0x04001100L,0x04101100L,
+0x04001008L,0x04101008L,0x04001108L,0x04101108L,
+0x00020000L,0x00120000L,0x00020100L,0x00120100L,
+0x00020008L,0x00120008L,0x00020108L,0x00120108L,
+0x00021000L,0x00121000L,0x00021100L,0x00121100L,
+0x00021008L,0x00121008L,0x00021108L,0x00121108L,
+0x04020000L,0x04120000L,0x04020100L,0x04120100L,
+0x04020008L,0x04120008L,0x04020108L,0x04120108L,
+0x04021000L,0x04121000L,0x04021100L,0x04121100L,
+0x04021008L,0x04121008L,0x04021108L,0x04121108L,
+},{
+/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
+0x00000000L,0x10000000L,0x00010000L,0x10010000L,
+0x00000004L,0x10000004L,0x00010004L,0x10010004L,
+0x20000000L,0x30000000L,0x20010000L,0x30010000L,
+0x20000004L,0x30000004L,0x20010004L,0x30010004L,
+0x00100000L,0x10100000L,0x00110000L,0x10110000L,
+0x00100004L,0x10100004L,0x00110004L,0x10110004L,
+0x20100000L,0x30100000L,0x20110000L,0x30110000L,
+0x20100004L,0x30100004L,0x20110004L,0x30110004L,
+0x00001000L,0x10001000L,0x00011000L,0x10011000L,
+0x00001004L,0x10001004L,0x00011004L,0x10011004L,
+0x20001000L,0x30001000L,0x20011000L,0x30011000L,
+0x20001004L,0x30001004L,0x20011004L,0x30011004L,
+0x00101000L,0x10101000L,0x00111000L,0x10111000L,
+0x00101004L,0x10101004L,0x00111004L,0x10111004L,
+0x20101000L,0x30101000L,0x20111000L,0x30111000L,
+0x20101004L,0x30101004L,0x20111004L,0x30111004L,
+},{
+/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
+0x00000000L,0x08000000L,0x00000008L,0x08000008L,
+0x00000400L,0x08000400L,0x00000408L,0x08000408L,
+0x00020000L,0x08020000L,0x00020008L,0x08020008L,
+0x00020400L,0x08020400L,0x00020408L,0x08020408L,
+0x00000001L,0x08000001L,0x00000009L,0x08000009L,
+0x00000401L,0x08000401L,0x00000409L,0x08000409L,
+0x00020001L,0x08020001L,0x00020009L,0x08020009L,
+0x00020401L,0x08020401L,0x00020409L,0x08020409L,
+0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
+0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
+0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
+0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
+0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
+0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
+0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
+0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
+},{
+/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
+0x00000000L,0x00000100L,0x00080000L,0x00080100L,
+0x01000000L,0x01000100L,0x01080000L,0x01080100L,
+0x00000010L,0x00000110L,0x00080010L,0x00080110L,
+0x01000010L,0x01000110L,0x01080010L,0x01080110L,
+0x00200000L,0x00200100L,0x00280000L,0x00280100L,
+0x01200000L,0x01200100L,0x01280000L,0x01280100L,
+0x00200010L,0x00200110L,0x00280010L,0x00280110L,
+0x01200010L,0x01200110L,0x01280010L,0x01280110L,
+0x00000200L,0x00000300L,0x00080200L,0x00080300L,
+0x01000200L,0x01000300L,0x01080200L,0x01080300L,
+0x00000210L,0x00000310L,0x00080210L,0x00080310L,
+0x01000210L,0x01000310L,0x01080210L,0x01080310L,
+0x00200200L,0x00200300L,0x00280200L,0x00280300L,
+0x01200200L,0x01200300L,0x01280200L,0x01280300L,
+0x00200210L,0x00200310L,0x00280210L,0x00280310L,
+0x01200210L,0x01200310L,0x01280210L,0x01280310L,
+},{
+/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
+0x00000000L,0x04000000L,0x00040000L,0x04040000L,
+0x00000002L,0x04000002L,0x00040002L,0x04040002L,
+0x00002000L,0x04002000L,0x00042000L,0x04042000L,
+0x00002002L,0x04002002L,0x00042002L,0x04042002L,
+0x00000020L,0x04000020L,0x00040020L,0x04040020L,
+0x00000022L,0x04000022L,0x00040022L,0x04040022L,
+0x00002020L,0x04002020L,0x00042020L,0x04042020L,
+0x00002022L,0x04002022L,0x00042022L,0x04042022L,
+0x00000800L,0x04000800L,0x00040800L,0x04040800L,
+0x00000802L,0x04000802L,0x00040802L,0x04040802L,
+0x00002800L,0x04002800L,0x00042800L,0x04042800L,
+0x00002802L,0x04002802L,0x00042802L,0x04042802L,
+0x00000820L,0x04000820L,0x00040820L,0x04040820L,
+0x00000822L,0x04000822L,0x00040822L,0x04040822L,
+0x00002820L,0x04002820L,0x00042820L,0x04042820L,
+0x00002822L,0x04002822L,0x00042822L,0x04042822L,
+}};
diff --git a/Common/rt api/spr.h b/Common/rt api/spr.h
new file mode 100644 (file)
index 0000000..4fd00b6
--- /dev/null
@@ -0,0 +1,207 @@
+/*     $FreeBSD: src/sys/crypto/des/spr.h,v 1.4 2002/03/05 09:19:02 ume Exp $  */
+/*     $KAME: spr.h,v 1.4 2001/09/10 04:03:58 itojun Exp $     */
+
+/* crypto/des/spr.h */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+const DES_LONG des_SPtrans[8][64]={
+{
+/* nibble 0 */
+0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
+0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
+0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
+0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
+0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
+0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
+0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
+0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
+0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
+0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
+0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
+0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
+0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
+0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
+0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
+0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
+},{
+/* nibble 1 */
+0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
+0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
+0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
+0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
+0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
+0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
+0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
+0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
+0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
+0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
+0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
+0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
+0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
+0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
+0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
+0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
+},{
+/* nibble 2 */
+0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
+0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
+0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
+0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
+0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
+0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
+0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
+0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
+0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
+0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
+0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
+0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
+0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
+0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
+0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
+0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
+},{
+/* nibble 3 */
+0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
+0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
+0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
+0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
+0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
+0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
+0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
+0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
+0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
+0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
+0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
+0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
+0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
+0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
+0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
+0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
+},{
+/* nibble 4 */
+0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
+0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
+0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
+0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
+0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
+0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
+0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
+0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
+0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
+0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
+0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
+0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
+0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
+0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
+0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
+0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
+},{
+/* nibble 5 */
+0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
+0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
+0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
+0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
+0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
+0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
+0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
+0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
+0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
+0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
+0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
+0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
+0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
+0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
+0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
+0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
+},{
+/* nibble 6 */
+0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
+0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
+0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
+0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
+0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
+0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
+0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
+0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
+0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
+0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
+0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
+0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
+0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
+0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
+0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
+0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
+},{
+/* nibble 7 */
+0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
+0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
+0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
+0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
+0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
+0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
+0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
+0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
+0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
+0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
+0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
+0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
+0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
+0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
+0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
+0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
+}};
diff --git a/Common/rt api/tmp/HashAlgorithm.cpp b/Common/rt api/tmp/HashAlgorithm.cpp
new file mode 100644 (file)
index 0000000..07cebe5
--- /dev/null
@@ -0,0 +1,349 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "HashAlgorithm.h"
+
+#include "Public.h"
+
+#include <openssl/des.h>
+#include <openssl/md2.h>
+#include <openssl/md4.h>
+#include <openssl/md5.h>
+#include <openssl/sha.h>
+#include <openssl/ripemd.h>
+#ifdef _WIN32
+       #pragma comment(lib, "libeay32.lib")
+#endif
+#define MSCACHE_HASH_SIZE 16
+void setup_des_key(unsigned char key_56[], des_key_schedule &ks)
+{
+       des_cblock key;
+
+       key[0] = key_56[0];
+       key[1] = (key_56[0] << 7) | (key_56[1] >> 1);
+       key[2] = (key_56[1] << 6) | (key_56[2] >> 2);
+       key[3] = (key_56[2] << 5) | (key_56[3] >> 3);
+       key[4] = (key_56[3] << 4) | (key_56[4] >> 4);
+       key[5] = (key_56[4] << 3) | (key_56[5] >> 5);
+       key[6] = (key_56[5] << 2) | (key_56[6] >> 6);
+       key[7] = (key_56[6] << 1);
+
+       //des_set_odd_parity(&key);
+       des_set_key(&key, ks);
+}
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       /*
+       unsigned char data[7] = {0};
+       memcpy(data, pPlain, nPlainLen > 7 ? 7 : nPlainLen);
+       */
+
+       int i;
+       for (i = nPlainLen; i < 7; i++)
+               pPlain[i] = 0;
+
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       des_key_schedule ks;
+       //setup_des_key(data, ks);
+       setup_des_key(pPlain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pHash, ks, DES_ENCRYPT);
+}
+
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char pass[14];
+       unsigned char pre_lmresp[21];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+       des_key_schedule ks;
+
+       memset (pass,0,sizeof(pass));
+       memset (pre_lmresp,0,sizeof(pre_lmresp));
+
+       memcpy (pass,pPlain, nPlainLen);
+
+       setup_des_key(pass, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(&pass[7], ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)&pre_lmresp[8], ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[7], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[14], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+
+} 
+
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{      
+       unsigned char pre_lmresp[8];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char salt[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+       des_key_schedule ks;
+       unsigned char plain[8] = {0};   
+       memcpy(plain, pPlain, nPlainLen);
+       setup_des_key(plain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)salt, (des_cblock*)pHash, ks, DES_ENCRYPT);
+} 
+
+
+
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+  unsigned char UnicodePlain[MAX_PLAIN_LEN];
+  static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+  
+  int len = (nPlainLen < 127) ? nPlainLen : 127;
+  int i;
+  
+  for (i = 0; i < len; i++)
+  {
+    UnicodePlain[i * 2] = pPlain[i];
+    UnicodePlain[i * 2 + 1] = 0x00;
+  }
+
+  des_key_schedule ks;
+  unsigned char lm[21];
+
+  MD4(UnicodePlain, len * 2, lm);
+  lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
+
+  setup_des_key(lm, ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[7], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[14], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+}
+
+
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char ToEncrypt[256];
+       char temp[256];
+       char username[256];
+
+       DES_cblock iv,iv2;
+       DES_key_schedule ks1,ks2;
+       unsigned char deskey_fixed[]={ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
+       int i,j;
+
+       strcpy (username, "SYS");
+       int userlen = 3;
+       
+//     strupr ((char*) pPlain);
+       memset (ToEncrypt,0,sizeof(ToEncrypt));
+
+       for (i=1,j=0; j<userlen; i++,j++)
+       {
+               ToEncrypt[i] = username[j];
+               i++;
+       }
+
+       for (j=0; j<nPlainLen; i++,j++)
+       {
+               ToEncrypt[i] = pPlain[j];
+               i++;
+       }
+
+       i=i-1;
+       memset (iv,0,8);
+       memset (iv2,0,8);
+       DES_set_key((DES_cblock*) deskey_fixed, &ks1);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks1, &iv, DES_ENCRYPT);
+       DES_set_key((DES_cblock*) &iv, &ks2);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks2, &iv2, DES_ENCRYPT);
+       memcpy (pHash,iv2,8);
+}
+
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char UnicodePlain[MAX_PLAIN_LEN * 2];
+       int i;
+       for (i = 0; i < nPlainLen; i++)
+       {
+               UnicodePlain[i * 2] = pPlain[i];
+               UnicodePlain[i * 2 + 1] = 0x00;
+       }
+
+       MD4(UnicodePlain, nPlainLen * 2, pHash);
+}
+
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD2(pPlain, nPlainLen, pHash);
+}
+
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD4(pPlain, nPlainLen, pHash);
+}
+
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5(pPlain, nPlainLen, pHash);
+}
+
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       SHA1(pPlain, nPlainLen, pHash);
+}
+
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       RIPEMD160(pPlain, nPlainLen, pHash);
+}
+
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char unicode_pwd[256];
+       char unicode_user[256];
+       static unsigned char username[] = "administrator";
+       static int userlen = 13;
+       unsigned char   final1[MD4_DIGEST_LENGTH];
+       MD4_CTX ctx;
+       int i;
+
+//     strcpy (username, "administrator");
+//     userlen = 13;
+
+       for (i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }
+
+       for (i=0; i<userlen; i++)
+       {
+               unicode_user[i*2] = username[i];
+               unicode_user[i*2+1] = 0x00;
+       }
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,unicode_pwd,nPlainLen*2);
+       MD4_Final(final1,&ctx);
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,final1,MD4_DIGEST_LENGTH);
+       MD4_Update(&ctx,(unsigned char*) unicode_user,userlen*2);
+       MD4_Final(pHash,&ctx);
+
+       /*
+       unsigned char unicode_pwd[256];
+       for (int i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }*/     
+       /*
+       unsigned char *buf = (unsigned char*)calloc(MSCACHE_HASH_SIZE + nSaltLength, sizeof(unsigned char));    
+       HashNTLM(pPlain, nPlainLen, buf, NULL);
+       //MD4(unicode_pwd, nPlainLen*2, buf);
+       memcpy(buf + MSCACHE_HASH_SIZE, pSalt, nSaltLength);
+       MD4(buf, MSCACHE_HASH_SIZE + nSaltLength, pHash); 
+       free(buf);
+       */
+}
+
+//*********************************************************************************
+// Code for MySQL password hashing
+//*********************************************************************************
+
+inline void mysql_hash_password_323(unsigned long *result, const char *password) 
+{
+  register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
+  unsigned long tmp;
+  for (; *password ; password++) 
+  {
+    if (*password == ' ' || *password == '\t') continue;
+       tmp= (unsigned long) (unsigned char) *password;
+       nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
+       nr2+=(nr2 << 8) ^ nr;
+       add+=tmp;
+  }
+  result[0]=nr & (((unsigned long) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
+  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
+  return;
+}
+
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned long hash_pass[2];     
+       unsigned char* f = (unsigned char*) hash_pass;
+
+       unsigned char* pass = (unsigned char*) calloc (nPlainLen+4,sizeof(unsigned char));
+       memcpy(pass,pPlain,nPlainLen);
+
+       mysql_hash_password_323(hash_pass, (char*) pass);
+       pHash[0]=*(f+3); pHash[1]=*(f+2); pHash[2]=*(f+1); pHash[3]=*(f+0);
+       pHash[4]=*(f+7); pHash[5]=*(f+6); pHash[6]=*(f+5); pHash[7]=*(f+4);
+
+       free (pass);
+}
+
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char hash_stage1[SHA_DIGEST_LENGTH];
+       SHA_CTX ctx;
+
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, (unsigned char *) pPlain, nPlainLen);
+       SHA1_Final(hash_stage1, &ctx);
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, hash_stage1, SHA_DIGEST_LENGTH);
+       SHA1_Final(pHash, &ctx);
+}
+
+//*********************************************************************************
+// Code for PIX password hashing
+//*********************************************************************************
+static char itoa64[] =          /* 0 ... 63 => ascii - 64 */
+        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void _crypt_to64(char *s, unsigned long v, int n)
+{
+        while (--n >= 0) {
+                *s++ = itoa64[v&0x3f];
+                v >>= 6;
+        }
+}
+
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char temp[MD5_DIGEST_LENGTH+1];
+       unsigned char final[MD5_DIGEST_LENGTH];
+       char* pass = (char*) calloc (nPlainLen+MD5_DIGEST_LENGTH,sizeof(char));
+
+       memcpy (pass,pPlain,nPlainLen);
+
+       MD5_CTX ctx;
+       MD5_Init(&ctx);
+       MD5_Update(&ctx, (unsigned char *) pass, MD5_DIGEST_LENGTH);
+       MD5_Final(final, &ctx);
+
+       char* p = (char*) temp;
+       _crypt_to64(p,*(unsigned long*) (final+0),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+4),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+8),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+12),4); p += 4;
+       *p=0;
+
+       memcpy(pHash,temp,MD5_DIGEST_LENGTH);
+
+       free (pass);
+}
diff --git a/Common/rt api/tmp/HashAlgorithm.h b/Common/rt api/tmp/HashAlgorithm.h
new file mode 100644 (file)
index 0000000..b617f9f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHALGORITHM_H
+#define _HASHALGORITHM_H
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash);
+//****************************************************************************
+// MySQL Password Hashing
+//****************************************************************************
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// Cisco PIX Password Hashing
+//****************************************************************************
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// (HALF) LM CHALL hashing
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+// From mao
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+#endif
diff --git a/Common/rt api/tmp/HashRoutine.cpp b/Common/rt api/tmp/HashRoutine.cpp
new file mode 100644 (file)
index 0000000..b61ae63
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "HashRoutine.h"
+#include "HashAlgorithm.h"
+
+//////////////////////////////////////////////////////////////////////
+
+CHashRoutine::CHashRoutine()
+{
+       // Notice: MIN_HASH_LEN <= nHashLen <= MAX_HASH_LEN
+
+       AddHashRoutine("lm",   HashLM,   8);
+       AddHashRoutine("md5",  HashMD5,  16);
+       AddHashRoutine("sha1", HashSHA1, 20);
+       AddHashRoutine("ntlm", HashNTLM, 16);
+}      
+
+CHashRoutine::~CHashRoutine()
+{
+}
+
+void CHashRoutine::AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen)
+{
+       vHashRoutineName.push_back(sHashRoutineName);
+       vHashRoutine.push_back(pHashRoutine);
+       vHashLen.push_back(nHashLen);
+}
+
+string CHashRoutine::GetAllHashRoutineName()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+               sRet += vHashRoutineName[i] + " ";
+
+       return sRet;
+}
+
+void CHashRoutine::GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+       {
+               if (sHashRoutineName == vHashRoutineName[i])
+               {
+                       pHashRoutine = vHashRoutine[i];
+                       nHashLen = vHashLen[i];
+                       return;
+               }
+       }
+
+       pHashRoutine = NULL;
+       nHashLen = 0;
+}
diff --git a/Common/rt api/tmp/HashRoutine.h b/Common/rt api/tmp/HashRoutine.h
new file mode 100644 (file)
index 0000000..681fa78
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHROUTINE_H
+#define _HASHROUTINE_H
+
+#include <string>
+#include <vector>
+using namespace std;
+
+typedef void (*HASHROUTINE)(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+class CHashRoutine  
+{
+public:
+       CHashRoutine();
+       virtual ~CHashRoutine();
+
+private:
+       vector<string>          vHashRoutineName;
+       vector<HASHROUTINE>     vHashRoutine;
+       vector<int>                     vHashLen;
+       void AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen);
+
+public:
+       string GetAllHashRoutineName();
+       void GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen);
+};
+
+#endif
diff --git a/Server Applications/rsearchi/ChainWalkContext.cpp b/Server Applications/rsearchi/ChainWalkContext.cpp
new file mode 100644 (file)
index 0000000..7c1b58d
--- /dev/null
@@ -0,0 +1,585 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkContext.h"
+
+#include <ctype.h>
+#include <openssl/rand.h>
+#ifdef _WIN32
+       #pragma comment(lib, "libeay32.lib")
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+string CChainWalkContext::m_sHashRoutineName;
+HASHROUTINE CChainWalkContext::m_pHashRoutine;
+int CChainWalkContext::m_nHashLen;
+int CChainWalkContext::m_nPlainLenMinTotal = 0;
+int CChainWalkContext::m_nPlainLenMaxTotal = 0;
+int CChainWalkContext::m_nHybridCharset = 0;
+vector<stCharset> CChainWalkContext::m_vCharset;
+uint64 CChainWalkContext::m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];
+uint64 CChainWalkContext::m_nPlainSpaceTotal;
+unsigned char CChainWalkContext::m_Salt[MAX_SALT_LEN];
+int CChainWalkContext::m_nSaltLen = 0;
+int CChainWalkContext::m_nRainbowTableIndex;
+uint64 CChainWalkContext::m_nReduceOffset;
+
+//////////////////////////////////////////////////////////////////////
+
+CChainWalkContext::CChainWalkContext()
+{
+}
+
+CChainWalkContext::~CChainWalkContext()
+{
+}
+
+bool CChainWalkContext::LoadCharset(string sName)
+{
+       /*
+       m_vCharset.clear();
+       if (sName == "byte")
+       {
+               stCharset tCharset;
+               int i;
+               for (i = 0x00; i <= 0xff; i++)
+                       tCharset.m_PlainCharset[i] = i;
+               tCharset.m_nPlainCharsetLen = 256;
+               tCharset.m_sPlainCharsetName = sName;
+               tCharset.m_sPlainCharsetContent = "0x00, 0x01, ... 0xff";
+               m_vCharset.push_back(tCharset);
+               return true;
+       }
+       if(sName.substr(0, 6) == "hybrid") // Hybrid charset consisting of 2 charsets
+       {
+               m_nHybridCharset = 1;           
+       }
+       vector<string> vLine;
+       if (ReadLinesFromFile("charset.txt", vLine))
+       {
+               int i;
+               for (i = 0; i < vLine.size(); i++)
+               {
+                       // Filter comment
+                       if (vLine[i][0] == '#')
+                               continue;
+
+                       vector<string> vPart;
+                       if (SeperateString(vLine[i], "=", vPart))
+                       {
+                               // sCharsetName
+                               string sCharsetName = TrimString(vPart[0]);
+                               if (sCharsetName == "")
+                                       continue;
+                                                               
+                               // sCharsetName charset check
+                               bool fCharsetNameCheckPass = true;
+                               int j;
+                               for (j = 0; j < sCharsetName.size(); j++)
+                               {
+                                       if (   !isalpha(sCharsetName[j])
+                                               && !isdigit(sCharsetName[j])
+                                               && (sCharsetName[j] != '-'))
+                                       {
+                                               fCharsetNameCheckPass = false;
+                                               break;
+                                       }
+                               }
+                               if (!fCharsetNameCheckPass)
+                               {
+                                       printf("invalid charset name %s in charset configuration file\n", sCharsetName.c_str());
+                                       continue;
+                               }
+
+                               // sCharsetContent
+                               string sCharsetContent = TrimString(vPart[1]);
+                               if (sCharsetContent == "" || sCharsetContent == "[]")
+                                       continue;
+                               if (sCharsetContent[0] != '[' || sCharsetContent[sCharsetContent.size() - 1] != ']')
+                               {
+                                       printf("invalid charset content %s in charset configuration file\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+                               sCharsetContent = sCharsetContent.substr(1, sCharsetContent.size() - 2);
+                               if (sCharsetContent.size() > 256)
+                               {
+                                       printf("charset content %s too long\n", sCharsetContent.c_str());
+                                       continue;
+                               }
+
+                               //printf("%s = [%s]\n", sCharsetName.c_str(), sCharsetContent.c_str());
+
+                               // Is it the wanted charset?
+                               if(m_nHybridCharset == 1)
+                               {
+                                       vector<tCharset> vCharsets;
+                                       GetHybridCharsets(sName, vCharsets);
+                                       if(sCharsetName == vCharsets[m_vCharset.size()].sName)
+                                       {
+                                               stCharset tCharset = {0};
+                                               tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                               memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                               tCharset.m_sPlainCharsetName = sCharsetName;
+                                               tCharset.m_sPlainCharsetContent = sCharsetContent;      
+                                               tCharset.m_nPlainLenMin = vCharsets[m_vCharset.size()].nPlainLenMin;
+                                               tCharset.m_nPlainLenMax = vCharsets[m_vCharset.size()].nPlainLenMax;
+                                               m_vCharset.push_back(tCharset);
+                                               if(vCharsets.size() == m_vCharset.size())
+                                                       return true;
+                                               i = 0; // Start the lookup over again for the next charset
+                                       }                                               
+                               }
+                               else if (sCharsetName == sName)
+                               {
+                                       stCharset tCharset;
+                                       tCharset.m_nPlainCharsetLen = sCharsetContent.size();                                                   
+                                       memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen);
+                                       tCharset.m_sPlainCharsetName = sCharsetName;
+                                       tCharset.m_sPlainCharsetContent = sCharsetContent;                                                      
+                                       m_vCharset.push_back(tCharset);
+                                       return true;
+                               }
+                       }
+               }
+               printf("charset %s not found in charset.txt\n", sName.c_str());
+       }
+       else
+               printf("can't open charset configuration file\n");*/
+       return true;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+bool CChainWalkContext::SetHashRoutine(string sHashRoutineName)
+{
+       CHashRoutine hr;
+       hr.GetHashRoutine(sHashRoutineName, m_pHashRoutine, m_nHashLen);
+       if (m_pHashRoutine != NULL)
+       {
+               m_sHashRoutineName = sHashRoutineName;
+               return true;
+       }
+       else
+               return false;
+}
+
+bool CChainWalkContext::SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax)
+{
+/*
+// m_PlainCharset, m_nPlainCharsetLen, m_sPlainCharsetName, m_sPlainCharsetContent
+       if (!LoadCharset(sCharsetName))
+               return false;
+
+       if(m_vCharset.size() == 1) // Not hybrid charset
+       {
+               // m_nPlainLenMin, m_nPlainLenMax
+               if (nPlainLenMin < 1 || nPlainLenMax > MAX_PLAIN_LEN || nPlainLenMin > nPlainLenMax)
+               {
+                       printf("invalid plaintext length range: %d - %d\n", nPlainLenMin, nPlainLenMax);
+                       return false;
+               }
+               m_vCharset[0].m_nPlainLenMin = nPlainLenMin;
+               m_vCharset[0].m_nPlainLenMax = nPlainLenMax;
+       }
+       // m_nPlainSpaceUpToX
+       m_nPlainSpaceUpToX[0] = 0;
+       m_nPlainLenMaxTotal = 0;
+       m_nPlainLenMinTotal = 0;
+       uint64 nTemp = 1;
+       int j, k = 1;
+       for(j = 0; j < m_vCharset.size(); j++)
+       {
+               int i;
+               m_nPlainLenMaxTotal += m_vCharset[j].m_nPlainLenMax;
+               m_nPlainLenMinTotal += m_vCharset[j].m_nPlainLenMin;
+               for (i = 1; i <= m_vCharset[j].m_nPlainLenMax; i++)
+               {                       
+                       nTemp *= m_vCharset[j].m_nPlainCharsetLen;
+                       if (i < m_vCharset[j].m_nPlainLenMin)
+                               m_nPlainSpaceUpToX[k] = 0;
+                       else
+                               m_nPlainSpaceUpToX[k] = m_nPlainSpaceUpToX[k - 1] + nTemp;
+                       k++;
+               }               
+       }
+       // m_nPlainSpaceTotal
+       m_nPlainSpaceTotal = m_nPlainSpaceUpToX[m_nPlainLenMaxTotal];
+*/
+       return true;
+}
+
+bool CChainWalkContext::SetRainbowTableIndex(int nRainbowTableIndex)
+{
+       if (nRainbowTableIndex < 0)
+               return false;
+       m_nRainbowTableIndex = nRainbowTableIndex;
+       m_nReduceOffset = 65536 * nRainbowTableIndex;
+
+       return true;
+}
+
+bool CChainWalkContext::SetSalt(unsigned char *Salt, int nSaltLength)
+{
+       memcpy(&m_Salt[0], Salt, nSaltLength);
+       
+       m_nSaltLen = nSaltLength;
+//     m_sSalt = sSalt;
+       return true;
+}
+
+bool CChainWalkContext::SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount)
+{
+       // something like lm_alpha#1-7_0_100x16_test.rt
+
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       if (nIndex != -1)
+               sPathName = sPathName.substr(nIndex + 1);
+
+       if (sPathName.size() < 3)
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+       if (sPathName.substr(sPathName.size() - 4) != ".rti")
+       {
+               printf("%s is not a rainbow table\n", sPathName.c_str());
+               return false;
+       }
+
+       // Parse
+       vector<string> vPart;
+       if (!SeperateString(sPathName, "___x_", vPart))
+       {
+               printf("filename %s not identified\n", sPathName.c_str());
+               return false;
+       }
+
+       string sHashRoutineName   = vPart[0];
+       int nRainbowTableIndex    = atoi(vPart[2].c_str());
+       nRainbowChainLen          = atoi(vPart[3].c_str());
+       nRainbowChainCount        = atoi(vPart[4].c_str());
+
+       // Parse charset definition
+       string sCharsetDefinition = vPart[1];
+       string sCharsetName;
+       int nPlainLenMin = 0, nPlainLenMax = 0;         
+
+//     printf("Charset: %s", sCharsetDefinition.c_str());
+       
+       if(sCharsetDefinition.substr(0, 6) == "hybrid") // Hybrid table
+       {
+               sCharsetName = sCharsetDefinition;
+       }
+       else
+       {
+               if (sCharsetDefinition.find('#') == -1)         // For backward compatibility, "#1-7" is implied
+               {                       
+                       sCharsetName = sCharsetDefinition;
+                       nPlainLenMin = 1;
+                       nPlainLenMax = 7;
+               }
+               else
+               {
+                       vector<string> vCharsetDefinitionPart;
+                       if (!SeperateString(sCharsetDefinition, "#-", vCharsetDefinitionPart))
+                       {
+                               printf("filename %s not identified\n", sPathName.c_str());
+                               return false;   
+                       }
+                       else
+                       {
+                               sCharsetName = vCharsetDefinitionPart[0];
+                               nPlainLenMin = atoi(vCharsetDefinitionPart[1].c_str());
+                               nPlainLenMax = atoi(vCharsetDefinitionPart[2].c_str());
+                       }
+               }
+       }
+       // Setup
+       if (!SetHashRoutine(sHashRoutineName))
+       {
+               printf("hash routine %s not supported\n", sHashRoutineName.c_str());
+               return false;
+       }
+       if (!SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
+               return false;
+       if (!SetRainbowTableIndex(nRainbowTableIndex))
+       {
+               printf("invalid rainbow table index %d\n", nRainbowTableIndex);
+               return false;
+       }
+
+       return true;
+}
+
+string CChainWalkContext::GetHashRoutineName()
+{
+       return m_sHashRoutineName;
+}
+
+int CChainWalkContext::GetHashLen()
+{
+       return m_nHashLen;
+}
+
+string CChainWalkContext::GetPlainCharsetName()
+{
+       return m_vCharset[0].m_sPlainCharsetName;
+}
+
+string CChainWalkContext::GetPlainCharsetContent()
+{
+       return m_vCharset[0].m_sPlainCharsetContent;
+}
+
+int CChainWalkContext::GetPlainLenMin()
+{
+       return m_vCharset[0].m_nPlainLenMin;
+}
+
+int CChainWalkContext::GetPlainLenMax()
+{
+       return m_vCharset[0].m_nPlainLenMax;
+}
+
+uint64 CChainWalkContext::GetPlainSpaceTotal()
+{
+       return m_nPlainSpaceTotal;
+}
+
+int CChainWalkContext::GetRainbowTableIndex()
+{
+       return m_nRainbowTableIndex;
+}
+
+void CChainWalkContext::Dump()
+{
+       printf("hash routine: %s\n", m_sHashRoutineName.c_str());
+       printf("hash length: %d\n", m_nHashLen);
+
+       printf("plain charset: ");
+       int i;
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+       {
+               if (isprint(m_vCharset[0].m_PlainCharset[i]))
+                       printf("%c", m_vCharset[0].m_PlainCharset[i]);
+               else
+                       printf("?");
+       }
+       printf("\n");
+
+       printf("plain charset in hex: ");
+       for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++)
+               printf("%02x ", m_vCharset[0].m_PlainCharset[i]);
+       printf("\n");
+
+       printf("plain length range: %d - %d\n", m_vCharset[0].m_nPlainLenMin, m_vCharset[0].m_nPlainLenMax);
+       printf("plain charset name: %s\n", m_vCharset[0].m_sPlainCharsetName.c_str());
+       //printf("plain charset content: %s\n", m_sPlainCharsetContent.c_str());
+       //for (i = 0; i <= m_nPlainLenMax; i++)
+       //      printf("plain space up to %d: %s\n", i, uint64tostr(m_nPlainSpaceUpToX[i]).c_str());
+       printf("plain space total: %s\n", uint64tostr(m_nPlainSpaceTotal).c_str());
+
+       printf("rainbow table index: %d\n", m_nRainbowTableIndex);
+       printf("reduce offset: %s\n", uint64tostr(m_nReduceOffset).c_str());
+       printf("\n");
+}
+
+void CChainWalkContext::GenerateRandomIndex()
+{
+       RAND_bytes((unsigned char*)&m_nIndex, 8);
+       m_nIndex = m_nIndex % m_nPlainSpaceTotal;
+}
+
+void CChainWalkContext::SetIndex(uint64 nIndex)
+{
+       m_nIndex = nIndex;
+}
+
+void CChainWalkContext::SetHash(unsigned char* pHash)
+{
+       memcpy(m_Hash, pHash, m_nHashLen);
+}
+
+void CChainWalkContext::IndexToPlain()
+{
+       int i;
+       m_nPlainLen = 0;
+       for (i = m_nPlainLenMaxTotal - 1; i >= m_nPlainLenMinTotal - 1; i--)
+       {
+               if (m_nIndex >= m_nPlainSpaceUpToX[i])
+               {
+                       m_nPlainLen = i + 1;
+                       break;
+               }
+       }
+       if(m_nPlainLen == 0)
+               m_nPlainLen = m_nPlainLenMinTotal;
+       uint64 nIndexOfX = m_nIndex - m_nPlainSpaceUpToX[m_nPlainLen - 1];
+
+#ifdef _WIN64
+       
+       // Slow version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); i++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                       }
+               }
+       }
+#else
+
+
+       // Fast version
+       for (i = m_nPlainLen - 1; i >= 0; i--)
+       {
+#ifdef _WIN32
+               if (nIndexOfX < 0x100000000I64)
+                       break;
+#else
+               if (nIndexOfX < 0x100000000llu)
+                       break;
+#endif
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+                               m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX % m_vCharset[j].m_nPlainCharsetLen];
+                               nIndexOfX /= m_vCharset[j].m_nPlainCharsetLen;
+                               break;
+                       }
+               }
+       }
+
+       unsigned int nIndexOfX32 = (unsigned int)nIndexOfX;
+       for (; i >= 0; i--)
+       {
+               int nCharsetLen = 0;
+               for(int j = 0; j < m_vCharset.size(); j++)
+               {
+                       nCharsetLen += m_vCharset[j].m_nPlainLenMax;
+                       if(i < nCharsetLen) // We found the correct charset
+                       {
+
+//             m_Plain[i] = m_PlainCharset[nIndexOfX32 % m_vCharset[j].m_nPlainCharsetLen];
+//             nIndexOfX32 /= m_vCharset[j].m_nPlainCharsetLen;
+
+               unsigned int nPlainCharsetLen = m_vCharset[j].m_nPlainCharsetLen;
+               unsigned int nTemp;
+#ifdef _WIN32
+               __asm
+               {
+                       mov eax, nIndexOfX32
+                       xor edx, edx
+                       div nPlainCharsetLen
+                       mov nIndexOfX32, eax
+                       mov nTemp, edx
+               }
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#else
+               __asm__ __volatile__ (  "mov %2, %%eax;"
+                                                               "xor %%edx, %%edx;"
+                                                               "divl %3;"
+                                                               "mov %%eax, %0;"
+                                                               "mov %%edx, %1;"
+                                                               : "=m"(nIndexOfX32), "=m"(nTemp)
+                                                               : "m"(nIndexOfX32), "m"(nPlainCharsetLen)
+                                                               : "%eax", "%edx"
+                                                        );
+               m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp];
+#endif
+               break;
+                       }
+               }
+       }
+#endif
+}
+
+void CChainWalkContext::PlainToHash()
+{      
+       m_pHashRoutine(m_Plain, m_nPlainLen, m_Hash);
+}
+
+void CChainWalkContext::HashToIndex(int nPos)
+{
+       m_nIndex = (*(uint64*)m_Hash + m_nReduceOffset + nPos) % m_nPlainSpaceTotal;
+}
+
+uint64 CChainWalkContext::GetIndex()
+{
+       return m_nIndex;
+}
+const uint64 *CChainWalkContext::GetIndexPtr()
+{
+       return &m_nIndex;
+}
+
+string CChainWalkContext::GetPlain()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < m_nPlainLen; i++)
+       {
+               char c = m_Plain[i];
+               if (c >= 32 && c <= 126)
+                       sRet += c;
+               else
+                       sRet += '?';
+       }
+       
+       return sRet;
+}
+
+string CChainWalkContext::GetBinary()
+{
+       return HexToStr(m_Plain, m_nPlainLen);
+}
+/*
+string CChainWalkContext::GetPlainBinary()
+{
+       string sRet;
+       sRet += GetPlain();
+       int i;
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += ' ';
+
+       sRet += "|";
+
+       sRet += GetBinary();
+       for (i = 0; i < m_nPlainLenMax - m_nPlainLen; i++)
+               sRet += "  ";
+
+       return sRet;
+}
+*/
+string CChainWalkContext::GetHash()
+{
+       return HexToStr(m_Hash, m_nHashLen);
+}
+
+bool CChainWalkContext::CheckHash(unsigned char* pHash)
+{
+       if (memcmp(m_Hash, pHash, m_nHashLen) == 0)
+               return true;
+
+       return false;
+}
diff --git a/Server Applications/rsearchi/ChainWalkContext.h b/Server Applications/rsearchi/ChainWalkContext.h
new file mode 100644 (file)
index 0000000..acd8a34
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKCONTEXT_H
+#define _CHAINWALKCONTEXT_H
+
+#include "HashRoutine.h"
+#include "Public.h"
+
+typedef struct 
+{
+       unsigned char m_PlainCharset[255];
+       int m_nPlainCharsetLen;
+       int m_nPlainLenMin;
+       int m_nPlainLenMax;
+       string m_sPlainCharsetName;
+       string m_sPlainCharsetContent;
+} stCharset;
+class CChainWalkContext 
+{
+public:
+       CChainWalkContext();
+       virtual ~CChainWalkContext();
+
+private:
+       static string m_sHashRoutineName;       
+       static HASHROUTINE m_pHashRoutine;                                                      // Configuration
+       static int m_nHashLen;                                                                          // Configuration
+
+//     static unsigned char m_PlainCharset[256];                                       // Configuration
+//     static unsigned char m_PlainCharset2[256];                                      // Configuration
+       static vector<stCharset> m_vCharset;
+       static int m_nPlainLenMinTotal, m_nPlainLenMaxTotal;
+       static uint64 m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];            // Performance consideration
+       static uint64 m_nPlainSpaceTotal;                                                       // Performance consideration
+       static int m_nHybridCharset;
+       static int m_nRainbowTableIndex;                                                        // Configuration
+       static uint64 m_nReduceOffset;                                                          // Performance consideration
+
+       // Context
+       uint64 m_nIndex;
+       unsigned char m_Plain[MAX_PLAIN_LEN];
+       int m_nPlainLen;
+       unsigned char m_Hash[MAX_HASH_LEN];
+       static unsigned char m_Salt[MAX_SALT_LEN];
+       static int m_nSaltLen;
+private:
+       static bool LoadCharset(string sCharset);
+
+public:
+       static bool SetHashRoutine(string sHashRoutineName);                                                                                            // Configuration
+       static bool SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax);                           // Configuration
+       static bool SetRainbowTableIndex(int nRainbowTableIndex);       
+       static bool SetSalt(unsigned char *Salt, int nSaltLength);// Configuration
+       static bool SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount);        // Wrapper
+       static string GetHashRoutineName();
+       static int GetHashLen();
+       static string GetPlainCharsetName();
+       static string GetPlainCharsetContent();
+       static int GetPlainLenMin();
+       static int GetPlainLenMax();
+       static uint64 GetPlainSpaceTotal();
+       static int GetRainbowTableIndex();
+       static void Dump();
+
+       void GenerateRandomIndex();
+       void SetIndex(uint64 nIndex);
+       void SetHash(unsigned char* pHash);             // The length should be m_nHashLen
+
+       void IndexToPlain();
+       void PlainToHash();
+       void HashToIndex(int nPos);
+
+       uint64 GetIndex();
+       const uint64* GetIndexPtr();
+       string GetPlain();
+       string GetBinary();
+//     string GetPlainBinary();
+       string GetHash();
+       bool CheckHash(unsigned char* pHash);   // The length should be m_nHashLen
+};
+
+#endif
diff --git a/Server Applications/rsearchi/ChainWalkSet.cpp b/Server Applications/rsearchi/ChainWalkSet.cpp
new file mode 100644 (file)
index 0000000..a081eb8
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "ChainWalkSet.h"
+
+CChainWalkSet::CChainWalkSet()
+{
+       m_sHashRoutineName   = "";
+       m_sPlainCharsetName  = "";
+       m_nPlainLenMin       = 0;
+       m_nPlainLenMax       = 0;
+       m_nRainbowTableIndex = 0;
+       m_nRainbowChainLen   = 0;
+}
+
+CChainWalkSet::~CChainWalkSet()
+{
+       DiscardAll();
+}
+
+void CChainWalkSet::DiscardAll()
+{
+       //printf("debug: discarding all walk...\n");
+
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+               delete it->pIndexE;
+       m_lChainWalk.clear();
+}
+
+uint64* CChainWalkSet::RequestWalk(unsigned char* pHash, int nHashLen,
+                                                                  string sHashRoutineName,
+                                                                  string sPlainCharsetName, int nPlainLenMin, int nPlainLenMax, 
+                                                                  int nRainbowTableIndex, 
+                                                                  int nRainbowChainLen,
+                                                                  bool& fNewlyGenerated)
+{
+       if (   m_sHashRoutineName   != sHashRoutineName
+               || m_sPlainCharsetName  != sPlainCharsetName
+               || m_nPlainLenMin       != nPlainLenMin
+               || m_nPlainLenMax       != nPlainLenMax
+               || m_nRainbowTableIndex != nRainbowTableIndex
+               || m_nRainbowChainLen   != nRainbowChainLen)
+       {
+               DiscardAll();
+
+               m_sHashRoutineName   = sHashRoutineName;
+               m_sPlainCharsetName  = sPlainCharsetName;
+               m_nPlainLenMin       = nPlainLenMin;
+               m_nPlainLenMax       = nPlainLenMax;
+               m_nRainbowTableIndex = nRainbowTableIndex;
+               m_nRainbowChainLen   = nRainbowChainLen;
+
+               ChainWalk cw;
+               memcpy(cw.Hash, pHash, nHashLen);
+               cw.pIndexE = new uint64[nRainbowChainLen - 1];
+               m_lChainWalk.push_back(cw);
+
+               fNewlyGenerated = true;
+               return cw.pIndexE;
+       }
+
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+       {
+               if (memcmp(it->Hash, pHash, nHashLen) == 0)
+               {
+                       fNewlyGenerated = false;
+                       return it->pIndexE;
+               }
+       }
+
+       ChainWalk cw;
+       memcpy(cw.Hash, pHash, nHashLen);
+       cw.pIndexE = new uint64[nRainbowChainLen - 1];
+       m_lChainWalk.push_back(cw);
+
+       fNewlyGenerated = true;
+       return cw.pIndexE;
+}
+
+void CChainWalkSet::DiscardWalk(uint64* pIndexE)
+{
+       list<ChainWalk>::iterator it;
+       for (it = m_lChainWalk.begin(); it != m_lChainWalk.end(); it++)
+       {
+               if (it->pIndexE == pIndexE)
+               {
+                       delete it->pIndexE;
+                       m_lChainWalk.erase(it);
+                       return;
+               }
+       }
+
+       printf("debug: pIndexE not found\n");
+}
diff --git a/Server Applications/rsearchi/ChainWalkSet.h b/Server Applications/rsearchi/ChainWalkSet.h
new file mode 100644 (file)
index 0000000..4276894
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CHAINWALKSET_H
+#define _CHAINWALKSET_H
+
+#include "Public.h"
+
+struct ChainWalk
+{
+       unsigned char Hash[MAX_HASH_LEN];
+       //int nHashLen;         // Implied
+       uint64* pIndexE;        // mapStartPosIndexE, Len = nRainbowChainLen - 1
+};
+
+class CChainWalkSet
+{
+public:
+       CChainWalkSet();
+       virtual ~CChainWalkSet();
+
+private:
+       string m_sHashRoutineName;              // Discard all if not match
+       string m_sPlainCharsetName;             // Discard all if not match
+       int    m_nPlainLenMin;                  // Discard all if not match
+       int    m_nPlainLenMax;                  // Discard all if not match
+       int    m_nRainbowTableIndex;    // Discard all if not match
+       int    m_nRainbowChainLen;              // Discard all if not match
+       list<ChainWalk> m_lChainWalk;
+
+private:
+       void DiscardAll();
+
+public:
+       uint64* RequestWalk(unsigned char* pHash, int nHashLen,
+                                               string sHashRoutineName,
+                                               string sPlainCharsetName, int nPlainLenMin, int nPlainLenMax, 
+                                               int nRainbowTableIndex, 
+                                               int nRainbowChainLen,
+                                               bool& fNewlyGenerated);
+       void DiscardWalk(uint64* pIndexE);
+};
+
+#endif
diff --git a/Server Applications/rsearchi/CrackEngine.cpp b/Server Applications/rsearchi/CrackEngine.cpp
new file mode 100644 (file)
index 0000000..d2c4a43
--- /dev/null
@@ -0,0 +1,604 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "CrackEngine.h"
+
+#include <time.h>
+
+CCrackEngine::CCrackEngine()
+{
+       ResetStatistics();
+}
+
+CCrackEngine::~CCrackEngine()
+{
+}
+
+//////////////////////////////////////////////////////////////////////
+
+void CCrackEngine::ResetStatistics()
+{
+       m_fTotalDiskAccessTime               = 0.0f;
+       m_fTotalCryptanalysisTime            = 0.0f;
+       m_nTotalChainWalkStep                = 0;
+       m_nTotalFalseAlarm                   = 0;
+       m_nTotalChainWalkStepDueToFalseAlarm = 0;
+}
+
+RainbowChain *CCrackEngine::BinarySearch(RainbowChain *pChain, int nChainCountRead, uint64 nIndex, IndexChain *pIndex, int nIndexSize, int nIndexStart)
+{
+       uint64 nPrefix = nIndex >> 16;
+       int nLow, nHigh;        
+       //vector<RainbowChain> vChain;
+       //clock_t t1Search = clock();
+//     for (int j = 0; j < vIndex.size(); j++)
+//     {
+               bool found = false;
+               int nChains = 0;
+               
+               if(nPrefix > pIndex[nIndexSize-1].nPrefix) // check if its in the index file
+               {
+                       return NULL;
+               }
+               /*
+               clock_t t1Index = clock();              
+               for(int i = 0; i < vIndexSize[j]; i++)
+               {
+                       
+                       if(nPrefix > pIndex[i].nPrefix)
+                       {
+               //              nChains += pIndex[i].nChainCount;
+                               continue;
+                       }
+                       else if(nPrefix == pIndex[i].nPrefix)
+                       {
+               //              nLow = nChains;
+               //              nHigh = nLow + pIndex[i].nChainCount;
+                               nLow = 5;
+                               nHigh = 8;
+               //              unsigned int nChunk = pIndex[i].nChainCount * 8;
+                               //printf("prefix found %i. Limiting chunk size to %i chains\n", pIndex[i].nPrefix, pIndex[i].nChainCount);
+                               found = true;
+                               break;
+                       }
+                       else 
+                       {
+                               break;
+                       }
+               }
+               clock_t t2Index = clock();
+               m_fIndexSearchTime += 1.0f * (t2Index - t1Index) / CLOCKS_PER_SEC;
+               */
+
+               clock_t t1Index = clock();              
+               int nBLow = 0;
+               int nBHigh = nIndexSize - 1;
+               while (nBLow <= nBHigh)
+               {
+                       int nBMid = (nBLow + nBHigh) / 2;
+                       if (nPrefix == pIndex[nBMid].nPrefix)
+                       {
+                               //nLow = nChains;
+                               int nChains = 0;
+/*                             for(int i = 0; i < nBMid; i++)
+                               {
+                                       nChains += pIndex[i].nChainCount;
+                               }*/
+
+                               nLow = pIndex[nBMid].nFirstChain;
+                               nHigh = nLow + pIndex[nBMid].nChainCount;
+                               if(nLow >= nIndexStart && nLow <= nIndexStart + nChainCountRead) 
+                               {                                       
+                                       if(nHigh > nIndexStart + nChainCountRead)
+                                               nHigh = nIndexStart + nChainCountRead;
+                               }
+                               else if(nLow < nIndexStart && nHigh >= nIndexStart)
+                               {
+                                       nLow = nIndexStart;
+                               }
+                               else break;                                     
+
+//                             printf("Chain Count: %u\n", pIndex[nBMid].nChainCount);
+//                             unsigned int nChunk = pIndex[nBMid].nChainCount * 8;
+                               //printf("prefix found %i. Limiting chunk size to %i chains\n", pIndex[i].nPrefix, pIndex[i].nChainCount);
+
+                               found = true;
+                               break;
+                       }
+                       else if (nPrefix < pIndex[nBMid].nPrefix)
+                               nBHigh = nBMid - 1;
+                       else
+                               nBLow = nBMid + 1;
+               }
+               clock_t t2Index = clock();
+//             m_fIndexSearchTime += 1.0f * (t2Index - t1Index) / CLOCKS_PER_SEC;
+
+//             printf("Time: %.2f nLow: %i nHigh %i\n", (1.0f * (t2Index - t1Index) / CLOCKS_PER_SEC), nLow, nHigh);
+               if(found == true)
+               {
+/*                     for(int i = 0; i < numChains; i++)
+                       {
+                               RainbowChain *chains = new RainbowChain();
+                               memcpy(chains, pChain[nLow + i], sizeof(RainbowChain));
+                       }*/
+//                     printf("Numchains: %i ", numChains);
+                       //                      clock_t t1 = clock();
+                       if(pChain == NULL) // The chains are not preloaded. We need to seek the file for the chains
+                       {
+                               int numChains = nHigh - nLow;
+                               fseek(m_fChains, nLow * 8, SEEK_SET);
+                               RainbowChain *tmpChain = (RainbowChain*) new unsigned char[numChains * sizeof(RainbowChain)];
+                               memset(tmpChain, 0x00, numChains * sizeof(RainbowChain));
+                               unsigned char *data = new unsigned char[numChains * 8];
+                               fread(data, 1, numChains * 8, m_fChains);
+
+                               for(int i = 0; i < numChains; i++)
+                               {
+                                       memcpy(&tmpChain[i].nIndexS, &data[i * 8], 5);
+                                       memcpy(&tmpChain[i].nIndexE, &data[i * 8 + 5], 2);
+                                       memcpy(&tmpChain[i].nCheckPoint, &data[i * 8 + 7], 1);                          
+                               }
+                               for(int i = 0; i < numChains; i++)
+                               {
+                                       // TODO: Seek to the position in the file, read the chains and check them
+                                       int nSIndex = ((int)nIndex) & 0x0000FFFF;                               
+                                       if (nSIndex == tmpChain[i].nIndexE)
+                                       {
+                                               RainbowChain *chain = new RainbowChain();
+                                               memcpy(chain, &tmpChain[i], sizeof(tmpChain));
+                                               delete tmpChain;
+                                               return chain;
+                                       }                               
+                                       else if(tmpChain[i].nIndexE > nSIndex)
+                                               break;
+                               }
+                               delete tmpChain;
+                       }
+                       else
+                       {
+                               for(int i = nLow - nIndexStart; i < nHigh - nIndexStart; i++)
+                               {
+                                       // TODO: Seek to the position in the file, read the chains and check them
+                                       int nSIndex = ((int)nIndex) & 0x0000FFFF;                               
+                                       if (nSIndex == pChain[i].nIndexE)
+                                       {
+                                               return &pChain[i];
+                                       }                               
+                                       else if(pChain[i].nIndexE > nSIndex)
+                                               break;
+                               }
+                       }
+               }
+//     }
+//     clock_t t2Search = clock();
+//     m_fIndexSearchTime += 1.0f * (t2Search - t1Search) / CLOCKS_PER_SEC;
+       
+       return NULL;
+}
+
+
+void CCrackEngine::SearchTableChunk(RainbowChain* pChain, int nRainbowChainLen, int nRainbowChainCount, CHashSet& hs, IndexChain *pIndex, int nIndexSize, int nChainStart)
+{
+       vector<string> vHash;
+       vector<uint64 *> vIndices;
+       vector<RainbowChain *> vChains;
+       hs.GetLeftHashWithLen(vHash, vIndices, CChainWalkContext::GetHashLen());
+       printf("searching for %d hash%s...\n", vHash.size(),
+                                                                                  vHash.size() > 1 ? "es" : "");
+
+       int nChainWalkStep = 0;
+       int nFalseAlarm = 0;
+       int nChainWalkStepDueToFalseAlarm = 0;
+
+       int nHashIndex;
+       for (nHashIndex = 0; nHashIndex < vHash.size(); nHashIndex++)
+       {
+               unsigned char TargetHash[MAX_HASH_LEN];
+               int nHashLen;
+//             printf("\nParsing hash...");
+               ParseHash(vHash[nHashIndex], TargetHash, nHashLen);
+//             printf("Done!\n");
+               if (nHashLen != CChainWalkContext::GetHashLen())
+                       printf("debug: nHashLen mismatch\n");
+
+               // Rqeuest ChainWalk
+               bool fNewlyGenerated;
+//             printf("Requesting walk...");
+               //uint64* pStartPosIndexE = 
+               uint64 *pStartPosIndexE = vIndices[nHashIndex];
+/*
+                       m_cws.RequestWalk(TargetHash,
+                                                                                                       nHashLen,
+                                                                                                       CChainWalkContext::GetHashRoutineName(),
+                                                                                                       CChainWalkContext::GetPlainCharsetName(),
+                                                                                                       CChainWalkContext::GetPlainLenMin(),
+                                                                                                       CChainWalkContext::GetPlainLenMax(),
+                                                                                                       CChainWalkContext::GetRainbowTableIndex(),
+                                                                                                       nRainbowChainLen,
+                                                                                                       fNewlyGenerated);
+                                                                                                       */
+//             printf("done!\n");
+//             printf("debug: using %s walk for %s\n", fNewlyGenerated ? "newly generated" : "existing",
+//                                                                                             vHash[nHashIndex].c_str());
+
+               // Walk
+               int nPos;
+                       /*
+               if (fNewlyGenerated)
+               {
+                       printf("Pregenerating index...");
+                       for (nPos = nRainbowChainLen - 2; nPos >= 0; nPos--)
+                       {
+
+                                       
+                                       CChainWalkContext cwc;
+                                       cwc.SetHash(TargetHash);
+                                       cwc.HashToIndex(nPos);
+                                       int i;
+                                       for (i = nPos + 1; i <= nRainbowChainLen - 2; i++)
+                                       {
+                                               cwc.IndexToPlain();
+                                               cwc.PlainToHash();
+                                               cwc.HashToIndex(i);
+                                       }
+                                       pStartPosIndexE[nPos] = cwc.GetIndex();
+                                       nChainWalkStep += nRainbowChainLen - 2 - nPos;
+                       }
+                       printf("ok\n");
+
+               }
+               */
+               
+               for (nPos = nRainbowChainLen - 2; nPos >= 0; nPos--)
+               {
+                       uint64 nIndexEOfCurPos = pStartPosIndexE[nPos];
+               
+//                     printf("%I64u,\n", nIndexEOfCurPos);
+                       
+                       // Search matching nIndexE
+                       RainbowChain *pChainFound = BinarySearch(pChain, nRainbowChainCount, nIndexEOfCurPos, pIndex, nIndexSize, nChainStart);
+                       if (pChainFound != NULL)
+                       {
+                               
+                               FoundRainbowChain chain; // Convert to FoundRainbowChain which allows us to add a line at which position we found the chain                             
+                               memcpy(&chain, pChainFound, sizeof(RainbowChain));
+                               chain.nGuessedPos = nPos;
+                               hs.AddChain(vHash[nHashIndex], chain);
+                               if(pChain == NULL) // We need to delete the chain because its only temporarily loaded
+                                       delete pChainFound;
+/*                             int nMatchingIndexEFrom, nMatchingIndexETo;
+                               GetChainIndexRangeWithSameEndpoint(pChain, nRainbowChainCount,
+                                                                                                  nMatchingIndexE,
+                                                                                                  nMatchingIndexEFrom, nMatchingIndexETo);
+                                                                                                  */
+//                             int i;
+                       //      printf("%i - %i = \n", nMatchingIndexEFrom, nMatchingIndexETo, ((nMatchingIndexETo - nMatchingIndexEFrom) +1));
+/*                             for (i = 0; i < vChain.size(); i++)
+//                             {
+
+/*                                     if (CheckAlarm(&vChain[i], nPos, TargetHash, hs))
+                                       {
+                                               //printf("debug: discarding walk for %s\n", vHash[nHashIndex].c_str());
+                                               //m_cws.DiscardWalk(pStartPosIndexE);
+                                               goto NEXT_HASH;
+                                       }
+                                       else
+                                       {
+                                               nChainWalkStepDueToFalseAlarm += nPos + 1;
+                                               nFalseAlarm++;
+                                       }*/
+//                             }
+                       }
+               }
+NEXT_HASH:;
+       }
+
+       //printf("debug: chain walk step: %d\n", nChainWalkStep);
+       //printf("debug: false alarm: %d\n", nFalseAlarm);
+       //printf("debug: chain walk step due to false alarm: %d\n", nChainWalkStepDueToFalseAlarm);
+/*
+       m_nTotalChainWalkStep += nChainWalkStep;
+       m_nTotalFalseAlarm += nFalseAlarm;
+       m_nTotalChainWalkStepDueToFalseAlarm += nChainWalkStepDueToFalseAlarm;
+       */
+}
+
+void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
+{
+       // FileName
+#ifdef _WIN32
+       int nIndex = sPathName.find_last_of('\\');
+#else
+       int nIndex = sPathName.find_last_of('/');
+#endif
+       string sFileName;
+       if (nIndex != -1)
+               sFileName = sPathName.substr(nIndex + 1);
+       else
+               sFileName = sPathName;
+
+       // Info
+       printf("%s:\n", sFileName.c_str());
+
+       // Setup
+       int nRainbowChainLen, nRainbowChainCount;
+       if (!CChainWalkContext::SetupWithPathName(sPathName, nRainbowChainLen, nRainbowChainCount))
+               return;
+
+       // Already finished?
+       if (!hs.AnyHashLeftWithLen(CChainWalkContext::GetHashLen()))
+       {
+               printf("this table contains hashes with length %d only\n", CChainWalkContext::GetHashLen());
+               return;
+       }
+
+       // Open
+       FILE* file = fopen(sPathName.c_str(), "rb");
+       if (file != NULL)
+       {
+               // File length check
+               unsigned int nFileLen = GetFileLen(file);
+               if (nFileLen % 8 != 0 || nRainbowChainCount * 8 != nFileLen)
+                       printf("file length mismatch\n");
+               else
+               {
+                       FILE* fIndex = fopen(((string)(sPathName + string(".index"))).c_str(), "rb");
+                       IndexChain *pIndex = NULL;
+                       int nIndexSize = 0;
+                       if(fIndex != NULL)
+                       {
+                               // File length check
+                               unsigned int nTotalChainCount = nFileLen / 8;
+                               unsigned int nIndexFileLen = GetFileLen(fIndex);
+
+                               unsigned int nRows = nIndexFileLen / 11;
+                               unsigned int nSize = nRows * sizeof(IndexChain);
+                               if (nIndexFileLen % 11 != 0)
+                                       printf("index file length mismatch (%u bytes)\n", nIndexFileLen);
+                               else
+                               {
+                                       pIndex = (IndexChain*)new unsigned char[nSize];
+                                       memset(pIndex, 0x00, nSize);
+                                       fseek(fIndex, 0, SEEK_SET);
+                                       unsigned char *pData = new unsigned char[11];
+                                       int nRead = 0;
+                                       uint64 nLastPrefix = 0;
+                                       for(int i = 0; (i * 11) < nIndexFileLen; i++)
+                                       {
+                                               nRead = fread(pData, 1, 11, fIndex);
+                                               if(nRead == 11)
+                                               {
+//                                                     nDataRead += nRead;
+                                                       memcpy(&pIndex[i].nPrefix, &pData[0], 5);
+                                                       memcpy(&pIndex[i].nFirstChain, &pData[5], 4);
+                                                       memcpy(&pIndex[i].nChainCount, &pData[9], 2);
+                                               }
+                                               else break;
+                                               // Index checking part
+                                               if(i != 0 && pIndex[i].nFirstChain < pIndex[i-1].nFirstChain)
+                                               {
+                                                       printf("Corrupted index detected (FirstChain is lower than previous)\n");
+                                                       exit(-1);
+                                               }
+                                               else if(i != 0 && pIndex[i].nFirstChain != pIndex[i-1].nFirstChain + pIndex[i-1].nChainCount)
+                                               {
+                                                       printf("Corrupted index detected (LastChain + nChainCount != FirstChain)\n");
+                                                       exit(-1);
+                                               }
+                                               else if(pIndex[i].nPrefix < nLastPrefix)
+                                               {
+                                                       printf("Corrupted index detected (Prefix is decreasing)\n");
+                                                       exit(-1);
+                                               }
+                                               nLastPrefix = pIndex[i].nPrefix;
+
+                                       }
+                                       nIndexSize = nRows;
+                                       if(pIndex[nIndexSize - 1].nFirstChain + pIndex[nIndexSize - 1].nChainCount + 1 <= nTotalChainCount) // +1 is needed.
+                                       {
+                                               printf("Corrupted index detected: Not covering the entire file\n");
+                                               exit(-1);
+                                       }
+                                       if(pIndex[nIndexSize - 1].nFirstChain + pIndex[nIndexSize - 1].nChainCount > nTotalChainCount) // +1 is not needed here
+                                       {
+                                               printf("Corrupted index detected: The index is covering more than the file. Covering %u of %u chains\n", pIndex[nIndexSize - 1].nFirstChain + pIndex[nIndexSize - 1].nChainCount, nTotalChainCount);
+                                               exit(-1);
+                                       }
+                                       fclose(fIndex);
+                                       delete pData;
+                                       printf("Index loaded successfully\n");
+                               }               
+                       }
+                       else 
+                       {
+                               printf("Can't load index\n");
+                               return;
+                       }
+/*                     if(hs.GetStatHashTotal() > 10)
+                       {*/
+                               static CMemoryPool mp;
+                               unsigned int nAllocatedSize;
+                               RainbowChain* pChain = (RainbowChain*)mp.Allocate(nFileLen * 2, nAllocatedSize);
+                               if (pChain != NULL)
+                               {
+                                       nAllocatedSize = nAllocatedSize / 16 * 16;              // Round to 16-byte boundary
+
+                                       fseek(file, 0, SEEK_SET);
+                                       bool fVerified = false;
+                                       int nProcessedChains = 0;
+                                       while (true)    // Chunk read loop
+                                       {
+                                               if (ftell(file) == nFileLen)
+                                                       break;
+
+                                               // Load table chunk
+                                               memset(pChain, 0x00, nAllocatedSize);
+                                               printf("reading...\n");
+                                               unsigned char *pData = new unsigned char[8];
+                                               unsigned int nDataRead = 0;
+                                               unsigned int nRead = 0;
+                                               clock_t t1 = clock();
+                                               for(int i = 0; i < nAllocatedSize / 16; i++) // Chain size is 16 bytes
+                                               {
+                                                       nRead = fread(pData, 1, 8, file);
+                                                       if(nRead == 8)
+                                                       {
+                                                               nDataRead += nRead;
+                                                               memcpy(&pChain[i].nIndexS, &pData[0], 6);
+                                                               memcpy(&pChain[i].nIndexE, &pData[6], 2);
+//                                                             memcpy(&pChain[i].nCheckPoint, &pData[7], 1);                                           
+                                                       }
+                                                       else break;
+                                               }
+                                               clock_t t2 = clock();
+                                               delete pData;
+       //                                      unsigned int nDataRead = fread(pChain, 1, nAllocatedSize, file);
+                                               float fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+                                               printf("%u bytes read, disk access time: %.2f s\n", nDataRead, fTime);
+                                               m_fTotalDiskAccessTime += fTime;
+                                               int nRainbowChainCountRead = nDataRead / 8;
+                                               // Verify table chunk
+                                               
+                                               if (!fVerified)
+                                               {
+                                                       printf("verifying the file...\n");
+
+                                                       // Chain length test
+                                                       int nIndexToVerify = nRainbowChainCountRead / 2;
+/*                                                     CChainWalkContext cwc;
+                                                       cwc.SetIndex(pChain[nIndexToVerify].nIndexS);
+                                                       int nPos;
+                                                       for (nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
+                                                       {
+                                                               cwc.IndexToPlain();
+                                                               cwc.PlainToHash();
+                                                               cwc.HashToIndex(nPos);
+                                                       }
+                                                       
+                                                       uint64 nEndPoint = 0;
+                                                       for(int i = 0; i < nIndexSize; i++)
+                                                       {
+                                                               if(nIndexToVerify >= pIndex[i].nFirstChain && nIndexToVerify < pIndex[i].nFirstChain + pIndex[i].nChainCount) // We found the matching index
+                                                               { // Now we need to seek nIndexToVerify into the chains
+                                                                       nEndPoint += pIndex[i].nPrefix << 16;
+                                                                       nEndPoint += pChain[nIndexToVerify].nIndexE;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       if (cwc.GetIndex() != nEndPoint)
+                                                       {
+                                                               printf("rainbow chain length verify fail\n");
+                                                               break;
+                                                       }
+*/
+                                                       // Chain sort test
+                                                       // We assume its sorted in the indexing process
+                                                       /*
+                                                       int i;
+                                                       for (i = 0; i < nRainbowChainCountRead - 1; i++)
+                                                       {
+                                                               if (pChain[i].nIndexE > pChain[i + 1].nIndexE)
+                                                                       break;
+                                                       }
+                                                       if (i != nRainbowChainCountRead - 1)
+                                                       {
+                                                               printf("this file is not sorted\n");
+                                                               break;
+                                                       }
+                                                       */
+                                                       fVerified = true;
+                                               }
+       
+                                               // Search table chunk
+                                               t1 = clock();
+                                               SearchTableChunk(pChain, nRainbowChainLen, nRainbowChainCountRead, hs, pIndex, nIndexSize, nProcessedChains);
+                                               t2 = clock();
+                                               fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+                                               printf("cryptanalysis time: %.2f s\n", fTime);
+                                               m_fTotalCryptanalysisTime += fTime;
+                                               nProcessedChains += nRainbowChainCountRead;
+                                               // Already finished?
+                                               if (!hs.AnyHashLeftWithLen(CChainWalkContext::GetHashLen()))
+                                                       break;
+                                       }
+                               }
+                               else printf("memory allocation fail\n");
+                       //}
+/*                     else // So few hashes to search for. No need to load the entire chain file.
+                       {
+                               clock_t t1 = clock();
+                               m_fChains = file;
+                               SearchTableChunk(NULL, nRainbowChainLen, 0, hs, pIndex, nIndexSize, 0);
+                               clock_t t2 = clock();
+                               float fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC;
+                               printf("cryptanalysis time: %.2f s\n", fTime);
+                               m_fTotalCryptanalysisTime += fTime;
+
+                       }*/
+
+                       delete pIndex;
+               }
+               fclose(file);
+       }
+       else
+               printf("can't open file\n");
+}
+
+void CCrackEngine::Run(vector<string> vPathName, CHashSet& hs)
+{
+       // Reset statistics
+       ResetStatistics();
+
+       // Sort vPathName (CChainWalkSet need it)
+       int i, j;
+       for (i = 0; i < vPathName.size() - 1; i++)
+               for (j = 0; j < vPathName.size() - i - 1; j++)
+               {
+                       if (vPathName[j] > vPathName[j + 1])
+                       {
+                               string sTemp;
+                               sTemp = vPathName[j];
+                               vPathName[j] = vPathName[j + 1];
+                               vPathName[j + 1] = sTemp;
+                       }
+               }
+
+       // Run
+       for (i = 0; i < vPathName.size() && hs.AnyhashLeft(); i++)
+       {
+               SearchRainbowTable(vPathName[i], hs);
+               printf("\n");
+       }
+}
+
+float CCrackEngine::GetStatTotalDiskAccessTime()
+{
+       return m_fTotalDiskAccessTime;
+}
+
+float CCrackEngine::GetStatTotalCryptanalysisTime()
+{
+       return m_fTotalCryptanalysisTime;
+}
+
+int CCrackEngine::GetStatTotalChainWalkStep()
+{
+       return m_nTotalChainWalkStep;
+}
+
+int CCrackEngine::GetStatTotalFalseAlarm()
+{
+       return m_nTotalFalseAlarm;
+}
+
+int CCrackEngine::GetStatTotalChainWalkStepDueToFalseAlarm()
+{
+       return m_nTotalChainWalkStepDueToFalseAlarm;
+}
diff --git a/Server Applications/rsearchi/CrackEngine.h b/Server Applications/rsearchi/CrackEngine.h
new file mode 100644 (file)
index 0000000..996072e
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _CRACKENGINE_H
+#define _CRACKENGINE_H
+
+#include "Public.h"
+#include "HashSet.h"
+#include "ChainWalkContext.h"
+#include "MemoryPool.h"
+#include "ChainWalkSet.h"
+
+class CCrackEngine
+{
+public:
+       CCrackEngine();
+       virtual ~CCrackEngine();
+
+private:
+       CChainWalkSet m_cws;
+
+       // Statistics
+       float m_fTotalDiskAccessTime;
+       float m_fTotalCryptanalysisTime;
+       int m_nTotalChainWalkStep;
+       int m_nTotalFalseAlarm;
+       int m_nTotalChainWalkStepDueToFalseAlarm;
+       FILE *m_fChains;
+private:
+       void ResetStatistics();
+       RainbowChain *BinarySearch(RainbowChain *pChain, int nChainCountRead, uint64 nIndex, IndexChain *pIndex, int nIndexSize, int nIndexStart);
+       void SearchTableChunk(RainbowChain* pChain, int nRainbowChainLen, int nRainbowChainCount, CHashSet& hs, IndexChain *pIndex, int nIndexSize, int nChainStart);
+
+public:
+       void SearchRainbowTable(string sPathName, CHashSet& hs);
+       void Run(vector<string> vPathName, CHashSet& hs);
+       float GetStatTotalDiskAccessTime();
+       float GetStatTotalCryptanalysisTime();
+       int   GetStatTotalChainWalkStep();
+       int   GetStatTotalFalseAlarm();
+       int   GetStatTotalChainWalkStepDueToFalseAlarm();
+};
+
+#endif
diff --git a/Server Applications/rsearchi/Database.h b/Server Applications/rsearchi/Database.h
new file mode 100644 (file)
index 0000000..3f70dca
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __DATABASE_H__
+#define __DATABASE_H__
+typedef __int64 uint64;
+class CDatabase
+{
+public:
+       virtual void Query(std::string szQuery) = 0;
+       virtual uint64 Select(std::string szQuery) = 0;
+       virtual int SelectUnbuffered(std::string szQuery) = 0;
+       virtual int Fetch() = 0;
+       virtual void Escape(std::string& szQuery) = 0;
+       virtual int GetInt(int nColumn) = 0;
+       virtual const unsigned char* GetText(int nColumn) = 0;
+       virtual __int64 GetInt64(int Column) = 0;
+       virtual __int64 GetLastInsertID() = 0; 
+       virtual __int64 GetAffectedRows() = 0;
+};
+
+#endif
+
diff --git a/Server Applications/rsearchi/Exception.cpp b/Server Applications/rsearchi/Exception.cpp
new file mode 100644 (file)
index 0000000..06f3a5c
--- /dev/null
@@ -0,0 +1,18 @@
+
+#include "Exception.h"
+
+Exception::Exception(std::string szErrorMessage)
+{
+       m_Message = szErrorMessage;
+}
+
+Exception::~Exception(void)
+{
+}
+
+const char* Exception::GetErrorMessage()
+{
+       return m_Message.c_str();
+}
+
+
diff --git a/Server Applications/rsearchi/Exception.h b/Server Applications/rsearchi/Exception.h
new file mode 100644 (file)
index 0000000..56482ff
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __EXCEPTION_H__
+#define __EXCEPTION_H__
+#include <string>
+
+
+class Exception
+{
+protected:
+       std::string m_Message;
+
+public:
+       Exception(std::string szErrorMessage);
+       const char* GetErrorMessage();
+public:
+       ~Exception(void);
+};
+
+class DatabaseException : public Exception
+{
+protected:
+       unsigned int nErrorCode;        
+       
+public:
+       DatabaseException(std::string szError, unsigned int nErrorNum) : Exception(szError) { nErrorCode = nErrorNum; };
+       unsigned int getErrorCode() { return nErrorCode; }
+};
+
+#endif
+
diff --git a/Server Applications/rsearchi/HashAlgorithm.cpp b/Server Applications/rsearchi/HashAlgorithm.cpp
new file mode 100644 (file)
index 0000000..07cebe5
--- /dev/null
@@ -0,0 +1,349 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "HashAlgorithm.h"
+
+#include "Public.h"
+
+#include <openssl/des.h>
+#include <openssl/md2.h>
+#include <openssl/md4.h>
+#include <openssl/md5.h>
+#include <openssl/sha.h>
+#include <openssl/ripemd.h>
+#ifdef _WIN32
+       #pragma comment(lib, "libeay32.lib")
+#endif
+#define MSCACHE_HASH_SIZE 16
+void setup_des_key(unsigned char key_56[], des_key_schedule &ks)
+{
+       des_cblock key;
+
+       key[0] = key_56[0];
+       key[1] = (key_56[0] << 7) | (key_56[1] >> 1);
+       key[2] = (key_56[1] << 6) | (key_56[2] >> 2);
+       key[3] = (key_56[2] << 5) | (key_56[3] >> 3);
+       key[4] = (key_56[3] << 4) | (key_56[4] >> 4);
+       key[5] = (key_56[4] << 3) | (key_56[5] >> 5);
+       key[6] = (key_56[5] << 2) | (key_56[6] >> 6);
+       key[7] = (key_56[6] << 1);
+
+       //des_set_odd_parity(&key);
+       des_set_key(&key, ks);
+}
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       /*
+       unsigned char data[7] = {0};
+       memcpy(data, pPlain, nPlainLen > 7 ? 7 : nPlainLen);
+       */
+
+       int i;
+       for (i = nPlainLen; i < 7; i++)
+               pPlain[i] = 0;
+
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       des_key_schedule ks;
+       //setup_des_key(data, ks);
+       setup_des_key(pPlain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pHash, ks, DES_ENCRYPT);
+}
+
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char pass[14];
+       unsigned char pre_lmresp[21];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+       des_key_schedule ks;
+
+       memset (pass,0,sizeof(pass));
+       memset (pre_lmresp,0,sizeof(pre_lmresp));
+
+       memcpy (pass,pPlain, nPlainLen);
+
+       setup_des_key(pass, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(&pass[7], ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)&pre_lmresp[8], ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[7], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+       setup_des_key(&pre_lmresp[14], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+
+} 
+
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{      
+       unsigned char pre_lmresp[8];
+       static unsigned char magic[] = {0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
+       static unsigned char salt[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+       des_key_schedule ks;
+       unsigned char plain[8] = {0};   
+       memcpy(plain, pPlain, nPlainLen);
+       setup_des_key(plain, ks);
+       des_ecb_encrypt((des_cblock*)magic, (des_cblock*)pre_lmresp, ks, DES_ENCRYPT);
+
+       setup_des_key(pre_lmresp, ks);
+       des_ecb_encrypt((des_cblock*)salt, (des_cblock*)pHash, ks, DES_ENCRYPT);
+} 
+
+
+
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+  unsigned char UnicodePlain[MAX_PLAIN_LEN];
+  static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+  
+  int len = (nPlainLen < 127) ? nPlainLen : 127;
+  int i;
+  
+  for (i = 0; i < len; i++)
+  {
+    UnicodePlain[i * 2] = pPlain[i];
+    UnicodePlain[i * 2 + 1] = 0x00;
+  }
+
+  des_key_schedule ks;
+  unsigned char lm[21];
+
+  MD4(UnicodePlain, len * 2, lm);
+  lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
+
+  setup_des_key(lm, ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[7], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+
+  setup_des_key(&lm[14], ks);
+  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+}
+
+
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char ToEncrypt[256];
+       char temp[256];
+       char username[256];
+
+       DES_cblock iv,iv2;
+       DES_key_schedule ks1,ks2;
+       unsigned char deskey_fixed[]={ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
+       int i,j;
+
+       strcpy (username, "SYS");
+       int userlen = 3;
+       
+//     strupr ((char*) pPlain);
+       memset (ToEncrypt,0,sizeof(ToEncrypt));
+
+       for (i=1,j=0; j<userlen; i++,j++)
+       {
+               ToEncrypt[i] = username[j];
+               i++;
+       }
+
+       for (j=0; j<nPlainLen; i++,j++)
+       {
+               ToEncrypt[i] = pPlain[j];
+               i++;
+       }
+
+       i=i-1;
+       memset (iv,0,8);
+       memset (iv2,0,8);
+       DES_set_key((DES_cblock*) deskey_fixed, &ks1);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks1, &iv, DES_ENCRYPT);
+       DES_set_key((DES_cblock*) &iv, &ks2);
+       DES_ncbc_encrypt((unsigned char*) ToEncrypt, (unsigned char*) temp, i, &ks2, &iv2, DES_ENCRYPT);
+       memcpy (pHash,iv2,8);
+}
+
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char UnicodePlain[MAX_PLAIN_LEN * 2];
+       int i;
+       for (i = 0; i < nPlainLen; i++)
+       {
+               UnicodePlain[i * 2] = pPlain[i];
+               UnicodePlain[i * 2 + 1] = 0x00;
+       }
+
+       MD4(UnicodePlain, nPlainLen * 2, pHash);
+}
+
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD2(pPlain, nPlainLen, pHash);
+}
+
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD4(pPlain, nPlainLen, pHash);
+}
+
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       MD5(pPlain, nPlainLen, pHash);
+}
+
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       SHA1(pPlain, nPlainLen, pHash);
+}
+
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       RIPEMD160(pPlain, nPlainLen, pHash);
+}
+
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char unicode_pwd[256];
+       char unicode_user[256];
+       static unsigned char username[] = "administrator";
+       static int userlen = 13;
+       unsigned char   final1[MD4_DIGEST_LENGTH];
+       MD4_CTX ctx;
+       int i;
+
+//     strcpy (username, "administrator");
+//     userlen = 13;
+
+       for (i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }
+
+       for (i=0; i<userlen; i++)
+       {
+               unicode_user[i*2] = username[i];
+               unicode_user[i*2+1] = 0x00;
+       }
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,unicode_pwd,nPlainLen*2);
+       MD4_Final(final1,&ctx);
+
+       MD4_Init(&ctx);
+       MD4_Update(&ctx,final1,MD4_DIGEST_LENGTH);
+       MD4_Update(&ctx,(unsigned char*) unicode_user,userlen*2);
+       MD4_Final(pHash,&ctx);
+
+       /*
+       unsigned char unicode_pwd[256];
+       for (int i=0; i<nPlainLen; i++)
+       {
+               unicode_pwd[i*2] = pPlain[i];
+               unicode_pwd[i*2+1] = 0x00;
+       }*/     
+       /*
+       unsigned char *buf = (unsigned char*)calloc(MSCACHE_HASH_SIZE + nSaltLength, sizeof(unsigned char));    
+       HashNTLM(pPlain, nPlainLen, buf, NULL);
+       //MD4(unicode_pwd, nPlainLen*2, buf);
+       memcpy(buf + MSCACHE_HASH_SIZE, pSalt, nSaltLength);
+       MD4(buf, MSCACHE_HASH_SIZE + nSaltLength, pHash); 
+       free(buf);
+       */
+}
+
+//*********************************************************************************
+// Code for MySQL password hashing
+//*********************************************************************************
+
+inline void mysql_hash_password_323(unsigned long *result, const char *password) 
+{
+  register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
+  unsigned long tmp;
+  for (; *password ; password++) 
+  {
+    if (*password == ' ' || *password == '\t') continue;
+       tmp= (unsigned long) (unsigned char) *password;
+       nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
+       nr2+=(nr2 << 8) ^ nr;
+       add+=tmp;
+  }
+  result[0]=nr & (((unsigned long) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
+  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
+  return;
+}
+
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned long hash_pass[2];     
+       unsigned char* f = (unsigned char*) hash_pass;
+
+       unsigned char* pass = (unsigned char*) calloc (nPlainLen+4,sizeof(unsigned char));
+       memcpy(pass,pPlain,nPlainLen);
+
+       mysql_hash_password_323(hash_pass, (char*) pass);
+       pHash[0]=*(f+3); pHash[1]=*(f+2); pHash[2]=*(f+1); pHash[3]=*(f+0);
+       pHash[4]=*(f+7); pHash[5]=*(f+6); pHash[6]=*(f+5); pHash[7]=*(f+4);
+
+       free (pass);
+}
+
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       unsigned char hash_stage1[SHA_DIGEST_LENGTH];
+       SHA_CTX ctx;
+
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, (unsigned char *) pPlain, nPlainLen);
+       SHA1_Final(hash_stage1, &ctx);
+       SHA1_Init(&ctx);
+       SHA1_Update(&ctx, hash_stage1, SHA_DIGEST_LENGTH);
+       SHA1_Final(pHash, &ctx);
+}
+
+//*********************************************************************************
+// Code for PIX password hashing
+//*********************************************************************************
+static char itoa64[] =          /* 0 ... 63 => ascii - 64 */
+        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void _crypt_to64(char *s, unsigned long v, int n)
+{
+        while (--n >= 0) {
+                *s++ = itoa64[v&0x3f];
+                v >>= 6;
+        }
+}
+
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
+{
+       char temp[MD5_DIGEST_LENGTH+1];
+       unsigned char final[MD5_DIGEST_LENGTH];
+       char* pass = (char*) calloc (nPlainLen+MD5_DIGEST_LENGTH,sizeof(char));
+
+       memcpy (pass,pPlain,nPlainLen);
+
+       MD5_CTX ctx;
+       MD5_Init(&ctx);
+       MD5_Update(&ctx, (unsigned char *) pass, MD5_DIGEST_LENGTH);
+       MD5_Final(final, &ctx);
+
+       char* p = (char*) temp;
+       _crypt_to64(p,*(unsigned long*) (final+0),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+4),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+8),4); p += 4;
+       _crypt_to64(p,*(unsigned long*) (final+12),4); p += 4;
+       *p=0;
+
+       memcpy(pHash,temp,MD5_DIGEST_LENGTH);
+
+       free (pass);
+}
diff --git a/Server Applications/rsearchi/HashAlgorithm.h b/Server Applications/rsearchi/HashAlgorithm.h
new file mode 100644 (file)
index 0000000..b617f9f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHALGORITHM_H
+#define _HASHALGORITHM_H
+
+void HashLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash);
+//****************************************************************************
+// MySQL Password Hashing
+//****************************************************************************
+void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// Cisco PIX Password Hashing
+//****************************************************************************
+void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+//****************************************************************************
+// (HALF) LM CHALL hashing
+void HashLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+// From mao
+void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+#endif
diff --git a/Server Applications/rsearchi/HashRoutine.cpp b/Server Applications/rsearchi/HashRoutine.cpp
new file mode 100644 (file)
index 0000000..b61ae63
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+
+#include "HashRoutine.h"
+#include "HashAlgorithm.h"
+
+//////////////////////////////////////////////////////////////////////
+
+CHashRoutine::CHashRoutine()
+{
+       // Notice: MIN_HASH_LEN <= nHashLen <= MAX_HASH_LEN
+
+       AddHashRoutine("lm",   HashLM,   8);
+       AddHashRoutine("md5",  HashMD5,  16);
+       AddHashRoutine("sha1", HashSHA1, 20);
+       AddHashRoutine("ntlm", HashNTLM, 16);
+}      
+
+CHashRoutine::~CHashRoutine()
+{
+}
+
+void CHashRoutine::AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen)
+{
+       vHashRoutineName.push_back(sHashRoutineName);
+       vHashRoutine.push_back(pHashRoutine);
+       vHashLen.push_back(nHashLen);
+}
+
+string CHashRoutine::GetAllHashRoutineName()
+{
+       string sRet;
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+               sRet += vHashRoutineName[i] + " ";
+
+       return sRet;
+}
+
+void CHashRoutine::GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < vHashRoutineName.size(); i++)
+       {
+               if (sHashRoutineName == vHashRoutineName[i])
+               {
+                       pHashRoutine = vHashRoutine[i];
+                       nHashLen = vHashLen[i];
+                       return;
+               }
+       }
+
+       pHashRoutine = NULL;
+       nHashLen = 0;
+}
diff --git a/Server Applications/rsearchi/HashRoutine.h b/Server Applications/rsearchi/HashRoutine.h
new file mode 100644 (file)
index 0000000..681fa78
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHROUTINE_H
+#define _HASHROUTINE_H
+
+#include <string>
+#include <vector>
+using namespace std;
+
+typedef void (*HASHROUTINE)(unsigned char* pPlain, int nPlainLen, unsigned char* pHash);
+
+class CHashRoutine  
+{
+public:
+       CHashRoutine();
+       virtual ~CHashRoutine();
+
+private:
+       vector<string>          vHashRoutineName;
+       vector<HASHROUTINE>     vHashRoutine;
+       vector<int>                     vHashLen;
+       void AddHashRoutine(string sHashRoutineName, HASHROUTINE pHashRoutine, int nHashLen);
+
+public:
+       string GetAllHashRoutineName();
+       void GetHashRoutine(string sHashRoutineName, HASHROUTINE& pHashRoutine, int& nHashLen);
+};
+
+#endif
diff --git a/Server Applications/rsearchi/HashSet.cpp b/Server Applications/rsearchi/HashSet.cpp
new file mode 100644 (file)
index 0000000..f99cb19
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#else
+#define _atoi64 atoll
+#define stricmp strcasecmp
+#endif
+
+#include "HashSet.h"
+#include <string.h>
+CHashSet::CHashSet()
+{
+}
+
+CHashSet::~CHashSet()
+{
+       for(int i = 0; i < m_vIndices.size(); i++)
+       {
+               delete m_vIndices[i];           
+       }
+}
+int CHashSet::GetLookupID(string sHash)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
+               {
+                       return m_vLookupIDs[i];
+               }
+       }
+
+}
+void CHashSet::AddHash(string sHash, uint64 *pIndices, int nLookupID)
+{
+       if (sHash == "aad3b435b51404ee")
+               return;
+
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vHash[i] == sHash)
+                       return;
+       }
+
+       //printf("debug: adding hash %s\n", sHash.c_str());
+
+       m_vHash.push_back(sHash);
+       m_vFound.push_back(false);
+       m_vPlain.push_back("");
+       m_vBinary.push_back("");
+       m_vIndices.push_back(pIndices);
+       m_vLookupIDs.push_back(nLookupID);
+       VECTOR_CHAIN vec;
+       m_vFoundChains.push_back(vec);
+}
+
+bool CHashSet::AnyhashLeft()
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (!m_vFound[i])
+                       return true;
+       }
+
+       return false;
+}
+
+bool CHashSet::AnyHashLeftWithLen(int nLen)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (!m_vFound[i])
+                       if (m_vHash[i].size() == nLen * 2)
+                               return true;
+       }
+
+       return false;
+}
+
+void CHashSet::GetLeftHashWithLen(vector<string>& vHash, vector<uint64 *>& vIndices, int nLen)
+{
+       vHash.clear();
+       vIndices.clear();
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (!m_vFound[i])
+                       if (m_vHash[i].size() == nLen * 2)
+                       {
+                               vHash.push_back(m_vHash[i]);
+                               vIndices.push_back(m_vIndices[i]);
+                       }
+       }
+}
+
+void CHashSet::SetPlain(string sHash, string sPlain, string sBinary)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
+               {
+                       m_vFound[i]    = true;
+                       m_vPlain[i]    = sPlain;
+                       m_vBinary[i]   = sBinary;
+                       return;
+               }
+       }
+}
+// Add a chain to verify (matching endpoint)
+void CHashSet::AddChain(string sHash, FoundRainbowChain &Chain)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
+               {
+                       m_vFoundChains[i].push_back(Chain);
+                       return;
+               }
+       }
+}
+/*
+vector<RainbowChain> CHashSet::GetChains(string sHash)
+{
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
+               {
+                       return m_vFoundChains[i];
+               }
+       }
+       VECTOR_CHAIN vec;
+       return vec;
+}*/
+bool CHashSet::GetPlain(string sHash, string& sPlain, string& sBinary)
+{
+       if (stricmp(sHash.c_str(),"aad3b435b51404ee") == 0)
+       {
+               sPlain  = "";
+               sBinary = "";
+               return true;
+       }
+
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vHash[i] == sHash)
+               {
+                       if (m_vFound[i])
+                       {
+                               sPlain  = m_vPlain[i];
+                               sBinary = m_vBinary[i];
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
+int CHashSet::GetStatHashFound()
+{
+       int nHashFound = 0;
+       int i;
+       for (i = 0; i < m_vHash.size(); i++)
+       {
+               if (m_vFound[i])
+                       nHashFound++;
+       }
+
+       return nHashFound;
+}
+
+int CHashSet::GetStatHashTotal()
+{
+       return m_vHash.size();
+}
+
+void CHashSet::GetFoundChains(map<string, VECTOR_CHAIN> &mHashList)
+{
+//     map<string, string> *mHashList = new map<string, string>;
+       for(int i = 0; i < m_vHash.size(); i++)
+       {
+               mHashList[m_vHash[i]] = m_vFoundChains[i];
+       }
+//     return mHashList;
+}
\ No newline at end of file
diff --git a/Server Applications/rsearchi/HashSet.h b/Server Applications/rsearchi/HashSet.h
new file mode 100644 (file)
index 0000000..6302815
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _HASHSET_H
+#define _HASHSET_H
+
+#include "Public.h"
+#include <map>
+using std::map;
+class CHashSet
+{
+public:
+       CHashSet();
+       ~CHashSet();
+
+private:
+       vector<string> m_vHash;
+       vector<bool>   m_vFound;
+       vector<string> m_vPlain;
+       vector<string> m_vBinary;
+       vector<uint64*> m_vIndices;
+       vector<int>     m_vLookupIDs;
+       typedef vector<FoundRainbowChain> VECTOR_CHAIN;
+       vector<VECTOR_CHAIN> m_vFoundChains;
+public:
+       
+       void AddHash(string sHash, uint64 *pIndices, int nLookupID);            // lowercase, len % 2 == 0, MIN_HASH_LEN * 2 <= len <= MAX_HASH_LEN * 2
+       bool AnyhashLeft();
+       bool AnyHashLeftWithLen(int nLen);
+       void GetLeftHashWithLen(vector<string>& vHash, vector<uint64 *>& vIndices, int nLen);
+       void AddChain(string sHash, FoundRainbowChain &Chain);
+       void SetPlain(string sHash, string sPlain, string sBinary);
+       bool GetPlain(string sHash, string& sPlain, string& sBinary);
+       int GetLookupID(string sHash);
+       //vector<FoundRainbowChain> CHashSet::GetChains(string sHash);
+       int GetStatHashFound();
+       int GetStatHashTotal();
+       void GetFoundChains(map<string, VECTOR_CHAIN> &mHashList);
+};
+
+#endif
diff --git a/Server Applications/rsearchi/Makefile b/Server Applications/rsearchi/Makefile
new file mode 100644 (file)
index 0000000..69f48be
--- /dev/null
@@ -0,0 +1,3 @@
+all: rtgen
+rtgen:
+       g++ ChainWalkContext.cpp ChainWalkSet.cpp CrackEngine.cpp Exception.cpp HashAlgorithm.cpp HashRoutine.cpp HashSet.cpp MemoryPool.cpp MySQL.cpp Public.cpp stdafx.cpp rsearch.cpp -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lssl -O3 -o rsearchi
diff --git a/Server Applications/rsearchi/MemoryPool.cpp b/Server Applications/rsearchi/MemoryPool.cpp
new file mode 100644 (file)
index 0000000..5c4d08d
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "MemoryPool.h"
+#include "Public.h"
+
+CMemoryPool::CMemoryPool()
+{
+       m_pMem = NULL;
+       m_nMemSize = 0;
+
+       unsigned int nAvailPhys = GetAvailPhysMemorySize();
+       if (nAvailPhys < 16 * 1024 * 1024)
+               m_nMemMax = nAvailPhys / 2;                                     // Leave some memory for CChainWalkSet
+       else
+               m_nMemMax = nAvailPhys - 8 * 1024 * 1024;       // Leave some memory for CChainWalkSet
+       m_nMemMax = 300 * 1024 * 1024;
+}
+
+CMemoryPool::~CMemoryPool()
+{
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+}
+
+unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
+{
+       if (nFileLen <= m_nMemSize)
+       {
+               nAllocatedSize = nFileLen;
+               return m_pMem;
+       }
+
+       unsigned int nTargetSize;
+       if (nFileLen < m_nMemMax)
+               nTargetSize = nFileLen;
+       else
+               nTargetSize = m_nMemMax;
+
+       // Free existing memory
+       if (m_pMem != NULL)
+       {
+               delete m_pMem;
+               m_pMem = NULL;
+               m_nMemSize = 0;
+       }
+
+       // Allocate new memory
+       //printf("allocating %u bytes memory\n", nTargetSize);
+       m_pMem = new unsigned char[nTargetSize];
+       if (m_pMem != NULL)
+       {
+               m_nMemSize = nTargetSize;
+               nAllocatedSize = nTargetSize;
+               return m_pMem;
+       }
+       else
+       {
+               nAllocatedSize = 0;
+               return NULL;
+       }
+}
diff --git a/Server Applications/rsearchi/MemoryPool.h b/Server Applications/rsearchi/MemoryPool.h
new file mode 100644 (file)
index 0000000..9f2ea4e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _MEMORYPOOL_H
+#define _MEMORYPOOL_H
+
+class CMemoryPool  
+{
+public:
+       CMemoryPool();
+       virtual ~CMemoryPool();
+
+private:
+       unsigned char* m_pMem;
+       unsigned int m_nMemSize;
+
+       unsigned int m_nMemMax;
+
+public:
+       unsigned char* Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize);
+};
+
+#endif
diff --git a/Server Applications/rsearchi/MySQL.cpp b/Server Applications/rsearchi/MySQL.cpp
new file mode 100644 (file)
index 0000000..1e5973d
--- /dev/null
@@ -0,0 +1,203 @@
+#include "stdafx.h"
+#include "MySQL.h"
+#include <sstream>
+#include <stdlib.h>
+#include <iostream>
+MySQL::MySQL(void)
+{
+}
+MySQL::MySQL(std::string Servername, std::string Username, std::string Password, std::string Database, int Port)
+{
+       m_LastResult = NULL;
+#ifdef DEBUG
+//     logfile << "Connecting to database";
+#endif
+       OpenDatabase(Servername, Username, Password, Database, Port);
+}
+MySQL::~MySQL(void)
+{
+       if(m_LastResult != NULL)
+       {
+               mysql_free_result(m_LastResult);
+
+       }
+#ifdef DEBUG
+//     logfile << "Shutting down database connection";
+#endif
+       mysql_close(&m_DBHandle);
+}
+
+void MySQL::OpenDatabase(std::string Servername, std::string Username, std::string Password, std::string Database, int Port)
+{
+       mysql_init(&m_DBHandle);
+       if(!mysql_real_connect(&m_DBHandle, Servername.c_str(), Username.c_str(), Password.c_str(), Database.c_str(), Port, NULL, 0))
+       {
+               std::stringstream error;
+               error << "Could not connect to server: " << mysql_error(&m_DBHandle);
+               throw new MySQLException(error.str(), mysql_errno(&m_DBHandle));
+       }
+       m_Servername = Servername;
+       m_Username = Username;
+       m_Password = Password;
+       m_Database = Database;
+       m_Port = Port;
+}
+
+void MySQL::Reconnect()
+{
+       OpenDatabase(m_Servername, m_Username, m_Password, m_Database, m_Port);
+}
+void MySQL::Query(std::string SQLQuery)
+{
+#ifdef DEBUG
+//     logfile << SQLQuery;
+#endif
+       try
+       {
+               if(mysql_query(&m_DBHandle, SQLQuery.c_str()) != 0)
+               {
+                       std::stringstream error;
+                       error << "Error querying server: " << mysql_error(&m_DBHandle) << std::endl << "SQL: " << SQLQuery;
+                       throw new MySQLException(error.str(), mysql_errno(&m_DBHandle));
+               }
+       }
+       catch(DatabaseException *ex)
+       {
+               if(ex->getErrorCode() == CR_SERVER_LOST)
+               {
+//                     logfile << "Reconnecting to server" << std::endl;
+                       Reconnect();
+                       
+                       Query(SQLQuery);
+               }
+               else throw ex;
+       }
+}
+
+uint64 MySQL::Select(std::string SQLQuery)
+{
+#ifdef DEBUG
+       std::cout << "Doing query " << SQLQuery << std::endl;
+#endif
+       Query(SQLQuery);
+       if(m_LastResult != NULL) { 
+#ifdef DEBUG
+               std::cout << "Freeing up previous result" << std::endl;
+#endif
+               mysql_free_result(m_LastResult); 
+       }
+
+#ifdef DEBUG
+               std::cout << "Transferring result from database server" << std::endl;
+#endif
+               
+       m_LastResult = mysql_store_result(&m_DBHandle);
+       if(m_LastResult == NULL)
+       {
+               std::stringstream szError;
+               szError << "Error while transferring result from database server: " << mysql_error(&m_DBHandle);
+               throw new MySQLException(szError.str(), mysql_errno(&m_DBHandle));
+       }
+#ifdef DEBUG
+       std::cout << "Result transferred OK" << std::endl;
+#endif
+       return true;
+}
+int MySQL::SelectUnbuffered(std::string SQLQuery)
+{
+       Query(SQLQuery);
+       if(m_LastResult != NULL) { 
+#ifdef DEBUG
+       //      logfile << "Freeing up previous result";
+#endif
+               mysql_free_result(m_LastResult); 
+       }
+/*
+#ifdef DEBUG
+               logfile << "Transferring result from database server";
+#endif
+               */
+       m_LastResult = mysql_use_result(&m_DBHandle);
+       if(m_LastResult == NULL)
+       {
+               std::stringstream szError;
+               szError << "Error while transferring result from database server: " << mysql_error(&m_DBHandle);
+               throw new MySQLException(szError.str(), mysql_errno(&m_DBHandle));
+       }
+#ifdef DEBUG
+//     logfile << "Result transferred OK";
+#endif
+       return mysql_num_rows(m_LastResult);
+}
+
+int MySQL::Fetch()
+{
+       if(m_LastResult == NULL)
+               return false;
+#ifdef DEBUG
+       std::cout << "Fetching MySQL row" << std::endl;
+#endif
+       m_Row = mysql_fetch_row(m_LastResult);
+       if(m_Row == NULL)
+       {
+#ifdef DEBUG
+        std::cout << "row == NULL" << std::endl;
+#endif
+
+               if(mysql_errno(&m_DBHandle) > 0)
+               {
+                       std::stringstream szError;
+                       szError << "Error while fetching row from database server: " << mysql_error(&m_DBHandle);
+                       throw new MySQLException(szError.str(), mysql_errno(&m_DBHandle));              
+               }
+               return false;   
+       }
+       return true;
+}
+
+const unsigned char* MySQL::GetText(int Column)
+{
+       return (const unsigned char*)m_Row[Column];
+}
+int MySQL::GetInt(int Column)
+{
+       if(m_Row[Column] == NULL)
+       {
+#ifdef DEBUG
+               std::cout << "Returning NULL from MySQL::GetInt()";
+#endif
+               return 0;
+       }
+/*
+#ifdef DEBUG
+       std::stringstream log;
+       log << "mysql atoi() " << Column << " " << m_Row[Column];
+       logfile.AddLine(log.str());
+#endif
+       */
+       return atoi(m_Row[Column]);
+}
+__int64 MySQL::GetInt64(int Column)
+{
+       
+       return _atoi64(m_Row[Column]);
+}
+__int64 MySQL::GetLastInsertID()
+{
+       return (__int64)mysql_insert_id(&m_DBHandle);
+}
+__int64 MySQL::GetAffectedRows()
+{
+       return (__int64)mysql_affected_rows(&m_DBHandle);
+}
+void MySQL::Escape(std::string &Data)
+{
+       int tmpsize = Data.size() * 2 + 1;
+       int usedsize;
+       char tmp[8096];// = new char[tmpsize];
+       memset(tmp, 0x00, sizeof(tmp));
+       usedsize = mysql_real_escape_string(&m_DBHandle, tmp, Data.c_str(), Data.size()); 
+       Data.assign(tmp, usedsize);
+//     delete tmp;
+}
+
diff --git a/Server Applications/rsearchi/MySQL.h b/Server Applications/rsearchi/MySQL.h
new file mode 100644 (file)
index 0000000..a69cc16
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef __MYSQL__H_DB__
+#define __MYSQL__H_DB__
+#ifdef WIN32
+       #include <WinSock2.h>
+#else 
+       #include <sys/socket.h>
+#define _atoi64 atoll
+
+#endif
+#include <mysql.h>
+#include <errmsg.h>
+#include <string>
+#include "Exception.h"
+#include "Database.h"
+
+
+class MySQLException : public DatabaseException
+{
+public:
+       MySQLException(std::string szErrorMessage, unsigned int nErrorCode) : DatabaseException(szErrorMessage, nErrorCode)     { }
+};
+
+class MySQL : public CDatabase
+{
+private:
+       MYSQL m_DBHandle;
+       MYSQL_RES *m_LastResult;
+       MYSQL_ROW m_Row;
+
+       std::string m_Servername, m_Username, m_Password, m_Database;
+       int m_Port;
+public:
+       MySQL(void);
+       MySQL(std::string Servername, std::string Username, std::string Password, std::string Database, int Port = 0);
+       ~MySQL(void);
+
+public:
+       void Reconnect();
+       void Query(std::string SQLQuery);
+       uint64 Select(std::string SQLQuery);
+       int SelectUnbuffered(std::string SQLQuery);
+       int Fetch(); // TRUE is more data is available
+       void OpenDatabase(std::string Servername, std::string Username, std::string Password, std::string Database, int Port = 0);
+       int GetInt(int Column);
+       __int64 GetInt64(int Column);
+       __int64 GetLastInsertID();
+       __int64 GetAffectedRows();
+       const unsigned char* GetText(int Column);
+       void Escape(std::string&);
+};
+#endif
+
+
diff --git a/Server Applications/rsearchi/Public.cpp b/Server Applications/rsearchi/Public.cpp
new file mode 100644 (file)
index 0000000..7a703d8
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifdef _WIN32
+       #pragma warning(disable : 4786)
+#endif
+#include "Public.h"
+
+#ifdef _WIN32
+       #include <windows.h>
+#else
+       #include <sys/sysinfo.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+unsigned int GetFileLen(FILE* file)
+{
+       unsigned int pos = ftell(file);
+       fseek(file, 0, SEEK_END);
+       unsigned int len = ftell(file);
+       fseek(file, pos, SEEK_SET);
+       return len;
+}
+
+string TrimString(string s)
+{
+       while (s.size() > 0)
+       {
+               if (s[0] == ' ' || s[0] == '\t')
+                       s = s.substr(1);
+               else
+                       break;
+       }
+
+       while (s.size() > 0)
+       {
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+                       s = s.substr(0, s.size() - 1);
+               else
+                       break;
+       }
+
+       return s;
+}
+
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+
+       FILE* file = fopen(sPathName.c_str(), "rb");
+       if (file != NULL)
+       {
+               unsigned int len = GetFileLen(file);
+               char* data = new char[len + 1];
+               fread(data, 1, len, file);
+               data[len] = '\0';
+               string content = data;
+               content += "\n";
+               delete data;
+
+               int i;
+               for (i = 0; i < content.size(); i++)
+               {
+                       if (content[i] == '\r')
+                               content[i] = '\n';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       string line = content.substr(0, n);
+                       line = TrimString(line);
+                       if (line != "")
+                               vLine.push_back(line);
+                       content = content.substr(n + 1);
+               }
+
+               fclose(file);
+       }
+       else
+               return false;
+
+       return true;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+       vPart.clear();
+
+       int i;
+       for (i = 0; i < sSeperator.size(); i++)
+       {
+               int n = s.find(sSeperator[i]);
+               if (n != -1)
+               {
+                       vPart.push_back(s.substr(0, n));
+                       s = s.substr(n + 1);
+               }
+               else
+                       return false;
+       }
+       vPart.push_back(s);
+
+       return true;
+}
+
+string uint64tostr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%I64u", n);
+#else
+       sprintf(str, "%llu", n);
+#endif
+
+       return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+       char str[32];
+
+#ifdef _WIN32
+       sprintf(str, "%016I64x", n);
+#else
+       sprintf(str, "%016llx", n);
+#endif
+
+       return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+       string sRet;
+       int i;
+       for (i = 0; i < nLen; i++)
+       {
+               char szByte[3];
+               sprintf(szByte, "%02x", pData[i]);
+               sRet += szByte;
+       }
+
+       return sRet;
+}
+
+unsigned int GetAvailPhysMemorySize()
+{
+//     return 20971520;
+#ifdef _WIN32
+               MEMORYSTATUS ms;
+               GlobalMemoryStatus(&ms);
+               return ms.dwAvailPhys;
+#else
+       struct sysinfo info;
+       sysinfo(&info);                 // This function is Linux-specific
+       //return 
+       return 200 * 1024 * 1024;
+//     return info.freeram;
+#endif
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+       int i;
+       for (i = 0; i < sHash.size() / 2; i++)
+       {
+               string sSub = sHash.substr(i * 2, 2);
+               int nValue;
+               sscanf(sSub.c_str(), "%02x", &nValue);
+               pHash[i] = (unsigned char)nValue;
+       }
+
+       nHashLen = sHash.size() / 2;
+}
+
+void Logo()
+{
+       printf("RainbowCrack 1.2 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+       printf("by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+       printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
+
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+       // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+       if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+               return false;
+       size_t nEnd = sCharset.rfind(')');
+       size_t nStart = sCharset.rfind('(');
+       string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+       vector<string> vParts;
+       SeperateString(sChar, ",", vParts);
+       for(int i = 0; i < vParts.size(); i++)
+       {
+               tCharset stCharset;
+               vector<string> vParts2;
+               SeperateString(vParts[i], "#", vParts2);
+               stCharset.sName = vParts2[0];
+               vector<string> vParts3;
+               SeperateString(vParts2[1], "-", vParts3);
+               stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+               stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+               vCharset.push_back(stCharset);
+       }
+       return true;
+}
diff --git a/Server Applications/rsearchi/Public.h b/Server Applications/rsearchi/Public.h
new file mode 100644 (file)
index 0000000..a3421ac
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#ifndef _PUBLIC_H
+#define _PUBLIC_H
+#include "stdafx.h"
+
+#include <stdio.h>
+
+#include <string>
+#include <vector>
+#include <list>
+using namespace std;
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 u_int64_t
+#endif
+
+struct RainbowChainO
+{
+       uint64 nIndexS;
+       uint64 nIndexE;
+};
+
+struct RainbowChain
+{
+       uint64 nIndexS;
+       int nIndexE;
+       int nCheckPoint;
+};
+struct FoundRainbowChain
+{
+       uint64 nIndexS;
+       int nIndexE;
+       int nCheckPoint;
+       int nGuessedPos;
+};
+struct IndexChain
+{
+       uint64 nPrefix;
+       int nFirstChain;
+       int nChainCount;
+};
+typedef struct
+{
+       string sName;
+       int nPlainLenMin;
+       int nPlainLenMax;
+} tCharset;
+
+#define MAX_PLAIN_LEN 256
+#define MIN_HASH_LEN  8
+#define MAX_HASH_LEN  256
+#define MAX_SALT_LEN  256
+
+unsigned int GetFileLen(FILE* file);
+string TrimString(string s);
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine);
+bool SeperateString(string s, string sSeperator, vector<string>& vPart);
+string uint64tostr(uint64 n);
+string uint64tohexstr(uint64 n);
+string HexToStr(const unsigned char* pData, int nLen);
+unsigned int GetAvailPhysMemorySize();
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen);
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset);
+
+void Logo();
+
+#endif
diff --git a/Server Applications/rsearchi/RainbowTableSort.cpp b/Server Applications/rsearchi/RainbowTableSort.cpp
new file mode 100644 (file)
index 0000000..ff810a4
--- /dev/null
@@ -0,0 +1,317 @@
+/*
+   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
+
+   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+*/
+
+#include "Public.h"
+
+#define ASSUMED_MIN_MEMORY 32 * 1024 * 1024
+
+/////////////////////////////////////////////////////////////////////////////
+
+/*
+int QuickSortCompare(const void* pElem1, const void* pElem2)
+{
+       uint64 n1 = ((RainbowChain*)pElem1)->nIndexE;
+       uint64 n2 = ((RainbowChain*)pElem2)->nIndexE;
+
+       if (n1 < n2)
+               return -1;
+       else if (n1 == n2)
+               return 0;
+       else
+               return 1;
+}
+
+void QuickSort(RainbowChain* pChain, int nRainbowChainCount)
+{
+       qsort(pChain, nRainbowChainCount, 16, QuickSortCompare);        // so slow!
+}
+*/
+
+/////////////////////////////////////////////////////////////////////////////
+
+int QuickSortPartition(RainbowChain* pChain, int nLow, int nHigh)
+{
+       int nRandomIndex = nLow + ((unsigned int)rand() * (RAND_MAX + 1) + (unsigned int)rand()) % (nHigh - nLow + 1);
+       RainbowChain TempChain;
+       TempChain = pChain[nLow];
+       pChain[nLow] = pChain[nRandomIndex];
+       pChain[nRandomIndex] = TempChain;
+
+       TempChain = pChain[nLow];
+       uint64 nPivotKey = pChain[nLow].nIndexE;
+       while (nLow < nHigh)
+       {
+               while (nLow < nHigh && pChain[nHigh].nIndexE >= nPivotKey)
+                       nHigh--;
+               pChain[nLow] = pChain[nHigh];
+               while (nLow < nHigh && pChain[nLow].nIndexE <= nPivotKey)
+                       nLow++;
+               pChain[nHigh] = pChain[nLow];
+       }
+       pChain[nLow] = TempChain;
+       return nLow;
+}
+
+void QuickSort(RainbowChain* pChain, int nLow, int nHigh)
+{
+       if (nLow < nHigh)
+       {
+               int nPivotLoc = QuickSortPartition(pChain, nLow, nHigh);
+               QuickSort(pChain, nLow, nPivotLoc - 1);
+               QuickSort(pChain, nPivotLoc + 1, nHigh);
+       }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define SORTED_SEGMENT_MAX_CHAIN_IN_MEMORY 1024
+
+class CSortedSegment
+{
+public:
+       CSortedSegment(FILE* file, unsigned int nFileChainOffset, int nFileChainCount)
+       {
+               m_nChainCount     = 0;
+               m_nNextChainIndex = 0;
+       
+               m_file             = file;
+               m_nFileChainOffset = nFileChainOffset;
+               m_nFileChainCount  = nFileChainCount;
+       }
+
+private:
+       RainbowChain m_Chain[SORTED_SEGMENT_MAX_CHAIN_IN_MEMORY];
+       int m_nChainCount;
+       int m_nNextChainIndex;
+
+       FILE* m_file;
+       unsigned int m_nFileChainOffset;
+       int m_nFileChainCount;
+
+public:
+       RainbowChain* GetNextChain()    // Don't call this if no chain left
+       {
+               if (m_nChainCount == m_nNextChainIndex)
+               {
+                       int nChainCountToRead;
+                       if (m_nFileChainCount < SORTED_SEGMENT_MAX_CHAIN_IN_MEMORY)
+                               nChainCountToRead = m_nFileChainCount;
+                       else
+                               nChainCountToRead = SORTED_SEGMENT_MAX_CHAIN_IN_MEMORY;
+
+                       //printf("reading... (offset = %u, chain count = %d)\n", m_nFileChainOffset, nChainCountToRead);
+                       fseek(m_file, m_nFileChainOffset, SEEK_SET);
+                       fread(m_Chain, 1, sizeof(RainbowChain) * nChainCountToRead, m_file);
+                       m_nChainCount       = nChainCountToRead;
+                       m_nNextChainIndex   = 0;
+                       m_nFileChainOffset += sizeof(RainbowChain) * nChainCountToRead;
+                       m_nFileChainCount  -= nChainCountToRead;
+               }
+
+               return &m_Chain[m_nNextChainIndex];
+       }
+
+       bool RemoveTopChain()   // return whether already empty
+       {
+               m_nNextChainIndex++;
+
+               if (m_nChainCount == m_nNextChainIndex)
+                       if (m_nFileChainCount == 0)
+                               return true;
+
+               return false;
+       }
+};
+
+FILE* CreateTemporaryFile(string sPathName, unsigned int nLen)
+{
+       FILE* tempfile = fopen(sPathName.c_str(), "w+b");
+       if (tempfile == NULL)
+       {
+               printf("can't create temporary file %s\n", sPathName.c_str());
+               return NULL;
+       }
+
+       // Set proper length - this is not a good method
+       fseek(tempfile, nLen - 4, SEEK_SET);
+       int x;
+       fwrite(&x, 1, 4, tempfile);
+       if (GetFileLen(tempfile) != nLen)
+       {
+               printf("not enough temporary disk space, %u bytes required\n", nLen);
+               fclose(tempfile);
+               remove(sPathName.c_str());
+               return NULL;
+       }
+
+       return tempfile;
+}
+
+bool PrepareSortedSegment(list<CSortedSegment>& lSS, FILE* file, FILE* tempfile)
+{
+       unsigned int nAvailPhys = GetAvailPhysMemorySize();
+       if (nAvailPhys < ASSUMED_MIN_MEMORY)
+               nAvailPhys = ASSUMED_MIN_MEMORY;
+       nAvailPhys = nAvailPhys / 16 * 16;
+
+       // Allocate memory
+       unsigned char* pMem = new unsigned char[nAvailPhys];
+       if (pMem == NULL)
+       {
+               printf("memory allocation fail\n");
+               return false;
+       }
+
+       // Run
+       unsigned int nFileLen = GetFileLen(file);
+       fseek(file, 0, SEEK_SET);
+       fseek(tempfile, 0, SEEK_SET);
+       int i;
+       for (i = 0; ; i++)
+       {
+               if (ftell(file) == nFileLen)
+                       break;
+
+               printf("reading segment #%d...\n", i);
+               unsigned int nRead = fread(pMem, 1, nAvailPhys, file);
+
+               printf("sorting segment #%d...\n", i);
+               QuickSort((RainbowChain*)pMem, 0, nRead / 16 - 1);
+
+               CSortedSegment ss(tempfile, ftell(tempfile), nRead / 16);
+               lSS.push_back(ss);
+
+               printf("writing sorted segment #%d...\n", i);
+               fwrite(pMem, 1, nRead, tempfile);
+       }
+
+       // Free memory
+       delete pMem;
+
+       return true;
+}
+
+void MergeSortedSegment(list<CSortedSegment>& lSS, FILE* file)
+{
+       printf("merging sorted segments...\n");
+
+       fseek(file, 0, SEEK_SET);
+       while (!lSS.empty())
+       {
+               list<CSortedSegment>::iterator MinIt;
+               uint64 nMinIndexE;
+               list<CSortedSegment>::iterator it;
+               for (it = lSS.begin(); it != lSS.end(); it++)
+               {
+                       if (it == lSS.begin())
+                       {
+                               MinIt = it;
+                               nMinIndexE = ((*it).GetNextChain())->nIndexE;
+                       }
+                       else
+                       {
+                               if (((*it).GetNextChain())->nIndexE < nMinIndexE)
+                               {
+                                       MinIt = it;
+                                       nMinIndexE = ((*it).GetNextChain())->nIndexE;
+                               }
+                       }
+               }
+
+               fwrite((*MinIt).GetNextChain(), 1, 16, file);
+
+               if ((*MinIt).RemoveTopChain())
+                       lSS.erase(MinIt);
+       }
+}
+
+void ExternalSort(FILE* file, string sTemporaryFilePathName)
+{
+       FILE* tempfile = CreateTemporaryFile(sTemporaryFilePathName, GetFileLen(file));
+       if (tempfile != NULL)
+       {
+               list<CSortedSegment> lSS;
+               if (PrepareSortedSegment(lSS, file, tempfile))
+                       MergeSortedSegment(lSS, file);
+               fclose(tempfile);
+               remove(sTemporaryFilePathName.c_str());
+       }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int SortRainbowtable(string sPathName)
+{
+/*     if (argc != 2)
+       {
+               Logo();
+
+               printf("usage: rtsort rainbow_table_pathname\n");
+               return 0;
+       }
+       string sPathName = argv[1];
+*/
+       // Open file
+       FILE* file = fopen(sPathName.c_str(), "r+b");
+       if (file == NULL)
+       {
+               printf("failed to open %s\n", sPathName.c_str());
+               return 0;
+       }
+
+       // Sort
+       unsigned int nFileLen = GetFileLen(file);
+       if (nFileLen % 16 != 0)
+               printf("rainbow table size check fail\n");
+       else
+       {
+               // Available physical memory
+               unsigned int nAvailPhys = GetAvailPhysMemorySize();
+               printf("available physical memory: %u bytes\n", nAvailPhys);
+
+               // QuickSort or ExternalSort
+               if (nAvailPhys >= nFileLen || nFileLen <= ASSUMED_MIN_MEMORY)
+               {
+                       int nRainbowChainCount = nFileLen / 16;
+                       RainbowChain* pChain = (RainbowChain*)new unsigned char[nFileLen];
+                       if (pChain != NULL)
+                       {
+                               // Load file
+                               printf("loading rainbow table...\n");
+                               fseek(file, 0, SEEK_SET);
+                               if (fread(pChain, 1, nFileLen, file) != nFileLen)
+                               {
+                                       printf("disk read fail\n");
+                                       goto ABORT;
+                               }
+
+                               // Sort file
+                               printf("sorting rainbow table...\n");
+                               QuickSort(pChain, 0, nRainbowChainCount - 1);
+
+                               // Write file
+                               printf("writing sorted rainbow table...\n");
+                               fseek(file, 0, SEEK_SET);
+                               fwrite(pChain, 1, nFileLen, file);
+
+                               delete[] pChain;
+                       }
+                       else
+                               printf("memory allocation fail\n");
+               }
+               else
+               {
+                       // External sort when memory is low
+                       ExternalSort(file, sPathName + ".tmp");
+               }
+       }
+ABORT:
+
+       // Close file
+       fclose(file);
+
+       return 0;
+}
diff --git a/Server Applications/rsearchi/config.h b/Server Applications/rsearchi/config.h
new file mode 100644 (file)
index 0000000..a6e70b7
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __CONFIG_H_
+#define __CONFIG_H_
+
+#define DATA_CHUNK_SIZE 16*100
+#define PROTOCOL_VERSION 0x03
+#ifndef WIN32
+       #define Sleep(num) sleep(num / 1000)
+#endif
+#endif
diff --git a/Server Applications/rsearchi/rsearch b/Server Applications/rsearchi/rsearch
new file mode 100644 (file)
index 0000000..289ceec
Binary files /dev/null and b/Server Applications/rsearchi/rsearch differ
diff --git a/Server Applications/rsearchi/rsearch.cpp b/Server Applications/rsearchi/rsearch.cpp
new file mode 100644 (file)
index 0000000..7227219
--- /dev/null
@@ -0,0 +1,359 @@
+// distrrtgen_assembler.cpp : Defines the entry point for the console application.
+//
+#include "stdafx.h"
+
+#include "MySQL.h"
+#include <string>
+#include <sstream>
+#include <list>
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <time.h>
+#include <map>
+#include <sys/types.h>
+#include "dirent.h"
+#include <errno.h>
+#include <vector>
+
+#include "ChainWalkContext.h"
+#include "CrackEngine.h"
+//#include "ServerConnector.h"
+#ifdef WIN32
+       #include <direct.h>
+#endif
+typedef struct
+{
+       std::string sHost;
+       std::string sUsername;
+       std::string sPassword;
+       std::string sDatabase;
+} DB_SETTINGS;
+using std::map;
+using namespace std;
+#define DIR_INDICES "/home/boincadm/indices/"
+#define DIR_CHAINS "/home/boincadm/chains/"
+//typedef __int64 uint64;
+//typedef int uint32;
+
+DB_SETTINGS dbSettings;
+
+void GetCharset(std::string sCharsetName, char **pCharset);
+
+void RunCracker(int nTableID, CHashSet &hs, vector<string> &vPathName)
+{
+//     vector<string> vPathName;
+//     vPathName.push_back("md5_mixalpha-numeric-all-space#1-6_0_10000x9434153_0.rt");
+
+}
+
+
+int main(int argc, char* argv[])
+{
+       
+#ifdef WIN32
+       std::string sRTPath = "/rainbowtables_i";
+#else
+       std::string sRTPath = "/home/rainbow/tables/indexed";
+nice(19);
+#endif
+       while(1)
+       {
+               try
+               {
+       //              chdir(sRTPath.c_str());
+
+                       dbSettings.sDatabase.assign(MYSQL_DATABASE);
+                       dbSettings.sHost.assign(MYSQL_HOST);
+                       dbSettings.sPassword.assign(MYSQL_PASSWORD);
+                       dbSettings.sUsername.assign(MYSQL_USERNAME);
+
+                       map<int, vector<string> > mTableSets; 
+                       std::cout << "Connecting to database" << std::endl;
+                       CDatabase *pDatabase = (CDatabase*)new MySQL(dbSettings.sHost, dbSettings.sUsername, dbSettings.sPassword, dbSettings.sDatabase);
+                       std::cout << "Connected!" << std::endl;
+                       while(1)
+                       {
+                               vector<string> vFiles;
+/*
+                               pDatabase->Select("SELECT rct.tableid, rctf.filename, rcts.hashroutine, rcts.charset, rcts.minletters, rcts.maxletters, rct.`index` FROM rainbowcrack_cracker_tables rct INNER JOIN rainbowcrack_cracker_tablesets rcts ON rcts.tablesetid = rct.tablesetid INNER JOIN rainbowcrack_cracker_tsfiles rctf ON rctf.tableid = rct.tableid");
+                               int nPrevSet = 0;
+                               while(pDatabase->Fetch() == true)
+                               {
+                                       if(pDatabase->GetInt(0) != nPrevSet)
+                                       {
+                                               if(nPrevSet != 0)
+                                               {
+                                                       mTableSets[nPrevSet] = vFiles;
+                                                       vFiles.erase(vFiles.begin(), vFiles.end());
+                                               }
+                                               nPrevSet = pDatabase->GetInt(0);
+                                       }
+                                       vFiles.push_back((const char *)pDatabase->GetText(1));                          
+                               }
+                               if(nPrevSet > 0)
+                                       mTableSets[nPrevSet] = vFiles;
+*/
+                               DIR *hr, *files, *tables;//, *letters, *index, ;
+                               struct dirent *hrp, *filesp, *tablesp;//, *charsetp, *lettersp, *indexp;
+                               cout << "Opening dir " << sRTPath << endl;
+                               if((hr  = opendir(sRTPath.c_str())) == NULL) {
+                                       cout << "Error(" << errno << ") opening dir " << sRTPath << endl;
+                                       return errno;
+                               }
+                               while ((hrp = readdir(hr)) != NULL) 
+                               {
+
+                                       string hrs = string(hrp->d_name);
+                                       if(hrs != "." && hrs != "..")
+                                       {
+                                               string sDirTables = string(sRTPath + string("/") + hrs);
+                                               cout << "Opening dir " << sDirTables << endl;
+                                               if((tables = opendir(sDirTables.c_str())) == NULL) {
+                                                       cout << "Error(" << errno << ") opening dir " << sDirTables << endl;
+                                                       continue;
+                                               }
+                                               while ((tablesp = readdir(tables)) != NULL) 
+                                               {
+                                                       string tablename = string(tablesp->d_name);
+                                                       if(tablename != "." && tablename != ".." && tablename.substr(tablename.length()-8) != ".torrent")
+                                                       {
+                                                               string hashroutine;
+                                                               string charsets;
+                                                               string sminletters;
+                                                               string smaxletters;
+                                                               string indexs;
+
+                                                               vector<string> vPart;
+                                                               if(tablename.find("hybrid") != string::npos)
+                                                               {// Special file handling of hybrid files
+                                                                       if (!SeperateString(tablename, "_()#-_", vPart))
+                                                                       {
+                                                                               printf("filename %s not identified\n", tablename.c_str());
+                                                                               continue;
+                                                                       }
+                                                                       
+                                                                       hashroutine = vPart[0];
+                                                                       charsets = string(vPart[1] + string("(") + vPart[2] + ")");
+                                                                       sminletters = vPart[4];
+                                                                       smaxletters = vPart[5];
+                                                                       indexs = vPart[6];
+                                                                       
+                                                               }
+                                                               else
+                                                               {
+                                                                       if (!SeperateString(tablename, "_#-_", vPart))
+                                                                       {
+                                                                               printf("filename %s not identified\n", tablename.c_str());
+                                                                               continue;
+                                                                       }
+                                                                       hashroutine = vPart[0];
+                                                                       charsets = vPart[1];
+                                                                       sminletters = vPart[2];
+                                                                       smaxletters = vPart[3];
+                                                                       indexs = vPart[4];
+                                                               }
+
+                                                               string sDirFiles = string(sRTPath + string("/") + hrs + string("/") + tablename);
+                                                               if((files  = opendir(sDirFiles.c_str())) == NULL) {
+                                                                       cout << "Error(" << errno << ") opening " << sDirFiles << endl;
+                                                                       continue;
+                                                               }
+                                                               vFiles.erase(vFiles.begin(), vFiles.end());                                                                                             
+                                                               while ((filesp = readdir(files)) != NULL) 
+                                                               {
+                                                                       string filess = string(filesp->d_name);
+                                                                       if(filess != "." && filess != "..")
+                                                                       {
+                                                                               string extension = filess.substr(filess.length() - 4, 4);
+                                                                               if(extension.compare(".rti") == 0)
+                                                                                       vFiles.push_back(filess);
+                                                                       }
+                                                               }
+                                                               closedir(files);                                                                                        
+                                                               if(vFiles.size() > 0)
+                                                               {
+                                                                       std::stringstream sSQL;
+                                                                       sSQL << "SELECT t.tableid FROM rainbowcrack_cracker_tables t INNER JOIN rainbowcrack_cracker_tablesets ts ON ts.tablesetid = t.tablesetid WHERE ts.hashroutine = '" << hashroutine << "' AND ts.charset = '" << charsets << "' AND ts.minletters = " << sminletters<< " AND ts.maxletters = " << smaxletters << " AND t.`index` = " << indexs;
+                                                                       pDatabase->Select(sSQL.str());
+                                                                       if(pDatabase->Fetch() == true)
+                                                                       {
+                                                                               int nTableID = pDatabase->GetInt(0);
+                                                                               mTableSets[nTableID] = vFiles;
+                                                                       }
+                                                               }                                                                       
+                                                       }
+                                               }
+                                       }                                                                                       
+                               }
+                               closedir(hr);
+
+                               CCrackEngine ce;
+                               
+                               for(map<int, vector<string> >::iterator cur = mTableSets.begin(); cur != mTableSets.end(); cur++)
+                               {
+
+                                       ostringstream sSQL;
+                                       vector<int> vRequestID;
+
+       //                              sSQL << "SELECT workid, hash, cl.salt, indicelist, ts.charset, ts.chainlength FROM rainbowcrack_cracker_hashlist cl INNER JOIN rainbowcrack_cracker_tablesets ts ON (ts.tableid = cl.tableid) WHERE processed = 1 AND indicelist IS NOT NULL AND ts.tableid = " << cur->first;
+       //                              sSQL << "SELECT cl.lookupid, ch.hash, ts.salt, cl.indices, ts.charset, ts.chainlength FROM rainbowcrack_cracker_hashlist ch INNER JOIN rainbowcrack_cracker_lookups cl ON (ch.hashid = cl.hashid) INNER JOIN rainbowcrack_cracker_tables ct ON (ct.tableid = cl.tableid) INNER JOIN rainbowcrack_cracker_tablesets ts ON (ts.tablesetid = ct.tablesetid) WHERE cl.indices IS NOT NULL AND ch.password IS NULL AND status = 0 AND ct.tableid = " << cur->first << " LIMIT 100";
+
+                                       cout << "Querying for " << cur->first << std::endl;
+                                       sSQL << "SELECT cl.lookupid, ch.hash, ts.hashroutine, ts.charset, ts.minletters, ts.maxletters, ct.index, ts.salt, ts.chainlength FROM rainbowcrack_cracker_hashlist ch INNER JOIN rainbowcrack_cracker_lookups cl ON (ch.hashid = cl.hashid) INNER JOIN rainbowcrack_cracker_tables ct ON (ct.tableid = cl.tableid) INNER JOIN rainbowcrack_cracker_tablesets ts ON (ts.tablesetid = ct.tablesetid) WHERE cl.hasindices = 2 AND ch.password IS NULL AND (status = 0 OR (status = 1 AND DATE_SUB(NOW(), INTERVAL 1 HOUR) > time_serverassignment)) AND ct.tableid = " << cur->first << " LIMIT 1000";
+                                       if(pDatabase->Select(sSQL.str()) > 0)
+                                       {
+                                               std::string sHashRoutine;                                                       
+                                               CHashSet *hs = new CHashSet();
+                                               std::ostringstream sToLook;
+                                               sToLook << "UPDATE rainbowcrack_cracker_lookups SET status = 1, time_serverassignment = NOW() WHERE lookupid IN (";
+                                               int nRow = 0;                                           
+                                               while(pDatabase->Fetch() == true)
+                                               {
+                                                       if(nRow > 0)
+                                                       {
+                                                               sToLook << ",";
+                                                       }
+                                                       else
+                                                       {
+                                                               printf("Fetching indices");
+                                                       }
+                                                       nRow++;
+                                                       printf(".");
+                                                       sHashRoutine.assign((char *)pDatabase->GetText(2));
+                                                       sToLook << pDatabase->GetInt(0);
+                                                       ostringstream sPath;
+                                                       sPath << sRTPath << "/" << pDatabase->GetText(2) << "/" << pDatabase->GetText(2) << "_" << pDatabase->GetText(3) << "#" << pDatabase->GetInt(4) << "-" << pDatabase->GetInt(5) << "_" << pDatabase->GetInt(6);
+       #ifdef WIN32
+                                                       _chdir(sPath.str().c_str());                            
+       #else
+                                                       chdir(sPath.str().c_str());                             
+       #endif
+                                                       vRequestID.push_back(pDatabase->GetInt(0));
+                                                       
+
+
+
+                                                       // New code, loads from the local disk
+                                                       std::string sIndexDir = DIR_INDICES;
+                                                       std::stringstream indiceFilename;
+                                                       indiceFilename << sIndexDir.c_str() << pDatabase->GetText(0) << ".index";
+                                                       FILE *fIndex = fopen(indiceFilename.str().c_str(), "rb");                                               
+                                                       if(fIndex == NULL)
+                                                       {
+                                                               printf("Could not open file %s", indiceFilename.str().c_str());
+                                                               continue;
+                                                       }
+
+
+                                                       uint64 *indices = new uint64[pDatabase->GetInt(8)];
+                                                       int i = 0;
+                                                       std::string sInt;
+                                                       if(fread(indices, 8, pDatabase->GetInt(8), fIndex) != pDatabase->GetInt(8))
+                                                       {
+                                                               printf("Error reading index file %s\n", indiceFilename.str().c_str()); 
+                                                               fclose(fIndex);
+                                                               continue;
+                                                       }
+                                                       fclose(fIndex);
+                                                       hs->AddHash((const char *)pDatabase->GetText(1), indices, pDatabase->GetInt(0));
+                                               }
+                                               
+                                               sToLook << ")";
+                                               if(nRow > 0)
+                                               {
+                                                       pDatabase->Query(sToLook.str());
+                                                       printf("ok!\n");
+                                               }
+                                               ce.Run(cur->second, *hs);
+                                               map<string, vector<FoundRainbowChain> > mHashes;
+                                               hs->GetFoundChains(mHashes);
+//                                                     ServerConnector *sc = new ServerConnector();
+                                               for(map<string, vector<FoundRainbowChain> >::iterator curHash = mHashes.begin(); curHash != mHashes.end(); curHash++)
+                                               {
+                                                       std::stringstream sChains;
+                                                       // Old code - Upload the chains through HTTP
+                                                       // New code. Write it directly to the file and update the DB
+                                                       std::stringstream sChainFile;
+                                                       sChainFile << DIR_CHAINS << hs->GetLookupID(curHash->first) << ".chains";
+                                                       FILE *fChains = fopen(sChainFile.str().c_str(), "wb");
+                                                       if(fChains == NULL)
+                                                       {
+                                                               printf("Unable to open file %s", sChainFile.str().c_str());
+                                                               continue;
+                                                       }
+                                                       for(int i = 0; i < curHash->second.size(); i++)
+                                                       {
+                                                               if(fwrite(&curHash->second[i].nIndexS, sizeof(curHash->second[i].nIndexS), 1, fChains) != 1)
+                                                               {
+                                                                       printf("Unable to write data to %s", sChainFile.str().c_str());
+                                                                       continue;
+                                                               }
+                                                               if(fwrite(&curHash->second[i].nGuessedPos, sizeof(curHash->second[i].nGuessedPos), 1, fChains) != 1)
+                                                               {
+                                                                       printf("Unable to write data to %s", sChainFile.str().c_str());
+                                                                       continue;
+                                                               }
+                                                       }                                                       
+                                                       fclose(fChains);                                                        
+                                                       sSQL.str("");
+                                                       sSQL << "UPDATE rainbowcrack_cracker_lookups SET status = 4, hasindices = 3 WHERE lookupid = " << hs->GetLookupID(curHash->first);
+                                                       try
+                                                       {
+                                                               pDatabase->Query(sSQL.str());
+                                                               sSQL.str("");
+                                                               sSQL << "INSERT IGNORE INTO rainbowcrack_cracker_verificationqueue (lookupid, hash, hashroutine, tablesetid, charset, minletters, maxletters, chainlength, salt, `index`) ";
+                                                       sSQL << "SELECT l.lookupid, h.hash, h.hashroutine, t.tablesetid, ts.charset, ts.minletters, ts.maxletters, ts.chainlength, ts.salt, t.`index` ";
+                                                       sSQL << " FROM rainbowcrack_cracker_lookups l ";
+                                                       sSQL << " INNER JOIN rainbowcrack_cracker_hashlist h ON h.hashid = l.hashid ";
+                                                       sSQL << " INNER JOIN rainbowcrack_cracker_tables t ON t.tableid = l.tableid ";
+                                                       sSQL << " INNER JOIN rainbowcrack_cracker_tablesets ts ON ts.tablesetid = t.tablesetid ";
+                                                               sSQL << " WHERE l.lookupid = " << hs->GetLookupID(curHash->first);
+                                                               pDatabase->Query(sSQL.str());
+
+                                                       }
+                                                       catch(DatabaseException *ex)
+                                                       {
+                                                               if(ex->getErrorCode() == CR_SERVER_GONE_ERROR || ex->getErrorCode() == CR_SERVER_LOST)
+                                                               {
+                                                                       std::cout << "Server has disconnected";
+                                                               }
+                                                               else throw ex;
+                                                       }
+                                               }
+//                                             delete sc;
+                                               delete hs;
+                                       }
+                                       sSQL.str("");
+                                       for(int i = 0; i < vRequestID.size(); i++)
+                                       {
+                                               stringstream sFile;
+                                               sFile << DIR_INDICES << vRequestID[i] << ".index";
+                                               unlink(sFile.str().c_str());
+                                       }                                       
+               /*                      if(vRequestID.size() > 0)
+                                       {
+                                               stringstream sList;
+                                               for(int i = 0; i < vRequestID.size(); i++)
+                                               {
+                                                       if(i != 0)
+                                                               sList << ",";                                   
+                                                       sList << vRequestID[i];
+                                               }
+                                               sSQL << "UPDATE rainbowcrack_cracker_lookups SET status = 2, hasindices = 2 WHERE lookupid IN (" << sList.str() << ")";
+                                               pDatabase->Query(sSQL.str());
+                                       }*/
+                               }
+                               Sleep(1000);
+                       }
+               }
+               catch(DatabaseException *ex)
+               {
+                       std::cout << "Database exception " << " ( " << ex->getErrorCode() << " ): " << ex->GetErrorMessage()  << std::endl;
+                       delete ex;
+                       
+               }
+       }
+       return 0;
+}
+
diff --git a/Server Applications/rsearchi/rsearchi b/Server Applications/rsearchi/rsearchi
new file mode 100644 (file)
index 0000000..07bb717
Binary files /dev/null and b/Server Applications/rsearchi/rsearchi differ
diff --git a/Server Applications/rsearchi/stdafx.cpp b/Server Applications/rsearchi/stdafx.cpp
new file mode 100644 (file)
index 0000000..a36c2f2
--- /dev/null
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// distrrtgen_assembler.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/Server Applications/rsearchi/stdafx.h b/Server Applications/rsearchi/stdafx.h
new file mode 100644 (file)
index 0000000..d6e47ac
--- /dev/null
@@ -0,0 +1,34 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#ifndef __STDAFX_H__
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN            // Exclude rarely-used stuff from Windows headers
+#include <stdio.h>
+#include <tchar.h>
+#define MYSQL_HOST "freerainbowtables.com"
+#else
+#define MYSQL_HOST "localhost"
+
+#endif
+
+#ifndef BUILD_ATEA
+#define MYSQL_DATABASE "rainbowtables-distrrtgen"
+#define MYSQL_USERNAME "rainbow"
+#define MYSQL_PASSWORD "QQrQaQQ123$"
+#endif
+
+#define STATUS_TABLE_NOTSTARTED 0
+#define STATUS_TABLE_INPROGRESS 1
+#define STATUS_TABLE_COMPLETED 2
+
+#ifndef _WIN32
+       #define Sleep(num) sleep(num / 1000) 
+       #define __int64 long long
+#endif
+
+#endif
+// TODO: reference additional headers your program requires here
diff --git a/Server Applications/rtperfecter0.0/RTCommon.h b/Server Applications/rtperfecter0.0/RTCommon.h
new file mode 100644 (file)
index 0000000..3f720e2
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTCOMMON_H
+#define RTCOMMON_H
+
+#include <stdio.h>
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 unsigned long long
+#endif
+/*
+struct RTChain
+{
+       uint64 startpt;
+       uint64 endpt;
+};
+*/
+struct RTChain
+{
+       uint64 startpt;
+       uint64 endpt;
+       unsigned short checkpoint;      
+};
+
+#endif
+
diff --git a/Server Applications/rtperfecter0.0/RTRead.cpp b/Server Applications/rtperfecter0.0/RTRead.cpp
new file mode 100644 (file)
index 0000000..084f217
--- /dev/null
@@ -0,0 +1,416 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctime>
+#include <errno.h>
+#include <stdlib.h>
+#include "RTRead.h"
+
+#ifdef HAVE_DIRENT_H
+       #include <dirent.h>
+#else
+       // I know Microsoft's compiler, .Net 2005 or older, does not come with this file.
+       // You can use this if you don't have dirent.h: http://www.cs.fiu.edu/~weiss/cop4338_spr06/dirent.h
+       // Umm I'm not sure if the license on that file, which appears to be public domain, conflicts with GPL v3.
+       // So only use that if you need it and the licenses don't conflict.
+       #include "dirent.h"
+#endif
+
+#ifdef _WIN32
+       #include <conio.h>
+       #define DIRECTORY_SEPERATOR '\\'
+#else
+       #include <fcntl.h>
+       #define DIRECTORY_SEPERATOR '/'
+#endif
+
+#ifndef NAME_MAX
+       #define NAME_MAX 256
+#endif
+
+#include "RTRead.h"
+
+RTRead::RTRead(char *dir, uint64 maxIndex, int verbose)
+{
+       int dirLen = strlen(dir), dirFileLen;
+       char *file = new char[dirLen + NAME_MAX + 2];
+       DIR *pDir;
+       struct dirent *pDirFile;
+       FileList *head = NULL, *current = NULL, *temp = new FileList;
+
+       // Init
+       m_verbose = verbose;
+       m_maxIndex = maxIndex;
+       m_chainsRead = 0;
+       m_chains = 0;
+       m_pqSize = 0;
+       m_pq = NULL;
+       temp->next = NULL;
+       strncpy(file, dir, dirLen);
+       if (dir[dirLen - 1] != DIRECTORY_SEPERATOR)
+       {
+               file[dirLen] = DIRECTORY_SEPERATOR;
+               dirLen++;
+       }
+
+       // Open directory
+       pDir = opendir(dir);
+       if (pDir == NULL)
+       {
+               printf("Error #%u: Opening directory '%s'\n", errno, dir);
+               exit(errno);
+       }
+
+       // Get files
+       for (pDirFile = readdir(pDir); pDirFile != NULL; pDirFile = readdir(pDir))
+       {
+               dirFileLen = strlen(pDirFile->d_name);
+               if (pDirFile->d_name[0] != '.' && dirFileLen > 3 &&
+                   pDirFile->d_name[dirFileLen - 3] == '.' &&
+                  (pDirFile->d_name[dirFileLen - 2] == 'r' || pDirFile->d_name[dirFileLen - 2] == 'R') &&
+                  (pDirFile->d_name[dirFileLen - 1] == 't' || pDirFile->d_name[dirFileLen - 1] == 'T'))
+               {
+                       strcpy(file + dirLen, pDirFile->d_name);
+                       if (getInfo(file, dirLen + dirFileLen, temp) == 0)
+                       {
+                               m_chains += temp->chains;
+                               m_pqSize++;
+                               if (head == NULL)
+                               {
+                                       head = temp;
+                                       current = temp;
+                               }
+                               else
+                               {
+                                       current->next = temp;
+                                       current = temp;
+                               }
+                               temp = new FileList;
+                               temp->next = NULL;
+                       }
+                       else
+                       {
+                               printf("Continue? (y/n): ");
+                               int ch = 0;
+                               while (ch != EOF && ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N')
+                               {
+                                       ch = getchar();
+                               }
+                               if (ch != 'y' && ch != 'Y')
+                               {
+                                       while (head != NULL)
+                                       {
+                                               current = head;
+                                               head = head->next;
+                                               fclose(current->pFile);
+                                               delete [] current->name;
+                                               delete current;
+                                       }
+                                       delete [] file;
+                                       delete temp;
+                                       closedir(pDir);
+                                       exit(1);
+                               }
+                       }
+               }
+       }
+       delete [] file;
+       delete temp;
+       closedir(pDir);
+       if (head == NULL)
+       {
+               printf("Error no '*.rt' input files found in directory '%s'.\n", dir);
+               exit(1);
+       }
+
+       // Push file list into priority queue
+       PriorityQueueNode tmpNode;
+       unsigned int i = 0, node, par;
+
+       m_pq = new PriorityQueueNode[m_pqSize];
+       while (head != NULL)
+       {
+               if (readGoodChain(head->pFile, &(m_pq[i].chain)) == 0)
+               {
+                       // Init priority queue node
+                       m_pq[i].pFile = head->pFile;
+                       m_pq[i].fName = head->name;
+
+                       // Insert into priority queue
+                       if (i != 0)
+                       {
+                               node = i;
+                               par = (node - 1) >> 1;
+                               if (m_pq[par].chain.endpt > m_pq[node].chain.endpt)
+                               {
+                                       tmpNode = m_pq[node];
+                                       do
+                                       {
+                                               m_pq[node] = m_pq[par];
+                                               node = par;
+                                               if (par == 0)
+                                               {
+                                                       break;
+                                               }
+                                               par = (node - 1) >> 1;
+                                       } while (m_pq[par].chain.endpt > tmpNode.chain.endpt);
+                               }
+                               if (i != node)
+                               {
+                                       m_pq[node] = tmpNode;
+                               }
+                       }
+                       i++;
+               }
+               else
+               {
+                       m_pqSize--;
+                       printf("File had no valid chains '%s'\n", head->name);
+                       delete [] head->name;
+               }
+
+               // Delete file list node
+               current = head;
+               head = head->next;
+               delete current;
+       }
+
+       printf("Starting with %u files.\n", m_pqSize);
+       m_startTime = clock();
+}
+
+RTRead::~RTRead()
+{
+       if (m_pq != NULL)
+       {
+               for (unsigned int i = 0; i < m_pqSize; i++)
+               {
+                       if (m_pq[i].pFile != NULL)
+                       {
+                               fclose(m_pq[i].pFile);
+                       }
+                       if (m_pq[i].fName != NULL)
+                       {
+                               delete [] m_pq[i].fName;
+                       }
+               }
+               delete [] m_pq;
+       }
+}
+
+int RTRead::readChain(RTChain *chain)
+{
+       PriorityQueueNode tmp;
+       unsigned int child, node;
+
+       if (m_pq == NULL)
+       {
+               return 1;
+       }
+       *chain = m_pq[0].chain;
+       bool remove = (readGoodChain(m_pq[0].pFile, &(m_pq[0].chain)) != 0);
+
+       if (remove)
+       {
+               if (m_verbose)
+               {
+                       printf("Finished with file '%s'\n", m_pq[0].fName);
+               }
+               delete [] m_pq[0].fName;
+
+               // Remove node from queue
+               m_pqSize--;
+               if (m_pqSize == 2)
+               {
+                       if (m_pq[1].chain.endpt < m_pq[2].chain.endpt)
+                       {
+                               m_pq[0] = m_pq[1];
+                               m_pq[1] = m_pq[2];
+                       }
+                       else
+                       {
+                               m_pq[0] = m_pq[2];
+                       }
+                       m_pq[2].fName = NULL;
+                       m_pq[2].pFile = NULL;
+               }
+               else if (m_pqSize == 1)
+               {
+                       m_pq[0] = m_pq[1];
+                       m_pq[1].fName = NULL;
+                       m_pq[1].pFile = NULL;
+               }
+               else if (m_pqSize == 0)
+               {
+                       delete [] m_pq;
+                       m_pq = NULL;
+               }
+       }
+       if (m_pqSize > 2)
+       {
+               if (remove)
+               {
+                       tmp = m_pq[m_pqSize];
+                       m_pq[m_pqSize].fName = NULL;
+                       m_pq[m_pqSize].pFile = NULL;
+               }
+               else
+               {                       
+                       tmp = m_pq[0];
+               }
+               // Move tmp node to proper posistion in queue
+               node = 0;
+               child = 1;
+               if (m_pq[1].chain.endpt > m_pq[2].chain.endpt)
+               {
+                       child = 2;
+               }
+               while (tmp.chain.endpt > m_pq[child].chain.endpt)
+               {
+                       m_pq[node] = m_pq[child];
+                       node = child;
+                       // child = left node
+                       child = (node << 1) + 1;
+                       if (child >= m_pqSize)
+                       {
+                               break;
+                       }
+                       if (child + 1 < m_pqSize && m_pq[child].chain.endpt > m_pq[child + 1].chain.endpt)
+                       {
+                               // child = right node
+                               child++;
+                       }
+               }
+               if (node != 0 || remove)
+               {
+                       m_pq[node] = tmp;
+               }
+       }
+       else if (m_pqSize == 2 && !remove)
+       {
+               if (m_pq[0].chain.endpt > m_pq[1].chain.endpt)
+               {
+                       tmp = m_pq[1];
+                       m_pq[1] = m_pq[0];
+                       m_pq[0] = tmp;
+               }
+       }
+       return 0;
+}
+
+int RTRead::readGoodChain(FILE *pFile, RTChain *chain)
+{
+       size_t ret;
+
+       if (pFile == NULL)
+       {
+               return 1;
+       }
+       do
+       {
+               ret = fread((void*)chain, 16, 1, pFile);
+               if(ret == 1) ret = fread((void*)&chain->checkpoint, 2, 1, pFile);
+               if (ret != 1)
+               {
+                       if (ferror(pFile) != 0)
+                       {
+                               printf("Error reading file.\n");
+                               printf("Continue? (y/n): ");
+                               int ch = 0;
+                               while (ch != EOF && ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N')
+                               {
+                                       ch = getchar();
+                               }
+                               if (ch != 'y' && ch != 'Y')
+                               {
+                                       exit(1);
+                               }
+                               clearerr(pFile);
+                       }
+                       else if (feof(pFile) != 0)
+                       {
+                               fclose(pFile);
+                               return 1;
+                       }
+               }
+               else
+               {
+                       m_chainsRead++;
+               }
+       } while (ret != 1 || chain->startpt > m_maxIndex || chain->endpt > m_maxIndex);
+       return 0;
+}
+
+void RTRead::printStatus()
+{
+       double percent = ((double) m_chainsRead / (double) m_chains) * 100.0;
+       double timeElapsed = (clock() - m_startTime) / (double)CLOCKS_PER_SEC;
+
+       printf("\n*** Status ***\n");
+#ifdef _WIN32
+       printf("  Chains Read:   %I64u\n", m_chainsRead);
+       printf("  Total Chains:  %I64u\n", m_chains);
+#else
+       printf("  Chains Read:   %llu\n", m_chainsRead);
+       printf("  Total Chains:  %llu\n", m_chains);
+#endif
+       printf("  Files Open:    %u\n", m_pqSize);
+       printf("  Percent:       %0.1f\n", percent);
+       printf("  Time Elapsed:  %0.0f sec\n", timeElapsed);
+       printf("  Time Left:     %0.0f sec\n\n", timeElapsed / (percent / 100.0) - timeElapsed);
+}
+
+int RTRead::getInfo(char *file, int len, FileList *ret)
+{
+       FILE *pFile;
+       unsigned int size;
+
+       if (m_verbose)
+       {
+               printf("Opening file '%s'\n", file);
+       }
+       pFile = fopen(file, "rb");
+       if (pFile == NULL)
+       {
+               perror(file);
+               return 1;
+       }
+
+       // Get file size
+       fseek(pFile, 0, SEEK_END);
+       size = ftell(pFile);
+       if (size & 15 != 0)
+       {
+               fclose(pFile);
+               printf("Error file size of '%s' is not a multible of 16 bytes.\n", file);
+               return 1;
+       }
+       fseek(pFile, 0, SEEK_SET);
+       ret->chains = size >> 4;
+       ret->pFile = pFile;
+
+       ret->name = new char[len + 1];
+       strncpy(ret->name, file, len);
+       ret->name[len] = '\0';
+       return 0;
+}
+
diff --git a/Server Applications/rtperfecter0.0/RTRead.h b/Server Applications/rtperfecter0.0/RTRead.h
new file mode 100644 (file)
index 0000000..02cc313
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTREAD_H
+#define RTREAD_H
+
+#include <sys/types.h>
+#include "RTCommon.h"
+
+struct FileList
+{
+       char *name;
+       unsigned int chains;
+       FILE *pFile;
+       FileList *next;
+};
+
+struct PriorityQueueNode
+{
+       RTChain chain;
+       FILE *pFile;
+       char *fName;
+};
+
+class RTRead
+{
+public:
+        RTRead(char *dir, uint64 maxIndex, int verbose);
+       ~RTRead();
+
+       int readChain(RTChain *c);
+       void printStatus();
+
+private:
+       int getInfo(char *file, int len, FileList *ret);
+       int readGoodChain(FILE *pFile, RTChain *chain);
+
+       uint64 m_chains, m_chainsRead, m_maxIndex;
+       PriorityQueueNode *m_pq;
+       clock_t m_startTime;
+       unsigned int m_pqSize;
+       int m_verbose;
+};
+
+#endif
+
diff --git a/Server Applications/rtperfecter0.0/RTWrite.cpp b/Server Applications/rtperfecter0.0/RTWrite.cpp
new file mode 100644 (file)
index 0000000..688b9a5
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "RTWrite.h"
+
+RTWrite::RTWrite(char *fileName, int maxChainsPerFile)
+{
+       unsigned int len = strlen(fileName);
+
+       m_file = new char[len + 1];
+       m_fileTemp = new char[len + 21];
+       strncpy(m_file, fileName, len);
+       m_file[len] = '\0';
+
+       m_curFile = 0;
+       m_curFileChains = 0;
+       m_chainsPerFile = maxChainsPerFile;
+       m_pFile = NULL;
+       m_prevEndpt = 0;
+}
+
+RTWrite::~RTWrite()
+{
+       if (m_pFile != NULL)
+       {
+               fclose(m_pFile);
+               sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
+               if (rename("temp.rt", m_fileTemp) != 0)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+       }
+       if (m_file != NULL)
+       {
+               delete [] m_file;
+       }
+       if (m_fileTemp != NULL)
+       {
+               delete [] m_fileTemp;
+       }
+}
+
+void RTWrite::writeChain(RTChain *chain)
+{
+
+       if (m_prevEndpt >= chain->endpt && chain->endpt != 0)
+       {
+               printf("**** Error writeChain(): Tring to write unsorted data. ****\n");
+               exit(1);
+       }
+       if (m_pFile == NULL)
+       {
+               m_pFile = fopen("temp.rt", "wb");
+               if (m_pFile == NULL)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+       }
+       if (fwrite((void*)chain, 16, 1, m_pFile) != 1)
+       {
+               perror("temp.rt");
+               exit(1);
+       }       
+       if (fwrite((void*)&chain->checkpoint, 2, 1, m_pFile) != 1)
+       {
+               perror("temp.rt");
+               exit(1);
+       }
+       m_curFileChains++;
+       if (m_curFileChains >= m_chainsPerFile)
+       {
+               fclose(m_pFile);
+               m_pFile = NULL;
+               sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
+               if (rename("temp.rt", m_fileTemp) != 0)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+               m_curFile++;
+               m_curFileChains = 0;
+       }
+}
+
diff --git a/Server Applications/rtperfecter0.0/RTWrite.h b/Server Applications/rtperfecter0.0/RTWrite.h
new file mode 100644 (file)
index 0000000..d2c8c6e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTWRITE_H
+#define RTWRITE_H
+
+#include "RTCommon.h"
+
+class RTWrite
+{
+public:
+        RTWrite(char *fileName, int maxChainsPerFile);
+       ~RTWrite();
+
+       void writeChain(RTChain *c);
+
+private:
+       uint64 m_prevEndpt;
+       unsigned int m_curFile, m_curFileChains, m_chainsPerFile;
+       char *m_file, *m_fileTemp;
+       FILE *m_pFile;
+       int m_verbose;
+};
+
+#endif
+
diff --git a/Server Applications/rtperfecter0.0/main.cpp b/Server Applications/rtperfecter0.0/main.cpp
new file mode 100644 (file)
index 0000000..df4d85f
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctime>
+#include "RTWrite.h"
+#include "RTRead.h"
+
+#ifdef _WIN32
+       #include <conio.h>
+       #define DIRECTORY_SEPERATOR '\\'
+#else
+       #include <fcntl.h>
+       #define DIRECTORY_SEPERATOR '/'
+#endif
+
+struct RTChain2
+{
+       uint64 startpt;
+       unsigned int endpt32_1;
+       unsigned int endpt32_2;
+       unsigned short checkpoint;
+};
+
+union RTChainU
+{
+       RTChain c;
+       RTChain2 c2;    
+};
+
+void usage(char *runStr);
+
+int main(int argc, char **argv)
+{
+#ifdef _WIN32
+       uint64 maxIndex = 0xffffffffffffffff;
+#else
+       uint64 maxIndex = 0xffffffffffffffffll;
+#endif
+       int argi = 1, i, argsUsed = 0;
+       unsigned int maxChainsPerFile = 67108864;
+
+       // Get arguments
+       if (argc > 3 && argc < 6)
+       {
+               for (; argi < argc - 2; argi++)
+               {
+                       if (strcmp(argv[argi], "-v") == 0 && (argsUsed & 1) == 0)
+                       {
+                               // Enable verbose mode
+                               argsUsed |= 1;
+                       }
+                       else if (strncmp(argv[argi], "-s=", 3) == 0 && (argsUsed & 2) == 0)
+                       {
+                               // Max file size in MiB
+                               argsUsed |= 2;
+                               maxChainsPerFile = 0;
+                               for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       maxChainsPerFile *= 10;
+                                       maxChainsPerFile += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               if (i > 8 || maxChainsPerFile > 65535) // i - 3 > 5
+                               {
+                                       printf("Error: Number is to large.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               maxChainsPerFile <<= 16; // maxChainsPerFile *= 1024 * 1024 / 16
+                       }
+                       else if (strncmp(argv[argi], "-i=", 3) == 0 && (argsUsed & 4) == 0)
+                       {
+                               // Maximum index for chains
+                               argsUsed |= 4;
+                               maxIndex = 0;
+                               for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       maxIndex *= 10;
+                                       maxIndex += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               if (i > 23) // i - 3 > 20
+                               {
+                                       printf("Error: Number is to large.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                       }
+                       else
+                       {
+                               printf("Error: Unknown argument.\n\n");
+                               usage(argv[0]);
+                               return 1;
+                       }
+               }
+       }
+       else if (argc != 3)
+       {
+               if (argc == 1 || argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
+               {
+                       usage(argv[0]);
+                       return 0;
+               }
+               printf("Error: Wrong number of arguments.\n\n");
+               usage(argv[0]);
+               return 1;
+       }
+
+       // Init
+       RTChainU chain, prevChain;
+       memset(&prevChain.c, 0x00, sizeof(prevChain.c));
+       uint64 uniqueChains = 0;
+       RTRead inRt(argv[argi], maxIndex, argsUsed & 1);
+       RTWrite outRt(argv[argi + 1], maxChainsPerFile);
+
+#ifndef _WIN32
+       // Set stdin to non-blocking
+       fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NDELAY);
+#endif
+       clock_t t = clock();
+
+       for (int ret = inRt.readChain(&(chain.c)); ret == 0; ret = inRt.readChain(&(chain.c)))
+       {
+/*
+               // Show status
+#ifdef _WIN32
+               if (kbhit())
+               {
+                       int ch = getchar();
+                       if (ch == (int)'\n')
+                       {
+                               inRt.printStatus();
+                       }
+               }
+#else
+               int ch = getchar();
+               if (ch == (int)'\n')
+               {
+                       inRt.printStatus();
+               }
+#endif
+*/
+               // Check the least significate 32 bits first
+               if (chain.c2.endpt32_1 != prevChain.c2.endpt32_1 || chain.c2.endpt32_2 != prevChain.c2.endpt32_2)
+               {
+                       outRt.writeChain(&(chain.c));
+                       uniqueChains++;
+               }
+               prevChain = chain;
+       }
+#ifdef _WIN32
+       printf("Unique Chains: %I64u\nTotal time:    %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
+#else
+       printf("Unique Chains: %llu\nTotal time:    %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
+#endif
+       return 0;
+}
+
+void usage(char *runStr)
+{
+       printf("\n                          **** RT Perfecter v0.0 ****\n\n");
+       printf("Converts sorted rt files in a directory to a perfect rainbow table. All rt files\n");
+       printf("in the directory must all be from the same rainbow table.\n\n");
+       printf("%s [Options] input-directory output-file-pattern\n\n", runStr);
+       printf("Options:\n");
+       printf("  -i=number\n");
+       printf("    Maximum index for chains.\n\n");
+       printf("  -s=number\n");
+       printf("    Maximum size for output files in MiB [default is 1024, max is 65535].\n\n");
+       printf("  -v\n");
+       printf("    Verbose mode, displays extra info.\n\n");
+       printf("output-file-pattern:\n");
+       printf("  This will be passed into sprintf() with the number of chains in the file and\n");
+       printf("  the current file number starting at 0. This could look like:\n");
+       printf("  'some-folder%csome-name%%u-%%03u.rt'\n", DIRECTORY_SEPERATOR);
+       printf("  Where '%%u' would be the number of chains in the file and '%%03u' would be the\n");
+       printf("  file number formated like 000, 001, 002, and so on.\n\n");
+       printf("Run-time:\n");
+       printf("  Press [Enter] to display a status message.\n\n");
+       printf("Copyright (c) 2008 Steve Thomas <SMT837784@yahoo.com>\n");
+       printf("  This is free software: you can redistribute it and/or modify it under the\n");
+       printf("  terms of the GNU General Public License as published by the Free Software\n");
+       printf("  Foundation, either version 3 of the License, or (at your option) any later\n");
+       printf("  version. There is NO WARRANTY, to the extent permitted by law.\n");
+}
+
diff --git a/Server Applications/rtperfecter0.0/makefile b/Server Applications/rtperfecter0.0/makefile
new file mode 100644 (file)
index 0000000..85a0528
--- /dev/null
@@ -0,0 +1,7 @@
+all: main
+
+main: 
+       g++ RTRead.cpp RTWrite.cpp main.cpp -O3 -o rtperfecter0
+clean:
+       -rm *.o
+
diff --git a/Server Applications/rtperfecter0.0/rtperfecter0 b/Server Applications/rtperfecter0.0/rtperfecter0
new file mode 100644 (file)
index 0000000..23dfea1
Binary files /dev/null and b/Server Applications/rtperfecter0.0/rtperfecter0 differ
diff --git a/Server Applications/rtperfecter0.0/rtperfecter0.0.7z b/Server Applications/rtperfecter0.0/rtperfecter0.0.7z
new file mode 100644 (file)
index 0000000..edd38dc
Binary files /dev/null and b/Server Applications/rtperfecter0.0/rtperfecter0.0.7z differ
diff --git a/Server Applications/rtperfecter0.1/RTCommon.h b/Server Applications/rtperfecter0.1/RTCommon.h
new file mode 100644 (file)
index 0000000..3f720e2
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTCOMMON_H
+#define RTCOMMON_H
+
+#include <stdio.h>
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 unsigned long long
+#endif
+/*
+struct RTChain
+{
+       uint64 startpt;
+       uint64 endpt;
+};
+*/
+struct RTChain
+{
+       uint64 startpt;
+       uint64 endpt;
+       unsigned short checkpoint;      
+};
+
+#endif
+
diff --git a/Server Applications/rtperfecter0.1/RTRead.cpp b/Server Applications/rtperfecter0.1/RTRead.cpp
new file mode 100644 (file)
index 0000000..084f217
--- /dev/null
@@ -0,0 +1,416 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctime>
+#include <errno.h>
+#include <stdlib.h>
+#include "RTRead.h"
+
+#ifdef HAVE_DIRENT_H
+       #include <dirent.h>
+#else
+       // I know Microsoft's compiler, .Net 2005 or older, does not come with this file.
+       // You can use this if you don't have dirent.h: http://www.cs.fiu.edu/~weiss/cop4338_spr06/dirent.h
+       // Umm I'm not sure if the license on that file, which appears to be public domain, conflicts with GPL v3.
+       // So only use that if you need it and the licenses don't conflict.
+       #include "dirent.h"
+#endif
+
+#ifdef _WIN32
+       #include <conio.h>
+       #define DIRECTORY_SEPERATOR '\\'
+#else
+       #include <fcntl.h>
+       #define DIRECTORY_SEPERATOR '/'
+#endif
+
+#ifndef NAME_MAX
+       #define NAME_MAX 256
+#endif
+
+#include "RTRead.h"
+
+RTRead::RTRead(char *dir, uint64 maxIndex, int verbose)
+{
+       int dirLen = strlen(dir), dirFileLen;
+       char *file = new char[dirLen + NAME_MAX + 2];
+       DIR *pDir;
+       struct dirent *pDirFile;
+       FileList *head = NULL, *current = NULL, *temp = new FileList;
+
+       // Init
+       m_verbose = verbose;
+       m_maxIndex = maxIndex;
+       m_chainsRead = 0;
+       m_chains = 0;
+       m_pqSize = 0;
+       m_pq = NULL;
+       temp->next = NULL;
+       strncpy(file, dir, dirLen);
+       if (dir[dirLen - 1] != DIRECTORY_SEPERATOR)
+       {
+               file[dirLen] = DIRECTORY_SEPERATOR;
+               dirLen++;
+       }
+
+       // Open directory
+       pDir = opendir(dir);
+       if (pDir == NULL)
+       {
+               printf("Error #%u: Opening directory '%s'\n", errno, dir);
+               exit(errno);
+       }
+
+       // Get files
+       for (pDirFile = readdir(pDir); pDirFile != NULL; pDirFile = readdir(pDir))
+       {
+               dirFileLen = strlen(pDirFile->d_name);
+               if (pDirFile->d_name[0] != '.' && dirFileLen > 3 &&
+                   pDirFile->d_name[dirFileLen - 3] == '.' &&
+                  (pDirFile->d_name[dirFileLen - 2] == 'r' || pDirFile->d_name[dirFileLen - 2] == 'R') &&
+                  (pDirFile->d_name[dirFileLen - 1] == 't' || pDirFile->d_name[dirFileLen - 1] == 'T'))
+               {
+                       strcpy(file + dirLen, pDirFile->d_name);
+                       if (getInfo(file, dirLen + dirFileLen, temp) == 0)
+                       {
+                               m_chains += temp->chains;
+                               m_pqSize++;
+                               if (head == NULL)
+                               {
+                                       head = temp;
+                                       current = temp;
+                               }
+                               else
+                               {
+                                       current->next = temp;
+                                       current = temp;
+                               }
+                               temp = new FileList;
+                               temp->next = NULL;
+                       }
+                       else
+                       {
+                               printf("Continue? (y/n): ");
+                               int ch = 0;
+                               while (ch != EOF && ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N')
+                               {
+                                       ch = getchar();
+                               }
+                               if (ch != 'y' && ch != 'Y')
+                               {
+                                       while (head != NULL)
+                                       {
+                                               current = head;
+                                               head = head->next;
+                                               fclose(current->pFile);
+                                               delete [] current->name;
+                                               delete current;
+                                       }
+                                       delete [] file;
+                                       delete temp;
+                                       closedir(pDir);
+                                       exit(1);
+                               }
+                       }
+               }
+       }
+       delete [] file;
+       delete temp;
+       closedir(pDir);
+       if (head == NULL)
+       {
+               printf("Error no '*.rt' input files found in directory '%s'.\n", dir);
+               exit(1);
+       }
+
+       // Push file list into priority queue
+       PriorityQueueNode tmpNode;
+       unsigned int i = 0, node, par;
+
+       m_pq = new PriorityQueueNode[m_pqSize];
+       while (head != NULL)
+       {
+               if (readGoodChain(head->pFile, &(m_pq[i].chain)) == 0)
+               {
+                       // Init priority queue node
+                       m_pq[i].pFile = head->pFile;
+                       m_pq[i].fName = head->name;
+
+                       // Insert into priority queue
+                       if (i != 0)
+                       {
+                               node = i;
+                               par = (node - 1) >> 1;
+                               if (m_pq[par].chain.endpt > m_pq[node].chain.endpt)
+                               {
+                                       tmpNode = m_pq[node];
+                                       do
+                                       {
+                                               m_pq[node] = m_pq[par];
+                                               node = par;
+                                               if (par == 0)
+                                               {
+                                                       break;
+                                               }
+                                               par = (node - 1) >> 1;
+                                       } while (m_pq[par].chain.endpt > tmpNode.chain.endpt);
+                               }
+                               if (i != node)
+                               {
+                                       m_pq[node] = tmpNode;
+                               }
+                       }
+                       i++;
+               }
+               else
+               {
+                       m_pqSize--;
+                       printf("File had no valid chains '%s'\n", head->name);
+                       delete [] head->name;
+               }
+
+               // Delete file list node
+               current = head;
+               head = head->next;
+               delete current;
+       }
+
+       printf("Starting with %u files.\n", m_pqSize);
+       m_startTime = clock();
+}
+
+RTRead::~RTRead()
+{
+       if (m_pq != NULL)
+       {
+               for (unsigned int i = 0; i < m_pqSize; i++)
+               {
+                       if (m_pq[i].pFile != NULL)
+                       {
+                               fclose(m_pq[i].pFile);
+                       }
+                       if (m_pq[i].fName != NULL)
+                       {
+                               delete [] m_pq[i].fName;
+                       }
+               }
+               delete [] m_pq;
+       }
+}
+
+int RTRead::readChain(RTChain *chain)
+{
+       PriorityQueueNode tmp;
+       unsigned int child, node;
+
+       if (m_pq == NULL)
+       {
+               return 1;
+       }
+       *chain = m_pq[0].chain;
+       bool remove = (readGoodChain(m_pq[0].pFile, &(m_pq[0].chain)) != 0);
+
+       if (remove)
+       {
+               if (m_verbose)
+               {
+                       printf("Finished with file '%s'\n", m_pq[0].fName);
+               }
+               delete [] m_pq[0].fName;
+
+               // Remove node from queue
+               m_pqSize--;
+               if (m_pqSize == 2)
+               {
+                       if (m_pq[1].chain.endpt < m_pq[2].chain.endpt)
+                       {
+                               m_pq[0] = m_pq[1];
+                               m_pq[1] = m_pq[2];
+                       }
+                       else
+                       {
+                               m_pq[0] = m_pq[2];
+                       }
+                       m_pq[2].fName = NULL;
+                       m_pq[2].pFile = NULL;
+               }
+               else if (m_pqSize == 1)
+               {
+                       m_pq[0] = m_pq[1];
+                       m_pq[1].fName = NULL;
+                       m_pq[1].pFile = NULL;
+               }
+               else if (m_pqSize == 0)
+               {
+                       delete [] m_pq;
+                       m_pq = NULL;
+               }
+       }
+       if (m_pqSize > 2)
+       {
+               if (remove)
+               {
+                       tmp = m_pq[m_pqSize];
+                       m_pq[m_pqSize].fName = NULL;
+                       m_pq[m_pqSize].pFile = NULL;
+               }
+               else
+               {                       
+                       tmp = m_pq[0];
+               }
+               // Move tmp node to proper posistion in queue
+               node = 0;
+               child = 1;
+               if (m_pq[1].chain.endpt > m_pq[2].chain.endpt)
+               {
+                       child = 2;
+               }
+               while (tmp.chain.endpt > m_pq[child].chain.endpt)
+               {
+                       m_pq[node] = m_pq[child];
+                       node = child;
+                       // child = left node
+                       child = (node << 1) + 1;
+                       if (child >= m_pqSize)
+                       {
+                               break;
+                       }
+                       if (child + 1 < m_pqSize && m_pq[child].chain.endpt > m_pq[child + 1].chain.endpt)
+                       {
+                               // child = right node
+                               child++;
+                       }
+               }
+               if (node != 0 || remove)
+               {
+                       m_pq[node] = tmp;
+               }
+       }
+       else if (m_pqSize == 2 && !remove)
+       {
+               if (m_pq[0].chain.endpt > m_pq[1].chain.endpt)
+               {
+                       tmp = m_pq[1];
+                       m_pq[1] = m_pq[0];
+                       m_pq[0] = tmp;
+               }
+       }
+       return 0;
+}
+
+int RTRead::readGoodChain(FILE *pFile, RTChain *chain)
+{
+       size_t ret;
+
+       if (pFile == NULL)
+       {
+               return 1;
+       }
+       do
+       {
+               ret = fread((void*)chain, 16, 1, pFile);
+               if(ret == 1) ret = fread((void*)&chain->checkpoint, 2, 1, pFile);
+               if (ret != 1)
+               {
+                       if (ferror(pFile) != 0)
+                       {
+                               printf("Error reading file.\n");
+                               printf("Continue? (y/n): ");
+                               int ch = 0;
+                               while (ch != EOF && ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N')
+                               {
+                                       ch = getchar();
+                               }
+                               if (ch != 'y' && ch != 'Y')
+                               {
+                                       exit(1);
+                               }
+                               clearerr(pFile);
+                       }
+                       else if (feof(pFile) != 0)
+                       {
+                               fclose(pFile);
+                               return 1;
+                       }
+               }
+               else
+               {
+                       m_chainsRead++;
+               }
+       } while (ret != 1 || chain->startpt > m_maxIndex || chain->endpt > m_maxIndex);
+       return 0;
+}
+
+void RTRead::printStatus()
+{
+       double percent = ((double) m_chainsRead / (double) m_chains) * 100.0;
+       double timeElapsed = (clock() - m_startTime) / (double)CLOCKS_PER_SEC;
+
+       printf("\n*** Status ***\n");
+#ifdef _WIN32
+       printf("  Chains Read:   %I64u\n", m_chainsRead);
+       printf("  Total Chains:  %I64u\n", m_chains);
+#else
+       printf("  Chains Read:   %llu\n", m_chainsRead);
+       printf("  Total Chains:  %llu\n", m_chains);
+#endif
+       printf("  Files Open:    %u\n", m_pqSize);
+       printf("  Percent:       %0.1f\n", percent);
+       printf("  Time Elapsed:  %0.0f sec\n", timeElapsed);
+       printf("  Time Left:     %0.0f sec\n\n", timeElapsed / (percent / 100.0) - timeElapsed);
+}
+
+int RTRead::getInfo(char *file, int len, FileList *ret)
+{
+       FILE *pFile;
+       unsigned int size;
+
+       if (m_verbose)
+       {
+               printf("Opening file '%s'\n", file);
+       }
+       pFile = fopen(file, "rb");
+       if (pFile == NULL)
+       {
+               perror(file);
+               return 1;
+       }
+
+       // Get file size
+       fseek(pFile, 0, SEEK_END);
+       size = ftell(pFile);
+       if (size & 15 != 0)
+       {
+               fclose(pFile);
+               printf("Error file size of '%s' is not a multible of 16 bytes.\n", file);
+               return 1;
+       }
+       fseek(pFile, 0, SEEK_SET);
+       ret->chains = size >> 4;
+       ret->pFile = pFile;
+
+       ret->name = new char[len + 1];
+       strncpy(ret->name, file, len);
+       ret->name[len] = '\0';
+       return 0;
+}
+
diff --git a/Server Applications/rtperfecter0.1/RTRead.h b/Server Applications/rtperfecter0.1/RTRead.h
new file mode 100644 (file)
index 0000000..02cc313
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTREAD_H
+#define RTREAD_H
+
+#include <sys/types.h>
+#include "RTCommon.h"
+
+struct FileList
+{
+       char *name;
+       unsigned int chains;
+       FILE *pFile;
+       FileList *next;
+};
+
+struct PriorityQueueNode
+{
+       RTChain chain;
+       FILE *pFile;
+       char *fName;
+};
+
+class RTRead
+{
+public:
+        RTRead(char *dir, uint64 maxIndex, int verbose);
+       ~RTRead();
+
+       int readChain(RTChain *c);
+       void printStatus();
+
+private:
+       int getInfo(char *file, int len, FileList *ret);
+       int readGoodChain(FILE *pFile, RTChain *chain);
+
+       uint64 m_chains, m_chainsRead, m_maxIndex;
+       PriorityQueueNode *m_pq;
+       clock_t m_startTime;
+       unsigned int m_pqSize;
+       int m_verbose;
+};
+
+#endif
+
diff --git a/Server Applications/rtperfecter0.1/RTWrite.cpp b/Server Applications/rtperfecter0.1/RTWrite.cpp
new file mode 100644 (file)
index 0000000..18d2fb6
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "RTWrite.h"
+
+RTWrite::RTWrite(char *fileName, int maxChainsPerFile)
+{
+       unsigned int len = strlen(fileName);
+
+       m_file = new char[len + 1];
+       m_fileTemp = new char[len + 21];
+       strncpy(m_file, fileName, len);
+       m_file[len] = '\0';
+
+       m_curFile = 0;
+       m_curFileChains = 0;
+       m_chainsPerFile = maxChainsPerFile;
+       m_pFile = NULL;
+       m_prevEndpt = 0;
+}
+
+RTWrite::~RTWrite()
+{
+       if (m_pFile != NULL)
+       {
+               fclose(m_pFile);
+               sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
+               if (rename("temp.rt", m_fileTemp) != 0)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+       }
+       if (m_file != NULL)
+       {
+               delete [] m_file;
+       }
+       if (m_fileTemp != NULL)
+       {
+               delete [] m_fileTemp;
+       }
+}
+
+void RTWrite::writeChain(RTChain *chain)
+{
+
+       if (m_prevEndpt >= chain->endpt && chain->endpt != 0)
+       {
+               printf("**** Error writeChain(): Tring to write unsorted data. ****\n");
+               exit(1);
+       }
+       if (m_pFile == NULL)
+       {
+               m_pFile = fopen("temp.rt", "wb");
+               if (m_pFile == NULL)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+       }
+       if (fwrite((void*)chain, 16, 1, m_pFile) != 1)
+       {
+               perror("temp.rt");
+               exit(1);
+       }       
+       m_curFileChains++;
+       if (m_curFileChains >= m_chainsPerFile)
+       {
+               fclose(m_pFile);
+               m_pFile = NULL;
+               sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
+               if (rename("temp.rt", m_fileTemp) != 0)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+               m_curFile++;
+               m_curFileChains = 0;
+       }
+}
+
diff --git a/Server Applications/rtperfecter0.1/RTWrite.h b/Server Applications/rtperfecter0.1/RTWrite.h
new file mode 100644 (file)
index 0000000..d2c8c6e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTWRITE_H
+#define RTWRITE_H
+
+#include "RTCommon.h"
+
+class RTWrite
+{
+public:
+        RTWrite(char *fileName, int maxChainsPerFile);
+       ~RTWrite();
+
+       void writeChain(RTChain *c);
+
+private:
+       uint64 m_prevEndpt;
+       unsigned int m_curFile, m_curFileChains, m_chainsPerFile;
+       char *m_file, *m_fileTemp;
+       FILE *m_pFile;
+       int m_verbose;
+};
+
+#endif
+
diff --git a/Server Applications/rtperfecter0.1/main.cpp b/Server Applications/rtperfecter0.1/main.cpp
new file mode 100644 (file)
index 0000000..df4d85f
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctime>
+#include "RTWrite.h"
+#include "RTRead.h"
+
+#ifdef _WIN32
+       #include <conio.h>
+       #define DIRECTORY_SEPERATOR '\\'
+#else
+       #include <fcntl.h>
+       #define DIRECTORY_SEPERATOR '/'
+#endif
+
+struct RTChain2
+{
+       uint64 startpt;
+       unsigned int endpt32_1;
+       unsigned int endpt32_2;
+       unsigned short checkpoint;
+};
+
+union RTChainU
+{
+       RTChain c;
+       RTChain2 c2;    
+};
+
+void usage(char *runStr);
+
+int main(int argc, char **argv)
+{
+#ifdef _WIN32
+       uint64 maxIndex = 0xffffffffffffffff;
+#else
+       uint64 maxIndex = 0xffffffffffffffffll;
+#endif
+       int argi = 1, i, argsUsed = 0;
+       unsigned int maxChainsPerFile = 67108864;
+
+       // Get arguments
+       if (argc > 3 && argc < 6)
+       {
+               for (; argi < argc - 2; argi++)
+               {
+                       if (strcmp(argv[argi], "-v") == 0 && (argsUsed & 1) == 0)
+                       {
+                               // Enable verbose mode
+                               argsUsed |= 1;
+                       }
+                       else if (strncmp(argv[argi], "-s=", 3) == 0 && (argsUsed & 2) == 0)
+                       {
+                               // Max file size in MiB
+                               argsUsed |= 2;
+                               maxChainsPerFile = 0;
+                               for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       maxChainsPerFile *= 10;
+                                       maxChainsPerFile += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               if (i > 8 || maxChainsPerFile > 65535) // i - 3 > 5
+                               {
+                                       printf("Error: Number is to large.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               maxChainsPerFile <<= 16; // maxChainsPerFile *= 1024 * 1024 / 16
+                       }
+                       else if (strncmp(argv[argi], "-i=", 3) == 0 && (argsUsed & 4) == 0)
+                       {
+                               // Maximum index for chains
+                               argsUsed |= 4;
+                               maxIndex = 0;
+                               for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       maxIndex *= 10;
+                                       maxIndex += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               if (i > 23) // i - 3 > 20
+                               {
+                                       printf("Error: Number is to large.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                       }
+                       else
+                       {
+                               printf("Error: Unknown argument.\n\n");
+                               usage(argv[0]);
+                               return 1;
+                       }
+               }
+       }
+       else if (argc != 3)
+       {
+               if (argc == 1 || argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
+               {
+                       usage(argv[0]);
+                       return 0;
+               }
+               printf("Error: Wrong number of arguments.\n\n");
+               usage(argv[0]);
+               return 1;
+       }
+
+       // Init
+       RTChainU chain, prevChain;
+       memset(&prevChain.c, 0x00, sizeof(prevChain.c));
+       uint64 uniqueChains = 0;
+       RTRead inRt(argv[argi], maxIndex, argsUsed & 1);
+       RTWrite outRt(argv[argi + 1], maxChainsPerFile);
+
+#ifndef _WIN32
+       // Set stdin to non-blocking
+       fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NDELAY);
+#endif
+       clock_t t = clock();
+
+       for (int ret = inRt.readChain(&(chain.c)); ret == 0; ret = inRt.readChain(&(chain.c)))
+       {
+/*
+               // Show status
+#ifdef _WIN32
+               if (kbhit())
+               {
+                       int ch = getchar();
+                       if (ch == (int)'\n')
+                       {
+                               inRt.printStatus();
+                       }
+               }
+#else
+               int ch = getchar();
+               if (ch == (int)'\n')
+               {
+                       inRt.printStatus();
+               }
+#endif
+*/
+               // Check the least significate 32 bits first
+               if (chain.c2.endpt32_1 != prevChain.c2.endpt32_1 || chain.c2.endpt32_2 != prevChain.c2.endpt32_2)
+               {
+                       outRt.writeChain(&(chain.c));
+                       uniqueChains++;
+               }
+               prevChain = chain;
+       }
+#ifdef _WIN32
+       printf("Unique Chains: %I64u\nTotal time:    %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
+#else
+       printf("Unique Chains: %llu\nTotal time:    %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
+#endif
+       return 0;
+}
+
+void usage(char *runStr)
+{
+       printf("\n                          **** RT Perfecter v0.0 ****\n\n");
+       printf("Converts sorted rt files in a directory to a perfect rainbow table. All rt files\n");
+       printf("in the directory must all be from the same rainbow table.\n\n");
+       printf("%s [Options] input-directory output-file-pattern\n\n", runStr);
+       printf("Options:\n");
+       printf("  -i=number\n");
+       printf("    Maximum index for chains.\n\n");
+       printf("  -s=number\n");
+       printf("    Maximum size for output files in MiB [default is 1024, max is 65535].\n\n");
+       printf("  -v\n");
+       printf("    Verbose mode, displays extra info.\n\n");
+       printf("output-file-pattern:\n");
+       printf("  This will be passed into sprintf() with the number of chains in the file and\n");
+       printf("  the current file number starting at 0. This could look like:\n");
+       printf("  'some-folder%csome-name%%u-%%03u.rt'\n", DIRECTORY_SEPERATOR);
+       printf("  Where '%%u' would be the number of chains in the file and '%%03u' would be the\n");
+       printf("  file number formated like 000, 001, 002, and so on.\n\n");
+       printf("Run-time:\n");
+       printf("  Press [Enter] to display a status message.\n\n");
+       printf("Copyright (c) 2008 Steve Thomas <SMT837784@yahoo.com>\n");
+       printf("  This is free software: you can redistribute it and/or modify it under the\n");
+       printf("  terms of the GNU General Public License as published by the Free Software\n");
+       printf("  Foundation, either version 3 of the License, or (at your option) any later\n");
+       printf("  version. There is NO WARRANTY, to the extent permitted by law.\n");
+}
+
diff --git a/Server Applications/rtperfecter0.1/makefile b/Server Applications/rtperfecter0.1/makefile
new file mode 100644 (file)
index 0000000..2f19bb8
--- /dev/null
@@ -0,0 +1,7 @@
+all: main
+
+main: 
+       g++ RTRead.cpp RTWrite.cpp main.cpp -O3 -o rtperfecter1
+clean:
+       -rm *.o
+
diff --git a/Server Applications/rtperfecter0.1/rtperfecter1 b/Server Applications/rtperfecter0.1/rtperfecter1
new file mode 100644 (file)
index 0000000..8baeae8
Binary files /dev/null and b/Server Applications/rtperfecter0.1/rtperfecter1 differ
diff --git a/Server Applications/rtperfectp/Debug/BuildLog.htm b/Server Applications/rtperfectp/Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..d6d93f8
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/BuildLog.htm differ
diff --git a/Server Applications/rtperfectp/Debug/RTRead.obj b/Server Applications/rtperfectp/Debug/RTRead.obj
new file mode 100644 (file)
index 0000000..c49b2db
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/RTRead.obj differ
diff --git a/Server Applications/rtperfectp/Debug/RTWrite.obj b/Server Applications/rtperfectp/Debug/RTWrite.obj
new file mode 100644 (file)
index 0000000..f913045
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/RTWrite.obj differ
diff --git a/Server Applications/rtperfectp/Debug/main.obj b/Server Applications/rtperfectp/Debug/main.obj
new file mode 100644 (file)
index 0000000..941dec0
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/main.obj differ
diff --git a/Server Applications/rtperfectp/Debug/mt.dep b/Server Applications/rtperfectp/Debug/mt.dep
new file mode 100644 (file)
index 0000000..251314b
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 18:01:44,78 on 17-11-2008 
diff --git a/Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest b/Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest
new file mode 100644 (file)
index 0000000..fac40ba
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
\ No newline at end of file
diff --git a/Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest.res b/Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..9e54244
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/rtperfectp.exe.embed.manifest.res differ
diff --git a/Server Applications/rtperfectp/Debug/rtperfectp.exe.intermediate.manifest b/Server Applications/rtperfectp/Debug/rtperfectp.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..3351598
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Server Applications/rtperfectp/Debug/vc90.idb b/Server Applications/rtperfectp/Debug/vc90.idb
new file mode 100644 (file)
index 0000000..e4e998e
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/vc90.idb differ
diff --git a/Server Applications/rtperfectp/Debug/vc90.pdb b/Server Applications/rtperfectp/Debug/vc90.pdb
new file mode 100644 (file)
index 0000000..5b1d14b
Binary files /dev/null and b/Server Applications/rtperfectp/Debug/vc90.pdb differ
diff --git a/Server Applications/rtperfectp/RTCommon.h b/Server Applications/rtperfectp/RTCommon.h
new file mode 100644 (file)
index 0000000..81fcc50
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter.
+
+       RT Perfecter is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTCOMMON_H
+#define RTCOMMON_H
+
+#include <stdio.h>
+
+#ifdef _WIN32
+       #define uint64 unsigned __int64
+#else
+       #define uint64 unsigned long long
+#endif
+
+struct RTChain
+{
+       uint64 startpt;
+       uint64 endpt;
+};
+struct RTChainCP
+{
+       uint64 startpt;
+       uint64 endpt;
+       unsigned short checkpoint;
+};
+#endif
+
diff --git a/Server Applications/rtperfectp/RTRead.cpp b/Server Applications/rtperfectp/RTRead.cpp
new file mode 100644 (file)
index 0000000..9b26c6f
--- /dev/null
@@ -0,0 +1,420 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter.
+
+       RT Perfecter is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctime>
+#include <errno.h>
+#include <stdlib.h>
+#include "RTRead.h"
+
+#ifdef HAVE_DIRENT_H
+       #include <dirent.h>
+#else
+       // I know Microsoft's compiler, .Net 2005 or older, does not come with this file.
+       // You can use this if you don't have dirent.h: http://www.cs.fiu.edu/~weiss/cop4338_spr06/dirent.h
+       // Umm I'm not sure if the license on that file, which appears to be public domain, conflicts with GPL v3.
+       // So only use that if you need it and the licenses don't conflict.
+       #include "dirent.h"
+#endif
+
+#ifdef _WIN32
+       #include <conio.h>
+       #define DIRECTORY_SEPERATOR '\\'
+#else
+       #include <fcntl.h>
+       #define DIRECTORY_SEPERATOR '/'
+#endif
+
+#ifndef NAME_MAX
+       #define NAME_MAX 256
+#endif
+
+#include "RTRead.h"
+
+RTRead::RTRead(char *dir, uint64 maxIndex, int verbose)
+{
+       int dirLen = strlen(dir), dirFileLen;
+       char *file = new char[dirLen + NAME_MAX + 2];
+       DIR *pDir;
+       struct dirent *pDirFile;
+       FileList *head = NULL, *current = NULL, *temp = new FileList;
+
+       // Init
+       m_verbose = verbose;
+       m_maxIndex = maxIndex;
+       m_chainsRead = 0;
+       m_chains = 0;
+       m_pqSize = 0;
+       m_pq = NULL;
+       temp->next = NULL;
+       strncpy(file, dir, dirLen);
+       if (dir[dirLen - 1] != DIRECTORY_SEPERATOR)
+       {
+               file[dirLen] = DIRECTORY_SEPERATOR;
+               dirLen++;
+       }
+
+       // Open directory
+       pDir = opendir(dir);
+       if (pDir == NULL)
+       {
+               printf("Error #%u: Opening directory '%s'\n", errno, dir);
+               exit(errno);
+       }
+
+       // Get files
+       for (pDirFile = readdir(pDir); pDirFile != NULL; pDirFile = readdir(pDir))
+       {
+               dirFileLen = strlen(pDirFile->d_name);
+               if (pDirFile->d_name[0] != '.' && dirFileLen > 5 &&
+                   pDirFile->d_name[dirFileLen - 5] == '.' &&
+                  (pDirFile->d_name[dirFileLen - 4] == 'p' || pDirFile->d_name[dirFileLen - 4] == 'P') &&
+                  (pDirFile->d_name[dirFileLen - 3] == 'a' || pDirFile->d_name[dirFileLen - 3] == 'A') &&
+                  (pDirFile->d_name[dirFileLen - 2] == 'r' || pDirFile->d_name[dirFileLen - 2] == 'R') &&
+                  (pDirFile->d_name[dirFileLen - 1] == 't' || pDirFile->d_name[dirFileLen - 1] == 'T'))
+
+               {
+                       strcpy(file + dirLen, pDirFile->d_name);
+                       if (getInfo(file, dirLen + dirFileLen, temp) == 0)
+                       {
+                               m_chains += temp->chains;
+                               m_pqSize++;
+                               if (head == NULL)
+                               {
+                                       head = temp;
+                                       current = temp;
+                               }
+                               else
+                               {
+                                       current->next = temp;
+                                       current = temp;
+                               }
+                               temp = new FileList;
+                               temp->next = NULL;
+                       }
+                       else
+                       {
+                               printf("Continue? (y/n): ");
+                               int ch = 0;
+                               while (ch != EOF && ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N')
+                               {
+                                       ch = getchar();
+                               }
+                               if (ch != 'y' && ch != 'Y')
+                               {
+                                       while (head != NULL)
+                                       {
+                                               current = head;
+                                               head = head->next;
+                                               fclose(current->pFile);
+                                               delete [] current->name;
+                                               delete current;
+                                       }
+                                       delete [] file;
+                                       delete temp;
+                                       closedir(pDir);
+                                       exit(1);
+                               }
+                       }
+               }
+       }
+       delete [] file;
+       delete temp;
+       closedir(pDir);
+       if (head == NULL)
+       {
+               printf("Error no '*.part' input files found in directory '%s'.\n", dir);
+               exit(1);
+       }
+
+       // Push file list into priority queue
+       PriorityQueueNode tmpNode;
+       unsigned int i = 0, node, par;
+
+       m_pq = new PriorityQueueNode[m_pqSize];
+       while (head != NULL)
+       {
+               if (readGoodChain(head->pFile, &(m_pq[i].chain)) == 0)
+               {
+                       // Init priority queue node
+                       m_pq[i].pFile = head->pFile;
+                       m_pq[i].fName = head->name;
+
+                       // Insert into priority queue
+                       if (i != 0)
+                       {
+                               node = i;
+                               par = (node - 1) >> 1;
+                               if (m_pq[par].chain.endpt > m_pq[node].chain.endpt)
+                               {
+                                       tmpNode = m_pq[node];
+                                       do
+                                       {
+                                               m_pq[node] = m_pq[par];
+                                               node = par;
+                                               if (par == 0)
+                                               {
+                                                       break;
+                                               }
+                                               par = (node - 1) >> 1;
+                                       } while (m_pq[par].chain.endpt > tmpNode.chain.endpt);
+                               }
+                               if (i != node)
+                               {
+                                       m_pq[node] = tmpNode;
+                               }
+                       }
+                       i++;
+               }
+               else
+               {
+                       m_pqSize--;
+                       printf("File had no valid chains '%s'\n", head->name);
+                       delete [] head->name;
+               }
+
+               // Delete file list node
+               current = head;
+               head = head->next;
+               delete current;
+       }
+
+       printf("Starting with %u files.\n", m_pqSize);
+       m_startTime = clock();
+}
+
+RTRead::~RTRead()
+{
+       if (m_pq != NULL)
+       {
+               for (unsigned int i = 0; i < m_pqSize; i++)
+               {
+                       if (m_pq[i].pFile != NULL)
+                       {
+                               fclose(m_pq[i].pFile);
+                       }
+                       if (m_pq[i].fName != NULL)
+                       {
+                               delete [] m_pq[i].fName;
+                       }
+               }
+               delete [] m_pq;
+       }
+}
+
+int RTRead::readChain(RTChainCP *chain)
+{
+       PriorityQueueNode tmp;
+       unsigned int child, node;
+
+       if (m_pq == NULL)
+       {
+               return 1;
+       }
+       *chain = m_pq[0].chain;
+       bool remove = (readGoodChain(m_pq[0].pFile, &(m_pq[0].chain)) != 0);
+
+       if (remove)
+       {
+               if (m_verbose)
+               {
+                       printf("Finished with file '%s'\n", m_pq[0].fName);
+               }
+               delete [] m_pq[0].fName;
+
+               // Remove node from queue
+               m_pqSize--;
+               if (m_pqSize == 2)
+               {
+                       if (m_pq[1].chain.endpt < m_pq[2].chain.endpt)
+                       {
+                               m_pq[0] = m_pq[1];
+                               m_pq[1] = m_pq[2];
+                       }
+                       else
+                       {
+                               m_pq[0] = m_pq[2];
+                       }
+                       m_pq[2].fName = NULL;
+                       m_pq[2].pFile = NULL;
+               }
+               else if (m_pqSize == 1)
+               {
+                       m_pq[0] = m_pq[1];
+                       m_pq[1].fName = NULL;
+                       m_pq[1].pFile = NULL;
+               }
+               else if (m_pqSize == 0)
+               {
+                       delete [] m_pq;
+                       m_pq = NULL;
+               }
+       }
+       if (m_pqSize > 2)
+       {
+               if (remove)
+               {
+                       tmp = m_pq[m_pqSize];
+                       m_pq[m_pqSize].fName = NULL;
+                       m_pq[m_pqSize].pFile = NULL;
+               }
+               else
+               {                       
+                       tmp = m_pq[0];
+               }
+               // Move tmp node to proper posistion in queue
+               node = 0;
+               child = 1;
+               if (m_pq[1].chain.endpt > m_pq[2].chain.endpt)
+               {
+                       child = 2;
+               }
+               while (tmp.chain.endpt > m_pq[child].chain.endpt)
+               {
+                       m_pq[node] = m_pq[child];
+                       node = child;
+                       // child = left node
+                       child = (node << 1) + 1;
+                       if (child >= m_pqSize)
+                       {
+                               break;
+                       }
+                       if (child + 1 < m_pqSize && m_pq[child].chain.endpt > m_pq[child + 1].chain.endpt)
+                       {
+                               // child = right node
+                               child++;
+                       }
+               }
+               if (node != 0 || remove)
+               {
+                       m_pq[node] = tmp;
+               }
+       }
+       else if (m_pqSize == 2 && !remove)
+       {
+               if (m_pq[0].chain.endpt > m_pq[1].chain.endpt)
+               {
+                       tmp = m_pq[1];
+                       m_pq[1] = m_pq[0];
+                       m_pq[0] = tmp;
+               }
+       }
+       return 0;
+}
+
+int RTRead::readGoodChain(FILE *pFile, RTChainCP *chain)
+{
+       size_t ret;
+
+       if (pFile == NULL)
+       {
+               return 1;
+       }
+       do
+       {
+               ret = fread((void*)chain, 16, 1, pFile);
+               if(ret == 1)
+                       ret = fread((void*)&chain->checkpoint, 2, 1, pFile);
+               if (ret != 1)
+               {
+                       if (ferror(pFile) != 0)
+                       {
+                               printf("Error reading file.\n");
+                               printf("Continue? (y/n): ");
+                               int ch = 0;
+                               while (ch != EOF && ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N')
+                               {
+                                       ch = getchar();
+                               }
+                               if (ch != 'y' && ch != 'Y')
+                               {
+                                       exit(1);
+                               }
+                               clearerr(pFile);
+                       }
+                       else if (feof(pFile) != 0)
+                       {
+                               fclose(pFile);
+                               return 1;
+                       }
+               }
+               else
+               {
+                       m_chainsRead++;
+               }
+       } while (ret != 1 || chain->startpt > m_maxIndex || chain->endpt > m_maxIndex);
+       return 0;
+}
+
+void RTRead::printStatus()
+{
+       double percent = ((double) m_chainsRead / (double) m_chains) * 100.0;
+       double timeElapsed = (clock() - m_startTime) / (double)CLOCKS_PER_SEC;
+
+       printf("\n*** Status ***\n");
+#ifdef _WIN32
+       printf("  Chains Read:   %I64u\n", m_chainsRead);
+       printf("  Total Chains:  %I64u\n", m_chains);
+#else
+       printf("  Chains Read:   %llu\n", m_chainsRead);
+       printf("  Total Chains:  %llu\n", m_chains);
+#endif
+       printf("  Files Open:    %u\n", m_pqSize);
+       printf("  Percent:       %0.1f\n", percent);
+       printf("  Time Elapsed:  %0.0f sec\n", timeElapsed);
+       printf("  Time Left:     %0.0f sec\n\n", timeElapsed / (percent / 100.0) - timeElapsed);
+}
+
+int RTRead::getInfo(char *file, int len, FileList *ret)
+{
+       FILE *pFile;
+       unsigned int size;
+
+       if (m_verbose)
+       {
+               printf("Opening file '%s'\n", file);
+       }
+       pFile = fopen(file, "rb");
+       if (pFile == NULL)
+       {
+               perror(file);
+               return 1;
+       }
+
+       // Get file size
+       fseek(pFile, 0, SEEK_END);
+       size = ftell(pFile);
+       if (size & 15 != 0)
+       {
+               fclose(pFile);
+               printf("Error file size of '%s' is not a multible of 16 bytes.\n", file);
+               return 1;
+       }
+       fseek(pFile, 0, SEEK_SET);
+       ret->chains = size >> 4;
+       ret->pFile = pFile;
+
+       ret->name = new char[len + 1];
+       strncpy(ret->name, file, len);
+       ret->name[len] = '\0';
+       return 0;
+}
+
diff --git a/Server Applications/rtperfectp/RTRead.h b/Server Applications/rtperfectp/RTRead.h
new file mode 100644 (file)
index 0000000..e6c6d84
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter.
+
+       RT Perfecter is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTREAD_H
+#define RTREAD_H
+
+#include <sys/types.h>
+#include "RTCommon.h"
+
+struct FileList
+{
+       char *name;
+       unsigned int chains;
+       FILE *pFile;
+       FileList *next;
+};
+
+struct PriorityQueueNode
+{
+       RTChainCP chain;
+       FILE *pFile;
+       char *fName;
+};
+
+class RTRead
+{
+public:
+        RTRead(char *dir, uint64 maxIndex, int verbose);
+       ~RTRead();
+
+       int readChain(RTChainCP *c);
+       void printStatus();
+
+private:
+       int getInfo(char *file, int len, FileList *ret);
+       int readGoodChain(FILE *pFile, RTChainCP *chain);
+
+       uint64 m_chains, m_chainsRead, m_maxIndex;
+       PriorityQueueNode *m_pq;
+       clock_t m_startTime;
+       unsigned int m_pqSize;
+       int m_verbose;
+};
+
+#endif
+
diff --git a/Server Applications/rtperfectp/RTWrite.cpp b/Server Applications/rtperfectp/RTWrite.cpp
new file mode 100644 (file)
index 0000000..35692d1
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "RTWrite.h"
+
+RTWrite::RTWrite(char *fileName, int maxChainsPerFile)
+{
+       unsigned int len = strlen(fileName);
+
+       m_file = new char[len + 1];
+       m_fileTemp = new char[len + 21];
+       strncpy(m_file, fileName, len);
+       m_file[len] = '\0';
+
+       m_curFile = 0;
+       m_curFileChains = 0;
+       m_chainsPerFile = maxChainsPerFile;
+       m_pFile = NULL;
+       m_prevEndpt = 0;
+}
+
+RTWrite::~RTWrite()
+{
+       if (m_pFile != NULL)
+       {
+               fclose(m_pFile);
+               sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
+               if (rename("temp.rt", m_fileTemp) != 0)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+       }
+       if (m_file != NULL)
+       {
+               delete [] m_file;
+       }
+       if (m_fileTemp != NULL)
+       {
+               delete [] m_fileTemp;
+       }
+}
+
+void RTWrite::writeChain(RTChainCP *chain)
+{
+       if(chain->startpt == 0 || chain->endpt == 0)
+               return;
+
+       if (m_prevEndpt > chain->endpt)
+       {
+               printf("**** Error writeChain(): Tring to write unsorted data. (%llu > %llu)****\n", m_prevEndpt, chain->endpt);
+               exit(1);
+       }
+       /*
+#ifdef _WIN32
+       if(chain->startpt > 0x0000ffffffffffffI64)
+#else
+       if(chain->startpt > 0x0000ffffffffffff11u)
+#endif
+       {
+               printf("**** Error writeChain(): Prefix is bigger than 6 bytes. (%llx) %u chains ****\n", chain->startpt, m_curFileChains);
+               exit(1);                                                                                
+               return;
+       }
+       */
+       if (m_pFile == NULL)
+       {
+               m_pFile = fopen("temp.rt", "wb");
+               if (m_pFile == NULL)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+       }
+       if (fwrite((void*)chain, 16, 1, m_pFile) != 1)
+       {
+               perror("temp.rt");
+               exit(1);
+       }
+       if (fwrite((void*)&chain->checkpoint, 2, 1, m_pFile) != 1)
+       {
+               perror("temp.rt");
+               exit(1);
+       }
+
+       m_curFileChains++;
+       if (m_curFileChains >= m_chainsPerFile)
+       {
+               fclose(m_pFile);
+               m_pFile = NULL;
+               sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
+               if (rename("temp.rt", m_fileTemp) != 0)
+               {
+                       perror(m_fileTemp);
+                       exit(1);
+               }
+               m_curFile++;
+               m_curFileChains = 0;
+       }
+}
+
diff --git a/Server Applications/rtperfectp/RTWrite.h b/Server Applications/rtperfectp/RTWrite.h
new file mode 100644 (file)
index 0000000..d16a31e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter v0.0.
+
+       RT Perfecter v0.0 is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter v0.0 is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter v0.0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RTWRITE_H
+#define RTWRITE_H
+
+#include "RTCommon.h"
+
+class RTWrite
+{
+public:
+        RTWrite(char *fileName, int maxChainsPerFile);
+       ~RTWrite();
+
+       void writeChain(RTChainCP *c);
+
+private:
+       uint64 m_prevEndpt;
+       unsigned int m_curFile, m_curFileChains, m_chainsPerFile;
+       char *m_file, *m_fileTemp;
+       FILE *m_pFile;
+       int m_verbose;
+};
+
+#endif
+
diff --git a/Server Applications/rtperfectp/Release/BuildLog.htm b/Server Applications/rtperfectp/Release/BuildLog.htm
new file mode 100644 (file)
index 0000000..ccb49da
Binary files /dev/null and b/Server Applications/rtperfectp/Release/BuildLog.htm differ
diff --git a/Server Applications/rtperfectp/Release/RTRead.obj b/Server Applications/rtperfectp/Release/RTRead.obj
new file mode 100644 (file)
index 0000000..9addaae
Binary files /dev/null and b/Server Applications/rtperfectp/Release/RTRead.obj differ
diff --git a/Server Applications/rtperfectp/Release/RTWrite.obj b/Server Applications/rtperfectp/Release/RTWrite.obj
new file mode 100644 (file)
index 0000000..31532ac
Binary files /dev/null and b/Server Applications/rtperfectp/Release/RTWrite.obj differ
diff --git a/Server Applications/rtperfectp/Release/main.obj b/Server Applications/rtperfectp/Release/main.obj
new file mode 100644 (file)
index 0000000..71ef23a
Binary files /dev/null and b/Server Applications/rtperfectp/Release/main.obj differ
diff --git a/Server Applications/rtperfectp/Release/mt.dep b/Server Applications/rtperfectp/Release/mt.dep
new file mode 100644 (file)
index 0000000..ab06d59
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 17:36:59,26 on 17-11-2008 
diff --git a/Server Applications/rtperfectp/Release/rtperfectp.exe.intermediate.manifest b/Server Applications/rtperfectp/Release/rtperfectp.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..7256947
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/Server Applications/rtperfectp/Release/vc90.idb b/Server Applications/rtperfectp/Release/vc90.idb
new file mode 100644 (file)
index 0000000..c7c43b0
Binary files /dev/null and b/Server Applications/rtperfectp/Release/vc90.idb differ
diff --git a/Server Applications/rtperfectp/Release/vc90.pdb b/Server Applications/rtperfectp/Release/vc90.pdb
new file mode 100644 (file)
index 0000000..f1d2b32
Binary files /dev/null and b/Server Applications/rtperfectp/Release/vc90.pdb differ
diff --git a/Server Applications/rtperfectp/dirent.h b/Server Applications/rtperfectp/dirent.h
new file mode 100644 (file)
index 0000000..a43fd7f
--- /dev/null
@@ -0,0 +1,679 @@
+/*
+ * uce-dirent.h - operating system independent dirent implementation
+ * 
+ * Copyright (C) 1998-2002  Toni Ronkko
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * ``Software''), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * 
+ * May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
+ *
+ * $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
+ *
+ * $Log: uce-dirent.h,v $
+ * Revision 1.7  2002/05/13 10:48:35  tr
+ * embedded some source code directly to the header so that no source
+ * modules need to be included in the MS Visual C project using the
+ * interface, removed all the dependencies to other headers of the `uce'
+ * library so that the header can be made public
+ *
+ * Revision 1.6  2002/04/12 16:22:04  tr
+ * Unified Compiling Environment (UCE) replaced `std' library
+ *
+ * Revision 1.5  2001/07/20 16:33:40  tr
+ * moved to `std' library and re-named defines accordingly
+ *
+ * Revision 1.4  2001/07/10 16:47:18  tronkko
+ * revised comments
+ *
+ * Revision 1.3  2001/01/11 13:16:43  tr
+ * using ``uce-machine.h'' for finding out defines such as `FREEBSD'
+ *
+ * Revision 1.2  2000/10/08 16:00:41  tr
+ * copy of FreeBSD man page
+ *
+ * Revision 1.1  2000/07/10 05:53:16  tr
+ * Initial revision
+ *
+ * Revision 1.2  1998/07/19 18:29:14  tr
+ * Added error reporting capabilities and some asserts.
+ *
+ * Revision 1.1  1998/07/04 16:27:51  tr
+ * Initial revision
+ *
+ * 
+ * MSVC 1.0 scans automatic dependencies incorrectly when your project
+ * contains this very header.  The problem is that MSVC cannot handle
+ * include directives inside #if..#endif block those are never entered.
+ * Since this header ought to compile in many different operating systems,
+ * there had to be several conditional blocks that are compiled only in
+ * operating systems for what they were designed for.  MSVC 1.0 cannot
+ * handle inclusion of sys/dir.h in a part that is compiled only in Apollo
+ * operating system.  To fix the problem you need to insert DIR.H into
+ * SYSINCL.DAT located in MSVC\BIN directory and restart visual C++.
+ * Consult manuals for more informaton about the problem.
+ *
+ * Since many UNIX systems have dirent.h we assume to have one also.
+ * However, if your UNIX system does not have dirent.h you can download one
+ * for example at: http://ftp.uni-mannheim.de/ftp/GNU/dirent/dirent.tar.gz.
+ * You can also see if you have one of dirent.h, direct.h, dir.h, ndir.h,
+ * sys/dir.h and sys/ndir.h somewhere.  Try defining HAVE_DIRENT_H,
+ * HAVE_DIRECT_H, HAVE_DIR_H, HAVE_NDIR_H, HAVE_SYS_DIR_H and
+ * HAVE_SYS_NDIR_H according to the files found.
+ */
+#ifndef DIRENT_H
+#define DIRENT_H
+#define DIRENT_H_INCLUDED
+
+/* find out platform */
+#if defined(MSDOS)                             /* MS-DOS */
+#elif defined(__MSDOS__)                       /* Turbo C/Borland */
+# define MSDOS
+#elif defined(__DOS__)                         /* Watcom */
+# define MSDOS
+#endif
+
+#if defined(WIN32)                             /* MS-Windows */
+#elif defined(__NT__)                          /* Watcom */
+# define WIN32
+#elif defined(_WIN32)                          /* Microsoft */
+# define WIN32
+#elif defined(__WIN32__)                       /* Borland */
+# define WIN32
+#endif
+
+/*
+ * See what kind of dirent interface we have unless autoconf has already
+ * determinated that.
+ */
+#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
+# if defined(_MSC_VER)                         /* Microsoft C/C++ */
+    /* no dirent.h */
+# elif defined(__BORLANDC__)                   /* Borland C/C++ */
+#   define HAVE_DIRENT_H
+#   define VOID_CLOSEDIR
+# elif defined(__TURBOC__)                     /* Borland Turbo C */
+    /* no dirent.h */
+# elif defined(__WATCOMC__)                    /* Watcom C/C++ */
+#   define HAVE_DIRECT_H
+# elif defined(__apollo)                       /* Apollo */
+#   define HAVE_SYS_DIR_H
+# elif defined(__hpux)                         /* HP-UX */
+#   define HAVE_DIRENT_H
+# elif defined(__alpha) || defined(__alpha__)  /* Alpha OSF1 */
+#   error "not implemented"
+# elif defined(__sgi)                          /* Silicon Graphics */
+#   define HAVE_DIRENT_H
+# elif defined(sun) || defined(_sun)           /* Sun Solaris */
+#   define HAVE_DIRENT_H
+# elif defined(__FreeBSD__)                    /* FreeBSD */
+#   define HAVE_DIRENT_H
+# elif defined(__linux__)                      /* Linux */
+#   define HAVE_DIRENT_H
+# elif defined(__GNUC__)                       /* GNU C/C++ */
+#   define HAVE_DIRENT_H
+# else
+#   error "not implemented"
+# endif
+#endif
+
+/* include proper interface headers */
+#if defined(HAVE_DIRENT_H)
+# include <dirent.h>
+# ifdef FREEBSD
+#   define NAMLEN(dp) ((int)((dp)->d_namlen))
+# else
+#   define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
+# endif
+
+#elif defined(HAVE_NDIR_H)
+# include <ndir.h>
+# define NAMLEN(dp) ((int)((dp)->d_namlen))
+
+#elif defined(HAVE_SYS_NDIR_H)
+# include <sys/ndir.h>
+# define NAMLEN(dp) ((int)((dp)->d_namlen))
+
+#elif defined(HAVE_DIRECT_H)
+# include <direct.h>
+# define NAMLEN(dp) ((int)((dp)->d_namlen))
+
+#elif defined(HAVE_DIR_H)
+# include <dir.h>
+# define NAMLEN(dp) ((int)((dp)->d_namlen))
+
+#elif defined(HAVE_SYS_DIR_H)
+# include <sys/types.h>
+# include <sys/dir.h>
+# ifndef dirent
+#   define dirent direct
+# endif
+# define NAMLEN(dp) ((int)((dp)->d_namlen))
+
+#elif defined(MSDOS) || defined(WIN32)
+
+  /* figure out type of underlaying directory interface to be used */
+# if defined(WIN32)
+#   define DIRENT_WIN32_INTERFACE
+# elif defined(MSDOS)
+#   define DIRENT_MSDOS_INTERFACE
+# else
+#   error "missing native dirent interface"
+# endif
+
+  /*** WIN32 specifics ***/
+# if defined(DIRENT_WIN32_INTERFACE)
+#   include <windows.h>
+#   if !defined(DIRENT_MAXNAMLEN)
+#     define DIRENT_MAXNAMLEN (MAX_PATH)
+#   endif
+
+
+  /*** MS-DOS specifics ***/
+# elif defined(DIRENT_MSDOS_INTERFACE)
+#   include <dos.h>
+
+    /* Borland defines file length macros in dir.h */
+#   if defined(__BORLANDC__)
+#     include <dir.h>
+#     if !defined(DIRENT_MAXNAMLEN)
+#       define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
+#     endif
+#     if !defined(_find_t)
+#       define _find_t find_t
+#     endif
+
+    /* Turbo C defines ffblk structure in dir.h */
+#   elif defined(__TURBOC__)
+#     include <dir.h>
+#     if !defined(DIRENT_MAXNAMLEN)
+#       define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT))
+#     endif
+#     define DIRENT_USE_FFBLK
+
+    /* MSVC */
+#   elif defined(_MSC_VER)
+#     if !defined(DIRENT_MAXNAMLEN)
+#       define DIRENT_MAXNAMLEN (12)
+#     endif
+
+    /* Watcom */
+#   elif defined(__WATCOMC__)
+#     if !defined(DIRENT_MAXNAMLEN)
+#       if defined(__OS2__) || defined(__NT__)
+#         define DIRENT_MAXNAMLEN (255)
+#       else
+#         define DIRENT_MAXNAMLEN (12)
+#       endif
+#     endif
+
+#   endif
+# endif
+
+  /*** generic MS-DOS and MS-Windows stuff ***/
+# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
+#   define NAME_MAX DIRENT_MAXNAMLEN
+# endif
+# if NAME_MAX < DIRENT_MAXNAMLEN
+#   error "assertion failed: NAME_MAX >= DIRENT_MAXNAMLEN"
+# endif
+
+
+  /*
+   * Substitute for real dirent structure.  Note that `d_name' field is a
+   * true character array although we have it copied in the implementation
+   * dependent data.  We could save some memory if we had declared `d_name'
+   * as a pointer refering the name within implementation dependent data.
+   * We have not done that since some code may rely on sizeof(d_name) to be
+   * something other than four.  Besides, directory entries are typically so
+   * small that it takes virtually no time to copy them from place to place.
+   */
+  typedef struct dirent {
+    char d_name[NAME_MAX + 1];
+
+    /*** Operating system specific part ***/
+# if defined(DIRENT_WIN32_INTERFACE)       /*WIN32*/
+    WIN32_FIND_DATA data;
+# elif defined(DIRENT_MSDOS_INTERFACE)     /*MSDOS*/
+#   if defined(DIRENT_USE_FFBLK)
+    struct ffblk data;
+#   else
+    struct _find_t data;
+#   endif
+# endif
+  } dirent;
+
+  /* DIR substitute structure containing directory name.  The name is
+   * essential for the operation of ``rewinndir'' function. */
+  typedef struct DIR {
+    char          *dirname;                    /* directory being scanned */
+    dirent        current;                     /* current entry */
+    int           dirent_filled;               /* is current un-processed? */
+
+  /*** Operating system specific part ***/
+#  if defined(DIRENT_WIN32_INTERFACE)
+    HANDLE        search_handle;
+#  elif defined(DIRENT_MSDOS_INTERFACE)
+#  endif
+  } DIR;
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* supply prototypes for dirent functions */
+static DIR *opendir (const char *dirname);
+static struct dirent *readdir (DIR *dirp);
+static int closedir (DIR *dirp);
+static void rewinddir (DIR *dirp);
+
+/*
+ * Implement dirent interface as static functions so that the user does not
+ * need to change his project in any way to use dirent function.  With this
+ * it is sufficient to include this very header from source modules using
+ * dirent functions and the functions will be pulled in automatically.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+/* use ffblk instead of _find_t if requested */
+#if defined(DIRENT_USE_FFBLK)
+# define _A_ARCH   (FA_ARCH)
+# define _A_HIDDEN (FA_HIDDEN)
+# define _A_NORMAL (0)
+# define _A_RDONLY (FA_RDONLY)
+# define _A_SUBDIR (FA_DIREC)
+# define _A_SYSTEM (FA_SYSTEM)
+# define _A_VOLID  (FA_LABEL)
+# define _dos_findnext(dest) findnext(dest)
+# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags)
+#endif
+
+static int _initdir (DIR *p);
+static const char *_getdirname (const struct dirent *dp);
+static void _setdirname (struct DIR *dirp);
+
+/*
+ * <function name="opendir">
+ * <intro>open directory stream for reading
+ * <syntax>DIR *opendir (const char *dirname);
+ *
+ * <desc>Open named directory stream for read and return pointer to the
+ * internal working area that is used for retrieving individual directory
+ * entries.  The internal working area has no fields of your interest.
+ *
+ * <ret>Returns a pointer to the internal working area or NULL in case the 
+ * directory stream could not be opened.  Global `errno' variable will set
+ * in case of error as follows:
+ *
+ * <table>
+ * [EACESS  |Permission denied.
+ * [EMFILE  |Too many open files used by the process.
+ * [ENFILE  |Too many open files in system.
+ * [ENOENT  |Directory does not exist.
+ * [ENOMEM  |Insufficient memory.
+ * [ENOTDIR |dirname does not refer to directory.  This value is not
+ *           reliable on MS-DOS and MS-Windows platforms.  Many
+ *           implementations return ENOENT even when the name refers to a
+ *           file.]
+ * </table>
+ * </function>
+ */
+static DIR *
+opendir(
+    const char *dirname)
+{
+  DIR *dirp;
+  assert (dirname != NULL);
+  
+  dirp = (DIR*)malloc (sizeof (struct DIR));
+  if (dirp != NULL) {
+    char *p;
+    
+    /* allocate room for directory name */
+    dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
+    if (dirp->dirname == NULL) {
+      /* failed to duplicate directory name.  errno set by malloc() */
+      free (dirp);
+      return NULL;
+    }
+    /* Copy directory name while appending directory separator and "*.*".
+     * Directory separator is not appended if the name already ends with
+     * drive or directory separator.  Directory separator is assumed to be
+     * '/' or '\' and drive separator is assumed to be ':'. */
+    strcpy (dirp->dirname, dirname);
+    p = strchr (dirp->dirname, '\0');
+    if (dirp->dirname < p  &&
+        *(p - 1) != '\\'  &&  *(p - 1) != '/'  &&  *(p - 1) != ':')
+    {
+      strcpy (p++, "\\");
+    }
+# ifdef DIRENT_WIN32_INTERFACE
+    strcpy (p, "*"); /*scan files with and without extension in win32*/
+# else
+    strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
+# endif
+
+    /* open stream */
+    if (_initdir (dirp) == 0) {
+      /* initialization failed */
+      free (dirp->dirname);
+      free (dirp);
+      return NULL;
+    }
+  }
+  return dirp;
+}
+
+
+/*
+ * <function name="readdir">
+ * <intro>read a directory entry
+ * <syntax>struct dirent *readdir (DIR *dirp);
+ *
+ * <desc>Read individual directory entry and return pointer to a structure
+ * containing the name of the entry.  Individual directory entries returned
+ * include normal files, sub-directories, pseudo-directories "." and ".."
+ * and also volume labels, hidden files and system files in MS-DOS and
+ * MS-Windows.   You might want to use stat(2) function to determinate which
+ * one are you dealing with.  Many dirent implementations already contain
+ * equivalent information in dirent structure but you cannot depend on
+ * this.
+ *
+ * The dirent structure contains several system dependent fields that
+ * generally have no interest to you.  The only interesting one is char
+ * d_name[] that is also portable across different systems.  The d_name
+ * field contains the name of the directory entry without leading path.
+ * While d_name is portable across different systems the actual storage
+ * capacity of d_name varies from system to system and there is no portable
+ * way to find out it at compile time as different systems define the
+ * capacity of d_name with different macros and some systems do not define
+ * capacity at all (besides actual declaration of the field). If you really
+ * need to find out storage capacity of d_name then you might want to try
+ * NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
+ * there are many MS-DOS and MS-Windows implementations those do not define
+ * it.  There are also systems that declare d_name as "char d_name[1]" and
+ * then allocate suitable amount of memory at run-time.  Thanks to Alain
+ * Decamps (Alain.Decamps@advalvas.be) for pointing it out to me.
+ *
+ * This all leads to the fact that it is difficult to allocate space
+ * for the directory names when the very same program is being compiled on
+ * number of operating systems.  Therefore I suggest that you always
+ * allocate space for directory names dynamically.
+ *
+ * <ret>
+ * Returns a pointer to a structure containing name of the directory entry
+ * in `d_name' field or NULL if there was an error.  In case of an error the
+ * global `errno' variable will set as follows:
+ *
+ * <table>
+ * [EBADF  |dir parameter refers to an invalid directory stream.  This value
+ *          is not set reliably on all implementations.]
+ * </table>
+ * </function>
+ */
+static struct dirent *
+readdir (DIR *dirp)
+{
+  assert (dirp != NULL);
+  if (dirp == NULL) {
+    errno = EBADF;
+    return NULL;
+  }
+
+#if defined(DIRENT_WIN32_INTERFACE)
+  if (dirp->search_handle == INVALID_HANDLE_VALUE) {
+    /* directory stream was opened/rewound incorrectly or it ended normally */
+    errno = EBADF;
+    return NULL;
+  }
+#endif
+
+  if (dirp->dirent_filled != 0) {
+    /*
+     * Directory entry has already been retrieved and there is no need to
+     * retrieve a new one.  Directory entry will be retrieved in advance
+     * when the user calls readdir function for the first time.  This is so
+     * because real dirent has separate functions for opening and reading
+     * the stream whereas Win32 and DOS dirents open the stream
+     * automatically when we retrieve the first file.  Therefore, we have to
+     * save the first file when opening the stream and later we have to
+     * return the saved entry when the user tries to read the first entry.
+     */
+    dirp->dirent_filled = 0;
+  } else {
+    /* fill in entry and return that */
+#if defined(DIRENT_WIN32_INTERFACE)
+    if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
+      /* Last file has been processed or an error occured */
+      FindClose (dirp->search_handle);
+      dirp->search_handle = INVALID_HANDLE_VALUE;
+      errno = ENOENT;
+      return NULL;
+    }
+
+# elif defined(DIRENT_MSDOS_INTERFACE)
+    if (_dos_findnext (&dirp->current.data) != 0) {
+      /* _dos_findnext and findnext will set errno to ENOENT when no
+       * more entries could be retrieved. */
+      return NULL;
+    }
+# endif
+
+    _setdirname (dirp);
+    assert (dirp->dirent_filled == 0);
+  }
+  return &dirp->current;
+}
+
+
+/*
+ * <function name="closedir">
+ * <intro>close directory stream.
+ * <syntax>int closedir (DIR *dirp);
+ *
+ * <desc>Close directory stream opened by the `opendir' function.  Close of
+ * directory stream invalidates the DIR structure as well as previously read
+ * dirent entry.
+ *
+ * <ret>The function typically returns 0 on success and -1 on failure but
+ * the function may be declared to return void on same systems.  At least
+ * Borland C/C++ and some UNIX implementations use void as a return type.
+ * The dirent wrapper tries to define VOID_CLOSEDIR whenever closedir is
+ * known to return nothing.  The very same definition is made by the GNU
+ * autoconf if you happen to use it.
+ *
+ * The global `errno' variable will set to EBADF in case of error.
+ * </function>
+ */
+static int
+closedir (DIR *dirp)
+{   
+  int retcode = 0;
+
+  /* make sure that dirp points to legal structure */
+  assert (dirp != NULL);
+  if (dirp == NULL) {
+    errno = EBADF;
+    return -1;
+  }
+  /* free directory name and search handles */
+  if (dirp->dirname != NULL) free (dirp->dirname);
+
+#if defined(DIRENT_WIN32_INTERFACE)
+  if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+    if (FindClose (dirp->search_handle) == FALSE) {
+      /* Unknown error */
+      retcode = -1;
+      errno = EBADF;
+    }
+  }
+#endif                     
+
+  /* clear dirp structure to make sure that it cannot be used anymore*/
+  memset (dirp, 0, sizeof (*dirp));
+# if defined(DIRENT_WIN32_INTERFACE)
+  dirp->search_handle = INVALID_HANDLE_VALUE;
+# endif
+
+  free (dirp);
+  return retcode;
+}
+
+
+/*
+ * <function name="rewinddir">
+ * <intro>rewind directory stream to the beginning
+ * <syntax>void rewinddir (DIR *dirp);
+ *
+ * <desc>Rewind directory stream to the beginning so that the next call of
+ * readdir() returns the very first directory entry again.  However, note
+ * that next call of readdir() may not return the same directory entry as it
+ * did in first time.  The directory stream may have been affected by newly
+ * created files.
+ *
+ * Almost every dirent implementation ensure that rewinddir will update
+ * the directory stream to reflect any changes made to the directory entries
+ * since the previous ``opendir'' or ``rewinddir'' call.  Keep an eye on
+ * this if your program depends on the feature.  I know at least one dirent
+ * implementation where you are required to close and re-open the stream to
+ * see the changes.
+ *
+ * <ret>Returns nothing.  If something went wrong while rewinding, you will
+ * notice it later when you try to retrieve the first directory entry.
+ */
+static void
+rewinddir (DIR *dirp)
+{   
+  /* make sure that dirp is legal */
+  assert (dirp != NULL);
+  if (dirp == NULL) {
+    errno = EBADF;
+    return;
+  }
+  assert (dirp->dirname != NULL);
+  
+  /* close previous stream */
+#if defined(DIRENT_WIN32_INTERFACE)
+  if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+    if (FindClose (dirp->search_handle) == FALSE) {
+      /* Unknown error */
+      errno = EBADF;
+    }
+  }
+#endif
+
+  /* re-open previous stream */
+  if (_initdir (dirp) == 0) {
+    /* initialization failed but we cannot deal with error.  User will notice
+     * error later when she tries to retrieve first directory enty. */
+    /*EMPTY*/;
+  }
+}
+
+
+/*
+ * Open native directory stream object and retrieve first file.
+ * Be sure to close previous stream before opening new one.
+ */
+static int
+_initdir (DIR *dirp)
+{ 
+  assert (dirp != NULL);
+  assert (dirp->dirname != NULL);
+  dirp->dirent_filled = 0;
+
+# if defined(DIRENT_WIN32_INTERFACE)
+  /* Open stream and retrieve first file */
+  dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
+  if (dirp->search_handle == INVALID_HANDLE_VALUE) {
+    /* something went wrong but we don't know what.  GetLastError() could
+     * give us more information about the error, but then we should map
+     * the error code into errno. */
+    errno = ENOENT;
+    return 0;
+  }
+
+# elif defined(DIRENT_MSDOS_INTERFACE)
+  if (_dos_findfirst (dirp->dirname,
+          _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
+          &dirp->current.data) != 0)
+  {
+    /* _dos_findfirst and findfirst will set errno to ENOENT when no 
+     * more entries could be retrieved. */
+    return 0;
+  }
+# endif
+
+  /* initialize DIR and it's first entry */
+  _setdirname (dirp);
+  dirp->dirent_filled = 1;
+  return 1;
+}
+
+
+/*
+ * Return implementation dependent name of the current directory entry.
+ */
+static const char *
+_getdirname (const struct dirent *dp)
+{
+#if defined(DIRENT_WIN32_INTERFACE)
+  return dp->data.cFileName;
+  
+#elif defined(DIRENT_USE_FFBLK)
+  return dp->data.ff_name;
+  
+#else
+  return dp->data.name;
+#endif  
+}
+
+
+/*
+ * Copy name of implementation dependent directory entry to the d_name field.
+ */
+static void
+_setdirname (struct DIR *dirp) {
+  /* make sure that d_name is long enough */
+  assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
+  
+  strncpy (dirp->current.d_name,
+      _getdirname (&dirp->current),
+      NAME_MAX);
+  dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
+}
+  
+# ifdef __cplusplus
+}
+# endif
+# define NAMLEN(dp) ((int)(strlen((dp)->d_name)))
+
+#else
+# error "missing dirent interface"
+#endif
+
+
+#endif /*DIRENT_H*/
+
diff --git a/Server Applications/rtperfectp/main.cpp b/Server Applications/rtperfectp/main.cpp
new file mode 100644 (file)
index 0000000..34c6e1e
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+       Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
+
+       This file is part of RT Perfecter.
+
+       RT Perfecter is free software: you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 3 of the License, or
+       (at your option) any later version.
+
+       RT Perfecter is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with RT Perfecter.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// Current version "RT Perfecter v0.1"
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctime>
+#include "RTWrite.h"
+#include "RTRead.h"
+
+#ifdef _WIN32
+       #include <conio.h>
+       #define DIRECTORY_SEPERATOR '\\'
+#else
+       #include <fcntl.h>
+       #define DIRECTORY_SEPERATOR '/'
+#endif
+
+#define DISPLAY_STATUS_MIN_LOOPS 2000000
+
+struct RTChain2
+{
+       uint64 startpt;
+       unsigned int endpt32_1;
+       unsigned int endpt32_2;
+       unsigned short checkpoint;
+};
+
+union RTChainU
+{
+       RTChainCP c;
+       RTChain2 c2;
+       unsigned short checkpoint;
+};
+
+void usage(char *runStr);
+
+int main(int argc, char **argv)
+{
+#ifdef _WIN32
+       uint64 maxIndex = 0xffffffffffffffff;
+#else
+       uint64 maxIndex = 0xffffffffffffffffll;
+#endif
+       int argi = 1, i, argsUsed = 0;
+       unsigned int maxChainsPerFile = 67108864;
+       
+       // Get arguments
+       if (argc > 3 && argc < 6)
+       {
+               for (; argi < argc - 2; argi++)
+               {
+                       if (strcmp(argv[argi], "-v") == 0 && (argsUsed & 1) == 0)
+                       {
+                               // Enable verbose mode
+                               argsUsed |= 1;
+                       }
+                       else if (strncmp(argv[argi], "-s=", 3) == 0 && (argsUsed & 2) == 0)
+                       {
+                               // Max file size in MiB
+                               argsUsed |= 2;
+                               maxChainsPerFile = 0;
+                               for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       maxChainsPerFile *= 10;
+                                       maxChainsPerFile += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               if (i > 8 || maxChainsPerFile > 65535) // i - 3 > 5
+                               {
+                                       printf("Error: Number is to large.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               maxChainsPerFile <<= 16; // maxChainsPerFile *= 1024 * 1024 / 16
+                       }
+                       else if (strncmp(argv[argi], "-i=", 3) == 0 && (argsUsed & 4) == 0)
+                       {
+                               // Maximum index for chains
+                               argsUsed |= 4;
+                               maxIndex = 0;
+                               for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
+                               {
+                                       maxIndex *= 10;
+                                       maxIndex += ((int) argv[argi][i]) - 0x30;
+                               }
+                               if (argv[argi][i] != '\0')
+                               {
+                                       printf("Error: Invalid number.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                               if (i > 23) // i - 3 > 20
+                               {
+                                       printf("Error: Number is to large.\n\n");
+                                       usage(argv[0]);
+                                       return 1;
+                               }
+                       }
+                       else
+                       {
+                               printf("Error: Unknown argument.\n\n");
+                               usage(argv[0]);
+                               return 1;
+                       }
+               }
+       }
+       else if (argc != 3)
+       {
+               if (argc == 1 || argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
+               {
+                       usage(argv[0]);
+                       return 0;
+               }
+               printf("Error: Wrong number of arguments.\n\n");
+               usage(argv[0]);
+               return 1;
+       }
+
+       // Init
+       RTChainU chain, prevChain;
+       uint64 uniqueChains = 0;
+       RTRead inRt(argv[argi], maxIndex, argsUsed & 1);
+       RTWrite outRt(argv[argi + 1], maxChainsPerFile);
+
+       prevChain.c2.endpt32_1 = 0xffffffff;
+       prevChain.c2.endpt32_2 = 0xffffffff;
+#ifndef _WIN32
+       // Set stdin to non-blocking
+       fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NDELAY);
+#endif
+       clock_t t = clock();
+       int loops = 0;
+       for (int ret = inRt.readChain(&(chain.c)); ret == 0; ret = inRt.readChain(&(chain.c)))
+       {
+               // Show status
+               loops++;
+               if (loops >= DISPLAY_STATUS_MIN_LOOPS)
+               {
+#ifdef _WIN32
+                       // Pressing any key will show the status
+                       if (kbhit())
+                       {
+                               inRt.printStatus();
+                       }
+#else
+                       // Pressing enter will show the status
+                       int ch;
+                       do
+                       {
+                               ch = getchar();
+                       } while (ch != (int)'\n' && ch != EOF);
+                       if (ch == (int)'\n')
+                       {
+                               inRt.printStatus();
+                       }
+#endif
+                       loops = 0;
+               }
+
+               // Check the least significate 32 bits first
+               if (chain.c2.endpt32_1 != prevChain.c2.endpt32_1 || chain.c2.endpt32_2 != prevChain.c2.endpt32_2)
+               {
+                       outRt.writeChain(&(chain.c));
+                       uniqueChains++;
+               }
+               prevChain = chain;
+       }
+#ifdef _WIN32
+       printf("Unique Chains: %I64u\nTotal time:    %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
+#else
+       printf("Unique Chains: %llu\nTotal time:    %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
+#endif
+       return 0;
+}
+
+void usage(char *runStr)
+{
+       printf("\n                          **** RT Perfecter v0.1 ****\n\n");
+       printf("Converts sorted rt files in a directory to a perfect rainbow table. All rt files\n");
+       printf("in the directory must all be from the same rainbow table.\n\n");
+       printf("%s [Options] input-directory output-file-pattern\n\n", runStr);
+       printf("Options:\n");
+       printf("  -i=number\n");
+       printf("    Maximum index for chains.\n\n");
+       printf("  -s=number\n");
+       printf("    Maximum size for output files in MiB [default is 1024, max is 65535].\n\n");
+       printf("  -v\n");
+       printf("    Verbose mode, displays extra info.\n\n");
+       printf("output-file-pattern:\n");
+       printf("  This will be passed into sprintf() with the number of chains in the file and\n");
+       printf("  the current file number starting at 0. This could look like:\n");
+       printf("  'some-folder%csome-name%%u-%%03u.rt'\n", DIRECTORY_SEPERATOR);
+       printf("  Where '%%u' would be the number of chains in the file and '%%03u' would be the\n");
+       printf("  file number formated like 000, 001, 002, and so on.\n\n");
+       printf("Run-time:\n");
+       printf("  Press [Enter] to display a status message.\n\n");
+       printf("Copyright (c) 2008 Steve Thomas <SMT837784@yahoo.com>\n");
+       printf("  This is free software: you can redistribute it and/or modify it under the\n");
+       printf("  terms of the GNU General Public License as published by the Free Software\n");
+       printf("  Foundation, either version 3 of the License, or (at your option) any later\n");
+       printf("  version. There is NO WARRANTY, to the extent permitted by law.\n");
+}
+
diff --git a/Server Applications/rtperfectp/rtperfectp.vcproj b/Server Applications/rtperfectp/rtperfectp.vcproj
new file mode 100644 (file)
index 0000000..82f8425
--- /dev/null
@@ -0,0 +1,213 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="rtperfectp"
+       ProjectGUID="{9725038C-A07B-40DD-87CD-3A119021A244}"
+       RootNamespace="rtperfectp"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="196613"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="2"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="2"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="0"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               EnableIntrinsicFunctions="true"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="2"
+                               EnableFunctionLevelLinking="true"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath=".\main.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\RTRead.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\RTWrite.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath=".\RTCommon.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\RTRead.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\RTWrite.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/Server Applications/rtperfectp/rtperfectp.vcproj.MWJ-PC.mwj.user b/Server Applications/rtperfectp/rtperfectp.vcproj.MWJ-PC.mwj.user
new file mode 100644 (file)
index 0000000..15b19f6
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="MWJ-PC"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Server Applications/rtperfectp/rtperfectp.vcproj.W-L-MWJ.Administrator.user b/Server Applications/rtperfectp/rtperfectp.vcproj.W-L-MWJ.Administrator.user
new file mode 100644 (file)
index 0000000..5aff747
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+       ProjectType="Visual C++"
+       Version="9,00"
+       ShowAllFiles="false"
+       >
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       >
+                       <DebugSettings
+                               Command="$(TargetPath)"
+                               WorkingDirectory=""
+                               CommandArguments=""
+                               Attach="false"
+                               DebuggerType="3"
+                               Remote="1"
+                               RemoteMachine="W-L-MWJ"
+                               RemoteCommand=""
+                               HttpUrl=""
+                               PDBPath=""
+                               SQLDebugging=""
+                               Environment=""
+                               EnvironmentMerge="true"
+                               DebuggerFlavor=""
+                               MPIRunCommand=""
+                               MPIRunArguments=""
+                               MPIRunWorkingDirectory=""
+                               ApplicationCommand=""
+                               ApplicationArguments=""
+                               ShimCommand=""
+                               MPIAcceptMode=""
+                               MPIAcceptFilter=""
+                       />
+               </Configuration>
+       </Configurations>
+</VisualStudioUserFile>
diff --git a/Server Applications/rtperfectp/whatitis.txt b/Server Applications/rtperfectp/whatitis.txt
new file mode 100644 (file)
index 0000000..274ec41
--- /dev/null
@@ -0,0 +1 @@
+A tool used to perfect the parts and assemble them in 1 table
\ No newline at end of file