mirror of
https://github.com/emmansun/gmsm.git
synced 2025-05-10 19:16:18 +08:00
Updated SM4 with AESENCLAST (markdown)
parent
dcc2985f40
commit
96d3ad4563
@ -25,7 +25,7 @@ sm4_box_aesenclast <-> sm4_box_aesbox_1 <-> sm4_box_aesbox_2 <-> sm4_box_aesbox_
|
||||
|
||||
**We note that each affine transform can be constructed from XOR of two 4x8-bit table lookups, which we implement with constant time byte shuffle instructions (each 16-entry table is in a single 128-bit register).**
|
||||
|
||||
```
|
||||
```golang
|
||||
sm4_box_aesenclast
|
||||
y := mm_and_si128(x, const_0f)
|
||||
y = mm_shuffle_epi8(a1l, y)
|
||||
@ -91,8 +91,8 @@ sm4_box_aesbox_4
|
||||
}
|
||||
```
|
||||
**How to calculate lookup table from M, C?**
|
||||
```
|
||||
{Mi+C | i>=0 && i<256}
|
||||
```golang
|
||||
// {Mi+C | i>=0 && i<256}
|
||||
|
||||
// Generate lookup table based on M matrix and C
|
||||
func gen_lookup_table(m [8]byte, c byte) {
|
||||
@ -113,7 +113,7 @@ func gen_lookup_table(m [8]byte, c byte) {
|
||||
}
|
||||
```
|
||||
Below python code is more intuitive:
|
||||
```
|
||||
```python
|
||||
from pyfinite import genericmatrix
|
||||
|
||||
XOR = lambda x,y:x^y
|
||||
@ -203,7 +203,7 @@ Below is sample
|
||||
00111100
|
||||
```
|
||||
|
||||
```
|
||||
```golang
|
||||
// Generate matrix based on lookup table
|
||||
func gen_matrix(lookup [256]byte) (m [8]byte) {
|
||||
c := lookup[0]
|
||||
@ -228,7 +228,7 @@ func gen_matrix(lookup [256]byte) (m [8]byte) {
|
||||
}
|
||||
```
|
||||
Similar python code:
|
||||
```
|
||||
```python
|
||||
from pyfinite import genericmatrix
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user