• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: Apr  7, 2019  Time: 06:58:58PM
38  */
39 
40 #ifndef    _MEMORY_FP_H_
41 #define    _MEMORY_FP_H_
42 
43 //*** MemoryCopy()
44 // This is an alias for memmove. This is used in place of memcpy because
45 // some of the moves may overlap and rather than try to make sure that
46 // memmove is used when necessary, it is always used.
47 void
48 MemoryCopy(
49     void        *dest,
50     const void  *src,
51     int          sSize
52 );
53 
54 //*** MemoryEqual()
55 // This function indicates if two buffers have the same values in the indicated
56 // number of bytes.
57 //  Return Type: BOOL
58 //      TRUE(1)         all octets are the same
59 //      FALSE(0)        all octets are not the same
60 BOOL
61 MemoryEqual(
62     const void      *buffer1,       // IN: compare buffer1
63     const void      *buffer2,       // IN: compare buffer2
64     unsigned int     size           // IN: size of bytes being compared
65 );
66 
67 //*** MemoryCopy2B()
68 // This function copies a TPM2B. This can be used when the TPM2B types are
69 // the same or different.
70 //
71 // This function returns the number of octets in the data buffer of the TPM2B.
72 LIB_EXPORT INT16
73 MemoryCopy2B(
74     TPM2B           *dest,          // OUT: receiving TPM2B
75     const TPM2B     *source,        // IN: source TPM2B
76     unsigned int     dSize          // IN: size of the receiving buffer
77 );
78 
79 //*** MemoryConcat2B()
80 // This function will concatenate the buffer contents of a TPM2B to an
81 // the buffer contents of another TPM2B and adjust the size accordingly
82 //      ('a' := ('a' | 'b')).
83 void
84 MemoryConcat2B(
85     TPM2B           *aInOut,        // IN/OUT: destination 2B
86     TPM2B           *bIn,           // IN: second 2B
87     unsigned int     aMaxSize       // IN: The size of aInOut.buffer (max values for
88                                     //     aInOut.size)
89 );
90 
91 //*** MemoryEqual2B()
92 // This function will compare two TPM2B structures. To be equal, they
93 // need to be the same size and the buffer contexts need to be the same
94 // in all octets.
95 //  Return Type: BOOL
96 //      TRUE(1)         size and buffer contents are the same
97 //      FALSE(0)        size or buffer contents are not the same
98 BOOL
99 MemoryEqual2B(
100     const TPM2B     *aIn,           // IN: compare value
101     const TPM2B     *bIn            // IN: compare value
102 );
103 
104 //*** MemorySet()
105 // This function will set all the octets in the specified memory range to
106 // the specified octet value.
107 // Note: A previous version had an additional parameter (dSize) that was
108 // intended to make sure that the destination would not be overrun. The
109 // problem is that, in use, all that was happening was that the value of
110 // size was used for dSize so there was no benefit in the extra parameter.
111 void
112 MemorySet(
113     void            *dest,
114     int              value,
115     size_t           size
116 );
117 
118 //*** MemoryPad2B()
119 // Function to pad a TPM2B with zeros and adjust the size.
120 void
121 MemoryPad2B(
122     TPM2B           *b,
123     UINT16           newSize
124 );
125 
126 //*** Uint16ToByteArray()
127 // Function to write an integer to a byte array
128 void
129 Uint16ToByteArray(
130     UINT16              i,
131     BYTE                *a
132 );
133 
134 //*** Uint32ToByteArray()
135 // Function to write an integer to a byte array
136 void
137 Uint32ToByteArray(
138     UINT32              i,
139     BYTE                *a
140 );
141 
142 //*** Uint64ToByteArray()
143 // Function to write an integer to a byte array
144 void
145 Uint64ToByteArray(
146     UINT64               i,
147     BYTE                *a
148 );
149 
150 //*** ByteArrayToUint8()
151 // Function to write a UINT8 to a byte array. This is included for completeness
152 // and to allow certain macro expansions
153 UINT8
154 ByteArrayToUint8(
155     BYTE                *a
156 );
157 
158 //*** ByteArrayToUint16()
159 // Function to write an integer to a byte array
160 UINT16
161 ByteArrayToUint16(
162     BYTE                *a
163 );
164 
165 //*** ByteArrayToUint32()
166 // Function to write an integer to a byte array
167 UINT32
168 ByteArrayToUint32(
169     BYTE                *a
170 );
171 
172 //*** ByteArrayToUint64()
173 // Function to write an integer to a byte array
174 UINT64
175 ByteArrayToUint64(
176     BYTE                *a
177 );
178 
179 #endif  // _MEMORY_FP_H_
180