RVCCrypt.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #ifdef RVCCRYPT_EXPORTS
  2. #define RVCCRYPT_API __declspec(dllexport)
  3. #else
  4. #define RVCCRYPT_API __declspec(dllimport)
  5. #endif
  6. #ifndef WINAPI
  7. #define WINAPI __stdcall
  8. #endif
  9. #define PUKFILENAME_RSA "RVCPubKey.ini"
  10. #define PUKFILENAME_SM2 "RVCSM2PubKey.ini"
  11. #define PFKEYFILENAME_DES "CMBRVCKeys.dat"
  12. #define PFKEYFILENAME_SM4 "CMBRVCSm4Keys.dat"
  13. typedef enum {
  14. cKEK = 0,
  15. cTMK = 1,
  16. cTPK = 2,
  17. cEDK = 4,
  18. csKEK = 5,
  19. csTMK = 6,
  20. csTPK = 7,
  21. csEDK = 9
  22. } TWKKeyType;
  23. #define TMK_LEN 32
  24. #define EDK_LEN 32
  25. #define TPK_LEN 32
  26. #define TMK_CHK_LEN 8
  27. #define EDK_CHK_LEN 8
  28. #define TPK_CHK_LEN 8
  29. typedef enum {
  30. TMK, TMKCHK, TPK, TPKCHK, EDK, EDKCHK, FIELDS
  31. } KeyType;
  32. typedef enum {
  33. DES, SM4, DES_SM4, NO_ALG
  34. } ALGType;
  35. typedef struct _EncKeys EncKeys;
  36. #ifdef __cplusplus
  37. extern "C"{
  38. #endif
  39. RVCCRYPT_API int WINAPI Init(const char* szKeyFileDirBuf,int nKeyFileDirBufLen, int algFlag);
  40. RVCCRYPT_API int WINAPI Release();
  41. RVCCRYPT_API int WINAPI CreateInitTMKReq(char* pOutBuf,int* pOutBufLen);
  42. RVCCRYPT_API int WINAPI CreateInitSMTMKReq(char* pOutBuf,int* pOutBufLen);
  43. RVCCRYPT_API int WINAPI ParseTMKRes(char * pTMKRes,int nTMKResLen);
  44. RVCCRYPT_API int WINAPI ParseSMTMKRes(char * pTMKRes,int nTMKResLen);
  45. RVCCRYPT_API int WINAPI CreateUpdateReq(char* pOutBuf,int* pOutBufLen, int algFlag);
  46. RVCCRYPT_API int WINAPI ParseUpdateRes(char* pUpdateRes,int nUpdateResLen, int algFlag);
  47. RVCCRYPT_API int WINAPI GetKey(char* pOutKeyBuf, int *pOutKeyBufLen, char *pOutChkBuf, int *pOutChkBufLen, TWKKeyType tKeyType);
  48. RVCCRYPT_API int WINAPI GetLastErrorMsg(char * pOutMsgBuf, int* pOutMsgBufLen);
  49. ///*
  50. // return value: 0 success
  51. // Input: szRSAKeyBuf RSA public key string
  52. // nRSAKeyBufLen RSA public key string length
  53. // szSM2KeyBuf RSA public key string
  54. // nSM2KeyBufLen RSA public key string length
  55. // logDir log dir
  56. // algFlag des/sm4/des_sm4
  57. // */
  58. //RVCCRYPT_API int WINAPI Init(const char* szRSAKeyBuf, int nRSAKeyBufLen, const char* szSM2KeyBuf, int nSM2KeyBufLen, char* logDir, int algFlag);
  59. //
  60. ///*
  61. // return Value: 0 success
  62. // input: algFlag des/sm4
  63. // output: pTMKRequest tmk init request
  64. // pTMKRequestLen buffer length
  65. //*/
  66. //RVCCRYPT_API int WINAPI CreateInitTMKReq(int algFlag, char* pTMKRequest, int* pTMKRequestLen);
  67. //
  68. ///*
  69. // return value: 0 success
  70. // input: pTMKRes tmk response
  71. // nTMKResLen buffer length
  72. // algFlag des/sm4
  73. // output: pKeys tmk & other keys
  74. // pTmk tmk value
  75. // pTmkLen tmk len
  76. //*/
  77. //RVCCRYPT_API int WINAPI ParseTMKRes(char *pTMKRes, int nTMKResLen, int algFlag, char* pTmk, int* pTmkLen, EncKeys **pKeys);
  78. //
  79. ///*
  80. //return Value: 0 success
  81. //input: pKeyChk tmk check value
  82. // algFlag des/sm4
  83. //output: pUpdateRequest update request
  84. // pUpdateRequestLen buffer length
  85. //*/
  86. //RVCCRYPT_API int WINAPI CreateUpdateReq(char *pKeyChk, int algFlag, char* pUpdateRequest, int* pUpdateRequestLen);
  87. //
  88. ///*
  89. // Return Value: 0 success
  90. // input: pUpdateRes update response
  91. // nUpdateResLen buffer length
  92. // algFlag des/sm4
  93. // output: pKeys work keys
  94. //*/
  95. //RVCCRYPT_API int WINAPI ParseUpdateRes(char* pUpdateRes, int nUpdateResLen, int algFlag, EncKeys **pKeys);
  96. //
  97. ///*
  98. // Return Value: addr of keybuf
  99. // input: pKeys struct EncKeys
  100. // type tmk/tmkchk...
  101. // output: keybuf key value or check value
  102. //*/
  103. //RVCCRYPT_API char* WINAPI GetKey(EncKeys *pKeys, KeyType type, char* keybuf);
  104. ///*
  105. // Return Value: 0 success
  106. // input: pKeys struct EncKeys
  107. //*/
  108. //RVCCRYPT_API int Close(EncKeys *pKeys);
  109. //
  110. //RVCCRYPT_API int WINAPI GetLastErrorMsg(char* pOutMsgBuf, int* pOutMsgBufLen);
  111. //RVCCRYPT_API int WINAPI Release();
  112. /*
  113. return value: 0 success
  114. Input: szRSAKeyBuf RSA public key string
  115. nRSAKeyBufLen RSA public key string length
  116. szSM2KeyBuf RSA public key string
  117. nSM2KeyBufLen RSA public key string length
  118. logDir log dir
  119. algFlag des/sm4/des_sm4
  120. */
  121. RVCCRYPT_API int WINAPI RvcInit(const char* szRSAKeyBuf, int nRSAKeyBufLen, const char* szSM2KeyBuf, int nSM2KeyBufLen, char* logDir, int algFlag);
  122. /*
  123. return Value: 0 success
  124. input: algFlag des/sm4
  125. output: pTMKRequest tmk init request
  126. pTMKRequestLen buffer length
  127. */
  128. RVCCRYPT_API int WINAPI RvcCreateInitTMKReq(int algFlag, char* pTMKRequest, int* pTMKRequestLen);
  129. /*
  130. return value: 0 success
  131. input: pTMKRes tmk response
  132. nTMKResLen buffer length
  133. algFlag des/sm4
  134. output: pKeys tmk & other keys
  135. pTmk tmk value
  136. pTmkLen tmk len
  137. */
  138. RVCCRYPT_API int WINAPI RvcParseTMKRes(char *pTMKRes, int nTMKResLen, int algFlag, char* pTmk, int* pTmkLen, EncKeys **pKeys);
  139. /*
  140. return Value: 0 success
  141. input: pKeyChk tmk check value
  142. algFlag des/sm4
  143. output: pUpdateRequest update request
  144. pUpdateRequestLen buffer length
  145. */
  146. RVCCRYPT_API int WINAPI RvcCreateUpdateReq(char *pKeyChk, int algFlag, char* pUpdateRequest, int* pUpdateRequestLen);
  147. /*
  148. Return Value: 0 success
  149. input: pUpdateRes update response
  150. nUpdateResLen buffer length
  151. algFlag des/sm4
  152. output: pKeys work keys
  153. */
  154. RVCCRYPT_API int WINAPI RvcParseUpdateRes(char* pUpdateRes, int nUpdateResLen, int algFlag, EncKeys **pKeys);
  155. /*
  156. Return Value: addr of keybuf
  157. input: pKeys struct EncKeys
  158. type tmk/tmkchk...
  159. output: keybuf key value or check value
  160. */
  161. RVCCRYPT_API char* WINAPI RvcGetKey(EncKeys *pKeys, KeyType type, char* keybuf);
  162. /*
  163. Return Value: 0 success
  164. input: pKeys struct EncKeys
  165. */
  166. RVCCRYPT_API int RvcClose(EncKeys *pKeys);
  167. RVCCRYPT_API int WINAPI RvcGetLastErrorMsg(char* pOutMsgBuf, int* pOutMsgBufLen);
  168. RVCCRYPT_API int WINAPI RvcRelease();
  169. #ifdef __cplusplus
  170. }
  171. #endif