[U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment

Marek Vasut marex at denx.de
Fri Dec 28 10:05:06 UTC 2018


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 <marex at denx.de>; Michal Simek <michal.simek at xilinx.com>;
>> Siva Durga Prasad Paladugu <siva.durga.paladugu at xilinx.com>
>> Cc: u-boot at lists.denx.de; Ooi, Joyce <joyce.ooi at intel.com>; See, Chin Liang
>> <chin.liang.see at intel.com>; Chee, Tien Fong <tien.fong.chee at intel.com>; Tan,
>> Ley Foon <ley.foon.tan at intel.com>
>> 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 <joyce.ooi at intel.com>
>> ---
>>  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


More information about the U-Boot mailing list