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.

80 lines
2.6 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 2000
  6. //
  7. // File: nonce.h
  8. //
  9. // Contents: Constants for the Nonce Generator/Validator
  10. //
  11. // History:
  12. // KDamour 21Mar00 Created
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef NTDIGEST_NONCE_H
  16. #define NTDIGEST_NONCE_H
  17. #include <wincrypt.h>
  18. // Handle into the CryptoAPI
  19. extern HCRYPTPROV g_hCryptProv;
  20. extern WORD g_SupportedCrypto;
  21. extern char *pbSeparator; // the COLON separator
  22. // NONCE FORMAT
  23. // rand-data = rand[16]
  24. // nonce_binary = time-stamp rand-data H(time-stamp ":" rand-data ":" nonce_private_key)
  25. // nonce = hex(nonce_binary)
  26. // SIZE implies number of ASCII chars
  27. // BYTESIZE is the number of bytes of Data (binary)
  28. #define NONCE_PRIVATE_KEY_BYTESIZE 16 // Generate 128 bit random private key
  29. #define RANDDATA_BYTESIZE 16 // # of random bytes at beginning of nonce
  30. #define TIMESTAMP_BYTESIZE sizeof(time_t) // size of timestamp in nonce binary 8 bytes
  31. #define MD5_HASH_BYTESIZE 16 // MD5 hash size
  32. #define MD5_HASH_HEX_SIZE (2*MD5_HASH_BYTESIZE) // BYTES needed to store a Hash as hex Encoded
  33. // For Hex encoding need 2chars per byte encoded
  34. #define NONCE_SIZE ((2*TIMESTAMP_BYTESIZE) + (2*RANDDATA_BYTESIZE) + (2*MD5_HASH_BYTESIZE))
  35. #define NONCE_TIME_LOC 0
  36. #define NONCE_RANDDATA_LOC (2 * TIMESTAMP_BYTESIZE)
  37. #define NONCE_HASH_LOC (NONCE_RANDDATA_LOC + (2 * RANDDATA_BYTESIZE))
  38. #define OPAQUE_RANDATA_SIZE 16 // Make 128bits of rand data for reference
  39. #define OPAQUE_SIZE (OPAQUE_RANDATA_SIZE * 2)
  40. #define MAX_URL_SIZE 512
  41. NTSTATUS NTAPI NonceInitialize(VOID);
  42. NTSTATUS NTAPI NonceCreate(OUT PSTRING pstrNonce);
  43. // Primary function to call to check validity of a nonce
  44. NTSTATUS NonceIsValid(PSTRING pstrNonce);
  45. // Helper function for NonceIsValid to check if time expired
  46. BOOL NonceIsExpired(PSTRING pstrNonce);
  47. // Helper function for NonceIsValid to check if Hash is correct
  48. BOOL NonceIsTampered(PSTRING pstrNonce);
  49. BOOL HashData(BYTE *pbData, DWORD cbData, BYTE *pbHash );
  50. // Create the Hash for the Nonce Parameters
  51. NTSTATUS NTAPI NonceHash( IN LPBYTE pbTime, IN DWORD cbTime,
  52. IN LPBYTE pbRandom, IN DWORD cbRandom,
  53. IN LPBYTE pbKey, IN DWORD cbKey,
  54. OUT LPBYTE pbHash);
  55. NTSTATUS NTAPI OpaqueCreate(IN OUT PSTRING pstrOpaque);
  56. // Set the bitmask for the supported crypto CSP installed
  57. NTSTATUS NTAPI SetSupportedCrypto(VOID);
  58. #endif