tpm2: rev155: Extend HASH_DEF with BYTE *OID

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2019-06-12 17:03:23 -04:00 committed by Stefan Berger
parent 244cd1bae9
commit d098436a34
2 changed files with 41 additions and 1 deletions

View File

@ -62,6 +62,8 @@
#ifndef CRYPTHASH_H
#define CRYPTHASH_H
/* 10.1.3.1 Introduction */
/* This header contains the hash structure definitions used in the TPM code to define the amount of
space to be reserved for the hash state. This allows the TPM code to not have to import all of
the symbols used by the hash computations. This lets the build environment of the TPM code not to
@ -75,6 +77,7 @@ typedef struct
const BYTE der[20];
} HASH_INFO;
union SMAC_STATES;
/* These definitions add the high-level methods for processing state that may be an SMAC */
typedef void(* SMAC_DATA_METHOD)(
union SMAC_STATES *state,
@ -212,6 +215,27 @@ TPM2B_TYPE(SHA512_DIGEST, SHA512_DIGEST_SIZE);
#if ALG_SM3_256
TPM2B_TYPE(SM3_256_DIGEST, SM3_256_DIGEST_SIZE);
#endif
/* When the TPM implements RSA, the hash-dependent OID pointers are part of the HASH_DEF. These
macros conditionally add the OID reference to the HASH_DEF and the HASH_DEF_TEMPLATE. */
#if ALG_RSA
#define PKCS1_HASH_REF const BYTE *PKCS1;
#define PKCS1_OID(NAME) , OID_PKCS1_##NAME
#else
#define PKCS1_HASH_REF
#define PKCS1_OID(NAME)
#endif
/* When the TPM implements ECC, the hash-dependent OID pointers are part of the HASH_DEF. These
macros conditionally add the OID reference to the HASH_DEF and the HASH_DEF_TEMPLATE. */
#if ALG_ECDSA
#define ECDSA_HASH_REF const BYTE *ECDSA;
#define ECDSA_OID(NAME) , OID_ECDSA_##NAME
#else
#define ECDSA_HASH_REF
#define ECDSA_OID(NAME)
#endif
typedef const struct
{
HASH_METHODS method;
@ -219,7 +243,11 @@ typedef const struct
uint16_t digestSize;
uint16_t contextSize;
uint16_t hashAlg;
const BYTE *OID;
PKCS1_HASH_REF // PKCS1 OID
ECDSA_HASH_REF // ECDSA OID
} HASH_DEF, *PHASH_DEF;
/* Macro to fill in the HASH_DEF for an algorithm. For SHA1, the instance would be:
HASH_DEF_TEMPLATE(Sha1, SHA1) This handles the difference in capitalization for the various
pieces. */
@ -236,7 +264,8 @@ typedef const struct
HASH##_BLOCK_SIZE, /*block size */ \
HASH##_DIGEST_SIZE, /*data size */ \
sizeof(tpmHashState##HASH##_t), \
TPM_ALG_##HASH};
TPM_ALG_##HASH, OID_##HASH \
PKCS1_OID(HASH) ECDSA_OID(HASH)};
/* These definitions are for the types that can be in a hash state structure. These types are used
in the cryptographic utilities. This is a define rather than an enum so that the size of this

View File

@ -67,6 +67,7 @@
#include "Tpm.h"
#include "CryptHash_fp.h"
#include "CryptHash.h"
#include "OIDS.h"
#define HASH_TABLE_SIZE (HASH_COUNT + 1)
extern const HASH_INFO g_hashData[HASH_COUNT + 1];
#if ALG_SHA1
@ -232,6 +233,16 @@ CryptHashGetBlockSize(
{
return CryptGetHashDef(hashAlg)->blockSize;
}
/* 10.2.13.4.7 CryptHashGetOid() */
/* This function returns a pointer to DER=encoded OID for a hash algorithm. All OIDs are full OID
values including the Tag (0x06) and length byte. */
LIB_EXPORT const BYTE *
CryptHashGetOid(
TPM_ALG_ID hashAlg
)
{
return CryptGetHashDef(hashAlg)->OID;
}
/* 10.2.13.4.8 CryptHashGetDer */
/* This function returns a pointer to the DER string for the algorithm and indicates its size. */
LIB_EXPORT UINT16