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.

146 lines
3.8 KiB

  1. // KeyContext.h -- Key Context class declaration
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #if !defined(SLBCSP_KEYCONTEXT_H)
  8. #define SLBCSP_KEYCONTEXT_H
  9. #include <memory> // for auto_ptr
  10. #include <wincrypt.h>
  11. #include <winscard.h>
  12. #include <handles.h>
  13. #include "AlignedBlob.h"
  14. #include "RsaKey.h"
  15. #define KT_UNDEFINED static_cast<DWORD>(0x00000000)
  16. #define KT_PUBLICKEY static_cast<DWORD>(PUBLICKEYBLOB)
  17. #define KT_SESSIONKEY static_cast<DWORD>(SIMPLEBLOB)
  18. class CKeyContext
  19. : public CHandle
  20. {
  21. public:
  22. // Types
  23. typedef RsaKey::StrengthType StrengthType;
  24. enum
  25. {
  26. Symmetric,
  27. RsaKeyPair
  28. } KeyClass;
  29. // C'tors/D'tors
  30. virtual
  31. ~CKeyContext();
  32. // Operators
  33. // Operations
  34. virtual std::auto_ptr<CKeyContext>
  35. Clone(DWORD const *pdwReserved,
  36. DWORD dwFlags) const = 0;
  37. virtual void
  38. Close();
  39. virtual void
  40. Decrypt(HCRYPTHASH hAuxHash,
  41. BOOL fFinal,
  42. DWORD dwFlags,
  43. BYTE *pbData,
  44. DWORD *pdwDataLen);
  45. virtual void
  46. Encrypt(HCRYPTHASH hAuxHash,
  47. BOOL fFinal,
  48. DWORD dwFlags,
  49. BYTE *pbData,
  50. DWORD *pdwDataLen,
  51. DWORD dwBufLen);
  52. virtual void
  53. Generate(ALG_ID AlgoId,
  54. DWORD dwFlags) = 0;
  55. virtual void
  56. ImportToAuxCSP() = 0;
  57. // Access
  58. virtual AlignedBlob
  59. AsAlignedBlob(HCRYPTKEY hcryptkey,
  60. DWORD dwBlobType) const = 0;
  61. HCRYPTKEY
  62. GetKey() const;
  63. virtual HCRYPTKEY
  64. KeyHandleInAuxCSP();
  65. virtual StrengthType
  66. MaxStrength() const = 0;
  67. virtual StrengthType
  68. MinStrength() const = 0;
  69. virtual DWORD
  70. TypeOfKey() const;
  71. // Predicates
  72. protected:
  73. // Types
  74. // C'tors/D'tors
  75. CKeyContext(HCRYPTPROV hProv,
  76. DWORD dwTypeOfKey = KT_UNDEFINED);
  77. // Duplicate the key and its state
  78. CKeyContext(CKeyContext const &rhs,
  79. DWORD const *pdwReserved,
  80. DWORD dwFlags);
  81. // Operators
  82. // Operations
  83. // Access
  84. HCRYPTPROV
  85. AuxProvider() const;
  86. // Predicates
  87. // Variables
  88. HCRYPTKEY m_hKey;
  89. std::auto_ptr<AlignedBlob> m_apabKey;
  90. private:
  91. // Types
  92. // C'tors/D'tors
  93. // not defined, copying not allowed
  94. CKeyContext(CKeyContext const &rkctx);
  95. // Operators
  96. // not defined, initializing not allowed
  97. CKeyContext &
  98. operator=(CKeyContext const &rkctx);
  99. // Operations
  100. // Access
  101. // Predicates
  102. // Variables
  103. DWORD const m_dwTypeOfKey;
  104. HCRYPTPROV const m_hAuxProvider;
  105. };
  106. #endif // SLBCSP_KEYCONTEXT_H