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 typedef struct _IESYS_CRYPTO_CONTEXT IESYS_CRYPTO_CONTEXT_BLOB; 20 21 TSS2_RC iesys_cryptossl_hash_start( 22 IESYS_CRYPTO_CONTEXT_BLOB **context, 23 TPM2_ALG_ID hashAlg); 24 25 TSS2_RC iesys_cryptossl_hash_update( 26 IESYS_CRYPTO_CONTEXT_BLOB *context, 27 const uint8_t *buffer, size_t size); 28 29 TSS2_RC iesys_cryptossl_hash_update2b( 30 IESYS_CRYPTO_CONTEXT_BLOB *context, 31 TPM2B *b); 32 33 TSS2_RC iesys_cryptossl_hash_finish( 34 IESYS_CRYPTO_CONTEXT_BLOB **context, 35 uint8_t *buffer, 36 size_t *size); 37 38 TSS2_RC iesys_cryptossl_hash_finish2b( 39 IESYS_CRYPTO_CONTEXT_BLOB **context, 40 TPM2B *b); 41 42 void iesys_cryptossl_hash_abort(IESYS_CRYPTO_CONTEXT_BLOB **context); 43 44 #define iesys_crypto_pk_encrypt iesys_cryptossl_pk_encrypt 45 #define iesys_crypto_hash_start iesys_cryptossl_hash_start 46 #define iesys_crypto_hash_update iesys_cryptossl_hash_update 47 #define iesys_crypto_hash_update2b iesys_cryptossl_hash_update2b 48 #define iesys_crypto_hash_finish iesys_cryptossl_hash_finish 49 #define iesys_crypto_hash_finish2b iesys_cryptossl_hash_finish2b 50 #define iesys_crypto_hash_abort iesys_cryptossl_hash_abort 51 52 TSS2_RC iesys_cryptossl_hmac_start( 53 IESYS_CRYPTO_CONTEXT_BLOB **context, 54 TPM2_ALG_ID hmacAlg, 55 const uint8_t *key, 56 size_t size); 57 58 TSS2_RC iesys_cryptossl_hmac_start2b( 59 IESYS_CRYPTO_CONTEXT_BLOB **context, 60 TPM2_ALG_ID hmacAlg, 61 TPM2B *b); 62 63 TSS2_RC iesys_cryptossl_hmac_update( 64 IESYS_CRYPTO_CONTEXT_BLOB *context, 65 const uint8_t *buffer, 66 size_t size); 67 68 TSS2_RC iesys_cryptossl_hmac_update2b( 69 IESYS_CRYPTO_CONTEXT_BLOB *context, 70 TPM2B *b); 71 72 TSS2_RC iesys_cryptossl_hmac_finish( 73 IESYS_CRYPTO_CONTEXT_BLOB **context, 74 uint8_t *buffer, 75 size_t *size); 76 77 TSS2_RC iesys_cryptossl_hmac_finish2b( 78 IESYS_CRYPTO_CONTEXT_BLOB **context, 79 TPM2B *b); 80 81 void iesys_cryptossl_hmac_abort(IESYS_CRYPTO_CONTEXT_BLOB **context); 82 83 #define iesys_crypto_hmac_start iesys_cryptossl_hmac_start 84 #define iesys_crypto_hmac_start2b iesys_cryptossl_hmac_start2b 85 #define iesys_crypto_hmac_update iesys_cryptossl_hmac_update 86 #define iesys_crypto_hmac_update2b iesys_cryptossl_hmac_update2b 87 #define iesys_crypto_hmac_finish iesys_cryptossl_hmac_finish 88 #define iesys_crypto_hmac_finish2b iesys_cryptossl_hmac_finish2b 89 #define iesys_crypto_hmac_abort iesys_cryptossl_hmac_abort 90 91 TSS2_RC iesys_cryptossl_random2b(TPM2B_NONCE *nonce, size_t num_bytes); 92 93 TSS2_RC iesys_cryptossl_pk_encrypt( 94 TPM2B_PUBLIC *key, 95 size_t in_size, 96 BYTE *in_buffer, 97 size_t max_out_size, 98 BYTE *out_buffer, 99 size_t *out_size, 100 const char *label); 101 102 103 TSS2_RC iesys_cryptossl_sym_aes_encrypt( 104 uint8_t *key, 105 TPM2_ALG_ID tpm_sym_alg, 106 TPMI_AES_KEY_BITS key_bits, 107 TPM2_ALG_ID tpm_mode, 108 size_t blk_len, 109 uint8_t *dst, 110 size_t dst_size, 111 uint8_t *iv); 112 113 TSS2_RC iesys_cryptossl_sym_aes_decrypt( 114 uint8_t *key, 115 TPM2_ALG_ID tpm_sym_alg, 116 TPMI_AES_KEY_BITS key_bits, 117 TPM2_ALG_ID tpm_mode, 118 size_t blk_len, 119 uint8_t *dst, 120 size_t dst_size, 121 uint8_t *iv); 122 123 TSS2_RC iesys_cryptossl_get_ecdh_point( 124 TPM2B_PUBLIC *key, 125 size_t max_out_size, 126 TPM2B_ECC_PARAMETER *Z, 127 TPMS_ECC_POINT *Q, 128 BYTE * out_buffer, 129 size_t * out_size); 130 131 #define iesys_crypto_random2b iesys_cryptossl_random2b 132 #define iesys_crypto_get_ecdh_point iesys_cryptossl_get_ecdh_point 133 #define iesys_crypto_sym_aes_encrypt iesys_cryptossl_sym_aes_encrypt 134 #define iesys_crypto_sym_aes_decrypt iesys_cryptossl_sym_aes_decrypt 135 136 TSS2_RC iesys_cryptossl_init(); 137 138 #define iesys_crypto_init iesys_cryptossl_init 139 140 #ifdef __cplusplus 141 } /* extern "C" */ 142 #endif 143 144 #endif /* ESYS_CRYPTO_OSSL_H */ 145