Skip to content

Commit 7ac8a72

Browse files
author
Markus Humm
committed
Changed parameter name for more clarity
1 parent 10aa9c5 commit 7ac8a72

File tree

1 file changed

+59
-35
lines changed

1 file changed

+59
-35
lines changed

Unit Tests/Tests/TestDECHashSHA3.pas

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ TestTHash_SHA3_Base = class(THash_TestBaseExtended)
147147
/// <returns>
148148
/// The input vector with added padding
149149
/// </returns>
150+
{ TODO : Namen überlegen zu ändern, im Kommentar Keccak drin lassen }
150151
function AddLastByteForKeccakTest(SHA3InputVector : RawByteString;
151152
var LastByteLength : UInt8): RawByteString; virtual;
152153

@@ -318,15 +319,15 @@ TestTHash_Keccak_Base = class(TestTHash_SHA3_Base)
318319
/// The SHA3 input vector in bytes (not hex encoded!) which shall get
319320
/// the padding appended.
320321
/// </param>
321-
/// <param name="LastByteLength">
322+
/// <param name="NumBitsOfLastByteUsed">
322323
/// Number of bits used in the last byte. In the keccak override this will
323324
/// be adjusted inside so it's a var param.
324325
/// </param>
325326
/// <returns>
326327
/// The input vector with added padding
327328
/// </returns>
328-
function AddLastByteForKeccakTest(SHA3InputVector : RawByteString;
329-
var LastByteLength : UInt8): RawByteString; override;
329+
function AddLastByteForKeccakTest(SHA3InputVector : RawByteString;
330+
var NumBitsOfLastByteUsed : UInt8): RawByteString; override;
330331
end;
331332

