103 EVP_MD_CTX *
mdctx = EVP_MD_CTX_create();
104 EVP_DigestInit_ex(
mdctx, md, NULL);
106 EVP_DigestFinal_ex(
mdctx, out, &d_len);
110 EVP_MD_CTX_destroy(
mdctx);
119 BCRYPT_ALG_HANDLE hAlg = 0;
120 BCRYPT_HASH_HANDLE hHash = 0;
124 PBYTE pbHashObj = NULL;
131 if (!BCRYPT_SUCCESS(status =
132 BCryptOpenAlgorithmProvider(&hAlg, alg, NULL, 0))) {
136 if (!BCRYPT_SUCCESS(status = BCryptGetProperty(hAlg, BCRYPT_OBJECT_LENGTH,
138 sizeof(DWORD), &cbData, 0))) {
142 if (!(pbHashObj = (PBYTE) malloc(cbHashObj))) {
146 if (!BCRYPT_SUCCESS(status = BCryptGetProperty(hAlg, BCRYPT_HASH_LENGTH,
147 (PBYTE) &cbHash,
sizeof(DWORD),
156 if (!BCRYPT_SUCCESS(status = BCryptCreateHash(hAlg, &hHash, pbHashObj,
157 cbHashObj, NULL, 0, 0))) {
161 if (!BCRYPT_SUCCESS(status = BCryptHashData(hHash, (PBYTE) in,
len, 0))) {
165 if (!BCRYPT_SUCCESS(status = BCryptFinishHash(hHash, out, cbHash, 0))) {
178 BCryptDestroyHash(hHash);
181 BCryptCloseAlgorithmProvider(hAlg, 0);
200 const EVP_MD *md = NULL;
222 if (!BCRYPT_SUCCESS(status = BCryptOpenAlgorithmProvider(&(ctx_temp->hAlg),
227 if (!BCRYPT_SUCCESS(status =
228 BCryptGetProperty(ctx_temp->hAlg, BCRYPT_OBJECT_LENGTH,
229 (PBYTE) &cbHashObj,
sizeof(DWORD),
234 if (!(ctx_temp->pbHashObj = (PBYTE) malloc(cbHashObj))) {
238 if (!BCRYPT_SUCCESS(status =
239 BCryptGetProperty(ctx_temp->hAlg, BCRYPT_HASH_LENGTH,
240 (PBYTE) &cbHash,
sizeof(DWORD),
245 ctx_temp->cbHash = (size_t) cbHash;
247 if (!BCRYPT_SUCCESS(status =
248 BCryptCreateHash(ctx_temp->hAlg, &(ctx_temp->hHash),
249 ctx_temp->pbHashObj, cbHashObj, NULL,
250 0, BCRYPT_HASH_REUSABLE_FLAG))) {
254 ctx_temp->fFinal =
true;
261 if (!(ctx_temp->
mdctx = EVP_MD_CTX_create())) {
278 if (ctx_temp->hHash) {
279 BCryptDestroyHash(ctx_temp->hHash);
281 if (ctx_temp->pbHashObj) {
282 free(ctx_temp->pbHashObj);
284 if (ctx_temp->hAlg) {
285 BCryptCloseAlgorithmProvider(ctx_temp->hAlg, 0);
bool hash_bytes(const uint8_t *in, size_t len, hash_t hash, uint8_t *out, size_t *out_len)