diff options
author | Martin Roth <martinroth@chromium.org> | 2016-10-26 11:11:47 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-11-16 19:04:28 -0800 |
commit | 645e4ceef4b87b55262371ade74360a8c9856015 (patch) | |
tree | d34e929a8015005ddbe5dee579b2b1617d4d0573 /board/cr50 | |
parent | 2bdc25c2e11b5a155e23d0f77e331d3dd3545eef (diff) | |
download | chrome-ec-645e4ceef4b87b55262371ade74360a8c9856015.tar.gz |
cr50: Init variable before sending to function that uses it
Although the variable "hashing" is not used for PADDING_MODE_NULL or
PADDING_MODE_PKCS1, the functions DCRYPTO_rsa_encrypt and
DCRYPTO_rsa_decrypt use it for other padding types.
Because of this, GCC 5.3 and newer throws warnings when the variable is
passed in to those functions without being initialized. To fix this,
always initialize the variable, even if it's not going to be used.
This does not increase the size of any ec.*.flat file.
BRANCH=none
BUG=none
TEST=build succeeds under GCC 4.9.2, 5.3 and 6.2
Change-Id: Iafaaaed8b05080f70f2b1c2f0dbf1ee22227fd78
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/403499
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board/cr50')
-rw-r--r-- | board/cr50/tpm2/rsa.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/board/cr50/tpm2/rsa.c b/board/cr50/tpm2/rsa.c index 8b156feb75..e0bf3559e6 100644 --- a/board/cr50/tpm2/rsa.c +++ b/board/cr50/tpm2/rsa.c @@ -32,15 +32,16 @@ static int check_encrypt_params(TPM_ALG_ID padding_alg, TPM_ALG_ID hash_alg, enum padding_mode *padding, enum hashing_mode *hashing) { + /* Initialize hashing for all padding types */ + *hashing = HASH_SHA1; + if (padding_alg == TPM_ALG_RSAES) { *padding = PADDING_MODE_PKCS1; } else if (padding_alg == TPM_ALG_OAEP) { /* Only SHA1 and SHA256 supported with OAEP. */ - if (hash_alg == TPM_ALG_SHA1) - *hashing = HASH_SHA1; - else if (hash_alg == TPM_ALG_SHA256) + if (hash_alg == TPM_ALG_SHA256) *hashing = HASH_SHA256; - else + else if (hash_alg != TPM_ALG_SHA1) /* Unsupported hash algorithm. */ return 0; *padding = PADDING_MODE_OAEP; |