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 /*(Auto-generated) 36 * Created by TpmPrototypes; Version 3.0 July 18, 2017 37 * Date: Oct 24, 2019 Time: 11:37:07AM 38 */ 39 40 #ifndef _TPM_TO_OSSL_MATH_FP_H_ 41 #define _TPM_TO_OSSL_MATH_FP_H_ 42 43 #ifdef MATH_LIB_OSSL 44 45 //*** OsslToTpmBn() 46 // This function converts an OpenSSL BIGNUM to a TPM bignum. In this implementation 47 // it is assumed that OpenSSL uses a different control structure but the same data 48 // layout -- an array of native-endian words in little-endian order. 49 // Return Type: BOOL 50 // TRUE(1) success 51 // FALSE(0) failure because value will not fit or OpenSSL variable doesn't 52 // exist 53 BOOL 54 OsslToTpmBn( 55 bigNum bn, 56 BIGNUM *osslBn 57 ); 58 59 //*** BigInitialized() 60 // This function initializes an OSSL BIGNUM from a TPM bigConst. Do not use this for 61 // values that are passed to OpenSLL when they are not declared as const in the 62 // function prototype. Instead, use BnNewVariable(). 63 BIGNUM * 64 BigInitialized( 65 BIGNUM *toInit, 66 bigConst initializer 67 ); 68 #if LIBRARY_COMPATIBILITY_CHECK 69 70 //*** MathLibraryCompatibilityCheck() 71 BOOL 72 MathLibraryCompatibilityCheck( 73 void 74 ); 75 #endif 76 77 //*** BnModMult() 78 // This function does a modular multiply. It first does a multiply and then a divide 79 // and returns the remainder of the divide. 80 // Return Type: BOOL 81 // TRUE(1) success 82 // FALSE(0) failure in operation 83 LIB_EXPORT BOOL 84 BnModMult( 85 bigNum result, 86 bigConst op1, 87 bigConst op2, 88 bigConst modulus 89 ); 90 91 //*** BnMult() 92 // Multiplies two numbers 93 // Return Type: BOOL 94 // TRUE(1) success 95 // FALSE(0) failure in operation 96 LIB_EXPORT BOOL 97 BnMult( 98 bigNum result, 99 bigConst multiplicand, 100 bigConst multiplier 101 ); 102 103 //*** BnDiv() 104 // This function divides two bigNum values. The function returns FALSE if 105 // there is an error in the operation. 106 // Return Type: BOOL 107 // TRUE(1) success 108 // FALSE(0) failure in operation 109 LIB_EXPORT BOOL 110 BnDiv( 111 bigNum quotient, 112 bigNum remainder, 113 bigConst dividend, 114 bigConst divisor 115 ); 116 117 #if ALG_RSA 118 //*** BnGcd() 119 // Get the greatest common divisor of two numbers 120 // Return Type: BOOL 121 // TRUE(1) success 122 // FALSE(0) failure in operation 123 LIB_EXPORT BOOL 124 BnGcd( 125 bigNum gcd, // OUT: the common divisor 126 bigConst number1, // IN: 127 bigConst number2 // IN: 128 ); 129 130 //***BnModExp() 131 // Do modular exponentiation using bigNum values. The conversion from a bignum_t to 132 // a bigNum is trivial as they are based on the same structure 133 // Return Type: BOOL 134 // TRUE(1) success 135 // FALSE(0) failure in operation 136 LIB_EXPORT BOOL 137 BnModExp( 138 bigNum result, // OUT: the result 139 bigConst number, // IN: number to exponentiate 140 bigConst exponent, // IN: 141 bigConst modulus // IN: 142 ); 143 144 //*** BnModInverse() 145 // Modular multiplicative inverse 146 // Return Type: BOOL 147 // TRUE(1) success 148 // FALSE(0) failure in operation 149 LIB_EXPORT BOOL 150 BnModInverse( 151 bigNum result, 152 bigConst number, 153 bigConst modulus 154 ); 155 #endif // ALG_RSA 156 #if ALG_ECC 157 158 //*** BnCurveInitialize() 159 // This function initializes the OpenSSL curve information structure. This 160 // structure points to the TPM-defined values for the curve, to the context for the 161 // number values in the frame, and to the OpenSSL-defined group values. 162 // Return Type: bigCurve * 163 // NULL the TPM_ECC_CURVE is not valid or there was a problem in 164 // in initializing the curve data 165 // non-NULL points to 'E' 166 LIB_EXPORT bigCurve 167 BnCurveInitialize( 168 bigCurve E, // IN: curve structure to initialize 169 TPM_ECC_CURVE curveId // IN: curve identifier 170 ); 171 172 //*** BnCurveFree() 173 // This function will free the allocated components of the curve and end the 174 // frame in which the curve data exists 175 LIB_EXPORT void 176 BnCurveFree( 177 bigCurve E 178 ); 179 180 //*** BnEccModMult() 181 // This function does a point multiply of the form R = [d]S 182 // Return Type: BOOL 183 // TRUE(1) success 184 // FALSE(0) failure in operation; treat as result being point at infinity 185 LIB_EXPORT BOOL 186 BnEccModMult( 187 bigPoint R, // OUT: computed point 188 pointConst S, // IN: point to multiply by 'd' (optional) 189 bigConst d, // IN: scalar for [d]S 190 bigCurve E 191 ); 192 193 //*** BnEccModMult2() 194 // This function does a point multiply of the form R = [d]G + [u]Q 195 // Return Type: BOOL 196 // TRUE(1) success 197 // FALSE(0) failure in operation; treat as result being point at infinity 198 LIB_EXPORT BOOL 199 BnEccModMult2( 200 bigPoint R, // OUT: computed point 201 pointConst S, // IN: optional point 202 bigConst d, // IN: scalar for [d]S or [d]G 203 pointConst Q, // IN: second point 204 bigConst u, // IN: second scalar 205 bigCurve E // IN: curve 206 ); 207 208 //** BnEccAdd() 209 // This function does addition of two points. 210 // Return Type: BOOL 211 // TRUE(1) success 212 // FALSE(0) failure in operation; treat as result being point at infinity 213 LIB_EXPORT BOOL 214 BnEccAdd( 215 bigPoint R, // OUT: computed point 216 pointConst S, // IN: point to multiply by 'd' 217 pointConst Q, // IN: second point 218 bigCurve E // IN: curve 219 ); 220 #endif // ALG_ECC 221 #endif // MATHLIB OSSL 222 223 #endif // _TPM_TO_OSSL_MATH_FP_H_ 224