luckfox-pico-sdk/sysdrv/source/uboot/u-boot/lib/rsa/rsa-checksum.c
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00

108 lines
2.3 KiB
C

/*
* Copyright (c) 2013, Andreas Oetken.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef USE_HOSTCC
#include <common.h>
#include <crypto.h>
#include <fdtdec.h>
#include <asm/byteorder.h>
#include <linux/errno.h>
#include <asm/unaligned.h>
#include <hash.h>
#else
#include "fdt_host.h"
#endif
#include <u-boot/rsa.h>
int rsa_hash_calculate(const char *name,
const struct image_region region[],
int region_count, uint8_t *checksum)
{
struct hash_algo *algo;
int ret = 0;
void *ctx;
uint32_t i;
i = 0;
ret = hash_progressive_lookup_algo(name, &algo);
if (ret)
return ret;
ret = algo->hash_init(algo, &ctx);
if (ret)
return ret;
for (i = 0; i < region_count - 1; i++) {
ret = algo->hash_update(algo, ctx, region[i].data,
region[i].size, 0);
if (ret)
return ret;
}
ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1);
if (ret)
return ret;
ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size);
if (ret)
return ret;
return 0;
}
#if !defined(USE_HOSTCC)
#if CONFIG_IS_ENABLED(FIT_HW_CRYPTO)
int hw_rsa_hash_calculate(const char *name,
const struct image_region region[],
int region_count, uint8_t *checksum)
{
struct udevice *dev;
sha_context ctx;
if (!name)
return -EINVAL;
if (!strcmp(name, "sha1"))
ctx.algo = CRYPTO_SHA1;
else if (!strcmp(name, "sha256"))
ctx.algo = CRYPTO_SHA256;
else
return -EPERM;
dev = crypto_get_device(ctx.algo);
if (!dev) {
printf("No crypto device for expected capability\n");
return -ENODEV;
}
return crypto_sha_regions_csum(dev, &ctx, region,
region_count, checksum);
}
#endif
#endif
int hash_calculate(const char *name,
const struct image_region region[],
int region_count, uint8_t *checksum)
{
#if defined(USE_HOSTCC)
return rsa_hash_calculate(name, region, region_count, checksum);
#else
/*
* Don't delete hw_rsa_hash_calculate() for some platform doesn't
* want to use rk-crypto depend on soft sha1/256 dispatch path.
*
* Because CONFIG_SHA1/256=y and CONFIG_SPL_HASH_SUPPORT=y(if spl)
* increase the code size.
*/
#if CONFIG_IS_ENABLED(ARMV8_CRYPTO) || !CONFIG_IS_ENABLED(FIT_HW_CRYPTO)
return rsa_hash_calculate(name, region, region_count, checksum);
#else
return hw_rsa_hash_calculate(name, region, region_count, checksum);
#endif
#endif
}