rvcfileheader.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <stdio.h>
  3. #include "filecryption.h"
  4. #include <stdint.h>
  5. #ifndef RVC_FILE_HEADER_FLAG_LEN
  6. #define RVC_FILE_HEADER_FLAG_LEN 16
  7. #endif
  8. #ifndef RVC_FILE_HASH_LEN
  9. #define RVC_FILE_HASH_LEN 32
  10. #endif
  11. #ifndef RVC_CRYPTION_VER_FLAG_LEN
  12. #define RVC_CRYPTION_VER_FLAG_LEN 8
  13. #endif
  14. #ifndef MAX_PATH
  15. #define MAX_PATH 260
  16. #endif // !MAX_PATH
  17. // {5565B9BA-2953-4F19-B05A-0F179287DB2D}
  18. static const char rvc_header[] = {0x55, 0x65, 0xb9, 0xba, 0x29, 0x53, 0x4f, 0x19, 0xb0, 0x5a, 0x0f, 0x17, 0x92, 0x87, 0xdb, 0x2d, 0x0};
  19. static const char* cryption_ver_flag_table[] = {
  20. "rvcfilea",
  21. "rvcfileb",
  22. "rvcfilec",
  23. "rvcfiled"
  24. };
  25. /*添加的自定义文件头信息
  26. 1. 自定义文件头标识16位
  27. 2. 自定义文件头长度4位
  28. 3. 文件加密版本标识
  29. 4. 源文件hash值
  30. 5. 源文件文件大小
  31. 6. 源文件文件名
  32. 7. 真实文件格式,后缀名
  33. */
  34. typedef struct rvc_fileheader_s{
  35. unsigned char strhead[RVC_FILE_HEADER_FLAG_LEN];
  36. size_t uheadlen;
  37. char strcryptver[RVC_CRYPTION_VER_FLAG_LEN];
  38. unsigned char strhash[RVC_FILE_HASH_LEN];
  39. uint32_t usrcfilelen;
  40. char strsrcfilename[MAX_PATH];
  41. char strsrcfileformat[MAX_PATH];
  42. }rvc_fileheader_t;
  43. int constrcut_rvc_file_header(char* pbuffer, uint32_t* ulen, const char* pfilename, const filecryption_callback_t* pcallback, eRvcCryptionVersion eversion);
  44. // pheadbuffer从自定义的文件头的字段3,文件加密版本标识初开始
  45. int get_rvc_file_header_info(rvc_fileheader_t* pdata, char* pheadbuffer, uint32_t ulen, const filecryption_callback_t* pcallback);
  46. int fill_tag_buffer(char* pbuffer, uint32_t ubuffersize, const char* pdata, uint32_t udatalen);
  47. int get_tag_value_from_buffer(char* pbuffer, uint32_t ubuffersize, const char* pdata, uint32_t udatalen);
  48. int get_key_from_header_info(unsigned char* pkey, uint32_t ukeysize, char* pheader, uint32_t udatalen, const filecryption_callback_t* pcallback);