mirror of
https://github.com/emmansun/gmsm.git
synced 2025-05-11 03:26:17 +08:00
Updated SM4 with AESENCLAST (markdown)
parent
d94b871e1d
commit
5e1a1898cd
@ -89,6 +89,28 @@ sm4_box_aesbox_4
|
||||
x.bytes[i] = v
|
||||
}
|
||||
```
|
||||
**How to calculate lookup table from M, C?**
|
||||
```
|
||||
{Mi+C | i>=0 && i<256}
|
||||
|
||||
// Generate lookup table based on M matrix and C
|
||||
func gen_lookup_table(m [8]byte, c byte) {
|
||||
for i := 0; i < 16; i++ {
|
||||
for j := 0; j < 16; j++ {
|
||||
x := ((byte(bits.OnesCount8(byte(i*16+j)&m[0])) & 1) << 7) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[1])) & 1) << 6) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[2])) & 1) << 5) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[3])) & 1) << 4) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[4])) & 1) << 3) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[5])) & 1) << 2) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[6])) & 1) << 1) ^
|
||||
((byte(bits.OnesCount8(byte(i*16+j)&m[7])) & 1) << 0) ^ c
|
||||
fmt.Printf("0x%02X, ", x)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**How to calculate M, C from lookup table?**
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user