blob: 80be94b0a064f24ba7f2722cc1aab513278f71a6 [file] [log] [blame]
Raymond Mao87010c32024-10-03 14:50:15 -07001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (c) 2024 Linaro Limited
4 * Author: Raymond Mao <raymond.mao@linaro.org>
5 */
6#ifndef SHA256_ALT_H
7#define SHA256_ALT_H
8
9#include <image.h>
10#include <u-boot/sha256.h>
11
12typedef sha256_context mbedtls_sha256_context;
13
14static inline void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
15{
16}
17
18static inline void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
19{
20}
21
22static inline void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
23 const mbedtls_sha256_context *src)
24{
25 *dst = *src;
26}
27
28static inline int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
29{
30 if (is224)
31 return -EOPNOTSUPP;
32
33 sha256_starts(ctx);
34 return 0;
35}
36
37static inline int mbedtls_sha256_update(mbedtls_sha256_context *ctx,
38 const unsigned char *input,
39 size_t ilen)
40{
41 sha256_update(ctx, input, ilen);
42 return 0;
43}
44
45static inline int mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
46 unsigned char *output)
47{
48 sha256_finish(ctx, output);
49 return 0;
50}
51
52static inline int mbedtls_sha256(const unsigned char *input,
53 size_t ilen,
54 unsigned char *output,
55 int is224)
56{
57 if (is224)
58 return -EOPNOTSUPP;
59
60 sha256_csum_wd(input, ilen, output, CHUNKSZ_SHA256);
61 return 0;
62}
63
64#endif /* sha256_alt.h */