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 // This file contains the function prototypes for the functions that need to be 37 // present in the selected math library. For each function listed, there should 38 // be a small stub function. That stub provides the interface between the TPM 39 // code and the support library. In most cases, the stub function will only need 40 // to do a format conversion between the TPM big number and the support library 41 // big number. The TPM big number format was chosen to make this relatively 42 // simple and fast. 43 // 44 // Arithmetic operations return a BOOL to indicate if the operation completed 45 // successfully or not. 46 47 #ifndef SUPPORT_LIBRARY_FUNCTION_PROTOTYPES_H 48 #define SUPPORT_LIBRARY_FUNCTION_PROTOTYPES_H 49 50 //** SupportLibInit() 51 // This function is called by CryptInit() so that necessary initializations can be 52 // performed on the cryptographic library. 53 LIB_EXPORT 54 int SupportLibInit(void); 55 56 //** MathLibraryCompatibililtyCheck() 57 // This function is only used during development to make sure that the library 58 // that is being referenced is using the same size of data structures as the TPM. 59 BOOL 60 MathLibraryCompatibilityCheck( 61 void 62 ); 63 64 //** BnModMult() 65 // Does 'op1' * 'op2' and divide by 'modulus' returning the remainder of the divide. 66 LIB_EXPORT BOOL 67 BnModMult(bigNum result, bigConst op1, bigConst op2, bigConst modulus); 68 69 //** BnMult() 70 // Multiplies two numbers and returns the result 71 LIB_EXPORT BOOL 72 BnMult(bigNum result, bigConst multiplicand, bigConst multiplier); 73 74 //** BnDiv() 75 // This function divides two bigNum values. The function returns FALSE if there is 76 // an error in the operation. 77 LIB_EXPORT BOOL 78 BnDiv(bigNum quotient, bigNum remainder, 79 bigConst dividend, bigConst divisor); 80 //** BnMod() 81 #define BnMod(a, b) BnDiv(NULL, (a), (a), (b)) 82 83 //** BnGcd() 84 // Get the greatest common divisor of two numbers. This function is only needed 85 // when the TPM implements RSA. 86 LIB_EXPORT BOOL 87 BnGcd(bigNum gcd, bigConst number1, bigConst number2); 88 89 //** BnModExp() 90 // Do modular exponentiation using bigNum values. This function is only needed 91 // when the TPM implements RSA. 92 LIB_EXPORT BOOL 93 BnModExp(bigNum result, bigConst number, 94 bigConst exponent, bigConst modulus); 95 //** BnModInverse() 96 // Modular multiplicative inverse. This function is only needed 97 // when the TPM implements RSA. 98 LIB_EXPORT BOOL BnModInverse(bigNum result, bigConst number, 99 bigConst modulus); 100 101 //** BnEccModMult() 102 // This function does a point multiply of the form R = [d]S. A return of FALSE 103 // indicates that the result was the point at infinity. This function is only needed 104 // if the TPM supports ECC. 105 LIB_EXPORT BOOL 106 BnEccModMult(bigPoint R, pointConst S, bigConst d, bigCurve E); 107 108 //** BnEccModMult2() 109 // This function does a point multiply of the form R = [d]S + [u]Q. A return of 110 // FALSE indicates that the result was the point at infinity. This function is only 111 // needed if the TPM supports ECC. 112 LIB_EXPORT BOOL 113 BnEccModMult2(bigPoint R, pointConst S, bigConst d, 114 pointConst Q, bigConst u, bigCurve E); 115 116 //** BnEccAdd() 117 // This function does a point add R = S + Q. A return of FALSE 118 // indicates that the result was the point at infinity. This function is only needed 119 // if the TPM supports ECC. 120 LIB_EXPORT BOOL 121 BnEccAdd(bigPoint R, pointConst S, pointConst Q, bigCurve E); 122 123 //** BnCurveInitialize() 124 // This function is used to initialize the pointers of a bnCurve_t structure. The 125 // structure is a set of pointers to bigNum values. The curve-dependent values are 126 // set by a different function. This function is only needed 127 // if the TPM supports ECC. 128 LIB_EXPORT bigCurve 129 BnCurveInitialize(bigCurve E, TPM_ECC_CURVE curveId); 130 131 //*** BnCurveFree() 132 // This function will free the allocated components of the curve and end the 133 // frame in which the curve data exists 134 LIB_EXPORT void 135 BnCurveFree(bigCurve E); 136 137 #endif