Skip to content

Commit

Permalink
Clean: replace magic values with define
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Feb 21, 2024
1 parent d5b9334 commit 1c589ae
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 185 deletions.
4 changes: 2 additions & 2 deletions src/monero_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ void display_account(void);
/* ----------------------------------------------------------------------- */
/* --- KEYS & ADDRESS ---- */
/* ----------------------------------------------------------------------- */
extern const unsigned char C_FAKE_SEC_VIEW_KEY[32];
extern const unsigned char C_FAKE_SEC_SPEND_KEY[32];
extern const unsigned char C_FAKE_SEC_VIEW_KEY[KEY_SIZE];
extern const unsigned char C_FAKE_SEC_SPEND_KEY[KEY_SIZE];

int is_fake_view_key(unsigned char *s);
int is_fake_spend_key(unsigned char *s);
Expand Down
12 changes: 6 additions & 6 deletions src/monero_blind.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
int monero_apdu_blind() {
unsigned char v[32];
unsigned char k[32];
unsigned char AKout[32];
unsigned char AKout[KEY_SIZE];
int err = 0;

err = monero_io_fetch_decrypt(AKout, 32, TYPE_AMOUNT_KEY);
err = monero_io_fetch_decrypt(AKout, KEY_SIZE, TYPE_AMOUNT_KEY);
if (err) {
return err;
}
Expand Down Expand Up @@ -132,10 +132,10 @@ int monero_unblind(unsigned char *v, unsigned char *k, unsigned char *AKout,
int monero_apdu_unblind() {
unsigned char v[32];
unsigned char k[32];
unsigned char AKout[32];
unsigned char AKout[KEY_SIZE];
int err = 0;

err = monero_io_fetch_decrypt(AKout, 32, TYPE_AMOUNT_KEY);
err = monero_io_fetch_decrypt(AKout, KEY_SIZE, TYPE_AMOUNT_KEY);
if (err) {
return err;
}
Expand All @@ -162,10 +162,10 @@ int monero_apdu_unblind() {
/* ----------------------------------------------------------------------- */
int monero_apdu_gen_commitment_mask() {
unsigned char k[32];
unsigned char AKout[32];
unsigned char AKout[KEY_SIZE];
int err = 0;

err = monero_io_fetch_decrypt(AKout, 32, TYPE_AMOUNT_KEY);
err = monero_io_fetch_decrypt(AKout, KEY_SIZE, TYPE_AMOUNT_KEY);
if (err) {
return err;
}
Expand Down
10 changes: 5 additions & 5 deletions src/monero_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ unsigned char const C_EIGHT[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0
/* --- --- */
/* ----------------------------------------------------------------------- */
int monero_aes_derive(cx_aes_key_t *sk, unsigned char *seed32, unsigned char *a, unsigned char *b) {
unsigned char h1[32];
unsigned char h1[KEY_SIZE];
int error;

error = monero_keccak_init_H();
if (error) {
return error;
}

error = monero_keccak_update_H(seed32, 32);
error = monero_keccak_update_H(seed32, KEY_SIZE);
if (error) {
return error;
}

error = monero_keccak_update_H(a, 32);
error = monero_keccak_update_H(a, KEY_SIZE);
if (error) {
return error;
}

error = monero_keccak_update_H(b, 32);
error = monero_keccak_update_H(b, KEY_SIZE);
if (error) {
return error;
}
Expand All @@ -87,7 +87,7 @@ int monero_aes_derive(cx_aes_key_t *sk, unsigned char *seed32, unsigned char *a,
return error;
}

error = monero_keccak_H(h1, 32, h1);
error = monero_keccak_H(h1, KEY_SIZE, h1);
if (error) {
return error;
}
Expand Down
14 changes: 7 additions & 7 deletions src/monero_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
/* ----------------------*/
const unsigned char C_MAGIC[8] = {'M', 'O', 'N', 'E', 'R', 'O', 'H', 'W'};

const unsigned char C_FAKE_SEC_VIEW_KEY[32] = {
const unsigned char C_FAKE_SEC_VIEW_KEY[KEY_SIZE] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const unsigned char C_FAKE_SEC_SPEND_KEY[32] = {
const unsigned char C_FAKE_SEC_SPEND_KEY[KEY_SIZE] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

Expand Down Expand Up @@ -72,7 +72,7 @@ unsigned int monero_init() {
int monero_init_private_key(void) {
unsigned int path[5];
unsigned char seed[64];
unsigned char chain[32];
unsigned char chain[KEY_SIZE];
int error;

// generate account keys
Expand All @@ -91,7 +91,7 @@ int monero_init_private_key(void) {
switch (N_monero_pstate->key_mode) {
case KEY_MODE_SEED:

error = monero_keccak_F(seed, 32, G_monero_vstate.b);
error = monero_keccak_F(seed, KEY_SIZE, G_monero_vstate.b);
if (error) {
return error;
}
Expand All @@ -102,7 +102,7 @@ int monero_init_private_key(void) {
return error;
}

error = monero_keccak_F(G_monero_vstate.b, 32, G_monero_vstate.a);
error = monero_keccak_F(G_monero_vstate.b, KEY_SIZE, G_monero_vstate.a);
if (error) {
return error;
}
Expand All @@ -115,8 +115,8 @@ int monero_init_private_key(void) {
break;

case KEY_MODE_EXTERNAL:
memcpy(G_monero_vstate.a, (void*)N_monero_pstate->a, 32);
memcpy(G_monero_vstate.b, (void*)N_monero_pstate->b, 32);
memcpy(G_monero_vstate.a, (void*)N_monero_pstate->a, KEY_SIZE);
memcpy(G_monero_vstate.b, (void*)N_monero_pstate->b, KEY_SIZE);
break;

default:
Expand Down
Loading

0 comments on commit 1c589ae

Please sign in to comment.