88#include "mcuboot_config/mcuboot_config.h"
99#include <stddef.h>
1010#include <stdint.h>
11-
12- #if defined(MCUBOOT_USE_MBED_TLS )
13- #if defined(MBEDTLS_HKDF_C )
14- #include "mbedtls/hkdf.h"
15- #endif /* MBEDTLS_HKDF_C */
16- #include "mbedtls/md.h"
17- #else /* MCUBOOT_USE_MBED_TLS */
1811#include <string.h>
19- #endif /* MCUBOOT_USE_MBED_TLS */
2012
2113int
2214bootutil_sha (const uint8_t * const data , size_t data_len ,
@@ -32,66 +24,6 @@ bootutil_sha(const uint8_t *const data, size_t data_len,
3224 return rc ;
3325}
3426
35- #if defined(MCUBOOT_USE_MBED_TLS )
36-
37- static const mbedtls_md_type_t md_type =
38- #if defined(MCUBOOT_SHA512 )
39- MBEDTLS_MD_SHA384 ;
40- #elif defined(MCUBOOT_SIGN_EC384 )
41- MBEDTLS_MD_SHA384 ;
42- #else
43- MBEDTLS_MD_SHA256 ;
44- #endif /* MCUBOOT_SIGN */
45-
46- int
47- bootutil_sha_hmac (const uint8_t * const key , size_t key_len ,
48- const uint8_t * const data , size_t data_len ,
49- uint8_t hmac [static IMAGE_HASH_SIZE ])
50- {
51- return mbedtls_md_hmac (mbedtls_md_info_from_type (md_type ),
52- key , key_len ,
53- data , data_len ,
54- hmac );
55- }
56-
57- #if defined(MBEDTLS_HKDF_C )
58- int
59- bootutil_sha_hkdf_extract (const uint8_t * const salt , size_t salt_len ,
60- const uint8_t * const ikm , size_t ikm_len ,
61- uint8_t prk [static IMAGE_HASH_SIZE ])
62- {
63- return mbedtls_hkdf_extract (mbedtls_md_info_from_type (md_type ),
64- salt , salt_len ,
65- ikm , ikm_len ,
66- prk );
67- }
68-
69- int
70- bootutil_sha_hkdf_expand (const uint8_t * const prk , size_t prk_len ,
71- const uint8_t * const info , size_t info_len ,
72- uint8_t * const okm , uint_fast16_t okm_len )
73- {
74- return mbedtls_hkdf_expand (mbedtls_md_info_from_type (md_type ),
75- prk , prk_len ,
76- info , info_len ,
77- okm , okm_len );
78- }
79-
80- int
81- bootutil_sha_hkdf (const uint8_t * const salt , size_t salt_len ,
82- const uint8_t * const ikm , size_t ikm_len ,
83- const uint8_t * const info , size_t info_len ,
84- uint8_t * const okm , uint_fast16_t okm_len )
85- {
86- return mbedtls_hkdf (mbedtls_md_info_from_type (md_type ),
87- salt , salt_len ,
88- ikm , ikm_len ,
89- info , info_len ,
90- okm , okm_len );
91- }
92- #endif /* MBEDTLS_HKDF_C */
93- #else /* MCUBOOT_USE_MBED_TLS */
94-
9527#if defined(MCUBOOT_SHA512 ) || defined(MCUBOOT_SIGN_EC384 )
9628#define BLOCK_SIZE 128
9729#else
@@ -235,4 +167,3 @@ bootutil_sha_hkdf(const uint8_t *const salt, size_t salt_len,
235167 }
236168 return bootutil_sha_hkdf_expand (prk , sizeof (prk ), info , info_len , okm , okm_len );
237169}
238- #endif /* MCUBOOT_USE_MBED_TLS */
0 commit comments