49 #define CHECK_RESULT(...) \ 50 state->result = __VA_ARGS__; \ 52 printf("Line: %u Error: %u\n", __LINE__, (unsigned int)state->result); \ 53 PT_EXIT(&state->pt); \ 56 PT_THREAD(ecc_compare(ecc_compare_state_t *state)) {
59 CHECK_RESULT(
bignum_cmp_start(state->a, state->b, state->size, state->process));
66 PT_THREAD(ecc_multiply(ecc_multiply_state_t *state)) {
69 CHECK_RESULT(
ecc_mul_start(state->secret, &state->point_in, state->curve_info, &state->rv, state->process));
76 PT_THREAD(ecc_dsa_sign(ecc_dsa_sign_state_t *state)) {
78 uint8_t size = state->curve_info->size;
79 const uint32_t *ord = state->curve_info->n;
82 memcpy(point.x, state->curve_info->x,
sizeof(point.x));
83 memcpy(point.y, state->curve_info->y,
sizeof(point.y));
93 CHECK_RESULT(
ecc_mul_start(state->k_e, &point, state->curve_info, &state->rv, state->process));
99 CHECK_RESULT(
bignum_mul_start(state->secret, size, state->point_r.x, size, &state->rv, state->process));
105 CHECK_RESULT(
bignum_mod_start(state->signature_s, state->len, ord, size, &state->rv, state->process));
110 CHECK_RESULT(
bignum_add_start(state->hash, size, state->signature_s, size, &state->rv, state->process));
116 CHECK_RESULT(
bignum_mod_start(state->signature_s, state->len, ord, size, &state->rv, state->process));
121 CHECK_RESULT(
bignum_mul_start(state->k_e_inv, size, state->signature_s, size, &state->rv, state->process));
127 CHECK_RESULT(
bignum_mod_start(state->signature_s, state->len, ord, size, &state->rv, state->process));
134 PT_THREAD(ecc_dsa_verify(ecc_dsa_verify_state_t *state)) {
136 uint8_t size = state->curve_info->size;
137 const uint32_t *ord = state->curve_info->n;
140 memcpy(point.x, state->curve_info->x,
sizeof(point.x));
141 memcpy(point.y, state->curve_info->y,
sizeof(point.y));
146 CHECK_RESULT(
bignum_inv_mod_start(state->signature_s, size, ord, size, &state->rv, state->process));
151 CHECK_RESULT(
bignum_mul_start(state->s_inv, size, state->hash, size, &state->rv, state->process));
157 CHECK_RESULT(
bignum_mod_start(state->u1, state->len, ord, size, &state->rv, state->process));
162 CHECK_RESULT(
bignum_mul_start(state->s_inv, size, state->signature_r, size, &state->rv, state->process));
168 CHECK_RESULT(
bignum_mod_start(state->u2, state->len, ord, size, &state->rv, state->process));
173 CHECK_RESULT(
ecc_mul_start(state->u1, &point, state->curve_info, &state->rv, state->process));
178 CHECK_RESULT(
ecc_mul_start(state->u2, &state->public, state->curve_info, &state->rv, state->process));
183 CHECK_RESULT(
ecc_add_start(&state->p1, &state->p2, state->curve_info, &state->rv, state->process));
188 CHECK_RESULT(
bignum_cmp_start(state->signature_r, state->p1.x, size, state->process));
uint8_t bignum_cmp_get_result(void)
Gets the result of the comparison operation of two big numbers.
uint8_t ecc_mul_get_result(ec_point_t *ec_point, uint32_t result_vector)
Gets the result of ECC Multiplication.
Header file for the cc2538 ECC Algorithms.
uint8_t pka_check_status(void)
Checks the status of the PKA engine operation.
#define PKA_STATUS_A_LT_B
Big number compare return status if the first big num is less than the second.
uint8_t bignum_mod_get_result(uint32_t *buffer, const uint8_t buffer_size, const uint32_t result_vector)
Gets the result of the big number modulus operation.
#define PT_BEGIN(pt)
Declare the start of a protothread inside the C function implementing the protothread.
uint8_t bignum_inv_mod_get_result(uint32_t *buffer, const uint8_t buffer_size, const uint32_t result_vector)
Gets the result of the big number inverse modulo operation.
uint8_t bignum_mod_start(const uint32_t *number, const uint8_t number_size, const uint32_t *modulus, const uint8_t modulus_size, uint32_t *result_vector, struct process *process)
Starts the big number modulus operation.
#define PT_WAIT_UNTIL(pt, condition)
Block and wait until condition is true.
#define PKA_STATUS_A_GR_B
Big number compare return status if the first big num is greater than the second. ...
PT_THREAD(ecc_compare(ecc_compare_state_t *state))
Do a compare of two big numbers.
uint8_t ecc_add_get_result(ec_point_t *ec_point, uint32_t result_vector)
Gets the result of the ECC Addition.
uint8_t bignum_mul_start(const uint32_t *multiplicand, const uint8_t multiplicand_size, const uint32_t *multiplier, const uint8_t multiplier_size, uint32_t *result_vector, struct process *process)
Starts the big number multiplication.
uint8_t ecc_mul_start(uint32_t *scalar, ec_point_t *ec_point, ecc_curve_info_t *curve, uint32_t *result_vector, struct process *process)
Starts ECC Multiplication.
uint8_t bignum_add_start(const uint32_t *number1, const uint8_t number1_size, const uint32_t *number2, const uint8_t number2_size, uint32_t *result_vector, struct process *process)
Starts the addition of two big number.
Header file for the cc2538 PKA engine driver.
#define PT_END(pt)
Declare the end of a protothread.
Header file for the cc2538 ECC driver.
Header file for the Contiki process interface.
uint8_t ecc_add_start(ec_point_t *ec_point1, ec_point_t *ec_point2, ecc_curve_info_t *curve, uint32_t *result_vector, struct process *process)
Starts the ECC Addition.
uint8_t bignum_add_get_result(uint32_t *buffer, uint32_t *buffer_size, const uint32_t result_vector)
Gets the result of the addition operation on two big number.
uint8_t bignum_cmp_start(const uint32_t *number1, const uint32_t *number2, const uint8_t size, struct process *process)
Starts the comparison of two big numbers.
uint8_t bignum_inv_mod_start(const uint32_t *number, const uint8_t number_size, const uint32_t *modulus, const uint8_t modulus_size, uint32_t *result_vector, struct process *process)
Starts the big number inverse modulo operation.
uint8_t bignum_mul_get_result(uint32_t *buffer, uint32_t *buffer_size, const uint32_t result_vector)
Gets the results of the big number multiplication.
#define PKA_STATUS_SIGNATURE_INVALID
Signature is invalid.