Added the Windows implementation of the "improved" random number generation.

This commit is contained in:
Moritz Bunkus 2005-05-02 14:55:09 +00:00
parent 432d6a3596
commit bb924c0038
3 changed files with 47 additions and 8 deletions

View File

@ -107,6 +107,7 @@ endif
ifeq (1,$(MINGW)) ifeq (1,$(MINGW))
MMG_RESOURCES = src/mmg/mmg-resources.rc MMG_RESOURCES = src/mmg/mmg-resources.rc
LIBRPCRT = -lrpcrt4
endif endif
DEP_COMMON = src/common/libmtxcommon.$(LIBMTXCOMMONEXT) DEP_COMMON = src/common/libmtxcommon.$(LIBMTXCOMMONEXT)
@ -319,7 +320,8 @@ libmtxcommon_OBJECTS := $(patsubst %.cpp,%.o,$(libmtxcommon_SOURCES))
src/common/libmtxcommon.dll: $(libmtxcommon_OBJECTS) src/common/libmtxcommon.dll: $(libmtxcommon_OBJECTS)
@echo ' LD/DLL ' $@ @echo ' LD/DLL ' $@
$(Q)$(LINKSHARED) -Wl,--out-implib=$@.a -o $@ $(libmtxcommon_OBJECTS) \ $(Q)$(LINKSHARED) -Wl,--out-implib=$@.a -o $@ $(libmtxcommon_OBJECTS) \
-liconv -lz $(COMPRESSION_LIBRARIES) -lmatroska -lebml -lexpat -liconv -lz $(COMPRESSION_LIBRARIES) -lmatroska -lebml \
-lexpat -lrpcrt4
src/common/libmtxcommon.a: $(libmtxcommon_OBJECTS) src/common/libmtxcommon.a: $(libmtxcommon_OBJECTS)
@rm -f $@ @rm -f $@
@ -369,7 +371,7 @@ mkvmerge_LDADD = -lmtxinput -lmtxoutput \
-lmtxcommon -lmatroska -lebml \ -lmtxcommon -lmatroska -lebml \
-lavi -lrmff -lmpegparser \ -lavi -lrmff -lmpegparser \
$(FLAC_LIBS) -lvorbis -logg -lz $(COMPRESSION_LIBRARIES) \ $(FLAC_LIBS) -lvorbis -logg -lz $(COMPRESSION_LIBRARIES) \
-lexpat $(ICONV_LIBS) $(LIBINTL_LIBS) -lexpat $(ICONV_LIBS) $(LIBINTL_LIBS) $(LIBRPCRT)
# #
# src/info # src/info
@ -380,7 +382,7 @@ mkvinfo_OBJECTS := $(patsubst %.cpp,%.o,$(mkvinfo_SOURCES))
mkvinfo_DEPENDENCIES += $(DEP_COMMON) mkvinfo_DEPENDENCIES += $(DEP_COMMON)
mkvinfo_LDADD = -lmtxcommon -lmatroska -lebml \ mkvinfo_LDADD = -lmtxcommon -lmatroska -lebml \
$(WXWINDOWS_LIBS) \ $(WXWINDOWS_LIBS) \
$(ICONV_LIBS) $(LIBINTL_LIBS) $(ICONV_LIBS) $(LIBINTL_LIBS) $(LIBRPCRT)
# #
# src/extract # src/extract
@ -391,7 +393,7 @@ mkvextract_OBJECTS := $(patsubst %.cpp,%.o,$(mkvextract_SOURCES))
mkvextract_DEPENDENCIES += $(DEP_COMMON) $(DEP_AVILIB) $(DEP_RMFF) mkvextract_DEPENDENCIES += $(DEP_COMMON) $(DEP_AVILIB) $(DEP_RMFF)
mkvextract_LDADD = -lmtxcommon -lvorbis -logg -lavi -lmatroska -lebml -lrmff \ mkvextract_LDADD = -lmtxcommon -lvorbis -logg -lavi -lmatroska -lebml -lrmff \
$(ICONV_LIBS) $(LIBINTL_LIBS) -lexpat \ $(ICONV_LIBS) $(LIBINTL_LIBS) -lexpat \
-lz $(COMPRESSION_LIBRARIES) -lz $(COMPRESSION_LIBRARIES) $(LIBRPCRT)
# #
# src # src
@ -400,7 +402,8 @@ mkvextract_LDADD = -lmtxcommon -lvorbis -logg -lavi -lmatroska -lebml -lrmff \
base64tool_SOURCES = src/base64tool.cpp base64tool_SOURCES = src/base64tool.cpp
base64tool_OBJECTS := $(patsubst %.cpp,%.o,$(base64tool_SOURCES)) base64tool_OBJECTS := $(patsubst %.cpp,%.o,$(base64tool_SOURCES))
base64tool_DEPENDENCIES += $(DEP_COMMON) base64tool_DEPENDENCIES += $(DEP_COMMON)
base64tool_LDADD = -lmtxcommon $(ICONV_LIBS) $(LIBINTL_LIBS) base64tool_LDADD = -lmtxcommon $(ICONV_LIBS) $(LIBINTL_LIBS) \
$(LIBRPCRT)
# #
# src/mmg # src/mmg
@ -411,7 +414,8 @@ mmg_OBJECTS := $(patsubst %.cpp,%.o,$(mmg_SOURCES)) \
$(patsubst %.rc,%.o,$(MMG_RESOURCES)) $(patsubst %.rc,%.o,$(MMG_RESOURCES))
mmg_DEPENDENCIES += $(DEP_COMMON) mmg_DEPENDENCIES += $(DEP_COMMON)
mmg_LDADD = -lmtxcommon -lmatroska -lebml -lexpat $(ICONV_LIBS) \ mmg_LDADD = -lmtxcommon -lmatroska -lebml -lexpat $(ICONV_LIBS) \
$(WXWINDOWS_LIBS) $(LIBINTL_LIBS) $(MINGW_GUIAPP) $(WXWINDOWS_LIBS) $(LIBINTL_LIBS) $(MINGW_GUIAPP) \
$(LIBRPCRT)
mkvmerge: src/mkvmerge@EXEEXT@ mkvmerge: src/mkvmerge@EXEEXT@

