' ########################################################################################
' Microsoft Windows
' File: ncrypt.inc
' Contents: Cryptographic 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_ncrypt_PBI)
#DEFINE PBX_ncrypt_PBI
%EQUATE `NCRYPT_INC = 1
'#ifndef __SECSTATUS_DEFINED__
'typedef LONG SECURITY_STATUS;
'#define __SECSTATUS_DEFINED__
'#endif
#INCLUDE ONCE "Legacy/Security/bcrypt.inc"
'//
'// Microsoft built-in providers.
'//
$$MS_KEY_STORAGE_PROVIDER = "Microsoft Software Key Storage Provider"$$
$$MS_SMART_CARD_KEY_STORAGE_PROVIDER = "Microsoft Smart Card Key Storage Provider"$$
'//
'// Common algorithm identifiers.
'//
$$NCRYPT_RSA_ALGORITHM = $$BCRYPT_RSA_ALGORITHM
$$NCRYPT_RSA_SIGN_ALGORITHM = $$BCRYPT_RSA_SIGN_ALGORITHM
$$NCRYPT_DH_ALGORITHM = $$BCRYPT_DH_ALGORITHM
$$NCRYPT_DSA_ALGORITHM = $$BCRYPT_DSA_ALGORITHM
$$NCRYPT_MD2_ALGORITHM = $$BCRYPT_MD2_ALGORITHM
$$NCRYPT_MD4_ALGORITHM = $$BCRYPT_MD4_ALGORITHM
$$NCRYPT_MD5_ALGORITHM = $$BCRYPT_MD5_ALGORITHM
$$NCRYPT_SHA1_ALGORITHM = $$BCRYPT_SHA1_ALGORITHM
$$NCRYPT_SHA256_ALGORITHM = $$BCRYPT_SHA256_ALGORITHM
$$NCRYPT_SHA384_ALGORITHM = $$BCRYPT_SHA384_ALGORITHM
$$NCRYPT_SHA512_ALGORITHM = $$BCRYPT_SHA512_ALGORITHM
$$NCRYPT_ECDSA_P256_ALGORITHM = $$BCRYPT_ECDSA_P256_ALGORITHM
$$NCRYPT_ECDSA_P384_ALGORITHM = $$BCRYPT_ECDSA_P384_ALGORITHM
$$NCRYPT_ECDSA_P521_ALGORITHM = $$BCRYPT_ECDSA_P521_ALGORITHM
$$NCRYPT_ECDH_P256_ALGORITHM = $$BCRYPT_ECDH_P256_ALGORITHM
$$NCRYPT_ECDH_P384_ALGORITHM = $$BCRYPT_ECDH_P384_ALGORITHM
$$NCRYPT_ECDH_P521_ALGORITHM = $$BCRYPT_ECDH_P521_ALGORITHM
$$NCRYPT_KEY_STORAGE_ALGORITHM = "KEY_STORAGE"$$
'//
'// Interfaces
'//
%EQUATE `NCRYPT_HASH_INTERFACE = %BCRYPT_HASH_INTERFACE
%EQUATE `NCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE = %BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE
%EQUATE `NCRYPT_SECRET_AGREEMENT_INTERFACE = %BCRYPT_SECRET_AGREEMENT_INTERFACE
%EQUATE `NCRYPT_SIGNATURE_INTERFACE = %BCRYPT_SIGNATURE_INTERFACE
%EQUATE `NCRYPT_KEY_STORAGE_INTERFACE = &H00010001
%EQUATE `NCRYPT_SCHANNEL_INTERFACE = &H00010002
%EQUATE `NCRYPT_SCHANNEL_SIGNATURE_INTERFACE = &H00010003
'//
'// algorithm groups.
'//
$$NCRYPT_RSA_ALGORITHM_GROUP = $$NCRYPT_RSA_ALGORITHM
$$NCRYPT_DH_ALGORITHM_GROUP = $$NCRYPT_DH_ALGORITHM
$$NCRYPT_DSA_ALGORITHM_GROUP = $$NCRYPT_DSA_ALGORITHM
$$NCRYPT_ECDSA_ALGORITHM_GROUP = "ECDSA"$$
$$NCRYPT_ECDH_ALGORITHM_GROUP = "ECDH"$$
'//
'// NCrypt generic memory descriptors
'//
%EQUATE `NCRYPTBUFFER_VERSION = 0
%EQUATE `NCRYPTBUFFER_EMPTY = 0
%EQUATE `NCRYPTBUFFER_DATA = 1
%EQUATE `NCRYPTBUFFER_SSL_CLIENT_RANDOM = 20
%EQUATE `NCRYPTBUFFER_SSL_SERVER_RANDOM = 21
%EQUATE `NCRYPTBUFFER_SSL_HIGHEST_VERSION = 22
%EQUATE `NCRYPTBUFFER_SSL_CLEAR_KEY = 23
%EQUATE `NCRYPTBUFFER_SSL_KEY_ARG_DATA = 24
%EQUATE `NCRYPTBUFFER_PKCS_OID = 40
%EQUATE `NCRYPTBUFFER_PKCS_ALG_OID = 41
%EQUATE `NCRYPTBUFFER_PKCS_ALG_PARAM = 42
%EQUATE `NCRYPTBUFFER_PKCS_ALG_ID = 43
%EQUATE `NCRYPTBUFFER_PKCS_ATTRS = 44
%EQUATE `NCRYPTBUFFER_PKCS_KEY_NAME = 45
%EQUATE `NCRYPTBUFFER_PKCS_SECRET = 46
%EQUATE `NCRYPTBUFFER_CERT_BLOB = 47
'// NCRYPT shares the same BCRYPT definitions
'typedef BCryptBuffer NCryptBuffer;
'typedef BCryptBuffer* PNCryptBuffer;
'typedef BCryptBufferDesc NCryptBufferDesc;
'typedef BCryptBufferDesc* PNCryptBufferDesc;
MACRO NCryptBuffer = BCryptBuffer
MACRO NCryptBufferDesc = BCryptBufferDesc
'//
'// NCrypt handles
'//
'typedef ULONG_PTR NCRYPT_HANDLE;
'typedef ULONG_PTR NCRYPT_PROV_HANDLE;
'typedef ULONG_PTR NCRYPT_KEY_HANDLE;
'typedef ULONG_PTR NCRYPT_HASH_HANDLE;
'typedef ULONG_PTR NCRYPT_SECRET_HANDLE;
'//
'// NCrypt API Flags
'//
%EQUATE `NCRYPT_NO_PADDING_FLAG = %BCRYPT_PAD_NONE
%EQUATE `NCRYPT_PAD_PKCS1_FLAG = %BCRYPT_PAD_PKCS1 ' // NCryptEncrypt/Decrypt NCryptSignHash/VerifySignature
%EQUATE `NCRYPT_PAD_OAEP_FLAG = %BCRYPT_PAD_OAEP ' // BCryptEncrypt/Decrypt
%EQUATE `NCRYPT_PAD_PSS_FLAG = %BCRYPT_PAD_PSS ' // BCryptSignHash/VerifySignature
%EQUATE `NCRYPT_NO_KEY_VALIDATION = %BCRYPT_NO_KEY_VALIDATION
%EQUATE `NCRYPT_MACHINE_KEY_FLAG = &H00000020 ' // same as CAPI CRYPT_MACHINE_KEYSET
%EQUATE `NCRYPT_SILENT_FLAG = &H00000040 ' // same as CAPI CRYPT_SILENT
%EQUATE `NCRYPT_OVERWRITE_KEY_FLAG = &H00000080
%EQUATE `NCRYPT_WRITE_KEY_TO_LEGACY_STORE_FLAG = &H00000200
%EQUATE `NCRYPT_DO_NOT_FINALIZE_FLAG = &H00000400
%EQUATE `NCRYPT_PERSIST_ONLY_FLAG = &H40000000
%EQUATE `NCRYPT_PERSIST_FLAG = &H80000000
%EQUATE `NCRYPT_REGISTER_NOTIFY_FLAG = &H00000001
%EQUATE `NCRYPT_UNREGISTER_NOTIFY_FLAG = &H00000002
'//
'// Functions used to manage persisted keys.
'//
DECLARE FUNCTION NCryptOpenStorageProvider LIB "ncrypt.dll" ALIAS "NCryptOpenStorageProvider" ( BYREF phProvider AS QUAD , BYREF pszProviderName AS WSTRINGZ , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
'// AlgOperations flags for use with NCryptEnumAlgorithms()
%EQUATE `NCRYPT_CIPHER_OPERATION = %BCRYPT_CIPHER_OPERATION
%EQUATE `NCRYPT_HASH_OPERATION = %BCRYPT_HASH_OPERATION
%EQUATE `NCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION = %BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION
%EQUATE `NCRYPT_SECRET_AGREEMENT_OPERATION = %BCRYPT_SECRET_AGREEMENT_OPERATION
%EQUATE `NCRYPT_SIGNATURE_OPERATION = %BCRYPT_SIGNATURE_OPERATION
%EQUATE `NCRYPT_RNG_OPERATION = %BCRYPT_RNG_OPERATION
'// USE EXTREME CAUTION: editing comments that contain "certenrolls_*" tokens
'// could break building CertEnroll idl files:
'// certenrolls_begin -- NCryptAlgorithmName
' // Size = 16 bytes
TYPE NCryptAlgorithmName DWORD
 pszName AS WSTRINGZ PTR
 dwClass AS DWORD ' DWORD // the CNG interface that supports this algorithm
 dwAlgOperations AS DWORD ' DWORD // the types of operations supported by this algorithm
 dwFlags AS DWORD
END TYPE
DECLARE FUNCTION NCryptEnumAlgorithms LIB "ncrypt.dll" ALIAS "NCryptEnumAlgorithms" ( BYVAL hProvider AS QUAD , BYVAL dwAlgOperations AS QUAD , BYREF pdwAlgCount AS QUAD , BYREF ppAlgList AS ANY , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptIsAlgSupported LIB "ncrypt.dll" ALIAS "NCryptIsAlgSupported" ( BYVAL hProvider AS QUAD , BYREF pszAlgId AS WSTRINGZ , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
'// NCryptEnumKeys flags
%EQUATE `NCRYPT_MACHINE_KEY_FLAG = &H00000020
' // Size = 16 bytes
TYPE NCryptKeyName DWORD
 pszName AS WSTRINGZ PTR
 pszAlgid AS WSTRINGZ PTR
 dwLegacyKeySpec AS DWORD
 dwFlags AS DWORD
END TYPE
DECLARE FUNCTION NCryptEnumKeys LIB "ncrypt.dll" ALIAS "NCryptEnumKeys" ( BYVAL hProvider AS QUAD , BYREF pszScope AS WSTRINGZ , BYREF ppKeyName AS ANY , BYREF ppEnumState AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
' // Size = 8 bytes
TYPE NCryptProviderName DWORD
 pszName AS WSTRINGZ PTR
 pszComment AS WSTRINGZ PTR
END TYPE
DECLARE FUNCTION NCryptEnumStorageProviders LIB "ncrypt.dll" ALIAS "NCryptEnumStorageProviders" ( BYREF pdwProviderCount AS QUAD , BYREF ppProviderList AS ANY , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptFreeBuffer LIB "ncrypt.dll" ALIAS "NCryptFreeBuffer" ( BYVAL pvInput AS QUAD ) AS LONG ' SECURITY_STATUS
'// NCryptOpenKey flags
%EQUATE `NCRYPT_MACHINE_KEY_FLAG = &H00000020
%EQUATE `NCRYPT_SILENT_FLAG = &H00000040
DECLARE FUNCTION NCryptOpenKey LIB "ncrypt.dll" ALIAS "NCryptOpenKey" ( BYVAL hProvider AS QUAD , BYREF phKey AS QUAD , BYREF pszKeyName AS WSTRINGZ , BYVAL dwLegacyKeySpec AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
'// NCryptCreatePersistedKey flags
%EQUATE `NCRYPT_MACHINE_KEY_FLAG = &H00000020
%EQUATE `NCRYPT_OVERWRITE_KEY_FLAG = &H00000080
DECLARE FUNCTION NCryptCreatePersistedKey LIB "ncrypt.dll" ALIAS "NCryptCreatePersistedKey" ( BYVAL hProvider AS QUAD , BYREF phKey AS QUAD , BYREF pszAlgId AS WSTRINGZ , BYREF pszKeyName AS WSTRINGZ , BYVAL dwLegacyKeySpec AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
'// Standard property names.
$$NCRYPT_NAME_PROPERTY = "Name"$$
$$NCRYPT_UNIQUE_NAME_PROPERTY = "Unique Name"$$
$$NCRYPT_ALGORITHM_PROPERTY = "Algorithm Name"$$
$$NCRYPT_LENGTH_PROPERTY = "Length"$$
$$NCRYPT_LENGTHS_PROPERTY = "Lengths"$$
$$NCRYPT_BLOCK_LENGTH_PROPERTY = "Block Length"$$
$$NCRYPT_UI_POLICY_PROPERTY = "UI Policy"$$
$$NCRYPT_EXPORT_POLICY_PROPERTY = "Export Policy"$$
$$NCRYPT_WINDOW_HANDLE_PROPERTY = "HWND Handle"$$
$$NCRYPT_USE_CONTEXT_PROPERTY = "Use Context"$$
$$NCRYPT_IMPL_TYPE_PROPERTY = "Impl Type"$$
$$NCRYPT_KEY_USAGE_PROPERTY = "Key Usage"$$
$$NCRYPT_KEY_TYPE_PROPERTY = "Key Type"$$
$$NCRYPT_VERSION_PROPERTY = "Version"$$
$$NCRYPT_SECURITY_DESCR_SUPPORT_PROPERTY = "Security Descr Support"$$
$$NCRYPT_SECURITY_DESCR_PROPERTY = "Security Descr"$$
$$NCRYPT_USE_COUNT_ENABLED_PROPERTY = "Enabled Use Count"$$
$$NCRYPT_USE_COUNT_PROPERTY = "Use Count"$$
$$NCRYPT_LAST_MODIFIED_PROPERTY = "Modified"$$
$$NCRYPT_MAX_NAME_LENGTH_PROPERTY = "Max Name Length"$$
$$NCRYPT_ALGORITHM_GROUP_PROPERTY = "Algorithm Group"$$
$$NCRYPT_DH_PARAMETERS_PROPERTY = $$BCRYPT_DH_PARAMETERS
$$NCRYPT_PROVIDER_HANDLE_PROPERTY = "Provider Handle"$$
$$NCRYPT_PIN_PROPERTY = "SmartCardPin"$$
$$NCRYPT_READER_PROPERTY = "SmartCardReader"$$
$$NCRYPT_SMARTCARD_GUID_PROPERTY = "SmartCardGuid"$$
$$NCRYPT_CERTIFICATE_PROPERTY = "SmartCardKeyCertificate"$$
$$NCRYPT_PIN_PROMPT_PROPERTY = "SmartCardPinPrompt"$$
$$NCRYPT_USER_CERTSTORE_PROPERTY = "SmartCardUserCertStore"$$
$$NCRYPT_ROOT_CERTSTORE_PROPERTY = "SmartcardRootCertStore"$$
$$NCRYPT_SECURE_PIN_PROPERTY = "SmartCardSecurePin"$$
$$NCRYPT_ASSOCIATED_ECDH_KEY = "SmartCardAssociatedECDHKey"$$
$$NCRYPT_SCARD_PIN_ID = "SmartCardPinId"$$
$$NCRYPT_SCARD_PIN_INFO = "SmartCardPinInfo"$$
'// Maximum length of property name (in characters)
%EQUATE `NCRYPT_MAX_PROPERTY_NAME = 64
'// Maximum length of property data (in bytes)
%EQUATE `NCRYPT_MAX_PROPERTY_DATA = &H100000
'// NCRYPT_EXPORT_POLICY_PROPERTY property flags.
%EQUATE `NCRYPT_ALLOW_EXPORT_FLAG = &H00000001
%EQUATE `NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG = &H00000002
%EQUATE `NCRYPT_ALLOW_ARCHIVING_FLAG = &H00000004
%EQUATE `NCRYPT_ALLOW_PLAINTEXT_ARCHIVING_FLAG = &H00000008
'// NCRYPT_IMPL_TYPE_PROPERTY property flags.
%EQUATE `NCRYPT_IMPL_HARDWARE_FLAG = &H00000001
%EQUATE `NCRYPT_IMPL_SOFTWARE_FLAG = &H00000002
%EQUATE `NCRYPT_IMPL_REMOVABLE_FLAG = &H00000008
%EQUATE `NCRYPT_IMPL_HARDWARE_RNG_FLAG = &H00000010
'// NCRYPT_KEY_USAGE_PROPERTY property flags.
%EQUATE `NCRYPT_ALLOW_DECRYPT_FLAG = &H00000001
%EQUATE `NCRYPT_ALLOW_SIGNING_FLAG = &H00000002
%EQUATE `NCRYPT_ALLOW_KEY_AGREEMENT_FLAG = &H00000004
%EQUATE `NCRYPT_ALLOW_ALL_USAGES = &H00ffffff
'// NCRYPT_UI_POLICY_PROPERTY property flags and structure
%EQUATE `NCRYPT_UI_PROTECT_KEY_FLAG = &H00000001
%EQUATE `NCRYPT_UI_FORCE_HIGH_PROTECTION_FLAG = &H00000002
' // Size = 20 bytes
TYPE NCRYPT_UI_POLICY_BLOB DWORD
 dwVersion AS DWORD
 dwFlags AS DWORD
 cbCreationTitle AS DWORD
 cbFriendlyName AS DWORD
 cbDescription AS DWORD
 ' // creation title string
 ' // friendly name string
 ' // description string
END TYPE
' // Size = 20 bytes
TYPE NCRYPT_UI_POLICY DWORD
 dwVersion AS DWORD
 dwFlags AS DWORD
 pszCreationTitle AS WSTRINGZ PTR
 pszFriendlyName AS WSTRINGZ PTR
 pszDescription AS WSTRINGZ PTR
END TYPE
'// NCRYPT_LENGTHS_PROPERTY property structure.
' // Size = 16 bytes
TYPE NCRYPT_SUPPORTED_LENGTHS DWORD
 dwMinLength AS DWORD
 dwMaxLength AS DWORD
 dwIncrement AS DWORD
 dwDefaultLength AS DWORD
END TYPE
'// NCryptGetProperty flags
%EQUATE `NCRYPT_PERSIST_ONLY_FLAG = &H40000000
DECLARE FUNCTION NCryptGetProperty LIB "ncrypt.dll" ALIAS "NCryptGetProperty" ( BYVAL hObject AS QUAD , BYREF pszProperty AS WSTRINGZ , BYVAL pbOutput AS QUAD , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
'// NCryptSetProperty flags
%EQUATE `NCRYPT_PERSIST_FLAG = &H80000000
%EQUATE `NCRYPT_PERSIST_ONLY_FLAG = &H40000000
DECLARE FUNCTION NCryptSetProperty LIB "ncrypt.dll" ALIAS "NCryptSetProperty" ( BYVAL hObject AS QUAD , BYREF pszProperty AS WSTRINGZ , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
%EQUATE `NCRYPT_WRITE_KEY_TO_LEGACY_STORE_FLAG = &H00000200
DECLARE FUNCTION NCryptFinalizeKey LIB "ncrypt.dll" ALIAS "NCryptFinalizeKey" ( BYVAL hKey AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptEncrypt LIB "ncrypt.dll" ALIAS "NCryptEncrypt" ( BYVAL hKey AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptDecrypt LIB "ncrypt.dll" ALIAS "NCryptDecrypt" ( BYVAL hKey AS QUAD , BYVAL pbInput AS BYTE PTR , BYVAL cbInput AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbOutput AS BYTE PTR , BYVAL cbOutput AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
$$NCRYPT_PKCS7_ENVELOPE_BLOB = "PKCS7_ENVELOPE"$$
$$NCRYPT_PKCS8_PRIVATE_KEY_BLOB = "PKCS8_PRIVATEKEY"$$
$$NCRYPT_OPAQUETRANSPORT_BLOB = "OpaqueTransport"$$
%EQUATE `NCRYPT_MACHINE_KEY_FLAG = &H00000020
%EQUATE `NCRYPT_DO_NOT_FINALIZE_FLAG = &H00000400
%EQUATE `NCRYPT_EXPORT_LEGACY_FLAG = &H00000800
DECLARE FUNCTION NCryptImportKey LIB "ncrypt.dll" ALIAS "NCryptImportKey" ( BYVAL hProvider AS QUAD , BYVAL hImportKey AS QUAD , BYREF pszBlobType AS WSTRINGZ , BYREF pParameterList AS NCryptBufferDesc , BYREF phKey AS QUAD , BYVAL pbData AS BYTE PTR , BYVAL cbData AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptExportKey LIB "ncrypt.dll" ALIAS "NCryptExportKey" ( BYVAL hKey AS QUAD , BYVAL hExportKey AS QUAD , BYREF pszBlobType AS WSTRINGZ , BYREF pParameterList AS NCryptBufferDesc , BYVAL pbOutput AS QUAD , BYVAL pcbResult AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptSignHash LIB "ncrypt.dll" ALIAS "NCryptSignHash" ( BYVAL hKey AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbHashValue AS BYTE PTR , BYVAL cbHashValue AS QUAD , BYVAL pbSignature AS BYTE PTR , BYVAL cbSignature AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptVerifySignature LIB "ncrypt.dll" ALIAS "NCryptVerifySignature" ( BYVAL hKey AS QUAD , BYREF pPaddingInfo AS ANY , BYVAL pbHashValue AS BYTE PTR , BYVAL cbHashValue AS QUAD , BYVAL pbSignature AS BYTE PTR , BYVAL cbSignature AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptDeleteKey LIB "ncrypt.dll" ALIAS "NCryptDeleteKey" ( BYVAL hKey AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptFreeObject LIB "ncrypt.dll" ALIAS "NCryptFreeObject" ( BYVAL hObject AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptIsKeyHandle LIB "ncrypt.dll" ALIAS "NCryptIsKeyHandle" ( BYVAL hKey AS QUAD ) AS LONG
DECLARE FUNCTION NCryptTranslateHandle LIB "ncrypt.dll" ALIAS "NCryptTranslateHandle" ( BYREF phProvider AS QUAD
 , BYREF phKey AS DWORD
 , BYVAL hLegacyProv AS DWORD
 , BYVAL hLegacyKey AS DWORD
 , BYVAL dwLegacyKeySpec AS DWORD
 , BYVAL dwFlags AS DWORD
 ) AS LONG ' SECURITY_STATUS
'// NCryptNotifyChangeKey flags
%EQUATE `NCRYPT_REGISTER_NOTIFY_FLAG = &H00000001
%EQUATE `NCRYPT_UNREGISTER_NOTIFY_FLAG = &H00000002
%EQUATE `NCRYPT_MACHINE_KEY_FLAG = &H00000020
DECLARE FUNCTION NCryptNotifyChangeKey LIB "ncrypt.dll" ALIAS "NCryptNotifyChangeKey" ( BYVAL hProvider AS QUAD , BYREF phEvent AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptSecretAgreement LIB "ncrypt.dll" ALIAS "NCryptSecretAgreement" ( BYVAL hPrivKey AS QUAD , BYVAL hPubKey AS QUAD , BYREF phAgreedSecret AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
DECLARE FUNCTION NCryptDeriveKey LIB "ncrypt.dll" ALIAS "NCryptDeriveKey" ( BYVAL hSharedSecret AS QUAD , BYREF pwszKDF AS WSTRINGZ , BYREF pParameterList AS NCryptBufferDesc , BYVAL pbDerivedKey AS QUAD , BYVAL cbDerivedKey AS QUAD , BYREF pcbResult AS QUAD , BYVAL dwFlags AS QUAD ) AS LONG ' SECURITY_STATUS
'#define NCRYPT_KEY_STORAGE_INTERFACE_VERSION BCRYPT_MAKE_INTERFACE_VERSION(1,0)
#ENDIF
