program HashingBug;
uses
SysUtils,
DCPmd5,
DCPsha1,
DCPsha256;
var
bytes: TBytes;
OutputMD5: array[0..15] of byte;
OutputSHA1: array[0..19] of byte;
OutputSHA256: array[0..31] of byte;
HashMD5: TDCP_MD5;
HashSHA1: TDCP_SHA1;
HashSHA256: TDCP_SHA256;
Result: string;
Idx: Int32;
begin
System.SetLength(bytes, 1024 * 1024 * 1024); // 1 GB Byte Array filled with Zeros
FillChar(OutputMD5, SizeOf(OutputMD5), 0);
FillChar(OutputSHA1, SizeOf(OutputSHA1), 0);
FillChar(OutputSHA256, SizeOf(OutputSHA256), 0);
WriteLn('Performing Hash Operation');
HashMD5 := TDCP_MD5.Create(nil);
HashMD5.Init;
HashMD5.Update(bytes[0], System.Length(bytes));
HashMD5.Final(OutputMD5);
Result := '';
for Idx := Low(OutputMD5) to High(OutputMD5) do
Result := Result + IntToHex(OutputMD5[Idx], 2);
WriteLn(Format('Expected "%s" As MD5 Hash of Zero Filled 1GB Dummy Byte Array But Got "%s"',
['CD573CFAACE07E7949BC0C46028904FF', Result]));
HashSHA1 := TDCP_SHA1.Create(nil);
HashSHA1.Init;
HashSHA1.Update(bytes[0], System.Length(bytes));
HashSHA1.Final(OutputSHA1);
Result := '';
for Idx := Low(OutputSHA1) to High(OutputSHA1) do
Result := Result + IntToHex(OutputSHA1[Idx], 2);
WriteLn(Format('Expected "%s" As SHA1 Hash of Zero Filled 1GB Dummy Byte Array But Got "%s"',
['2A492F15396A6768BCBCA016993F4B4C8B0B5307', Result]));
HashSHA256 := TDCP_SHA256.Create(nil);
HashSHA256.Init;
HashSHA256.Update(bytes[0], System.Length(bytes));
HashSHA256.Final(OutputSHA256);
Result := '';
for Idx := Low(OutputSHA256) to High(OutputSHA256) do
Result := Result + IntToHex(OutputSHA256[Idx], 2);
WriteLn(Format(
'Expected "%s" As SHA256 Hash of Zero Filled 1GB Dummy Byte Array But Got "%s"',
['49BC20DF15E412A64472421E13FE86FF1C5165E18B2AFCCF160D4DC19FE68A14', Result]));
WriteLn('Finish');
ReadLn();
end.