Skip to content

Commit b0cba9b

Browse files
committed
feat: Update docs for decryption
1 parent f1b345e commit b0cba9b

File tree

5 files changed

+121
-5
lines changed

5 files changed

+121
-5
lines changed

apps/inheritance_app/inheritance_decrypt_data.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,80 @@
9595
* STATIC FUNCTION PROTOTYPES
9696
*****************************************************************************/
9797

98+
/**
99+
* @brief Checks if the given request matches the expected request type.
100+
*
101+
* @param query Pointer to the inheritance query.
102+
* @param which_request The expected request type.
103+
* @return true if the request type matches, false otherwise.
104+
*/
105+
static bool check_which_request(const inheritance_query_t *query,
106+
pb_size_t which_request);
107+
108+
/**
109+
* @brief Validates the request data for decryption.
110+
*
111+
* @param request Pointer to the decryption request data.
112+
* @return true if the request data is valid, false otherwise.
113+
*/
114+
static bool validate_request_data(
115+
const inheritance_decrypt_data_with_pin_request_t *request);
116+
117+
/**
118+
* @brief Handles the initiation of the decryption query.
119+
*
120+
* @param query Pointer to the inheritance query.
121+
* @return true if the initiation is successful, false otherwise.
122+
*/
123+
STATIC bool inheritance_handle_initiate_query(inheritance_query_t *query);
124+
125+
/**
126+
* @brief Sends the decrypted data as a response.
127+
*
128+
* @param query Pointer to the inheritance query.
129+
* @return true if sending the response is successful, false otherwise.
130+
*/
131+
static bool send_decrypted_data(inheritance_query_t *query);
132+
133+
/**
134+
* @brief Decrypts the packet containing encrypted data.
135+
*
136+
* @return true if decryption is successful, false otherwise.
137+
*/
138+
static bool decrypt_packet(void);
139+
140+
/**
141+
* @brief Deserializes the decrypted packet into individual data items.
142+
*
143+
* @return true if deserialization is successful, false otherwise.
144+
*/
145+
static bool deserialize_packet(void);
146+
147+
/**
148+
* @brief Decrypts the message data within the packet.
149+
*
150+
* @return true if message data decryption is successful, false otherwise.
151+
*/
152+
static bool decrypt_message_data(void);
153+
154+
/**
155+
* @brief Decrypts the overall data.
156+
*
157+
* @return true if decryption is successful, false otherwise.
158+
*/
159+
static bool decrypt_data(void);
160+
161+
/**
162+
* @brief Displays decrypted data or performs related actions based on the data.
163+
*
164+
* This function processes the decrypted data and either shows it on the device
165+
* screen (if the tag indicates display-only) or prepares it for further
166+
* response.
167+
*
168+
* @return true if the operation is successful, false otherwise.
169+
*/
170+
static bool show_data(void);
171+
98172
/*****************************************************************************
99173
* STATIC VARIABLES
100174
*****************************************************************************/

common/core/core_session.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ void core_session_parse_start_message(const core_msg_t *core_msg);
116116
*/
117117
session_error_type_e session_aes_encrypt(uint8_t *InOut_data, uint16_t *len);
118118

119+
/**
120+
* @brief Decrypts data using AES-CBC mode.
121+
*
122+
* This function decrypts the input data using the session key and IV.
123+
*
124+
* @param InOut_data Pointer to the input data (encrypted) and output data
125+
* (decrypted).
126+
* @param len Pointer to the length of the data (updated with actual decrypted
127+
* length).
128+
* @return The session error type indicating the decryption result.
129+
*/
119130
session_error_type_e session_aes_decrypt(uint8_t *InOut_data, uint16_t *len);
120131

121132
#endif // CORE_SESSION

src/card_operations/card_fetch_data.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,34 @@ typedef struct {
5252
*****************************************************************************/
5353

5454
/**
55-
* @brief Encrypts given secure_data_t with card and stores the encrypted data
56-
* in the same struct
55+
* @brief Fetches and encrypts data for a given wallet ID.
5756
*
58-
* @return A card_error_type_e value representing the result of the operation.
57+
* This function retrieves plain data associated with a wallet ID, encrypts it,
58+
* and stores the encrypted data in the provided secure_data_t structures.
59+
*
60+
* @param wallet_id Pointer to the wallet ID.
61+
* @param msgs Pointer to an array of secure_data_t structures to store the
62+
* encrypted data.
63+
* @param msg_count Number of secure_data_t structures in the array.
64+
* @return The card error type indicating the result of the operation.
5965
*/
60-
card_error_type_e card_fetch_encrypt_data(uint8_t *wallet_id,
66+
card_error_type_e card_fetch_encrypt_data(const uint8_t *wallet_id,
6167
secure_data_t *msgs,
6268
size_t msg_count);
6369

70+
/**
71+
* @brief Fetches and decrypts data from the card.
72+
*
73+
* This function retrieves encrypted data associated with a wallet ID from the
74+
* card, decrypts it, and stores the plain data in the provided secure_data_t
75+
* structures.
76+
*
77+
* @param wallet_id Pointer to the wallet ID.
78+
* @param msgs Pointer to an array of secure_data_t structures to store the
79+
* decrypted data.
80+
* @param msg_count Number of secure_data_t structures in the array.
81+
* @return The card error type indicating the result of the operation.
82+
*/
6483
card_error_type_e card_fetch_decrypt_data(const uint8_t *wallet_id,
6584
secure_data_t *msgs,
6685
size_t msg_count);

src/card_operations/card_fetch_encrypt_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
* GLOBAL FUNCTIONS
100100
*****************************************************************************/
101101

102-
card_error_type_e card_fetch_encrypt_data(uint8_t *wallet_id,
102+
card_error_type_e card_fetch_encrypt_data(const uint8_t *wallet_id,
103103
secure_data_t *msgs,
104104
size_t msg_count) {
105105
card_error_type_e result = CARD_OPERATION_DEFAULT_INVALID;

src/card_operations/card_fetch_wallet_list.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ card_error_type_e card_fetch_wallet_list(
5757
const card_fetch_wallet_list_config_t *config,
5858
card_fetch_wallet_list_response_t *response);
5959

60+
/**
61+
* @brief Fetches the wallet name associated with a given wallet ID.
62+
*
63+
* This function retrieves the list of wallets from the card and searches for
64+
* the wallet with the specified wallet ID. If found, it copies the wallet name
65+
* to the provided buffer.
66+
*
67+
* @param wallet_id Pointer to the wallet ID.
68+
* @param wallet_name Pointer to the buffer where the wallet name will be
69+
* copied.
70+
* @return true if the wallet name is successfully fetched, false otherwise.
71+
*/
6072
bool card_fetch_wallet_name(const uint8_t *wallet_id, char *wallet_name);
6173

6274
#endif /* CARD_FETCH_WALLET_LIST_H */

0 commit comments

Comments
 (0)