aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorPhilippe Reynes2018-11-14 13:51:00 +0100
committerTom Rini2018-12-03 10:44:10 -0500
commit20031567e12bb312bff95b70767f6275e20f0346 (patch)
tree00c9c34581da071f3a87ee01c27370cc524cf223 /common
parent3b5d6979fcb80ffae3b140be6edc04cbde1a0b72 (diff)
rsa: add a structure for the padding
The rsa signature use a padding algorithm. By default, we use the padding pkcs-1.5. In order to add some new padding algorithm, we add a padding framework to manage several padding algorithm. The choice of the padding is done in the file .its. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/image-fit.c5
-rw-r--r--common/image-sig.c29
2 files changed, 34 insertions, 0 deletions
diff --git a/common/image-fit.c b/common/image-fit.c
index 8d39a243f8d..ac901e131ca 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -165,6 +165,7 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p,
uint8_t *value;
int value_len;
char *algo;
+ const char *padding;
int required;
int ret, i;
@@ -184,6 +185,10 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p,
printf(" (required)");
printf("\n");
+ padding = fdt_getprop(fit, noffset, "padding", NULL);
+ if (padding)
+ printf("%s %s padding: %s\n", p, type, padding);
+
ret = fit_image_hash_get_value(fit, noffset, &value,
&value_len);
printf("%s %s value: ", p, type);
diff --git a/common/image-sig.c b/common/image-sig.c
index 5d860e12663..3d8281f2faa 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -71,6 +71,13 @@ struct crypto_algo crypto_algos[] = {
};
+struct padding_algo padding_algos[] = {
+ {
+ .name = "pkcs-1.5",
+ .verify = padding_pkcs_15_verify,
+ },
+};
+
struct checksum_algo *image_get_checksum_algo(const char *full_name)
{
int i;
@@ -106,6 +113,21 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name)
return NULL;
}
+struct padding_algo *image_get_padding_algo(const char *name)
+{
+ int i;
+
+ if (!name)
+ return NULL;
+
+ for (i = 0; i < ARRAY_SIZE(padding_algos); i++) {
+ if (!strcmp(padding_algos[i].name, name))
+ return &padding_algos[i];
+ }
+
+ return NULL;
+}
+
/**
* fit_region_make_list() - Make a list of image regions
*
@@ -155,6 +177,7 @@ static int fit_image_setup_verify(struct image_sign_info *info,
char **err_msgp)
{
char *algo_name;
+ const char *padding_name;
if (fdt_totalsize(fit) > CONFIG_FIT_SIGNATURE_MAX_SIZE) {
*err_msgp = "Total size too large";
@@ -165,6 +188,11 @@ static int fit_image_setup_verify(struct image_sign_info *info,
*err_msgp = "Can't get hash algo property";
return -1;
}
+
+ padding_name = fdt_getprop(fit, noffset, "padding", NULL);
+ if (!padding_name)
+ padding_name = RSA_DEFAULT_PADDING_NAME;
+
memset(info, '\0', sizeof(*info));
info->keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
info->fit = (void *)fit;
@@ -172,6 +200,7 @@ static int fit_image_setup_verify(struct image_sign_info *info,
info->name = algo_name;
info->checksum = image_get_checksum_algo(algo_name);
info->crypto = image_get_crypto_algo(algo_name);
+ info->padding = image_get_padding_algo(padding_name);
info->fdt_blob = gd_fdt_blob();
info->required_keynode = required_keynode;
printf("%s:%s", algo_name, info->keyname);