Skip to content

Commit

Permalink
BLAKE3
Browse files Browse the repository at this point in the history
  • Loading branch information
namazso committed Aug 21, 2020
1 parent e84efbd commit 57fd26b
Show file tree
Hide file tree
Showing 17 changed files with 10,098 additions and 1 deletion.
34 changes: 34 additions & 0 deletions OpenHashTab/Hasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "blake2sp.h"
#include "sha3.h"
#include "crc32.h"
#include "blake3.h"

template <
typename Ctx,
Expand Down Expand Up @@ -237,6 +238,38 @@ class Crc32HashContext : HashContext
}
};

class Blake3HashContext : HashContext
{
template <typename T> friend HashContext* hash_context_factory(HashAlgorithm* algorithm);

blake3_hasher ctx{};

public:
Blake3HashContext(HashAlgorithm* algorithm) : HashContext(algorithm)
{
blake3_hasher_init(&ctx);
}
~Blake3HashContext() = default;

void Clear() override
{
blake3_hasher_init(&ctx);
}

void Update(const void* data, size_t size) override
{
blake3_hasher_update(&ctx, data, size);
}

std::vector<uint8_t> Finish() override
{
std::vector<uint8_t> result;
result.resize(BLAKE3_OUT_LEN);
blake3_hasher_finalize(&ctx, result.data(), BLAKE3_OUT_LEN);
return result;
}
};

template <typename T> HashContext* hash_context_factory(HashAlgorithm* algorithm) { return new T(algorithm); }

// these are what I found with a quick FTP search
Expand Down Expand Up @@ -266,4 +299,5 @@ HashAlgorithm HashAlgorithm::g_hashers[] =
{ "SHA3-256", 32, no_exts, hash_context_factory<Sha3_256HashContext>, true, false },
{ "SHA3-384", 48, no_exts, hash_context_factory<Sha3_384HashContext>, true, false },
{ "SHA3-512", 64, sha3_512_exts, hash_context_factory<Sha3_512HashContext>, true, false },
{ "BLAKE3", 32, no_exts, hash_context_factory<Blake3HashContext>, true, false },
};
2 changes: 1 addition & 1 deletion OpenHashTab/Hasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HashAlgorithm
{
public:
using FactoryFn = HashContext*(HashAlgorithm* algorithm);
constexpr static auto k_count = 14;
constexpr static auto k_count = 15;
constexpr static auto k_max_size = 64;
static HashAlgorithm g_hashers[k_count];
static HashAlgorithm* ByName(std::string_view name)
Expand Down
82 changes: 82 additions & 0 deletions OpenHashTab/OpenHashTab.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
Expand Down Expand Up @@ -404,6 +405,66 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="blake3.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="blake3_avx2.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="blake3_avx512.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="blake3_dispatch.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="blake3_portable.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="blake3_sse41.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="crc32.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
Expand Down Expand Up @@ -483,6 +544,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="blake2sp.h" />
<ClInclude Include="blake3.h" />
<ClInclude Include="blake3_impl.h" />
<ClInclude Include="crc32.h" />
<ClInclude Include="dllmain.h" />
<ClInclude Include="FileHashTask.h" />
Expand All @@ -506,6 +569,24 @@
<ResourceCompile Include="OpenHashTab.rc" />
</ItemGroup>
<ItemGroup>
<None Include="blake3_avx2_x86-64_windows_msvc.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</None>
<None Include="blake3_avx512_x86-64_windows_msvc.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</None>
<None Include="blake3_sse41_x86-64_windows_msvc.asm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</None>
<None Include="OpenHashTab.def" />
<None Include="OpenHashTab.rgs" />
<None Include="OpenHashTabShlExt.rgs" />
Expand All @@ -515,5 +596,6 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>
36 changes: 36 additions & 0 deletions OpenHashTab/OpenHashTab.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<Filter Include="CRC32">
<UniqueIdentifier>{f023d767-ba4d-4281-9822-8aff43aeaf05}</UniqueIdentifier>
</Filter>
<Filter Include="BLAKE3">
<UniqueIdentifier>{26c5a99a-5567-4892-9570-ea3267dd882d}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -109,6 +112,24 @@
<ClCompile Include="Standalone.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="blake3.c">
<Filter>BLAKE3</Filter>
</ClCompile>
<ClCompile Include="blake3_avx2.c">
<Filter>BLAKE3</Filter>
</ClCompile>
<ClCompile Include="blake3_avx512.c">
<Filter>BLAKE3</Filter>
</ClCompile>
<ClCompile Include="blake3_dispatch.c">
<Filter>BLAKE3</Filter>
</ClCompile>
<ClCompile Include="blake3_portable.c">
<Filter>BLAKE3</Filter>
</ClCompile>
<ClCompile Include="blake3_sse41.c">
<Filter>BLAKE3</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
Expand Down Expand Up @@ -165,6 +186,12 @@
<ClInclude Include="Coordinator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="blake3_impl.h">
<Filter>BLAKE3</Filter>
</ClInclude>
<ClInclude Include="blake3.h">
<Filter>BLAKE3</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="OpenHashTab.rc">
Expand All @@ -184,6 +211,15 @@
<None Include="OpenHashTabShlExt.rgs">
<Filter>Resource Files</Filter>
</None>
<None Include="blake3_avx2_x86-64_windows_msvc.asm">
<Filter>BLAKE3</Filter>
</None>
<None Include="blake3_avx512_x86-64_windows_msvc.asm">
<Filter>BLAKE3</Filter>
</None>
<None Include="blake3_sse41_x86-64_windows_msvc.asm">
<Filter>BLAKE3</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Midl Include="OpenHashTab.idl">
Expand Down
Loading

0 comments on commit 57fd26b

Please sign in to comment.