' ########################################################################################
' Microsoft Windows
' File: bcrypt.inc
' Contents: Cryptographic Primitive API Prototypes and Definitions
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_bcrypt_PBI)
#DEFINE PBX_bcrypt_PBI
%EQUATE `BCRYPT_INC = 1
'#ifndef _NTDEF_
'typedef __success(return >= 0) LONG NTSTATUS;
'typedef NTSTATUS *PNTSTATUS;
'#endif
'#ifndef BCRYPT_SUCCESS
'#define BCRYPT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
'#endif
#IF NOT %DEF(%BCRYPT_SUCCESS)
%EQUATE `BCRYPT_SUCCESS = 1
FUNCTION BCRYPT_SUCCESS (BYVAL nStatus AS LONG) AS LONG
 FUNCTION = -(nStatus >= 0)
END FUNCTION
#ENDIF
'//
'// Alignment macros
'//
'//
'// BCRYPT_OBJECT_ALIGNMENT must be a power of 2
'// We align all our internal data structures to 16 to
'// allow fast XMM memory accesses.
'// BCrypt callers do not need to take any alignment precautions.
'//
%EQUATE `BCRYPT_OBJECT_ALIGNMENT = 16
'//
'// BCRYPT_STRUCT_ALIGNMENT is an alignment macro that we no longer use.
'// It used to align declspec(align(4)) on x86 and declspec(align(8)) on x64/ia64 but
'// all structures that used it contained a pointer so they were already 4/8 aligned.
'//
'#define BCRYPT_STRUCT_ALIGNMENT
'//
'// DeriveKey KDF Types
'//
$$BCRYPT_KDF_HASH = "HASH"$$
$$BCRYPT_KDF_HMAC = "HMAC"$$
$$BCRYPT_KDF_TLS_PRF = "TLS_PRF"$$
$$BCRYPT_KDF_SP80056A_CONCAT = "SP800_56A_CONCAT"$$
'//
'// DeriveKey KDF BufferTypes
'//
'// For BCRYPT_KDF_HASH and BCRYPT_KDF_HMAC operations, there may be an arbitrary
'// number of KDF_SECRET_PREPEND and KDF_SECRET_APPEND buffertypes in the
'// parameter list. The BufferTypes are processed in order of appearence
'// within the parameter list.
'//
%EQUATE `KDF_HASH_ALGORITHM = &H0
%EQUATE `KDF_SECRET_PREPEND = &H1
%EQUATE `KDF_SECRET_APPEND = &H2
%EQUATE `KDF_HMAC_KEY = &H3
%EQUATE `KDF_TLS_PRF_LABEL = &H4
%EQUATE `KDF_TLS_PRF_SEED = &H5
%EQUATE `KDF_SECRET_HANDLE = &H6
%EQUATE `KDF_TLS_PRF_PROTOCOL = &H7
%EQUATE `KDF_ALGORITHMID = &H8
%EQUATE `KDF_PARTYUINFO = &H9
%EQUATE `KDF_PARTYVINFO = &HA
%EQUATE `KDF_SUPPPUBINFO = &HB
%EQUATE `KDF_SUPPPRIVINFO = &HC
'//
'// DeriveKey Flags:
'//
'// KDF_USE_SECRET_AS_HMAC_KEY_FLAG causes the secret agreement to serve also
'// as the HMAC key. If this flag is used, the KDF_HMAC_KEY parameter should
'// NOT be specified.
'//
%EQUATE `KDF_USE_SECRET_AS_HMAC_KEY_FLAG = &H1
'//
'// BCrypt structs
'//
' // Size = 12 bytes
TYPE BCRYPT_KEY_LENGTHS_STRUCT DWORD
 dwMinLength AS DWORD ' ULONG
 dwMaxLength AS DWORD ' ULONG
 dwIncrement AS DWORD ' ULONG
END TYPE
'typedef BCRYPT_KEY_LENGTHS_STRUCT BCRYPT_AUTH_TAG_LENGTHS_STRUCT;
MACRO BCRYPT_AUTH_TAG_LENGTHS_STRUCT = BCRYPT_KEY_LENGTHS_STRUCT
' // Size = 8 bytes
TYPE BCRYPT_OID DWORD
 cbOID AS DWORD ' ULONG
 pbOID AS BYTE PTR
END TYPE
' // Size = 8 bytes
TYPE BCRYPT_OID_LIST DWORD
 dwOIDCount AS DWORD ' ULONG
 pOIDs AS BCRYPT_OID PTR ' BCRYPT_OID *
END TYPE
' // Size = 4 bytes
TYPE BCRYPT_PKCS1_PADDING_INFO DWORD
 pszAlgId AS WSTRINGZ PTR
END TYPE
' // Size = 8 bytes
TYPE BCRYPT_PSS_PADDING_INFO DWORD
 pszAlgId AS WSTRINGZ PTR
 cbSalt AS DWORD ' ULONG
END TYPE
' // Size = 12 bytes
TYPE BCRYPT_OAEP_PADDING_INFO DWORD
 pszAlgId AS WSTRINGZ PTR
 pbLabel AS BYTE PTR
 cbLabel AS DWORD ' ULONG
END TYPE
%EQUATE `BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION = 1
%EQUATE `BCRYPT_AUTH_MODE_CHAIN_CALLS_FLAG = &H00000001
%EQUATE `BCRYPT_AUTH_MODE_IN_PROGRESS_FLAG = &H00000002
' // Size = 64 bytes
TYPE BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO DWORD
 cbSize AS DWORD ' ULONG
 dwInfoVersion AS DWORD ' ULONG
 pbNonce AS BYTE PTR
 cbNonce AS DWORD ' ULONG
 pbAuthData AS BYTE PTR
 cbAuthData AS DWORD ' ULONG
 pbTag AS BYTE PTR
 cbTag AS DWORD ' ULONG
 pbMacContext AS BYTE PTR
 cbMacContext AS DWORD ' ULONG
 cbAAD AS DWORD ' ULONG
 filler1 AS DWORD ' // To keep QWORD alignment
 cbData AS QUAD ' ULONGLONG
 dwFlags AS DWORD ' ULONG
 filler2 AS DWORD ' // To keep QWORD alignment
