@@ -147,6 +147,7 @@ TestTHash_SHA3_Base = class(THash_TestBaseExtended)
147
147
// / <returns>
148
148
// / The input vector with added padding
149
149
// / </returns>
150
+ { TODO : Namen überlegen zu ändern, im Kommentar Keccak drin lassen }
150
151
function AddLastByteForKeccakTest (SHA3InputVector : RawByteString;
151
152
var LastByteLength : UInt8): RawByteString; virtual ;
152
153
@@ -318,15 +319,15 @@ TestTHash_Keccak_Base = class(TestTHash_SHA3_Base)
318
319
// / The SHA3 input vector in bytes (not hex encoded!) which shall get
319
320
// / the padding appended.
320
321
// / </param>
321
- // / <param name="LastByteLength ">
322
+ // / <param name="NumBitsOfLastByteUsed ">
322
323
// / Number of bits used in the last byte. In the keccak override this will
323
324
// / be adjusted inside so it's a var param.
324
325
// / </param>
325
326
// / <returns>
326
327
// / The input vector with added padding
327
328
// / </returns>
328
- function AddLastByteForKeccakTest (SHA3InputVector : RawByteString;
329
- var LastByteLength : UInt8): RawByteString; override;
329
+ function AddLastByteForKeccakTest (SHA3InputVector : RawByteString;
330
+ var NumBitsOfLastByteUsed : UInt8): RawByteString; override;
330
331
end ;
331
332
332
333
// Test methods for class THash_Keccak_224
@@ -1767,28 +1768,28 @@ procedure TestTHash_SHA3_Base.AddLastByteForCodeTest(var lDataRow : IHashTest
1767
1768
CalcUnicodeHash(string(TFormat_HexL.Encode(MsgWithFixup)), FHash);
1768
1769
end ;
1769
1770
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;
1772
1773
var
1773
1774
lastbyte : UInt8;
1774
1775
begin
1775
- case LastByteLength of
1776
+ case NumBitsOfLastByteUsed of
1776
1777
0 : begin // ist ok
1777
- SHA3InputVector := SHA3InputVector + chr($02 );
1778
- LastByteLength := 2 ;
1778
+ SHA3InputVector := SHA3InputVector + chr($02 );
1779
+ NumBitsOfLastByteUsed := 2 ;
1779
1780
end ;
1780
1781
1 ..6 :
1781
1782
begin
1782
1783
lastbyte := UInt8(SHA3InputVector[High(SHA3InputVector)]);
1783
1784
// 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);
1785
1786
// 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 ));
1787
1788
SHA3InputVector[High(SHA3InputVector)] := Ansichar(lastbyte);
1788
- if LastByteLength < 6 then
1789
- inc(LastByteLength ,2 )
1789
+ if NumBitsOfLastByteUsed < 6 then
1790
+ inc(NumBitsOfLastByteUsed ,2 )
1790
1791
else
1791
- LastByteLength := 0 ;
1792
+ NumBitsOfLastByteUsed := 0 ;
1792
1793
end ;
1793
1794
7 : begin // ist ok
1794
1795
// 0 anhängen - es könnte sein, dass in mSHA3 eine 1 steht
@@ -1799,7 +1800,7 @@ function TestTHash_Keccak_Base.AddLastByteForKeccakTest(SHA3InputVector : Raw
1799
1800
SHA3InputVector[High(SHA3InputVector)] := Ansichar(lastbyte);
1800
1801
1801
1802
SHA3InputVector := SHA3InputVector + chr($01 );
1802
- LastByteLength := 1 ;
1803
+ NumBitsOfLastByteUsed := 1 ;
1803
1804
end ;
1804
1805
end ;
1805
1806
@@ -1828,41 +1829,64 @@ procedure TestTHash_Keccak_224.SetUp;
1828
1829
1829
1830
// Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-
1830
1831
// 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' );
1834
1835
// SourceEnd
1835
1836
1836
1837
// Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
1837
1838
// and-Guidelines/documents/examples/SHA3-224_Msg5.pdf
1838
- lDataRow := FTestData.AddRow;
1839
- lDataRow.ExpectedOutput := ' ffbad5da96bad71789330206dc6768ecaeb1b32d' +
1840
- ' ca6b3301489674ab' ;
1841
- AddLastByteForCodeTest(lDataRow, #$19 , 5 );
1842
1839
1843
1840
lDataRow := FTestData.AddRow;
1844
- lDataRow.ExpectedOutput := ' 6f2fc54a6b11a6da611ed734505b9cab89eec ' +
1845
- ' c1dc7dd2debd27bd1c9 ' ;
1846
- AddLastByteForCodeTest(lDataRow, #$ 01 , 1 );
1841
+ lDataRow.ExpectedOutput := ' 6b4e03423667dbb73b6e15454f0eb1abd459 ' +
1842
+ ' 7f9a1b078e3f5b5a6bc7 ' ;
1843
+ AddLastByteForCodeTest(lDataRow, ' ' , 0 );
1847
1844
1848
1845
1849
- // Source https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-
1850
- // and-Guidelines/documents/examples/SHA3-224_Msg30.pdf
1851
1846
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);
1855
1872
1856
1873
// 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' ;
1862
1879
// lDataRow.ExpectedOutputUTFStrTest := '28a4a80fded04a676674687c8330422eedeb18c9' +
1863
1880
// '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);
1865
1888
// lDataRow.FinalBitLength := 0;
1889
+ // lDataRow.FinalBitLength := 2;
1866
1890
//
1867
1891
// // Source: https://emn178.github.io/online-tools/sha3_224.html
1868
1892
// lDataRow := FTestData.AddRow;
0 commit comments