SHA-3 Is Built Differently
SHA3-256 and SHA-256 both return 32 bytes but share nothing else; compare them on one text, then read a SHAKE128 output of a chosen length from a file with one command.
The question
SHA-256 is one of the SHA-2 functions of FIPS 180-4. FIPS 202 defines a second family, SHA-3, built on a different construction. SHA3-256 also returns 32 bytes. If two hash functions return the same number of bytes for the same message, are their digests related?
FIPS 202 also defines two extendable-output functions, SHAKE128 and SHAKE256, which return as many bytes as you ask for. That raises a second question: what decides how long the output is?
Work it by hand
FIPS 202 section 6.1 lists the four SHA-3 hash functions and section 6.2 the two extendable-output functions. Read both: the first fixes the output length in the function's name, the second takes it from the caller.
For the three letters abc, SHA3-256 gives 3a985da7 4fe225b2 045c172d 6bd390bd 855f086e 3e9d525b 46bfe245 11431532, which is 32 bytes. The SHA-256 digest of the same letters, ba7816bf 8f01cfea and so on, is also 32 bytes and starts with other bytes. Nothing in one tells you the other.
SHAKE128 on abc with 16 output bytes gives 5881092d d818bf5c f8a3ddb7 93fbcba7. With 24 output bytes it gives the same 16 bytes followed by 4097d5c5 26a6d35f. A longer SHAKE output starts with the shorter one, a property that appendix A.2 of FIPS 202 describes for any XOF.
Run it
The program hashes the text in the box twice, once with SHA-256 and once with SHA3-256, and counts the hex digits that differ. Line 1 is the SHA-256 digest and line 2 the SHA3-256 digest. The loop that starts at line 4 compares them digit by digit, and line 11 returns the count of differing digits.

let d1 = ssl.digest("SHA256", text);
let d2 = ssl.digest("SHA3-256", text);
let differ = 0;
for (i in range(0, str_len(d1))) {
if (str_substr(d1, i, 1) != str_substr(d2, i, 1)) {
differ = differ + 1;
}
}
lmcode_return_put("sha256", d1);
lmcode_return_put("sha3", d2);
let answer = differ;
{
"answer": 57,
"sha256": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
"sha3": "644bcc7e564373040999aac89e7622f3ca71fba1d972fd94a31c3bfbf24e3938"
}You can change the text: printable ASCII and newlines, any length up to 2048 bytes, and an empty box is accepted. Both digests keep 32 bytes, and the count of differing digits changes with the text.
Your turn
SHAKE128 does not run as a program here: ssl.digest refuses it. The command below should write a file out.bin. Run it, read what the page shows for the file, decide whether the file holds 24 bytes of SHAKE128 of the message in in/message.txt, and edit the command until it does. You may type any single openssl command. Check runs your command on the data shown and on four others.

# in/message.txt holds the message.
# The result goes to out.bin.
openssl dgst -shake128 -binary -out out.bin in/message.txt
{
"message": "OpenSSL: unsupported"
}Write one openssl command that writes the SHAKE128 output of the file in/message.txt to out.bin as 24 raw bytes. Check runs your command with other messages in that file: an empty file, short texts, a text with newlines and a longer text.
Read the result carefully
The page shows that SHA-256 and SHA3-256 differ on one text, and that a longer SHAKE128 output of abc starts with the shorter one. It does not run an attack on either family. FIPS 202 appendix A.1 states that the SHA-3 functions are also designed to resist length-extension attacks; this page repeats that design statement and does not test it.
SHAKE128 with 16 or 24 bytes is a choice of the caller. A shorter output is only a prefix of a longer one, so asking for fewer bytes does not give an independent value.
Recap
- SHA3-256 and SHA-256 both return 32 bytes, from different constructions.
- Equal length does not make two digests related.
- A SHAKE function returns the number of bytes the caller asks for.
- The first 16 bytes of the 24-byte SHAKE128 output of a message are the 16-byte SHAKE128 output of the same message.