@@ -298,3 +298,95 @@ TEST_CASE(test_SHA512_hash_empty_string)
298298 auto digest = Crypto::Hash::SHA512::hash (" " sv);
299299 EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA512::digest_size ()) == 0 );
300300}
301+
302+ TEST_CASE (test_SHA3_256_name)
303+ {
304+ auto sha = Crypto::Hash::SHA3_256::create ();
305+ EXPECT_EQ (sha->class_name (), " SHA3-256" sv);
306+ }
307+
308+ TEST_CASE (test_SHA3_256_hash_string)
309+ {
310+ u8 result[] {
311+ 0x25 , 0x5c , 0x1e , 0x6c , 0xf3 , 0x10 , 0x48 , 0x9e , 0xca , 0x35 , 0xbf , 0xab , 0x82 , 0x1d , 0x38 , 0x2d , 0xc0 , 0xc8 , 0x95 , 0x16 , 0x49 , 0x85 , 0x54 , 0xc6 , 0xf1 , 0xa5 , 0xf5 , 0x26 , 0x1a , 0xc2 , 0x06 , 0x9e
312+ };
313+ auto digest = Crypto::Hash::SHA3_256::hash (" Well hello friends" sv);
314+ EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA3_256::digest_size ()) == 0 );
315+ }
316+
317+ TEST_CASE (test_SHA3_256_hash_empty_string)
318+ {
319+ u8 result[] {
320+ 0xa7 , 0xff , 0xc6 , 0xf8 , 0xbf , 0x1e , 0xd7 , 0x66 , 0x51 , 0xc1 , 0x47 , 0x56 , 0xa0 , 0x61 , 0xd6 , 0x62 , 0xf5 , 0x80 , 0xff , 0x4d , 0xe4 , 0x3b , 0x49 , 0xfa , 0x82 , 0xd8 , 0x0a , 0x4b , 0x80 , 0xf8 , 0x43 , 0x4a
321+ };
322+ auto digest = Crypto::Hash::SHA3_256::hash (" " sv);
323+ EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA3_256::digest_size ()) == 0 );
324+ }
325+
326+ TEST_CASE (test_SHA3_256_hash_split_into_blocks)
327+ {
328+ u8 result[] {
329+ 0x0c , 0x4e , 0x02 , 0xfb , 0x73 , 0x31 , 0xe9 , 0xe7 , 0x25 , 0x8c , 0xcf , 0xc6 , 0x25 , 0x03 , 0xe9 , 0x2c , 0xa5 , 0x7f , 0xaa , 0x91 , 0x4a , 0x21 , 0xde , 0x00 , 0x03 , 0x72 , 0x9a , 0xa0 , 0xaa , 0x0d , 0x9e , 0x76
330+ };
331+ auto digest = Crypto::Hash::SHA3_256::hash (" 0123456789012345678901234567890123456789012345678901234567890123abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd" sv);
332+ EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA3_256::digest_size ()) == 0 );
333+ }
334+
335+ TEST_CASE (test_SHA3_384_name)
336+ {
337+ auto sha = Crypto::Hash::SHA3_384::create ();
338+ EXPECT_EQ (sha->class_name (), " SHA3-384" sv);
339+ }
340+
341+ TEST_CASE (test_SHA3_384_hash_string)
342+ {
343+ u8 result[] {
344+ 0x4e , 0x86 , 0xc0 , 0x05 , 0x5f , 0x8d , 0x11 , 0x51 , 0xc8 , 0xcd , 0x71 , 0xd6 , 0xe8 , 0x61 , 0xc0 , 0x86 , 0x14 , 0x6d , 0xdc , 0xa8 , 0x79 , 0xe0 , 0x2f , 0x07 , 0x69 , 0x8e , 0xde , 0xfd , 0xcf , 0x36 , 0x4f , 0x9b , 0xfa , 0x86 , 0xb0 , 0x78 , 0xee , 0xbe , 0xca , 0xa4 , 0xff , 0x20 , 0xc9 , 0x51 , 0x32 , 0x31 , 0xd2 , 0xe5
345+ };
346+ auto digest = Crypto::Hash::SHA3_384::hash (" Well hello friends" sv);
347+ EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA3_384::digest_size ()) == 0 );
348+ }
349+
350+ TEST_CASE (test_SHA3_384_hash_bug)
351+ {
352+ u8 result[] {
353+ 0x79 , 0x40 , 0x7d , 0x3b , 0x59 , 0x16 , 0xb5 , 0x9c , 0x3e , 0x30 , 0xb0 , 0x98 , 0x22 , 0x97 , 0x47 , 0x91 , 0xc3 , 0x13 , 0xfb , 0x9e , 0xcc , 0x84 , 0x9e , 0x40 , 0x6f , 0x23 , 0x59 , 0x2d , 0x04 , 0xf6 , 0x25 , 0xdc , 0x8c , 0x70 , 0x9b , 0x98 , 0xb4 , 0x3b , 0x38 , 0x52 , 0xb3 , 0x37 , 0x21 , 0x61 , 0x79 , 0xaa , 0x7f , 0xc7
354+ };
355+ ReadonlyBytes result_bytes { result, 48 };
356+ auto digest = Crypto::Hash::SHA3_384::hash (" abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" sv);
357+ EXPECT_EQ (result_bytes, digest.bytes ());
358+ }
359+
360+ TEST_CASE (test_SHA3_512_name)
361+ {
362+ auto sha = Crypto::Hash::SHA3_512::create ();
363+ EXPECT_EQ (sha->class_name (), " SHA3-512" sv);
364+ }
365+
366+ TEST_CASE (test_SHA3_512_hash_string)
367+ {
368+ u8 result[] {
369+ 0x4e , 0xda , 0x90 , 0x1e , 0x2c , 0xf7 , 0x4a , 0xe1 , 0x5a , 0x30 , 0xbd , 0x3a , 0x13 , 0x5a , 0xeb , 0x07 , 0x3e , 0x3c , 0x5d , 0x6a , 0x86 , 0x34 , 0xab , 0x94 , 0xa8 , 0x97 , 0x5b , 0x7c , 0x38 , 0x91 , 0x89 , 0xe5 , 0xd1 , 0x5a , 0xd9 , 0x49 , 0x7c , 0xbf , 0x85 , 0xd6 , 0x8c , 0x5d , 0xd2 , 0x75 , 0x09 , 0x41 , 0xb4 , 0xa5 , 0xe5 , 0xf5 , 0xf5 , 0xc8 , 0xc6 , 0x44 , 0x9b , 0xe1 , 0x2f , 0x0e , 0x45 , 0xa8 , 0x28 , 0xf4 , 0x49 , 0xea
370+ };
371+ auto digest = Crypto::Hash::SHA3_512::hash (" Well hello friends" sv);
372+ EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA3_512::digest_size ()) == 0 );
373+ }
374+
375+ TEST_CASE (test_SHA3_512_hash_bug)
376+ {
377+ u8 result[] {
378+ 0xaf , 0xeb , 0xb2 , 0xef , 0x54 , 0x2e , 0x65 , 0x79 , 0xc5 , 0x0c , 0xad , 0x06 , 0xd2 , 0xe5 , 0x78 , 0xf9 , 0xf8 , 0xdd , 0x68 , 0x81 , 0xd7 , 0xdc , 0x82 , 0x4d , 0x26 , 0x36 , 0x0f , 0xee , 0xbf , 0x18 , 0xa4 , 0xfa , 0x73 , 0xe3 , 0x26 , 0x11 , 0x22 , 0x94 , 0x8e , 0xfc , 0xfd , 0x49 , 0x2e , 0x74 , 0xe8 , 0x2e , 0x21 , 0x89 , 0xed , 0x0f , 0xb4 , 0x40 , 0xd1 , 0x87 , 0xf3 , 0x82 , 0x27 , 0x0c , 0xb4 , 0x55 , 0xf2 , 0x1d , 0xd1 , 0x85
379+ };
380+ ReadonlyBytes result_bytes { result, 64 };
381+ auto digest = Crypto::Hash::SHA3_512::hash (" abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" sv);
382+ EXPECT_EQ (result_bytes, digest.bytes ());
383+ }
384+
385+ TEST_CASE (test_SHA3_512_hash_empty_string)
386+ {
387+ u8 result[] {
388+ 0xa6 , 0x9f , 0x73 , 0xcc , 0xa2 , 0x3a , 0x9a , 0xc5 , 0xc8 , 0xb5 , 0x67 , 0xdc , 0x18 , 0x5a , 0x75 , 0x6e , 0x97 , 0xc9 , 0x82 , 0x16 , 0x4f , 0xe2 , 0x58 , 0x59 , 0xe0 , 0xd1 , 0xdc , 0xc1 , 0x47 , 0x5c , 0x80 , 0xa6 , 0x15 , 0xb2 , 0x12 , 0x3a , 0xf1 , 0xf5 , 0xf9 , 0x4c , 0x11 , 0xe3 , 0xe9 , 0x40 , 0x2c , 0x3a , 0xc5 , 0x58 , 0xf5 , 0x00 , 0x19 , 0x9d , 0x95 , 0xb6 , 0xd3 , 0xe3 , 0x01 , 0x75 , 0x85 , 0x86 , 0x28 , 0x1d , 0xcd , 0x26
389+ };
390+ auto digest = Crypto::Hash::SHA3_512::hash (" " sv);
391+ EXPECT (memcmp (result, digest.data , Crypto::Hash::SHA3_512::digest_size ()) == 0 );
392+ }
0 commit comments