272cc39ecd93430e6452497980aefaea51120dae
[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 <sapi/tpm20.h>
23 #include <openssl/rsa.h>
24 #include <openssl/aes.h>
25 #include <openssl/rsa.h>
26 #include <openssl/sha.h>
27 #include <openssl/hmac.h>
28 #include <openssl/evp.h>
29
30 typedef BYTE* PBYTE;
31
32 int RSA_OAEP_Enc(TPM2B_PUBLIC_KEY_RSA *plain, // plain text to encrypt
33                                                                                         //Size of plain (0 <= pl <= kl - (2 * hashLen + 2)
34                                 TPM2B_PUBLIC_KEY_RSA *cipher,           // must be same size as key in bytes
35                                 TPM2B_PUBLIC_KEY_RSA *key,                      // Key in big endian byte array
36                                 TPM2B_DATA *encoding_params // Null terminated string like
37                                                                                                 // ((unsigned char*)"DUPLICATE")
38                                                                                                 // length of encoding parameter includes \0
39                                                                                                 // (10 in DUPLICATE case..)
40                                 );
41
42 void AES_128_CFB_enc_dec(
43                 TPM2B *in,
44                 TPM2B *out,
45                 const TPM2B *const key,
46                 const TPM2B *const ivIn,
47                 TPM2B *ivOut,
48                 const TPMI_YES_NO enc);
49
50
51
52 TPM_RC KDFa( TPMI_ALG_HASH hashAlg, TPM2B *key, char *label,
53     TPM2B *contextU, TPM2B *contextV, UINT16 bits, TPM2B_MAX_BUFFER  *resultKey );
54
55 UINT32 OpenSslHmac( TPMI_ALG_HASH hashAlg, TPM2B *key,TPM2B **bufferList, TPM2B_DIGEST *result );
56
57 void print_buff(char * data, int len, const PBYTE buff);
58
59 #endif
60