View File

@ -18,6 +18,8 @@
#if !defined(SYS_WINDOWS) #if !defined(SYS_WINDOWS)
# include <sys/time.h> # include <sys/time.h>
# include <time.h> # include <time.h>
#else
# include <windows.h>
#endif #endif
#include "mm_io.h" #include "mm_io.h"
@ -25,9 +27,41 @@
#if defined(SYS_WINDOWS) #if defined(SYS_WINDOWS)
bool random_c::m_seeded = false;
void
random_c::generate_bytes(void *destination,
int num_bytes) {
int i, num_left;
i = 0;
while (num_bytes > 0) {
UUID uuid;
RPC_STATUS status;
status = UuidCreate(&uuid);
if ((RPC_S_OK != status) && (RPC_S_UUID_LOCAL_ONLY != status)) {
if (!m_seeded) {
srand(GetTickCount());
m_seeded = true;
}
while (0 > num_bytes) {
((unsigned char *)destination)[i + num_bytes] =
(unsigned char)(256.0 * rand() / (RAND_MAX + 1.0));
--num_bytes;
}
}
num_left = num_bytes > 8 ? 8 : num_bytes;
memcpy((unsigned char *)destination + i, &uuid.Data4, num_left);
num_bytes -= num_left;
i += num_left;
}
}
#else // defined(SYS_WINDOWS) #else // defined(SYS_WINDOWS)
bool random_c::m_seeded = false;
auto_ptr<mm_file_io_c> random_c::m_dev_urandom; auto_ptr<mm_file_io_c> random_c::m_dev_urandom;
bool random_c::m_tried_dev_urandom = false; bool random_c::m_tried_dev_urandom = false;

View File

@ -23,8 +23,9 @@
class MTX_DLL_API random_c { class MTX_DLL_API random_c {
private: private:
#if !defined(SYS_WINDOWS)
static bool m_seeded; static bool m_seeded;
#if !defined(SYS_WINDOWS)
static auto_ptr<mm_file_io_c> m_dev_urandom; static auto_ptr<mm_file_io_c> m_dev_urandom;
static bool m_tried_dev_urandom; static bool m_tried_dev_urandom;
#endif #endif