The invention discloses an SM4
encryption and decryption
key generation hardware design method based on a shared state
machine, the
encryption key generation process and the decryption
key generation process are combined, all data paths are shared, a part of the state
machine is shared, the state
machine takes K0, K1, K2 and K3 as main key input during
encryption, and takes K35, K34, K33 and K32 as main key input during decryption, so that the encryption key
generation process and the decryption key
generation process are integrated. The generation of the decryption key can be completed by only 32 cycles when the key does not need to be updated, so that the number of cycles required by the generation of the decryption round key is reduced. The customized state machine optimizes the decryption key
generation process through state jump, and ensures the
correctness of the generated encryption round key and decryption round key through control of a
control signal. The method is used for generating an SM4 encryption and decryption key, and the period number of generation of the decryption key is reduced by 50% when the key is not changed. And the number of registers and combinatorial logics required by generation of encryption and decryption keys is reduced.