summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-01-22 21:25:42 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-25 22:12:28 -0800
commit7d2e4fbf5ba0c27f5d84bfa321bd857dbd7c33ff (patch)
tree6a8626fd1f271cf2bfaffc4d9e81a20ad20254e5 /test
parent09fca7bddbc4785c5f0d5f4590cdf9d09b3d5471 (diff)
downloadchrome-ec-7d2e4fbf5ba0c27f5d84bfa321bd857dbd7c33ff.tar.gz
g: common: introduce generic crypto API
On boards based on the g chip cryptographic functions come from hardware, they should be implemented in chip/g as opposed to a particular board. The common modules (like nvmem) should be using some generic API, which hopefully will be implemented by other chips, or could be replaced by a purely software implementation where crypto hardware support is not available. Crypto API definition is being added in include/ and the g chip implementation (a wrapper around dcrypto functions) is being added in chip/g. test/nvmem_vars.h needed to be edited to avoid conflict with <string.h>. BRANCH=none BUG=chrome-os-partner:62260 TEST=make buildall -j still passes. Booting reef with the new image works fine too. Change-Id: Ifef281215f89239966882ecbe3e90c8351b9b91a Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/431313 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Nagendra Modadugu <ngm@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/nvmem.c11
-rw-r--r--test/nvmem_vars.c2
2 files changed, 7 insertions, 6 deletions
diff --git a/test/nvmem.c b/test/nvmem.c
index 5ed33f3445..3366f8e862 100644
--- a/test/nvmem.c
+++ b/test/nvmem.c
@@ -30,8 +30,8 @@ static uint8_t read_buffer[NVMEM_PARTITION_SIZE];
static int flash_write_fail;
static int lock_test_started;
-void nvmem_compute_sha(uint8_t *p_buf, int num_bytes, uint8_t *p_sha,
- int sha_bytes)
+void app_compute_hash(uint8_t *p_buf, size_t num_bytes,
+ uint8_t *p_hash, size_t hash_bytes)
{
uint32_t crc;
uint32_t *p_data;
@@ -46,8 +46,11 @@ void nvmem_compute_sha(uint8_t *p_buf, int num_bytes, uint8_t *p_sha,
crc32_hash32(*p_data++);
crc = crc32_result();
- p_data = (uint32_t *)p_sha;
- *p_data = crc;
+ for (n = 0; n < hash_bytes; n += sizeof(crc)) {
+ size_t copy_bytes = MIN(sizeof(crc), hash_bytes - n);
+
+ memcpy(p_hash + n, &crc, copy_bytes);
+ }
}
/* Used to allow/prevent Flash erase/write operations */
diff --git a/test/nvmem_vars.c b/test/nvmem_vars.c
index 56b96ef054..5e31d6a2aa 100644
--- a/test/nvmem_vars.c
+++ b/test/nvmem_vars.c
@@ -5,8 +5,6 @@
* Test of the key=val variable implementation (set, get, delete, etc).
*/
-#include <string.h>
-
#include "common.h"
#include "compile_time_macros.h"
#include "nvmem.h"