• 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_GCRYPT_H
7 #define ESYS_CRYPTO_GCRYPT_H
8 
9 #include <stddef.h>
10 #include "tss2_tpm2_types.h"
11 #include "tss2-sys/sysapi_util.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef struct _IESYS_CRYPTO_CONTEXT IESYS_CRYPTO_CONTEXT_BLOB;
18 
19 TSS2_RC iesys_cryptogcry_hash_start(
20     IESYS_CRYPTO_CONTEXT_BLOB **context,
21     TPM2_ALG_ID hashAlg);
22 
23 TSS2_RC iesys_cryptogcry_hash_update(
24     IESYS_CRYPTO_CONTEXT_BLOB *context,
25     const uint8_t *buffer, size_t size);
26 
27 TSS2_RC iesys_cryptogcry_hash_update2b(
28     IESYS_CRYPTO_CONTEXT_BLOB *context,
29     TPM2B *b);
30 
31 TSS2_RC iesys_cryptogcry_hash_finish(
32     IESYS_CRYPTO_CONTEXT_BLOB **context,
33     uint8_t *buffer,
34     size_t *size);
35 
36 TSS2_RC iesys_cryptogcry_hash_finish2b(
37     IESYS_CRYPTO_CONTEXT_BLOB **context,
38     TPM2B *b);
39 
40 void iesys_cryptogcry_hash_abort(IESYS_CRYPTO_CONTEXT_BLOB **context);
41 
42 #define iesys_crypto_hash_start iesys_cryptogcry_hash_start
43 #define iesys_crypto_hash_update iesys_cryptogcry_hash_update
44 #define iesys_crypto_hash_update2b iesys_cryptogcry_hash_update2b
45 #define iesys_crypto_hash_finish iesys_cryptogcry_hash_finish
46 #define iesys_crypto_hash_finish2b iesys_cryptogcry_hash_finish2b
47 #define iesys_crypto_hash_abort iesys_cryptogcry_hash_abort
48 
49 TSS2_RC iesys_cryptogcry_hmac_start(
50     IESYS_CRYPTO_CONTEXT_BLOB **context,
51     TPM2_ALG_ID hmacAlg,
52     const uint8_t *key,
53     size_t size);
54 
55 TSS2_RC iesys_cryptogcry_hmac_start2b(
56     IESYS_CRYPTO_CONTEXT_BLOB **context,
57     TPM2_ALG_ID hmacAlg,
58     TPM2B *b);
59 
60 TSS2_RC iesys_cryptogcry_hmac_update(
61     IESYS_CRYPTO_CONTEXT_BLOB *context,
62     const uint8_t *buffer,
63     size_t size);
64 
65 TSS2_RC iesys_cryptogcry_hmac_update2b(
66     IESYS_CRYPTO_CONTEXT_BLOB *context,
67     TPM2B *b);
68 
69 TSS2_RC iesys_cryptogcry_hmac_finish(
70     IESYS_CRYPTO_CONTEXT_BLOB **context,
71     uint8_t *buffer,
72     size_t *size);
73 
74 TSS2_RC iesys_cryptogcry_hmac_finish2b(
75     IESYS_CRYPTO_CONTEXT_BLOB **context,
76     TPM2B *b);
77 
78 void iesys_cryptogcry_hmac_abort(IESYS_CRYPTO_CONTEXT_BLOB **context);
79 
80 #define iesys_crypto_hmac_start iesys_cryptogcry_hmac_start
81 #define iesys_crypto_hmac_start2b iesys_cryptogcry_hmac_start2b
82 #define iesys_crypto_hmac_update iesys_cryptogcry_hmac_update
83 #define iesys_crypto_hmac_update2b iesys_cryptogcry_hmac_update2b
84 #define iesys_crypto_hmac_finish iesys_cryptogcry_hmac_finish
85 #define iesys_crypto_hmac_finish2b iesys_cryptogcry_hmac_finish2b
86 #define iesys_crypto_hmac_abort iesys_cryptogcry_hmac_abort
87 
88 TSS2_RC iesys_cryptogcry_random2b(TPM2B_NONCE *nonce, size_t num_bytes);
89 #define iesys_crypto_random2b iesys_cryptogcry_random2b
90 
91 TSS2_RC iesys_cryptogcry_pk_encrypt(
92     TPM2B_PUBLIC *key,
93     size_t in_size,
94     BYTE *in_buffer,
95     size_t max_out_size,
96     BYTE *out_buffer,
97     size_t *out_size,
98     const char *label);
99 
100 #define iesys_crypto_pk_encrypt iesys_cryptogcry_pk_encrypt
101 
102 TSS2_RC iesys_cryptogcry_sym_aes_encrypt(
103     uint8_t *key,
104     TPM2_ALG_ID tpm_sym_alg,
105     TPMI_AES_KEY_BITS key_bits,
106     TPM2_ALG_ID tpm_mode,
107     size_t blk_len,
108     uint8_t *dst,
109     size_t dst_size,
110     uint8_t *iv);
111 
112 TSS2_RC iesys_cryptogcry_sym_aes_decrypt(
113     uint8_t *key,
114     TPM2_ALG_ID tpm_sym_alg,
115     TPMI_AES_KEY_BITS key_bits,
116     TPM2_ALG_ID tpm_mode,
117     size_t blk_len,
118     uint8_t *dst,
119     size_t dst_size,
120     uint8_t *iv);
121 
122 TSS2_RC iesys_cryptogcry_get_ecdh_point(
123     TPM2B_PUBLIC *key,
124     size_t max_out_size,
125     TPM2B_ECC_PARAMETER *Z,
126     TPMS_ECC_POINT *Q,
127     BYTE * out_buffer,
128     size_t * out_size);
129 
130 #define iesys_crypto_get_ecdh_point iesys_cryptogcry_get_ecdh_point
131 #define iesys_crypto_sym_aes_encrypt iesys_cryptogcry_sym_aes_encrypt
132 #define iesys_crypto_sym_aes_decrypt iesys_cryptogcry_sym_aes_decrypt
133 
134 TSS2_RC iesys_cryptogcry_init();
135 
136 #define iesys_crypto_init iesys_cryptogcry_init
137 
138 #endif /* ESYS_CRYPTO_GCRYPT_H */
139 
140 #ifdef __cplusplus
141 } /* extern "C" */
142 #endif
143