tpmclient: move TPM2B helper functions to sample.h
There is no need to have a separate .c file for each of them.
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
diff --git a/Makefile-test.am b/Makefile-test.am
index 18bb43d..3c35c29 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -259,7 +259,6 @@
test_tpmclient_tpmclient_int_CFLAGS = $(AM_CFLAGS) -U_FORTIFY_SOURCE $(TESTS_CFLAGS)
test_tpmclient_tpmclient_int_LDADD = $(TESTS_LDADD)
test_tpmclient_tpmclient_int_SOURCES = \
- test/tpmclient/CatSizedByteBuffer.c test/tpmclient/CopySizedBuffer.c \
test/tpmclient/CreateNullSession.c test/tpmclient/DecryptEncrypt.c \
test/tpmclient/Entity.c test/tpmclient/kdfa.c \
test/tpmclient/LoadExternalHMACKey.c test/integration/main.c \
diff --git a/test/tpmclient/CatSizedByteBuffer.c b/test/tpmclient/CatSizedByteBuffer.c
deleted file mode 100644
index ba91d5a..0000000
--- a/test/tpmclient/CatSizedByteBuffer.c
+++ /dev/null
@@ -1,42 +0,0 @@
-//**********************************************************************;
-// Copyright (c) 2015, Intel Corporation
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//**********************************************************************;
-
-#include "tss2_tpm2_types.h"
-
-#include "util/tpm2b.h"
-
-void CatSizedByteBuffer( TPM2B *dest, TPM2B *src )
-{
- int i;
-
- if( dest != 0 && src != 0 )
- {
- for( i = 0; i < src->size; i++ )
- dest->buffer[ dest->size + i] = src->buffer[i];
- dest->size += src->size;
- }
-}
diff --git a/test/tpmclient/CopySizedBuffer.c b/test/tpmclient/CopySizedBuffer.c
deleted file mode 100644
index afea2d9..0000000
--- a/test/tpmclient/CopySizedBuffer.c
+++ /dev/null
@@ -1,60 +0,0 @@
-//**********************************************************************;
-// Copyright (c) 2015, Intel Corporation
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//**********************************************************************;
-
-#include <string.h>
-
-#include "tss2_tpm2_types.h"
-
-#include "util/tpm2b.h"
-
-UINT16 CopySizedByteBuffer( TPM2B *dest, TPM2B *src )
-{
- int i;
- UINT16 rval = 0;
-
- if( dest != 0 )
- {
- if( src == 0 )
- {
- dest->size = 0;
- rval = 0;
- }
- else
- {
- dest->size = src->size;
- for( i = 0; i < src->size; i++ )
- dest->buffer[i] = src->buffer[i];
- rval = ( sizeof( UINT16 ) + src->size );
- }
- }
- else
- {
- rval = 0;
- }
-
- return rval;
-}
diff --git a/test/tpmclient/sample.h b/test/tpmclient/sample.h
index 63b3b48..391cb5a 100644
--- a/test/tpmclient/sample.h
+++ b/test/tpmclient/sample.h
@@ -37,6 +37,7 @@
#include "tpmclient.h"
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "syscontext.h"
extern TSS2_TCTI_CONTEXT *resMgrTctiContext;
@@ -212,8 +213,6 @@
TSS2_RC LoadExternalHMACKey( TPMI_ALG_HASH hashAlg, TPM2B *key, TPM2_HANDLE *keyHandle, TPM2B_NAME *keyName );
-UINT16 CopySizedByteBuffer( TPM2B *dest, TPM2B *src );
-
TSS2_RC EncryptCommandParam( SESSION *session, TPM2B_MAX_BUFFER *encryptedData, TPM2B_MAX_BUFFER *clearData, TPM2B_AUTH *authValue );
TSS2_RC DecryptResponseParam( SESSION *session, TPM2B_MAX_BUFFER *clearData, TPM2B_MAX_BUFFER *encryptedData, TPM2B_AUTH *authValue );
@@ -223,7 +222,27 @@
UINT32 TpmHashSequence( TPMI_ALG_HASH hashAlg, UINT8 numBuffers, TPM2B_DIGEST *bufferList, TPM2B_DIGEST *result );
-void CatSizedByteBuffer( TPM2B *dest, TPM2B *src );
+static inline void CatSizedByteBuffer(TPM2B *dest, TPM2B *src)
+{
+ if (!dest || !src)
+ return;
+ memcpy(dest->buffer + dest->size, src->buffer, src->size);
+ dest->size += src->size;
+}
+static inline UINT16 CopySizedByteBuffer(TPM2B *dest, TPM2B *src)
+{
+ if (!dest)
+ return 0;
+
+ if (!src) {
+ dest->size = 0;
+ return 0;
+ }
+
+ memcpy(dest->buffer, src->buffer, src->size);
+ dest->size = src->size;
+ return src->size + 2;
+}
void RollNonces( SESSION *session, TPM2B_NONCE *newNonce );