|
55 | 55 |
|
56 | 56 | #elif defined(MCUBOOT_USE_MBED_TLS)
|
57 | 57 |
|
| 58 | +#ifdef MCUBOOT_SHA512 |
| 59 | +#include <mbedtls/sha512.h> |
| 60 | +#else |
58 | 61 | #include <mbedtls/sha256.h>
|
| 62 | +#endif |
| 63 | + |
59 | 64 | #include <mbedtls/version.h>
|
60 | 65 | #if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
61 | 66 | #include <mbedtls/compat-2.x.h>
|
@@ -123,31 +128,65 @@ static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
|
123 | 128 |
|
124 | 129 | #elif defined(MCUBOOT_USE_MBED_TLS)
|
125 | 130 |
|
| 131 | +#ifdef MCUBOOT_SHA512 |
| 132 | +typedef mbedtls_sha512_context bootutil_sha_context; |
| 133 | +#else |
126 | 134 | typedef mbedtls_sha256_context bootutil_sha_context;
|
| 135 | +#endif |
127 | 136 |
|
128 | 137 | static inline int bootutil_sha_init(bootutil_sha_context *ctx)
|
129 | 138 | {
|
| 139 | + int ret; |
| 140 | + |
| 141 | +#ifdef MCUBOOT_SHA512 |
| 142 | + mbedtls_sha512_init(ctx); |
| 143 | + ret = mbedtls_sha512_starts_ret(ctx, 0); |
| 144 | +#else |
130 | 145 | mbedtls_sha256_init(ctx);
|
131 |
| - return mbedtls_sha256_starts_ret(ctx, 0); |
| 146 | + ret = mbedtls_sha256_starts_ret(ctx, 0); |
| 147 | +#endif |
| 148 | + |
| 149 | + return ret; |
132 | 150 | }
|
133 | 151 |
|
134 | 152 | static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
|
135 | 153 | {
|
| 154 | +#ifdef MCUBOOT_SHA512 |
| 155 | + mbedtls_sha512_free(ctx); |
| 156 | +#else |
136 | 157 | mbedtls_sha256_free(ctx);
|
| 158 | +#endif |
| 159 | + |
137 | 160 | return 0;
|
138 | 161 | }
|
139 | 162 |
|
140 | 163 | static inline int bootutil_sha_update(bootutil_sha_context *ctx,
|
141 | 164 | const void *data,
|
142 | 165 | uint32_t data_len)
|
143 | 166 | {
|
144 |
| - return mbedtls_sha256_update_ret(ctx, data, data_len); |
| 167 | + int ret; |
| 168 | + |
| 169 | +#ifdef MCUBOOT_SHA512 |
| 170 | + ret = mbedtls_sha512_update_ret(ctx, data, data_len); |
| 171 | +#else |
| 172 | + ret = mbedtls_sha256_update_ret(ctx, data, data_len); |
| 173 | +#endif |
| 174 | + |
| 175 | + return ret; |
145 | 176 | }
|
146 | 177 |
|
147 | 178 | static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
|
148 | 179 | uint8_t *output)
|
149 | 180 | {
|
150 |
| - return mbedtls_sha256_finish_ret(ctx, output); |
| 181 | + int ret; |
| 182 | + |
| 183 | +#ifdef MCUBOOT_SHA512 |
| 184 | + ret = mbedtls_sha512_finish_ret(ctx, output); |
| 185 | +#else |
| 186 | + ret = mbedtls_sha256_finish_ret(ctx, output); |
| 187 | +#endif |
| 188 | + |
| 189 | + return ret; |
151 | 190 | }
|
152 | 191 |
|
153 | 192 | #endif /* MCUBOOT_USE_MBED_TLS */
|
|
0 commit comments