# # add_file "botan/es_win32.cpp" # # add_file "botan/es_win32.h" # # patch "ChangeLog" # from [74cffba3d081392851de3bd76dbcb0e98746eb3b] # to [f653b018e04494889f9da4e4561edf445f71a1bf] # # patch "Makefile.am" # from [22561331132b97a7bd306abdf5196779bf2126db] # to [964cfb5a0488711ecd135b48fc8d28b560285d5a] # # patch "botan/es_win32.cpp" # from [] # to [e9b9c76342a863825e2a60c12de29627e4f7057d] # # patch "botan/es_win32.h" # from [] # to [1c730fe9b6a9a522c7b61e45c055b1f60cf2a8f9] # # patch "keys.cc" # from [879b4743893dd20d6bb2e26ad82605dcfb89b825] # to [c7d1fb792f418a999639b5675f6a7e4c57d748c8] # # patch "win32/inodeprint.cc" # from [40ec91986e7a59d0f427e293d08879887b06ce97] # to [b861168f4636365c587b88177629559acfad329e] # =============================================== --- ChangeLog 74cffba3d081392851de3bd76dbcb0e98746eb3b +++ ChangeLog f653b018e04494889f9da4e4561edf445f71a1bf @@ -1,3 +1,12 @@ +2005-08-03 Matthew Gregan + + * win32/inodeprint.cc: Botan changes. Also, hash individual + FileTime structure members rather than the entire structure. + * keys.cc: Add explicit 'using' for Botan::byte. + * botan/es_win32.{cpp,h}: Add missing files. + * Makefile.am: Enable entropy collection via CryptoAPI and Win32 + API. + 2005-08-02 Matt Johnston * botan/gzip.cpp: forgot to commit some semicolons =============================================== --- Makefile.am 22561331132b97a7bd306abdf5196779bf2126db +++ Makefile.am 964cfb5a0488711ecd135b48fc8d28b560285d5a @@ -225,8 +225,8 @@ libplatform_a_SOURCES += $(WIN32_PLATFORM_SOURCES) monotone_LDADD += -lws2_32 -lintl -liconv -liphlpapi unit_tests_LDADD += -lws2_32 -lintl -liconv -liphlpapi - lib3rdparty_a_CPPFLAGS += -DWIN32 - lib3rdparty_a_SOURCES += botan/es_capi.cpp + lib3rdparty_a_CPPFLAGS += -DWIN32 -DBOTAN_EXT_ENTROPY_SRC_CAPI -DBOTAN_EXT_ENTROPY_SRC_WIN32 + lib3rdparty_a_SOURCES += botan/es_capi.cpp botan/es_win32.cpp else libplatform_a_SOURCES += $(UNIX_PLATFORM_SOURCES) endif =============================================== --- botan/es_win32.cpp +++ botan/es_win32.cpp e9b9c76342a863825e2a60c12de29627e4f7057d @@ -0,0 +1,104 @@ +/************************************************* +* Win32 EntropySource Source File * +* (C) 1999-2005 The Botan Project * +*************************************************/ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* Win32 Fast Poll * +*************************************************/ +void Win32_EntropySource::do_fast_poll() + { + add_bytes(GetTickCount()); + add_bytes(GetMessagePos()); + add_bytes(GetMessageTime()); + add_bytes(GetInputState()); + add_bytes(GetCurrentProcessId()); + add_bytes(GetCurrentThreadId()); + + SYSTEM_INFO sys_info; + GetSystemInfo(&sys_info); + add_bytes(&sys_info, sizeof(sys_info)); + + MEMORYSTATUS mem_info; + GlobalMemoryStatus(&mem_info); + add_bytes(&mem_info, sizeof(mem_info)); + + POINT point; + GetCursorPos(&point); + add_bytes(&point, sizeof(point)); + GetCaretPos(&point); + add_bytes(&point, sizeof(point)); + } + +/************************************************* +* Win32 Slow Poll * +*************************************************/ +void Win32_EntropySource::do_slow_poll() + { + const u32bit MAX_ITEMS = 256; + const u32bit HEAP_LISTS_MAX = 32; + const u32bit HEAP_OBJS_PER_LIST = 128; + + do_fast_poll(); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); + +#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \ + { \ + u32bit items = 0; \ + DATA_TYPE info; \ + info.dwSize = sizeof(DATA_TYPE); \ + if(FUNC_FIRST(snapshot, &info)) \ + { \ + do \ + { \ + if(items++ > MAX_ITEMS) break; \ + add_bytes(&info, sizeof(info)); \ + } while(FUNC_NEXT(snapshot, &info)); \ + } \ + } + + TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next); + TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next); + TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next); + +#undef TOOLHELP32_ITER + + u32bit heap_lists_found = 0; + HEAPLIST32 heap_list; + heap_list.dwSize = sizeof(HEAPLIST32); + if(Heap32ListFirst(snapshot, &heap_list)) + { + do + { + add_bytes(&heap_list, sizeof(HEAPLIST32)); + + if(heap_lists_found++ > HEAP_LISTS_MAX) + break; + + u32bit heap_objs_found = 0; + HEAPENTRY32 heap_entry; + heap_entry.dwSize = sizeof(HEAPENTRY32); + if(Heap32First(&heap_entry, heap_list.th32ProcessID, + heap_list.th32HeapID)) + { + do + { + if(heap_objs_found++ > HEAP_OBJS_PER_LIST) + break; + add_bytes(&heap_entry, sizeof(HEAPENTRY32)); + } while(Heap32Next(&heap_entry)); + } + } while(Heap32ListNext(snapshot, &heap_list)); + } + + CloseHandle(snapshot); + } + +} =============================================== --- botan/es_win32.h +++ botan/es_win32.h 1c730fe9b6a9a522c7b61e45c055b1f60cf2a8f9 @@ -0,0 +1,25 @@ +/************************************************* +* Win32 EntropySource Header File * +* (C) 1999-2005 The Botan Project * +*************************************************/ + +#ifndef BOTAN_EXT_ENTROPY_SRC_WIN32_H__ +#define BOTAN_EXT_ENTROPY_SRC_WIN32_H__ + +#include + +namespace Botan { + +/************************************************* +* Win32 Entropy Source * +*************************************************/ +class Win32_EntropySource : public Buffered_EntropySource + { + private: + void do_fast_poll(); + void do_slow_poll(); + }; + +} + +#endif =============================================== --- keys.cc 879b4743893dd20d6bb2e26ad82605dcfb89b825 +++ keys.cc c7d1fb792f418a999639b5675f6a7e4c57d748c8 @@ -33,6 +33,7 @@ using boost::shared_ptr; using boost::shared_dynamic_cast; +using Botan::byte; static void do_arc4(SecureVector & phrase, =============================================== --- win32/inodeprint.cc 40ec91986e7a59d0f427e293d08879887b06ce97 +++ win32/inodeprint.cc b861168f4636365c587b88177629559acfad329e @@ -6,7 +6,8 @@ #include #include -#include "cryptopp/sha.h" +#include "botan/botan.h" +#include "botan/sha160.h" #include "platform.hh" #include "transforms.hh" @@ -15,12 +16,12 @@ namespace { template void - inline add_hash(CryptoPP::SHA & hash, T obj) + inline add_hash(Botan::SHA_160 & hash, T obj) { size_t size = sizeof(obj); - hash.Update(reinterpret_cast(&size), + hash.update(reinterpret_cast(&size), sizeof(size)); - hash.Update(reinterpret_cast(&obj), + hash.update(reinterpret_cast(&obj), sizeof(obj)); } }; @@ -31,7 +32,7 @@ if (_stati64(localized_as_string(file).c_str(), &st) < 0) return false; - CryptoPP::SHA hash; + Botan::SHA_160 hash; add_hash(hash, st.st_mode); add_hash(hash, st.st_dev); @@ -48,15 +49,17 @@ return false; } - add_hash(hash, create); - add_hash(hash, write); + add_hash(hash, create.dwLowDateTime); + add_hash(hash, create.dwHighDateTime); + add_hash(hash, write.dwLowDateTime); + add_hash(hash, write.dwHighDateTime); if (CloseHandle(filehandle) == 0) return false; - char digest[CryptoPP::SHA::DIGESTSIZE]; - hash.Final(reinterpret_cast(digest)); - std::string out(digest, CryptoPP::SHA::DIGESTSIZE); + char digest[hash.OUTPUT_LENGTH]; + hash.final(reinterpret_cast(digest)); + std::string out(digest, hash.OUTPUT_LENGTH); inodeprint ip_raw(out); encode_hexenc(ip_raw, ip); return true;