Add components for attestation service
In preparation for implementing the attestation service provider,
building block components have been add. This includes the
service access protocol definition, an external cbor library,
generic claim model and a concrete claim source for extracting
claims from a TCG event log.
This commit contains derived work, the following files are copied
from other projects:
components/service/attestation/claims/sources/event_log/tcg.h
Origin:
https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
include/drivers/measured_boot/tcg.h
#a5394205e94b70faf7ddd34841528ec631711d1a
components/service/attestation/include/psa/initial_attestation.h
Origin:
https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
interface/include/psa/initial_attestation.h
#9280ae9d898bffbb889e4796e51aab35a392ef82
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I5ed3e4ef7111a19b29643538ef3c47b3b6e1dd5c
diff --git a/components/common/endian/component.cmake b/components/common/endian/component.cmake
new file mode 100644
index 0000000..92d7138
--- /dev/null
+++ b/components/common/endian/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/le.c"
+ )
diff --git a/components/common/endian/le.c b/components/common/endian/le.c
new file mode 100644
index 0000000..88196f6
--- /dev/null
+++ b/components/common/endian/le.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "le.h"
+
+uint8_t load_u8_le(const void *base, size_t offset)
+{
+ const uint8_t *v = (const uint8_t*)base + offset;
+ uint8_t r = v[0];
+
+ return r;
+}
+
+uint16_t load_u16_le(const void *base, size_t offset)
+{
+ const uint8_t *v = (const uint8_t*)base + offset;
+ uint16_t r = 0;
+ r |= (uint16_t)v[0];
+ r |= (uint16_t)v[1] << 8;
+
+ return r;
+}
+
+uint32_t load_u32_le(const void *base, size_t offset)
+{
+ const uint8_t *v = (const uint8_t*)base + offset;
+ uint32_t r = 0;
+ r |= (uint32_t)v[0];
+ r |= (uint32_t)v[1] << 8;
+ r |= (uint32_t)v[2] << 16;
+ r |= (uint32_t)v[3] << 24;
+
+ return r;
+}
+
+uint64_t load_u64_le(const void *base, size_t offset)
+{
+ const uint8_t *v = (const uint8_t*)base + offset;
+ uint64_t r = 0;
+ r |= (uint64_t)v[0];
+ r |= (uint64_t)v[1] << 8;
+ r |= (uint64_t)v[2] << 16;
+ r |= (uint64_t)v[3] << 24;
+ r |= (uint64_t)v[4] << 32;
+ r |= (uint64_t)v[5] << 40;
+ r |= (uint64_t)v[6] << 48;
+ r |= (uint64_t)v[7] << 56;
+
+ return r;
+}
+
+void store_u8_le(void *base, size_t offset, uint8_t val)
+{
+ uint8_t *v = (uint8_t*)base + offset;
+ v[0] = val;
+}
+
+void store_u16_le(void *base, size_t offset, uint16_t val)
+{
+ uint8_t *v = (uint8_t*)base + offset;
+
+ v[0] = (uint8_t)(val & 0xff);
+ v[1] = (uint8_t)((val >> 8) & 0xff);
+}
+
+void store_u32_le(void *base, size_t offset, uint32_t val)
+{
+ uint8_t *v = (uint8_t*)base + offset;
+
+ v[0] = (uint8_t)(val & 0xff);
+ v[1] = (uint8_t)((val >> 8) & 0xff);
+ v[2] = (uint8_t)((val >> 16) & 0xff);
+ v[3] = (uint8_t)((val >> 24) & 0xff);
+}
+
+void store_u64_le(void *base, size_t offset, uint64_t val)
+{
+ uint8_t *v = (uint8_t*)base + offset;
+
+ v[0] = (uint8_t)(val & 0xff);
+ v[1] = (uint8_t)((val >> 8) & 0xff);
+ v[2] = (uint8_t)((val >> 16) & 0xff);
+ v[3] = (uint8_t)((val >> 24) & 0xff);
+ v[4] = (uint8_t)((val >> 32) & 0xff);
+ v[5] = (uint8_t)((val >> 40) & 0xff);
+ v[6] = (uint8_t)((val >> 48) & 0xff);
+ v[7] = (uint8_t)((val >> 56) & 0xff);
+}
diff --git a/components/common/endian/le.h b/components/common/endian/le.h
new file mode 100644
index 0000000..c6172e1
--- /dev/null
+++ b/components/common/endian/le.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ENDIAN_LE_H
+#define ENDIAN_LE_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Functions for loading and storing integer values as unaligned
+ * values in Little Endian byte order. The address to load or
+ * store the value is specified by a base address and an offset
+ * to facilitate unaligned structure access.
+ */
+uint8_t load_u8_le(const void *base, size_t offset);
+uint16_t load_u16_le(const void *base, size_t offset);
+uint32_t load_u32_le(const void *base, size_t offset);
+uint64_t load_u64_le(const void *base, size_t offset);
+
+void store_u8_le(void *base, size_t offset, uint8_t val);
+void store_u16_le(void *base, size_t offset, uint16_t val);
+void store_u32_le(void *base, size_t offset, uint32_t val);
+void store_u64_le(void *base, size_t offset, uint64_t val);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ENDIAN_LE_H */
diff --git a/components/common/endian/test/component.cmake b/components/common/endian/test/component.cmake
new file mode 100644
index 0000000..c909666
--- /dev/null
+++ b/components/common/endian/test/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/endian_test.cpp"
+ )
diff --git a/components/common/endian/test/endian_test.cpp b/components/common/endian/test/endian_test.cpp
new file mode 100644
index 0000000..dabf276
--- /dev/null
+++ b/components/common/endian/test/endian_test.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <cstring>
+#include <common/endian/le.h>
+#include <CppUTest/TestHarness.h>
+
+TEST_GROUP(EndianTests)
+{
+
+};
+
+TEST(EndianTests, le8)
+{
+ const uint8_t test_vector[] = {0x00, 0x01, 0x02, 0x03, 0x04};
+ uint8_t store_result[sizeof(test_vector)];
+
+ memcpy(store_result, test_vector, sizeof(test_vector));
+
+ UNSIGNED_LONGS_EQUAL(0x03, load_u8_le(test_vector, 3));
+
+ store_u8_le(store_result, 2, 0x02);
+ MEMCMP_EQUAL(test_vector, store_result, sizeof(test_vector));
+}
+
+TEST(EndianTests, le16)
+{
+ const uint8_t test_vector[] = {0x00, 0x01, 0x02, 0x03, 0x04};
+ uint8_t store_result[sizeof(test_vector)];
+
+ memcpy(store_result, test_vector, sizeof(test_vector));
+
+ UNSIGNED_LONGS_EQUAL(0x0201, load_u16_le(test_vector, 1));
+
+ store_u16_le(store_result, 1, 0x0201);
+ MEMCMP_EQUAL(test_vector, store_result, sizeof(test_vector));
+}
+
+TEST(EndianTests, le32)
+{
+ const uint8_t test_vector[] = {0x00, 0x01, 0x02, 0x03, 0x04};
+ uint8_t store_result[sizeof(test_vector)];
+
+ memcpy(store_result, test_vector, sizeof(test_vector));
+
+ UNSIGNED_LONGS_EQUAL(0x04030201, load_u32_le(test_vector, 1));
+
+ store_u32_le(store_result, 1, 0x04030201);
+ MEMCMP_EQUAL(test_vector, store_result, sizeof(test_vector));
+}
+
+TEST(EndianTests, le64)
+{
+ const uint8_t test_vector[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+ uint8_t store_result[sizeof(test_vector)];
+
+ memcpy(store_result, test_vector, sizeof(test_vector));
+
+ UNSIGNED_LONGS_EQUAL(0x0807060504030201, load_u64_le(test_vector, 1));
+
+ store_u64_le(store_result, 1, 0x0807060504030201);
+ MEMCMP_EQUAL(test_vector, store_result, sizeof(test_vector));
+}