├── README.md ├── HashLib ├── PushNuget.ps1 ├── HashRounds.cs ├── AssemblyInformation.cs ├── Crypto │ ├── BuildIn │ │ ├── SHA1Cng.cs │ │ ├── SHA256Cng.cs │ │ ├── SHA384Cng.cs │ │ ├── SHA512Cng.cs │ │ ├── SHA256CryptoServiceProvider.cs │ │ ├── SHA384CryptoServiceProvider.cs │ │ ├── SHA512CryptoServiceProvider.cs │ │ ├── SHA256Managed.cs │ │ ├── SHA1Managed.cs │ │ ├── SHA384Managed.cs │ │ ├── RIPEMD160Managed .cs │ │ ├── SHA512Managed.cs │ │ ├── MD5CryptoServiceProvider.cs │ │ └── SHA1CryptoServiceProvider.cs │ ├── SHA1.cs │ ├── SHA224.cs │ ├── SHA256.cs │ ├── SHA512.cs │ ├── SHA384.cs │ ├── MDBase.cs │ ├── RadioGatun32.cs │ ├── RadioGatun64.cs │ ├── SHA256Base.cs │ ├── MD2.cs │ └── HAS160.cs ├── HashSize.cs ├── Hash32 │ ├── DEK.cs │ ├── DJB.cs │ ├── FNV.cs │ ├── Bernstein.cs │ ├── Bernstein1.cs │ ├── FNV1a.cs │ ├── JS.cs │ ├── SDBM.cs │ ├── Rotating.cs │ ├── ShiftAndXor.cs │ ├── BKDR.cs │ ├── RS.cs │ ├── ELF.cs │ ├── OneAtTime.cs │ ├── AP.cs │ ├── PJW.cs │ ├── SuperFast.cs │ └── DotNet.cs ├── Extensions │ ├── Bits.cs │ ├── TypeExtensions.cs │ └── ArrayExtensions.cs ├── Hash64 │ ├── FNV64.cs │ ├── FNV1a64.cs │ └── Murmur2_64.cs ├── HashLib.csproj ├── HashAlgorithmWrapper.cs ├── Checksum │ ├── Adler32.cs │ ├── CRC64.cs │ └── CRC32.cs ├── Properties │ └── AssemblyInfo.cs ├── HashCryptoBuildIn.cs ├── MultipleTransformsNonBlock.cs ├── HMACBuildInAdapter.cs ├── HashCryptoNotBuildIn.cs ├── IHashInfo.cs ├── HashResult.cs ├── IHash.cs ├── HMACNotBuildInAdapter.cs ├── HashBuffer.cs └── Hashes.cs ├── HashLibTest ├── TestData │ ├── APTest.txt │ ├── DEKTest.txt │ ├── DJBTest.txt │ ├── ELFTest.txt │ ├── FNVTest.txt │ ├── JSTest.txt │ ├── PJWTest.txt │ ├── RSTest.txt │ ├── Adler32Test.txt │ ├── BKDRTest.txt │ ├── CRC32_QTest.txt │ ├── FNV1aTest.txt │ ├── RotatingTest.txt │ ├── SDBMTest.txt │ ├── Bernstein1Test.txt │ ├── BernsteinTest.txt │ ├── CRC32_IEEETest.txt │ ├── CRC32_KOOPMANTest.txt │ ├── OneAtTimeTest.txt │ ├── ShiftAndXorTest.txt │ ├── CRC32_CASTAGNOLITest.txt │ ├── FNV1a64Test.txt │ ├── FNV64Test.txt │ ├── CRC64_ECMATest.txt │ ├── CRC64_ISOTest.txt │ ├── SuperFastTest.txt │ ├── Hamsi224Test.txt │ ├── Hamsi256Test.txt │ ├── Grindahl256Test.txt │ ├── Murmur2Test.txt │ ├── Murmur3Test.txt │ ├── Jenkins3Test.txt │ ├── Hamsi384Test.txt │ ├── Hamsi512Test.txt │ ├── Grindahl512Test.txt │ └── Murmur2_64Test.txt ├── Properties │ └── AssemblyInfo.cs └── HMACsTest.cs ├── TomanuExtensions ├── Extensions │ ├── RichTextBoxExtensions.cs │ ├── DictionaryExtensions.cs │ ├── EnumExtensions.cs │ ├── XmlNodeExtensions.cs │ ├── ConstructorInfoExtensions.cs │ ├── FileInfoExtensions.cs │ ├── MarshalExtensions.cs │ ├── CollectionExtensions.cs │ ├── StreamExtensions.cs │ ├── MathExtensions.cs │ ├── MethodInfoExtensions.cs │ ├── IListExtensions.cs │ ├── RectangleExtensions.cs │ ├── DirectoryInfoExtensions.cs │ ├── PropertyInfoExtensions.cs │ └── XmlWriterExtensions.cs ├── Utils │ ├── ValueClass.cs │ ├── SHA1.cs │ ├── FileUtils.cs │ ├── Profiler.cs │ ├── Bits.cs │ ├── XmlBase.cs │ └── Hex.cs ├── Properties │ └── AssemblyInfo.cs └── TestUtils │ ├── ProgressForm.cs │ ├── ProgressIndicator.cs │ └── ProgressForm.Designer.cs └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # A fork of the HashLib library version 2.1 [HashLib](https://hashlib.codeplex.com/). 2 | -------------------------------------------------------------------------------- /HashLib/PushNuget.ps1: -------------------------------------------------------------------------------- 1 | rm "bin\release\" -Recurse -Force 2 | dotnet pack HashLib.csproj --configuration Release 3 | dotnet nuget push "bin\Release\*.nupkg" --source "https://api.nuget.org/v3/index.json" 4 | 5 | -------------------------------------------------------------------------------- /HashLib/HashRounds.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib 4 | { 5 | public enum HashRounds 6 | { 7 | Rounds3 = 3, 8 | Rounds4 = 4, 9 | Rounds5 = 5, 10 | Rounds8 = 8 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /HashLib/AssemblyInformation.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | // Properties/AssemblyInfo.cs is no longer generated by default in VS2017/.NETStandard, 3 | // so this file is added manually and called 'AssemblyInformation.cs' 4 | [assembly: InternalsVisibleTo("HashLibTest")] -------------------------------------------------------------------------------- /HashLibTest/TestData/APTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 5877FEFF 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: BFECC91E 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 1C105084 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/DEKTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 60000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: B70E0000 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 9FB00000 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: B7367500 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/DJBTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 05150000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: E5B50200 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 2D715900 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: B3FF870B 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: C8B39B7C 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/ELFTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: A7030000 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: FF4F0000 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 078F0700 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/FNVTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: C59D1C81 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 5F5D0C05 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: FDAF7620 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 03892FFB 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 9A5218C6 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/JSTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: A7C6674E 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 6E00F5AE 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 2344A8A4 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 65949B1A 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: DAF0BB40 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/PJWTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: A7030000 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: FF4F0000 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 078F0700 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/RSTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 16DFF80E 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 1C13536C 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 8B87CA50 20 | 21 | -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA1Cng.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | using System; 3 | 4 | namespace HashLib.Crypto.BuildIn 5 | { 6 | internal class SHA1Cng : HashCryptoBuildIn 7 | { 8 | public SHA1Cng() 9 | : base(new System.Security.Cryptography.SHA1Cng(), 64) 10 | { 11 | } 12 | } 13 | } 14 | #endif -------------------------------------------------------------------------------- /HashLibTest/TestData/Adler32Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 01000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 41004100 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: C900FB00 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 4F010D02 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 24021805 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/BKDRTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: AA190000 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: FA3B1400 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 2976AE0E 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/CRC32_QTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: C0C33537 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 1C12DB79 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 20F4E183 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 3CC3ADCE 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/FNV1aTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: C59D1C81 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 5FF80BC5 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: D1BFEB7A 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 43EA0C9D 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 2C331A24 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/RotatingTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 87030000 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: FF4F0000 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: E70C0600 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/SDBMTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: A60C3100 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 0AB30C26 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 6580E505 20 | 21 | -------------------------------------------------------------------------------- /HashLib/HashSize.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib 4 | { 5 | public enum HashSize 6 | { 7 | HashSize128 = 16, 8 | HashSize160 = 20, 9 | HashSize192 = 24, 10 | HashSize224 = 28, 11 | HashSize256 = 32, 12 | HashSize384 = 48, 13 | HashSize512 = 64 14 | }; 15 | } -------------------------------------------------------------------------------- /HashLibTest/TestData/Bernstein1Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 05150000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: E5B50200 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 83685900 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: D5CC870B 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 40896D7C 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/BernsteinTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 05150000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: E5B50200 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 2D715900 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: B3FF870B 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: C8B39B7C 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/CRC32_IEEETest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 1DAEDEA4 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: AA13EFE9 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: E44EDD36 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 51949BB0 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/CRC32_KOOPMANTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 65C0CA4A 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 248220B6 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 098B6051 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 9838DBAA 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/OneAtTimeTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 6DA7BF93 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 02D4B205 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 29CE3489 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 9D5163D0 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/ShiftAndXorTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 40000000 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: F2060000 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: DD3F0100 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 4B7F3800 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/CRC32_CASTAGNOLITest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: ED4E0613 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: DA65EFE4 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 6125C171 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: DD7135FA 20 | 21 | -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA256Cng.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA256Cng : HashCryptoBuildIn 8 | { 9 | public SHA256Cng() 10 | : base(new System.Security.Cryptography.SHA256Cng(), 64) 11 | { 12 | } 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA384Cng.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA384Cng : HashCryptoBuildIn 8 | { 9 | public SHA384Cng() 10 | : base(new System.Security.Cryptography.SHA384Cng(), 128) 11 | { 12 | } 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA512Cng.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA512Cng : HashCryptoBuildIn 8 | { 9 | public SHA512Cng() 10 | : base(new System.Security.Cryptography.SHA512Cng(), 128) 11 | { 12 | } 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /HashLibTest/TestData/FNV1a64Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 25232284E49CF2CB 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 9F2402864CFD63AF 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: D163B9B40731F807 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 03D06FB41912421D 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: CC29A152AFEBF71F 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/FNV64Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 25232284E49CF2CB 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 9FB701864CBD63AF 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: FD89EBB407973208 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 830F316B188247D8 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 1A5D0AC87EE77FD2 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/CRC64_ECMATest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 0000000000000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: F8B8A48FB98A1B7B 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: D49B3BAEA1F7B8FE 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: D37446DDE80C16C0 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: A86E9982AFA6605C 20 | 21 | -------------------------------------------------------------------------------- /HashLibTest/TestData/CRC64_ISOTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 0000000000000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 0000000000009003 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 000000000020C3A8 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 0000000060F95AC9 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 000000D05E91F6C4 20 | 21 | -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA256CryptoServiceProvider.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA256CryptoServiceProvider : HashCryptoBuildIn 8 | { 9 | public SHA256CryptoServiceProvider() 10 | : base(new System.Security.Cryptography.SHA256CryptoServiceProvider(), 64) 11 | { 12 | } 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA384CryptoServiceProvider.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA384CryptoServiceProvider : HashCryptoBuildIn 8 | { 9 | public SHA384CryptoServiceProvider() 10 | : base(new System.Security.Cryptography.SHA384CryptoServiceProvider(), 128) 11 | { 12 | } 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA512CryptoServiceProvider.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA512CryptoServiceProvider : HashCryptoBuildIn 8 | { 9 | public SHA512CryptoServiceProvider() 10 | : base(new System.Security.Cryptography.SHA512CryptoServiceProvider(), 128) 11 | { 12 | } 13 | } 14 | } 15 | #endif -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/RichTextBoxExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Windows.Forms; 3 | 4 | namespace TomanuExtensions 5 | { 6 | [DebuggerStepThrough] 7 | public static class RichTextBoxExtensions 8 | { 9 | public static void ScrollToEnd(this RichTextBox a_edit) 10 | { 11 | a_edit.SelectionStart = a_edit.Text.Length; 12 | a_edit.ScrollToCaret(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/DictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace TomanuExtensions 6 | { 7 | [DebuggerStepThrough] 8 | public static class DictionaryExtensions 9 | { 10 | public static IDictionary Invert( 11 | this IDictionary a_dictionary) 12 | { 13 | return a_dictionary.ToDictionary(pair => pair.Value, pair => pair.Key); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /HashLib/Crypto/SHA1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class SHA1 : SHA0 6 | { 7 | public SHA1() 8 | { 9 | } 10 | 11 | protected override void Expand(uint[] a_data) 12 | { 13 | for (int i = 16; i < 80; i++) 14 | { 15 | uint T = a_data[i - 3] ^ a_data[i - 8] ^ a_data[i - 14] ^ a_data[i - 16]; 16 | a_data[i] = ((T << 1) | (T >> 31)); 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA256Managed.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | using System; 3 | 4 | namespace HashLib.Crypto.BuildIn 5 | { 6 | internal class SHA256Managed : HashCryptoBuildIn, IHasHMACBuildIn 7 | { 8 | public SHA256Managed() 9 | : base(new System.Security.Cryptography.SHA256Managed(), 64) 10 | { 11 | } 12 | 13 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 14 | { 15 | return new System.Security.Cryptography.HMACSHA256(); 16 | } 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA1Managed.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | using System; 3 | 4 | namespace HashLib.Crypto.BuildIn 5 | { 6 | internal class SHA1Managed : HashCryptoBuildIn, IHasHMACBuildIn 7 | { 8 | public SHA1Managed() 9 | : base(new System.Security.Cryptography.SHA1Managed(), 64) 10 | { 11 | } 12 | 13 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 14 | { 15 | return new System.Security.Cryptography.HMACSHA1(new byte[0], true); 16 | } 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA384Managed.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA384Managed : HashCryptoBuildIn, IHasHMACBuildIn 8 | { 9 | public SHA384Managed() 10 | : base(new System.Security.Cryptography.SHA384Managed(), 128) 11 | { 12 | } 13 | 14 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 15 | { 16 | return new System.Security.Cryptography.HMACSHA384(); 17 | } 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/RIPEMD160Managed .cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | using System; 3 | 4 | namespace HashLib.Crypto.BuildIn 5 | { 6 | internal class RIPEMD160Managed : HashCryptoBuildIn, IHasHMACBuildIn 7 | { 8 | public RIPEMD160Managed() 9 | : base(new System.Security.Cryptography.RIPEMD160Managed(), 64) 10 | { 11 | } 12 | 13 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 14 | { 15 | return new System.Security.Cryptography.HMACRIPEMD160(); 16 | } 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA512Managed.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class SHA512Managed : HashCryptoBuildIn, IHasHMACBuildIn 8 | { 9 | public SHA512Managed() 10 | : base(new System.Security.Cryptography.SHA512Managed(), 128) 11 | { 12 | } 13 | 14 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 15 | { 16 | return new System.Security.Cryptography.HMACSHA512(); 17 | } 18 | } 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /HashLib/Hash32/DEK.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Hash32 4 | { 5 | internal class DEK : MultipleTransformNonBlock, IHash32 6 | { 7 | public DEK() 8 | : base(4, 1) 9 | { 10 | } 11 | 12 | protected override HashResult ComputeAggregatedBytes(byte[] a_data) 13 | { 14 | uint hash = (uint)a_data.Length; 15 | 16 | foreach (byte b in a_data) 17 | hash = ((hash << 5) ^ (hash >> 27)) ^ b; 18 | 19 | return new HashResult(hash); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | 6 | namespace TomanuExtensions 7 | { 8 | [DebuggerStepThrough] 9 | public static class EnumExtensions 10 | { 11 | public static T Parse(string a_str) 12 | { 13 | return (T)Enum.Parse(typeof(T), a_str); 14 | } 15 | 16 | public static IEnumerable GetValues() 17 | { 18 | return Enum.GetValues(typeof(T)).Cast(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/XmlNodeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Xml; 3 | 4 | namespace TomanuExtensions 5 | { 6 | [DebuggerStepThrough] 7 | public static class XmlNodeExtensions 8 | { 9 | public static XmlNode CreateChildNode(this XmlNode a_node, string a_name) 10 | { 11 | var document = (a_node is XmlDocument ? (XmlDocument)a_node : a_node.OwnerDocument); 12 | XmlNode node = document.CreateElement(a_name); 13 | a_node.AppendChild(node); 14 | return node; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/MD5CryptoServiceProvider.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | 3 | using System; 4 | 5 | namespace HashLib.Crypto.BuildIn 6 | { 7 | internal class MD5CryptoServiceProvider : HashCryptoBuildIn, IHasHMACBuildIn 8 | { 9 | public MD5CryptoServiceProvider() 10 | : base(new System.Security.Cryptography.MD5CryptoServiceProvider(), 64) 11 | { 12 | } 13 | 14 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 15 | { 16 | return new System.Security.Cryptography.HMACMD5(); 17 | } 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /HashLib/Crypto/BuildIn/SHA1CryptoServiceProvider.cs: -------------------------------------------------------------------------------- 1 | #if !NETCORE 2 | using System; 3 | 4 | namespace HashLib.Crypto.BuildIn 5 | { 6 | internal class SHA1CryptoServiceProvider : HashCryptoBuildIn, IHasHMACBuildIn 7 | { 8 | public SHA1CryptoServiceProvider() 9 | : base(new System.Security.Cryptography.SHA1CryptoServiceProvider(), 64) 10 | { 11 | } 12 | 13 | public virtual System.Security.Cryptography.HMAC GetBuildHMAC() 14 | { 15 | return new System.Security.Cryptography.HMACSHA1(new byte[0], false); 16 | } 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /TomanuExtensions/Utils/ValueClass.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace TomanuExtensions.Utils 4 | { 5 | [DebuggerDisplay("Value: {Value}")] 6 | public class ValueClass where T : struct 7 | { 8 | public T Value; 9 | 10 | public ValueClass(T a_value) 11 | { 12 | Value = a_value; 13 | } 14 | 15 | public static implicit operator T(ValueClass a_bc) 16 | { 17 | return a_bc.Value; 18 | } 19 | 20 | public static implicit operator ValueClass(T a_value) 21 | { 22 | return new ValueClass(a_value); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/ConstructorInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Runtime.CompilerServices; 8 | 9 | namespace TomanuExtensions 10 | { 11 | [DebuggerStepThrough] 12 | public static class ConstructorInfoExtensions 13 | { 14 | public static Object Invoke(this ConstructorInfo a_ci) 15 | { 16 | return a_ci.Invoke(null); 17 | } 18 | 19 | public static Object Invoke(this ConstructorInfo a_ci, params Object[] a_params) 20 | { 21 | return a_ci.Invoke(a_params); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /HashLib/Extensions/Bits.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib 5 | { 6 | internal static class Bits 7 | { 8 | static public uint RotateLeft(uint a_uint, int a_n) 9 | { 10 | Debug.Assert(a_n >= 0); 11 | 12 | return (uint)((a_uint << a_n) | (a_uint >> (32 - a_n))); 13 | } 14 | 15 | static public uint RotateRight(uint a_uint, int a_n) 16 | { 17 | Debug.Assert(a_n >= 0); 18 | 19 | return (uint)((a_uint >> a_n) | (a_uint << (32 - a_n))); 20 | } 21 | 22 | static public ulong RotateRight(ulong a_ulong, int a_n) 23 | { 24 | Debug.Assert(a_n >= 0); 25 | 26 | return (ulong)((a_ulong >> a_n) | (a_ulong << (64 - a_n))); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /HashLib/Crypto/SHA224.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class SHA224 : SHA256Base 6 | { 7 | public SHA224() 8 | : base(28) 9 | { 10 | } 11 | 12 | protected override byte[] GetResult() 13 | { 14 | return Converters.ConvertUIntsToBytesSwapOrder(m_state, 0, 7); 15 | } 16 | 17 | public override void Initialize() 18 | { 19 | m_state[0] = 0xc1059ed8; 20 | m_state[1] = 0x367cd507; 21 | m_state[2] = 0x3070dd17; 22 | m_state[3] = 0xf70e5939; 23 | m_state[4] = 0xffc00b31; 24 | m_state[5] = 0x68581511; 25 | m_state[6] = 0x64f98fa7; 26 | m_state[7] = 0xbefa4fa4; 27 | 28 | base.Initialize(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /HashLib/Crypto/SHA256.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class SHA256 : SHA256Base 6 | { 7 | public SHA256() 8 | : base(32) 9 | { 10 | } 11 | 12 | public override void Initialize() 13 | { 14 | m_state[0] = 0x6a09e667; 15 | m_state[1] = 0xbb67ae85; 16 | m_state[2] = 0x3c6ef372; 17 | m_state[3] = 0xa54ff53a; 18 | m_state[4] = 0x510e527f; 19 | m_state[5] = 0x9b05688c; 20 | m_state[6] = 0x1f83d9ab; 21 | m_state[7] = 0x5be0cd19; 22 | 23 | 24 | base.Initialize(); 25 | } 26 | 27 | protected override byte[] GetResult() 28 | { 29 | return Converters.ConvertUIntsToBytesSwapOrder(m_state); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /HashLib/Crypto/SHA512.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class SHA512 : SHA512Base 6 | { 7 | public SHA512() 8 | : base(64) 9 | { 10 | } 11 | 12 | protected override byte[] GetResult() 13 | { 14 | return Converters.ConvertULongsToBytesSwapOrder(m_state); 15 | } 16 | 17 | public override void Initialize() 18 | { 19 | m_state[0] = 0x6a09e667f3bcc908; 20 | m_state[1] = 0xbb67ae8584caa73b; 21 | m_state[2] = 0x3c6ef372fe94f82b; 22 | m_state[3] = 0xa54ff53a5f1d36f1; 23 | m_state[4] = 0x510e527fade682d1; 24 | m_state[5] = 0x9b05688c2b3e6c1f; 25 | m_state[6] = 0x1f83d9abfb41bd6b; 26 | m_state[7] = 0x5be0cd19137e2179; 27 | 28 | base.Initialize(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /HashLib/Crypto/SHA384.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class SHA384 : SHA512Base 6 | { 7 | public SHA384() 8 | : base(48) 9 | { 10 | } 11 | 12 | protected override byte[] GetResult() 13 | { 14 | return Converters.ConvertULongsToBytesSwapOrder(m_state, 0, 6); 15 | } 16 | 17 | public override void Initialize() 18 | { 19 | m_state[0] = 0xcbbb9d5dc1059ed8; 20 | m_state[1] = 0x629a292a367cd507; 21 | m_state[2] = 0x9159015a3070dd17; 22 | m_state[3] = 0x152fecd8f70e5939; 23 | m_state[4] = 0x67332667ffc00b31; 24 | m_state[5] = 0x8eb44a8768581511; 25 | m_state[6] = 0xdb0c2e0d64f98fa7; 26 | m_state[7] = 0x47b5481dbefa4fa4; 27 | 28 | base.Initialize(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /HashLib/Hash32/DJB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class DJB : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public DJB() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 5381; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = ((m_hash << 5) + m_hash) + a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/FNV.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class FNV : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public FNV() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 2166136261; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash * 16777619) ^ a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/Bernstein.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class Bernstein : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public Bernstein() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 5381; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash * 33) + a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/Bernstein1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class Bernstein1 : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public Bernstein1() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 5381; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash * 33) ^ a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/FNV1a.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class FNV1a : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public FNV1a() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 2166136261; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash ^ a_data[i]) * 16777619; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/JS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class JS : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public JS() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 1315423911; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash ^= ((m_hash << 5) + a_data[i] + (m_hash >> 2)); 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLibTest/TestData/SuperFastTest.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 15C33F97 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 7A45AEC2 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: F31EFBA2 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 6615B0B5 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: E721642C 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: 97688774 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: B42B4CB9 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: C01FB003 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: 6C9F5EF8 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: 633D75D2 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: E6360E5E 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: FD6AC728 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: A17E7005 56 | 57 | -------------------------------------------------------------------------------- /TomanuExtensions/Utils/SHA1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TomanuExtensions.Utils 4 | { 5 | public static class SHA1 6 | { 7 | /// 8 | /// Calculate SHA1 9 | /// 10 | /// 11 | /// 12 | public static string Calculate(string a_filePath) 13 | { 14 | return Calculate(FileUtils.ReadFile(a_filePath)); 15 | } 16 | 17 | /// 18 | /// Calculate SHA1 19 | /// 20 | /// 21 | /// 22 | public static string Calculate(byte[] a_data) 23 | { 24 | using (var hasher = System.Security.Cryptography.SHA1.Create()) 25 | { 26 | byte[] hash = hasher.ComputeHash(a_data); 27 | return BitConverter.ToString(hash).ToUpper().Replace("-", ""); 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /HashLib/Hash32/SDBM.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class SDBM : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public SDBM() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 0; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = a_data[i] + (m_hash << 6) + (m_hash << 16) - m_hash; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/Rotating.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class Rotating : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public Rotating() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 0; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash << 4) ^ (m_hash >> 28) ^ a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash64/FNV64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash64 5 | { 6 | internal class FNV64 : Hash, IHash64, IBlockHash 7 | { 8 | private ulong m_hash; 9 | 10 | public FNV64() 11 | : base(8, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 14695981039346656037; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash * 1099511628211) ^ a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash32/ShiftAndXor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class ShiftAndXor : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public ShiftAndXor() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 0; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash ^= (m_hash << 5) + (m_hash >> 2) + a_data[i]; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/Hash64/FNV1a64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash64 5 | { 6 | internal class FNV1a64 : Hash, IHash64, IBlockHash 7 | { 8 | private ulong m_hash; 9 | 10 | public FNV1a64() 11 | : base(8, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 14695981039346656037; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | m_hash = (m_hash ^ a_data[i]) * 1099511628211; 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | return new HashResult(m_hash); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HashLib/HashLib.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | NStratis.HashLib 5 | Copyright © Stratis Platform SA 2017 6 | The C# hash library based on HashLib 7 | 8 | 9 | 10 | 1.0.0.1 11 | 12 | 13 | 14 | netstandard1.3 15 | NStratis.HashLib 16 | NStratis.HashLib 17 | NStratis.HashLib 18 | 19 | 20 | 21 | TRACE;DEBUG;NETSTANDARD1_6;NETCORE 22 | 23 | 24 | 25 | TRACE;NETSTANDARD1_6;NETCORE; 26 | 27 | 28 | -------------------------------------------------------------------------------- /HashLib/Hash32/BKDR.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class BKDR : Hash, IHash32, IBlockHash 7 | { 8 | private const int SEED = 131; 9 | 10 | private uint m_hash; 11 | 12 | public BKDR() 13 | : base(4, 1) 14 | { 15 | } 16 | 17 | public override void Initialize() 18 | { 19 | m_hash = 0; 20 | } 21 | 22 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 23 | { 24 | Debug.Assert(a_index >= 0); 25 | Debug.Assert(a_length >= 0); 26 | Debug.Assert(a_index + a_length <= a_data.Length); 27 | 28 | for (int i = a_index; a_length > 0; i++, a_length--) 29 | m_hash = (m_hash * SEED) + a_data[i]; 30 | } 31 | 32 | public override HashResult TransformFinal() 33 | { 34 | return new HashResult(m_hash); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/FileInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.IO; 3 | 4 | namespace TomanuExtensions 5 | { 6 | [DebuggerStepThrough] 7 | public static class FileInfoExtensions 8 | { 9 | public static void Rename(this FileInfo a_file_info, string a_file_name) 10 | { 11 | var filePath = Path.Combine(Path.GetDirectoryName(a_file_info.FullName), a_file_name); 12 | a_file_info.MoveTo(filePath); 13 | } 14 | 15 | public static void RenameFileWithoutExtension(this FileInfo a_file_info, string a_file_name) 16 | { 17 | var fileName = string.Concat(a_file_name, a_file_info.Extension); 18 | a_file_info.Rename(fileName); 19 | } 20 | 21 | public static void ChangeExtension(this FileInfo a_file_info, string a_file_ext) 22 | { 23 | a_file_ext = a_file_ext.EnsureStartsWith("."); 24 | var fileName = string.Concat(Path.GetFileNameWithoutExtension(a_file_info.FullName), a_file_ext); 25 | a_file_info.Rename(fileName); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Stratisplatform 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 | -------------------------------------------------------------------------------- /HashLib/Hash32/RS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class RS : Hash, IHash32, IBlockHash 7 | { 8 | private const uint B = 378551; 9 | 10 | private uint m_a = 63689; 11 | private uint m_hash; 12 | 13 | public RS() 14 | : base(4, 1) 15 | { 16 | } 17 | 18 | public override void Initialize() 19 | { 20 | m_hash = 0; 21 | m_a = 63689; 22 | } 23 | 24 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 25 | { 26 | Debug.Assert(a_index >= 0); 27 | Debug.Assert(a_length >= 0); 28 | Debug.Assert(a_index + a_length <= a_data.Length); 29 | 30 | for (int i = a_index; a_length > 0; i++, a_length--) 31 | { 32 | m_hash = (m_hash * m_a) + a_data[i]; 33 | m_a = m_a * B; 34 | } 35 | } 36 | 37 | public override HashResult TransformFinal() 38 | { 39 | return new HashResult(m_hash); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /HashLib/Hash32/ELF.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class ELF : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public ELF() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 0; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | { 28 | m_hash = (m_hash << 4) + a_data[i]; 29 | uint g = m_hash & 0xf0000000; 30 | 31 | if (g != 0) 32 | m_hash ^= g >> 24; 33 | 34 | m_hash &= ~g; 35 | } 36 | } 37 | 38 | public override HashResult TransformFinal() 39 | { 40 | return new HashResult(m_hash); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /HashLib/HashAlgorithmWrapper.cs: -------------------------------------------------------------------------------- 1 | #if !USEBC 2 | 3 | using System; 4 | using System.Diagnostics; 5 | 6 | namespace HashLib 7 | { 8 | internal class HashAlgorithmWrapper : System.Security.Cryptography.HashAlgorithm 9 | { 10 | private IHash m_hash; 11 | 12 | public HashAlgorithmWrapper(IHash a_hash) 13 | { 14 | m_hash = a_hash; 15 | #if !NETCORE 16 | HashSizeValue = a_hash.HashSize * 8; 17 | #endif 18 | } 19 | 20 | protected override void HashCore(byte[] array, int ibStart, int cbSize) 21 | { 22 | Debug.Assert(cbSize >= 0); 23 | Debug.Assert(ibStart >= 0); 24 | Debug.Assert(ibStart + cbSize <= array.Length); 25 | 26 | m_hash.TransformBytes(array, ibStart, cbSize); 27 | } 28 | 29 | 30 | protected override byte[] HashFinal() 31 | { 32 | byte[] ret = null; 33 | #if !NETCORE 34 | ret = m_hash.TransformFinal().GetBytes(); 35 | HashValue = ret; 36 | #endif 37 | return ret; 38 | } 39 | 40 | public override void Initialize() 41 | { 42 | m_hash.Initialize(); 43 | } 44 | } 45 | } 46 | #endif -------------------------------------------------------------------------------- /HashLib/Checksum/Adler32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Checksum 5 | { 6 | internal class Adler32 : Hash, IChecksum, IBlockHash, IHash32 7 | { 8 | private const uint MOD_ADLER = 65521; 9 | 10 | private uint m_a; 11 | private uint m_b; 12 | 13 | public Adler32() 14 | : base(4, 1) 15 | { 16 | } 17 | 18 | public override void Initialize() 19 | { 20 | m_a = 1; 21 | m_b = 0; 22 | } 23 | 24 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 25 | { 26 | Debug.Assert(a_index >= 0); 27 | Debug.Assert(a_length >= 0); 28 | Debug.Assert(a_index + a_length <= a_data.Length); 29 | 30 | for (int i = a_index; a_length > 0; i++, a_length--) 31 | { 32 | m_a = (m_a + a_data[i]) % MOD_ADLER; 33 | m_b = (m_b + m_a) % MOD_ADLER; 34 | 35 | } 36 | } 37 | 38 | public override HashResult TransformFinal() 39 | { 40 | return new HashResult((m_b << 16) | m_a); 41 | 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /HashLib/Hash32/OneAtTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class OneAtTime : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | 10 | public OneAtTime() 11 | : base(4, 1) 12 | { 13 | } 14 | 15 | public override void Initialize() 16 | { 17 | m_hash = 0; 18 | } 19 | 20 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 21 | { 22 | Debug.Assert(a_index >= 0); 23 | Debug.Assert(a_length >= 0); 24 | Debug.Assert(a_index + a_length <= a_data.Length); 25 | 26 | for (int i = a_index; a_length > 0; i++, a_length--) 27 | { 28 | m_hash += a_data[i]; 29 | m_hash += (m_hash << 10); 30 | m_hash ^= (m_hash >> 6); 31 | } 32 | } 33 | 34 | public override HashResult TransformFinal() 35 | { 36 | m_hash += (m_hash << 3); 37 | m_hash ^= (m_hash >> 11); 38 | m_hash += (m_hash << 15); 39 | 40 | return new HashResult(m_hash); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /HashLib/Hash32/AP.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class AP : Hash, IHash32, IBlockHash 7 | { 8 | private uint m_hash; 9 | private int m_index; 10 | 11 | public AP() 12 | : base(4, 1) 13 | { 14 | } 15 | 16 | public override void Initialize() 17 | { 18 | m_hash = 0; 19 | m_index = 0; 20 | } 21 | 22 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 23 | { 24 | Debug.Assert(a_index >= 0); 25 | Debug.Assert(a_length >= 0); 26 | Debug.Assert(a_index + a_length <= a_data.Length); 27 | 28 | for (int i = a_index; a_length > 0; i++, a_length--) 29 | { 30 | m_hash ^= ((m_index & 1) == 0) ? ((m_hash << 7) ^ a_data[i] ^ (m_hash >> 3)) : 31 | (~((m_hash << 11) ^ a_data[i] ^ (m_hash >> 5))); 32 | m_index++; 33 | } 34 | } 35 | 36 | public override HashResult TransformFinal() 37 | { 38 | return new HashResult(m_hash); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /HashLib/Extensions/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Runtime.CompilerServices; 8 | 9 | namespace HashLib 10 | { 11 | [DebuggerStepThrough] 12 | internal static class TypeExtensions 13 | { 14 | public static bool IsDerivedFrom(this Type a_type, Type a_baseType) 15 | { 16 | #if !NETCORE 17 | Debug.Assert(a_type != null); 18 | Debug.Assert(a_baseType != null); 19 | Debug.Assert(a_type.IsClass); 20 | Debug.Assert(a_baseType.IsClass); 21 | 22 | return a_baseType.IsAssignableFrom(a_type); 23 | #else 24 | return false; 25 | #endif 26 | } 27 | 28 | public static bool IsImplementInterface(this Type a_type, Type a_interfaceType) 29 | { 30 | #if !NETCORE 31 | Debug.Assert(a_type != null); 32 | Debug.Assert(a_interfaceType != null); 33 | Debug.Assert(a_type.IsClass || a_type.IsInterface || a_type.IsValueType); 34 | Debug.Assert(a_interfaceType.IsInterface); 35 | 36 | return a_interfaceType.IsAssignableFrom(a_type); 37 | #else 38 | return false; 39 | #endif 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/MarshalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace TomanuExtensions 6 | { 7 | [DebuggerStepThrough] 8 | public static class MarshalExtensions 9 | { 10 | public static byte[] StructureToArray(T a_struct) where T : struct 11 | { 12 | int len = Marshal.SizeOf(typeof(T)); 13 | byte[] arr = new byte[len]; 14 | IntPtr ptr = Marshal.AllocHGlobal(len); 15 | Marshal.StructureToPtr(a_struct, ptr, true); 16 | Marshal.Copy(ptr, arr, 0, len); 17 | Marshal.FreeHGlobal(ptr); 18 | return arr; 19 | } 20 | 21 | public static void ArrayToStruct(byte[] a_bytes, T a_struct) where T : struct 22 | { 23 | int size = Marshal.SizeOf(typeof(T)); 24 | IntPtr ptr = Marshal.AllocHGlobal(size); 25 | Marshal.StructureToPtr(a_struct, ptr, true); 26 | Marshal.Copy(a_bytes, 0, ptr, size); 27 | object obj = Marshal.PtrToStructure(ptr, typeof(T)); 28 | Marshal.FreeHGlobal(ptr); 29 | } 30 | 31 | public static byte[] StructurePtrToArray(IntPtr a_struct) where T : struct 32 | { 33 | int len = Marshal.SizeOf(typeof(T)); 34 | byte[] arr = new byte[len]; 35 | Marshal.Copy(a_struct, arr, 0, len); 36 | return arr; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /HashLib/Hash32/PJW.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class PJW : Hash, IHash32, IBlockHash 7 | { 8 | private const int BitsInUnsignedInt = sizeof(uint) * 8; 9 | private const int ThreeQuarters = (BitsInUnsignedInt * 3) / 4; 10 | private const int OneEighth = BitsInUnsignedInt / 8; 11 | private const uint HighBits = uint.MaxValue << (BitsInUnsignedInt - OneEighth); 12 | 13 | private uint m_hash; 14 | 15 | public PJW() 16 | : base(4, 1) 17 | { 18 | } 19 | 20 | public override void Initialize() 21 | { 22 | m_hash = 0; 23 | } 24 | 25 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 26 | { 27 | Debug.Assert(a_index >= 0); 28 | Debug.Assert(a_length >= 0); 29 | Debug.Assert(a_index + a_length <= a_data.Length); 30 | 31 | for (int i = a_index; a_length > 0; i++, a_length--) 32 | { 33 | m_hash = (m_hash << OneEighth) + a_data[i]; 34 | 35 | uint test = m_hash & HighBits; 36 | if (test != 0) 37 | m_hash = ((m_hash ^ (test >> ThreeQuarters)) & (~HighBits)); 38 | } 39 | } 40 | 41 | public override HashResult TransformFinal() 42 | { 43 | return new HashResult(m_hash); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /HashLibTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HashLibTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("HashLibTest")] 13 | [assembly: AssemblyCopyright("")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM componenets. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a44c639e-35ce-4c94-ad1e-c6aa924981cc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("2.1.0.0")] 35 | [assembly: AssemblyFileVersion("2.1.0.0")] 36 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | 6 | namespace TomanuExtensions 7 | { 8 | [DebuggerStepThrough] 9 | public static class CollectionExtensions 10 | { 11 | public static void RemoveRange(this ICollection a_collection, IEnumerable a_elements) 12 | { 13 | foreach (var ele in a_elements) 14 | a_collection.Remove(ele); 15 | } 16 | 17 | public static void RemoveAll(this ICollection a_collection, Predicate a_predicate) 18 | { 19 | var deleteList = a_collection.Where(child => a_predicate(child)).ToList(); 20 | deleteList.ForEach(t => a_collection.Remove(t)); 21 | } 22 | 23 | public static bool AddUnique(this ICollection a_collection, T a_value) 24 | { 25 | if (a_collection.Contains(a_value) == false) 26 | { 27 | a_collection.Add(a_value); 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | public static int AddRangeUnique(this ICollection a_collection, IEnumerable a_values) 34 | { 35 | var count = 0; 36 | foreach (var value in a_values) 37 | { 38 | if (a_collection.AddUnique(value)) 39 | count++; 40 | } 41 | return count; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /TomanuExtensions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TomanuExtensions")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TomanuExtensions")] 13 | [assembly: AssemblyCopyright("")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e556353a-238c-4eda-b027-dcb6b4036342")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.1.0.0")] 36 | [assembly: AssemblyFileVersion("2.1.0.0")] 37 | -------------------------------------------------------------------------------- /TomanuExtensions/Utils/FileUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace TomanuExtensions.Utils 5 | { 6 | public static class FileUtils 7 | { 8 | public static bool IsFilePathValid(string a_path) 9 | { 10 | if (String.IsNullOrEmpty(a_path.Trim())) 11 | { 12 | return false; 13 | } 14 | 15 | string pathname; 16 | string filename; 17 | 18 | try 19 | { 20 | pathname = Path.GetPathRoot(a_path); 21 | filename = Path.GetFileName(a_path); 22 | } 23 | catch (ArgumentException) 24 | { 25 | // GetPathRoot() and GetFileName() above will throw exceptions 26 | // if pathname/filename could not be parsed. 27 | 28 | return false; 29 | } 30 | 31 | // Make sure the filename part was actually specified 32 | if (String.IsNullOrEmpty(filename.Trim())) 33 | { 34 | return false; 35 | } 36 | 37 | // Not sure if additional checking below is needed, but no harm done 38 | if (pathname.IndexOfAny(Path.GetInvalidPathChars()) >= 0) 39 | { 40 | return false; 41 | } 42 | 43 | if (filename.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) 44 | { 45 | return false; 46 | } 47 | 48 | return true; 49 | } 50 | 51 | public static byte[] ReadFile(string a_path) 52 | { 53 | return File.ReadAllBytes(a_path); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /HashLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System; 5 | 6 | [assembly: CLSCompliant(false)] 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | //[assembly: AssemblyTitle("HashLib")] 12 | //[assembly: AssemblyDescription("")] 13 | //[assembly: AssemblyConfiguration("")] 14 | //[assembly: AssemblyCompany("")] 15 | //[assembly: AssemblyProduct("HashLib")] 16 | //[assembly: AssemblyCopyright("")] 17 | //[assembly: AssemblyTrademark("")] 18 | //[assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | //[assembly: ComVisible(false)] 24 | 25 | #if !NETCORE 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("9419e00e-d63b-4d92-954a-937ac7ec005d")] 28 | 29 | #endif 30 | 31 | // Version information for an assembly consists of the following four values: 32 | // 33 | // Major Version 34 | // Minor Version 35 | // Build Number 36 | // Revision 37 | // 38 | // You can specify all the values or you can default the Build and Revision Numbers 39 | // by using the '*' as shown below: 40 | // [assembly: AssemblyVersion("1.0.*")] 41 | //[assembly: AssemblyVersion("2.1.0.0")] 42 | //[assembly: AssemblyFileVersion("2.1.0.0")] 43 | 44 | [assembly: InternalsVisibleTo("HashLibTest")] 45 | 46 | -------------------------------------------------------------------------------- /HashLib/Extensions/ArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace HashLib 6 | { 7 | [DebuggerStepThrough] 8 | internal static class ArrayExtensions 9 | { 10 | /// 11 | /// Clear array with zeroes. 12 | /// 13 | /// 14 | public static void Clear(this T[] a_array, T a_value = default(T)) 15 | { 16 | for (int i = 0; i < a_array.Length; i++) 17 | a_array[i] = a_value; 18 | } 19 | 20 | /// 21 | /// Clear array with zeroes. 22 | /// 23 | /// 24 | public static void Clear(this T[,] a_array, T a_value = default(T)) 25 | { 26 | for (int x = 0; x < a_array.GetLength(0); x++) 27 | { 28 | for (int y = 0; y < a_array.GetLength(1); y++) 29 | { 30 | a_array[x, y] = a_value; 31 | } 32 | } 33 | } 34 | 35 | /// 36 | /// Return array stated from a_index and with a_count legth. 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | public static T[] SubArray(this T[] a_array, int a_index, int a_count) 44 | { 45 | T[] result = new T[a_count]; 46 | Array.Copy(a_array, a_index, result, 0, a_count); 47 | return result; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/StreamExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Reflection; 5 | 6 | namespace TomanuExtensions 7 | { 8 | [DebuggerStepThrough] 9 | public static class StreamExtensions 10 | { 11 | /// 12 | /// Get stream for resource. 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | public static Stream FromResource(Type a_type, string a_res_name, string a_res_subfolder = "") 19 | { 20 | if (a_res_subfolder != "") 21 | a_res_subfolder = "." + a_res_subfolder; 22 | 23 | string res = a_type.GetParentFullName() + a_res_subfolder + "." + a_res_name; 24 | return Assembly.GetAssembly(a_type).GetManifestResourceStream(res); 25 | } 26 | 27 | /// 28 | /// Read all bytes from stream. 29 | /// 30 | /// 31 | /// 32 | public static byte[] ReadAll(this Stream a_stream) 33 | { 34 | byte[] res = new byte[a_stream.Length]; 35 | a_stream.Read(res, 0, res.Length); 36 | return res; 37 | } 38 | 39 | public static Stream SeekToBegin(this Stream a_stream) 40 | { 41 | a_stream.Seek(0, SeekOrigin.Begin); 42 | return a_stream; 43 | } 44 | 45 | public static Stream SeekToEnd(this Stream a_stream) 46 | { 47 | a_stream.Seek(0, SeekOrigin.End); 48 | return a_stream; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /HashLib/Crypto/MDBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal abstract class MDBase : BlockHash, ICryptoNotBuildIn 6 | { 7 | protected readonly uint[] m_state; 8 | 9 | protected const uint C1 = 0x50a28be6; 10 | protected const uint C2 = 0x5a827999; 11 | protected const uint C3 = 0x5c4dd124; 12 | protected const uint C4 = 0x6ed9eba1; 13 | protected const uint C5 = 0x6d703ef3; 14 | protected const uint C6 = 0x8f1bbcdc; 15 | protected const uint C7 = 0x7a6d76e9; 16 | protected const uint C8 = 0xa953fd4e; 17 | 18 | protected MDBase(int a_state_length, int a_hash_size) 19 | : base(a_hash_size, 64) 20 | { 21 | m_state = new uint[a_state_length]; 22 | 23 | Initialize(); 24 | } 25 | 26 | public override void Initialize() 27 | { 28 | m_state[0] = 0x67452301; 29 | m_state[1] = 0xefcdab89; 30 | m_state[2] = 0x98badcfe; 31 | m_state[3] = 0x10325476; 32 | 33 | base.Initialize(); 34 | } 35 | 36 | protected override byte[] GetResult() 37 | { 38 | return Converters.ConvertUIntsToBytes(m_state); 39 | } 40 | 41 | protected override void Finish() 42 | { 43 | ulong bits = m_processed_bytes * 8; 44 | int padindex = (m_buffer.Pos < 56) ? (56 - m_buffer.Pos) : (120 - m_buffer.Pos); 45 | 46 | byte[] pad = new byte[padindex + 8]; 47 | 48 | pad[0] = 0x80; 49 | 50 | Converters.ConvertULongToBytes(bits, pad, padindex); 51 | padindex += 8; 52 | 53 | TransformBytes(pad, 0, padindex); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /HashLib/HashCryptoBuildIn.cs: -------------------------------------------------------------------------------- 1 | #if !USEBC 2 | 3 | using System; 4 | using System.Diagnostics; 5 | 6 | namespace HashLib 7 | { 8 | internal class HashCryptoBuildIn : Hash, ICryptoBuildIn 9 | { 10 | protected static readonly byte[] EMPTY = new byte[0]; 11 | 12 | protected System.Security.Cryptography.HashAlgorithm m_hash_algorithm; 13 | 14 | public HashCryptoBuildIn(System.Security.Cryptography.HashAlgorithm a_hash_algorithm, int a_block_size) 15 | : base(a_hash_algorithm.HashSize / 8, a_block_size) 16 | { 17 | #if !NETCORE 18 | if (a_hash_algorithm.CanReuseTransform == false) 19 | throw new NotImplementedException(); 20 | if (a_hash_algorithm.CanTransformMultipleBlocks == false) 21 | throw new NotImplementedException(); 22 | #endif 23 | m_hash_algorithm = a_hash_algorithm; 24 | } 25 | 26 | public override void Initialize() 27 | { 28 | m_hash_algorithm.Initialize(); 29 | } 30 | 31 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 32 | { 33 | Debug.Assert(a_index >= 0); 34 | Debug.Assert(a_length >= 0); 35 | Debug.Assert(a_index + a_length <= a_data.Length); 36 | #if !NETCORE 37 | m_hash_algorithm.TransformBlock(a_data, a_index, a_length, null, 0); 38 | #endif 39 | } 40 | 41 | public override HashResult TransformFinal() 42 | { 43 | byte[] result = null; 44 | #if !NETCORE 45 | m_hash_algorithm.TransformFinalBlock(EMPTY, 0, 0); 46 | result = m_hash_algorithm.Hash; 47 | #endif 48 | Debug.Assert(result.Length == HashSize); 49 | 50 | Initialize(); 51 | return new HashResult(result); 52 | } 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /TomanuExtensions/TestUtils/ProgressForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using System.Threading; 9 | 10 | namespace TomanuExtensions.TestUtils 11 | { 12 | public partial class ProgressForm : Form 13 | { 14 | public AutoResetEvent CreatedEvent = new AutoResetEvent(false); 15 | 16 | public ProgressForm() 17 | { 18 | InitializeComponent(); 19 | } 20 | 21 | public void AddLine(string a_line) 22 | { 23 | if (richTextBox.Lines.Length > 0) 24 | richTextBox.AppendText(System.Environment.NewLine); 25 | richTextBox.AppendText(a_line); 26 | 27 | richTextBox.SelectionStart = richTextBox.TextLength; 28 | richTextBox.ScrollToCaret(); 29 | } 30 | 31 | public void UpdateLastLine(string a_line) 32 | { 33 | if (richTextBox.Lines.Length > 0) 34 | DeleteLine(richTextBox.Lines.Count() - 1); 35 | 36 | AddLine(a_line); 37 | } 38 | 39 | private void DeleteLine(int a_line) 40 | { 41 | int start_index = richTextBox.GetFirstCharIndexFromLine(a_line); 42 | int count = richTextBox.Lines[a_line].Length; 43 | 44 | if (a_line < richTextBox.Lines.Length - 1) 45 | { 46 | count += richTextBox.GetFirstCharIndexFromLine(a_line + 1) - 47 | ((start_index + count - 1) + 1); 48 | } 49 | 50 | richTextBox.Text = richTextBox.Text.Remove(start_index, count); 51 | } 52 | 53 | private void ProgressForm_Shown(object sender, EventArgs e) 54 | { 55 | CreatedEvent.Set(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /TomanuExtensions/Utils/Profiler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | 5 | namespace TomanuExtensions.Utils 6 | { 7 | public class Profiler 8 | { 9 | public static long Profile(Action a_action, int a_tries = 5, int a_action_repeats = 1, bool a_boost = true) 10 | { 11 | IntPtr old_aff = Process.GetCurrentProcess().ProcessorAffinity; 12 | ProcessPriorityClass old_proc_prior = Process.GetCurrentProcess().PriorityClass; 13 | ThreadPriority old_thread_prio = Thread.CurrentThread.Priority; 14 | 15 | if (a_boost) 16 | { 17 | Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(1); 18 | Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; 19 | Thread.CurrentThread.Priority = ThreadPriority.Highest; 20 | } 21 | 22 | long result = long.MaxValue; 23 | Stopwatch sw = new Stopwatch(); 24 | 25 | try 26 | { 27 | for (int i = 0; i < a_tries; i++) 28 | { 29 | sw.Restart(); 30 | 31 | for (int j = 0; j < a_action_repeats; j++) 32 | a_action(); 33 | 34 | sw.Stop(); 35 | 36 | if (sw.ElapsedMilliseconds < result) 37 | result = sw.ElapsedMilliseconds; 38 | } 39 | } 40 | finally 41 | { 42 | if (a_boost) 43 | { 44 | Process.GetCurrentProcess().ProcessorAffinity = old_aff; 45 | Process.GetCurrentProcess().PriorityClass = old_proc_prior; 46 | Thread.CurrentThread.Priority = old_thread_prio; 47 | } 48 | } 49 | 50 | return result / a_action_repeats; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /HashLibTest/TestData/Hamsi224Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 6F5708887722A92764A4D55527FEAEBA32F297F05D35A8276301D508 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: B46FE654CE99E60376766D315B182DA5EA01A348AD05A75BA9C3E415 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: F2C07CEE69FE2C4C8DA44EE7519C59B9820405FCE3EC5D418B80C371 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 27F8046FCE7EE5D6DB5E231FEF0146301EECEDA6FE6F8551B9475E01 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 4E1075222ED0553AE64267E921D8D10432C535FD79A18E6133CD11ED 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: AD81CD3963C523285DA533BD2431CE93664F05E9888C5247846985BE 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: 7F8EA5AC7E197471BE82DB41AFCBDD11F36DF679EA53958FEBB9FF53 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: 845F5D423B6027359149A29F12CEDCCE7E2D0DFE41D5DE5C8F19D0E2 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: 89BCF46FEAE4623E8B866E423BD54C3783E485F03915888C03DBE2CA 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: B4A11B3902B2E7AC3AC0F741E9375A57DAC2E73898B8812B8B1ADFE5 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: E87FDE334481472297CF1100BB764DA738CA71C6AFF882DBA85EC0A8 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: FBCBDE90A0746F9E206521580A66638A6462402A72D1B54B207975A1 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: 63D6FBE247DCD1DA39F01D0D9666936FCE5A5EC1B2BD8CFE1A93304E 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: E80226FFEE593924339F9A9C8D97536D211031EAA12E9C21997529AB 56 | 57 | Repeat: 16777216 58 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 59 | Hash: F0A60F639B55AF68652DB7FE2A66EFD71CA96A45BB3C025DE4306C76 60 | 61 | Repeat: 67108865 62 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 63 | Hash: 1690D0A82513EF5ED1891BA5DA2DFCE3E0B191976644DE0A9703C447 64 | 65 | -------------------------------------------------------------------------------- /HashLib/MultipleTransformsNonBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace HashLib 6 | { 7 | internal abstract class MultipleTransformNonBlock : Hash, INonBlockHash 8 | { 9 | private List> m_list = new List>(); 10 | 11 | public MultipleTransformNonBlock(int a_hash_size, int a_block_size) 12 | : base(a_hash_size, a_block_size) 13 | { 14 | } 15 | 16 | public override void Initialize() 17 | { 18 | m_list.Clear(); 19 | } 20 | 21 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 22 | { 23 | Debug.Assert(a_index >= 0); 24 | Debug.Assert(a_length >= 0); 25 | Debug.Assert(a_index + a_length <= a_data.Length); 26 | 27 | m_list.Add(new ArraySegment(a_data, a_index, a_length)); 28 | } 29 | 30 | public override HashResult TransformFinal() 31 | { 32 | HashResult result = ComputeAggregatedBytes(Aggregate()); 33 | Initialize(); 34 | return result; 35 | } 36 | 37 | private byte[] Aggregate() 38 | { 39 | int sum = 0; 40 | foreach (ArraySegment seg in m_list) 41 | sum += seg.Count; 42 | 43 | byte[] res = new byte[sum]; 44 | 45 | int index = 0; 46 | 47 | foreach (ArraySegment seg in m_list) 48 | { 49 | Array.Copy(seg.Array, seg.Offset, res, index, seg.Count); 50 | index += seg.Count; 51 | } 52 | 53 | return res; 54 | } 55 | 56 | public override HashResult ComputeBytes(byte[] a_data) 57 | { 58 | Initialize(); 59 | return ComputeAggregatedBytes(a_data); 60 | } 61 | 62 | protected abstract HashResult ComputeAggregatedBytes(byte[] a_data); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Hamsi256Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 750E9EC469F4DB626BEE7E0C10DDAA1BD01FE194B94EFBABEBD24764DC2B13E9 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 048024E2A35CB74EDFCCBB0E84DBF621786914DD57065DAFB61C524BF78BAB6B 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: DC3425EA2DB8F0B83032E0535D6968FF5F81665936028D04F40CBDAC117898F8 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 16B45D5550C626781AEB126A5F59F251827CF14107AD2884EA456BF5EEC7C5FE 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 18A582FF502860F3E2BC29BF44ECC160AE130ED34359CB9ECA9498B079A3C402 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: 2D226157302D8DCB55B230E429637CB1A7F17E61F4097D64BA485C5581E512C1 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: 9F1F0C33E5E1867234C042109A6EAD4E2224F5C78743C81596105BF4ACB19EB1 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: 071D18AE1984BB03FF95D5E1E31C682D4689103C24D9DD58A9F946BD907DE24B 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: CFDB916033FCC3FA88B2D20A87DC3133CF2A33548B6E4C0537E8E73F9FE9EC51 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: A8A8D39B5E01B0520E1C9D5C1F0179797610379EC9611022B3D2E1DD39FB058C 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: C8A54E8AC60919F2796B062EF9CCB78CF9A5DB4E7902076088C86E6E535572DD 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: 2DF717ED61FEEEBBA91DF2610BAE16990E646E0B2D854AD7446571E1BD2242B8 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: 338E09148F5BDDC7FFB1CE4F87E4F27A727B462A8220A25F518F87AF04A1270B 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: 02B91B1C09FBF1AE3B01569C83426487050638AA61624A7294B969AACD697AFA 56 | 57 | Repeat: 16777216 58 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 59 | Hash: D3CD9FA5576C0CA65D008D0F5B510D307A1A1A393FFAA736700457143DBBDE0E 60 | 61 | Repeat: 67108865 62 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 63 | Hash: 46DF78AEDB3CF1E384288A571A1B21D1B5C2B324B6EFF1C091C17F29B914D09E 64 | 65 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Grindahl256Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 45A7600159AF54AE110FCB6EA0F38AD57875EAC814F74D2CBC247D28C89923E6 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 5F361D0E8F41497CCD40EEB2773E3B091EC2055028E04C536CF971986A95EB17 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 6ECBFA39ED1BBE78A032BAD6998BED7930F5FEF2F2C5FC750F60105D6B5F7DE7 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: FA55E410F98E3343504D9B44AB92C91888F58D1671E81A19BD8463282F31324B 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 355F4F0253E8EFA32B3DDFF245001E9F57927B5BB482267F02AB4D1F9BE3F486 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: 1C1AD6FC3B21CB32023B33F774CACD1E5F502D676A1ABB168696D13611FF1A45 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: 21AEB257D87F60B3CC4AF291EF6CBAFCAD21CB74DBFF894EA0E25FCEC11158FF 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: A25159EF343EF7ED64291168B2E26C365A2111D03312383DE9FFD8D4A8121B08 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: 61BB943A12C620E7CC0EF3523216CB6CE0DA24AEACD7D55FDEC96C2D70477E2E 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: 03FFC6EF9384FF0B36FA9BCDC1D20D79833EB9A8D54368A11C579A0D08FEF8B0 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: CDFBB1C70CA23D0E163A668697E5DE94CA939A88D718BDAA5729C0F4231CEB5F 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: E150D5D53F5067323ED907C40D4FEF9689C429D7480527BF50FEA95D3351937D 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: 4B4D1351AB660F8B42A72699823CD09622917296E7C9D87C33DEB71543E93A96 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: FA03435694941EABD900D1E8DE4B473C630431550D668AC9DECE1912C5800061 56 | 57 | Repeat: 16777216 58 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 59 | Hash: 171F074FEC784AF3362078E3B8878DB55866CFCBFB86E3642E5D30EA5CC83656 60 | 61 | Repeat: 67108865 62 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 63 | Hash: B62A41A8A1B6F903B0DA2F4B995CEB45E29DC60824FF6D35E0FE310ACEA995FC 64 | 65 | -------------------------------------------------------------------------------- /HashLib/Hash32/SuperFast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Hash32 4 | { 5 | internal class SuperFast : MultipleTransformNonBlock, IHash32 6 | { 7 | public SuperFast() 8 | : base(4, 4) 9 | { 10 | } 11 | 12 | protected override HashResult ComputeAggregatedBytes(byte[] a_data) 13 | { 14 | int length = a_data.Length; 15 | 16 | if (length == 0) 17 | return new HashResult(0); 18 | 19 | uint hash = (UInt32)length; 20 | 21 | int currentIndex = 0; 22 | 23 | while (length >= 4) 24 | { 25 | hash += (ushort)(a_data[currentIndex++] | a_data[currentIndex++] << 8); 26 | uint tmp = (uint)((uint)(a_data[currentIndex++] | a_data[currentIndex++] << 8) << 11) ^ hash; 27 | hash = (hash << 16) ^ tmp; 28 | hash += hash >> 11; 29 | 30 | length -= 4; 31 | } 32 | 33 | switch (length) 34 | { 35 | case 3: 36 | hash += (ushort)(a_data[currentIndex++] | a_data[currentIndex++] << 8); 37 | hash ^= hash << 16; 38 | hash ^= ((uint)a_data[currentIndex]) << 18; 39 | hash += hash >> 11; 40 | break; 41 | case 2: 42 | hash += (ushort)(a_data[currentIndex++] | a_data[currentIndex] << 8); 43 | hash ^= hash << 11; 44 | hash += hash >> 17; 45 | break; 46 | case 1: 47 | hash += a_data[currentIndex]; 48 | hash ^= hash << 10; 49 | hash += hash >> 1; 50 | break; 51 | default: 52 | break; 53 | } 54 | 55 | hash ^= hash << 3; 56 | hash += hash >> 5; 57 | hash ^= hash << 4; 58 | hash += hash >> 17; 59 | hash ^= hash << 25; 60 | hash += hash >> 6; 61 | 62 | return new HashResult(hash); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/MathExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace TomanuExtensions 7 | { 8 | public static class MathExtensions 9 | { 10 | public const double PI = 3.1415926535897932384626433832795; 11 | public const double SQRT2 = 1.4142135623730950488016887242097; 12 | public const double SQRT3 = 1.7320508075688772935274463415059; 13 | 14 | private static int[][] s_pascal_triangle; 15 | 16 | static MathExtensions() 17 | { 18 | s_pascal_triangle = new int [10][]; 19 | s_pascal_triangle[0] = new int[] { 1 }; 20 | 21 | for (int i = 1; i < s_pascal_triangle.Length; i++) 22 | s_pascal_triangle[i] = PascalTriangle(s_pascal_triangle[i - 1]); 23 | } 24 | 25 | public static int[] PascalTriangle(int a_row) 26 | { 27 | if (a_row <= s_pascal_triangle.Length) 28 | return s_pascal_triangle[a_row - 1]; 29 | else 30 | { 31 | int[] result = s_pascal_triangle[s_pascal_triangle.Length - 1]; 32 | 33 | for (int i = s_pascal_triangle.Length; i < a_row; i++) 34 | result = PascalTriangle(result); 35 | 36 | return result; 37 | } 38 | } 39 | 40 | private static int[] PascalTriangle(int[] a_start) 41 | { 42 | int[] result = new int[a_start.Length + 1]; 43 | 44 | result[0] = 1; 45 | result[result.Length - 1] = 1; 46 | 47 | for (int j = 0; j < a_start.Length - 1; j++) 48 | result[j+1] = a_start[j] + a_start[j + 1]; 49 | 50 | return result; 51 | } 52 | 53 | public static double ToRad(double a_deg) 54 | { 55 | return a_deg * PI / 180; 56 | } 57 | 58 | public static double ToDeg(double a_rad) 59 | { 60 | return a_rad * 180 / PI; 61 | } 62 | 63 | public static double Hypot(double a_x, double a_y) 64 | { 65 | return Math.Sqrt(a_x * a_x + a_y * a_y); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/MethodInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace TomanuExtensions 7 | { 8 | [DebuggerStepThrough] 9 | public static class MethodInfoExtensions 10 | { 11 | /// 12 | /// With virtual keyword. Also interface implementations even without virtual keyword. 13 | /// 14 | /// 15 | /// 16 | public static bool IsVirtual(this MethodInfo a_mi) 17 | { 18 | return a_mi.IsVirtual && !a_mi.IsAbstract && !a_mi.IsOverriden(); 19 | } 20 | 21 | /// 22 | /// With override keyword. 23 | /// 24 | /// 25 | /// 26 | public static bool IsOverriden(this MethodInfo a_mi) 27 | { 28 | return a_mi.DeclaringType != a_mi.GetBaseDefinition().DeclaringType; 29 | } 30 | 31 | public static IEnumerable GetBaseDefinitions(this MethodInfo a_mi, 32 | bool a_with_this = false) 33 | { 34 | if (a_with_this) 35 | yield return a_mi; 36 | 37 | MethodInfo t = a_mi; 38 | 39 | while ((t.GetBaseDefinition() != null) && (t.GetBaseDefinition() != t)) 40 | { 41 | t = t.GetBaseDefinition(); 42 | yield return t; 43 | } 44 | } 45 | 46 | public static bool IsDerivedFrom(this MethodInfo a_mi, MethodInfo a_base, 47 | bool a_with_this = false) 48 | { 49 | if (a_mi.Name != a_base.Name) 50 | return false; 51 | if (a_mi.DeclaringType == a_base.DeclaringType) 52 | { 53 | if (!a_mi.GetParameters().Select(p => p.ParameterType).SequenceEqual( 54 | a_base.GetParameters().Select(p => p.ParameterType))) 55 | { 56 | return false; 57 | } 58 | 59 | return a_with_this; 60 | } 61 | 62 | return a_mi.GetBaseDefinitions().Contains(a_base); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /TomanuExtensions/TestUtils/ProgressIndicator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Windows.Forms; 7 | 8 | namespace TomanuExtensions.TestUtils 9 | { 10 | public class ProgressIndicator 11 | { 12 | private Thread m_thread; 13 | private ProgressForm m_form = new ProgressForm(); 14 | 15 | public ProgressIndicator(string a_title) 16 | { 17 | m_form.Text = a_title; 18 | 19 | m_thread = new Thread(() => 20 | { 21 | Application.EnableVisualStyles(); 22 | Application.Run(m_form); 23 | m_thread = null; 24 | }); 25 | 26 | m_thread.SetApartmentState(ApartmentState.MTA); 27 | m_thread.Start(); 28 | m_form.CreatedEvent.WaitOne(); 29 | m_form.CreatedEvent.Close(); 30 | } 31 | 32 | public bool IsDisposed 33 | { 34 | get 35 | { 36 | return m_form.IsDisposed; 37 | } 38 | } 39 | 40 | private T Invoke(Func a_delegate) 41 | { 42 | if (m_form.InvokeRequired) 43 | { 44 | try 45 | { 46 | return (T)m_form.Invoke(a_delegate); 47 | } 48 | catch (ObjectDisposedException) 49 | { 50 | return default(T); 51 | } 52 | } 53 | else if (m_form.IsHandleCreated) 54 | return a_delegate(); 55 | else 56 | return default(T); 57 | } 58 | 59 | private void Invoke(Action a_delegate) 60 | { 61 | if (m_form.InvokeRequired) 62 | m_form.BeginInvoke(a_delegate); 63 | else if (m_form.IsHandleCreated) 64 | a_delegate(); 65 | } 66 | 67 | public void AddLine(string a_line) 68 | { 69 | Invoke(() => { m_form.AddLine(a_line); }); 70 | } 71 | 72 | public void UpdateLastLine(string a_line) 73 | { 74 | Invoke(() => { m_form.UpdateLastLine(a_line); }); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/IListExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace TomanuExtensions 6 | { 7 | [DebuggerStepThrough] 8 | public static class IListExtensions 9 | { 10 | public static int IndexOf(this IList a_list, T a_element) 11 | { 12 | for (int i = 0; i < a_list.Count; i++) 13 | { 14 | if (a_element.Equals(a_list[i])) 15 | return i; 16 | } 17 | 18 | return -1; 19 | } 20 | 21 | public static int IndexOf(this IList a_list, T a_element, IEqualityComparer a_comparer) 22 | { 23 | for (int i = 0; i < a_list.Count; i++) 24 | { 25 | if (a_comparer.Equals(a_list[i], a_element)) 26 | return i; 27 | } 28 | 29 | return -1; 30 | } 31 | 32 | public static T RemoveLast(this IList a_list) 33 | { 34 | T last = a_list.Last(); 35 | a_list.RemoveAt(a_list.Count - 1); 36 | return last; 37 | } 38 | 39 | public static T RemoveFirst(this IList a_list) 40 | { 41 | T first = a_list.First(); 42 | a_list.RemoveAt(0); 43 | return first; 44 | } 45 | 46 | public static T Last(this IList a_list) 47 | { 48 | return a_list[a_list.Count - 1]; 49 | } 50 | 51 | public static void RemoveRange(this IList a_list, IEnumerable a_elements) 52 | { 53 | foreach (var ele in a_elements) 54 | a_list.Remove(ele); 55 | } 56 | 57 | public static int GetHashCode(IList a_list) 58 | { 59 | int hash = 0; 60 | 61 | foreach (var el in a_list) 62 | hash ^= el.GetHashCode(); 63 | 64 | return hash; 65 | } 66 | 67 | public static bool Replace(this IList a_list, T a_old, T a_new) 68 | { 69 | int index = a_list.IndexOf(a_old); 70 | 71 | if (index == -1) 72 | return false; 73 | 74 | a_list[index] = a_new; 75 | return true; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/RectangleExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Drawing; 4 | using System.Xml.Linq; 5 | 6 | namespace TomanuExtensions 7 | { 8 | [DebuggerStepThrough] 9 | public static class RectangleExtensions 10 | { 11 | public static Rectangle Scale(this Rectangle a_rect, int a_ratio) 12 | { 13 | return new Rectangle(a_rect.Left * a_ratio, a_rect.Top * a_ratio, 14 | a_rect.Width * a_ratio, a_rect.Height * a_ratio); 15 | } 16 | 17 | /// 18 | /// Round mode: Math.Round() 19 | /// 20 | /// 21 | /// 22 | /// 23 | public static Rectangle Scale(this Rectangle a_rect, double a_ratio) 24 | { 25 | return Rectangle.FromLTRB( 26 | (a_rect.Left * a_ratio).Round(), 27 | (a_rect.Top * a_ratio).Round(), 28 | (a_rect.Right * a_ratio).Round(), 29 | (a_rect.Bottom * a_ratio).Round()); 30 | } 31 | 32 | public static IEnumerable EnumPixels(this Rectangle a_rect) 33 | { 34 | for (int y = a_rect.Top; y < a_rect.Bottom; y++) 35 | { 36 | for (int x = a_rect.Left; x < a_rect.Right; x++) 37 | { 38 | yield return new Point(x, y); 39 | } 40 | } 41 | } 42 | 43 | public static XElement GetAsXml(this Rectangle a_rect, string a_name) 44 | { 45 | return new XElement(a_name, 46 | new XElement("Left", a_rect.Left), 47 | new XElement("Top", a_rect.Top), 48 | new XElement("Width", a_rect.Width), 49 | new XElement("Height", a_rect.Height)); 50 | } 51 | 52 | public static Rectangle FromXml(XElement a_element) 53 | { 54 | return new Rectangle( 55 | a_element.Element("Left").Value.ToInt(), 56 | a_element.Element("Top").Value.ToInt(), 57 | a_element.Element("Width").Value.ToInt(), 58 | a_element.Element("Height").Value.ToInt()); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /HashLib/HMACBuildInAdapter.cs: -------------------------------------------------------------------------------- 1 | #if !USEBC 2 | 3 | using System; 4 | using System.Diagnostics; 5 | 6 | namespace HashLib 7 | { 8 | internal class HMACBuildInAdapter : Hash, IHMACBuildIn 9 | { 10 | protected static readonly byte[] EMPTY = new byte[0]; 11 | protected System.Security.Cryptography.HMAC m_hmac; 12 | private byte[] m_key; 13 | 14 | public byte[] Key 15 | { 16 | get 17 | { 18 | return (byte[])m_key.Clone(); 19 | } 20 | set 21 | { 22 | if (m_key == null) 23 | { 24 | m_key = new byte[0]; 25 | } 26 | else 27 | { 28 | m_key = (byte[])value.Clone(); 29 | } 30 | } 31 | } 32 | 33 | public int? KeyLength 34 | { 35 | get 36 | { 37 | return null; 38 | } 39 | } 40 | 41 | public HMACBuildInAdapter(System.Security.Cryptography.HMAC a_hmac, int a_block_size) 42 | : base(a_hmac.HashSize / 8, a_block_size) 43 | { 44 | m_hmac = a_hmac; 45 | m_key = new byte[0]; 46 | } 47 | 48 | public override void Initialize() 49 | { 50 | m_hmac.Initialize(); 51 | m_hmac.Key = Key; 52 | } 53 | 54 | public override HashResult TransformFinal() 55 | { 56 | #if !NETCORE 57 | m_hmac.TransformFinalBlock(EMPTY, 0, 0); 58 | byte[] result = m_hmac.Hash; 59 | 60 | 61 | Debug.Assert(result.Length == HashSize); 62 | 63 | Initialize(); 64 | return new HashResult(result); 65 | #else 66 | return null; 67 | #endif 68 | } 69 | 70 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 71 | { 72 | Debug.Assert(a_index >= 0); 73 | Debug.Assert(a_length >= 0); 74 | Debug.Assert(a_index + a_length <= a_data.Length); 75 | #if !NETCORE 76 | m_hmac.TransformBlock(a_data, a_index, a_length, null, 0); 77 | #endif 78 | } 79 | 80 | public override string Name 81 | { 82 | get 83 | { 84 | return String.Format("{0}({1})", GetType().Name, m_hmac.GetType().Name); 85 | } 86 | } 87 | } 88 | } 89 | #endif -------------------------------------------------------------------------------- /HashLib/Checksum/CRC64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Checksum 5 | { 6 | public static class CRC64Polynomials 7 | { 8 | public static ulong ISO = 0xD800000000000000; 9 | public static ulong ECMA_182 = 0xC96C5795D7870F42; 10 | } 11 | 12 | internal class CRC64_ISO : CRC64 13 | { 14 | public CRC64_ISO() 15 | : base(CRC64Polynomials.ISO) 16 | { 17 | } 18 | } 19 | 20 | internal class CRC64_ECMA : CRC64 21 | { 22 | public CRC64_ECMA() 23 | : base(CRC64Polynomials.ECMA_182) 24 | { 25 | } 26 | } 27 | 28 | internal class CRC64 : Hash, IChecksum, IBlockHash, IHash64 29 | { 30 | private ulong[] m_crc_tab = new ulong[256]; 31 | 32 | private ulong m_hash; 33 | private ulong m_initial_value; 34 | private ulong m_final_xor; 35 | 36 | public CRC64(ulong a_polynomial, ulong a_initial_value = ulong.MaxValue, ulong a_final_xor = ulong.MaxValue) 37 | : base(8, 1) 38 | { 39 | m_initial_value = a_initial_value; 40 | m_final_xor = a_final_xor; 41 | 42 | GenerateCRCTable(a_polynomial); 43 | } 44 | 45 | private void GenerateCRCTable(ulong a_poly64) 46 | { 47 | for (uint i = 0; i < 256; ++i) 48 | { 49 | ulong crc = i; 50 | 51 | for (uint j = 0; j < 8; ++j) 52 | { 53 | if ((crc & 1) == 1) 54 | crc = (crc >> 1) ^ a_poly64; 55 | else 56 | crc >>= 1; 57 | } 58 | 59 | m_crc_tab[i] = crc; 60 | } 61 | } 62 | 63 | public override void Initialize() 64 | { 65 | m_hash = m_initial_value; 66 | } 67 | 68 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 69 | { 70 | Debug.Assert(a_index >= 0); 71 | Debug.Assert(a_length >= 0); 72 | Debug.Assert(a_index + a_length <= a_data.Length); 73 | 74 | for (int i = a_index; a_length > 0; i++, a_length--) 75 | m_hash = (m_hash >> 8) ^ m_crc_tab[(byte)m_hash ^ a_data[i]]; 76 | } 77 | 78 | public override HashResult TransformFinal() 79 | { 80 | return new HashResult(m_hash ^ m_final_xor); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /HashLib/HashCryptoNotBuildIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib 5 | { 6 | internal abstract class BlockHash : Hash, IBlockHash 7 | { 8 | protected readonly HashBuffer m_buffer; 9 | protected ulong m_processed_bytes; 10 | 11 | protected BlockHash(int a_hash_size, int a_block_size, int a_buffer_size = -1) 12 | : base(a_hash_size, a_block_size) 13 | { 14 | if (a_buffer_size == -1) 15 | a_buffer_size = a_block_size; 16 | 17 | m_buffer = new HashBuffer(a_buffer_size); 18 | m_processed_bytes = 0; 19 | } 20 | 21 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 22 | { 23 | Debug.Assert(a_index >= 0); 24 | Debug.Assert(a_length >= 0); 25 | Debug.Assert(a_index + a_length <= a_data.Length); 26 | 27 | if (!m_buffer.IsEmpty) 28 | { 29 | if (m_buffer.Feed(a_data, ref a_index, ref a_length, ref m_processed_bytes)) 30 | TransformBuffer(); 31 | } 32 | 33 | while (a_length >= m_buffer.Length) 34 | { 35 | m_processed_bytes += (ulong)m_buffer.Length; 36 | TransformBlock(a_data, a_index); 37 | a_index += m_buffer.Length; 38 | a_length -= m_buffer.Length; 39 | } 40 | 41 | if (a_length > 0) 42 | m_buffer.Feed(a_data, ref a_index, ref a_length, ref m_processed_bytes); 43 | } 44 | 45 | public override void Initialize() 46 | { 47 | m_buffer.Initialize(); 48 | m_processed_bytes = 0; 49 | } 50 | 51 | public override HashResult TransformFinal() 52 | { 53 | Finish(); 54 | 55 | Debug.Assert(m_buffer.IsEmpty); 56 | 57 | byte[] result = GetResult(); 58 | 59 | Debug.Assert(result.Length == HashSize); 60 | 61 | Initialize(); 62 | return new HashResult(result); 63 | } 64 | 65 | protected void TransformBuffer() 66 | { 67 | Debug.Assert(m_buffer.IsFull); 68 | 69 | TransformBlock(m_buffer.GetBytes(), 0); 70 | } 71 | 72 | protected abstract void Finish(); 73 | protected abstract void TransformBlock(byte[] a_data, int a_index); 74 | protected abstract byte[] GetResult(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Murmur2Test.txt: -------------------------------------------------------------------------------- 1 | Key: 7B1A8FC5 2 | Repeat: 1 3 | Messsage: 4 | Hash: 00000000 5 | 6 | Key: E60E3263 7 | Repeat: 1 8 | Messsage: 9 | Hash: 00000000 10 | 11 | Key: 7B1A8FC5 12 | Repeat: 1 13 | Messsage: 40 14 | Hash: A8E8A4CE 15 | 16 | Key: E60E3263 17 | Repeat: 1 18 | Messsage: 31 19 | Hash: 71F0AC63 20 | 21 | Key: 7B1A8FC5 22 | Repeat: 1 23 | Messsage: 974D 24 | Hash: CAD35951 25 | 26 | Key: E60E3263 27 | Repeat: 1 28 | Messsage: 22DF 29 | Hash: 2BB8BEA4 30 | 31 | Key: 7B1A8FC5 32 | Repeat: 1 33 | Messsage: 6CCD13 34 | Hash: B9C68D6F 35 | 36 | Key: E60E3263 37 | Repeat: 1 38 | Messsage: D7D8D9 39 | Hash: 4168073E 40 | 41 | Key: 7B1A8FC5 42 | Repeat: 1 43 | Messsage: C639AEFB 44 | Hash: D0FBB8CA 45 | 46 | Key: E60E3263 47 | Repeat: 1 48 | Messsage: C4AB9E4B 49 | Hash: C21B8F10 50 | 51 | Key: 7B1A8FC5 52 | Repeat: 1 53 | Messsage: 2FD19BEB74 54 | Hash: EE56909A 55 | 56 | Key: E60E3263 57 | Repeat: 1 58 | Messsage: 93463948DE 59 | Hash: FEF0CB7C 60 | 61 | Key: 7B1A8FC5 62 | Repeat: 1 63 | Messsage: 5F4845276C8F 64 | Hash: D11911B9 65 | 66 | Key: E60E3263 67 | Repeat: 1 68 | Messsage: 8E854990BC47 69 | Hash: ED2B76E7 70 | 71 | Key: 7B1A8FC5 72 | Repeat: 1 73 | Messsage: A07EAA4EB0FE43 74 | Hash: 4316121E 75 | 76 | Key: E60E3263 77 | Repeat: 1 78 | Messsage: 3C6B87F34B29BE 79 | Hash: A29CA2BD 80 | 81 | Key: 7B1A8FC5 82 | Repeat: 1 83 | Messsage: 497843C583498751 84 | Hash: D3D32CF5 85 | 86 | Key: E60E3263 87 | Repeat: 1 88 | Messsage: 94418331CA295643 89 | Hash: A6BA7C10 90 | 91 | Key: 7B1A8FC5 92 | Repeat: 1 93 | Messsage: 3A094249FDBEBF62FA 94 | Hash: EAA129C7 95 | 96 | Key: E60E3263 97 | Repeat: 1 98 | Messsage: 2EECBE87D080E92C37 99 | Hash: 8BBC4951 100 | 101 | Key: 7B1A8FC5 102 | Repeat: 1 103 | Messsage: EB4A8BAE394046AFBC47 104 | Hash: 216C35BF 105 | 106 | Key: E60E3263 107 | Repeat: 1 108 | Messsage: D690224CB978D9CE79AF 109 | Hash: 9D9F500C 110 | 111 | Key: 7B1A8FC5 112 | Repeat: 1 113 | Messsage: C1E0C41E2A48278E4B4B81 114 | Hash: A8FC189B 115 | 116 | Key: E60E3263 117 | Repeat: 1 118 | Messsage: 6B650FB50D8E848DB94034 119 | Hash: FB81FBD2 120 | 121 | Key: 7B1A8FC5 122 | Repeat: 1 123 | Messsage: 628FC520629768E3633858B4 124 | Hash: 76332B9C 125 | 126 | Key: E60E3263 127 | Repeat: 1 128 | Messsage: D23D04773DA28CBCFB55462F 129 | Hash: 900BB25E 130 | 131 | Key: 7B1A8FC5 132 | Repeat: 1 133 | Messsage: F88CDF40292838C888B71D16EA 134 | Hash: 29367F99 135 | 136 | Key: E60E3263 137 | Repeat: 1 138 | Messsage: 5D88C69924B3A64312DB5808B1 139 | Hash: AAACD84E 140 | 141 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Murmur3Test.txt: -------------------------------------------------------------------------------- 1 | Key: 7B1A8FC5 2 | Repeat: 1 3 | Messsage: 4 | Hash: 86991F82 5 | 6 | Key: 24B0B688 7 | Repeat: 1 8 | Messsage: 9 | Hash: A1F371BB 10 | 11 | Key: 7B1A8FC5 12 | Repeat: 1 13 | Messsage: 40 14 | Hash: EBD052D6 15 | 16 | Key: 24B0B688 17 | Repeat: 1 18 | Messsage: 31 19 | Hash: CBFF3699 20 | 21 | Key: 7B1A8FC5 22 | Repeat: 1 23 | Messsage: 974D 24 | Hash: C1B4E96C 25 | 26 | Key: 24B0B688 27 | Repeat: 1 28 | Messsage: 22DF 29 | Hash: 8A80C26F 30 | 31 | Key: 7B1A8FC5 32 | Repeat: 1 33 | Messsage: 6CCD13 34 | Hash: 2ED5BB6A 35 | 36 | Key: 24B0B688 37 | Repeat: 1 38 | Messsage: D7D8D9 39 | Hash: 09C1C637 40 | 41 | Key: 7B1A8FC5 42 | Repeat: 1 43 | Messsage: C639AEFB 44 | Hash: EA9F514F 45 | 46 | Key: 24B0B688 47 | Repeat: 1 48 | Messsage: C4AB9E4B 49 | Hash: B2DE2BE4 50 | 51 | Key: 7B1A8FC5 52 | Repeat: 1 53 | Messsage: 2FD19BEB74 54 | Hash: 8B960B1C 55 | 56 | Key: 24B0B688 57 | Repeat: 1 58 | Messsage: 93463948DE 59 | Hash: D15391EC 60 | 61 | Key: 7B1A8FC5 62 | Repeat: 1 63 | Messsage: 5F4845276C8F 64 | Hash: 2FAA1D91 65 | 66 | Key: 24B0B688 67 | Repeat: 1 68 | Messsage: 8E854990BC47 69 | Hash: 2E5B4BD4 70 | 71 | Key: 7B1A8FC5 72 | Repeat: 1 73 | Messsage: A07EAA4EB0FE43 74 | Hash: 4985B099 75 | 76 | Key: 24B0B688 77 | Repeat: 1 78 | Messsage: 3C6B87F34B29BE 79 | Hash: 381B2A1F 80 | 81 | Key: 7B1A8FC5 82 | Repeat: 1 83 | Messsage: 497843C583498751 84 | Hash: EEA23F67 85 | 86 | Key: 24B0B688 87 | Repeat: 1 88 | Messsage: 94418331CA295643 89 | Hash: 25231F33 90 | 91 | Key: 7B1A8FC5 92 | Repeat: 1 93 | Messsage: 3A094249FDBEBF62FA 94 | Hash: 4D9E97B7 95 | 96 | Key: 24B0B688 97 | Repeat: 1 98 | Messsage: 2EECBE87D080E92C37 99 | Hash: 62C00DB8 100 | 101 | Key: 7B1A8FC5 102 | Repeat: 1 103 | Messsage: EB4A8BAE394046AFBC47 104 | Hash: 010A316E 105 | 106 | Key: 24B0B688 107 | Repeat: 1 108 | Messsage: D690224CB978D9CE79AF 109 | Hash: CA0C9A27 110 | 111 | Key: 7B1A8FC5 112 | Repeat: 1 113 | Messsage: C1E0C41E2A48278E4B4B81 114 | Hash: BAD3F8A3 115 | 116 | Key: 24B0B688 117 | Repeat: 1 118 | Messsage: 6B650FB50D8E848DB94034 119 | Hash: 2378215B 120 | 121 | Key: 7B1A8FC5 122 | Repeat: 1 123 | Messsage: 628FC520629768E3633858B4 124 | Hash: 757B4353 125 | 126 | Key: 24B0B688 127 | Repeat: 1 128 | Messsage: D23D04773DA28CBCFB55462F 129 | Hash: EEE4BABE 130 | 131 | Key: 7B1A8FC5 132 | Repeat: 1 133 | Messsage: F88CDF40292838C888B71D16EA 134 | Hash: 24794066 135 | 136 | Key: 24B0B688 137 | Repeat: 1 138 | Messsage: 5D88C69924B3A64312DB5808B1 139 | Hash: 9ECFBB3B 140 | 141 | -------------------------------------------------------------------------------- /HashLib/IHashInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib 4 | { 5 | public interface ICrypto : IHash, IBlockHash 6 | { 7 | } 8 | 9 | public interface ICryptoBuildIn : ICrypto 10 | { 11 | } 12 | 13 | public interface ICryptoNotBuildIn : ICrypto 14 | { 15 | } 16 | 17 | public interface IHMAC : IWithKey, ICrypto 18 | { 19 | } 20 | 21 | public interface IHMACBuildIn : IHMAC, ICryptoBuildIn 22 | { 23 | } 24 | 25 | public interface IHMACNotBuildIn : IHMAC, ICryptoNotBuildIn 26 | { 27 | } 28 | 29 | public interface IHasHMACBuildIn : ICrypto 30 | { 31 | #if !USEBC 32 | System.Security.Cryptography.HMAC GetBuildHMAC(); 33 | #endif 34 | } 35 | 36 | public interface IHash32 : IHash 37 | { 38 | } 39 | 40 | public interface IHash128 : IHash 41 | { 42 | } 43 | 44 | public interface IHash64 : IHash 45 | { 46 | } 47 | 48 | public interface IWithKey : IHash 49 | { 50 | byte[] Key 51 | { 52 | get; 53 | set; 54 | } 55 | 56 | int? KeyLength 57 | { 58 | get; 59 | } 60 | } 61 | 62 | public interface IHashWithKey : IHash, IWithKey 63 | { 64 | } 65 | 66 | public interface IFastHash32 67 | { 68 | int ComputeByteFast(byte a_data); 69 | int ComputeCharFast(char a_data); 70 | int ComputeShortFast(short a_data); 71 | int ComputeUShortFast(ushort a_data); 72 | int ComputeIntFast(int a_data); 73 | int ComputeUIntFast(uint a_data); 74 | int ComputeLongFast(long a_data); 75 | int ComputeULongFast(ulong a_data); 76 | int ComputeFloatFast(float a_data); 77 | int ComputeDoubleFast(double a_data); 78 | int ComputeStringFast(string a_data); 79 | int ComputeBytesFast(byte[] a_data); 80 | int ComputeCharsFast(char[] a_data); 81 | int ComputeShortsFast(short[] a_data); 82 | int ComputeUShortsFast(ushort[] a_data); 83 | int ComputeIntsFast(int[] a_data); 84 | int ComputeUIntsFast(uint[] a_data); 85 | int ComputeLongsFast(long[] a_data); 86 | int ComputeULongsFast(ulong[] a_data); 87 | int ComputeDoublesFast(double[] a_data); 88 | int ComputeFloatsFast(float[] a_data); 89 | } 90 | 91 | public interface IBlockHash 92 | { 93 | } 94 | 95 | public interface INonBlockHash 96 | { 97 | } 98 | 99 | public interface IChecksum 100 | { 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/DirectoryInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.IO; 4 | 5 | namespace TomanuExtensions 6 | { 7 | [DebuggerStepThrough] 8 | public static class DirectoryInfoExtensions 9 | { 10 | public static void DeleteAll(this DirectoryInfo a_dir_info) 11 | { 12 | if (!a_dir_info.Exists) 13 | return; 14 | 15 | foreach (FileInfo file_info in a_dir_info.GetFiles()) 16 | file_info.Delete(); 17 | 18 | foreach (DirectoryInfo dir_info in a_dir_info.GetDirectories()) 19 | dir_info.DeleteAll(); 20 | 21 | a_dir_info.Delete(false); 22 | } 23 | 24 | public static void DeleteContent(this DirectoryInfo a_dir_info) 25 | { 26 | if (!a_dir_info.Exists) 27 | return; 28 | 29 | foreach (FileInfo file_info in a_dir_info.GetFiles()) 30 | file_info.Delete(); 31 | 32 | foreach (DirectoryInfo dir_info in a_dir_info.GetDirectories()) 33 | dir_info.DeleteAll(); 34 | } 35 | 36 | public static void CreateOrEmpty(this DirectoryInfo a_dir_info) 37 | { 38 | a_dir_info.DeleteContent(); 39 | a_dir_info.Create(); 40 | } 41 | 42 | public static FileInfo[] FindFilesRecursive(this DirectoryInfo a_dir_info, string a_pattern) 43 | { 44 | var foundFiles = new List(); 45 | FindFilesRecursive(a_dir_info, a_pattern, foundFiles); 46 | return foundFiles.ToArray(); 47 | } 48 | 49 | private static void FindFilesRecursive(DirectoryInfo a_dir_info, string a_pattern, 50 | List a_files) 51 | { 52 | a_files.AddRange(a_dir_info.GetFiles(a_pattern)); 53 | 54 | foreach (var dir in a_dir_info.GetDirectories()) 55 | FindFilesRecursive(dir, a_pattern, a_files); 56 | } 57 | 58 | public static string FindExistingDirectory(this DirectoryInfo a_di) 59 | { 60 | string str = a_di.FullName; 61 | 62 | for (; ; ) 63 | { 64 | DirectoryInfo di = new DirectoryInfo(str); 65 | 66 | if (di.Exists) 67 | return str; 68 | 69 | if (di.Parent == null) 70 | return ""; 71 | 72 | str = di.Parent.FullName; 73 | } 74 | } 75 | 76 | public static DirectoryInfo Append(this DirectoryInfo a_di, string a_dir) 77 | { 78 | return new DirectoryInfo(a_di.FullName + Path.DirectorySeparatorChar + a_dir); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /TomanuExtensions/TestUtils/ProgressForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace TomanuExtensions.TestUtils 2 | { 3 | partial class ProgressForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.richTextBox = new System.Windows.Forms.RichTextBox(); 32 | this.SuspendLayout(); 33 | // 34 | // richTextBox 35 | // 36 | this.richTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 37 | | System.Windows.Forms.AnchorStyles.Left) 38 | | System.Windows.Forms.AnchorStyles.Right))); 39 | this.richTextBox.Location = new System.Drawing.Point(12, 12); 40 | this.richTextBox.Name = "richTextBox"; 41 | this.richTextBox.ReadOnly = true; 42 | this.richTextBox.Size = new System.Drawing.Size(720, 293); 43 | this.richTextBox.TabIndex = 0; 44 | this.richTextBox.Text = ""; 45 | // 46 | // ProgressForm 47 | // 48 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 49 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 50 | this.ClientSize = new System.Drawing.Size(744, 317); 51 | this.Controls.Add(this.richTextBox); 52 | this.MaximizeBox = false; 53 | this.Name = "ProgressForm"; 54 | this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; 55 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 56 | this.Text = "Test"; 57 | this.Shown += new System.EventHandler(this.ProgressForm_Shown); 58 | this.ResumeLayout(false); 59 | 60 | } 61 | 62 | #endregion 63 | 64 | private System.Windows.Forms.RichTextBox richTextBox; 65 | 66 | } 67 | } -------------------------------------------------------------------------------- /HashLib/HashResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace HashLib 6 | { 7 | [DebuggerDisplay("HashResult, Size: {m_hash.Length}, Hash: {ToString()}")] 8 | public class HashResult 9 | { 10 | private byte[] m_hash; 11 | 12 | public HashResult(uint a_hash) 13 | { 14 | m_hash = BitConverter.GetBytes(a_hash); 15 | } 16 | 17 | internal HashResult(int a_hash) 18 | { 19 | m_hash = BitConverter.GetBytes(a_hash); 20 | } 21 | 22 | public HashResult(ulong a_hash) 23 | { 24 | m_hash = BitConverter.GetBytes(a_hash); 25 | } 26 | public HashResult(byte[] a_hash) 27 | { 28 | m_hash = a_hash; 29 | } 30 | 31 | public byte[] GetBytes() 32 | { 33 | return m_hash.ToArray(); 34 | } 35 | 36 | public uint GetUInt() 37 | { 38 | if (m_hash.Length != 4) 39 | throw new InvalidOperationException(); 40 | 41 | return BitConverter.ToUInt32(m_hash, 0); 42 | } 43 | 44 | public int GetInt() 45 | { 46 | if (m_hash.Length != 4) 47 | throw new InvalidOperationException(); 48 | 49 | return BitConverter.ToInt32(m_hash, 0); 50 | } 51 | 52 | public ulong GetULong() 53 | { 54 | if (m_hash.Length != 8) 55 | throw new InvalidOperationException(); 56 | 57 | return BitConverter.ToUInt64(m_hash, 0); 58 | } 59 | 60 | public override string ToString() 61 | { 62 | return Converters.ConvertBytesToHexString(m_hash); 63 | } 64 | 65 | public override bool Equals(Object a_obj) 66 | { 67 | HashResult hash_result = a_obj as HashResult; 68 | if ((HashResult)hash_result == null) 69 | return false; 70 | 71 | return Equals(hash_result); 72 | } 73 | 74 | public bool Equals(HashResult a_hashResult) 75 | { 76 | return HashResult.SameArrays(a_hashResult.GetBytes(), m_hash); 77 | } 78 | 79 | public override int GetHashCode() 80 | { 81 | return Convert.ToBase64String(m_hash).GetHashCode(); 82 | } 83 | 84 | private static bool SameArrays(byte[] a_ar1, byte[] a_ar2) 85 | { 86 | if (Object.ReferenceEquals(a_ar1, a_ar2)) 87 | return true; 88 | 89 | if (a_ar1.Length != a_ar2.Length) 90 | return false; 91 | 92 | for (int i = 0; i < a_ar1.Length; i++) 93 | if (a_ar1[i] != a_ar2[i]) 94 | return false; 95 | 96 | return true; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /TomanuExtensions/Utils/Bits.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace TomanuExtensions.Utils 4 | { 5 | public static class Bits 6 | { 7 | public static bool IsSet(byte a_byte, int a_bit_index) 8 | { 9 | Debug.Assert(a_bit_index >= 0); 10 | Debug.Assert(a_bit_index <= 7); 11 | 12 | return (a_byte & (1 << a_bit_index)) != 0; 13 | } 14 | 15 | public static void SetBit(ref byte a_byte, int a_bit_index, bool a_bit_value) 16 | { 17 | Debug.Assert(a_bit_index >= 0); 18 | Debug.Assert(a_bit_index <= 7); 19 | 20 | if (a_bit_value) 21 | a_byte = (byte)(a_byte | (1 << a_bit_index)); 22 | else 23 | a_byte = (byte)(a_byte & ~(1 << a_bit_index)); 24 | } 25 | 26 | public static bool IsSet(ushort a_ushort, int a_bitIndex) 27 | { 28 | Debug.Assert(a_bitIndex >= 0); 29 | Debug.Assert(a_bitIndex <= 15); 30 | 31 | return (a_ushort & (1 << a_bitIndex)) != 0; 32 | } 33 | 34 | public static void SetBit(ref ushort a_ushort, int a_bit_index, bool a_bit_value) 35 | { 36 | Debug.Assert(a_bit_index >= 0); 37 | Debug.Assert(a_bit_index <= 15); 38 | 39 | if (a_bit_value) 40 | a_ushort = (ushort)(a_ushort | (1 << a_bit_index)); 41 | else 42 | a_ushort = (ushort)(a_ushort & ~(1 << a_bit_index)); 43 | } 44 | 45 | public static bool IsSet(uint a_uint, int a_bit_index) 46 | { 47 | Debug.Assert(a_bit_index >= 0); 48 | Debug.Assert(a_bit_index <= 31); 49 | 50 | return (a_uint & (1 << a_bit_index)) != 0; 51 | } 52 | 53 | public static void SetBit(ref uint a_uint, int a_bit_index, bool a_bit_value) 54 | { 55 | Debug.Assert(a_bit_index >= 0); 56 | Debug.Assert(a_bit_index <= 31); 57 | 58 | if (a_bit_value) 59 | a_uint = a_uint | (1U << a_bit_index); 60 | else 61 | a_uint = a_uint & ~(1U << a_bit_index); 62 | } 63 | 64 | static public uint RotateLeft(uint a_uint, int a_n) 65 | { 66 | Debug.Assert(a_n >= 0); 67 | 68 | return (uint)((a_uint << a_n) | (a_uint >> (32 - a_n))); 69 | } 70 | 71 | static public ulong RotateLeft(ulong a_ulong, int a_n) 72 | { 73 | Debug.Assert(a_n >= 0); 74 | 75 | return (ulong)((a_ulong << a_n) | (a_ulong >> (64 - a_n))); 76 | } 77 | 78 | static public uint RotateRight(uint a_uint, int a_n) 79 | { 80 | Debug.Assert(a_n >= 0); 81 | 82 | return (uint)((a_uint >> a_n) | (a_uint << (32 - a_n))); 83 | } 84 | 85 | static public ulong RotateRight(ulong a_ulong, int a_n) 86 | { 87 | Debug.Assert(a_n >= 0); 88 | 89 | return (ulong)((a_ulong >> a_n) | (a_ulong << (64 - a_n))); 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /HashLib/Checksum/CRC32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace HashLib.Checksum 6 | { 7 | public static class CRC32Polynomials 8 | { 9 | public static uint IEEE_802_3 = 0xEDB88320; 10 | public static uint Castagnoli = 0x82F63B78; 11 | public static uint Koopman = 0xEB31D82E; 12 | public static uint CRC_32Q = 0xD5828281; 13 | } 14 | 15 | internal class CRC32_IEEE : CRC32 16 | { 17 | public CRC32_IEEE() 18 | : base(CRC32Polynomials.IEEE_802_3) 19 | { 20 | } 21 | } 22 | 23 | internal class CRC32_CASTAGNOLI : CRC32 24 | { 25 | public CRC32_CASTAGNOLI() 26 | : base(CRC32Polynomials.Castagnoli) 27 | { 28 | } 29 | } 30 | 31 | internal class CRC32_KOOPMAN : CRC32 32 | { 33 | public CRC32_KOOPMAN() 34 | : base(CRC32Polynomials.Koopman) 35 | { 36 | } 37 | } 38 | 39 | internal class CRC32_Q : CRC32 40 | { 41 | public CRC32_Q() 42 | : base(CRC32Polynomials.CRC_32Q) 43 | { 44 | } 45 | } 46 | 47 | internal class CRC32 : Hash, IChecksum, IBlockHash, IHash32 48 | { 49 | private uint[] m_crc_tab = new uint[256]; 50 | 51 | private uint m_hash; 52 | private uint m_initial_value; 53 | private uint m_final_xor; 54 | 55 | public CRC32(uint a_polynomial, uint a_initial_value = uint.MaxValue, uint a_final_xor = uint.MaxValue) 56 | : base(4, 1) 57 | { 58 | m_initial_value = a_initial_value; 59 | m_final_xor = a_final_xor; 60 | 61 | GenerateCRCTable(a_polynomial); 62 | } 63 | 64 | private void GenerateCRCTable(uint a_poly32) 65 | { 66 | for (uint i = 0; i < 256; ++i) 67 | { 68 | uint crc = i; 69 | 70 | for (int j = 0; j < 8; j++) 71 | { 72 | if ((crc & 1) == 1) 73 | crc = (crc >> 1) ^ a_poly32; 74 | else 75 | crc = crc >> 1; 76 | } 77 | 78 | m_crc_tab[i] = crc; 79 | } 80 | } 81 | 82 | public override void Initialize() 83 | { 84 | m_hash = m_initial_value; 85 | } 86 | 87 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 88 | { 89 | Debug.Assert(a_index >= 0); 90 | Debug.Assert(a_length >= 0); 91 | Debug.Assert(a_index + a_length <= a_data.Length); 92 | 93 | for (int i = a_index; a_length > 0; i++, a_length--) 94 | m_hash = (m_hash >> 8) ^ m_crc_tab[(byte)m_hash ^ a_data[i]]; 95 | } 96 | 97 | public override HashResult TransformFinal() 98 | { 99 | return new HashResult(m_hash ^ m_final_xor); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /HashLib/IHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.IO; 4 | 5 | namespace HashLib 6 | { 7 | public interface IHash 8 | { 9 | string Name { get; } 10 | int BlockSize { get; } 11 | int HashSize { get; } 12 | 13 | HashResult ComputeObject(object a_data); 14 | HashResult ComputeByte(byte a_data); 15 | HashResult ComputeChar(char a_data); 16 | HashResult ComputeShort(short a_data); 17 | HashResult ComputeUShort(ushort a_data); 18 | HashResult ComputeInt(int a_data); 19 | HashResult ComputeUInt(uint a_data); 20 | HashResult ComputeLong(long a_data); 21 | HashResult ComputeULong(ulong a_data); 22 | HashResult ComputeFloat(float a_data); 23 | HashResult ComputeDouble(double a_data); 24 | HashResult ComputeString(string a_data); 25 | HashResult ComputeString(string a_data, Encoding a_encoding); 26 | HashResult ComputeBytes(byte[] a_data); 27 | HashResult ComputeChars(char[] a_data); 28 | HashResult ComputeShorts(short[] a_data); 29 | HashResult ComputeUShorts(ushort[] a_data); 30 | HashResult ComputeInts(int[] a_data); 31 | HashResult ComputeUInts(uint[] a_data); 32 | HashResult ComputeLongs(long[] a_data); 33 | HashResult ComputeULongs(ulong[] a_data); 34 | HashResult ComputeDoubles(double[] a_data); 35 | HashResult ComputeFloats(float[] a_data); 36 | HashResult ComputeStream(Stream a_stream, long a_length = -1); 37 | HashResult ComputeFile(string a_file_name, long a_from = 0, long a_length = -1); 38 | 39 | void Initialize(); 40 | 41 | void TransformBytes(byte[] a_data); 42 | void TransformBytes(byte[] a_data, int a_index); 43 | void TransformBytes(byte[] a_data, int a_index, int a_length); 44 | 45 | HashResult TransformFinal(); 46 | 47 | void TransformObject(object a_data); 48 | void TransformByte(byte a_data); 49 | void TransformChar(char a_data); 50 | void TransformShort(short a_data); 51 | void TransformUShort(ushort a_data); 52 | void TransformInt(int a_data); 53 | void TransformUInt(uint a_data); 54 | void TransformLong(long a_data); 55 | void TransformULong(ulong a_data); 56 | void TransformFloat(float a_data); 57 | void TransformDouble(double a_data); 58 | void TransformString(string a_data); 59 | void TransformString(string a_data, Encoding a_encoding); 60 | void TransformChars(char[] a_data); 61 | void TransformShorts(short[] a_data); 62 | void TransformUShorts(ushort[] a_data); 63 | void TransformInts(int[] a_data); 64 | void TransformUInts(uint[] a_data); 65 | void TransformLongs(long[] a_data); 66 | void TransformULongs(ulong[] a_data); 67 | void TransformDoubles(double[] a_data); 68 | void TransformFloats(float[] a_data); 69 | void TransformStream(Stream a_stream, long a_length = -1); 70 | void TransformFile(string a_file_name, long a_from = 0, long a_length = -1); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/PropertyInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | namespace TomanuExtensions 6 | { 7 | [DebuggerStepThrough] 8 | public static class PropertyInfoExtensions 9 | { 10 | /// 11 | /// With virtual keyword. Also interface implementations even without virtual keyword. 12 | /// 13 | /// 14 | /// 15 | public static bool IsVirtual(this PropertyInfo a_pi) 16 | { 17 | if (a_pi.GetAccessors(true).Length == 0) 18 | return false; 19 | 20 | return a_pi.GetAccessors(true)[0].IsVirtual(); 21 | } 22 | 23 | /// 24 | /// With abstract keyword. 25 | /// 26 | /// 27 | /// 28 | public static bool IsAbstract(this PropertyInfo a_pi) 29 | { 30 | if (a_pi.GetAccessors(true).Length == 0) 31 | return false; 32 | return a_pi.GetAccessors(true)[0].IsAbstract; 33 | } 34 | 35 | /// 36 | /// With override keyword. 37 | /// 38 | /// 39 | /// 40 | public static bool IsOverriden(this PropertyInfo a_pi) 41 | { 42 | if (a_pi.GetAccessors(true).Length == 0) 43 | return false; 44 | 45 | return a_pi.GetAccessors(true)[0].IsOverriden(); 46 | } 47 | 48 | public static bool IsDerivedFrom(this PropertyInfo a_pi, PropertyInfo a_base, 49 | bool a_with_this = false) 50 | { 51 | if (a_pi.Name != a_base.Name) 52 | return false; 53 | if (a_pi.PropertyType != a_base.PropertyType) 54 | return false; 55 | if (!a_pi.GetIndexParameters().Select(p => p.ParameterType).SequenceEqual( 56 | a_base.GetIndexParameters().Select(p => p.ParameterType))) 57 | { 58 | return false; 59 | } 60 | if (a_pi.DeclaringType == a_base.DeclaringType) 61 | return a_with_this; 62 | 63 | MethodInfo m1 = a_pi.GetGetMethod(true); 64 | MethodInfo m3 = a_base.GetGetMethod(true); 65 | 66 | if ((m1 != null) && (m3 != null)) 67 | { 68 | if (m1.GetBaseDefinitions().ContainsAny(m3.GetBaseDefinitions(true))) 69 | return true; 70 | } 71 | else if ((m1 != null) || (m3 != null)) 72 | return false; 73 | 74 | MethodInfo m2 = a_pi.GetSetMethod(true); 75 | MethodInfo m4 = a_base.GetSetMethod(true); 76 | 77 | if ((m2 != null) && (m4 != null)) 78 | { 79 | if (m2.GetBaseDefinitions().ContainsAny(m4.GetBaseDefinitions(true))) 80 | return true; 81 | } 82 | else if ((m2 != null) || (m4 != null)) 83 | return false; 84 | 85 | return false; 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /HashLib/HMACNotBuildInAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib 5 | { 6 | internal class HMACNotBuildInAdapter : Hash, IHMACNotBuildIn 7 | { 8 | private byte[] m_opad; 9 | private byte[] m_ipad; 10 | private IHash m_hash; 11 | private byte[] m_key; 12 | 13 | public virtual byte[] Key 14 | { 15 | get 16 | { 17 | return (byte[])m_key.Clone(); 18 | } 19 | set 20 | { 21 | if (value == null) 22 | { 23 | m_key = new byte[0]; 24 | } 25 | else 26 | { 27 | m_key = (byte[])value.Clone(); 28 | } 29 | } 30 | } 31 | 32 | internal HMACNotBuildInAdapter(IHash a_underlyingHash) 33 | : base(a_underlyingHash.HashSize, a_underlyingHash.BlockSize) 34 | { 35 | m_hash = a_underlyingHash; 36 | m_key = new byte[0]; 37 | m_ipad = new byte[m_hash.BlockSize]; 38 | m_opad = new byte[m_hash.BlockSize]; 39 | } 40 | 41 | private void UpdatePads() 42 | { 43 | byte[] key; 44 | if (Key.Length > m_hash.BlockSize) 45 | key = m_hash.ComputeBytes(Key).GetBytes(); 46 | else 47 | key = Key; 48 | 49 | for (int i = 0; i < m_hash.BlockSize; i++) 50 | { 51 | m_ipad[i] = 0x36; 52 | m_opad[i] = 0x5c; 53 | } 54 | 55 | for (int i = 0; i < key.Length; i++) 56 | { 57 | m_ipad[i] ^= key[i]; 58 | m_opad[i] ^= key[i]; 59 | } 60 | } 61 | 62 | public override void Initialize() 63 | { 64 | m_hash.Initialize(); 65 | UpdatePads(); 66 | m_hash.TransformBytes(m_ipad); 67 | } 68 | 69 | public override HashResult TransformFinal() 70 | { 71 | HashResult h = m_hash.TransformFinal(); 72 | m_hash.TransformBytes(m_opad); 73 | m_hash.TransformBytes(h.GetBytes()); 74 | h = m_hash.TransformFinal(); 75 | Initialize(); 76 | return h; 77 | } 78 | 79 | public override void TransformBytes(byte[] a_data, int a_index, int a_length) 80 | { 81 | Debug.Assert(a_index >= 0); 82 | Debug.Assert(a_length >= 0); 83 | Debug.Assert(a_index + a_length <= a_data.Length); 84 | 85 | m_hash.TransformBytes(a_data, a_index, a_length); 86 | } 87 | 88 | public override string Name 89 | { 90 | get 91 | { 92 | return String.Format("{0}({1})", GetType().Name, m_hash.GetType().Name); 93 | } 94 | } 95 | 96 | public int? KeyLength 97 | { 98 | get 99 | { 100 | return null; 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /HashLib/Hash32/DotNet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace HashLib.Hash32 5 | { 6 | internal class DotNet : MultipleTransformNonBlock, IHash32, IFastHash32 7 | { 8 | public DotNet() 9 | : base(4, 8) 10 | { 11 | } 12 | 13 | protected override HashResult ComputeAggregatedBytes(byte[] a_data) 14 | { 15 | return new HashResult(ComputeBytesFast(a_data)); 16 | } 17 | 18 | public int ComputeBytesFast(byte[] a_data) 19 | { 20 | return a_data.GetHashCode(); 21 | } 22 | 23 | public int ComputeByteFast(byte a_data) 24 | { 25 | return a_data.GetHashCode(); 26 | } 27 | 28 | public int ComputeCharFast(char a_data) 29 | { 30 | return a_data.GetHashCode(); 31 | } 32 | 33 | public int ComputeShortFast(short a_data) 34 | { 35 | return a_data.GetHashCode(); 36 | } 37 | 38 | public int ComputeUShortFast(ushort a_data) 39 | { 40 | return a_data.GetHashCode(); 41 | } 42 | 43 | public int ComputeIntFast(int a_data) 44 | { 45 | return a_data.GetHashCode(); 46 | } 47 | 48 | public int ComputeUIntFast(uint a_data) 49 | { 50 | return a_data.GetHashCode(); 51 | } 52 | 53 | public int ComputeLongFast(long a_data) 54 | { 55 | return a_data.GetHashCode(); 56 | } 57 | 58 | public int ComputeULongFast(ulong a_data) 59 | { 60 | return a_data.GetHashCode(); 61 | } 62 | 63 | public int ComputeFloatFast(float a_data) 64 | { 65 | return a_data.GetHashCode(); 66 | } 67 | 68 | public int ComputeDoubleFast(double a_data) 69 | { 70 | return a_data.GetHashCode(); 71 | } 72 | 73 | 74 | public int ComputeStringFast(string a_data) 75 | { 76 | return a_data.GetHashCode(); 77 | } 78 | 79 | public int ComputeCharsFast(char[] a_data) 80 | { 81 | return a_data.GetHashCode(); 82 | } 83 | 84 | public int ComputeShortsFast(short[] a_data) 85 | { 86 | return a_data.GetHashCode(); 87 | } 88 | 89 | public int ComputeUShortsFast(ushort[] a_data) 90 | { 91 | return a_data.GetHashCode(); 92 | } 93 | 94 | public int ComputeIntsFast(int[] a_data) 95 | { 96 | return a_data.GetHashCode(); 97 | } 98 | 99 | public int ComputeUIntsFast(uint[] a_data) 100 | { 101 | return a_data.GetHashCode(); 102 | } 103 | 104 | public int ComputeLongsFast(long[] a_data) 105 | { 106 | return a_data.GetHashCode(); 107 | } 108 | 109 | public int ComputeULongsFast(ulong[] a_data) 110 | { 111 | return a_data.GetHashCode(); 112 | } 113 | 114 | public int ComputeDoublesFast(double[] a_data) 115 | { 116 | return a_data.GetHashCode(); 117 | } 118 | 119 | public int ComputeFloatsFast(float[] a_data) 120 | { 121 | return a_data.GetHashCode(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /HashLib/HashBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib 5 | { 6 | internal class HashBuffer 7 | { 8 | private byte[] m_data; 9 | private int m_pos; 10 | 11 | public HashBuffer(int a_length) 12 | { 13 | Debug.Assert(a_length > 0); 14 | 15 | m_data = new byte[a_length]; 16 | 17 | Initialize(); 18 | } 19 | 20 | public void Initialize() 21 | { 22 | m_pos = 0; 23 | } 24 | 25 | public byte[] GetBytes() 26 | { 27 | Debug.Assert(IsFull); 28 | 29 | m_pos = 0; 30 | return m_data; 31 | } 32 | 33 | public byte[] GetBytesZeroPadded() 34 | { 35 | Array.Clear(m_data, m_pos, m_data.Length - m_pos); 36 | m_pos = 0; 37 | return m_data; 38 | } 39 | 40 | public bool Feed(byte[] a_data, ref int a_start_index, ref int a_length, ref ulong a_processed_bytes) 41 | { 42 | Debug.Assert(a_start_index >= 0); 43 | Debug.Assert(a_length >= 0); 44 | Debug.Assert(a_start_index + a_length <= a_data.Length); 45 | Debug.Assert(!IsFull); 46 | 47 | if (a_data.Length == 0) 48 | return false; 49 | 50 | if (a_length == 0) 51 | return false; 52 | 53 | int length = m_data.Length - m_pos; 54 | if (length > a_length) 55 | length = a_length; 56 | 57 | Array.Copy(a_data, a_start_index, m_data, m_pos, length); 58 | 59 | m_pos += length; 60 | a_start_index += length; 61 | a_length -= length; 62 | a_processed_bytes += (ulong)length; 63 | 64 | return IsFull; 65 | } 66 | 67 | public bool Feed(byte[] a_data, int a_length) 68 | { 69 | Debug.Assert(a_length >= 0); 70 | Debug.Assert(a_length <= a_data.Length); 71 | Debug.Assert(!IsFull); 72 | 73 | if (a_data.Length == 0) 74 | return false; 75 | 76 | if (a_length == 0) 77 | return false; 78 | 79 | int length = m_data.Length - m_pos; 80 | if (length > a_length) 81 | length = a_length; 82 | 83 | Array.Copy(a_data, 0, m_data, m_pos, length); 84 | 85 | m_pos += length; 86 | 87 | return IsFull; 88 | } 89 | 90 | public bool IsEmpty 91 | { 92 | get 93 | { 94 | return m_pos == 0; 95 | } 96 | } 97 | 98 | public int Pos 99 | { 100 | get 101 | { 102 | return m_pos; 103 | } 104 | } 105 | 106 | public int Length 107 | { 108 | get 109 | { 110 | return m_data.Length; 111 | } 112 | } 113 | 114 | public bool IsFull 115 | { 116 | get 117 | { 118 | return (m_pos == m_data.Length); 119 | } 120 | } 121 | 122 | public override string ToString() 123 | { 124 | return String.Format("HashBuffer, Legth: {0}, Pos: {1}, IsEmpty: {2}", Length, Pos, IsEmpty); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /HashLibTest/HMACsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using System.Collections.Generic; 4 | using HashLib; 5 | using TomanuExtensions; 6 | using TomanuExtensions.Utils; 7 | 8 | namespace HashLibTest 9 | { 10 | [TestClass] 11 | public class HMACsTest 12 | { 13 | private MersenneTwister m_random = new MersenneTwister(4563487); 14 | 15 | [TestMethod] 16 | public void HashLib_HMAC_All() 17 | { 18 | Test(HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.BuildIn.CreateMD5CryptoServiceProvider()), 19 | HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.CreateMD5())); 20 | Test(HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.BuildIn.CreateRIPEMD160Managed()), 21 | HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.CreateRIPEMD160())); 22 | Test(HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.BuildIn.CreateSHA1CryptoServiceProvider()), 23 | HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.CreateSHA1())); 24 | Test(HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.BuildIn.CreateSHA256Managed()), 25 | HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.CreateSHA256())); 26 | Test(HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.BuildIn.CreateSHA384Managed()), 27 | HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.CreateSHA384())); 28 | Test(HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.BuildIn.CreateSHA512Managed()), 29 | HashFactory.HMAC.CreateHMAC(HashFactory.Crypto.CreateSHA512())); 30 | } 31 | 32 | private void Test(IHMAC a_base_hmac, IHMAC a_hmac) 33 | { 34 | Assert.AreEqual(a_base_hmac.HashSize, a_hmac.HashSize); 35 | Assert.AreEqual(a_base_hmac.BlockSize, a_hmac.BlockSize); 36 | 37 | List keys_length = new List() { 0, 1, 7, 51, 121, 512, 1023 }; 38 | keys_length.Add(a_hmac.BlockSize - 1); 39 | keys_length.Add(a_hmac.BlockSize); 40 | keys_length.Add(a_hmac.BlockSize + 1); 41 | 42 | List msgs_length = new List(); 43 | msgs_length.AddRange(keys_length); 44 | msgs_length.Add(a_hmac.BlockSize * 4 - 1); 45 | msgs_length.Add(a_hmac.BlockSize * 4); 46 | msgs_length.Add(a_hmac.BlockSize * 4 + 1); 47 | 48 | foreach (int key_length in keys_length) 49 | { 50 | byte[] key = m_random.NextBytes(key_length); 51 | 52 | a_base_hmac.Key = key; 53 | a_hmac.Key = key; 54 | 55 | foreach (int msg_length in msgs_length) 56 | { 57 | byte[] msg = m_random.NextBytes(msg_length); 58 | 59 | a_base_hmac.Initialize(); 60 | a_base_hmac.TransformBytes(msg); 61 | HashResult h1 = a_base_hmac.TransformFinal(); 62 | 63 | a_hmac.Initialize(); 64 | a_hmac.TransformBytes(msg); 65 | HashResult h2 = a_hmac.TransformFinal(); 66 | 67 | Assert.AreEqual(h1, h2, a_hmac.Name); 68 | 69 | h1 = a_base_hmac.ComputeString(BitConverter.ToString(msg)); 70 | h2 = a_hmac.ComputeString(BitConverter.ToString(msg)); 71 | 72 | Assert.AreEqual(h1, h2, a_hmac.Name); 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /HashLib/Crypto/RadioGatun32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class RadioGatun32 : BlockHash, ICryptoNotBuildIn 6 | { 7 | private const int MILL_SIZE = 19; 8 | private const int BELT_WIDTH = 3; 9 | private const int BELT_LENGTH = 13; 10 | private const int NUMBER_OF_BLANK_ITERATIONS = 16; 11 | 12 | private uint[] m_mill = new uint[MILL_SIZE]; 13 | private uint[][] m_belt; 14 | 15 | public RadioGatun32() 16 | : base(32, 4 * BELT_WIDTH) 17 | { 18 | m_belt = new uint[BELT_LENGTH][]; 19 | for (int i = 0; i < BELT_LENGTH; i++) 20 | m_belt[i] = new uint[BELT_WIDTH]; 21 | 22 | Initialize(); 23 | } 24 | 25 | public override void Initialize() 26 | { 27 | m_mill.Clear(); 28 | 29 | for (int i = 0; i < BELT_LENGTH; i++) 30 | m_belt[i].Clear(); 31 | 32 | base.Initialize(); 33 | } 34 | 35 | protected override void Finish() 36 | { 37 | int padding_size = BlockSize - (((int)m_processed_bytes) % BlockSize); 38 | 39 | byte[] pad = new byte[padding_size]; 40 | pad[0] = 0x01; 41 | TransformBytes(pad, 0, padding_size); 42 | 43 | for (int i = 0; i < NUMBER_OF_BLANK_ITERATIONS; i++) 44 | RoundFunction(); 45 | } 46 | 47 | protected override byte[] GetResult() 48 | { 49 | uint[] result = new uint[HashSize / 4]; 50 | for (int i = 0; i < HashSize / 8; i++) 51 | { 52 | RoundFunction(); 53 | Array.Copy(m_mill, 1, result, i * 2, 2); 54 | } 55 | return Converters.ConvertUIntsToBytes(result); 56 | } 57 | 58 | protected override void TransformBlock(byte[] a_data, int a_index) 59 | { 60 | uint[] data = Converters.ConvertBytesToUInts(a_data, a_index, BlockSize); 61 | 62 | for (int i = 0; i < BELT_WIDTH; i++) 63 | { 64 | m_mill[i + 16] ^= data[i]; 65 | m_belt[0][i] ^= data[i]; 66 | } 67 | 68 | RoundFunction(); 69 | } 70 | 71 | private void RoundFunction() 72 | { 73 | uint[] q = m_belt[BELT_LENGTH - 1]; 74 | for (int i = BELT_LENGTH - 1; i > 0; i--) 75 | m_belt[i] = m_belt[i - 1]; 76 | m_belt[0] = q; 77 | 78 | for (int i = 0; i < 12; i++) 79 | m_belt[i + 1][i % BELT_WIDTH] ^= m_mill[i + 1]; 80 | 81 | uint[] a = new uint[MILL_SIZE]; 82 | 83 | for (int i = 0; i < MILL_SIZE; i++) 84 | a[i] = m_mill[i] ^ (m_mill[(i + 1) % MILL_SIZE] | ~m_mill[(i + 2) % MILL_SIZE]); 85 | 86 | for (int i = 0; i < MILL_SIZE; i++) 87 | m_mill[i] = Bits.RotateRight(a[(7 * i) % MILL_SIZE], i * (i + 1) / 2); 88 | 89 | for (int i = 0; i < MILL_SIZE; i++) 90 | a[i] = m_mill[i] ^ m_mill[(i + 1) % MILL_SIZE] ^ m_mill[(i + 4) % MILL_SIZE]; 91 | 92 | a[0] ^= 1; 93 | for (int i = 0; i < MILL_SIZE; i++) 94 | m_mill[i] = a[i]; 95 | 96 | for (int i = 0; i < BELT_WIDTH; i++) 97 | m_mill[i + 13] ^= q[i]; 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /HashLib/Crypto/RadioGatun64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class RadioGatun64 : BlockHash, ICryptoNotBuildIn 6 | { 7 | private const int MILL_SIZE = 19; 8 | private const int BELT_WIDTH = 3; 9 | private const int BELT_LENGTH = 13; 10 | private const int NUMBER_OF_BLANK_ITERATIONS = 16; 11 | 12 | private ulong[] m_mill = new ulong[MILL_SIZE]; 13 | private ulong[][] m_belt; 14 | 15 | public RadioGatun64() 16 | : base(32, 8 * BELT_WIDTH) 17 | { 18 | m_belt = new ulong[BELT_LENGTH][]; 19 | for (int i = 0; i < BELT_LENGTH; i++) 20 | m_belt[i] = new ulong[BELT_WIDTH]; 21 | 22 | Initialize(); 23 | } 24 | 25 | public override void Initialize() 26 | { 27 | m_mill.Clear(); 28 | 29 | for (int i = 0; i < BELT_LENGTH; i++) 30 | m_belt[i].Clear(); 31 | 32 | base.Initialize(); 33 | } 34 | 35 | protected override void Finish() 36 | { 37 | int padding_size = BlockSize - (((int)m_processed_bytes) % BlockSize); 38 | 39 | byte[] pad = new byte[padding_size]; 40 | pad[0] = 0x01; 41 | TransformBytes(pad, 0, padding_size); 42 | 43 | for (int i = 0; i < NUMBER_OF_BLANK_ITERATIONS; i++) 44 | RoundFunction(); 45 | } 46 | 47 | protected override byte[] GetResult() 48 | { 49 | ulong[] result = new ulong[HashSize / 8]; 50 | for (int i = 0; i < HashSize / 16; i++) 51 | { 52 | RoundFunction(); 53 | Array.Copy(m_mill, 1, result, i * 2, 2); 54 | } 55 | 56 | return Converters.ConvertULongsToBytes(result); 57 | } 58 | 59 | protected override void TransformBlock(byte[] a_data, int a_index) 60 | { 61 | ulong[] data = Converters.ConvertBytesToULongs(a_data, a_index, BlockSize); 62 | 63 | for (int i = 0; i < BELT_WIDTH; i++) 64 | { 65 | m_mill[i + 16] ^= data[i]; 66 | m_belt[0][i] ^= data[i]; 67 | } 68 | 69 | RoundFunction(); 70 | } 71 | 72 | private void RoundFunction() 73 | { 74 | ulong[] q = m_belt[BELT_LENGTH - 1]; 75 | for (int i = BELT_LENGTH - 1; i > 0; i--) 76 | m_belt[i] = m_belt[i - 1]; 77 | m_belt[0] = q; 78 | 79 | for (int i = 0; i < 12; i++) 80 | m_belt[i + 1][i % BELT_WIDTH] ^= m_mill[i + 1]; 81 | 82 | ulong[] a = new ulong[MILL_SIZE]; 83 | 84 | for (int i = 0; i < MILL_SIZE; i++) 85 | a[i] = m_mill[i] ^ (m_mill[(i + 1) % MILL_SIZE] | ~m_mill[(i + 2) % MILL_SIZE]); 86 | 87 | for (int i = 0; i < MILL_SIZE; i++) 88 | m_mill[i] = Bits.RotateRight(a[(7 * i) % MILL_SIZE], i * (i + 1) / 2); 89 | 90 | for (int i = 0; i < MILL_SIZE; i++) 91 | a[i] = m_mill[i] ^ m_mill[(i + 1) % MILL_SIZE] ^ m_mill[(i + 4) % MILL_SIZE]; 92 | 93 | a[0] ^= 1; 94 | for (int i = 0; i < MILL_SIZE; i++) 95 | m_mill[i] = a[i]; 96 | 97 | for (int i = 0; i < BELT_WIDTH; i++) 98 | m_mill[i + 13] ^= q[i]; 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Jenkins3Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 00000000 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 6ECACBFB 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 73A267D7 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 08E978AF 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 1704142A 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: 0661DF9C 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: DE1734CF 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: B2991C9D 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: 80225BAB 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: 55D6ABD0 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: 3C7AC54E 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: 53D5BF82 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: EFC35F97 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: 376B8A59 56 | 57 | Repeat: 1 58 | Messsage: 4A8BAE394046AFBC47D690224CB9 59 | Hash: 64DFDF02 60 | 61 | Repeat: 1 62 | Messsage: 78D9CE79AFC1E0C41E2A48278E4B4B 63 | Hash: F4063FFD 64 | 65 | Repeat: 1 66 | Messsage: 816B650FB50D8E848DB94034628FC520 67 | Hash: 54B9346D 68 | 69 | Repeat: 1 70 | Messsage: 629768E3633858B4D23D04773DA28CBCFB 71 | Hash: B3CF81AA 72 | 73 | Repeat: 1 74 | Messsage: 55462FF88CDF40292838C888B71D16EA5D88 75 | Hash: EC7BCF2D 76 | 77 | Repeat: 1 78 | Messsage: C69924B3A64312DB5808B1C3AD05C05413E958 79 | Hash: BEDAB10B 80 | 81 | Repeat: 1 82 | Messsage: 5A6462CE04496BA8DCF67799EE4CAB353E337A47 83 | Hash: 095853E1 84 | 85 | Repeat: 1 86 | Messsage: 99F397D1268B57091AA4A299685C3826FC77196E21 87 | Hash: 7A04804E 88 | 89 | Repeat: 1 90 | Messsage: 7A78E5E46E36837950F3D53061C0789B90F5374CEC88 91 | Hash: A30093B9 92 | 93 | Repeat: 1 94 | Messsage: A0DAC9754045558650DA891AFB3EC312CCF85D3300D426 95 | Hash: 7DEF29B3 96 | 97 | Repeat: 1 98 | Messsage: 0B69E8AA8DEED1859D2B7FF78D07DCEDE826A872E66E0AE1 99 | Hash: 8F3195F2 100 | 101 | Repeat: 1 102 | Messsage: 3ECD10659E510DD8F28C8DDABAA5790C640A77C8243F958C9C 103 | Hash: 866C0FE4 104 | 105 | Repeat: 1 106 | Messsage: 2618CDDCA206E42E247BE6474224E5A634377B9AD6C4BAC621D6 107 | Hash: 68959A91 108 | 109 | Repeat: 1 110 | Messsage: 55314A0198F4C4623A364C3B81F45D079EDA66F50C44BB33E8279F 111 | Hash: CB29B29A 112 | 113 | Repeat: 1 114 | Messsage: FCED8CDC4690D5F10121060934800A4B881DE2CA9B1F206C76658D0C 115 | Hash: B0F975F3 116 | 117 | Repeat: 1 118 | Messsage: C89186812C99D936B8751D6901CA1892C03D8FB0B72B60A7A87BA20A93 119 | Hash: 07FD2158 120 | 121 | Repeat: 1 122 | Messsage: 1915A470840704DA66E2384473A79AB5D98924B7EDB4FD6329975F0A49D3 123 | Hash: C672603A 124 | 125 | Repeat: 1 126 | Messsage: 3C256BF4BC51F5BD41B1480C641BF721630AC4165B490CA14E324E49136D9F 127 | Hash: 4C04EEB0 128 | 129 | Repeat: 1 130 | Messsage: 2E86993AA9577E0176DEE507BF649F9358EEBE67CEAFA2D4C10ACE8D4BE895AD 131 | Hash: F8A2637F 132 | 133 | Repeat: 1 134 | Messsage: 015ECA91AB59E81C9486D97C079CBE1867834BD5B03C3AE3C65A9FBB842643FD84 135 | Hash: 364C456E 136 | 137 | Repeat: 1 138 | Messsage: EBECF3C5A7476DBB35D348DBEC5A0EB7B3A5499BE07B8FCD489A7B56E07F0A91D196 139 | Hash: 3D2B32D7 140 | 141 | Repeat: 1 142 | Messsage: 4971FB343551CA6D29F63D2260F4158E2467304ECE74DF2CA1410B338726BF3ED9BB4B 143 | Hash: 9040BD1A 144 | 145 | Repeat: 1 146 | Messsage: F5E91932E0D1AE09905D4680BD42ECC7FBEC8A21C96EB71DFA0C6062BE8E9C6B187E3B81 147 | Hash: 32E67B62 148 | 149 | Repeat: 1 150 | Messsage: 9C4F0FBE8D3A23204B11E776E474D359626D5BCEEA3F4C9A3F9F939CEA88F7CBF71E99A8D5 151 | Hash: 916CA386 152 | 153 | -------------------------------------------------------------------------------- /HashLib/Crypto/SHA256Base.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal abstract class SHA256Base : BlockHash, ICryptoNotBuildIn 6 | { 7 | protected readonly uint[] m_state = new uint[8]; 8 | 9 | #region Consts 10 | 11 | private static readonly uint[] s_K = 12 | { 13 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 14 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 15 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 16 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 17 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 18 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 19 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 20 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 21 | }; 22 | 23 | #endregion 24 | 25 | public SHA256Base(int a_hash_size) 26 | : base(a_hash_size, 64) 27 | { 28 | Initialize(); 29 | } 30 | 31 | protected override void Finish() 32 | { 33 | ulong bits = m_processed_bytes * 8; 34 | int padindex = (m_buffer.Pos < 56) ? (56 - m_buffer.Pos) : (120 - m_buffer.Pos); 35 | 36 | byte[] pad = new byte[padindex + 8]; 37 | pad[0] = 0x80; 38 | 39 | Converters.ConvertULongToBytesSwapOrder(bits, pad, padindex); 40 | padindex += 8; 41 | 42 | TransformBytes(pad, 0, padindex); 43 | } 44 | 45 | protected override void TransformBlock(byte[] a_data, int a_index) 46 | { 47 | uint[] data = new uint[64]; 48 | Converters.ConvertBytesToUIntsSwapOrder(a_data, a_index, BlockSize, data, 0); 49 | 50 | uint A = m_state[0]; 51 | uint B = m_state[1]; 52 | uint C = m_state[2]; 53 | uint D = m_state[3]; 54 | uint E = m_state[4]; 55 | uint F = m_state[5]; 56 | uint G = m_state[6]; 57 | uint H = m_state[7]; 58 | 59 | for (int r = 16; r < 64; r++) 60 | { 61 | uint T = data[r - 2]; 62 | uint T2 = data[r - 15]; 63 | data[r] = (((T >> 17) | (T << 15)) ^ ((T >> 19) | (T << 13)) ^ (T >> 10)) + data[r - 7] + 64 | (((T2 >> 7) | (T2 << 25)) ^ ((T2 >> 18) | (T2 << 14)) ^ (T2 >> 3)) + data[r - 16]; 65 | } 66 | 67 | for (int r = 0; r < 64; r++) 68 | { 69 | uint T = s_K[r] + data[r] + H + (((E >> 6) | (E << 26)) ^ ((E >> 11) | (E << 21)) ^ ((E >> 25) | 70 | (E << 7))) + ((E & F) ^ (~E & G)); 71 | uint T2 = (((A >> 2) | (A << 30)) ^ ((A >> 13) | (A << 19)) ^ 72 | ((A >> 22) | (A << 10))) + ((A & B) ^ (A & C) ^ (B & C)); 73 | H = G; 74 | G = F; 75 | F = E; 76 | E = D + T; 77 | D = C; 78 | C = B; 79 | B = A; 80 | A = T + T2; 81 | } 82 | 83 | m_state[0] += A; 84 | m_state[1] += B; 85 | m_state[2] += C; 86 | m_state[3] += D; 87 | m_state[4] += E; 88 | m_state[5] += F; 89 | m_state[6] += G; 90 | m_state[7] += H; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /TomanuExtensions/Utils/XmlBase.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Xml; 3 | 4 | namespace TomanuExtensions.Utils 5 | { 6 | /// 7 | /// Base class suitable for all classes that can be saved and loaded from xml. 8 | /// 9 | public abstract class XmlBase 10 | { 11 | /// 12 | /// Constructor. 13 | /// 14 | public XmlBase() 15 | { 16 | } 17 | 18 | /// 19 | /// Constructor. 20 | /// 21 | /// 22 | public XmlBase(XmlBase a_source) 23 | { 24 | MemoryStream ms = new MemoryStream(); 25 | a_source.Save(ms); 26 | ms.Position = 0; 27 | Load(ms); 28 | } 29 | 30 | /// 31 | /// Constructor. 32 | /// 33 | /// 34 | public XmlBase(XmlReader a_reader) 35 | { 36 | ReadXml(a_reader); 37 | } 38 | 39 | /// 40 | /// Load object from xml file. 41 | /// 42 | /// 43 | protected virtual void Load(string a_file_name) 44 | { 45 | using (FileStream fs = new FileStream(a_file_name, FileMode.Open, FileAccess.Read)) 46 | Load(fs); 47 | } 48 | 49 | /// 50 | /// Load object from xml stream. 51 | /// 52 | /// 53 | protected virtual void Load(Stream a_stream) 54 | { 55 | XmlReaderExtensions.ReadXml(a_stream, (reader) => ReadXml(reader)); 56 | } 57 | 58 | /// 59 | /// Load object from xml. 60 | /// 61 | /// 62 | protected abstract void ReadXml(XmlReader a_reader); 63 | 64 | /// 65 | /// Save object to xml file. 66 | /// 67 | /// 68 | public virtual void Save(string a_file_name) 69 | { 70 | using (FileStream fs = new FileStream(a_file_name, FileMode.Create)) 71 | Save(fs); 72 | } 73 | 74 | /// 75 | /// Save object to xml stream. 76 | /// 77 | /// 78 | public virtual void Save(Stream a_stream) 79 | { 80 | XmlWriterExtensions.WriteXml(a_stream, (writer) => WriteXml(writer)); 81 | } 82 | 83 | /// 84 | /// Save object to xml. 85 | /// 86 | /// 87 | internal protected abstract void WriteXml(XmlWriter a_writer); 88 | 89 | /// 90 | /// Compare objects through xml. 91 | /// 92 | /// 93 | /// 94 | public override bool Equals(object a_obj) 95 | { 96 | if (a_obj == null) 97 | return false; 98 | 99 | XmlBase xml_base = a_obj as XmlBase; 100 | if (xml_base == null) 101 | return false; 102 | 103 | MemoryStream ms1 = new MemoryStream(); 104 | xml_base.Save(ms1); 105 | 106 | MemoryStream ms2 = new MemoryStream(); 107 | Save(ms2); 108 | 109 | return ms1.ToArray().AreSame(ms2.ToArray()); 110 | } 111 | 112 | /// 113 | /// Calculate hash through xml. 114 | /// 115 | /// 116 | public override int GetHashCode() 117 | { 118 | MemoryStream ms = new MemoryStream(); 119 | Save(ms); 120 | return ArrayExtensions.GetHashCode(ms.ToArray()); 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /HashLibTest/TestData/Hamsi384Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 3943CD34E3B96B197A8BF4BAC7AA982D18530DD12F41136B26D7E88759255F21153F4A4BD02E523612B8427F9DD96C8D 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 3AB3352155BCD961285D82749E1817666044799C7FDBB0DB269258323D0C3395E9BC2A71DE0743363C331E89FBF0F47B 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 0695DA32CADACCE2E03AD744AA5EE7E029D639D17EBAE7AFAB0636A56C54917C139DFB48F4BE3B314F770D6E924A15FB 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 5DC7B0A138A194E1D45812E9772AD509A84A12BC0248E7765C5493D24B09112BA1F1C8E539D9E42E0BD77C536EACF864 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: F1599DC5DAB4941690DFA8665B226607F9A7F581AB954A576EA5E1690DFE683CBEA935494F38BCD9FCB36B9B780F4E3E 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: D83585DE8BA80386BE56B9ECFEA87CE32F6F3623ADEC0F06B366065E515AF1E483567945507E15055C0E4D8E356AAB7B 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: F3AE0F37CD3220CE426140290294B8F71904701D7609E3E22A865E22938FAE87385CB7AEC7500C7160372B9305DEA862 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: 7EAD79B0522B838CDFB64D2B0189D6952D2187BFA60D0739C1950D0E84ED22774F0FBA0459900527FD2328DF7BD1B927 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: 9EFF44FF01FA87F17847A3029CCCED13DB0EE7D8D2CEE0522513364925C174BD01CC00495021E53E29F63C654A22D5E2 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: 7D46564E4579F94D9C980F248482743C2391201339E15C4BFF8CFDE61610E6A31654BA7D4893442C28D77995582EC0DE 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: BC69B0F07DD17C9826AA518377EBA98FC1B4D226ECBC93F6402B65CA4B5264923E44FC5D28EC067B9AE2B3BDD3D6E740 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: D361CF81902A13B96292115EFE9779D60A090AF311B386691F3798A607E6A2F96D329E9FF2C5488E010015C2FAE80FE4 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: 2080359CB214D5FE9E40B459D671FA700ED98FCBA578537961AC36F73580A05DC2C116E987527756184BC4508006106A 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: 7CDC71CB9226654FAEEBE4FE5A892F5702AE0ACA0FDF5329597C148C87CF4D1089DB51F3EA63DFEFB40165B5605502FB 56 | 57 | Repeat: 1 58 | Messsage: 4A8BAE394046AFBC47D690224CB9 59 | Hash: 91556BBBCEF804A3D94C4580FAF3CFFE6008BE2E02F3C4498939964CC2FDB3BCCA63158617CC5ACFEF070D7148049A19 60 | 61 | Repeat: 1 62 | Messsage: 78D9CE79AFC1E0C41E2A48278E4B4B 63 | Hash: D72DCA0D2FE26D941C0435C54532E3DB66152A36DF4C6A50F9C876F6E4D21B3F3E18D15AB10C51606E51588C6C7A6D58 64 | 65 | Repeat: 1 66 | Messsage: 816B650FB50D8E848DB94034628FC520 67 | Hash: B1F02481000387C33AF09C64590CFCDCD8200148DE4E55DBF925E82B6858904050C1A83D6ABD4C3E5047E0C136CF571F 68 | 69 | Repeat: 1 70 | Messsage: 629768E3633858B4D23D04773DA28CBCFB 71 | Hash: 09897693AF2E4655A2AF127BFA66B60088D7B17446C3C0EDF058F2159D0F57491863B25B2739388A9EE2BCFFDF41B61E 72 | 73 | Repeat: 1 74 | Messsage: 55462FF88CDF40292838C888B71D16EA5D88 75 | Hash: 36326A564DB04321786D4AA630AF5D838AD0FBAC7AF6D281C45E2CB9B6709006D09C782AB2BE192AB3FC1883C394E200 76 | 77 | Repeat: 1 78 | Messsage: C69924B3A64312DB5808B1C3AD05C05413E958 79 | Hash: 6D7242031DE945782C1E1BDE986A367E84EE9B1A5F0E01CDDD12844E9E5B5BB2787E20E98535D24E9D97060F2404176F 80 | 81 | Repeat: 1 82 | Messsage: 5A6462CE04496BA8DCF67799EE4CAB353E337A47 83 | Hash: D95210C51599F41B4D46CD0FE10DD2272FEE867C3B322437D4AA744C7BAE5AADECF8E1F969A189D3C448E880C8335930 84 | 85 | Repeat: 1 86 | Messsage: 99F397D1268B57091AA4A299685C3826FC77196E21 87 | Hash: AA00A2840392C02C7DB38D3EB481E4848BCA1FDADD469EE7D62FE80A136B88300F47C10A5A5C6E9676F594D4F4765826 88 | 89 | Repeat: 1 90 | Messsage: 7A78E5E46E36837950F3D53061C0789B90F5374CEC88 91 | Hash: 8570DCB5F9EE9239D4746E586E5CDAB96D6E13EAC2BBAE96E82F0ECECF965F0A31E0319FE6DBBDCBF42CAB8FD5A41310 92 | 93 | Repeat: 1 94 | Messsage: A0DAC9754045558650DA891AFB3EC312CCF85D3300D426 95 | Hash: 7EB80C2CB1C508A580E25D43E92881E4D713A1E5DF2D5C5CBF2BEC9608841E99253D89A4EC8BC2FC4358BADBA756077A 96 | 97 | Repeat: 1 98 | Messsage: 0B69E8AA8DEED1859D2B7FF78D07DCEDE826A872E66E0AE1 99 | Hash: CEE2037B1C7D4832C4E45FD7E01F1B4F0FD007F002BE9C4A3AAB4844B84021C1A5E87959B4EBDFAA9822F88B6EFC5B8A 100 | 101 | Repeat: 1 102 | Messsage: 3ECD10659E510DD8F28C8DDABAA5790C640A77C8243F958C9C 103 | Hash: 4886347F9383A1810DBED9342928907895EF93EE58BDD66348A504F335F22804802C48920A43C36EECEECB968B4EB101 104 | 105 | Repeat: 16777216 106 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 107 | Hash: 46F00E93ADC4733F1A9C438A03273E880B91F27157E7FA167626F4C9D8EE202044D0895F6E0AE5F76FD6B417541D6468 108 | 109 | Repeat: 67108865 110 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 111 | Hash: A5F4E65A057190692B3ADFDA2BABA87DEBB9F75777969D07C57C4E7BE05D55B54A606DA78C4F6FE0466439177900C10E 112 | 113 | -------------------------------------------------------------------------------- /TomanuExtensions/Extensions/XmlWriterExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Drawing; 4 | using System.Globalization; 5 | using System.IO; 6 | using System.Xml; 7 | using TomanuExtensions.Utils; 8 | 9 | namespace TomanuExtensions 10 | { 11 | [DebuggerStepThrough] 12 | public static class XmlWriterExtensions 13 | { 14 | public static void WriteHexElement(this XmlWriter a_writer, string a_name, byte a_byte) 15 | { 16 | a_writer.WriteElementString(a_name, Hex.ByteToHex(a_byte)); 17 | } 18 | 19 | public static void WriteHexElement(this XmlWriter a_writer, string a_name, ushort a_byte) 20 | { 21 | a_writer.WriteElementString(a_name, Hex.UShortToHex(a_byte)); 22 | } 23 | 24 | public static void WriteHexElement(this XmlWriter a_writer, string a_name, uint a_byte) 25 | { 26 | a_writer.WriteElementString(a_name, Hex.UIntToHex(a_byte)); 27 | } 28 | 29 | public static void WriteElement(this XmlWriter a_writer, string a_name, T a_obj) 30 | { 31 | a_writer.WriteElementString(a_name, a_obj.ToString()); 32 | } 33 | 34 | public static void WriteElement(this XmlWriter a_writer, string a_name, double a_value) 35 | { 36 | a_writer.WriteElementString(a_name, a_value.ToString(CultureInfo.InvariantCulture)); 37 | } 38 | 39 | public static void WriteElementSize(this XmlWriter a_writer, string a_name, Size a_size) 40 | { 41 | a_writer.WriteStartElement(a_name); 42 | a_writer.WriteAttribute("Width", a_size.Width); 43 | a_writer.WriteAttribute("Height", a_size.Height); 44 | a_writer.WriteEndElement(); 45 | } 46 | 47 | public static void WriteElementRectangle(this XmlWriter a_writer, string a_name, 48 | Rectangle a_rect) 49 | { 50 | a_writer.WriteStartElement(a_name); 51 | a_writer.WriteAttribute("Left", a_rect.Left); 52 | a_writer.WriteAttribute("Top", a_rect.Top); 53 | a_writer.WriteAttribute("Width", a_rect.Width); 54 | a_writer.WriteAttribute("Height", a_rect.Height); 55 | a_writer.WriteEndElement(); 56 | } 57 | 58 | public static void WriteElementEnum(this XmlWriter a_writer, string a_name, Enum a_enum) 59 | { 60 | a_writer.WriteElementString(a_name, a_enum.ToString().Replace(", ", " ")); 61 | } 62 | 63 | public static void WriteHexAttribute(this XmlWriter a_writer, string a_name, byte a_byte) 64 | { 65 | a_writer.WriteAttributeString(a_name, Hex.ByteToHex(a_byte)); 66 | } 67 | 68 | public static void WriteHexAttribute(this XmlWriter a_writer, string a_name, ushort a_byte) 69 | { 70 | a_writer.WriteAttributeString(a_name, Hex.UShortToHex(a_byte)); 71 | } 72 | 73 | public static void WriteHexAttribute(this XmlWriter a_writer, string a_name, uint a_byte) 74 | { 75 | a_writer.WriteAttributeString(a_name, Hex.UIntToHex(a_byte)); 76 | } 77 | 78 | public static void WriteAttribute(this XmlWriter a_writer, string a_name, T a_obj) 79 | { 80 | a_writer.WriteAttributeString(a_name, a_obj.ToString()); 81 | } 82 | 83 | public static void WriteAttributeEnum(this XmlWriter a_writer, string a_name, Enum a_enum) 84 | { 85 | a_writer.WriteAttributeString(a_name, a_enum.ToString().Replace(", ", " ")); 86 | } 87 | 88 | /// 89 | /// Helper for xml writing. 90 | /// 91 | /// 92 | /// 93 | public static void WriteXml(Stream a_stream, Action a_write_func) 94 | { 95 | XmlWriterSettings settings = new XmlWriterSettings(); 96 | settings.Indent = true; 97 | 98 | using (XmlWriter writer = new NoNamespacesXmlWriter(XmlWriter.Create(a_stream, settings))) 99 | { 100 | writer.WriteStartDocument(); 101 | a_write_func(writer); 102 | writer.WriteEndDocument(); 103 | } 104 | } 105 | 106 | /// 107 | /// Helper for xml writing. 108 | /// 109 | /// 110 | /// 111 | public static void WriteXml(string a_file_name, Action a_write_func) 112 | { 113 | using (var fs = new FileStream(a_file_name, FileMode.Create)) 114 | WriteXml(fs, a_write_func); 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /HashLib/Hash64/Murmur2_64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace HashLib.Hash64 5 | { 6 | internal class Murmur2_64 : MultipleTransformNonBlock, IHash64, IHashWithKey 7 | { 8 | protected const uint KEY = 0xC58F1A7B; 9 | protected const ulong M = 0xC6A4A7935BD1E995; 10 | protected const int R = 47; 11 | 12 | private uint m_key = KEY; 13 | private uint m_working_key; 14 | 15 | public Murmur2_64() 16 | : base(8, 8) 17 | { 18 | } 19 | 20 | public override void Initialize() 21 | { 22 | m_working_key = m_key; 23 | 24 | base.Initialize(); 25 | } 26 | 27 | protected override HashResult ComputeAggregatedBytes(byte[] a_data) 28 | { 29 | int length = a_data.Length; 30 | 31 | if (length == 0) 32 | return new HashResult((ulong)0); 33 | 34 | ulong h = m_working_key ^ (ulong)length; 35 | int current_index = 0; 36 | 37 | 38 | while (length >= 8) 39 | { 40 | ulong k = (ulong)a_data[current_index++] | (ulong)a_data[current_index++] << 8 | 41 | (ulong)a_data[current_index++] << 16 | (ulong)a_data[current_index++] << 24 | 42 | (ulong)a_data[current_index++] << 32 | (ulong)a_data[current_index++] << 40 | 43 | (ulong)a_data[current_index++] << 48 | (ulong)a_data[current_index++] << 56; 44 | 45 | k *= M; 46 | k ^= k >> R; 47 | k *= M; 48 | 49 | h ^= k; 50 | h *= M; 51 | 52 | length -= 8; 53 | } 54 | 55 | switch (length) 56 | { 57 | case 7: 58 | h ^= (ulong)a_data[current_index++] << 48 | (ulong)a_data[current_index++] << 40 | 59 | (ulong)a_data[current_index++] << 32 | (ulong)a_data[current_index++] << 24 | 60 | (ulong)a_data[current_index++] << 16 | (ulong)a_data[current_index++] << 8 | 61 | (ulong)a_data[current_index++]; 62 | h *= M; 63 | break; 64 | case 6: 65 | h ^= (ulong)a_data[current_index++] << 40 | (ulong)a_data[current_index++] << 32 | 66 | (ulong)a_data[current_index++] << 24 | (ulong)a_data[current_index++] << 16 | 67 | (ulong)a_data[current_index++] << 8 | (ulong)a_data[current_index++]; 68 | h *= M; 69 | break; 70 | case 5: 71 | h ^= (ulong)a_data[current_index++] << 32 | (ulong)a_data[current_index++] << 24 | 72 | (ulong)a_data[current_index++] << 16 | (ulong)a_data[current_index++] << 8 | 73 | (ulong)a_data[current_index++]; 74 | h *= M; 75 | break; 76 | case 4: 77 | h ^= (ulong)a_data[current_index++] << 24 | (ulong)a_data[current_index++] << 16 | 78 | (ulong)a_data[current_index++] << 8 | (ulong)a_data[current_index++]; 79 | h *= M; 80 | break; 81 | case 3: 82 | h ^= (ulong)a_data[current_index++] << 16 | (ulong)a_data[current_index++] << 8 | 83 | (ulong)a_data[current_index++]; 84 | h *= M; 85 | break; 86 | case 2: 87 | h ^= (ulong)a_data[current_index++] << 8 | (ulong)a_data[current_index++]; 88 | h *= M; 89 | break; 90 | case 1: 91 | h ^= (ulong)a_data[current_index++]; 92 | h *= M; 93 | break; 94 | }; 95 | 96 | h ^= h >> R; 97 | h *= M; 98 | h ^= h >> R; 99 | 100 | return new HashResult(h); 101 | } 102 | 103 | public byte[] Key 104 | { 105 | get 106 | { 107 | return Converters.ConvertUIntToBytes(m_key); 108 | } 109 | set 110 | { 111 | if (value == null) 112 | { 113 | m_key = KEY; 114 | } 115 | else 116 | { 117 | Debug.Assert(value.Length == KeyLength); 118 | 119 | m_key = Converters.ConvertBytesToUInt(value); 120 | } 121 | } 122 | } 123 | 124 | public int? KeyLength 125 | { 126 | get 127 | { 128 | return 4; 129 | } 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /HashLib/Crypto/MD2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class MD2 : BlockHash, ICryptoNotBuildIn 6 | { 7 | private readonly byte[] m_state = new byte[16]; 8 | private readonly byte[] m_checksum = new byte[16]; 9 | 10 | #region Consts 11 | 12 | private static readonly byte[] s_pi = new byte[] 13 | { 14 | 41, 46, 67, 201, 15 | 162, 216, 124, 1, 16 | 61, 54, 84, 161, 17 | 236, 240, 6, 19, 18 | 19 | 98, 167, 5, 243, 20 | 192, 199, 115, 140, 21 | 152, 147, 43, 217, 22 | 188, 76, 130, 202, 23 | 24 | 30, 155, 87, 60, 25 | 253, 212, 224, 22, 26 | 103, 66, 111, 24, 27 | 138, 23, 229, 18, 28 | 29 | 190, 78, 196, 214, 30 | 218, 158, 222, 73, 31 | 160, 251, 245, 142, 32 | 187, 47, 238, 122, 33 | 34 | 169, 104, 121, 145, 35 | 21, 178, 7, 63, 36 | 148, 194, 16, 137, 37 | 11, 34, 95, 33, 38 | 39 | 128, 127, 93, 154, 40 | 90, 144, 50, 39, 41 | 53, 62, 204, 231, 42 | 191, 247, 151, 3, 43 | 44 | 255, 25, 48, 179, 45 | 72, 165, 181, 209, 46 | 215, 94, 146, 42, 47 | 172, 86, 170, 198, 48 | 49 | 79, 184, 56, 210, 50 | 150, 164, 125, 182, 51 | 118, 252, 107, 226, 52 | 156, 116, 4, 241, 53 | 54 | 69, 157, 112, 89, 55 | 100, 113, 135, 32, 56 | 134, 91, 207, 101, 57 | 230, 45, 168, 2, 58 | 59 | 27, 96, 37, 173, 60 | 174, 176, 185, 246, 61 | 28, 70, 97, 105, 62 | 52, 64, 126, 15, 63 | 64 | 85, 71, 163, 35, 65 | 221, 81, 175, 58, 66 | 195, 92, 249, 206, 67 | 186, 197, 234, 38, 68 | 69 | 44, 83, 13, 110, 70 | 133, 40, 132, 9, 71 | 211, 223, 205, 244, 72 | 65, 129, 77, 82, 73 | 74 | 106, 220, 55, 200, 75 | 108, 193, 171, 250, 76 | 36, 225, 123, 8, 77 | 12, 189, 177, 74, 78 | 79 | 120, 136, 149, 139, 80 | 227, 99, 232, 109, 81 | 233, 203, 213, 254, 82 | 59, 0, 29, 57, 83 | 84 | 242, 239, 183, 14, 85 | 102, 88, 208, 228, 86 | 166, 119, 114, 248, 87 | 235, 117, 75, 10, 88 | 89 | 49, 68, 80, 180, 90 | 143, 237, 31, 26, 91 | 219, 153, 141, 51, 92 | 159, 17, 131, 20 93 | }; 94 | 95 | #endregion 96 | 97 | public MD2() 98 | : base(16, 16) 99 | { 100 | Initialize(); 101 | } 102 | 103 | public override void Initialize() 104 | { 105 | m_state.Clear(); 106 | m_checksum.Clear(); 107 | 108 | base.Initialize(); 109 | } 110 | 111 | protected override void Finish() 112 | { 113 | int padLen = 16 - m_buffer.Pos; 114 | 115 | byte[] pad = new byte[padLen]; 116 | 117 | for (int i = 0; i < padLen; i++) 118 | pad[i] = (byte)padLen; 119 | 120 | TransformBytes(pad, 0, padLen); 121 | TransformBytes(m_checksum, 0, 16); 122 | } 123 | 124 | protected override byte[] GetResult() 125 | { 126 | return (byte[])m_state.Clone(); 127 | } 128 | 129 | protected override void TransformBlock(byte[] a_data, int a_index) 130 | { 131 | byte[] temp = new byte[48]; 132 | 133 | Array.Copy(m_state, temp, 16); 134 | Array.Copy(a_data, a_index, temp, 16, 16); 135 | 136 | for (int i = 0; i < 16; i++) 137 | temp[i + 32] = (byte)(m_state[i] ^ a_data[i + a_index]); 138 | 139 | uint t = 0; 140 | 141 | for (int i = 0; i < 18; i++) 142 | { 143 | for (int j = 0; j < 48; j++) 144 | t = temp[j] ^= s_pi[t]; 145 | 146 | t = (byte)(t + i); 147 | } 148 | 149 | Array.Copy(temp, m_state, 16); 150 | 151 | t = m_checksum[15]; 152 | for (int i = 0; i < BlockSize; i++) 153 | { 154 | m_checksum[i] ^= s_pi[a_data[i + a_index] ^ t]; 155 | t = m_checksum[i]; 156 | } 157 | } 158 | } 159 | } -------------------------------------------------------------------------------- /HashLib/Crypto/HAS160.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HashLib.Crypto 4 | { 5 | internal class HAS160 : BlockHash, ICryptoNotBuildIn 6 | { 7 | #region Consts 8 | private static readonly int[] s_rot = new int[] 9 | { 10 | 5, 11, 7, 15, 6, 13, 8, 14, 7, 12, 9, 11, 8, 15, 6, 12, 9, 14, 5, 13 11 | }; 12 | 13 | private static readonly int[] s_tor = new int[] 14 | { 15 | 27, 21, 25, 17, 26, 19, 24, 18, 25, 20, 23, 21, 24, 17, 26, 20, 23, 18, 27, 19 16 | }; 17 | 18 | private static readonly int[] s_index = new int[] 19 | { 20 | 18, 0, 1, 2, 3, 19, 4, 5, 6, 7, 16, 8, 9, 10, 11, 17, 12, 13, 14, 15, 21 | 18, 3, 6, 9, 12, 19, 15, 2, 5, 8, 16, 11, 14, 1, 4, 17, 7, 10, 13, 0, 22 | 18, 12, 5, 14, 7, 19, 0, 9, 2, 11, 16, 4, 13, 6, 15, 17, 8, 1, 10, 3, 23 | 18, 7, 2, 13, 8, 19, 3, 14, 9, 4, 16, 15, 10, 5, 0, 17, 11, 6, 1, 12 24 | }; 25 | #endregion 26 | 27 | private readonly uint[] m_hash = new uint[5]; 28 | 29 | public HAS160() 30 | : base(20, 64) 31 | { 32 | Initialize(); 33 | } 34 | 35 | protected override void Finish() 36 | { 37 | ulong bits = m_processed_bytes * 8; 38 | int pad_index = (m_buffer.Pos < 56) ? (56 - m_buffer.Pos) : (120 - m_buffer.Pos); 39 | 40 | byte[] pad = new byte[pad_index + 8]; 41 | pad[0] = 0x80; 42 | 43 | Converters.ConvertULongToBytes(bits, pad, pad_index); 44 | pad_index += 8; 45 | 46 | TransformBytes(pad, 0, pad_index); 47 | } 48 | 49 | protected override byte[] GetResult() 50 | { 51 | return Converters.ConvertUIntsToBytes(m_hash); 52 | } 53 | 54 | protected override void TransformBlock(byte[] a_data, int a_index) 55 | { 56 | uint A = m_hash[0]; 57 | uint B = m_hash[1]; 58 | uint C = m_hash[2]; 59 | uint D = m_hash[3]; 60 | uint E = m_hash[4]; 61 | 62 | uint[] data = new uint[20]; 63 | Converters.ConvertBytesToUInts(a_data, a_index, BlockSize, data); 64 | 65 | data[16] = data[0] ^ data[1] ^ data[2] ^ data[3]; 66 | data[17] = data[4] ^ data[5] ^ data[6] ^ data[7]; 67 | data[18] = data[8] ^ data[9] ^ data[10] ^ data[11]; 68 | data[19] = data[12] ^ data[13] ^ data[14] ^ data[15]; 69 | 70 | for (int r = 0; r < 20; r++) 71 | { 72 | uint T = data[s_index[r]] + (A << s_rot[r] | A >> s_tor[r]) + ((B & C) | (~B & D)) + E; 73 | E = D; 74 | D = C; 75 | C = B << 10 | B >> 22; 76 | B = A; 77 | A = T; 78 | } 79 | 80 | data[16] = data[3] ^ data[6] ^ data[9] ^ data[12]; 81 | data[17] = data[2] ^ data[5] ^ data[8] ^ data[15]; 82 | data[18] = data[1] ^ data[4] ^ data[11] ^ data[14]; 83 | data[19] = data[0] ^ data[7] ^ data[10] ^ data[13]; 84 | 85 | for (int r = 20; r < 40; r++) 86 | { 87 | uint T = data[s_index[r]] + 0x5A827999 + (A << s_rot[r - 20] | A >> s_tor[r - 20]) + (B ^ C ^ D) + E; 88 | E = D; 89 | D = C; 90 | C = B << 17 | B >> 15; 91 | B = A; 92 | A = T; 93 | } 94 | 95 | data[16] = data[5] ^ data[7] ^ data[12] ^ data[14]; 96 | data[17] = data[0] ^ data[2] ^ data[9] ^ data[11]; 97 | data[18] = data[4] ^ data[6] ^ data[13] ^ data[15]; 98 | data[19] = data[1] ^ data[3] ^ data[8] ^ data[10]; 99 | 100 | for (int r = 40; r < 60; r++) 101 | { 102 | uint T = data[s_index[r]] + 0x6ED9EBA1 + (A << s_rot[r - 40] | A >> s_tor[r - 40]) + (C ^ (B | ~D)) + E; 103 | E = D; 104 | D = C; 105 | C = B << 25 | B >> 7; 106 | B = A; 107 | A = T; 108 | } 109 | 110 | data[16] = data[2] ^ data[7] ^ data[8] ^ data[13]; 111 | data[17] = data[3] ^ data[4] ^ data[9] ^ data[14]; 112 | data[18] = data[0] ^ data[5] ^ data[10] ^ data[15]; 113 | data[19] = data[1] ^ data[6] ^ data[11] ^ data[12]; 114 | 115 | for (int r = 60; r < 80; r++) 116 | { 117 | uint T = data[s_index[r]] + 0x8F1BBCDC + (A << s_rot[r - 60] | A >> s_tor[r - 60]) + (B ^ C ^ D) + E; 118 | E = D; 119 | D = C; 120 | C = B << 30 | B >> 2; 121 | B = A; 122 | A = T; 123 | } 124 | 125 | m_hash[0] += A; 126 | m_hash[1] += B; 127 | m_hash[2] += C; 128 | m_hash[3] += D; 129 | m_hash[4] += E; 130 | } 131 | 132 | public override void Initialize() 133 | { 134 | m_hash[0] = 0x67452301; 135 | m_hash[1] = 0xEFCDAB89; 136 | m_hash[2] = 0x98BADCFE; 137 | m_hash[3] = 0x10325476; 138 | m_hash[4] = 0xC3D2E1F0; 139 | 140 | base.Initialize(); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /HashLib/Hashes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.ObjectModel; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace HashLib 7 | { 8 | public static class Hashes 9 | { 10 | public readonly static ReadOnlyCollection All; 11 | public readonly static ReadOnlyCollection AllUnique; 12 | public readonly static ReadOnlyCollection Hash32; 13 | public readonly static ReadOnlyCollection Hash64; 14 | public readonly static ReadOnlyCollection Hash128; 15 | public readonly static ReadOnlyCollection CryptoAll; 16 | public readonly static ReadOnlyCollection CryptoNotBuildIn; 17 | public readonly static ReadOnlyCollection CryptoBuildIn; 18 | public readonly static ReadOnlyCollection HasHMACBuildIn; 19 | 20 | public readonly static ReadOnlyCollection NonBlock; 21 | public readonly static ReadOnlyCollection FastComputes; 22 | public readonly static ReadOnlyCollection Checksums; 23 | public readonly static ReadOnlyCollection WithKey; 24 | 25 | static Hashes() 26 | { 27 | #if !NETCORE 28 | All = (from hf in Assembly.GetAssembly(typeof(IHash)).GetTypes() 29 | where hf.IsClass 30 | where !hf.IsAbstract 31 | where hf != typeof(HMACNotBuildInAdapter) 32 | where hf != typeof(HashCryptoBuildIn) 33 | where hf != typeof(HMACBuildInAdapter) 34 | where hf.IsImplementInterface(typeof(IHash)) 35 | where !hf.IsNested 36 | select hf).ToList().AsReadOnly(); 37 | 38 | All = (from hf in All 39 | orderby hf.Name 40 | select hf).ToList().AsReadOnly(); 41 | 42 | var x2 = new Type[] 43 | { 44 | 45 | typeof(HashLib.Crypto.BuildIn.SHA1Cng), 46 | typeof(HashLib.Crypto.BuildIn.SHA1Managed), 47 | typeof(HashLib.Crypto.BuildIn.SHA256Cng), 48 | typeof(HashLib.Crypto.BuildIn.SHA256Managed), 49 | typeof(HashLib.Crypto.BuildIn.SHA384Cng), 50 | typeof(HashLib.Crypto.BuildIn.SHA384Managed), 51 | typeof(HashLib.Crypto.BuildIn.SHA512Cng), 52 | typeof(HashLib.Crypto.BuildIn.SHA512Managed), 53 | typeof(HashLib.Crypto.MD5), 54 | typeof(HashLib.Crypto.RIPEMD160), 55 | typeof(HashLib.Crypto.SHA1), 56 | typeof(HashLib.Crypto.SHA256), 57 | typeof(HashLib.Crypto.SHA384), 58 | typeof(HashLib.Crypto.SHA512), 59 | }; 60 | 61 | AllUnique = (from hf in All 62 | where !(hf.IsDerivedFrom(typeof(HashLib.Hash32.DotNet))) 63 | where !x2.Contains(hf) 64 | where !hf.IsNested 65 | select hf).ToList().AsReadOnly(); 66 | 67 | Hash32 = (from hf in All 68 | where hf.IsImplementInterface(typeof(IHash32)) 69 | where !hf.IsImplementInterface(typeof(IChecksum)) 70 | select hf).ToList().AsReadOnly(); 71 | 72 | Hash64 = (from hf in All 73 | where hf.IsImplementInterface(typeof(IHash64)) 74 | where !hf.IsImplementInterface(typeof(IChecksum)) 75 | select hf).ToList().AsReadOnly(); 76 | 77 | Hash128 = (from hf in All 78 | where hf.IsImplementInterface(typeof(IHash128)) 79 | where !hf.IsImplementInterface(typeof(IChecksum)) 80 | select hf).ToList().AsReadOnly(); 81 | 82 | Checksums = (from hf in All 83 | where hf.IsImplementInterface(typeof(IChecksum)) 84 | select hf).ToList().AsReadOnly(); 85 | 86 | FastComputes = (from hf in All 87 | where hf.IsImplementInterface(typeof(IFastHash32)) 88 | select hf).ToList().AsReadOnly(); 89 | 90 | NonBlock = (from hf in All 91 | where hf.IsImplementInterface(typeof(INonBlockHash)) 92 | select hf).ToList().AsReadOnly(); 93 | 94 | WithKey = (from hf in All 95 | where hf.IsImplementInterface(typeof(IWithKey)) 96 | select hf).ToList().AsReadOnly(); 97 | 98 | CryptoAll = (from hf in All 99 | where hf.IsImplementInterface(typeof(ICrypto)) 100 | select hf).ToList().AsReadOnly(); 101 | 102 | CryptoNotBuildIn = (from hf in CryptoAll 103 | where hf.IsImplementInterface(typeof(ICryptoNotBuildIn)) 104 | select hf).ToList().AsReadOnly(); 105 | 106 | CryptoBuildIn = (from hf in CryptoAll 107 | where hf.IsImplementInterface(typeof(ICryptoBuildIn)) 108 | select hf).ToList().AsReadOnly(); 109 | 110 | HasHMACBuildIn = (from hf in CryptoBuildIn 111 | where hf.IsImplementInterface(typeof(IHasHMACBuildIn)) 112 | select hf).ToList().AsReadOnly(); 113 | #endif 114 | 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Hamsi512Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: 5CD7436A91E27FC809D7015C3407540633DAB391127113CE6BA360F0C1E35F404510834A551610D6E871E75651EA381A8BA628AF1DCF2B2BE13AF2EB6247290F 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 43062E509458BB167153374FAD674381BB25D0799A2FD0CCBA16514AAA0AF4D4193589CEB3CC71B426D36355D1E3ABECFA5F36A8472B78E95F1F69604F9DD04D 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: 1DDCB4DE69E86F1DC5A40D8ED7CBB06F44CB8BE86F41A10B72C458303C42C4E6ED8B0B87C340F0E1F8AED28F60093F97F606B345DAD8A850213FE316A4B99C49 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: FE762C99A0BA0CF541EB5FE9C0C939B4633B77403E3B71AB9AD4FC21B44FAE248B13346B2044CEF79C111095D54AD9A3EED3F2A7090DF477FD84D092FEE459CF 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 2DB6387AF0F6C8D52D9F95BA8C2DEB88864C1E2C99484ADAFA8D366689C8265986D7C505CA138723561D045D78AED93B993F03C225C20CE5263767FFAC4A8BF9 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: 2E1C5FCF1EA89CC366FD6E9A90AAFA2995A99332F007BCDCA4C2F965B4619397AD0FED0A420872EABF6BCB6BC03EC66AF49B0469E0615DF4F9E6208ABF97B122 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: 5A6D0729E90207BB3C9051D78C6851F108E5D1613B46D127AD664C59AC1196730C6BF5B4754E7A9AF059BEA303A498B9B69D3B8F8DFE9D95DD03949728317B17 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: AA55C267959724473960B69286654A714429E51D648551EA5D4AB032E5292A23FB56E01D61744A2216562DCFD0E0179910FC22867394C6C17D7CDC0FAB1DBE5D 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: B89F9897E64ECFED0A9988E1972E66827BAC882FE73849C4A93683FEE90D9878428426B54C279DB456E4DB678B7816FC726DFC6EEB531BE8A01BC447C786BA1E 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: CC7EC64E8063888338C431C60C7A9CDA23AB3C4A2F72534532248B0109E71C77FB79944F1AD39138DDF83C35F3B78332A976D2560E3E7A17783D7C6686389880 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: 167ECBD79893B0BE008138AF2396E6F270F41ACA4B3D57F6410FAAF3D12315975F177ABB83CA5C0B5AFDA37D46C0303071480D207F2E43EE23DAF2C3861FF2FA 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: E5C5AEA3936F08F10765D983139EDAA557CB4916ADB7C0D62D059001732033E84640FF2A84A90CB6AF4AD99AB1894191F2A2B5C115728E7C1B1F6C2750894C3B 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: 755C988363E0BBBD2494B80CDBFF173FA716A8B9B61060AD350FE3FDF1E4129ACA3F786827F8C1974C3DB41904ED57E19A85891DFF3D1438080390B2DD99BB6B 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: DB91249A315864A9619D55760B6708F28B91183CBD8DD7351B6BB12E00C75972AC115702D0B80F5D2211AF5D7A8AB7ECD4AEFDED6A083CA22352886C6B4CA2B4 56 | 57 | Repeat: 1 58 | Messsage: 4A8BAE394046AFBC47D690224CB9 59 | Hash: A7B2B9CEF5876BB7E49807D37195F8CB8923DB695F286F0B9405376BD374B5E676E09FA6E3192B0A329A446BB11D194843B12F9E406E19EDEC5768D3FCCBEE03 60 | 61 | Repeat: 1 62 | Messsage: 78D9CE79AFC1E0C41E2A48278E4B4B 63 | Hash: F6FF49EC8E2012665CE401FE2DA9D41EEBF41887BCE2FF7F7DDCA1C2F20D623AC5A5E3C5B1A2AA327742D39BDBE5318A141388BB7A15DD821A6BE95B8D78F269 64 | 65 | Repeat: 1 66 | Messsage: 816B650FB50D8E848DB94034628FC520 67 | Hash: C5167DABDAC66DE3A4F5C4432D68E55364B667A86436522E56EF0F7722FE766268D472AFD0EBC6C8240D39A7252870A4ED226544EB51FCE812C46AEA8A6DC22F 68 | 69 | Repeat: 1 70 | Messsage: 629768E3633858B4D23D04773DA28CBCFB 71 | Hash: 2E92AA31752D4F33B88B18ACA7687EE339B2029C359843F409EF4C14E5FD427BC81F068378B3C7E0A0C2F70ACD78F9D751C94587DBBC8ED4F459E8381E30B9D5 72 | 73 | Repeat: 1 74 | Messsage: 55462FF88CDF40292838C888B71D16EA5D88 75 | Hash: 47B3C6CF6EB64256CE2FC42976213C37CE4E8CFEF1E042EBD10B2342B138CA1655B7B273C616F5F43248C8E35E9DE2A1EC163AD88CE92404597961E2EC7B0C56 76 | 77 | Repeat: 1 78 | Messsage: C69924B3A64312DB5808B1C3AD05C05413E958 79 | Hash: 7DC12453157095FED00953D2FBF4C0509D2462CAC36307D5B4EB6EA68673DD230C939374A29D260AFAF569FE40E07F4719AFDEA1B9F5BED71E3C9E4E0DCB8EAA 80 | 81 | Repeat: 1 82 | Messsage: 5A6462CE04496BA8DCF67799EE4CAB353E337A47 83 | Hash: 4F1354734B40550BC84B7ED12F0C1BE0ED37357EE3C9040D411D597A1E5B5B559F431C0E3677349DFDF9FF2006CFCC3EE0584581A969472C8368B4C84AC51FC4 84 | 85 | Repeat: 1 86 | Messsage: 99F397D1268B57091AA4A299685C3826FC77196E21 87 | Hash: 18B991FF81E90201547EC96A3D3CDE8E9FC45894EDC453A4C78C4B432FAF75CC3CEE7D2598C077F2E9F7D8144B2BB3C9AFA70CB2BE3A36A0A5707B1B42086386 88 | 89 | Repeat: 1 90 | Messsage: 7A78E5E46E36837950F3D53061C0789B90F5374CEC88 91 | Hash: D978BC8373798FEC2307D3606B2A0B1FB89344708267C4A05082B5E8323711733E1D2E26A4D0E90F053796C8FF8850338B0DC5411E8B037CB6054CA19E3EAE55 92 | 93 | Repeat: 1 94 | Messsage: A0DAC9754045558650DA891AFB3EC312CCF85D3300D426 95 | Hash: 95D6EF7B69C58EADCF96C3F92BB7BE67950EA3B34B3EC8473670B370A0D69D55D3898801160F7BB18BC89D0FC7BE2B39D2AC279A9962BDC0A7B3DD2A9DA73B89 96 | 97 | Repeat: 1 98 | Messsage: 0B69E8AA8DEED1859D2B7FF78D07DCEDE826A872E66E0AE1 99 | Hash: BC7FA8C2DA6773C9F8C10B5B18EA8A73D056F0879B7402ED6DA12C73EDD5AD9581CA13DED4390B17F63EC515A12E0730613FB596D933BE9693F8CE376555DDDA 100 | 101 | Repeat: 1 102 | Messsage: 3ECD10659E510DD8F28C8DDABAA5790C640A77C8243F958C9C 103 | Hash: 6B260241D8D3EE50A3F4A6EC69579B5D1F5B11FDC9D5A11A895B12FAD4E2F7A329430E8F0280B48D93B3B347863FDEFD16CD6CDEC4FC6C550B8173114E9BC645 104 | 105 | Repeat: 16777216 106 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 107 | Hash: 047448D564FEB5F0ECB7CF18E82090A552ABC3424A5D5E547BE13C245AA0C77733C667234989D55A0F8B3AAD0CB91E2C9AA7319CC36FE73065190F7B6F370638 108 | 109 | Repeat: 67108865 110 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 111 | Hash: 3B29DB4AA5AAA742C80B8553DD34D59B51D2FB8FCD61676AFB7DEA9E453CA15AEBC2DAAAC0FD2F87E3C6D52A72026C8634770535B73B19E5C3609086118A9283 112 | 113 | -------------------------------------------------------------------------------- /TomanuExtensions/Utils/Hex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TomanuExtensions.Utils 4 | { 5 | public static class Hex 6 | { 7 | private static byte[] m_trans_hex_to_bin = new byte[255]; 8 | private static char[] m_trans_bin_to_hex = new[] { '0', '1', '2', '3', '4', '5', '6', '7', 9 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 10 | 11 | static Hex() 12 | { 13 | for (int i = '0'; i <= '9'; i++) 14 | m_trans_hex_to_bin[i] = (byte)(i - '0'); 15 | for (int i = 'a'; i <= 'f'; i++) 16 | m_trans_hex_to_bin[i] = (byte)(i - 'a' + 10); 17 | for (int i = 'A'; i <= 'F'; i++) 18 | m_trans_hex_to_bin[i] = (byte)(i - 'A' + 10); 19 | } 20 | 21 | public static byte HexToByte(string a_str, bool a_added_0x = true) 22 | { 23 | int index = 0; 24 | if (a_added_0x) 25 | index += 2; 26 | 27 | return (byte)( 28 | (m_trans_hex_to_bin[a_str[index++]] << 4) | 29 | m_trans_hex_to_bin[a_str[index++]]); 30 | } 31 | 32 | public static ushort HexToUShort(string a_str, bool a_added_0x = true) 33 | { 34 | int index = 0; 35 | if (a_added_0x) 36 | index += 2; 37 | 38 | return (ushort)( 39 | (m_trans_hex_to_bin[a_str[index++]] << 12) | 40 | (m_trans_hex_to_bin[a_str[index++]] << 8) | 41 | (m_trans_hex_to_bin[a_str[index++]] << 4) | 42 | m_trans_hex_to_bin[a_str[index++]]); 43 | } 44 | 45 | public static uint HexToUInt(string a_str, bool a_added_0x = true) 46 | { 47 | int index = 0; 48 | if (a_added_0x) 49 | index += 2; 50 | 51 | return (uint)( 52 | (m_trans_hex_to_bin[a_str[index++]] << 28) | 53 | (m_trans_hex_to_bin[a_str[index++]] << 24) | 54 | (m_trans_hex_to_bin[a_str[index++]] << 20) | 55 | (m_trans_hex_to_bin[a_str[index++]] << 16) | 56 | (m_trans_hex_to_bin[a_str[index++]] << 12) | 57 | (m_trans_hex_to_bin[a_str[index++]] << 8) | 58 | (m_trans_hex_to_bin[a_str[index++]] << 4) | 59 | m_trans_hex_to_bin[a_str[index++]]); 60 | } 61 | 62 | public static string ByteToHex(byte a_value, bool a_add_0x = true) 63 | { 64 | if (a_add_0x) 65 | { 66 | return new String(new char[] 67 | { 68 | '0', 'x', 69 | m_trans_bin_to_hex[a_value >> 4], 70 | m_trans_bin_to_hex[a_value & 0x0F] 71 | }); 72 | } 73 | else 74 | { 75 | return new String(new char[] 76 | { 77 | m_trans_bin_to_hex[a_value >> 4], 78 | m_trans_bin_to_hex[a_value & 0x0F] 79 | }); 80 | } 81 | } 82 | 83 | public static string UShortToHex(ushort a_value, bool a_add_0x = true) 84 | { 85 | if (a_add_0x) 86 | { 87 | return new String(new char[] 88 | { 89 | '0', 'x', 90 | m_trans_bin_to_hex[a_value >> 12], 91 | m_trans_bin_to_hex[(a_value >> 8) & 0x0F], 92 | m_trans_bin_to_hex[(a_value >> 4) & 0x0F], 93 | m_trans_bin_to_hex[a_value & 0x0F] 94 | }); 95 | } 96 | else 97 | { 98 | return new String(new char[] 99 | { 100 | m_trans_bin_to_hex[a_value >> 12], 101 | m_trans_bin_to_hex[(a_value >> 8) & 0x0F], 102 | m_trans_bin_to_hex[(a_value >> 4) & 0x0F], 103 | m_trans_bin_to_hex[a_value & 0x0F] 104 | }); 105 | } 106 | } 107 | 108 | public static string UIntToHex(uint a_value, bool a_add_0x = true) 109 | { 110 | if (a_add_0x) 111 | { 112 | return new String(new char[] 113 | { 114 | '0', 'x', 115 | m_trans_bin_to_hex[a_value >> 28], 116 | m_trans_bin_to_hex[(a_value >> 24) & 0x0F], 117 | m_trans_bin_to_hex[(a_value >> 20) & 0x0F], 118 | m_trans_bin_to_hex[(a_value >> 16) & 0x0F], 119 | m_trans_bin_to_hex[(a_value >> 12) & 0x0F], 120 | m_trans_bin_to_hex[(a_value >> 8) & 0x0F], 121 | m_trans_bin_to_hex[(a_value >> 4) & 0x0F], 122 | m_trans_bin_to_hex[a_value & 0x0F] 123 | }); 124 | } 125 | else 126 | { 127 | return new String(new char[] 128 | { 129 | m_trans_bin_to_hex[a_value >> 28], 130 | m_trans_bin_to_hex[(a_value >> 24) & 0x0F], 131 | m_trans_bin_to_hex[(a_value >> 20) & 0x0F], 132 | m_trans_bin_to_hex[(a_value >> 16) & 0x0F], 133 | m_trans_bin_to_hex[(a_value >> 12) & 0x0F], 134 | m_trans_bin_to_hex[(a_value >> 8) & 0x0F], 135 | m_trans_bin_to_hex[(a_value >> 4) & 0x0F], 136 | m_trans_bin_to_hex[a_value & 0x0F] 137 | }); 138 | } 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /HashLibTest/TestData/Grindahl512Test.txt: -------------------------------------------------------------------------------- 1 | Repeat: 1 2 | Messsage: 3 | Hash: EE0BA85F90B6D232430BA43DD0EDD008462591816962A355602ED214FAAE54A9A4607D6F577CE950421FF58AEA53F51A7A9F5CCA894C3776104D43568FEA1207 4 | 5 | Repeat: 1 6 | Messsage: 40 7 | Hash: 5104726C9D699FA0BB1002BD5908FF566DCCDEAB4CD59C2FB01F18E8229AD8516F5DC6D1724F3E1BAEB5366017682DEFD0C71DFCC20A36CCD21CCCC0033C2DDC 8 | 9 | Repeat: 1 10 | Messsage: 3197 11 | Hash: EAA8EE1F3128F57BE17B287E4EC38ED8EBEFF54FD6364E39E60E0C6471AE95B569FBF3D0D79FCEB7EB2E19069A5E555031875399119EE3368FDF0EFA9B54A3B7 12 | 13 | Repeat: 1 14 | Messsage: 4D22DF 15 | Hash: 3CC3A8D0556264F9EC5761606A0F3F234A1883128D0EBF9A8FDEB47ECEE4450D462E61BD4F9F831C62921CFB98297198B43F300F88FEABD297D623DCCD32C864 16 | 17 | Repeat: 1 18 | Messsage: 6CCD13D7 19 | Hash: 8544C2F1439C5BF52979B88002B4DF8B3D5FCD579D689A03E956385043627D1DD53B501165C7EDF9DA15DDA81C126B87D45727BB62EF6B640713E9800AD83C36 20 | 21 | Repeat: 1 22 | Messsage: D8D9C639AE 23 | Hash: 51745A9125BB08661DAB0C42953AD8369180A1322FA52291BB7CE048FD8FD5C190DDFF6437964DECC6C32FBD97CC162534B8C0DA0FF71DD98537420BAD87D2F6 24 | 25 | Repeat: 1 26 | Messsage: FBC4AB9E4B2F 27 | Hash: 8894348D082AF40B19C110174F6638E96F265B451F4FDE19C229D9AA76211FF958EBEB89752DD801A5382F6AA2D9290B6C7A506226BC76E98B8F93FF4F48375E 28 | 29 | Repeat: 1 30 | Messsage: D19BEB74934639 31 | Hash: 516C039B8ACC816387FEFC22905389FE6907E65C4C6D33D84CB07E15E4FD336D427D2A969E449F7405955C2103CB622A3AD882C9E7B5B7B8EB081CBDE3CCE2C8 32 | 33 | Repeat: 1 34 | Messsage: 48DE5F4845276C8F 35 | Hash: 8F799124979EAF92A90B7C63A95C292D8E733EB639BA119C37EB42991E8445949F8A62CD637E60CE963CA1B194B3411CFB66A2852574E0CAC1613E2169F1FD08 36 | 37 | Repeat: 1 38 | Messsage: 8E854990BC47A07EAA 39 | Hash: 1BAED07B32341D73A571FAC873651687415A6F073FB7DDD42613D6E7675C9AA70F11BEC2983042A6059CC489FD85CDC867A730FE325934AE4983FB531A425F0B 40 | 41 | Repeat: 1 42 | Messsage: 4EB0FE433C6B87F34B29 43 | Hash: 0A1FDB39C10CE56887C6C2232005226E3F91CFC601A0DE41C06B46E887F175EA7E467E08D3A7AA9D442807514BC358DE6BC7DB9306D409C84D6ED551A9146699 44 | 45 | Repeat: 1 46 | Messsage: BE497843C5834987519441 47 | Hash: 6DA557F474A80EAEFED00CAF119D028251EDBBECA46FE162D16163332CD5C598D3E6D9066BF4BB7AE58539E93E430C70A8DA72025F323EC961340DA6A1986F51 48 | 49 | Repeat: 1 50 | Messsage: 8331CA2956433A094249FDBE 51 | Hash: 175507E32BE9A7441B7BD659B8142C1F83AA55DDC0BD6BD48C110649F34692AF736CACD7C168F51E59F17379C53F22F14A3482A7EECD41DAB497FB1F2DECF72E 52 | 53 | Repeat: 1 54 | Messsage: BF62FA2EECBE87D080E92C37EB 55 | Hash: 24BFECCC00BF4B5A810EBD4A070E3E023B020A218988E12CF9D6335B52B2FF5F7081ADDDE28975CDB085C4289CB7D9B8359568FD974D7596587148542866812F 56 | 57 | Repeat: 1 58 | Messsage: 4A8BAE394046AFBC47D690224CB9 59 | Hash: 5850ACE261A7691F35A2DCD84BD6AC71E752E85CDA66AED803AE957CB540B9F1D85825E1E7CB3BA3DF72B74DFC8203141A3A66E21567E98124E30F215EFD0E12 60 | 61 | Repeat: 1 62 | Messsage: 78D9CE79AFC1E0C41E2A48278E4B4B 63 | Hash: 756C2BC8FD1B1231A9A34EECA9A81261A8D141D623467A2C462E069CA4C36ECC2E8CCF82EAB676089CDEBEEF414AD7511DB9B43A90F98F9FA67081A2487BA997 64 | 65 | Repeat: 1 66 | Messsage: 816B650FB50D8E848DB94034628FC520 67 | Hash: 1C4BCC70E5AEBE2969AD7384F04C3F30CFC8C7254EAB9EBEA10FBBD7DC7FDE4BDE4F1EB5363BF7274E1A5B7C5DD8AA618B14E7D246BF3748F4F49D121A69721E 68 | 69 | Repeat: 1 70 | Messsage: 629768E3633858B4D23D04773DA28CBCFB 71 | Hash: 7508948850789EE6406F642E5BEB7B14F92D39D4EB53372D524CB3766D047F810D923A59B36A806E6BEF5FB1A1C86FBF55CB29965C4A8E5930A8413E377702B3 72 | 73 | Repeat: 1 74 | Messsage: 55462FF88CDF40292838C888B71D16EA5D88 75 | Hash: 5316F36B615A58C3A85B55CAF108F3BC032EB508856F513573B8B8D2C302C0FDEB2866EE72A23433C795ED2012D250C786BFAF736E7428847AD83F11BDC46EE4 76 | 77 | Repeat: 1 78 | Messsage: C69924B3A64312DB5808B1C3AD05C05413E958 79 | Hash: 1A700A266ECD4298F656A878AD07AFED619888FAF6655D58905C6BC2FA08AD86BC5771218B0D4715E6F675E49BE7F6E15C39EA4789FE5D1CB5B75C549814B3FC 80 | 81 | Repeat: 1 82 | Messsage: 5A6462CE04496BA8DCF67799EE4CAB353E337A47 83 | Hash: 9C66267D0D8490EA3364C077479A355D6466FDE55DE4B857D0C8CAAFD1B3B3159D1C876937CAB541F42A88E73767820CBC110E5B94016667D81E722ECBEE1286 84 | 85 | Repeat: 1 86 | Messsage: 99F397D1268B57091AA4A299685C3826FC77196E21 87 | Hash: 61F7A6FE8C2C624C3E07E220CFE2BB1A5DCB6D41AE53874388A9A9D754FA20994412698BF4D430411441D42F0340393BA9B77905EDE9CFEE10441D07ECEDED97 88 | 89 | Repeat: 1 90 | Messsage: 7A78E5E46E36837950F3D53061C0789B90F5374CEC88 91 | Hash: CD863A3EC43F6F3240CAB346D06C916B68A1F45B74573479E6B7816EB90962E99EDEC8953B01902B617141D86D02E1035384A077A83F6C4CAB4FB078DB9D402A 92 | 93 | Repeat: 1 94 | Messsage: A0DAC9754045558650DA891AFB3EC312CCF85D3300D426 95 | Hash: 51ECD1BCB00AA2340AEE315CA89F9F56A8083DD611ED8C76A809A0B3B649509E8C0F358CB78157DE484B4005D5F9A3D58DFCA1F3D4E625C2104AAABC5C231303 96 | 97 | Repeat: 1 98 | Messsage: 0B69E8AA8DEED1859D2B7FF78D07DCEDE826A872E66E0AE1 99 | Hash: 2B7CF619B4CC33CF15F09EE3E7860FF0248F732E19FEC98AFC0562C378960ECC9F54C0382420703FC310313D59A42B9FDB92D035A8A526A3ACCFBBF971F8C9FB 100 | 101 | Repeat: 1 102 | Messsage: 3ECD10659E510DD8F28C8DDABAA5790C640A77C8243F958C9C 103 | Hash: 59CFC7CF5CC43BF1B3C57396ABDFB96F1AC76935A7DB9E851716DF01609A59D71D191401536FF3DC6CC7DBDE3A092F72D7CE6B665BF766114361BAECCD335BCA 104 | 105 | Repeat: 16777216 106 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 107 | Hash: BED7C81D53A15E6971149880BB7705E5C59B114150FAD48CD10991EDE34385C5B74BAF27113F50BD04C415172C2E795F8106C0F40E20800BDB26BF4B9CDC512E 108 | 109 | Repeat: 67108865 110 | Text: abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno 111 | Hash: A3FCD312285CC17471C2C98726DF0122159366EFD73AA922D266EC38AA3CA1DE807694D4022D2FD17FDDA815A4EA0805506915165F431DC864A0D7C330324026 112 | 113 | -------------------------------------------------------------------------------- /HashLibTest/TestData/Murmur2_64Test.txt: -------------------------------------------------------------------------------- 1 | Key: 7B1A8FC5 2 | Repeat: 1 3 | Messsage: 4 | Hash: 0000000000000000 5 | 6 | Key: E60E3263 7 | Repeat: 1 8 | Messsage: 9 | Hash: 0000000000000000 10 | 11 | Key: 7B1A8FC5 12 | Repeat: 1 13 | Messsage: 40 14 | Hash: 8587975F5F7E7E51 15 | 16 | Key: E60E3263 17 | Repeat: 1 18 | Messsage: 31 19 | Hash: EB8B0C67C68DBE4D 20 | 21 | Key: 7B1A8FC5 22 | Repeat: 1 23 | Messsage: 974D 24 | Hash: E024B75CAD1A49C2 25 | 26 | Key: E60E3263 27 | Repeat: 1 28 | Messsage: 22DF 29 | Hash: A8F13C93DBBBABA7 30 | 31 | Key: 7B1A8FC5 32 | Repeat: 1 33 | Messsage: 6CCD13 34 | Hash: CE282A81392E8D5C 35 | 36 | Key: E60E3263 37 | Repeat: 1 38 | Messsage: D7D8D9 39 | Hash: 9EE125DDEFF14854 40 | 41 | Key: 7B1A8FC5 42 | Repeat: 1 43 | Messsage: C639AEFB 44 | Hash: 2A6913486D8BD97D 45 | 46 | Key: E60E3263 47 | Repeat: 1 48 | Messsage: C4AB9E4B 49 | Hash: 26AE722A53CDDA04 50 | 51 | Key: 7B1A8FC5 52 | Repeat: 1 53 | Messsage: 2FD19BEB74 54 | Hash: 296AD7D13920DE29 55 | 56 | Key: E60E3263 57 | Repeat: 1 58 | Messsage: 93463948DE 59 | Hash: EBD522C035863027 60 | 61 | Key: 7B1A8FC5 62 | Repeat: 1 63 | Messsage: 5F4845276C8F 64 | Hash: 198CC78B144DA2F5 65 | 66 | Key: E60E3263 67 | Repeat: 1 68 | Messsage: 8E854990BC47 69 | Hash: 8732BD4E66619D83 70 | 71 | Key: 7B1A8FC5 72 | Repeat: 1 73 | Messsage: A07EAA4EB0FE43 74 | Hash: 96BEA7667042193D 75 | 76 | Key: E60E3263 77 | Repeat: 1 78 | Messsage: 3C6B87F34B29BE 79 | Hash: 1112ED1580DA204A 80 | 81 | Key: 7B1A8FC5 82 | Repeat: 1 83 | Messsage: 497843C583498751 84 | Hash: 2780296C30C62DA0 85 | 86 | Key: E60E3263 87 | Repeat: 1 88 | Messsage: 94418331CA295643 89 | Hash: 46D3698A5AD75D4B 90 | 91 | Key: 7B1A8FC5 92 | Repeat: 1 93 | Messsage: 3A094249FDBEBF62FA 94 | Hash: 4C6EEA6B53AD751F 95 | 96 | Key: E60E3263 97 | Repeat: 1 98 | Messsage: 2EECBE87D080E92C37 99 | Hash: 03209C01CD1582C0 100 | 101 | Key: 7B1A8FC5 102 | Repeat: 1 103 | Messsage: EB4A8BAE394046AFBC47 104 | Hash: EB949B263B616965 105 | 106 | Key: E60E3263 107 | Repeat: 1 108 | Messsage: D690224CB978D9CE79AF 109 | Hash: 9314D51FAF0862B0 110 | 111 | Key: 7B1A8FC5 112 | Repeat: 1 113 | Messsage: C1E0C41E2A48278E4B4B81 114 | Hash: 5352AD98D33C3D2F 115 | 116 | Key: E60E3263 117 | Repeat: 1 118 | Messsage: 6B650FB50D8E848DB94034 119 | Hash: 7E5DE27FCE19E358 120 | 121 | Key: 7B1A8FC5 122 | Repeat: 1 123 | Messsage: 628FC520629768E3633858B4 124 | Hash: 64E1A45F3C971ED9 125 | 126 | Key: E60E3263 127 | Repeat: 1 128 | Messsage: D23D04773DA28CBCFB55462F 129 | Hash: 821B841E356781C7 130 | 131 | Key: 7B1A8FC5 132 | Repeat: 1 133 | Messsage: F88CDF40292838C888B71D16EA 134 | Hash: 8831CCCA73CFFF0C 135 | 136 | Key: E60E3263 137 | Repeat: 1 138 | Messsage: 5D88C69924B3A64312DB5808B1 139 | Hash: 1A0F9D1913F8440B 140 | 141 | Key: 7B1A8FC5 142 | Repeat: 1 143 | Messsage: C3AD05C05413E9585A6462CE0449 144 | Hash: FDC402E1FD7F8687 145 | 146 | Key: E60E3263 147 | Repeat: 1 148 | Messsage: 6BA8DCF67799EE4CAB353E337A47 149 | Hash: C7D4239B183150FD 150 | 151 | Key: 7B1A8FC5 152 | Repeat: 1 153 | Messsage: 99F397D1268B57091AA4A299685C38 154 | Hash: 9AD3A516A28E82F0 155 | 156 | Key: E60E3263 157 | Repeat: 1 158 | Messsage: 26FC77196E217A78E5E46E36837950 159 | Hash: 9C7C7A805D347232 160 | 161 | Key: 7B1A8FC5 162 | Repeat: 1 163 | Messsage: F3D53061C0789B90F5374CEC88A0DAC9 164 | Hash: 6224A70764AF7D3F 165 | 166 | Key: E60E3263 167 | Repeat: 1 168 | Messsage: 754045558650DA891AFB3EC312CCF85D 169 | Hash: B2E88E4F940EC348 170 | 171 | Key: 7B1A8FC5 172 | Repeat: 1 173 | Messsage: 3300D4260B69E8AA8DEED1859D2B7FF78D 174 | Hash: F30864CC62A09F17 175 | 176 | Key: E60E3263 177 | Repeat: 1 178 | Messsage: 07DCEDE826A872E66E0AE13ECD10659E51 179 | Hash: 85F2C1746C7E1488 180 | 181 | Key: 7B1A8FC5 182 | Repeat: 1 183 | Messsage: 0DD8F28C8DDABAA5790C640A77C8243F958C 184 | Hash: 8FBE346FF1137921 185 | 186 | Key: E60E3263 187 | Repeat: 1 188 | Messsage: 9C2618CDDCA206E42E247BE6474224E5A634 189 | Hash: 5BB9970130F104F1 190 | 191 | Key: 7B1A8FC5 192 | Repeat: 1 193 | Messsage: 377B9AD6C4BAC621D655314A0198F4C4623A36 194 | Hash: C11A295E5024C1B8 195 | 196 | Key: E60E3263 197 | Repeat: 1 198 | Messsage: 4C3B81F45D079EDA66F50C44BB33E8279FFCED 199 | Hash: 2F1F3AEBE8D3B447 200 | 201 | Key: 7B1A8FC5 202 | Repeat: 1 203 | Messsage: 8CDC4690D5F10121060934800A4B881DE2CA9B1F 204 | Hash: 5A538F15A59608BD 205 | 206 | Key: E60E3263 207 | Repeat: 1 208 | Messsage: 206C76658D0CC89186812C99D936B8751D6901CA 209 | Hash: 37202392247B06A6 210 | 211 | Key: 7B1A8FC5 212 | Repeat: 1 213 | Messsage: 1892C03D8FB0B72B60A7A87BA20A931915A4708407 214 | Hash: 4A2D549470837BB6 215 | 216 | Key: E60E3263 217 | Repeat: 1 218 | Messsage: 04DA66E2384473A79AB5D98924B7EDB4FD6329975F 219 | Hash: D59055594936BF74 220 | 221 | Key: 7B1A8FC5 222 | Repeat: 1 223 | Messsage: 0A49D33C256BF4BC51F5BD41B1480C641BF721630AC4 224 | Hash: 6A7F7D3EA5BF9541 225 | 226 | Key: E60E3263 227 | Repeat: 1 228 | Messsage: 165B490CA14E324E49136D9F2E86993AA9577E0176DE 229 | Hash: 28FC1529616894C7 230 | 231 | Key: 7B1A8FC5 232 | Repeat: 1 233 | Messsage: E507BF649F9358EEBE67CEAFA2D4C10ACE8D4BE895AD01 234 | Hash: 89EC6428F416DA6F 235 | 236 | Key: E60E3263 237 | Repeat: 1 238 | Messsage: 5ECA91AB59E81C9486D97C079CBE1867834BD5B03C3AE3 239 | Hash: B5A57C4DAE339C03 240 | 241 | Key: 7B1A8FC5 242 | Repeat: 1 243 | Messsage: C65A9FBB842643FD84EBECF3C5A7476DBB35D348DBEC5A0E 244 | Hash: F0F83354B3FBEA6F 245 | 246 | Key: E60E3263 247 | Repeat: 1 248 | Messsage: B7B3A5499BE07B8FCD489A7B56E07F0A91D1964971FB3435 249 | Hash: FD0068FC9D210DE4 250 | 251 | Key: 7B1A8FC5 252 | Repeat: 1 253 | Messsage: 51CA6D29F63D2260F4158E2467304ECE74DF2CA1410B338726 254 | Hash: C9541D9E8853D607 255 | 256 | Key: E60E3263 257 | Repeat: 1 258 | Messsage: BF3ED9BB4BF5E91932E0D1AE09905D4680BD42ECC7FBEC8A21 259 | Hash: E61559D37CE77ADD 260 | 261 | --------------------------------------------------------------------------------