1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /******************************************************************************* 3 * Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG 4 * All rights reserved. 5 ******************************************************************************/ 6 #ifndef FAPI_CRYPTO_H 7 #define FAPI_CRYPTO_H 8 9 #include "fapi_int.h" 10 11 TSS2_RC 12 ifapi_get_profile_sig_scheme( 13 const IFAPI_PROFILE *profile, 14 const TPMT_PUBLIC *tpmPublic, 15 TPMT_SIG_SCHEME *signatureScheme); 16 17 TSS2_RC 18 ifapi_der_sig_to_tpm( 19 const TPMT_PUBLIC *tpmPublic, 20 const unsigned char *signature, 21 size_t signatureSize, 22 TPMI_ALG_HASH hashAlgorithm, 23 TPMT_SIGNATURE *tpmSignature); 24 25 TSS2_RC 26 ifapi_tpm_ecc_sig_to_der( 27 const TPMT_SIGNATURE *tpmSignature, 28 uint8_t **signature, 29 size_t *signatureSize); 30 31 TSS2_RC 32 ifapi_pub_pem_key_from_tpm( 33 const TPM2B_PUBLIC *tpmPublicKey, 34 char **pemKey, 35 int *pemKeySize); 36 37 TSS2_RC 38 ifapi_verify_signature( 39 const IFAPI_OBJECT *keyObject, 40 const uint8_t *signature, 41 size_t signatureSize, 42 const uint8_t *digest, 43 size_t digestSize); 44 45 TSS2_RC 46 ifapi_verify_signature_quote( 47 const IFAPI_OBJECT *keyObject, 48 const uint8_t *signature, 49 size_t signatureSize, 50 const uint8_t *digest, 51 size_t digestSize, 52 const TPMT_SIG_SCHEME *signatureScheme); 53 54 55 typedef struct _IFAPI_CRYPTO_CONTEXT IFAPI_CRYPTO_CONTEXT_BLOB; 56 57 TSS2_RC 58 ifapi_crypto_hash_start( 59 IFAPI_CRYPTO_CONTEXT_BLOB **context, 60 TPM2_ALG_ID hashAlgorithm); 61 62 TSS2_RC 63 ifapi_crypto_hash_update( 64 IFAPI_CRYPTO_CONTEXT_BLOB *context, 65 const uint8_t *buffer, 66 size_t size); 67 68 TSS2_RC 69 ifapi_crypto_hash_finish( 70 IFAPI_CRYPTO_CONTEXT_BLOB **context, 71 uint8_t *digest, 72 size_t *digestSize); 73 74 void 75 ifapi_crypto_hash_abort( 76 IFAPI_CRYPTO_CONTEXT_BLOB **context); 77 78 TSS2_RC 79 ifapi_cert_to_pem( 80 const uint8_t *certBuffer, 81 size_t certBufferSize, 82 char **pemCert, 83 TPM2_ALG_ID *certAlgorithmId, 84 TPM2B_PUBLIC *tpmPublic); 85 86 size_t 87 ifapi_hash_get_digest_size( 88 TPM2_ALG_ID hashAlgorithm); 89 90 TSS2_RC 91 ifapi_get_tpm2b_public_from_pem( 92 const char *pemKey, 93 TPM2B_PUBLIC *tpmPublic); 94 95 TSS2_RC 96 ifapi_get_hash_alg_for_size( 97 uint16_t size, 98 TPMI_ALG_HASH *hashAlgorithm); 99 100 TSS2_RC 101 ifapi_get_public_from_pem_cert( 102 const char* pem_cert, 103 TPM2B_PUBLIC *tpm_public); 104 105 TSS2_RC 106 ifapi_initialize_sign_public( 107 TPM2_ALG_ID signatureAlgorithm, 108 TPM2B_PUBLIC *template); 109 110 TPM2_ALG_ID 111 ifapi_get_signature_algorithm_from_pem( 112 const char *pemKey); 113 114 TSS2_RC 115 ifapi_verify_ek_cert( 116 char* root_cert_pem, 117 char* intermed_cert_pem, 118 char* ek_cert_pem); 119 120 TSS2_RC 121 ifapi_get_tpm_key_fingerprint( 122 const TPM2B_PUBLIC *tpmPublicKey, 123 TPMI_ALG_HASH hashAlg, 124 TPM2B_DIGEST *fingerprint); 125 126 #endif /* FAPI_CRYPTO_H */ 127