|
8 | 8 | #include <file/file_path.h> |
9 | 9 | #include <compat/strl.h> |
10 | 10 | #include <sys/stat.h> |
| 11 | +#include <lrc_hash.h> |
11 | 12 |
|
12 | 13 | #if defined(_WIN32) |
13 | 14 | #include <direct.h> |
14 | 15 | #endif |
15 | 16 |
|
16 | | -/* mbedtls SHA256 */ |
17 | | -#include "../../deps/mbedtls/mbedtls/sha256.h" |
18 | | - |
19 | 17 | #include "../../configuration.h" |
20 | 18 | #include "../../verbosity.h" |
21 | 19 |
|
@@ -149,27 +147,26 @@ extern "C" { |
149 | 147 | bool spirv_cache_compute_hash(const char *vertex_source, const char *fragment_source, |
150 | 148 | char *hash_out) |
151 | 149 | { |
152 | | - uint8_t digest[32]; |
153 | | - mbedtls_sha256_context sha; |
154 | | - int i; |
155 | | - |
156 | 150 | if (!vertex_source || !fragment_source || !hash_out) |
157 | 151 | return false; |
158 | 152 |
|
159 | | - /* Compute SHA256 hash of vertex + "|" + fragment source */ |
160 | | - mbedtls_sha256_init(&sha); |
161 | | - mbedtls_sha256_starts(&sha, 0); /* 0 for SHA256 */ |
162 | | - mbedtls_sha256_update(&sha, (const unsigned char *)vertex_source, strlen(vertex_source)); |
163 | | - mbedtls_sha256_update(&sha, (const unsigned char *)"|", 1); |
164 | | - mbedtls_sha256_update(&sha, (const unsigned char *)fragment_source, strlen(fragment_source)); |
165 | | - mbedtls_sha256_finish(&sha, digest); |
166 | | - mbedtls_sha256_free(&sha); |
| 153 | + /* Build combined hash input: vertex + "|" + fragment */ |
| 154 | + size_t vertex_len = strlen(vertex_source); |
| 155 | + size_t fragment_len = strlen(fragment_source); |
| 156 | + size_t total_len = vertex_len + 1 + fragment_len; /* 1 for "|" separator */ |
| 157 | + |
| 158 | + uint8_t *combined = new uint8_t[total_len]; |
| 159 | + if (!combined) |
| 160 | + return false; |
| 161 | + |
| 162 | + memcpy(combined, vertex_source, vertex_len); |
| 163 | + combined[vertex_len] = '|'; |
| 164 | + memcpy(combined + vertex_len + 1, fragment_source, fragment_len); |
167 | 165 |
|
168 | | - /* Convert to hex string */ |
169 | | - for (i = 0; i < 32; i++) |
170 | | - sprintf(hash_out + (i * 2), "%02x", digest[i]); |
| 166 | + /* Compute SHA256 hash using libretro-common */ |
| 167 | + sha256_hash(hash_out, combined, total_len); |
171 | 168 |
|
172 | | - hash_out[64] = '\0'; |
| 169 | + delete[] combined; |
173 | 170 | return true; |
174 | 171 | } |
175 | 172 |
|
|
0 commit comments