diff options
author | James Bottomley <James.Bottomley@HansenPartnership.com> | 2018-11-06 12:20:54 -0800 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2018-11-07 08:07:52 -0800 |
commit | 1d1701af30637700f63e0e99c9aae9e1f7c3cfd4 (patch) | |
tree | 923ecd0dc8f53a688ace08b3a2db87c85e5fa14b | |
parent | ef8d71aae38cfed2e701e0e93b962b8a0e1b5f95 (diff) | |
download | openssl_tpm2_engine-1d1701af30637700f63e0e99c9aae9e1f7c3cfd4.tar.gz |
create_tpm2_key: fix name algorithm selection
The results from strcasecmp are zero if it matches, so you need a not
in front of strcasecmp() for the condition to be "it matches". The
current strncasecmp() in the name algorithm selection were missing the
not's resulting in the wrong algorithm being selected if you specified
it on the command line.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r-- | create_tpm2_key.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/create_tpm2_key.c b/create_tpm2_key.c index f95f70c..1f8a479 100644 --- a/create_tpm2_key.c +++ b/create_tpm2_key.c @@ -65,7 +65,6 @@ static struct option long_options[] = { }; static TPM_ALG_ID name_alg = TPM_ALG_SHA256; -static int name_alg_size = SHA256_DIGEST_SIZE; void usage(char *argv0) @@ -676,16 +675,13 @@ int main(int argc, char **argv) case 'n': if (!strcasecmp("sha1", optarg)) { name_alg = TPM_ALG_SHA1; - name_alg_size = SHA1_DIGEST_SIZE; - } else if (strcasecmp("sha256", optarg)) { + } else if (!strcasecmp("sha256", optarg)) { /* default, do nothing */ - } else if (strcasecmp("sha384", optarg)) { + } else if (!strcasecmp("sha384", optarg)) { name_alg = TPM_ALG_SHA384; - name_alg_size = SHA384_DIGEST_SIZE; #ifdef TPM_ALG_SHA512 - } else if (strcasecmp("sha512", optarg)) { + } else if (!strcasecmp("sha512", optarg)) { name_alg = TPM_ALG_SHA512; - name_alg_size = SHA512_DIGEST_SIZE; #endif } else { usage(argv[0]); |