From 0f5ec7e68e779ff5df82efca8c2eb94bcdfbaa28 Mon Sep 17 00:00:00 2001 From: "u.harbuz" Date: Thu, 4 May 2017 17:21:47 +0200 Subject: [PATCH] Fix type casting. Change-Id: I7e2cf5cabaf0c9793fcf12bd4b74c72ffb17eba0 --- TEEStub/PropertyAccess/PropertyApi.cpp | 4 +-- build/build.sh | 15 ++++++++--- build/ssflib/dep/cryptocore/source/base/subdir.mk | 3 ++- .../ssflib/dep/cryptocore/source/middle/subdir.mk | 3 ++- build/ssflib/dep/cryptocore/source/subdir.mk | 4 ++- build/ssflib/dep/swdss/source/subdir.mk | 3 ++- build/ssflib/dep/time/subdir.mk | 3 ++- build/ssflib/dep/uci/source/subdir.mk | 3 ++- build/ssflib/src/subdir.mk | 4 ++- ssflib/dep/cryptocore/include/CC_Type.h | 11 ++++---- ssflib/dep/swdss/include/ss_types.h | 2 +- ssflib/dep/uci/include/uci_aes_xcbc_mac.h | 2 +- ssflib/dep/uci/include/uci_api.h | 16 +++++------ ssflib/dep/uci/include/uci_cryptocore.h | 10 +++---- ssflib/dep/uci/include/uci_type.h | 2 +- ssflib/dep/uci/source/uci_aes_xcbc_mac.c | 2 +- ssflib/dep/uci/source/uci_api.c | 31 ++++++++++++---------- ssflib/dep/uci/source/uci_cryptocore.c | 28 +++++++++++++------ ssflib/src/ssf_crypto.c | 25 ++++++++--------- 19 files changed, 102 insertions(+), 69 deletions(-) diff --git a/TEEStub/PropertyAccess/PropertyApi.cpp b/TEEStub/PropertyAccess/PropertyApi.cpp index 7cc2e15..161d18c 100755 --- a/TEEStub/PropertyAccess/PropertyApi.cpp +++ b/TEEStub/PropertyAccess/PropertyApi.cpp @@ -296,7 +296,7 @@ void TEE_FreePropertyEnumerator(TEE_PropSetHandle enumerator) { void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator, TEE_PropSetHandle propSet) { PropertyEnumHandle *newEnumHandle = (PropertyEnumHandle*)enumerator; - switch ((uint32_t)propSet) { + switch ((intptr_t)propSet) { case TEE_PROPSET_CURRENT_TA: { newEnumHandle->property = new TAProperty( string(TEE_TASTORE_ROOT) + thisTAUUIDGlobal + "-ext/" @@ -375,7 +375,7 @@ TEE_Result TEE_GetNextProperty(TEE_PropSetHandle enumerator) { Property* _GetTargetProperty(TEE_PropSetHandle propsetOrEnumerator) { Property *targetProperty = NULL; - switch ((uint32_t)propsetOrEnumerator) { + switch ((intptr_t)propsetOrEnumerator) { case TEE_PROPSET_TEE_IMPLEMENTATION: { targetProperty = teeProperty; break; diff --git a/build/build.sh b/build/build.sh index 204083d..c0bc759 100755 --- a/build/build.sh +++ b/build/build.sh @@ -25,6 +25,9 @@ SIMDAEMON_PATH=$DIR/simulatordaemon Package=$2 TOOLCHAIN=$3 +CA_SIMULATOR_LIB=$Package/CA/simulator/usr/lib/ +TA_SIMULATOR_LIB=$Package/TA/simulator/usr/lib/ + #check error case check_make_error() { @@ -88,7 +91,8 @@ check_make_error make TOOLCHAIN=$TOOLCHAIN check_make_error echo "Copying libteec.so in Package" -cp libteec2.so $Package/CA/simulator/usr/lib/ +mkdir -p $CA_SIMULATOR_LIB +cp libteec2.so $CA_SIMULATOR_LIB check_make_error cd $DIR } @@ -101,7 +105,8 @@ check_make_error make TOOLCHAIN=$TOOLCHAIN check_make_error echo "Copying libssflib.so in Package" -cp libssflib.so $Package/TA/simulator/usr/lib/ +mkdir -p $TA_SIMULATOR_LIB +cp libssflib.so $TA_SIMULATOR_LIB check_make_error cd $DIR } @@ -114,7 +119,8 @@ check_make_error make TOOLCHAIN=$TOOLCHAIN check_make_error echo "Copying libTEEStub.a in Package" -cp libTEEStub.a $Package/TA/simulator/usr/lib/ +mkdir -p $TA_SIMULATOR_LIB +cp libTEEStub.a $TA_SIMULATOR_LIB check_make_error cd $DIR } @@ -127,7 +133,8 @@ check_make_error make TOOLCHAIN=$TOOLCHAIN check_make_error echo "Copying SimulatorDaemon in Package" -cp SimulatorDaemon $Package/CA/simulator/usr/lib/ +mkdir -p $CA_SIMULATOR_LIB +cp SimulatorDaemon $CA_SIMULATOR_LIB check_make_error cd $DIR } diff --git a/build/ssflib/dep/cryptocore/source/base/subdir.mk b/build/ssflib/dep/cryptocore/source/base/subdir.mk index 5f01c31..c6fdf8b 100755 --- a/build/ssflib/dep/cryptocore/source/base/subdir.mk +++ b/build/ssflib/dep/cryptocore/source/base/subdir.mk @@ -47,12 +47,13 @@ C_DEPS += \ ./dep/cryptocore/source/base/cc_sha2.d \ ./dep/cryptocore/source/base/cc_snow2.d +C_FLAGS += -fPIC # Each subdirectory must supply rules for building sources it contributes dep/cryptocore/source/base/%.o: $(SSFLIB_SOURCE)/dep/cryptocore/source/base/%.c @echo 'Building file: $<' @echo 'Invoking: GCC C Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/build/ssflib/dep/cryptocore/source/middle/subdir.mk b/build/ssflib/dep/cryptocore/source/middle/subdir.mk index 73d96ca..f709eb5 100755 --- a/build/ssflib/dep/cryptocore/source/middle/subdir.mk +++ b/build/ssflib/dep/cryptocore/source/middle/subdir.mk @@ -35,12 +35,13 @@ C_DEPS += \ ./dep/cryptocore/source/middle/cc_symmetric.d \ ./dep/cryptocore/source/middle/cc_tdes.d +C_FLAGS += -fPIC # Each subdirectory must supply rules for building sources it contributes dep/cryptocore/source/middle/%.o: $(SSFLIB_SOURCE)/dep/cryptocore/source/middle/%.c @echo 'Building file: $<' @echo 'Invoking: GCC C Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/build/ssflib/dep/cryptocore/source/subdir.mk b/build/ssflib/dep/cryptocore/source/subdir.mk index 0b82019..23e59c8 100755 --- a/build/ssflib/dep/cryptocore/source/subdir.mk +++ b/build/ssflib/dep/cryptocore/source/subdir.mk @@ -8,12 +8,14 @@ OBJS += \ C_DEPS += \ ./dep/cryptocore/source/CC_API.d +C_FLAGS += -fPIC + # Each subdirectory must supply rules for building sources it contributes dep/cryptocore/source/%.o: $(SSFLIB_SOURCE)/dep/cryptocore/source/%.c @echo 'Building file: $<' @echo 'Invoking: GCC C Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/build/ssflib/dep/swdss/source/subdir.mk b/build/ssflib/dep/swdss/source/subdir.mk index fd93294..93190bd 100755 --- a/build/ssflib/dep/swdss/source/subdir.mk +++ b/build/ssflib/dep/swdss/source/subdir.mk @@ -23,12 +23,13 @@ CPP_DEPS += \ ./dep/swdss/source/ss_misc.d \ ./dep/swdss/source/ss_temp_store.d +C_FLAGS += -fPIC # Each subdirectory must supply rules for building sources it contributes dep/swdss/source/%.o: $(SSFLIB_SOURCE)/dep/swdss/source/%.cpp @echo 'Building file: $<' @echo 'Invoking: GCC C++ Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/build/ssflib/dep/time/subdir.mk b/build/ssflib/dep/time/subdir.mk index 58955f9..12cc093 100755 --- a/build/ssflib/dep/time/subdir.mk +++ b/build/ssflib/dep/time/subdir.mk @@ -8,12 +8,13 @@ OBJS += \ CPP_DEPS += \ ./dep/time/ssf_time.d +C_FLAGS += -fPIC # Each subdirectory must supply rules for building sources it contributes dep/time/%.o: $(SSFLIB_SOURCE)/dep/time/%.cpp @echo 'Building file: $<' @echo 'Invoking: GCC C++ Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/build/ssflib/dep/uci/source/subdir.mk b/build/ssflib/dep/uci/source/subdir.mk index e103ce3..5823e7a 100755 --- a/build/ssflib/dep/uci/source/subdir.mk +++ b/build/ssflib/dep/uci/source/subdir.mk @@ -17,12 +17,13 @@ C_DEPS += \ ./dep/uci/source/uci_cryptocore.d \ ./dep/uci/source/uci_hwcrypto.d +C_FLAGS += -fPIC # Each subdirectory must supply rules for building sources it contributes dep/uci/source/%.o: $(SSFLIB_SOURCE)/dep/uci/source/%.c @echo 'Building file: $<' @echo 'Invoking: GCC C Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/build/ssflib/src/subdir.mk b/build/ssflib/src/subdir.mk index 6a5a5b6..f1ddb62 100755 --- a/build/ssflib/src/subdir.mk +++ b/build/ssflib/src/subdir.mk @@ -32,12 +32,14 @@ C_DEPS += \ ./src/ssf_taentrypoint.d \ ./src/app_debug.d +C_FLAGS += -fPIC + # Each subdirectory must supply rules for building sources it contributes src/%.o: $(SSFLIB_SOURCE)/src/%.c @echo 'Building file: $<' @echo 'Invoking: GCC C Compiler' - $(TOOLCHAIN)g++ -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + $(TOOLCHAIN)g++ $(C_FLAGS) -D_SECOS_SIM_ -D__DEBUG__ -I"$(HOME)/ssflib/dep/cryptocore/include" -I"$(HOME)/log" -I"$(HOME)/osal" -I"$(HOME)/include/include" -I"$(HOME)/ssflib/dep/cryptocore/include/base" -I"$(HOME)/ssflib/dep/cryptocore/include/middle" -I"$(HOME)/ssflib/dep/swdss/include" -I"$(HOME)/ssflib/dep/uci/include" -I"$(HOME)/ssflib/inc" -I$(INCLUDE) -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/ssflib/dep/cryptocore/include/CC_Type.h b/ssflib/dep/cryptocore/include/CC_Type.h index 1de5240..94afd90 100755 --- a/ssflib/dep/cryptocore/include/CC_Type.h +++ b/ssflib/dep/cryptocore/include/CC_Type.h @@ -12,15 +12,16 @@ #ifndef _CC_TYPE_H_ #define _CC_TYPE_H_ +#include /*! @brief 1-byte data type */ -typedef unsigned char cc_u8; +typedef uint8_t cc_u8; /*! @brief 2-byte data type */ -typedef unsigned short cc_u16; +typedef uint16_t cc_u16; /*! @brief 4-byte data type */ -typedef unsigned int cc_u32; +typedef uint32_t cc_u32; #ifndef _OP64_NOTSUPPORTED @@ -28,11 +29,11 @@ typedef unsigned int cc_u32; #ifdef _WIN32 typedef unsigned __int64 cc_u64; #else - typedef unsigned long long cc_u64; + typedef uint64_t cc_u64; #endif //_WIN32 #endif //_OP64_NOTSUPPORTED #endif //_CC_TYPE_H_ -/***************************** End of File *****************************/ \ No newline at end of file +/***************************** End of File *****************************/ diff --git a/ssflib/dep/swdss/include/ss_types.h b/ssflib/dep/swdss/include/ss_types.h index 02f1791..82f9663 100755 --- a/ssflib/dep/swdss/include/ss_types.h +++ b/ssflib/dep/swdss/include/ss_types.h @@ -86,7 +86,7 @@ typedef struct credential { typedef unsigned char uint8_t; typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; +typedef unsigned long uint64_t; typedef uint8_t CBT_OCTET; typedef uint8_t* CBT_OCTET_PTR; typedef uint32_t CBT_UINT32; diff --git a/ssflib/dep/uci/include/uci_aes_xcbc_mac.h b/ssflib/dep/uci/include/uci_aes_xcbc_mac.h index 47ff5f0..176a150 100755 --- a/ssflib/dep/uci/include/uci_aes_xcbc_mac.h +++ b/ssflib/dep/uci/include/uci_aes_xcbc_mac.h @@ -43,7 +43,7 @@ typedef struct { int xcbc_init(aes_xcbc_state *xcbc, unsigned char *key, unsigned int keylen); int xcbc_process(aes_xcbc_state *xcbc, unsigned char *in, unsigned int inlen); -int xcbc_done(aes_xcbc_state *xcbc, unsigned char *out, unsigned int *outlen); +int xcbc_done(aes_xcbc_state *xcbc, unsigned char *out, size_t *outlen); #ifdef __cplusplus } diff --git a/ssflib/dep/uci/include/uci_api.h b/ssflib/dep/uci/include/uci_api.h index 0acb7e4..4ce1e25 100755 --- a/ssflib/dep/uci/include/uci_api.h +++ b/ssflib/dep/uci/include/uci_api.h @@ -132,7 +132,7 @@ int uci_mac_update(UCI_HANDLE oh, unsigned char *msg, unsigned int msg_len); * @retval UCI_ERROR if output is NULL. */ int uci_mac_final(UCI_HANDLE oh, unsigned char *output, - unsigned int *output_len); + size_t *output_len); /** * @brief generate c-mac code @@ -298,7 +298,7 @@ int uci_ae_set_keypair(UCI_HANDLE oh, uci_key_s* keymaterial, * @retval UCI_ERROR input or output is NULL.. */ int uci_ae_encrypt(UCI_HANDLE oh, unsigned char * input, unsigned int input_len, - unsigned char * output, unsigned int* output_len); + unsigned char * output, size_t* output_len); /** * @brief RSA Decryption @@ -313,7 +313,7 @@ int uci_ae_encrypt(UCI_HANDLE oh, unsigned char * input, unsigned int input_len, * @retval UCI_ERROR input or output is NULL. */ int uci_ae_decrypt(UCI_HANDLE oh, unsigned char * input, unsigned int input_len, - unsigned char * output, unsigned int* output_len); + unsigned char * output, size_t* output_len); /** * @brief RSA Decryption using CRT @@ -371,7 +371,7 @@ int uci_wbae_decrypt(UCI_HANDLE oh, unsigned char * input, * @retval UCI_ERROR if hash or signature is NULL. */ int uci_ds_sign(UCI_HANDLE oh, unsigned char * hash, unsigned int hash_len, - unsigned char * signature, unsigned int* sign_len); + unsigned char * signature, size_t* sign_len); /** * @brief generate signature for given value @@ -442,13 +442,13 @@ int uci_authcrypt_init(UCI_HANDLE oh, unsigned int mode, unsigned char *nonce, int uci_authcrypt_update_aad(UCI_HANDLE oh, unsigned char *aad, unsigned int aad_len); int uci_authcrypt_update(UCI_HANDLE oh, unsigned char *src, - unsigned int src_len, unsigned char *dest, unsigned int *dest_len); + unsigned int src_len, unsigned char *dest, size_t *dest_len); int uci_authcrypt_encryptfinal(UCI_HANDLE oh, unsigned char *src, - unsigned int src_len, unsigned char *dest, unsigned int *dest_len, - unsigned char *tag, unsigned int *tag_len); + unsigned int src_len, unsigned char *dest, size_t *dest_len, + unsigned char *tag, size_t *tag_len); int uci_authcrypt_decryptfinal(UCI_HANDLE oh, unsigned char *src, - unsigned int src_len, unsigned char *dest, unsigned int *dest_len, + unsigned int src_len, unsigned char *dest, size_t *dest_len, unsigned char *tag, unsigned int tag_len); /** diff --git a/ssflib/dep/uci/include/uci_cryptocore.h b/ssflib/dep/uci/include/uci_cryptocore.h index ab40685..1e83215 100755 --- a/ssflib/dep/uci/include/uci_cryptocore.h +++ b/ssflib/dep/uci/include/uci_cryptocore.h @@ -126,7 +126,7 @@ int cryptocore_mac_update(UCI_HANDLE oh, unsigned char *msg, */ int cryptocore_mac_final(UCI_HANDLE oh, unsigned char *output, - unsigned int *output_len); + size_t *output_len); /** * @brief generate c-mac code @@ -267,7 +267,7 @@ int cryptocore_ae_set_keypair(UCI_HANDLE oh, uci_key_s* keymaterial, */ int cryptocore_ae_encrypt(UCI_HANDLE oh, unsigned char * input, - unsigned int input_len, unsigned char * output, unsigned int* output_len); + unsigned int input_len, unsigned char * output, size_t* output_len); /** * @brief RSA Decryption @@ -281,7 +281,7 @@ int cryptocore_ae_encrypt(UCI_HANDLE oh, unsigned char * input, * @retval UCI_ERROR other error occured. */ int cryptocore_ae_decrypt(UCI_HANDLE oh, unsigned char * input, - unsigned int input_len, unsigned char * output, unsigned int* output_len); + unsigned int input_len, unsigned char * output, size_t* output_len); /** * @brief RSA Decryption using CRT @@ -295,7 +295,7 @@ int cryptocore_ae_decrypt(UCI_HANDLE oh, unsigned char * input, * @retvla UCI_ERROR other error occured. */ int cryptocore_ae_decryptbycrt(UCI_HANDLE oh, unsigned char * input, - unsigned int input_len, unsigned char * output, unsigned int* output_len); + unsigned int input_len, unsigned char * output, size_t* output_len); /** * @brief generate signature for given value @@ -309,7 +309,7 @@ int cryptocore_ae_decryptbycrt(UCI_HANDLE oh, unsigned char * input, * @retval UCI_ERROR other error occured. */ int cryptocore_ds_sign(UCI_HANDLE oh, unsigned char * hash, - unsigned int hash_len, unsigned char * signature, unsigned int* sign_len); + unsigned int hash_len, unsigned char * signature, size_t* sign_len); /** * @brief generate signature for given value diff --git a/ssflib/dep/uci/include/uci_type.h b/ssflib/dep/uci/include/uci_type.h index f3c8843..f123fa8 100755 --- a/ssflib/dep/uci/include/uci_type.h +++ b/ssflib/dep/uci/include/uci_type.h @@ -35,7 +35,7 @@ * @brief UCI handle. * */ -typedef int UCI_HANDLE; +typedef intptr_t UCI_HANDLE; /** * @brief UCI return error type. * diff --git a/ssflib/dep/uci/source/uci_aes_xcbc_mac.c b/ssflib/dep/uci/source/uci_aes_xcbc_mac.c index ae3f3b0..e20585f 100755 --- a/ssflib/dep/uci/source/uci_aes_xcbc_mac.c +++ b/ssflib/dep/uci/source/uci_aes_xcbc_mac.c @@ -94,7 +94,7 @@ int xcbc_process(aes_xcbc_state *xcbc, unsigned char *in, unsigned int inlen) { } return 1; } -int xcbc_done(aes_xcbc_state *xcbc, unsigned char *out, unsigned int *outlen) { +int xcbc_done(aes_xcbc_state *xcbc, unsigned char *out, size_t *outlen) { unsigned int x; if (xcbc == NULL || out == NULL) { return 0; diff --git a/ssflib/dep/uci/source/uci_api.c b/ssflib/dep/uci/source/uci_api.c index 15cb5fc..59928ae 100755 --- a/ssflib/dep/uci/source/uci_api.c +++ b/ssflib/dep/uci/source/uci_api.c @@ -83,7 +83,7 @@ UCI_HANDLE uci_context_alloc(unsigned int algorithm, uci_engine_config_e config) ctx = (uci_context_s*)OsaMalloc(sizeof(uci_context_s)); ctx->imp = (aes_xcbc_state *)OsaMalloc(sizeof(aes_xcbc_state)); ctx->alg = ID_UCI_XCBCMAC; - return (int)ctx; + return (UCI_HANDLE)ctx; } if (conf == UCI_SW_CRYPTOCORE) { return cryptocore_context_alloc(algorithm); @@ -172,7 +172,7 @@ int uci_mac_update(UCI_HANDLE oh, unsigned char *msg, unsigned int msg_len) { } int uci_mac_final(UCI_HANDLE oh, unsigned char *output, - unsigned int *output_len) { + size_t *output_len) { int ret = 0; uci_context_s *pctx = (uci_context_s*)oh; if (pctx->alg == ID_UCI_XCBCMAC) { @@ -189,8 +189,8 @@ int uci_mac_final(UCI_HANDLE oh, unsigned char *output, int uci_mac_get_mac(UCI_HANDLE oh, unsigned char *key, unsigned int key_len, unsigned char *msg, unsigned int msg_len, unsigned char *output, - unsigned int *output_len) { - //int ret = 0; + size_t *output_len) { + int ret = 0; uci_context_s *pctx = (uci_context_s*)oh; if (pctx->alg == ID_UCI_XCBCMAC) { if (xcbc_init((aes_xcbc_state *)(pctx->imp), key, key_len) != 1) { @@ -207,8 +207,11 @@ int uci_mac_get_mac(UCI_HANDLE oh, unsigned char *key, unsigned int key_len, return UCI_SUCCESS; } - return cryptocore_mac_getmac(oh, key, key_len, msg, msg_len, output, - output_len); + unsigned int uioutput_len = (unsigned int)(*output_len); + ret = cryptocore_mac_getmac(oh, key, key_len, msg, msg_len, output, + &uioutput_len); + *output_len = (size_t)uioutput_len; + return ret; } int uci_se_init(UCI_HANDLE oh, unsigned int mode, unsigned padding, @@ -315,17 +318,17 @@ int uci_ae_set_keypair(UCI_HANDLE oh, uci_key_s *keymaterial, } int uci_ae_encrypt(UCI_HANDLE oh, unsigned char *input, unsigned int input_len, - unsigned char *output, unsigned int *output_len) { + unsigned char *output, size_t *output_len) { return cryptocore_ae_encrypt(oh, input, input_len, output, output_len); } int uci_ae_decrypt(UCI_HANDLE oh, unsigned char *input, unsigned int input_len, - unsigned char *output, unsigned int *output_len) { + unsigned char *output, size_t *output_len) { return cryptocore_ae_decrypt(oh, input, input_len, output, output_len); } int uci_ae_decryptbycrt(UCI_HANDLE oh, unsigned char *input, - unsigned int input_len, unsigned char *output, unsigned int *output_len) { + unsigned int input_len, unsigned char *output, size_t *output_len) { return cryptocore_ae_decryptbycrt(oh, input, input_len, output, output_len); } @@ -340,7 +343,7 @@ int uci_wbae_decrypt(UCI_HANDLE oh, unsigned char *input, } int uci_ds_sign(UCI_HANDLE oh, unsigned char *hash, unsigned int hash_len, - unsigned char *signature, unsigned int *sign_len) { + unsigned char *signature, size_t *sign_len) { return cryptocore_ds_sign(oh, hash, hash_len, signature, sign_len); } @@ -443,7 +446,7 @@ int uci_authcrypt_update_aad(UCI_HANDLE oh, unsigned char *aad, return UCI_ERROR; } int uci_authcrypt_update(UCI_HANDLE oh, unsigned char *src, - unsigned int src_len, unsigned char *dest, unsigned int *dest_len) { + unsigned int src_len, unsigned char *dest, size_t *dest_len) { #if 0 uci_context_s *pctx = (uci_context_s*)oh; gcm_context *gctx; @@ -477,8 +480,8 @@ int uci_authcrypt_update(UCI_HANDLE oh, unsigned char *src, return UCI_ERROR; } int uci_authcrypt_encryptfinal(UCI_HANDLE oh, unsigned char *src, - unsigned int src_len, unsigned char *dest, unsigned int *dest_len, - unsigned char *tag, unsigned int *tag_len) { + unsigned int src_len, unsigned char *dest, size_t *dest_len, + unsigned char *tag, size_t *tag_len) { #if 0 uci_context_s *pctx = (uci_context_s*)oh; gcm_context *gctx = NULL; @@ -525,7 +528,7 @@ int uci_authcrypt_encryptfinal(UCI_HANDLE oh, unsigned char *src, return UCI_ERROR; } int uci_authcrypt_decryptfinal(UCI_HANDLE oh, unsigned char *src, - unsigned int src_len, unsigned char *dest, unsigned int *dest_len, + unsigned int src_len, unsigned char *dest, size_t *dest_len, unsigned char *tag, unsigned int tag_len) { #if 0 uci_context_s *pctx = (uci_context_s*)oh; diff --git a/ssflib/dep/uci/source/uci_cryptocore.c b/ssflib/dep/uci/source/uci_cryptocore.c index db15895..f695180 100755 --- a/ssflib/dep/uci/source/uci_cryptocore.c +++ b/ssflib/dep/uci/source/uci_cryptocore.c @@ -182,7 +182,7 @@ int cryptocore_mac_update(UCI_HANDLE oh, unsigned char *msg, } int cryptocore_mac_final(UCI_HANDLE oh, unsigned char *output, - unsigned int *output_len) { + size_t *output_len) { int ret; uci_context_s *pctx = (uci_context_s*)oh; if (pctx == NULL) { @@ -193,8 +193,11 @@ int cryptocore_mac_final(UCI_HANDLE oh, unsigned char *output, return UCI_INVALID_HANDLE; } + cc_u32 output_len32 = (cc_u32)(*output_len); ret = ((CryptoCoreContainer *)pctx->imp)->MAC_final( - (CryptoCoreContainer*)(pctx->imp), output, output_len); + (CryptoCoreContainer*)(pctx->imp), output, &output_len32); + *output_len = (size_t)output_len32; + if (ret != CRYPTO_SUCCESS) { return UCI_ERROR; } @@ -709,7 +712,7 @@ int cryptocore_ae_set_keypair(UCI_HANDLE oh, uci_key_s *keymaterial, } int cryptocore_ae_encrypt(UCI_HANDLE oh, unsigned char *input, - unsigned int input_len, unsigned char *output, unsigned int *output_len) { + unsigned int input_len, unsigned char *output, size_t *output_len) { int ret; uci_context_s *pctx = (uci_context_s*)oh; @@ -724,8 +727,11 @@ int cryptocore_ae_encrypt(UCI_HANDLE oh, unsigned char *input, if (pctx->alg < ID_UCI_RSA || pctx->alg > ID_UCI_RSA512) { return UCI_INVALID_HANDLE; } + + cc_u32 output_len32 = (cc_u32)(*output_len); ret = ((CryptoCoreContainer *)pctx->imp)->AE_encrypt( - ((CryptoCoreContainer*)pctx->imp), input, input_len, output, output_len); + ((CryptoCoreContainer*)pctx->imp), input, input_len, output, &output_len32); + *output_len = (size_t)output_len32; if (ret == CRYPTO_MSG_TOO_LONG) { return UCI_MSG_TOO_LONG; } @@ -736,7 +742,7 @@ int cryptocore_ae_encrypt(UCI_HANDLE oh, unsigned char *input, } int cryptocore_ae_decrypt(UCI_HANDLE oh, unsigned char *input, - unsigned int input_len, unsigned char *output, unsigned int *output_len) { + unsigned int input_len, unsigned char *output, size_t *output_len) { int ret; uci_context_s *pctx = (uci_context_s*)oh; @@ -752,8 +758,12 @@ int cryptocore_ae_decrypt(UCI_HANDLE oh, unsigned char *input, if (pctx->alg < ID_UCI_RSA || pctx->alg > ID_UCI_RSA512) { return UCI_INVALID_HANDLE; } + + cc_u32 output_len32 = (cc_u32)(*output_len); ret = ((CryptoCoreContainer *)pctx->imp)->AE_decrypt( - ((CryptoCoreContainer*)pctx->imp), input, input_len, output, output_len); + ((CryptoCoreContainer*)pctx->imp), input, input_len, output, &output_len32); + *output_len = (size_t)output_len32; + if (ret == CRYPTO_MSG_TOO_LONG) { return UCI_MSG_TOO_LONG; } @@ -791,7 +801,7 @@ int cryptocore_ae_decryptbycrt(UCI_HANDLE oh, unsigned char *input, } int cryptocore_ds_sign(UCI_HANDLE oh, unsigned char *hash, - unsigned int hash_len, unsigned char *signature, unsigned int *sign_len) { + unsigned int hash_len, unsigned char *signature, size_t *sign_len) { int ret; uci_context_s *pctx = (uci_context_s*)oh; @@ -804,8 +814,10 @@ int cryptocore_ds_sign(UCI_HANDLE oh, unsigned char *hash, return UCI_INVALID_HANDLE; } + cc_u32 sign_len32 = (cc_u32)(*sign_len); ret = ((CryptoCoreContainer *)pctx->imp)->DS_sign( - ((CryptoCoreContainer*)pctx->imp), hash, hash_len, signature, sign_len); + ((CryptoCoreContainer*)pctx->imp), hash, hash_len, signature, &sign_len32); + *sign_len = (size_t)sign_len32; if (ret == CRYPTO_MSG_TOO_LONG) { return UCI_MSG_TOO_LONG; } diff --git a/ssflib/src/ssf_crypto.c b/ssflib/src/ssf_crypto.c index 655eabd..fc14963 100755 --- a/ssflib/src/ssf_crypto.c +++ b/ssflib/src/ssf_crypto.c @@ -1339,9 +1339,9 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, unsigned char pub[384]; unsigned char priv[384]; unsigned char module[384]; - unsigned int pubLen = 384; - unsigned int privLen = 384; - unsigned int moduleLen = 384; + size_t pubLen = 384; + size_t privLen = 384; + size_t moduleLen = 384; unsigned int alg; memset(&ucikey, 0, sizeof(uci_key_s)); memset(&uciparam, 0, sizeof(uci_param_s)); @@ -1425,6 +1425,7 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, uciparam.ucip_rsa_padding = ID_UCI_NO_PADDING; break; } + size_t obj_size = (size_t)(key->info.objectSize); switch (key->info.objectType) { case TEE_TYPE_RSA_PUBLIC_KEY: case TEE_TYPE_RSA_KEYPAIR: @@ -1524,7 +1525,7 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, uciparam.ucip_dsa_g_len = key->info.objectSize; uciparam.ucip_dsa_q_len = key->info.objectSize; rc = TEE_GetObjectBufferAttribute(key, TEE_ATTR_DSA_PRIME, - uciparam.ucip_dsa_p, &uciparam.ucip_dsa_p_len); + uciparam.ucip_dsa_p, &obj_size); if (rc != TEE_SUCCESS) { OsaFree(uciparam.ucip_dsa_p); OsaFree(uciparam.ucip_dsa_q); @@ -1534,7 +1535,7 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, return rc; } rc = TEE_GetObjectBufferAttribute(key, TEE_ATTR_DSA_BASE, - uciparam.ucip_dsa_g, &uciparam.ucip_dsa_g_len); + uciparam.ucip_dsa_g, &obj_size); if (rc != TEE_SUCCESS) { OsaFree(uciparam.ucip_dsa_p); OsaFree(uciparam.ucip_dsa_q); @@ -1544,7 +1545,7 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, return rc; } rc = TEE_GetObjectBufferAttribute(key, TEE_ATTR_DSA_SUBPRIME, - uciparam.ucip_dsa_q, &uciparam.ucip_dsa_q_len); + uciparam.ucip_dsa_q, &obj_size); if (rc != TEE_SUCCESS) { OsaFree(uciparam.ucip_dsa_p); OsaFree(uciparam.ucip_dsa_q); @@ -1571,7 +1572,7 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, key->info.objectSize); uciparam.ucip_dh_len = key->info.objectSize; rc = TEE_GetObjectBufferAttribute(key, TEE_ATTR_DH_PRIME, - uciparam.ucip_dh_prime, &uciparam.ucip_dh_len); + uciparam.ucip_dh_prime, &obj_size); if (rc != TEE_SUCCESS) { OsaFree(uciparam.ucip_dh_prime); OsaFree(uciparam.ucip_dh_generator); @@ -1580,7 +1581,7 @@ TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, return rc; } rc = TEE_GetObjectBufferAttribute(key, TEE_ATTR_DH_BASE, - uciparam.ucip_dh_generator, &uciparam.ucip_dh_len); + uciparam.ucip_dh_generator, &obj_size); if (rc != TEE_SUCCESS) { OsaFree(uciparam.ucip_dh_prime); OsaFree(uciparam.ucip_dh_generator); @@ -1728,9 +1729,9 @@ void TEE_CipherInit(TEE_OperationHandle operation, const void* IV, size_t IVLen) unsigned int mode; unsigned char key1[32] = {0x0, }; //unsigned char key2[32] = {0x0, }; - unsigned int key_len1 = sizeof(key1); + size_t key_len1 = sizeof(key1); //unsigned int key_len2 = sizeof(key2); - unsigned int uci_alg; + size_t uci_alg; TEE_Result rc; struct TEE_Operation * op = (struct TEE_Operation*)operation; @@ -2521,8 +2522,8 @@ void TEE_DeriveKey(TEE_OperationHandle operation, const TEE_Attribute* params, unsigned char authkey[512]; unsigned char privkey[512]; unsigned char *pubkey = NULL; - unsigned int pubkey_len = 0; - unsigned int privkey_len = sizeof(privkey); + size_t pubkey_len = 0; + size_t privkey_len = sizeof(privkey); TEE_Attribute attrs[1]; TEE_Result rc; struct TEE_Operation * op = (struct TEE_Operation*)operation; -- 2.7.4