Skip to content

Commit d97dd16

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Minor fixes for readability in Cracen driver
Does some small improvements to increase readability by removing unnecessary code. When memcpy is used it is valid to pass 0 as length so it removes if statements which check the length. Replaes duplicated return statements to single ones. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent 391f6d7 commit d97dd16

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

subsys/nrf_security/src/drivers/cracen/cracen_sw/src/cracen_sw_cipher.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ static psa_status_t encrypt_cbc(const struct sxkeyref *key, const uint8_t *input
152152
}
153153

154154
memset(padded_input_block, padding, sizeof(padded_input_block));
155-
if (remaining_bytes > 0) {
156-
memcpy(padded_input_block, input + full_blocks_length, remaining_bytes);
157-
}
155+
memcpy(padded_input_block, input + full_blocks_length, remaining_bytes);
158156

159157
sx_status = sx_blkcipher_crypt(&cipher_ctx, padded_input_block, sizeof(padded_input_block),
160158
output + full_blocks_length);
@@ -170,10 +168,9 @@ static psa_status_t encrypt_cbc(const struct sxkeyref *key, const uint8_t *input
170168
sx_status = sx_blkcipher_wait(&cipher_ctx);
171169
if (sx_status == SX_OK) {
172170
*output_length = padded_input_length;
173-
return PSA_SUCCESS;
174-
} else {
175-
return silex_statuscodes_to_psa(sx_status);
176171
}
172+
173+
return silex_statuscodes_to_psa(sx_status);
177174
}
178175

179176
static psa_status_t decrypt_cbc(const struct sxkeyref *key, const uint8_t *input,

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/cipher.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ static psa_status_t encrypt_cbc(const struct sxkeyref *key, const uint8_t *input
198198
}
199199

200200
memset(padded_input_block, padding, sizeof(padded_input_block));
201-
if (remaining_bytes > 0) {
202-
memcpy(padded_input_block, input + full_blocks_length, remaining_bytes);
203-
}
201+
memcpy(padded_input_block, input + full_blocks_length, remaining_bytes);
204202

205203
sx_status = sx_blkcipher_crypt(&cipher_ctx, padded_input_block, sizeof(padded_input_block),
206204
output + full_blocks_length);
@@ -216,10 +214,9 @@ static psa_status_t encrypt_cbc(const struct sxkeyref *key, const uint8_t *input
216214
sx_status = sx_blkcipher_wait(&cipher_ctx);
217215
if (sx_status == SX_OK) {
218216
*output_length = padded_input_length;
219-
return PSA_SUCCESS;
220-
} else {
221-
return silex_statuscodes_to_psa(sx_status);
222217
}
218+
219+
return silex_statuscodes_to_psa(sx_status);
223220
}
224221

225222
static psa_status_t decrypt_cbc(const struct sxkeyref *key, const uint8_t *input,

0 commit comments

Comments
 (0)