Debian Codegraph @

simulator/ms-tpm-20-ref/TPMCmd/tpm/include/Ossl/TpmToOsslSym.h

raw
1 /* Microsoft Reference Implementation for TPM 2.0
2 *
3 * The copyright in this software is being made available under the BSD License,
4 * included below. This software may be subject to other third party and
5 * contributor rights, including patent rights, and no such rights are granted
6 * under this license.
7 *
8 * Copyright (c) Microsoft Corporation
9 *
10 * All rights reserved.
11 *
12 * BSD License
13 *
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 *
17 * Redistributions of source code must retain the above copyright notice, this list
18 * of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright notice, this
21 * list of conditions and the following disclaimer in the documentation and/or
22 * other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 //** Introduction
36 //
37 // This header file is used to 'splice' the OpenSSL library into the TPM code.
38 //
39 // The support required of a library are a hash module, a block cipher module and
40 // portions of a big number library.
41
42 #ifndef SYM_LIB_DEFINED
43 #define SYM_LIB_DEFINED
44
45 #define SYM_LIB_OSSL
46
47 #include <openssl/aes.h>
48 #include <openssl/des.h>
49 #include <openssl/bn.h>
50 #include <openssl/ossl_typ.h>
51
52 //***************************************************************
53 //** Links to the OpenSSL AES code
54 //***************************************************************
55
56 #if ALG_SM4
57 #error "SM4 is not available"
58 #endif
59
60 #if ALG_CAMELLIA
61 #error "Camellia is not available"
62 #endif
63
64 // Define the order of parameters to the library functions that do block encryption
65 // and decryption.
66 typedef void(*TpmCryptSetSymKeyCall_t)(
67 const BYTE *in,
68 BYTE *out,
69 void *keySchedule
70 );
71
72 // The Crypt functions that call the block encryption function use the parameters
73 // in the order:
74 // 1) keySchedule
75 // 2) in buffer
76 // 3) out buffer
77 // Since open SSL uses the order in encryptoCall_t above, need to swizzle the
78 // values to the order required by the library.
79 #define SWIZZLE(keySchedule, in, out) \
80 (const BYTE *)(in), (BYTE *)(out), (void *)(keySchedule)
81
82 // Macros to set up the encryption/decryption key schedules
83 //
84 // AES:
85 #define TpmCryptSetEncryptKeyAES(key, keySizeInBits, schedule) \
86 AES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
87 #define TpmCryptSetDecryptKeyAES(key, keySizeInBits, schedule) \
88 AES_set_decrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
89
90 // TDES:
91 #define TpmCryptSetEncryptKeyTDES(key, keySizeInBits, schedule) \
92 TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
93 #define TpmCryptSetDecryptKeyTDES(key, keySizeInBits, schedule) \
94 TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
95
96 // Macros to alias encryption calls to specific algorithms. This should be used
97 // sparingly. Currently, only used by CryptRand.c
98 //
99 // When using these calls, to call the AES block encryption code, the caller
100 // should use:
101 // TpmCryptEncryptAES(SWIZZLE(keySchedule, in, out));
102 #define TpmCryptEncryptAES AES_encrypt
103 #define TpmCryptDecryptAES AES_decrypt
104 #define tpmKeyScheduleAES AES_KEY
105
106
107 #define TpmCryptEncryptTDES TDES_encrypt
108 #define TpmCryptDecryptTDES TDES_decrypt
109 #define tpmKeyScheduleTDES DES_key_schedule
110
111 typedef union tpmCryptKeySchedule_t tpmCryptKeySchedule_t;
112
113 #if ALG_TDES
114 #include "TpmToOsslDesSupport_fp.h"
115 #endif
116
117 // This definition would change if there were something to report
118 #define SymLibSimulationEnd()
119
120 #endif // SYM_LIB_DEFINED