File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
subsys/nrf_security/src/drivers/cracen/cracenpsa/src Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -258,20 +258,20 @@ static psa_status_t decrypt_cbc(const struct sxkeyref *key, const uint8_t *input
258258 return silex_statuscodes_to_psa (sx_status );
259259 }
260260
261- uint8_t padding = output [input_length - 1 ];
261+ size_t padding_length = output [input_length - 1 ];
262+ size_t padding_index = input_length - padding_length ;
263+ uint32_t failure = 0 ;
262264
263- if (padding > SX_BLKCIPHER_AES_BLK_SZ || padding == 0 ) {
264- return PSA_ERROR_INVALID_PADDING ;
265- }
265+ failure |= (padding_length > SX_BLKCIPHER_AES_BLK_SZ );
266+ failure |= (padding_length == 0 );
266267
267- for (size_t i = input_length - padding ; i < input_length ; i ++ ) {
268- if (output [i ] != padding ) {
269- return PSA_ERROR_INVALID_PADDING ;
270- }
268+ for (size_t i = 0 ; i < input_length ; i ++ ) {
269+ failure |= (output [i ] ^ padding_length ) * (i >= padding_index );
271270 }
272271
273- * output_length = input_length - padding ;
274- return PSA_SUCCESS ;
272+ * output_length = padding_index ;
273+
274+ return (failure == 0 ) ? PSA_SUCCESS : PSA_ERROR_INVALID_PADDING ;
275275}
276276
277277psa_status_t cracen_cipher_encrypt (const psa_key_attributes_t * attributes ,
You can’t perform that action at this time.
0 commit comments