Cleanup, Windows fixes, Self test fix

This commit is contained in:
Adam Ierymenko 2017-04-18 12:22:44 -07:00
parent 72bd3064a2
commit aaf597f020
6 changed files with 41 additions and 25 deletions

View file

@ -2,11 +2,9 @@
extern "C" { extern "C" {
#endif #endif
// Generates Salsa20/12 key stream
// output, outlen, nonce, key (256-bit / 32-byte) // output, outlen, nonce, key (256-bit / 32-byte)
extern int zt_salsa2012_amd64_xmm6(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *); extern int zt_salsa2012_amd64_xmm6(unsigned char *, unsigned long long, const unsigned char *, const unsigned char *);
// ciphertext, message, mlen, nonce, key
extern int zt_salsa2012_amd64_xmm6_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -176,12 +176,12 @@ public:
j = 0; j = 0;
esc = false; esc = false;
++p; ++p;
while ((*p != 0)&&(*p != '\r')&&(*p != '\n')) { while ((*p != 0)&&(*p != 13)&&(*p != 10)) {
if (esc) { if (esc) {
esc = false; esc = false;
switch(*p) { switch(*p) {
case 'r': dest[j++] = '\r'; break; case 'r': dest[j++] = 13; break;
case 'n': dest[j++] = '\n'; break; case 'n': dest[j++] = 10; break;
case '0': dest[j++] = (char)0; break; case '0': dest[j++] = (char)0; break;
case 'e': dest[j++] = '='; break; case 'e': dest[j++] = '='; break;
default: dest[j++] = *p; break; default: dest[j++] = *p; break;
@ -207,7 +207,7 @@ public:
dest[j] = (char)0; dest[j] = (char)0;
return j; return j;
} else { } else {
while ((*p)&&(*p != '\r')&&(*p != '\n')) { while ((*p)&&(*p != 13)&&(*p != 10)) {
if (++p == eof) { if (++p == eof) {
dest[0] = (char)0; dest[0] = (char)0;
return -1; return -1;
@ -299,7 +299,7 @@ public:
unsigned int j = i; unsigned int j = i;
if (j > 0) { if (j > 0) {
_d[j++] = '\n'; _d[j++] = (char)10;
if (j == C) { if (j == C) {
_d[i] = (char)0; _d[i] = (char)0;
return false; return false;
@ -326,8 +326,8 @@ public:
while ( ((vlen < 0)&&(*p)) || (k < vlen) ) { while ( ((vlen < 0)&&(*p)) || (k < vlen) ) {
switch(*p) { switch(*p) {
case 0: case 0:
case '\r': case 13:
case '\n': case 10:
case '\\': case '\\':
case '=': case '=':
_d[j++] = '\\'; _d[j++] = '\\';
@ -337,8 +337,8 @@ public:
} }
switch(*p) { switch(*p) {
case 0: _d[j++] = '0'; break; case 0: _d[j++] = '0'; break;
case '\r': _d[j++] = 'r'; break; case 13: _d[j++] = 'r'; break;
case '\n': _d[j++] = 'n'; break; case 10: _d[j++] = 'n'; break;
case '\\': _d[j++] = '\\'; break; case '\\': _d[j++] = '\\'; break;
case '=': _d[j++] = 'e'; break; case '=': _d[j++] = 'e'; break;
} }

View file

@ -1257,7 +1257,7 @@ public:
}; };
#ifdef __WINDOWS__ #ifdef __WINDOWS__
int _tmain(int argc, _TCHAR* argv[]) int __cdecl _tmain(int argc, _TCHAR* argv[])
#else #else
int main(int argc,char **argv) int main(int argc,char **argv)
#endif #endif

View file

@ -212,12 +212,10 @@ static int testCrypto()
std::cout << "[crypto] Benchmarking Salsa20/12 fast x64 ASM... "; std::cout.flush(); std::cout << "[crypto] Benchmarking Salsa20/12 fast x64 ASM... "; std::cout.flush();
{ {
unsigned char *bb = (unsigned char *)::malloc(1234567); unsigned char *bb = (unsigned char *)::malloc(1234567);
for(unsigned int i=0;i<1234567;++i)
bb[i] = (unsigned char)i;
double bytes = 0.0; double bytes = 0.0;
uint64_t start = OSUtils::now(); uint64_t start = OSUtils::now();
for(unsigned int i=0;i<200;++i) { for(unsigned int i=0;i<200;++i) {
zt_salsa2012_amd64_xmm6_xor(bb,bb,1234567,s20TV0Iv,s20TV0Key); zt_salsa2012_amd64_xmm6(bb, 1234567, s20TV0Iv, s20TV0Key);
bytes += 1234567.0; bytes += 1234567.0;
} }
uint64_t end = OSUtils::now(); uint64_t end = OSUtils::now();
@ -806,20 +804,19 @@ static int testOther()
memset(key, 0, sizeof(key)); memset(key, 0, sizeof(key));
memset(value, 0, sizeof(value)); memset(value, 0, sizeof(value));
for(unsigned int q=0;q<32;++q) { for(unsigned int q=0;q<32;++q) {
Utils::snprintf(key[q],16,"%.8lx",(unsigned long)rand()); Utils::snprintf(key[q],16,"%.8lx",(unsigned long)(rand() % 1000) + (q * 1000));
int r = (rand() % 127) + 1; int r = rand() % 128;
for(int x=0;x<r;++x) for(int x=0;x<r;++x)
value[q][x] = ("0123456789\0\t\r\n= ")[rand() % 16]; value[q][x] = ("0123456789\0\t\r\n= ")[rand() % 16];
value[q][r] = (char)0; value[q][r] = (char)0;
test->add(key[q],value[q],r); test->add(key[q],value[q],r);
} }
for(unsigned int q=0;q<1024;++q) { for(unsigned int q=0;q<1024;++q) {
//int r = rand() % 128; int r = rand() % 32;
int r = 31;
char tmp[128]; char tmp[128];
if (test->get(key[r],tmp,sizeof(tmp)) >= 0) { if (test->get(key[r],tmp,sizeof(tmp)) >= 0) {
if (strcmp(value[r],tmp)) { if (strcmp(value[r],tmp)) {
std::cout << "FAILED (invalid value)!" << std::endl; std::cout << "FAILED (invalid value '" << value[r] << "' != '" << tmp << "')!" << std::endl;
return -1; return -1;
} }
} else { } else {
@ -1048,7 +1045,7 @@ static int testHttp()
*/ */
#ifdef __WINDOWS__ #ifdef __WINDOWS__
int _tmain(int argc, _TCHAR* argv[]) int __cdecl _tmain(int argc, _TCHAR* argv[])
#else #else
int main(int argc,char **argv) int main(int argc,char **argv)
#endif #endif

View file

@ -72,12 +72,27 @@
<ClCompile Include="..\..\node\Tag.cpp" /> <ClCompile Include="..\..\node\Tag.cpp" />
<ClCompile Include="..\..\node\Topology.cpp" /> <ClCompile Include="..\..\node\Topology.cpp" />
<ClCompile Include="..\..\node\Utils.cpp" /> <ClCompile Include="..\..\node\Utils.cpp" />
<ClCompile Include="..\..\one.cpp" /> <ClCompile Include="..\..\one.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\osdep\Http.cpp" /> <ClCompile Include="..\..\osdep\Http.cpp" />
<ClCompile Include="..\..\osdep\ManagedRoute.cpp" /> <ClCompile Include="..\..\osdep\ManagedRoute.cpp" />
<ClCompile Include="..\..\osdep\OSUtils.cpp" /> <ClCompile Include="..\..\osdep\OSUtils.cpp" />
<ClCompile Include="..\..\osdep\PortMapper.cpp" /> <ClCompile Include="..\..\osdep\PortMapper.cpp" />
<ClCompile Include="..\..\osdep\WindowsEthernetTap.cpp" /> <ClCompile Include="..\..\osdep\WindowsEthernetTap.cpp" />
<ClCompile Include="..\..\selftest.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\service\OneService.cpp" /> <ClCompile Include="..\..\service\OneService.cpp" />
<ClCompile Include="..\..\service\SoftwareUpdater.cpp" /> <ClCompile Include="..\..\service\SoftwareUpdater.cpp" />
<ClCompile Include="ServiceBase.cpp" /> <ClCompile Include="ServiceBase.cpp" />
@ -363,7 +378,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Full</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
@ -377,6 +392,9 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers> <OmitFramePointers>true</OmitFramePointers>
<DisableSpecificWarnings>4996</DisableSpecificWarnings> <DisableSpecificWarnings>4996</DisableSpecificWarnings>
<ControlFlowGuard>Guard</ControlFlowGuard>
<EnableParallelCodeGeneration>false</EnableParallelCodeGeneration>
<CallingConvention>VectorCall</CallingConvention>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>

View file

@ -252,6 +252,9 @@
<ClCompile Include="..\..\one.cpp"> <ClCompile Include="..\..\one.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\selftest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="resource.h"> <ClInclude Include="resource.h">