{"id":484,"date":"2026-11-13T13:39:14","date_gmt":"2026-11-13T05:39:14","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-aes-encrypts-one-block-in-ten-rounds\/"},"modified":"2026-11-13T21:58:47","modified_gmt":"2026-11-13T13:58:47","slug":"how-aes-encrypts-one-block-in-ten-rounds","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-aes-encrypts-one-block-in-ten-rounds\/","title":{"rendered":"How AES encrypts one block in ten rounds"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>AES<\/strong> encrypts a 16-byte block. AES-128 expands a 16-byte key into eleven round keys and runs ten rounds. Each of the first nine rounds is SubBytes, ShiftRows, MixColumns, and AddRoundKey. The last round skips MixColumns. The FIPS 197 key <code>000102030405060708090a0b0c0d0e0f<\/code> and plaintext <code>00112233445566778899aabbccddeeff<\/code> encrypt to <code>69c4e0d86a7b0430d8cdb78070b4c55a<\/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 block cipher has to be a keyed permutation of fixed-size blocks. AES fixes the block at 16 bytes. The public structure is a substitution-permutation network. The secret is the key. The 16 state bytes are stored in column-major order: index <code>4 * c + r<\/code> is row <code>r<\/code> of column <code>c<\/code>. ShiftRows and MixColumns are defined on that layout. A message longer than 16 bytes is not one AES input. A mode of operation is what chains blocks, and an authenticator is what detects a changed ciphertext.<\/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\">For each 16-byte key, AES-128 is one permutation of the 16-byte strings. SubBytes applies an S-box that inverts the byte in GF(2^8), using the irreducible <code>x^8 + x^4 + x^3 + x + 1<\/code>, and then applies the AES affine map and the constant <code>0x63<\/code>. ShiftRows rotates row <code>r<\/code> left by <code>r<\/code> bytes. MixColumns multiplies each column by the fixed polynomial whose bytes are 2, 3, 1, and 1, modulo <code>x^4 + 1<\/code>. The key schedule produces 176 bytes. None of that says two equal plaintext blocks hide their equality, and none of it rejects a modified ciphertext.<\/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>Build the S-box from the field inverse and the affine map.<\/li>\n<li>Expand the key. Every fourth word is rotated, passed through the S-box, and xored with the round constant. Xor it with the word 16 bytes earlier. The other words are the previous word xored with the word 16 bytes earlier.<\/li>\n<li>Xor the first round key into the state.<\/li>\n<li>Nine times, apply SubBytes, ShiftRows, MixColumns, and the next round key.<\/li>\n<li>Finish with SubBytes, ShiftRows, and the last round key. Read the state out in the same column-major order.<\/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 for a message longer than one block<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Encrypt each 16-byte piece on its own with the same key<\/td>\n<td>Equal pieces stay equal. That is ECB, and it is not a message encryption.<\/td>\n<\/tr>\n<tr>\n<td>Skip MixColumns on the early rounds<\/td>\n<td>Column mixing is the step that spreads one byte across the other bytes of the column. Dropping it defines a different permutation.<\/td>\n<\/tr>\n<tr>\n<td>Store the state row by row<\/td>\n<td>ShiftRows and MixColumns index columns. The transposed state does not produce the FIPS ciphertext.<\/td>\n<\/tr>\n<tr>\n<td>Treat the block permutation as a message format<\/td>\n<td>A permutation has no nonce, no length, and no tag. A mode and an authenticator carry a message.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">Cipher block chaining, counter mode, and GCM are ways to use this permutation on more than one block. AES is the permutation.<\/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 builds the S-box, expands the FIPS 197 key, and encrypts the FIPS 197 block. It prints <code>69c4e0d86a7b0430d8cdb78070b4c55a<\/code>.<\/p>\n\n<pre><code class=\"language-python\">def _xtime(a: int) -&gt; int:\n    return ((a &lt;&lt; 1) ^ 0x1B) &amp; 0xFF if a &amp; 0x80 else (a &lt;&lt; 1) &amp; 0xFF\n\ndef _gmul(a: int, b: int) -&gt; int:\n    p = 0\n    for _ in range(8):\n        if b &amp; 1:\n            p ^= a\n        a = _xtime(a)\n        b &gt;&gt;= 1\n    return p\n\ndef _sbox() -&gt; list[int]:\n    box = []\n    for x in range(256):\n        inv = 0 if x == 0 else next(i for i in range(1, 256) if _gmul(x, i) == 1)\n        y = 0\n        for i in range(8):\n            bit = (inv &gt;&gt; i) ^ (inv &gt;&gt; ((i + 4) % 8)) ^ (inv &gt;&gt; ((i + 5) % 8))\n            bit ^= (inv &gt;&gt; ((i + 6) % 8)) ^ (inv &gt;&gt; ((i + 7) % 8)) ^ (0x63 &gt;&gt; i)\n            y |= (bit &amp; 1) &lt;&lt; i\n        box.append(y)\n    return box\n\n_S = _sbox()\n\ndef aes128_encrypt(block: bytes, key: bytes) -&gt; bytes:\n    words = list(key)\n    rcon = 1\n    while len(words) &lt; 176:\n        t = words[-4:]\n        if len(words) % 16 == 0:\n            t = t[1:] + t[:1]\n            t = [_S[b] for b in t]\n            t[0] ^= rcon\n            rcon = _xtime(rcon)\n        earlier = words[-16:-12]\n        words.extend(earlier[i] ^ t[i] for i in range(4))\n    state = list(block)\n\n    def add(rnd: int) -&gt; None:\n        rk = words[rnd * 16 : (rnd + 1) * 16]\n        for i in range(16):\n            state[i] ^= rk[i]\n\n    def sub() -&gt; None:\n        for i in range(16):\n            state[i] = _S[state[i]]\n\n    def shift() -&gt; None:\n        for r in range(1, 4):\n            row = [state[r + 4 * c] for c in range(4)]\n            row = row[r:] + row[:r]\n            for c in range(4):\n                state[r + 4 * c] = row[c]\n\n    def mix() -&gt; None:\n        for c in range(4):\n            col = state[4 * c : 4 * c + 4]\n            state[4 * c] = _gmul(col[0], 2) ^ _gmul(col[1], 3) ^ col[2] ^ col[3]\n            state[4 * c + 1] = col[0] ^ _gmul(col[1], 2) ^ _gmul(col[2], 3) ^ col[3]\n            state[4 * c + 2] = col[0] ^ col[1] ^ _gmul(col[2], 2) ^ _gmul(col[3], 3)\n            state[4 * c + 3] = _gmul(col[0], 3) ^ col[1] ^ col[2] ^ _gmul(col[3], 2)\n\n    add(0)\n    for rnd in range(1, 10):\n        sub()\n        shift()\n        mix()\n        add(rnd)\n    sub()\n    shift()\n    add(10)\n    return bytes(state)\n\nkey = bytes.fromhex(&quot;000102030405060708090a0b0c0d0e0f&quot;)\nblock = bytes.fromhex(&quot;00112233445566778899aabbccddeeff&quot;)\ncipher = aes128_encrypt(block, key)\nassert cipher.hex() == &quot;69c4e0d86a7b0430d8cdb78070b4c55a&quot;\nprint(cipher.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\"><strong>TLS<\/strong>, <strong>LUKS<\/strong>, <strong>BitLocker<\/strong>, and <strong>FileVault<\/strong> encrypt with AES. WPA2 and WPA3 use it as well. A message longer than one block uses a mode such as GCM; the ten-round map is only the permutation.<\/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 AES as a format for a message. Keep AES-128 as the 16-byte permutation inside a mode that uses each nonce once and, wherever a modified ciphertext must be rejected, an authenticator.<\/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 AES returns the ten-round structure and the FIPS 197 ciphertext. <strong>AES-128 expands a 16-byte key into eleven round keys and encrypts one column-major block in ten rounds, skipping MixColumns only on the last round.<\/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: AES encrypts a 16-byte block. AES-128 expands a 16-byte key into eleven round keys and runs ten rounds. Each of the first nine rounds is SubBytes, ShiftRows, MixColumns, and AddRoundKey. The last round skips MixColumns. The FIPS 197 key 000102030405060708090a0b0c0d0e0f and plaintext 00112233445566778899aabbccddeeff encrypt to 69c4e0d86a7b0430d8cdb78070b4c55a. What&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-484","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\/484","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=484"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":696,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/484\/revisions\/696"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}