mirror of
https://github.com/aaru-dps/Aaru.Checksums.git
synced 2025-12-16 19:24:29 +00:00
🐛Moved checksums to interface.
This commit is contained in:
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements the Adler-32 algorithm
|
/// Implements the Adler-32 algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Adler32Context
|
public class Adler32Context : IChecksum
|
||||||
{
|
{
|
||||||
const ushort ADLER_MODULE = 65521;
|
const ushort ADLER_MODULE = 65521;
|
||||||
ushort sum1, sum2;
|
ushort sum1, sum2;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a CRC16-CCITT algorithm
|
/// Implements a CRC16-CCITT algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Crc16Context
|
public class Crc16Context : IChecksum
|
||||||
{
|
{
|
||||||
const ushort CRC16_POLY = 0xA001;
|
const ushort CRC16_POLY = 0xA001;
|
||||||
const ushort CRC16_SEED = 0x0000;
|
const ushort CRC16_SEED = 0x0000;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a CRC32 algorithm
|
/// Implements a CRC32 algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Crc32Context
|
public class Crc32Context : IChecksum
|
||||||
{
|
{
|
||||||
const uint CRC32_POLY = 0xEDB88320;
|
const uint CRC32_POLY = 0xEDB88320;
|
||||||
const uint CRC32_SEED = 0xFFFFFFFF;
|
const uint CRC32_SEED = 0xFFFFFFFF;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a CRC64 (ECMA) algorithm
|
/// Implements a CRC64 (ECMA) algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Crc64Context
|
public class Crc64Context : IChecksum
|
||||||
{
|
{
|
||||||
const ulong CRC64_POLY = 0xC96C5795D7870F42;
|
const ulong CRC64_POLY = 0xC96C5795D7870F42;
|
||||||
const ulong CRC64_SEED = 0xFFFFFFFFFFFFFFFF;
|
const ulong CRC64_SEED = 0xFFFFFFFFFFFFFFFF;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="IChecksum.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="SpamSumContext.cs" />
|
<Compile Include="SpamSumContext.cs" />
|
||||||
<Compile Include="Adler32Context.cs" />
|
<Compile Include="Adler32Context.cs" />
|
||||||
|
|||||||
@@ -31,14 +31,14 @@
|
|||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
// Disabled because the speed is abnormally slow
|
// Disabled because the speed is abnormally slow
|
||||||
/*
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
public class Fletcher32Context
|
public class Fletcher32Context : IChecksum
|
||||||
{
|
{
|
||||||
bool inodd;
|
bool inodd;
|
||||||
byte oddValue;
|
byte oddValue;
|
||||||
@@ -423,4 +423,4 @@ namespace DiscImageChef.Checksums
|
|||||||
return Data(data, (uint)data.Length, out hash);
|
return Data(data, (uint)data.Length, out hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
65
IChecksum.cs
Normal file
65
IChecksum.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : IChecksum.cs
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Component : Checksums.
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Provides an interface for implementing checksums and hashes.
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2011-2018 Natalia Portillo
|
||||||
|
// ****************************************************************************/
|
||||||
|
|
||||||
|
namespace DiscImageChef.Checksums
|
||||||
|
{
|
||||||
|
public interface IChecksum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the algorithm
|
||||||
|
/// </summary>
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the hash with data.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">Data buffer.</param>
|
||||||
|
/// <param name="len">Length of buffer to hash.</param>
|
||||||
|
void Update(byte[] data, uint len);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the hash with data.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">Data buffer.</param>
|
||||||
|
void Update(byte[] data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a byte array of the hash value.
|
||||||
|
/// </summary>
|
||||||
|
byte[] Final();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a hexadecimal representation of the hash value.
|
||||||
|
/// </summary>
|
||||||
|
string End();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps up .NET MD5 implementation to a Init(), Update(), Final() context.
|
/// Wraps up .NET MD5 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Md5Context
|
public class Md5Context : IChecksum
|
||||||
{
|
{
|
||||||
MD5 md5Provider;
|
MD5 md5Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps up .NET RIPEMD160 implementation to a Init(), Update(), Final() context.
|
/// Wraps up .NET RIPEMD160 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Ripemd160Context
|
public class Ripemd160Context : IChecksum
|
||||||
{
|
{
|
||||||
RIPEMD160 ripemd160Provider;
|
RIPEMD160 ripemd160Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps up .NET SHA1 implementation to a Init(), Update(), Final() context.
|
/// Wraps up .NET SHA1 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha1Context
|
public class Sha1Context : IChecksum
|
||||||
{
|
{
|
||||||
SHA1 sha1Provider;
|
SHA1 sha1Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps up .NET SHA256 implementation to a Init(), Update(), Final() context.
|
/// Wraps up .NET SHA256 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha256Context
|
public class Sha256Context : IChecksum
|
||||||
{
|
{
|
||||||
SHA256 sha256Provider;
|
SHA256 sha256Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps up .NET SHA384 implementation to a Init(), Update(), Final() context.
|
/// Wraps up .NET SHA384 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha384Context
|
public class Sha384Context : IChecksum
|
||||||
{
|
{
|
||||||
SHA384 sha384Provider;
|
SHA384 sha384Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps up .NET SHA512 implementation to a Init(), Update(), Final() context.
|
/// Wraps up .NET SHA512 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha512Context
|
public class Sha512Context : IChecksum
|
||||||
{
|
{
|
||||||
SHA512 sha512Provider;
|
SHA512 sha512Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements the SpamSum fuzzy hashing algorithm.
|
/// Implements the SpamSum fuzzy hashing algorithm.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SpamSumContext
|
public class SpamSumContext : IChecksum
|
||||||
{
|
{
|
||||||
const uint ROLLING_WINDOW = 7;
|
const uint ROLLING_WINDOW = 7;
|
||||||
const uint MIN_BLOCKSIZE = 3;
|
const uint MIN_BLOCKSIZE = 3;
|
||||||
|
|||||||
Reference in New Issue
Block a user