Import code from previous AssetBuilder version

This commit is contained in:
Jan
2019-09-24 10:45:09 +02:00
parent 5609557516
commit 0d8432d4f7
919 changed files with 154412 additions and 26 deletions

160
thirdparty/salsa20/salsa20.cpp vendored Normal file
View File

@ -0,0 +1,160 @@
/*
BASED ON salsa20-ref.c version 20051118
original author: D. J. Bernstein
Public domain.
*/
#include "salsa20.h"
#include <cassert>
#define U8V(v) ((uint8_t)(v) & 0xFFu)
#define U16V(v) ((uint16_t)(v) & 0xFFFFu)
#define U32V(v) ((uint32_t)(v) & 0xFFFFFFFFu)
#define U64V(v) ((uint64_t)(v) & 0xFFFFFFFFFFFFFFFFu)
#define ROTL8(v, n) \
(U8V((v) << (n)) | ((v) >> (8 - (n))))
#define ROTL16(v, n) \
(U16V((v) << (n)) | ((v) >> (16 - (n))))
#define ROTL32(v, n) \
(U32V((v) << (n)) | ((v) >> (32 - (n))))
#define ROTL64(v, n) \
(U64V((v) << (n)) | ((v) >> (64 - (n))))
#define SWAP32(v) \
((ROTL32(v, 8) & 0x00FF00FFu) | \
(ROTL32(v, 24) & 0xFF00FF00u))
#define XOR(v,w) ((v) ^ (w))
#define PLUS(v,w) (U32V((v) + (w)))
#define PLUSONE(v) (PLUS((v),1))
#ifdef BIG_ENDIAN
#define U32TO8_LITTLE(output8, input32) (((uint32_t*)(output8))[0] = SWAP32(input32))
#define U8TO32_LITTLE(input8) (SWAP32(((uint32_t*)(input8))[0]))
#else
#define U32TO8_LITTLE(output8, input32) (((uint32_t*)(output8))[0] = (input32))
#define U8TO32_LITTLE(input8) (((uint32_t*)(input8))[0])
#endif
static void Salsa20_WordToByte(uint8_t output[64], const uint32_t input[16])
{
uint32_t x[16];
int i;
for (i = 0; i < 16; ++i) x[i] = input[i];
for (i = 20; i > 0; i -= 2)
{
x[ 4] ^= ROTL32(PLUS(x[ 0], x[12]), 7);
x[ 8] ^= ROTL32(PLUS(x[ 4], x[ 0]), 9);
x[12] ^= ROTL32(PLUS(x[ 8], x[ 4]), 13);
x[ 0] ^= ROTL32(PLUS(x[12], x[ 8]), 18);
x[ 9] ^= ROTL32(PLUS(x[ 5], x[ 1]), 7);
x[13] ^= ROTL32(PLUS(x[ 9], x[ 5]), 9);
x[ 1] ^= ROTL32(PLUS(x[13], x[ 9]), 13);
x[ 5] ^= ROTL32(PLUS(x[ 1], x[13]), 18);
x[14] ^= ROTL32(PLUS(x[10], x[ 6]), 7);
x[ 2] ^= ROTL32(PLUS(x[14], x[10]), 9);
x[ 6] ^= ROTL32(PLUS(x[ 2], x[14]), 13);
x[10] ^= ROTL32(PLUS(x[ 6], x[ 2]), 18);
x[ 3] ^= ROTL32(PLUS(x[15], x[11]), 7);
x[ 7] ^= ROTL32(PLUS(x[ 3], x[15]), 9);
x[11] ^= ROTL32(PLUS(x[ 7], x[ 3]), 13);
x[15] ^= ROTL32(PLUS(x[11], x[ 7]), 18);
x[ 1] ^= ROTL32(PLUS(x[ 0], x[ 3]), 7);
x[ 2] ^= ROTL32(PLUS(x[ 1], x[ 0]), 9);
x[ 3] ^= ROTL32(PLUS(x[ 2], x[ 1]), 13);
x[ 0] ^= ROTL32(PLUS(x[ 3], x[ 2]), 18);
x[ 6] ^= ROTL32(PLUS(x[ 5], x[ 4]), 7);
x[ 7] ^= ROTL32(PLUS(x[ 6], x[ 5]), 9);
x[ 4] ^= ROTL32(PLUS(x[ 7], x[ 6]), 13);
x[ 5] ^= ROTL32(PLUS(x[ 4], x[ 7]), 18);
x[11] ^= ROTL32(PLUS(x[10], x[ 9]), 7);
x[ 8] ^= ROTL32(PLUS(x[11], x[10]), 9);
x[ 9] ^= ROTL32(PLUS(x[ 8], x[11]), 13);
x[10] ^= ROTL32(PLUS(x[ 9], x[ 8]), 18);
x[12] ^= ROTL32(PLUS(x[15], x[14]), 7);
x[13] ^= ROTL32(PLUS(x[12], x[15]), 9);
x[14] ^= ROTL32(PLUS(x[13], x[12]), 13);
x[15] ^= ROTL32(PLUS(x[14], x[13]), 18);
}
for (i = 0; i < 16; ++i) x[i] = PLUS(x[i], input[i]);
for (i = 0; i < 16; ++i) U32TO8_LITTLE(output + 4 * i, x[i]);
}
static const char* sigma = "expand 32-byte k";
static const char* tau = "expand 16-byte k";
void Salsa20_KeySetup(salsa20_ctx* ctx, const uint8_t* key, const uint32_t keySize)
{
const char* constants;
assert(keySize == 256 || keySize == 128);
ctx->m_input[1] = U8TO32_LITTLE(key + 0);
ctx->m_input[2] = U8TO32_LITTLE(key + 4);
ctx->m_input[3] = U8TO32_LITTLE(key + 8);
ctx->m_input[4] = U8TO32_LITTLE(key + 12);
if (keySize == 256)
{
/* recommended */
key += 16;
constants = sigma;
}
else
{
/* keySize == 128 */
constants = tau;
}
ctx->m_input[11] = U8TO32_LITTLE(key + 0);
ctx->m_input[12] = U8TO32_LITTLE(key + 4);
ctx->m_input[13] = U8TO32_LITTLE(key + 8);
ctx->m_input[14] = U8TO32_LITTLE(key + 12);
ctx->m_input[0] = U8TO32_LITTLE(constants + 0);
ctx->m_input[5] = U8TO32_LITTLE(constants + 4);
ctx->m_input[10] = U8TO32_LITTLE(constants + 8);
ctx->m_input[15] = U8TO32_LITTLE(constants + 12);
}
void Salsa20_IVSetup(salsa20_ctx* ctx, const uint8_t* iv)
{
ctx->m_input[6] = U8TO32_LITTLE(iv + 0);
ctx->m_input[7] = U8TO32_LITTLE(iv + 4);
ctx->m_input[8] = 0;
ctx->m_input[9] = 0;
}
void Salsa20_Encrypt_Bytes(salsa20_ctx* ctx, const uint8_t* plainText, uint8_t* cipherText, uint32_t msgLen)
{
uint8_t output[64];
unsigned int i;
if (!msgLen) return;
for (;;)
{
Salsa20_WordToByte(output, ctx->m_input);
ctx->m_input[8] = PLUSONE(ctx->m_input[8]);
if (!ctx->m_input[8])
{
ctx->m_input[9] = PLUSONE(ctx->m_input[9]);
/* stopping at 2^70 bytes per nonce is user's responsibility */
}
if (msgLen <= 64)
{
for (i = 0; i < msgLen; ++i) cipherText[i] = plainText[i] ^ output[i];
return;
}
for (i = 0; i < 64; ++i) cipherText[i] = plainText[i] ^ output[i];
msgLen -= 64;
cipherText += 64;
plainText += 64;
}
}
void Salsa20_Decrypt_Bytes(salsa20_ctx* ctx, const uint8_t* cipherText, uint8_t* plainText, const uint32_t msgLen)
{
Salsa20_Encrypt_Bytes(ctx, cipherText, plainText, msgLen);
}

