diff options
Diffstat (limited to 'chip/host')
-rw-r--r-- | chip/host/build.mk | 20 | ||||
-rw-r--r-- | chip/host/dcrypto/app_cipher.c | 6 | ||||
-rw-r--r-- | chip/host/dcrypto/sha256.c | 22 |
3 files changed, 37 insertions, 11 deletions
diff --git a/chip/host/build.mk b/chip/host/build.mk index 8b7ab0efc2..0ea6027533 100644 --- a/chip/host/build.mk +++ b/chip/host/build.mk @@ -15,9 +15,16 @@ chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o endif ifeq ($(CONFIG_DCRYPTO),y) -CPPFLAGS += -I$(abspath ./chip/g) -dirs-y += chip/g/dcrypto +CPPFLAGS += -I$(abspath ./board/cr50) +dirs-y += board/cr50/dcrypto +LDFLAGS_EXTRA += -lcrypto endif + +ifeq ($(CONFIG_DCRYPTO_MOCK),y) +CPPFLAGS += -I$(abspath ./board/cr50) +dirs-y += board/cr50/dcrypto +endif + dirs-y += chip/host/dcrypto chip-$(CONFIG_DCRYPTO)+= dcrypto/aes.o @@ -26,4 +33,11 @@ chip-$(CONFIG_DCRYPTO)+= dcrypto/app_key.o chip-$(CONFIG_DCRYPTO)+= dcrypto/sha256.o # Object files that can be shared with the Cr50 dcrypto implementation -chip-$(CONFIG_DCRYPTO)+= ../g/dcrypto/hmac.o +chip-$(CONFIG_DCRYPTO)+= ../../board/cr50/dcrypto/hmac_sw.o +chip-$(CONFIG_DCRYPTO)+= ../../board/cr50/dcrypto/sha1.o +chip-$(CONFIG_DCRYPTO)+= ../../board/cr50/dcrypto/sha256.o +chip-$(CONFIG_DCRYPTO)+= ../../board/cr50/dcrypto/hmac_drbg.o + +# We still want raw SHA & HMAC implementations for mocked dcrypto +chip-$(CONFIG_DCRYPTO_MOCK)+= ../../board/cr50/dcrypto/sha256.o +chip-$(CONFIG_DCRYPTO_MOCK)+= ../../board/cr50/dcrypto/hmac_sw.o
\ No newline at end of file diff --git a/chip/host/dcrypto/app_cipher.c b/chip/host/dcrypto/app_cipher.c index 4c4809005c..a3ce4e3184 100644 --- a/chip/host/dcrypto/app_cipher.c +++ b/chip/host/dcrypto/app_cipher.c @@ -9,15 +9,15 @@ void app_compute_hash(const void *p_buf, size_t num_bytes, void *p_hash, size_t hash_len) { - uint8_t digest[SHA256_DIGEST_SIZE]; + struct sha256_digest digest; /* * Use the built in dcrypto engine to generate the sha1 hash of the * buffer. */ - DCRYPTO_SHA256_hash(p_buf, num_bytes, digest); + SHA256_hw_hash(p_buf, num_bytes, &digest); - memcpy(p_hash, digest, MIN(hash_len, sizeof(digest))); + memcpy(p_hash, digest.b8, MIN(hash_len, sizeof(digest))); if (hash_len > sizeof(digest)) memset((uint8_t *)p_hash + sizeof(digest), 0, diff --git a/chip/host/dcrypto/sha256.c b/chip/host/dcrypto/sha256.c index 429588c8ac..1c9fda27c2 100644 --- a/chip/host/dcrypto/sha256.c +++ b/chip/host/dcrypto/sha256.c @@ -5,14 +5,26 @@ #include "dcrypto.h" -void DCRYPTO_SHA256_init(LITE_SHA256_CTX *ctx, uint32_t sw_required) +void SHA256_hw_init(struct sha256_ctx *ctx) { - SHA256_init(ctx); + SHA256_sw_init(ctx); } -const uint8_t *DCRYPTO_SHA256_hash(const void *data, uint32_t n, - uint8_t *digest) +const struct sha256_digest *SHA256_hw_hash(const void *data, size_t n, + struct sha256_digest *digest) { - SHA256_hash(data, n, digest); + SHA256_sw_hash(data, n, digest); return digest; } + +void HMAC_SHA256_hw_init(struct hmac_sha256_ctx *ctx, const void *key, + size_t len) +{ + SHA256_hw_init(&ctx->hash); + HMAC_sw_init((union hmac_ctx *)ctx, key, len); +} + +const struct sha256_digest *HMAC_SHA256_hw_final(struct hmac_sha256_ctx *ctx) +{ + return HMAC_SHA256_final(ctx); +} |