END TYPE
'#define BCRYPT_INIT_AUTH_MODE_INFO(_AUTH_INFO_STRUCT_) \
' RtlZeroMemory((&_AUTH_INFO_STRUCT_), sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO)); \
' (_AUTH_INFO_STRUCT_).cbSize = sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO); \
' (_AUTH_INFO_STRUCT_).dwInfoVersion = BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION;
#IF %DEF(%USEPBDECL)
MACRO BCRYPT_INIT_AUTH_MODE_INFO(AUTH_INFO_STRUCT)
 MACROTEMP bacmi
 LOCAL bacmi AS BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO
 LSET AUTH_INFO_STRUCT = STRING$(SIZEOF(AUTH_INFO_STRUCT), 0)
 AUTH_INFO_STRUCT.cbSize = SIZEOF(bacmi)
 AUTH_INFO_STRUCT.dwInfoVersion = %BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION
END MACRO
#ELSE
SUB BCRYPT_INIT_AUTH_MODE_INFO (BYREF bacmi AS BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO)
 bacmi.cbSize = SIZEOF(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO)
 bacmi.dwInfoVersion = %BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION
END SUB
#ENDIF
'//
'// BCrypt String Properties
'//
'// BCrypt(Import/Export)Key BLOB types
$$BCRYPT_OPAQUE_KEY_BLOB = "OpaqueKeyBlob"$$
$$BCRYPT_KEY_DATA_BLOB = "KeyDataBlob"$$
$$BCRYPT_AES_WRAP_KEY_BLOB = "Rfc3565KeyWrapBlob"$$
'// BCryptGetProperty strings
$$BCRYPT_OBJECT_LENGTH = "ObjectLength"$$
$$BCRYPT_ALGORITHM_NAME = "AlgorithmName"$$
$$BCRYPT_PROVIDER_HANDLE = "ProviderHandle"$$
$$BCRYPT_CHAINING_MODE = "ChainingMode"$$
$$BCRYPT_BLOCK_LENGTH = "BlockLength"$$
$$BCRYPT_KEY_LENGTH = "KeyLength"$$
$$BCRYPT_KEY_OBJECT_LENGTH = "KeyObjectLength"$$
$$BCRYPT_KEY_STRENGTH = "KeyStrength"$$
$$BCRYPT_KEY_LENGTHS = "KeyLengths"$$
$$BCRYPT_BLOCK_SIZE_LIST = "BlockSizeList"$$
$$BCRYPT_EFFECTIVE_KEY_LENGTH = "EffectiveKeyLength"$$
$$BCRYPT_HASH_LENGTH = "HashDigestLength"$$
$$BCRYPT_HASH_OID_LIST = "HashOIDList"$$
$$BCRYPT_PADDING_SCHEMES = "PaddingSchemes"$$
$$BCRYPT_SIGNATURE_LENGTH = "SignatureLength"$$
$$BCRYPT_HASH_BLOCK_LENGTH = "HashBlockLength"$$
$$BCRYPT_AUTH_TAG_LENGTH = "AuthTagLength"$$
$$BCRYPT_PRIMITIVE_TYPE = "PrimitiveType"$$
$$BCRYPT_IS_KEYED_HASH = "IsKeyedHash"$$
'// BCryptSetProperty strings
'#define BCRYPT_INITIALIZATION_VECTOR L"IV"
$$BCRYPT_INITIALIZATION_VECTOR = "IV"$$
'// Property Strings
$$BCRYPT_CHAIN_MODE_NA = "ChainingModeN/A"$$
$$BCRYPT_CHAIN_MODE_CBC = "ChainingModeCBC"$$
$$BCRYPT_CHAIN_MODE_ECB = "ChainingModeECB"$$
$$BCRYPT_CHAIN_MODE_CFB = "ChainingModeCFB"$$
$$BCRYPT_CHAIN_MODE_CCM = "ChainingModeCCM"$$
$$BCRYPT_CHAIN_MODE_GCM = "ChainingModeGCM"$$
'// Supported RSA Padding Types
%EQUATE `BCRYPT_SUPPORTED_PAD_ROUTER = &H00000001
%EQUATE `BCRYPT_SUPPORTED_PAD_PKCS1_ENC = &H00000002
%EQUATE `BCRYPT_SUPPORTED_PAD_PKCS1_SIG = &H00000004
%EQUATE `BCRYPT_SUPPORTED_PAD_OAEP = &H00000008
%EQUATE `BCRYPT_SUPPORTED_PAD_PSS = &H00000010
'//
'// BCrypt Flags
'//
%EQUATE `BCRYPT_PROV_DISPATCH = &H00000001 ' // BCryptOpenAlgorithmProvider
%EQUATE `BCRYPT_BLOCK_PADDING = &H00000001 ' // BCryptEncrypt/Decrypt
'// RSA padding schemes
%EQUATE `BCRYPT_PAD_NONE = &H00000001
%EQUATE `BCRYPT_PAD_PKCS1 = &H00000002 ' // BCryptEncrypt/Decrypt BCryptSignHash/VerifySignature
%EQUATE `BCRYPT_PAD_OAEP = &H00000004 ' // BCryptEncrypt/Decrypt
%EQUATE `BCRYPT_PAD_PSS = &H00000008 ' // BCryptSignHash/VerifySignature
%EQUATE `BCRYPTBUFFER_VERSION = 0
' // Size = 12 bytes
TYPE BCryptBuffer DWORD
 cbBuffer AS DWORD ' ULONG // Length of buffer, in bytes
 BufferType AS DWORD ' ULONG // Buffer type
 pvBuffer AS DWORD ' PVOID // Pointer to buffer
