20 #ifndef WINPR_BCRYPT_H
21 #define WINPR_BCRYPT_H
27 #include <winpr/winpr.h>
28 #include <winpr/wtypes.h>
30 typedef PVOID BCRYPT_HANDLE;
31 typedef PVOID BCRYPT_ALG_HANDLE;
32 typedef PVOID BCRYPT_KEY_HANDLE;
33 typedef PVOID BCRYPT_HASH_HANDLE;
34 typedef PVOID BCRYPT_SECRET_HANDLE;
36 static const WCHAR BCRYPT_RSA_ALGORITHM[] = u
"RSA";
37 static const WCHAR BCRYPT_RSA_SIGN_ALGORITHM[] = u
"RSA_SIGN";
38 static const WCHAR BCRYPT_DH_ALGORITHM[] = u
"DH";
39 static const WCHAR BCRYPT_DSA_ALGORITHM[] = u
"DSA";
40 static const WCHAR BCRYPT_RC2_ALGORITHM[] = u
"RC2";
41 static const WCHAR BCRYPT_RC4_ALGORITHM[] = u
"RC4";
42 static const WCHAR BCRYPT_AES_ALGORITHM[] = u
"AES";
43 static const WCHAR BCRYPT_DES_ALGORITHM[] = u
"DES";
44 static const WCHAR BCRYPT_DESX_ALGORITHM[] = u
"DESX";
45 static const WCHAR BCRYPT_3DES_ALGORITHM[] = u
"3DES";
46 static const WCHAR BCRYPT_3DES_112_ALGORITHM[] = u
"3DES_112";
47 static const WCHAR BCRYPT_MD2_ALGORITHM[] = u
"MD2";
48 static const WCHAR BCRYPT_MD4_ALGORITHM[] = u
"MD4";
49 static const WCHAR BCRYPT_MD5_ALGORITHM[] = u
"MD5";
50 static const WCHAR BCRYPT_SHA1_ALGORITHM[] = u
"SHA1";
51 static const WCHAR BCRYPT_SHA256_ALGORITHM[] = u
"SHA256";
52 static const WCHAR BCRYPT_SHA384_ALGORITHM[] = u
"SHA384";
53 static const WCHAR BCRYPT_SHA512_ALGORITHM[] = u
"SHA512";
54 static const WCHAR BCRYPT_AES_GMAC_ALGORITHM[] = u
"AES-GMAC";
55 static const WCHAR BCRYPT_AES_CMAC_ALGORITHM[] = u
"AES-CMAC";
56 static const WCHAR BCRYPT_ECDSA_P256_ALGORITHM[] = u
"ECDSA_P256";
57 static const WCHAR BCRYPT_ECDSA_P384_ALGORITHM[] = u
"ECDSA_P384";
58 static const WCHAR BCRYPT_ECDSA_P521_ALGORITHM[] = u
"ECDSA_P521";
59 static const WCHAR BCRYPT_ECDH_P256_ALGORITHM[] = u
"ECDSA_P256";
60 static const WCHAR BCRYPT_ECDH_P384_ALGORITHM[] = u
"ECDSA_P384";
61 static const WCHAR BCRYPT_ECDH_P521_ALGORITHM[] = u
"ECDSA_P521";
62 static const WCHAR BCRYPT_RNG_ALGORITHM[] = u
"RNG";
63 static const WCHAR BCRYPT_RNG_FIPS186_DSA_ALGORITHM[] = u
"FIPS186DSARNG";
64 static const WCHAR BCRYPT_RNG_DUAL_EC_ALGORITHM[] = u
"DUALECRNG";
66 static const WCHAR BCRYPT_ECDSA_ALGORITHM[] = u
"ECDSA";
67 static const WCHAR BCRYPT_ECDH_ALGORITHM[] = u
"ECDH";
68 static const WCHAR BCRYPT_XTS_AES_ALGORITHM[] = u
"XTS-AES";
70 static const WCHAR MS_PRIMITIVE_PROVIDER[] = u
"Microsoft Primitive Provider";
71 static const WCHAR MS_PLATFORM_CRYPTO_PROVIDER[] = u
"Microsoft Platform Crypto Provider";
73 #define BCRYPT_ALG_HANDLE_HMAC_FLAG 0x00000008
74 #define BCRYPT_PROV_DISPATCH 0x00000001
76 static const WCHAR BCRYPT_OBJECT_LENGTH[] = u
"ObjectLength";
77 static const WCHAR BCRYPT_ALGORITHM_NAME[] = u
"AlgorithmName";
78 static const WCHAR BCRYPT_PROVIDER_HANDLE[] = u
"ProviderHandle";
79 static const WCHAR BCRYPT_CHAINING_MODE[] = u
"ChainingMode";
80 static const WCHAR BCRYPT_BLOCK_LENGTH[] = u
"BlockLength";
81 static const WCHAR BCRYPT_KEY_LENGTH[] = u
"KeyLength";
82 static const WCHAR BCRYPT_KEY_OBJECT_LENGTH[] = u
"KeyObjectLength";
83 static const WCHAR BCRYPT_KEY_STRENGTH[] = u
"KeyStrength";
84 static const WCHAR BCRYPT_KEY_LENGTHS[] = u
"KeyLengths";
85 static const WCHAR BCRYPT_BLOCK_SIZE_LIST[] = u
"BlockSizeList";
86 static const WCHAR BCRYPT_EFFECTIVE_KEY_LENGTH[] = u
"EffectiveKeyLength";
87 static const WCHAR BCRYPT_HASH_LENGTH[] = u
"HashDigestLength";
88 static const WCHAR BCRYPT_HASH_OID_LIST[] = u
"HashOIDList";
89 static const WCHAR BCRYPT_PADDING_SCHEMES[] = u
"PaddingSchemes";
90 static const WCHAR BCRYPT_SIGNATURE_LENGTH[] = u
"SignatureLength";
91 static const WCHAR BCRYPT_HASH_BLOCK_LENGTH[] = u
"HashBlockLength";
92 static const WCHAR BCRYPT_AUTH_TAG_LENGTH[] = u
"AuthTagLength";
93 static const WCHAR BCRYPT_PRIMITIVE_TYPE[] = u
"PrimitiveType";
94 static const WCHAR BCRYPT_IS_KEYED_HASH[] = u
"IsKeyedHash";
95 static const WCHAR BCRYPT_KEY_DATA_BLOB[] = u
"KeyDataBlob";
97 #define BCRYPT_BLOCK_PADDING 0x00000001
99 #define BCRYPT_KEY_DATA_BLOB_MAGIC 0x4d42444b
100 #define BCRYPT_KEY_DATA_BLOB_VERSION1 0x1
114 WINPR_API NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* phAlgorithm, LPCWSTR pszAlgId,
115 LPCWSTR pszImplementation, ULONG dwFlags);
117 WINPR_API NTSTATUS BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags);
119 WINPR_API NTSTATUS BCryptGetProperty(BCRYPT_HANDLE hObject, LPCWSTR pszProperty,
120 PUCHAR pbOutput, ULONG cbOutput, ULONG* pcbResult,
123 WINPR_API NTSTATUS BCryptCreateHash(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_HASH_HANDLE* phHash,
124 PUCHAR pbHashObject, ULONG cbHashObject, PUCHAR pbSecret,
125 ULONG cbSecret, ULONG dwFlags);
127 WINPR_API NTSTATUS BCryptDestroyHash(BCRYPT_HASH_HANDLE hHash);
129 WINPR_API NTSTATUS BCryptHashData(BCRYPT_HASH_HANDLE hHash, PUCHAR pbInput, ULONG cbInput,
132 WINPR_API NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE hHash, PUCHAR pbOutput, ULONG cbOutput,
135 WINPR_API NTSTATUS BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer,
136 ULONG cbBuffer, ULONG dwFlags);
138 WINPR_API NTSTATUS BCryptGenerateSymmetricKey(BCRYPT_ALG_HANDLE hAlgorithm,
139 BCRYPT_KEY_HANDLE* phKey, PUCHAR pbKeyObject,
140 ULONG cbKeyObject, PUCHAR pbSecret,
141 ULONG cbSecret, ULONG dwFlags);
143 WINPR_API NTSTATUS BCryptGenerateKeyPair(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE* phKey,
144 ULONG dwLength, ULONG dwFlags);
146 WINPR_API NTSTATUS BCryptImportKey(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE hImportKey,
147 LPCWSTR pszBlobType, BCRYPT_KEY_HANDLE* phKey,
148 PUCHAR pbKeyObject, ULONG cbKeyObject, PUCHAR pbInput,
149 ULONG cbInput, ULONG dwFlags);
151 WINPR_API NTSTATUS BCryptDestroyKey(BCRYPT_KEY_HANDLE hKey);
153 WINPR_API NTSTATUS BCryptEncrypt(BCRYPT_KEY_HANDLE hKey, PUCHAR pbInput, ULONG cbInput,
154 VOID* pPaddingInfo, PUCHAR pbIV, ULONG cbIV, PUCHAR pbOutput,
155 ULONG cbOutput, ULONG* pcbResult, ULONG dwFlags);
157 WINPR_API NTSTATUS BCryptDecrypt(BCRYPT_KEY_HANDLE hKey, PUCHAR pbInput, ULONG cbInput,
158 VOID* pPaddingInfo, PUCHAR pbIV, ULONG cbIV, PUCHAR pbOutput,
159 ULONG cbOutput, ULONG* pcbResult, ULONG dwFlags);