From e1850c427769b91b662661106cd2c3aeffc62916 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Mon, 4 Mar 2019 02:28:30 +0100 Subject: [PATCH] Fix `gigimport` in RSA --- src/common/crypto/EmuRsa.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/crypto/EmuRsa.cpp b/src/common/crypto/EmuRsa.cpp index 0cd833be0..36bf27b04 100644 --- a/src/common/crypto/EmuRsa.cpp +++ b/src/common/crypto/EmuRsa.cpp @@ -18,6 +18,7 @@ // * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. // * // * (c) 2018 ergo720 +// * (c) 2019 Jannik Vogel // * // * All rights reserved // * @@ -236,11 +237,6 @@ giant newgiant(int numshorts) return(thegiant); } -// ergo720: there's a bug in the original implementation of gigimport that prevents the rsa algorithm from working correctly on Windows (but -// for some reason it works on Ubuntu). This replacement implementation is taken from -// http://xbox-linux-devel.narkive.com/Qw6o31DP/xbedump-fix-for-array-out-of-bounds-access#post1 -// and it has been improved based on JayFoxRox suggestions. See the link below for the details -// https://github.com/xqemu/xbedump/pull/5 void gigimport(giant g, const unsigned char *buff, int len) { // copy buffered 'number' into giant's number buffer @@ -248,8 +244,14 @@ void gigimport(giant g, const unsigned char *buff, int len) { assert((len % 2) == 0); + // Get number of shorts g->sign = len / 2; + // Only count used shorts + while((g->sign >= 1) && (g->n[g->sign - 1] == 0)) { + g->sign -= 1; + } + assert(g->sign != 0); }