BCryptEnumContextFunctionProviders function (bcrypt.h)
The BCryptEnumContextFunctionProviders function obtains the providers for the cryptographic functions for a context in the specified configuration table.
Syntax
NTSTATUS BCryptEnumContextFunctionProviders(
[in] ULONG dwTable,
[in] LPCWSTR pszContext,
[in] ULONG dwInterface,
[in] LPCWSTR pszFunction,
[in, out] ULONG *pcbBuffer,
[in, out] PCRYPT_CONTEXT_FUNCTION_PROVIDERS *ppBuffer
);
Parameters
[in] dwTable
Identifies the configuration table from which to retrieve the context function providers. This can be one of the following values.
Value | Meaning |
---|---|
|
Retrieve the context functions from the local-machine configuration table. |
|
This value is not available for use. |
[in] pszContext
A pointer to a null-terminated Unicode string that contains the identifier of the context to enumerate the function providers for.
[in] dwInterface
Identifies the cryptographic interface to retrieve the function providers for. This can be one of the following values.
Value | Meaning |
---|---|
|
Retrieve the asymmetric encryption function providers. |
|
Retrieve the cipher function providers. |
|
Retrieve the hash function providers. |
|
Retrieve the random number generator function providers. |
|
Retrieve the secret agreement function providers. |
|
Retrieve the signature function providers. |
|
Retrieve the key storage function providers. |
|
Retrieve the Schannel function providers. |
[in] pszFunction
A pointer to a null-terminated Unicode string that contains the identifier of the function to enumerate the providers for.
[in, out] pcbBuffer
The address of a ULONG variable that, on entry, contains the size, in bytes, of the buffer pointed to by ppBuffer. If this size is not large enough to hold the set of context identifiers, this function will fail with STATUS_BUFFER_TOO_SMALL.
After this function returns, this value contains the number of bytes that were copied to the ppBuffer buffer.
[in, out] ppBuffer
The address of a pointer to a CRYPT_CONTEXT_FUNCTION_PROVIDERS structure that receives the set of context function providers retrieved by this function. The value pointed to by the pcbBuffer parameter contains the size of this buffer.
If the value pointed to by this parameter is NULL, this function will allocate the required memory. This memory must be freed when it is no longer needed by passing this pointer to the BCryptFreeBuffer function.
If this parameter is NULL, this function will place the required size, in bytes, in the variable pointed to by the pcbBuffer parameter and return STATUS_BUFFER_TOO_SMALL.
Return value
Returns a status code that indicates the success or failure of the function.
Possible return codes include, but are not limited to, the following.
Return code | Description |
---|---|
|
The function was successful. |
|
The ppBuffer parameter is not NULL, and the value pointed to by the pcbBuffer parameter is not large enough to hold the set of contexts. |
|
One or more parameters are not valid. |
|
A memory allocation failure occurred. |
|
No context function providers that match the specified criteria were found. |
Remarks
BCryptEnumContextFunctionProviders can be called only in user mode.
Examples
The following example shows how to use the BCryptEnumContextFunctionProviders function to enumerate the providers for all key storage functions for all contexts in the local-machine configuration table.
#include <windows.h>
#include <stdio.h>
#include <ntstatus.h>
#include <Bcrypt.h>
#pragma comment(lib, "Bcrypt.lib")
#ifndef NT_SUCCESS
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
#endif
NTSTATUS EnumContextFunctionProviders()
{
NTSTATUS status;
ULONG uSize = 0;
ULONG uTable = CRYPT_LOCAL;
PCRYPT_CONTEXTS pContexts = NULL;
// Get the contexts for the local machine.
// CNG will allocate the memory for us.
status = BCryptEnumContexts(uTable, &uSize, &pContexts);
if(NT_SUCCESS(status))
{
// Enumerate the context identifiers.
for(ULONG a = 0;
a < pContexts->cContexts;
a++)
{
ULONG uInterface = NCRYPT_SCHANNEL_INTERFACE;
wprintf(L"Context functions for %s:\n",
pContexts->rgpszContexts[a]);
// Get the functions for this context.
// CNG will allocate the memory for us.
PCRYPT_CONTEXT_FUNCTIONS pContextFunctions = NULL;
status = BCryptEnumContextFunctions(
uTable,
pContexts->rgpszContexts[a],
uInterface,
&uSize,
&pContextFunctions);
if(NT_SUCCESS(status))
{
// Enumerate the functions.
for(ULONG b = 0;
b < pContextFunctions->cFunctions;
b++)
{
wprintf(L"\tFunction providers for %s:\n",
pContextFunctions->rgpszFunctions[b]);
// Get the providers for this function.
PCRYPT_CONTEXT_FUNCTION_PROVIDERS pProviders;
pProviders = NULL;
status = BCryptEnumContextFunctionProviders(
uTable,
pContexts->rgpszContexts[a],
uInterface,
pContextFunctions->rgpszFunctions[b],
&uSize,
&pProviders);
if(NT_SUCCESS(status))
{
for(ULONG c = 0;
c < pProviders->cProviders;
c++)
{
wprintf(L"\t\t%s\n",
pProviders->rgpszProviders[c]);
}
}
else if(STATUS_NOT_FOUND == status)
{
wprintf(L"\t\tNone found.\n");
}
}
// Free the context functions buffer.
BCryptFreeBuffer(pContextFunctions);
}
}
// Free the contexts buffer.
BCryptFreeBuffer(pContexts);
}
return status;
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows Vista [desktop apps only] |
Minimum supported server | Windows Server 2008 [desktop apps only] |
Target Platform | Windows |
Header | bcrypt.h |
Library | Bcrypt.lib |
DLL | Bcrypt.dll |