Skip to content

Commit b16165d

Browse files
committed
switch to libretro-common hash method to avoid mbedtls dep for MSVC/UWP buildfix
1 parent 2e01da1 commit b16165d

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

gfx/drivers_shader/slang_cache.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
#include <file/file_path.h>
99
#include <compat/strl.h>
1010
#include <sys/stat.h>
11+
#include <lrc_hash.h>
1112

1213
#if defined(_WIN32)
1314
#include <direct.h>
1415
#endif
1516

16-
/* mbedtls SHA256 */
17-
#include "../../deps/mbedtls/mbedtls/sha256.h"
18-
1917
#include "../../configuration.h"
2018
#include "../../verbosity.h"
2119

@@ -149,27 +147,26 @@ extern "C" {
149147
bool spirv_cache_compute_hash(const char *vertex_source, const char *fragment_source,
150148
char *hash_out)
151149
{
152-
uint8_t digest[32];
153-
mbedtls_sha256_context sha;
154-
int i;
155-
156150
if (!vertex_source || !fragment_source || !hash_out)
157151
return false;
158152

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);
167165

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);
171168

172-
hash_out[64] = '\0';
169+
delete[] combined;
173170
return true;
174171
}
175172

0 commit comments

Comments
 (0)