How to properly open handle to TPMs RNG in C?

0

I'm trying to use TPM to generate random numbers. This is purely to learn to use TPM.

The issue i encountered, is i can't obtain the handle. When i use MS_PLATFORM_CRYPTO_PROVIDER, the handle is not created with STATUS_NOT_FOUND message. It works with default NULL.

How do i properly set up the handle to use TPM as RNG?

#include <Windows.h>
#include <bcrypt.h>
#pragma comment(lib, "bcrypt.lib")
...
BCRYPT_ALG_HANDLE *handle;
NTSTATUS handle_status = BCryptOpenAlgorithmProvider(
    &handle,
    BCRYPT_RNG_ALGORITHM,
    MS_PLATFORM_CRYPTO_PROVIDER,
    0
);
// Status code 0xC0000225 STATUS_NOT_FOUND
unsigned char *buffer = calloc(BIT_SIZE/sizeof(char), sizeof(char));
NTSTATUS gen_status = BCryptGenRandom(
    handle,
    buffer,
    BIT_SIZE / sizeof(char),
    0
);
...

I have an Intel TPM with 2.0 Specification Version. Status as ready.

c
windows
winapi
random
tpm
asked on Stack Overflow Oct 4, 2019 by Zerg Overmind

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0