Updated SM4 with AESENCLAST (markdown)

Sun Yimin 2023-10-11 14:14:22 +08:00
parent 6077f2cd91
commit 183b8d5894

@ -554,47 +554,66 @@ print(gen_matrix_based_high_low([0x00,0x50,0x14,0x44,0x89,0xd9,0x9d,0xcd,0xde,0x
16字节State是这样存储的
$in_0 \ in_1 \ in_2 \ in_3 \ in_4\ in_5\ in_6\ in_7\ in_8\ in_9\ in_{10}\ in_{11}\ in_{12}\ in_{13}\ in_{14}\ in_{15}$
ShiftRows操作
|<!-- --> |<!-- --> | <!-- --> |<!-- --> |
|------|------|------|------|
|0 | 4 | 8 | c |
|1 | 5 | 9 | d |
|2 | 6 | a | e |
|3 | 7 | b | f |
ShiftRows后变成
|<!-- --> |<!-- --> | <!-- --> |<!-- --> |
|------|------|------|------|
|0 | 4 | 8 | c |
|5 | 9 | d | 1 |
|a | e | 2 | 6 |
|f | 3 | 7 | b |
STATE先逆ShiftRows, 再ShiftRows回到初始STATE。
<table>
<tr><td>
<table>
<tr>
<td>0</td><td>4</td><td>8</td><td>c</td>
</tr>
<tr>
<td>1</td><td>5</td><td>9</td><td>d</td>
</tr>
<tr>
<td>2</td><td>6</td><td>a</td><td>e</td>
</tr>
<tr>
<td>3</td><td>7</td><td>b</td><td>f</td>
</tr>
</table>
</td>
<td>
逆ShiftRows后=>
</td>
<td>
<table>
<tr>
<td>0</td><td>4</td><td>8</td><td>c</td>
</tr>
<tr>
<td>d</td><td>1</td><td>5</td><td>9</td>
</tr>
<tr>
<td>a</td><td>e</td><td>2</td><td>6</td>
</tr>
<tr>
<td>7</td><td>b</td><td>f</td><td>3</td>
</tr>
</table>
</td>
<td>
再ShiftRows后=>
</td>
<td>
<table>
<tr>
<td>0</td><td>4</td><td>8</td><td>c</td>
</tr>
<tr>
<td>1</td><td>5</td><td>9</td><td>d</td>
</tr>
<tr>
<td>2</td><td>6</td><td>a</td><td>e</td>
</tr>
<tr>
<td>3</td><td>7</td><td>b</td><td>f</td>
</tr>
</table>
</td>
</tr>
</table>
再来看STATE 先逆ShiftRows, 再ShiftRows
|<!-- --> |<!-- --> | <!-- --> |<!-- --> |
|------|------|------|------|
|0 | 4 | 8 | c |
|1 | 5 | 9 | d |
|2 | 6 | a | e |
|3 | 7 | b | f |
STATE逆ShiftRows后
|<!-- --> |<!-- --> | <!-- --> |<!-- --> |
|------|------|------|------|
|0 | 4 | 8 | c |
|d | 1 | 5 | 9 |
|a | e | 2 | 6 |
|7 | b | f | 3 |
再ShiftRows后
|<!-- --> |<!-- --> | <!-- --> |<!-- --> |
|------|------|------|------|
|0 | 4 | 8 | c |
|1 | 5 | 9 | d |
|2 | 6 | a | e |
|3 | 7 | b | f |
回到初始STATE。
# Reference
* [AES-NI used in SM4](https://github.com/mjosaarinen/sm4ni)