blob: 596f17ae4dac0e2be8de9f6782195a4913fa5438 [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 SHA512_ALT_H
7#define SHA512_ALT_H
8
9#include <image.h>
10#include <u-boot/sha512.h>
11
12typedef struct mbedtls_sha512_context {
13 sha512_context *ubctx;
14 bool is384;
15} mbedtls_sha512_context;
16
17static inline void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
18{
19}
20
21static inline void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
22{
23}
24
25static inline void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
26 const mbedtls_sha512_context *src)
27{
28 *dst = *src;
29}
30
31static inline int mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
32{
33 if (is384)
34 sha384_starts(ctx->ubctx);
35 else
36 sha512_starts(ctx->ubctx);
37
38 ctx->is384 = is384;
39 return 0;
40}
41
42static inline int mbedtls_sha512_update(mbedtls_sha512_context *ctx,
43 const unsigned char *input,
44 size_t ilen)
45{
46 if (ctx->is384)
47 sha384_update(ctx->ubctx, input, ilen);
48 else
49 sha512_update(ctx->ubctx, input, ilen);
50
51 return 0;
52}
53
54static inline int mbedtls_sha512_finish(mbedtls_sha512_context *ctx,
55 unsigned char *output)
56{
57 if (ctx->is384)
58 sha384_finish(ctx->ubctx, output);
59 else
60 sha512_finish(ctx->ubctx, output);
61
62 return 0;
63}
64
65static inline int mbedtls_sha512(const unsigned char *input,
66 size_t ilen,
67 unsigned char *output,
68 int is384)
69{
70 if (is384)
71 sha384_csum_wd(input, ilen, output, CHUNKSZ_SHA512);
72 else
73 sha512_csum_wd(input, ilen, output, CHUNKSZ_SHA512);
74
75 return 0;
76}
77
78#endif /* sha512_alt.h */