mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
tpm2d: Use BYTE type to acces TPM2B object.
* tpm2d/tpm2.c (tpm2_SensitiveToDuplicate): Don't use the cast of (TPM2B *). -- While it works (since the actual access is done by the macros), compiler may complain the alignment property of type BYTE * and TPM2B object is different. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
0cb7f6fbb7
commit
e0543f97be
27
tpm2d/tpm2.c
27
tpm2d/tpm2.c
@ -695,8 +695,8 @@ TPM_RC tpm2_SensitiveToDuplicate (TPMT_SENSITIVE *s,
|
|||||||
{
|
{
|
||||||
TPMT_HA hash;
|
TPMT_HA hash;
|
||||||
const int hlen = TSS_GetDigestSize (nalg);
|
const int hlen = TSS_GetDigestSize (nalg);
|
||||||
TPM2B *digest = (TPM2B *)buf;
|
BYTE *digest;
|
||||||
TPM2B *s2b;
|
BYTE *s2b;
|
||||||
int32_t size;
|
int32_t size;
|
||||||
unsigned char null_iv[AES_128_BLOCK_SIZE_BYTES];
|
unsigned char null_iv[AES_128_BLOCK_SIZE_BYTES];
|
||||||
UINT16 bsize, written = 0;
|
UINT16 bsize, written = 0;
|
||||||
@ -707,13 +707,12 @@ TPM_RC tpm2_SensitiveToDuplicate (TPMT_SENSITIVE *s,
|
|||||||
memset (null_iv, 0, sizeof (null_iv));
|
memset (null_iv, 0, sizeof (null_iv));
|
||||||
|
|
||||||
/* reserve space for hash before the encrypted sensitive */
|
/* reserve space for hash before the encrypted sensitive */
|
||||||
bsize = sizeof (digest->size) + hlen;
|
digest = buf;
|
||||||
buf += bsize;
|
bsize = sizeof (uint16_t /* TPM2B.size */) + hlen;
|
||||||
p->size += bsize;
|
p->size += bsize;
|
||||||
s2b = (TPM2B *)buf;
|
s2b = digest + bsize;
|
||||||
|
|
||||||
/* marshal the digest size */
|
/* marshal the digest size */
|
||||||
buf = (BYTE *)&digest->size;
|
|
||||||
bsize = hlen;
|
bsize = hlen;
|
||||||
size = 2;
|
size = 2;
|
||||||
TSS_UINT16_Marshal (&bsize, &written, &buf, &size);
|
TSS_UINT16_Marshal (&bsize, &written, &buf, &size);
|
||||||
@ -721,13 +720,13 @@ TPM_RC tpm2_SensitiveToDuplicate (TPMT_SENSITIVE *s,
|
|||||||
/* marshal the unencrypted sensitive in place */
|
/* marshal the unencrypted sensitive in place */
|
||||||
size = sizeof (*s);
|
size = sizeof (*s);
|
||||||
bsize = 0;
|
bsize = 0;
|
||||||
buf = s2b->buffer;
|
buf = s2b + offsetof (TPM2B, buffer);
|
||||||
TSS_TPMT_SENSITIVE_Marshal (s, &bsize, &buf, &size);
|
TSS_TPMT_SENSITIVE_Marshal (s, &bsize, &buf, &size);
|
||||||
buf = (BYTE *)&s2b->size;
|
buf = s2b;
|
||||||
size = 2;
|
size = 2;
|
||||||
TSS_UINT16_Marshal (&bsize, &written, &buf, &size);
|
TSS_UINT16_Marshal (&bsize, &written, &buf, &size);
|
||||||
|
|
||||||
bsize = bsize + sizeof (s2b->size);
|
bsize = bsize + sizeof (uint16_t /* TPM2B.size */);
|
||||||
p->size += bsize;
|
p->size += bsize;
|
||||||
|
|
||||||
/* compute hash of unencrypted marshalled sensitive and
|
/* compute hash of unencrypted marshalled sensitive and
|
||||||
@ -736,7 +735,7 @@ TPM_RC tpm2_SensitiveToDuplicate (TPMT_SENSITIVE *s,
|
|||||||
TSS_Hash_Generate (&hash, bsize, s2b,
|
TSS_Hash_Generate (&hash, bsize, s2b,
|
||||||
name->size, name->name,
|
name->size, name->name,
|
||||||
0, NULL);
|
0, NULL);
|
||||||
memcpy (digest->buffer, &hash.digest, hlen);
|
memcpy (digest + offsetof (TPM2B, buffer), &hash.digest, hlen);
|
||||||
gcry_cipher_open (&hd, GCRY_CIPHER_AES128,
|
gcry_cipher_open (&hd, GCRY_CIPHER_AES128,
|
||||||
GCRY_CIPHER_MODE_CFB, GCRY_CIPHER_SECURE);
|
GCRY_CIPHER_MODE_CFB, GCRY_CIPHER_SECURE);
|
||||||
gcry_cipher_setiv (hd, null_iv, sizeof (null_iv));
|
gcry_cipher_setiv (hd, null_iv, sizeof (null_iv));
|
||||||
@ -749,20 +748,20 @@ TPM_RC tpm2_SensitiveToDuplicate (TPMT_SENSITIVE *s,
|
|||||||
else if (symdef->algorithm == TPM_ALG_NULL)
|
else if (symdef->algorithm == TPM_ALG_NULL)
|
||||||
{
|
{
|
||||||
/* Code is for debugging only, should never be used in production */
|
/* Code is for debugging only, should never be used in production */
|
||||||
TPM2B *s2b = (TPM2B *)buf;
|
BYTE *s2b = buf;
|
||||||
int32_t size = sizeof (*s);
|
int32_t size = sizeof (*s);
|
||||||
UINT16 bsize = 0, written = 0;
|
UINT16 bsize = 0, written = 0;
|
||||||
|
|
||||||
log_error ("Secret key sent to TPM unencrypted\n");
|
log_error ("Secret key sent to TPM unencrypted\n");
|
||||||
buf = s2b->buffer;
|
buf = s2b + offsetof (TPM2B, buffer);
|
||||||
|
|
||||||
/* marshal the unencrypted sensitive in place */
|
/* marshal the unencrypted sensitive in place */
|
||||||
TSS_TPMT_SENSITIVE_Marshal (s, &bsize, &buf, &size);
|
TSS_TPMT_SENSITIVE_Marshal (s, &bsize, &buf, &size);
|
||||||
buf = (BYTE *)&s2b->size;
|
buf = s2b;
|
||||||
size = 2;
|
size = 2;
|
||||||
TSS_UINT16_Marshal (&bsize, &written, &buf, &size);
|
TSS_UINT16_Marshal (&bsize, &written, &buf, &size);
|
||||||
|
|
||||||
p->size += bsize + sizeof (s2b->size);
|
p->size += bsize + sizeof (uint16_t /* TPM2B.size */);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user