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: Mar 28, 2019 Time: 08:25:19PM 38 */ 39 40 #ifndef _MATH_ON_BYTE_BUFFERS_FP_H_ 41 #define _MATH_ON_BYTE_BUFFERS_FP_H_ 42 43 //*** UnsignedCmpB 44 // This function compare two unsigned values. The values are byte-aligned, 45 // big-endian numbers (e.g, a hash). 46 // Return Type: int 47 // 1 if (a > b) 48 // 0 if (a = b) 49 // -1 if (a < b) 50 LIB_EXPORT int 51 UnsignedCompareB( 52 UINT32 aSize, // IN: size of a 53 const BYTE *a, // IN: a 54 UINT32 bSize, // IN: size of b 55 const BYTE *b // IN: b 56 ); 57 58 //***SignedCompareB() 59 // Compare two signed integers: 60 // Return Type: int 61 // 1 if a > b 62 // 0 if a = b 63 // -1 if a < b 64 int 65 SignedCompareB( 66 const UINT32 aSize, // IN: size of a 67 const BYTE *a, // IN: a buffer 68 const UINT32 bSize, // IN: size of b 69 const BYTE *b // IN: b buffer 70 ); 71 72 //*** ModExpB 73 // This function is used to do modular exponentiation in support of RSA. 74 // The most typical uses are: 'c' = 'm'^'e' mod 'n' (RSA encrypt) and 75 // 'm' = 'c'^'d' mod 'n' (RSA decrypt). When doing decryption, the 'e' parameter 76 // of the function will contain the private exponent 'd' instead of the public 77 // exponent 'e'. 78 // 79 // If the results will not fit in the provided buffer, 80 // an error is returned (CRYPT_ERROR_UNDERFLOW). If the results is smaller 81 // than the buffer, the results is de-normalized. 82 // 83 // This version is intended for use with RSA and requires that 'm' be 84 // less than 'n'. 85 // 86 // Return Type: TPM_RC 87 // TPM_RC_SIZE number to exponentiate is larger than the modulus 88 // TPM_RC_NO_RESULT result will not fit into the provided buffer 89 // 90 TPM_RC 91 ModExpB( 92 UINT32 cSize, // IN: the size of the output buffer. It will 93 // need to be the same size as the modulus 94 BYTE *c, // OUT: the buffer to receive the results 95 // (c->size must be set to the maximum size 96 // for the returned value) 97 const UINT32 mSize, 98 const BYTE *m, // IN: number to exponentiate 99 const UINT32 eSize, 100 const BYTE *e, // IN: power 101 const UINT32 nSize, 102 const BYTE *n // IN: modulus 103 ); 104 105 //*** DivideB() 106 // Divide an integer ('n') by an integer ('d') producing a quotient ('q') and 107 // a remainder ('r'). If 'q' or 'r' is not needed, then the pointer to them 108 // may be set to NULL. 109 // 110 // Return Type: TPM_RC 111 // TPM_RC_NO_RESULT 'q' or 'r' is too small to receive the result 112 // 113 LIB_EXPORT TPM_RC 114 DivideB( 115 const TPM2B *n, // IN: numerator 116 const TPM2B *d, // IN: denominator 117 TPM2B *q, // OUT: quotient 118 TPM2B *r // OUT: remainder 119 ); 120 121 //*** AdjustNumberB() 122 // Remove/add leading zeros from a number in a TPM2B. Will try to make the number 123 // by adding or removing leading zeros. If the number is larger than the requested 124 // size, it will make the number as small as possible. Setting 'requestedSize' to 125 // zero is equivalent to requesting that the number be normalized. 126 UINT16 127 AdjustNumberB( 128 TPM2B *num, 129 UINT16 requestedSize 130 ); 131 132 //*** ShiftLeft() 133 // This function shifts a byte buffer (a TPM2B) one byte to the left. That is, 134 // the most significant bit of the most significant byte is lost. 135 TPM2B * 136 ShiftLeft( 137 TPM2B *value // IN/OUT: value to shift and shifted value out 138 ); 139 140 #endif // _MATH_ON_BYTE_BUFFERS_FP_H_ 141