mirror of
https://github.com/emmansun/gmsm.git
synced 2025-05-11 03:26:17 +08:00
Updated SM4 with AESENCLAST (markdown)
parent
a83c7d6e3e
commit
c06e4573b4
@ -398,6 +398,54 @@ def matrix_from_cols(cols):
|
|||||||
def gen_matrix_based_table(table):
|
def gen_matrix_based_table(table):
|
||||||
return matrix_from_cols([table[0x80] ^ table[0], table[0x40] ^ table[0], table[0x20] ^ table[0], table[0x10] ^ table[0], table[0x08] ^ table[0], table[0x04] ^ table[0], table[0x02] ^ table[0], table[0x01] ^ table[0]])
|
return matrix_from_cols([table[0x80] ^ table[0], table[0x40] ^ table[0], table[0x20] ^ table[0], table[0x10] ^ table[0], table[0x08] ^ table[0], table[0x04] ^ table[0], table[0x02] ^ table[0], table[0x01] ^ table[0]])
|
||||||
```
|
```
|
||||||
|
# AES ShiftRows
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
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
|
||||||
|
|<!-- --> |<!-- --> | <!-- --> |<!-- --> |
|
||||||
|
|------|------|------|------|
|
||||||
|
|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
|
# Reference
|
||||||
* [AES-NI used in SM4](https://github.com/mjosaarinen/sm4ni)
|
* [AES-NI used in SM4](https://github.com/mjosaarinen/sm4ni)
|
||||||
* [Advanced Encryption Standard (AES)](https://www.nist.gov/publications/advanced-encryption-standard-aes)
|
* [Advanced Encryption Standard (AES)](https://www.nist.gov/publications/advanced-encryption-standard-aes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user