summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2020-10-11 14:10:12 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2020-10-11 14:10:12 +0200
commitfcdfeb2a45bf0045e5d23104259de68b1da7b16e (patch)
tree5fab451e8bfb997e35130546c48fa779ca0e0017
parente371dee4a3278c6912ac5b1548042ae1d894bf6f (diff)
downloadrockbox-fcdfeb2a45bf0045e5d23104259de68b1da7b16e.tar.gz
rockbox-fcdfeb2a45bf0045e5d23104259de68b1da7b16e.zip
nwztools: re-implement MD5 on Windows
I forgot to fixup the windows up and missed it because of conditional compilation Change-Id: I526c765b9d56508815941ecb9b9dbac7ea407cf0
-rw-r--r--utils/nwztools/upgtools/mg.cpp25
-rw-r--r--utils/nwztools/upgtools/upgtool.c4
2 files changed, 27 insertions, 2 deletions
diff --git a/utils/nwztools/upgtools/mg.cpp b/utils/nwztools/upgtools/mg.cpp
index a4d06cd77f..79107e96bb 100644
--- a/utils/nwztools/upgtools/mg.cpp
+++ b/utils/nwztools/upgtools/mg.cpp
@@ -78,6 +78,31 @@ void MD5_CalculateDigest(void *digest, const void *input, size_t length)
78 CryptDestroyHash(hHash); 78 CryptDestroyHash(hHash);
79} 79}
80 80
81void *md5_start()
82{
83 if(!check_context())
84 return NULL;
85 HCRYPTHASH hHash;
86 if(!CryptCreateHash(g_hCryptProv, CALG_MD5, 0, 0, &hHash))
87 return NULL;
88 return reinterpret_cast<void *>(hHash);
89}
90
91void md5_update(void *md5_obj, const void *input, size_t length)
92{
93 HCRYPTHASH hHash = reinterpret_cast<HCRYPTHASH>(md5_obj);
94 CryptHashData(hHash, (const BYTE *)input, length, 0);
95}
96
97void md5_final(void *md5_obj, void *digest)
98{
99 HCRYPTHASH hHash = reinterpret_cast<HCRYPTHASH>(md5_obj);
100 DWORD dwSize = 16;
101 if(!CryptGetHashParam(hHash, HP_HASHVAL, (BYTE *)digest, &dwSize, 0))
102 return;
103 CryptDestroyHash(hHash);
104}
105
81void mg_decrypt_fw(void *in, int size, void *out, uint8_t *key) 106void mg_decrypt_fw(void *in, int size, void *out, uint8_t *key)
82{ 107{
83 if(!check_context() || (size % 8) != 0) 108 if(!check_context() || (size % 8) != 0)
diff --git a/utils/nwztools/upgtools/upgtool.c b/utils/nwztools/upgtools/upgtool.c
index 03d7d706d7..8235e487bf 100644
--- a/utils/nwztools/upgtools/upgtool.c
+++ b/utils/nwztools/upgtools/upgtool.c
@@ -225,7 +225,7 @@ static void compare_md5(struct upg_file_t *file, int idx, size_t filesize, uint8
225 cprintf_field(" Name: ", "%s ", g_md5name[idx]); 225 cprintf_field(" Name: ", "%s ", g_md5name[idx]);
226 cprintf(RED, found ? "Found" : " Not found"); 226 cprintf(RED, found ? "Found" : " Not found");
227 printf("\n"); 227 printf("\n");
228 cprintf_field(" Size: ", "%lu", filesize); 228 cprintf_field(" Size: ", "%lu", (unsigned long)filesize);
229 cprintf(RED, " %s", !found ? "Cannot check" : filesize == expected_size ? "Ok" : "Mismatch"); 229 cprintf(RED, " %s", !found ? "Cannot check" : filesize == expected_size ? "Ok" : "Mismatch");
230 printf("\n"); 230 printf("\n");
231 cprintf_field(" MD5:", " "); 231 cprintf_field(" MD5:", " ");
@@ -423,7 +423,7 @@ static int create_upg(int argc, char **argv)
423 MD5_CalculateDigest(md5, buf, size); 423 MD5_CalculateDigest(md5, buf, size);
424 size_t inc_sz = 16 + NWZ_MD5_SIZE * 2 + strlen(g_md5name[i]); 424 size_t inc_sz = 16 + NWZ_MD5_SIZE * 2 + strlen(g_md5name[i]);
425 md5_prepend = realloc(md5_prepend, md5_prepend_sz + inc_sz); 425 md5_prepend = realloc(md5_prepend, md5_prepend_sz + inc_sz);
426 md5_prepend_sz += sprintf(md5_prepend + md5_prepend_sz, "%lu ", size); 426 md5_prepend_sz += sprintf(md5_prepend + md5_prepend_sz, "%lu ", (unsigned long)size);
427 for(int i = 0; i < NWZ_MD5_SIZE; i++) 427 for(int i = 0; i < NWZ_MD5_SIZE; i++)
428 md5_prepend_sz += sprintf(md5_prepend + md5_prepend_sz, "%02x", md5[i]); 428 md5_prepend_sz += sprintf(md5_prepend + md5_prepend_sz, "%02x", md5[i]);
429 md5_prepend_sz += sprintf(md5_prepend + md5_prepend_sz, " %s\n", g_md5name[i]); 429 md5_prepend_sz += sprintf(md5_prepend + md5_prepend_sz, " %s\n", g_md5name[i]);