blob: a28d94350e2d32befd4be7956eda4797b5299a45 [file] [log] [blame]
Raef Coles15a37f82021-12-07 15:59:14 +00001/*
Raef Colesa5d031b2023-07-04 10:45:33 +01002 * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
Raef Coles15a37f82021-12-07 15:59:14 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "util.h"
9
Raef Coles15a37f82021-12-07 15:59:14 +000010#include "fih.h"
Raef Colesa5d031b2023-07-04 10:45:33 +010011#include <string.h>
Raef Coles15a37f82021-12-07 15:59:14 +000012
Raef Colesa5d031b2023-07-04 10:45:33 +010013#ifdef TFM_FIH_PROFILE_ON
14fih_int bl_fih_memeql(const void *ptr1, const void *ptr2, size_t num)
Raef Coles15a37f82021-12-07 15:59:14 +000015{
Raef Colesa5d031b2023-07-04 10:45:33 +010016 size_t idx;
Raef Coles15a37f82021-12-07 15:59:14 +000017
Raef Colesa5d031b2023-07-04 10:45:33 +010018 for (idx = 0; idx < num; idx++) {
19 if (((uint8_t *)ptr1)[idx] != ((uint8_t *)ptr2)[idx]) {
20 FIH_RET(FIH_FAILURE);
Raef Coles15a37f82021-12-07 15:59:14 +000021 }
22
Raef Colesa5d031b2023-07-04 10:45:33 +010023 fih_delay();
Raef Coles15a37f82021-12-07 15:59:14 +000024
Raef Colesa5d031b2023-07-04 10:45:33 +010025 if (((uint8_t *)ptr1)[idx] != ((uint8_t *)ptr2)[idx]) {
26 FIH_RET(FIH_FAILURE);
Raef Coles15a37f82021-12-07 15:59:14 +000027 }
Raef Coles15a37f82021-12-07 15:59:14 +000028 }
29
Raef Colesa5d031b2023-07-04 10:45:33 +010030 if (idx != num) {
31 FIH_RET(FIH_FAILURE);
Raef Coles15a37f82021-12-07 15:59:14 +000032 }
33
34 FIH_RET(FIH_SUCCESS);
35}
Raef Colesa5d031b2023-07-04 10:45:33 +010036#else
37fih_int bl_fih_memeql(const void *ptr1, const void *ptr2, size_t num)
38{
39 /* Only return 1 or 0 */
40 return memcmp(ptr1, ptr2, num) != 0;
41}
42#endif /* TFM_FIH_PROFILE_ON */