aboutsummaryrefslogtreecommitdiff
path: root/modexp.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-10-04 22:31:47 -0400
committerRob Austein <sra@hactrn.net>2015-10-04 22:31:47 -0400
commitb3bbd3dbccef8c499e980490203cd5085dd13a98 (patch)
tree68091332d4e2429fcc9a8533bf2e26b2d49ab791 /modexp.c
parente164eecc55dd96efc98d2c723e96aaaecdcfda13 (diff)
Whack libhal API to use current configure_core_selector mechanism.
Compiles, not yet tested.
Diffstat (limited to 'modexp.c')
-rw-r--r--modexp.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/modexp.c b/modexp.c
index b82f1ff..f008064 100644
--- a/modexp.c
+++ b/modexp.c
@@ -46,6 +46,7 @@
#include <assert.h>
#include "hal.h"
+#include "verilog_constants.h"
/*
* Whether we want debug output.
@@ -76,7 +77,8 @@ void hal_modexp_set_debug(const int onoff)
* Set an ordinary register.
*/
-static hal_error_t set_register(const hal_addr_t addr,
+static hal_error_t set_register(const hal_core_t *core,
+ const hal_addr_t addr,
uint32_t value)
{
uint8_t w[4];
@@ -87,7 +89,7 @@ static hal_error_t set_register(const hal_addr_t addr,
value >>= 8;
}
- return hal_io_write(addr, w, sizeof(w));
+ return hal_io_write(core, addr, w, sizeof(w));
}
/*
@@ -96,7 +98,8 @@ static hal_error_t set_register(const hal_addr_t addr,
* expects.
*/
-static hal_error_t get_buffer(const hal_addr_t data_addr,
+static hal_error_t get_buffer(const hal_core_t *core,
+ const hal_addr_t data_addr,
uint8_t *value,
const size_t length)
{
@@ -105,7 +108,7 @@ static hal_error_t get_buffer(const hal_addr_t data_addr,
assert(value != NULL && length % 4 == 0);
for (i = 0; i < length; i += 4)
- check(hal_io_read(data_addr + i/4, &value[length - 4 - i], 4));
+ check(hal_io_read(core, data_addr + i/4, &value[length - 4 - i], 4));
return HAL_OK;
}
@@ -116,7 +119,8 @@ static hal_error_t get_buffer(const hal_addr_t data_addr,
* expects.
*/
-static hal_error_t set_buffer(const hal_addr_t data_addr,
+static hal_error_t set_buffer(const hal_core_t *core,
+ const hal_addr_t data_addr,
const uint8_t * const value,
const size_t length)
{
@@ -125,7 +129,7 @@ static hal_error_t set_buffer(const hal_addr_t data_addr,
assert(value != NULL && length % 4 == 0);
for (i = 0; i < length; i += 4)
- check(hal_io_write(data_addr + i/4, &value[length - 4 - i], 4));
+ check(hal_io_write(core, data_addr + i/4, &value[length - 4 - i], 4));
return HAL_OK;
}
@@ -134,7 +138,8 @@ static hal_error_t set_buffer(const hal_addr_t data_addr,
* Run one modexp operation.
*/
-hal_error_t hal_modexp(const uint8_t * const msg, const size_t msg_len, /* Message */
+hal_error_t hal_modexp(const hal_core_t *core,
+ const uint8_t * const msg, const size_t msg_len, /* Message */
const uint8_t * const exp, const size_t exp_len, /* Exponent */
const uint8_t * const mod, const size_t mod_len, /* Modulus */
uint8_t *result, const size_t result_len)
@@ -171,37 +176,37 @@ hal_error_t hal_modexp(const uint8_t * const msg, const size_t msg_len, /* Messa
*/
/* Select mode (1 = fast, 0 = safe) */
- check(set_register(MODEXPS6_ADDR_MODE, (exp_len <= 4)));
+ check(set_register(core, MODEXPS6_ADDR_MODE, (exp_len <= 4)));
/* Set modulus size in bits */
- check(set_register(MODEXPS6_ADDR_MODULUS_WIDTH, mod_len * 8));
+ check(set_register(core, MODEXPS6_ADDR_MODULUS_WIDTH, mod_len * 8));
/* Write new modulus */
- check(set_buffer(MODEXPS6_ADDR_MODULUS, mod, mod_len));
+ check(set_buffer(core, MODEXPS6_ADDR_MODULUS, mod, mod_len));
/* Pre-calcuate speed-up coefficient */
- check(hal_io_init(MODEXPS6_ADDR_CTRL));
+ check(hal_io_init(core));
/* Wait for calculation to complete */
- check(hal_io_wait_ready(MODEXPS6_ADDR_STATUS));
+ check(hal_io_wait_ready(core));
/* Write new message */
- check(set_buffer(MODEXPS6_ADDR_MESSAGE, msg, msg_len));
+ check(set_buffer(core, MODEXPS6_ADDR_MESSAGE, msg, msg_len));
/* Set new exponent length in bits */
- check(set_register(MODEXPS6_ADDR_EXPONENT_WIDTH, exp_len * 8));
+ check(set_register(core, MODEXPS6_ADDR_EXPONENT_WIDTH, exp_len * 8));
/* Set new exponent */
- check(set_buffer(MODEXPS6_ADDR_EXPONENT, exp, exp_len));
+ check(set_buffer(core, MODEXPS6_ADDR_EXPONENT, exp, exp_len));
/* Start calculation */
- check(hal_io_next(MODEXPS6_ADDR_CTRL));
+ check(hal_io_next(core));
/* Wait for result */
- check(hal_io_wait_valid(MODEXPS6_ADDR_STATUS));
+ check(hal_io_wait_valid(core));
/* Extract result */
- check(get_buffer(MODEXPS6_ADDR_RESULT, result, mod_len));
+ check(get_buffer(core, MODEXPS6_ADDR_RESULT, result, mod_len));
return HAL_OK;
}