Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.4 KiB

  1. /* dh_key.h */
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #define DH_MAX_LENGTH 0x00000200 // in bytes, 512 bytes, 4096 bits
  6. #define DH_KEYSIZE_INC 0x40
  7. /*********************************/
  8. /* Definitions */
  9. /*********************************/
  10. #define DH_PUBLIC_MAGIC 0x31484400
  11. #define DH_PRIVATE_MAGIC 0x32484400
  12. #define DH_PUBLIC_MAGIC_VER3 0x33484400
  13. #define DH_PRIV_MAGIC_VER3 0x34484400
  14. /*********************************/
  15. /* Structure Definitions */
  16. /*********************************/
  17. typedef dsa_private_t DHKey_t; // use a DSA key since X 9.42 requires key
  18. // gen like DSA
  19. /*
  20. typedef struct {
  21. ALG_ID Algid; // algorithm type of the key (SF or EPHEM)
  22. DH_PRIV_KEY Priv;
  23. } DHKey_t;
  24. */
  25. /*********************************/
  26. /* Function Definitions */
  27. /*********************************/
  28. // Initialize DH key
  29. DWORD
  30. initKeyDH(
  31. IN Context_t *pContext,
  32. IN OUT DHKey_t *pDH,
  33. IN ALG_ID Algid,
  34. IN DWORD dwFlags,
  35. IN BOOL fAnyLength);
  36. DHKey_t *allocDHKey ();
  37. void freeKeyDH (DHKey_t *dh);
  38. // Get the DH parameters
  39. DWORD getDHParams (
  40. IN DHKey_t *dh,
  41. IN DWORD param,
  42. OUT BYTE *data,
  43. OUT DWORD *len
  44. );
  45. // Set the DH parameters
  46. DWORD setDHParams (
  47. IN OUT DHKey_t *pDH,
  48. IN DWORD dwParam,
  49. IN CONST BYTE *pbData,
  50. IN OUT Context_t *pContext
  51. );
  52. // Generate a dh key
  53. DWORD dhGenerateKey (
  54. IN Context_t *pContext,
  55. IN OUT DHKey_t *pDH);
  56. DWORD dhDeriveKey (DHKey_t *dh, BYTE *data, DWORD len);
  57. // Export the DH key in blob format
  58. DWORD exportDHKey (
  59. IN Context_t *pContext,
  60. IN DHKey_t *pDH,
  61. IN ALG_ID Algid,
  62. IN DWORD dwFlags,
  63. IN DWORD dwReserved,
  64. IN DWORD dwBlobType,
  65. OUT BYTE *pbData,
  66. OUT DWORD *pcbData,
  67. IN BOOL fInternal
  68. );
  69. DWORD DHPrivBlobToKey(
  70. IN Context_t *pContext,
  71. IN BLOBHEADER *pBlob,
  72. IN DWORD cbBlob,
  73. IN DWORD dwKeysetType,
  74. OUT Key_t *pPrivKey
  75. );
  76. // Import the blob into DH key
  77. DWORD importDHKey(
  78. IN OUT Key_t *pPrivKey,
  79. IN Context_t *pContext,
  80. IN BYTE *pbBlob,
  81. IN DWORD cbBlob,
  82. OUT Key_t *pKey,
  83. IN DWORD dwKeysetType,
  84. IN BOOL fInternal
  85. );
  86. void copyDHPubKey(
  87. IN DHKey_t *pDH1,
  88. IN DHKey_t *pDH2
  89. );
  90. DWORD copyDHKey(
  91. IN DHKey_t *pDH1,
  92. IN DHKey_t *pDH2,
  93. IN ALG_ID Algid,
  94. IN Context_t *pContext
  95. );
  96. //
  97. // Function : UseDHKey
  98. //
  99. // Description : This function creates an ephemeral DH key and then generates
  100. // two agreed keys, thus simulating a DH exchange. If the
  101. // agreed keys are not the same then the function fails.
  102. //
  103. DWORD UseDHKey(
  104. IN Context_t *pContext,
  105. IN PEXPO_OFFLOAD_STRUCT pOffloadInfo,
  106. IN DHKey_t *pDH
  107. );
  108. #ifdef __cplusplus
  109. }
  110. #endif