| 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 other |
| 22 | * 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 | |
| 36 | //** Introduction |
| 37 | // |
| 38 | // This header file is used to "splice" the TPM to the LTC symmetric cipher code. |
| 39 | |
| 40 | #ifndef SYM_LIB_DEFINED |
| 41 | #define SYM_LIB_DEFINED |
| 42 | |
| 43 | #define SYM_LIB_LTC |
| 44 | |
| 45 | // Avoid pulling in the MPA math if not doing asymmetric with LTC |
| 46 | #if !(defined MATH_LIB_LTC) |
| 47 | # define LTC_NO_ASYMMETRIC |
| 48 | #endif |
| 49 | |
| 50 | #include "LtcSettings.h" |
| 51 | |
| 52 | //*************************************************************** |
| 53 | //******** Linking to the TomCrypt 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 functions that do block encryption and |
| 65 | // decryption. |
| 66 | typedef void(*TpmCryptSetSymKeyCall_t)( |
| 67 | const void *in, |
| 68 | void *out, |
| 69 | void *keySchedule |
| 70 | ); |
| 71 | |
| 72 | // Macro to put the parameters in the order required by the library |
| 73 | #define SWIZZLE(keySchedule, in, out) \ |
| 74 | (const void *)(in), (void *)(out), (void *)(keySchedule) |
| 75 | |
| 76 | // Macros to set up the encryption/decryption key schedules |
| 77 | // |
| 78 | // AES: |
| 79 | # define TpmCryptSetEncryptKeyAES(key, keySizeInBits, schedule) \ |
| 80 | aes_setup((key), BITS_TO_BYTES(keySizeInBits), 0, (symmetric_key *)(schedule)) |
| 81 | # define TpmCryptSetDecryptKeyAES(key, keySizeInBits, schedule) \ |
| 82 | aes_setup((key), BITS_TO_BYTES(keySizeInBits), 0, (symmetric_key *)(schedule)) |
| 83 | |
| 84 | // TDES: |
| 85 | # define TpmCryptSetEncryptKeyTDES(key, keySizeInBits, schedule) \ |
| 86 | TDES_setup((key), (keySizeInBits), (symmetric_key *)(schedule)) |
| 87 | # define TpmCryptSetDecryptKeyTDES(key, keySizeInBits, schedule) \ |
| 88 | TDES_setup((key), (keySizeInBits), (symmetric_key *)(schedule)) |
| 89 | |
| 90 | |
| 91 | // Macros to alias encrypt and decrypt function calls to library-specific values |
| 92 | // sparingly. These should be used sparingly. Currently, they are only used by |
| 93 | // CryptRand.c in the AES version of the DRBG. |
| 94 | #define TpmCryptEncryptAES aes_ecb_encrypt |
| 95 | #define TpmCryptDecryptAES aes_ecb_decrypt |
| 96 | #define tpmKeyScheduleAES struct rijndael_key |
| 97 | // |
| 98 | #define TpmCryptEncryptTDES des3_ecb_encrypt |
| 99 | #define TpmCryptDecryptTDES des3_ecb_decrypt |
| 100 | #define tpmKeyScheduleTDES struct des3_key |
| 101 | |
| 102 | typedef union tpmCryptKeySchedule_t tpmCryptKeySchedule_t; |
| 103 | |
| 104 | #include "TpmToLtcDesSupport_fp.h" |
| 105 | |
| 106 | // This is used to trigger printing of simulation statistics |
| 107 | |
| 108 | #define SymLibSimulationEnd() |
| 109 | |
| 110 | #endif // SYM_LIB_DEFINED |