xref: /aosp_15_r20/external/ms-tpm-20-ref/TPMCmd/tpm/include/prototypes/TpmASN1_fp.h (revision 5c591343844d1f9da7da26467c4bf7efc8a7a413)
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_ASN1_FP_H_
41 #define    _TPM_ASN1_FP_H_
42 
43 //*** ASN1UnmarshalContextInitialize()
44 // Function does standard initialization of a context.
45 //  Return Type: BOOL
46 //      TRUE(1)     success
47 //      FALSE(0)    failure
48 BOOL
49 ASN1UnmarshalContextInitialize(
50     ASN1UnmarshalContext    *ctx,
51     INT16                    size,
52     BYTE                    *buffer
53 );
54 
55 //***ASN1DecodeLength()
56 // This function extracts the length of an element from 'buffer' starting at 'offset'.
57 // Return Type: UINT16
58 //      >=0         the extracted length
59 //      <0          an error
60 INT16
61 ASN1DecodeLength(
62     ASN1UnmarshalContext        *ctx
63 );
64 
65 //***ASN1NextTag()
66 // This function extracts the next type from 'buffer' starting at 'offset'.
67 // It advances 'offset' as it parses the type and the length of the type. It returns
68 // the length of the type. On return, the 'length' octets starting at 'offset' are the
69 // octets of the type.
70 // Return Type: UINT
71 //     >=0          the number of octets in 'type'
72 //     <0           an error
73 INT16
74 ASN1NextTag(
75     ASN1UnmarshalContext    *ctx
76 );
77 
78 //*** ASN1GetBitStringValue()
79 // Try to parse a bit string of up to 32 bits from a value that is expected to be
80 // a bit string. The bit string is left justified so that the MSb of the input is
81 // the MSb of the returned value.
82 // If there is a general parsing error, the context->size is set to -1.
83 //  Return Type: BOOL
84 //      TRUE(1)     success
85 //      FALSE(0)    failure
86 BOOL
87 ASN1GetBitStringValue(
88     ASN1UnmarshalContext        *ctx,
89     UINT32                      *val
90 );
91 
92 //*** ASN1InitialializeMarshalContext()
93 // This creates a structure for handling marshaling of an ASN.1 formatted data
94 // structure.
95 void
96 ASN1InitialializeMarshalContext(
97     ASN1MarshalContext      *ctx,
98     INT16                    length,
99     BYTE                    *buffer
100 );
101 
102 //*** ASN1StartMarshalContext()
103 // This starts a new constructed element. It is constructed on 'top' of the value
104 // that was previously placed in the structure.
105 void
106 ASN1StartMarshalContext(
107     ASN1MarshalContext      *ctx
108 );
109 
110 //*** ASN1EndMarshalContext()
111 // This function restores the end pointer for an encapsulating structure.
112 //  Return Type: INT16
113 //      > 0             the size of the encapsulated structure that was just ended
114 //      <= 0            an error
115 INT16
116 ASN1EndMarshalContext(
117     ASN1MarshalContext      *ctx
118 );
119 
120 //***ASN1EndEncapsulation()
121 // This function puts a tag and length in the buffer. In this function, an embedded
122 // BIT_STRING is assumed to be a collection of octets. To indicate that all bits
123 // are used, a byte of zero is prepended. If a raw bit-string is needed, a new
124 // function like ASN1PushInteger() would be needed.
125 //  Return Type: INT16
126 //      > 0         number of octets in the encapsulation
127 //      == 0        failure
128 UINT16
129 ASN1EndEncapsulation(
130     ASN1MarshalContext          *ctx,
131     BYTE                         tag
132 );
133 
134 //*** ASN1PushByte()
135 BOOL
136 ASN1PushByte(
137     ASN1MarshalContext          *ctx,
138     BYTE                         b
139 );
140 
141 //*** ASN1PushBytes()
142 // Push some raw bytes onto the buffer. 'count' cannot be zero.
143 //  Return Type: IN16
144 //      > 0             count bytes
145 //      == 0            failure unless count was zero
146 INT16
147 ASN1PushBytes(
148     ASN1MarshalContext          *ctx,
149     INT16                        count,
150     const BYTE                  *buffer
151 );
152 
153 //*** ASN1PushNull()
154 //  Return Type: IN16
155 //      > 0             count bytes
156 //      == 0            failure unless count was zero
157 INT16
158 ASN1PushNull(
159     ASN1MarshalContext      *ctx
160 );
161 
162 //*** ASN1PushLength()
163 // Push a length value. This will only handle length values that fit in an INT16.
164 //  Return Type: UINT16
165 //      > 0         number of bytes added
166 //      == 0        failure
167 INT16
168 ASN1PushLength(
169     ASN1MarshalContext          *ctx,
170     INT16                        len
171 );
172 
173 //*** ASN1PushTagAndLength()
174 //  Return Type: INT16
175 //      > 0         number of bytes added
176 //      == 0        failure
177 INT16
178 ASN1PushTagAndLength(
179     ASN1MarshalContext          *ctx,
180     BYTE                         tag,
181     INT16                        length
182 );
183 
184 //*** ASN1PushTaggedOctetString()
185 // This function will push a random octet string.
186 //  Return Type: INT16
187 //      > 0         number of bytes added
188 //      == 0        failure
189 INT16
190 ASN1PushTaggedOctetString(
191     ASN1MarshalContext          *ctx,
192     INT16                        size,
193     const BYTE                  *string,
194     BYTE                         tag
195 );
196 
197 //*** ASN1PushUINT()
198 // This function pushes an native-endian integer value. This just changes a
199 // native-endian integer into a big-endian byte string and calls ASN1PushInteger().
200 // That function will remove leading zeros and make sure that the number is positive.
201 //  Return Type: IN16
202 //      > 0             count bytes
203 //      == 0            failure unless count was zero
204 INT16
205 ASN1PushUINT(
206     ASN1MarshalContext      *ctx,
207     UINT32                   integer
208 );
209 
210 //*** ASN1PushInteger
211 // Push a big-endian integer on the end of the buffer
212 //  Return Type: UINT16
213 //      > 0         the number of bytes marshaled for the integer
214 //      == 0        failure
215 INT16
216 ASN1PushInteger(
217     ASN1MarshalContext  *ctx,           // IN/OUT: buffer context
218     INT16                iLen,          // IN: octets of the integer
219     BYTE                *integer        // IN: big-endian integer
220 );
221 
222 //*** ASN1PushOID()
223 // This function is used to add an OID. An OID is 0x06 followed by a byte of size
224 // followed by size bytes. This is used to avoid having to do anything special in the
225 // definition of an OID.
226 //  Return Type: UINT16
227 //      > 0         the number of bytes marshaled for the integer
228 //      == 0        failure
229 INT16
230 ASN1PushOID(
231     ASN1MarshalContext          *ctx,
232     const BYTE                  *OID
233 );
234 
235 #endif  // _TPM_ASN1_FP_H_
236