Skip to content

Commit

Permalink
check return error
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Dec 7, 2023
1 parent 2e623f8 commit be1e4a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 7 additions & 3 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,17 @@ void handleTest(volatile uint32_t *tx) {

jubjub_extendedpoint p;
jubjub_fq scal;
jubjub_field_frombytes(scal, scalar);
if (jubjub_field_frombytes(scal, scalar) != zxerr_ok) {
*tx = 0;
MEMZERO(point, sizeof(point));
THROW(APDU_CODE_OK);
}

jubjub_extendedpoint_tobytes(point, JUBJUB_GEN);
zxerr_t err = jubjub_extendedpoint_frombytes(&p, point);
const zxerr_t err = jubjub_extendedpoint_frombytes(&p, point);
if (err != zxerr_ok) {
*tx = 0;
MEMZERO(point, 32);
MEMZERO(point, sizeof(point));
THROW(APDU_CODE_OK);
}
// MEMCPY(&p, &JUBJUB_GEN, 32);
Expand Down
7 changes: 4 additions & 3 deletions app/src/jubjub.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ void u8_cmov(uint8_t *r, uint8_t a, uint8_t bit) {
*r = *r ^ x;
}

void jubjub_field_frombytes(jubjub_fq r, const uint8_t *s) {
zxerr_t jubjub_field_frombytes(jubjub_fq r, const uint8_t *s) {
MEMZERO(r, sizeof(jubjub_fq));
MEMCPY(r, s, sizeof(jubjub_fq));
cx_math_modm_no_throw(r, JUBJUB_FIELD_BYTES, JUBJUB_FQ_MODULUS_BYTES,
const cx_err_t error = cx_math_modm_no_throw(r, JUBJUB_FIELD_BYTES, JUBJUB_FQ_MODULUS_BYTES,
JUBJUB_FIELD_BYTES);
return error == CX_OK ? zxerr_ok : zxerr_invalid_crypto_settings;
}

int jubjub_field_iszero(const jubjub_fq r) {
Expand Down Expand Up @@ -353,7 +354,7 @@ zxerr_t jubjub_extendedpoint_frombytes(jubjub_extendedpoint *p, uint8_t *s) {

jubjub_fq v, v2, v3, u;

jubjub_field_frombytes(v, b);
CHECK_ZXERR(jubjub_field_frombytes(v, b));
jubjub_field_square(v2, v);
jubjub_field_copy(v3, v2);
jubjub_field_mult(v2, v2, JUBJUB_FQ_EDWARDS_D);
Expand Down
2 changes: 1 addition & 1 deletion app/src/jubjub.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ void jubjub_extendedpoint_tobytes(uint8_t *s, jubjub_extendedpoint p);

void jubjub_extendedpoint_scalarmult(jubjub_extendedpoint *r, jubjub_fr scalar);

void jubjub_field_frombytes(jubjub_fq r, const uint8_t *s);
zxerr_t jubjub_field_frombytes(jubjub_fq r, const uint8_t *s);

zxerr_t jubjub_extendedpoint_frombytes(jubjub_extendedpoint *p, uint8_t *s);

0 comments on commit be1e4a6

Please sign in to comment.