diff --git a/xzre_code/CMakeLists.txt b/xzre_code/CMakeLists.txt index cdf97e3..dbe8437 100644 --- a/xzre_code/CMakeLists.txt +++ b/xzre_code/CMakeLists.txt @@ -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 diff --git a/xzre_code/rsa_key_hash.c b/xzre_code/rsa_key_hash.c new file mode 100644 index 0000000..781fec9 --- /dev/null +++ b/xzre_code/rsa_key_hash.c @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2024 Stefano Moioli + **/ +#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; +} \ No newline at end of file