From: Marek Vasut Date: Fri, 28 Dec 2018 11:05:06 +0100 Subject: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment In-Reply-To: References: <1544257051-3526-1-git-send-email-joyce.ooi@intel.com> Message-ID: <7b9c9491-4af1-e8bc-ecfd-813d3cca0482@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 12/28/18 8:30 AM, Ooi, Joyce wrote: > Hi Marek, Hi, > Any comments about this? Use get_unaligned() ? > Thanks, > Joyce Ooi > >> -----Original Message----- >> From: Ooi, Joyce >> Sent: Saturday, December 8, 2018 4:18 PM >> To: Marek Vasut ; Michal Simek ; >> Siva Durga Prasad Paladugu >> Cc: u-boot at lists.denx.de; Ooi, Joyce ; See, Chin Liang >> ; Chee, Tien Fong ; Tan, >> Ley Foon >> Subject: [PATCH] rsa: read out public_exponent value based on 32-bit alignment >> >> Public_exponent is a 64-bit data, which is stored in the device tree blob in a 32- >> bit alignment address. This causes a problem for ARM64 when public_exponent >> is read out one shot as a 64-bit data from an unaligned address. Hence, to solve >> this problem, public_exponent is read out as two 32-bit datas, and then >> concatenating them. >> >> Signed-off-by: Ooi, Joyce >> --- >> lib/rsa/rsa-mod-exp.c | 6 ++++-- >> 1 files changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/lib/rsa/rsa-mod-exp.c b/lib/rsa/rsa-mod-exp.c index >> 9d78aa1..3eace38 100644 >> --- a/lib/rsa/rsa-mod-exp.c >> +++ b/lib/rsa/rsa-mod-exp.c >> @@ -252,6 +252,9 @@ int rsa_mod_exp_sw(const uint8_t *sig, uint32_t >> sig_len, { >> struct rsa_public_key key; >> int ret; >> + uint64_t exponent = >> + (uint64_t)(*((uint32_t *)(prop->public_exponent + 4))) << 32 | >> + *((uint32_t *)(prop->public_exponent)); >> >> if (!prop) { >> debug("%s: Skipping invalid prop", __func__); @@ -263,8 >> +266,7 @@ int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len, >> if (!prop->public_exponent) >> key.exponent = RSA_DEFAULT_PUBEXP; >> else >> - key.exponent = >> - fdt64_to_cpu(*((uint64_t *)(prop->public_exponent))); >> + key.exponent = fdt64_to_cpu(exponent); >> >> if (!key.len || !prop->modulus || !prop->rr) { >> debug("%s: Missing RSA key info", __func__); >> -- >> 1.7.1 > -- Best regards, Marek Vasut