91 {
92#ifndef _WIN32_BCRYPT
93
94 const EVP_MD *md;
95
97
99 if (md == NULL) {
100 return false;
101 }
102
103 EVP_MD_CTX *
mdctx = EVP_MD_CTX_create();
104 EVP_DigestInit_ex(
mdctx, md, NULL);
106 EVP_DigestFinal_ex(
mdctx, out, &d_len);
107
109
110 EVP_MD_CTX_destroy(
mdctx);
111
112 return true;
113
114#else
115
116 bool res = false;
117 NTSTATUS status = 0;
118 LPCWSTR alg = NULL;
119 BCRYPT_ALG_HANDLE hAlg = 0;
120 BCRYPT_HASH_HANDLE hHash = 0;
121 DWORD cbHashObj = 0;
122 DWORD cbHash = 0;
123 DWORD cbData = 0;
124 PBYTE pbHashObj = NULL;
125
127 if (alg == NULL) {
128 return false;
129 }
130
131 if (!BCRYPT_SUCCESS(status =
132 BCryptOpenAlgorithmProvider(&hAlg, alg, NULL, 0))) {
133 goto cleanup;
134 }
135
136 if (!BCRYPT_SUCCESS(status = BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH,
137 (PBYTE) &cbHashObj,
138 sizeof(DWORD), &cbData, 0))) {
139 goto cleanup;
140 }
141
142 if (!(pbHashObj = (PBYTE) malloc(cbHashObj))) {
143 goto cleanup;
144 }
145
146 if (!BCRYPT_SUCCESS(status = BCryptGetProperty(hAlg, BCRYPT_HASH_LENGTH,
147 (PBYTE) &cbHash, sizeof(DWORD),
148 &cbData, 0))) {
149 goto cleanup;
150 }
151
153 goto cleanup;
154 }
155
156 if (!BCRYPT_SUCCESS(status = BCryptCreateHash(hAlg, &hHash, pbHashObj,
157 cbHashObj, NULL, 0, 0))) {
158 goto cleanup;
159 }
160
161 if (!BCRYPT_SUCCESS(status = BCryptHashData(hHash, (PBYTE) in,
len, 0))) {
162 goto cleanup;
163 }
164
165 if (!BCRYPT_SUCCESS(status = BCryptFinishHash(hHash, out, cbHash, 0))) {
166 goto cleanup;
167 }
168
170 res = true;
171
172cleanup:
173
174 if (pbHashObj) {
175 free(pbHashObj);
176 }
177 if (hHash) {
178 BCryptDestroyHash(hHash);
179 }
180 if (hAlg) {
181 BCryptCloseAlgorithmProvider(hAlg, 0);
182 }
183
184 return res;
185
186#endif
187}
const YH_INTERNAL EVP_MD * get_hash(hash_t hash)