blob: b667a14645d6e0a2f591d1d1ed4b5418960af979 [file] [log] [blame]
Will Arthur54e04e42015-07-15 11:29:25 -04001//**********************************************************************;
2// Copyright (c) 2015, Intel Corporation
3// All rights reserved.
Philip Tricca1ea84a52015-11-19 18:07:06 -08004//
5// Redistribution and use in source and binary forms, with or without
Will Arthur54e04e42015-07-15 11:29:25 -04006// modification, are permitted provided that the following conditions are met:
Philip Tricca1ea84a52015-11-19 18:07:06 -08007//
8// 1. Redistributions of source code must retain the above copyright notice,
Will Arthur54e04e42015-07-15 11:29:25 -04009// this list of conditions and the following disclaimer.
Philip Tricca1ea84a52015-11-19 18:07:06 -080010//
11// 2. Redistributions in binary form must reproduce the above copyright notice,
12// this list of conditions and the following disclaimer in the documentation
Will Arthur54e04e42015-07-15 11:29:25 -040013// and/or other materials provided with the distribution.
Philip Tricca1ea84a52015-11-19 18:07:06 -080014//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
Will Arthur54e04e42015-07-15 11:29:25 -040025// THE POSSIBILITY OF SUCH DAMAGE.
26//**********************************************************************;
27
Philip Triccadd3b03c2017-03-05 11:38:08 -080028#include "sapi/tpm20.h"
Philip Triccac3dedc22016-01-15 13:47:22 -080029#include "sysapi_util.h"
Tadeusz Struk8203a372017-06-26 15:15:18 -070030#include "tss2_endian.h"
Will Arthur54e04e42015-07-15 11:29:25 -040031
wcarthur7b10eeb2015-12-03 16:40:41 -050032void Unmarshal_Simple_TPM2B( UINT8 *outBuffPtr, UINT32 maxResponseSize, UINT8 **nextData, TPM2B *outTPM2B, TSS2_RC *rval )
Will Arthur54e04e42015-07-15 11:29:25 -040033{
34//deleted for now--spec issues with nested TPM2B's
35#if 0
36 INT64 callerAllocatedSize;
Philip Triccadfa41a52016-07-20 17:43:57 -070037#endif
Will Arthur54e04e42015-07-15 11:29:25 -040038 int i;
39 UINT16 length;
Philip Triccadfa41a52016-07-20 17:43:57 -070040
Will Arthur54e04e42015-07-15 11:29:25 -040041 if( *rval == TSS2_RC_SUCCESS )
42 {
43 if( outBuffPtr == 0 || nextData == 0 || *nextData == 0 )
44 {
45 *rval = TSS2_SYS_RC_BAD_REFERENCE;
46 }
47 else
48 {
49 if( *rval == TSS2_RC_SUCCESS )
50 {
Tadeusz Struk8203a372017-06-26 15:15:18 -070051 length = BE_TO_HOST_16(*(UINT16 *)*nextData);
wcarthur7b10eeb2015-12-03 16:40:41 -050052
53 if( outTPM2B != 0 )
Will Arthur54e04e42015-07-15 11:29:25 -040054 {
wcarthur7b10eeb2015-12-03 16:40:41 -050055 if( length > outTPM2B->size )
56 {
57 *rval = TSS2_SYS_RC_INSUFFICIENT_BUFFER;
58 }
59 else
60 {
61 Unmarshal_UINT16( outBuffPtr, maxResponseSize, nextData, &( outTPM2B->size ), rval );
62 }
Will Arthur54e04e42015-07-15 11:29:25 -040063 }
64 else
65 {
wcarthur7b10eeb2015-12-03 16:40:41 -050066 // Let low level function deal with NULL output pointer.
Will Arthur54e04e42015-07-15 11:29:25 -040067 Unmarshal_UINT16( outBuffPtr, maxResponseSize, nextData, 0, rval );
68 }
69
70 if( *rval == TSS2_RC_SUCCESS )
71 {
72 // Copy to output TPM2B.
73 for( i = 0; i < length; i++ )
74 {
wcarthur7b10eeb2015-12-03 16:40:41 -050075 if( outTPM2B != 0 )
Will Arthur54e04e42015-07-15 11:29:25 -040076 {
wcarthur7b10eeb2015-12-03 16:40:41 -050077 Unmarshal_UINT8( outBuffPtr, maxResponseSize, nextData, &( outTPM2B->buffer[i] ), rval );
Will Arthur54e04e42015-07-15 11:29:25 -040078 }
79 else
80 {
wcarthur7b10eeb2015-12-03 16:40:41 -050081 // Let low level function deal with NULL output pointer.
Will Arthur54e04e42015-07-15 11:29:25 -040082 Unmarshal_UINT8( outBuffPtr, maxResponseSize, nextData, 0, rval );
83 }
84
85 if( *rval != TSS2_RC_SUCCESS )
86 {
87 break;
88 }
89 }
90 }
91 }
92 }
93 }
94}
95