1 /* 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
12 typedef sha256_context mbedtls_sha256_context;
13
mbedtls_sha256_init(mbedtls_sha256_context * ctx)14 static inline void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
15 {
16 }
17
mbedtls_sha256_free(mbedtls_sha256_context * ctx)18 static inline void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
19 {
20 }
21
mbedtls_sha256_clone(mbedtls_sha256_context * dst,const mbedtls_sha256_context * src)22 static inline void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
23 const mbedtls_sha256_context *src)
24 {
25 *dst = *src;
26 }
27
mbedtls_sha256_starts(mbedtls_sha256_context * ctx,int is224)28 static 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
mbedtls_sha256_update(mbedtls_sha256_context * ctx,const unsigned char * input,size_t ilen)37 static 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
mbedtls_sha256_finish(mbedtls_sha256_context * ctx,unsigned char * output)45 static inline int mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
46 unsigned char *output)
47 {
48 sha256_finish(ctx, output);
49 return 0;
50 }
51
mbedtls_sha256(const unsigned char * input,size_t ilen,unsigned char * output,int is224)52 static 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 */
65