Skip to content

Commit b971116

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Simplify logic for Cracen SW cipher encrypt
Simplify the logic that handles the inplace cipher encryption in the Cracen cipher driver with the software workarounds and add a comment to describe the issue in more detail. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent d97dd16 commit b971116

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,14 @@ psa_status_t cracen_cipher_encrypt(const psa_key_attributes_t *attributes,
245245
return PSA_ERROR_BUFFER_TOO_SMALL;
246246
}
247247

248-
/* Handle inplace encryption by moving plaintext to right to free space for
249-
* iv
248+
/* Handle inplace encryption by moving plaintext to the right by iv_length
249+
* bytes. This is done because in inplace encryption the input and output
250+
* should point to the same data so that the output can overwrite its own
251+
* input. If they are not in sync the output will overwrite the input of
252+
* another operation which is of course wrong.
253+
*
250254
*/
251-
if (input_length && output > input && output < input + input_length) {
255+
if (output == input + iv_length) {
252256
memmove(output, input, input_length);
253257
input = output;
254258
}

0 commit comments

Comments
 (0)