summaryrefslogtreecommitdiff
path: root/lib/mbedtls/port/sha256_alt.h
blob: 80be94b0a064f24ba7f2722cc1aab513278f71a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Copyright (c) 2024 Linaro Limited
 * Author: Raymond Mao <raymond.mao@linaro.org>
 */
#ifndef SHA256_ALT_H
#define SHA256_ALT_H

#include <image.h>
#include <u-boot/sha256.h>

typedef sha256_context mbedtls_sha256_context;

static inline void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
{
}

static inline void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
{
}

static inline void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
					const mbedtls_sha256_context *src)
{
	*dst = *src;
}

static inline int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
{
	if (is224)
		return -EOPNOTSUPP;

	sha256_starts(ctx);
	return 0;
}

static inline int mbedtls_sha256_update(mbedtls_sha256_context *ctx,
					const unsigned char *input,
					size_t ilen)
{
	sha256_update(ctx, input, ilen);
	return 0;
}

static inline int mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
					unsigned char *output)
{
	sha256_finish(ctx, output);
	return 0;
}

static inline int mbedtls_sha256(const unsigned char *input,
				 size_t ilen,
				 unsigned char *output,
				 int is224)
{
	if (is224)
		return -EOPNOTSUPP;

	sha256_csum_wd(input, ilen, output, CHUNKSZ_SHA256);
	return 0;
}

#endif /* sha256_alt.h */