From 2e2e4951c5d7e0933a87f0466cf0c8618499d7f5 Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Wed, 7 Sep 2016 13:00:09 -0400 Subject: [PATCH] Makes block print usable in embedded applications if this repo is submodule --- block.c | 14 ++++++++------ block.h | 4 ++-- template/Makefile.posix | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index bd9707e..2591f5e 100644 --- a/block.c +++ b/block.c @@ -8,18 +8,21 @@ #include #include +#if __has_include("config.h") #include "config.h" +#endif #include "block.h" -void block_print(char const *const label, uint8_t const *const b) { +#if defined (HOST_BUILD) || defined (DEBUG_UART) +void block_print(char const *const label, void const *const b) { block_print_bytes(label, b, 16); return; } -void block_print_bytes(char const *const label, uint8_t const *const b, +void block_print_bytes(char const *const label, void const *const v, uint32_t num_bytes) { -#if defined (HOST_BUILD) || defined (DEBUG_UART) - printf("%s: ", label); + const uint8_t *b = v; + printf("%s: ", label); for (int i = 0; i < num_bytes; i++) { printf("%.2x", b[i]); if (!((i + 1) % 4)) { @@ -27,9 +30,8 @@ void block_print_bytes(char const *const label, uint8_t const *const b, } } printf("\r\n"); -#endif } - +#endif void block_xor(uint8_t *dest, uint8_t *const a, uint8_t *const b) { for (uint_fast8_t i = 0; i < 4; i++) { diff --git a/block.h b/block.h index 810ad2a..6ca99b7 100644 --- a/block.h +++ b/block.h @@ -8,8 +8,8 @@ void block_decr(uint8_t *); void block_incr(uint8_t *); -void block_print(char const *const, uint8_t const *const); -void block_print_bytes(char const *const, uint8_t const *const, uint32_t); +void block_print(char const *const, void const *const); +void block_print_bytes(char const *const, void const *const, uint32_t); void block_shiftl(uint8_t *, uint8_t *const, uint_fast8_t); void block_shiftr(uint8_t *, uint8_t *const, uint_fast8_t); void block_xor(uint8_t *, uint8_t *const, uint8_t *const); diff --git a/template/Makefile.posix b/template/Makefile.posix index e0d01c0..c646c8a 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -78,7 +78,7 @@ debug-gdbinit: .PHONY: flash flash-softdevice erase-all startdebug -TEST_CFLAGS=-std=gnu99 -g -Wall -Werror -I.. -DHOST_BUILD -Os +TEST_CFLAGS=-std=gnu99 -g -Wall -Werror -I.. -I . -DHOST_BUILD -Os test: $(HOST_CC) $(TEST_CFLAGS) -lcrypto block.c aes.c cmac.c tests/test_cmac.c -o tests/test_cmac