1 /* 2 * Copyright (c) 2023 O.S.Systems 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __UPDATEHUB_INTEGRITY_H__ 8 #define __UPDATEHUB_INTEGRITY_H__ 9 10 #if defined(CONFIG_PSA_CRYPTO_CLIENT) 11 #include <psa/crypto.h> 12 #else 13 #include <mbedtls/sha256.h> 14 #endif 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #define SHA256_BIN_DIGEST_SIZE (32) 21 #define SHA256_HEX_DIGEST_SIZE ((SHA256_BIN_DIGEST_SIZE * 2) + 1) 22 23 #if defined(CONFIG_PSA_CRYPTO_CLIENT) 24 typedef psa_hash_operation_t updatehub_crypto_context_t; 25 #else 26 typedef mbedtls_sha256_context updatehub_crypto_context_t; 27 #endif 28 29 int updatehub_integrity_init(updatehub_crypto_context_t *ctx); 30 int updatehub_integrity_update(updatehub_crypto_context_t *ctx, 31 const uint8_t *buffer, const uint32_t len); 32 int updatehub_integrity_finish(updatehub_crypto_context_t *ctx, 33 uint8_t *hash, const uint32_t size); 34 35 #ifdef __cplusplus 36 } 37 #endif 38 39 #endif /* __UPDATEHUB_INTEGRITY_H__ */ 40