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.

78 lines
1.6 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: pkcrypto.h
  4. //
  5. // Microsoft Digital Rights Management
  6. // Copyright (C) 1998-1999 Microsoft Corporation, All Rights Reserved
  7. //
  8. // Description:
  9. // public key crypto library
  10. //
  11. // Author: marcuspe
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DRMPKCRYPTO_H__
  15. #define __DRMPKCRYPTO_H__
  16. /*
  17. #ifdef USER_MODE
  18. #include <wtypes.h>
  19. #else
  20. #define S_OK 0
  21. #define E_FAIL 1
  22. #define E_INVALIDARG 2
  23. #define CHAR_BIT 8
  24. #endif
  25. */
  26. #define LNGQDW 5
  27. /*
  28. typedef struct {
  29. DWORD y[2*LNGQDW];
  30. } PUBKEY;
  31. typedef struct {
  32. DWORD x[LNGQDW];
  33. } PRIVKEY;
  34. */
  35. #define PK_ENC_PUBLIC_KEY_LEN (2 * LNGQDW * sizeof(DWORD))
  36. #define PK_ENC_PRIVATE_KEY_LEN ( LNGQDW * sizeof(DWORD))
  37. #define PK_ENC_PLAINTEXT_LEN ((LNGQDW-1) * sizeof(DWORD))
  38. #define PK_ENC_CIPHERTEXT_LEN (4 * LNGQDW * sizeof(DWORD))
  39. #define PK_ENC_SIGNATURE_LEN (2 * LNGQDW * sizeof(DWORD))
  40. typedef struct {
  41. BYTE y[ PK_ENC_PUBLIC_KEY_LEN ];
  42. } PUBKEY;
  43. typedef struct {
  44. BYTE x[ PK_ENC_PRIVATE_KEY_LEN ];
  45. } PRIVKEY;
  46. class CDRMPKCrypto {
  47. private:
  48. char *pkd;
  49. public:
  50. CDRMPKCrypto();
  51. ~CDRMPKCrypto();
  52. HRESULT PKinit();
  53. HRESULT PKencrypt( PUBKEY *pk, BYTE *in, BYTE *out );
  54. HRESULT PKdecrypt( PRIVKEY *pk, BYTE *in, BYTE *out );
  55. HRESULT PKsign( PRIVKEY *privkey, BYTE *buffer, DWORD lbuf, BYTE *sign );
  56. BOOL PKverify( PUBKEY *pubkey, BYTE *buffer, DWORD lbuf, BYTE *sign );
  57. HRESULT PKGenKeyPair( PUBKEY *pPub, PRIVKEY *pPriv );
  58. };
  59. extern "C" {
  60. extern void random_bytes(BYTE*, DWORD);
  61. };
  62. #endif