-
Notifications
You must be signed in to change notification settings - Fork 13
/
beatmap_win.cc
51 lines (39 loc) · 1.08 KB
/
beatmap_win.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <Windows.h>
#include <direct.h>
#include <Wincrypt.h>
#define mkdir _mkdir
internalfn
size_t get_exe_path(char* buf, size_t bufsize) {
return GetModuleFileNameA(0, buf, (u32)bufsize);
}
#define MD5_DIGEST_LENGTH 16
internalfn
void MD5(u8 const* buf, size_t buflen, u8* digest)
{
HCRYPTPROV prov;
if (!CryptAcquireContext(&prov, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
fprintf(stderr, "CryptAcquireContext 0x%08X\n", GetLastError());
return;
}
HCRYPTHASH hash;
if (!CryptCreateHash(prov, CALG_MD5, 0, 0, &hash))
{
fprintf(stderr, "CryptCreateHash 0x%08X\n", GetLastError());
goto cleanup;
}
if (!CryptHashData(hash, buf, (DWORD)buflen, 0))
{
fprintf(stderr, "CryptHashData 0x%08X\n", GetLastError());
goto cleanup2;
}
DWORD hashlen = MD5_DIGEST_LENGTH;
if (!CryptGetHashParam(hash, HP_HASHVAL, digest, &hashlen, 0))
{
fprintf(stderr, "CryptGetHashParam 0x%08X\n", GetLastError());
}
cleanup2:
CryptDestroyHash(hash);
cleanup:
CryptReleaseContext(prov, 0);
}