END TYPE
' // Size = 12 bytes
TYPE BCryptBufferDesc DWORD
 ulVersion AS DWORD ' ULONG // Version number
 cBuffers AS DWORD ' ULONG // Number of buffers
 pBuffers AS BCryptBuffer PTR ' PBCryptBuffer // Pointer to array of buffers
END TYPE
'//
'// Primitive handles
'//
'typedef PVOID BCRYPT_HANDLE;
'typedef PVOID BCRYPT_ALG_HANDLE;
'typedef PVOID BCRYPT_KEY_HANDLE;
'typedef PVOID BCRYPT_HASH_HANDLE;
'typedef PVOID BCRYPT_SECRET_HANDLE;
'//
'// Structures used to represent key blobs.
'//
$$BCRYPT_PUBLIC_KEY_BLOB = "PUBLICBLOB"$$
$$BCRYPT_PRIVATE_KEY_BLOB = "PRIVATEBLOB"$$
' // Size = 4 bytes
TYPE BCRYPT_KEY_BLOB DWORD
 Magic AS DWORD ' ULONG
END TYPE
'// The BCRYPT_RSAPUBLIC_BLOB and BCRYPT_RSAPRIVATE_BLOB blob types are used
'// to transport plaintext RSA keys. These blob types will be supported by
'// all RSA primitive providers.
'// The BCRYPT_RSAPRIVATE_BLOB includes the following values:
'// Public Exponent
'// Modulus
'// Prime1
'// Prime2
$$BCRYPT_RSAPUBLIC_BLOB = "RSAPUBLICBLOB"$$
$$BCRYPT_RSAPRIVATE_BLOB = "RSAPRIVATEBLOB"$$
$$LEGACY_RSAPUBLIC_BLOB = "CAPIPUBLICBLOB"$$
$$LEGACY_RSAPRIVATE_BLOB = "CAPIPRIVATEBLOB"$$
%EQUATE `BCRYPT_RSAPUBLIC_MAGIC = &H31415352 ' // RSA1
%EQUATE `BCRYPT_RSAPRIVATE_MAGIC = &H32415352 ' // RSA2
' // Size = 24 bytes
TYPE BCRYPT_RSAKEY_BLOB DWORD
 Magic AS DWORD ' ULONG
 BitLength AS DWORD ' ULONG
 cbPublicExp AS DWORD ' ULONG
 cbModulus AS DWORD ' ULONG
 cbPrime1 AS DWORD ' ULONG
 cbPrime2 AS DWORD ' ULONG
END TYPE
'// The BCRYPT_RSAFULLPRIVATE_BLOB blob type is used to transport
'// plaintext private RSA keys. It includes the following values:
'// Public Exponent
'// Modulus
'// Prime1
'// Prime2
'// Private Exponent mod (Prime1 - 1)
'// Private Exponent mod (Prime2 - 1)
'// Inverse of Prime2 mod Prime1
'// PrivateExponent
$$BCRYPT_RSAFULLPRIVATE_BLOB = "RSAFULLPRIVATEBLOB"$$
%EQUATE `BCRYPT_RSAFULLPRIVATE_MAGIC = &H33415352 ' // RSA3
'// The BCRYPT_ECCPUBLIC_BLOB and BCRYPT_ECCPRIVATE_BLOB blob types are used
'// to transport plaintext ECC keys. These blob types will be supported by
'// all ECC primitive providers.
$$BCRYPT_ECCPUBLIC_BLOB = "ECCPUBLICBLOB"$$
$$BCRYPT_ECCPRIVATE_BLOB = "ECCPRIVATEBLOB"$$
%EQUATE `BCRYPT_ECDH_PUBLIC_P256_MAGIC = &H314B4345 ' // ECK1
%EQUATE `BCRYPT_ECDH_PRIVATE_P256_MAGIC = &H324B4345 ' // ECK2
%EQUATE `BCRYPT_ECDH_PUBLIC_P384_MAGIC = &H334B4345 ' // ECK3
%EQUATE `BCRYPT_ECDH_PRIVATE_P384_MAGIC = &H344B4345 ' // ECK4
%EQUATE `BCRYPT_ECDH_PUBLIC_P521_MAGIC = &H354B4345 ' // ECK5
%EQUATE `BCRYPT_ECDH_PRIVATE_P521_MAGIC = &H364B4345 ' // ECK6
%EQUATE `BCRYPT_ECDSA_PUBLIC_P256_MAGIC = &H31534345 ' // ECS1
%EQUATE `BCRYPT_ECDSA_PRIVATE_P256_MAGIC = &H32534345 ' // ECS2
%EQUATE `BCRYPT_ECDSA_PUBLIC_P384_MAGIC = &H33534345 ' // ECS3
%EQUATE `BCRYPT_ECDSA_PRIVATE_P384_MAGIC = &H34534345 ' // ECS4
%EQUATE `BCRYPT_ECDSA_PUBLIC_P521_MAGIC = &H35534345 ' // ECS5
%EQUATE `BCRYPT_ECDSA_PRIVATE_P521_MAGIC = &H36534345 ' // ECS6
' // Size = 8 bytes
TYPE BCRYPT_ECCKEY_BLOB
 dwMagic AS DWORD ' ULONG
 cbKey AS DWORD ' ULONG
END TYPE
'// The BCRYPT_DH_PUBLIC_BLOB and BCRYPT_DH_PRIVATE_BLOB blob types are used
'// to transport plaintext DH keys. These blob types will be supported by
'// all DH primitive providers.
$$BCRYPT_DH_PUBLIC_BLOB = "DHPUBLICBLOB"$$
$$BCRYPT_DH_PRIVATE_BLOB = "DHPRIVATEBLOB"$$
$$LEGACY_DH_PUBLIC_BLOB = "CAPIDHPUBLICBLOB"$$
$$LEGACY_DH_PRIVATE_BLOB = "CAPIDHPRIVATEBLOB"$$
%EQUATE `BCRYPT_DH_PUBLIC_MAGIC = &H42504844 ' // DHPB
%EQUATE `BCRYPT_DH_PRIVATE_MAGIC = &H56504844 ' // DHPV
' // Size = 8 bytes
TYPE BCRYPT_DH_KEY_BLOB DWORD
 dwMagic AS DWORD ' ULONG
 cbKey AS DWORD ' ULONG
END TYPE
'// Property Strings for DH
$$BCRYPT_DH_PARAMETERS = "DHParameters"$$
%EQUATE `BCRYPT_DH_PARAMETERS_MAGIC = &H4d504844 ' // DHPM
' // Size = 12 bytes
TYPE BCRYPT_DH_PARAMETER_HEADER DWORD
 cbLength AS DWORD ' ULONG
 dwMagic AS DWORD ' ULONG
 cbKeyLength AS DWORD ' ULONG
