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:18PM 38 */ 39 40 #ifndef _BN_CONVERT_FP_H_ 41 #define _BN_CONVERT_FP_H_ 42 43 //*** BnFromBytes() 44 // This function will convert a big-endian byte array to the internal number 45 // format. If bn is NULL, then the output is NULL. If bytes is null or the 46 // required size is 0, then the output is set to zero 47 LIB_EXPORT bigNum 48 BnFromBytes( 49 bigNum bn, 50 const BYTE *bytes, 51 NUMBYTES nBytes 52 ); 53 54 //*** BnFrom2B() 55 // Convert an TPM2B to a BIG_NUM. 56 // If the input value does not exist, or the output does not exist, or the input 57 // will not fit into the output the function returns NULL 58 LIB_EXPORT bigNum 59 BnFrom2B( 60 bigNum bn, // OUT: 61 const TPM2B *a2B // IN: number to convert 62 ); 63 64 //*** BnFromHex() 65 // Convert a hex string into a bigNum. This is primarily used in debugging. 66 LIB_EXPORT bigNum 67 BnFromHex( 68 bigNum bn, // OUT: 69 const char *hex // IN: 70 ); 71 72 //*** BnToBytes() 73 // This function converts a BIG_NUM to a byte array. It converts the bigNum to a 74 // big-endian byte string and sets 'size' to the normalized value. If 'size' is an 75 // input 0, then the receiving buffer is guaranteed to be large enough for the result 76 // and the size will be set to the size required for bigNum (leading zeros 77 // suppressed). 78 // 79 // The conversion for a little-endian machine simply requires that all significant 80 // bytes of the bigNum be reversed. For a big-endian machine, rather than 81 // unpack each word individually, the bigNum is converted to little-endian words, 82 // copied, and then converted back to big-endian. 83 LIB_EXPORT BOOL 84 BnToBytes( 85 bigConst bn, 86 BYTE *buffer, 87 NUMBYTES *size // This the number of bytes that are 88 // available in the buffer. The result 89 // should be this big. 90 ); 91 92 //*** BnTo2B() 93 // Function to convert a BIG_NUM to TPM2B. 94 // The TPM2B size is set to the requested 'size' which may require padding. 95 // If 'size' is non-zero and less than required by the value in 'bn' then an error 96 // is returned. If 'size' is zero, then the TPM2B is assumed to be large enough 97 // for the data and a2b->size will be adjusted accordingly. 98 LIB_EXPORT BOOL 99 BnTo2B( 100 bigConst bn, // IN: 101 TPM2B *a2B, // OUT: 102 NUMBYTES size // IN: the desired size 103 ); 104 #if ALG_ECC 105 106 //*** BnPointFrom2B() 107 // Function to create a BIG_POINT structure from a 2B point. 108 // A point is going to be two ECC values in the same buffer. The values are going 109 // to be the size of the modulus. They are in modular form. 110 LIB_EXPORT bn_point_t * 111 BnPointFrom2B( 112 bigPoint ecP, // OUT: the preallocated point structure 113 TPMS_ECC_POINT *p // IN: the number to convert 114 ); 115 116 //*** BnPointTo2B() 117 // This function converts a BIG_POINT into a TPMS_ECC_POINT. A TPMS_ECC_POINT 118 // contains two TPM2B_ECC_PARAMETER values. The maximum size of the parameters 119 // is dependent on the maximum EC key size used in an implementation. 120 // The presumption is that the TPMS_ECC_POINT is large enough to hold 2 TPM2B 121 // values, each as large as a MAX_ECC_PARAMETER_BYTES 122 LIB_EXPORT BOOL 123 BnPointTo2B( 124 TPMS_ECC_POINT *p, // OUT: the converted 2B structure 125 bigPoint ecP, // IN: the values to be converted 126 bigCurve E // IN: curve descriptor for the point 127 ); 128 #endif // ALG_ECC 129 130 #endif // _BN_CONVERT_FP_H_ 131