sm4_src.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef __lk_sm4_h__
  2. #define __lk_sm4_h__
  3. #ifdef __cpluscplus
  4. extern "C" {
  5. #endif
  6. #include "stm32f10x.h"
  7. //#include <strings.h>
  8. #include <string.h>
  9. #ifdef __cpluscplus
  10. }
  11. #endif
  12. #define u8 unsigned char
  13. #define u32 unsigned long
  14. void four_uCh2uLong(u8 *in, u32 *out); //四字节转换成u32
  15. void uLong2four_uCh(u32 in, u8 *out); //u32转换成四字节
  16. unsigned long move(u32 data, int length); //左移,保留丢弃位放置尾部
  17. unsigned long func_key(u32 input); //先使用Sbox进行非线性变化,再将线性变换L置换为L'
  18. unsigned long func_data(u32 input); //先使用Sbox进行非线性变化,再进行线性变换L
  19. void print_hex(u8 *data, int len); //无符号字符数组转16进制打印
  20. extern u16 encode_fun(u8 len,u8 *key, u8 *input, u8 *output); //加密函数
  21. extern void decode_fun(u8 len,u8 *key, u8 *input, u8 *output); //解密函数
  22. typedef struct _sm4_data_{
  23. u32 mkey[4]; //存储密钥的u32数据
  24. u32 key[36]; //用于密钥扩展算法与系统参数FK运算后的结果存储
  25. u32 rkey[36]; //用于存放加密数据
  26. }sm4daInfo;
  27. #ifdef __cpluscplus
  28. extern "C" {
  29. #endif
  30. #ifdef __cpluscplus
  31. }
  32. #endif
  33. #endif