Skip to content

Commit

Permalink
xzre_code: add rsa_key_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Aug 3, 2024
1 parent eab7ebb commit f4e6005
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions xzre_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_library(xzre_code
fake_lzma_free.c
find_function.c
main_elf_parse.c
rsa_key_hash.c
run_backdoor_commands.c
secret_data_append_from_address.c
secret_data_append_item.c
Expand Down
28 changes: 28 additions & 0 deletions xzre_code/rsa_key_hash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2024 Stefano Moioli <[email protected]>
**/
#include "xzre.h"

BOOL rsa_key_hash(
const RSA *rsa,
u8 *mdBuf,
u64 mdBufSize,
imported_funcs_t *funcs
){
u8 buf[0x100A] = {0};
u64 written = 0, expSize = 0;
const BIGNUM *n = NULL, *e = NULL;
BOOL result = (TRUE
&& funcs && rsa && funcs->RSA_get0_key
&& (funcs->RSA_get0_key(rsa, &n, &e, NULL), e != NULL && n != NULL)
// get bytes of 'e'
&& bignum_serialize(buf, sizeof(buf), &written, e, funcs)
&& (expSize = written, written <= 0x1009)
// get bytes of 'n'
&& bignum_serialize(buf + written, sizeof(buf) - written, &written, n, funcs)
&& written + expSize <= sizeof(buf)
// hash e+n
&& sha256(buf, written + expSize, mdBuf, mdBufSize, funcs)
);
return result;
}

0 comments on commit f4e6005

Please sign in to comment.