Implement `XcModExp`

This commit is contained in:
Jannik Vogel 2019-03-03 20:58:30 +01:00
parent e1850c4277
commit af0c85286f
3 changed files with 23 additions and 19 deletions

View File

@ -152,24 +152,24 @@ void iaddg(int i, giant g); /* g += i, with i non-negative and < 2^16. */
int gsign(giant g); /* Returns the sign of g: -1, 0, 1. */
void absg(giant g); /* g := |g|. */
void ModExp(unsigned char* a_number, const unsigned char* b_number, unsigned int b_len, const unsigned char* c_number, unsigned int c_len, const unsigned char* d_number, unsigned int d_len)
{
giant b = newgiant(GIANT_INFINITY);
giant c = newgiant(GIANT_INFINITY);
giant d = newgiant(GIANT_INFINITY);
gigimport(b, b_number, b_len);
gigimport(c, c_number, c_len);
gigimport(d, d_number, d_len);
/* a = b := b^c (mod d). */
powermodg(b, c, d);
memcpy(a_number, b->n, d_len);
}
void RSAdecrypt(const unsigned char* c_number, unsigned char* cryptbuffer, RSA_PUBLIC_KEY key)
{
giant n = newgiant(GIANT_INFINITY);
giant e = newgiant(GIANT_INFINITY);
giant sig = newgiant(GIANT_INFINITY);
gigimport(sig, c_number, 256);
gigimport(n, key.KeyData.Modulus, 256);
gigimport(e, key.KeyData.Exponent, 4);
/* x := x^n (mod z). */
powermodg(sig, e, n);
memset(cryptbuffer, 0x00, 256);
memcpy(cryptbuffer, sig->n, 256);
ModExp(cryptbuffer, c_number, 256, key.KeyData.Exponent, 4, key.KeyData.Modulus, 256);
}
bool Verifyhash(const unsigned char* hash, const unsigned char* decryptBuffer, RSA_PUBLIC_KEY key)

View File

@ -47,6 +47,7 @@ typedef struct _RSA_PUBLIC_KEY
#pragma pack()
void ModExp(unsigned char* a_number, const unsigned char* b_number, unsigned int b_len, const unsigned char* c_number, unsigned int c_len, const unsigned char* d_number, unsigned int d_len);
void RSAdecrypt(const unsigned char* c_number, unsigned char* cryptbuffer, RSA_PUBLIC_KEY key);
bool Verifyhash(const unsigned char* hash, const unsigned char* decryptBuffer, RSA_PUBLIC_KEY key);

View File

@ -20,7 +20,8 @@
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
// * (c) 2016 Patrick van Logchem <pvanlogchem@gmail.com>
// * (c) 2016 Patrick van Logchem <pvanlogchem@gmail.com>
// * (c) 2019 Jannik Vogel
// *
// * All rights reserved
// *
@ -40,6 +41,7 @@ namespace xboxkrnl
#include "common\crypto\EmuSha.h" // For A_SHAInit, etc.
#include "common\crypto\LibRc4.h" // For RC4 Functions
#include "common\crypto\EmuDes.h" // For DES Functions
#include "common\crypto\EmuRSA.h" // For RSA Functions
// prevent name collisions
namespace NtDll
@ -212,9 +214,10 @@ xboxkrnl::ULONG NTAPI JumpedModExp
xboxkrnl::ULONG dwN
)
{
ULONG ret = 0;
LOG_UNIMPLEMENTED();
ULONG ret = 1;
unsigned int len = dwN * 4;
ModExp((unsigned char*)pA, (const unsigned char*)pB, len, (const unsigned char*)pC, len, (const unsigned char*)pD, len);
return ret;
}