END TYPE
'// The BCRYPT_DSA_PUBLIC_BLOB and BCRYPT_DSA_PRIVATE_BLOB blob types are used
'// to transport plaintext DSA keys. These blob types will be supported by
'// all DSA primitive providers.
$$BCRYPT_DSA_PUBLIC_BLOB = "DSAPUBLICBLOB"$$
$$BCRYPT_DSA_PRIVATE_BLOB = "DSAPRIVATEBLOB"$$
$$LEGACY_DSA_PUBLIC_BLOB = "CAPIDSAPUBLICBLOB"$$
$$LEGACY_DSA_PRIVATE_BLOB = "CAPIDSAPRIVATEBLOB"$$
$$LEGACY_DSA_V2_PUBLIC_BLOB = "V2CAPIDSAPUBLICBLOB"$$
$$LEGACY_DSA_V2_PRIVATE_BLOB = "V2CAPIDSAPRIVATEBLOB"$$
%EQUATE `BCRYPT_DSA_PUBLIC_MAGIC = &H42505344 ' // DSPB
%EQUATE `BCRYPT_DSA_PRIVATE_MAGIC = &H56505344 ' // DSPV
' // Size = 52 bytes
TYPE BCRYPT_DSA_KEY_BLOB DWORD
 dwMagic AS DWORD ' ULONG
 cbKey AS DWORD ' ULONG
 Count(3) AS BYTE ' UCHAR[4]
 Seed(19) AS BYTE ' UCHAR[20]
 q(19) AS BYTE ' UCHAR[20]
END TYPE
' // Size = 12 bytes
TYPE BCRYPT_KEY_DATA_BLOB_HEADER DWORD
 dwMagic AS DWORD ' ULONG
 dwVersion AS DWORD ' ULONG
 cbKeyData AS DWORD ' ULONG
END TYPE
%EQUATE `BCRYPT_KEY_DATA_BLOB_MAGIC = &H4d42444b ' //Key Data Blob Magic (KDBM)
%EQUATE `BCRYPT_KEY_DATA_BLOB_VERSION1 = &H1
'// Property Strings for DSA
$$BCRYPT_DSA_PARAMETERS = "DSAParameters"$$
%EQUATE `BCRYPT_DSA_PARAMETERS_MAGIC = &H4d505344 ' // DSPM
' // Size = 56 bytes
TYPE BCRYPT_DSA_PARAMETER_HEADER DWORD
 cbLength AS DWORD ' ULONG
 dwMagic AS DWORD ' ULONG
 cbKeyLength AS DWORD ' ULONG
 Count(3) AS BYTE ' UCHAR[4]
 Seed(19) AS BYTE ' UCHAR[20]
 q(19) AS BYTE ' UCHAR[20]
END TYPE
'//
'// Microsoft built-in providers.
'//
$$MS_PRIMITIVE_PROVIDER = "Microsoft Primitive Provider"$$
'//
'// Common algorithm identifiers.
'//
$$BCRYPT_RSA_ALGORITHM = "RSA"$$
$$BCRYPT_RSA_SIGN_ALGORITHM = "RSA_SIGN"$$
$$BCRYPT_DH_ALGORITHM = "DH"$$
$$BCRYPT_DSA_ALGORITHM = "DSA"$$
$$BCRYPT_RC2_ALGORITHM = "RC2"$$
$$BCRYPT_RC4_ALGORITHM = "RC4"$$
$$BCRYPT_AES_ALGORITHM = "AES"$$
$$BCRYPT_DES_ALGORITHM = "DES"$$
$$BCRYPT_DESX_ALGORITHM = "DESX"$$
$$BCRYPT_3DES_ALGORITHM = "3DES"$$
$$BCRYPT_3DES_112_ALGORITHM = "3DES_112"$$
$$BCRYPT_MD2_ALGORITHM = "MD2"$$
$$BCRYPT_MD4_ALGORITHM = "MD4"$$
$$BCRYPT_MD5_ALGORITHM = "MD5"$$
$$BCRYPT_SHA1_ALGORITHM = "SHA1"$$
$$BCRYPT_SHA256_ALGORITHM = "SHA256"$$
$$BCRYPT_SHA384_ALGORITHM = "SHA384"$$
$$BCRYPT_SHA512_ALGORITHM = "SHA512"$$
$$BCRYPT_AES_GMAC_ALGORITHM = "AES-GMAC"$$
$$BCRYPT_ECDSA_P256_ALGORITHM = "ECDSA_P256"$$
$$BCRYPT_ECDSA_P384_ALGORITHM = "ECDSA_P384"$$
$$BCRYPT_ECDSA_P521_ALGORITHM = "ECDSA_P521"$$
$$BCRYPT_ECDH_P256_ALGORITHM = "ECDH_P256"$$
$$BCRYPT_ECDH_P384_ALGORITHM = "ECDH_P384"$$
$$BCRYPT_ECDH_P521_ALGORITHM = "ECDH_P521"$$
$$BCRYPT_RNG_ALGORITHM = "RNG"$$
$$BCRYPT_RNG_FIPS186_DSA_ALGORITHM = "FIPS186DSARNG"$$
$$BCRYPT_RNG_DUAL_EC_ALGORITHM = "DUALECRNG"$$
'//
'// Interfaces
'//
%EQUATE `BCRYPT_CIPHER_INTERFACE = &H00000001
%EQUATE `BCRYPT_HASH_INTERFACE = &H00000002
%EQUATE `BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE = &H00000003
%EQUATE `BCRYPT_SECRET_AGREEMENT_INTERFACE = &H00000004
%EQUATE `BCRYPT_SIGNATURE_INTERFACE = &H00000005
%EQUATE `BCRYPT_RNG_INTERFACE = &H00000006
'//
'// Primitive algorithm provider functions.
'//
%EQUATE `BCRYPT_ALG_HANDLE_HMAC_FLAG = &H00000008
DECLARE FUNCTION BCryptOpenAlgorithmProvider LIB "bcrypt.dll" ALIAS "BCryptOpenAlgorithmProvider" ( BYREF phAlgorithm AS QUAD , BYREF pszAlgId AS WSTRINGZ , BYREF pszImplementation AS WSTRINGZ , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
'// AlgOperations flags for use with BCryptEnumAlgorithms()
%EQUATE `BCRYPT_CIPHER_OPERATION = &H00000001
%EQUATE `BCRYPT_HASH_OPERATION = &H00000002
%EQUATE `BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION = &H00000004
%EQUATE `BCRYPT_SECRET_AGREEMENT_OPERATION = &H00000008
%EQUATE `BCRYPT_SIGNATURE_OPERATION = &H00000010
%EQUATE `BCRYPT_RNG_OPERATION = &H00000020
'// USE EXTREME CAUTION: editing comments that contain "certenrolls_*" tokens
'// could break building CertEnroll idl files:
'// certenrolls_begin -- BCRYPT_ALGORITHM_IDENTIFIER
' // Size = 12 bytes
TYPE BCRYPT_ALGORITHM_IDENTIFIER DWORD
 pszName AS WSTRINGZ PTR
 dwClass AS DWORD ' ULONG
 dwFlags AS DWORD ' ULONG
END TYPE
DECLARE FUNCTION BCryptEnumAlgorithms LIB "bcrypt.dll" ALIAS "BCryptEnumAlgorithms" ( BYVAL dwAlgOperations AS QUAD , BYREF pAlgCount AS QUAD , BYREF ppAlgList AS ANY , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
' // Size = 4 bytes
TYPE BCRYPT_PROVIDER_NAME DWORD
 pszProviderName AS WSTRINGZ PTR
END TYPE
DECLARE FUNCTION BCryptEnumProviders LIB "bcrypt.dll" ALIAS "BCryptEnumProviders" ( BYREF pszAlgId AS WSTRINGZ , BYREF pImplCount AS QUAD , BYREF ppImplList AS ANY , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
'// Flags for use with BCryptGetProperty and BCryptSetProperty
%EQUATE `BCRYPT_PUBLIC_KEY_FLAG = &H00000001
%EQUATE `BCRYPT_PRIVATE_KEY_FLAG = &H00000002
DECLARE FUNCTION BCryptGetProperty LIB "bcrypt.dll" ALIAS "BCryptGetProperty" ( BYVAL hObject AS QUAD , BYREF pszProperty AS WSTRINGZ , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptSetProperty LIB "bcrypt.dll" ALIAS "BCryptSetProperty" ( BYVAL hObject AS QUAD , BYREF pszProperty AS WSTRINGZ , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptCloseAlgorithmProvider LIB "bcrypt.dll" ALIAS "BCryptCloseAlgorithmProvider" ( BYVAL hAlgorithm AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
#IF %DEF(%USEPBDECL)
' Note: This PB declaration forces to use the BYVAL override to pass the pointer to free
' and may cause memory leaks if the user forgets to do it.
DECLARE SUB BCryptFreeBuffer LIB "BCrypt.dll" ALIAS "BCryptFreeBuffer" (pvBuffer AS ANY)
#ELSE
DECLARE SUB BCryptFreeBuffer LIB "bcrypt.dll" ALIAS "BCryptFreeBuffer" ( BYVAL pvBuffer AS QUAD )
#ENDIF
'//
'// Primitive encryption functions.
'//
DECLARE FUNCTION BCryptGenerateSymmetricKey LIB "bcrypt.dll" ALIAS "BCryptGenerateSymmetricKey" ( BYVAL hAlgorithm AS QUAD , BYREF phKey AS QUAD , BYVAL pbKeyObject AS BYTE PTR , BYVAL cbKeyObject AS QUAD , BYVAL pbSecret AS BYTE PTR , BYVAL cbSecret AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptGenerateKeyPair LIB "bcrypt.dll" ALIAS "BCryptGenerateKeyPair" ( BYVAL hAlgorithm AS QUAD , BYREF phKey AS QUAD , BYVAL dwLength AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptEncrypt LIB "bcrypt.dll" ALIAS "BCryptEncrypt" ( BYVAL hKey AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbIV AS BYTE PTR , BYVAL cbIV AS QUAD , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDecrypt LIB "bcrypt.dll" ALIAS "BCryptDecrypt" ( BYVAL hKey AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbIV AS BYTE PTR , BYVAL cbIV AS QUAD , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptExportKey LIB "bcrypt.dll" ALIAS "BCryptExportKey" ( BYVAL hKey AS QUAD , BYVAL hExportKey AS QUAD , BYREF pszBlobType AS WSTRINGZ , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptImportKey LIB "bcrypt.dll" ALIAS "BCryptImportKey" ( BYVAL hAlgorithm AS QUAD , BYVAL hImportKey AS QUAD , BYREF pszBlobType AS WSTRINGZ , BYREF phKey AS QUAD , BYVAL pbKeyObject AS BYTE PTR , BYVAL cbKeyObject AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
%EQUATE `BCRYPT_NO_KEY_VALIDATION = &H00000008
DECLARE FUNCTION BCryptImportKeyPair LIB "bcrypt.dll" ALIAS "BCryptImportKeyPair" ( BYVAL hAlgorithm AS QUAD , BYVAL hImportKey AS QUAD , BYREF pszBlobType AS WSTRINGZ , BYREF phKey AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDuplicateKey LIB "bcrypt.dll" ALIAS "BCryptDuplicateKey" ( BYVAL hKey AS QUAD , BYREF phNewKey AS QUAD , BYVAL pbKeyObject AS BYTE PTR , BYVAL cbKeyObject AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptFinalizeKeyPair LIB "bcrypt.dll" ALIAS "BCryptFinalizeKeyPair" ( BYVAL hKey AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDestroyKey LIB "bcrypt.dll" ALIAS "BCryptDestroyKey" ( BYVAL hKey AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDestroySecret LIB "bcrypt.dll" ALIAS "BCryptDestroySecret" ( BYVAL hSecret AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptSignHash LIB "bcrypt.dll" ALIAS "BCryptSignHash" ( BYVAL hKey AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptVerifySignature LIB "bcrypt.dll" ALIAS "BCryptVerifySignature" ( BYVAL hKey AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbHash AS BYTE PTR , BYVAL cbHash AS QUAD , BYVAL pbSignature AS BYTE PTR , BYVAL cbSignature AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptSecretAgreement LIB "bcrypt.dll" ALIAS "BCryptSecretAgreement" ( BYVAL hPrivKey AS QUAD , BYVAL hPubKey AS QUAD , BYREF phAgreedSecret AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDeriveKey LIB "bcrypt.dll" ALIAS "BCryptDeriveKey" ( BYVAL hSharedSecret AS QUAD , BYREF pwszKDF AS WSTRINGZ , BYVAL pParameterList AS BCryptBufferDesc PTR , BYVAL pbDerivedKey AS BYTE PTR , BYVAL cbDerivedKey AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
'//
'// Primitive hashing functions.
'//
DECLARE FUNCTION BCryptCreateHash LIB "bcrypt.dll" ALIAS "BCryptCreateHash" ( BYVAL hAlgorithm AS QUAD , BYREF phHash AS QUAD , BYVAL pbHashObject AS BYTE PTR , BYVAL cbHashObject AS QUAD , BYVAL pbSecret AS BYTE PTR , BYVAL cbSecret AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptHashData LIB "bcrypt.dll" ALIAS "BCryptHashData" ( BYVAL hHash AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptFinishHash LIB "bcrypt.dll" ALIAS "BCryptFinishHash" ( BYVAL hHash AS QUAD , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDuplicateHash LIB "bcrypt.dll" ALIAS "BCryptDuplicateHash" ( BYVAL hHash AS QUAD , BYREF phNewHash AS QUAD , BYVAL pbHashObject AS BYTE PTR , BYVAL cbHashObject AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDestroyHash LIB "bcrypt.dll" ALIAS "BCryptDestroyHash" ( BYVAL hHash AS QUAD ) AS LONG ' NTSTATUS
'//
'// Primitive random number generation.
'//
'// Flags to BCryptGenRandom
%EQUATE `BCRYPT_RNG_USE_ENTROPY_IN_BUFFER = &H00000001
%EQUATE `BCRYPT_USE_SYSTEM_PREFERRED_RNG = &H00000002
DECLARE FUNCTION BCryptGenRandom LIB "bcrypt.dll" ALIAS "BCryptGenRandom" ( BYVAL hAlgorithm AS QUAD , BYVAL pbBuffer AS BYTE PTR , BYVAL cbBuffer AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
'//
'// Primitive key derivation functions.
'//
DECLARE FUNCTION BCryptDeriveKeyCapi LIB "bcrypt.dll" ALIAS "BCryptDeriveKeyCapi" ( BYVAL hHash AS QUAD , BYVAL hTargetAlg AS QUAD , BYVAL pbDerivedKey AS BYTE PTR , BYVAL cbDerivedKey AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDeriveKeyPBKDF2 LIB "bcrypt.dll" ALIAS "BCryptDeriveKeyPBKDF2" ( BYVAL hPrf AS QUAD , BYVAL pbPassword AS BYTE PTR , BYVAL cbPassword AS QUAD , BYVAL pbSalt AS BYTE PTR , BYVAL cbSalt AS QUAD , BYVAL cIterations AS QUAD , BYVAL pbDerivedKey AS BYTE PTR , BYVAL cbDerivedKey AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' NTSTATUS
'//
'// Interface version control...
'//
' // Size = 4 bytes
TYPE BCRYPT_INTERFACE_VERSION WORD
 MajorVersion AS WORD ' USHORT
 MinorVersion AS WORD ' USHORT
END TYPE
'#define BCRYPT_MAKE_INTERFACE_VERSION(major,minor) {(USHORT)major, (USHORT)minor}
'#define BCRYPT_IS_INTERFACE_VERSION_COMPATIBLE(loader, provider) \
' ((loader).MajorVersion <= (provider).MajorVersion)
'//
'// Primitive provider interfaces.
'//
'#define BCRYPT_CIPHER_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION(1,0)
'#define BCRYPT_HASH_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION(1,0)
'#define BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION(1,0)
'#define BCRYPT_SECRET_AGREEMENT_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION(1,0)
'#define BCRYPT_SIGNATURE_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION(1,0)
'#define BCRYPT_RNG_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION(1,0)
'//////////////////////////////////////////////////////////////////////////////
'// CryptoConfig Definitions //////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
'// Interface registration flags
%EQUATE `CRYPT_MIN_DEPENDENCIES = &H00000001
%EQUATE `CRYPT_PROCESS_ISOLATE = &H00010000 ' // User-mode only
'// Processor modes supported by a provider
'//
'// (Valid for BCryptQueryProviderRegistration and BCryptResolveProviders???:
'//
%EQUATE `CRYPT_UM = &H00000001 ' // User mode only
%EQUATE `CRYPT_KM = &H00000002 ' // Kernel mode only
%EQUATE `CRYPT_MM = &H00000003 ' // Multi-mode: Must support BOTH UM and KM
'//
'// (Valid only for BCryptQueryProviderRegistration???:
'//
%EQUATE `CRYPT_ANY = &H00000004 ' // Wildcard: Either UM, or KM, or both
'// Write behavior flags
%EQUATE `CRYPT_OVERWRITE = &H00000001
'// Configuration tables
%EQUATE `CRYPT_LOCAL = &H00000001
%EQUATE `CRYPT_DOMAIN = &H00000002
'// Context configuration flags
%EQUATE `CRYPT_EXCLUSIVE = &H00000001
%EQUATE `CRYPT_OVERRIDE = &H00010000 ' // Enterprise table only
'// Resolution and enumeration flags
%EQUATE `CRYPT_ALL_FUNCTIONS = &H00000001
%EQUATE `CRYPT_ALL_PROVIDERS = &H00000002
'// Priority list positions
%EQUATE `CRYPT_PRIORITY_TOP = &H00000000
#IF %DEF(%USEPBDECL)
%EQUATE `CRYPT_PRIORITY_BOTTOM = &HFFFFFFFF
#ELSE
%EQUATE `CRYPT_PRIORITY_BOTTOM = &HFFFFFFFF
#ENDIF
'// Default system-wide context
$CRYPT_DEFAULT_CONTEXT = "Default"
'//////////////////////////////////////////////////////////////////////////////
'// CryptoConfig Structures ///////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
'//
'// Provider Registration Structures
'//
' // Size = 16 bytes
TYPE CRYPT_INTERFACE_REG DWORD
 dwInterface AS DWORD ' ULONG
 dwFlags AS DWORD ' ULONG
 cFunctions AS DWORD ' ULONG
 rgpszFunctions AS WSTRINGZ PTR ' PWSTR *
END TYPE
' // Size = 12 bytes
TYPE CRYPT_IMAGE_REG DWORD
 pszImage AS WSTRINGZ PTR
 cInterfaces AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpInterfaces AS DWORD
#ELSE
 rgpInterfaces AS CRYPT_INTERFACE_REG PTR ' PCRYPT_INTERFACE_REG *
#ENDIF
END TYPE
' // Size = 16 bytes
TYPE CRYPT_PROVIDER_REG DWORD
 cAliases AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpszAliases AS DWORD
#ELSE
 rgpszAliases AS WSTRINGZ PTR ' PWSTR *
#ENDIF
 pUM AS CRYPT_IMAGE_REG PTR ' PCRYPT_IMAGE_REG
 pKM AS CRYPT_IMAGE_REG PTR ' PCRYPT_IMAGE_REG
END TYPE
' // Size = 8 bytes
TYPE CRYPT_PROVIDERS DWORD
 cProviders AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpszProviders AS DWORD
#ELSE
 rgpszProviders AS WSTRINGZ PTR ' PWSTR *
#ENDIF
END TYPE
'//
'// Context Configuration Structures
'//
' // Size = 8 bytes
TYPE CRYPT_CONTEXT_CONFIG DWORD
 dwFlags AS DWORD ' ULONG
 dwReserved AS DWORD ' ULONG
END TYPE
' // Size = 8 bytes
TYPE CRYPT_CONTEXT_FUNCTION_CONFIG DWORD
 dwFlags AS DWORD ' ULONG
 dwReserved AS DWORD ' ULONG
END TYPE
' // Size = 8 bytes
TYPE CRYPT_CONTEXTS DWORD
 cContexts AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpszContexts AS DWORD
#ELSE
 rgpszContexts AS WSTRINGZ PTR ' PWSTR *
#ENDIF
END TYPE
' // Size = 8 bytes
TYPE CRYPT_CONTEXT_FUNCTIONS DWORD
 cFunctions AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpszFunctions AS DWORD
#ELSE
 rgpszFunctions AS WSTRINGZ PTR ' PWSTR *
#ENDIF
END TYPE
' // Size = 8 bytes
TYPE CRYPT_CONTEXT_FUNCTION_PROVIDERS DWORD
 cProviders AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpszProviders AS DWORD
#ELSE
 rgpszProviders AS WSTRINGZ PTR ' PWSTR *
#ENDIF
END TYPE
'//
'// Provider Resolution Structures
'//
' // Size = 12 bytes
TYPE CRYPT_PROPERTY_REF DWORD
 pszProperty AS WSTRINGZ PTR
 cbValue AS DWORD ' ULONG
 pbValue AS BYTE PTR
END TYPE
' // Size = 8 bytes
TYPE CRYPT_IMAGE_REF DWORD
 pszImage AS WSTRINGZ PTR
 dwFlags AS DWORD ' ULONG
END TYPE
' // Size = 28 bytes
TYPE CRYPT_PROVIDER_REF DWORD
 dwInterface AS DWORD ' ULONG
 pszFunction AS WSTRINGZ PTR
 pszProvider AS WSTRINGZ PTR
 cProperties AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpProperties AS DWORD
#ELSE
 rgpProperties AS CRYPT_PROPERTY_REF PTR ' PCRYPT_PROPERTY_REF *
#ENDIF
 pUM AS CRYPT_IMAGE_REF PTR ' PCRYPT_IMAGE_REF
 pKM AS CRYPT_IMAGE_REF PTR ' PCRYPT_IMAGE_REF
END TYPE
' // Size = 8 bytes
TYPE CRYPT_PROVIDER_REFS DWORD
 cProviders AS DWORD ' ULONG
#IF %DEF(%USEPBDECL)
 rgpProviders AS DWORD
#ELSE
 rgpProviders AS CRYPT_PROVIDER_REF PTR ' PCRYPT_PROVIDER_REF
#ENDIF
END TYPE
'//////////////////////////////////////////////////////////////////////////////
'// CryptoConfig Functions ////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
#IF NOT %DEF(%KERNEL_MODE_CNG)
DECLARE FUNCTION BCryptQueryProviderRegistration LIB "bcrypt.dll" ALIAS "BCryptQueryProviderRegistration" ( BYREF pszProvider AS WSTRINGZ , BYVAL dwMode AS QUAD , BYVAL dwInterface AS QUAD , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptEnumRegisteredProviders LIB "bcrypt.dll" ALIAS "BCryptEnumRegisteredProviders" ( BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
'//
'// Context Configuration Functions
'//
DECLARE FUNCTION BCryptCreateContext LIB "bcrypt.dll" ALIAS "BCryptCreateContext" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , OPTIONAL BYREF pConfig AS CRYPT_CONTEXT_CONFIG ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptDeleteContext LIB "bcrypt.dll" ALIAS "BCryptDeleteContext" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptEnumContexts LIB "bcrypt.dll" ALIAS "BCryptEnumContexts" ( BYVAL dwTable AS QUAD , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptConfigureContext LIB "bcrypt.dll" ALIAS "BCryptConfigureContext" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYREF pConfig AS CRYPT_CONTEXT_CONFIG ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptQueryContextConfiguration LIB "bcrypt.dll" ALIAS "BCryptQueryContextConfiguration" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptAddContextFunction LIB "bcrypt.dll" ALIAS "BCryptAddContextFunction" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYVAL dwPosition AS QUAD ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptRemoveContextFunction LIB "bcrypt.dll" ALIAS "BCryptRemoveContextFunction" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptEnumContextFunctions LIB "bcrypt.dll" ALIAS "BCryptEnumContextFunctions" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptConfigureContextFunction LIB "bcrypt.dll" ALIAS "BCryptConfigureContextFunction" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYREF pConfig AS CRYPT_CONTEXT_FUNCTION_CONFIG ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptQueryContextFunctionConfiguration LIB "bcrypt.dll" ALIAS "BCryptQueryContextFunctionConfiguration" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptEnumContextFunctionProviders LIB "bcrypt.dll" ALIAS "BCryptEnumContextFunctionProviders" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptSetContextFunctionProperty LIB "bcrypt.dll" ALIAS "BCryptSetContextFunctionProperty" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYREF pszProperty AS WSTRINGZ , BYVAL cbValue AS QUAD , BYVAL pbValue AS BYTE PTR ) AS LONG ' NTSTATUS
DECLARE FUNCTION BCryptQueryContextFunctionProperty LIB "bcrypt.dll" ALIAS "BCryptQueryContextFunctionProperty" ( BYVAL dwTable AS QUAD , BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYREF pszProperty AS WSTRINGZ , BYREF pcbValue AS QUAD , BYREF ppbValue AS ANY ) AS LONG ' NTSTATUS
#ENDIF ' //#ifndef KERNEL_MODE_CNG
'//
'// Configuration Change Notification Functions
'//
'#ifdef KERNEL_MODE_CNG
'NTSTATUS
'WINAPI
'BCryptRegisterConfigChangeNotify(
'#else
'NTSTATUS
'WINAPI
'BCryptRegisterConfigChangeNotify(
'#endif
DECLARE FUNCTION BCryptRegisterConfigChangeNotify LIB "bcrypt.dll" ALIAS "BCryptRegisterConfigChangeNotify" ( BYREF phEvent AS QUAD ) AS LONG ' NTSTATUS
'#ifdef KERNEL_MODE_CNG
'NTSTATUS
'WINAPI
'BCryptUnregisterConfigChangeNotify(
'#else
'NTSTATUS
'WINAPI
'BCryptUnregisterConfigChangeNotify(
'#endif
DECLARE FUNCTION BCryptUnregisterConfigChangeNotify LIB "bcrypt.dll" ALIAS "BCryptUnregisterConfigChangeNotify" ( BYVAL hEvent AS QUAD ) AS LONG ' NTSTATUS
'//
'// Provider Resolution Functions
'//
DECLARE FUNCTION BCryptResolveProviders LIB "bcrypt.dll" ALIAS "BCryptResolveProviders" ( BYREF pszContext AS WSTRINGZ , BYVAL dwInterface AS QUAD , BYREF pszFunction AS WSTRINGZ , BYREF pszProvider AS WSTRINGZ , BYVAL dwMode AS QUAD , BYVAL dwFlags AS QUAD , BYREF pcbBuffer AS QUAD , BYREF ppBuffer AS ANY ) AS LONG ' NTSTATUS
'//
'// Miscellaneous queries about the crypto environment
'//
DECLARE FUNCTION BCryptGetFipsAlgorithmMode LIB "bcrypt.dll" ALIAS "BCryptGetFipsAlgorithmMode" ( BYREF pfEnabled AS LONG ) AS LONG ' NTSTATUS
#ENDIF