55
thirdparty/salsa20/salsa20.h vendored Normal file
View File

@ -0,0 +1,55 @@
/*
BASED ON salsa20-ref.c version 20051118
original author: D. J. Bernstein
Public domain.
*/
#pragma once
#include <cstdint>
struct salsa20_ctx
{
uint32_t m_input[16];
};
/*
* Initializes the context with the chosen key.
*
* ctx: The context to initialize.
* key: A pointer to the key bytes.
* keySize: The length of the key in bits. Has to be 128 or 256.
*/
void Salsa20_KeySetup(salsa20_ctx* ctx, const uint8_t* key, uint32_t keySize);
/*
* Initializes or changes the IV of the context.
* Can be called multiple times on the same context in order to encrypt/decrypt messages with the same key but different IV's.
*
* ctx: The context to initialize.
* iv: A pointer to the IV bytes. Must be 64 bits long.
*/
void Salsa20_IVSetup(salsa20_ctx* ctx, const uint8_t* iv);
/*
* Encrypts the specified amount of plain text and writes it to the cipher text buffer.
* The cipher text buffer and the plain text buffer can be the same.
*
* ctx: The context that was previously initialized with a key and IV.
* cipherText: A pointer to the cipher text buffer which must at least be msgLen bytes.
* plainText: A pointer to the plain text buffer which must at least be msgLen bytes.
* msgLen: The amount of bytes to encrypt.
*/
void Salsa20_Encrypt_Bytes(salsa20_ctx* ctx, const uint8_t* plainText, uint8_t* cipherText, uint32_t msgLen);
/*
* Decrypts the specified amount of cipher text and writes it to the plain text buffer.
* The cipher text buffer and the plain text buffer can be the same.
* Internally just calls the encryption method.
*
* ctx: The context that was previously initialized with a key and IV.
* cipherText: A pointer to the cipher text buffer which must at least be msgLen bytes.
* plainText: A pointer to the plain text buffer which must at least be msgLen bytes.
* msgLen: The amount of bytes to decrypt.
*/
void Salsa20_Decrypt_Bytes(salsa20_ctx* ctx, const uint8_t* cipherText, uint8_t* plainText, uint32_t msgLen);

174
thirdparty/salsa20/salsa20.vcxproj vendored Normal file
View File

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="salsa20.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="salsa20.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{599A7D9D-0CB8-4B99-AA2E-EA5EC081CF77}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>salsa20</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>
<OutDir>$(SolutionDir)lib\$(Configuration)_$(Platform)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<AdditionalOptions>/ignore:4221</AdditionalOptions>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<AdditionalOptions>/ignore:4221</AdditionalOptions>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<AdditionalOptions>/ignore:4221</AdditionalOptions>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<AdditionalOptions>/ignore:4221</AdditionalOptions>
</Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>