usnistgov / SP800-90B_EntropyAssessment

The SP800-90B_EntropyAssessment C++package implements the min-entropy assessment methods included in Special Publication 800-90B.
195 stars 88 forks source link

Compiling in Windows #219

Open rafagenova opened 1 year ago

rafagenova commented 1 year ago

Hello everybody,

Please, I have being trying to run the entropy assessment tools in a Windows computer and I think I am having problems with the libdivsufsort library.

I got the same results on Ubuntu VMWare and Windows with the exception of the IID tests.

When running the IID test with the provided truerand_8bit.bin dataset in Windows, there is one test that gives me different results than in Ubuntu.

The results that are unexpected are:

Literal Longest Repeated Substring results: Pr(X >= 1) = -0.08935833987813369874015 Length of longest repeated substring test: Failed

This probability value should not be negative. The LRS tests passed on Ubuntu with this dataset.

Please I would like to know if anyone has a solution or has an idea of what to do to fix this problem.

I am using the following command to run the entropy estiamators:

./ea_iid.exe -i -a -vv ../bin/truerand_8bit.bin 8 > truernd8.txt

I am using MSYS2 MinGW64 to compile the programs. The only library I could not find at the msys2 repository was libdivsufsort, and this is the reason I think this is the library giving me problems. All the other libraries needed were found in https://repo.msys2.org/msys/x86_64/

I installed the last version of the libdivsufsort from the https://github.com/y-256/libdivsufsort, as suggested in the wiki/Installing-Packages.

I used the following commands to build this library:

mkdir build

cd build

cmake .. -G "MinGW Makefiles"

cmake --build .

cmake --install .

Then I moved libdivsufsort.dll, divsufsort.h, libdivsufsort.dll.a and libdivsufsort.pc to their correct places in MinGW64.

The linux /dev/urandom was also not working because it is not available on windows, so I did a modification in the seed(uint64_t *xoshiro256starstarState) function in utils.h.

There was a comment in this function suggesting the use of the builtin function RdRand, so I changed the function to:

void seed(uint64_t *xoshiro256starstarState)
{
    uint64_t rand64;
    int retries = 10;
    int mem_elements = 4;
    while(mem_elements--)
    {
        while(retries--)
        {
            if( __builtin_ia32_rdrand64_step(&rand64) != 1)
            {
                perror("Can't read random seed");
                exit(-1);
            }
        }
        xoshiro256starstarState[mem_elements] = rand64;
        retries = 10;
    }

}
skbhaskarla commented 1 year ago

Hi Rafagenova,

Windows is not officially supported but I can offer some suggestions.

I used MS Visual Studio 2019 to build the libdivsufsort library in the x86 32-bit option because I received warnings from the 64-bit option.

Next, I updated the EntropyAssessment Makefile CXXFLAGS options with an -L switch of the path to the lib folder of the libdivsufsort project. (Makefile CXX was set to "clang++".)

I also had to compile Bzip2 and Getopt libraries separately because they were not readily available as Windows libraries at the time when I was compiling the EntropyAssessment project code.

Clang was on my command line shell PATH but it must be noted that the path to must not use quotes. Example: set PATH=%PATH%;c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin\;

clang version 12.0.0 Target: i686-pc-windows-msvc

Cd to SP800-90B_EntropyAssessment\cpp Mingw32-make Check the *.exe files

Copy the getopt.dll and divsufsort.dll to the .exe file location. Note: The divsufsort.dll is the dll from the x86 folder.

After I compiled the EntropyAssessment project, I created a Windows Batch file to run commands like: ..\ea_non_iid -vv ....\bin\truerand_8bit.bin > result\truerand_8bit.res

Then, I used Strawberry Perl in another batch file to run the compareresults.pl script like so: perl compareresults.pl result\truerand_8bit.res refdata\truerand_8bit.res echo %ERRORLEVEL%

skbhaskarla commented 1 year ago

@rafagenova The Windows 10 branch is well behind master but is relevant to the comments I made above.

joshuaehill commented 1 year ago

As an aside, if NIST eventually applies PR #217, then the 64-bit divsufsort will also be required.