summaryrefslogtreecommitdiff
path: root/common/u2f.c
diff options
context:
space:
mode:
authorYicheng Li <yichengli@chromium.org>2021-01-04 14:49:19 -0800
committerCommit Bot <commit-bot@chromium.org>2021-01-12 20:55:51 +0000
commit72a3dd167c24a20a6df568d0c84c77dd45a6d2cf (patch)
tree1d1c66467f1ce5e5b0117438c1c104b51f954f5d /common/u2f.c
parentec643f0d99397eafa09ab39b2d7dd6b968bd70d8 (diff)
downloadchrome-ec-72a3dd167c24a20a6df568d0c84c77dd45a6d2cf.tar.gz
The u2f functionality had no unittests at all. This change is more of a setup (in terms of build dependencies) so that u2f tests can be easily added in the future. This change comes with a few simple tests for u2f_generate. The basic idea here is to use board/host/dcrypto.h to mock the dcrypto functionalities. Since board/host/dcrypto.h includes an alternative to cryptoc's sha256 definitions, we need to exclude cryptoc/sha256.h in the test builds. BUG=b:172971998 TEST=make -j run-u2f TEST=make CR50_DEV=1 BOARD=cr50 -j Signed-off-by: Yicheng Li <yichengli@chromium.org> Change-Id: Idae6f55f599a017aedcaf0fe4cdb6c0506e72712 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2610133 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Diffstat (limited to 'common/u2f.c')
-rw-r--r--common/u2f.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/common/u2f.c b/common/u2f.c
index 5205809379..936dd7f035 100644
--- a/common/u2f.c
+++ b/common/u2f.c
@@ -7,7 +7,11 @@
#include "console.h"
#include "cryptoc/p256.h"
+
+#ifndef TEST_BUILD
#include "cryptoc/sha256.h"
+#endif
+
#include "dcrypto.h"
#include "extension.h"
#include "system.h"
@@ -79,8 +83,8 @@ static void copy_versioned_kh_pubkey_out(p256_int *opk_x, p256_int *opk_y,
}
/* U2F GENERATE command */
-static enum vendor_cmd_rc u2f_generate(enum vendor_cmd_cc code, void *buf,
- size_t input_size, size_t *response_size)
+enum vendor_cmd_rc u2f_generate(enum vendor_cmd_cc code, void *buf,
+ size_t input_size, size_t *response_size)
{
struct u2f_generate_req *req = buf;
uint8_t kh_version =
@@ -440,7 +444,7 @@ static enum vendor_cmd_rc u2f_attest(enum vendor_cmd_cc code, void *buf,
int verify_ret;
- HASH_CTX h_ctx;
+ struct HASH_CTX h_ctx;
struct drbg_ctx dr_ctx;
/* Data hash, and corresponding signature. */