tpm2-tss  3.2.1
TPM Software stack 2.0 TCG spec compliant implementation
esys_crypto_ossl.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_OSSL_H
7 #define ESYS_CRYPTO_OSSL_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 #define OSSL_FREE(S,TYPE) if((S) != NULL) {TYPE##_free((void*) (S)); (S)=NULL;}
18 
19 TSS2_RC iesys_cryptossl_hash_start(
20  ESYS_CRYPTO_CONTEXT_BLOB **context,
21  TPM2_ALG_ID hashAlg,
22  void *userdata);
23 
24 TSS2_RC iesys_cryptossl_hash_update(
25  ESYS_CRYPTO_CONTEXT_BLOB *context,
26  const uint8_t *buffer, size_t size,
27  void *userdata);
28 
29 TSS2_RC iesys_cryptossl_hash_finish(
30  ESYS_CRYPTO_CONTEXT_BLOB **context,
31  uint8_t *buffer,
32  size_t *size,
33  void *userdata);
34 
35 void iesys_cryptossl_hash_abort(
36  ESYS_CRYPTO_CONTEXT_BLOB **context,
37  void *userdata);
38 
39 #define _iesys_crypto_rsa_pk_encrypt iesys_cryptossl_pk_encrypt
40 #define _iesys_crypto_hash_start iesys_cryptossl_hash_start
41 #define _iesys_crypto_hash_update iesys_cryptossl_hash_update
42 #define _iesys_crypto_hash_finish iesys_cryptossl_hash_finish
43 #define _iesys_crypto_hash_abort iesys_cryptossl_hash_abort
44 
45 TSS2_RC iesys_cryptossl_hmac_start(
46  ESYS_CRYPTO_CONTEXT_BLOB **context,
47  TPM2_ALG_ID hmacAlg,
48  const uint8_t *key,
49  size_t size,
50  void *userdata);
51 
52 TSS2_RC iesys_cryptossl_hmac_update(
53  ESYS_CRYPTO_CONTEXT_BLOB *context,
54  const uint8_t *buffer,
55  size_t size,
56  void *userdata);
57 
58 TSS2_RC iesys_cryptossl_hmac_finish(
59  ESYS_CRYPTO_CONTEXT_BLOB **context,
60  uint8_t *buffer,
61  size_t *size,
62  void *userdata);
63 
64 void iesys_cryptossl_hmac_abort(
65  ESYS_CRYPTO_CONTEXT_BLOB **context,
66  void *userdata);
67 
68 #define _iesys_crypto_hmac_start iesys_cryptossl_hmac_start
69 #define _iesys_crypto_hmac_start2b iesys_cryptossl_hmac_start2b
70 #define _iesys_crypto_hmac_update iesys_cryptossl_hmac_update
71 #define _iesys_crypto_hmac_update2b iesys_cryptossl_hmac_update2b
72 #define _iesys_crypto_hmac_finish iesys_cryptossl_hmac_finish
73 #define _iesys_crypto_hmac_finish2b iesys_cryptossl_hmac_finish2b
74 #define _iesys_crypto_hmac_abort iesys_cryptossl_hmac_abort
75 
76 TSS2_RC iesys_cryptossl_random2b(
77  TPM2B_NONCE *nonce,
78  size_t num_bytes,
79  void *userdata);
80 
81 TSS2_RC iesys_cryptossl_pk_encrypt(
82  TPM2B_PUBLIC *key,
83  size_t in_size,
84  BYTE *in_buffer,
85  size_t max_out_size,
86  BYTE *out_buffer,
87  size_t *out_size,
88  const char *label,
89  void *userdata);
90 
91 
92 TSS2_RC iesys_cryptossl_sym_aes_encrypt(
93  uint8_t *key,
94  TPM2_ALG_ID tpm_sym_alg,
95  TPMI_AES_KEY_BITS key_bits,
96  TPM2_ALG_ID tpm_mode,
97  uint8_t *dst,
98  size_t dst_size,
99  uint8_t *iv,
100  void *userdata);
101 
102 TSS2_RC iesys_cryptossl_sym_aes_decrypt(
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  uint8_t *dst,
108  size_t dst_size,
109  uint8_t *iv,
110  void *userdata);
111 
112 #if HAVE_EVP_SM4_CFB && !defined(OPENSSL_NO_SM4)
113 TSS2_RC iesys_cryptossl_sym_sm4_encrypt(
114  uint8_t *key,
115  TPM2_ALG_ID tpm_sym_alg,
116  TPMI_SM4_KEY_BITS key_bits,
117  TPM2_ALG_ID tpm_mode,
118  uint8_t *dst,
119  size_t dst_size,
120  uint8_t *iv,
121  void *userdata);
122 
123 TSS2_RC iesys_cryptossl_sym_sm4_decrypt(
124  uint8_t *key,
125  TPM2_ALG_ID tpm_sym_alg,
126  TPMI_SM4_KEY_BITS key_bits,
127  TPM2_ALG_ID tpm_mode,
128  uint8_t *dst,
129  size_t dst_size,
130  uint8_t *iv,
131  void *userdata);
132 #endif
133 
134 TSS2_RC iesys_cryptossl_get_ecdh_point(
135  TPM2B_PUBLIC *key,
136  size_t max_out_size,
137  TPM2B_ECC_PARAMETER *Z,
138  TPMS_ECC_POINT *Q,
139  BYTE * out_buffer,
140  size_t * out_size,
141  void *userdata);
142 
143 #define _iesys_crypto_get_random2b iesys_cryptossl_random2b
144 #define _iesys_crypto_get_ecdh_point iesys_cryptossl_get_ecdh_point
145 #define _iesys_crypto_aes_encrypt iesys_cryptossl_sym_aes_encrypt
146 #define _iesys_crypto_aes_decrypt iesys_cryptossl_sym_aes_decrypt
147 #if HAVE_EVP_SM4_CFB && !defined(OPENSSL_NO_SM4)
148 #define _iesys_crypto_sm4_encrypt iesys_cryptossl_sym_sm4_encrypt
149 #define _iesys_crypto_sm4_decrypt iesys_cryptossl_sym_sm4_decrypt
150 #else
151 #define _iesys_crypto_sm4_encrypt NULL
152 #define _iesys_crypto_sm4_decrypt NULL
153 #endif
154 
155 TSS2_RC iesys_cryptossl_init(void *userdata);
156 
157 #define _iesys_crypto_init iesys_cryptossl_init
158 
159 #ifdef __cplusplus
160 } /* extern "C" */
161 #endif
162 
163 #endif /* ESYS_CRYPTO_OSSL_H */
Definition: esys_crypto_mbed.c:34