mirror of
https://github.com/emmansun/gmsm.git
synced 2025-05-11 03:26:17 +08:00
Updated SM4 with AESENCLAST (markdown)
parent
6c97ff23b5
commit
a7e0f772d7
@ -229,7 +229,28 @@ func gen_matrix(lookup [256]byte) (m [8]byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Similar python code:
|
||||||
|
```
|
||||||
|
from pyfinite import genericmatrix
|
||||||
|
|
||||||
|
|
||||||
|
def XOR(x, y): return x ^ y
|
||||||
|
def AND(x, y): return x & y
|
||||||
|
def DIV(x, y): return x
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_from_cols(cols):
|
||||||
|
m = genericmatrix.GenericMatrix(size=(8, 8), zeroElement=0, identityElement=1, add=XOR, mul=AND, sub=XOR, div=DIV)
|
||||||
|
for i in range (8):
|
||||||
|
k = 7 - i
|
||||||
|
j = 1 << k
|
||||||
|
m.SetRow(i, [(cols[0] & j) >> k, (cols[1] & j) >> k, (cols[2] & j) >> k, (cols[3] & j) >> k, (cols[4] & j) >> k, (cols[5] & j) >> k, (cols[6] & j) >> k, (cols[7] & j) >> k])
|
||||||
|
return m
|
||||||
|
|
||||||
|
|
||||||
|
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]])
|
||||||
|
```
|
||||||
# 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