diff mbox series

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

Message ID 1544257051-3526-1-git-send-email-joyce.ooi@intel.com
State Deferred
Delegated to: Tom Rini
Headers show
Series [U-Boot] rsa: read out public_exponent value based on 32-bit alignment | expand

Commit Message

Joyce Ooi Dec. 8, 2018, 8:17 a.m. UTC
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@intel.com>
---
 lib/rsa/rsa-mod-exp.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Comments

Joyce Ooi Dec. 28, 2018, 7:30 a.m. UTC | #1
Hi Marek,

Any comments about this?

Thanks,
Joyce Ooi

> -----Original Message-----
> From: Ooi, Joyce
> Sent: Saturday, December 8, 2018 4:18 PM
> To: Marek Vasut <marex@denx.de>; Michal Simek <michal.simek@xilinx.com>;
> Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
> Cc: u-boot@lists.denx.de; Ooi, Joyce <joyce.ooi@intel.com>; See, Chin Liang
> <chin.liang.see@intel.com>; Chee, Tien Fong <tien.fong.chee@intel.com>; Tan,
> Ley Foon <ley.foon.tan@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@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
Marek Vasut Dec. 28, 2018, 10:05 a.m. UTC | #2
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@denx.de>; Michal Simek <michal.simek@xilinx.com>;
>> Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
>> Cc: u-boot@lists.denx.de; Ooi, Joyce <joyce.ooi@intel.com>; See, Chin Liang
>> <chin.liang.see@intel.com>; Chee, Tien Fong <tien.fong.chee@intel.com>; Tan,
>> Ley Foon <ley.foon.tan@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@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
>
Joyce Ooi Dec. 28, 2018, 1:32 p.m. UTC | #3
> -----Original Message-----
> From: Marek Vasut [mailto:marex@denx.de]
> Sent: Friday, December 28, 2018 6:05 PM
> To: Ooi, Joyce <joyce.ooi@intel.com>; Michal Simek
> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> <siva.durga.paladugu@xilinx.com>
> Cc: u-boot@lists.denx.de; See, Chin Liang <chin.liang.see@intel.com>; Chee,
> Tien Fong <tien.fong.chee@intel.com>; Tan, Ley Foon
> <ley.foon.tan@intel.com>
> Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit
> alignment
> 
> On 12/28/18 8:30 AM, Ooi, Joyce wrote:
> > Hi Marek,
> 
> Hi,
> 
> > Any comments about this?
> 
> Use get_unaligned() ?
It seems that if USE_HOSTCC is enabled, get_unaligned_* can't be used.

In lib/rsa/rsa-mod-exp.c,
#ifndef USE_HOSTCC
..
#include <asm/unaligned.h>
#else
#include "fdt_host.h"
#include "mkimage.h"
#include <fdt_support.h>
#endif

So, to make it more generic (with or without USE_HOSTCC enabled), I read out
the public_exponent as two 32-bit datas and then concatenating them into a
64-bit data.
> 
> > Thanks,
> > Joyce Ooi
> >
> >> -----Original Message-----
> >> From: Ooi, Joyce
> >> Sent: Saturday, December 8, 2018 4:18 PM
> >> To: Marek Vasut <marex@denx.de>; Michal Simek
> >> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> >> <siva.durga.paladugu@xilinx.com>
> >> Cc: u-boot@lists.denx.de; Ooi, Joyce <joyce.ooi@intel.com>; See, Chin
> >> Liang <chin.liang.see@intel.com>; Chee, Tien Fong
> >> <tien.fong.chee@intel.com>; Tan, Ley Foon <ley.foon.tan@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@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
Marek Vasut Dec. 28, 2018, 6:44 p.m. UTC | #4
On 12/28/18 2:32 PM, Ooi, Joyce wrote:
>> -----Original Message-----
>> From: Marek Vasut [mailto:marex@denx.de]
>> Sent: Friday, December 28, 2018 6:05 PM
>> To: Ooi, Joyce <joyce.ooi@intel.com>; Michal Simek
>> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
>> <siva.durga.paladugu@xilinx.com>
>> Cc: u-boot@lists.denx.de; See, Chin Liang <chin.liang.see@intel.com>; Chee,
>> Tien Fong <tien.fong.chee@intel.com>; Tan, Ley Foon
>> <ley.foon.tan@intel.com>
>> Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit
>> alignment
>>
>> On 12/28/18 8:30 AM, Ooi, Joyce wrote:
>>> Hi Marek,
>>
>> Hi,
>>
>>> Any comments about this?
>>
>> Use get_unaligned() ?
> It seems that if USE_HOSTCC is enabled, get_unaligned_* can't be used.

