2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-03-03 11:19:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Andreas Oetken.
|
|
|
|
*/
|
|
|
|
|
2014-03-03 11:19:30 +00:00
|
|
|
#ifndef USE_HOSTCC
|
2014-03-03 11:19:26 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <asm/byteorder.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2014-03-03 11:19:26 +00:00
|
|
|
#include <asm/unaligned.h>
|
2015-01-23 10:31:59 +00:00
|
|
|
#include <hash.h>
|
2014-03-03 11:19:30 +00:00
|
|
|
#else
|
|
|
|
#include "fdt_host.h"
|
2015-01-23 10:31:59 +00:00
|
|
|
#endif
|
2021-02-19 18:45:10 +00:00
|
|
|
#include <hash.h>
|
|
|
|
#include <image.h>
|
2014-03-03 11:19:26 +00:00
|
|
|
|
2015-01-23 10:31:59 +00:00
|
|
|
int hash_calculate(const char *name,
|
2021-09-26 01:43:33 +00:00
|
|
|
const struct image_region *region,
|
2015-01-23 10:31:59 +00:00
|
|
|
int region_count, uint8_t *checksum)
|
2014-03-03 11:19:26 +00:00
|
|
|
{
|
2015-01-23 10:31:59 +00:00
|
|
|
struct hash_algo *algo;
|
|
|
|
int ret = 0;
|
|
|
|
void *ctx;
|
2014-03-03 11:19:26 +00:00
|
|
|
uint32_t i;
|
|
|
|
i = 0;
|
|
|
|
|
2015-01-23 10:31:59 +00:00
|
|
|
ret = hash_progressive_lookup_algo(name, &algo);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-03-03 11:19:26 +00:00
|
|
|
|
2015-01-23 10:31:59 +00:00
|
|
|
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;
|
2014-03-03 11:19:26 +00:00
|
|
|
|
2015-01-23 10:31:59 +00:00
|
|
|
return 0;
|
2014-03-03 11:19:26 +00:00
|
|
|
}
|