Skip to content

Commit

Permalink
move io_id check from set_key to handle_input
Browse files Browse the repository at this point in the history
in set_key, io_id might as well be an _output_ identifier, so it was 
wrong to add that check here.
  • Loading branch information
gianlu33 committed Oct 20, 2021
1 parent ba4ff89 commit f3b071c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/stubs/sm_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ uint16_t SM_ENTRY(SM_NAME) __sm_handle_input(uint16_t conn_idx,

Connection *conn = &__sm_io_connections[conn_idx];

// check if io_id is a valid input ID
if (conn->io_id >= SM_NUM_INPUTS) {
return 3;
}

// associated data only contains the nonce, therefore we can use this
// this trick to build the array fastly (i.e. by swapping the bytes)
const uint16_t nonce_rev = conn->nonce << 8 | conn->nonce >> 8;
Expand All @@ -35,5 +40,5 @@ uint16_t SM_ENTRY(SM_NAME) __sm_handle_input(uint16_t conn_idx,
}

// here only if decryption fails
return 3;
return 4;
}
4 changes: 2 additions & 2 deletions src/stubs/sm_set_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ uint16_t SM_ENTRY(SM_NAME) __sm_set_key(const uint8_t* ad, const uint8_t* cipher
return 2;
}

// check parameters
if(nonce != __sm_num_connections || io_id >= SM_NUM_INPUTS) {
// check nonce
if(nonce != __sm_num_connections) {
return 3;
}

Expand Down

0 comments on commit f3b071c

Please sign in to comment.