Can this be fixed ?

> In lib/rsa/rsa-mod-exp.c,
> #ifndef USE_HOSTCC
> ..
> #include <asm/unaligned.h>
> #else
> #include "fdt_host.h"
> #include "mkimage.h"
> #include <fdt_support.h>
> #endif
> 
> So, to make it more generic (with or without USE_HOSTCC enabled), I read out
> the public_exponent as two 32-bit datas and then concatenating them into a
> 64-bit data.

See above -- I'd much rather see the get_unaligned() fixed and used.
Simon Goldschmidt Dec. 28, 2018, 9:04 p.m. UTC | #5
Am 28.12.2018 um 19:44 schrieb Marek Vasut:
> On 12/28/18 2:32 PM, Ooi, Joyce wrote:
>>> -----Original Message-----
>>> From: Marek Vasut [mailto:marex@denx.de]
>>> Sent: Friday, December 28, 2018 6:05 PM
>>> To: Ooi, Joyce <joyce.ooi@intel.com>; Michal Simek
>>> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
>>> <siva.durga.paladugu@xilinx.com>
>>> Cc: u-boot@lists.denx.de; See, Chin Liang <chin.liang.see@intel.com>; Chee,
>>> Tien Fong <tien.fong.chee@intel.com>; Tan, Ley Foon
>>> <ley.foon.tan@intel.com>
>>> Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit
>>> alignment
>>>
>>> On 12/28/18 8:30 AM, Ooi, Joyce wrote:
>>>> Hi Marek,
>>>
>>> Hi,
>>>
>>>> Any comments about this?
>>>
>>> Use get_unaligned() ?
>> It seems that if USE_HOSTCC is enabled, get_unaligned_* can't be used.
> 
> Can this be fixed ?

I was working on a patch (or series?) to make USE_HOSTCC more generic 
(i.e. concentrate the HOSTCC specific things in some header files, 
hopefully) as I have stumbled accross this when adding 
compression/uncompression to mkimage, but I haven't found the time to 
complete this, yet.

Nevertheless, I think this is where we should go, rather then add yet 
more #ifdef USE_HOSTCC to C files...

Regards,
Simon

> 
>> In lib/rsa/rsa-mod-exp.c,
>> #ifndef USE_HOSTCC
>> ..
>> #include <asm/unaligned.h>
>> #else
>> #include "fdt_host.h"
>> #include "mkimage.h"
>> #include <fdt_support.h>
>> #endif
>>
>> So, to make it more generic (with or without USE_HOSTCC enabled), I read out
>> the public_exponent as two 32-bit datas and then concatenating them into a
>> 64-bit data.
> 
> See above -- I'd much rather see the get_unaligned() fixed and used.
>
Joyce Ooi Jan. 4, 2019, 9:36 a.m. UTC | #6
> -----Original Message-----
> From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt@gmail.com]
> Sent: Saturday, December 29, 2018 5:04 AM
> To: Marek Vasut <marex@denx.de>; Ooi, Joyce <joyce.ooi@intel.com>; Michal
> Simek <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> <siva.durga.paladugu@xilinx.com>
> Cc: u-boot@lists.denx.de; Chee, Tien Fong <tien.fong.chee@intel.com>; See,
> Chin Liang <chin.liang.see@intel.com>
> Subject: Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-
> bit alignment
> 
> Am 28.12.2018 um 19:44 schrieb Marek Vasut:
> > On 12/28/18 2:32 PM, Ooi, Joyce wrote:
> >>> -----Original Message-----
> >>> From: Marek Vasut [mailto:marex@denx.de]
> >>> Sent: Friday, December 28, 2018 6:05 PM
> >>> To: Ooi, Joyce <joyce.ooi@intel.com>; Michal Simek
> >>> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> >>> <siva.durga.paladugu@xilinx.com>
> >>> Cc: u-boot@lists.denx.de; See, Chin Liang
> >>> <chin.liang.see@intel.com>; Chee, Tien Fong
> >>> <tien.fong.chee@intel.com>; Tan, Ley Foon <ley.foon.tan@intel.com>
> >>> Subject: Re: [PATCH] rsa: read out public_exponent value based on
> >>> 32-bit alignment
> >>>
> >>> On 12/28/18 8:30 AM, Ooi, Joyce wrote:
> >>>> Hi Marek,
> >>>
> >>> Hi,
> >>>
> >>>> Any comments about this?
> >>>
> >>> Use get_unaligned() ?
> >> It seems that if USE_HOSTCC is enabled, get_unaligned_* can't be used.
> >
> > Can this be fixed ?
> 
> I was working on a patch (or series?) to make USE_HOSTCC more generic (i.e.
> concentrate the HOSTCC specific things in some header files,
> hopefully) as I have stumbled accross this when adding
> compression/uncompression to mkimage, but I haven't found the time to
> complete this, yet.
> 
> Nevertheless, I think this is where we should go, rather then add yet more #ifdef
> USE_HOSTCC to C files...
> 
> Regards,
> Simon
Can you please help to fix this, Simon? I'm not too familiar with USE_HOSTCC..
Thanks.

> 
> >
> >> In lib/rsa/rsa-mod-exp.c,
> >> #ifndef USE_HOSTCC
> >> ..
> >> #include <asm/unaligned.h>
> >> #else
> >> #include "fdt_host.h"
> >> #include "mkimage.h"
> >> #include <fdt_support.h>
> >> #endif
> >>
> >> So, to make it more generic (with or without USE_HOSTCC enabled), I
> >> read out the public_exponent as two 32-bit datas and then
> >> concatenating them into a 64-bit data.
> >
> > See above -- I'd much rather see the get_unaligned() fixed and used.
> >
Simon Goldschmidt Jan. 4, 2019, 9:46 a.m. UTC | #7
On Fri, Jan 4, 2019 at 10:36 AM Ooi, Joyce <joyce.ooi@intel.com> wrote:
>
> > -----Original Message-----
> > From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt@gmail.com]
> > Sent: Saturday, December 29, 2018 5:04 AM
> > To: Marek Vasut <marex@denx.de>; Ooi, Joyce <joyce.ooi@intel.com>; Michal
> > Simek <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> > <siva.durga.paladugu@xilinx.com>
> > Cc: u-boot@lists.denx.de; Chee, Tien Fong <tien.fong.chee@intel.com>; See,
> > Chin Liang <chin.liang.see@intel.com>
> > Subject: Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-
> > bit alignment
> >
> > Am 28.12.2018 um 19:44 schrieb Marek Vasut:
> > > On 12/28/18 2:32 PM, Ooi, Joyce wrote:
> > >>> -----Original Message-----
> > >>> From: Marek Vasut [mailto:marex@denx.de]
> > >>> Sent: Friday, December 28, 2018 6:05 PM
> > >>> To: Ooi, Joyce <joyce.ooi@intel.com>; Michal Simek
> > >>> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> > >>> <siva.durga.paladugu@xilinx.com>
> > >>> Cc: u-boot@lists.denx.de; See, Chin Liang
> > >>> <chin.liang.see@intel.com>; Chee, Tien Fong
> > >>> <tien.fong.chee@intel.com>; Tan, Ley Foon <ley.foon.tan@intel.com>
> > >>> Subject: Re: [PATCH] rsa: read out public_exponent value based on
> > >>> 32-bit alignment
> > >>>
> > >>> On 12/28/18 8:30 AM, Ooi, Joyce wrote:
> > >>>> Hi Marek,
> > >>>
> > >>> Hi,
> > >>>
> > >>>> Any comments about this?
> > >>>
> > >>> Use get_unaligned() ?
> > >> It seems that if USE_HOSTCC is enabled, get_unaligned_* can't be used.
> > >
> > > Can this be fixed ?
> >
> > I was working on a patch (or series?) to make USE_HOSTCC more generic (i.e.
> > concentrate the HOSTCC specific things in some header files,
> > hopefully) as I have stumbled accross this when adding
> > compression/uncompression to mkimage, but I haven't found the time to
> > complete this, yet.
> >
> > Nevertheless, I think this is where we should go, rather then add yet more #ifdef
> > USE_HOSTCC to C files...
> >
> > Regards,
> > Simon
> Can you please help to fix this, Simon? I'm not too familiar with USE_HOSTCC..

I'm not there, yet, unfortunately. I don't have too much time for
U-Boot right now and my current work is getting of-platdata to run.

So it might be a few weeks until I can continue working on that.

Regards,
Simon

