示例#1
0
/* grub_fatal() on error */
static void
grub_TPM_readpcr( const unsigned long index, grub_uint8_t* result ) {

    CHECK_FOR_NULL_ARGUMENT( result )

	PassThroughToTPM_InputParamBlock *passThroughInput = NULL;
	PCRReadIncoming* pcrReadIncoming = NULL;
    grub_uint16_t inputlen = sizeof( *passThroughInput ) - sizeof( passThroughInput->TPMOperandIn ) + sizeof( *pcrReadIncoming );

	PassThroughToTPM_OutputParamBlock *passThroughOutput = NULL;
	PCRReadOutgoing* pcrReadOutgoing = NULL;
    grub_uint16_t outputlen = sizeof( *passThroughOutput ) - sizeof( passThroughOutput->TPMOperandOut ) + sizeof( *pcrReadOutgoing );

	passThroughInput = grub_zalloc( inputlen );
	if( ! passThroughInput ) {
        grub_fatal( "readpcr: memory allocation failed" );
	}

	passThroughInput->IPBLength = inputlen;
	passThroughInput->OPBLength = outputlen;

	pcrReadIncoming = (void *)passThroughInput->TPMOperandIn;
	pcrReadIncoming->tag = grub_swap_bytes16_compile_time( TPM_TAG_RQU_COMMAND );
	pcrReadIncoming->paramSize = grub_swap_bytes32( sizeof( *pcrReadIncoming ) );
	pcrReadIncoming->ordinal = grub_swap_bytes32_compile_time( TPM_ORD_PcrRead );
	pcrReadIncoming->pcrIndex = grub_swap_bytes32( (grub_uint32_t) index);

	passThroughOutput = grub_zalloc( outputlen );
	if( ! passThroughOutput ) {
		grub_free( passThroughInput );
        grub_fatal( "readpcr: memory allocation failed" );
	}

	grub_TPM_int1A_passThroughToTPM( passThroughInput, passThroughOutput );
	grub_free( passThroughInput );

	pcrReadOutgoing = (void *)passThroughOutput->TPMOperandOut;
	grub_uint32_t tpm_PCRreadReturnCode = grub_swap_bytes32( pcrReadOutgoing->returnCode );

	if( tpm_PCRreadReturnCode != TPM_SUCCESS ) {
		grub_free( passThroughOutput );

		if( tpm_PCRreadReturnCode == TPM_BADINDEX ) {
            grub_fatal( "readpcr: bad pcr index" );
		}

        grub_fatal( "readpcr: tpm_PCRreadReturnCode: %u", tpm_PCRreadReturnCode );
	}

	grub_memcpy( result, pcrReadOutgoing->pcr_value, SHA1_DIGEST_SIZE );
	grub_free( passThroughOutput );
}
示例#2
0
static void
test32 (grub_uint32_t a)
{
  grub_uint32_t b, c;
  grub_uint8_t *ap, *bp;
  int i;
  b = grub_swap_bytes32 (a);
  c = grub_swap_bytes32 (b);
  grub_test_assert (a == c, "bswap not idempotent: 0x%llx, 0x%llx, 0x%llx",
		    (long long) a, (long long) b, (long long) c);
  ap = (grub_uint8_t *) &a;
  bp = (grub_uint8_t *) &b;
  for (i = 0; i < 4; i++)
    {
      grub_test_assert (ap[i] == bp[3 - i],
			"bswap bytes wrong: 0x%llx, 0x%llx",
			(long long) a, (long long) b);
    }
}
示例#3
0
文件: gpt.c 项目: crawford/grub
static void
grub_gpt_lecrc32 (grub_uint32_t *crc, const void *data, grub_size_t len)
{
  grub_uint32_t crc32_val;

  grub_crypto_hash (GRUB_MD_CRC32, &crc32_val, data, len);

  /* GRUB_MD_CRC32 always uses big endian, gpt is always little.  */
  *crc = grub_swap_bytes32 (crc32_val);
}