---------------------------------
// An application will call on the object provider with the GET function when
// the application needs an object. The name blob uniquely identifies the content
// to return. This function can return an identifier data blob. Subsequent calls
// to this function for the same object will pass in the identifier that was previously
// returned. The identifier does not need to uniquely identify a particular object.
//
// pPluginContext
//    This is the context that is returned by the object locator provider when
//    it is initialized. 
//
// pIdentifier
//    This is the identifier that was returned on a previous GET call for this object.
//    On the first call for a particular object it is always NULL.
//
// dwNameType, pNameBlob
//    The name the application is using for the object. The name will uniquely identify
//    an object.
//
// ppContent, pcbContent
//    The returned object.
//
// ppwszPassword
//    If the returned object is a pfx then this is the password for the pfx.
//
// ppIdentifier
//    The identifier for the object.
//--------------------------------------------------------------------------
_Success_(return != 0)
typedef BOOL (WINAPI *PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET)(
    _In_opt_ LPVOID pPluginContext,
    _In_opt_ PCRYPT_DATA_BLOB pIdentifier,
    _In_ DWORD dwNameType,
    _In_ PCERT_NAME_BLOB pNameBlob,
    _Outptr_result_bytebuffer_(*pcbContent) PBYTE *ppbContent,
    _Out_ DWORD *pcbContent,
    _Outptr_result_maybenull_ PCWSTR *ppwszPassword,
    _Outptr_result_maybenull_ PCRYPT_DATA_BLOB *ppIdentifier);


//--------------------------------------------------------------------------
// The application has indicated it no longer needs to locate objects by
// calling this release function.
//
// dwReason
//   Can be one of:
//       CRYPT_OBJECT_LOCATOR_RELEASE_SYSTEM_SHUTDOWN
//       CRYPT_OBJECT_LOCATOR_RELEASE_SERVICE_STOP 
//       CRYPT_OBJECT_LOCATOR_RELEASE_PROCESS_EXIT
//       CRYPT_OBJECT_LOCATOR_RELEASE_DLL_UNLOAD
//
//  pPluginContext
//    This is the context that is returned by the object locator provider when
//    it is initialized. 
//--------------------------------------------------------------------------
typedef void (WINAPI * PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_RELEASE)(
    _In_ DWORD dwReason,
    _In_opt_ LPVOID pPluginContext);


//--------------------------------------------------------------------------
// If the PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET function returns a password
// that is non-NULL then this function will be called to release the memory.
// Best practice is to zero the memory before releasing it.
//
//  pPluginContext
//    This is the context that is returned by the object locator provider when
//    it is initialized. 
//
//  pwszPassword
//    Password obtained from PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET
//--------------------------------------------------------------------------
typedef void (WINAPI *PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_PASSWORD)(
    _In_opt_ LPVOID pPluginContext,
    _In_ PCWSTR pwszPassword
);


//--------------------------------------------------------------------------
// The content returned by the PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET function
// is released using this function.
//
//  pPluginContext
//    This is the context that is returned by the object locator provider when
//    it is initialized. 
//
//  pbData
//    Content returned by the GET function.
//--------------------------------------------------------------------------
typedef void (WINAPI *PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE)(
    _In_opt_ LPVOID pPluginContext,
    _In_  PBYTE pbData
);


//--------------------------------------------------------------------------
//
// The identifier returned by the PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET function
// is released with this function. This will be called only if the identifier is 
// non-NULL.
// The identifier will be released when the application no longer needs the
// object that was returned by the GET call.
//
// pPluginContext
//    This is the context that is returned by the object locator provider when
//    it is initialized. 
//
// pIdentifier
//    Identifier returned by the GET function.
//--------------------------------------------------------------------------
typedef void (WINAPI *PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_IDENTIFIER)(
    _In_opt_ LPVOID pPluginContext,
    _In_ PCRYPT_DATA_BLOB pIdentifier);


typedef struct _CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE
{
    _Field_range_(sizeof(CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE), sizeof(CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE)) DWORD cbSize;
    PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_GET pfnGet;
    PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_RELEASE pfnRelease;
    PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_PASSWORD pfnFreePassword;
    PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE pfnFree;
    PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FREE_IDENTIFIER pfnFreeIdentifier;
} CRYPT_OBJECT_LOCATOR_PROVIDER_TABLE, *PCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE;


