summaryrefslogtreecommitdiff
path: root/board
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 /board
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 'board')
-rw-r--r--board/host/dcrypto.h44
1 files changed, 28 insertions, 16 deletions
diff --git a/board/host/dcrypto.h b/board/host/dcrypto.h
index 48bde62592..31f04e51aa 100644
--- a/board/host/dcrypto.h
+++ b/board/host/dcrypto.h
@@ -11,26 +11,23 @@
#ifndef __CROS_EC_DCRYPTO_HOST_H
#define __CROS_EC_DCRYPTO_HOST_H
-
-#include <sha256.h>
#include <stdint.h>
#include <string.h>
-#define AES256_BLOCK_CIPHER_KEY_SIZE 32
-#define SHA256_DIGEST_SIZE 32
+/* Allow tests to return a faked result for the purpose of testing. If
+ * this is not set, a combination of cryptoc and openssl are used for the
+ * dcrypto implementation.
+ */
+#ifndef CONFIG_DCRYPTO_MOCK
-#define HASH_CTX sha256_ctx
+/* If not using the mock struct definitions, use the ones from Cr50. */
+#include "chip/g/dcrypto/dcrypto.h"
-enum dcrypto_appid {
- RESERVED = 0,
- NVMEM = 1,
- U2F_ATTEST = 2,
- U2F_ORIGIN = 3,
- U2F_WRAP = 4,
- PERSO_AUTH = 5,
- PINWEAVER = 6,
- /* This enum value should not exceed 7. */
-};
+#else /* defined(CONFIG_DCRYPTO_MOCK) */
+
+#include <sha256.h>
+
+#define HASH_CTX sha256_ctx
/* Used as a replacement for declarations in cryptoc that are used by Cr50, but
* add unnecessary complexity to the test code.
@@ -42,9 +39,22 @@ struct dcrypto_mock_ctx_t {
#define LITE_SHA256_CTX struct HASH_CTX
void HASH_update(struct HASH_CTX *ctx, const void *data, size_t len);
-
uint8_t *HASH_final(struct HASH_CTX *ctx);
+#define AES256_BLOCK_CIPHER_KEY_SIZE 32
+#define SHA256_DIGEST_SIZE 32
+
+enum dcrypto_appid {
+ RESERVED = 0,
+ NVMEM = 1,
+ U2F_ATTEST = 2,
+ U2F_ORIGIN = 3,
+ U2F_WRAP = 4,
+ PERSO_AUTH = 5,
+ PINWEAVER = 6,
+ /* This enum value should not exceed 7. */
+};
+
void DCRYPTO_SHA256_init(LITE_SHA256_CTX *ctx, uint32_t sw_required);
void DCRYPTO_HMAC_SHA256_init(LITE_HMAC_CTX *ctx, const void *key,
@@ -63,4 +73,6 @@ void DCRYPTO_appkey_finish(struct APPKEY_CTX *ctx);
int DCRYPTO_appkey_derive(enum dcrypto_appid appid, const uint32_t input[8],
uint32_t output[8]);
+#endif /* CONFIG_DCRYPTO_MOCK */
+
#endif /* __CROS_EC_HOST_DCRYPTO_H */