Skip to contentSkip to conversation

rsa: read out public_exponent value based on 32-bit alignment

PATCH New Ooi 3 participants 9 messages Dec 8, 2018 – Jan 24, 2019

lore
Share & tools
lore

Ooi

#0 lore raw

PATCH 1/1 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.

---
 lib/rsa/rsa-mod-exp.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
lib/rsa/rsa-mod-exp.c +4 -2
index 9d78aa1..3eace38 100644
@@ -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__);
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Hi Marek,

Any comments about this?

Thanks,
Joyce Ooi

Quoted 47 lines

-----Original Message-----
From: Ooi, Joyce
Sent: Saturday, December 8, 2018 4:18 PM
To: Marek Vasut <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; Ooi, Joyce <[email protected]>; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
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.

---
 lib/rsa/rsa-mod-exp.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
lib/rsa/rsa-mod-exp.c index renamed from lib/rsa/rsa-mod-exp.c +0 -0

9d78aa1..3eace38 100644

lib/rsa/rsa-mod-exp.c +5 -3
@@ -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

#2 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Quoted 1 line · Joyce

Hi Marek,

Hi,

Quoted 1 line

Any comments about this?

Use get_unaligned() ?

Quoted 51 lines

Thanks,
Joyce Ooi

Quoted 47 lines

-----Original Message-----
From: Ooi, Joyce
Sent: Saturday, December 8, 2018 4:18 PM
To: Marek Vasut <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; Ooi, Joyce <[email protected]>; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
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.

---
 lib/rsa/rsa-mod-exp.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
lib/rsa/rsa-mod-exp.c index renamed from lib/rsa/rsa-mod-exp.c +0 -0

9d78aa1..3eace38 100644

lib/rsa/rsa-mod-exp.c +5 -3
@@ -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

Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Quoted 12 lines

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Friday, December 28, 2018 6:05 PM
To: Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit alignment

Quoted 8 lines
Quoted 1 line · Joyce

Hi Marek,

Hi,

Quoted 1 line

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.

Quoted 59 lines
Quoted 49 lines

Thanks,
Joyce Ooi

Quoted 45 lines

-----Original Message-----
From: Ooi, Joyce
Sent: Saturday, December 8, 2018 4:18 PM
To: Marek Vasut <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; Ooi, Joyce <[email protected]>; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
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.

---
 lib/rsa/rsa-mod-exp.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
lib/rsa/rsa-mod-exp.c index renamed from lib/rsa/rsa-mod-exp.c +0 -0

9d78aa1..3eace38 100644

lib/rsa/rsa-mod-exp.c +5 -2
@@ -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);
Quoted 5 lines
Quoted 4 lines
lib/rsa/rsa-mod-exp.c +0 -1
 	if (!key.len || !prop->modulus || !prop->rr) {
 		debug("%s: Missing RSA key info", __func__);
--

1.7.1

--
Best regards,
Marek Vasut

#4 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Quoted 13 lines · Joyce
Quoted 13 lines

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Friday, December 28, 2018 6:05 PM
To: Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit alignment

On 12/28/18 8:30 AM, Ooi, Joyce wrote:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Hi Marek,

Hi,

Quoted 1 line

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 ?

Quoted 10 lines

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

Quoted 3 lines

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.

Signature · 2 lines
Best regards,
Marek Vasut
#5 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Am 28.12.2018 um 19:44 schrieb Marek Vasut:

Quoted 16 lines · Joyce
Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Friday, December 28, 2018 6:05 PM
To: Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit alignment

Quoted 1 line · Joyce

Hi Marek,

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Hi,

Quoted 1 line

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

Quoted 17 lines
Quoted 11 lines

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

Quoted 3 lines

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.

#6 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Quoted 43 lines

-----Original Message-----
From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt at gmail.com]
Sent: Saturday, December 29, 2018 5:04 AM
To: Marek Vasut <[email protected]>; Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; Chee, Tien Fong <[email protected]>; See, Chin Liang <[email protected]>
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:

Quoted 16 lines · Joyce
Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Friday, December 28, 2018 6:05 PM
To: Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit alignment

Quoted 1 line · Joyce

Hi Marek,

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Hi,

Quoted 1 line

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.

Quoted 5 lines

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.

Quoted 18 lines
Quoted 18 lines
Quoted 12 lines

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

Quoted 3 lines

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.

#7 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Quoted 44 lines · Joyce
Quoted 44 lines

-----Original Message-----
From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt at gmail.com]
Sent: Saturday, December 29, 2018 5:04 AM
To: Marek Vasut <[email protected]>; Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; Chee, Tien Fong <[email protected]>; See, Chin Liang <[email protected]>
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:

Quoted 16 lines · Joyce
Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Friday, December 28, 2018 6:05 PM
To: Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit alignment

Quoted 1 line · Joyce

Hi Marek,

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Hi,

Quoted 1 line

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.

Quoted 6 lines
Quoted 5 lines

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

Quoted 21 lines

Thanks.

Quoted 18 lines
Quoted 18 lines
Quoted 12 lines

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

Quoted 3 lines

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.

#8 lore raw

PATCH 1/1 rsa: read out public_exponent value based on 32-bit alignment

Quoted 62 lines

-----Original Message-----
From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt at gmail.com]
Sent: Friday, January 4, 2019 5:46 PM
To: Ooi, Joyce <[email protected]>
Cc: Marek Vasut <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>; u- boot at lists.denx.de; Chee, Tien Fong <[email protected]>; See, Chin Liang <[email protected]>
Subject: Re: [U-Boot] [PATCH] rsa: read out public_exponent value based on 32- bit alignment

Quoted 33 lines · Joyce
Quoted 33 lines

-----Original Message-----
From: Simon Goldschmidt [mailto:simon.k.r.goldschmidt at gmail.com]
Sent: Saturday, December 29, 2018 5:04 AM
To: Marek Vasut <[email protected]>; Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; Chee, Tien Fong <[email protected]>; See, Chin Liang <[email protected]>
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:

Quoted 19 lines · Joyce
Quoted 18 lines
Quoted 18 lines

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Friday, December 28, 2018 6:05 PM
To: Ooi, Joyce <[email protected]>; Michal Simek <[email protected]>; Siva Durga Prasad Paladugu <[email protected]>
Cc: u-boot at lists.denx.de; See, Chin Liang <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: Re: [PATCH] rsa: read out public_exponent value based on 32-bit alignment

Quoted 1 line · Joyce

Hi Marek,

Hi,

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 8 lines
Quoted 8 lines

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...

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

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!

Quoted 25 lines

Regards,
Simon

Quoted 21 lines

Thanks.

Quoted 18 lines
Quoted 18 lines
Quoted 12 lines

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

Quoted 3 lines

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.