Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment
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 ; Michal Simek ; > Siva Durga Prasad Paladugu > Cc: u-boot@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 ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [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() ? > 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@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 ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment
> -Original Message- > From: Marek Vasut [mailto:ma...@denx.de] > Sent: Friday, December 28, 2018 6:05 PM > To: Ooi, Joyce ; Michal Simek > ; Siva Durga Prasad Paladugu > > Cc: u-boot@lists.denx.de; See, Chin Liang ; Chee, > Tien Fong ; Tan, Ley Foon > > 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 #else #include "fdt_host.h" #include "mkimage.h" #include #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 ; Michal Simek > >> ; Siva Durga Prasad Paladugu > >> > >> Cc: u-boot@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 ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment
On 12/28/18 2:32 PM, Ooi, Joyce wrote: >> -Original Message- >> From: Marek Vasut [mailto:ma...@denx.de] >> Sent: Friday, December 28, 2018 6:05 PM >> To: Ooi, Joyce ; Michal Simek >> ; Siva Durga Prasad Paladugu >> >> Cc: u-boot@lists.denx.de; See, Chin Liang ; Chee, >> Tien Fong ; Tan, Ley Foon >> >> 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 > #else > #include "fdt_host.h" > #include "mkimage.h" > #include > #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. -- Best regards, Marek Vasut ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
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:ma...@denx.de] Sent: Friday, December 28, 2018 6:05 PM To: Ooi, Joyce ; Michal Simek ; Siva Durga Prasad Paladugu Cc: u-boot@lists.denx.de; See, Chin Liang ; Chee, Tien Fong ; Tan, Ley Foon 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 #else #include "fdt_host.h" #include "mkimage.h" #include #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. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment
> -Original Message- > From: Simon Goldschmidt [mailto:simon.k.r.goldschm...@gmail.com] > Sent: Saturday, December 29, 2018 5:04 AM > To: Marek Vasut ; Ooi, Joyce ; Michal > Simek ; Siva Durga Prasad Paladugu > > Cc: u-boot@lists.denx.de; Chee, Tien Fong ; See, > Chin Liang > 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:ma...@denx.de] > >>> Sent: Friday, December 28, 2018 6:05 PM > >>> To: Ooi, Joyce ; Michal Simek > >>> ; Siva Durga Prasad Paladugu > >>> > >>> Cc: u-boot@lists.denx.de; See, Chin Liang > >>> ; Chee, Tien Fong > >>> ; Tan, Ley Foon > >>> 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 > >> #else > >> #include "fdt_host.h" > >> #include "mkimage.h" > >> #include > >> #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. > > ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
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 wrote: > > > -Original Message- > > From: Simon Goldschmidt [mailto:simon.k.r.goldschm...@gmail.com] > > Sent: Saturday, December 29, 2018 5:04 AM > > To: Marek Vasut ; Ooi, Joyce ; Michal > > Simek ; Siva Durga Prasad Paladugu > > > > Cc: u-boot@lists.denx.de; Chee, Tien Fong ; See, > > Chin Liang > > 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:ma...@denx.de] > > >>> Sent: Friday, December 28, 2018 6:05 PM > > >>> To: Ooi, Joyce ; Michal Simek > > >>> ; Siva Durga Prasad Paladugu > > >>> > > >>> Cc: u-boot@lists.denx.de; See, Chin Liang > > >>> ; Chee, Tien Fong > > >>> ; Tan, Ley Foon > > >>> 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 > > >> #else > > >> #include "fdt_host.h" > > >> #include "mkimage.h" > > >> #include > > >> #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. > > > > ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32-bit alignment
> -Original Message- > From: Simon Goldschmidt [mailto:simon.k.r.goldschm...@gmail.com] > Sent: Friday, January 4, 2019 5:46 PM > To: Ooi, Joyce > Cc: Marek Vasut ; Michal Simek ; > Siva Durga Prasad Paladugu ; u- > b...@lists.denx.de; Chee, Tien Fong ; See, Chin > Liang > 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 wrote: > > > > > -Original Message- > > > From: Simon Goldschmidt [mailto:simon.k.r.goldschm...@gmail.com] > > > Sent: Saturday, December 29, 2018 5:04 AM > > > To: Marek Vasut ; Ooi, Joyce ; > > > Michal Simek ; Siva Durga Prasad Paladugu > > > > > > Cc: u-boot@lists.denx.de; Chee, Tien Fong > > > ; See, Chin Liang > > > > > > 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:ma...@denx.de] > > > >>> Sent: Friday, December 28, 2018 6:05 PM > > > >>> To: Ooi, Joyce ; Michal Simek > > > >>> ; Siva Durga Prasad Paladugu > > > >>> > > > >>> Cc: u-boot@lists.denx.de; See, Chin Liang > > > >>> ; Chee, Tien Fong > > > >>> ; Tan, Ley Foon > > > >>> > > > >>> 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 > > > >> #else > > > >> #include "fdt_host.h" > > > >> #include "mkimage.h" > > > >> #include > > > >> #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. > > > > > > ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot