}
if (ok) {
- total_processing_len -= npad; // padding OK. Othewise padding will not be removed
+ if (total_processing_len >= npad)
+ total_processing_len -= npad; // padding OK. Othewise padding will not be removed
+ else
+ total_processing_len = 0;
}
}
} else if (operation->info.algorithm == TEE_ALG_AES_ECB_ISO9797_M1 ||operation->info.algorithm == TEE_ALG_AES_CBC_ISO9797_M1) {
npad = 0; // don't remove any padding
}
- total_processing_len -= npad;
+ if (total_processing_len >= npad)
+ total_processing_len -= npad;
+ else
+ total_processing_len = 0;
} else if (operation->info.algorithm == TEE_ALG_AES_CTR || operation->info.algorithm == TEE_ALG_AES_CTR_NOPAD) {
memcpy(operation->data, in_data, remaining_number_of_bytes);
operation->data_len += remaining_number_of_bytes;