summaryrefslogtreecommitdiff
path: root/include/nvmem.h
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-01-23 08:13:32 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-25 22:12:28 -0800
commit7a8d505ce34173c7b12b921b67a53586ada00c4c (patch)
treee0784fd57ac3074cb2fe499b715be665f86c3fcc /include/nvmem.h
parent7d2e4fbf5ba0c27f5d84bfa321bd857dbd7c33ff (diff)
downloadchrome-ec-7a8d505ce34173c7b12b921b67a53586ada00c4c.tar.gz
nvmem: encrypt contents using crypto api
This patch makes incompatible changes to the nvmem layout: the header is increased to accommodate a 16 byte sha ans a 16 byte padding for future extensions. The layout version field is also introduced to make it easier to track changes in the future. When calculating SHA the entire partition above the SHA field is processed. Encryption covers everything above the header. Introducing encryption makes it impossible to use flash contents directly for read and compare operations. The nvmem_setup function is modified to use the nvnem_save() instead of writing into the flash directly. BRANCH=none BUG=chrome-os-partner:62260 TEST=ran the following tests, all succeeded make buildall -j TEST_LIST_HOST=nvmem make runtests tcg test suite corp enroll on reef, reboot a few times, verify that enrollment sticks Change-Id: I50b148ac0dc6bc924f4d65c67bc6610100d9dfc0 Reviewed-on: https://chromium-review.googlesource.com/428691 Commit-Ready: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'include/nvmem.h')
-rw-r--r--include/nvmem.h40
1 files changed, 23 insertions, 17 deletions
diff --git a/include/nvmem.h b/include/nvmem.h
index 536548fc4c..1f9a27b1c7 100644
--- a/include/nvmem.h
+++ b/include/nvmem.h
@@ -14,25 +14,24 @@
* and a buffer for each NvMem user.
*
* NvMem Partiion
- * ---------------------------------------------------------------------
- * |0x8 tag | User Buffer 0 | User Buffer 1 | .... | User Buffer N-1 |
- * ---------------------------------------------------------------------
+ * ------------------------------------------------------------------------
+ * |36 byte tag | User Buffer 0 | User Buffer 1 | .... | User Buffer N-1 |
+ * ------------------------------------------------------------------------
*
* Physical Block Tag details
- * --------------------------------------------------------------------
- * | sha | generation | reserved |
- * --------------------------------------------------------------------
- * sha -> 4 bytes of sha1 digest
+ * ------------------------------------------------------------------------
+ * | sha | padding | version | generation | reserved |
+ * -------------------------------------------------------------------------
+ * sha -> 16 bytes of sha1 digest
+ * padding -> 16 bytes for future extensions
+ * version -> nvmem layout version, currently at 0
* generation -> 1 byte generation number (0 - 0xfe)
- * reserved -> 3 bytes
+ * reserved -> 2 bytes
*
* At initialization time, each partition is scanned to see if it has a good sha
* entry. One of the two partitions being valid is a supported condition. If
- * however, neither partiion is valid, then a check is made to see if NvMem
- * space is fully erased. If this is detected, then the tag for partion 0 is
- * populated and written into flash. If neither partition is valid and they
- * aren't fully erased, then NvMem is marked corrupt and this failure condition
- * must be reported back to the caller.
+ * neither partiion is valid a new partition is created with generation set to
+ * zero.
*
* Note that the NvMem partitions can be placed anywhere in flash space, but
* must be equal in total size. A table is used by the NvMem module to get the
@@ -66,15 +65,19 @@
extern uint32_t nvmem_user_sizes[NVMEM_NUM_USERS];
#define NVMEM_NUM_PARTITIONS 2
-#define NVMEM_SHA_SIZE 4
+#define NVMEM_SHA_SIZE CIPHER_SALT_SIZE
#define NVMEM_GENERATION_BITS 8
#define NVMEM_GENERATION_MASK ((1 << NVMEM_GENERATION_BITS) - 1)
+#define NVMEM_PADDING_SIZE 16
+#define NVMEM_LAYOUT_VERSION 0
/* Struct for NV block tag */
struct nvmem_tag {
uint8_t sha[NVMEM_SHA_SIZE];
+ uint8_t padding[NVMEM_PADDING_SIZE];
+ uint8_t layout_version;
uint8_t generation;
- uint8_t reserved[3];
+ uint8_t reserved[2];
};
/* Structure MvMem Partition */
@@ -159,8 +162,11 @@ int nvmem_move(uint32_t src_offset, uint32_t dest_offset, uint32_t size,
*/
int nvmem_commit(void);
-/**
- * One time initialization of NvMem partitions
+/*
+ * Reinitialzse all NvMem partitions
+ *
+ * This function should be called when NvMem needs to be wiped out.
+ *
* @param generation: Starting generation number of partition 0
*
* @return EC_SUCCESS if flash operations are successful.