Commit 154a96bf authored by Tetsuo Handa's avatar Tetsuo Handa Committed by James Morris

trusted-keys: avoid scattring va_end()

We can avoid scattering va_end() within the

  va_start();
  for (;;) {

  }
  va_end();

loop, assuming that crypto_shash_init()/crypto_shash_update() return 0 on
success and negative value otherwise.

Make TSS_authhmac()/TSS_checkhmac1()/TSS_checkhmac2() similar to TSS_rawhmac()
by removing "va_end()/goto" from the loop.
Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: default avatarJesper Juhl <jj@chaosbits.net>
Acked-by: default avatarMimi Zohar <zohar@us.ibm.com>
Acked-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 0e7491f6
...@@ -150,17 +150,15 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key, ...@@ -150,17 +150,15 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
data = va_arg(argp, unsigned char *); data = va_arg(argp, unsigned char *);
if (!data) { if (!data) {
ret = -EINVAL; ret = -EINVAL;
va_end(argp); break;
goto out;
} }
ret = crypto_shash_update(&sdesc->shash, data, dlen); ret = crypto_shash_update(&sdesc->shash, data, dlen);
if (ret < 0) { if (ret < 0)
va_end(argp); break;
goto out;
}
} }
va_end(argp); va_end(argp);
ret = crypto_shash_final(&sdesc->shash, paramdigest); if (!ret)
ret = crypto_shash_final(&sdesc->shash, paramdigest);
if (!ret) if (!ret)
ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE, ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
paramdigest, TPM_NONCE_SIZE, h1, paramdigest, TPM_NONCE_SIZE, h1,
...@@ -229,13 +227,12 @@ static int TSS_checkhmac1(unsigned char *buffer, ...@@ -229,13 +227,12 @@ static int TSS_checkhmac1(unsigned char *buffer,
break; break;
dpos = va_arg(argp, unsigned int); dpos = va_arg(argp, unsigned int);
ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen); ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
if (ret < 0) { if (ret < 0)
va_end(argp); break;
goto out;
}
} }
va_end(argp); va_end(argp);
ret = crypto_shash_final(&sdesc->shash, paramdigest); if (!ret)
ret = crypto_shash_final(&sdesc->shash, paramdigest);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -323,13 +320,12 @@ static int TSS_checkhmac2(unsigned char *buffer, ...@@ -323,13 +320,12 @@ static int TSS_checkhmac2(unsigned char *buffer,
break; break;
dpos = va_arg(argp, unsigned int); dpos = va_arg(argp, unsigned int);
ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen); ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
if (ret < 0) { if (ret < 0)
va_end(argp); break;
goto out;
}
} }
va_end(argp); va_end(argp);
ret = crypto_shash_final(&sdesc->shash, paramdigest); if (!ret)
ret = crypto_shash_final(&sdesc->shash, paramdigest);
if (ret < 0) if (ret < 0)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment