Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

Switch to xxhash for hashing blobs #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hw/ps4/liverpool/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
obj-y += gca/
obj-y += sam/
obj-y += xxhash/
obj-y += lvp_dce.o
obj-y += lvp_dce_d.o
obj-y += lvp_gart.o
Expand Down
22 changes: 5 additions & 17 deletions hw/ps4/liverpool/lvp_samu.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "lvp_samu.h"
#include "lvp_gart.h"
#include "qapi/error.h"
#include "crypto/hash.h"
#include "xxhash/xxhash.h"
#include "crypto/random.h"
#include "hw/ps4/macros.h"
#include "hw/pci/pci.h"
Expand Down Expand Up @@ -63,31 +63,19 @@ static zip_t *blobs_zip = NULL;
void liverpool_gc_samu_fakedecrypt(uint8_t *out_buffer,
const uint8_t *in_buffer, uint64_t in_length)
{
int err;
uint64_t hash;
char filename[256];
char hashstr[33];
char hashchr;
uint8_t *hash;
size_t hashlen = 0;
zip_stat_t stat;
zip_file_t *file;
size_t read;

/* compute filename of decrypted blob */
err = qcrypto_hash_bytes(QCRYPTO_HASH_ALG_MD5,
in_buffer, in_length, &hash, &hashlen, NULL);
if (err) {
hash = XXH64(in_buffer, in_length, 0);
if (!hash) {
printf("qemu: samu-fakedecrypt: Could not hash input data\n");
return;
}
memset(hashstr, 0, sizeof(hashstr));
for (int i = 0; i < 16; i++) {
hashchr = (hash[i] >> 4) & 0xF;
hashstr[2*i+0] = hashchr >= 0xA ? hashchr + 0x37 : hashchr + 0x30;
hashchr = (hash[i] >> 0) & 0xF;
hashstr[2*i+1] = hashchr >= 0xA ? hashchr + 0x37 : hashchr + 0x30;
}
snprintf(filename, sizeof(filename), "%s.bin", hashstr);
snprintf(filename, sizeof(filename), "%llX.bin", hash);

/* return decrypted blob contents */
if (zip_stat(blobs_zip, filename, 0, &stat) == -1) {
Expand Down
1 change: 1 addition & 0 deletions hw/ps4/liverpool/xxhash/Makefile.objs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += xxhash.o
Loading