• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef OSSL
13 #include "esys_crypto_ossl.h"
14 #elif defined (BSSL)
15 #include "esys_crypto_bssl.h"
16 #else
17 #include "esys_crypto_gcrypt.h"
18 #endif
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define AES_BLOCK_SIZE_IN_BYTES 16
25 
26 TSS2_RC iesys_crypto_hash_get_digest_size(TPM2_ALG_ID hashAlg, size_t *size);
27 
28 TSS2_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 
50 TSS2_RC iesys_crypto_authHmac(
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 
63 TSS2_RC iesys_crypto_KDFaHmac(
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 
75 TSS2_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 
87 TSS2_RC iesys_xor_parameter_obfuscation(
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 
96 TSS2_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 
105 TSS2_RC iesys_initialize_crypto();
106 
107 #ifdef __cplusplus
108 } /* extern "C" */
109 #endif
110 
111 #endif /* ESYS_CRYPTO_H */
112