summaryrefslogtreecommitdiff
path: root/chip/host/dcrypto/app_cipher.c
diff options
context:
space:
mode:
authorAllen Webb <allenwebb@google.com>2018-08-17 17:45:26 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-07 18:36:33 -0700
commit5c5555a49d89154f14efa0c68c99938ef1313b73 (patch)
treeff53547f53396b590e39630c30c862908fdcacd0 /chip/host/dcrypto/app_cipher.c
parent6a9a3a62732ff31e247a9eb61a5f4e7c53154ee5 (diff)
downloadchrome-ec-5c5555a49d89154f14efa0c68c99938ef1313b73.tar.gz
host: Add dcrypto definitions that can be used by fuzzing targets.
These definitions provide the necessary dcrypto functionality for fuzzing pinweaver. They can be built out as needed to support further fuzzing. BRANCH=none BUG=chromium:876582 TEST=make -j buildfuzztests && ./build/host/cr50_fuzz/cr50_fuzz.exe (with the cr50_fuzz CL) Change-Id: I36ce874efab5dbc59825d126f6079b7b6d0da9ef Signed-off-by: Allen Webb <allenwebb@google.com> Reviewed-on: https://chromium-review.googlesource.com/1180573 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/host/dcrypto/app_cipher.c')
-rw-r--r--chip/host/dcrypto/app_cipher.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/chip/host/dcrypto/app_cipher.c b/chip/host/dcrypto/app_cipher.c
new file mode 100644
index 0000000000..af6c2c4beb
--- /dev/null
+++ b/chip/host/dcrypto/app_cipher.c
@@ -0,0 +1,33 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "dcrypto.h"
+#include "util.h"
+
+void app_compute_hash(uint8_t *p_buf, size_t num_bytes,
+ uint8_t *p_hash, size_t hash_len)
+{
+ uint8_t digest[SHA256_DIGEST_SIZE];
+
+ /*
+ * Use the built in dcrypto engine to generate the sha1 hash of the
+ * buffer.
+ */
+ DCRYPTO_SHA256_hash((uint8_t *)p_buf, num_bytes, digest);
+
+ memcpy(p_hash, digest, MIN(hash_len, sizeof(digest)));
+
+ if (hash_len > sizeof(digest))
+ memset(p_hash + sizeof(digest), 0,
+ hash_len - sizeof(digest));
+}
+
+int app_cipher(const void *salt_p, void *out_p, const void *in_p, size_t size)
+{
+ /* See README.md for while this is a passthrough. */
+ memcpy(out_p, in_p, size);
+ return 1;
+}
+