-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |