├── .github └── workflows │ ├── codeql.yml │ ├── dotnet.yml │ └── greetings.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── SECURITY.md ├── appveyor.pr.yml ├── appveyor.production.yml ├── appveyor.yml ├── build ├── build-configuration.ps1 ├── build.ps1 └── coverity.ps1 ├── data_hashfunction_logo.png ├── doxygen ├── Doxyfile.doxygen ├── doxygen-awesome-LICENSE ├── doxygen-awesome-darkmode-toggle.js ├── doxygen-awesome-fragment-copy-button.js ├── doxygen-awesome-interactive-toc.js ├── doxygen-awesome-paragraph-link.js ├── doxygen-awesome-sidebar-only-darkmode-toggle.css ├── doxygen-awesome-sidebar-only.css ├── doxygen-awesome-tabs.js ├── doxygen-awesome.css ├── logo.png └── mainpage.md ├── src ├── .nuget │ └── packages.config ├── Data.HashFunction.BernsteinHash │ ├── BernsteinHashFactory.cs │ ├── BernsteinHash_Implementation.cs │ ├── Data.HashFunction.BernsteinHash.csproj │ ├── IBernsteinHash.cs │ ├── IBernsteinHashFactory.cs │ ├── IModifiedBernsteinHash.cs │ ├── IModifiedBernsteinHashFactory.cs │ ├── ModifiedBernsteinHashFactory.cs │ ├── ModifiedBernsteinHash_Implementation.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.Blake2 │ ├── Blake2BConfig.cs │ ├── Blake2BFactory.cs │ ├── Blake2B_ComputeRounds.cs │ ├── Blake2B_Implementation.cs │ ├── Data.HashFunction.Blake2.csproj │ ├── IBlake2B.cs │ ├── IBlake2BConfig.cs │ ├── IBlake2BFactory.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Utilities │ │ └── UInt128.cs ├── Data.HashFunction.Blake3 │ ├── Blake3Config.cs │ ├── Blake3Factory.cs │ ├── Blake3_Implementation.cs │ ├── Data.HashFunction.Blake3.csproj │ ├── Hasher.cs │ ├── IBlake3.cs │ ├── IBlake3Config.cs │ ├── IBlake3Factory.cs │ └── runtimes │ │ ├── linux-arm │ │ └── native │ │ │ └── libblake3_dotnet.so │ │ ├── linux-arm64 │ │ └── native │ │ │ └── libblake3_dotnet.so │ │ ├── linux-x64 │ │ └── native │ │ │ └── libblake3_dotnet.so │ │ ├── osx-arm64 │ │ └── native │ │ │ └── libblake3_dotnet.dylib │ │ ├── osx-x64 │ │ └── native │ │ │ └── libblake3_dotnet.dylib │ │ ├── win-arm64 │ │ └── native │ │ │ └── blake3_dotnet.dll │ │ ├── win-x64 │ │ └── native │ │ │ └── blake3_dotnet.dll │ │ └── win-x86 │ │ └── native │ │ └── blake3_dotnet.dll ├── Data.HashFunction.BuzHash │ ├── BuzHashConfig.cs │ ├── BuzHashFactory.cs │ ├── BuzHash_Implementation.cs │ ├── CircularShiftDirection.cs │ ├── Data.HashFunction.BuzHash.csproj │ ├── DefaultBuzHashConfig.cs │ ├── IBuzHash.cs │ ├── IBuzHashConfig.cs │ ├── IBuzHashFactory.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.CRC │ ├── CRCConfig.cs │ ├── CRCFactory.cs │ ├── CRC_Implementation.cs │ ├── Data.HashFunction.CRC.csproj │ ├── ICRC.cs │ ├── ICRCConfig.cs │ ├── ICRCFactory.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.CityHash │ ├── CityHashConfig.cs │ ├── CityHashFactory.cs │ ├── CityHash_Implementation.cs │ ├── Data.HashFunction.CityHash.csproj │ ├── ICityHash.cs │ ├── ICityHashConfig.cs │ ├── ICityHashFactory.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Utilities │ │ └── UInt128.cs ├── Data.HashFunction.Core │ ├── BlockTransformerBase.cs │ ├── Data.HashFunction.Core.csproj │ ├── HashFunctionBase.cs │ ├── IHashFunction_Extensions.cs │ ├── NativeLibraryLoader │ │ ├── Kernel32.cs │ │ ├── Libdl.cs │ │ ├── NativeLibraryLoader.cs │ │ └── OperatingSystemHelper.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── StreamableHashFunctionBase.cs │ └── Utilities │ │ └── HashValue.cs ├── Data.HashFunction.ELF64 │ ├── Data.HashFunction.ELF64.csproj │ ├── ELF64Factory.cs │ ├── ELF64_Implementation.cs │ ├── IELF64.cs │ ├── IELF64Factory.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.FNV │ ├── Data.HashFunction.FNV.csproj │ ├── FNV1Base.cs │ ├── FNV1Factory.cs │ ├── FNV1_Implementation.cs │ ├── FNV1aFactory.cs │ ├── FNV1a_Implementation.cs │ ├── FNVConfig.cs │ ├── IFNV.cs │ ├── IFNV1.cs │ ├── IFNV1Factory.cs │ ├── IFNV1a.cs │ ├── IFNV1aFactory.cs │ ├── IFNVConfig.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Utilities │ │ └── FNVPrimeOffset.cs ├── Data.HashFunction.FarmHash │ ├── Data.HashFunction.FarmHash.csproj │ ├── FarmHashFingerprint128Factory.cs │ ├── FarmHashFingerprint128_Implementation.cs │ ├── FarmHashFingerprint32Factory.cs │ ├── FarmHashFingerprint32_Implementation.cs │ ├── FarmHashFingerprint64Factory.cs │ ├── FarmHashFingerprint64_Implementation.cs │ ├── IFarmHashFingerprint128.cs │ ├── IFarmHashFingerprint128Factory.cs │ ├── IFarmHashFingerprint32.cs │ ├── IFarmHashFingerprint32Factory.cs │ ├── IFarmHashFingerprint64.cs │ ├── IFarmHashFingerprint64Factory.cs │ └── Utilities │ │ └── UInt128.cs ├── Data.HashFunction.HashAlgorithm │ ├── Data.HashFunction.HashAlgorithm.csproj │ ├── HashAlgorithmWrapperConfig.cs │ ├── HashAlgorithmWrapperFactory.cs │ ├── HashAlgorithmWrapper_Implementation.cs │ ├── IHashAlgorithmWrapper.cs │ ├── IHashAlgorithmWrapperConfig.cs │ ├── IHashAlgorithmWrapperFactory.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.Interfaces │ ├── Data.HashFunction.Interfaces.csproj │ ├── IBlockTransformer.cs │ ├── IHashFunction.cs │ ├── IHashValue.cs │ ├── IStreamableHashFunction.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.Jenkins │ ├── Data.HashFunction.Jenkins.csproj │ ├── IJenkins.cs │ ├── IJenkinsLookup2.cs │ ├── IJenkinsLookup2Config.cs │ ├── IJenkinsLookup2Factory.cs │ ├── IJenkinsLookup3.cs │ ├── IJenkinsLookup3Config.cs │ ├── IJenkinsLookup3Factory.cs │ ├── IJenkinsOneAtATime.cs │ ├── IJenkinsOneAtATimeFactory.cs │ ├── JenkinsLookup2Config.cs │ ├── JenkinsLookup2Factory.cs │ ├── JenkinsLookup2_Implementation.cs │ ├── JenkinsLookup3Config.cs │ ├── JenkinsLookup3Factory.cs │ ├── JenkinsLookup3_Implementation.cs │ ├── JenkinsOneAtATimeFactory.cs │ ├── JenkinsOneAtATime_Implementation.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.MetroHash │ ├── Data.HashFunction.MetroHash.csproj │ ├── IMetroHash128.cs │ ├── IMetroHash128Factory.cs │ ├── IMetroHash64.cs │ ├── IMetroHash64Factory.cs │ ├── IMetroHashConfig.cs │ ├── MetroHash128Factory.cs │ ├── MetroHash128_Implementation.cs │ ├── MetroHash64Factory.cs │ ├── MetroHash64_Implementation.cs │ └── MetroHashConfig.cs ├── Data.HashFunction.MurmurHash │ ├── Data.HashFunction.MurmurHash.csproj │ ├── IMurmurHash1.cs │ ├── IMurmurHash1Config.cs │ ├── IMurmurHash1Factory.cs │ ├── IMurmurHash2.cs │ ├── IMurmurHash2Config.cs │ ├── IMurmurHash2Factory.cs │ ├── IMurmurHash3.cs │ ├── IMurmurHash3Config.cs │ ├── IMurmurHash3Factory.cs │ ├── MurmurHash1Config.cs │ ├── MurmurHash1Factory.cs │ ├── MurmurHash1_Implementation.cs │ ├── MurmurHash2Config.cs │ ├── MurmurHash2Factory.cs │ ├── MurmurHash2_Implementation.cs │ ├── MurmurHash3Config.cs │ ├── MurmurHash3Factory.cs │ ├── MurmurHash3_Implementation.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Data.HashFunction.Pearson │ ├── Data.HashFunction.Pearson.csproj │ ├── IPearson.cs │ ├── IPearsonConfig.cs │ ├── IPearsonFactory.cs │ ├── PearsonConfig.cs │ ├── PearsonFactory.cs │ ├── Pearson_Implementation.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── WikipediaPearsonConfig.cs ├── Data.HashFunction.Production.snk ├── Data.HashFunction.SpookyHash │ ├── Data.HashFunction.SpookyHash.csproj │ ├── ISpookyHashConfig.cs │ ├── ISpookyHashV1.cs │ ├── ISpookyHashV1Factory.cs │ ├── ISpookyHashV2.cs │ ├── ISpookyHashV2Factory.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SpookyHashConfig.cs │ ├── SpookyHashV1Factory.cs │ ├── SpookyHashV1_Implementation.cs │ ├── SpookyHashV2Factory.cs │ └── SpookyHashV2_Implementation.cs ├── Data.HashFunction.Test │ ├── App.config │ ├── BernsteinHash │ │ ├── BernsteinHashFactory_Tests.cs │ │ ├── BernsteinHash_Implementation_Tests.cs │ │ ├── ModifiedBernsteinHashFactory_Tests.cs │ │ └── ModifiedBernsteinHash_Implementation_Tests.cs │ ├── Blake2 │ │ ├── Blake2BConfig_Tests.cs │ │ ├── Blake2BFactory_Tests.cs │ │ ├── Blake2B_Implementation_Tests.cs │ │ └── Utilities │ │ │ └── UInt128_Tests.cs │ ├── Blake3 │ │ ├── Blake3Config_Tests.cs │ │ ├── Blake3Factory_Tests.cs │ │ └── Blake3_Implementation_Tests.cs │ ├── BuzHash │ │ ├── BuzHashConfig_Tests.cs │ │ ├── BuzHashFactory_Tests.cs │ │ ├── BuzHash_Implementation_Tests.cs │ │ └── DefaultBuzHashConfig_Tests.cs │ ├── CRC │ │ ├── CRCConfig_Tests.cs │ │ ├── CRCFactory_Tests.cs │ │ └── CRC_Implementation_Tests.cs │ ├── CityHash │ │ ├── CityHashConfig_Tests.cs │ │ ├── CityHashFactory_Tests.cs │ │ ├── CityHash_Implementation_Tests.cs │ │ └── Utilities │ │ │ └── UInt128_Tests.cs │ ├── Core │ │ ├── HashFunctionBase_Tests.cs │ │ ├── IHashFunction_Extensions_Tests.cs │ │ ├── IHashFunction_TestBase.cs │ │ ├── IStreamableHashFunction_TestBase.cs │ │ └── Utilities │ │ │ └── HashValue_Tests.cs │ ├── Data.HashFunction.Test.csproj │ ├── ELF64 │ │ ├── ELF64Factory_Tests.cs │ │ └── ELF64_Implementation_Tests.cs │ ├── FNV │ │ ├── FNV1Base_Tests.cs │ │ ├── FNV1Factory_Tests.cs │ │ ├── FNV1_Implementation_Tests.cs │ │ ├── FNV1aFactory_Tests.cs │ │ ├── FNV1a_Implementation_Tests.cs │ │ ├── FNVConfig_Tests.cs │ │ └── Utilities │ │ │ └── FNVPrimeOffset_Tests.cs │ ├── FarmHash │ │ ├── FarmHashFingerprint128Factory_Tests.cs │ │ ├── FarmHashFingerprint128_Implementation_Tests.cs │ │ ├── FarmHashFingerprint32Factory_Tests.cs │ │ ├── FarmHashFingerprint32_Implementation_Tests.cs │ │ ├── FarmHashFingerprint64Factory_Tests.cs │ │ ├── FarmHashFingerprint64_Implementation_Tests.cs │ │ └── Utilities │ │ │ └── UInt128_Tests.cs │ ├── GlobalSuppressions.cs │ ├── HashAlgorithm │ │ ├── HashAlgorithmWrapperConfig_Tests.cs │ │ ├── HashAlgorithmWrapperFactory_Tests.cs │ │ └── HashAlgorithmWrapper_Implementation_Tests.cs │ ├── IHashFunction_SpeedTest.cs │ ├── Jenkins │ │ ├── JenkinsLookup2Config_Tests.cs │ │ ├── JenkinsLookup2Factory_Tests.cs │ │ ├── JenkinsLookup2_Implementation_Tests.cs │ │ ├── JenkinsLookup3Config_Tests.cs │ │ ├── JenkinsLookup3Factory_Tests.cs │ │ ├── JenkinsLookup3Tests.cs │ │ ├── JenkinsLookup3_Implementation_Tests.cs │ │ ├── JenkinsOneAtATimeFactory_Tests.cs │ │ └── JenkinsOneAtATime_Implementation_Tests.cs │ ├── MetroHash │ │ ├── MetroHash128Factory_Tests.cs │ │ ├── MetroHash128_Implementation_Tests.cs │ │ ├── MetroHash64Factory_Tests.cs │ │ ├── MetroHash64_Implementation_Tests.cs │ │ └── MetroHashConfig_Tests.cs │ ├── MurmurHash │ │ ├── MurmurHash1Config_Tests.cs │ │ ├── MurmurHash1Factory_Tests.cs │ │ ├── MurmurHash1_Implementation_Tests.cs │ │ ├── MurmurHash2Config_Tests.cs │ │ ├── MurmurHash2Factory_Tests.cs │ │ ├── MurmurHash2_Implementation_Tests.cs │ │ ├── MurmurHash3Config_Tests.cs │ │ ├── MurmurHash3Factory_Tests.cs │ │ └── MurmurHash3_Implementation_Tests.cs │ ├── Pearson │ │ ├── PearsonBaseTests.cs │ │ ├── PearsonConfig_Tests.cs │ │ ├── PearsonFactory_Tests.cs │ │ ├── Pearson_Implementation_Tests.cs │ │ └── WikipediaPearsonConfig_Tests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SpookyHash │ │ ├── SpookyHashConfig_Tests.cs │ │ ├── SpookyHashV1Factory_Tests.cs │ │ ├── SpookyHashV1_Implementation_Tests.cs │ │ ├── SpookyHashV2Factory_Tests.cs │ │ └── SpookyHashV2_Implementation_Tests.cs │ ├── Test │ │ └── _Utilities │ │ │ └── UtilityExtension_Tests.cs │ ├── _Mocks │ │ ├── HashFunctionImpl.cs │ │ └── SlowAsyncStream.cs │ ├── _Utilities │ │ ├── TestConstants.cs │ │ └── UtilityExtensions.cs │ ├── packages.config │ ├── results.xml │ └── xxHash │ │ ├── xxHashConfig_Tests.cs │ │ ├── xxHashFactory_Tests.cs │ │ └── xxHash_Implementation_Tests.cs ├── Data.HashFunction.runsettings ├── Data.HashFunction.sln ├── Data.HashFunction.xxHash │ ├── Data.HashFunction.xxHash.csproj │ ├── GlobalSuppressions.cs │ ├── IxxHash.cs │ ├── IxxHashConfig.cs │ ├── IxxHashFactory.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── xxHashConfig.cs │ ├── xxHashFactory.cs │ └── xxHash_Implementation.cs ├── Data.HashFunction │ └── Data.HashFunction.csproj ├── FriendAssemblies.cs └── SolutionInfo.cs └── tools └── nuget.exe /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET 5 | 6 | on: 7 | push: 8 | branches: [ "master" ] 9 | pull_request: 10 | branches: [ "master" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | defaults: 17 | run: 18 | working-directory: ./src 19 | 20 | steps: 21 | - uses: actions/checkout@v4 22 | - name: Setup .NET 23 | uses: actions/setup-dotnet@v4 24 | with: 25 | dotnet-version: 8.0.x 26 | - name: Restore dependencies 27 | run: dotnet restore 28 | - name: Build 29 | run: dotnet build --no-restore 30 | - name: Test 31 | run: dotnet test --no-build --verbosity normal 32 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request_target, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | steps: 12 | - uses: actions/first-interaction@v1 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | issue-message: "Thank you for highlighting this issue. We genuinely appreciate your effort!" 16 | pr-message: "🎉 Welcome to Data.HashFunction! Your first pull request is a significant milestone, and we're thrilled to have your contribution. Let's create something amazing together!" 17 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/psake"] 2 | path = tools/psake 3 | url = https://github.com/psake/psake.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2024 Deskasoft International 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Security issues and bugs should be reported privately to Deskasoft International by emailing security@deskasoft.com. 6 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your 7 | original message. 8 | 9 | Please do not open issues for anything you think might have a security implication. 10 | -------------------------------------------------------------------------------- /appveyor.pr.yml: -------------------------------------------------------------------------------- 1 | version: '1.0.{build}' 2 | configuration: 3 | - Debug 4 | nuget: 5 | account_feed: false 6 | project_feed: true 7 | disable_publish_on_pr: false 8 | platform: Any CPU 9 | init: 10 | - ps: $Env:APPVEYOR_BUILD_NUMBER_PADDED = $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0") 11 | before_build: 12 | - appveyor-retry tools\nuget.exe restore src 13 | - appveyor-retry dotnet restore -v Minimal src 14 | - ps: .\build\build.ps1 -taskList 'Validate' -configuration 'Debug' -preReleaseTag 'pr' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 15 | build_script: 16 | - ps: .\build\build.ps1 -taskList 'Build' -configuration 'Debug' -preReleaseTag 'pr' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 17 | - ps: .\build\build.ps1 -taskList 'Pack' -configuration 'Debug' -preReleaseTag 'pr' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 18 | test_script: 19 | - ps: .\build\build.ps1 -taskList 'Test' -configuration 'Debug' -preReleaseTag 'pr' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 20 | artifacts: 21 | - path: Artifacts\Packages\*.nupkg 22 | name: Packages 23 | type: NuGetPackage 24 | -------------------------------------------------------------------------------- /appveyor.production.yml: -------------------------------------------------------------------------------- 1 | version: '1.0.{build}' 2 | configuration: 3 | - Release 4 | nuget: 5 | account_feed: false 6 | project_feed: false 7 | disable_publish_on_pr: true 8 | platform: Any CPU 9 | before_build: 10 | - appveyor-retry tools\nuget.exe restore src 11 | - appveyor-retry dotnet restore -v Minimal src 12 | - ps: .\build\build.ps1 -taskList 'Validate' -configuration 'Release' -preReleaseTag '' 13 | build_script: 14 | - ps: .\build\build.ps1 -taskList 'Build' -configuration 'Release' -preReleaseTag '' 15 | - ps: .\build\build.ps1 -taskList 'Pack' -configuration 'Release' -preReleaseTag '' 16 | test_script: 17 | - ps: .\build\build.ps1 -taskList 'Test' -configuration 'Debug' -preReleaseTag '' 18 | artifacts: 19 | - path: Artifacts\Packages\*.nupkg 20 | name: Packages 21 | type: NuGetPackage 22 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '1.0.{build}' 2 | branches: 3 | only: 4 | - master 5 | configuration: 6 | - Debug 7 | environment: 8 | COVERALLS_REPO_TOKEN: 9 | secure: 6jeh+WtWuKh30geTgWNduraiRDXN4HDp5TJNWRwrzl3ZZvG9HPZ0DVvpKWqeG6Ha 10 | COVERITY_TOKEN: 11 | secure: CSQbgJmXPTyS85qE8DgVZJaUVxUL883PJjXsKChfYR4 12 | nuget: 13 | account_feed: false 14 | project_feed: true 15 | disable_publish_on_pr: true 16 | platform: Any CPU 17 | init: 18 | - ps: $Env:APPVEYOR_BUILD_NUMBER_PADDED = $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0") 19 | before_build: 20 | - appveyor-retry tools\nuget.exe restore src 21 | - appveyor-retry dotnet restore -v Minimal src 22 | - ps: .\build\build.ps1 -taskList 'Validate' -configuration 'Debug' -preReleaseTag 'ci' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 23 | build_script: 24 | - ps: .\build\build.ps1 -taskList 'Build' -configuration 'Debug' -preReleaseTag 'ci' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 25 | - ps: .\build\build.ps1 -taskList 'Pack' -configuration 'Debug' -preReleaseTag 'ci' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 26 | test_script: 27 | - ps: .\build\build.ps1 -taskList 'Test' -configuration 'Debug' -preReleaseTag 'ci' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 28 | after_test: 29 | - cmd: src\packages\coveralls.io.1.3.4\tools\coveralls.net.exe --opencover Artifacts\Coverage\*.xml 30 | # For when coverity supports dotnet analysis. 31 | # - ps: .\build\coverity.ps1 -configuration 'Debug' -preReleaseTag 'coverity-ci' -buildNumber $Env:APPVEYOR_BUILD_NUMBER_PADDED 32 | artifacts: 33 | - path: Artifacts\Packages\*.nupkg 34 | name: Packages 35 | type: NuGetPackage 36 | - path: Artifacts\Coverage\*.xml 37 | name: CoverageResults 38 | type: File 39 | -------------------------------------------------------------------------------- /build/build-configuration.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/build/build-configuration.ps1 -------------------------------------------------------------------------------- /build/build.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [Parameter()] 3 | [string] $taskList, 4 | [Parameter()] 5 | [string] $configuration, 6 | [Parameter()] 7 | [string] $preReleaseTag, 8 | [Parameter()] 9 | [string] $buildNumber, 10 | [Parameter()] 11 | [string] $gitExecutable, 12 | [Parameter()] 13 | [string] $dotNetExecutable 14 | ) 15 | 16 | $buildDir = $PSScriptRoot 17 | $baseDir = Resolve-Path $PSScriptRoot\.. -Relative 18 | 19 | Import-Module $(Resolve-Path "$baseDir\src\packages\psake.4.6.0\tools\psake.psm1") 20 | 21 | $properties = @{} 22 | foreach ($parameterKey in $PSBoundParameters.Keys) 23 | { 24 | if ($parameterKey -eq "taskList") 25 | { 26 | continue 27 | } 28 | 29 | $properties.Add($parameterKey, $PSBoundParameters[$parameterKey]) 30 | } 31 | 32 | Invoke-psake "$buildDir\build-configuration.ps1" -taskList $taskList -properties $properties -------------------------------------------------------------------------------- /build/coverity.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [Parameter()] 3 | [string] $configuration, 4 | [Parameter()] 5 | [string] $preReleaseTag, 6 | [Parameter()] 7 | [string] $buildNumber, 8 | [Parameter()] 9 | [string] $gitExecutable, 10 | [Parameter()] 11 | [string] $dotNetExecutable 12 | ) 13 | 14 | 15 | $buildDir = $PSScriptRoot 16 | $baseDir = Resolve-Path $PSScriptRoot\.. -Relative 17 | 18 | 19 | if (-Not (Test-Path Artifacts)) 20 | { 21 | New-Item Artifacts -ItemType Directory > $null 22 | } 23 | 24 | if (Test-Path "Artifacts\Coverity") 25 | { 26 | Remove-Item "Artifacts\Coverity\*" -Force -Recurse 27 | } else { 28 | New-Item "Artifacts\Coverity" -ItemType Directory > $null 29 | } 30 | 31 | 32 | $buildArguments = "-taskList `"Build`" " 33 | 34 | foreach ($parameterKey in $PSBoundParameters.Keys) 35 | { 36 | $buildArguments += "-{0} `"{1}`" " -f $parameterKey,$PSBoundParameters[$parameterKey] 37 | } 38 | 39 | 40 | Invoke-Expression "cov-build.exe --dir $baseDir\Artifacts\Coverity powershell.exe `-NonInteractive `-File $buildDir\build.ps1 $buildArguments" 41 | 42 | & "$baseDir\src\packages\PublishCoverity.0.11.0\tools\PublishCoverity.exe" compress -o "$baseDir\Artifacts\Coverity\Coverity.zip" -i "$baseDir\Artifacts\Coverity" 43 | & "$baseDir\src\packages\PublishCoverity.0.11.0\tools\PublishCoverity.exe" publish -z "$baseDir\Artifacts\Coverity\Coverity.zip" -e "brandon.dahler@gmail.com" -r "brandondahler/Data.HashFunction" -t "$Env:COVERITY_TOKEN" --codeVersion "$preReleaseTag-$buildNumber" -------------------------------------------------------------------------------- /data_hashfunction_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/data_hashfunction_logo.png -------------------------------------------------------------------------------- /doxygen/doxygen-awesome-LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 - 2023 jothepro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /doxygen/doxygen-awesome-sidebar-only-darkmode-toggle.css: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | 4 | Doxygen Awesome 5 | https://github.com/jothepro/doxygen-awesome-css 6 | 7 | MIT License 8 | 9 | Copyright (c) 2021 - 2023 jothepro 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | 29 | */ 30 | 31 | @media screen and (min-width: 768px) { 32 | 33 | #MSearchBox { 34 | width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - var(--searchbar-height) - 1px); 35 | } 36 | 37 | #MSearchField { 38 | width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - 66px - var(--searchbar-height)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /doxygen/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/doxygen/logo.png -------------------------------------------------------------------------------- /src/.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/BernsteinHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.BernsteinHash; 4 | using System.Text; 5 | 6 | namespace Data.HashFunction.BernsteinHash 7 | { 8 | /// 9 | /// Provides instances of implementations of . 10 | /// 11 | public sealed class BernsteinHashFactory 12 | : IBernsteinHashFactory 13 | { 14 | /// 15 | /// Gets the singleton instance of this factory. 16 | /// 17 | public static IBernsteinHashFactory Instance { get; } = new BernsteinHashFactory(); 18 | 19 | 20 | private BernsteinHashFactory() 21 | { 22 | 23 | } 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// 29 | /// A instance. 30 | /// 31 | public IBernsteinHash Create() 32 | { 33 | return new BernsteinHash_Implementation(); 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/BernsteinHash_Implementation.cs: -------------------------------------------------------------------------------- 1 | using Data.HashFunction.BernsteinHash; 2 | using Data.HashFunction.Core; 3 | using Data.HashFunction.Core.Utilities; 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace Data.HashFunction.BernsteinHash 10 | { 11 | internal class BernsteinHash_Implementation 12 | : StreamableHashFunctionBase, 13 | IBernsteinHash 14 | { 15 | public override int HashSizeInBits { get; } = 32; 16 | 17 | 18 | public override IBlockTransformer CreateBlockTransformer() => 19 | new BlockTransformer(); 20 | 21 | 22 | private class BlockTransformer 23 | : BlockTransformerBase 24 | { 25 | private UInt32 _hashValue; 26 | 27 | 28 | protected override void CopyStateTo(BlockTransformer other) 29 | { 30 | base.CopyStateTo(other); 31 | 32 | other._hashValue = _hashValue; 33 | } 34 | 35 | protected override void TransformByteGroupsInternal(ArraySegment data) 36 | { 37 | var dataArray = data.Array; 38 | var endOffset = data.Offset + data.Count; 39 | 40 | var tempHashValue = _hashValue; 41 | 42 | for (var currentOffset = data.Offset; currentOffset < endOffset; ++currentOffset) 43 | tempHashValue = (33 * tempHashValue) + dataArray[currentOffset]; 44 | 45 | _hashValue = tempHashValue; 46 | } 47 | 48 | protected override IHashValue FinalizeHashValueInternal(CancellationToken cancellationToken) 49 | { 50 | return new HashValue( 51 | BitConverter.GetBytes(_hashValue), 52 | 32); 53 | } 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/IBernsteinHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BernsteinHash 6 | { 7 | /// 8 | /// Implementation of Bernstein hash as specified at http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx#djb. 9 | /// 10 | /// From http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx#djb: 11 | /// " 12 | /// Dan Bernstein created this algorithm and posted it in a newsgroup. 13 | /// It is known by many as the Chris Torek hash because Chris went a long way toward popularizing it. 14 | /// Since then it has been used successfully by many, but despite that the algorithm itself is not very sound 15 | /// when it comes to avalanche and permutation of the internal state. 16 | /// It has proven very good for small character keys, where it can outperform algorithms that result 17 | /// in a more random distribution. 18 | /// 19 | /// Bernstein's hash should be used with caution. 20 | /// It performs very well in practice, for no apparently known reasons 21 | /// (much like how the constant 33 does better than more logical constants for no apparent reason), 22 | /// but in theory it is not up to snuff. 23 | /// Always test this function with sample data for every application to ensure that it does not encounter 24 | /// a degenerate case and cause excessive collisions. 25 | /// " 26 | /// 27 | public interface IBernsteinHash 28 | : IStreamableHashFunction 29 | { 30 | 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/IBernsteinHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BernsteinHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IBernsteinHashFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IBernsteinHash Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/IModifiedBernsteinHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BernsteinHash 6 | { 7 | /// 8 | /// Implementation of Modified Bernstein hash as specified at http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx#djb2. 9 | /// 10 | /// " 11 | /// [The Modified Bernstein hash is a] minor update to Bernstein's hash which replaces addition with 12 | /// XOR for the combining step. 13 | /// This change does not appear to be well known or often used, the original algorithm is still 14 | /// recommended by nearly everyone, but the new algorithm typically results in a better distribution. 15 | /// 16 | /// Dan Bernstein created [the Bernstein hash] algorithm and posted it in a newsgroup. 17 | /// It is known by many as the Chris Torek hash because Chris went a long way toward popularizing it. 18 | /// Since then it has been used successfully by many, but despite that the algorithm itself is not very sound 19 | /// when it comes to avalanche and permutation of the internal state. 20 | /// It has proven very good for small character keys, where it can outperform algorithms that result 21 | /// in a more random distribution. 22 | /// 23 | /// Bernstein's hash should be used with caution. 24 | /// It performs very well in practice, for no apparently known reasons 25 | /// (much like how the constant 33 does better than more logical constants for no apparent reason), 26 | /// but in theory it is not up to snuff. 27 | /// Always test this function with sample data for every application to ensure that it does not encounter 28 | /// a degenerate case and cause excessive collisions. 29 | /// " 30 | /// 31 | public interface IModifiedBernsteinHash 32 | : IStreamableHashFunction 33 | { 34 | 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/IModifiedBernsteinHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BernsteinHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IModifiedBernsteinHashFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IModifiedBernsteinHash Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/ModifiedBernsteinHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BernsteinHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class ModifiedBernsteinHashFactory 11 | : IModifiedBernsteinHashFactory 12 | { 13 | 14 | /// 15 | /// Gets the singleton instance of this factory. 16 | /// 17 | public static IModifiedBernsteinHashFactory Instance { get; } = new ModifiedBernsteinHashFactory(); 18 | 19 | 20 | private ModifiedBernsteinHashFactory() 21 | { 22 | 23 | } 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// 29 | /// A instance. 30 | /// 31 | public IModifiedBernsteinHash Create() 32 | { 33 | return new ModifiedBernsteinHash_Implementation(); 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/ModifiedBernsteinHash_Implementation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Core; 4 | using Data.HashFunction.Core.Utilities; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Runtime.CompilerServices; 8 | using System.Text; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace Data.HashFunction.BernsteinHash 13 | { 14 | internal class ModifiedBernsteinHash_Implementation 15 | : StreamableHashFunctionBase, 16 | IModifiedBernsteinHash 17 | { 18 | public override int HashSizeInBits { get; } = 32; 19 | 20 | 21 | public override IBlockTransformer CreateBlockTransformer() => 22 | new BlockTransformer(); 23 | 24 | 25 | private class BlockTransformer 26 | : BlockTransformerBase 27 | { 28 | private UInt32 _hashValue; 29 | 30 | 31 | protected override void CopyStateTo(BlockTransformer other) 32 | { 33 | base.CopyStateTo(other); 34 | 35 | other._hashValue = _hashValue; 36 | } 37 | 38 | protected override void TransformByteGroupsInternal(ArraySegment data) 39 | { 40 | var dataArray = data.Array; 41 | var endOffset = data.Offset + data.Count; 42 | 43 | var tempHashValue = _hashValue; 44 | 45 | for (var currentOffset = data.Offset; currentOffset < endOffset; ++currentOffset) 46 | tempHashValue = (33 * tempHashValue) ^ dataArray[currentOffset]; 47 | 48 | _hashValue = tempHashValue; 49 | } 50 | 51 | protected override IHashValue FinalizeHashValueInternal(CancellationToken cancellationToken) 52 | { 53 | return new HashValue( 54 | BitConverter.GetBytes(_hashValue), 55 | 32); 56 | } 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BernsteinHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.BernsteinHash")] 6 | [assembly: AssemblyProduct("Data.HashFunction.BernsteinHash")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/Blake2BConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Data.HashFunction.Blake2 5 | { 6 | /// 7 | /// Defines a configuration for a Blake2B hash function implementation. 8 | /// 9 | public class Blake2BConfig 10 | : IBlake2BConfig 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | /// 19 | /// Defaults to 512. 20 | /// 21 | public int HashSizeInBits { get; set; } = 512; 22 | 23 | 24 | /// 25 | /// Gets the key. 26 | /// 27 | /// 28 | /// The key. 29 | /// 30 | /// 31 | /// Defaults to null. 32 | /// 33 | public IReadOnlyList Key { get; set; } = null; 34 | 35 | /// 36 | /// Gets the salt. 37 | /// 38 | /// 39 | /// The salt. 40 | /// 41 | /// 42 | /// Defaults to null. 43 | /// 44 | public IReadOnlyList Salt { get; set; } = null; 45 | 46 | /// 47 | /// Gets the personalization sequence. 48 | /// 49 | /// 50 | /// The personalization sequence. 51 | /// 52 | /// 53 | /// Defaults to null. 54 | /// 55 | public IReadOnlyList Personalization { get; set; } = null; 56 | 57 | 58 | 59 | /// 60 | /// Makes a deep clone of current instance. 61 | /// 62 | /// A deep clone of the current instance. 63 | public IBlake2BConfig Clone() => 64 | new Blake2BConfig() { 65 | HashSizeInBits = HashSizeInBits, 66 | Key = Key?.ToArray(), 67 | Salt = Salt?.ToArray(), 68 | Personalization = Personalization?.ToArray(), 69 | }; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/Blake2BFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake2 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class Blake2BFactory 11 | : IBlake2BFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IBlake2BFactory Instance { get; } = new Blake2BFactory(); 17 | 18 | 19 | private Blake2BFactory() 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Creates a new instance with the default configuration. 26 | /// 27 | /// 28 | /// A instance. 29 | /// 30 | public IBlake2B Create() 31 | { 32 | return Create(new Blake2BConfig()); 33 | } 34 | 35 | /// 36 | /// Creates a new instance with given configuration. 37 | /// 38 | /// The configuration to use. 39 | /// 40 | /// A instance. 41 | /// 42 | /// 43 | public IBlake2B Create(IBlake2BConfig config) 44 | { 45 | if (config == null) 46 | throw new ArgumentNullException(nameof(config)); 47 | 48 | return new Blake2B_Implementation(config); 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/IBlake2B.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake2 6 | { 7 | /// 8 | /// Implementation of BLAKE2b as specified at https://blake2.net/. Implementations are expected to support 9 | /// hash output sizes of 8 through 512 bits in 8-bit increments and allowing it to be seeded with a key, salt, 10 | /// and/or personalization sequence. 11 | /// 12 | public interface IBlake2B 13 | : IStreamableHashFunction 14 | { 15 | /// 16 | /// Configuration used when creating this instance. 17 | /// 18 | /// 19 | /// A clone of configuration that was used when creating this instance. 20 | /// 21 | IBlake2BConfig Config { get; } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/IBlake2BConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake2 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IBlake2BConfig 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | int HashSizeInBits { get; } 19 | 20 | 21 | /// 22 | /// Gets the key. 23 | /// 24 | /// 25 | /// The key. 26 | /// 27 | IReadOnlyList Key { get; } 28 | 29 | /// 30 | /// Gets the salt. 31 | /// 32 | /// 33 | /// The salt. 34 | /// 35 | IReadOnlyList Salt { get; } 36 | 37 | /// 38 | /// Gets the personalization sequence. 39 | /// 40 | /// 41 | /// The personalization sequence. 42 | /// 43 | IReadOnlyList Personalization { get; } 44 | 45 | 46 | 47 | /// 48 | /// Makes a deep clone of current instance. 49 | /// 50 | /// A deep clone of the current instance. 51 | IBlake2BConfig Clone(); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/IBlake2BFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake2 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IBlake2BFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IBlake2B Create(); 17 | 18 | 19 | /// 20 | /// Creates a new instance with given configuration. 21 | /// 22 | /// The configuration to use. 23 | /// A instance. 24 | IBlake2B Create(IBlake2BConfig config); 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Blake2")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Blake2")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake2/Utilities/UInt128.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Data.HashFunction.Blake2.Utilities 8 | { 9 | 10 | internal struct UInt128 11 | { 12 | public UInt64 Low { get; } 13 | public UInt64 High { get; } 14 | 15 | 16 | public UInt128(UInt64 low) 17 | : this(low, 0) 18 | { 19 | 20 | } 21 | 22 | public UInt128(UInt64 low, UInt64 high) 23 | { 24 | Low = low; 25 | High = high; 26 | } 27 | 28 | 29 | public static UInt128 operator +(UInt128 a, UInt128 b) 30 | { 31 | var carryOver = 0UL; 32 | var lowResult = unchecked(a.Low + b.Low); 33 | 34 | if (lowResult < a.Low) 35 | carryOver = 1UL; 36 | 37 | 38 | return new UInt128(lowResult, a.High + b.High + carryOver); 39 | } 40 | 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/Blake3Config.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Data.HashFunction.Blake3 5 | { 6 | /// 7 | /// Defines a configuration for a Blake2B hash function implementation. 8 | /// 9 | public class Blake3Config 10 | : IBlake3Config 11 | { 12 | /// 13 | /// The default hash size, in bits. 14 | /// 15 | public const int DefaultHashSizeInBits = 32; 16 | 17 | /// 18 | /// Gets the desired hash size, in bits. 19 | /// 20 | /// 21 | /// The desired hash size, in bits. 22 | /// 23 | /// 24 | /// Defaults to 32. 25 | /// 26 | public int HashSizeInBits { get; set; } = DefaultHashSizeInBits; 27 | 28 | /// 29 | /// Makes a deep clone of current instance. 30 | /// 31 | /// A deep clone of the current instance. 32 | public IBlake3Config Clone() => 33 | new Blake3Config() { 34 | HashSizeInBits = HashSizeInBits 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/Blake3Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake3 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class Blake3Factory 11 | : IBlake3Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IBlake3Factory Instance { get; } = new Blake3Factory(); 17 | 18 | 19 | private Blake3Factory() 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Creates a new instance with the default configuration. 26 | /// 27 | /// 28 | /// A instance. 29 | /// 30 | public IBlake3 Create() 31 | { 32 | return Create(new Blake3Config()); 33 | } 34 | 35 | /// 36 | /// Creates a new instance with given configuration. 37 | /// 38 | /// The configuration to use. 39 | /// 40 | /// A instance. 41 | /// 42 | /// 43 | public IBlake3 Create(IBlake3Config config) 44 | { 45 | if (config == null) 46 | throw new ArgumentNullException(nameof(config)); 47 | 48 | return new Blake3_Implementation(config); 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/Blake3_Implementation.cs: -------------------------------------------------------------------------------- 1 | using Data.HashFunction.Core; 2 | using Data.HashFunction.Core.Utilities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using System.Security.Cryptography; 8 | using System.Threading; 9 | 10 | namespace Data.HashFunction.Blake3 11 | { 12 | internal partial class Blake3_Implementation 13 | : HashFunctionBase, 14 | IBlake3 15 | { 16 | private readonly IBlake3Config _config; 17 | public IBlake3Config Config => _config.Clone(); 18 | 19 | public const int MinHashSizeInBits = 8; 20 | public const int MaxHashSizeInBits = 4096; 21 | 22 | public Blake3_Implementation(IBlake3Config config) 23 | { 24 | if (config == null) 25 | throw new ArgumentNullException(nameof(config)); 26 | 27 | _config = config.Clone(); 28 | 29 | if (_config.HashSizeInBits < MinHashSizeInBits || _config.HashSizeInBits > MaxHashSizeInBits) 30 | throw new ArgumentOutOfRangeException($"{nameof(config)}.{nameof(config.HashSizeInBits)}", _config.HashSizeInBits, $"Expected: {MinHashSizeInBits} >= {nameof(config)}.{nameof(config.HashSizeInBits)} <= {MaxHashSizeInBits}"); 31 | 32 | if (_config.HashSizeInBits % 8 != 0) 33 | throw new ArgumentOutOfRangeException($"{nameof(config)}.{nameof(config.HashSizeInBits)}", _config.HashSizeInBits, $"{nameof(config)}.{nameof(config.HashSizeInBits)} must be a multiple of 8."); 34 | } 35 | 36 | public override int HashSizeInBits => _config.HashSizeInBits; 37 | 38 | protected override IHashValue ComputeHashInternal(ArraySegment data, CancellationToken cancellationToken) 39 | { 40 | byte[] outputBuffer = new byte[Config.HashSizeInBits]; 41 | 42 | Span output = new Span(outputBuffer); 43 | Hasher.Hash(data.AsSpan(), output); 44 | 45 | return new HashValue(outputBuffer, Config.HashSizeInBits); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/IBlake3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake3 6 | { 7 | /// 8 | /// Implementation of BLAKE3 as specified at https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3. 9 | /// 10 | public interface IBlake3 11 | : IHashFunction 12 | { 13 | /// 14 | /// Configuration used when creating this instance. 15 | /// 16 | /// 17 | /// A clone of configuration that was used when creating this instance. 18 | /// 19 | IBlake3Config Config { get; } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/IBlake3Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake3 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IBlake3Config 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | /// 19 | /// Defaults to 32. 20 | /// 21 | int HashSizeInBits { get; } 22 | 23 | 24 | /// 25 | /// Makes a deep clone of current instance. 26 | /// 27 | /// A deep clone of the current instance. 28 | IBlake3Config Clone(); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/IBlake3Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Blake3 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IBlake3Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IBlake3 Create(); 17 | 18 | 19 | /// 20 | /// Creates a new instance with given configuration. 21 | /// 22 | /// The configuration to use. 23 | /// A instance. 24 | IBlake3 Create(IBlake3Config config); 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/linux-arm/native/libblake3_dotnet.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/linux-arm/native/libblake3_dotnet.so -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/linux-arm64/native/libblake3_dotnet.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/linux-arm64/native/libblake3_dotnet.so -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/linux-x64/native/libblake3_dotnet.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/linux-x64/native/libblake3_dotnet.so -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/osx-arm64/native/libblake3_dotnet.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/osx-arm64/native/libblake3_dotnet.dylib -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/osx-x64/native/libblake3_dotnet.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/osx-x64/native/libblake3_dotnet.dylib -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/win-arm64/native/blake3_dotnet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/win-arm64/native/blake3_dotnet.dll -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/win-x64/native/blake3_dotnet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/win-x64/native/blake3_dotnet.dll -------------------------------------------------------------------------------- /src/Data.HashFunction.Blake3/runtimes/win-x86/native/blake3_dotnet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Blake3/runtimes/win-x86/native/blake3_dotnet.dll -------------------------------------------------------------------------------- /src/Data.HashFunction.BuzHash/BuzHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BuzHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class BuzHashFactory 11 | : IBuzHashFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IBuzHashFactory Instance { get; } = new BuzHashFactory(); 17 | 18 | 19 | private BuzHashFactory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// 29 | /// A instance. 30 | /// 31 | public IBuzHash Create() 32 | { 33 | return Create(new DefaultBuzHashConfig()); 34 | } 35 | 36 | /// 37 | /// Creates a new instance with given configuration. 38 | /// 39 | /// The configuration to use. 40 | /// 41 | /// A instance. 42 | /// 43 | /// 44 | public IBuzHash Create(IBuzHashConfig config) 45 | { 46 | if (config == null) 47 | throw new ArgumentNullException(nameof(config)); 48 | 49 | return new BuzHash_Implementation(config); 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BuzHash/CircularShiftDirection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BuzHash 6 | { 7 | /// Enumeration of possible directions a circular shift can be defined for. 8 | public enum CircularShiftDirection 9 | { 10 | /// Shift bits left. 11 | Left, 12 | /// Shift bits right. 13 | Right 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BuzHash/IBuzHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BuzHash 6 | { 7 | /// 8 | /// Implementation of BuzHash as specified at http://www.serve.net/buz/hash.adt/java.002.html. 9 | /// 10 | /// Relies on a table of 256 (preferably distinct) 64-bit integers. 11 | /// Also can be set to use left or right rotation when running the rotate step. 12 | /// 13 | public interface IBuzHash 14 | : IStreamableHashFunction 15 | { 16 | 17 | /// 18 | /// Configuration used when creating this instance. 19 | /// 20 | /// 21 | /// A clone of configuration that was used when creating this instance. 22 | /// 23 | IBuzHashConfig Config { get; } 24 | 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BuzHash/IBuzHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Data.HashFunction.BuzHash 5 | { 6 | /// 7 | /// Defines a configuration for a implementation. 8 | /// 9 | public interface IBuzHashConfig 10 | { 11 | /// 12 | /// Gets a list of 256 (preferably random and distinct) values. 13 | /// 14 | /// 15 | /// List of 256 values. 16 | /// 17 | IReadOnlyList Rtab { get; } 18 | 19 | 20 | /// 21 | /// Gets the desired hash size, in bits. 22 | /// 23 | /// Implementations are expected to support sizes of 8, 16, 32, and 64. 24 | /// 25 | /// 26 | /// The desired hash size, in bits. 27 | /// 28 | int HashSizeInBits { get; } 29 | 30 | 31 | /// 32 | /// Gets the seed value. 33 | /// 34 | /// 35 | /// The seed value. 36 | /// 37 | /// 38 | /// Only the bottom bits shoudl be used for a given configuration. 39 | /// 40 | UInt64 Seed { get; } 41 | 42 | /// 43 | /// Gets the shift direction. 44 | /// 45 | /// 46 | /// The shift direction. 47 | /// 48 | CircularShiftDirection ShiftDirection { get; } 49 | 50 | 51 | 52 | /// 53 | /// Makes a deep clone of current instance. 54 | /// 55 | /// A deep clone of the current instance. 56 | IBuzHashConfig Clone(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BuzHash/IBuzHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.BuzHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IBuzHashFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IBuzHash Create(); 17 | 18 | 19 | /// 20 | /// Creates a new instance with given configuration. 21 | /// 22 | /// The configuration to use. 23 | /// A instance. 24 | IBuzHash Create(IBuzHashConfig config); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.BuzHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Buzhash")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Buzhash")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CRC/CRCFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CRC 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class CRCFactory 11 | : ICRCFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static ICRCFactory Instance { get; } = new CRCFactory(); 17 | 18 | 19 | private CRCFactory() 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Creates a new instance with the default configuration. 26 | /// 27 | /// 28 | /// A instance. 29 | /// 30 | public ICRC Create() 31 | { 32 | return Create(CRCConfig.CRC32); 33 | } 34 | 35 | /// 36 | /// Creates a new instance with given configuration. 37 | /// 38 | /// The configuration to use. 39 | /// 40 | /// A instance. 41 | /// 42 | public ICRC Create(ICRCConfig config) 43 | { 44 | if (config == null) 45 | throw new ArgumentNullException(nameof(config)); 46 | 47 | return new CRC_Implementation(config); 48 | } 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CRC/ICRC.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CRC 6 | { 7 | /// 8 | /// Implementation of the cyclic redundancy check error-detecting code as defined at http://en.wikipedia.org/wiki/Cyclic_redundancy_check. 9 | /// 10 | public interface ICRC 11 | : IStreamableHashFunction 12 | { 13 | 14 | 15 | /// 16 | /// Configuration used when creating this instance. 17 | /// 18 | /// 19 | /// A clone of configuration that was used when creating this instance. 20 | /// 21 | ICRCConfig Config { get; } 22 | 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CRC/ICRCFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CRC 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface ICRCFactory 11 | { 12 | 13 | /// 14 | /// Creates a new instance with the default configuration. 15 | /// 16 | /// A instance. 17 | ICRC Create(); 18 | 19 | 20 | /// 21 | /// Creates a new instance with given configuration. 22 | /// 23 | /// The configuration to use. 24 | /// A instance. 25 | ICRC Create(ICRCConfig config); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CRC/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.CRC")] 6 | [assembly: AssemblyProduct("Data.HashFunction.CRC")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/CityHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CityHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class CityHashConfig 11 | : ICityHashConfig 12 | { 13 | /// 14 | /// Gets the desired hash size, in bits. 15 | /// 16 | /// 17 | /// The desired hash size, in bits. 18 | /// 19 | /// Defaults to 32. 20 | public int HashSizeInBits { get; set; } = 32; 21 | 22 | 23 | 24 | /// 25 | /// Makes a deep clone of current instance. 26 | /// 27 | /// A deep clone of the current instance. 28 | public ICityHashConfig Clone() => 29 | new CityHashConfig() { 30 | HashSizeInBits = HashSizeInBits 31 | }; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/CityHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CityHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class CityHashFactory 11 | : ICityHashFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static ICityHashFactory Instance { get; } = new CityHashFactory(); 17 | 18 | 19 | private CityHashFactory() 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Creates a new instance with the default configuration. 26 | /// 27 | /// 28 | /// A instance. 29 | /// 30 | public ICityHash Create() 31 | { 32 | return Create(new CityHashConfig()); 33 | } 34 | 35 | /// 36 | /// Creates a new instance with given configuration. 37 | /// 38 | /// The configuration to use. 39 | /// 40 | /// A instance. 41 | /// 42 | /// 43 | public ICityHash Create(ICityHashConfig config) 44 | { 45 | if (config == null) 46 | throw new ArgumentNullException(nameof(config)); 47 | 48 | return new CityHash_Implementation(config); 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/ICityHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CityHash 6 | { 7 | 8 | /// 9 | /// Implementation of CityHash as specified at https://code.google.com/p/cityhash/. 10 | /// 11 | /// " 12 | /// CityHash provides hash functions for strings. The functions mix the 13 | /// input bits thoroughly but are not suitable for cryptography. 14 | /// 15 | /// [Hash size of 128-bits is] tuned for strings of at least a few hundred bytes. 16 | /// Depending on your compiler and hardware, it's likely faster than [the hash size of 64-bits] on 17 | /// sufficiently long strings. 18 | /// It's slower than necessary on shorter strings, but we expect that case to be relatively unimportant. 19 | /// " 20 | /// 21 | public interface ICityHash 22 | : IHashFunction 23 | { 24 | /// 25 | /// Configuration used when creating this instance. 26 | /// 27 | /// 28 | /// A clone of configuration that was used when creating this instance. 29 | /// 30 | ICityHashConfig Config { get; } 31 | 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/ICityHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CityHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface ICityHashConfig 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | int HashSizeInBits { get; } 19 | 20 | 21 | /// 22 | /// Makes a deep clone of current instance. 23 | /// 24 | /// A deep clone of the current instance. 25 | ICityHashConfig Clone(); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/ICityHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.CityHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface ICityHashFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | ICityHash Create(); 17 | 18 | 19 | /// 20 | /// Creates a new instance with given configuration. 21 | /// 22 | /// The configuration to use. 23 | /// 24 | /// A instance. 25 | /// 26 | /// 27 | ICityHash Create(ICityHashConfig config); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.CityHash")] 6 | [assembly: AssemblyProduct("Data.HashFunction.CityHash")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.CityHash/Utilities/UInt128.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Data.HashFunction.CityHash.Utilities 8 | { 9 | internal struct UInt128 10 | { 11 | public UInt64 Low { get; } 12 | public UInt64 High { get; } 13 | 14 | public UInt128(UInt64 low) 15 | : this(low, 0UL) 16 | { 17 | 18 | } 19 | 20 | public UInt128(UInt64 low, UInt64 high) 21 | { 22 | Low = low; 23 | High = high; 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Core/NativeLibraryLoader/Kernel32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using System.Text; 5 | 6 | namespace Data.HashFunction.Core.LibraryLoader 7 | { 8 | internal static class Kernel32 9 | { 10 | [DllImport("kernel32.dll")] 11 | public static extern IntPtr LoadLibrary(string fileName); 12 | 13 | [DllImport("kernel32.dll")] 14 | public static extern IntPtr GetProcAddress(IntPtr module, string procName); 15 | 16 | [DllImport("kernel32.dll")] 17 | public static extern int FreeLibrary(IntPtr module); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Core")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Core")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.ELF64/ELF64Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.ELF64 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class ELF64Factory 11 | : IELF64Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IELF64Factory Instance { get; } = new ELF64Factory(); 17 | 18 | 19 | private ELF64Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IELF64 Create() => new ELF64_Implementation(); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/Data.HashFunction.ELF64/IELF64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.ELF64 6 | { 7 | /// 8 | /// Implementation of the hash function used in the elf64 object file format as specified at 9 | /// http://downloads.openwatcom.org/ftp/devel/docs/elf-64-gen.pdf on page 17. 10 | /// 11 | /// Contrary to the name, the hash algorithm is only designed for 32-bit output hash sizes. 12 | /// 13 | public interface IELF64 14 | : IStreamableHashFunction 15 | { 16 | 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.ELF64/IELF64Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.ELF64 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IELF64Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IELF64 Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.ELF64/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.ELF64")] 6 | [assembly: AssemblyProduct("Data.HashFunction.ELF64")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/FNV1Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class FNV1Factory 11 | : IFNV1Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IFNV1Factory Instance { get; } = new FNV1Factory(); 17 | 18 | 19 | private FNV1Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IFNV1 Create() 30 | { 31 | return Create( 32 | FNVConfig.GetPredefinedConfig(64)); 33 | } 34 | 35 | /// 36 | /// Creates a new instance with the specified configuration. 37 | /// 38 | /// Configuration to use when constructing the instance. 39 | /// A instance. 40 | public IFNV1 Create(IFNVConfig config) 41 | { 42 | if (config == null) 43 | throw new ArgumentNullException(nameof(config)); 44 | 45 | return new FNV1_Implementation(config); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/FNV1aFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class FNV1aFactory 11 | : IFNV1aFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IFNV1aFactory Instance { get; } = new FNV1aFactory(); 17 | 18 | 19 | private FNV1aFactory() 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Creates a new instance with the default configuration. 26 | /// 27 | /// A instance. 28 | public IFNV1a Create() 29 | { 30 | return Create( 31 | FNVConfig.GetPredefinedConfig(64)); 32 | } 33 | 34 | /// 35 | /// Creates a new instance with the specified configuration. 36 | /// 37 | /// Configuration to use when constructing the instance. 38 | /// A instance. 39 | public IFNV1a Create(IFNVConfig config) 40 | { 41 | if (config == null) 42 | throw new ArgumentNullException(nameof(config)); 43 | 44 | return new FNV1a_Implementation(config); 45 | } 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/IFNV.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Implementation of Fowler–Noll–Vo hash function (FNV-1 or FNV-1a) as specified at http://www.isthe.com/chongo/tech/comp/fnv/index.html. 9 | /// 10 | public interface IFNV 11 | : IStreamableHashFunction 12 | { 13 | 14 | /// 15 | /// Configuration used when creating this instance. 16 | /// 17 | /// 18 | /// A clone of configuration that was used when creating this instance. 19 | /// 20 | IFNVConfig Config { get; } 21 | 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/IFNV1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Implementation of Fowler–Noll–Vo hash function (FNV-1) as specified at http://www.isthe.com/chongo/tech/comp/fnv/index.html. 9 | /// 10 | public interface IFNV1 11 | : IFNV 12 | { 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/IFNV1Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IFNV1Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IFNV1 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IFNV1 Create(IFNVConfig config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/IFNV1a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Implementation of Fowler–Noll–Vo hash function (FNV-1a) as specified at http://www.isthe.com/chongo/tech/comp/fnv/index.html. 9 | /// 10 | public interface IFNV1a 11 | : IFNV 12 | { 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/IFNV1aFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FNV 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IFNV1aFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IFNV1a Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IFNV1a Create(IFNVConfig config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/IFNVConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Numerics; 4 | using System.Text; 5 | 6 | namespace Data.HashFunction.FNV 7 | { 8 | /// 9 | /// Defines a configuration for a implementation. 10 | /// 11 | public interface IFNVConfig 12 | { 13 | /// 14 | /// Length of the produced hash, in bits. 15 | /// 16 | /// 17 | /// The length of the produced hash, in bits 18 | /// 19 | int HashSizeInBits { get; } 20 | 21 | /// 22 | /// The prime integer to use when calculating the FNV value. 23 | /// 24 | /// 25 | /// The prime value. 26 | /// 27 | BigInteger Prime { get; } 28 | 29 | /// 30 | /// The offset integer to use when calculating the FNV value. 31 | /// 32 | /// 33 | /// The offset value. 34 | /// 35 | BigInteger Offset { get; } 36 | 37 | 38 | 39 | /// 40 | /// Makes a deep clone of current instance. 41 | /// 42 | /// A deep clone of the current instance. 43 | IFNVConfig Clone(); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FNV/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.FNV")] 6 | [assembly: AssemblyProduct("Data.HashFunction.FNV")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/FarmHashFingerprint128Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class FarmHashFingerprint128Factory 11 | : IFarmHashFingerprint128Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IFarmHashFingerprint128Factory Instance { get; } = new FarmHashFingerprint128Factory(); 17 | 18 | 19 | private FarmHashFingerprint128Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance. 27 | /// 28 | /// A instance. 29 | public IFarmHashFingerprint128 Create() => 30 | new FarmHashFingerprint128_Implementation(); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/FarmHashFingerprint32Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class FarmHashFingerprint32Factory 11 | : IFarmHashFingerprint32Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IFarmHashFingerprint32Factory Instance { get; } = new FarmHashFingerprint32Factory(); 17 | 18 | 19 | private FarmHashFingerprint32Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance. 27 | /// 28 | /// A instance. 29 | public IFarmHashFingerprint32 Create() => 30 | new FarmHashFingerprint32_Implementation(); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/FarmHashFingerprint64Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class FarmHashFingerprint64Factory 11 | : IFarmHashFingerprint64Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IFarmHashFingerprint64Factory Instance { get; } = new FarmHashFingerprint64Factory(); 17 | 18 | 19 | private FarmHashFingerprint64Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance. 27 | /// 28 | /// A instance. 29 | public IFarmHashFingerprint64 Create() => 30 | new FarmHashFingerprint64_Implementation(); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/IFarmHashFingerprint128.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Implementation of FarmHash's Fingerprint128 method as specified at https://github.com/google/farmhash. 9 | /// 10 | public interface IFarmHashFingerprint128 11 | : IHashFunction 12 | { 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/IFarmHashFingerprint128Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IFarmHashFingerprint128Factory 11 | { 12 | /// 13 | /// Creates a new instance. 14 | /// 15 | /// A instance. 16 | IFarmHashFingerprint128 Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/IFarmHashFingerprint32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Implementation of FarmHash's Fingerprint32 method as specified at https://github.com/google/farmhash. 9 | /// 10 | public interface IFarmHashFingerprint32 11 | : IHashFunction 12 | { 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/IFarmHashFingerprint32Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IFarmHashFingerprint32Factory 11 | { 12 | /// 13 | /// Creates a new instance. 14 | /// 15 | /// A instance. 16 | IFarmHashFingerprint32 Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/IFarmHashFingerprint64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Implementation of FarmHash's Fingerprint64 method as specified at https://github.com/google/farmhash. 9 | /// 10 | public interface IFarmHashFingerprint64 11 | : IHashFunction 12 | { 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/IFarmHashFingerprint64Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IFarmHashFingerprint64Factory 11 | { 12 | /// 13 | /// Creates a new instance. 14 | /// 15 | /// A instance. 16 | IFarmHashFingerprint64 Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.FarmHash/Utilities/UInt128.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.FarmHash.Utilities 6 | { 7 | internal struct UInt128 8 | { 9 | public UInt64 Low { get; set; } 10 | public UInt64 High { get; set; } 11 | 12 | 13 | public UInt128(UInt64 low, UInt64 high ) 14 | { 15 | Low = low; 16 | High = high; 17 | } 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/Data.HashFunction.HashAlgorithm/HashAlgorithmWrapperConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Data.HashFunction.HashAlgorithm 9 | { 10 | using HashAlgorithm = System.Security.Cryptography.HashAlgorithm; 11 | 12 | /// 13 | /// Defines a configuration for a implementation. 14 | /// 15 | public class HashAlgorithmWrapperConfig 16 | : IHashAlgorithmWrapperConfig 17 | { 18 | /// 19 | /// A delegate that produces instances. 20 | /// 21 | /// 22 | /// The delegate. 23 | /// 24 | public Func InstanceFactory { get; set; } 25 | 26 | 27 | 28 | /// 29 | /// Makes a deep clone of current instance. 30 | /// 31 | /// A deep clone of the current instance. 32 | public IHashAlgorithmWrapperConfig Clone() => 33 | new HashAlgorithmWrapperConfig() { 34 | InstanceFactory = InstanceFactory 35 | }; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/Data.HashFunction.HashAlgorithm/HashAlgorithmWrapperFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Data.HashFunction.HashAlgorithm 8 | { 9 | /// 10 | /// Provides instances of implementations of . 11 | /// 12 | public class HashAlgorithmWrapperFactory 13 | : IHashAlgorithmWrapperFactory 14 | { 15 | /// 16 | /// Gets the singleton instance of this factory. 17 | /// 18 | public static IHashAlgorithmWrapperFactory Instance { get; } = new HashAlgorithmWrapperFactory(); 19 | 20 | 21 | private HashAlgorithmWrapperFactory() 22 | { 23 | 24 | } 25 | 26 | 27 | /// 28 | /// Creates a new instance with given configuration. 29 | /// 30 | /// The configuration to use. 31 | /// A instance. 32 | public IHashAlgorithmWrapper Create(IHashAlgorithmWrapperConfig config) 33 | { 34 | if (config == null) 35 | throw new ArgumentNullException(nameof(config)); 36 | 37 | return new HashAlgorithmWrapper_Implementation(config); 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/Data.HashFunction.HashAlgorithm/IHashAlgorithmWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace Data.HashFunction.HashAlgorithm 7 | { 8 | /// 9 | /// Implementation of that wraps cryptographic hash functions known as . 10 | /// 11 | public interface IHashAlgorithmWrapper 12 | : IHashFunction 13 | { 14 | 15 | /// 16 | /// Configuration used when creating this instance. 17 | /// 18 | /// 19 | /// A clone of configuration that was used when creating this instance. 20 | /// 21 | IHashAlgorithmWrapperConfig Config { get; } 22 | 23 | /// 24 | /// Computes hash value for given stream. 25 | /// 26 | /// Stream of data to hash. 27 | /// 28 | /// Hash value of the data. 29 | /// 30 | /// 31 | /// Stream must be readable.; 32 | /// Stream must be seekable for this type of hash function.; 33 | IHashValue ComputeHash(Stream data); 34 | 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.HashAlgorithm/IHashAlgorithmWrapperConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.HashAlgorithm 6 | { 7 | using HashAlgorithm = System.Security.Cryptography.HashAlgorithm; 8 | 9 | /// 10 | /// Defines a configuration for a implementation. 11 | /// 12 | public interface IHashAlgorithmWrapperConfig 13 | { 14 | /// 15 | /// A delegate that produces instances. 16 | /// 17 | /// 18 | /// The delegate. 19 | /// 20 | Func InstanceFactory { get; } 21 | 22 | 23 | 24 | /// 25 | /// Makes a deep clone of current instance. 26 | /// 27 | /// A deep clone of the current instance. 28 | IHashAlgorithmWrapperConfig Clone(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.HashAlgorithm/IHashAlgorithmWrapperFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.HashAlgorithm 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IHashAlgorithmWrapperFactory 11 | { 12 | 13 | /// 14 | /// Creates a new instance with given configuration. 15 | /// 16 | /// The configuration to use. 17 | /// A instance. 18 | IHashAlgorithmWrapper Create(IHashAlgorithmWrapperConfig config); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/Data.HashFunction.HashAlgorithm/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.HashAlgorithm")] 6 | [assembly: AssemblyProduct("Data.HashFunction.HashAlgorithm")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Interfaces/IHashValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Data.HashFunction 9 | { 10 | /// 11 | /// Common interface to represent a hash value. 12 | /// 13 | public interface IHashValue 14 | : IEquatable 15 | { 16 | /// 17 | /// Gets the length of the hash value in bits. 18 | /// 19 | /// 20 | /// The length of the hash value in bits. 21 | /// 22 | int BitLength { get; } 23 | 24 | /// 25 | /// Gets resulting byte array. 26 | /// 27 | /// 28 | /// The hash value. 29 | /// 30 | /// 31 | /// Implementations should coerce the input hash value to be size in bits. 32 | /// 33 | byte[] Hash { get; } 34 | 35 | 36 | /// 37 | /// Converts the hash value to a bit array. 38 | /// 39 | /// A instance to represent this hash value. 40 | BitArray AsBitArray(); 41 | 42 | /// 43 | /// Converts the hash value to a hexadecimal string. 44 | /// 45 | /// A hex string representing this hash value. 46 | string AsHexString(); 47 | 48 | /// 49 | /// Converts the hash value to a hexadecimal string. 50 | /// 51 | /// true if the result should use uppercase hex values; otherwise false. 52 | /// A hex string representing this hash value. 53 | string AsHexString(bool uppercase); 54 | 55 | /// 56 | /// Converts the hash value to a the base64 string. 57 | /// 58 | /// A base64 string representing this hash value. 59 | string AsBase64String(); 60 | 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Interfaces/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Interfaces")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Interfaces")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkins.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Implementation of Bob Jenkins' One at a Time, Lookup2, or Lookup3 hash function as specified at http://www.burtleburtle.net/bob/hash/doobs.html. 9 | /// 10 | public interface IJenkins 11 | : IStreamableHashFunction 12 | { 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsLookup2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Implementation of Bob Jenkins' Lookup2 hash function as specified at http://burtleburtle.net/bob/c/lookup2.c and http://www.burtleburtle.net/bob/hash/doobs.html. 9 | /// 10 | /// This hash function has been superseded by JenkinsLookup3. 11 | /// 12 | public interface IJenkinsLookup2 13 | : IJenkins 14 | { 15 | 16 | /// 17 | /// Configuration used when creating this instance. 18 | /// 19 | /// 20 | /// A clone of configuration that was used when creating this instance. 21 | /// 22 | IJenkinsLookup2Config Config { get; } 23 | 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsLookup2Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IJenkinsLookup2Config 11 | { 12 | 13 | /// 14 | /// Gets the seed. 15 | /// 16 | /// 17 | /// The seed. 18 | /// 19 | UInt32 Seed { get; } 20 | 21 | 22 | 23 | /// 24 | /// Makes a deep clone of current instance. 25 | /// 26 | /// A deep clone of the current instance. 27 | IJenkinsLookup2Config Clone(); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsLookup2Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IJenkinsLookup2Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IJenkinsLookup2 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IJenkinsLookup2 Create(IJenkinsLookup2Config config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsLookup3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Implementation of Bob Jenkins' Lookup3 hash function as specified at http://burtleburtle.net/bob/c/lookup3.c. 9 | /// 10 | public interface IJenkinsLookup3 11 | : IHashFunction 12 | { 13 | 14 | /// 15 | /// Configuration used when creating this instance. 16 | /// 17 | /// 18 | /// A clone of configuration that was used when creating this instance. 19 | /// 20 | IJenkinsLookup3Config Config { get; } 21 | 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsLookup3Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IJenkinsLookup3Config 11 | { 12 | 13 | /// 14 | /// Gets the desired hash size, in bits. 15 | /// 16 | /// 17 | /// The desired hash size, in bits. 18 | /// 19 | int HashSizeInBits { get; } 20 | 21 | 22 | /// 23 | /// Gets the seed. 24 | /// 25 | /// 26 | /// The seed. 27 | /// 28 | UInt32 Seed { get; } 29 | 30 | /// 31 | /// Gets the second seed. 32 | /// 33 | /// 34 | /// The second seed. 35 | /// 36 | UInt32 Seed2 { get; } 37 | 38 | 39 | 40 | /// 41 | /// Makes a deep clone of current instance. 42 | /// 43 | /// A deep clone of the current instance. 44 | IJenkinsLookup3Config Clone(); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsLookup3Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IJenkinsLookup3Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IJenkinsLookup3 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IJenkinsLookup3 Create(IJenkinsLookup3Config config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsOneAtATime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Implementation of Bob Jenkins' One-at-a-Time hash function as specified at http://www.burtleburtle.net/bob/hash/doobs.html (function named "one_at_a_time"). 9 | /// 10 | /// This hash function has been superseded by JenkinsLookup2 and JenkinsLookup3. 11 | /// 12 | public interface IJenkinsOneAtATime 13 | : IJenkins 14 | { 15 | 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/IJenkinsOneAtATimeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IJenkinsOneAtATimeFactory 11 | { 12 | /// 13 | /// Creates a new instance. 14 | /// 15 | /// A instance. 16 | IJenkinsOneAtATime Create(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/JenkinsLookup2Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class JenkinsLookup2Config 11 | : IJenkinsLookup2Config 12 | { 13 | /// 14 | /// Gets the seed. 15 | /// 16 | /// 17 | /// The seed. 18 | /// 19 | public UInt32 Seed { get; set; } = 0U; 20 | 21 | 22 | 23 | /// 24 | /// Makes a deep clone of current instance. 25 | /// 26 | /// A deep clone of the current instance. 27 | public IJenkinsLookup2Config Clone() => 28 | new JenkinsLookup2Config() { 29 | Seed = Seed 30 | }; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/JenkinsLookup2Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class JenkinsLookup2Factory 11 | : IJenkinsLookup2Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IJenkinsLookup2Factory Instance { get; } = new JenkinsLookup2Factory(); 17 | 18 | 19 | private JenkinsLookup2Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IJenkinsLookup2 Create() => 30 | Create(new JenkinsLookup2Config()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public IJenkinsLookup2 Create(IJenkinsLookup2Config config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new JenkinsLookup2_Implementation(config); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/JenkinsLookup3Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class JenkinsLookup3Config 11 | : IJenkinsLookup3Config 12 | { 13 | 14 | /// 15 | /// Gets the desired hash size, in bits. 16 | /// 17 | /// 18 | /// The desired hash size, in bits. 19 | /// 20 | public int HashSizeInBits { get; set; } = 32; 21 | 22 | /// 23 | /// Gets the seed. 24 | /// 25 | /// 26 | /// The seed. 27 | /// 28 | public UInt32 Seed { get; set; } = 0U; 29 | 30 | /// 31 | /// Gets the second seed. 32 | /// 33 | /// 34 | /// The second seed. 35 | /// 36 | public UInt32 Seed2 { get; set; } = 0U; 37 | 38 | 39 | 40 | /// 41 | /// Makes a deep clone of current instance. 42 | /// 43 | /// A deep clone of the current instance. 44 | public IJenkinsLookup3Config Clone() => 45 | new JenkinsLookup3Config() { 46 | HashSizeInBits = HashSizeInBits, 47 | Seed = Seed, 48 | Seed2 = Seed2 49 | }; 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/JenkinsLookup3Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class JenkinsLookup3Factory 11 | : IJenkinsLookup3Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IJenkinsLookup3Factory Instance { get; } = new JenkinsLookup3Factory(); 17 | 18 | 19 | private JenkinsLookup3Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IJenkinsLookup3 Create() => 30 | Create(new JenkinsLookup3Config()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public IJenkinsLookup3 Create(IJenkinsLookup3Config config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new JenkinsLookup3_Implementation(config); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/JenkinsOneAtATimeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Jenkins 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class JenkinsOneAtATimeFactory 11 | : IJenkinsOneAtATimeFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IJenkinsOneAtATimeFactory Instance { get; } = new JenkinsOneAtATimeFactory(); 17 | 18 | 19 | private JenkinsOneAtATimeFactory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance. 27 | /// 28 | /// A instance. 29 | public IJenkinsOneAtATime Create() => 30 | new JenkinsOneAtATime_Implementation(); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Jenkins/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Jenkins")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Jenkins")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/IMetroHash128.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Implementation of MetroHash128 as specified at https://github.com/jandrewrogers/MetroHash. 9 | /// 10 | /// " 11 | /// MetroHash is a set of state-of-the-art hash functions for non-cryptographic use cases. 12 | /// They are notable for being algorithmically generated in addition to their exceptional performance. 13 | /// The set of published hash functions may be expanded in the future, 14 | /// having been selected from a very large set of hash functions that have been constructed this way. 15 | /// " 16 | /// 17 | public interface IMetroHash128 18 | : IStreamableHashFunction 19 | { 20 | 21 | /// 22 | /// Configuration used when creating this instance. 23 | /// 24 | /// 25 | /// A clone of configuration that was used when creating this instance. 26 | /// 27 | IMetroHashConfig Config { get; } 28 | 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/IMetroHash128Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IMetroHash128Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IMetroHash128 Create(); 17 | 18 | 19 | /// 20 | /// Creates a new instance with given configuration. 21 | /// 22 | /// The configuration to use. 23 | /// 24 | /// A instance. 25 | /// 26 | /// 27 | IMetroHash128 Create(IMetroHashConfig config); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/IMetroHash64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Implementation of MetroHash64 as specified at https://github.com/jandrewrogers/MetroHash. 9 | /// 10 | /// " 11 | /// MetroHash is a set of state-of-the-art hash functions for non-cryptographic use cases. 12 | /// They are notable for being algorithmically generated in addition to their exceptional performance. 13 | /// The set of published hash functions may be expanded in the future, 14 | /// having been selected from a very large set of hash functions that have been constructed this way. 15 | /// " 16 | /// 17 | public interface IMetroHash64 18 | : IStreamableHashFunction 19 | { 20 | 21 | /// 22 | /// Configuration used when creating this instance. 23 | /// 24 | /// 25 | /// A clone of configuration that was used when creating this instance. 26 | /// 27 | IMetroHashConfig Config { get; } 28 | 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/IMetroHash64Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IMetroHash64Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IMetroHash64 Create(); 17 | 18 | 19 | /// 20 | /// Creates a new instance with given configuration. 21 | /// 22 | /// The configuration to use. 23 | /// 24 | /// A instance. 25 | /// 26 | /// 27 | IMetroHash64 Create(IMetroHashConfig config); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/IMetroHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Defines a configuration for a MetroHash implementation. 9 | /// 10 | public interface IMetroHashConfig 11 | { 12 | /// 13 | /// Gets the seed value. 14 | /// 15 | /// 16 | /// The seed value. 17 | /// 18 | UInt64 Seed { get; } 19 | 20 | /// 21 | /// Makes a deep clone of current instance. 22 | /// 23 | /// A deep clone of the current instance. 24 | IMetroHashConfig Clone(); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/MetroHash128Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class MetroHash128Factory 11 | : IMetroHash128Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IMetroHash128Factory Instance { get; } = new MetroHash128Factory(); 17 | 18 | 19 | private MetroHash128Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IMetroHash128 Create() => Create(new MetroHashConfig()); 30 | 31 | 32 | /// 33 | /// Creates a new instance with given configuration. 34 | /// 35 | /// The configuration to use. 36 | /// 37 | /// A instance. 38 | /// 39 | /// 40 | public IMetroHash128 Create(IMetroHashConfig config) 41 | { 42 | if (config == null) 43 | throw new ArgumentNullException(nameof(config)); 44 | 45 | return new MetroHash128_Implementation(config); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/MetroHash64Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public sealed class MetroHash64Factory 11 | : IMetroHash64Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IMetroHash64Factory Instance { get; } = new MetroHash64Factory(); 17 | 18 | 19 | private MetroHash64Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IMetroHash64 Create() => Create(new MetroHashConfig()); 30 | 31 | 32 | /// 33 | /// Creates a new instance with given configuration. 34 | /// 35 | /// The configuration to use. 36 | /// 37 | /// A instance. 38 | /// 39 | /// 40 | public IMetroHash64 Create(IMetroHashConfig config) 41 | { 42 | if (config == null) 43 | throw new ArgumentNullException(nameof(config)); 44 | 45 | return new MetroHash64_Implementation(config); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MetroHash/MetroHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MetroHash 6 | { 7 | /// 8 | /// Defines a configuration for a MetroHash implementation. 9 | /// 10 | public class MetroHashConfig 11 | : IMetroHashConfig 12 | { 13 | /// 14 | /// Gets the seed value. 15 | /// 16 | /// 17 | /// The seed value. 18 | /// 19 | public UInt64 Seed { get; set; } = 0; 20 | 21 | 22 | /// 23 | /// Makes a deep clone of current instance. 24 | /// 25 | /// A deep clone of the current instance. 26 | public IMetroHashConfig Clone() => 27 | new MetroHashConfig() { 28 | Seed = Seed 29 | }; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Implementation of MurmurHash1 as specified at https://github.com/aappleby/smhasher/blob/master/src/MurmurHash1.cpp 9 | /// and https://github.com/aappleby/smhasher/wiki/MurmurHash1. 10 | /// 11 | /// This hash function has been superseded by MurmurHash2 and MurmurHash3. 12 | /// 13 | public interface IMurmurHash1 14 | : IHashFunction 15 | { 16 | 17 | /// 18 | /// Configuration used when creating this instance. 19 | /// 20 | /// 21 | /// A clone of configuration that was used when creating this instance. 22 | /// 23 | IMurmurHash1Config Config { get; } 24 | 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash1Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IMurmurHash1Config 11 | { 12 | /// 13 | /// Gets the seed. 14 | /// 15 | /// 16 | /// The seed. 17 | /// 18 | UInt32 Seed { get; } 19 | 20 | 21 | 22 | /// 23 | /// Makes a deep clone of current instance. 24 | /// 25 | /// A deep clone of the current instance. 26 | IMurmurHash1Config Clone(); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash1Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IMurmurHash1Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IMurmurHash1 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IMurmurHash1 Create(IMurmurHash1Config config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Implementation of MurmurHash2 as specified at https://github.com/aappleby/smhasher/blob/master/src/MurmurHash2.cpp 9 | /// and https://github.com/aappleby/smhasher/wiki/MurmurHash2. 10 | /// 11 | /// This hash function has been superseded by MurmurHash3. 12 | /// 13 | public interface IMurmurHash2 14 | : IHashFunction 15 | { 16 | 17 | /// 18 | /// Configuration used when creating this instance. 19 | /// 20 | /// 21 | /// A clone of configuration that was used when creating this instance. 22 | /// 23 | IMurmurHash2Config Config { get; } 24 | 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash2Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IMurmurHash2Config 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | int HashSizeInBits { get; } 19 | 20 | /// 21 | /// Gets the seed. 22 | /// 23 | /// 24 | /// The seed. 25 | /// 26 | UInt64 Seed { get; } 27 | 28 | 29 | 30 | /// 31 | /// Makes a deep clone of current instance. 32 | /// 33 | /// A deep clone of the current instance. 34 | IMurmurHash2Config Clone(); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash2Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IMurmurHash2Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IMurmurHash2 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IMurmurHash2 Create(IMurmurHash2Config config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Implementation of MurmurHash3 as specified at https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp 9 | /// and https://github.com/aappleby/smhasher/wiki/MurmurHash3. 10 | /// 11 | public interface IMurmurHash3 12 | : IStreamableHashFunction 13 | { 14 | 15 | /// 16 | /// Configuration used when creating this instance. 17 | /// 18 | /// 19 | /// A clone of configuration that was used when creating this instance. 20 | /// 21 | IMurmurHash3Config Config { get; } 22 | 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash3Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IMurmurHash3Config 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | int HashSizeInBits { get; } 19 | 20 | /// 21 | /// Gets the seed. 22 | /// 23 | /// 24 | /// The seed. 25 | /// 26 | UInt32 Seed { get; } 27 | 28 | 29 | 30 | /// 31 | /// Makes a deep clone of current instance. 32 | /// 33 | /// A deep clone of the current instance. 34 | IMurmurHash3Config Clone(); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/IMurmurHash3Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IMurmurHash3Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IMurmurHash3 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IMurmurHash3 Create(IMurmurHash3Config config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/MurmurHash1Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class MurmurHash1Config 11 | : IMurmurHash1Config 12 | { 13 | /// 14 | /// Gets the seed. 15 | /// 16 | /// 17 | /// The seed. 18 | /// 19 | public UInt32 Seed { get; set; } = 0U; 20 | 21 | 22 | 23 | /// 24 | /// Makes a deep clone of current instance. 25 | /// 26 | /// A deep clone of the current instance. 27 | public IMurmurHash1Config Clone() => 28 | new MurmurHash1Config() { 29 | Seed = Seed 30 | }; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/MurmurHash1Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class MurmurHash1Factory 11 | : IMurmurHash1Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IMurmurHash1Factory Instance { get; } = new MurmurHash1Factory(); 17 | 18 | 19 | private MurmurHash1Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IMurmurHash1 Create() => 30 | Create(new MurmurHash1Config()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public IMurmurHash1 Create(IMurmurHash1Config config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new MurmurHash1_Implementation(config); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/MurmurHash2Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class MurmurHash2Config 11 | : IMurmurHash2Config 12 | { 13 | /// 14 | /// Gets the desired hash size, in bits. 15 | /// 16 | /// 17 | /// The desired hash size, in bits. 18 | /// 19 | public int HashSizeInBits { get; set; } = 64; 20 | 21 | /// 22 | /// Gets the seed. 23 | /// 24 | /// 25 | /// The seed. 26 | /// 27 | public UInt64 Seed { get; set; } = 0UL; 28 | 29 | 30 | 31 | /// 32 | /// Makes a deep clone of current instance. 33 | /// 34 | /// A deep clone of the current instance. 35 | public IMurmurHash2Config Clone() => 36 | new MurmurHash2Config() { 37 | HashSizeInBits = HashSizeInBits, 38 | Seed = Seed 39 | }; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/MurmurHash2Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class MurmurHash2Factory 11 | : IMurmurHash2Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IMurmurHash2Factory Instance { get; } = new MurmurHash2Factory(); 17 | 18 | 19 | private MurmurHash2Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IMurmurHash2 Create() => 30 | Create(new MurmurHash2Config()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public IMurmurHash2 Create(IMurmurHash2Config config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new MurmurHash2_Implementation(config); 43 | } 44 | 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/MurmurHash3Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class MurmurHash3Config 11 | : IMurmurHash3Config 12 | { 13 | /// 14 | /// Gets the desired hash size, in bits. 15 | /// 16 | /// 17 | /// The desired hash size, in bits. 18 | /// 19 | public int HashSizeInBits { get; set; } = 32; 20 | 21 | /// 22 | /// Gets the seed. 23 | /// 24 | /// 25 | /// The seed. 26 | /// 27 | public UInt32 Seed { get; set; } = 0U; 28 | 29 | 30 | 31 | /// 32 | /// Makes a deep clone of current instance. 33 | /// 34 | /// A deep clone of the current instance. 35 | public IMurmurHash3Config Clone() => 36 | new MurmurHash3Config() { 37 | HashSizeInBits = HashSizeInBits, 38 | Seed = Seed 39 | }; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/MurmurHash3Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.MurmurHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class MurmurHash3Factory 11 | : IMurmurHash3Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IMurmurHash3Factory Instance { get; } = new MurmurHash3Factory(); 17 | 18 | 19 | private MurmurHash3Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IMurmurHash3 Create() => 30 | Create(new MurmurHash3Config()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public IMurmurHash3 Create(IMurmurHash3Config config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new MurmurHash3_Implementation(config); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Data.HashFunction.MurmurHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.MurmurHash")] 6 | [assembly: AssemblyProduct("Data.HashFunction.MurmurHash")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Pearson/IPearson.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Pearson 6 | { 7 | /// 8 | /// Implementation of Pearson hashing as specified at http://en.wikipedia.org/wiki/Pearson_hashing and 9 | /// http://cs.mwsu.edu/~griffin/courses/2133/downloads/Spring11/p677-pearson.pdf. 10 | /// 11 | public interface IPearson 12 | : IStreamableHashFunction 13 | { 14 | 15 | /// 16 | /// Configuration used when creating this instance. 17 | /// 18 | /// 19 | /// A clone of configuration that was used when creating this instance. 20 | /// 21 | IPearsonConfig Config { get; } 22 | 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Pearson/IPearsonConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Pearson 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IPearsonConfig 11 | { 12 | /// 13 | /// A 256-length lookup table that is a defined permutation of [0, 255]. 14 | /// 15 | /// 16 | /// The table. 17 | /// 18 | IReadOnlyList Table { get; } 19 | 20 | /// 21 | /// Gets the desired hash size, in bits. 22 | /// 23 | /// 24 | /// The desired hash size, in bits. 25 | /// 26 | int HashSizeInBits { get; } 27 | 28 | 29 | 30 | /// 31 | /// Makes a deep clone of current instance. 32 | /// 33 | /// A deep clone of the current instance. 34 | IPearsonConfig Clone(); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Pearson/IPearsonFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Pearson 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IPearsonFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IPearson Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IPearson Create(IPearsonConfig config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Pearson/PearsonConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Data.HashFunction.Pearson 7 | { 8 | /// 9 | /// Defines a configuration for a implementation. 10 | /// 11 | public class PearsonConfig 12 | : IPearsonConfig 13 | { 14 | /// 15 | /// A 256-length lookup table of a permutation of [0, 255]. 16 | /// 17 | /// 18 | /// The table. 19 | /// 20 | public IReadOnlyList Table { get; set; } = null; 21 | 22 | /// 23 | /// Gets the desired hash size, in bits. 24 | /// 25 | /// 26 | /// The desired hash size, in bits. 27 | /// 28 | public int HashSizeInBits { get; set; } = 8; 29 | 30 | 31 | 32 | /// 33 | /// Makes a deep clone of current instance. 34 | /// 35 | /// A deep clone of the current instance. 36 | public IPearsonConfig Clone() => 37 | new PearsonConfig() { 38 | Table = Table?.ToArray(), 39 | HashSizeInBits = HashSizeInBits 40 | }; 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Pearson/PearsonFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.Pearson 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class PearsonFactory 11 | : IPearsonFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IPearsonFactory Instance { get; } = new PearsonFactory(); 17 | 18 | 19 | private PearsonFactory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | /// 30 | /// Implementation uses a default instance of 31 | /// 32 | public IPearson Create() => 33 | Create(new WikipediaPearsonConfig()); 34 | 35 | /// 36 | /// Creates a new instance with the specified configuration. 37 | /// 38 | /// Configuration to use when constructing the instance. 39 | /// A instance. 40 | public IPearson Create(IPearsonConfig config) 41 | { 42 | if (config == null) 43 | throw new ArgumentNullException(nameof(config)); 44 | 45 | return new Pearson_Implementation(config); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Pearson/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Pearson")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Pearson")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Production.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/src/Data.HashFunction.Production.snk -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/ISpookyHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.SpookyHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface ISpookyHashConfig 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | int HashSizeInBits { get; } 19 | 20 | 21 | /// 22 | /// Gets the seed. 23 | /// 24 | /// 25 | /// The seed. 26 | /// 27 | UInt64 Seed { get; } 28 | 29 | 30 | /// 31 | /// Gets the second seed. 32 | /// 33 | /// 34 | /// The second seed. 35 | /// 36 | UInt64 Seed2 { get; } 37 | 38 | 39 | 40 | /// 41 | /// Makes a deep clone of current instance. 42 | /// 43 | /// A deep clone of the current instance. 44 | ISpookyHashConfig Clone(); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/ISpookyHashV1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.SpookyHash 6 | { 7 | /// 8 | /// Implementation of SpookyHash V1 as specified at http://burtleburtle.net/bob/hash/spooky.html. 9 | /// 10 | /// This hash function has been superseded by due to a loss of entropy from a 11 | /// coding error in the original specification. It still passes the hash function tests the creator set for it, 12 | /// but it is preferred that SpookyHash V2 is used. 13 | /// 14 | [Obsolete("SpookyHashV1 has known issues, use SpookyHashV2.")] 15 | public interface ISpookyHashV1 16 | : IStreamableHashFunction 17 | { 18 | 19 | /// 20 | /// Configuration used when creating this instance. 21 | /// 22 | /// 23 | /// A clone of configuration that was used when creating this instance. 24 | /// 25 | ISpookyHashConfig Config { get; } 26 | 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/ISpookyHashV1Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | #pragma warning disable CS0618 // Type or member is obsolete 6 | namespace Data.HashFunction.SpookyHash 7 | { 8 | /// 9 | /// Provides instances of implementations of . 10 | /// 11 | public interface ISpookyHashV1Factory 12 | { 13 | /// 14 | /// Creates a new instance with the default configuration. 15 | /// 16 | /// A instance. 17 | ISpookyHashV1 Create(); 18 | 19 | /// 20 | /// Creates a new instance with the specified configuration. 21 | /// 22 | /// Configuration to use when constructing the instance. 23 | /// A instance. 24 | ISpookyHashV1 Create(ISpookyHashConfig config); 25 | } 26 | } 27 | #pragma warning restore CS0618 // Type or member is obsolete 28 | 29 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/ISpookyHashV2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.SpookyHash 6 | { 7 | /// 8 | /// Implements SpookyHash V2 as specified at http://burtleburtle.net/bob/hash/spooky.html. 9 | /// 10 | public interface ISpookyHashV2 11 | : IStreamableHashFunction 12 | { 13 | 14 | /// 15 | /// Configuration used when creating this instance. 16 | /// 17 | /// 18 | /// A clone of configuration that was used when creating this instance. 19 | /// 20 | ISpookyHashConfig Config { get; } 21 | 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/ISpookyHashV2Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.SpookyHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface ISpookyHashV2Factory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | ISpookyHashV2 Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | ISpookyHashV2 Create(ISpookyHashConfig config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.SpookyHash")] 6 | [assembly: AssemblyProduct("Data.HashFunction.SpookyHash")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/SpookyHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.SpookyHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class SpookyHashConfig 11 | : ISpookyHashConfig 12 | { 13 | /// 14 | /// Gets the desired hash size, in bits. 15 | /// 16 | /// 17 | /// The desired hash size, in bits. 18 | /// 19 | public int HashSizeInBits { get; set; } = 128; 20 | 21 | 22 | /// 23 | /// Gets the seed. 24 | /// 25 | /// 26 | /// The seed. 27 | /// 28 | public UInt64 Seed { get; set; } = 0UL; 29 | 30 | /// 31 | /// Gets the second seed. 32 | /// 33 | /// 34 | /// The second seed. 35 | /// 36 | public UInt64 Seed2 { get; set; } = 0UL; 37 | 38 | 39 | 40 | /// 41 | /// Makes a deep clone of current instance. 42 | /// 43 | /// A deep clone of the current instance. 44 | public ISpookyHashConfig Clone() => 45 | new SpookyHashConfig() { 46 | HashSizeInBits = HashSizeInBits, 47 | Seed = Seed, 48 | Seed2 = Seed2 49 | }; 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/SpookyHashV1Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | #pragma warning disable CS0618 // Type or member is obsolete 6 | namespace Data.HashFunction.SpookyHash 7 | { 8 | /// 9 | /// Provides instances of implementations of . 10 | /// 11 | [Obsolete("SpookyHashV1 has known issues, use SpookyHashV2.")] 12 | public class SpookyHashV1Factory 13 | : ISpookyHashV1Factory 14 | { 15 | /// 16 | /// Gets the singleton instance of this factory. 17 | /// 18 | public static ISpookyHashV1Factory Instance { get; } = new SpookyHashV1Factory(); 19 | 20 | 21 | private SpookyHashV1Factory() 22 | { 23 | 24 | } 25 | 26 | 27 | /// 28 | /// Creates a new instance with the default configuration. 29 | /// 30 | /// A instance. 31 | public ISpookyHashV1 Create() => 32 | Create(new SpookyHashConfig()); 33 | 34 | /// 35 | /// Creates a new instance with the specified configuration. 36 | /// 37 | /// Configuration to use when constructing the instance. 38 | /// A instance. 39 | public ISpookyHashV1 Create(ISpookyHashConfig config) 40 | { 41 | if (config == null) 42 | throw new ArgumentNullException(nameof(config)); 43 | 44 | return new SpookyHashV1_Implementation(config); 45 | } 46 | } 47 | } 48 | #pragma warning restore CS0618 // Type or member is obsolete 49 | 50 | -------------------------------------------------------------------------------- /src/Data.HashFunction.SpookyHash/SpookyHashV2Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.SpookyHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class SpookyHashV2Factory 11 | : ISpookyHashV2Factory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static ISpookyHashV2Factory Instance { get; } = new SpookyHashV2Factory(); 17 | 18 | 19 | private SpookyHashV2Factory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public ISpookyHashV2 Create() => 30 | Create(new SpookyHashConfig()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public ISpookyHashV2 Create(ISpookyHashConfig config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new SpookyHashV2_Implementation(config); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/BernsteinHash/BernsteinHashFactory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.BernsteinHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.BernsteinHash 8 | { 9 | public class BernsteinHashFactory_Tests 10 | { 11 | [Fact] 12 | public void BernsteinHashFactory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(BernsteinHashFactory.Instance); 15 | Assert.IsType(BernsteinHashFactory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void BernsteinHashFactory_Create_Works() 20 | { 21 | var bernsteinHashFactory = BernsteinHashFactory.Instance; 22 | var bernsteinHash = bernsteinHashFactory.Create(); 23 | 24 | Assert.NotNull(bernsteinHash); 25 | Assert.IsType(bernsteinHash); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/BernsteinHash/BernsteinHash_Implementation_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.BernsteinHash; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.Text; 6 | using Xunit; 7 | 8 | namespace Data.HashFunction.Test.BernsteinHash 9 | { 10 | public class BernsteinHash_Implementation_Tests 11 | { 12 | 13 | [Fact] 14 | public void BernsteinHash_Implementation_HashSizeInBits_IsSet() 15 | { 16 | var bernsteinHash = new BernsteinHash_Implementation(); 17 | 18 | Assert.Equal(32, bernsteinHash.HashSizeInBits); 19 | } 20 | 21 | 22 | public class IStreamableHashFunction_Tests 23 | : IStreamableHashFunction_TestBase 24 | { 25 | protected override IEnumerable KnownValues { get; } = 26 | new KnownValue[] { 27 | new KnownValue(32, TestConstants.Empty, 0x00000000), 28 | new KnownValue(32, TestConstants.FooBar, 0xf6055bf9), 29 | new KnownValue(32, TestConstants.LoremIpsum, 0x24bdc248), 30 | }; 31 | 32 | protected override IBernsteinHash CreateHashFunction(int hashSize) 33 | { 34 | return new BernsteinHash_Implementation(); 35 | } 36 | } 37 | 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/BernsteinHash/ModifiedBernsteinHashFactory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.BernsteinHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.BernsteinHash 8 | { 9 | public class ModifiedBernsteinHashFactory_Tests 10 | { 11 | [Fact] 12 | public void ModifiedBernsteinHashFactory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(ModifiedBernsteinHashFactory.Instance); 15 | Assert.IsType(ModifiedBernsteinHashFactory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void ModifiedBernsteinHashFactory_Create_Works() 20 | { 21 | var modifiedBernsteinHashFactory = ModifiedBernsteinHashFactory.Instance; 22 | var modifiedBernsteinHash = modifiedBernsteinHashFactory.Create(); 23 | 24 | Assert.NotNull(modifiedBernsteinHash); 25 | Assert.IsType(modifiedBernsteinHash); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/BernsteinHash/ModifiedBernsteinHash_Implementation_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.BernsteinHash; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.Text; 6 | using Xunit; 7 | 8 | namespace Data.HashFunction.Test.BernsteinHash 9 | { 10 | public class ModifiedBernsteinHash_Implementation_Tests 11 | { 12 | 13 | [Fact] 14 | public void ModifiedBernsteinHash_Implementation_HashSizeInBits_IsSet() 15 | { 16 | var bernsteinHash = new BernsteinHash_Implementation(); 17 | 18 | Assert.Equal(32, bernsteinHash.HashSizeInBits); 19 | } 20 | 21 | 22 | public class IStreamableHashFunction_Tests 23 | : IStreamableHashFunction_TestBase 24 | { 25 | protected override IEnumerable KnownValues { get; } = 26 | new KnownValue[] { 27 | new KnownValue(32, TestConstants.Empty, 0x00000000), 28 | new KnownValue(32, TestConstants.FooBar, 0xf030b397), 29 | new KnownValue(32, TestConstants.LoremIpsum, 0xfeceaf2a), 30 | }; 31 | 32 | protected override IModifiedBernsteinHash CreateHashFunction(int hashSize) 33 | { 34 | return new ModifiedBernsteinHash_Implementation(); 35 | } 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Blake2/Blake2BConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Blake2; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.Blake2 8 | { 9 | public class Blake2BConfig_Tests 10 | { 11 | [Fact] 12 | public void Blake2BConfig_Defaults_HaventChanged() 13 | { 14 | var blake2BConfig = new Blake2BConfig(); 15 | 16 | Assert.Equal(512, blake2BConfig.HashSizeInBits); 17 | 18 | Assert.Null(blake2BConfig.Key); 19 | Assert.Null(blake2BConfig.Salt); 20 | Assert.Null(blake2BConfig.Personalization); 21 | } 22 | 23 | [Fact] 24 | public void Blake2BConfig_Clone_Works() 25 | { 26 | var blake2BConfig = new Blake2BConfig() { 27 | HashSizeInBits = 256, 28 | Key = new byte[64], 29 | Salt = new byte[16], 30 | Personalization = new byte[16], 31 | }; 32 | 33 | var blake2BConfigClone = blake2BConfig.Clone(); 34 | 35 | Assert.IsType(blake2BConfigClone); 36 | 37 | Assert.Equal(blake2BConfig.HashSizeInBits, blake2BConfigClone.HashSizeInBits); 38 | 39 | Assert.Equal(blake2BConfig.Key, blake2BConfigClone.Key); 40 | Assert.Equal(blake2BConfig.Salt, blake2BConfigClone.Salt); 41 | Assert.Equal(blake2BConfig.Personalization, blake2BConfigClone.Personalization); 42 | } 43 | 44 | [Fact] 45 | public void Blake2BConfig_Clone_WithNullArrays_Works() 46 | { 47 | var blake2BConfig = new Blake2BConfig() { 48 | Key = null, 49 | Salt = null, 50 | Personalization = null, 51 | }; 52 | 53 | 54 | var blake2BConfigClone = blake2BConfig.Clone(); 55 | 56 | Assert.IsType(blake2BConfigClone); 57 | 58 | Assert.Null(blake2BConfigClone.Key); 59 | Assert.Null(blake2BConfigClone.Salt); 60 | Assert.Null(blake2BConfigClone.Personalization); 61 | } 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Blake2/Utilities/UInt128_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Blake2.Utilities; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.Blake2.Utilities 8 | { 9 | public class UInt128_Tests 10 | { 11 | [Fact] 12 | public void UInt128_Constructor_LowOnly_Works() 13 | { 14 | var uint128 = new UInt128(1337UL); 15 | 16 | Assert.Equal(1337UL, uint128.Low); 17 | Assert.Equal(0UL, uint128.High); 18 | } 19 | 20 | [Fact] 21 | public void UInt128_Constructor_LowHigh_Works() 22 | { 23 | var uint128 = new UInt128(1337UL, 7331UL); 24 | 25 | Assert.Equal(1337UL, uint128.Low); 26 | Assert.Equal(7331UL, uint128.High); 27 | } 28 | 29 | 30 | [Fact] 31 | public void UInt128_opAddition_Works() 32 | { 33 | var x = new UInt128(1337UL); 34 | var y = x + new UInt128(1UL); 35 | 36 | Assert.Equal(1338UL, y.Low); 37 | Assert.Equal(0UL, y.High); 38 | } 39 | 40 | 41 | [Fact] 42 | public void UInt128_opAddition_WithCarryOver_Works() 43 | { 44 | var x = new UInt128(0xFFFFFFFFFFFFFFFFUL); 45 | var y = x + new UInt128(3UL); 46 | 47 | Assert.Equal(2UL, y.Low); 48 | Assert.Equal(1UL, y.High); 49 | } 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Blake3/Blake3Config_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Cryptography; 4 | using System.Text; 5 | using Xunit; 6 | using Data.HashFunction.Blake3; 7 | 8 | namespace Data.HashFunction.Test.Blake3 9 | { 10 | public class Blake3Config_Tests 11 | { 12 | [Fact] 13 | public void Blake3Config_Defaults_HaventChanged() 14 | { 15 | var blake3Config = new Blake3Config(); 16 | 17 | Assert.Equal(Blake3Config.DefaultHashSizeInBits, blake3Config.HashSizeInBits); 18 | } 19 | 20 | [Fact] 21 | public void Blake3Config_Clone_Works() 22 | { 23 | var blake3Config = new Blake3Config() { 24 | HashSizeInBits = 64, 25 | }; 26 | 27 | var blake3ConfigClone = blake3Config.Clone(); 28 | 29 | Assert.IsType(blake3ConfigClone); 30 | 31 | Assert.Equal(blake3Config.HashSizeInBits, blake3ConfigClone.HashSizeInBits); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Blake3/Blake3Factory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Cryptography; 4 | using System.Text; 5 | using Xunit; 6 | using Data.HashFunction.Blake3; 7 | 8 | namespace Data.HashFunction.Test.Blake3 9 | { 10 | public class Blake3Factory_Tests 11 | { 12 | [Fact] 13 | public void Blake3Factory_Instance_IsDefined() 14 | { 15 | Assert.NotNull(Blake3Factory.Instance); 16 | Assert.IsType(Blake3Factory.Instance); 17 | } 18 | 19 | [Fact] 20 | public void blake3Factory_Create_Config_IsNull_Throws() 21 | { 22 | var blake3Factory = Blake3Factory.Instance; 23 | 24 | Assert.Equal( 25 | "config", 26 | Assert.Throws( 27 | () => blake3Factory.Create(null)) 28 | .ParamName); 29 | } 30 | 31 | [Fact] 32 | public void blake3Factory_Create_Config_Works() 33 | { 34 | var blake3Config = new Blake3Config(); 35 | 36 | var blake3Factory = Blake3Factory.Instance; 37 | var blake3 = blake3Factory.Create(blake3Config); 38 | 39 | Assert.NotNull(blake3); 40 | Assert.IsType(blake3); 41 | 42 | var resultingBlake3Config = blake3.Config; 43 | 44 | Assert.Equal(resultingBlake3Config.HashSizeInBits, resultingBlake3Config.HashSizeInBits); 45 | Assert.Equal(resultingBlake3Config, resultingBlake3Config); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/CityHash/CityHashConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.CityHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.CityHash 8 | { 9 | public class CityHashConfig_Tests 10 | { 11 | [Fact] 12 | public void CityHashConfig_Defaults_HaventChanged() 13 | { 14 | var cityHashConfig = new CityHashConfig(); 15 | 16 | 17 | Assert.Equal(32, cityHashConfig.HashSizeInBits); 18 | } 19 | 20 | [Fact] 21 | public void CityHashConfig_Clone_Works() 22 | { 23 | var cityHashConfig = new CityHashConfig() { 24 | HashSizeInBits = 64, 25 | }; 26 | 27 | var cityHashConfigClone = cityHashConfig.Clone(); 28 | 29 | Assert.IsType(cityHashConfigClone); 30 | 31 | Assert.Equal(cityHashConfig.HashSizeInBits, cityHashConfigClone.HashSizeInBits); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/CityHash/CityHashFactory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.CityHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.CityHash 8 | { 9 | public class CityHashFactory_Tests 10 | { 11 | [Fact] 12 | public void CityHashFactory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(CityHashFactory.Instance); 15 | Assert.IsType(CityHashFactory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void CityHashFactory_Create_Works() 20 | { 21 | var defaultCityHashConfig = new CityHashConfig(); 22 | 23 | var cityHashFactory = CityHashFactory.Instance; 24 | var cityHash = cityHashFactory.Create(); 25 | 26 | Assert.NotNull(cityHash); 27 | Assert.IsType(cityHash); 28 | 29 | 30 | var resultingCityHashConfig = cityHash.Config; 31 | 32 | Assert.Equal(defaultCityHashConfig.HashSizeInBits, resultingCityHashConfig.HashSizeInBits); 33 | } 34 | 35 | 36 | [Fact] 37 | public void CityHashFactory_Create_Config_IsNull_Throws() 38 | { 39 | var cityHashFactory = CityHashFactory.Instance; 40 | 41 | Assert.Equal( 42 | "config", 43 | Assert.Throws( 44 | () => cityHashFactory.Create(null)) 45 | .ParamName); 46 | } 47 | 48 | [Fact] 49 | public void CityHashFactory_Create_Config_Works() 50 | { 51 | var cityHashConfig = new CityHashConfig() { 52 | HashSizeInBits = 64, 53 | }; 54 | 55 | var cityHashFactory = CityHashFactory.Instance; 56 | var cityHash = cityHashFactory.Create(cityHashConfig); 57 | 58 | Assert.NotNull(cityHash); 59 | Assert.IsType(cityHash); 60 | 61 | 62 | var resultingCityHashConfig = cityHash.Config; 63 | 64 | Assert.Equal(cityHashConfig.HashSizeInBits, resultingCityHashConfig.HashSizeInBits); 65 | } 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/CityHash/Utilities/UInt128_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.CityHash.Utilities; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.CityHash.Utilities 8 | { 9 | public class UInt128_Tests 10 | { 11 | [Fact] 12 | public void UInt128_Constructor_LowOnly_Works() 13 | { 14 | var uint128 = new UInt128(1337UL); 15 | 16 | Assert.Equal(1337UL, uint128.Low); 17 | Assert.Equal(0UL, uint128.High); 18 | } 19 | 20 | [Fact] 21 | public void UInt128_Constructor_LowHigh_Works() 22 | { 23 | var uint128 = new UInt128(1337UL, 7331UL); 24 | 25 | Assert.Equal(1337UL, uint128.Low); 26 | Assert.Equal(7331UL, uint128.High); 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Core/HashFunctionBase_Tests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using System; 3 | using System.Collections.Generic; 4 | using Data.HashFunction.Test._Mocks; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | 11 | namespace Data.HashFunction.Test.Core 12 | { 13 | public class HashFunctionBase_Tests 14 | { 15 | [Fact] 16 | public void HashFunctionBase_ComputeHash_ByteArray_IsNull_Throws() 17 | { 18 | var hashFunction = new HashFunctionImpl(); 19 | 20 | Assert.Equal("data", 21 | Assert.Throws(() => 22 | hashFunction.ComputeHash((byte[]) null)) 23 | .ParamName); 24 | } 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/ELF64/ELF64Factory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.ELF64; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.ELF64 8 | { 9 | public class ELF64Factory_Tests 10 | { 11 | [Fact] 12 | public void ELF64Factory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(ELF64Factory.Instance); 15 | Assert.IsType(ELF64Factory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void ELF64Factory_Create_Works() 20 | { 21 | var elf64Factory = ELF64Factory.Instance; 22 | var elf64 = elf64Factory.Create(); 23 | 24 | Assert.NotNull(elf64); 25 | Assert.IsType(elf64); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/ELF64/ELF64_Implementation_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.ELF64; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.Text; 6 | using Xunit; 7 | 8 | namespace Data.HashFunction.Test.ELF64 9 | { 10 | public class ELF64_Implementation_Tests 11 | { 12 | 13 | #region HashSizeInBits 14 | 15 | [Fact] 16 | public void ELF64_Implementation_HashSizeInBits_IsNotChanged() 17 | { 18 | var elf64 = new ELF64_Implementation(); 19 | 20 | Assert.Equal(32, elf64.HashSizeInBits); 21 | } 22 | 23 | #endregion 24 | 25 | 26 | 27 | public class IStreamableHashFunction_Tests_ELF64 28 | : IStreamableHashFunction_TestBase 29 | { 30 | protected override IEnumerable KnownValues { get; } = 31 | new KnownValue[] { 32 | new KnownValue(32, TestConstants.Empty, 0x00000000), 33 | new KnownValue(32, TestConstants.FooBar, 0x06d65882), 34 | new KnownValue(32, TestConstants.LoremIpsum, 0x09e0a53e), 35 | }; 36 | 37 | protected override IELF64 CreateHashFunction(int hashSize) => 38 | new ELF64_Implementation(); 39 | } 40 | 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FNV/FNV1Base_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FNV; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.FNV 8 | { 9 | public class FNV1Base_Tests 10 | { 11 | private abstract class FNV1Impl 12 | : FNV1Base 13 | { 14 | private FNV1Impl(IFNVConfig config) 15 | : base(config) 16 | { 17 | 18 | } 19 | 20 | public static UInt32[] _ExtendedMultiply(IReadOnlyList operand1, IReadOnlyList operand2, int hashSizeInBytes) => 21 | ExtendedMultiply(operand1, operand2, hashSizeInBytes); 22 | 23 | } 24 | 25 | 26 | [Fact] 27 | public void FNV1Base_ExtendedMultiply_WorksConversly() 28 | { 29 | var x = new UInt32[] { 65536, 1024 }; 30 | var y = new UInt32[] { 524288, 65536, 1024, 8 }; 31 | 32 | var expectedValue = new UInt32[] { 0, 536870920, 134217729, 1572864 }; 33 | 34 | 35 | Assert.Equal(expectedValue, FNV1Impl._ExtendedMultiply(x, y, 16)); 36 | Assert.Equal(expectedValue, FNV1Impl._ExtendedMultiply(y, x, 16)); 37 | 38 | } 39 | 40 | 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FarmHash/FarmHashFingerprint128Factory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FarmHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.FarmHash 8 | { 9 | public class FarmHashFingerprint128Factory_Tests 10 | { 11 | [Fact] 12 | public void FarmHashFingerprint128Factory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(FarmHashFingerprint128Factory.Instance); 15 | Assert.IsType(FarmHashFingerprint128Factory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void FarmHashFingerprint128Factory_Create_Works() 20 | { 21 | var farmHashFingerprint128Factory = FarmHashFingerprint128Factory.Instance; 22 | var farmHashFingerprint128 = farmHashFingerprint128Factory.Create(); 23 | 24 | Assert.NotNull(farmHashFingerprint128); 25 | Assert.IsType(farmHashFingerprint128); 26 | } 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FarmHash/FarmHashFingerprint32Factory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FarmHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.FarmHash 8 | { 9 | public class FarmHashFingerprint32Factory_Tests 10 | { 11 | [Fact] 12 | public void FarmHashFingerprint32Factory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(FarmHashFingerprint32Factory.Instance); 15 | Assert.IsType(FarmHashFingerprint32Factory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void FarmHashFingerprint32Factory_Create_Works() 20 | { 21 | var farmHashFingerprint32Factory = FarmHashFingerprint32Factory.Instance; 22 | var farmHashFingerprint32 = farmHashFingerprint32Factory.Create(); 23 | 24 | Assert.NotNull(farmHashFingerprint32); 25 | Assert.IsType(farmHashFingerprint32); 26 | } 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FarmHash/FarmHashFingerprint32_Implementation_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FarmHash; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.Linq; 6 | using System.Text; 7 | using Xunit; 8 | 9 | namespace Data.HashFunction.Test.FarmHash 10 | { 11 | public class FarmHashFingerprint32_Implementation_Tests 12 | { 13 | 14 | #region Constructor 15 | 16 | [Fact] 17 | public void FarmHashFingerprint32_Implementation_Constructor_Works() 18 | { 19 | GC.KeepAlive( 20 | new FarmHashFingerprint32_Implementation()); 21 | } 22 | 23 | #endregion 24 | 25 | #region HashSizeInBits 26 | 27 | [Fact] 28 | public void FarmHashFingerprint32_Implementation_HashSizeInBits_Is32() 29 | { 30 | var farmHash = new FarmHashFingerprint32_Implementation(); 31 | 32 | Assert.Equal(32, farmHash.HashSizeInBits); 33 | } 34 | 35 | #endregion 36 | 37 | 38 | 39 | public class IHashFunction_Tests 40 | : IHashFunction_TestBase 41 | { 42 | protected override IEnumerable KnownValues { get; } = 43 | new KnownValue[] { 44 | new KnownValue(32, TestConstants.Empty, 0xdc56d17a), 45 | new KnownValue(32, TestConstants.FooBar.Take(3), 0x6b5025e3), 46 | new KnownValue(32, TestConstants.FooBar, 0xe2f34cdf), 47 | new KnownValue(32, TestConstants.LoremIpsum.Take(17), 0xe3e27892), 48 | new KnownValue(32, TestConstants.LoremIpsum, 0x6482ed0d), 49 | }; 50 | 51 | protected override IFarmHashFingerprint32 CreateHashFunction(int hashSize) => 52 | new FarmHashFingerprint32_Implementation(); 53 | } 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FarmHash/FarmHashFingerprint64Factory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FarmHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.FarmHash 8 | { 9 | public class FarmHashFingerprint64Factory_Tests 10 | { 11 | [Fact] 12 | public void FarmHashFingerprint64Factory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(FarmHashFingerprint64Factory.Instance); 15 | Assert.IsType(FarmHashFingerprint64Factory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void FarmHashFingerprint64Factory_Create_Works() 20 | { 21 | var farmHashFingerprint64Factory = FarmHashFingerprint64Factory.Instance; 22 | var farmHashFingerprint64 = farmHashFingerprint64Factory.Create(); 23 | 24 | Assert.NotNull(farmHashFingerprint64); 25 | Assert.IsType(farmHashFingerprint64); 26 | } 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FarmHash/FarmHashFingerprint64_Implementation_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FarmHash; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.Linq; 6 | using System.Text; 7 | using Xunit; 8 | 9 | namespace Data.HashFunction.Test.FarmHash 10 | { 11 | public class FarmHashFingerprint64_Implementation_Tests 12 | { 13 | 14 | #region Constructor 15 | 16 | [Fact] 17 | public void FarmHashFingerprint64_Implementation_Constructor_Works() 18 | { 19 | GC.KeepAlive( 20 | new FarmHashFingerprint64_Implementation()); 21 | } 22 | 23 | #endregion 24 | 25 | #region HashSizeInBits 26 | 27 | [Fact] 28 | public void FarmHashFingerprint64_Implementation_HashSizeInBits_Is64() 29 | { 30 | var farmHash = new FarmHashFingerprint64_Implementation(); 31 | 32 | Assert.Equal(64, farmHash.HashSizeInBits); 33 | } 34 | 35 | #endregion 36 | 37 | 38 | 39 | public class IHashFunction_Tests 40 | : IHashFunction_TestBase 41 | { 42 | protected override IEnumerable KnownValues { get; } = 43 | new KnownValue[] { 44 | new KnownValue(64, TestConstants.Empty, 0x9ae16a3b2f90404f), 45 | new KnownValue(64, TestConstants.FooBar.Take(3), 0x555c6f602f9383e3), 46 | new KnownValue(64, TestConstants.FooBar, 0xc43fb29ab5effcfe), 47 | new KnownValue(64, TestConstants.LoremIpsum.Take(13), 0x54145170e3383fcc), 48 | new KnownValue(64, TestConstants.LoremIpsum.Take(17), 0xbb25bd7ca089d86), 49 | new KnownValue(64, TestConstants.LoremIpsum.Take(50), 0x5462bf74ef4729b1), 50 | new KnownValue(64, TestConstants.LoremIpsum, 0x7975a177275d65bf), 51 | }; 52 | 53 | protected override IFarmHashFingerprint64 CreateHashFunction(int hashSize) => 54 | new FarmHashFingerprint64_Implementation(); 55 | } 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/FarmHash/Utilities/UInt128_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.FarmHash.Utilities; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.FarmHash.Utilities 8 | { 9 | public class UInt128_Tests 10 | { 11 | 12 | #region Constructor 13 | 14 | [Fact] 15 | public void UInt128_Constructor_Default_IsZero() 16 | { 17 | var uint128 = new UInt128(); 18 | 19 | Assert.Equal(0UL, uint128.Low); 20 | Assert.Equal(0UL, uint128.High); 21 | } 22 | 23 | [Fact] 24 | public void UInt128_Constructor_LowHigh_Works() 25 | { 26 | var uint128 = new UInt128(1337UL, 7331UL); 27 | 28 | Assert.Equal(1337UL, uint128.Low); 29 | Assert.Equal(7331UL, uint128.High); 30 | } 31 | 32 | #endregion 33 | 34 | #region Low 35 | 36 | [Fact] 37 | public void UInt128_Low_Works() 38 | { 39 | var uint128 = new UInt128(); 40 | 41 | Assert.Equal(0UL, uint128.Low); 42 | Assert.Equal(0UL, uint128.High); 43 | 44 | uint128.Low = 1337UL; 45 | Assert.Equal(1337UL, uint128.Low); 46 | Assert.Equal(0UL, uint128.High); 47 | } 48 | 49 | #endregion 50 | 51 | #region High 52 | 53 | [Fact] 54 | public void UInt128_High_Works() 55 | { 56 | var uint128 = new UInt128(); 57 | 58 | Assert.Equal(0UL, uint128.Low); 59 | Assert.Equal(0UL, uint128.High); 60 | 61 | uint128.High = 1337UL; 62 | Assert.Equal(0UL, uint128.Low); 63 | Assert.Equal(1337UL, uint128.High); 64 | } 65 | 66 | #endregion 67 | 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | // 6 | // To add a suppression to this file, right-click the message in the 7 | // Code Analysis results, point to "Suppress Message", and click 8 | // "In Suppression File". 9 | // You do not need to add suppressions to this file manually. 10 | 11 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations", Scope = "member", Target = "Data.HashFunction.Test.Mocks.ArrayData_ThrowNonAsync.#.cctor()")] 12 | 13 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/HashAlgorithm/HashAlgorithmWrapperConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.HashAlgorithm; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using Xunit; 7 | 8 | namespace Data.HashFunction.Test.HashAlgorithm 9 | { 10 | public class HashAlgorithmWrapperConfig_Tests 11 | { 12 | [Fact] 13 | public void HashAlgorithmWrapperConfig_Defaults_HaventChanged() 14 | { 15 | var hashAlgorithmWrapperConfig = new HashAlgorithmWrapperConfig(); 16 | 17 | 18 | Assert.Null(hashAlgorithmWrapperConfig.InstanceFactory); 19 | } 20 | 21 | [Fact] 22 | public void HashAlgorithmWrapperConfig_Clone_Works() 23 | { 24 | var hashAlgorithmWrapperConfig = new HashAlgorithmWrapperConfig() { 25 | InstanceFactory = () => SHA1.Create() 26 | }; 27 | 28 | var hashAlgorithmWrapperConfigClone = hashAlgorithmWrapperConfig.Clone(); 29 | 30 | Assert.IsType(hashAlgorithmWrapperConfigClone); 31 | 32 | Assert.Equal(hashAlgorithmWrapperConfig.InstanceFactory, hashAlgorithmWrapperConfigClone.InstanceFactory); 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/HashAlgorithm/HashAlgorithmWrapperFactory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.HashAlgorithm; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using Xunit; 7 | 8 | namespace Data.HashFunction.Test.HashAlgorithm 9 | { 10 | public class HashAlgorithmWrapperFactory_Tests 11 | { 12 | [Fact] 13 | public void HashAlgorithmWrapperFactory_Instance_IsDefined() 14 | { 15 | Assert.NotNull(HashAlgorithmWrapperFactory.Instance); 16 | Assert.IsType(HashAlgorithmWrapperFactory.Instance); 17 | } 18 | 19 | [Fact] 20 | public void HashAlgorithmWrapperFactory_Create_Config_IsNull_Throws() 21 | { 22 | var hashAlgorithmWrapperFactory = HashAlgorithmWrapperFactory.Instance; 23 | 24 | Assert.Equal( 25 | "config", 26 | Assert.Throws( 27 | () => hashAlgorithmWrapperFactory.Create(null)) 28 | .ParamName); 29 | } 30 | 31 | [Fact] 32 | public void HashAlgorithmWrapperFactory_Create_Config_Works() 33 | { 34 | var hashAlgorithmWrapperConfig = new HashAlgorithmWrapperConfig() { 35 | InstanceFactory = () => SHA1.Create() 36 | }; 37 | 38 | var hashAlgorithmWrapperFactory = HashAlgorithmWrapperFactory.Instance; 39 | var hashAlgorithmWrapper = hashAlgorithmWrapperFactory.Create(hashAlgorithmWrapperConfig); 40 | 41 | Assert.NotNull(hashAlgorithmWrapper); 42 | Assert.IsType(hashAlgorithmWrapper); 43 | 44 | 45 | var resultingHashAlgorithmWrapperConfig = hashAlgorithmWrapper.Config; 46 | 47 | Assert.Equal(hashAlgorithmWrapperConfig.InstanceFactory, resultingHashAlgorithmWrapperConfig.InstanceFactory); 48 | } 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Jenkins/JenkinsLookup2Config_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Jenkins; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.Jenkins 8 | { 9 | public class JenkinsLookup2Config_Tests 10 | { 11 | [Fact] 12 | public void JenkinsLookup2Config_Defaults_HaventChanged() 13 | { 14 | var jenkinsLookup2Config = new JenkinsLookup2Config(); 15 | 16 | 17 | Assert.Equal(0U, jenkinsLookup2Config.Seed); 18 | } 19 | 20 | [Fact] 21 | public void JenkinsLookup2Config_Clone_Works() 22 | { 23 | var jenkinsLookup2Config = new JenkinsLookup2Config() { 24 | Seed = 1337U, 25 | }; 26 | 27 | var jenkinsLookup2ConfigClone = jenkinsLookup2Config.Clone(); 28 | 29 | Assert.IsType(jenkinsLookup2ConfigClone); 30 | 31 | Assert.Equal(jenkinsLookup2Config.Seed, jenkinsLookup2ConfigClone.Seed); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Jenkins/JenkinsLookup3Config_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Jenkins; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.Jenkins 8 | { 9 | public class JenkinsLookup3Config_Tests 10 | { 11 | [Fact] 12 | public void JenkinsLookup3Config_Defaults_HaventChanged() 13 | { 14 | var jenkinsLookup3Config = new JenkinsLookup3Config(); 15 | 16 | 17 | Assert.Equal(32, jenkinsLookup3Config.HashSizeInBits); 18 | Assert.Equal(0U, jenkinsLookup3Config.Seed); 19 | Assert.Equal(0U, jenkinsLookup3Config.Seed2); 20 | } 21 | 22 | [Fact] 23 | public void JenkinsLookup3Config_Clone_Works() 24 | { 25 | var jenkinsLookup3Config = new JenkinsLookup3Config() { 26 | HashSizeInBits = 64, 27 | Seed = 1337U, 28 | Seed2 = 7331U 29 | }; 30 | 31 | var jenkinsLookup3ConfigClone = jenkinsLookup3Config.Clone(); 32 | 33 | Assert.IsType(jenkinsLookup3ConfigClone); 34 | 35 | Assert.Equal(jenkinsLookup3Config.HashSizeInBits, jenkinsLookup3ConfigClone.HashSizeInBits); 36 | Assert.Equal(jenkinsLookup3Config.Seed, jenkinsLookup3ConfigClone.Seed); 37 | Assert.Equal(jenkinsLookup3Config.Seed2, jenkinsLookup3ConfigClone.Seed2); 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Jenkins/JenkinsLookup3Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Jenkins; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | 11 | namespace Data.HashFunction.Test.Jenkins 12 | { 13 | public class JenkinsLookup3Tests 14 | { 15 | [Fact] 16 | public void JenkinsLookup3_32bit_ComputeHash_ExtremelyLongStream_Works() 17 | { 18 | byte[] knownValue; 19 | 20 | { 21 | var loremIpsumRepeatCount = 800; 22 | var loremIpsumLength = TestConstants.LoremIpsum.Length; 23 | 24 | 25 | knownValue = new byte[loremIpsumLength * loremIpsumRepeatCount]; 26 | 27 | for (var x = 0; x < loremIpsumRepeatCount; ++x) 28 | Array.Copy(TestConstants.LoremIpsum, 0, knownValue, loremIpsumLength * x, loremIpsumLength); 29 | } 30 | 31 | 32 | var jenkinsLookup3 = new JenkinsLookup3_Implementation( 33 | new JenkinsLookup3Config() { 34 | HashSizeInBits = 32 35 | }); 36 | 37 | var resultBytes = jenkinsLookup3.ComputeHash(knownValue); 38 | 39 | Assert.Equal( 40 | 0x85c64fdU, 41 | BitConverter.ToUInt32(resultBytes.Hash, 0)); 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Jenkins/JenkinsOneAtATimeFactory_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Jenkins; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.Jenkins 8 | { 9 | public class JenkinsOneAtATimeFactory_Tests 10 | { 11 | [Fact] 12 | public void JenkinsOneAtATimeFactory_Instance_IsDefined() 13 | { 14 | Assert.NotNull(JenkinsOneAtATimeFactory.Instance); 15 | Assert.IsType(JenkinsOneAtATimeFactory.Instance); 16 | } 17 | 18 | [Fact] 19 | public void JenkinsOneAtATimeFactory_Create_Works() 20 | { 21 | var jenkinsOneAtATimeFactory = JenkinsOneAtATimeFactory.Instance; 22 | var jenkinsOneAtATime = jenkinsOneAtATimeFactory.Create(); 23 | 24 | Assert.NotNull(jenkinsOneAtATime); 25 | Assert.IsType(jenkinsOneAtATime); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Jenkins/JenkinsOneAtATime_Implementation_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Jenkins; 4 | using Data.HashFunction.Test._Utilities; 5 | using System.Text; 6 | 7 | namespace Data.HashFunction.Test.Jenkins 8 | { 9 | public class JenkinsOneAtATime_Implementation_Tests 10 | { 11 | 12 | public class IStreamableHashFunction_Tests 13 | : IStreamableHashFunction_TestBase 14 | { 15 | protected override IEnumerable KnownValues { get; } = 16 | new KnownValue[] { 17 | new KnownValue(32, TestConstants.FooBar, 0xf952fde7), 18 | }; 19 | 20 | protected override IJenkinsOneAtATime CreateHashFunction(int hashSize) => 21 | new JenkinsOneAtATime_Implementation(); 22 | } 23 | 24 | 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/MetroHash/MetroHashConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.MetroHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.MetroHash 8 | { 9 | public class MetroHashConfig_Tests 10 | { 11 | [Fact] 12 | public void MetroHashConfig_Defaults_HaventChanged() 13 | { 14 | var metroHashConfig = new MetroHashConfig(); 15 | 16 | 17 | Assert.Equal(0UL, metroHashConfig.Seed); 18 | } 19 | 20 | [Fact] 21 | public void MetroHashConfig_Clone_Works() 22 | { 23 | var metroHashConfig = new MetroHashConfig() { 24 | Seed = 1, 25 | }; 26 | 27 | var metroHashConfigClone = metroHashConfig.Clone(); 28 | 29 | Assert.IsType(metroHashConfigClone); 30 | 31 | Assert.Equal(metroHashConfig.Seed, metroHashConfigClone.Seed); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/MurmurHash/MurmurHash1Config_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.MurmurHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.MurmurHash 8 | { 9 | public class MurmurHash1Config_Tests 10 | { 11 | [Fact] 12 | public void MurmurHash1Config_Defaults_HaventChanged() 13 | { 14 | var murmurHash1Config = new MurmurHash1Config(); 15 | 16 | 17 | Assert.Equal(0U, murmurHash1Config.Seed); 18 | } 19 | 20 | [Fact] 21 | public void MurmurHash1Config_Clone_Works() 22 | { 23 | var murmurHash1Config = new MurmurHash1Config() { 24 | Seed = 1337U 25 | }; 26 | 27 | var murmurHash1ConfigClone = murmurHash1Config.Clone(); 28 | 29 | Assert.IsType(murmurHash1ConfigClone); 30 | 31 | Assert.Equal(murmurHash1Config.Seed, murmurHash1ConfigClone.Seed); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/MurmurHash/MurmurHash2Config_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.MurmurHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.MurmurHash 8 | { 9 | public class MurmurHash2Config_Tests 10 | { 11 | [Fact] 12 | public void MurmurHash2Config_Defaults_HaventChanged() 13 | { 14 | var murmurHash2Config = new MurmurHash2Config(); 15 | 16 | 17 | Assert.Equal(64, murmurHash2Config.HashSizeInBits); 18 | Assert.Equal(0UL, murmurHash2Config.Seed); 19 | } 20 | 21 | [Fact] 22 | public void MurmurHash2Config_Clone_Works() 23 | { 24 | var murmurHash2Config = new MurmurHash2Config() { 25 | HashSizeInBits = 32, 26 | Seed = 1337UL, 27 | }; 28 | 29 | var murmurHash2ConfigClone = murmurHash2Config.Clone(); 30 | 31 | Assert.IsType(murmurHash2ConfigClone); 32 | 33 | Assert.Equal(murmurHash2Config.HashSizeInBits, murmurHash2ConfigClone.HashSizeInBits); 34 | Assert.Equal(murmurHash2Config.Seed, murmurHash2ConfigClone.Seed); 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/MurmurHash/MurmurHash3Config_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.MurmurHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.MurmurHash 8 | { 9 | public class MurmurHash3Config_Tests 10 | { 11 | [Fact] 12 | public void MurmurHash3Config_Defaults_HaventChanged() 13 | { 14 | var murmurHash3Config = new MurmurHash3Config(); 15 | 16 | 17 | Assert.Equal(32, murmurHash3Config.HashSizeInBits); 18 | Assert.Equal(0U, murmurHash3Config.Seed); 19 | } 20 | 21 | [Fact] 22 | public void MurmurHash3Config_Clone_Works() 23 | { 24 | var murmurHash3Config = new MurmurHash3Config() { 25 | HashSizeInBits = 64, 26 | Seed = 1337U, 27 | }; 28 | 29 | var murmurHash3ConfigClone = murmurHash3Config.Clone(); 30 | 31 | Assert.IsType(murmurHash3ConfigClone); 32 | 33 | Assert.Equal(murmurHash3Config.HashSizeInBits, murmurHash3ConfigClone.HashSizeInBits); 34 | Assert.Equal(murmurHash3Config.Seed, murmurHash3ConfigClone.Seed); 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Pearson/PearsonConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Pearson; 4 | using System.Linq; 5 | using System.Text; 6 | using Xunit; 7 | 8 | namespace Data.HashFunction.Test.Pearson 9 | { 10 | public class PearsonConfig_Tests 11 | { 12 | [Fact] 13 | public void PearsonConfig_Defaults_HaventChanged() 14 | { 15 | var pearsonConfig = new PearsonConfig(); 16 | 17 | Assert.Null(pearsonConfig.Table); 18 | 19 | Assert.Equal(8, pearsonConfig.HashSizeInBits); 20 | } 21 | 22 | [Fact] 23 | public void PearsonConfig_Clone_Works() 24 | { 25 | var pearsonConfig = new PearsonConfig() { 26 | Table = new byte[256], 27 | HashSizeInBits = 16, 28 | }; 29 | 30 | var pearsonConfigClone = pearsonConfig.Clone(); 31 | 32 | Assert.IsType(pearsonConfigClone); 33 | 34 | Assert.Equal(pearsonConfig.Table, pearsonConfigClone.Table); 35 | } 36 | 37 | [Fact] 38 | public void PearsonConfig_Clone_WithNullArrays_Works() 39 | { 40 | var pearsonConfig = new PearsonConfig() { 41 | Table = null, 42 | HashSizeInBits = 16, 43 | }; 44 | 45 | var pearsonConfigClone = pearsonConfig.Clone(); 46 | 47 | Assert.IsType(pearsonConfigClone); 48 | 49 | Assert.Equal(pearsonConfig.Table, pearsonConfigClone.Table); 50 | Assert.Equal(pearsonConfig.HashSizeInBits, pearsonConfigClone.HashSizeInBits); 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.Test")] 6 | [assembly: AssemblyProduct("Data.HashFunction.Test")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/SpookyHash/SpookyHashConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.SpookyHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.SpookyHash 8 | { 9 | public class SpookyHashConfig_Tests 10 | { 11 | [Fact] 12 | public void SpookyHashConfig_Defaults_HaventChanged() 13 | { 14 | var spookyHashConfig = new SpookyHashConfig(); 15 | 16 | 17 | Assert.Equal(128, spookyHashConfig.HashSizeInBits); 18 | Assert.Equal(0UL, spookyHashConfig.Seed); 19 | Assert.Equal(0UL, spookyHashConfig.Seed2); 20 | } 21 | 22 | [Fact] 23 | public void SpookyHashConfig_Clone_Works() 24 | { 25 | var spookyHashConfig = new SpookyHashConfig() { 26 | HashSizeInBits = 32, 27 | Seed = 1337UL, 28 | Seed2 = 7331UL 29 | }; 30 | 31 | var spookyHashConfigClone = spookyHashConfig.Clone(); 32 | 33 | Assert.IsType(spookyHashConfigClone); 34 | 35 | Assert.Equal(spookyHashConfig.HashSizeInBits, spookyHashConfigClone.HashSizeInBits); 36 | Assert.Equal(spookyHashConfig.Seed, spookyHashConfigClone.Seed); 37 | Assert.Equal(spookyHashConfig.Seed2, spookyHashConfigClone.Seed2); 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/_Mocks/HashFunctionImpl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.Core; 4 | using Data.HashFunction.Core.Utilities; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace Data.HashFunction.Test._Mocks 12 | { 13 | public class HashFunctionImpl 14 | : HashFunctionBase 15 | { 16 | public Func, CancellationToken, IHashValue> OnComputeHashInternal { get; set; } = (_, __) => new HashValue(new byte[1], 1); 17 | 18 | 19 | public override int HashSizeInBits { get; } 20 | 21 | 22 | 23 | public HashFunctionImpl() 24 | : this(1) 25 | { 26 | 27 | } 28 | 29 | public HashFunctionImpl(int hashSize) 30 | { 31 | HashSizeInBits = hashSize; 32 | } 33 | 34 | 35 | protected override IHashValue ComputeHashInternal(ArraySegment data, CancellationToken cancellationToken) 36 | { 37 | return OnComputeHashInternal(data, cancellationToken); 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/_Utilities/TestConstants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Data.HashFunction.Core.Utilities; 7 | 8 | namespace Data.HashFunction.Test._Utilities 9 | { 10 | internal sealed class TestConstants 11 | { 12 | // Constant values available for KnownValues to use. 13 | public static readonly byte[] Empty = new byte[0]; 14 | public static readonly byte[] FooBar = "foobar".ToBytes(); 15 | 16 | public static readonly byte[] LoremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ornare aliquam mauris, at volutpat massa. Phasellus pulvinar purus eu venenatis commodo.".ToBytes(); 17 | 18 | public static readonly byte[] RandomShort = "55d0e01ec669dc69".HexToBytes(); 19 | public static readonly byte[] RandomLong = "1122eeba86d52989b26b0efd2be8d091d3ad307b771ff8d1208104f9aa40b12ab057a0d78656ba037e475178c159bf3ee64dcd279610d64bb7888a97211884c7a894378263135124720ef6ef560da6c85fb491cb732b331e89bcb00e7daef271e127483e91b189ceeaf2f6711394e2eca07fb4db62c5a8fd8195ae3b39da63".HexToBytes(); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Data.HashFunction.Test/xxHash/xxHashConfig_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Data.HashFunction.xxHash; 4 | using System.Text; 5 | using Xunit; 6 | 7 | namespace Data.HashFunction.Test.xxHash 8 | { 9 | public class xxHashConfig_Tests 10 | { 11 | [Fact] 12 | public void xxHashConfig_Defaults_HaventChanged() 13 | { 14 | var xxHashConfigInstance = new xxHashConfig(); 15 | 16 | Assert.Equal(32, xxHashConfigInstance.HashSizeInBits); 17 | Assert.Equal(0UL, xxHashConfigInstance.Seed); 18 | } 19 | 20 | [Fact] 21 | public void xxHashConfig_Clone_Works() 22 | { 23 | var xxHashConfigInstance = new xxHashConfig() { 24 | HashSizeInBits = 64, 25 | Seed = 1337UL, 26 | }; 27 | 28 | var xxHashConfigClone = xxHashConfigInstance.Clone(); 29 | 30 | Assert.IsType(xxHashConfigClone); 31 | 32 | Assert.Equal(xxHashConfigInstance.HashSizeInBits, xxHashConfigClone.HashSizeInBits); 33 | Assert.Equal(xxHashConfigInstance.Seed, xxHashConfigClone.Seed); 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | .*\\moq\.dll$ 11 | .*\\OpenSource\.Data\.HashFunction\.Test(\..+)?\.dll$ 12 | .*\\xunit\..*\.dll$ 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file is used by Code Analysis to maintain SuppressMessage 3 | // attributes that are applied to this project. 4 | // Project-level suppressions either have no target or are given 5 | // a specific target and scoped to a namespace, type, member, etc. 6 | 7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "", Scope = "type", Target = "~T:Data.HashFunction.xxHash")] 8 | 9 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/IxxHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.xxHash 6 | { 7 | /// 8 | /// Implements xxHash as specified at https://github.com/Cyan4973/xxHash/blob/dev/xxhash.c and 9 | /// https://github.com/Cyan4973/xxHash. 10 | /// 11 | public interface IxxHash 12 | : IStreamableHashFunction 13 | { 14 | 15 | /// 16 | /// Configuration used when creating this instance. 17 | /// 18 | /// 19 | /// A clone of configuration that was used when creating this instance. 20 | /// 21 | IxxHashConfig Config { get; } 22 | 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/IxxHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.xxHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public interface IxxHashConfig 11 | { 12 | /// 13 | /// Gets the desired hash size, in bits. 14 | /// 15 | /// 16 | /// The desired hash size, in bits. 17 | /// 18 | int HashSizeInBits { get; } 19 | 20 | /// 21 | /// Gets the seed. 22 | /// 23 | /// 24 | /// The seed. 25 | /// 26 | UInt64 Seed { get; } 27 | 28 | 29 | 30 | /// 31 | /// Makes a deep clone of current instance. 32 | /// 33 | /// A deep clone of the current instance. 34 | IxxHashConfig Clone(); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/IxxHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.xxHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public interface IxxHashFactory 11 | { 12 | /// 13 | /// Creates a new instance with the default configuration. 14 | /// 15 | /// A instance. 16 | IxxHash Create(); 17 | 18 | /// 19 | /// Creates a new instance with the specified configuration. 20 | /// 21 | /// Configuration to use when constructing the instance. 22 | /// A instance. 23 | IxxHash Create(IxxHashConfig config); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Data.HashFunction.xxHash")] 6 | [assembly: AssemblyProduct("Data.HashFunction.xxHash")] 7 | 8 | [assembly: ComVisible(false)] 9 | 10 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/xxHashConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.xxHash 6 | { 7 | /// 8 | /// Defines a configuration for a implementation. 9 | /// 10 | public class xxHashConfig 11 | : IxxHashConfig 12 | { 13 | /// 14 | /// Gets the desired hash size, in bits. 15 | /// 16 | /// 17 | /// The desired hash size, in bits. 18 | /// 19 | public int HashSizeInBits { get; set; } = 32; 20 | 21 | /// 22 | /// Gets the seed. 23 | /// 24 | /// 25 | /// The seed. 26 | /// 27 | public UInt64 Seed { get; set; } = 0UL; 28 | 29 | 30 | 31 | /// 32 | /// Makes a deep clone of current instance. 33 | /// 34 | /// A deep clone of the current instance. 35 | public IxxHashConfig Clone() => 36 | new xxHashConfig() { 37 | HashSizeInBits = HashSizeInBits, 38 | Seed = Seed 39 | }; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/Data.HashFunction.xxHash/xxHashFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Data.HashFunction.xxHash 6 | { 7 | /// 8 | /// Provides instances of implementations of . 9 | /// 10 | public class xxHashFactory 11 | : IxxHashFactory 12 | { 13 | /// 14 | /// Gets the singleton instance of this factory. 15 | /// 16 | public static IxxHashFactory Instance { get; } = new xxHashFactory(); 17 | 18 | 19 | private xxHashFactory() 20 | { 21 | 22 | } 23 | 24 | 25 | /// 26 | /// Creates a new instance with the default configuration. 27 | /// 28 | /// A instance. 29 | public IxxHash Create() => 30 | Create(new xxHashConfig()); 31 | 32 | /// 33 | /// Creates a new instance with the specified configuration. 34 | /// 35 | /// Configuration to use when constructing the instance. 36 | /// A instance. 37 | public IxxHash Create(IxxHashConfig config) 38 | { 39 | if (config == null) 40 | throw new ArgumentNullException(nameof(config)); 41 | 42 | return new xxHash_Implementation(config); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/FriendAssemblies.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | #if DEBUG 4 | 5 | [assembly:InternalsVisibleTo("Data.HashFunction.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010085f076d56d0e4c1461db01820a06d1814c38d171cebad2714bf251a15ad82214fa3c51cd0c76e26265b4e46f96dd5ab5c9843b7406815d301bea7d7904c61c21ac54f4921b95a79443d801eeda3ffd6d32c3f458f73babb09a22d06f303dfd1afbb6e27eecffd072c8fe17c669d666b954c8a423ea9b4a9313691daf942a74b1")] 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/SolutionInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTrademark("")] 5 | [assembly: AssemblyCulture("")] 6 | 7 | [assembly: CLSCompliant(false)] 8 | 9 | -------------------------------------------------------------------------------- /tools/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deskasoft/Data.HashFunction/bbb484ab1da8a16169ab7bbb5d797cb98f50874f/tools/nuget.exe --------------------------------------------------------------------------------