63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
/*
|
|
Package sm1 is the implementation of SM1 block cipher.
|
|
|
|
The SM1 works as follows, There are three keys:
|
|
- systems key SK
|
|
- auxiliary key AK
|
|
- key
|
|
|
|
# Enecryption
|
|
|
|
PT key SK
|
|
| | |
|
|
v +---v------v----+
|
|
R(·) <---- |rk |
|
|
| | |
|
|
| | key expand |
|
|
v | |
|
|
round f(·) <---|rk |
|
|
| +---------------+
|
|
v
|
|
J(·)
|
|
|
|
|
v
|
|
CT
|
|
|
|
# Decryption
|
|
|
|
CT key SK
|
|
| | |
|
|
v +---v------v----+
|
|
R⁻¹(·) <--- |rk |
|
|
| | |
|
|
| | key expand |
|
|
v | |
|
|
round f(·) <---|rk |
|
|
| +---------------+
|
|
v
|
|
J(·)
|
|
|
|
|
v
|
|
PT
|
|
|
|
# R Transformation
|
|
|
|
The input of R is 128 bits, and denotes as X0, X1, X2, X3 from left to right.
|
|
The output of R is 128 bits, and denotes as Y0, Y1, Y2, Y3 from left to right..
|
|
|
|
Y0 = X0 << 1
|
|
Y1 = X1 << 9
|
|
Y2 = X2 << 17
|
|
Y3 = X3 << 25
|
|
|
|
# R⁻¹ Transformation
|
|
|
|
The R⁻¹ Transformation is the reverse of R transformation.
|
|
|
|
Y0 = X0 >> 1
|
|
Y1 = X1 >> 9
|
|
Y2 = X2 >> 17
|
|
Y3 = X3 >> 25
|
|
*/
|
|
package sm1
|