FreeRDP
bcrypt.h
1 
20 #ifndef WINPR_BCRYPT_H
21 #define WINPR_BCRYPT_H
22 
23 #ifdef _WIN32
24 #include <bcrypt.h>
25 #else
26 
27 #include <winpr/winpr.h>
28 #include <winpr/wtypes.h>
29 
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;
35 
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";
65 
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";
69 
70 static const WCHAR MS_PRIMITIVE_PROVIDER[] = u"Microsoft Primitive Provider";
71 static const WCHAR MS_PLATFORM_CRYPTO_PROVIDER[] = u"Microsoft Platform Crypto Provider";
72 
73 #define BCRYPT_ALG_HANDLE_HMAC_FLAG 0x00000008
74 #define BCRYPT_PROV_DISPATCH 0x00000001
75 
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";
96 
97 #define BCRYPT_BLOCK_PADDING 0x00000001
98 
99 #define BCRYPT_KEY_DATA_BLOB_MAGIC 0x4d42444b
100 #define BCRYPT_KEY_DATA_BLOB_VERSION1 0x1
101 
102 typedef struct
103 {
104  ULONG dwMagic;
105  ULONG dwVersion;
106  ULONG cbKeyData;
108 
109 #ifdef __cplusplus
110 extern "C"
111 {
112 #endif
113 
114  WINPR_API NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* phAlgorithm, LPCWSTR pszAlgId,
115  LPCWSTR pszImplementation, ULONG dwFlags);
116 
117  WINPR_API NTSTATUS BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags);
118 
119  WINPR_API NTSTATUS BCryptGetProperty(BCRYPT_HANDLE hObject, LPCWSTR pszProperty,
120  PUCHAR pbOutput, ULONG cbOutput, ULONG* pcbResult,
121  ULONG dwFlags);
122 
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);
126 
127  WINPR_API NTSTATUS BCryptDestroyHash(BCRYPT_HASH_HANDLE hHash);
128 
129  WINPR_API NTSTATUS BCryptHashData(BCRYPT_HASH_HANDLE hHash, PUCHAR pbInput, ULONG cbInput,
130  ULONG dwFlags);
131 
132  WINPR_API NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE hHash, PUCHAR pbOutput, ULONG cbOutput,
133  ULONG dwFlags);
134 
135  WINPR_API NTSTATUS BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer,
136  ULONG cbBuffer, ULONG dwFlags);
137 
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);
142 
143  WINPR_API NTSTATUS BCryptGenerateKeyPair(BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE* phKey,
144  ULONG dwLength, ULONG dwFlags);
145 
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);
150 
151  WINPR_API NTSTATUS BCryptDestroyKey(BCRYPT_KEY_HANDLE hKey);
152 
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);
156 
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);
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* _WIN32 */
166 #endif /* WINPR_BCRYPT_H */