Updated SM4 with AESENCLAST (markdown)

Sun Yimin 2023-10-10 15:28:40 +08:00
parent 62f04864fc
commit 88c6ed8177

@ -141,6 +141,41 @@ sm4_box_aesbox_4
x.bytes[i] = v
}
```
## Intel的方法
[pcpsms4_l9cn](https://github.com/intel/ipp-crypto/blob/develop/sources/ippcp/pcpsms4_l9cn.h)
```go
var shift_row_inv = set64(0x0306090C0F020508, 0x0B0E0104070A0D00)
var intelm1l = set64(0xdcf84460b3972b0f, 0xb6922e0ad9fd4165)
var intelm1h = set64(0x64ad03cae42d834a, 0x2ee74980ae67c900)
var intelm2l = set64(0x48c2a32957ddbc36, 0xad2746ccb23859d3)
var intelm2h = set64(0x134307579aca8ede, 0xcd9dd98944145000)
var intelenckey = set64(0x6363636363636363, 0x6363636363636363)
var intelmaskSrows = shift_row_inv
func sm4_box_aesenclast_intel(rk uint32, t0, t1, t2, t3, a1l, a1h, a2l, a2h __m128i) __m128i {
rk128 := mm_set_epi32(rk, rk, rk, rk)
x := xor(xor(t1, t2), t3)
x = xor(x, rk128)
y := mm_and_si128(x, const_0f)
y = mm_shuffle_epi8(a1l, y)
x = mm_srli_epi64(x, 4)
x = mm_and_si128(x, const_0f)
x = xor(mm_shuffle_epi8(a1h, x), y)
x = mm_aesenclast_si128(x, intelenckey)
x = mm_shuffle_epi8(x, intelmaskSrows)
y = mm_and_si128(x, const_0f)
y = mm_shuffle_epi8(a2l, y)
x = mm_srli_epi64(x, 4)
x = mm_and_si128(x, const_0f)
x = xor(mm_shuffle_epi8(a2h, x), y)
return x
}
```
## How to calculate lookup table from M, C?
$\{ M\times i + C \mid i \in [0,255] \}$