From: Igor Kotrasinski Date: Mon, 23 Apr 2018 09:51:29 +0000 (+0200) Subject: Port padding sanity checks from suprem X-Git-Tag: submit/tizen/20180828.110226~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F176808%2F4;p=platform%2Fcore%2Fsecurity%2Ftef-simulator.git Port padding sanity checks from suprem Change-Id: Icee3e0f1e04ee874fd931ec0079a28f606ad9638 Signed-off-by: Igor Kotrasinski --- diff --git a/ssflib/src/ssf_crypto.cpp b/ssflib/src/ssf_crypto.cpp index dccd8d0..d0b3153 100644 --- a/ssflib/src/ssf_crypto.cpp +++ b/ssflib/src/ssf_crypto.cpp @@ -1269,7 +1269,10 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s } 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) { @@ -1292,7 +1295,10 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s 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;