app: aboot: Add functions to validate userkey
Add functions to store, erase and get userkey which
is required for validation of AVB2.0.
Change-Id: I989df64e40865b508c5d32b601e6da2c7009fc9b
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 5024edc..f24bc3f 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -2368,6 +2368,47 @@
return 0;
}
+int store_userkey(uint8_t *user_key, uint32_t user_key_size)
+{
+ if (!devinfo_present) {
+ dprintf(CRITICAL, "DeviceInfo not initalized \n");
+ return -EINVAL;
+ }
+
+ if (user_key_size > ARRAY_SIZE(device.user_public_key)) {
+ dprintf(CRITICAL, "StoreUserKey, UserKeySize too large!\n");
+ return -ENODEV;
+ }
+
+ memcpy(device.user_public_key, user_key, user_key_size);
+ device.user_public_key_length = user_key_size;
+ write_device_info(&device);
+ return 0;
+}
+
+int erase_userkey()
+{
+ if (!devinfo_present) {
+ dprintf(CRITICAL, "DeviceInfo not initalized \n");
+ return -EINVAL;
+ }
+ memset(device.user_public_key, 0, ARRAY_SIZE(device.user_public_key));
+ device.user_public_key_length = 0;
+ write_device_info(&device);
+ return 0;
+}
+
+int get_userkey(uint8_t **user_key, uint32_t *user_key_size)
+{
+ if (!devinfo_present) {
+ dprintf(CRITICAL, "DeviceInfo not initalized \n");
+ return -EINVAL;
+ }
+ *user_key = device.user_public_key;
+ *user_key_size = device.user_public_key_length;
+ return 0;
+}
+
void read_device_info(device_info *dev)
{
if(target_is_emmc_boot())
diff --git a/include/platform.h b/include/platform.h
index f6f739f..bce5970 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -97,4 +97,7 @@
uint32_t get_page_size();
int read_rollback_index(uint32_t loc, uint64_t *roll_back_index);
int write_rollback_index(uint32_t loc, uint64_t roll_back_index);
+int get_userkey(uint8_t **user_key, uint32_t *user_key_size);
+int erase_userkey();
+int store_userkey(uint8_t *user_key, uint32_t user_key_size);
#endif