General code refactor and cleanup.

This commit is contained in:
2022-11-23 18:16:04 +00:00
parent 40487268b4
commit aa5bbc1f5b
21 changed files with 340 additions and 331 deletions

View File

@@ -1,86 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CC48B324-A532-4A45-87A6-6F91F7141E8D}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Aaru.Checksums</RootNamespace>
<AssemblyName>Aaru.Checksums</AssemblyName>
<ReleaseVersion>$(Version)</ReleaseVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>6.0.0-alpha8</Version>
<Company>Claunia.com</Company>
<Copyright>Copyright © 2011-2022 Natalia Portillo</Copyright>
<Product>Aaru Data Preservation Suite</Product>
<Title>Aaru.Checksums</Title>
<ApplicationVersion>$(Version)</ApplicationVersion>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11</LangVersion>
<Description>C# implementation of CRC16, CRC32, CRC64, Fletcher, MD5, SHA1, SHA2 and SpamSum.</Description>
<PackageProjectUrl>https://github.com/aaru-dps/</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<RepositoryUrl>https://github.com/aaru-dps/Aaru.Checksums</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Authors>Natalia Portillo &lt;claunia@claunia.com&gt;</Authors>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<NoWarn>CS1591;CS1574</NoWarn>
</PropertyGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<InternalsVisibleTo Include="Aaru.Tests"/>
<InternalsVisibleTo Include="Aaru.Tests.Devices"/>
</ItemGroup>
<PropertyGroup>
<NrtRevisionFormat>$(Version)+{chash:8}</NrtRevisionFormat>
<NrtResolveSimpleAttributes>true</NrtResolveSimpleAttributes>
<NrtShowRevision>true</NrtShowRevision>
</PropertyGroup>
<ItemGroup>
<Compile Include="Adler32\neon.cs"/>
<Compile Include="Adler32\ssse3.cs"/>
<Compile Include="CRC16CCITTContext.cs"/>
<Compile Include="CRC16IBMContext.cs"/>
<Compile Include="CRC32\arm_simd.cs"/>
<Compile Include="CRC32\clmul.cs"/>
<Compile Include="CRC64\clmul.cs"/>
<Compile Include="Native.cs"/>
<Compile Include="Register.cs"/>
<Compile Include="SpamSumContext.cs"/>
<Compile Include="Adler32Context.cs"/>
<Compile Include="CDChecksums.cs"/>
<Compile Include="CRC16Context.cs"/>
<Compile Include="CRC32Context.cs"/>
<Compile Include="CRC64Context.cs"/>
<Compile Include="FletcherContext.cs"/>
<Compile Include="MD5Context.cs"/>
<Compile Include="ReedSolomon.cs"/>
<Compile Include="SHA1Context.cs"/>
<Compile Include="SHA256Context.cs"/>
<Compile Include="SHA384Context.cs"/>
<Compile Include="SHA512Context.cs"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Aaru.CommonTypes\Aaru.CommonTypes.csproj"/>
<ProjectReference Include="..\Aaru.Helpers\Aaru.Helpers.csproj"/>
<ProjectReference Include="..\Aaru.Console\Aaru.Console.csproj"/>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\LICENSE.LGPL">
<Link>LICENSE.LGPL</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\LICENSE">
<Link>LICENSE</Link>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aaru.Checksums.Native" Version="6.0.0-alpha6"/>
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.4.3" PrivateAssets="all"/>
</ItemGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CC48B324-A532-4A45-87A6-6F91F7141E8D}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Aaru.Checksums</RootNamespace>
<AssemblyName>Aaru.Checksums</AssemblyName>
<ReleaseVersion>$(Version)</ReleaseVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>6.0.0-alpha8</Version>
<Company>Claunia.com</Company>
<Copyright>Copyright © 2011-2022 Natalia Portillo</Copyright>
<Product>Aaru Data Preservation Suite</Product>
<Title>Aaru.Checksums</Title>
<ApplicationVersion>$(Version)</ApplicationVersion>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11</LangVersion>
<Description>C# implementation of CRC16, CRC32, CRC64, Fletcher, MD5, SHA1, SHA2 and SpamSum.</Description>
<PackageProjectUrl>https://github.com/aaru-dps/</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<RepositoryUrl>https://github.com/aaru-dps/Aaru.Checksums</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Authors>Natalia Portillo &lt;claunia@claunia.com&gt;</Authors>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<NoWarn>CS1591;CS1574</NoWarn>
</PropertyGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<InternalsVisibleTo Include="Aaru.Tests"/>
<InternalsVisibleTo Include="Aaru.Tests.Devices"/>
</ItemGroup>
<PropertyGroup>
<NrtRevisionFormat>$(Version)+{chash:8}</NrtRevisionFormat>
<NrtResolveSimpleAttributes>true</NrtResolveSimpleAttributes>
<NrtShowRevision>true</NrtShowRevision>
</PropertyGroup>
<ItemGroup>
<Compile Include="Adler32\neon.cs"/>
<Compile Include="Adler32\ssse3.cs"/>
<Compile Include="CRC16CCITTContext.cs"/>
<Compile Include="CRC16IBMContext.cs"/>
<Compile Include="CRC32\arm_simd.cs"/>
<Compile Include="CRC32\clmul.cs"/>
<Compile Include="CRC64\clmul.cs"/>
<Compile Include="Native.cs"/>
<Compile Include="Register.cs"/>
<Compile Include="SpamSumContext.cs"/>
<Compile Include="Adler32Context.cs"/>
<Compile Include="CDChecksums.cs"/>
<Compile Include="CRC16Context.cs"/>
<Compile Include="CRC32Context.cs"/>
<Compile Include="CRC64Context.cs"/>
<Compile Include="FletcherContext.cs"/>
<Compile Include="MD5Context.cs"/>
<Compile Include="ReedSolomon.cs"/>
<Compile Include="SHA1Context.cs"/>
<Compile Include="SHA256Context.cs"/>
<Compile Include="SHA384Context.cs"/>
<Compile Include="SHA512Context.cs"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Aaru.CommonTypes\Aaru.CommonTypes.csproj"/>
<ProjectReference Include="..\Aaru.Helpers\Aaru.Helpers.csproj"/>
<ProjectReference Include="..\Aaru.Console\Aaru.Console.csproj"/>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\LICENSE.LGPL">
<Link>LICENSE.LGPL</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\LICENSE">
<Link>LICENSE</Link>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aaru.Checksums.Native" Version="6.0.0-alpha6"/>
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.4.3" PrivateAssets="all"/>
</ItemGroup>
</Project>

View File

@@ -45,11 +45,11 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// ****************************************************************************/
namespace Aaru.Checksums.Adler32;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
namespace Aaru.Checksums.Adler32;
static class Neon
{
internal static void Step(ref ushort preSum1, ref ushort preSum2, byte[] buf, uint len)
@@ -60,7 +60,7 @@ static class Neon
uint s1 = preSum1;
uint s2 = preSum2;
var bufPos = 0;
int bufPos = 0;
/*
* Process the data in blocks.
@@ -81,8 +81,8 @@ static class Neon
* Process n blocks of data. At most NMAX data bytes can be
* processed before s2 must be reduced modulo ADLER_MODULE.
*/
var vS2 = Vector128.Create(s1 * n, 0, 0, 0);
var vS1 = Vector128.Create(0u, 0, 0, 0);
Vector128<uint> vS2 = Vector128.Create(s1 * n, 0, 0, 0);
Vector128<uint> vS1 = Vector128.Create(0u, 0, 0, 0);
Vector128<ushort> vColumnSum1 = AdvSimd.DuplicateToVector128((ushort)0);
Vector128<ushort> vColumnSum2 = AdvSimd.DuplicateToVector128((ushort)0);
Vector128<ushort> vColumnSum3 = AdvSimd.DuplicateToVector128((ushort)0);
@@ -93,17 +93,21 @@ static class Neon
/*
* Load 32 input bytes.
*/
var bytes1 = Vector128.Create(buf[bufPos], buf[bufPos + 1], buf[bufPos + 2], buf[bufPos + 3],
buf[bufPos + 4], buf[bufPos + 5], buf[bufPos + 6], buf[bufPos + 7],
buf[bufPos + 8], buf[bufPos + 9], buf[bufPos + 10], buf[bufPos + 11],
buf[bufPos + 12], buf[bufPos + 13], buf[bufPos + 14], buf[bufPos + 15]);
Vector128<byte> bytes1 = Vector128.Create(buf[bufPos], buf[bufPos + 1], buf[bufPos + 2],
buf[bufPos + 3], buf[bufPos + 4], buf[bufPos + 5],
buf[bufPos + 6], buf[bufPos + 7], buf[bufPos + 8],
buf[bufPos + 9], buf[bufPos + 10], buf[bufPos + 11],
buf[bufPos + 12], buf[bufPos + 13], buf[bufPos + 14],
buf[bufPos + 15]);
bufPos += 16;
var bytes2 = Vector128.Create(buf[bufPos], buf[bufPos + 1], buf[bufPos + 2], buf[bufPos + 3],
buf[bufPos + 4], buf[bufPos + 5], buf[bufPos + 6], buf[bufPos + 7],
buf[bufPos + 8], buf[bufPos + 9], buf[bufPos + 10], buf[bufPos + 11],
buf[bufPos + 12], buf[bufPos + 13], buf[bufPos + 14], buf[bufPos + 15]);
Vector128<byte> bytes2 = Vector128.Create(buf[bufPos], buf[bufPos + 1], buf[bufPos + 2],
buf[bufPos + 3], buf[bufPos + 4], buf[bufPos + 5],
buf[bufPos + 6], buf[bufPos + 7], buf[bufPos + 8],
buf[bufPos + 9], buf[bufPos + 10], buf[bufPos + 11],
buf[bufPos + 12], buf[bufPos + 13], buf[bufPos + 14],
buf[bufPos + 15]);
bufPos += 16;
/*

View File

@@ -45,19 +45,19 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// ****************************************************************************/
namespace Aaru.Checksums.Adler32;
using System;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
namespace Aaru.Checksums.Adler32;
static class Ssse3
{
internal static void Step(ref ushort sum1, ref ushort sum2, byte[] buf, uint len)
{
uint s1 = sum1;
uint s2 = sum2;
var bufPos = 0;
int bufPos = 0;
/*
* Process the data in blocks.
@@ -78,33 +78,33 @@ static class Ssse3
Vector128<byte> tap1 = Vector128.Create(32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17).
AsByte();
Vector128<byte> tap2 = Vector128.Create(16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1).AsByte();
Vector128<byte> zero = Vector128.Create(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0).AsByte();
var ones = Vector128.Create(1, 1, 1, 1, 1, 1, 1, 1);
Vector128<byte> tap2 = Vector128.Create(16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1).AsByte();
Vector128<byte> zero = Vector128.Create(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0).AsByte();
Vector128<short> ones = Vector128.Create(1, 1, 1, 1, 1, 1, 1, 1);
/*
* Process n blocks of data. At most NMAX data bytes can be
* processed before s2 must be reduced modulo BASE.
*/
var vPs = Vector128.Create(s1 * n, 0, 0, 0);
var vS2 = Vector128.Create(s2, 0, 0, 0);
var vS1 = Vector128.Create(0u, 0, 0, 0);
Vector128<uint> vPs = Vector128.Create(s1 * n, 0, 0, 0);
Vector128<uint> vS2 = Vector128.Create(s2, 0, 0, 0);
Vector128<uint> vS1 = Vector128.Create(0u, 0, 0, 0);
do
{
/*
* Load 32 input bytes.
*/
var bytes1 = Vector128.Create(BitConverter.ToUInt32(buf, bufPos),
BitConverter.ToUInt32(buf, bufPos + 4),
BitConverter.ToUInt32(buf, bufPos + 8),
BitConverter.ToUInt32(buf, bufPos + 12));
Vector128<uint> bytes1 = Vector128.Create(BitConverter.ToUInt32(buf, bufPos),
BitConverter.ToUInt32(buf, bufPos + 4),
BitConverter.ToUInt32(buf, bufPos + 8),
BitConverter.ToUInt32(buf, bufPos + 12));
bufPos += 16;
var bytes2 = Vector128.Create(BitConverter.ToUInt32(buf, bufPos),
BitConverter.ToUInt32(buf, bufPos + 4),
BitConverter.ToUInt32(buf, bufPos + 8),
BitConverter.ToUInt32(buf, bufPos + 12));
Vector128<uint> bytes2 = Vector128.Create(BitConverter.ToUInt32(buf, bufPos),
BitConverter.ToUInt32(buf, bufPos + 4),
BitConverter.ToUInt32(buf, bufPos + 8),
BitConverter.ToUInt32(buf, bufPos + 12));
bufPos += 16;

View File

@@ -36,8 +36,6 @@
// Copyright (C) Jean-loup Gailly
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Runtime.InteropServices;
@@ -48,6 +46,8 @@ using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
using Ssse3 = System.Runtime.Intrinsics.X86.Ssse3;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Implements the Adler-32 algorithm</summary>
public sealed class Adler32Context : IChecksum

View File

@@ -31,13 +31,13 @@
// ECC algorithm from ECM(c) 2002-2011 Neill Corlett
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.Collections.Generic;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Checksums;
/// <summary>Implements ReedSolomon and CRC32 algorithms as used by CD-ROM</summary>
public static class CdChecksums
{
@@ -81,8 +81,8 @@ public static class CdChecksums
{
case 2448:
{
var subchannel = new byte[96];
var channel = new byte[2352];
byte[] subchannel = new byte[96];
byte[] channel = new byte[2352];
Array.Copy(buffer, 0, channel, 0, 2352);
Array.Copy(buffer, 2352, subchannel, 0, 96);
@@ -97,11 +97,11 @@ public static class CdChecksums
status = false;
status = channelStatus switch
{
null when subchannelStatus == true => true,
true when subchannelStatus == null => true,
_ => status
};
{
null when subchannelStatus == true => true,
true when subchannelStatus == null => true,
_ => status
};
return status;
}
@@ -120,7 +120,7 @@ public static class CdChecksums
for(uint i = 0; i < 256; i++)
{
uint edc = i;
var j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
uint j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
_eccFTable[i] = (byte)j;
_eccBTable[i ^ j] = (byte)i;
@@ -139,7 +139,7 @@ public static class CdChecksums
for(major = 0; major < majorCount; major++)
{
uint index = (major >> 1) * majorMult + (major & 1);
uint index = ((major >> 1) * majorMult) + (major & 1);
byte eccA = 0;
byte eccB = 0;
uint minor;
@@ -200,7 +200,7 @@ public static class CdChecksums
{
//AaruConsole.DebugWriteLine("CD checksums", "Mode 0 sector at address {0:X2}:{1:X2}:{2:X2}",
// channel[0x00C], channel[0x00D], channel[0x00E]);
for(var i = 0x010; i < 0x930; i++)
for(int i = 0x010; i < 0x930; i++)
if(channel[i] != 0x00)
{
AaruConsole.DebugWriteLine("CD checksums",
@@ -227,11 +227,11 @@ public static class CdChecksums
return false;
case 0x01:
{
var address = new byte[4];
var data = new byte[2060];
var data2 = new byte[2232];
var eccP = new byte[172];
var eccQ = new byte[104];
byte[] address = new byte[4];
byte[] data = new byte[2060];
byte[] data2 = new byte[2232];
byte[] eccP = new byte[172];
byte[] eccQ = new byte[104];
Array.Copy(channel, 0x0C, address, 0, 4);
Array.Copy(channel, 0x10, data, 0, 2060);
@@ -255,7 +255,7 @@ public static class CdChecksums
"Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check",
channel[0x00C], channel[0x00D], channel[0x00E]);
var storedEdc = BitConverter.ToUInt32(channel, 0x810);
uint storedEdc = BitConverter.ToUInt32(channel, 0x810);
uint calculatedEdc = ComputeEdc(0, channel, 0x810);
correctEdc = calculatedEdc == storedEdc;
@@ -275,7 +275,7 @@ public static class CdChecksums
{
//AaruConsole.DebugWriteLine("CD checksums", "Mode 2 sector at address {0:X2}:{1:X2}:{2:X2}",
// channel[0x00C], channel[0x00D], channel[0x00E]);
var mode2Sector = new byte[channel.Length - 0x10];
byte[] mode2Sector = new byte[channel.Length - 0x10];
Array.Copy(channel, 0x10, mode2Sector, 0, mode2Sector.Length);
if((channel[0x012] & 0x20) == 0x20) // mode 2 form 2
@@ -288,7 +288,7 @@ public static class CdChecksums
"Subheader copies differ in mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}",
channel[0x00C], channel[0x00D], channel[0x00E]);
var storedEdc = BitConverter.ToUInt32(mode2Sector, 0x91C);
uint storedEdc = BitConverter.ToUInt32(mode2Sector, 0x91C);
// No CRC stored!
if(storedEdc == 0x00000000)
@@ -318,9 +318,9 @@ public static class CdChecksums
"Subheader copies differ in mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}",
channel[0x00C], channel[0x00D], channel[0x00E]);
var address = new byte[4];
var eccP = new byte[172];
var eccQ = new byte[104];
byte[] address = new byte[4];
byte[] eccP = new byte[172];
byte[] eccQ = new byte[104];
Array.Copy(mode2Sector, 0x80C, eccP, 0, 172);
Array.Copy(mode2Sector, 0x8B8, eccQ, 0, 104);
@@ -341,7 +341,7 @@ public static class CdChecksums
"Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check",
channel[0x00C], channel[0x00D], channel[0x00E]);
var storedEdc = BitConverter.ToUInt32(mode2Sector, 0x808);
uint storedEdc = BitConverter.ToUInt32(mode2Sector, 0x808);
uint calculatedEdc = ComputeEdc(0, mode2Sector, 0x808);
correctEdc = calculatedEdc == storedEdc;
@@ -367,7 +367,7 @@ public static class CdChecksums
static uint ComputeEdc(uint edc, IReadOnlyList<byte> src, int size)
{
var pos = 0;
int pos = 0;
for(; size > 0; size--)
edc = (edc >> 8) ^ _edcTable[(edc ^ src[pos++]) & 0xFF];
@@ -377,23 +377,23 @@ public static class CdChecksums
static bool? CheckCdSectorSubChannel(IReadOnlyList<byte> subchannel)
{
bool? status = true;
var qSubChannel = new byte[12];
var cdTextPack1 = new byte[18];
var cdTextPack2 = new byte[18];
var cdTextPack3 = new byte[18];
var cdTextPack4 = new byte[18];
var cdSubRwPack1 = new byte[24];
var cdSubRwPack2 = new byte[24];
var cdSubRwPack3 = new byte[24];
var cdSubRwPack4 = new byte[24];
bool? status = true;
byte[] qSubChannel = new byte[12];
byte[] cdTextPack1 = new byte[18];
byte[] cdTextPack2 = new byte[18];
byte[] cdTextPack3 = new byte[18];
byte[] cdTextPack4 = new byte[18];
byte[] cdSubRwPack1 = new byte[24];
byte[] cdSubRwPack2 = new byte[24];
byte[] cdSubRwPack3 = new byte[24];
byte[] cdSubRwPack4 = new byte[24];
var i = 0;
int i = 0;
for(var j = 0; j < 12; j++)
for(int j = 0; j < 12; j++)
qSubChannel[j] = 0;
for(var j = 0; j < 18; j++)
for(int j = 0; j < 18; j++)
{
cdTextPack1[j] = 0;
cdTextPack2[j] = 0;
@@ -401,7 +401,7 @@ public static class CdChecksums
cdTextPack4[j] = 0;
}
for(var j = 0; j < 24; j++)
for(int j = 0; j < 24; j++)
{
cdSubRwPack1[j] = 0;
cdSubRwPack2[j] = 0;
@@ -409,7 +409,7 @@ public static class CdChecksums
cdSubRwPack4[j] = 0;
}
for(var j = 0; j < 12; j++)
for(int j = 0; j < 12; j++)
{
qSubChannel[j] = (byte)(qSubChannel[j] | ((subchannel[i++] & 0x40) << 1));
qSubChannel[j] = (byte)(qSubChannel[j] | (subchannel[i++] & 0x40));
@@ -423,7 +423,7 @@ public static class CdChecksums
i = 0;
for(var j = 0; j < 18; j++)
for(int j = 0; j < 18; j++)
{
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -440,7 +440,7 @@ public static class CdChecksums
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F));
}
for(var j = 0; j < 18; j++)
for(int j = 0; j < 18; j++)
{
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -457,7 +457,7 @@ public static class CdChecksums
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F));
}
for(var j = 0; j < 18; j++)
for(int j = 0; j < 18; j++)
{
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -474,7 +474,7 @@ public static class CdChecksums
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F));
}
for(var j = 0; j < 18; j++)
for(int j = 0; j < 18; j++)
{
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -493,16 +493,16 @@ public static class CdChecksums
i = 0;
for(var j = 0; j < 24; j++)
for(int j = 0; j < 24; j++)
cdSubRwPack1[j] = (byte)(subchannel[i++] & 0x3F);
for(var j = 0; j < 24; j++)
for(int j = 0; j < 24; j++)
cdSubRwPack2[j] = (byte)(subchannel[i++] & 0x3F);
for(var j = 0; j < 24; j++)
for(int j = 0; j < 24; j++)
cdSubRwPack3[j] = (byte)(subchannel[i++] & 0x3F);
for(var j = 0; j < 24; j++)
for(int j = 0; j < 24; j++)
cdSubRwPack4[j] = (byte)(subchannel[i++] & 0x3F);
switch(cdSubRwPack1[0])
@@ -544,8 +544,8 @@ public static class CdChecksums
break;
}
var qSubChannelCrc = BigEndianBitConverter.ToUInt16(qSubChannel, 10);
var qSubChannelForCrc = new byte[10];
ushort qSubChannelCrc = BigEndianBitConverter.ToUInt16(qSubChannel, 10);
byte[] qSubChannelForCrc = new byte[10];
Array.Copy(qSubChannel, 0, qSubChannelForCrc, 0, 10);
ushort calculatedQcrc = CRC16CCITTContext.Calculate(qSubChannelForCrc);
@@ -559,8 +559,8 @@ public static class CdChecksums
if((cdTextPack1[0] & 0x80) == 0x80)
{
var cdTextPack1Crc = BigEndianBitConverter.ToUInt16(cdTextPack1, 16);
var cdTextPack1ForCrc = new byte[16];
ushort cdTextPack1Crc = BigEndianBitConverter.ToUInt16(cdTextPack1, 16);
byte[] cdTextPack1ForCrc = new byte[16];
Array.Copy(cdTextPack1, 0, cdTextPack1ForCrc, 0, 16);
ushort calculatedCdtp1Crc = CRC16CCITTContext.Calculate(cdTextPack1ForCrc);
@@ -576,8 +576,8 @@ public static class CdChecksums
if((cdTextPack2[0] & 0x80) == 0x80)
{
var cdTextPack2Crc = BigEndianBitConverter.ToUInt16(cdTextPack2, 16);
var cdTextPack2ForCrc = new byte[16];
ushort cdTextPack2Crc = BigEndianBitConverter.ToUInt16(cdTextPack2, 16);
byte[] cdTextPack2ForCrc = new byte[16];
Array.Copy(cdTextPack2, 0, cdTextPack2ForCrc, 0, 16);
ushort calculatedCdtp2Crc = CRC16CCITTContext.Calculate(cdTextPack2ForCrc);
@@ -596,8 +596,8 @@ public static class CdChecksums
if((cdTextPack3[0] & 0x80) == 0x80)
{
var cdTextPack3Crc = BigEndianBitConverter.ToUInt16(cdTextPack3, 16);
var cdTextPack3ForCrc = new byte[16];
ushort cdTextPack3Crc = BigEndianBitConverter.ToUInt16(cdTextPack3, 16);
byte[] cdTextPack3ForCrc = new byte[16];
Array.Copy(cdTextPack3, 0, cdTextPack3ForCrc, 0, 16);
ushort calculatedCdtp3Crc = CRC16CCITTContext.Calculate(cdTextPack3ForCrc);
@@ -617,8 +617,8 @@ public static class CdChecksums
if((cdTextPack4[0] & 0x80) != 0x80)
return status;
var cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
var cdTextPack4ForCrc = new byte[16];
ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
byte[] cdTextPack4ForCrc = new byte[16];
Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16);
ushort calculatedCdtp4Crc = CRC16CCITTContext.Calculate(cdTextPack4ForCrc);

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Runtime.InteropServices;
@@ -39,6 +37,8 @@ using System.Text;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Implements a CRC16 algorithm</summary>
public class Crc16Context : IChecksum

View File

@@ -45,18 +45,18 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// ****************************************************************************/
namespace Aaru.Checksums.CRC32;
using System;
using System.Runtime.Intrinsics.Arm;
namespace Aaru.Checksums.CRC32;
static class ArmSimd
{
internal static uint Step64(byte[] buf, long len, uint crc)
{
uint c = crc;
var bufPos = 0;
int bufPos = 0;
while(len >= 64)
{
@@ -96,7 +96,7 @@ static class ArmSimd
{
uint c = crc;
var bufPos = 0;
int bufPos = 0;
while(len >= 32)
{

View File

@@ -47,13 +47,13 @@
// Copyright (C) 2013 Intel Corporation. All rights reserved.
// ****************************************************************************/
namespace Aaru.Checksums.CRC32;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
namespace Aaru.Checksums.CRC32;
static class Clmul
{
static readonly uint[] _crcK =
@@ -66,7 +66,7 @@ static class Clmul
static void Fold4(ref Vector128<uint> xmmCRC0, ref Vector128<uint> xmmCRC1, ref Vector128<uint> xmmCRC2,
ref Vector128<uint> xmmCRC3)
{
var xmmFold4 = Vector128.Create(0xc6e41596, 0x00000001, 0x54442bd4, 0x00000001);
Vector128<uint> xmmFold4 = Vector128.Create(0xc6e41596, 0x00000001, 0x54442bd4, 0x00000001);
Vector128<uint> xTmp0 = xmmCRC0;
Vector128<uint> xTmp1 = xmmCRC1;
@@ -110,37 +110,41 @@ static class Clmul
Vector128<uint> xmmCRC1 = Vector128<uint>.Zero;
Vector128<uint> xmmCRC2 = Vector128<uint>.Zero;
Vector128<uint> xmmCRC3 = Vector128<uint>.Zero;
var bufPos = 0;
int bufPos = 0;
var first = true;
bool first = true;
/* fold 512 to 32 step variable declarations for ISO-C90 compat. */
var xmmMask = Vector128.Create(0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000);
var xmmMask2 = Vector128.Create(0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
Vector128<uint> xmmMask = Vector128.Create(0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000);
Vector128<uint> xmmMask2 = Vector128.Create(0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
while((len -= 64) >= 0)
{
var xmmT0 = Vector128.Create(BitConverter.ToUInt32(src, bufPos), BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
Vector128<uint> xmmT0 = Vector128.Create(BitConverter.ToUInt32(src, bufPos),
BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
bufPos += 16;
var xmmT1 = Vector128.Create(BitConverter.ToUInt32(src, bufPos), BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
Vector128<uint> xmmT1 = Vector128.Create(BitConverter.ToUInt32(src, bufPos),
BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
bufPos += 16;
var xmmT2 = Vector128.Create(BitConverter.ToUInt32(src, bufPos), BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
Vector128<uint> xmmT2 = Vector128.Create(BitConverter.ToUInt32(src, bufPos),
BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
bufPos += 16;
var xmmT3 = Vector128.Create(BitConverter.ToUInt32(src, bufPos), BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
Vector128<uint> xmmT3 = Vector128.Create(BitConverter.ToUInt32(src, bufPos),
BitConverter.ToUInt32(src, bufPos + 4),
BitConverter.ToUInt32(src, bufPos + 8),
BitConverter.ToUInt32(src, bufPos + 12));
bufPos += 16;
@@ -163,7 +167,7 @@ static class Clmul
/*
* k1
*/
var crcFold = Vector128.Create(_crcK[0], _crcK[1], _crcK[2], _crcK[3]);
Vector128<uint> crcFold = Vector128.Create(_crcK[0], _crcK[1], _crcK[2], _crcK[3]);
Vector128<uint> xTmp0 = Pclmulqdq.CarrylessMultiply(xmmCRC0.AsUInt64(), crcFold.AsUInt64(), 0x10).AsUInt32();

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Runtime.InteropServices;
@@ -42,6 +40,8 @@ using Aaru.Checksums.CRC32;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Implements a CRC32 algorithm</summary>
public sealed class Crc32Context : IChecksum

View File

@@ -21,13 +21,13 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums.CRC64;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
namespace Aaru.Checksums.CRC64;
static class Clmul
{
static readonly byte[] _shuffleMasks =
@@ -42,13 +42,14 @@ static class Clmul
{
uint maskPos = 16 - n;
var maskA = Vector128.Create(_shuffleMasks[maskPos], _shuffleMasks[maskPos + 1], _shuffleMasks[maskPos + 2],
_shuffleMasks[maskPos + 3], _shuffleMasks[maskPos + 4], _shuffleMasks[maskPos + 5],
_shuffleMasks[maskPos + 6], _shuffleMasks[maskPos + 7], _shuffleMasks[maskPos + 8],
_shuffleMasks[maskPos + 9], _shuffleMasks[maskPos + 10],
_shuffleMasks[maskPos + 11], _shuffleMasks[maskPos + 12],
_shuffleMasks[maskPos + 13], _shuffleMasks[maskPos + 14],
_shuffleMasks[maskPos + 15]);
Vector128<byte> maskA = Vector128.Create(_shuffleMasks[maskPos], _shuffleMasks[maskPos + 1],
_shuffleMasks[maskPos + 2], _shuffleMasks[maskPos + 3],
_shuffleMasks[maskPos + 4], _shuffleMasks[maskPos + 5],
_shuffleMasks[maskPos + 6], _shuffleMasks[maskPos + 7],
_shuffleMasks[maskPos + 8], _shuffleMasks[maskPos + 9],
_shuffleMasks[maskPos + 10], _shuffleMasks[maskPos + 11],
_shuffleMasks[maskPos + 12], _shuffleMasks[maskPos + 13],
_shuffleMasks[maskPos + 14], _shuffleMasks[maskPos + 15]);
Vector128<byte> maskB = Sse2.Xor(maskA, Sse2.CompareEqual(Vector128<byte>.Zero, Vector128<byte>.Zero));
@@ -63,14 +64,14 @@ static class Clmul
internal static ulong Step(ulong crc, byte[] data, uint length)
{
var bufPos = 16;
const ulong k1 = 0xe05dd497ca393ae4;
const ulong k2 = 0xdabe95afc7875f40;
const ulong mu = 0x9c3e466c172963d5;
const ulong pol = 0x92d8af2baf0e1e85;
var foldConstants1 = Vector128.Create(k1, k2);
var foldConstants2 = Vector128.Create(mu, pol);
var initialCrc = Vector128.Create(~crc, 0);
int bufPos = 16;
const ulong k1 = 0xe05dd497ca393ae4;
const ulong k2 = 0xdabe95afc7875f40;
const ulong mu = 0x9c3e466c172963d5;
const ulong pol = 0x92d8af2baf0e1e85;
Vector128<ulong> foldConstants1 = Vector128.Create(k1, k2);
Vector128<ulong> foldConstants2 = Vector128.Create(mu, pol);
Vector128<ulong> initialCrc = Vector128.Create(~crc, 0);
length -= 16;
// Initial CRC can simply be added to data

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Runtime.InteropServices;
@@ -41,6 +39,8 @@ using Aaru.Checksums.CRC64;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Implements a CRC64 algorithm</summary>
public sealed class Crc64Context : IChecksum

View File

@@ -32,8 +32,6 @@
// Disabled because the speed is abnormally slow
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Runtime.InteropServices;
@@ -41,6 +39,8 @@ using System.Text;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Implements the Fletcher-32 algorithm</summary>
public sealed class Fletcher32Context : IChecksum

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Wraps up .NET MD5 implementation to a Init(), Update(), Final() context.</summary>
public sealed class Md5Context : IChecksum

View File

@@ -30,10 +30,10 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System.Runtime.InteropServices;
namespace Aaru.Checksums;
/// <summary>Handles native implementations of compression algorithms</summary>
public static class Native
{

View File

@@ -57,11 +57,11 @@
*
*/
namespace Aaru.Checksums;
using System;
using Aaru.Console;
namespace Aaru.Checksums;
/// <summary>Implements the Reed-Solomon algorithm</summary>
public class ReedSolomon
{
@@ -87,69 +87,69 @@ public class ReedSolomon
public void InitRs(int n, int k, int m)
{
_pp = m switch
{
2 => new[]
{
1, 1, 1
},
3 => new[]
{
1, 1, 0, 1
},
4 => new[]
{
1, 1, 0, 0, 1
},
5 => new[]
{
1, 0, 1, 0, 0, 1
},
6 => new[]
{
1, 1, 0, 0, 0, 0, 1
},
7 => new[]
{
1, 0, 0, 1, 0, 0, 0, 1
},
8 => new[]
{
1, 0, 1, 1, 1, 0, 0, 0, 1
},
9 => new[]
{
1, 0, 0, 0, 1, 0, 0, 0, 0, 1
},
10 => new[]
{
1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1
},
11 => new[]
{
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
12 => new[]
{
1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1
},
13 => new[]
{
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
14 => new[]
{
1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
},
15 => new[]
{
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
16 => new[]
{
1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
},
_ => throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive")
};
{
2 => new[]
{
1, 1, 1
},
3 => new[]
{
1, 1, 0, 1
},
4 => new[]
{
1, 1, 0, 0, 1
},
5 => new[]
{
1, 0, 1, 0, 0, 1
},
6 => new[]
{
1, 1, 0, 0, 0, 0, 1
},
7 => new[]
{
1, 0, 0, 1, 0, 0, 0, 1
},
8 => new[]
{
1, 0, 1, 1, 1, 0, 0, 0, 1
},
9 => new[]
{
1, 0, 0, 0, 1, 0, 0, 0, 0, 1
},
10 => new[]
{
1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1
},
11 => new[]
{
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
12 => new[]
{
1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1
},
13 => new[]
{
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
14 => new[]
{
1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
},
15 => new[]
{
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
16 => new[]
{
1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
},
_ => throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive")
};
_mm = m;
_kk = k;
@@ -237,7 +237,7 @@ public class ReedSolomon
{
int i;
var mask = 1;
int mask = 1;
_alphaTo[_mm] = 0;
for(i = 0; i < _mm; i++)
@@ -396,18 +396,18 @@ public class ReedSolomon
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
erasPos = new int[_nn - _kk];
int i, j;
int q, tmp;
var recd = new int[_nn];
var lambda = new int[_nn - _kk + 1]; /* Err+Eras Locator poly */
var s = new int[_nn - _kk + 1]; /* syndrome poly */
var b = new int[_nn - _kk + 1];
var t = new int[_nn - _kk + 1];
var omega = new int[_nn - _kk + 1];
var root = new int[_nn - _kk];
var reg = new int[_nn - _kk + 1];
var loc = new int[_nn - _kk];
int count;
int i, j;
int q, tmp;
int[] recd = new int[_nn];
int[] lambda = new int[_nn - _kk + 1]; /* Err+Eras Locator poly */
int[] s = new int[_nn - _kk + 1]; /* syndrome poly */
int[] b = new int[_nn - _kk + 1];
int[] t = new int[_nn - _kk + 1];
int[] omega = new int[_nn - _kk + 1];
int[] root = new int[_nn - _kk];
int[] reg = new int[_nn - _kk + 1];
int[] loc = new int[_nn - _kk];
int count;
/* data[] is in polynomial form, copy and convert to index form */
for(i = _nn - 1; i >= 0; i--)
@@ -422,7 +422,7 @@ public class ReedSolomon
/* first form the syndromes; i.e., evaluate recd(x) at roots of g(x)
* namely @**(B0+i), i = 0, ... ,(NN-KK-1)
*/
var synError = 0;
int synError = 0;
for(i = 1; i <= _nn - _kk; i++)
{
@@ -430,7 +430,7 @@ public class ReedSolomon
for(j = 0; j < _nn; j++)
if(recd[j] != _a0) /* recd[j] in index form */
tmp ^= _alphaTo[Modnn(recd[j] + (B0 + i - 1) * j)];
tmp ^= _alphaTo[Modnn(recd[j] + ((B0 + i - 1) * j))];
synError |= tmp; /* set flag if non-zero syndrome =>
* error */
@@ -523,7 +523,7 @@ public class ReedSolomon
{
/* r is the step number */
/* Compute discrepancy at the r-th step in poly-form */
var discrR = 0;
int discrR = 0;
for(i = 0; i < r; i++)
if(lambda[i] != 0 &&
@@ -572,7 +572,7 @@ public class ReedSolomon
}
/* Convert lambda to index form and compute deg(lambda(x)) */
var degLambda = 0;
int degLambda = 0;
for(i = 0; i < _nn - _kk + 1; i++)
{
@@ -627,7 +627,7 @@ public class ReedSolomon
* Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo
* x**(NN-KK)). in index form. Also find deg(omega).
*/
var degOmega = 0;
int degOmega = 0;
for(i = 0; i < _nn - _kk; i++)
{
@@ -653,19 +653,19 @@ public class ReedSolomon
*/
for(j = count - 1; j >= 0; j--)
{
var num1 = 0;
int num1 = 0;
for(i = degOmega; i >= 0; i--)
if(omega[i] != _a0)
num1 ^= _alphaTo[Modnn(omega[i] + i * root[j])];
num1 ^= _alphaTo[Modnn(omega[i] + (i * root[j]))];
int num2 = _alphaTo[Modnn(root[j] * (B0 - 1) + _nn)];
var den = 0;
int num2 = _alphaTo[Modnn((root[j] * (B0 - 1)) + _nn)];
int den = 0;
/* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
for(i = Min(degLambda, _nn - _kk - 1) & ~1; i >= 0; i -= 2)
if(lambda[i + 1] != _a0)
den ^= _alphaTo[Modnn(lambda[i + 1] + i * root[j])];
den ^= _alphaTo[Modnn(lambda[i + 1] + (i * root[j]))];
if(den == 0)
{

View File

@@ -36,14 +36,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
public sealed class Register : IPluginRegister
{

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Wraps up .NET SHA1 implementation to a Init(), Update(), Final() context.</summary>
public sealed class Sha1Context : IChecksum

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Wraps up .NET SHA256 implementation to a Init(), Update(), Final() context.</summary>
public sealed class Sha256Context : IChecksum

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Wraps up .NET SHA384 implementation to a Init(), Update(), Final() context.</summary>
public sealed class Sha384Context : IChecksum

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Checksums;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Wraps up .NET SHA512 implementation to a Init(), Update(), Final() context.</summary>
public sealed class Sha512Context : IChecksum

View File

@@ -39,13 +39,13 @@
// http://www.samba.org/ftp/unpacked/junkcode/spamsum/
// http://ssdeep.sf.net/
namespace Aaru.Checksums;
using System;
using System.Runtime.CompilerServices;
using System.Text;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Checksums;
/// <inheritdoc />
/// <summary>Implements the SpamSum fuzzy hashing algorithm.</summary>
public sealed class SpamSumContext : IChecksum
@@ -56,7 +56,7 @@ public sealed class SpamSumContext : IChecksum
const uint HASH_INIT = 0x28021967;
const uint NUM_BLOCKHASHES = 31;
const uint SPAMSUM_LENGTH = 64;
const uint FUZZY_MAX_RESULT = 2 * SPAMSUM_LENGTH + 20;
const uint FUZZY_MAX_RESULT = (2 * SPAMSUM_LENGTH) + 20;
//"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
readonly byte[] _b64 =
@@ -77,7 +77,7 @@ public sealed class SpamSumContext : IChecksum
Bh = new BlockhashContext[NUM_BLOCKHASHES]
};
for(var i = 0; i < NUM_BLOCKHASHES; i++)
for(int i = 0; i < NUM_BLOCKHASHES; i++)
_self.Bh[i].Digest = new byte[SPAMSUM_LENGTH];
_self.Bhstart = 0;
@@ -99,7 +99,7 @@ public sealed class SpamSumContext : IChecksum
{
_self.TotalSize += len;
for(var i = 0; i < len; i++)
for(int i = 0; i < len; i++)
fuzzy_engine_step(data[i]);
}
@@ -274,7 +274,7 @@ public sealed class SpamSumContext : IChecksum
var sb = new StringBuilder();
uint bi = _self.Bhstart;
uint h = roll_sum();
var remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */
int remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */
result = new byte[FUZZY_MAX_RESULT];
/* Verify that our elimination was not overeager. */
@@ -471,7 +471,7 @@ public sealed class SpamSumContext : IChecksum
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string CToString(byte[] cString)
{
var count = 0;
int count = 0;
// ReSharper disable once LoopCanBeConvertedToQuery
// LINQ is six times slower