tpm2-tss 3.2.1
TPM Software stack 2.0 TCG spec compliant implementation
esys_crypto.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2/*******************************************************************************
3 * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG
4 * All rights reserved.
5 ******************************************************************************/
6#ifndef ESYS_CRYPTO_H
7#define ESYS_CRYPTO_H
8
9#include <stddef.h>
10#include "tss2_tpm2_types.h"
11#include "tss2-sys/sysapi_util.h"
12#if defined(OSSL)
13#include "esys_crypto_ossl.h"
14#elif defined(MBED)
15#include "esys_crypto_mbed.h"
16#else
17#error "No crypto backend defined"
18#endif
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define AES_BLOCK_SIZE_IN_BYTES 16
25
26TSS2_RC iesys_crypto_hash_get_digest_size(TPM2_ALG_ID hashAlg, size_t *size);
27
28TSS2_RC iesys_crypto_pHash(
29 TPM2_ALG_ID alg,
30 const uint8_t rcBuffer[4],
31 const uint8_t ccBuffer[4],
32 const TPM2B_NAME *name1,
33 const TPM2B_NAME *name2,
34 const TPM2B_NAME *name3,
35 const uint8_t *pBuffer,
36 size_t pBuffer_size,
37 uint8_t *pHash,
38 size_t *pHash_size);
39
40#define iesys_crypto_cpHash(alg, ccBuffer, name1, name2, name3, \
41 cpBuffer, cpBuffer_size, cpHash, cpHash_size) \
42 iesys_crypto_pHash(alg, NULL, ccBuffer, name1, name2, name3, cpBuffer, \
43 cpBuffer_size, cpHash, cpHash_size)
44#define iesys_crypto_rpHash(alg, rcBuffer, ccBuffer, rpBuffer, rpBuffer_size, \
45 rpHash, rpHash_size) \
46 iesys_crypto_pHash(alg, rcBuffer, ccBuffer, NULL, NULL, NULL, rpBuffer, \
47 rpBuffer_size, rpHash, rpHash_size)
48
49
51 TPM2_ALG_ID alg,
52 uint8_t *hmacKey,
53 size_t hmacKeySize,
54 const uint8_t *pHash,
55 size_t pHash_size,
56 const TPM2B_NONCE *nonceNewer,
57 const TPM2B_NONCE *nonceOlder,
58 const TPM2B_NONCE *nonceDecrypt,
59 const TPM2B_NONCE *nonceEncrypt,
60 TPMA_SESSION sessionAttributes,
61 TPM2B_AUTH *hmac);
62
64 TPM2_ALG_ID alg,
65 uint8_t *hmacKey,
66 size_t hmacKeySize,
67 uint32_t counter,
68 const char *label,
69 TPM2B_NONCE *contextU,
70 TPM2B_NONCE *contextV,
71 uint32_t bitlength,
72 uint8_t *hmac,
73 size_t *hmacSize);
74
75TSS2_RC iesys_crypto_KDFa(
76 TPM2_ALG_ID hashAlg,
77 uint8_t *hmacKey,
78 size_t hmacKeySize,
79 const char *label,
80 TPM2B_NONCE *contextU,
81 TPM2B_NONCE *contextV,
82 uint32_t bitLength,
83 uint32_t *counterInOut,
84 BYTE *outKey,
85 BOOL use_digest_size);
86
88 TPM2_ALG_ID hash_alg,
89 uint8_t *key,
90 size_t key_size,
91 TPM2B_NONCE * contextU,
92 TPM2B_NONCE * contextV,
93 BYTE *data,
94 size_t data_size);
95
96TSS2_RC iesys_crypto_KDFe(
97 TPM2_ALG_ID hashAlg,
98 TPM2B_ECC_PARAMETER *Z,
99 const char *label,
100 TPM2B_ECC_PARAMETER *partyUInfo,
101 TPM2B_ECC_PARAMETER *partyVInfo,
102 UINT32 bit_size,
103 BYTE *key);
104
105TSS2_RC iesys_initialize_crypto();
106
107#ifdef __cplusplus
108} /* extern "C" */
109#endif
110
111#endif /* ESYS_CRYPTO_H */
TSS2_RC iesys_crypto_KDFa(TPM2_ALG_ID hashAlg, uint8_t *hmacKey, size_t hmacKeySize, const char *label, TPM2B_NONCE *contextU, TPM2B_NONCE *contextV, uint32_t bitLength, uint32_t *counterInOut, BYTE *outKey, BOOL use_digest_size)
Definition: esys_crypto.c:326
TSS2_RC iesys_crypto_KDFe(TPM2_ALG_ID hashAlg, TPM2B_ECC_PARAMETER *Z, const char *label, TPM2B_ECC_PARAMETER *partyUInfo, TPM2B_ECC_PARAMETER *partyVInfo, UINT32 bit_size, BYTE *key)
Definition: esys_crypto.c:392
TSS2_RC iesys_crypto_KDFaHmac(TPM2_ALG_ID alg, uint8_t *hmacKey, size_t hmacKeySize, uint32_t counter, const char *label, TPM2B_NONCE *contextU, TPM2B_NONCE *contextV, uint32_t bitlength, uint8_t *hmac, size_t *hmacSize)
Definition: esys_crypto.c:245
TSS2_RC iesys_crypto_pHash(TPM2_ALG_ID alg, const uint8_t rcBuffer[4], const uint8_t ccBuffer[4], const TPM2B_NAME *name1, const TPM2B_NAME *name2, const TPM2B_NAME *name3, const uint8_t *pBuffer, size_t pBuffer_size, uint8_t *pHash, size_t *pHash_size)
Definition: esys_crypto.c:83
TSS2_RC iesys_xor_parameter_obfuscation(TPM2_ALG_ID hash_alg, uint8_t *key, size_t key_size, TPM2B_NONCE *contextU, TPM2B_NONCE *contextV, BYTE *data, size_t data_size)
Definition: esys_crypto.c:487
TSS2_RC iesys_crypto_authHmac(TPM2_ALG_ID alg, uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *pHash, size_t pHash_size, const TPM2B_NONCE *nonceNewer, const TPM2B_NONCE *nonceOlder, const TPM2B_NONCE *nonceDecrypt, const TPM2B_NONCE *nonceEncrypt, TPMA_SESSION sessionAttributes, TPM2B_AUTH *hmac)
Definition: esys_crypto.c:161
TSS2_RC iesys_crypto_hash_get_digest_size(TPM2_ALG_ID hashAlg, size_t *size)
Definition: esys_crypto.c:32