> Thanks.
>
> >
> > >
> > >> In lib/rsa/rsa-mod-exp.c,
> > >> #ifndef USE_HOSTCC
> > >> ..
> > >> #include <asm/unaligned.h>
> > >> #else
> > >> #include "fdt_host.h"
> > >> #include "mkimage.h"
> > >> #include <fdt_support.h>
> > >> #endif
> > >>
> > >> So, to make it more generic (with or without USE_HOSTCC enabled), I
> > >> read out the public_exponent as two 32-bit datas and then
> > >> concatenating them into a 64-bit data.
> > >
> > > See above -- I'd much rather see the get_unaligned() fixed and used.
> > >
>
Joyce Ooi Jan. 24, 2019, 6:09 a.m. UTC | #8
> -----Original Message-----
> From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt@gmail.com]
> Sent: Friday, January 4, 2019 5:46 PM
> To: Ooi, Joyce <joyce.ooi@intel.com>
> Cc: Marek Vasut <marex@denx.de>; Michal Simek <michal.simek@xilinx.com>;
> Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>; u-
> boot@lists.denx.de; Chee, Tien Fong <tien.fong.chee@intel.com>; See, Chin
> Liang <chin.liang.see@intel.com>
> Subject: Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-
> bit alignment
> 
> On Fri, Jan 4, 2019 at 10:36 AM Ooi, Joyce <joyce.ooi@intel.com> wrote:
> >
> > > -----Original Message-----
> > > From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt@gmail.com]
> > > Sent: Saturday, December 29, 2018 5:04 AM
> > > To: Marek Vasut <marex@denx.de>; Ooi, Joyce <joyce.ooi@intel.com>;
> > > Michal Simek <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> > > <siva.durga.paladugu@xilinx.com>
> > > Cc: u-boot@lists.denx.de; Chee, Tien Fong
> > > <tien.fong.chee@intel.com>; See, Chin Liang
> > > <chin.liang.see@intel.com>
> > > Subject: Re: [U-Boot] [PATCH] rsa: read out public_exponent value
> > > based on 32- bit alignment
> > >
> > > Am 28.12.2018 um 19:44 schrieb Marek Vasut:
> > > > On 12/28/18 2:32 PM, Ooi, Joyce wrote:
> > > >>> -----Original Message-----
> > > >>> From: Marek Vasut [mailto:marex@denx.de]
> > > >>> Sent: Friday, December 28, 2018 6:05 PM
> > > >>> To: Ooi, Joyce <joyce.ooi@intel.com>; Michal Simek
> > > >>> <michal.simek@xilinx.com>; Siva Durga Prasad Paladugu
> > > >>> <siva.durga.paladugu@xilinx.com>
> > > >>> Cc: u-boot@lists.denx.de; See, Chin Liang
> > > >>> <chin.liang.see@intel.com>; Chee, Tien Fong
> > > >>> <tien.fong.chee@intel.com>; Tan, Ley Foon
> > > >>> <ley.foon.tan@intel.com>
> > > >>> Subject: Re: [PATCH] rsa: read out public_exponent value based
> > > >>> on 32-bit alignment
> > > >>>
> > > >>> On 12/28/18 8:30 AM, Ooi, Joyce wrote:
> > > >>>> Hi Marek,
> > > >>>
> > > >>> Hi,
> > > >>>
> > > >>>> Any comments about this?
> > > >>>
> > > >>> Use get_unaligned() ?
> > > >> It seems that if USE_HOSTCC is enabled, get_unaligned_* can't be used.
> > > >
> > > > Can this be fixed ?
> > >
> > > I was working on a patch (or series?) to make USE_HOSTCC more generic
> (i.e.
> > > concentrate the HOSTCC specific things in some header files,
> > > hopefully) as I have stumbled accross this when adding
> > > compression/uncompression to mkimage, but I haven't found the time
> > > to complete this, yet.
> > >
> > > Nevertheless, I think this is where we should go, rather then add
> > > yet more #ifdef USE_HOSTCC to C files...
> > >
> > > Regards,
> > > Simon
> > Can you please help to fix this, Simon? I'm not too familiar with USE_HOSTCC..
> 
> I'm not there, yet, unfortunately. I don't have too much time for U-Boot right
> now and my current work is getting of-platdata to run.
> 
> So it might be a few weeks until I can continue working on that.
No worries. Do let me know when you've worked on it.

Thanks!
> 
> Regards,
> Simon
> 
> > Thanks.
> >
> > >
> > > >
> > > >> In lib/rsa/rsa-mod-exp.c,
> > > >> #ifndef USE_HOSTCC
> > > >> ..
> > > >> #include <asm/unaligned.h>
> > > >> #else
> > > >> #include "fdt_host.h"
> > > >> #include "mkimage.h"
> > > >> #include <fdt_support.h>
> > > >> #endif
> > > >>
> > > >> So, to make it more generic (with or without USE_HOSTCC enabled),
> > > >> I read out the public_exponent as two 32-bit datas and then
> > > >> concatenating them into a 64-bit data.
> > > >
> > > > See above -- I'd much rather see the get_unaligned() fixed and used.
> > > >
> >
diff mbox series

Patch

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__);