[PATCH v3 11/15] crypto: public-keys: use array of public_keys

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Sep 11 01:38:31 PDT 2024


Hello Sascha,

On 06.09.24 12:40, Sascha Hauer wrote:
> Instead of collecting the public keys directly in a section, we used to
> collect pointers to the public keys. This indirection is unnecessary,
> so drop it and put the keys directly into a section.

The loop adding the keys duplicates them first, so this change looks sensible.

> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

> ---
>  crypto/public-keys.c | 10 +++++-----
>  scripts/keytoc.c     | 12 ++++--------
>  2 files changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/crypto/public-keys.c b/crypto/public-keys.c
> index 36c308908d..dc51ef18f8 100644
> --- a/crypto/public-keys.c
> +++ b/crypto/public-keys.c
> @@ -73,15 +73,15 @@ int public_key_verify(const struct public_key *key, const uint8_t *sig,
>  	return -ENOKEY;
>  }
>  
> -extern const struct public_key * const __public_keys_start;
> -extern const struct public_key * const __public_keys_end;
> +extern const struct public_key __public_keys_start[];
> +extern const struct public_key __public_keys_end[];
>  
>  static int init_public_keys(void)
>  {
> -	const struct public_key * const *iter;
> +	const struct public_key *iter;
>  
> -	for (iter = &__public_keys_start; iter != &__public_keys_end; iter++) {
> -		struct public_key *key = public_key_dup(*iter);
> +	for (iter = __public_keys_start; iter != __public_keys_end; iter++) {
> +		struct public_key *key = public_key_dup(iter);
>  
>  		if (!key)
>  			continue;
> diff --git a/scripts/keytoc.c b/scripts/keytoc.c
> index 8b29118c95..bdda059759 100644
> --- a/scripts/keytoc.c
> +++ b/scripts/keytoc.c
> @@ -489,13 +489,11 @@ static int gen_key_ecdsa(EVP_PKEY *key, const char *key_name, const char *key_na
>  		fprintf(outfilep, "\t.y = %s_y,\n", key_name_c);
>  		fprintf(outfilep, "};\n");
>  		if (!standalone) {
> -			fprintf(outfilep, "\nstatic struct public_key %s_public_key = {\n", key_name_c);
> +			fprintf(outfilep, "\nstruct public_key __attribute__((section(\".public_keys.rodata.%s\"))) %s_public_key = {\n", key_name_c, key_name_c);
>  			fprintf(outfilep, "\t.type = PUBLIC_KEY_TYPE_ECDSA,\n");
>  			fprintf(outfilep, "\t.key_name_hint = \"%s\",\n", key_name);
>  			fprintf(outfilep, "\t.ecdsa = &%s,\n", key_name_c);
> -			fprintf(outfilep, "};");
> -			fprintf(outfilep, "\nstruct public_key *%s_ecdsa_p __attribute__((section(\".public_keys.rodata.%s\"))) = &%s_public_key;\n",
> -				key_name_c, key_name_c, key_name_c);
> +			fprintf(outfilep, "};\n");
>  		}
>  	}
>  
> @@ -555,13 +553,11 @@ static int gen_key_rsa(EVP_PKEY *key, const char *key_name, const char *key_name
>  		fprintf(outfilep, "};\n");
>  
>  		if (!standalone) {
> -			fprintf(outfilep, "\nstatic struct public_key %s_public_key = {\n", key_name_c);
> +			fprintf(outfilep, "\nstruct public_key __attribute__((section(\".public_keys.rodata.%s\"))) %s_public_key = {\n", key_name_c, key_name_c);
>  			fprintf(outfilep, "\t.type = PUBLIC_KEY_TYPE_RSA,\n");
>  			fprintf(outfilep, "\t.key_name_hint = \"%s\",\n", key_name);
>  			fprintf(outfilep, "\t.rsa = &%s,\n", key_name_c);
> -			fprintf(outfilep, "};");
> -			fprintf(outfilep, "\nstruct public_key *%sp __attribute__((section(\".public_keys.rodata.%s\"))) = &%s_public_key;\n",
> -				key_name_c, key_name_c, key_name_c);
> +			fprintf(outfilep, "};\n");
>  		}
>  	}
>  


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list