Use ST.Hashing for MD5
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<Version>0.6.1</Version>
|
<Version>0.7.0</Version>
|
||||||
|
|
||||||
<!-- Package Properties -->
|
<!-- Package Properties -->
|
||||||
<Authors>Deterous</Authors>
|
<Authors>Deterous</Authors>
|
||||||
|
|||||||
+14
-13
@@ -1046,20 +1046,20 @@ namespace LibIRD
|
|||||||
|
|
||||||
// Initialise MD5 region hashes
|
// Initialise MD5 region hashes
|
||||||
List<int> regions = [];
|
List<int> regions = [];
|
||||||
MD5[] regionMD5 = new MD5[RegionCount];
|
HashWrapper[] regionMD5 = new HashWrapper[RegionCount];
|
||||||
for (int i = 0; i < RegionCount; i++)
|
for (int i = 0; i < RegionCount; i++)
|
||||||
{
|
{
|
||||||
regions.Add(i);
|
regions.Add(i);
|
||||||
regionMD5[i] = MD5.Create();
|
regionMD5[i] = new(HashType.MD5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise MD5 file hashes
|
// Initialise MD5 file hashes
|
||||||
List<int> files = [];
|
List<int> files = [];
|
||||||
MD5[] fileMD5 = new MD5[FileCount];
|
HashWrapper[] fileMD5 = new HashWrapper[FileCount];
|
||||||
for (int i = 0; i < FileCount; i++)
|
for (int i = 0; i < FileCount; i++)
|
||||||
{
|
{
|
||||||
files.Add(i);
|
files.Add(i);
|
||||||
fileMD5[i] = MD5.Create();
|
fileMD5[i] = new(HashType.MD5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start hashing from beginning of ISO
|
// Start hashing from beginning of ISO
|
||||||
@@ -1135,23 +1135,24 @@ namespace LibIRD
|
|||||||
// Determine end byte
|
// Determine end byte
|
||||||
int endByte = (int)(SectorSize * (RegionEnd[i] - currentSector + 1));
|
int endByte = (int)(SectorSize * (RegionEnd[i] - currentSector + 1));
|
||||||
// Close region hash
|
// Close region hash
|
||||||
regionMD5[i].TransformFinalBlock(buf, startByte, endByte - startByte);
|
regionMD5[i].Process(buf, startByte, endByte - startByte);
|
||||||
RegionHashes[i] = regionMD5[i].Hash;
|
regionMD5[i].Terminate();
|
||||||
regionMD5[i].Clear();
|
RegionHashes[i] = regionMD5[i].CurrentHashBytes;
|
||||||
|
regionMD5[i].Dispose();
|
||||||
regionsEnded.Add(i);
|
regionsEnded.Add(i);
|
||||||
}
|
}
|
||||||
// Check if region has already begun
|
// Check if region has already begun
|
||||||
else if (RegionStart[i] <= currentSector)
|
else if (RegionStart[i] <= currentSector)
|
||||||
{
|
{
|
||||||
// Hash buffer
|
// Hash buffer
|
||||||
regionMD5[i].TransformBlock(buf, 0, (int)SectorSize * bufSectors, null, 0);
|
regionMD5[i].Process(buf, 0, (int)SectorSize * bufSectors);
|
||||||
}
|
}
|
||||||
// Region Start is in this buffer, ending is in the future
|
// Region Start is in this buffer, ending is in the future
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Hash partial buffer
|
// Hash partial buffer
|
||||||
int regionStart = (int)(SectorSize * (RegionStart[i] - currentSector));
|
int regionStart = (int)(SectorSize * (RegionStart[i] - currentSector));
|
||||||
regionMD5[i].TransformBlock(buf, regionStart, (int)SectorSize * bufSectors - regionStart, null, 0);
|
regionMD5[i].Process(buf, regionStart, (int)SectorSize * bufSectors - regionStart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (regionsEnded.Count > 0)
|
if (regionsEnded.Count > 0)
|
||||||
@@ -1205,7 +1206,7 @@ namespace LibIRD
|
|||||||
// Don't hash more than the buffer size
|
// Don't hash more than the buffer size
|
||||||
endByte = endByte < bufSectors * (int)SectorSize ? endByte : bufSectors * (int)SectorSize;
|
endByte = endByte < bufSectors * (int)SectorSize ? endByte : bufSectors * (int)SectorSize;
|
||||||
// Hash portion of buffer that file exists in
|
// Hash portion of buffer that file exists in
|
||||||
fileMD5[i].TransformBlock(buf, startByte, endByte - startByte, null, 0);
|
fileMD5[i].Process(buf, startByte, endByte - startByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if current file has ended in this buffer (assumes last extent contains last byte)
|
// Check if current file has ended in this buffer (assumes last extent contains last byte)
|
||||||
@@ -1214,9 +1215,9 @@ namespace LibIRD
|
|||||||
&& lastByte > SectorSize * currentSector)
|
&& lastByte > SectorSize * currentSector)
|
||||||
{
|
{
|
||||||
// Close file hash
|
// Close file hash
|
||||||
fileMD5[i].TransformFinalBlock(buf, 0, 0);
|
fileMD5[i].Terminate();
|
||||||
FileHashes[i] = fileMD5[i].Hash;
|
FileHashes[i] = fileMD5[i].CurrentHashBytes;
|
||||||
fileMD5[i].Clear();
|
fileMD5[i].Dispose();
|
||||||
filesEnded.Add(i);
|
filesEnded.Add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<Version>0.6.1</Version>
|
<Version>0.7.0</Version>
|
||||||
<PackageOutputPath>../nupkg</PackageOutputPath>
|
<PackageOutputPath>../nupkg</PackageOutputPath>
|
||||||
|
|
||||||
<!-- Package Properties -->
|
<!-- Package Properties -->
|
||||||
|
|||||||
Reference in New Issue
Block a user