dm: crypto: add API for multi regions checksum

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Id364b123a189987458b72adca28f4f4e75e90291
This commit is contained in:
Joseph Chen 2020-03-16 15:07:59 +08:00 committed by Jianhong Chen
parent cc668fbca4
commit c14e46abc4
2 changed files with 40 additions and 0 deletions

View File

@ -108,6 +108,30 @@ int crypto_sha_csum(struct udevice *dev, sha_context *ctx,
return ret;
}
int crypto_sha_regions_csum(struct udevice *dev, sha_context *ctx,
const struct image_region region[],
int region_count, u8 *output)
{
int i, ret;
ctx->length = 0;
for (i = 0; i < region_count; i++)
ctx->length += region[i].size;
ret = crypto_sha_init(dev, ctx);
if (ret)
return ret;
for (i = 0; i < region_count; i++) {
ret = crypto_sha_update(dev, (void *)region[i].data,
region[i].size);
if (ret)
return ret;
}
return crypto_sha_final(dev, ctx, output);
}
int crypto_rsa_verify(struct udevice *dev, rsa_key *ctx, u8 *sign, u8 *output)
{
const struct dm_crypto_ops *ops = device_get_ops(dev);

View File

@ -8,6 +8,7 @@
#include <common.h>
#include <dm.h>
#include <image.h>
#include <u-boot/sha1.h>
/* Algorithms/capability of crypto, works together with crypto_algo_nbits() */
@ -120,6 +121,21 @@ int crypto_sha_final(struct udevice *dev, sha_context *ctx, u8 *output);
int crypto_sha_csum(struct udevice *dev, sha_context *ctx,
char *input, u32 input_len, u8 *output);
/**
* crypto_sha_regions_csum() - Crypto sha hash for multi data blocks
*
* @dev: crypto device
* @ctx: sha context
* @region: regions buffer
* @region_count: regions count
* @output: output hash data
*
* @return 0 on success, otherwise failed
*/
int crypto_sha_regions_csum(struct udevice *dev, sha_context *ctx,
const struct image_region region[],
int region_count, u8 *output);
/**
* crypto_rsa_verify() - Crypto rsa verify
*