[PATCH v4 09/16] crypto: rsa: encapsulate rsa keys in public keys struct

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Sep 27 01:02:08 PDT 2024


On 13.09.24 09:59, Sascha Hauer wrote:
> This encapsulates struct rsa_public_key into a struct public_key. So far
> RSA keys are the only supported key type. With adding ECDSA keys we need
> a container struct so that we can add ECDSA keys using the same
> mechanisms.
> 
> Also we rename CONFIG_CRYPTO_RSA_KEY to CONFIG_CRYPTO_PUBLIC_KEYS and
> CONFIG_CRYPTO_RSA_BUILTIN_KEYS to CONFIG_CRYPTO_BUILTIN_KEYS as these
> variables will be used for all types of keys, not only RSA keys.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

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

But two comments below.

> diff --git a/crypto/public-keys.c b/crypto/public-keys.c
> new file mode 100644
> index 0000000000..a3ef3bafc8
> --- /dev/null
> +++ b/crypto/public-keys.c
> @@ -0,0 +1,39 @@

add a pr_fmt?

> +#include <common.h>
> +#include <crypto/public_key.h>
> +#include <rsa.h>
> +
> +extern const struct public_key * const __public_keys_start;
> +extern const struct public_key * const __public_keys_end;
> +
> +static int init_public_keys(void)
> +{
> +	const struct public_key * const *iter;
> +	int ret;
> +
> +	for (iter = &__public_keys_start; iter != &__public_keys_end; iter++) {
> +		struct rsa_public_key *rsa_key;
> +
> +		switch ((*iter)->type) {
> +		case PUBLIC_KEY_TYPE_RSA:
> +			rsa_key = rsa_key_dup((*iter)->rsa);
> +			if (!rsa_key)
> +				continue;
> +
> +			ret = rsa_key_add(rsa_key);
> +			if (ret)
> +				pr_err("Cannot add rsa key: %pe\n", ERR_PTR(ret));
> +			break;
> +		default:
> +			pr_err("Ignoring unknown key type %u\n", (*iter)->type);
> +		}
> +
> +	}
> +
> +	return 0;
> +}
> +
> +device_initcall(init_public_keys);
> +

> -extern const struct rsa_public_key * const __rsa_keys_start;
> -extern const struct rsa_public_key * const __rsa_keys_end;

I know you are just moving these around, but defining
these with [] is way less confusing IMO.


Thanks,
Ahmad

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