Browse Source

Cleanup, Windows fixes, Self test fix

Adam Ierymenko 8 years ago
parent
commit
aaf597f020

+ 2 - 4
ext/x64-salsa2012-asm/salsa2012.h

@@ -2,11 +2,9 @@
 extern "C" {
 #endif
 
+// Generates Salsa20/12 key stream
 // 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 *);
-
-// 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 *);
+extern int zt_salsa2012_amd64_xmm6(unsigned char *, unsigned long long, const unsigned char *, const unsigned char *);
 
 #ifdef __cplusplus
 }

+ 9 - 9
node/Dictionary.hpp

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

+ 1 - 1
one.cpp

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

+ 6 - 9
selftest.cpp

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

+ 20 - 2
windows/ZeroTierOne/ZeroTierOne.vcxproj

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

+ 3 - 0
windows/ZeroTierOne/ZeroTierOne.vcxproj.filters

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