Leaked source code of windows server 2003
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.

135 lines
3.7 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. IN ALG_ID AlgId
  52. );
  53. // Generate a dh key
  54. DWORD dhGenerateKey (
  55. IN Context_t *pContext,
  56. IN OUT DHKey_t *pDH,
  57. IN ALG_ID AlgId);
  58. DWORD dhDeriveKey (DHKey_t *dh, BYTE *data, DWORD len);
  59. // Export the DH key in blob format
  60. DWORD exportDHKey (
  61. IN Context_t *pContext,
  62. IN DHKey_t *pDH,
  63. IN ALG_ID Algid,
  64. IN DWORD dwFlags,
  65. IN DWORD dwReserved,
  66. IN DWORD dwBlobType,
  67. OUT BYTE *pbData,
  68. OUT DWORD *pcbData,
  69. IN BOOL fInternal
  70. );
  71. DWORD DHPrivBlobToKey(
  72. IN Context_t *pContext,
  73. IN BLOBHEADER *pBlob,
  74. IN DWORD cbBlob,
  75. IN DWORD dwKeysetType,
  76. OUT Key_t *pPrivKey
  77. );
  78. // Import the blob into DH key
  79. DWORD importDHKey(
  80. IN OUT Key_t *pPrivKey,
  81. IN Context_t *pContext,
  82. IN BYTE *pbBlob,
  83. IN DWORD cbBlob,
  84. OUT Key_t *pKey,
  85. IN DWORD dwKeysetType,
  86. IN BOOL fInternal
  87. );
  88. void copyDHPubKey(
  89. IN DHKey_t *pDH1,
  90. IN DHKey_t *pDH2
  91. );
  92. DWORD copyDHKey(
  93. IN DHKey_t *pDH1,
  94. IN DHKey_t *pDH2,
  95. IN ALG_ID Algid,
  96. IN Context_t *pContext
  97. );
  98. //
  99. // Function : UseDHKey
  100. //
  101. // Description : This function creates an ephemeral DH key and then generates
  102. // two agreed keys, thus simulating a DH exchange. If the
  103. // agreed keys are not the same then the function fails.
  104. //
  105. DWORD UseDHKey(
  106. IN Context_t *pContext,
  107. IN PEXPO_OFFLOAD_STRUCT pOffloadInfo,
  108. IN DHKey_t *pDH
  109. );
  110. #ifdef __cplusplus
  111. }
  112. #endif