//--------------------------------------------------------------------------
//
// This is the initialization function of the object locator provider.
// 
// pfnFlush
//    This is the function which the provider must call when it detects that
//    an object has changed and the calling application should know about it
//    to prevent stale copies of the object from being used.
//
// pContext
//    This context is passed to the intialization function. The provider
//    is expected to hold onto this context and pass it back with the call
//    call to the flush function
//
// pdwExpectedObjectCount
//    The number of objects that the provider expects it will need to locate.
//    This number will determine the size of a hash table used internally.
//
// pFuncTable
//    A structure that describes a set of callback functions which can be used
//    to get objects and free objects.
//
// ppPluginContext
//    Extra information that the provider can return in its initialize call which
//    will be passed back to each of the subsequent callback functions.
//--------------------------------------------------------------------------
_Success_(return != 0)
typedef BOOL (WINAPI *PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_INITIALIZE)(
    _In_ PFN_CRYPT_OBJECT_LOCATOR_PROVIDER_FLUSH pfnFlush,
    _In_ LPVOID pContext,
    _Out_ DWORD *pdwExpectedObjectCount,
    _Outptr_ PCRYPT_OBJECT_LOCATOR_PROVIDER_TABLE *ppFuncTable,
    _Outptr_result_maybenull_ void **ppPluginContext);


//
// If pTimeStamp is NULL or zero time, then, current time is used.
// For CERT_TIMESTAMP_HASH_USE_TYPE, current time is always used.
//
// If pSignerChainContext is NULL, then, checks if weak hash has
// been disabled for the more restrictive Third Party Chain. If TRUE
// is returned, then, this API must be called again with a nonNULL
// pSignerChainContext which might return FALSE for logging only or
// if this isn't a Third Party Chain and weak hash hasn't been disabled for
// all signers.
//
// For CERT_TIMESTAMP_HASH_USE_TYPE, this should be the file signer and
// not the timestamp chain signer.
//
// The following WinVerifyTrust dwProvFlags map to the corresponding
// dwChainFlags:
//  WTD_DISABLE_MD2_MD4 -> CERT_CHAIN_DISABLE_MD2_MD4
//  WTD_MOTW -> CERT_CHAIN_HAS_MOTW
//

WINCRYPT32API
BOOL
WINAPI
CertIsWeakHash(
    _In_ DWORD dwHashUseType,
    _In_ LPCWSTR pwszCNGHashAlgid,
    _In_ DWORD dwChainFlags,
    _In_opt_ PCCERT_CHAIN_CONTEXT pSignerChainContext,
    _In_opt_ LPFILETIME pTimeStamp,
    _In_opt_ LPCWSTR pwszFileName
    );

typedef WINCRYPT32API BOOL (WINAPI *PFN_CERT_IS_WEAK_HASH)(
    _In_ DWORD dwHashUseType,
    _In_ LPCWSTR pwszCNGHashAlgid,
    _In_ DWORD dwChainFlags,
    _In_opt_ PCCERT_CHAIN_CONTEXT pSignerChainContext,
    _In_opt_ LPFILETIME pTimeStamp,
    _In_opt_ LPCWSTR pwszFileName
    );


//
// Hash Use Types
//

#define CERT_FILE_HASH_USE_TYPE             1
#define CERT_TIMESTAMP_HASH_USE_TYPE        2


#endif // (NTDDI_VERSION >= NTDDI_WIN8)

#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP|WINAPI_PARTITION_PHONE_RESTRICTED | WINAPI_PARTITION_SYSTEM) */
#pragma endregion

#endif //!defined(_DDK_DRIVER_)

#ifdef __cplusplus
}       // Balance extern "C" above
#endif

#if defined (_MSC_VER)
#if ( _MSC_VER >= 800 )
#if _MSC_VER >= 1200
#pragma warning(pop)
#else
#pragma warning(default:4201)
#endif
#endif
#endif

#pragma region Desktop Family or OneCore Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)

//
// The following headers are refactored out of WinCrypt.h,
// reflecting the separate binaries.
// Applications which do not depend on all functionality of CRYPT32 etc.,
// can link directly to smaller binaries using smaller headers also.
//

#ifndef _WINCRYPT_NO_DPAPI
#include <dpapi.h>
#endif

#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */
#pragma endregion

#endif // __WINCRYPT_H__
