joylink_aes.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef JOYLINK2_AES_H
  2. #define JOYLINK2_AES_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #define UINT8 unsigned char
  8. #define UINT32 unsigned int
  9. enum
  10. {
  11. JOYLINK_SUCCESS = 0,
  12. JOYLINK_BUFFER_SPACE_ERR = -100, /*buffer不足*/
  13. JOYLINK_RECV_LEN_ERR = -101, /*接收数据长度有误*/
  14. JOYLINK_CHECKSUM_ERR = -102, /*数据校验失败*/
  15. JOYLINK_GET_CMD_ERR = -103, /*接收命令类型有误*/
  16. JOYLINK_GET_DEVID_ERR = -104, /*设备ID不一致*/
  17. JOYLINK_DEVID_ERR = -105, /*设备ID有误*/
  18. JOYLINK_TOKEN_ERR = -106, /*设备TOKEN有误*/
  19. JOYLINK_ENCTYPE_ERR = -107, /*不支持的加密策略*/
  20. JOYLINK_MAGIC_ERR = -108, /*无效数据包,magic有误*/
  21. JOYLINK_ENCINFO_ERR = -109, /*加密信息有误*/
  22. JOYLINK_PARAM_INVALID = -1000, /*参数数据有误*/
  23. JOYLINK_SYSTEM_ERR = -1001, /*系统调用错误,例如创建socket失败*/
  24. JOYLINK_NETWORK_TIMEOUT = -1002, /*网络超时*/
  25. JOYLINK_RECV_DATA_ERR = -1003, /*接收到的数据有误*/
  26. JOYLINK_CANCEL_ERR = -1004, /*用户取消操作*/
  27. };
  28. // ARC4 crypt, 若有用户自己实现, 则宏定义为1
  29. #define HARDWARE_ARC4 0
  30. extern int joylinkEnc1Crypt(UINT8 *key, UINT32 keyLen, UINT8 *data, UINT32 len);
  31. #define JOYLINK_ENC2_ENCRYPT 1
  32. #define JOYLINK_ENC2_DECRYPT 0
  33. //#define JOYLINK_ERR_ENC2_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
  34. //#define JOYLINK_ERR_ENC2_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
  35. //AES crypt, 若用户自己实现,则宏定义为1
  36. #define HARDWARE_AES 0
  37. extern int joylinkEnc2Crypt(UINT8 *key, UINT32 keyLen, UINT8 *iv, UINT8 *data, UINT32 *len, UINT32 maxLen, int isPKCS5, int type);
  38. //MD5 crypt, 若用户自己实现,则宏定义为1
  39. #define HARDWARE_MD5 1
  40. extern void joylinkENC3(UINT8 *input, UINT32 inputlen, UINT8 output[16]);
  41. #define JOYLINK_ENC4_KEY_BIT 1024
  42. #define JOYLINK_ENC4_ENCRYPT 1
  43. #define JOYLINK_ENC4_DECRYPT 0
  44. //RSA crypt, 需要由用户自己实现,
  45. #define HARDWARE_RSA 1
  46. extern int joylinkEnc4Crypt(UINT8 *input, UINT32 inputLen, UINT8 *output, UINT32 maxLen, UINT8 *key, int type);
  47. /**
  48. * brief:
  49. *
  50. * @Param: key
  51. * @Param: keyLength
  52. * @Param: iv
  53. * @Param: pEncIn
  54. * @Param: encLength
  55. * @Param: pPlainOut
  56. * @Param: maxOutLen
  57. *
  58. * @Returns:
  59. */
  60. extern int device_aes_decrypt(const UINT8 * key, int keyLength, const UINT8 * iv, const UINT8 *pEncIn, int encLength, UINT8 *pPlainOut, int maxOutLen);
  61. extern int device_aes_encrypt(const UINT8 * key, int keyLength, const UINT8 * iv, const UINT8 *pPlainIn, int plainLength, UINT8 *pEncOut, int maxOutLen);
  62. extern int device_aes_encrypt_entire_iv(const UINT8 * key, int keyLength,
  63. const UINT8 * iv, const UINT8 *pPlainIn,
  64. int plainLength, UINT8 *pEncOut, int maxOutLen);
  65. extern int device_aes_decrypt_entire_iv(const UINT8 * key, int keyLength,
  66. const UINT8 * iv, const UINT8 *pEncIn,
  67. int encLength, UINT8 *pPlainOut, int maxOutLen);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif