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: Aug 30, 2019 Time: 02:11:54PM 38 */ 39 40 #ifndef _TPM_TO_LTC_MATH_FP_H_ 41 #define _TPM_TO_LTC_MATH_FP_H_ 42 43 #ifdef MATH_LIB_LTC 44 45 //*** BnModMult() 46 // Does multiply and divide returning the remainder of the divide. 47 LIB_EXPORT BOOL 48 BnModMult( 49 bigNum result, 50 bigConst op1, 51 bigConst op2, 52 bigConst modulus 53 ); 54 55 //*** BnMult() 56 // Multiplies two numbers 57 LIB_EXPORT BOOL 58 BnMult( 59 bigNum result, 60 bigConst multiplicand, 61 bigConst multiplier 62 ); 63 64 //*** BnDiv() 65 // This function divides two BIGNUM values. The function always returns TRUE. 66 LIB_EXPORT BOOL 67 BnDiv( 68 bigNum quotient, 69 bigNum remainder, 70 bigConst dividend, 71 bigConst divisor 72 ); 73 74 #ifdef TPM_ALG_RSA 75 //*** BnGcd() 76 // Get the greatest common divisor of two numbers 77 LIB_EXPORT BOOL 78 BnGcd( 79 bigNum gcd, // OUT: the common divisor 80 bigConst number1, // IN: 81 bigConst number2 // IN: 82 ); 83 84 //***BnModExp() 85 // Do modular exponentiation using BIGNUM values. The conversion from a bignum_t 86 // to a BIGNUM is trivial as they are based on the same structure 87 LIB_EXPORT BOOL 88 BnModExp( 89 bigNum result, // OUT: the result 90 bigConst number, // IN: number to exponentiate 91 bigConst exponent, // IN: 92 bigConst modulus // IN: 93 ); 94 95 //*** BnModInverse() 96 // Modular multiplicative inverse 97 LIB_EXPORT BOOL 98 BnModInverse( 99 bigNum result, 100 bigConst number, 101 bigConst modulus 102 ); 103 #endif // TPM_ALG_RSA 104 #ifdef TPM_ALG_ECC 105 106 //*** BnEccModMult() 107 // This function does a point multiply of the form R = [d]S 108 // return type: BOOL 109 // FALSE failure in operation; treat as result being point at infinity 110 LIB_EXPORT BOOL 111 BnEccModMult( 112 bigPoint R, // OUT: computed point 113 pointConst S, // IN: point to multiply by 'd' 114 bigConst d, // IN: scalar for [d]S 115 bigCurve E 116 ); 117 118 //*** BnEccModMult2() 119 // This function does a point multiply of the form R = [d]S + [u]Q 120 // return type: BOOL 121 // FALSE failure in operation; treat as result being point at infinity 122 LIB_EXPORT BOOL 123 BnEccModMult2( 124 bigPoint R, // OUT: computed point 125 pointConst S, // IN: first point (optional) 126 bigConst d, // IN: scalar for [d]S or [d]G 127 pointConst Q, // IN: second point 128 bigConst u, // IN: second scalar 129 bigCurve E // IN: curve 130 ); 131 132 //*** BnEccAdd() 133 // This function does addition of two points. Since this is not implemented 134 // in LibTomCrypt() will try to trick it by doing multiply with scalar of 1. 135 // I have no idea if this will work and it's not needed unless MQV or the SM2 136 // variant is enabled. 137 // return type: BOOL 138 // FALSE failure in operation; treat as result being point at infinity 139 LIB_EXPORT BOOL 140 BnEccAdd( 141 bigPoint R, // OUT: computed point 142 pointConst S, // IN: point to multiply by 'd' 143 pointConst Q, // IN: second point 144 bigCurve E // IN: curve 145 ); 146 #endif // TPM_ALG_ECC 147 #endif // MATH_LIB_LTC 148 149 #endif // _TPM_TO_LTC_MATH_FP_H_ 150