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 // This file contains the structure definitions used for linking from the TPM 38 // code to the MPA and LTC math libraries. 39 40 #ifndef MATH_LIB_DEFINED 41 #define MATH_LIB_DEFINED 42 43 #define MATH_LIB_LTC 44 45 _REDUCE_WARNING_LEVEL_(2) 46 #include "LtcSettings.h" 47 #include "mpalib.h" 48 #include "mpa.h" 49 #include "tomcrypt_mpa.h" 50 _NORMAL_WARNING_LEVEL_ 51 52 53 #if RADIX_BITS != 32 54 #error "The mpa library used with LibTomCrypt only works for 32-bit words" 55 #endif 56 57 // These macros handle entering and leaving a scope 58 // from which an MPA or LibTomCrypt function may be called. 59 // Many of these functions require a scratch pool from which 60 // they will allocate scratch variables (rather than using their 61 // own stack). 62 extern mpa_scratch_mem external_mem_pool; 63 64 #define MPA_ENTER(vars, bits) \ 65 mpa_word_t POOL_ [ \ 66 mpa_scratch_mem_size_in_U32(vars, bits)]; \ 67 mpa_scratch_mem pool_save = external_mem_pool; \ 68 mpa_scratch_mem POOL = LtcPoolInit(POOL_, vars, bits) 69 70 #define MPA_LEAVE() init_mpa_tomcrypt(pool_save) 71 72 typedef ECC_CURVE_DATA bnCurve_t; 73 74 typedef bnCurve_t *bigCurve; 75 76 #define AccessCurveData(E) (E) 77 78 // Include the support functions for the routines that are used by LTC thunk. 79 #include "TpmToLtcSupport_fp.h" 80 81 #define CURVE_INITIALIZED(name, initializer) \ 82 bnCurve_t *name = (ECC_CURVE_DATA *)GetCurveData(initializer) 83 84 #define CURVE_FREE(E) 85 86 // This definition would change if there were something to report 87 #define MathLibSimulationEnd() 88 89 #endif // MATH_LIB_DEFINED 90