aboutsummaryrefslogtreecommitdiff
path: root/components/service/secure_storage/provider/secure_flash_store/sfs_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'components/service/secure_storage/provider/secure_flash_store/sfs_utils.c')
-rw-r--r--components/service/secure_storage/provider/secure_flash_store/sfs_utils.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/components/service/secure_storage/provider/secure_flash_store/sfs_utils.c b/components/service/secure_storage/provider/secure_flash_store/sfs_utils.c
new file mode 100644
index 0000000..3d16272
--- /dev/null
+++ b/components/service/secure_storage/provider/secure_flash_store/sfs_utils.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "sfs_utils.h"
+
+psa_status_t sfs_utils_check_contained_in(size_t superset_size,
+ size_t subset_offset,
+ size_t subset_size)
+{
+ /* Check that subset_offset is valid */
+ if (subset_offset > superset_size) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+
+ /* Check that subset_offset + subset_size fits in superset_size.
+ * The previous check passed, so we know that subset_offset <= superset_size
+ * and so the right hand side of the inequality cannot underflow.
+ */
+ if (subset_size > (superset_size - subset_offset)) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+
+ return PSA_SUCCESS;
+}
+
+psa_status_t sfs_utils_validate_fid(const uint8_t *fid)
+{
+ uint32_t fid_size = SFS_FILE_ID_SIZE;
+
+ /* A file ID is valid if it is non-zero */
+ while (fid_size--) {
+ if (*fid++) {
+ return PSA_SUCCESS;
+ }
+ }
+
+ return PSA_ERROR_DOES_NOT_EXIST;
+}