Upgrade Duplicate utility to the latest tss
[aaf/sshsm.git] / tpm-util / duplicate / include / crypto_aux.h
1 /*
2  * Copyright 2018 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16 // Author: Arun Kumar Sekar
17
18 #ifndef     CRYPTO_AUX
19 #define     CRYPTO_AUX
20
21 #include <string.h>
22 #include <tss2/tss2_sys.h>
23 #include <tss2/tss2_tcti_mssim.h>
24 #include <tss2/tss2_tpm2_types.h>
25 #include <tss2/tpm2b.h>
26 #include <openssl/rsa.h>
27 #include <openssl/aes.h>
28 #include <openssl/sha.h>
29 #include <openssl/hmac.h>
30 #include <openssl/evp.h>
31
32 typedef BYTE* PBYTE;
33
34 int RSA_OAEP_Enc(TPM2B_PUBLIC_KEY_RSA *plain, // plain text to encrypt
35                                                                                         //Size of plain (0 <= pl <= kl - (2 * hashLen + 2)
36                                 TPM2B_PUBLIC_KEY_RSA *cipher,           // must be same size as key in bytes
37                                 TPM2B_PUBLIC_KEY_RSA *key,                      // Key in big endian byte array
38                                 TPM2B_DATA *encoding_params // Null terminated string like
39                                                                                                 // ((unsigned char*)"DUPLICATE")
40                                                                                                 // length of encoding parameter includes \0
41                                                                                                 // (10 in DUPLICATE case..)
42                                 );
43
44 void AES_128_CFB_enc_dec(
45                 TPM2B *in,
46                 TPM2B *out,
47                 const TPM2B *const key,
48                 const TPM2B *const ivIn,
49                 TPM2B *ivOut,
50                 const TPMI_YES_NO enc);
51
52
53
54 TPM2_RC KDFa( TPMI_ALG_HASH hashAlg, TPM2B *key, char *label,
55     TPM2B *contextU, TPM2B *contextV, UINT16 bits, TPM2B_MAX_BUFFER  *resultKey );
56
57 UINT32 OpenSslHmac( TPMI_ALG_HASH hashAlg, TPM2B *key,TPM2B **bufferList, TPM2B_DIGEST *result );
58
59 void print_buff(char * data, int len, const PBYTE buff);
60
61 #endif
62