From 68019ff9624747d3505ef60d3dfb3cfc9b5d7720 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sat, 9 Sep 2017 02:08:16 -0400 Subject: Whack with club until compiles. --- hal.h | 34 ++-------------------------------- hal_internal.h | 35 +++++++++++++++++++++++++++++++++++ modexp.c | 6 +++--- rsa.c | 8 ++++---- tests/test-rsa.c | 6 +++--- tests/test-trng.c | 1 + 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/hal.h b/hal.h index d216984..74f35fa 100644 --- a/hal.h +++ b/hal.h @@ -203,36 +203,6 @@ extern hal_error_t hal_io_write(const hal_core_t *core, hal_addr_t offset, const extern hal_error_t hal_io_read(const hal_core_t *core, hal_addr_t offset, uint8_t *buf, size_t len); extern hal_error_t hal_io_wait(const hal_core_t *core, uint8_t status, int *count); -static inline hal_error_t hal_io_zero(const hal_core_t *core) -{ - const uint8_t buf[4] = { 0, 0, 0, 0 }; - return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); -} - -static inline hal_error_t hal_io_init(const hal_core_t *core) -{ - const uint8_t buf[4] = { 0, 0, 0, CTRL_INIT }; - return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); -} - -static inline hal_error_t hal_io_next(const hal_core_t *core) -{ - const uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT }; - return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); -} - -static inline hal_error_t hal_io_wait_ready(const hal_core_t *core) -{ - int limit = -1; - return hal_io_wait(core, STATUS_READY, &limit); -} - -static inline hal_error_t hal_io_wait_valid(const hal_core_t *core) -{ - int limit = -1; - return hal_io_wait(core, STATUS_VALID, &limit); -} - /* * Core management functions. * @@ -488,12 +458,12 @@ extern hal_error_t hal_rsa_key_get_public_exponent(const hal_rsa_key_t * const k extern void hal_rsa_key_clear(hal_rsa_key_t *key); extern hal_error_t hal_rsa_encrypt(hal_core_t *core, - const hal_rsa_key_t * const key, + hal_rsa_key_t *key, const uint8_t * const input, const size_t input_len, uint8_t * output, const size_t output_len); extern hal_error_t hal_rsa_decrypt(hal_core_t *core, - const hal_rsa_key_t * const key, + hal_rsa_key_t *key, const uint8_t * const input, const size_t input_len, uint8_t * output, const size_t output_len); diff --git a/hal_internal.h b/hal_internal.h index 2486fd2..7ab300d 100644 --- a/hal_internal.h +++ b/hal_internal.h @@ -68,6 +68,41 @@ inline uint32_t htonl(uint32_t w) #define ntohl htonl #endif +/* + * Low-level I/O convenience functions, moved here from hal.h + * because they use symbols defined in verilog_constants.h. + */ + +static inline hal_error_t hal_io_zero(const hal_core_t *core) +{ + const uint8_t buf[4] = { 0, 0, 0, 0 }; + return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); +} + +static inline hal_error_t hal_io_init(const hal_core_t *core) +{ + const uint8_t buf[4] = { 0, 0, 0, CTRL_INIT }; + return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); +} + +static inline hal_error_t hal_io_next(const hal_core_t *core) +{ + const uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT }; + return hal_io_write(core, ADDR_CTRL, buf, sizeof(buf)); +} + +static inline hal_error_t hal_io_wait_ready(const hal_core_t *core) +{ + int limit = -1; + return hal_io_wait(core, STATUS_READY, &limit); +} + +static inline hal_error_t hal_io_wait_valid(const hal_core_t *core) +{ + int limit = -1; + return hal_io_wait(core, STATUS_VALID, &limit); +} + /* * Static memory allocation on start-up. Don't use this except where * really necessary. By design, there's no way to free this, we don't diff --git a/modexp.c b/modexp.c index 3ded27e..950455f 100644 --- a/modexp.c +++ b/modexp.c @@ -64,7 +64,7 @@ void hal_modexp_set_debug(const int onoff) static hal_error_t inline get_register(const hal_core_t *core, const hal_addr_t addr, - uint32_t &value) + uint32_t *value) { hal_error_t err; uint8_t w[4]; @@ -143,7 +143,7 @@ static inline hal_error_t set_buffer(const hal_core_t *core, const uint8_t * const value, const size_t length) { - hal_error_t; + hal_error_t err; size_t i; if (value == NULL || length % 4 != 0) @@ -217,7 +217,7 @@ hal_error_t hal_modexp(hal_core_t *core, * says it can handle. */ - uint32_t operand_max; + uint32_t operand_max = 0; check(get_register(core, MODEXPA7_ADDR_BUFFER_BITS, &operand_max)); operand_max /= 8; diff --git a/rsa.c b/rsa.c index 90a878f..d964210 100644 --- a/rsa.c +++ b/rsa.c @@ -317,7 +317,7 @@ int fp_exptmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d) * try. Come back to this if it looks like a bottleneck. */ -static hal_error_t create_blinding_factors(hal_core_t *core, const hal_rsa_key_t * const key, fp_int *bf, fp_int *ubf) +static hal_error_t create_blinding_factors(hal_core_t *core, hal_rsa_key_t *key, fp_int *bf, fp_int *ubf) { if (key == NULL || bf == NULL || ubf == NULL) return HAL_ERROR_IMPOSSIBLE; @@ -349,7 +349,7 @@ static hal_error_t create_blinding_factors(hal_core_t *core, const hal_rsa_key_t * RSA decryption via Chinese Remainder Theorem (Garner's formula). */ -static hal_error_t rsa_crt(hal_core_t *core, const hal_rsa_key_t * const key, fp_int *msg, fp_int *sig) +static hal_error_t rsa_crt(hal_core_t *core, hal_rsa_key_t *key, fp_int *msg, fp_int *sig) { if (key == NULL || msg == NULL || sig == NULL) return HAL_ERROR_IMPOSSIBLE; @@ -429,7 +429,7 @@ static hal_error_t rsa_crt(hal_core_t *core, const hal_rsa_key_t * const key, fp */ hal_error_t hal_rsa_encrypt(hal_core_t *core, - const hal_rsa_key_t * const key, + hal_rsa_key_t *key, const uint8_t * const input, const size_t input_len, uint8_t * output, const size_t output_len) { @@ -455,7 +455,7 @@ hal_error_t hal_rsa_encrypt(hal_core_t *core, } hal_error_t hal_rsa_decrypt(hal_core_t *core, - const hal_rsa_key_t * const key, + hal_rsa_key_t *key, const uint8_t * const input, const size_t input_len, uint8_t * output, const size_t output_len) { diff --git a/tests/test-rsa.c b/tests/test-rsa.c index 57037c0..9ba9889 100644 --- a/tests/test-rsa.c +++ b/tests/test-rsa.c @@ -56,12 +56,12 @@ static int test_modexp(hal_core_t *core, const rsa_tc_bn_t * const exp, /* Exponent */ const rsa_tc_bn_t * const val) /* Expected result */ { - uint8_t result[tc->n.len]; + uint8_t result[tc->n.len], C[tc->n.len], F[tc->n.len]; printf("%s test for %lu-bit RSA key\n", kind, (unsigned long) tc->size); - if (hal_modexp(core, msg->val, msg->len, exp->val, exp->len, - tc->n.val, tc->n.len, result, sizeof(result)) != HAL_OK) + if (hal_modexp(core, 0, msg->val, msg->len, exp->val, exp->len, + tc->n.val, tc->n.len, result, sizeof(result), C, sizeof(C), F, sizeof(F)) != HAL_OK) return printf("ModExp failed\n"), 0; if (memcmp(result, val->val, val->len)) diff --git a/tests/test-trng.c b/tests/test-trng.c index f570752..45dec56 100644 --- a/tests/test-trng.c +++ b/tests/test-trng.c @@ -43,6 +43,7 @@ #include #include +#include #include #ifndef WAIT_FOR_CSPRNG_VALID -- cgit v1.2.3