crypto: Add manual relocation
cover crypto: Add manual relocation
Hi,
This patch series fixes manual relocation issue, as it is crashing when using RSA signed images on microblaze.
Thanks,
Michal
T Karthik Reddy (3):
common: hash: Manually relocate struct hash_algo
drivers: crypto: rsa_mod_exp: Add manual relocation for ops->mod_exp()
common: image-sig.c: Add manual relocation
common/hash.c | 29 +++++++++++++++++++++ common/image-sig.c | 29 +++++++++++++++++++++ drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 15 ++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
PATCH 1/3 common: hash: Manually relocate struct hash_algo
From: T Karthik Reddy <[email protected]>
This patch adds manual relocation for struct hash_algo if CONFIG_NEEDS_MANUAL_RELOC is enabled.
---
common/hash.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
common/hash.c +29 -0
@@ -30,6 +30,12 @@#include <u-boot/sha256.h> #include <u-boot/md5.h> +#if !defined(USE_HOSTCC ) && defined(CONFIG_NEEDS_MANUAL_RELOC ) +DECLARE_GLOBAL_DATA_PTR ; +#endif + +static void reloc_update (void ); +#if defined(CONFIG_SHA1 ) && !defined(CONFIG_SHA_PROG_HW_ACCEL )static int hash_init_sha1 (struct hash_algo *algo,void **ctxp) {
@@ -215,10 +221,31 @@ static struct hash_algo hash_algo[] = {#define multi_hash () 0#endif +static void reloc_update (void ) +{ +#if !defined(USE_HOSTCC ) && defined(CONFIG_NEEDS_MANUAL_RELOC ) +int i; +static bool done; + +if (!done) { + done = true; +for (i =0 ; i <ARRAY_SIZE (hash_algo); i++) { + hash_algo[i].name += gd->reloc_off; + hash_algo[i].hash_func_ws += gd->reloc_off; + hash_algo[i].hash_init += gd->reloc_off; + hash_algo[i].hash_update += gd->reloc_off; + hash_algo[i].hash_finish += gd->reloc_off; + } + } +#endif +} +int hash_lookup_algo (const char *algo_name,struct hash_algo **algop) {int i; +reloc_update (); +for (i =0 ; i <ARRAY_SIZE (hash_algo); i++) {if (!strcmp (algo_name, hash_algo[i].name)) { *algop = &hash_algo[i];
@@ -235,6 +262,8 @@ int hash_progressive_lookup_algo(const char *algo_name, {int i; +reloc_update (); +for (i =0 ; i <ARRAY_SIZE (hash_algo); i++) {if (!strcmp (algo_name, hash_algo[i].name)) {if (hash_algo[i].hash_init) {
Signature · 1 line
2.17.1
PATCH 2/3 drivers: crypto: rsa_mod_exp: Add manual relocation for ops->mod_exp()
In reply to Michal SimekFrom: T Karthik Reddy <[email protected]>
This patch adds manual relocation for Modular Exponentiation if CONFIG_NEEDS_MANUAL_RELOC is enabled.
---
drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/crypto/rsa_mod_exp/mod_exp_uclass.c +14 -1
@@ -13,10 +13,23 @@#include <asm/io.h> #include <linux/list.h> +#if !defined(USE_HOSTCC ) && defined(CONFIG_NEEDS_MANUAL_RELOC ) +DECLARE_GLOBAL_DATA_PTR ; +#endif +int rsa_mod_exp (struct udevice *dev,const uint8_t *sig,uint32_t sig_len,struct key_prop *node,uint8_t *out) { -const struct mod_exp_ops *ops =device_get_ops (dev); +struct mod_exp_ops *ops = (struct mod_exp_ops *)device_get_ops (dev); + +#if !defined(USE_HOSTCC ) && defined(CONFIG_NEEDS_MANUAL_RELOC ) +static bool done; + +if (!done) { + done = true; + ops->mod_exp += gd->reloc_off; + } +#endif if (!ops->mod_exp)return -ENOSYS ;
Signature · 1 line
2.17.1
PATCH 3/3 common: image-sig.c: Add manual relocation
In reply to Michal SimekFrom: T Karthik Reddy <[email protected]>
This patch adds manual relocation for struct checksum_algo & struct crypto_algo structures.
---
common/image-sig.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
common/image-sig.c +29 -0
@@ -89,6 +89,21 @@ struct checksum_algo *image_get_checksum_algo(const char *full_name)int i;const char *name; +#if !defined(USE_HOSTCC ) && defined(CONFIG_NEEDS_MANUAL_RELOC ) +static bool done; + +if (!done) { + done = true; +for (i =0 ; i <ARRAY_SIZE (checksum_algos); i++) { + checksum_algos[i].name += gd->reloc_off; +#if IMAGE_ENABLE_SIGN + checksum_algos[i].calculate_sign += gd->reloc_off; +#endif + checksum_algos[i].calculate += gd->reloc_off; + } + } +#endif +for (i =0 ; i <ARRAY_SIZE (checksum_algos); i++) { name = checksum_algos[i].name;/* Make sure names match and next char is a comma */
@@ -105,6 +120,20 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name)int i;const char *name; +#if !defined(USE_HOSTCC ) && defined(CONFIG_NEEDS_MANUAL_RELOC ) +static bool done; + +if (!done) { + done = true; +for (i =0 ; i <ARRAY_SIZE (crypto_algos); i++) { + crypto_algos[i].name += gd->reloc_off; + crypto_algos[i].sign += gd->reloc_off; + crypto_algos[i].add_verify_data += gd->reloc_off; + crypto_algos[i].verify += gd->reloc_off; + } + } +#endif +/* Move name to after the comma */ name =strchr (full_name,',' );if (!name)
Signature · 1 line
2.17.1
cover crypto: Add manual relocation
In reply to Michal Simekpo 14. 10. 2019 v 14:56 odesÃlatel Michal Simek
<[email protected]> napsal:
Quoted 15 lines
Hi,
This patch series fixes manual relocation issue, as it is crashing when using RSA signed images on microblaze.
Thanks,
MichalT Karthik Reddy (3):
common: hash: Manually relocate structhash_algo
drivers: crypto:rsa_mod_exp: Add manual relocation forops->mod_exp()
common:image-sig.c: Add manual relocation
Quoted 8 lines
common/hash.c | 29 +++++++++++++++++++++ common/image-sig.c | 29 +++++++++++++++++++++ drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 15 ++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-)--
2.17.1
Applied all.
M
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs