{"id":506,"date":"2026-11-13T13:39:58","date_gmt":"2026-11-13T05:39:58","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-sha-3-absorbs-a-message-into-a-keccak-sponge\/"},"modified":"2026-11-13T21:59:21","modified_gmt":"2026-11-13T13:59:21","slug":"how-sha-3-absorbs-a-message-into-a-keccak-sponge","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-sha-3-absorbs-a-message-into-a-keccak-sponge\/","title":{"rendered":"How SHA-3 absorbs a message into a Keccak sponge"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>SHA3-256<\/strong> is a Keccak sponge, not a Merkle-Damgard hash. The state is twenty-five 64-bit lanes. SHA3-256 absorbs 136 bytes at a time and pads with the domain byte <code>0x06<\/code>, zeros, and a final byte whose high bit is set. Each absorbed block is xored into the state, and the state is then permuted for twenty-four rounds. The digest of <code>abc<\/code> is <code>3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532<\/code>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A sponge hashes by absorbing the message into part of a large state and squeezing the digest back out. The part that is xored with the message is the rate, 136 bytes for SHA3-256. The rest is the capacity. The permutation has five steps: theta mixes columns, rho rotates lanes, pi moves lanes, chi mixes each lane with its neighbors, and iota xors a round constant into the first lane. The padding domain byte is what separates SHA-3 from the other Keccak instances that use the same permutation.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The same message produces the same 32-byte digest. The digest is the first 32 bytes of the state after the last permutation. SHA3-256 does not use the SHA-256 padding or the SHA-256 constants. A changed domain byte defines a different function. The capacity is the part of the state the message does not overwrite directly.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Start from a state of twenty-five zero lanes.<\/li>\n<li>Append <code>0x06<\/code>, zero bytes, and set the high bit of the last byte so the padded length is a multiple of 136.<\/li>\n<li>Xor each 136-byte block into the state and run the twenty-four-round permutation.<\/li>\n<li>Read the first 32 bytes of the state as the digest.<\/li>\n<\/ol>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when it is treated as SHA-256 with different constants<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Pad with the SHA-256 length suffix<\/td>\n<td>SHA-3 uses the domain byte and the high bit. The Merkle-Damgard length suffix is a different padding.<\/td>\n<\/tr>\n<tr>\n<td>Squeeze more than 32 bytes and still call it SHA3-256<\/td>\n<td>SHA3-256 is defined to squeeze 32 bytes. A longer squeeze is a different output length.<\/td>\n<\/tr>\n<tr>\n<td>Skip the domain byte because the permutation is the same<\/td>\n<td>The domain byte is how SHA-3 is separated from other uses of Keccak.<\/td>\n<\/tr>\n<tr>\n<td>Use the sponge as a password hash with no cost parameter<\/td>\n<td>The sponge is fast. A password store still wants a salt and a memory or iteration cost.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">SHA-256 is the Merkle-Damgard hash. SHA3-256 is the sponge.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment runs the Keccak permutation and squeezes a SHA3-256 digest of <code>abc<\/code>. It prints <code>3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532<\/code>.<\/p>\n\n<pre><code class=\"language-python\">def _rotl64(x: int, n: int) -&gt; int:\n    n %= 64\n    return ((x &lt;&lt; n) | (x &gt;&gt; (64 - n))) &amp; 0xFFFFFFFFFFFFFFFF\n\n_RC = [1, 32898, 9223372036854808714, 9223372039002292224, 32907, 2147483649, 9223372039002292353, 9223372036854808585, 138, 136, 2147516425, 2147483658, 2147516555, 9223372036854775947, 9223372036854808713, 9223372036854808579, 9223372036854808578, 9223372036854775936, 32778, 9223372039002259466, 9223372039002292353, 9223372036854808704, 2147483649, 9223372039002292232]\n\n_ROT = [[0, 36, 3, 41, 18], [1, 44, 10, 45, 2], [62, 6, 43, 15, 61], [28, 55, 25, 21, 56], [27, 20, 39, 8, 14]]\n\ndef _keccak_f(state: list[int]) -&gt; None:\n    rho = [[_ROT[x][y] for y in range(5)] for x in range(5)]\n    for rc in _RC:\n        lanes = [[state[x + 5 * y] for y in range(5)] for x in range(5)]\n        c = [lanes[x][0] ^ lanes[x][1] ^ lanes[x][2] ^ lanes[x][3] ^ lanes[x][4] for x in range(5)]\n        d = [c[(x - 1) % 5] ^ _rotl64(c[(x + 1) % 5], 1) for x in range(5)]\n        for x in range(5):\n            for y in range(5):\n                lanes[x][y] ^= d[x]\n        b = [[0] * 5 for _ in range(5)]\n        for x in range(5):\n            for y in range(5):\n                b[y][(2 * x + 3 * y) % 5] = _rotl64(lanes[x][y], rho[x][y])\n        for x in range(5):\n            for y in range(5):\n                lanes[x][y] = b[x][y] ^ ((~b[(x + 1) % 5][y]) &amp; b[(x + 2) % 5][y] &amp; 0xFFFFFFFFFFFFFFFF)\n        lanes[0][0] ^= rc\n        for x in range(5):\n            for y in range(5):\n                state[x + 5 * y] = lanes[x][y]\n\ndef sha3_256(data: bytes) -&gt; bytes:\n    rate = 136\n    state = [0] * 25\n    msg = data + b&quot;\\x06&quot;\n    msg += b&quot;\\x00&quot; * ((rate - len(msg) % rate) % rate)\n    msg = msg[:-1] + bytes([msg[-1] | 0x80])\n    for off in range(0, len(msg), rate):\n        block = msg[off : off + rate]\n        for i in range(rate \/\/ 8):\n            state[i] ^= int.from_bytes(block[i * 8 : (i + 1) * 8], &quot;little&quot;)\n        _keccak_f(state)\n    out = b&quot;&quot;.join(state[i].to_bytes(8, &quot;little&quot;) for i in range(4))\n    return out\n\ndigest = sha3_256(b&quot;abc&quot;)\nassert digest.hex() == &quot;3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532&quot;\nprint(digest.hex())\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">NIST <strong>SHA-3<\/strong> is the Keccak sponge with the domain byte <code>0x06<\/code>. Ethereum&#8217;s Keccak-256 is the same permutation with a different padding, so the two digests of one message differ. SHA-256 remains the hash most protocols already agreed on.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop SHA3-256 as a password store and as a tag. Keep it as the 256-bit sponge digest. A tag built from it is a keyed construction, not the bare sponge.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for SHA-3 returns the Keccak sponge, the domain byte <code>0x06<\/code>, and the digest of <code>abc<\/code>. <strong>SHA3-256 xors a message into a 136-byte rate, pads with the domain byte <code>0x06<\/code>, and squeezes 32 bytes from the Keccak state.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: SHA3-256 is a Keccak sponge, not a Merkle-Damgard hash. The state is twenty-five 64-bit lanes. SHA3-256 absorbs 136 bytes at a time and pads with the domain byte 0x06, zeros, and a final byte whose high bit is set. Each absorbed block is xored into the state,&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,49],"tags":[],"class_list":["post-506","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-cryptography"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=506"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/506\/revisions"}],"predecessor-version":[{"id":718,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/506\/revisions\/718"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}