332333
// Test methods for class THash_Keccak_224
@@ -1767,28 +1768,28 @@ procedure TestTHash_SHA3_Base.AddLastByteForCodeTest(var lDataRow : IHashTest
17671768
CalcUnicodeHash(string(TFormat_HexL.Encode(MsgWithFixup)), FHash);
17681769
end;
17691770

1770-
function TestTHash_Keccak_Base.AddLastByteForKeccakTest(SHA3InputVector : RawByteString;
1771-
var LastByteLength : UInt8): RawByteString;
1771+
function TestTHash_Keccak_Base.AddLastByteForKeccakTest(SHA3InputVector : RawByteString;
1772+
var NumBitsOfLastByteUsed : UInt8): RawByteString;
17721773
var
17731774
lastbyte : UInt8;
17741775
begin
1775-
case LastByteLength of
1776+
case NumBitsOfLastByteUsed of
17761777
0 : begin // ist ok
1777-
SHA3InputVector := SHA3InputVector + chr($02);
1778-
LastByteLength := 2;
1778+
SHA3InputVector := SHA3InputVector + chr($02);
1779+
NumBitsOfLastByteUsed := 2;
17791780
end;
17801781
1..6 :
17811782
begin
17821783
lastbyte := UInt8(SHA3InputVector[High(SHA3InputVector)]);
17831784
// in lastbyte 0 an stelle fblSHA3 einfügen:
1784-
lastbyte := lastbyte and (( 1 shl LastByteLength ) xor $FF);
1785+
lastbyte := lastbyte and (( 1 shl NumBitsOfLastByteUsed ) xor $FF);
17851786
// in lastbyte 1 an stelle fblSHA3+1 einfügen:
1786-
lastbyte := lastbyte or BYTE( 1 shl (LastByteLength + 1));
1787+
lastbyte := lastbyte or BYTE( 1 shl (NumBitsOfLastByteUsed + 1));
17871788
SHA3InputVector[High(SHA3InputVector)] := Ansichar(lastbyte);
1788-
if LastByteLength < 6 then
1789-
inc(LastByteLength,2)
1789+
if NumBitsOfLastByteUsed < 6 then
1790+
inc(NumBitsOfLastByteUsed,2)
17901791
else
1791-
LastByteLength := 0;
1792+
NumBitsOfLastByteUsed := 0;
17921793
end;
17931794
7 : begin // ist ok
17941795
// 0 anhängen - es könnte sein, dass in mSHA3 eine 1 steht
@@ -1799,7 +1800,7 @@ function TestTHash_Keccak_Base.AddLastByteForKeccakTest(SHA3InputVector : Raw
17991800
SHA3InputVector[High(SHA3InputVector)] := Ansichar(lastbyte);
18001801

18011802
SHA3InputVector := SHA3InputVector + chr($01);
1802-
LastByteLength := 1;
1803+
NumBitsOfLastByteUsed := 1;
18031804
end;
18041805
end;
18051806

@@ -1828,41 +1829,64 @@ procedure TestTHash_Keccak_224.SetUp;
18281829

18291830
//Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-
18301831
// Validation-Program/documents/sha3/sha-3bittestvectors.zip
1831-
FTestFileNames.Add('..\..\Unit Tests\Data\Keccak.rsp');
1832-
// FTestFileNames.Add('..\..\Unit Tests\Data\SHA3_224ShortMsg.rsp');
1833-
// FTestFileNames.Add('..\..\Unit Tests\Data\SHA3_224LongMsg.rsp');
1832+
1833+
FTestFileNames.Add('..\..\Unit Tests\Data\SHA3_224ShortMsg.rsp');
1834+
FTestFileNames.Add('..\..\Unit Tests\Data\SHA3_224LongMsg.rsp');
18341835
// SourceEnd
18351836

18361837
// Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
18371838
// and-Guidelines/documents/examples/SHA3-224_Msg5.pdf
1838-
lDataRow := FTestData.AddRow;
1839-
lDataRow.ExpectedOutput := 'ffbad5da96bad71789330206dc6768ecaeb1b32d' +
1840-
'ca6b3301489674ab';
1841-
AddLastByteForCodeTest(lDataRow, #$19, 5);
18421839

18431840
lDataRow := FTestData.AddRow;
1844-
lDataRow.ExpectedOutput := '6f2fc54a6b11a6da611ed734505b9cab89eec' +
1845-
'c1dc7dd2debd27bd1c9';
1846-
AddLastByteForCodeTest(lDataRow, #$01, 1);
1841+
lDataRow.ExpectedOutput := '6b4e03423667dbb73b6e15454f0eb1abd459' +
1842+
'7f9a1b078e3f5b5a6bc7';
1843+
AddLastByteForCodeTest(lDataRow, '', 0);
18471844

18481845

1849-
// Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
1850-
// and-Guidelines/documents/examples/SHA3-224_Msg30.pdf
18511846
lDataRow := FTestData.AddRow;
1852-
lDataRow.ExpectedOutput := 'd666a514cc9dba25ac1ba69ed3930460deaac985' +
1853-
'1b5f0baab007df3b';
1854-
AddLastByteForCodeTest(lDataRow, #$53#$58#$7B#$19, 6);
1847+
lDataRow.ExpectedOutput := 'ffbad5da96bad71789330206dc6768ecaeb1b32d' +
1848+
'ca6b3301489674ab';
1849+
lDataRow.AddInputVector(RawByteString(#$19), 1, 1);
1850+
lDataRow.AddInputVector(RawByteString(#$02), 1, 1);
1851+
lDataRow.FinalBitLength := 5;
1852+
// AddLastByteForCodeTest(lDataRow, #$19, 5);
1853+
//exit;
1854+
//
1855+
//// MsgWithFixup := AddLastByteForKeccakTest(
1856+
//// TFormat_HexL.Decode(RawByteString(msg)),
1857+
//// FinalByteLen);
1858+
//
1859+
//
1860+
// lDataRow := FTestData.AddRow;
1861+
// lDataRow.ExpectedOutput := '6f2fc54a6b11a6da611ed734505b9cab89eec' +
1862+
// 'c1dc7dd2debd27bd1c9';
1863+
// AddLastByteForCodeTest(lDataRow, #$01, 1);
1864+
//
1865+
//
1866+
// // Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
1867+
// // and-Guidelines/documents/examples/SHA3-224_Msg30.pdf
1868+
// lDataRow := FTestData.AddRow;
1869+
// lDataRow.ExpectedOutput := 'd666a514cc9dba25ac1ba69ed3930460deaac985' +
1870+
// '1b5f0baab007df3b';
1871+
// AddLastByteForCodeTest(lDataRow, #$53#$58#$7B#$19, 6);
18551872

18561873
// Commented out because AddLastByteForCodeTest cannot handle the 1, 20 syntax
1857-
// // Source: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
1858-
// // and-Guidelines/documents/examples/SHA3-224_1600.pdf
1859-
// lDataRow := FTestData.AddRow;
1860-
// lDataRow.ExpectedOutput := '9376816aba503f72f96ce7eb65ac095deee3be4b' +
1861-
// 'f9bbc2a1cb7e11e0';
1874+
// Source: https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
1875+
// and-Guidelines/documents/examples/SHA3-224_1600.pdf
1876+
lDataRow := FTestData.AddRow;
1877+
lDataRow.ExpectedOutput := '9376816aba503f72f96ce7eb65ac095deee3be4b' +
1878+
'f9bbc2a1cb7e11e0';
18621879
// lDataRow.ExpectedOutputUTFStrTest := '28a4a80fded04a676674687c8330422eedeb18c9' +
18631880
// 'dba976234a9e007a';
1864-
// lDataRow.AddInputVector(RawByteString(#$A3#$A3#$A3#$A3#$A3#$A3#$A3#$A3#$A3#$A3), 1, 20);
1881+
1882+
lDataRow.AddInputVector(RawByteString(#$A3#$A3#$A3#$A3#$A3#$A3#$A3#$A3#$A3#$A3), 1, 20);
1883+
lDataRow.AddInputVector(RawByteString(#$02), 1, 1);
1884+
lDataRow.FinalBitLength := 2;
1885+
exit;
1886+
1887+
// lDataRow.AddInputVector(RawByteString(#$80), 1, 1);
18651888
// lDataRow.FinalBitLength := 0;
1889+
// lDataRow.FinalBitLength := 2;
18661890
//
18671891
// // Source: https://emn178.github.io/online-tools/sha3_224.html
18681892
// lDataRow := FTestData.AddRow;

0 commit comments

Comments
 (0)